source: WorldVistAEHR/trunk/r/INPATIENT_MEDICATIONS-PSJ-PSIV-PSG--PSGW/PSJ0077.m@ 701

Last change on this file since 701 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 7.3 KB
Line 
1PSJ0077 ;BIR/LDT - Check for Dispense Drug ; 02 MAY-01
2 ;;5.0; INPATIENT MEDICATIONS ;**77**;16 DEC 97
3 ;
4 ; Reference to ^PS(55 is supported by DBIA# 2191.
5 ; Reference to ^PSDRUG( is supported by DBIA# 2192.
6 ; Reference to ^OR(100 is supported by DBIA# 3582.
7 ; Reference to $$STATUS^ORQOR2 is supported by DBIA# 3458.
8 ;
9ENNV ; Begin check of existing orders
10 I $G(DUZ)="" W !,"Your DUZ is not defined. It must be defined to run this routine." Q
11 K ZTSAVE,ZTSK S ZTRTN="ENQN^PSJ0077",ZTDESC="Inpatient Orders Check (INPATIENT MEDS)",ZTIO="" D ^%ZTLOAD
12 W !!,"The check of existing Pharmacy orders is",$S($D(ZTSK):"",1:" NOT")," queued",!
13 I $D(ZTSK) D
14 . W " (to start NOW).",!!,"YOU WILL RECEIVE A MAILMAN MESSAGE WHEN TASK #"_ZTSK_" HAS COMPLETED. IF"
15 . W !,"ERRORS ARE DETECTED, YOU WILL RECEIVE A SECOND MESSAGE INDICATING CLEANUP"
16 . W !,"HAS COMPLETED."
17 Q
18ENQN ; Check of existing Pharmacy orders.
19 N PSJBEG,PSJPDFN,PSJORD,PSJLORD,CREAT,EXPR,OCNT
20 D NOW^%DTC S PSJSTART=$E(%,1,12),CREAT=$E(%,1,7),EXPR=$$FMADD^XLFDT(CREAT,30,0,0,0),OCNT=0,PSJLORD=0
21 K ^XTMP("PSJ")
22 S PSJBEG="" F S PSJBEG=$O(^PS(55,"AUD",PSJBEG)) Q:PSJBEG="" S PSJPDFN=0 F S PSJPDFN=$O(^PS(55,"AUD",PSJBEG,PSJPDFN)) Q:'PSJPDFN D
23 . S PSJORD=0 F S PSJORD=$O(^PS(55,"AUD",PSJBEG,PSJPDFN,PSJORD)) Q:'PSJORD Q:'+$G(^PS(55,PSJPDFN,5,PSJORD,.2)) D
24 .. S PSJDRG=0 F S PSJDRG=$O(^PS(55,PSJPDFN,5,PSJORD,1,PSJDRG)) Q:'PSJDRG I $P($G(^PS(55,PSJPDFN,5,PSJORD,1,PSJDRG,0)),"^")="" S ^XTMP("PSJ",PSJPDFN,PSJORD,PSJDRG)=$P($G(^PS(55,PSJPDFN,5,PSJORD,.2)),"^") S:PSJORD'=PSJLORD OCNT=OCNT+1 D
25 ... S PSJLORD=PSJORD I PSJDRG>1 S $P(^XTMP("PSJ",PSJPDFN,PSJORD,PSJDRG),"^",2)="MULTIPLE DISPENSE DRUGS",$P(^XTMP("PSJ",PSJPDFN,PSJORD,1),"^",2)="MULTIPLE DISPENSE DRUGS"
26 ... D SET
27 S:$D(^XTMP("PSJ")) ^XTMP("PSJ",0)=EXPR_"^"_CREAT
28 D SENDMSG
29 I $D(^XTMP("PSJ")) D CLEAN
30DONE ;
31 K DAYS,MINS,HOURS,PSG,PSJSTART,X,XMDUZ,XMSUB,XMTEXT,XMY,Y,ZTDESC,ZTDTH,ZTIO,ZTREQ,ZTRTN,ZTSAVE,ZTSK S ZTREQ="@"
32 Q
33SENDMSG ;Send mail message when check is complete.
34 K PSG,XMY S XMDUZ="MEDICATIONS,INPATIENT",XMSUB="PSJ*5*77 INPATIENT MEDS ORDER CHECK COMPLETED",XMTEXT="PSG(",XMY(DUZ)="" D NOW^%DTC S Y=% X ^DD("DD")
35 S PSG(1,0)="The check of existing Pharmacy orders for use with Inpatient",PSG(2,0)="Medications 5.0 completed as of "_Y_"."
36 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)
37 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)_"."
38 S PSG(6,0)=OCNT_" pharmacy orders were found with no Dispense Drug."
39 D ^XMD
40 Q
41 ;
42CLEAN ;
43 N PSJPDFN,PSJORD,PSJDRG,PSJOI,DRG,CCNT,LFCNT,PSSTART,PSSTOP,PSSTATUS,ORSTART,ORSTOP,ORSTATUS,CHK,CHK3 S CCNT=0,LFCNT=0
44 S PSJPDFN=0 F S PSJPDFN=$O(^XTMP("PSJ",PSJPDFN)) Q:'PSJPDFN S PSJORD=0 F S PSJORD=$O(^XTMP("PSJ",PSJPDFN,PSJORD)) Q:'PSJORD S PSJDRG=0 F S PSJDRG=$O(^XTMP("PSJ",PSJPDFN,PSJORD,PSJDRG)) Q:'PSJDRG D
45 . I '$D(^PS(55,PSJPDFN,5,PSJORD)) Q
46 . I $P(^XTMP("PSJ",PSJPDFN,PSJORD,PSJDRG),U,2)="" S PSJOI=$P(^XTMP("PSJ",PSJPDFN,PSJORD,PSJDRG),U) S:PSJOI]"" DRG=$$CHECK I DRG D
47 .. S $P(^PS(55,PSJPDFN,5,PSJORD,1,1,0),U)=DRG,^PS(55,PSJPDFN,5,+PSJORD,1,"B",DRG,1)="" K ^PS(55,PSJPDFN,5,PSJORD,1,"B",0,1) S CCNT=CCNT+1
48 .. K DR D NOW^%DTC S PSSTART=$P($G(^XTMP("PSJ",PSJPDFN,PSJORD,5)),"^"),PSSTOP=$P($G(^XTMP("PSJ",PSJPDFN,PSJORD,5)),"^",2),PSSTATUS=$P($G(^XTMP("PSJ",PSJPDFN,PSJORD,5)),"^",3)
49 .. S ORSTART=$P($G(^XTMP("PSJ",PSJPDFN,PSJORD,6)),"^"),ORSTOP=$P($G(^XTMP("PSJ",PSJPDFN,PSJORD,6)),"^",2),ORSTATUS=$P($G(^XTMP("PSJ",PSJPDFN,PSJORD,6)),"^",3),DIE="^PS(55,"_PSJPDFN_",5,",DA=PSJORD,DA(1)=PSJPDFN
50 .. D CHECK2 I CHK,ORSTOP'="",+ORSTOP<+PSSTOP,+ORSTOP<% S STPDT=ORSTOP,DR="10////^S X=PSSTART;28////D;25////^S X=PSSTOP;34////^S X=STPDT"
51 .. I CHK,ORSTOP'="",+ORSTOP<+PSSTOP,+ORSTOP'<% S STPDT=%,DR="10////^S X=PSSTART;28////D;25////^S X=PSSTOP;34////^S X=STPDT"
52 .. I CHK,ORSTOP'="",PSSTOP="" S DR="10////^S X=PSSTART;28////D"_$S(ORSTOP<%:";34////^S X=ORSTOP",1:";34////"_%)
53 .. I CHK,ORSTOP="",PSSTOP'="",+PSSTOP'>% S DR="10////^S X=PSSTART;28////D;34////^S X=PSSTOP"
54 .. I CHK,ORSTOP="",PSSTOP="" S DR="10////^S X=PSSTART;28////D;34////"_%
55 .. I CHK,ORSTOP="",+PSSTOP>% S DR="10////^S X=PSSTART;28////D;25////^S X=PSSTOP;34////"_%
56 .. I CHK,+ORSTOP=+PSSTOP,+PSSTOP<% S DR="10////^S X=PSSTART;28////D;34////^S X=PSSTOP"
57 .. I CHK,+ORSTOP=+PSSTOP,+PSSTOP'<% S DR="10////^S X=PSSTART;28////D;25////^S X=PSSTOP;34////"_%
58 .. I 'CHK S:((PSSTATUS="A")&(+PSSTOP<%)) DR="10////^S X=PSSTART;28////E;34////^S X=PSSTOP" I PSSTATUS="A",+PSSTOP'<% I $$CHECKDUP^PSGOERI(PSJPDFN,PSJORD) S DR="10////^S X=PSSTART;28////D;34////"_%
59 .. I 'CHK,PSSTATUS="A",+PSSTOP'<% I '$$CHECKDUP^PSGOERI(PSJPDFN,PSJORD) S DR="10////^S X=PSSTART;34////^S X=PSSTOP"
60 .. I 'CHK,PSSTATUS'="A" S DR="10////^S X=PSSTART;34////^S X=PSSTOP"
61 .. I $D(DR) D ^DIE
62 .. S PSJHLMTN="ORM" D EN1^PSJHL2(PSJPDFN,"SC",PSJORD_"U") K ^XTMP("PSJ",PSJPDFN,PSJORD)
63 S PSJPDFN=0 F S PSJPDFN=$O(^XTMP("PSJ",PSJPDFN)) Q:'PSJPDFN S LFCNT=LFCNT+1
64 I 'LFCNT K ^XTMP("PSJ")
65 K PSG,XMY S XMDUZ="MEDICATIONS,INPATIENT",XMSUB="PSJ*5*77 INPATIENT MEDS ORDER CLEANUP COMPLETED",XMTEXT="PSG(",XMY(DUZ)="" D NOW^%DTC S Y=% X ^DD("DD")
66 S PSG(1,0)="The cleanup of Inpatient Medication orders with no Dispense Drugs ",PSG(2,0)="completed as of "_Y_"."
67 S PSG(3,0)=""
68 S PSG(4,0)=CCNT_" pharmacy orders with no Dispense Drugs were corrected."
69 I $D(^XTMP("PSJ")) S PSG(5,0)="",PSG(6,0)="The following orders couldn't be corrected:",MSGCNT=7 D
70 . S PSG(7,0)="Patient's DFN Order #"
71 . S PSJPDFN=0 F S PSJPDFN=$O(^XTMP("PSJ",PSJPDFN)) Q:'PSJPDFN S PSJORD=0 F S PSJORD=$O(^XTMP("PSJ",PSJPDFN,PSJORD)) Q:'PSJORD D
72 .. S MSGCNT=MSGCNT+1,PSG(MSGCNT,0)=$J(PSJPDFN,13)_" "_$J(PSJORD,6)_"U"
73 .S MSGCNT=MSGCNT+1,PSG(MSGCNT,0)=""
74 .S MSGCNT=MSGCNT+1,PSG(MSGCNT,0)="The person who installs this patch and the pharmacy adpac should work together"
75 .S MSGCNT=MSGCNT+1,PSG(MSGCNT,0)="to identify what the missing Dispense Drug should be and get the order updated."
76 .S MSGCNT=MSGCNT+1,PSG(MSGCNT,0)="Should you require further assistance please contact NVS."
77 D ^XMD
78 Q
79 ;
80CHECK() ;
81 I '$D(PSGDT) D NOW^%DTC S PSGDT=$E(%,1,12)
82 N Q,X,DRG,QPT S (X,Q,QPT)=0
83 F DRG=0:0 S DRG=$O(^PSDRUG("ASP",PSJOI,DRG)) Q:'DRG S:$G(^PSDRUG(DRG,"I")) X=^("I")'>PSGDT I $P(^PSDRUG(DRG,2),U,3)["U" S Q=Q+1 S:'X QPT=DRG
84 Q $S(Q=1:QPT,1:0)
85SET ;
86 S F="^PS(55,"_PSJPDFN_",5,"_PSJORD_","
87 S ND=$G(@(F_"0)")),OERR=+$P(ND,"^",21),ND2=$G(@(F_"2)")),PSSTART=$P(ND2,"^",2),PSSTOP=$P(ND2,"^",4),PSSTATUS=$P(ND,"^",9)
88 S ORND=$G(^OR(100,OERR,0)),ORND3=$G(^OR(100,OERR,3)),PSPTR=$G(^OR(100,OERR,4)),ORSTART=$P(ORND,"^",8),ORSTOP=$P(ORND,"^",9),ORSTATUS=$P(ORND3,"^",3) Q:'ND D
89 .S:'OERR ^XTMP("PSJ",PSJPDFN,PSJORD,3)=OERR_U_PSPTR
90 .S:+PSPTR'=PSJORD ^XTMP("PSJ",PSJPDFN,PSJORD,4)=OERR_U_PSPTR_U_$P(ND,"^")
91 .S ^XTMP("PSJ",PSJPDFN,PSJORD,5)=PSSTART_U_PSSTOP_U_PSSTATUS,^XTMP("PSJ",PSJPDFN,PSJORD,6)=ORSTART_U_ORSTOP_U_$$STATUS^ORQOR2(OERR)_U_OERR
92 Q
93CHECK2 ;
94 S CHK=0
95 I +PSSTART'=+ORSTART S CHK=1 Q
96 I +PSSTOP'=+ORSTOP S CHK=1 Q
97 D @PSSTATUS
98 Q
99A S:ORSTATUS'=6 CHK=1 Q
100D S:"1^13"'[ORSTATUS CHK=1 Q
101DE S:"1^12^13"'[ORSTATUS CHK=1 Q
102DR S:"1^13^15"'[ORSTATUS CHK=1 Q
103E S:ORSTATUS'=7 CHK=1 Q
104H S:ORSTATUS'=3 CHK=1 Q
105I S:ORSTATUS'=9 CHK=1 Q
106N S:ORSTATUS'=5 CHK=1 Q
107O S:ORSTATUS'=3 CHK=1 Q
108P S:ORSTATUS'=5 CHK=1 Q
109R S:ORSTATUS'=15 CHK=1 Q
110RE S:ORSTATUS'=6 CHK=1 Q
111U S CHK=1 Q
Note: See TracBrowser for help on using the repository browser.