PRCHES12 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;9/23/94 10:49 AM
V ;;5.1;IFCAP;;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;ROUTINE FOR MAINTAINING FIELD 16.5 (ELECTRONIC SIGNATURE), FILE 443.6
DECODE(LEVEL0) ;Extrinsic Function to return hashed esig to readable form.
;returns "" if unsuccessful
NEW RECORD,RECORD1,RECORD12,VERSION,PERSON,SIG,CHECKSUM
S RECORD=$G(^PRC(443.6,LEVEL0,0)) I RECORD="" Q ""
S RECORD1=$G(^PRC(443.6,LEVEL0,1))
S RECORD12=$G(^PRC(443.6,LEVEL0,12))
S VERSION=$P(RECORD12,"^",11)
S PERSON=+$P(RECORD1,"^",10)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD12,"^",2)
D1 ;decode e signature for version 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD12))
Q $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode esig for version 1 only
S Y=-4 Q ;-4 cannot encode record
;
RECODE(LEVEL0,CHECKSUM,Y) ;Recode esig for version 1 only
NEW RECORD,RECORD1,RECORD12,SIGBLOCK,USERNUM
S RECORD=$G(^PRC(443.6,LEVEL0,0))
S RECORD1=$G(^PRC(443.6,LEVEL0,1))
S RECORD12=$G(^PRC(443.6,LEVEL0,12))
I RECORD="" S Y=-1 Q ;-1 no record
S USERNUM=+$P(RECORD1,"^",10)
I $P(RECORD12,"^",2)=""!(USERNUM=0)!'CHECKSUM S Y=-4 Q ;-4 cannot recode record
;S SIGBLOCK=$$DECODE^PRCUESIG($P(RECORD12,"^",2),USERNUM,CHECKSUM)
S SIGBLOCK=$P($G(^VA(200,USERNUM,20)),"^",2)
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD12))
S $P(RECORD12,"^",2)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD12,"^",11,12)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRC(443.6,LEVEL0,12)=RECORD12
S Y=1 Q
REMOVE(LEVEL0) ;Entry point to remove esig from record
NEW I,RECORD1,RECORD12
S RECORD1=$G(^PRC(443.6,LEVEL0,1))
S RECORD12=$G(^PRC(443.6,LEVEL0,12))
F I=2,3,12 S $P(RECORD12,"^",I)=""
S ^PRC(443.6,LEVEL0,1)=RECORD1
S ^PRC(443.6,LEVEL0,12)=RECORD12
Q
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
NEW RECORD,RECORD1,RECORD12,VERSION,SIGBLOCK
S RECORD12=$G(^PRC(443.6,LEVEL0,12))
S VERSION=$P(RECORD12,"^",11),SIGBLOCK=$P(RECORD12,"^",12)
I VERSION_SIGBLOCK="" Q 1
Q ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X1,X12) ;Build String of critical fields
Q $P(X,"^")_"^"_$P(X1,"^",15)_"^"_$P(X,"^",3)_"^"_$P(X,"^",7)_"^"_$P(X,"^",9)_"^"_$P(X1,"^",1)_"^"_$P(X,"^",11)_"^"_$P(X,"^",13)_"^"_$P(X12,"^",3)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCHES12 2445 printed Dec 13, 2024@02:07:18 Page 2
PRCHES12 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;9/23/94 10:49 AM
V ;;5.1;IFCAP;;Oct 20, 2000
+1 ;Per VHA Directive 10-93-142, this routine should not be modified.
+2 ;ROUTINE FOR MAINTAINING FIELD 16.5 (ELECTRONIC SIGNATURE), FILE 443.6
DECODE(LEVEL0) ;Extrinsic Function to return hashed esig to readable form.
+1 ;returns "" if unsuccessful
+2 NEW RECORD,RECORD1,RECORD12,VERSION,PERSON,SIG,CHECKSUM
+3 SET RECORD=$GET(^PRC(443.6,LEVEL0,0))
IF RECORD=""
QUIT ""
+4 SET RECORD1=$GET(^PRC(443.6,LEVEL0,1))
+5 SET RECORD12=$GET(^PRC(443.6,LEVEL0,12))
+6 SET VERSION=$PIECE(RECORD12,"^",11)
+7 SET PERSON=+$PIECE(RECORD1,"^",10)
+8 IF VERSION'=""
IF VERSION'=1
QUIT ""
+9 SET SIG=$PIECE(RECORD12,"^",2)
D1 ;decode e signature for version 1
+1 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD12))
+2 QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode esig for version 1 only
+1 ;-4 cannot encode record
SET Y=-4
QUIT
+2 ;
RECODE(LEVEL0,CHECKSUM,Y) ;Recode esig for version 1 only
+1 NEW RECORD,RECORD1,RECORD12,SIGBLOCK,USERNUM
+2 SET RECORD=$GET(^PRC(443.6,LEVEL0,0))
+3 SET RECORD1=$GET(^PRC(443.6,LEVEL0,1))
+4 SET RECORD12=$GET(^PRC(443.6,LEVEL0,12))
+5 ;-1 no record
IF RECORD=""
SET Y=-1
QUIT
+6 SET USERNUM=+$PIECE(RECORD1,"^",10)
+7 ;-4 cannot recode record
IF $PIECE(RECORD12,"^",2)=""!(USERNUM=0)!'CHECKSUM
SET Y=-4
QUIT
+8 ;S SIGBLOCK=$$DECODE^PRCUESIG($P(RECORD12,"^",2),USERNUM,CHECKSUM)
+9 SET SIGBLOCK=$PIECE($GET(^VA(200,USERNUM,20)),"^",2)
+10 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD12))
+11 SET $PIECE(RECORD12,"^",2)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+12 SET $PIECE(RECORD12,"^",11,12)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
+13 SET ^PRC(443.6,LEVEL0,12)=RECORD12
+14 SET Y=1
QUIT
REMOVE(LEVEL0) ;Entry point to remove esig from record
+1 NEW I,RECORD1,RECORD12
+2 SET RECORD1=$GET(^PRC(443.6,LEVEL0,1))
+3 SET RECORD12=$GET(^PRC(443.6,LEVEL0,12))
+4 FOR I=2,3,12
SET $PIECE(RECORD12,"^",I)=""
+5 SET ^PRC(443.6,LEVEL0,1)=RECORD1
+6 SET ^PRC(443.6,LEVEL0,12)=RECORD12
+7 QUIT
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
+1 NEW RECORD,RECORD1,RECORD12,VERSION,SIGBLOCK
+2 SET RECORD12=$GET(^PRC(443.6,LEVEL0,12))
+3 SET VERSION=$PIECE(RECORD12,"^",11)
SET SIGBLOCK=$PIECE(RECORD12,"^",12)
+4 IF VERSION_SIGBLOCK=""
QUIT 1
+5 QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X1,X12) ;Build String of critical fields
+1 QUIT $PIECE(X,"^")_"^"_$PIECE(X1,"^",15)_"^"_$PIECE(X,"^",3)_"^"_$PIECE(X,"^",7)_"^"_$PIECE(X,"^",9)_"^"_$PIECE(X1,"^",1)_"^"_$PIECE(X,"^",11)_"^"_$PIECE(X,"^",13)_"^"_$PIECE(X12,"^",3)