PRCHES5 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;9/23/94 10:47 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 442
DECODE(LEVEL0) ;return esig in readable form
;returns "" if unsuccessful
NEW RECORD,RECORD1,RECORD12,VERSION,PERSON,SIG,CHECKSUM
S RECORD=$G(^PRC(442,LEVEL0,0)) I RECORD="" Q ""
S RECORD1=$G(^PRC(442,LEVEL0,1))
S RECORD12=$G(^PRC(442,LEVEL0,12))
S VERSION=$P(RECORD12,"^",11)
S PERSON=+$P(RECORD1,"^",10)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD12,"^",2)
D1 ;esig for ver 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD12))
Q $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode esig for ver 1 only
NEW RECORD,RECORD1,RECORD12,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 sig block
S RECORD=$G(^PRC(442,LEVEL0,0))
S RECORD1=$G(^PRC(442,LEVEL0,1))
S RECORD12=$G(^PRC(442,LEVEL0,12))
I RECORD="" S Y=-1 Q ;-1 no record
I $P(RECORD12,"^",2)'="" S Y=-4 Q ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD1,"^",10)
I OLDUSER=0 S $P(RECORD1,"^",10)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD12,"^",3)="" $P(RECORD12,"^",3)=$$NOW^PRCUESIG
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(442,LEVEL0,1)=RECORD1
S ^PRC(442,LEVEL0,12)=RECORD12
S Y=1 Q
RECODE(LEVEL0,CHECKSUM,Y) ;Recode esig for ver 1 only
NEW RECORD,RECORD1,RECORD12,SIGBLOCK,USERNUM
S RECORD=$G(^PRC(442,LEVEL0,0))
S RECORD1=$G(^PRC(442,LEVEL0,1))
S RECORD12=$G(^PRC(442,LEVEL0,12))
I RECORD="" S Y=-1 Q ;-1 no record
S USERNUM=+$P(RECORD1,"^",10)
I $P(RECORD12,"^",2)=""!(USERNUM=0) S Y=-4 Q ;can't recode
;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(442,LEVEL0,12)=RECORD12
S Y=1 Q
REMOVE(LEVEL0) ;Entry point to remove esig
NEW I,RECORD1,RECORD12
S RECORD1=$G(^PRC(442,LEVEL0,1))
S RECORD12=$G(^PRC(442,LEVEL0,12))
F I=2,3,12 S $P(RECORD12,"^",I)=""
S ^PRC(442,LEVEL0,1)=RECORD1
S ^PRC(442,LEVEL0,12)=RECORD12
Q
VERIFY(LEVEL0) ;verify ver 1 esig Returns 1 if valid
NEW RECORD,RECORD1,RECORD12,VERSION,SIGBLOCK
S RECORD12=$G(^PRC(442,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[HPRCHES5 3103 printed Nov 22, 2024@17:17:28 Page 2
PRCHES5 ;WISC/RHD/AKS-ESIG MAINTENANCE ROUTINE ;9/23/94 10:47 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 442
DECODE(LEVEL0) ;return esig in readable form
+1 ;returns "" if unsuccessful
+2 NEW RECORD,RECORD1,RECORD12,VERSION,PERSON,SIG,CHECKSUM
+3 SET RECORD=$GET(^PRC(442,LEVEL0,0))
IF RECORD=""
QUIT ""
+4 SET RECORD1=$GET(^PRC(442,LEVEL0,1))
+5 SET RECORD12=$GET(^PRC(442,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 ;esig for ver 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 ver 1 only
+1 NEW RECORD,RECORD1,RECORD12,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 sig block
IF SIGBLOCK=""
SET Y=-2
QUIT
+6 SET RECORD=$GET(^PRC(442,LEVEL0,0))
+7 SET RECORD1=$GET(^PRC(442,LEVEL0,1))
+8 SET RECORD12=$GET(^PRC(442,LEVEL0,12))
+9 ;-1 no record
IF RECORD=""
SET Y=-1
QUIT
+10 ;-4 cannot re-sign record
IF $PIECE(RECORD12,"^",2)'=""
SET Y=-4
QUIT
+11 SET OLDUSER=+$PIECE(RECORD1,"^",10)
+12 IF OLDUSER=0
SET $PIECE(RECORD1,"^",10)=USERNUM
+13 IF OLDUSER>0
SET USERNUM=OLDUSER
+14 if $PIECE(RECORD12,"^",3)=""
SET $PIECE(RECORD12,"^",3)=$$NOW^PRCUESIG
+15 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD12))
+16 SET $PIECE(RECORD12,"^",2)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+17 SET $PIECE(RECORD12,"^",11,12)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
+18 SET ^PRC(442,LEVEL0,1)=RECORD1
+19 SET ^PRC(442,LEVEL0,12)=RECORD12
+20 SET Y=1
QUIT
RECODE(LEVEL0,CHECKSUM,Y) ;Recode esig for ver 1 only
+1 NEW RECORD,RECORD1,RECORD12,SIGBLOCK,USERNUM
+2 SET RECORD=$GET(^PRC(442,LEVEL0,0))
+3 SET RECORD1=$GET(^PRC(442,LEVEL0,1))
+4 SET RECORD12=$GET(^PRC(442,LEVEL0,12))
+5 ;-1 no record
IF RECORD=""
SET Y=-1
QUIT
+6 SET USERNUM=+$PIECE(RECORD1,"^",10)
+7 ;can't recode
IF $PIECE(RECORD12,"^",2)=""!(USERNUM=0)
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(442,LEVEL0,12)=RECORD12
+14 SET Y=1
QUIT
REMOVE(LEVEL0) ;Entry point to remove esig
+1 NEW I,RECORD1,RECORD12
+2 SET RECORD1=$GET(^PRC(442,LEVEL0,1))
+3 SET RECORD12=$GET(^PRC(442,LEVEL0,12))
+4 FOR I=2,3,12
SET $PIECE(RECORD12,"^",I)=""
+5 SET ^PRC(442,LEVEL0,1)=RECORD1
+6 SET ^PRC(442,LEVEL0,12)=RECORD12
+7 QUIT
VERIFY(LEVEL0) ;verify ver 1 esig Returns 1 if valid
+1 NEW RECORD,RECORD1,RECORD12,VERSION,SIGBLOCK
+2 SET RECORD12=$GET(^PRC(442,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)