PRCHES9 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;3/18/93 15:38
V ;;5.1;IFCAP;;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;ROUTINE FOR MAINTAINING FIELD 114 (ISMS CODE SHEET ELEC. SIG), FILE 442
DECODE(LEVEL0) ;return esig to readable form
NEW RECORD,RECORD1,RECORD21,VERSION,PERSON,SIG,CHECKSUM
S RECORD=$G(^PRC(442,LEVEL0,0)) I RECORD="" Q ""
S RECORD21=$G(^PRC(442,LEVEL0,21))
S VERSION=$P(RECORD21,"^",6)
S PERSON=+$P(RECORD21,"^",3)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD21,"^",4)
D1 ;decode esig for version 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD21))
Q $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode esig for version 1 only
NEW RECORD,RECORD21,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,0))
S RECORD21=$G(^PRC(442,LEVEL0,21))
I RECORD="" S Y=-1 Q ;-1 no record
I $P(RECORD21,"^",4)'="" S Y=-4 Q ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD21,"^",3)
I OLDUSER=0 S $P(RECORD21,"^",3)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD21,"^",5)="" $P(RECORD21,"^",5)=$$NOW^PRCUESIG
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD21))
S $P(RECORD21,"^",4)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD21,"^",6,7)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRC(442,LEVEL0,21)=RECORD21
S Y=1 Q
REMOVE(LEVEL0) ;Entry point to remove esig
NEW I,RECORD21
S RECORD21=$G(^PRC(442,LEVEL0,21)) Q:RECORD21=""
F I=3,4,5,7 S $P(RECORD21,"^",I)=""
S ^PRC(442,LEVEL0,21)=RECORD21
Q
VERIFY(LEVEL0) ;verify ver 1 signature. Returns 1 if valid
NEW RECORD,RECORD1,RECORD21,VERSION,SIGBLOCK
S RECORD21=$G(^PRC(442,LEVEL0,21))
S VERSION=$P(RECORD21,"^",6),SIGBLOCK=$P(RECORD21,"^",7)
I VERSION_SIGBLOCK="" Q 1
Q ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X21) ;Build String of critical fields
Q $P(X21,"^",1)_"^"_$P(X21,"^",5)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCHES9 2076 printed Oct 16, 2024@18:08:12 Page 2
PRCHES9 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;3/18/93 15:38
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 114 (ISMS CODE SHEET ELEC. SIG), FILE 442
DECODE(LEVEL0) ;return esig to readable form
+1 NEW RECORD,RECORD1,RECORD21,VERSION,PERSON,SIG,CHECKSUM
+2 SET RECORD=$GET(^PRC(442,LEVEL0,0))
IF RECORD=""
QUIT ""
+3 SET RECORD21=$GET(^PRC(442,LEVEL0,21))
+4 SET VERSION=$PIECE(RECORD21,"^",6)
+5 SET PERSON=+$PIECE(RECORD21,"^",3)
+6 IF VERSION'=""
IF VERSION'=1
QUIT ""
+7 SET SIG=$PIECE(RECORD21,"^",4)
D1 ;decode esig for version 1
+1 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD21))
+2 QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode esig for version 1 only
+1 NEW RECORD,RECORD21,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,0))
+7 SET RECORD21=$GET(^PRC(442,LEVEL0,21))
+8 ;-1 no record
IF RECORD=""
SET Y=-1
QUIT
+9 ;-4 cannot re-sign record
IF $PIECE(RECORD21,"^",4)'=""
SET Y=-4
QUIT
+10 SET OLDUSER=+$PIECE(RECORD21,"^",3)
+11 IF OLDUSER=0
SET $PIECE(RECORD21,"^",3)=USERNUM
+12 IF OLDUSER>0
SET USERNUM=OLDUSER
+13 if $PIECE(RECORD21,"^",5)=""
SET $PIECE(RECORD21,"^",5)=$$NOW^PRCUESIG
+14 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD21))
+15 SET $PIECE(RECORD21,"^",4)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+16 SET $PIECE(RECORD21,"^",6,7)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
+17 SET ^PRC(442,LEVEL0,21)=RECORD21
+18 SET Y=1
QUIT
REMOVE(LEVEL0) ;Entry point to remove esig
+1 NEW I,RECORD21
+2 SET RECORD21=$GET(^PRC(442,LEVEL0,21))
if RECORD21=""
QUIT
+3 FOR I=3,4,5,7
SET $PIECE(RECORD21,"^",I)=""
+4 SET ^PRC(442,LEVEL0,21)=RECORD21
+5 QUIT
VERIFY(LEVEL0) ;verify ver 1 signature. Returns 1 if valid
+1 NEW RECORD,RECORD1,RECORD21,VERSION,SIGBLOCK
+2 SET RECORD21=$GET(^PRC(442,LEVEL0,21))
+3 SET VERSION=$PIECE(RECORD21,"^",6)
SET SIGBLOCK=$PIECE(RECORD21,"^",7)
+4 IF VERSION_SIGBLOCK=""
QUIT 1
+5 QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X21) ;Build String of critical fields
+1 QUIT $PIECE(X21,"^",1)_"^"_$PIECE(X21,"^",5)