source: WorldVistAEHR/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSO283PI.m@ 1650

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

initial load of WorldVistAEHR

File size: 8.1 KB
Line 
1PSO283PI ;BIR/MFR-EXPIRATION DATE PROBLEM TALLY ;05/03/07
2 ;;7.0;OUTPATIENT PHARMACY;**283**;DEC 1997;Build 28
3 ;External references ^DPT supported by DBIA 10035
4 ;External reference to STATUS^ORQOR2 is supported by DBIA 3458
5 ;External reference to ^PS(59.7 is supported by DBIA 694
6 N NMSP,JOBSTS,DIR,DIRUT,DIROUT,DTOUT,DUOUT,Y,ACTION,EXPJOBDT,PSODUZ
7 S NMSP="PSO283PI"
8 ;
9 S JOBSTS=$$JOBSTS^PSO283P1()
10 ;
11 W !?5,"Expiration Date problem tally patch for Outpatient Pharmacy prescriptions"
12 W !?5,"========================================================================="
13 W !?5,"Current status: "
14 W:JOBSTS="N" "NEVER RUN"
15 W:JOBSTS="S" "STOPPED ON "_$$FMTE^XLFDT($G(^XTMP(NMSP,"STOPPED")))
16 W:JOBSTS="R" "RUNNING"
17 W:JOBSTS="C" "COMPLETED ON "_$$FMTE^XLFDT($G(^XTMP(NMSP,"COMPLETED")))
18 W:$G(^XTMP(NMSP,"LASTRX")) " (Last Rx IEN: "_$G(^XTMP(NMSP,"LASTRX"))_")"
19 ;
20 S DIR(0)="SO^",DIR("A")=""
21 I JOBSTS="N" D
22 .S DIR(0)=DIR(0)_"ST:START TALLY JOB;",DIR("A")=DIR("A")_"(ST)Start,",DIR("B")="START"
23 I JOBSTS="S" D
24 . S DIR(0)=DIR(0)_"RE:RESUME TALLY JOB;",DIR("A")=DIR("A")_"(RE)Resume,"
25 I JOBSTS="R" D
26 . S DIR(0)=DIR(0)_"SP:STOP TALLY JOB;",DIR("A")=DIR("A")_"(SP)Stop,"
27 I JOBSTS="C" D
28 . S DIR(0)=DIR(0)_"RR:RE-RUN TALLY JOB;",DIR("A")=DIR("A")_"(RR)Re-run,"
29 S DIR(0)=DIR(0)_"VW:VIEW "_$S(JOBSTS'="C":"PARTIAL ",1:"")_"TALLY JOB RESULTS;"
30 S DIR("A")=DIR("A")_"(VW)View,",DIR("B")="VIEW"
31 S DIR(0)=DIR(0)_"QT:QUIT",DIR("A")=DIR("A")_"(QT)Quit"
32 D ^DIR I $D(DIRUT)!$D(DIROUT)!$D(DTOUT)!$D(DUOUT) G QUIT
33 S ACTION=Y
34 ;
35 I ACTION="SP" W !!,"Stopping..." D G QUIT
36 . N TIME,UNABLE
37 . S ^XTMP(NMSP,"STOP")=1,(TIME,UNABLE)=0
38 . F Q:$D(^XTMP(NMSP,"STOPPED")) D Q:UNABLE
39 . . H 1 S TIME=TIME+1 I $D(^XTMP(NMSP,"COMPLETED"))!($$JOBSTS^PSO283P1()'="R")!(TIME>30) S UNABLE=1
40 . W $S(UNABLE:"NOT OK (may no longer be running)",1:"OK")
41 . K ^XTMP(NMSP,"STOP")
42 ;
43 I ACTION="QT" G QUIT
44 I ACTION="VW" D DISPLAY^PSO283P1 G QUIT
45 I ACTION="RR" K ^XTMP(NMSP)
46 ;
47 D JOB^PSO283P1()
48 Q
49 ;
50PI ; Post-Install entry point
51 N EXPJOBDT,NMSP
52 S NMSP="PSO283PI" K ^XTMP(NMSP)
53 D LOG^PSO283P1("PATCH INSTALLATION")
54 D JOB^PSO283P1($$NOW^XLFDT())
55 Q
56 ;
57EN ;
58 N NMSP,PSOINST,CUTOFF,PSOACT,RXP,STOP,PSOINACT,PATIENT,COUNTER,RXP,PATICN,DRUG,STATUS
59 N ISSUEDT,EXPIRDT,BADRXCNT,DAYSSUP,NUMREFS
60 ;
61 S NMSP="PSO283PI" I '$G(PSODUZ) S PSODUZ=+$G(DUZ)
62 ;
63 ; - If can't get Lock, then already running.
64 L +^XTMP(NMSP):5 I '$T D LOG^PSO283P1("UNSUCCESSFUL (LOCKED)") G QUIT
65 ;
66 D SETXTMP
67 ;
68 I '$G(DT) S DT=$$DT^XLFDT
69 ;
70 S PSOINST=$P($$SITE^VASITE(),"^",2)_" ("_+$$SITE^VASITE()_")"
71 S CUTOFF=$$FMADD^XLFDT(DT,-2)
72 S PSOINACT=",11,12,13,14,15,"
73 S RXP=+$G(^XTMP(NMSP,0,"LASTRX")),STOP=0
74 F COUNTER=1:1 S RXP=$O(^PSRX(RXP)) Q:'RXP D Q:STOP
75 . S:'(COUNTER#100000) DT=$$DT^XLFDT()
76 . S PATIENT=$P($G(^PSRX(RXP,0)),"^",2)
77 . S PATICN=$P($$GETICN^MPIF001(PATIENT),"^")
78 . S DRUG=$P($G(^PSRX(RXP,0)),"^",6)
79 . S STATUS=$P($G(^PSRX(RXP,"STA")),"^")
80 . S ISSUEDT=$P($G(^PSRX(RXP,0)),"^",13)
81 . S DAYSSUP=$P($G(^PSRX(RXP,0)),"^",8)
82 . S NUMREFS=$P($G(^PSRX(RXP,0)),"^",9)
83 . S EXPIRDT=$P($G(^PSRX(RXP,2)),"^",6)
84 . S BADRXCNT(14)=$G(BADRXCNT(14))+1
85 . S BADRXCNT("LASTRX")=RXP
86 . ;--- eliminate bad Rx's
87 . I ('PATIENT!'DRUG) S BADRXCNT(13)=$G(BADRXCNT(13))+1 Q
88 . I '$D(^DPT(PATIENT))!('$D(^PSDRUG(DRUG))) S BADRXCNT(13)=$G(BADRXCNT(13))+1 Q
89 . I 'ISSUEDT S BADRXCNT(13)=$G(BADRXCNT(13))+1 Q
90 . ;---
91 . D SET
92 . ;---
93 . I '(COUNTER#10000) D
94 . . M ^XTMP(NMSP)=BADRXCNT
95 . . I $G(^XTMP(NMSP,"STOP")) S STOP=1
96 ;
97 I STOP D STOP G QUIT
98 ;
99 M ^XTMP(NMSP)=BADRXCNT
100 S ^XTMP(NMSP,"COMPLETED")=$$NOW^XLFDT()
101 K ^XTMP(NMSP,"LASTRX")
102 D LOG^PSO283P1("COMPLETED")
103 D MAIL^PSO283P1
104 ;
105QUIT ;
106 L -^XTMP(NMSP)
107 Q
108 ;
109STOP ;
110 K ^XTMP(NMSP,"STOP")
111 S ^XTMP(NMSP,"STOPPED")=$$NOW^XLFDT()
112 D LOG^PSO283P1("STOPPED")
113 D MAIL^PSO283P1
114 Q
115 ;
116SET ;
117 N CPRSDC,CPRSTA,NEWEXPDT,DA,DIE,ORN,DR
118 S CPRSDC=",1,7,12,13,"
119 ;
120 ; --- No expiration date on PRESCRIPTION file (#52)
121 I EXPIRDT="" D Q
122 . S ORN=$$CPRSNUM(RXP),CPRSTA=$P(ORN,"^",2),ORN=+ORN
123 . D CALCEXP^PSO283P1 I '$G(EXPIRDT) Q
124 . I EXPIRDT>CUTOFF D Q ; Expiration Date past Cutoff (will be exp. by auto exp. job), Quit
125 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
126 . . . S BADRXCNT(102)=$G(BADRXCNT(102))+1
127 . . . S ^XTMP(NMSP,102,RXP,"HDR")=""
128 . . S BADRXCNT(2)=$G(BADRXCNT(2))+1,^XTMP(NMSP,2,RXP)=""
129 . I ORN D Q ; Rx is expired in CPRS (Update HDR with Exp. Date), Quit
130 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
131 . . . I CPRSDC'[(","_CPRSTA_",") D
132 . . . . S ^XTMP(NMSP,103,RXP,"HDR")="",BADRXCNT(103)=$G(BADRXCNT(103))+1
133 . . . I CPRSDC[(","_CPRSTA_",") D
134 . . . . S ^XTMP(NMSP,104,RXP,"HDR")="",BADRXCNT(104)=$G(BADRXCNT(104))+1
135 . . I CPRSDC'[(","_CPRSTA_",") D Q
136 . . . S BADRXCNT(3)=$G(BADRXCNT(3))+1,^XTMP(NMSP,3,RXP)=""
137 . . S BADRXCNT(4)=$G(BADRXCNT(4))+1,^XTMP(NMSP,4,RXP)=""
138 . I 'ORN D ; No CPRS Order # (Update HDR with Exp. Date)
139 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
140 . . . S BADRXCNT(105)=$G(BADRXCNT(105))+1
141 . . . S ^XTMP(NMSP,105,RXP,"HDR")=""
142 . . S BADRXCNT(5)=$G(BADRXCNT(5))+1,^XTMP(NMSP,5,RXP)=""
143 ;
144 ; --- Rx is expired. Update CPRS and HDR if necessary
145 I STATUS=11 D Q
146 . S ORN=$$CPRSNUM(RXP),CPRSTA=$P(ORN,"^",2),ORN=+ORN
147 . S NEWEXPDT=0
148 . I $$FMDIFF^XLFDT(EXPIRDT,ISSUEDT,1)>366 D ; Expiration Date is > 366, Recalculate new Date
149 . . S NEWEXPDT=1 D CALCEXP^PSO283P1
150 . I ORN,CPRSDC'[(","_CPRSTA_",") D ; Rx is not expired in CPRS (Update CPRS/HDR with Exp. Date), Quit
151 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to CPRS
152 . . . I 'NEWEXPDT S BADRXCNT(106)=$G(BADRXCNT(106))+1,^XTMP(NMSP,106,RXP,"HDR")=""
153 . . . I NEWEXPDT S BADRXCNT(107)=$G(BADRXCNT(107))+1,^XTMP(NMSP,107,RXP,"HDR")=""
154 . . I 'NEWEXPDT S BADRXCNT(6)=$G(BADRXCNT(6))+1,^XTMP(NMSP,6,RXP)=""
155 . . I NEWEXPDT S BADRXCNT(7)=$G(BADRXCNT(7))+1,^XTMP(NMSP,7,RXP)=""
156 . I 'NEWEXPDT Q ; Expiration Date was not recalculated, don't send to HDR
157 . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
158 . . S BADRXCNT(108)=$G(BADRXCNT(108))+1
159 . . S ^XTMP(NMSP,108,RXP,"HDR")=""
160 . S BADRXCNT(8)=$G(BADRXCNT(8))+1,^XTMP(NMSP,8,RXP)=""
161 ;
162 I EXPIRDT<CUTOFF,(PSOINACT'[(","_STATUS_",")) D ; Rx is past exp. date but is still on a non-Expired/DC'd status
163 . S ORN=$$CPRSNUM(RXP),CPRSTA=$P(ORN,"^",2),ORN=+ORN
164 . I ORN,CPRSDC'[(","_CPRSTA_",") D Q ; Update CPRS if necessary, this will also call HDR
165 . . I PATICN=-1 D Q ; NO ICN# - Send it to CPRS but not to HDR
166 . . . S BADRXCNT(109)=$G(BADRXCNT(109))+1
167 . . . S ^XTMP(NMSP,109,RXP,"HDR")=""
168 . . S BADRXCNT(9)=$G(BADRXCNT(9))+1,^XTMP(NMSP,9,RXP)=""
169 . I ORN D Q ; If CPRS was not updated, call HDR if there is an Order #
170 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
171 . . . S BADRXCNT(110)=$G(BADRXCNT(110))+1
172 . . . S ^XTMP(NMSP,110,RXP,"HDR")=""
173 . . S BADRXCNT(10)=$G(BADRXCNT(10))+1,^XTMP(NMSP,10,RXP)=""
174 . I 'ORN D ; If no CPRS Order #, just report (no updates to CPRS/HDR)
175 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
176 . . . S BADRXCNT(111)=$G(BADRXCNT(111))+1
177 . . . S ^XTMP(NMSP,111,RXP,"HDR")=""
178 . . S BADRXCNT(11)=$G(BADRXCNT(11))+1
179 . . S ^XTMP(NMSP,11,RXP)=""
180 ;
181 I STATUS=13 D Q
182 . S ORN=+$$CPRSNUM(RXP)
183 . I 'ORN D
184 . . I PATICN=-1 D Q ; NO ICN# - DO NOT send it to HDR
185 . . . S BADRXCNT(112)=$G(BADRXCNT(112))+1
186 . . . S ^XTMP(NMSP,112,RXP,"HDR")=""
187 . . S BADRXCNT(12)=$G(BADRXCNT(12))+1,^XTMP(NMSP,12,RXP)=""
188 Q
189 ;
190CPRSNUM(RXP) ;
191 N ORN,STA
192 S ORN=$P($G(^PSRX(RXP,"OR1")),"^",2),STA=""
193 I ORN S STA=+$$STATUS^ORQOR2(ORN) I STA=0 S ORN=""
194 Q (ORN_"^"_STA)
195 ;
196SETXTMP ; - Initialize the XTMP global
197 I $D(^XTMP(NMSP,"STARTED")) D
198 . S ^XTMP(NMSP,"RE-STARTED")=$$NOW^XLFDT() D LOG^PSO283P1("RE-STARTED")
199 I '$D(^XTMP(NMSP,"STARTED")) D
200 . S ^XTMP(NMSP,"STARTED")=$$NOW^XLFDT() D LOG^PSO283P1("STARTED")
201 K ^XTMP(NMSP,"STOP"),^XTMP(NMSP,"STOPPED")
202 S ^XTMP(NMSP,0)=$$FMADD^XLFDT($$NOW^XLFDT(),730)_"^"_$$NOW^XLFDT()_"^PSO*7*283 - RX EXPIRATION DATE PROBLEM TALLY"
203 Q
Note: See TracBrowser for help on using the repository browser.