source: FOIAVistA/trunk/r/OUTPATIENT_PHARMACY-PSO-APSP-HUIP/PSOCPIB3.m@ 1154

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

initial load of FOIAVistA 6/30/08 version

File size: 9.2 KB
Line 
1PSOCPIB3 ;BIR/EJW-Clean up to bill unbilled NON-SERVICE CONNECTED copays ;12/12/02
2 ;;7.0;OUTPATIENT PHARMACY;**123**;DEC 1997
3 ;External reference to ^XUSEC supported by DBIA 10076
4 ;External reference to ^IBAM(354.7 supported by DBIA 3877
5 S ZTDTH=""
6 I $D(ZTQUEUED) S ZTDTH=$H
7 L +^XTMP("PSOCPIB3"):0 I '$T D Q
8 . I ZTDTH="" D BMES^XPDUTL("Clean up job is already running. Halting...")
9 L -^XTMP("PSOCPIB3")
10 I ZTDTH="" D
11 .D BMES^XPDUTL("Clean up for unbilled, released NON-SERVICE CONNECTED prescription fills.")
12 .D BMES^XPDUTL("If no start date/time is entered when prompted, the background job will be ")
13 .D MES^XPDUTL("queued to run NOW.")
14 .D GETDATE
15 .D BMES^XPDUTL("Queuing background job to reprocess unbilled NON-SERVICE CONNECTED fills...")
16 S ZTRTN="EN^PSOCPIB3",ZTIO="",ZTDESC="Background job to reprocess NON-SERVICE CONNECTED unbilled copays" D ^%ZTLOAD K ZTDTH,ZTRTN,ZTIO,ZTDESC
17 W:$D(ZTSK)&('$D(ZTQUEUED)) !!,"Task Queued !",!
18 Q
19EN ;
20 L +^XTMP("PSOCPIB3"):0 I '$T S:$D(ZTQUEUED) ZTREQ="@" Q
21 N PSODT,RXP,PSOTEXT,YY,PSOCNT,PSOSTART,PSOEND
22 S PSOCNT=0
23 D NOW^%DTC S Y=% D DD^%DT S PSOSTART=Y
24 I '$G(DT) S DT=$$DT^XLFDT
25 I '$D(^XTMP("PSOCPIB3")) S X1=DT,X2=+90 D C^%DTC S ^XTMP("PSOCPIB3",0)=$G(X)_"^"_DT
26 I $D(^XTMP("PSOCPBAK")) G PROCESS ; POTENTIALLY BILLABLE FILLS ALREADY IDENTIFIED
27 S PSODT=3020203.235959 ; START WITH DATE $7 COPAY WENT INTO EFFECT
28 F S PSODT=$O(^PSRX("AL",PSODT)) Q:'PSODT S RXP="" F S RXP=$O(^PSRX("AL",PSODT,RXP)) Q:'RXP D
29 .S PSODFN=$P($G(^PSRX(RXP,0)),"^",2) Q:PSODFN="" I '$D(^DPT(PSODFN,0)) Q
30 .I $G(^XTMP("PSOCPBAK",$J,PSODFN)) Q ; EXEMPT OR SC QUESTION APPLIES-- NOTHING TO REPROCESS FOR THIS PATIENT
31 .S BADDT=$G(^XTMP("PSOCPBAK",$J,PSODFN,RXP))
32 .I 'BADDT D CHKLOG^PSOCPBAK
33 .I BADDT,BADDT'>$P(PSODT,".") D
34 ..I '$D(^XTMP("PSOCPBAK",$J,PSODFN)) D XTYPE^PSOCPBAK S ^XTMP("PSOCPBAK",$J,PSODFN)=$S(PSOSCMX=1:"",1:1) I PSOSCMX'=1 Q ; QUIT IF SC QUESTION APPLIES -- NOTHING TO REPROCESS
35 ..S YY="" F S YY=$O(^PSRX("AL",PSODT,RXP,YY)) Q:YY="" D
36 ...S PSOREL=$S(YY=0:$P(^PSRX(RXP,2),"^",13),1:$P($G(^PSRX(RXP,1,YY,0)),"^",18)) I 'PSOREL Q ; RELEASED DATE WON'T BE PRESENT IF RETURNED TO STOCK
37 ...I 'YY I $P($G(^PSRX(RXP,"IB")),"^",2)'="" Q ; ALREADY BILLED
38 ...I 'YY I $P($G(^PSRX(RXP,"IB")),"^",4)'="" Q ; ALREADY BILLED (POTENTIAL BILL - EXCEEDED ANNUAL CAP)
39 ...I YY,$P($G(^PSRX(RXP,1,YY,"IB")),"^",1)'="" Q ; REFILL ALREADY BILLED
40 ...I YY,$P($G(^PSRX(RXP,1,YY,"IB")),"^",2)'="" Q ; REFILL ALREADY BILLED (POTENTIAL BILL - EXCEEDED ANNUAL CAP)
41 ...S PSOXIN=$$RXST^IBARXEU(PSODFN,$P(PSOREL,".")) I $P($G(PSOXIN),"^")=1 Q ; INCOME EXEMPT ON RELEASE DATE
42 ...I '$D(^XTMP("PSOCPBAK",$J,PSODFN,RXP)) S ^XTMP("PSOCPBAK",$J,PSODFN,RXP)=BADDT
43 ...S ^XTMP("PSOCPBAK",$J,PSODFN,RXP,YY)=$P(PSOREL,".") ; SAVE TO PROCESS IN "BILL" SECTION
44PROCESS ;
45 S PSOJ=0 F S PSOJ=$O(^XTMP("PSOCPBAK",PSOJ)) Q:'PSOJ D BILL
46 D MAIL
47 D MAIL2
48 L -^XTMP("PSOCPIB3")
49 S:$D(ZTQUEUED) ZTREQ="@"
50 Q
51 ;
52MAIL ;
53 D NOW^%DTC S Y=% D DD^%DT S PSOEND=Y
54 I $G(DUZ) S XMY(DUZ)=""
55 S XMDUZ="Outpatient Pharmacy",XMSUB="Outpatient Pharmacy Copay Clean-up"
56 F PSOCXPDA=0:0 S PSOCXPDA=$O(^XUSEC("PSO COPAY",PSOCXPDA)) Q:'PSOCXPDA S XMY(PSOCXPDA)=""
57 I $O(XMY(""))="" Q ; no recipients for mail message
58 S PSOTEXT(1)="The Rx copay clean up job for the Outpatient Pharmacy patch (PSO*7*123)"
59 S PSOTEXT(2)="started "_PSOSTART_" and completed "_PSOEND_"."
60 I PSOCNT>0 S PSOTEXT(3)="Released non-service connected prescriptions have now been reprocessed."
61 I PSOCNT>0 S PSOTEXT(4)="There were "_PSOCNT_" fills successfully billed." D
62 .S PSOTEXT(5)=" "
63 .S PSOTEXT(6)="To get a report of patient names/prescriptions that were billed as part of this"
64 .S PSOTEXT(7)="clean-up, enter D RPT^PSOCPIB3 at the programmer's prompt."
65 I PSOCNT=0 S PSOTEXT(3)="No released unbilled copay fills were found to reprocess."
66 S XMTEXT="PSOTEXT(" N DIFROM D ^XMD K XMDUZ,XMTEXT,XMSUB
67 Q
68 ;
69MAIL2 ; SEND NAME INFO FOR USE BY AAC
70 K XMY,PSOTEXT
71 S PSOCNT=0
72 S PSOINST=$P($G(^DIC(4,+$P($G(^XMB(1,1,"XUS")),"^",17),99)),"^")
73 S XMY(DUZ)=""
74 S XMY("WHITE.ELAINE@FORUM.VA.GOV")=""
75 S XMY("CARROLL.DAN@FORUM.VA.GOV")=""
76 S XMDUZ="PSO*7*123",XMSUB=$G(PSOINST)_" - AAC DATA"
77 S PSONAM="" F S PSONAM=$O(^XTMP("PSOCPIB3",$J,"BILLED",PSONAM)) Q:PSONAM="" S PSODFN="" F S PSODFN=$O(^XTMP("PSOCPIB3",$J,"BILLED",PSONAM,PSODFN)) Q:PSODFN="" D
78 .S DFN=PSODFN D DEM^VADPT
79 .S PSOCNT=PSOCNT+1,PSOTEXT(PSOCNT)=PSOINST_"^"_$G(VA("BID"))_$E($P(PSONAM,","),1,5)
80 I '$D(PSOTEXT) S PSOTEXT(1)="NO BILLED FILLS FOR INSTITUTION: "_PSOINST
81 S XMTEXT="PSOTEXT(" N DIFROM D ^XMD K XMDUZ,XMTEXT,XMSUB
82 Q
83 ;
84BILL ;
85 ; IF NO IB NUMBER FOR THIS FILL, SET UP VARIABLES AND CALL CP^PSOCP. IF THERE IS AN IB NUMBER AFTER THIS CALL, COUNT IT FOR SUMMARY MAIL MSG
86 S PSODFN="" F S PSODFN=$O(^XTMP("PSOCPBAK",PSOJ,PSODFN)) Q:'PSODFN D
87 .I $G(^XTMP("PSOCPBAK",PSOJ,PSODFN)) Q ; EXEMPT OR SC QUESTION APPLIES
88 .S PSOCAP(302)=0
89 .S PSOCAP(303)=0
90 .S RXP="" F S RXP=$O(^XTMP("PSOCPBAK",PSOJ,PSODFN,RXP)) Q:'RXP S YY="" F S YY=$O(^XTMP("PSOCPBAK",PSOJ,PSODFN,RXP,YY)) Q:YY="" D
91 ..S PSOREL=$G(^XTMP("PSOCPBAK",PSOJ,PSODFN,RXP,YY))
92 ..S PSOCPUN=$P(($P(^PSRX(RXP,0),"^",8)+29)/30,".",1) ; NUMBER OF 30-DAY UNITS ELIGIBLE TO BILL
93 ..S PSOSVUN=PSOCPUN
94 ..D CHKTOT
95 ..I PSOCAP($E(PSOREL,1,3)) Q ; ANNUAL CAP MET
96 ..I 'YY D Q
97 ...I $P($G(^PSRX(RXP,"IB")),"^",2)'="" Q ; ALREADY BILLED
98 ...D SITE^PSOCPBA2
99 ...D CP^PSOCP
100 ...S PSOBILL=$P($G(^PSRX(RXP,"IB")),"^",2) I PSOBILL'="" D
101 ....S PSONAM=$P($G(^DPT(PSODFN,0)),"^") I PSONAM="" S PSONAM="UNKNOWN"
102 ....S PSORXP=$P($G(^PSRX(RXP,0)),"^") I PSORXP="" Q
103 ....S PSOCNT=PSOCNT+1
104 ....S ^XTMP("PSOCPIB3",$J,"BILLED",PSONAM,PSODFN,PSORXP,YY)=$P(PSOREL,".")
105 ....D ACCUM
106 ..I $P($G(^PSRX(RXP,1,YY,"IB")),"^",1)="" D ; REFILL LEVEL
107 ...D SITE^PSOCPBA2
108 ...D CP^PSOCP
109 ...S PSOBILL=$P($G(^PSRX(RXP,1,YY,"IB")),"^",1) I PSOBILL'="" D
110 ....S PSONAM=$P($G(^DPT(PSODFN,0)),"^") I PSONAM="" S PSONAM="UNKNOWN"
111 ....S PSORXP=$P($G(^PSRX(RXP,0)),"^") I PSORXP="" Q
112 ....S PSOCNT=PSOCNT+1
113 ....S ^XTMP("PSOCPIB3",$J,"BILLED",PSONAM,PSODFN,PSORXP,YY)=$P(PSOREL,".")
114 ....D ACCUM
115 Q
116 ;
117GETDATE ; GET DATE/TIME OF WHEN BACKGROUND JOB SHOULD BE RUN
118 S PSOQUES="Queue copay clean-up Job to run Date@Time: "
119 D GETDATE^PSOCPIB4
120 Q
121 ;
122RPT ;
123 L +^XTMP("PSOCPIB3"):0 I '$T D Q
124 . W !,"Clean up job for PSO*7*123 is still running. Halting..."
125 L -^XTMP("PSOCPIB3")
126 W !!,"This report shows the patient name and prescription information for fills"
127 W !,"that were billed as part of patch PSO*7*123 clean-up."
128 W !!,"You may queue the report to print, if you wish.",!
129 ;
130DVC K %ZIS,POP,IOP S %ZIS="QM" D ^%ZIS I $G(POP) W !!,"Nothing queued to print.",! G DONE
131QUEUE I $D(IO("Q")) S ZTRTN="START^PSOCPIB3",ZTDESC="Billed copay report" D ^%ZTLOAD K %ZSI W !,"Report queued to print.",! G DONE
132START ;
133 U IO
134 S PSOOUT=0,PSODV=$S($E(IOST)="C":"C",1:"P")
135 S PSOPGCT=0,PSOPGLN=IOSL-7,PSOPGCT=1
136 D TITLE
137 S PSOJ=0
138 F S PSOJ=$O(^XTMP("PSOCPIB3",PSOJ)) Q:PSOJ="" S PSONAM="" F S PSONAM=$O(^XTMP("PSOCPIB3",PSOJ,"BILLED",PSONAM)) Q:PSONAM="" S PSODFN="" F S PSODFN=$O(^XTMP("PSOCPIB3",PSOJ,"BILLED",PSONAM,PSODFN)) Q:PSODFN="" D
139 .W !
140 .S RXP="" F S RXP=$O(^XTMP("PSOCPIB3",PSOJ,"BILLED",PSONAM,PSODFN,RXP)) Q:RXP="" S PSOFILL="" F S PSOFILL=$O(^XTMP("PSOCPIB3",PSOJ,"BILLED",PSONAM,PSODFN,RXP,PSOFILL)) Q:PSOFILL="" D
141 ..N XX
142 ..S XX=$G(^XTMP("PSOCPIB3",PSOJ,"BILLED",PSONAM,PSODFN,RXP,PSOFILL)) D
143 ...D FULL Q:$G(PSOOUT) W !,PSONAM D PRTSSN
144 ...W ?39," ",RXP," (",PSOFILL,")" D
145 ....S Y=XX I Y>0 X ^DD("DD")
146 ....W ?65," ",Y
147 G END
148 ;
149FULL ;
150 I ($Y+7)>IOSL&('$G(PSOOUT)) D TITLE
151 Q
152 ;
153TITLE ;
154 I $G(PSODV)="C",$G(PSOPGCT)'=1 W ! K DIR S DIR(0)="E" D ^DIR K DIR I 'Y S PSOOUT=1 Q
155 ;
156 W @IOF D
157 . W !,"Patch PSO*7*123 -COPAY PRESCRIPTION FILLS BILLED"
158 S Y=DT X ^DD("DD") W !,"Date printed: ",Y,?70,"Page: ",PSOPGCT,!
159 F MJT=1:1:79 W "="
160 W !,"PATIENT NAME (SSN) DIV",?40,"RX# (FILL)",?66,"RELEASE DATE"
161 W !,"------------------------",?40,"----------",?66,"------------"
162 S PSOPGCT=PSOPGCT+1
163 Q
164END ;
165 I '$G(PSOOUT),$G(PSODV)="C" W !!,"** End of Report **" K DIR S DIR(0)="E",DIR("A")="Press Return to continue" D ^DIR K DIR
166 I $G(PSODV)="C" W !
167 E W @IOF
168DONE ;
169 K MJT,PSOPGCT,PSOPGLN,Y,DIR,X,IOP,POP,IO("Q"),DIRUT,DUOUT,DTOUT
170 D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
171 Q
172 ;
173PRTSSN ;
174 N DFN
175 S DFN=PSODFN D PID^VADPT
176 S PSORXP=$O(^PSRX("B",RXP,"")) I PSORXP="" Q
177 S PSODIV=$P($G(^PSRX(PSORXP,2)),"^",9) S:PSODIV'="" PSODIV=$P($G(^PS(59,PSODIV,0)),"^",1)
178 W " ("_$G(VA("BID"))_")"_" "_PSODIV
179 Q
180 ;
181ACCUM ; ACCUMULATE TOTALS AND SEE IF PATIENT MET ANNUAL CAP
182 S PSOYR=$E(PSOREL,1,3)
183 S PSOCPUN=PSOSVUN
184 I PSOYR'=302,PSOYR'=303 Q
185 S PSOTOT=$G(^XTMP("PSOCPIB3",$J,PSODFN,PSOYR))
186 S ^XTMP("PSOCPIB3",$J,PSODFN,PSOYR)=PSOTOT+(PSOCPUN*7)
187 Q
188 ;
189CHKTOT ; SEE IF BILLING THIS FILL WOULD GO OVER CAP
190 S PSOYR=$E(PSOREL,1,3)
191 I PSOYR'=302,PSOYR'=303 Q
192 S PSOTOT=$G(^XTMP("PSOCPIB3",$J,PSODFN,PSOYR))
193 I 'PSOTOT D S ^XTMP("PSOCPIB3",$J,PSODFN,PSOYR)=PSOTOT
194 .S PSOSQ=0 F S PSOSQ=$O(^IBAM(354.7,PSODFN,1,PSOSQ)) Q:'PSOSQ S PSOLOG=$G(^IBAM(354.7,PSODFN,1,PSOSQ,0)) I $E(PSOLOG,1,3)=PSOYR D
195 ..I $E(PSOLOG,1,5)="30201" Q ; DON'T LOOK AT JANUARY 2002 TOTALS
196 ..S PSOTOT=PSOTOT+$P(PSOLOG,"^",2)
197 I PSOYR=302,PSOTOT+(7*PSOCPUN)>770 S PSOCAP(PSOYR)=1 Q ; BILLING FOR THIS WOULD EXCEED ANNUAL CAP
198 I PSOYR=303,PSOTOT+(7*PSOCPUN)>840 S PSOCAP(PSOYR)=1 Q ; BILLING FOR THIS WOULD EXCEED ANNUAL CAP
199 Q
200 ;
Note: See TracBrowser for help on using the repository browser.