PRCHES1 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;3/18/93 11:42
V ;;5.1;IFCAP;;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;ROUTINE FOR MAINTAINING SUBFIELD 7 (ELECTRONIC SIGNATURE)
; FIELD .6 (PARTIAL), FILE 442
DECODE(LEVEL0,LEVEL1) ;Extrinsic Function to return hashed esig in readable form.
;returns "" if unsuccessful
NEW RECORD,RECORD1,VERSION,PERSON,SIG,CHECKSUM
;get record and check version
S RECORD=$G(^PRC(442,LEVEL0,11,LEVEL1,0)) I RECORD="" Q ""
S RECORD1=$G(^PRC(442,LEVEL0,11,LEVEL1,1))
S VERSION=$P(RECORD1,"^",9)
S PERSON=+$P(RECORD,"^",7)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD,"^",8)
D1 ;decode e signature for version 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD))
Q $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,LEVEL1,USERNUM,Y) ;Encode esig for version 1 only
NEW RECORD,RECORD1,SIGBLOCK,CHECKSUM,OLDUSER
S USERNUM=+USERNUM
I USERNUM=0 S Y=-3 Q ;-3 no user number
S SIGBLOCK=$P($G(^VA(200,USERNUM,20)),"^",2)
I SIGBLOCK="" S Y=-2 Q ;-2 no signature block
S RECORD=$G(^PRC(442,LEVEL0,11,LEVEL1,0))
S RECORD1=$G(^PRC(442,LEVEL0,11,LEVEL1,1))
I RECORD="" S Y=-1 Q ;-1 no 2237 record
I $P(RECORD,"^",8)'="" S Y=-4 Q ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD,"^",7)
I OLDUSER=0 S $P(RECORD,"^",7)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD,"^",11)="" $P(RECORD,"^",11)=$$NOW^PRCUESIG
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD))
S $P(RECORD,"^",8)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD1,"^",9,10)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRC(442,LEVEL0,11,LEVEL1,0)=RECORD
S ^PRC(442,LEVEL0,11,LEVEL1,1)=RECORD1
S Y=1 Q
RECODE(LEVEL0,LEVEL1,CHECKSUM,Y) ;Recode esig for version 1 only
NEW RECORD,RECORD1,SIGBLOCK,USERNUM
S RECORD=$G(^PRC(442,LEVEL0,11,LEVEL1,0))
S RECORD1=$G(^PRC(442,LEVEL0,11,LEVEL1,1))
I RECORD=""!(RECORD1="") S Y=-1 Q ;-1 no record
S USERNUM=+$P(RECORD,"^",7)
I $P(RECORD,"^",8)=""!(USERNUM=0) S Y=-4 Q ;-4 cannot recode record
;S SIGBLOCK=$$DECODE^PRCUESIG($P(RECORD,"^",8),USERNUM,CHECKSUM)
S SIGBLOCK=$P($G(^VA(200,USERNUM,20)),"^",2)
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD))
S $P(RECORD,"^",8)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD1,"^",10)=$$SUM^PRCUESIG(SIGBLOCK)
S ^PRC(442,LEVEL0,11,LEVEL1,0)=RECORD
S ^PRC(442,LEVEL0,11,LEVEL1,1)=RECORD1
S Y=1
Q
REMOVE(LEVEL0,LEVEL1) ;Entry point to remove esig
NEW I,RECORD,RECORD1
S RECORD=$G(^PRC(442,LEVEL0,11,LEVEL1,0))
S RECORD1=$G(^PRC(442,LEVEL0,11,LEVEL1,1))
F I=7,8,11 S $P(RECORD,"^",I)=""
S $P(RECORD1,"^",10)=""
S ^PRC(442,LEVEL0,11,LEVEL1,0)=RECORD
S ^PRC(442,LEVEL0,11,LEVEL1,1)=RECORD1
Q
VERIFY(LEVEL0,LEVEL1) ;extrinsic function to verify esig Returns 1 if valid, 0 if not valid
NEW RECORD,RECORD1,VERSION,SIGBLOCK
S RECORD=$G(^PRC(442,LEVEL0,11,LEVEL1,0))
S RECORD1=$G(^PRC(442,LEVEL0,11,LEVEL1,1))
S VERSION=$P(RECORD1,"^",9),SIGBLOCK=$P(RECORD1,"^",10)
I VERSION_SIGBLOCK="" Q 1
Q $$SUM^PRCUESIG($$DECODE(LEVEL0,LEVEL1))=SIGBLOCK
STRING(X) ;Build String of critical fields
Q $P(X,"^")_"^"_$P(X,"^",3)_"^"_$P(X,"^",5)_"^"_$P(X,"^",11)_"^"_$P(X,"^",12)_"^"_$P(X,"^",14)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCHES1 3285 printed Dec 13, 2024@02:07:15 Page 2
PRCHES1 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;3/18/93 11:42
V ;;5.1;IFCAP;;Oct 20, 2000
+1 ;Per VHA Directive 10-93-142, this routine should not be modified.
+2 ;ROUTINE FOR MAINTAINING SUBFIELD 7 (ELECTRONIC SIGNATURE)
+3 ; FIELD .6 (PARTIAL), FILE 442
DECODE(LEVEL0,LEVEL1) ;Extrinsic Function to return hashed esig in readable form.
+1 ;returns "" if unsuccessful
+2 NEW RECORD,RECORD1,VERSION,PERSON,SIG,CHECKSUM
+3 ;get record and check version
+4 SET RECORD=$GET(^PRC(442,LEVEL0,11,LEVEL1,0))
IF RECORD=""
QUIT ""
+5 SET RECORD1=$GET(^PRC(442,LEVEL0,11,LEVEL1,1))
+6 SET VERSION=$PIECE(RECORD1,"^",9)
+7 SET PERSON=+$PIECE(RECORD,"^",7)
+8 IF VERSION'=""
IF VERSION'=1
QUIT ""
+9 SET SIG=$PIECE(RECORD,"^",8)
D1 ;decode e signature for version 1
+1 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD))
+2 QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,LEVEL1,USERNUM,Y) ;Encode esig for version 1 only
+1 NEW RECORD,RECORD1,SIGBLOCK,CHECKSUM,OLDUSER
+2 SET USERNUM=+USERNUM
+3 ;-3 no user number
IF USERNUM=0
SET Y=-3
QUIT
+4 SET SIGBLOCK=$PIECE($GET(^VA(200,USERNUM,20)),"^",2)
+5 ;-2 no signature block
IF SIGBLOCK=""
SET Y=-2
QUIT
+6 SET RECORD=$GET(^PRC(442,LEVEL0,11,LEVEL1,0))
+7 SET RECORD1=$GET(^PRC(442,LEVEL0,11,LEVEL1,1))
+8 ;-1 no 2237 record
IF RECORD=""
SET Y=-1
QUIT
+9 ;-4 cannot re-sign record
IF $PIECE(RECORD,"^",8)'=""
SET Y=-4
QUIT
+10 SET OLDUSER=+$PIECE(RECORD,"^",7)
+11 IF OLDUSER=0
SET $PIECE(RECORD,"^",7)=USERNUM
+12 IF OLDUSER>0
SET USERNUM=OLDUSER
+13 if $PIECE(RECORD,"^",11)=""
SET $PIECE(RECORD,"^",11)=$$NOW^PRCUESIG
+14 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD))
+15 SET $PIECE(RECORD,"^",8)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+16 SET $PIECE(RECORD1,"^",9,10)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
+17 SET ^PRC(442,LEVEL0,11,LEVEL1,0)=RECORD
+18 SET ^PRC(442,LEVEL0,11,LEVEL1,1)=RECORD1
+19 SET Y=1
QUIT
RECODE(LEVEL0,LEVEL1,CHECKSUM,Y) ;Recode esig for version 1 only
+1 NEW RECORD,RECORD1,SIGBLOCK,USERNUM
+2 SET RECORD=$GET(^PRC(442,LEVEL0,11,LEVEL1,0))
+3 SET RECORD1=$GET(^PRC(442,LEVEL0,11,LEVEL1,1))
+4 ;-1 no record
IF RECORD=""!(RECORD1="")
SET Y=-1
QUIT
+5 SET USERNUM=+$PIECE(RECORD,"^",7)
+6 ;-4 cannot recode record
IF $PIECE(RECORD,"^",8)=""!(USERNUM=0)
SET Y=-4
QUIT
+7 ;S SIGBLOCK=$$DECODE^PRCUESIG($P(RECORD,"^",8),USERNUM,CHECKSUM)
+8 SET SIGBLOCK=$PIECE($GET(^VA(200,USERNUM,20)),"^",2)
+9 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD))
+10 SET $PIECE(RECORD,"^",8)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+11 SET $PIECE(RECORD1,"^",10)=$$SUM^PRCUESIG(SIGBLOCK)
+12 SET ^PRC(442,LEVEL0,11,LEVEL1,0)=RECORD
+13 SET ^PRC(442,LEVEL0,11,LEVEL1,1)=RECORD1
+14 SET Y=1
+15 QUIT
REMOVE(LEVEL0,LEVEL1) ;Entry point to remove esig
+1 NEW I,RECORD,RECORD1
+2 SET RECORD=$GET(^PRC(442,LEVEL0,11,LEVEL1,0))
+3 SET RECORD1=$GET(^PRC(442,LEVEL0,11,LEVEL1,1))
+4 FOR I=7,8,11
SET $PIECE(RECORD,"^",I)=""
+5 SET $PIECE(RECORD1,"^",10)=""
+6 SET ^PRC(442,LEVEL0,11,LEVEL1,0)=RECORD
+7 SET ^PRC(442,LEVEL0,11,LEVEL1,1)=RECORD1
+8 QUIT
VERIFY(LEVEL0,LEVEL1) ;extrinsic function to verify esig Returns 1 if valid, 0 if not valid
+1 NEW RECORD,RECORD1,VERSION,SIGBLOCK
+2 SET RECORD=$GET(^PRC(442,LEVEL0,11,LEVEL1,0))
+3 SET RECORD1=$GET(^PRC(442,LEVEL0,11,LEVEL1,1))
+4 SET VERSION=$PIECE(RECORD1,"^",9)
SET SIGBLOCK=$PIECE(RECORD1,"^",10)
+5 IF VERSION_SIGBLOCK=""
QUIT 1
+6 QUIT $$SUM^PRCUESIG($$DECODE(LEVEL0,LEVEL1))=SIGBLOCK
STRING(X) ;Build String of critical fields
+1 QUIT $PIECE(X,"^")_"^"_$PIECE(X,"^",3)_"^"_$PIECE(X,"^",5)_"^"_$PIECE(X,"^",11)_"^"_$PIECE(X,"^",12)_"^"_$PIECE(X,"^",14)