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

PSBOMH.m

Go to the documentation of this file.
PSBOMH ;BIRMINGHAM/EFC-MAH ;03/06/16 3:06pm
 ;;3.0;BAR CODE MED ADMIN;**5,9,38,57,67,68,70,76,83,116**;Mar 2004;Build 2
 ;Per VHA Directive 2004-038, this routine should not be modified.
 ;
 ; Reference/IA
 ; EN^PSJBCMA/2828
 ; EN^PSJBCMA2/2830
 ; File 200/10060
 ; ^DIWP/10011
 ;
 ;*68 - remove old special instruction text encoding, defer to PSBOMH2
 ;*70 - add Clinic name to PSBO array for printing on grid via PSBOMH2
 ;       in ^TMP(""PSB",$J,"ORDERS",PSBX,"INST") global
 ;*83 - add remove logic to print RM and associated Gives in grid and
 ;      also remove string in order summary area.
 ;
EN ; Called from DQ^PSBO
 N PSBGBL,DFN,Q,X                                                 ;*83
 S PSBGBL=$NAME(^TMP("PSBO",$J,"B"))
 F  S PSBGBL=$Q(@PSBGBL) Q:PSBGBL=""  Q:$QS(PSBGBL,2)'=$J  Q:$QS(PSBGBL,1)'["PSBO"  D
 .S DFN=$QS(PSBGBL,5)
 .S (PSBSTRT,X)=$P(PSBRPT(.1),U,6) D H^%DTC S PSBSTH=%H
 .S (PSBSTOP,X)=$P(PSBRPT(.1),U,8)+.235959 D H^%DTC S PSBSPH=%H
 .S PSBCNT=0 F I=PSBSTH:1:PSBSPH S PSBAR(I)=PSBSTH+((PSBCNT\7)*7),PSBCNT=PSBCNT+1
 .D EN1
 K PSBCNT,PSBAR
 D CLEAN^PSBVT                                                    ;*83
 Q
EN1 ; Expects DFN,STRT,STOP
 N PSBGBL,PSBHDR,PSBX,PSBFLAG,PSBHLDFL,PSBADST1,PSBOST1,PSBCLINIC,PSBORSTP ;*70
 K ^TMP("PSJ",$J),^TMP("PSB",$J)
 S PSBEVDT=PSBSTRT
 D EN^PSJBCMA(DFN,PSBSTRT)
 N PSBCLINORD S PSBCLINORD=2                 ;*70 Combind mode headers
 I $G(^TMP("PSJ",$J,1,0))=-1 D  Q  ; No Ord
 .D PT^PSBOHDR(DFN,.PSBHDR) W !!,"****NO MEDICATIONS FOUND****"
 S PSBX=""
 F  S PSBX=$O(^TMP("PSJ",$J,PSBX)) Q:PSBX=""  D
 .Q:$P(^TMP("PSJ",$J,PSBX,0),U,3)?.N1"P"  ; No Pnd
 .S PSBORSTP=$P(^TMP("PSJ",$J,PSBX,1),U,5) S:$P(^TMP("PSJ",$J,PSBX,1),U,15)>PSBORSTP PSBORSTP=$P(^TMP("PSJ",$J,PSBX,1),U,15)
 .Q:PSBORSTP<PSBSTRT!($P(^TMP("PSJ",$J,PSBX,1),U,4)>PSBSTOP)  ;display orders active in date range of report
 .S X=$P(^TMP("PSJ",$J,PSBX,1),U,2)
 .S ^TMP("PSB",$J,"ORDERS",$P(^TMP("PSJ",$J,PSBX,0),U,3))=X
 I '$D(^TMP("PSB",$J,"ORDERS")) D  Q        ;No Orders
 .D PT^PSBOHDR(DFN,.PSBHDR) W !!,"****NO MEDICATIONS FOUND****"
 S PSBMHND="PSBOMH"
 ; Act on Orders
 S PSBX="" F  S PSBX=$O(^TMP("PSB",$J,"ORDERS",PSBX)) Q:PSBX=""  S PSBTYPE=^(PSBX) D
 .S:PSBTYPE'="C" PSBTYPE="P"
 .D CLEAN^PSBVT
 .D PSJ1^PSBVT(DFN,PSBX)
 .S PSBCLINIC=PSBCLORD
 .S X1=((PSBEVDT)\1)  S X2=-1  D C^%DTC  S PSBCNTST=X
 .S X1=((PSBSTOP)\1)  S X2=1  D C^%DTC  S PSBXSTOP=X
 .S PSBVALB=""
 .S PSBVALB=$$IVPTAB^PSBVDLU3(PSBOTYP,PSBIVT,PSBISYR,PSBCHEMT,PSBIVPSH)
 .S PSBZ=""
 .S X1=PSBXSTOP,X2=PSBCNTST D ^%DTC S PSBNCT=X
 .F PSBZ=1:1:PSBNCT S X1=PSBCNTST  S X2=1  D C^%DTC  S PSBCNTST=X  D
 ..I (PSBX["V")!(PSBX'["V")  D
 ...I PSBCNTST'>(PSBOST\1) S ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST)=""
 ...;add check for admin time before start time in PSB*3*57
 ...S PSBADST1=$E($P($G(PSBADST),"-",$L($G(PSBADST),"-"))_"00",1,4),PSBOST1=$E($P(PSBOST,".",2)_"0000",1,4) ;PSB*3*67
 ...I PSBCNTST=(PSBOST\1)&(PSBADST1>=PSBOST1) K ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST) ;PSB*3*67 - PSB*3*76 adds "=" for stop date/time check
 ...I PSBCNTST=(PSBOST\1),'$P($G(PSBADST),"-") K ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST) ;PSB*3*67
 ...I PSBCNTST>(PSBOSP\1) S ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST)=""
 ...I PSBCNTST=(PSBOSP\1)&($G(^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST))) K ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST) S ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST)=""
 ..S PSBDODD=""
 ..I (PSBFREQ#1440'=0),(1440#PSBFREQ'=0) S PSBDODD=1
 ..I ((PSBX'["V")!(PSBVALB="1")),((PSBDODD="1")&(PSBADST'="")) S ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST)=""
 ..I ((PSBX'["V")!(PSBVALB="1")),('$$OKAY^PSBVDLU1(PSBOST,PSBCNTST,PSBSCH,PSBON,PSBOITX,PSBFREQ,PSBOSTS)) S ^TMP("PSB",$J,"ORDERS",PSBONX,"NTDUE",PSBCNTST)=""  ;W t TMP
 .S (PSBYES,PSBODD,PSBFLAG,PSBYTFN,PSBDAYN)=0
 .S:$$PSBDCHK1^PSBVT1(PSBSCH) PSBYES=1,PSBDAYN=1
 .I PSBYES,PSBADST="",PSBSCHT'="O",PSBSCHT'="OC",PSBSCHT'="P" Q 
 .F I=1:1 Q:$P(PSBSCH,"-",I)=""  I $P(PSBSCH,"-",I)?2N!($P(PSBSCH,"-",I)?4N) S PSBYES=1,PSBYTFN=1
 .I (PSBFREQ="O")!(PSBTYPE="P") S PSBYES=1
 .I (PSBFREQ#1440'=0),(1440#PSBFREQ'=0) S PSBODD=1
 .;flg / admn t
 .S:PSBONX["U" PSBFLAG=1
 .I PSBIVT="A" S PSBADST="0000"
 .I PSBIVT="H" S PSBADST="0000"
 .I PSBIVT="C",PSBCHEMT="P" S:PSBADST="" PSBFLAG=1
 .I PSBIVT="C",PSBISYR=1 S:PSBADST="" PSBFLAG=1
 .I PSBIVT="C",PSBCHEMT="A" S PSBADST="0000"
 .I PSBIVT="C",PSBISYR=0 S PSBADST="0000"
 .I PSBIVT="P",($G(PSBADST)=0) S:PSBADST="" PSBFLAG=1
 .I PSBIVT="P" S:PSBADST="" PSBFLAG=1
 .I PSBIVT="S",PSBISYR=0 S PSBADST="0000"
 .I PSBIVT="S",PSBISYR=1 S:PSBADST="" PSBFLAG=1
 .I PSBFREQ="D" S PSBFREQ=""
 .I 'PSBYES,PSBADST="",PSBFREQ<1 Q
 .S (PSBEE,PSBZZ)=0
 .I (PSBVALB="1")!(PSBX'["V") D  Q:(PSBEE!PSBZZ)=1
 ..I PSBSCHT="C",PSBYTFN="1",PSBADST=""  S PSBEE=1
 ..I PSBSCHT="C",PSBDAYN'="1",PSBYTFN'="1",PSBADST'="",PSBFREQ<1  S PSBZZ=1
 .I 'PSBODD,PSBFLAG,PSBTYPE="C",PSBADST="" S PSBADST=$$GETADMIN^PSBVDLU1(DFN,PSBONX,PSBOST,PSBFREQ,PSBSTOP)
 .E  I PSBADST'="" K ^TMP("PSB",$J,"GETADMIN") S ^TMP("PSB",$J,"GETADMIN",0)=PSBADST
 .;Calc adm/frq
 .S PSBDT=PSBSTRT
 .K PSBO,^UTILITY($J)
 .F X=1:1:8 S PSBO(X)=""
 .S DIWL=0,DIWR=32,DIWF="C32"
 .S X=$P(PSBOSTX," ")_"          "_$P(PSBOSPX," ") D ^DIWP
 .S X="@"_$P(PSBOSTX," ",3)_"              @"_$P(PSBOSPX," ",3)_"   " D ^DIWP
 .S X="" D ^DIWP
 .S X=PSBOITX D ^DIWP
 .; DD,SOL,ADD
 .S X=""
 .F Y=0:0 S Y=$O(PSBDDA(Y)) Q:'Y  S X=X_$S(X]"":", ",1:"")_$P(PSBDDA(Y),U,3)
 .F Y=0:0 S Y=$O(PSBADA(Y)) Q:'Y  S X=X_$S(X]"":", ",1:"")_$P(PSBADA(Y),U,3)_" "_$P(PSBADA(Y),U,4)_$P(PSBADA(Y),U,5)
 .F Y=0:0 S Y=$O(PSBSOLA(Y)) Q:'Y  S X=X_$S(X]"":", ",1:"")_$P(PSBSOLA(Y),U,3)_" "_$P(PSBSOLA(Y),U,4)
 .S X=" "_X,DIWF="I2C32" D ^DIWP S DIWF="C32"
 .S PSBTXT=" Give: "_PSBDOSE_" "_PSBMRAB_" "_PSBSCH_" "_PSBIFR
 .F  S PSBWORD=$P(PSBTXT," ",1),PSBTXT=$P(PSBTXT," ",2,250) D  Q:PSBTXT=""
 ..F  Q:'$L(PSBWORD)  S X=$E(PSBWORD,1,30),PSBWORD=$E(PSBWORD,30,250) D ^DIWP
 .K ^TMP("PSJ",$J) D EN^PSJBCMA2(DFN,PSBX) I ^TMP("PSJ",$J,0)'=-1 D   ;get activity log
 ..S (PSBDISX,PSBHLDX)=0 F I=1:1:$P(^TMP("PSJ",$J,0),U,4) S X=$G(^TMP("PSJ",$J,I,1)) D  ;loop activities
 ...Q:X["EDITED"!(X["VERIF")  ;
 ...S:$P(X,U,4)["PLACED ON HOLD" PSBHLDFL=1 ;Set Hold Flag
 ...S:$P(X,U,4)["TAKEN OFF HOLD" PSBHLDFL=0 ;Remove Hold Flag
 ...S Z=0
 ...I X'["OFF HOLD",X'["UNHOLD",X'["REINSTATE" S Z=1 ; inc iv's
 ...S PSBHLDX=PSBHLDX+$S(Z>0:1,1:0)
 ...S $P(PSBHLD(PSBHLDX),U,$S(Z>0:1,1:11))=^TMP("PSJ",$J,I,1)  ;set up for multiple on hold entries save start & stop as pair if exists 
 ..F PSBHLDX=1:1 S X=$G(PSBHLD(PSBHLDX)) Q:'X  D  ;if a hold index - process 
 ...S PSBHLDN=$P(PSBHLD(PSBHLDX),U,1),PSBHLDF=$P(PSBHLD(PSBHLDX),U,11)  ;get on/off hold, dates, IEN number(for UD orders) of person. 
 ...Q:PSBHLDN>PSBSTOP  Q:(PSBHLDF<PSBSTRT)&(PSBHLDF'="") 
 ...F PSBHLDT=PSBSTRT\1:1:PSBSTOP\1 I (PSBHLDT'<(PSBHLDN\1)),(PSBHLDT'>PSBSTOP) D
 ....I X["DISCONTINUED" K ^TMP("PSB",$J,"ORDERS",PSBONX,"HOLD",PSBHLDT) S ^TMP("PSB",$J,"ORDERS",PSBONX,"DISC",PSBHLDT)=""
 ....I (X["HOLD")&($G(PSBHLDFL))&((PSBHLDN\1)'>PSBHLDT)&((PSBHLDF'<PSBHLDT)!(PSBHLDF="")) S ^TMP("PSB",$J,"ORDERS",PSBONX,"HOLD",PSBHLDT)="" ;Check additional flag for PSB*3*57
 ....I X["REINSTATE" K ^TMP("PSB",$J,"ORDERS",PSBONX,"DISC",PSBHLDT) I PSBOSTS="H" S ^TMP("PSB",$J,"ORDERS",PSBONX,"HOLD",PSBHLDT)=""
 ...F PSBHLDXP=1:10:$P(PSBHLD(PSBHLDX),U,11)]""+10 D
 ....S PSBDESC=$P(PSBHLD(PSBHLDX),U,PSBHLDXP+3),X=$S(PSBDESC["DISCONTINUE":"***",1:"")
 ....S X=" "_X_PSBDESC D ^DIWP  ;output activity text 
 ....S X="",PSBHLDI=$P(PSBHLD(PSBHLDX),U,PSBHLDXP+4) I PSBHLDI'="" S X=$$GET1^DIQ(200,PSBHLDI,"INITIAL")
 ....S:X="" X="99" ;no init present
 ....I X'="99" S X=" "_X D ^DIWP   ;get init & store
 ....S Y=$P(PSBHLD(PSBHLDX),U,PSBHLDXP) D DD^%DT S X=Y D ^DIWP  ;format hold date / write 
 ..K PSBHLD,PSBHLDF,PSBHLDN,PSBHLDT,PSBHLDX,PSBHLDXP,PSBHLDI,PSBDISX,PSBDISC,PSBDISXP,PSBDISI,PSBDIST,PSBDISN,PSBDESC
 .F X=0:0 S X=$O(^UTILITY($J,"W",0,X)) Q:'X  S PSBO(X)=$G(^(X,0)) D
 .;
 .;Insert removal times print text, insure 4 digit times           *83
 .; if removal time null, probably due to MRR type 1 so calculate
 .I $G(PSBRMST)]"" S PSBRMST=$$CNVRT4^PSBUTL(PSBRMST,"-")
 .I PSBMRRFL,$G(PSBRMST)="" S PSBRMST=$$REMSTR^PSBUTL(PSBADST,PSBDOA,PSBSCHT,PSBOSP,PSBOPRSP)
 .D:$G(PSBRMST)]""
 ..S X=$O(PSBO(""),-1)+1
 ..F Q=1:1:$L(PSBRMST,"-") D
 ...I Q=1 S PSBO(X)="     Removal Times: "_$P(PSBRMST,"-",Q) Q
 ...S X=X+1,PSBO(X)="                    "_$P(PSBRMST,"-",Q)
 .;
 .S X=$O(PSBO(""),-1) S X=$S(X<8:8,1:X+1)
 .S PSBO(X)=" RPH: "_PSBVPHI_"  RN: "_PSBVNI
 .S PSBVAL=$$IVPTAB^PSBVDLU3(PSBOTYP,PSBIVT,PSBISYR,PSBCHEMT,PSBIVPSH)
 .I PSBODD="1",PSBADST'="" D
 ..I (PSBVAL="1")!(PSBX'["V") D   ;checks iv/pb and u dose
 ...S PSBO(X+1)=""
 ...S PSBO(X+2)="NOTE - ODD SCHEDULE NO LONGER",PSBO(X+3)="       ALLOWS ADMIN TIMES."
 .K ^UTILITY($J)
 . ;*70 If no location, and not inpatient, and Manual Med Entry, relay this information
 .S PSBO(0)=$S(PSBCLINIC]"":PSBCLINIC,1:"INPATIENT")   ;clinic nam *70
 .S XORDERS=$S(PSBO(0)="INPATIENT":1,1:2)              ;IM or CO   *70
 .M ^TMP("PSB",$J,"ORDERS",PSBX,"INST")=PSBO
 .D:PSBTYPE="C"
 ..F  D  Q:PSBDT>PSBSTOP
 ...S X=PSBDT D H^%DTC S PSBWEEK=%H
 ...S ^TMP("PSB",$J,PSBWEEK,PSBONX)=""
 ...; Odd schd - msg
 ...S PSBIDOW=0 I PSBONX["U"!("PCS"[PSBIVT) S PSBIDOW=1
 ...I PSBADST="",PSBIDOW,(PSBODD) D
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",0)=7
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",1)="odd"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",2)="sched"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",3)=$E(PSBSCH,1,5)
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",4)="no"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",5)="fixed"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",6)="admin"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",7)="times"
 ...I PSBADST'="",PSBADST'="0000",+$G(PSBFREQ)>0,+$G(PSBFREQ)<45 D
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",0)=5
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",1)="Due"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",2)="every"
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",3)=$E(PSBFREQ,1,5)
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",4)="mins."
 ....S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",5)=" "
 ...S PSBATCNT=0    ; # times to print...
 ...I PSBADST'="",((+$G(PSBFREQ)>44)!(PSBFREQ="")!(PSBADST="0000")) F PSBXX=0:1  Q:$G(^TMP("PSB",$J,"GETADMIN",PSBXX))=""  D
 ....S PSBADST2=$G(^TMP("PSB",$J,"GETADMIN",PSBXX))
 ....F Y=1:1:$L(PSBADST2,"-") D
 .....Q:($P(PSBADST2,"-",Y)'?2N)&($P(PSBADST2,"-",Y)'?4N)  S PSBATCNT=PSBATCNT+1,^TMP("PSB",$J,"ORDERS",PSBONX,"AT",PSBATCNT)=$P(PSBADST2,"-",Y)
 ...;*70   Insert Xorders IM or CO flag (1 or 2) into Sort control
 ...I PSBADST'="",PSBFREQ>44 S ^TMP("PSB",$J,"ORDERS",PSBONX,"AT",0)=PSBATCNT
 ...S ^TMP("PSB",$J,PSBWEEK,"SORT",XORDERS,PSBTYPE,PSBOITX,PSBX)=""
 ...F PSBDOW=0:1:6 D  Q:X>(PSBSTOP-1)
 ....S %H=PSBWEEK+PSBDOW D YMD^%DTC
 ....S ^TMP("PSB",$J,PSBWEEK,PSBONX,X,0)=0
 ....I '$D(^TMP("PSB",$J,PSBWEEK,"HDR",X)) S ^TMP("PSB",$J,PSBWEEK,"HDR",X)=$E(X,4,5)_"/"_$E(X,6,7)_"/"_(1700+$E(X,1,3))
 ...S %H=PSBWEEK+7 D YMD^%DTC S PSBDT=X
 .D:PSBTYPE'="C"
 ..S X=PSBDT D H^%DTC S PSBWEEK=%H
 ..S (^TMP("PSB",$J,PSBWEEK,PSBONX),^TMP("PSB",$J,PSBWEEK,PSBONX,"AT",0))=""
 ..;*70   Insert Xorders IM or CO flag (1 or 2) into Sort control
 ..S ^TMP("PSB",$J,PSBWEEK,"SORT",XORDERS,PSBTYPE,PSBOITX,PSBX)=""
 D EN^PSBOMH1
 D EN^PSBOMH2
 Q
INSTR S PSBINIT=PSBINIT_"*"
 S PSBNAME=PSBNAME_"/"_$P(^PSB(53.79,PSBIEN,.9,$P(PSBDT,"."),0),U,3)_"  "_$$GET1^DIQ(53.79,PSBIEN_",",.06)
 Q