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

70 lines
3.0 KiB
Mathematica

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)