source: WorldVistAEHR/trunk/r/CMOP-PSX/PSXRPPL.m@ 823

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

initial load of WorldVistAEHR

File size: 9.1 KB
Line 
1PSXRPPL ;BIR/WPB,BAB-Gathers data for the CMOP Transmission ;13 Mar 2002 10:31 AM
2 ;;2.0;CMOP;**3,23,33,28,40,42,41,48,62,58**;11 Apr 97;Build 2
3 ;Reference to ^PS(52.5, supported by DBIA #1978
4 ;Reference to ^PSRX( supported by DBIA #1977
5 ;Reference to ^PSOHLSN1 supported by DBIA #2385
6 ;Reference to ^PSORXL supported by DBIA #1969
7 ;Reference to ^PSOLSET supported by DBIA #1973
8 ;Reference to %ZIS(1 supported by DBIA #290
9 ;Reference to %ZIS(2 supported by DBIA #2247
10 ;Reference to ^PSSLOCK supported by DBIA #2789
11 ;Reference to ^XTMP("ORLK-" supported by DBIA #4001
12 ;Reference to ^PSOBPSUT supported by DBIA #4701
13 ;Reference to ^PSOREJUT supported by DBIA #4706
14 ;Reference to ^BPSUTIL supported by DBIA #4410
15 ;Called from PSXRSUS -Builds ^PSX(550.2,,15,"C" , and returns to PSXRSUS or PSXRTRAN
16 ;
17SDT K ^TMP($J,"PSX"),^TMP($J,"PSXDFN"),ZCNT,PSXBAT D:$D(XRTL) T0^%ZOSV
18 S PSXTDIV=PSOSITE,PSXTYP=$S(+$G(PSXCS):"C",1:"N")
19 ;
20 ; - Submitting prescriptions to ECME (Electronic Claims Mgmt Engine) - 3rd pary
21 I $$ECMEON^BPSUTIL(PSXTDIV),$$CMOPON^BPSUTIL(PSXTDIV) D
22 . N BPSCNT S BPSCNT=$$SBTECME^PSXRPPL1(PSXTYP,PSXTDIV,PRTDT,PSXDTRG)
23 . ; - Wait 15 seconds per prescription sent to ECME (max of 2 hours)
24 . I BPSCNT>0 H 60+$S((BPSCNT*15)>7200:7200,1:(BPSCNT*15))
25 ;
26 ; - Transmitting prescription to CMOP (up to THROUGH DATE)
27 K ^TMP("PSXEPHIN",$J)
28 S SDT=0 F S SDT=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT)) S XDFN=0 Q:(SDT>PRTDT)!(SDT'>0) D
29 . F S XDFN=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,XDFN)) S REC=0 Q:(XDFN'>0)!(XDFN="") D
30 . . F S REC=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,XDFN,REC)) Q:(REC'>0)!(REC="") D
31 . . . D GETDATA D:$G(RXN) PSOUL^PSSLOCK(RXN),OERRLOCK(RXN)
32 ;
33 ; - Pulling prescriptions ahead (parameter in OUTPATIENT SITE file #59)
34 I $G(PSXBAT),'$G(PSXRTRAN) D CHKDFN
35 ;
36 ; - Sends a Mailman message if there were transmission problems with the 3rd Party Payer
37 I $D(^TMP("PSXEPHIN",$J)) D ^PSXBPSMS K ^TMP("PSXEPHIN",$J)
38 ;
39EXIT ;
40 K SDT,DFN,REC,RXNUM,PSXOK,FILNUM,REF,PNAME,CNAME,DIE,DR,NDFN,%,CNT,COM,DTTM,FILL,JJ,PRTDT,PSXDIV,XDFN,NFLAG,CIND,XDFN
41 K CHKDT,DAYS,DRUG,DRUGCHK,NM,OPDT,PHARCLK,PHY,PSTAT,PTRA,PTRB,QTY,REL,RXERR,RXF,SFN,PSXDGST,PSXMC,PSXMDT
42 S:$D(XRT0) XRTN=$T(+0) D:$D(XRT0) T1^%ZOSV
43 K ^TMP("PSXEPHIN",$J)
44 Q
45GETDATA ;Screens rxs and builds data
46 ;PSXOK=1:NOT CMOP DRUG OR DO NOT MAIL,2:TRADENAME,3:WINDOW,4:PRINTED,5:NOT SUSPENDED
47 ;PSXOK=6:ALREADY RELEASED,7:DIFFERENT DIVISION,8:BAD DATA IN 52.5
48 ;9:CS Mismatch,10:DEA 1 or 2
49 I '$D(^PS(52.5,REC,0)) K ^PS(52.5,"AQ",SDT,XDFN,REC),^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,XDFN,REC) Q
50 I $P(^PS(52.5,REC,0),"^",7)="" K ^PS(52.5,"AQ",SDT,XDFN,REC),^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,XDFN,REC) Q
51 I ($P(^PS(52.5,REC,0),"^",3)'=XDFN) K ^PS(52.5,"AQ",SDT,XDFN,REC),^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,XDFN,REC) Q
52 N DFN S DFN=XDFN D DEM^VADPT
53 I $G(VADM(6))'="" D DELETE K VADM Q
54 S PSXOK=0,NFLAG=0
55 S RXN=$P($G(^PS(52.5,REC,0)),"^",1) I RXN="" S PSXOK=8 Q
56 S RFL=+$$GET1^DIQ(52.5,REC,9,"I")
57 I '$D(^TMP($J,"PSXBAI",DFN)) D
58 .S PSXGOOD=$$ADDROK^PSXMISC1(RXN)
59 .I 'PSXGOOD S PSXFIRST=1 D I 'PSXFIRST S PSXOK=8
60 ..D CHKACT^PSXMISC1(RXN)
61 I PSXOK=8 K RXN Q
62 ;
63 N EPHQT S EPHQT=0
64 I $$PATCH^XPDUTL("PSO*7.0*148") D I EPHQT Q
65 . I $$DOUBLE^PSXRPPL1(RXN,RFL) S EPHQT=1 Q
66 . I $$RETRX^PSOBPSUT(RXN,RFL),SDT>DT S EPHQT=1 Q
67 . I $$FIND^PSOREJUT(RXN,RFL) S EPHQT=1 Q
68 . I $$STATUS^PSOBPSUT(RXN,RFL)="IN PROGRESS" D Q
69 . . S ^TMP("PSXEPHIN",$J,$$RXSITE^PSOBPSUT(RXN),RXN)=RFL,EPHQT=1
70 ;
71 D CHKDATA^PSXMISC1
72SET Q:(PSXOK=7)!(PSXOK=8)!(PSXOK=9)
73 S PNAME=$G(VADM(1))
74 I ($G(PSXCSRX)=1)&($G(PSXCS)=1) S ^XTMP("PSXCS",PSOSITE,DT,RXN)=""
75 I (PSXOK=0)&(PSXFLAG=1) S ^TMP($J,"PSXDFN",XDFN)="",NFLAG=4 D DQUE,RX550215 Q
76 I (PSXOK=0)&(PSXFLAG=2) D RX550215 Q
77 I (PSXOK>0)&(PSXOK<7)!(PSXOK=10) D DELETE Q
78 Q
79DELETE ; deletes the CMOP STATUS field in PS(52.5, reindex 'AC' x-ref
80 L +^PS(52.5,REC):600 Q:'$T
81 N DR,DIE,DA S DIE="^PS(52.5,",DA=REC,DR="3///@" D ^DIE
82 S ^PS(52.5,"AC",$P(^PS(52.5,REC,0),"^",3),$P(^PS(52.5,REC,0),"^",2),REC)=""
83 L -^PS(52.5,REC)
84 Q
85 ;the rest of the sub-routines go through the ^PSX(550.2,,15,"C"
86 ;global and checks for RXs within the days ahead range and
87 ;builds the ^PSX(550.2,PSXBAT,
88CHKDFN ; use the patient 'C' index under RX multiple in file 550.2 to GET dfn to gather Patients' future RXs
89 I '$D(^PSX(550.2,PSXBAT,15,"C")) Q
90 S PSXPTNM="" F S PSXPTNM=$O(^PSX(550.2,PSXBAT,15,"C",PSXPTNM)) Q:PSXPTNM="" D
91 . S XDFN=0 F S XDFN=$O(^PSX(550.2,PSXBAT,"15","C",PSXPTNM,XDFN)) Q:(XDFN'>0) D
92 . . S SDT=PRTDT F S SDT=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT)),NDFN=0 Q:(SDT>PSXDTRG)!(SDT="") D
93 . . . F S NDFN=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,NDFN)),REC=0 Q:NDFN'>0 I NDFN=XDFN D
94 . . . . F S REC=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,NDFN,REC)) Q:REC'>0 D
95 . . . . . D GETDATA D:$G(RXN) PSOUL^PSSLOCK(RXN),OERRLOCK(RXN)
96 Q
97BEGIN ; Select print device
98 I '$D(PSOPAR) D ^PSOLSET
99 I $D(PSOLAP),($G(PSOLAP)'=ION) S PSLION=PSOLAP G PROFILE
100 W ! S %ZIS("A")="PRINTER 'LABEL' DEVICE: ",%ZIS("B")="",%ZIS="MQN" D ^%ZIS S PSLION=ION G:POP EXIT
101 I $G(IOST)["C-" W !,"You must select a printer!",! G BEGIN
102 F J=0,1 S @("PSOBAR"_J)="" I $D(^%ZIS(2,^%ZIS(1,IOS,"SUBTYPE"),"BAR"_J)) S @("PSOBAR"_J)=^("BAR"_J)
103 S PSOBARS=PSOBAR1]""&(PSOBAR0]"")&$P(PSOPAR,"^",19)
104 K PSOION,J D ^%ZISC I $D(IO("Q")) K IO("Q")
105PROFILE I $D(PSOPROP),($G(PSOPROP)'=ION) Q
106 I $P(PSOPAR,"^",8) S %ZIS="MNQ",%ZIS("A")="Select PROFILE PRINTER: " D ^%ZIS K %ZIS,IO("Q"),IOP G:POP EXIT S PSOPROP=ION D ^%ZISC
107 I $G(PSOPROP)=ION W !,"You must select a printer!",! G PROFILE
108 Q
109PRT ; w auto error trapping
110 D NOW^%DTC S DTTM=% K %
111 S NM="" F S NM=$O(^PSX(550.2,PSXBAT,15,"C",NM)) Q:NM="" D DFN,PPL ;gather patient RXs, print patient RXs
112 S DIK="^PSX(550.2,",DA=PSXBAT D ^DIK K PSXBAT
113 K CHKDT,CIND,DAYS,DRUG,DRUGCHK,NFLAG,NM,ORD,PDT,PHARCLK,PHY,PSTAT,PTRA,PTRB,QTY,REL,RXERR,RXF,SFN,SIG,SITE,SUS,SUSPT
114 Q
115DFN S DFN=0,NFLAG=2
116 F S DFN=$O(^PSX(550.2,PSXBAT,15,"C",NM,DFN)),RXN=0 Q:(DFN="")!(DFN'>0) D
117 .F S RXN=$O(^PSX(550.2,PSXBAT,15,"C",NM,DFN,RXN)),RXF="" Q:(RXN="")!(RXN'>0) D
118 ..F S RXF=$O(^PSX(550.2,PSXBAT,15,"C",NM,DFN,RXN,RXF)) Q:RXF="" D BLD
119 Q
120BLD ;
121 S BATRXDA=$O(^PSX(550.2,PSXBAT,15,"B",RXN,0)) D NOW^%DTC S DTTM=%
122 S REC=$P(^PSX(550.2,PSXBAT,15,BATRXDA,0),U,5),SUS=$O(^PS(52.5,"B",RXN,0))
123 I SUS=REC,+SUS'=0 I 1 ;rx still valid in suspense
124 E D Q ;rx gone
125 . N DA,DIK S DIK=550.2,DA(1)=PSXBAT,DA=BATRXDA
126 . D ^DIK
127 S PSOSU(DFN,SUS)=RXN,RXCNTR=$G(RXCNTR)+1,NFLAG=2
128 S $P(^PSRX(RXN,0),U,15)=0,$P(^PSRX(RXN,"STA"),U,1)=0
129 K % S COM="CMOP Suspense Label "_$S($G(^PS(52.5,SUS,"P"))=0:"Printed",$G(^PS(52.5,SUS,"P"))="":"Printed",1:"Reprinted")_$S($G(^PSRX(RXN,"TYPE"))>0:" (PARTIAL)",1:"")
130 D EN^PSOHLSN1(RXN,"SC","ZU",COM)
131 S DA=SUS D DQUE K DA
132ACTLOG F JJ=0:0 S JJ=$O(^PSRX(RXN,"A",JJ)) Q:'JJ S CNT=JJ
133 S RFCNT=0 F RF=0:0 S RF=$O(^PSRX(RXN,1,RF)) Q:'RF S RFCNT=$S(RF<6:RF,1:RF+1)
134 S CNT=CNT+1,^PSRX(RXN,"A",0)="^52.3DA^"_CNT_"^"_CNT
135LOCK L +^PSRX(RXN):600 G:'$T LOCK
136 S ^PSRX(RXN,"A",CNT,0)=DTTM_"^S^"_DUZ_"^"_RFCNT_"^"_COM L -^PSRX(RXN)
137 K CNT,COM,RFCNT,%,JJ,RF,Y,RXCNTR
138 Q
139PPL K PPL,PPL1 S ORD="" F S ORD=$O(PSOSU(ORD)) Q:(ORD="")!(ORD'>0) D PPL1
140 Q
141PPL1 ; print patient labels
142 F SFN=0:0 S SFN=$O(PSOSU(ORD,SFN)) Q:'SFN D
143 . S:$L($G(PPL))<240 PPL=$P(PSOSU(ORD,SFN),"^")_","_$G(PPL)
144 . S:$L($G(PPL))>239 PPL1=$P(PSOSU(ORD,SFN),"^")_","_$G(PPL1)
145 . S DFN=$P(^PS(52.5,SFN,0),"^",3)
146 S SUSPT=1,PSNP=$S($P(PSOPAR,"^",8):1,1:0) S:$D(PSOPROP) PFIO=PSOPROP
147 D QLBL^PSORXL
148 I $D(PPL1) S PSNP=0,PPL=PPL1 D QLBL^PSORXL
149 K PPL,PPL1,PSOSU(ORD)
150 Q
151DQUE ; sets the CMOP indicator field, and printed field in 52.5
152 L +^PS(52.5,REC):600 G:'$T DQUE
153 I NFLAG=4 D
154 . S DA=REC,DIE="^PS(52.5,",DR="3////L;4////"_DT D ^DIE K DIE,DA,DR L -^PS(52.5,REC) ; the rest moved into PSXRTR
155 S CIND=$S(NFLAG=1:"X",NFLAG=2:"P",NFLAG=3:"@",1:0)
156 I $G(NFLAG)'=2 D
157 .S DA=REC,DIE="^PS(52.5,",DR="3////"_CIND_";4////"_DT
158 .D ^DIE K DIE,DA,DR
159 .S ^PS(52.5,REC,"P")=1,^PS(52.5,"ADL",DT,REC)=""
160 I $G(NFLAG)=2 D ;print label cycle
161 . S DA=REC,DIE="^PS(52.5,",DR="3////"_CIND_";4////"_DTTM_";5////"_DUZ_";7////"_RXCNTR
162 . D ^DIE K DIE,DA,DR
163 . S ^PS(52.5,REC,"P")=1,^PS(52.5,"ADL",$E($P(^PS(52.5,REC,0),"^",8),1,7),REC)=""
164 L -^PS(52.5,REC)
165 I $G(NFLAG)=2 D EN^PSOHLSN1(RXN,"SC","ZU","CMOP Suspense Label Printed")
166 Q
167RX550215 ; put RX into RX multiple TRANS 550.215 for PSXBAT
168 I '$G(PSXBAT) D BATCH^PSXRSYU ; first time through create batch, & return PSXBAT
169 K DD,DO,DIC,DA,DR,D0
170 S:'$D(^PSX(550.2,PSXBAT,15,0)) ^PSX(550.2,PSXBAT,15,0)="^550.215P^^"
171 S X=RXN,DA(1)=PSXBAT
172 S DIC="^PSX(550.2,"_PSXBAT_",15,",DIC("DR")=".02////^S X=RXF;.03////^S X=DFN;.05////^S X=REC",DIC(0)="ZF"
173 D FILE^DICN
174 S PSXRXTDA=+Y ;RX DA within PSXBAT 'T'ransmission
175 K DD,DO,DIC,DA,DR,D0
176 Q
177OERRLOCK(RXN) ; set XTMP for OERR/CPRS order locking
178 I $G(PSXBAT),$G(RXN),$G(PSXRXTDA) I 1
179 E Q
180 I $P(^PSX(550.2,PSXBAT,15,PSXRXTDA,0),U,1)'=RXN Q
181RXNSET ; set ^XTMP("ORLK-"_ORDER per IA 4001 needs RXN
182 Q:'$G(RXN)
183 N ORD,NOW,NOW1 S ORD=+$P($G(^PSRX(+$G(RXN),"OR1")),"^",2)
184 Q:'ORD
185 S NOW=$$NOW^XLFDT,NOW1=$$FMADD^XLFDT(NOW,1)
186 S ^XTMP("ORLK-"_+ORD,0)=NOW1_U_NOW_"^CPRS/CMOP RX/Order Lock",^(1)=DUZ_U_$J
187 Q
188RXNCLEAR ; needs RXN
189 Q:'$G(RXN)
190 N ORD S ORD=+$P($G(^PSRX(+$G(RXN),"OR1")),"^",2) Q:'ORD
191 I $D(^XTMP("ORLK-"_ORD,0)),^(0)["CPRS/CMOP" K ^XTMP("ORLK-"_ORD)
192 Q
Note: See TracBrowser for help on using the repository browser.