VistA-FOIAVistA/r/IFCAP-PRC-PRX--PRCA--PRCN/PRCSC1.m

99 lines
4.2 KiB
Mathematica

PRCSC1 ;WISC/LEM-ESIG MAINTENANCE ROUTINE ;4/23/97 8:55 AM
V ;;5.1;IFCAP;;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;ROUTINE FOR MAINTAINING FIELD 44.5 (ELECTRONIC SIGNATURE), FILE 410
DECODE(LEVEL0) ;Extrinsic Function to return hashed electronic sig to readable form.
;returns "" if unsuccessful
NEW RECORD7,RECORD71,VERSION,PERSON,SIG,CHECKSUM
;get record and check version
S RECORD7=$G(^PRCS(410,LEVEL0,7)) I RECORD7="" QUIT ""
S RECORD71=$G(^PRCS(410,LEVEL0,7.1))
S VERSION=$P(RECORD71,"^",3)
S PERSON=+$P(RECORD7,"^",3)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD7,"^",6)
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 RECORD=$G(^PRCS(410,LEVEL0,0))
S RECORD1=$G(^PRCS(410,LEVEL0,1))
S RECORD2=$G(^PRCS(410,LEVEL0,2))
S RECORD3=$G(^PRCS(410,LEVEL0,3))
S RECORD4=$G(^PRCS(410,LEVEL0,4))
S RECORD10=$G(^PRCS(410,LEVEL0,10))
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD2,RECORD3,RECORD4,RECORD7,RECORD10))
QUIT $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode e signature for version 1 only
;Parameter passing entry point
NEW RECORD,RECORD7,RECORD71,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(^PRCS(410,LEVEL0,0))
S RECORD1=$G(^PRCS(410,LEVEL0,1))
S RECORD2=$G(^PRCS(410,LEVEL0,2))
S RECORD3=$G(^PRCS(410,LEVEL0,3))
S RECORD4=$G(^PRCS(410,LEVEL0,4))
S RECORD7=$G(^PRCS(410,LEVEL0,7))
S RECORD71=$G(^PRCS(410,LEVEL0,7.1))
S RECORD10=$G(^PRCS(410,LEVEL0,10))
I RECORD="" S Y=-1 QUIT ;-1 no transaction record
I $P(RECORD7,"^",6)'="" S Y=-4 QUIT ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD7,"^",3)
I OLDUSER=0 S $P(RECORD7,"^",3)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD7,"^",7)="" $P(RECORD7,"^",7)=$$NOW^PRCUESIG
S:$P(RECORD7,"^",5)="" $P(RECORD7,"^",5)=$P($$NOW^PRCUESIG,".",1)
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD2,RECORD3,RECORD4,RECORD7,RECORD10))
S $P(RECORD7,"^",6)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD7,"^",4)=$P($G(^VA(200,USERNUM,20)),"^",3)
S $P(RECORD71,"^",3,4)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRCS(410,LEVEL0,7)=RECORD7
S ^PRCS(410,LEVEL0,7.1)=RECORD71
S Y=1 QUIT
RECODE(LEVEL0,Y) ;Recode esig for version 1 only
NEW RECORD,RECORD7,RECORD71,SIGBLOCK,CHECKSUM
NEW DA,DIC,RECORD1,RECORD10,RECORD2,RECORD3,RECORD4,USERNUM
S RECORD=$G(^PRCS(410,LEVEL0,0))
S RECORD1=$G(^PRCS(410,LEVEL0,1))
S RECORD2=$G(^PRCS(410,LEVEL0,2))
S RECORD3=$G(^PRCS(410,LEVEL0,3))
S RECORD4=$G(^PRCS(410,LEVEL0,4))
S RECORD7=$G(^PRCS(410,LEVEL0,7))
S RECORD71=$G(^PRCS(410,LEVEL0,7.1))
S RECORD10=$G(^PRCS(410,LEVEL0,10))
I RECORD="" S Y=-1 QUIT ;-1 no transaction record
S USERNUM=+$P(RECORD7,"^",3)
I $P(RECORD7,"^",6)=""!(USERNUM=0) S Y=-4 QUIT ;-4 cannot re-sign record
S SIGBLOCK=$P($G(^VA(200,USERNUM,20)),"^",2)
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD,RECORD1,RECORD2,RECORD3,RECORD4,RECORD7,RECORD10))
S $P(RECORD7,"^",6)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD7,"^",4)=$P($G(^VA(200,USERNUM,20)),"^",3)
S $P(RECORD71,"^",3,4)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRCS(410,LEVEL0,7)=RECORD7
S ^PRCS(410,LEVEL0,7.1)=RECORD71
S Y=1 QUIT
REMOVE(LEVEL0) ;Entry point to remove e signature from record
;NOT an extrinsic function
NEW RECORD7,RECORD71
S RECORD7=$G(^PRCS(410,LEVEL0,7))
S RECORD71=$G(^PRCS(410,LEVEL0,7.1))
S $P(RECORD7,"^",3,7)="^^^^"
S $P(RECORD71,"^",4)=""
S ^PRCS(410,LEVEL0,7)=RECORD7
S ^PRCS(410,LEVEL0,7.1)=RECORD71
QUIT
VERIFY(LEVEL0) ;extrinsic function to verify version 1 signature. Returns 1 if valid, 0 if not valid
NEW RECORD71,VERSION,SIGBLOCK
;get record variables
S RECORD71=$G(^PRCS(410,LEVEL0,7.1))
S VERSION=$P(RECORD71,"^",3),SIGBLOCK=$P(RECORD71,"^",4)
I VERSION_SIGBLOCK="" QUIT 1
QUIT ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X,X1,X2,X3,X4,X7,X10) ;Build String of critical fields
Q $P(X,"^",1)_"^"_$P(X1,"^",1)_"^"_$P(X2,"^",1)_"^"_$P(X3,"^",1)_"^"_$P(X3,"^",3)_"^"_$P(X4,"^",1)_"^"_$P(X7,"^",7)_"^"_$P(X10,"^",1)