Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PSIVINDL

PSIVINDL.m

Go to the documentation of this file.
  1. PSIVINDL ;SLC/SS - PROCESS IV ACTIVITY LOG ENTRIES FOR INDICATION ; Feb 02, 2022
  1. ;;5.0;INPATIENT MEDICATIONS;**399**;16 DEC 97;Build 64
  1. ;
  1. ;
  1. ;For IV orders only:
  1. ;Copy activity log entries for INDICATION (only) changes
  1. ;from NON-VERIFIED in the file (#53.1)
  1. ;to ACTIVE orders in the the file (#55)
  1. ;during verification process
  1. CPINDLOG(PSDFN,PS531,PS55100,PSJREAS) ;
  1. ;PSDFN - patient's DFN
  1. ;PS531 - IEN of the file (#53.1)
  1. ;PS55100 - IEN of IV multiple field (#100) in the file (#55)
  1. ;PSJREAS - reason (optional)
  1. N Z1,Z2,IEN,IEN2,NEWVAL,PSJTMP,NAME,REASON
  1. S PS531=+PS531,PS55100=+PS55100
  1. ;get the current value of INDICATION and use as the latest "TO" value
  1. S NEWVAL=$G(^PS(53.1,PS531,18))
  1. ;loop thru all INDICATION log entries in the file (#53.1) from newest to oldest and store all "TO" and "FROM" values in PSJTMP
  1. S IEN=99999 F S IEN=$O(^PS(53.1,PS531,"A",IEN),-1) Q:+IEN=0 S Z1=$G(^PS(53.1,PS531,"A",IEN,0)) I $P(Z1,U,4)="INDICATION" D
  1. . S NAME=$$GET1^DIQ(200,+$P(Z1,U,2),.01,"E")
  1. . S REASON=$S('$G(PSJREAS):$$GET1^DIQ(53.3,+$P(Z1,U,3),.01,"E"),1:PSJREAS)
  1. . S PSJTMP(IEN)=PSDFN_U_PS55100_U_"E"_U_NAME_U_REASON_U_+$P(Z1,U)_U_"INDICATION"_U_$P(Z1,U,5)_U_NEWVAL_U_+$P(Z1,U,2)
  1. . S NEWVAL=$P(Z1,U,5)
  1. S IEN2=0
  1. F S IEN2=$O(PSJTMP(IEN2)) Q:+IEN2=0 S Z2=PSJTMP(IEN2) D ADDENTRY($P(Z2,U,1),$P(Z2,U,2),$P(Z2,U,3),$P(Z2,U,4),$P(Z2,U,5),$P(Z2,U,6),$P(Z2,U,7),$P(Z2,U,8),$P(Z2,U,9),$P(Z2,U,10))
  1. Q
  1. ;
  1. ;Add one single entry to the subfile (#55.04) and its subentry in (#55.15)
  1. ADDENTRY(PSDFN,PS55100,PSACTTYP,PSUSERNM,PSACTRES,PSACTDAT,PSFIELD,PSFROM,PSTO,PSDUZ) ;
  1. ;PSDFN - patient's DFN
  1. ;PS55100 - IEN of IV multiple field (#100) in the file (#55)
  1. ;PSACTTYP - activity type, see 55.04,.02
  1. ;PSUSERNM - User name (55.04,.03)
  1. ;PSACTRES - REASON FOR ACTIVITY (55.04,.04)
  1. ;PSACTDAT - ACTIVITY DATE (55.04,.05)
  1. ;PSDUZ - user DUZ (55.04,.06)
  1. ;PSFIELD - the field that was edited/changed
  1. ;PSFROM - old value
  1. ;PSTO - new value
  1. S PS55100=+PS55100
  1. N PS0NODE,PSMAXN,NEWIEN,PSJTMP,NEWIEN2
  1. ;get the max number used by 55.04,.01 ACTIVITY LOG
  1. S PSMAXN=$$GETMAXN(PSDFN,PS55100)
  1. ;in the subfile 55.01,40 ACTIVITY LOG of the file (#55)
  1. ;create an 55.04 entry with PSMAXN+1 as ACTIVITY LOG value and populate fields: (#.02) TYPE OF ACTIVITY, (#.03) ENTRY CODE,
  1. ;(#.04) REASON FOR ACTIVITY, (#.05) ACTIVITY DATE, (#.06) USER
  1. S NEWIEN=$$ADD5504(PS55100,PSDFN,PSMAXN+1,PSACTTYP,PSUSERNM,PSACTRES,PSACTDAT,PSDUZ)
  1. ;in the subfile 55.04,1 FIELD CHANGED of the file (#55)
  1. ;create an entry and populate fields: (#.01) FIELD CHANGED,(#1) FROM,(#2) TO
  1. I $$ADD5515(NEWIEN,PS55100,PSDFN,PSFIELD,PSFROM,PSTO)
  1. Q
  1. ;
  1. ;in the subfile 55.04,1 FIELD CHANGED of the file (#55)
  1. ;create an entry with PSFLCHNG as (#.01) value and populate fields: (#.01) FIELD CHANGED,(#1) FROM,(#2) TO
  1. ADD5504(PS55100,PSDFN,PSMAXN,PSACTTYP,PSUSERNM,PSACTRES,PSACTDAT,PSDUZ) ;
  1. N PSJTMP,NEWIEN,IENS
  1. S NEWIEN=$$INSITEM(55.04,PS55100_","_PSDFN,PSMAXN,"")
  1. ;populate other fiedls
  1. S IENS=""_NEWIEN_","_PS55100_","_PSDFN_","_""
  1. S PSJTMP(55.04,IENS,.02)=PSACTTYP
  1. S PSJTMP(55.04,IENS,.03)=PSUSERNM
  1. S PSJTMP(55.04,IENS,.04)=PSACTRES
  1. S PSJTMP(55.04,IENS,.05)=PSACTDAT
  1. S PSJTMP(55.04,IENS,.06)=PSDUZ
  1. D FILE^DIE("","PSJTMP")
  1. Q NEWIEN
  1. ;
  1. ;in the subfile 55.04,1 FIELD CHANGED of the file (#55)
  1. ;create an entry with PSFLCHNG as (#.01) value and populate fields: (#.01) FIELD CHANGED,(#1) FROM,(#2) TO
  1. ADD5515(IEN5515,PS55100,PSDFN,PSFLCHNG,PSFROM,PSTO) ;
  1. N NEWIEN,PSJTMP,IENS
  1. S NEWIEN=$$INSITEM(55.15,IEN5515_","_PS55100_","_PSDFN,PSFLCHNG,"")
  1. ;populate other fiedls
  1. S IENS=""_NEWIEN_","_IEN5515_","_PS55100_","_PSDFN_","_""
  1. S PSJTMP(55.15,IENS,1)=PSFROM
  1. S PSJTMP(55.15,IENS,2)=PSTO
  1. D FILE^DIE("","PSJTMP")
  1. Q NEWIEN
  1. ;
  1. ; get max number for 55.04,.01
  1. GETMAXN(DFN,IEN100) ;
  1. N Z1,NUM,IEN55151 S NUM=0,IEN55151=0
  1. F S IEN55151=$O(^PS(55,DFN,"IV",IEN100,"A",IEN55151)) Q:+IEN55151=0 S Z1=+^PS(55,DFN,"IV",IEN100,"A",IEN55151,0) I Z1>NUM S NUM=Z1
  1. Q NUM
  1. ;
  1. ;generic API to insert an entry to the file or subfile
  1. INSITEM(PSFILE,PSIEN,PSVAL01,NEWRECNO,PSFLGS,LCKGL,LCKTIME,PSNEWREC) ;
  1. ;PSFILE - file or subfile number
  1. ;PSIEN - ien of the parent file entry in which the new subfile entry will be inserted
  1. ; = "" - if insert to the top-level
  1. ; = IEN0 - when you insert to the "child" level - i.e. 1st level after top-level
  1. ; IEN0 is the top-leveltop-level IEN
  1. ; = "IEN1,IEN0" - when you insert to the "grandchild" level - i.e. 2nd level after top-level
  1. ; IEN0 is the top-leveltop-level IEN
  1. ; IEN1 is the 1st level IEN
  1. ; = "IEN2,IEN1,IEN0" - when you insert to the 3rd level after top-level
  1. ; IEN0 is the top-leveltop-level IEN
  1. ; IEN1 is the 1st level IEN
  1. ; IEN2 is the 2nd level IEN
  1. ;PSVAL01 - .01 value for the new entry
  1. ;NEWRECNO -(optional) specify IEN if you want specific value
  1. ; Note: "" then the system will assign the entry number itself.
  1. ;PSFLGS - FLAGS parameter for UPDATE^DIE
  1. ;LCKGL - fully specified global reference to lock
  1. ;LCKTIME - time out for LOCK, if LOCKTIME=0 then the function will not lock the file
  1. ;PSNEWREC - optional, flag = if 1 then allow to create a new top level record
  1. ;
  1. ;returns IEN of the new entry
  1. ;Examples:
  1. ; W $$INSITEM(55.04,PS55100_","_PSDFN,PSMAXN,"") - 2nd level
  1. ; W $$INSITEM(55.15,IEN5515_","_PS55100_","_PSDFN,PSFLCHNG,"") - 3rd level
  1. I ('$G(PSFILE)) Q "0^Invalid parameter"
  1. I +$G(PSNEWREC)=0 I $G(NEWRECNO)>0,'$G(PSIEN) Q "0^Invalid parameter"
  1. I $G(PSVAL01)="" Q "0^Null"
  1. N PSLOCK S PSLOCK=0
  1. N PSSSI,PSIENS,PSFDA,PSERR
  1. I '$G(NEWRECNO) N NEWRECNO S NEWRECNO=$G(NEWRECNO)
  1. I PSIEN'="" S PSIENS="+1,"_PSIEN_"," I $L(NEWRECNO)>0 S PSSSI(1)=+NEWRECNO
  1. I PSIEN="" S PSIENS="+1," I $L(NEWRECNO)>0 S PSSSI(1)=+NEWRECNO
  1. S PSFDA(PSFILE,PSIENS,.01)=PSVAL01
  1. I $L($G(LCKGL)) L +@LCKGL:(+$G(LCKTIME)) S PSLOCK=$T I 'PSLOCK Q -2 ;lock failure
  1. D UPDATE^DIE($G(PSFLGS),"PSFDA","PSSSI","PSERR")
  1. I PSLOCK L -@LCKGL
  1. I $D(PSERR) D BMES^XPDUTL($G(PSERR("DIERR",1,"TEXT",1),"Update Error")) Q -1 ;D BMES^XPDUTL(PSERR("DIERR",1,"TEXT",1))
  1. Q +$G(PSSSI(1))
  1. ;
  1. ;PSIVINDL