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

PSJ0066.m

Go to the documentation of this file.
  1. PSJ0066 ;BIR/JLC - Check for null start dates/times ; 28-NOV-01
  1. ;;5.0; INPATIENT MEDICATIONS ;**66**;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^PSJ0066",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,PSJSTRT,CREAT,EXPR,OCNT,PSJND0,PSJND2,START
  1. D NOW^%DTC S PSJSTART=$E(%,1,12),CREAT=$E(%,1,7),EXPR=$$FMADD^XLFDT(CREAT,30,0,0,0),OCNT=0
  1. K ^XTMP("PSJ")
  1. ;process the stop date crossreference to find orders
  1. ;with stop dates no more than 30 days old
  1. S %H=$H-31_",86400" D YMD^%DTC S START=X
  1. S PSJBEG=START
  1. F S PSJBEG=$O(^PS(55,"AUD",PSJBEG)) Q:'PSJBEG D
  1. . S PSJPDFN=0
  1. . F S PSJPDFN=$O(^PS(55,"AUD",PSJBEG,PSJPDFN)) Q:'PSJPDFN D
  1. .. S PSJORD=0
  1. .. F S PSJORD=$O(^PS(55,"AUD",PSJBEG,PSJPDFN,PSJORD)) Q:'PSJORD D
  1. ... S PSJND2=$G(^PS(55,PSJPDFN,5,PSJORD,2)),PSJSTRT=$P(PSJND2,"^",2)
  1. ... I PSJSTRT=""!($P(PSJSTRT,".",2)="") S ^XTMP("PSJ",PSJPDFN,"U",PSJORD)=PSJSTRT,OCNT=OCNT+1
  1. S PSJBEG=START
  1. F S PSJBEG=$O(^PS(55,"AIV",PSJBEG)) Q:'PSJBEG D
  1. . S PSJPDFN=0
  1. . F S PSJPDFN=$O(^PS(55,"AIV",PSJBEG,PSJPDFN)) Q:'PSJPDFN D
  1. .. S PSJORD=0
  1. .. F S PSJORD=$O(^PS(55,"AIV",PSJBEG,PSJPDFN,PSJORD)) Q:'PSJORD D
  1. ... S PSJND0=$G(^PS(55,PSJPDFN,"IV",PSJORD,0)),PSJSTRT=$P(PSJND0,"^",2)
  1. ... I PSJSTRT=""!($P(PSJSTRT,".",2)="") S ^XTMP("PSJ",PSJPDFN,"I",PSJORD)=PSJSTRT,OCNT=OCNT+1
  1. S:$D(^XTMP("PSJ")) ^XTMP("PSJ",0)=EXPR_"^"_CREAT
  1. D SENDMSG
  1. I $D(^XTMP("PSJ")) D CLEAN
  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. SENDMSG ;Send mail message when check is complete.
  1. K PSG,XMY S XMDUZ="MEDICATIONS,INPATIENT",XMSUB="INPATIENT MEDS 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 start dates."
  1. D ^XMD
  1. Q
  1. ;
  1. CLEAN ;
  1. N PSJPDFN,PSJORD,PSJND,PSJND2,PSJST,PSJSTRT,PSJSTP,PSJLOG,Y,PSJOSTP,PSJPREV,AD,AIEN,BEG,END,DFN,FO,FSTOP,FSTRT,PCNT,PREV0,PREV2,RFO,OPSJSTRT,TYP,OI,OINAME,BLANK
  1. S PSJPDFN=0,BEG=1,END=0,PCNT=2,$P(BLANK," ",40)=""
  1. F S PSJPDFN=$O(^XTMP("PSJ",PSJPDFN)) Q:'PSJPDFN S PSJORD=0 F TYP="U","I" D
  1. . S DFN=PSJPDFN K VADM D DEM^VADPT
  1. . F S PSJORD=$O(^XTMP("PSJ",PSJPDFN,TYP,PSJORD)) Q:'PSJORD D
  1. .. I '$D(^PS(55,PSJPDFN,$S(TYP="U":5,1:"IV"),PSJORD)) Q
  1. .. K OINAME,FSTRT,FSTOP
  1. .. I TYP="U" D
  1. ... S PSJND=$G(^PS(55,PSJPDFN,5,PSJORD,0)),PSJST=$P(PSJND,"^",7),PSJPREV=+$P(PSJND,"^",25)
  1. ... S PSJND2=$G(^PS(55,PSJPDFN,5,PSJORD,2)),(PSJSTRT,OPSJSTRT)=$P(PSJND2,"^",2)
  1. ... S OI=$P($G(^PS(55,PSJPDFN,5,PSJORD,.2)),"^"),OINAME=$P($G(^PS(50.7,OI,0)),"^")
  1. ... S PREV0=$G(^PS(55,PSJPDFN,5,PSJPREV,0)),FO=$P(PREV0,"^",26),RFO=$P(PREV0,"^",27)
  1. ... S PSJOSTP=$P($G(^PS(55,PSJPDFN,5,PSJPREV,2)),"^",4)
  1. .. I TYP="I" D
  1. ... S PSJND=$G(^PS(55,PSJPDFN,"IV",PSJORD,0)),(PSJSTRT,OPSJSTRT)=$P(PSJND,"^",2),PSJST=$P(PSJND,"^",17)
  1. ... S PSJND2=$G(^PS(55,PSJPDFN,"IV",PSJORD,2)),PSJPREV=+$P(PSJND2,"^",5)
  1. ... S AD=$O(^PS(55,PSJPDFN,"IV",PSJORD,"AD",0)) I AD]"" S AIEN=$P($G(^(AD,0)),"^"),OINAME=$P(^PS(52.6,AIEN,0),"^")
  1. ... S PREV2=$G(^PS(55,PSJPDFN,"IV",PSJPREV,2)),FO=$P(PREV2,"^",6),RFO=$P(PREV2,"^",9)
  1. ... S PSJOSTP=$P($G(^PS(55,PSJPDFN,"IV",PSJPREV,0)),"^",3)
  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. .. I PSJSTRT="",PSJPREV D
  1. ... I +FO'=+PSJORD!(RFO'="R") Q
  1. ... I TYP="U" D
  1. .... S $P(^PS(55,PSJPDFN,5,PSJORD,2),"^",2)=+PSJOSTP
  1. .... I OPSJSTRT]"" K ^PS(55,"AUDS",OPSJSTRT,PSJPDFN,PSJORD)
  1. .... S ^PS(55,"AUDS",+PSJOSTP,PSJPDFN,PSJORD)=""
  1. ... I TYP="I" D
  1. .... S $P(^PS(55,PSJPDFN,"IV",PSJORD,0),"^",2)=+PSJOSTP
  1. .... I OPSJSTRT]"" K ^PS(55,"AIVS",OPSJSTRT,PSJPDFN,PSJORD)
  1. .... S ^PS(55,"AIVS",+PSJOSTP,PSJPDFN,PSJORD)=""
  1. .. ;check to be sure the start date on the order exists
  1. .. ;if it doesn't, can't proceed with the correction
  1. .. ;this is a new condition
  1. .. I TYP="U" S PSJND2=$G(^PS(55,PSJPDFN,5,PSJORD,2)),(PSJSTRT,OPSJSTRT)=$P(PSJND2,"^",2) I PSJSTRT'[".",$L(PSJSTRT)>7 S PSJSTRT=$E(PSJSTRT,1,7)
  1. .. I TYP="I" S PSJND=$G(^PS(55,PSJPDFN,"IV",PSJORD,0)),(PSJSTRT,OPSJSTRT)=$P(PSJND,"^",2) I PSJSTRT'[".",$L(PSJSTRT)>7 S PSJSTRT=$E(PSJSTRT,1,7)
  1. .. I PSJSTRT="" D Q
  1. ... S PCNT=PCNT+1,PSG(PCNT,0)=$E(VADM(1),1,30)_$E(BLANK,1,32-$L(VADM(1)))_$P(VADM(2),"^")_" "_$S(TYP="U":"Unit Dose",1:"IV")
  1. ... S PCNT=PCNT+1,PSG(PCNT,0)="can't determine start date. Order: "_PSJORD
  1. .. ;check to be sure the start date (even if
  1. .. ;acquired from a previous order) has a time on it
  1. .. ;if not, make it midnight
  1. .. I $P(PSJSTRT,".",2)="" S $P(PSJSTRT,".",2)=24
  1. .. I TYP="U" D
  1. ... S $P(^PS(55,PSJPDFN,5,PSJORD,2),"^",2)=+PSJSTRT
  1. ... K ^PS(55,"AUDS",OPSJSTRT,PSJPDFN,PSJORD)
  1. ... S ^PS(55,"AUDS",+PSJSTRT,PSJPDFN,PSJORD)=""
  1. .. I TYP="I" D
  1. ... S $P(^PS(55,PSJPDFN,"IV",PSJORD,0),"^",2)=+PSJSTRT
  1. ... K ^PS(55,"AIVS",OPSJSTRT,PSJPDFN,PSJORD)
  1. ... S ^PS(55,"AIVS",+PSJSTRT,PSJPDFN,PSJORD)=""
  1. .. I TYP="U" S PSJND2=$G(^PS(55,PSJPDFN,5,PSJORD,2)),PSJSTRT=$P(PSJND2,"^",2),PSJSTP=$P(PSJND2,"^",3)
  1. .. I TYP="I" S PSJND=$G(^PS(55,PSJPDFN,"IV",PSJORD,0)),(PSJSTRT,OPSJSTRT)=$P(PSJND,"^",2),PSJSTP=$P(PSJND,"^",3)
  1. .. S Y=PSJSTRT X ^DD("DD") S FSTRT=Y
  1. .. S Y=PSJSTP X ^DD("DD") S FSTOP=Y
  1. .. S PCNT=PCNT+1,PSG(PCNT,0)=$E(VADM(1),1,25)_$E(BLANK,1,27-$L(VADM(1)))_$P(VADM(2),"^")_" "_$S(TYP="U":"Unit Dose",1:"IV")
  1. .. S OINAME=$G(OINAME),FSTRT=$G(FSTRT),FSTOP=$G(FSTOP)
  1. .. S PCNT=PCNT+1,PSG(PCNT,0)=" "_$E(OINAME,1,25)_$E(BLANK,1,28-$L(OINAME))_"Start: "_FSTRT_" Stop: "_FSTOP
  1. .. S END=END+1 I '(END#500) D CLEANMSG(BEG,END) K PSG S PCNT=2,BEG=END+1
  1. D CLEANMSG(BEG,END) Q
  1. CLEANMSG(BEG,END) K XMY S XMDUZ="MEDICATIONS,INPATIENT",XMSUB="INPATIENT MEDS ORDER ("_BEG_"-"_END_") CLEANUP COMPLETED",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