source: WorldVistAEHR/trunk/r/E_CLAIMS_MGMT_ENGINE-BPS/BPSOSU.m@ 1211

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

initial load of WorldVistAEHR

File size: 8.7 KB
RevLine 
[613]1BPSOSU ;BHAM ISC/FCS/DRS/FLS - Common utilities ;06/01/2004
2 ;;1.0;E CLAIMS MGMT ENGINE;**1,2,5**;JUN 2004;Build 45
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 Q
5 ; Common utilities called a lot.
6 ;
7 ; SETSTAT - set status field for ^BPST(IEN59,
8 ; Input:
9 ; IEN59 - BPS Transaction
10 ; STATUS - Value to set into BPS Transaction
11SETSTAT(IEN59,STATUS) ; EP - from many places
12 ;
13 ; In case there is a timing problem, make sure the Status is not
14 ; already more than the requested status
15 I STATUS'=0,$P(^BPST(IEN59,0),U,2)>STATUS Q
16 ;
17 ; Lock the record - something is very wrong if you can't get the lock
18 F L +^BPST(IEN59):300 Q:$T Q:'$$IMPOSS^BPSOSUE("L","RTI","LOCK +^BPST",,"SETSTAT",$T(+0))
19 N DIE,DA,DR,X
20 S DIE=9002313.59,DA=IEN59,DR="1///"_STATUS_";7///NOW" ; Status and Last Update
21 I STATUS=0 S DR=DR_";15///NOW" ; If Status is 0, init START TIME
22 D ^DIE
23 ;
24 ; Verify that there no other statuses in the X-ref
25 S X=""
26 F S X=$O(^BPST("AD",X)) Q:X="" D
27 . I X'=STATUS K ^BPST("AD",X,IEN59)
28 I STATUS=99 D STATUS99(IEN59)
29 L -^BPST(IEN59)
30 Q
31 ;
32 ; STATUS99 - Special activity when a claim reaches status 99
33 ; Input:
34 ; IEN59 - BPS Transaction IEN
35STATUS99(IEN59) ;
36 N CLMSTAT,BPS57
37 ;
38 ; Get status of the claim
39 S CLMSTAT=$$CATEG^BPSOSUC(IEN59)
40 ;
41 S BPS57=$$NEW57(IEN59)
42 D LOG^BPSOSL(IEN59,$T(+0)_"-Created BPS Log of Transaction record "_BPS57)
43 ;
44 ; If claims completed normally, log its completion.
45 ; Do not log error'ed or stranded claims as we don't want to show these in the
46 ; turn-around stats
47 ; Needed for Turn-Around Stats - Do NOT delete/alter!!
48 I CLMSTAT'["E OTHER",CLMSTAT'["E STRANDED",CLMSTAT'["E REVERSAL STRANDED" D LOG^BPSOSL(IEN59,$T(+0)_"-Claim Complete")
49 ;
50 ; If the Reverse Then Resubmit field is set to Resubmitting (2),
51 ; then set to 'Done' (0)
52 I $P(^BPST(IEN59,1),U,12)=2 S $P(^BPST(IEN59,1),U,12)=0
53 ;
54 ; If resubmit flag is set to 'Reverse, then Resubmit' (1), see about
55 ; doing a resubmit
56 I $P(^BPST(IEN59,1),U,12)=1 D
57 . ;
58 . ; Initialize variables
59 . N SKIP,SITE
60 . D LOG^BPSOSL(IEN59,$T(+0)_"-Reverse then Resubmit attempt")
61 . ;
62 . ; Initialize the skip flag
63 . S SKIP=0
64 . ;
65 . ; Get Site info and make sure it exists
66 . S SITE=$P(^BPST(IEN59,1),U,4)
67 . I '$G(SITE) D
68 .. D LOG^BPSOSL(IEN59,$T(+0)_" Cannot - No site information")
69 .. S SKIP=1
70 . ;
71 . ; Check the ECME switch for the site
72 . I $G(SITE),'$$ECMEON^BPSUTIL(SITE) D
73 .. D LOG^BPSOSL(IEN59,$T(+0)_" Cannot - ECME switch is off for the site")
74 .. S SKIP=1
75 . ;
76 . ; If reversal was not successful, log message and quit
77 . I CLMSTAT'="E REVERSAL ACCEPTED" D
78 .. D LOG^BPSOSL(IEN59,$T(+0)_" Cannot - Reversal failed - "_CLMSTAT)
79 .. S SKIP=1
80 . ;
81 . ; Check if the MOREDATA array is defined
82 . I '$D(^XTMP("BPSOSRB","MOREDATA",IEN59,"RESUB")) D
83 .. D LOG^BPSOSL(IEN59,$T(+0)_" Cannot - MOREDATA array undefined")
84 .. S SKIP=1
85 . ;
86 . ; If skip flag is set, clear the resubmit flag and kill the temp global
87 . ; Else resubmit the claim
88 . I SKIP D
89 .. S $P(^BPST(IEN59,1),U,12)=0
90 .. K ^XTMP("BPSOSRB","MOREDATA",IEN59)
91 . E D
92 .. K MOREDATA
93 .. M MOREDATA=^XTMP("BPSOSRB","MOREDATA",IEN59,"RESUB")
94 .. K ^XTMP("BPSOSRB","MOREDATA",IEN59)
95 .. ;
96 .. ; Needed for Turn-Around Stats - Do NOT delete/alter!!
97 .. D LOG^BPSOSL(IEN59,$T(+0)_"-Now resubmit")
98 .. D CLAIM^BPSOSRB(IEN59,.MOREDATA)
99 ;
100 ; If the ECME Nightly Background job and CMOP release message are running at the same
101 ; time, there are unreleased RXs that are auto-reversed but then are released by
102 ; CMOP at the same time. Unfortunately, if the auto-reversal is in progress, CMOP
103 ; can not resubmit the claim (due to the queuing issue) so we need to automatically
104 ; submit them here.
105 ; Criteria:
106 ; Status is Reversal Accepted
107 ; RX is released
108 ; Normal Auto-Reversal
109 I CLMSTAT="E REVERSAL ACCEPTED" D
110 . N RX,RXR
111 . S RX=$P(IEN59,"."),RXR=+$E($P(IEN59,".",2),1,4)
112 . I '$$RXRLDT^PSOBPSUT(RX,RXR) Q
113 . N CLAIMIEN,AUTOREV
114 . S CLAIMIEN=$$GET1^DIQ(9002313.59,IEN59,3,"I")
115 . I '$G(CLAIMIEN) Q
116 . S AUTOREV=$$GET1^DIQ(9002313.02,CLAIMIEN,.07,"I")
117 . I $G(AUTOREV)'=1 Q
118 . N BDOS,BRES,BMES,BMSG
119 . D LOG^BPSOSL(IEN59,$T(+0)_"-Submit released auto-reversal")
120 . S BDOS=$$DOSDATE^BPSSCRRS(RX,RXR)
121 . S BRES=$$EN^BPSNCPDP(RX,RXR,BDOS,"ARES")
122 . D LOG^BPSOSL(IEN59,$T(+0)_"-Response from BPSNCPDP: "_BRES)
123 . S BMSG=$P(BRES,U,2),BRES=+BRES
124 . S BMES="Submitted to ECME: Resubmit for released autoreversal"
125 . S BMES=BMES_$S(BRES=1:"-NO SUBMISSION VIA ECME",BRES=4:"-NOT PROCESSED",BRES=5:"-SOFTWARE ERROR",1:"")
126 . D ECMEACT^PSOBPSU1(RX,RXR,BMES,.5)
127 . I BRES=2 D ECMEACT^PSOBPSU1(RX,RXR,"Not ECME Billable: "_BMSG,.5)
128 Q
129 ;
130 ; NEW57 - Copy the BPS Transaction into BPS Log of Transaction
131 ; Input
132 ; IEN59 - BPS Transaction
133 ; Returns
134 ; BPS Log of Transaction IEN
135NEW57(IEN59) ;
136 F L +^BPSTL:300 Q:$T Q:'$$IMPOSS^BPSOSUE("L","RTI","LOCK ^BPSTL",,"NEW57",$T(+0))
137 ;
138 ; Get next record number in BPS Log of Transactions
139NEW57A N N,C
140 S N=$P(^BPSTL(0),U,3)+1
141 S C=$P(^BPSTL(0),U,4)+1
142 S $P(^BPSTL(0),U,3,4)=N_U_C
143 I $D(^BPSTL(N)) G NEW57A ; should never happen
144 L -^BPSTL
145 ;
146 ; Merge BPS Transaction into Log of Transactions
147 M ^BPSTL(N)=^BPST(IEN59)
148 ;
149 ; Indexing - First, fileman indexing
150 D
151 . N DIK,DA S DIK="^BPSTL(",DA=N N N D IX1^DIK
152 ;
153 ; Setup the NON-FILEMAN index on RX and Fill
154 N A,B
155 S A=$P(^BPSTL(N,1),U,11)
156 S B=$P(^BPSTL(N,1),U)
157 S ^BPSTL("NON-FILEMAN","RXIRXR",A,B,N)=""
158 ;
159 ; Quit with the new record number
160 Q N
161 ;
162 ; ISREVES - Is this a reversal claim
163 ; Input
164 ; CLAIMIEN - Pointer to BPS Claims
165 ;
166 ; Return Value
167 ; 1 - Reversal claim
168 ; 0 - Not a reversal claim
169ISREVERS(CLAIM) ;
170 Q $P($G(^BPSC(CLAIM,100)),"^",3)="B2"
171 ;
172 ; SETCSTAT - Set the status for every transaction associated with
173 ; this claim
174SETCSTAT(CLAIM,STATUS) ;
175 N IEN59,INDEX
176 ;
177 ; Determine correct index
178 I $$ISREVERS(CLAIM) S INDEX="AER"
179 E S INDEX="AE"
180 ;
181 ; Loop through the transactions and set the status
182 S IEN59=""
183 F S IEN59=$O(^BPST(INDEX,CLAIM,IEN59)) Q:IEN59="" D SETSTAT(IEN59,STATUS)
184 Q
185 ;
186 ; ERROR - Handle any errors
187 ; Log them into BPS Transactions
188 ; Change status to 99
189 ; Update the LOG
190 ; Increment the statistics
191 ; We should be okay for the resubmit flag since the STATUS
192 ; will be E OTHER instead of E REVERSAL ACCEPTED
193 ; Input
194 ; RTN - Routine reporting the error
195 ; IEN59 - BPS Transaction
196 ; ERROR - Error Number (goes in RESULT CODE)
197 ; ERRTEXT - Error Text (goes in RESULT TEXT)
198 ;
199 ; To prevent conflicts, set the error number to the first digit of
200 ; Status and a unique number for the status.
201ERROR(RTN,IEN59,ERROR,ERRTEXT) ;
202 ;
203 ; Check parameters
204 I '$G(IEN59) Q
205 I '$G(ERROR) S ERROR=0
206 I $G(ERRTEXT)="" S ERRTEXT="ERROR - see LOG"
207 ;
208 ; Set Error and Error Text in BPS Transaction
209 D SETRESU(IEN59,ERROR,ERRTEXT)
210 ;
211 ; Log Message
212 D LOG^BPSOSL(IEN59,RTN_" returned error - "_ERRTEXT)
213 ;
214 ; Update unbillable count in stats
215 D INCSTAT^BPSOSUD("R",1)
216 ;
217 ; Update Status to complete
218 D SETSTAT(IEN59,99)
219 Q
220 ;
221 ; SETRESU - Set Result into ^BPST(IEN59,2)
222 ; Input
223 ; IEN59 - BPS Transaction IEN
224 ; RESULT - Result Code
225 ; TEXT - Result Text. Semi-colons (";") should not in the text data as
226 ; this is used as a separator between current and previous text
227 ; messages. If there is a semi-colon, it is converted to a dash.
228SETRESU(IEN59,RESULT,TEXT) ;
229 ;
230 ; First, store the Result Code
231 S $P(^BPST(IEN59,2),U)=$G(RESULT)
232 ;
233 ; Second, store the Result Text
234 ; Considerations:
235 ; Convert any semi-colons to dashes
236 ; Add semi-colon delimiter if needed
237 ; Truncate data if needed
238 I $G(TEXT)]"" D
239 . N X
240 . S TEXT=$TR(TEXT,";","-")
241 . S X=$P(^BPST(IEN59,2),U,2,99)
242 . I X]"",$E(X)'=";" S X=";"_X
243 . S X=$E(TEXT_X,1,255-$L(RESULT)-1)
244 . S $P(^BPST(IEN59,2),U,2)=X
245 Q
246 ;
247 ; SETCRESU - set the result code for every transaction assoc'd with
248 ; this claim. Note that this will only work for billing requests (B1)
249 ; Input
250 ; CLAIMIEN - BPS Claim IEN
251 ; RESULT - Result Code
252 ; TEXT - Result Text
253SETCRESU(CLAIM,RESULT,TEXT) ;
254 N IEN59
255 S IEN59=""
256 F S IEN59=$O(^BPST("AE",CLAIM,IEN59)) Q:IEN59="" D SETRESU(IEN59,RESULT,$G(TEXT))
257 Q
258 ;
259 ; STATI(X) gives a text version of what status code X means.
260 ; For effeciency, put more common ones at the top.
261 ; Also note that you should check the display on the stats screen if you
262 ; modify any of these.
263STATI(X) ;
264 I X=99 Q "Done"
265 I X=60 Q "Transmitting"
266 I X=0 Q "Waiting to start"
267 I X=40 Q "Building the HL7 packet"
268 I X=70 Q "Parsing response"
269 I X=30 Q "Building the claim"
270 I X=10 Q "Building the transaction"
271 I X=90 Q "Processing response"
272 I X=98 Q "Resubmitting" ; Used only by STATUS^BPSOSRX (Not stored in BPS Transactions)
273 I X=50 Q "Preparing for transmit"
274 I X=31 Q "Wait for retry (insurer asleep)"
275 I X=80 Q "Waiting to process response"
276 Q "?"_X_"?"
Note: See TracBrowser for help on using the repository browser.