VistA-WorldVistAEHR/r/IFCAP-PRC-PRX--PRCA--PRCN/PRCHES8.m

49 lines
1.9 KiB
Mathematica

PRCHES8 ;WISC/RHD/AKS-ESIG MAINT ;3/18/93 15:38
V ;;5.1;IFCAP;;Oct 20, 2000
;Per VHA Directive 10-93-142, this routine should not be modified.
;ROUTINE FOR MAINTAINING FIELD 105 (LOG CODE SHEET ELEC. SIG), FILE 442
DECODE(LEVEL0) ;return esig to readable form
NEW RECORD,RECORD1,RECORD18,VERSION,PERSON,SIG,CHECKSUM
S RECORD=$G(^PRC(442,LEVEL0,0)) I RECORD="" Q ""
S RECORD18=$G(^PRC(442,LEVEL0,18))
S VERSION=$P(RECORD18,"^",15)
S PERSON=+$P(RECORD18,"^",5)
I VERSION'="",VERSION'=1 Q ""
S SIG=$P(RECORD18,"^",6)
D1 ;decode e signature for version 1
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD18))
Q $$DECODE^PRCUESIG(SIG,PERSON,CHECKSUM)
ENCODE(LEVEL0,USERNUM,Y) ;Encode esig for ver 1 only
NEW RECORD,RECORD18,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 signature block
S RECORD=$G(^PRC(442,LEVEL0,0))
S RECORD18=$G(^PRC(442,LEVEL0,18))
I RECORD="" S Y=-1 Q ;-1 no record
I $P(RECORD18,"^",6)'="" S Y=-4 Q ;-4 cannot re-sign record
S OLDUSER=+$P(RECORD18,"^",5)
I OLDUSER=0 S $P(RECORD18,"^",5)=USERNUM
I OLDUSER>0 S USERNUM=OLDUSER
S:$P(RECORD18,"^",7)="" $P(RECORD18,"^",7)=$$NOW^PRCUESIG
S CHECKSUM=$$SUM^PRCUESIG(LEVEL0_"^"_$$STRING(RECORD18))
S $P(RECORD18,"^",6)=$$ENCODE^PRCUESIG(SIGBLOCK,USERNUM,CHECKSUM)
S $P(RECORD18,"^",15,16)="1^"_$$SUM^PRCUESIG(SIGBLOCK)
S ^PRC(442,LEVEL0,18)=RECORD18
S Y=1 Q
REMOVE(LEVEL0) ;Entry point to remove esig
NEW I,RECORD18
S RECORD18=$G(^PRC(442,LEVEL0,18)) Q:RECORD18=""
F I=5,6,7,16 S $P(RECORD18,"^",I)=""
S ^PRC(442,LEVEL0,18)=RECORD18
Q
VERIFY(LEVEL0) ;verify ver 1 sig Returns 1 if valid
NEW RECORD18,VERSION,SIGBLOCK
S RECORD18=$G(^PRC(442,LEVEL0,18))
S VERSION=$P(RECORD18,"^",15),SIGBLOCK=$P(RECORD18,"^",16)
I VERSION_SIGBLOCK="" Q 1
Q ($$SUM^PRCUESIG($$DECODE(LEVEL0))=SIGBLOCK)
STRING(X18) ;Build String of critical fields
Q $P(X18,"^",7)