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

PSJ078A.m

Go to the documentation of this file.
  1. PSJ078A ;BIR/JCH-Check for stop date problems ;28-NOV-01
  1. ;;5.0; INPATIENT MEDICATIONS ;**78**;16 DEC 97
  1. ;
  1. ;Reference to ^DD is supported by DBIA# 10017.
  1. ;Reference to ^PS(50.7 is supported by DBIA# 2180.
  1. ;Reference to ^PS(52.6 is supported by DBIA# 1231.
  1. ;Reference to ^PS(55 is supported by DBIA# 2191.
  1. ;Reference to ^%DTC is supported by DBIA# 10000.
  1. ;Reference to ^%ZTLOAD is supported by DBIA# 10063.
  1. ;Reference to ^VADPT is supported by DBIA# 10061.
  1. ;Reference to ^XLFDT is supported by DBIA# 10103.
  1. ;Reference to ^XMD is supported by DBIA# 10070.
  1. ;
  1. ENNV ; Begin check of existing orders
  1. I $G(DUZ)="" W !,"Your DUZ is not defined. It must be defined to run this routine." Q
  1. K ZTSAVE,ZTSK S ZTRTN="ENQN^PSJ078A",ZTDESC="Inpatient Orders Check (INPATIENT MEDS)",ZTIO="" D ^%ZTLOAD
  1. W !!,"The check of existing Pharmacy orders is",$S($D(ZTSK):"",1:" NOT")," queued",!
  1. I $D(ZTSK) D
  1. . W " (to start NOW).",!!,"YOU WILL RECEIVE A MAILMAN MESSAGE WHEN TASK #"_ZTSK_" HAS COMPLETED. IF"
  1. . W !,"ERRORS ARE DETECTED, YOU WILL RECEIVE A SECOND MESSAGE INDICATING CLEANUP"
  1. . W !,"HAS COMPLETED."
  1. Q
  1. ENQN ; Check of existing Pharmacy orders.
  1. N PSJBEG,PSJPDFN,PSJORD,PSJSTOP,PSJNVDT,CREAT,EXPR,OCNT,PSJND0,PSJND2,START
  1. N PSJSTRT
  1. D NOW^%DTC S PSJSTART=$E(%,1,12),CREAT=$E(%,1,7)
  1. S EXPR=$$FMADD^XLFDT(CREAT,30,0,0,0),OCNT=0
  1. K ^XTMP("PSJ"),^XTMP("PSJ XREF")
  1. ;
  1. ;process data nodes
  1. S PSJPDFN=0 F S PSJPDFN=$O(^PS(55,PSJPDFN)) Q:'PSJPDFN D
  1. . F TYP="IV",5 D
  1. .. S ORD=0 F S ORD=$O(^PS(55,PSJPDFN,TYP,ORD)) Q:'ORD D
  1. ... Q:$TR($P($G(^PS(55,PSJPDFN,TYP,ORD,0)),"^",2,8),"^")=""
  1. ... I TYP="IV" D
  1. .... S PSJND0=$G(^PS(55,PSJPDFN,"IV",ORD,0))
  1. .... S PSJSTRT=$P(PSJND0,"^",2),PSJSTOP=$P(PSJND0,"^",3)
  1. .... S PSJNVDT=$P($G(^PS(55,PSJPDFN,"IV",ORD,4)),"^",2)
  1. ... I TYP=5 D
  1. .... S ND2=$G(^PS(55,PSJPDFN,TYP,ORD,2)),PSJSTRT=$P(ND2,"^",2)
  1. .... S PSJSTOP=$P(ND2,"^",4)
  1. .... S PSJNVDT=$P($G(^PS(55,PSJPDFN,5,ORD,4)),"^",2)
  1. ... I PSJSTOP=""!($P(PSJSTOP,".",2)="")!(PSJSTOP'=+PSJSTOP)!($L(PSJSTOP)<5) D Q
  1. .... S ^XTMP("PSJ",PSJPDFN,TYP,ORD)=PSJSTRT,OCNT=OCNT+1
  1. ... I PSJSTRT=""!($P(PSJSTRT,".",2)="")!(PSJSTRT'=+PSJSTRT)!($L(PSJSTRT)<5) D Q
  1. .... S ^XTMP("PSJ",PSJPDFN,TYP,ORD)=PSJSTRT,OCNT=OCNT+1
  1. ... I PSJNVDT]"",PSJNVDT'=+PSJNVDT D
  1. .... S ^XTMP("PSJ",PSJPDFN,TYP,ORD)=PSJNVDT,OCNT=OCNT+1
  1. S:$D(^XTMP("PSJ")) ^XTMP("PSJ",0)=EXPR_"^"_CREAT
  1. D SENDMSG
  1. I $D(^XTMP("PSJ")) D CLEAN
  1. D XREFS^PSJ078B
  1. ;
  1. DONE ;
  1. K DAYS,MINS,HOURS,PSG,PSJSTART,X,XMDUZ,XMSUB,XMTEXT,XMY,Y,ZTDESC,ZTDTH,ZTIO,ZTREQ,ZTRTN,ZTSAVE,ZTSK S ZTREQ="@"
  1. Q
  1. ;
  1. SENDMSG ;Send mail message when check is complete.
  1. K PSG,XMY S XMDUZ="MEDICATIONS,INPATIENT",XMSUB="PSJ*5*78 INPATIENT MEDS STOP DATE ORDER CHECK COMPLETED",XMTEXT="PSG(",XMY(DUZ)="" D NOW^%DTC S Y=% X ^DD("DD")
  1. S PSG(1,0)=" The check of existing Pharmacy orders for use with Inpatient",PSG(2,0)="Medications 5.0 completed as of "_Y_"."
  1. S X=$$FMDIFF^XLFDT(%,PSJSTART,3) S:$L(X," ")>1 DAYS=+$P(X," "),X=$P(X," ",2) S HOURS=+$P(X,":"),MINS=+$P(X,":",2)
  1. S PSG(3,0)=" ",PSG(4,0)="This process checked orders for patients in "_$S($G(DAYS):DAYS_" day"_$E("s",DAYS'=1)_", ",1:"")_HOURS_" hour"_$E("s",HOURS'=1),PSG(5,0)="and "_MINS_" minute"_$E("s",MINS'=1)_"."
  1. S PSG(6,0)=OCNT_" pharmacy orders were found with invalid stop dates."
  1. D ^XMD
  1. Q
  1. ;
  1. CLEAN ;
  1. N PSJPDFN,PSJORD,PSJND,PSJND2,PSJSTRT,PSJLOG,Y,PSJOSTP
  1. N PSJFOL,AD,AEN,BEG,END,DFN,PO,FSTOP,FSTRT,PCNT,FOLL0,PREV2,RFO
  1. N OPSJSTP,OPSJSTRT,TYP,OI,OINAME,BLANK,PSGTMP
  1. S PSJPDFN=0,BEG=1,END=0,PCNT=6,$P(BLANK," ",40)="",AEN=0
  1. F S PSJPDFN=$O(^XTMP("PSJ",PSJPDFN)) Q:'PSJPDFN D
  1. . F TYP="IV",5 D
  1. .. S DFN=PSJPDFN K VADM D DEM^VADPT
  1. .. S PSJORD=0
  1. .. F S PSJORD=$O(^XTMP("PSJ",PSJPDFN,TYP,PSJORD)) Q:'PSJORD D
  1. ... S PSJND=$G(^PS(55,PSJPDFN,$S(TYP=5:5,1:"IV"),PSJORD,0))
  1. ... S PSJND4=$G(^PS(55,PSJPDFN,$S(TYP=5:5,1:"IV"),PSJORD,4))
  1. ... I $TR(PSJND,"^","")="" Q
  1. ... N PSJST,PSJPREV,PSJSTP,PSJSTRT,PSJFOL,OPSJSTP,OPSJSTRT
  1. ... K OINAME,FSTRT,FSTOP,STRTCHG,STOPCHG,FOLL2,FOLSTRT,PREVFO,PREV0
  1. ... K OI,FOLL0
  1. ... I TYP=5 D
  1. .... S PSJST=$P(PSJND,"^",7) ;Schedule Type for UD(different than IV)
  1. .... S PSJFOL=+$P(PSJND,"^",26)
  1. .... S PSJPREV=+$P(PSJND,"^",25),PSJND2=$G(^PS(55,PSJPDFN,5,PSJORD,2))
  1. .... S (PSJSTP,OPSJSTP)=$P(PSJND2,"^",4)
  1. .... S (PSJSTRT,OPSJSTRT)=$P(PSJND2,"^",2)
  1. .... S PSJNVDT=$P(PSJND4,"^",2)
  1. .... S OI=$P($G(^PS(55,PSJPDFN,5,PSJORD,.2)),"^")
  1. .... S OINAME=$S(OI:$P($G(^PS(50.7,OI,0)),"^"),1:"OI NOT FOUND")
  1. .... I PSJFOL D
  1. ..... S FOLL0=$G(^PS(55,PSJPDFN,5,PSJFOL,0)),FOLPO=$P(FOLL0,"^",25)
  1. ..... S FOLL2=$G(^PS(55,PSJPDFN,5,PSJFOL,2)),FOLSTRT=$P(FOLL2,"^",2)
  1. .... I PSJPREV D
  1. ..... S PSJOSTP=$P($G(^PS(55,PSJPDFN,5,PSJPREV,2)),"^",4)
  1. ..... S PREV0=$G(^PS(55,PSJPDFN,5,PSJPREV,0)),PREVFO=$P(PREV0,"^",26)
  1. ..... S PREVRFO=$P(PREV0,"^",27)
  1. ... I TYP="IV" D
  1. .... S PSJST=$P(PSJND,"^",4),(PSJSTRT,OPSJSTRT)=$P(PSJND,"^",2)
  1. .... S (PSJSTP,OPSJSTP)=$P(PSJND,"^",3)
  1. .... S OI=$P($G(^PS(55,PSJPDFN,"IV",PSJORD,.2)),"^")
  1. .... S OINAME=$S(OI:$P($G(^PS(50.7,OI,0)),"^"),1:"")
  1. .... S PSJND2=$G(^PS(55,PSJPDFN,"IV",PSJORD,2))
  1. .... S PSJNVDT=$P(PSJND4,"^",2)
  1. .... S AD=$O(^PS(55,PSJPDFN,"IV",PSJORD,"AD",0))
  1. .... I OINAME="",AD]"" S AEN=$P($G(^PS(55,PSJPDFN,"IV",PSJORD,"AD",AD,0)),"^") D
  1. ..... S OINAME=$P($G(^PS(52.6,+AEN,0)),"^")
  1. ..... S:OINAME="" OINAME="OI NOT FOUND"
  1. .... S PSJPREV=+$P(PSJND2,"^",5),PSJFOL=$P(PSJND2,"^",6)
  1. .... I PSJFOL S FOLL0=$G(^PS(55,PSJPDFN,"IV",+PSJFOL,0)) D
  1. ..... S FOLL2=$G(^PS(55,PSJPDFN,"IV",+PSJFOL,2))
  1. ..... S FOLPO=$P(FOLL2,"^",5),FOLSTRT=$P(FOLL0,"^",2)
  1. .... I PSJPREV S PREV2=$G(^PS(55,PSJPDFN,"IV",PSJPREV,2)) D
  1. ..... S PSJOSTP=$P($G(^PS(55,PSJPDFN,"IV",PSJPREV,0)),"^",3)
  1. ..... S PREVFO=$P(PREV2,"^",6),PREVRFO=$P(PREV2,"^",9)
  1. ... ;
  1. ... ;If there's a null start date, check if the previous order was
  1. ... ; renewed to cause this order to be created and if the stop date
  1. ... ; is there, use it
  1. ... ;If there's a null stop date, check if this order has a following
  1. ... ; order, and if the start date is there, use it
  1. ... ;Check to be sure the dates (even if acquired from a previous or
  1. ... ; following order) has a time on it; if not, make it midnight
  1. ... ;Check for trailing zeroes by forcing numeric
  1. ... ;Check for any other odd format with length < 5
  1. ... I PSJSTRT="",$G(PSJOSTP) I (+$G(PREVFO)=+PSJORD) D
  1. .... S PSJSTRT=+PSJOSTP,STRTCHG=1
  1. ... I PSJSTRT'[".",$L(PSJSTRT)>7 S PSJSTRT=$E(PSJSTRT,1,7),STRTCHG=1
  1. ... I PSJSTRT,$P(PSJSTRT,".",2)="" S $P(PSJSTRT,".",2)=1,STRTCHG=1
  1. ... I PSJSTRT,(PSJSTRT'=+PSJSTRT) S PSJSTRT=+PSJSTRT,STRTCHG=1
  1. ... I PSJSTP="",$G(FOLSTRT) I (+$G(FOLPO)=PSJORD) D
  1. .... S PSJSTP=FOLSTRT,STOPCHG=1
  1. ... I PSJSTP'[".",$L(PSJSTP)>7 S PSJSTP=$E(PSJSTP,1,7),STOPCHG=1
  1. ... I PSJSTP,$P(PSJSTP,".",2)="" S $P(PSJSTP,".",2)=24,STOPCHG=1
  1. ... I PSJSTP,(PSJSTP'=+PSJSTP) S PSJSTP=+PSJSTP,STOPCHG=1
  1. ... ; Prepare message with results
  1. ... I 'PSJSTRT!'PSJSTP!($G(STOPCHG))!($G(STRTCHG)) D
  1. .... S PCNT=PCNT+1,PSGTMP=$E(VADM(1),1,25)_$E(BLANK,1,27-$L(VADM(1)))
  1. .... S PSGTMP=PSGTMP_$P(VADM(2),"^")
  1. .... S PSG(PCNT,0)=PSGTMP_" "_$S(TYP=5:"Unit Dose",1:"IV")
  1. .... S Y=PSJSTRT X ^DD("DD") S FSTRT=Y,Y=PSJSTP X ^DD("DD") S FSTOP=Y
  1. .... I $G(STOPCHG)!$G(STRTCHG) D
  1. ..... S OINAME=$G(OINAME),FSTRT=$G(FSTRT),FSTOP=$G(FSTOP),PCNT=PCNT+1
  1. ..... S PSG(PCNT,0)=" "_$E(OINAME,1,20)_$E(BLANK,1,22-$L(OINAME))
  1. ..... S PSG(PCNT,0)=PSG(PCNT,0)_"Start: "_FSTRT_" Stop: "_FSTOP
  1. ..... I $G(STOPCHG),PSJST="" S PCNT=PCNT+1 D
  1. ...... S PSG(PCNT,0)=" Missing "_$S(TYP=5:"Schedule Type",1:"IV Type")
  1. ...... S PSG(PCNT,0)=PSG(PCNT,0)_" DATE(S) NOT CORRECTED. "
  1. ...... S PSG(PCNT,0)=PSG(PCNT,0)_" Order: "_PSJORD
  1. .... I 'PSJSTRT!'PSJSTP S PCNT=PCNT+1 D
  1. ..... I $G(STOPCHG)!$G(STRTCHG) S OINAME=""
  1. ..... S PSGTMP=" "_$E(OINAME,1,20)_$E(BLANK,1,22-$L(OINAME))_" Can't determine "_$S('PSJSTRT:"start date",1:"")
  1. ..... S PSGTMP=PSGTMP_$S('PSJSTRT&('PSJSTP):" or ",1:"")_$S('PSJSTP:"stop date",1:"")_". Order: "_PSJORD
  1. ..... S PSG(PCNT,0)=PSGTMP
  1. ... ;
  1. ... ; Update ^PS(55 and indices
  1. ... I TYP=5 D:$G(STRTCHG) UDSTART^PSJ078B D:$G(STOPCHG) UDSTOP^PSJ078B
  1. ... I TYP="IV" D:$G(STRTCHG) IVSTART^PSJ078B D:$G(STOPCHG) IVSTOP^PSJ078B
  1. ... S END=END+1
  1. ... I '(END#500) D CLEANMSG(BEG,END) K PSG S PCNT=2,BEG=END+1
  1. D CLEANMSG(BEG,END) Q
  1. ;
  1. CLEANMSG(BEG,END) ;
  1. K XMY S XMDUZ="MEDICATIONS,INPATIENT"
  1. S XMSUB="PSJ*5*78 INPATIENT MEDS STOP DATE ORDER ("_BEG_"-"_END_") CLEANUP COMPLETED"
  1. S XMTEXT="PSG(",XMY(DUZ)="" D NOW^%DTC S Y=% X ^DD("DD")
  1. S PSG(1,0)=" The cleanup of Inpatient Medication orders ("_BEG_"-"_END_") with invalid dates ",PSG(2,0)="completed as of "_Y_"."
  1. D ^XMD
  1. Q