source: WorldVistAEHR/trunk/r/INTEGRATED_BILLING-IB-PRQ--IBD--IBQ--PRQS/IBEFUNC.m@ 724

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

initial load of WorldVistAEHR

File size: 9.3 KB
Line 
1IBEFUNC ;ALB/RLW - EXTRINSIC FUNCTIONS ;12-JUN-92
2 ;;2.0;INTEGRATED BILLING;**55,91,106,139,51,153,232,155,249,327**;21-MAR-94
3 ;
4ETXT(X) ; -- output error text from 350.8
5 ; -- input error code
6 N Y S Y=X
7 I X="" G ETXTQ
8 S Y=$P($G(^IBE(350.8,+$O(^IBE(350.8,"AC",X,0)),0)),U,2)
9ETXTQ Q Y
10 ;
11IGN(X,Y) ; ignore means test? for appt type on dates
12 ; -- input x = mas appt type
13 ; y = appt date
14 ; output = true if this appt type should not be billed for
15 ; Means Test billing (352.1,.04) for given date
16 ;
17 I '$G(X)!('$G(Y)) Q 1
18 Q +$P($G(^IBE(352.1,+$O(^(+$O(^IBE(352.1,"AIVDT",+X,-(Y+.1))),0)),0)),U,4)
19 ;
20DSP(X,Y) ; display on input screen?
21 ; -- input X = mas appt type (P409.1)
22 ; Y = date
23 ; output = true if appt type X (352.1,.02) should be displayed as
24 ; a potential billable visit (352.1,.06) on given date Y (352.1,.03)
25 ;
26 I '$G(X)!('$G(Y)) Q 0
27 Q +$P($G(^IBE(352.1,+$O(^(+$O(^IBE(352.1,"AIVDT",+X,-(Y+.1))),0)),0)),U,6)
28 ;
29RPT(X,Y) ; print on report?
30 ; -- input X = mas appt type (P409.1)
31 ; Y = date
32 ; output = true if appt type X (352.1,.02) should be printed on 'Vets w/ Ins and Opt
33 ; Visits' report (352.1,.05) on given date Y (352.1,.06)
34 ;
35 I '$G(X)!('$G(Y)) Q 0
36 Q +$P($G(^IBE(352.1,+$O(^(+$O(^IBE(352.1,"AIVDT",+X,-(Y+.1))),0)),0)),U,5)
37 ;
38NBDIS(X,Y) ; Is disposition non-billable?
39 ; -- input X = disposition (P37)
40 ; Y = date of appt
41 ; output = true (1) if disposition should be ignored for
42 ; Means test billing (352.2,.03) for given date
43 ;
44 I '$G(X)!('$G(Y)) Q 0
45 Q +$P($G(^IBE(352.2,+$O(^(+$O(^IBE(352.2,"AIVDT",+X,-(Y+.1))),0)),0)),U,3)
46 ;
47NBCSC(X,Y) ; Is clinic stop code non-billable?
48 ; -- input X = clinic stop code (P40.7)
49 ; Y = date of appt
50 ; output = true (1) if clinic stop code should be ignored for
51 ; Means test billing (352.3,.03) for given date
52 ;
53 I '$G(X)!('$G(Y)) Q 0
54 Q +$P($G(^IBE(352.3,+$O(^(+$O(^IBE(352.3,"AIVDT",+X,-(Y+.1))),0)),0)),U,3)
55 ;
56NBCL(X,Y) ; Is clinic non-billable?
57 ; -- input X = clinic (P44)
58 ; Y = date of appt
59 ; output = true (1) if clinic should be ignored for
60 ; Means test billing (352.4,.03) for given date
61 ;
62 I '$G(X)!('$G(Y)) Q 0
63 Q +$P($G(^IBE(352.4,+$O(^(+$O(^IBE(352.4,"AIVDT",+X,-(Y+.1))),0)),0)),U,3)
64 ;
65NBST(X,Y) ; Is clinic stop code non-billable for Third Party?
66 ; -- input X = clinic stop code (P40.7), Y = appt date
67 ; output = true (1) if stop non-billable for Third Party (352.3,.05) for given dt
68 ;
69 I '$G(X)!('$G(Y)) Q 0
70 Q +$P($G(^IBE(352.3,+$O(^(+$O(^IBE(352.3,"AIVDTT2",+X,-(Y+.1))),0)),0)),U,5)
71 ;
72NBCT(X,Y) ; Is clinic non-billable for Third Party?
73 ; -- input X = clinic (P44), Y = appt dt
74 ; output = true (1) if clinic non-billable for Third Party (352.4,.05) for given date
75 ;
76 I '$G(X)!('$G(Y)) Q 0
77 Q +$P($G(^IBE(352.4,+$O(^(+$O(^IBE(352.4,"AIVDTT2",+X,-(Y+.1))),0)),0)),U,5)
78 ;
79NABST(X,Y) ; Returns true (1) if stop code flagged to be ignored by Third Party auto biller (use DT)
80 S:'$G(Y) Y=DT I '$G(X) Q 0
81 Q +$P($G(^IBE(352.3,+$O(^(+$O(^IBE(352.3,"AIVDTT2",+X,-(Y+.1))),0)),0)),U,6)
82 ;
83NABCT(X,Y) ; Returns true (1) if clinic is flagged to be ignored by Third Party auto biller (use DT)
84 S:'$G(Y) Y=DT I '$G(X) Q 0
85 Q +$P($G(^IBE(352.4,+$O(^(+$O(^IBE(352.4,"AIVDTT2",+X,-(Y+.1))),0)),0)),U,6)
86 ;
87PT(DFN) ;returns (patient name^long pat id^short pat id) or null if not found
88 N X,IBX S X="" I $D(DFN) S X=$G(^DPT(+DFN,0)) I X'="" S X=$P(X,U,1)_U_$P($G(^DPT(DFN,.36)),U,3,4) D
89 . S IBX=$P(^DPT(+DFN,0),U,9)
90 . I $P(X,U,2)="" S $P(X,U,2)=$E(IBX,1,3)_"-"_$E(IBX,4,5)_"-"_$E(IBX,6,10)
91 . I $P(X,U,3)="" S $P(X,U,3)=$E(IBX,6,10)
92 Q X
93 ;
94EXSET(X,D0,D1) ;returns external value of a set in file D0, field D1
95 Q $$EXPAND^IBTRE($G(D0),$G(D1),$G(X))
96 ;
97BABCSC(DFN,IBDT) ; -- any billable Third Party visits in encounter file for patient
98 ; -- Input dfn = patient, ibdt = date
99 ; output = 1 if any billable stop on date OR 0 if none
100 ;
101 N IBX,IBVAL,IBCBK,IBFILTER
102 S IBX=0
103 I '$G(DFN)!('$G(IBDT)) G BABQ
104 ;
105 S IBVAL("DFN")=DFN,IBVAL("BDT")=IBDT\1,IBVAL("EDT")=IBDT\1+.24
106 ;Ignore if not chkd out, no stop, non-billable stop, non-billable clinic
107 S IBFILTER=""
108 S IBCBK="I $P(Y0,U,12)=2,$P(Y0,U,3),'$$NBST^IBEFUNC($P(Y0,U,3),+Y0),'$$NBCT^IBEFUNC(+$P(Y0,U,4),+Y0) S (IBX,SDSTOP)=1"
109 D SCAN^IBSDU("PATIENT/DATE",.IBVAL,"",IBCBK,1) K ^TMP("DIERR",$J)
110 ;
111BABQ Q IBX
112 ;
113APPTCT(IBOE0) ; Determine if appt encounter/appt has valid status for billing
114 ; Returns 1 if valid, 0 if not
115 ; IBOE0 = the encounter's 0-node (input)
116 N STAT
117 S STAT=$P(IBOE0,U,12) ;Encounter stat
118 I STAT=14 S STAT=2
119 ; Assume 1,2 (and 14 sometimes) are valid, 8 = INPATIENT
120 Q STAT<3
121 ;
122NCTCL(IBOE0) ; Determine if a clinic for an outpt encounter is non-count
123 ; IBOE0 = the 0-node of the encounter
124 Q ($P($G(^SC(+$P(IBOE0,U,4),0)),U,17)="Y")
125 ;
126DISCT(IBOE,IBOE0) ; Determine if disposition has valid status for billing
127 ; Returns 1 if valid, 0 if not valid
128 ; IBOE = encounter ien
129 ; IBOE0 = 0-node of encounter (optional)
130 N IBX
131 S IBX=$$DISND^IBSDU(IBOE,$G(IBOE0),2)
132 Q (IBX<2)
133 ;
134NEEDMRA(IBIFN) ; Returns MRA NEEDED STATUS for bill
135 Q $P($G(^DGCR(399,+IBIFN,"TX")),U,5)
136 ;
137REQMRA(IBIFN) ; Determine from site parameter, ins assigned to bill and txmn
138 ; rules if request for MRA is needed (MCRWNR must be current ins co)
139 ; "R" = not needed due to next carrier not requiring it (txmn rules),
140 ; "R1" = not needed due to MRA turned off at site
141 ; 0 = not needed, 1 = needed
142 N IB0,COBINS,COBSEQ,IBOK,Z1,Z0,IBDA,IB00,IB0
143 ;
144 I $$COB^IBCEF(IBIFN)="A" S IBOK=0 G REQMRAQ ; payer sequence = patient not allowed for MRA
145 S COBSEQ=$$COBN^IBCEF(IBIFN)
146 S COBINS=$P($G(^DGCR(399,IBIFN,"M")),U,COBSEQ)
147 ;Curr ins must = MEDICARE WNR
148 S IBOK=+$$MCRWNR(COBINS)
149 I 'IBOK G REQMRAQ
150 ;
151 I '$$EDIACTV^IBCEF4(2) S IBOK="R1" G REQMRAQ ; Site param=NO
152 ;
153 ; Check next ins for MRA needed
154 I COBSEQ'<3 S IBOK=0 G REQMRAQ
155 ;
156 S IB0=$G(^DGCR(399,IBIFN,0))
157 S COBINS=+$P($G(^DGCR(399,IBIFN,"M")),U,COBSEQ+1)
158 I 'COBINS S IBOK=0 G REQMRAQ ;No next ins
159 I $$COB^IBCEF(IBIFN)="S" D I IBOK="R2" G REQMRAQ
160 . S COBINS=$P($G(^DGCR(399,IBIFN,"M")),U,COBSEQ)
161 . I +$$MCRWNR(COBINS)=1 S IBOK="R2"
162 ;
163 ; Check only rules with rule type = 2 (MRA REQUEST RESTRICTIONS)
164 S IBDA=0 F S IBDA=$O(^IBE(364.4,"AC",2,IBDA)) Q:'IBDA S IB00=$G(^IBE(364.4,IBDA,0)) D Q:'IBOK
165 . I $P(IB00,U,2)>DT Q ; Inactive
166 . I $P(IB00,U,6),$P(IB00,U,6)'>DT Q ; Expired
167 . S Z0=$$INPAT^IBCEF(IBIFN,1),Z0=$S(Z0=1:2,1:1)
168 . S Z1=$$FT^IBCEF(IBIFN),Z1=$S(Z1=3:1,1:2)
169 . I $S($P(IB00,U,4)=3:1,1:$P(IB00,U,4)=Z0),$S($P(IB00,U,5)=3:1,1:$P(IB00,U,5)=Z1) S Z0=$D(^IBE(364.4,IBDA,3,"B",COBINS)) I Z0>0 S IBOK="R"
170 ;
171REQMRAQ Q IBOK
172 ;
173MCRWNR(IBINS) ;Returns whether the ins co IBINS is MEDICARE WNR (Will
174 ; NOT Reimburse) 0=NO, 1=YES
175 N Z,Z0
176 S Z=0,Z0=$G(^DIC(36,+IBINS,0))
177 I $P(Z0,U,2)="N",$P($G(^IBE(355.2,+$P(Z0,U,13),0)),U)="MEDICARE" S Z=1
178 Q Z
179 ;
180WNRBILL(IBIFN,IBCOB) ; Returns whether the ins for COB seq IBCOB
181 ; is MEDICARE will not reimburse
182 ;
183 I $G(IBCOB)="" S IBCOB=$$COBN^IBCEF(IBIFN)
184 S IBCOB=$TR(IBCOB,"PST","123")
185 Q $$MCRWNR(+$G(^DGCR(399,IBIFN,"I"_IBCOB)))
186 ;
187MCR(IBINS) ;Returns whether the ins co IBINS is MCR Will Reimburse
188 ; 0=NO , 1=YES
189 N Z,Z0
190 S Z=0,Z0=$G(^DIC(36,+IBINS,0))
191 I $P(Z0,U,2)'="N",$P($G(^IBE(355.2,+$P(Z0,U,13),0)),U)="MEDICARE" S Z=1
192 Q Z
193 ;
194MRATYPE(IBIEN,IBVAR) ; Returns: A = MEDICARE A B = MEDICARE B
195 ; C = MEDICARE OTHER null = NOT MEDICARE
196 ; for the plan associated with bill ien IBIEN OR grp plan IBIEN
197 ; If IBVAR = "" or 'C', the data is from bill ien in IBIEN
198 ; = 'P', the data is from grp policy ien in IBIEN
199 ;
200 N IBPLAN
201 S IBPLAN=$S($G(IBVAR)'="P":+$$POLICY^IBCEF(IBIEN,18),1:IBIEN)
202 Q $P($G(^IBA(355.3,+IBPLAN,0)),U,14)
203 ;
204MCRONBIL(IBIFN,IBFLG) ; Returns 0 if MCR WNR not on bill IBIFN
205 ; 1 if on bill, is on or before current ins
206 ; 2 if on bill, but after current ins
207 ; IBFLG = a COB number if second "^" piece of return data should be
208 ; 1 if MCRWNR is the insurance at that COB sequence (optional)
209 N Z,IBON,Q
210 S IBON=0,Q=$$COBN^IBCEF(IBIFN)
211 F Z=1:1:3 I $$WNRBILL(IBIFN,Z) S IBON=$S(Q'<Z:1,1:2)_$S('$G(IBFLG):"",Z'=IBFLG:"",1:"^1") Q
212 Q IBON
213 ;
214PROFEE(IBIFN) ; Returns whether any rev codes for prof fees
215 ; included on bill IBIFN 0 = not included, 1 = included,
216 ; 2 = both inst and prof are included
217 ;
218 N IBPRO,Z
219 S IBPRO=0,Z=$O(^DGCR(399,IBIFN,"RC","B",959)) ; Rev cds 960-989 are prof
220 I Z,Z<990 D
221 . S IBPRO=1
222 . S Z=$O(^DGCR(399,IBIFN,"RC","B",0))
223 . I $S(Z:Z<960,1:0)!($O(^DGCR(399,IBIFN,"RC","B",1000),-1)'<990) S IBPRO=2
224 Q IBPRO
225 ;
226GETMOD(IBIFN,IBCPT,EXT) ; Returns 'list' of modifiers for file 399
227 ; procedure for bill IBIFN and proc ien IBCPT
228 ; in modifier seq order, separated by ','
229 ; If EXT = 1, return the actual modifier, not the ptr
230 N IBMOD,IBZ,IBZ0,IB0,Z
231 S IBZ=0,IBMOD=""
232 F S IBZ=$O(^DGCR(399,IBIFN,"CP",IBCPT,"MOD","B",IBZ)) Q:'IBZ S IBZ0=0 F S IBZ0=$O(^DGCR(399,IBIFN,"CP",IBCPT,"MOD","B",IBZ,IBZ0)) Q:'IBZ0 I $D(^DGCR(399,IBIFN,"CP",IBCPT,"MOD",IBZ0,0)) S IB0=$G(^(0)) D
233 . I '$G(EXT) S Z=$P(IB0,U,2)
234 . I $G(EXT) S Z=$$MOD^ICPTMOD($P(IB0,U,2),"I"),Z=$S($P(Z,U)=-1:"",1:$P(Z,U,2))
235 . Q:Z=""
236 . S IBMOD=IBMOD_$S(IBMOD="":"",1:",")_Z
237 Q IBMOD
238 ;
239MODLST(MODS,DESC,IBMOD) ; Returns string of actual mods
240 ; MOVED
241 Q $$MODLST^IBEFUNC2(MODS,$G(DESC),.IBMOD)
242 ;
243GETSPEC(FILE,FIELD) ; Get fld specifier for FIELD # in FILE
244 ; Use to set DIC("P") for FILE^DICN
245 N IBZ
246 D FIELD^DID(FILE,FIELD,"","SPECIFIER","IBZ")
247 Q $G(IBZ("SPECIFIER"))
248 ;
Note: See TracBrowser for help on using the repository browser.