PRCBES1 ;WISC@ALTOONA/CTB-ESIG MAINTENANCE ROUTINE ;1/15/95 12:28
V ;;5.1;IFCAP;;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;ROUTINE FOR MAINTAINING FIELD 12.5 (ELECTRONIC SIGNATURE), FILE 421
DECODE(LEVEL0) ;Extrinsic Function to return hashed electronic sig to readable form.
;returns "" if unsuccessful
NEW RECORD,RECORD4,VERSION,PERSON,SIG,CHECKSUM
;get record and check version
S RECORD=$G(^PRCF(421,LEVEL0,0)) I RECORD="" QUIT ""
S RECORD4=$G(^PRCF(421,LEVEL0,4))
S VERSION=$P(RECORD4,"^",11)
S PERSON=+$P(RECORD,"^",11)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD,"^",17)
I VERSION=1 G D1
D ;decode e signature less than version 1
S X=$$DECODE^PRCUESIG(SIG,LEVEL0,PERSON)
QUIT X
D1 ;decode e signature for version 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD4))
QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode e signature for version 1 only
;Parameter passing entry point
NEW RECORD,RECORD4,SIGBLOCK,CHECKSUM,OLDUSER
;get record
S USERNUM=+USERNUM
I USERNUM=0 S Y=-3 QUIT ;-3 no user num available
S SIGBLOCK=$P($G(^VA(200,USERNUM,20)),"^",2)
I SIGBLOCK="" S Y=-2 QUIT ;-2 no sigblock in file 200
S RECORD=$G(^PRCF(421,LEVEL0,0))
S RECORD4=$G(^PRCF(421,LEVEL0,4))
I RECORD="" S Y=-1 QUIT ;-1 no 2237 record
I $P(RECORD,"^",17)'="" S Y=-4 QUIT ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD,"^",11)
I OLDUSER=0 S $P(RECORD,"^",11)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD4,"^",13)="" $P(RECORD4,"^",13)=$$NOW^PRCUESIG
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD4))
S $P(RECORD,"^",17)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD4,"^",11,12)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRCF(421,LEVEL0,0)=RECORD
S ^PRCF(421,LEVEL0,4)=RECORD4
S Y=1 QUIT
REMOVE(LEVEL0) ;Entry point to remove e signature from record
;NOT an extrinsic function
NEW I,RECORD,RECORD4
S RECORD4=$G(^PRCF(421,LEVEL0,4))
S RECORD=$G(^PRCF(421,LEVEL0,0))
F I=11,17 S $P(RECORD,"^",I)=""
S $P(RECORD4,"^",12,13)="^"
S ^PRCF(421,LEVEL0,1)=RECORD1
S ^PRCF(421,LEVEL0,4)=RECORD4
QUIT
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
NEW RECORD,RECORD4,VERSION,SIGBLOCK
;get record variables
S RECORD=$G(^PRCF(421,LEVEL0,0))
S RECORD4=$G(^PRCF(421,LEVEL0,4))
S VERSION=$P(RECORD4,"^",11),SIGBLOCK=$P(RECORD4,"^",12)
I VERSION_SIGBLOCK="" QUIT 1
QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X4) ;Build String of critical fields
Q $P(X,"^",1,2)_"^"_$P(X,"^",4,10)_$P(X,"^",18)_"^"_$P(X4,"^",13)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCBES1 2682 printed Dec 13, 2024@02:00:40 Page 2
PRCBES1 ;WISC@ALTOONA/CTB-ESIG MAINTENANCE ROUTINE ;1/15/95 12:28
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 12.5 (ELECTRONIC SIGNATURE), FILE 421
DECODE(LEVEL0) ;Extrinsic Function to return hashed electronic sig to readable form.
+1 ;returns "" if unsuccessful
+2 NEW RECORD,RECORD4,VERSION,PERSON,SIG,CHECKSUM
+3 ;get record and check version
+4 SET RECORD=$GET(^PRCF(421,LEVEL0,0))
IF RECORD=""
QUIT ""
+5 SET RECORD4=$GET(^PRCF(421,LEVEL0,4))
+6 SET VERSION=$PIECE(RECORD4,"^",11)
+7 SET PERSON=+$PIECE(RECORD,"^",11)
+8 IF VERSION'=""
IF VERSION'=1
QUIT ""
+9 SET SIG=$PIECE(RECORD,"^",17)
+10 IF VERSION=1
GOTO D1
D ;decode e signature less than version 1
+1 SET X=$$DECODE^PRCUESIG(SIG,LEVEL0,PERSON)
+2 QUIT X
D1 ;decode e signature for version 1
+1 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD4))
+2 QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode e signature for version 1 only
+1 ;Parameter passing entry point
+2 NEW RECORD,RECORD4,SIGBLOCK,CHECKSUM,OLDUSER
+3 ;get record
+4 SET USERNUM=+USERNUM
+5 ;-3 no user num available
IF USERNUM=0
SET Y=-3
QUIT
+6 SET SIGBLOCK=$PIECE($GET(^VA(200,USERNUM,20)),"^",2)
+7 ;-2 no sigblock in file 200
IF SIGBLOCK=""
SET Y=-2
QUIT
+8 SET RECORD=$GET(^PRCF(421,LEVEL0,0))
+9 SET RECORD4=$GET(^PRCF(421,LEVEL0,4))
+10 ;-1 no 2237 record
IF RECORD=""
SET Y=-1
QUIT
+11 ;-4 cannot re-sign record
IF $PIECE(RECORD,"^",17)'=""
SET Y=-4
QUIT
+12 SET OLDUSER=+$PIECE(RECORD,"^",11)
+13 IF OLDUSER=0
SET $PIECE(RECORD,"^",11)=USERNUM
+14 IF OLDUSER>0
SET USERNUM=OLDUSER
+15 if $PIECE(RECORD4,"^",13)=""
SET $PIECE(RECORD4,"^",13)=$$NOW^PRCUESIG
+16 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD4))
+17 SET $PIECE(RECORD,"^",17)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+18 SET $PIECE(RECORD4,"^",11,12)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
+19 SET ^PRCF(421,LEVEL0,0)=RECORD
+20 SET ^PRCF(421,LEVEL0,4)=RECORD4
+21 SET Y=1
QUIT
REMOVE(LEVEL0) ;Entry point to remove e signature from record
+1 ;NOT an extrinsic function
+2 NEW I,RECORD,RECORD4
+3 SET RECORD4=$GET(^PRCF(421,LEVEL0,4))
+4 SET RECORD=$GET(^PRCF(421,LEVEL0,0))
+5 FOR I=11,17
SET $PIECE(RECORD,"^",I)=""
+6 SET $PIECE(RECORD4,"^",12,13)="^"
+7 SET ^PRCF(421,LEVEL0,1)=RECORD1
+8 SET ^PRCF(421,LEVEL0,4)=RECORD4
+9 QUIT
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
+1 NEW RECORD,RECORD4,VERSION,SIGBLOCK
+2 ;get record variables
+3 SET RECORD=$GET(^PRCF(421,LEVEL0,0))
+4 SET RECORD4=$GET(^PRCF(421,LEVEL0,4))
+5 SET VERSION=$PIECE(RECORD4,"^",11)
SET SIGBLOCK=$PIECE(RECORD4,"^",12)
+6 IF VERSION_SIGBLOCK=""
QUIT 1
+7 QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X4) ;Build String of critical fields
+1 QUIT $PIECE(X,"^",1,2)_"^"_$PIECE(X,"^",4,10)_$PIECE(X,"^",18)_"^"_$PIECE(X4,"^",13)