PRCFDES1 ;WISC/LEM-ESIG MAINTENANCE ROUTINE ;1/5/11 16:28
V ;;5.1;IFCAP;**154**;Oct 20, 2000;Build 5
;Per VHA Directive 2004-038, this routine should not be modified.
;ROUTINE FOR MAINTAINING FIELD 61 (CERTIFIED BY ELEC SIG), FILE 421.5
DECODE(LEVEL0) ;Extrinsic Function to return hashed electronic sig to readable form.
;returns "" if unsuccessful
NEW RECORD2,RECORD21,VERSION,PERSON,SIG,CHECKSUM
;get record and check version
S RECORD2=$G(^PRCF(421.5,LEVEL0,2)) I RECORD2="" QUIT ""
S RECORD21=$G(^PRCF(421.5,LEVEL0,2.1))
S VERSION=$P(RECORD21,"^",1)
S PERSON=+$P(RECORD2,"^",10)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD2,"^",12)
D1 ;decode e signature for version 1
S RECORD=$G(^PRCF(421.5,LEVEL0,0))
S RECORD1=$G(^PRCF(421.5,LEVEL0,1))
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1))
QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode e signature for version 1 only
;Parameter passing entry point
NEW SIGBLOCK,CHECKSUM,OLDUSER
NEW RECORD,RECORD1,RECORD2,RECORD21
;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.5,LEVEL0,0))
S RECORD1=$G(^PRCF(421.5,LEVEL0,1))
S RECORD2=$G(^PRCF(421.5,LEVEL0,2))
S RECORD21=$G(^PRCF(421.5,LEVEL0,2.1))
I RECORD="" S Y=-1 QUIT ;-1 no transaction record
I $P(RECORD2,"^",12)'="" S Y=-4 QUIT ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD2,"^",10)
I OLDUSER=0 S $P(RECORD2,"^",10)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD21,"^",5)="" $P(RECORD21,"^",5)=$$NOW^PRCUESIG
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1))
S $P(RECORD2,"^",12)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD21,"^",1,2)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRCF(421.5,LEVEL0,2)=RECORD2
S ^PRCF(421.5,LEVEL0,2.1)=RECORD21
N PRCDATE S PRCDATE=$P(RECORD21,U,5) I PRCDATE'="",LEVEL0>0 S ^PRCF(421.5,"AF",PRCDATE,LEVEL0)=""
S Y=1 QUIT
REMOVE(LEVEL0) ;Entry point to remove e signature from record
;NOT an extrinsic function
NEW RECORD2,RECORD21,I
S RECORD2=$G(^PRCF(421.5,LEVEL0,2))
S RECORD21=$G(^PRCF(421.5,LEVEL0,2.1))
F I=10,12 S $P(RECORD2,"^",I)=""
N PRCDATE S PRCDATE=$P(RECORD21,U,5) I PRCDATE'="",LEVEL0>0 K ^PRCF(421.5,"AF",PRCDATE,LEVEL0)
F I=2,5 S $P(RECORD21,"^",I)=""
S ^PRCF(421.5,LEVEL0,2)=RECORD2
S ^PRCF(421.5,LEVEL0,2.1)=RECORD21
QUIT
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
NEW RECORD21,VERSION,SIGBLOCK
;get record variables
S RECORD21=$G(^PRCF(421.5,LEVEL0,2.1))
S VERSION=$P(RECORD21,"^",1),SIGBLOCK=$P(RECORD21,"^",2)
I VERSION_SIGBLOCK="" QUIT 1
QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X1) ;Build String of critical fields
NEW RECORD,RECORD1
Q $P(X,"^",1)_"^"_$P(X,"^",3)_"^"_$P(X,"^",4)_"^"_$P(X,"^",8)_"^"_$P(X,"^",15)_"^"_$P(X1,"^",3)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPRCFDES1 3021 printed Nov 22, 2024@17:13:06 Page 2
PRCFDES1 ;WISC/LEM-ESIG MAINTENANCE ROUTINE ;1/5/11 16:28
V ;;5.1;IFCAP;**154**;Oct 20, 2000;Build 5
+1 ;Per VHA Directive 2004-038, this routine should not be modified.
+2 ;ROUTINE FOR MAINTAINING FIELD 61 (CERTIFIED BY ELEC SIG), FILE 421.5
DECODE(LEVEL0) ;Extrinsic Function to return hashed electronic sig to readable form.
+1 ;returns "" if unsuccessful
+2 NEW RECORD2,RECORD21,VERSION,PERSON,SIG,CHECKSUM
+3 ;get record and check version
+4 SET RECORD2=$GET(^PRCF(421.5,LEVEL0,2))
IF RECORD2=""
QUIT ""
+5 SET RECORD21=$GET(^PRCF(421.5,LEVEL0,2.1))
+6 SET VERSION=$PIECE(RECORD21,"^",1)
+7 SET PERSON=+$PIECE(RECORD2,"^",10)
+8 IF VERSION'=""
IF VERSION'=1
QUIT ""
+9 SET SIG=$PIECE(RECORD2,"^",12)
D1 ;decode e signature for version 1
+1 SET RECORD=$GET(^PRCF(421.5,LEVEL0,0))
+2 SET RECORD1=$GET(^PRCF(421.5,LEVEL0,1))
+3 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1))
+4 QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode e signature for version 1 only
+1 ;Parameter passing entry point
+2 NEW SIGBLOCK,CHECKSUM,OLDUSER
+3 NEW RECORD,RECORD1,RECORD2,RECORD21
+4 ;get record
+5 SET USERNUM=+USERNUM
+6 ;-3 no user num available
IF USERNUM=0
SET Y=-3
QUIT
+7 SET SIGBLOCK=$PIECE($GET(^VA(200,USERNUM,20)),"^",2)
+8 ;-2 no sigblock in file 200
IF SIGBLOCK=""
SET Y=-2
QUIT
+9 SET RECORD=$GET(^PRCF(421.5,LEVEL0,0))
+10 SET RECORD1=$GET(^PRCF(421.5,LEVEL0,1))
+11 SET RECORD2=$GET(^PRCF(421.5,LEVEL0,2))
+12 SET RECORD21=$GET(^PRCF(421.5,LEVEL0,2.1))
+13 ;-1 no transaction record
IF RECORD=""
SET Y=-1
QUIT
+14 ;-4 cannot re-sign record
IF $PIECE(RECORD2,"^",12)'=""
SET Y=-4
QUIT
+15 SET OLDUSER=+$PIECE(RECORD2,"^",10)
+16 IF OLDUSER=0
SET $PIECE(RECORD2,"^",10)=USERNUM
+17 IF OLDUSER>0
SET USERNUM=OLDUSER
+18 if $PIECE(RECORD21,"^",5)=""
SET $PIECE(RECORD21,"^",5)=$$NOW^PRCUESIG
+19 SET CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1))
+20 SET $PIECE(RECORD2,"^",12)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
+21 SET $PIECE(RECORD21,"^",1,2)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
+22 SET ^PRCF(421.5,LEVEL0,2)=RECORD2
+23 SET ^PRCF(421.5,LEVEL0,2.1)=RECORD21
+24 NEW PRCDATE
SET PRCDATE=$PIECE(RECORD21,U,5)
IF PRCDATE'=""
IF LEVEL0>0
SET ^PRCF(421.5,"AF",PRCDATE,LEVEL0)=""
+25 SET Y=1
QUIT
REMOVE(LEVEL0) ;Entry point to remove e signature from record
+1 ;NOT an extrinsic function
+2 NEW RECORD2,RECORD21,I
+3 SET RECORD2=$GET(^PRCF(421.5,LEVEL0,2))
+4 SET RECORD21=$GET(^PRCF(421.5,LEVEL0,2.1))
+5 FOR I=10,12
SET $PIECE(RECORD2,"^",I)=""
+6 NEW PRCDATE
SET PRCDATE=$PIECE(RECORD21,U,5)
IF PRCDATE'=""
IF LEVEL0>0
KILL ^PRCF(421.5,"AF",PRCDATE,LEVEL0)
+7 FOR I=2,5
SET $PIECE(RECORD21,"^",I)=""
+8 SET ^PRCF(421.5,LEVEL0,2)=RECORD2
+9 SET ^PRCF(421.5,LEVEL0,2.1)=RECORD21
+10 QUIT
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
+1 NEW RECORD21,VERSION,SIGBLOCK
+2 ;get record variables
+3 SET RECORD21=$GET(^PRCF(421.5,LEVEL0,2.1))
+4 SET VERSION=$PIECE(RECORD21,"^",1)
SET SIGBLOCK=$PIECE(RECORD21,"^",2)
+5 IF VERSION_SIGBLOCK=""
QUIT 1
+6 QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X1) ;Build String of critical fields
+1 NEW RECORD,RECORD1
+2 QUIT $PIECE(X,"^",1)_"^"_$PIECE(X,"^",3)_"^"_$PIECE(X,"^",4)_"^"_$PIECE(X,"^",8)_"^"_$PIECE(X,"^",15)_"^"_$PIECE(X1,"^",3)