PRCHES10 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;4/28/93 15:12
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 50 (AMENDMENT) FILE 443.6
DECODE(LEVEL0,LEVEL1) ;Extrinsic Function to return hashed electronic sig to readable form.
;returns "" if unsuccessful
NEW RECORD,RECORD1,VERSION,PERSON,SIG,CHECKSUM
S RECORD=$G(^PRC(443.6,LEVEL0,6,LEVEL1,0)) I RECORD="" Q ""
S RECORD1=$G(^PRC(443.6,LEVEL0,6,LEVEL1,1))
S VERSION=$P(RECORD,"^",9)
S PERSON=+$P(RECORD1,"^")
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD1,"^",2)
I VERSION=1 G D1
D ;decode e signature less than version 1
S X=$$DECODE^PRCUESIG(SIG,LEVEL1,PERSON)
Q X
D1 ;decode e signature for version 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD,RECORD1))
Q $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,LEVEL1,USERNUM,Y) ;Encode e signature for version 1 only
NEW RECORD,RECORD1,SIGBLOCK,CHECKSUM,OLDUSER
S USERNUM=+USERNUM
I USERNUM=0 S Y=-3 Q ;-3 no user number available for filing
S SIGBLOCK=$P($G(^VA(200,USERNUM,20)),"^",2)
I SIGBLOCK="" S Y=-2 Q ;-2 no signature block in file 200
S RECORD=$G(^PRC(443.6,LEVEL0,6,LEVEL1,0))
S RECORD1=$G(^PRC(443.6,LEVEL0,6,LEVEL1,1))
I RECORD="" S Y=-1 Q ;-1 no 2237 record
I $P(RECORD1,"^",2)'="" S Y=-4 Q ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD1,"^")
I OLDUSER=0 S $P(RECORD1,"^")=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD1,"^",3)="" $P(RECORD1,"^",3)=$$NOW^PRCUESIG
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD,RECORD1))
S $P(RECORD1,"^",2)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD,"^",9)="1",$P(RECORD,"^",10)=$$SUM^PRCUESIG(SIGBLOCK)
S ^PRC(443.6,LEVEL0,6,LEVEL1,0)=RECORD
S ^PRC(443.6,LEVEL0,6,LEVEL1,1)=RECORD1
S Y=1 Q
REMOVE(LEVEL0,LEVEL1) ;Entry point to remove e signature from record
NEW RECORD,RECORD1
S Y=""
;S RECORD=$G(^PRC(443.6,LEVEL0,6,LEVEL1,0)) Q:RECORD=""
;S $P(^PRC(443.6,LEVEL0,6,LEVEL1,0),"^",2,3)="^",$P(^(0),"^",10)="",$P(^(1),"^")="",$P(^(1),"^",2)=""
S RECORD=$G(^PRC(443.6,LEVEL0,6,LEVEL1,0))
S RECORD1=$G(^PRC(443.6,LEVEL0,6,LEVEL1,1))
I RECORD=""!(RECORD1="") S Y=-1 Q
S $P(RECORD1,"^",2,3)="^",$P(RECORD,"^",10)=""
S ^PRC(443.6,LEVEL0,6,LEVEL1,0)=RECORD
S ^PRC(443.6,LEVEL0,6,LEVEL1,1)=RECORD1
Q
VERIFY(LEVEL0,LEVEL1) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
NEW RECORD1,VERSION,SIGBLOCK
S RECORD1=$G(^PRC(443.6,LEVEL0,6,LEVEL1,1))
S VERSION=$P(RECORD,"^",9),SIGBLOCK=$P(RECORD,"^",10)
I VERSION_SIGBLOCK="" Q 1
Q ($$SUM^PRCUESIG($$DECODE(LEVEL0,LEVEL1))=SIGBLOCK)
STRING(X,X1) ;Build String of critical fields
Q $P(X,"^",1,4)_"^"_$P(X1,"^",3)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCHES10 2845 printed Oct 16, 2024@18:08:01 Page 2
PRCHES10 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;4/28/93 15:12
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 50 (AMENDMENT) FILE 443.6
DECODE(LEVEL0,LEVEL1) ;Extrinsic Function to return hashed electronic sig to readable form.
+1 ;returns "" if unsuccessful
+2 NEW RECORD,RECORD1,VERSION,PERSON,SIG,CHECKSUM
+3 SET RECORD=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,0))
IF RECORD=""
QUIT ""
+4 SET RECORD1=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,1))
+5 SET VERSION=$PIECE(RECORD,"^",9)
+6 SET PERSON=+$PIECE(RECORD1,"^")
+7 IF VERSION'=""
IF VERSION'=1
QUIT ""
+8 SET SIG=$PIECE(RECORD1,"^",2)
+9 IF VERSION=1
GOTO D1
D ;decode e signature less than version 1
+1 SET X=$$DECODE^PRCUESIG(SIG,LEVEL1,PERSON)
+2 QUIT X
D1 ;decode e signature for version 1
+1 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD,RECORD1))
+2 QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,LEVEL1,USERNUM,Y) ;Encode e signature for version 1 only
+1 NEW RECORD,RECORD1,SIGBLOCK,CHECKSUM,OLDUSER
+2 SET USERNUM=+USERNUM
+3 ;-3 no user number available for filing
IF USERNUM=0
SET Y=-3
QUIT
+4 SET SIGBLOCK=$PIECE($GET(^VA(200,USERNUM,20)),"^",2)
+5 ;-2 no signature block in file 200
IF SIGBLOCK=""
SET Y=-2
QUIT
+6 SET RECORD=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,0))
+7 SET RECORD1=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,1))
+8 ;-1 no 2237 record
IF RECORD=""
SET Y=-1
QUIT
+9 ;-4 cannot re-sign record
IF $PIECE(RECORD1,"^",2)'=""
SET Y=-4
QUIT
+10 SET OLDUSER=+$PIECE(RECORD1,"^")
+11 IF OLDUSER=0
SET $PIECE(RECORD1,"^")=USERNUM
+12 IF OLDUSER>0
SET USERNUM=OLDUSER
+13 if $PIECE(RECORD1,"^",3)=""
SET $PIECE(RECORD1,"^",3)=$$NOW^PRCUESIG
+14 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_LEVEL1_"^"_$$STRING(RECORD,RECORD1))
+15 SET $PIECE(RECORD1,"^",2)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+16 SET $PIECE(RECORD,"^",9)="1"
SET $PIECE(RECORD,"^",10)=$$SUM^PRCUESIG(SIGBLOCK)
+17 SET ^PRC(443.6,LEVEL0,6,LEVEL1,0)=RECORD
+18 SET ^PRC(443.6,LEVEL0,6,LEVEL1,1)=RECORD1
+19 SET Y=1
QUIT
REMOVE(LEVEL0,LEVEL1) ;Entry point to remove e signature from record
+1 NEW RECORD,RECORD1
+2 SET Y=""
+3 ;S RECORD=$G(^PRC(443.6,LEVEL0,6,LEVEL1,0)) Q:RECORD=""
+4 ;S $P(^PRC(443.6,LEVEL0,6,LEVEL1,0),"^",2,3)="^",$P(^(0),"^",10)="",$P(^(1),"^")="",$P(^(1),"^",2)=""
+5 SET RECORD=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,0))
+6 SET RECORD1=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,1))
+7 IF RECORD=""!(RECORD1="")
SET Y=-1
QUIT
+8 SET $PIECE(RECORD1,"^",2,3)="^"
SET $PIECE(RECORD,"^",10)=""
+9 SET ^PRC(443.6,LEVEL0,6,LEVEL1,0)=RECORD
+10 SET ^PRC(443.6,LEVEL0,6,LEVEL1,1)=RECORD1
+11 QUIT
VERIFY(LEVEL0,LEVEL1) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
+1 NEW RECORD1,VERSION,SIGBLOCK
+2 SET RECORD1=$GET(^PRC(443.6,LEVEL0,6,LEVEL1,1))
+3 SET VERSION=$PIECE(RECORD,"^",9)
SET SIGBLOCK=$PIECE(RECORD,"^",10)
+4 IF VERSION_SIGBLOCK=""
QUIT 1
+5 QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0,LEVEL1))=SIGBLOCK)
STRING(X,X1) ;Build String of critical fields
+1 QUIT $PIECE(X,"^",1,4)_"^"_$PIECE(X1,"^",3)
+2 QUIT