source: FOIAVistA/trunk/r/INTEGRATED_BILLING-IB-PRQ--IBD--IBQ--PRQS/IBCEF72.m@ 677

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

initial load of FOIAVistA 6/30/08 version

File size: 9.1 KB
Line 
1IBCEF72 ;WOIFO/SS - FORMATTER AND EXTRACTOR SPECIFIC BILL FUNCTIONS ;8/6/03 10:56am
2 ;;2.0;INTEGRATED BILLING;**232,320,349**;21-MAR-94;Build 46
3 ;;Per VHA Directive 2004-038, this routine should not be modified.
4 ;
5 ;
6 ;Input:
7 ;IBINSCO - ptr to #36
8 ;IBFRMTYP 0=unknwn/both,1=UB,2=1500
9 ;IBCARE - 0=unknwn or both inp/outp,1=inpatient, 2=outpatient, 3 -RX
10 ;Output: X12 IDtype^ID^ID TYPE ptr to file 355.97
11CH35591(IBINSCO,IBFRMTYP,IBCARE) ;
12 N IB35591,IBRET,IB1
13 S IB35591=0,IBRET=""
14 F S IB35591=$O(^IBA(355.91,"B",IBINSCO,IB35591)) Q:+IB35591=0 Q:IBRET'="" D
15 . S IB1=$G(^IBA(355.91,IB35591,0))
16 . I '($P(IB1,"^",4)=0!(IBFRMTYP=0)) Q:$P(IB1,"^",4)'=IBFRMTYP ;if wrong form type
17 . I ($P(IB1,"^",5)=3)!(IBCARE=3) Q:IBCARE'=$P(IB1,"^",5) ;if not RX
18 . I ($P(IB1,"^",5)=1)!($P(IB1,"^",5)=2) I (IBCARE=1)!(IBCARE=2) Q:$P(IB1,"^",5)'=IBCARE ;if wrong care type
19 . S IBRET=$P($G(^IBE(355.97,+$P(IB1,"^",6),0)),"^",3)_"^"_$P(IB1,"^",7)_U_+$P(IB1,U,6)
20 Q IBRET
21 ;
22FINDEIN(IBXIEN,IBPROV,IBFAC,IBS) ; find EIN for facility/ SSN for person
23 ; IBXIEN = ien of bill entry file 399
24 ; IBFAC = 1 if facility, 0 if individual provider
25 ; IBPROV = ien of provider (vp format)
26 ; IBS = 1 if person's EIN should be returned if there, otherwise SSN
27 ; FUNCTION RETURNS
28 ; EIN or SSN ^ 24 for EIN, 34 for SSN or null if none found
29 N Z,Z0,IBARR,IBEIN,IBSSN
30 S (IBEIN,IBSSN)=""
31 D ALLID^IBCEP8(IBPROV,"",.IBARR)
32 S Z=0 F S Z=$O(IBARR(Z)) Q:'Z D Q:IBEIN'=""
33 . I $G(IBFAC) Q:$P(IBARR(Z),U,7)'="EI" S IBEIN=$P(IBARR(Z),U,2)_U_24 Q
34 . I $P(IBARR(Z),U,7)="SY" D Q
35 .. I $G(IBS) S IBSSN=$P(IBARR(Z),U,2)_U_34 Q
36 . S IBEIN=$P(IBARR(Z),U,2)_U_24
37 . I $G(IBS),$P(IBARR(Z),U,7)="EI" S IBEIN=$P(IBARR(Z),U,2)_U_24
38 I $G(IBS),IBEIN="" S IBEIN=IBSSN
39 Q IBEIN
40 ;
41 ;
42NONVAID(IBXIEN,IBX,IBFAC,IBS) ; Find the non-VA provider default id
43 ; IBXIEN = the ien of the bill (file 399)
44 ; IBX = id data returned if passed by reference
45 ; IBFAC = 1 if getting the id for the facility or 0 for rendering prov
46 ; IBS = 1 if getting id for person, but need the EIN if there
47 ; Function returns the id^type of id^person/facility flag:
48 ; Type of id: 1 = SSN 2 = EIN 0 = not found
49 ; person/facility: 1 = person 2 = facility
50 N Z,IBXSAVE,IBU2,IBTYPE,IBZ,IBF,IBPROV,Q,Q0
51 S IBTYPE=2,IBU2=$G(^DGCR(399,IBXIEN,"U2")),IBF=2,IBPROV=""
52 ;
53 S Z=$P(IBU2,U,10)
54 I 'Z S IBX="",IBTYPE=0 G NONVAQ ; Not a non-VA facility
55 S IBPROV=Z_";IBA(355.93,"
56 ;
57 ; Get EIN
58 I $G(IBFAC) D G NONVAQ
59 . S IBX=$P($$FINDEIN(IBXIEN,IBPROV,IBFAC),U),IBTYPE=2
60 ;
61 ; Get EIN/SSN
62 I '$G(IBFAC) D G NONVAQ
63 . S IBX="",IBF=1
64 . S Q0=($$FT^IBCEF(IBXIEN)=3)+3 ; 3 for rendering/4 for attending
65 . S Q=+$O(^DGCR(399,IBXIEN,"PRV","B",Q0,0))
66 . S IBPROV=$P($G(^DGCR(399,IBXIEN,"PRV",Q,0)),U,2)
67 . I IBPROV S IBX=$$FINDEIN(IBXIEN,IBPROV,IBFAC,$G(IBS)),IBTYPE=$S($P(IBX,U,2)=24:2,$P(IBX,U,2)=34:1,1:0),IBX=$P(IBX,U)
68 ;
69NONVAQ I IBTYPE,IBX="",$P(IBU2,U,12)'="" S IBX=$P(IBU2,U,12) ; pull from 399
70 S IBX=$G(IBX)
71 Q IBX_U_IBTYPE_U_IBF
72 ;----
73 ;checks if there is data for OP* segments and
74 ;then populates PROV COB SEQ
75 ;Input:
76 ;IBXIEN - ien in #399
77 ;IBSAVE - "in" array (i.e. IBXSAVE)
78 ;IBDATA - "out" array (i.e. IBXDATA)
79 ;IBFUNC - FUNCTION from #399 (1-refering, 2 -operating, etc)
80 ;IBSEGM - segment record ID, optional
81 ;Output:
82 ; IBDATA with formatted output
83PROVSEQ(IBXIEN,IBSAVE,IBDATA,IBFUNC,IBSEGM) ;
84 N IB1,IB2,IBINS,IBFL
85 S IBFL=$S(IBFUNC=3!(IBFUNC=4):1,1:0)
86 F IB1=1,2 D
87 . Q:'$$ISINSUR^IBCEF71($G(IBSAVE("PROVINF",IBXIEN,"O",IB1)),IBXIEN) ;don't create anything if there is no such insurance
88 . I IBFL S IBFUNC=$S($O(IBSAVE("PROVINF",IBXIEN,"O",IB1,3,0)):3,1:4)
89 . S:$O(IBSAVE("PROVINF",IBXIEN,"O",IB1,IBFUNC,0)) IBDATA(IB1)=$G(IBSAVE("PROVINF",IBXIEN,"O",IB1))
90 . I $G(IBSEGM)'="" D:$O(IBSAVE("PROVINF",IBXIEN,"O",IB1,IBFUNC,0)) ID^IBCEF2(IB1,IBSEGM)
91 Q
92 ;
93OUTPRVID(IBXIEN,IBXSAVE) ; Extract the outside provider or facility ids
94 ; into IBXSAVE array
95 ; Function returns 1 if person or 2 if facility ids or "" if neither
96 N Z,IBXDATA,IBPERSON,TAG
97 ;WCJ;11/1/2005 Extract the first 3 chars of Z instead.
98 S Z=$E($$PSPRV^IBCEF7(IBXIEN),1,3),IBPERSON=""
99 ;EJK 8/23/05 IB*320 - CHANGED Z=101 TO Z=1010. Z WILL ALWAYS BE A 4 DIGIT #.
100 ; WCJ 11/1/2005 ; Removed EJK's change and added above change
101 I Z=111!(Z=101) S TAG=$S(Z=101:"OUTSIDE FAC PROVIDER INF",1:"CUR/OTH PROVIDER INFO") D F^IBCEF("N-ALL "_TAG) S IBPERSON=$S('$E(Z,2):2,1:1)
102 Q IBPERSON
103 ;
104OUTPRV(IBREC,IBXIEN,IBXSAVE) ; Extract the outside provider or facility ids
105 ; into IBXSAVE array
106 ; Function returns 1 if person or 2 if facility ids or "" if neither
107 ; IBREC = the record whose ids should be returned
108 N IBPERSON,IBFRM,IBTYPE,IBFAC
109 I IBREC="SUB1"!(IBREC="OP6") D
110 . K IBXSAVE("PROVINF",IBXIEN),IBXSAVE("PROVINF_FAC",IBXIEN)
111 . S IBPERSON=$$OUTPRVID(IBXIEN,.IBXSAVE),IBFAC=$S(IBPERSON=1:0,1:1)
112 E D
113 . K IBXSAVE("PROVINF_FAC",IBXIEN)
114 . D F^IBCEF("N-ALL OUTSIDE FAC PROVIDER INF")
115 . S IBPERSON=2,IBFAC=1
116 S IBFRM=$$FT^IBCEF(IBXIEN),IBFRM=$S(IBFRM=2:2,1:1)
117 S IBTYPE=$S(IBREC["SUB":"C",1:"O")
118 D CHCKSUB^IBCEF73(IBFRM,IBREC,IBFAC,IBTYPE,.IBXSAVE)
119 Q IBPERSON
120 ;
121 ;get IENs in file #36 for other insurances
122OTHINS(IB399,IBRES) ;
123 N IBFRMTYP,Z,Z1,Z2,Z4
124 S Z=$$COBN^IBCEF(IB399),Z0=0
125 F Z1=1:1:3 I Z1'=Z,$D(^DGCR(399,IB399,"I"_Z1)) S Z0=Z0+1,IBRES(Z0)=+$G(^DGCR(399,IB399,"I"_Z1))
126 Q
127 ;get other insurance EDI ID NUMBERs
128OTHINSID(IB399,IBRES) ;insurance EDI
129 N IBFRMTYP,IBZ,Z0,Z1,Z4
130 S IBFRMTYP=$$FT^IBCEF(IB399),IBFRMTYP=$S(IBFRMTYP=2:2,IBFRMTYP=3:1,1:0)
131 S Z4=$S(IBFRMTYP=1:4,1:2) ;UB - piece4,1500 or BOTH -piece 2
132 D OTHINS(IB399,.IBZ)
133 S Z1=0
134 F Z0=1:1:2 I $G(IBZ(Z0)) S IBRES(Z0)=$S($$MCRWNR^IBEFUNC(+IBZ(Z0)):$S(IBFRMTYP=1:"12M61",1:"SMTX1"),1:$P($G(^DIC(36,+IBZ(Z0),3)),U,Z4))
135 Q
136 ;
137 ;get other insurance addresses
138OTHINADR(IB399,IBRES,IBADDFLD) ;insurance EDI
139 N IBZ,Z0,Z1,Z4
140 D OTHINS(IB399,.IBZ)
141 S Z1=0
142 I IBADDFLD=18 D Q
143 . F Z0=1:1:2 I $G(IBZ(Z0)) D
144 . . S IBRES(Z0)=$P($G(^DIC(36,+IBZ(Z0),.11)),U,1)
145 . . S IBRES(Z0)=$E(IBRES(Z0),1,55)
146 I IBADDFLD=18.9 D Q
147 . F Z0=1:1:2 I $G(IBZ(Z0)) D
148 . . S IBRES(Z0)=$P($G(^DIC(36,+IBZ(Z0),.11)),U,1)
149 . . S Z4=$P($G(^DIC(36,+IBZ(Z0),.11)),U,2) S:Z4'="" IBRES(Z0)=IBRES(Z0)_", "_Z4
150 . . S Z4=$P($G(^DIC(36,+IBZ(Z0),.11)),U,3) S:Z4'="" IBRES(Z0)=IBRES(Z0)_", "_Z4
151 . . S Z4=$P($G(^DIC(36,+IBZ(Z0),.11)),U,4) S:Z4'="" IBRES(Z0)=IBRES(Z0)_", "_Z4
152 . . S Z4=$P($G(^DIC(5,+$P($G(^DIC(36,+IBZ(Z0),.11)),U,5),0)),U,2) S:Z4'="" IBRES(Z0)=IBRES(Z0)_", "_Z4
153 . . S Z4=$P($G(^DIC(36,+IBZ(Z0),.11)),U,6) S:Z4'="" IBRES(Z0)=IBRES(Z0)_", "_Z4
154 . . S IBRES(Z0)=$E(IBRES(Z0),1,157)
155 I IBADDFLD=19 D Q
156 . F Z0=1:1:2 I $G(IBZ(Z0)) D
157 . . S IBRES(Z0)=$P($G(^DIC(36,+IBZ(Z0),.11)),U,2)
158 . . S IBRES(Z0)=IBRES(Z0)_" "_$P($G(^DIC(36,+IBZ(Z0),.11)),U,3)
159 . . S IBRES(Z0)=$E(IBRES(Z0),1,55)
160 I IBADDFLD=20 D Q
161 . F Z0=1:1:2 I $G(IBZ(Z0)) D
162 . . S IBRES(Z0)=$P($G(^DIC(36,+IBZ(Z0),.11)),U,4)
163 . . S IBRES(Z0)=$E(IBRES(Z0),1,30)
164 I IBADDFLD=21 D Q
165 . F Z0=1:1:2 I $G(IBZ(Z0)) D
166 . . S IBRES(Z0)=$P($G(^DIC(5,+$P($G(^DIC(36,+IBZ(Z0),.11)),U,5),0)),U,2)
167 . . S IBRES(Z0)=$E(IBRES(Z0),1,2)
168 I IBADDFLD=22 D Q
169 . F Z0=1:1:2 I $G(IBZ(Z0)) D
170 . . S IBRES(Z0)=$P($G(^DIC(36,+IBZ(Z0),.11)),U,6)
171 . . S IBRES(Z0)=$E(IBRES(Z0),1,15)
172 Q
173 ;
174SFIDQ(IBXIEN,IBXSAVE,IBXDATA) ; Find the service facility id qualifier for
175 ; 837 record SUB2-5
176 ;IBXIEN = ien of 399
177 ;Pass by reference: IBXSAVE (input/output) IBXDATA (output)
178 N B,Z
179 K IBXSAVE("NVID")
180 D ; protect IBXDATA
181 . N IBXDATA
182 . D F^IBCEF("N-RENDERING INSTITUTION")
183 . S:IBXDATA'="" IBXSAVE("IBFAC")=IBXDATA
184 I $P($G(IBXSAVE("IBFAC")),U,2)'=1 K IBXDATA Q
185 S Z=$$PSPRV^IBCEF7(IBXIEN)
186 ;WCJ 11/04/2005 If a Non-VA facility
187 I $E(Z) D
188 . S IBXSAVE("NVID")=$$NONVAID^IBCEF72(IBXIEN,.B,$E(Z),1)
189 .; S IBXSAVE("NVID")=$$NONVAID^IBCEF72(IBXIEN,.B,'$E(Z,2),1)
190 . S IBXDATA=$P("^34^24",U,$P(IBXSAVE("NVID"),U,2)+1)
191 ;S Z=$$PSPRV^IBCEF7(IBXIEN),IBXSAVE("NVID")=$$NONVAID^IBCEF72(IBXIEN,.B,'$E(Z,2),1),IBXDATA=24
192 Q
193 ;
194OTHP36(IBXIEN,IBZOUT) ;
195 N Z,Z0,Z1,IBZ
196 D F^IBCEF("N-ALL INSURANCE CO 837 ID","IBZ")
197 F Z=1,2,3 S IBZOUT(Z)=+$$POLICY^IBCEF(IBXIEN,1,$E("PST",Z))
198 Q
199 ;
200 ;---------SORT-----------
201 ;IBPRNUM - seq #
202 ;IBPRTYP - type of provider (use FUNCTION value from file 399, fld 222)
203 ;IB399 = ien file 399
204 ;IBSRC,IBDST - source,destination arrays
205 ;IBN - starting #
206 ;Output:
207 ; IBDST(1-primary/2-secondary provider,Provider type(FUNCTION),N)=
208 ; =provider/VARIABLEPTR^Insurance PTR #36 or NONE^ID type^ID^Form type^Care type^state ptr #5 for state license #
209 ; where N is numeration (1 for ID1, 2 for ID2, etc)
210GETSSN(IBPTR) ;look for SSN in #200 first and if not found then look at #355.9
211 ;if in file #200
212 I $P(IBPTR,";",2)="VA(200," Q $$SSN200^IBCEF73(IBPTR)
213 ;if in 355.93 then use 355.9
214 Q $$SSN3559^IBCEF73(IBPTR)
215 ;--
216 ;SSN3559
217 ;Find SSN from 355.9
218 ;Input:
219 ; Variable pointer to ^VA(200 or ^IBA(355.93
220 ;Output:
221 ; SSN or null
222 ;
223PADNDC(Z) ;PAD LEADING ZERO'S INTO A NON 5-4-2 FORMAT NDC NUMBER
224 ;Z IS ITERATION, ONLY PAD CURRENT NDC NUMBER
225 N NDC
226 S NDC=$P(IBXSAVE("OUTPT",Z,"RX"),"^",3)
227 Q:$L(NDC)=13
228 I $L(NDC)=14 D Q
229 . S $P(NDC,"-",1)=$E($P(NDC,"-",1),2,$L($P(NDC,"-",1)))
230 . S $P(IBXSAVE("OUTPT",Z,"RX"),"^",3)=NDC
231 I $L($P(NDC,"-",1))'=5 S $P(NDC,"-",1)="0"_$P(NDC,"-",1)
232 I $L($P(NDC,"-",2))'=4 S $P(NDC,"-",2)="0"_$P(NDC,"-",2)
233 I $L($P(NDC,"-",3))'=2 S $P(NDC,"-",3)="0"_$P(NDC,"-",3)
234 S $P(IBXSAVE("OUTPT",Z,"RX"),"^",3)=NDC
235 Q
236 ;
Note: See TracBrowser for help on using the repository browser.