source: WorldVistAEHR/trunk/r/E_CLAIMS_MGMT_ENGINE-BPS/BPSOSRB.m@ 1006

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

initial load of WorldVistAEHR

File size: 5.8 KB
Line 
1BPSOSRB ;BHAM ISC/FCS/DRS/FLS - Process claim on processing queue ;06/01/2004
2 ;;1.0;E CLAIMS MGMT ENGINE;**1,5**;JUN 2004;Build 45
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5 Q
6BACKGR ;
7 I '$$LOCKNOW^BPSOSRX("BACKGROUND") Q
8 N TYPE,RXI,RXR,IEN59
9 I '$$LOCK^BPSOSRX("BACKGROUND",300) G FAIL
10 F TYPE="CLAIM","UNCLAIM" D
11 . S RXI="" F S RXI=$O(^XTMP("BPS-PROC",TYPE,RXI)) Q:RXI="" D
12 .. S RXR="" F S RXR=$O(^XTMP("BPS-PROC",TYPE,RXI,RXR)) Q:RXR="" D
13 ... N X S X=$$STATUS^BPSOSRX(RXI,RXR,0)
14 ... S IEN59=$$IEN59^BPSOSRX(RXI,RXR)
15 ... D LOG^BPSOSL(IEN59,$T(+0)_"-Dequeuing. Type is "_TYPE)
16 ... I $P(X,U)="IN PROGRESS" D Q
17 .... D LOG^BPSOSL(IEN59,$T(+0)_"-Status is 'IN PROGRESS'. Will retry later.")
18 ... N TIME,MOREDATA
19 ... S TIME=^XTMP("BPS-PROC",TYPE,RXI,RXR) ; time requested
20 ... I '$$LOCK^BPSOSRX("SUBMIT",10) D Q
21 .... D LOG^BPSOSL(IEN59,$T(+0)_"-Failed to $$LOCK^BPSOSRX(""SUBMIT""). Will retry later.")
22 ... I $D(^XTMP("BPS-PROC",TYPE,RXI,RXR,"MOREDATA")) M MOREDATA=^("MOREDATA")
23 ... E S MOREDATA=0
24 ... K ^XTMP("BPS-PROC",TYPE,RXI,RXR)
25 ... D BACKGR1(TYPE,RXI,RXR,TIME,.MOREDATA)
26 ... D UNLOCK^BPSOSRX("SUBMIT")
27FAIL D UNLOCK^BPSOSRX("BACKGROUND")
28 Q
29 ;
30 ; BACKGR1 - Further processing of the claim
31 ; Besides the parameter below, IEN59 also needs to be defined
32BACKGR1(TYPE,RXI,RXR,TIME,MOREDATA) ;
33 ; Resolve multiple requests
34 N SKIP S SKIP=0 ; skip if you already got desired result
35 N SKIPREAS
36 N RESULT S RESULT=$$STATUS^BPSOSRX(RXI,RXR,0),RESULT=$P(RESULT,U)
37 N STARTTIM S STARTTIM=$$STARTTIM(RXI,RXR)
38 I TYPE="CLAIM" D
39 . I $$RXDEL^BPSOS(RXI,RXR) D Q
40 .. S SKIP=1,SKIPREAS="Prescription is marked as DELETED or CANCELLED"
41 . ; If it's never been through ECME before, good.
42 . I RESULT="" Q
43 . ; There's already a complete transaction for this RXI,RXR
44 . ; (We screened out "IN PROGRESS" earlier)
45 . ; The program to poll indexes would have set DO NOT RESUBMIT.
46 . ; Calls from pharm pkg to ECME have '$D(MOREDATA("DO NOT RESUBMIT"))
47 . I $D(MOREDATA("DO NOT RESUBMIT")) D
48 .. S SKIP=1
49 .. S SKIPREAS="MOREDATA(""DO NOT RESUBMIT"") is set"
50 . E I TIME<STARTTIM D ; our request was made before trans. began
51 .. ; submit claim but only if the prev result was successful reversal
52 .. I RESULT="PAPER REVERSAL" Q
53 .. I RESULT="E REVERSAL ACCEPTED" Q
54 .. S SKIP=1
55 .. S SKIPREAS="Prev result "_RESULT_"; claim started "_STARTTIM_">"_TIME_" submitted"
56 . E D ; our request was made after it began
57 .. ; So we will make a reversal if necessary,
58 .. ; and then the claim will be resubmitted.
59 .. I RESULT="E PAYABLE"!(RESULT="E DUPLICATE"),$G(MOREDATA("REVERSE THEN RESUBMIT"))'=2 D
60 ... S MOREDATA("REVERSE THEN RESUBMIT")=1
61 E I TYPE="UNCLAIM" D
62 . ; It must have gone through ECME with a payable result
63 . I RESULT="E PAYABLE" Q
64 . I RESULT="E DUPLICATE" Q
65 . N RXACTION S RXACTION=$G(MOREDATA("RX ACTION"))
66 . I RESULT="E REVERSAL REJECTED",(",DE,EREV,RS,"[(","_RXACTION_",")) Q
67 . I RESULT="E REVERSAL STRANDED",RXACTION="EREV" Q
68 . S SKIP=1
69 . S SKIPREAS="Cannot reverse - previous result was "_RESULT
70 E D IMPOSS^BPSOSUE("P","TI","bad arg TYPE="_TYPE,,"BACKGR1",$T(+0))
71 I SKIP D Q
72 . D LOG^BPSOSL(IEN59,$T(+0)_"-Skipping. Reason: "_SKIPREAS)
73 S MOREDATA("SUBMIT TIME")=TIME
74 I TYPE="UNCLAIM"!$G(MOREDATA("REVERSE THEN RESUBMIT")) D REVERSE(IEN59,.MOREDATA)
75 I TYPE="CLAIM",'$G(MOREDATA("REVERSE THEN RESUBMIT")) D CLAIM(IEN59,.MOREDATA)
76 Q
77 ;
78 ; STARTTIM - Get START TIME field from BPS Transactions
79STARTTIM(RXI,RXR) Q $P($G(^BPST($$IEN59^BPSOSRX(RXI,RXR),0)),U,11)
80 ;
81 ; Process claim request
82 ; EP - Above and BPSOSU (for a resubmit after a reversal)
83CLAIM(IEN59,MOREDATA) ;
84 D LOG^BPSOSL(IEN59,$T(+0)_"-Initiating Claim")
85 D EN^BPSOSIZ(IEN59,.MOREDATA)
86 Q
87 ;
88 ; Process the reversal
89REVERSE(IEN59,MOREDATA) ;
90 N MSG,RETVAL,REV
91 ;
92 ; Log Reversal or Reversal/Resubmit message.
93 ; Note that the reversal/resubmit message is needed
94 ; for Turn-Around Stats - Do NOT delete/alter!!
95 S MSG=$T(+0)_"-Initiating Reversal"
96 I $G(MOREDATA("REVERSE THEN RESUBMIT"))=1 D
97 . S MSG=MSG_" and after that, claim will be resubmitted"
98 . N X,X1,X2
99 . S X1=DT,X2=30 D C^%DTC
100 . S ^XTMP("BPSOSRB",0)=X_U_DT_U_"PASS VARIABLES FOR RESUBMITS"
101 . K ^XTMP("BPSOSRB","MOREDATA",IEN59)
102 . M ^XTMP("BPSOSRB","MOREDATA",IEN59,"RESUB")=MOREDATA
103 D LOG^BPSOSL(IEN59,MSG)
104 ;
105 ; Change status to 0% (Waiting to Start), which will reset START TIME,
106 ; and then to 10% (Building transaction)
107 D SETSTAT^BPSOSU(IEN59,0)
108 D SETSTAT^BPSOSU(IEN59,10)
109 ;
110 ; Update User (#13), RX Action (#1201), and Reversal Reason (#404)
111 ; in BPS Transactions
112 N DIE,DR,DA
113 S DIE=9002313.59,DA=IEN59
114 S DR="6////"_$G(MOREDATA("SUBMIT TIME"))_";13////"_$G(MOREDATA("USER"))
115 S DR=DR_";404////"_$G(MOREDATA("REVERSAL REASON"))_";1201////"_$G(MOREDATA("RX ACTION"))
116 ;
117 ; Also update RESUBMIT AFTER REVERSAL field (#1.12) if needed
118 I $G(MOREDATA("REVERSE THEN RESUBMIT"))=1 S DR=DR_";1.12////1"
119 D ^DIE
120 ;
121 ; Log message for reverse without resubmit
122 I $G(MOREDATA("REVERSE THEN RESUBMIT"))=2 D LOG^BPSOSL(IEN59,$P($G(MOREDATA("BILL")),U,2)_"-Claim cannot be resubmitted")
123 ;
124 ; Store contents of BPST in the Log
125 D LOG^BPSOSL(IEN59,$T(+0)_"-Contents of ^BPST("_IEN59_") :")
126 D LOG59^BPSOSQA(IEN59) ; Log contents of 9002313.59
127 ;
128 ; Add semi-colon to result text
129 D PREVISLY^BPSOSIZ(IEN59)
130 ;
131 ; Contruct revesal claim
132 ; If no reversal claim is returned, log error and quit.
133 S REV=$$REVERSE^BPSECA8(IEN59)
134 I REV=0 D Q
135 . D LOG^BPSOSL(IEN59,$T(+0)_"-Reversal claim not created for "_IEN59)
136 . D ERROR^BPSOSU($T(+0),IEN59,100,"Reversal Claim not created")
137 ;
138 ; Update Reversal Field in the transaction
139 S DIE=9002313.59,DA=IEN59,DR="401////"_REV
140 D ^DIE
141 ;
142 ; Update Log
143 D LOG^BPSOSL(IEN59,$T(+0)_"-Reversal claim "_$P(^BPSC(REV,0),U)_" ("_REV_")")
144 ;
145 ; Update status to 30% (Building the claim)
146 D SETSTAT^BPSOSU(IEN59,30)
147 ;
148 ; Fire off task to get this on the HL7 queue
149 D TASK^BPSOSQA
150 Q
Note: See TracBrowser for help on using the repository browser.