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

PSJ5P193.m

Go to the documentation of this file.
  1. PSJ5P193 ;NCD - Check for null start date/times ; 2/4/09 11:26am
  1. ;;5.0; INPATIENT MEDICATIONS ;**193**;;Build 16
  1. ;
  1. ; Reference to ^PS(55 is supported by DBIA# 2191.
  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 ^%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. ;Reference to ^DD is supported by DBIA# 10017.
  1. ;
  1. ENVN ; 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,ZSTK
  1. S ZTIO="",ZTRTN="START^PSJ5P193",ZTDESC="START DATE CLEAN UP",ZTSAVE("DUZ")="",ZTDTH=$H 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, THE VERIFYING PHARMACIST WILL RECEIVE A MESSAGE INDICATING CLEANUP"
  1. . W !,"HAS COMPLETED."
  1. Q
  1. START ;Check of existing Pharmacy orders.
  1. N XPSJSTDT,XPSJDFN,XPSJON,XPSJLGDT,XPSJSTRT,XPSJSTP,XCNT,XCNTTOT,X,X1,X2,Y,PSJBEG,PSJSTART,CREAT,EXPR,START
  1. S (XPSJSTDT,XPSJDFN,XPSJON,XCNT,XCNTTOT)=0
  1. D NOW^%DTC S PSJSTART=$E(%,1,12),CREAT=$E(%,1,7),EXPR=$$FMADD^XLFDT(CREAT,30,0,0,0)
  1. K ^XTMP("PSJ5P193",$J)
  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. . F S XPSJDFN=$O(^PS(55,"AUD",PSJBEG,XPSJDFN)) Q:XPSJDFN="" D
  1. . . F S XPSJON=$O(^PS(55,"AUD",PSJBEG,XPSJDFN,XPSJON)) Q:XPSJON="" D
  1. . . . S XCNTTOT=XCNTTOT+1 I '(XCNTTOT#1000) H .1
  1. . . . S XPSJND2=$G(^PS(55,XPSJDFN,5,XPSJON,2)),XPSJSTRT=$P(XPSJND2,"^",2) ;start date/time
  1. . . . S XPSJLGDT=$P(^PS(55,XPSJDFN,5,XPSJON,0),"^",16) ;login date/time
  1. . . . I XPSJSTRT="" S ^XTMP("PSJ5P193",$J,XPSJDFN,"U",XPSJON)=XPSJSTRT_"^"_XPSJLGDT,XCNT=XCNT+1
  1. S PSJBEG=START,(XPSJDFN,XPSJON)=0
  1. F S PSJBEG=$O(^PS(55,"AIV",PSJBEG)) Q:'PSJBEG D
  1. . F S XPSJDFN=$O(^PS(55,"AIV",PSJBEG,XPSJDFN)) Q:XPSJDFN="" D
  1. . . F S XPSJON=$O(^PS(55,"AIV",PSJBEG,XPSJDFN,XPSJON)) Q:XPSJON="" D
  1. . . . S XPSJN0=$G(^PS(55,XPSJDFN,"IV",XPSJON,0)),XPSJSTRT=$P(XPSJN0,"^",2),XPSJLGDT=$P(^PS(55,XPSJDFN,"IV",XPSJON,2),"^")
  1. . . . I XPSJSTRT="" S ^XTMP("PSJ5P193",$J,XPSJDFN,"I",XPSJON)=XPSJSTRT_"^"_XPSJLGDT,XCNT=XCNT+1
  1. I $D(^XTMP("PSJ5P193")) S ^XTMP("PSJ5P193",$J,0)=EXPR_"^"_CREAT
  1. D SENDMSG
  1. I $D(^XTMP("PSJ5P193",$J)) D CLEAN
  1. END K X,X1,X2,XMDUZ,XMSUB,XMTEXT,XMY,Y,ZTDESC,ZTIO,ZTRTN,ZTSAVE,ZTSK
  1. S:$D(ZTQUEUED) ZTREQ="@"
  1. Q
  1. SENDMSG ;Send mail message when check is complete.
  1. K PSG
  1. N DIFROM,XMDUZ,XMSUB,XMTEXT,XMY
  1. S XMDUZ="INPATIENT,MEDICATIONS",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)=XCNT_" pharmacy order"_$S(XCNT'=1:"s were ",1:" was ")_" found with invalid start dates."
  1. D ^XMD
  1. Q
  1. ;
  1. CLEAN ;
  1. N DFN,X,XPCNT,BLANK,TYP,OI,OINAME,VADM,BEG,END,FSTRT,FSTOP,XPER,XPSJSEND
  1. K PSG
  1. S (XPSJDFN,XPSJON)=0,XPCNT=2,$P(BLANK," ",40)="",BEG=1,END=0
  1. F S XPSJDFN=$O(^XTMP("PSJ5P193",$J,XPSJDFN)) Q:XPSJDFN="" F TYP="U","I" D
  1. . S DFN=XPSJDFN K VADM D DEM^VADPT
  1. . F S XPSJON=$O(^XTMP("PSJ5P193",$J,XPSJDFN,TYP,XPSJON)) Q:XPSJON="" D
  1. . . I '$D(^PS(55,XPSJDFN,$S(TYP="U":5,1:"IV"),XPSJON)) Q
  1. . . K OINAME,FSTRT,FSTOP,XPER
  1. . . S X=^XTMP("PSJ5P193",$J,XPSJDFN,TYP,XPSJON),XPSJSTRT=$P(X,"^"),XPSJLGDT=$P(X,"^",2),XPSJLGTM=$P(XPSJLGDT,".",2)
  1. . . I TYP="U" S OI=$P($G(^PS(55,XPSJDFN,5,XPSJON,.2)),"^"),OINAME=$P($G(^PS(50.7,OI,0)),"^")
  1. . . I TYP="I" S AD=$O(^PS(55,XPSJDFN,"IV",XPSJON,"AD",0)) I AD]"" S AIEN=$P($G(^(AD,0)),"^"),OINAME=$P(^PS(52.6,AIEN,0),"^")
  1. . . ;check if the login time is between midnight and 1:00AM
  1. . . ;if it's not then can't proceed with the correction
  1. . . ;this is a new condition
  1. . . I XPSJSTRT="",XPSJLGDT#1*100'<1 D Q
  1. . . . S XPCNT=XPCNT+1,PSG(XPCNT,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 XPCNT=XPCNT+1,PSG(XPCNT,0)="can't determine start date. Order: "_XPSJON
  1. . . I TYP="U" D
  1. . . . ;S XPER=$G(^PS(55,XPSJDFN,5,XPSJON,4))
  1. . . . ;I $P(XPER,"^",3)'="" S XPSJSEND($J,$P(XPER,"^",3))="" ;get the verifying pharmacist
  1. . . . S $P(^PS(55,XPSJDFN,5,XPSJON,2),"^",2)=XPSJLGDT
  1. . . . K ^PS(55,"AUDS",0,XPSJDFN,XPSJON)
  1. . . . K DIK,DA S DA=XPSJON,DA(1)=XPSJDFN,DIK="^PS(55,"_DA(1)_",5,",DIK(1)="10^AUDS" D EN^DIK
  1. . . I TYP="I" D
  1. . . . ;S XPER=$G(^PS(55,XPSJDFN,"IV",XPSJON,4))
  1. . . . ;I $P(XPER,"^",4)'="" S XPSJSEND($J,$P(XPER,"^",4))="" ;get the verifying pharmacist
  1. . . . S $P(^PS(55,XPSJDFN,"IV",XPSJON,0),"^",2)=XPSJLGDT
  1. . . . K ^PS(55,"AIVS",0,XPSJDFN,XPSJON)
  1. . . . K DIK,DA S DA=XPSJON,DA(1)=XPSJDFN,DIK="^PS(55,"_DA(1)_",""IV"",",DIK(1)=".02^AIVS" D EN^DIK
  1. . . I TYP="U" S XPSJND2=$G(^PS(55,XPSJDFN,5,XPSJON,2)),XPSJSTRT=$P(XPSJND2,"^",2),XPSJSTP=$P(XPSJND2,"^",4)
  1. . . I TYP="I" S XPSJND0=$G(^PS(55,XPSJDFN,"IV",XPSJON,0)),XPSJSTRT=$P(XPSJND0,"^",2),XPSJSTP=$P(XPSJND0,"^",3)
  1. . . S Y=XPSJSTRT X ^DD("DD") S FSTRT=Y
  1. . . S Y=XPSJSTP X ^DD("DD") S FSTOP=Y
  1. . . S XPCNT=XPCNT+1,PSG(XPCNT,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 XPCNT=XPCNT+1,PSG(XPCNT,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 XPCNT=2,BEG=END+1
  1. D CLEANMSG(BEG,END)
  1. Q
  1. ;
  1. CLEANMSG(BEG,END) N DIFROM,XMDUZ,XMSUB,XMTEXT,XMY,LOOP
  1. S XMDUZ="INPATIENT,MEDICATIONS",XMSUB="INPATIENT MEDS ORDER "_$S(END>0:BEG_"-"_END_" ",1:"")_"CLEANUP COMPLETED",XMTEXT="PSG("
  1. S LOOP=""
  1. F S LOOP=$O(^XUSEC("PSJ RPHARM",LOOP)) Q:LOOP="" S XMY(LOOP)="" ;send mailman message to all pharmacist who holds PSJ RPHARM key
  1. D NOW^%DTC S Y=% X ^DD("DD")
  1. S PSG(1,0)="The cleanup of Inpatient Medication orders ("_$S(END>0:BEG_"-"_END,1:END)_") of "_XCNT_" orders with invalid ",PSG(2,0)="dates completed as of "_Y_"."
  1. D ^XMD
  1. Q