Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: BUDERPC3

BUDERPC3.m

Go to the documentation of this file.
BUDERPC3 ;IHS/CMI/LAB - UDS TABLE 1-6A;
 ;;12.0;IHS/RPMS UNIFORM DATA SYSTEM;;NOV 22, 2017;Build 75
T9D ;EP
 NEW BUDAIEN,BUDDATE,BUD0,BUDREC,BUDDILL,Z,BUDPIEC
 S BUDAIEN=0
 F  S BUDAIEN=$O(^BARTR(DUZ(2),"AF",DFN,BUDAIEN)) Q:BUDAIEN'=+BUDAIEN  D
 .Q:'$D(^BARTR(DUZ(2),BUDAIEN))
 .Q:'$D(^BARTR(DUZ(2),BUDAIEN,0))
 .S BUD0=^BARTR(DUZ(2),BUDAIEN,0)
 .S BUDDATE=$P(BUD0,U,12)
 .Q:$P(BUDDATE,".")<BUDBD  ;ONLY UDS DATE RANGE
 .Q:$P(BUDDATE,".")>BUDED
 .S BUDREC="",BUDPIEC=0
 .;DATE
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$FMTE^XLFDT(BUDDATE)
 .;BILL NUMBER
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,4)
 .;TRANSACTION TYPE
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,101)
 .;CREDIT 2 A/R TRANSACTION FILE
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$P(BUD0,U,2)
 .;DEBIT 3 A/R TRANSACTION FILE
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$P(BUD0,U,3)
 .;PRIME BILL AMOUNT
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,3.2)
 .;PAYMENT
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,3.6)
 .;ADJUSTMENT
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,3.7)
 .;ADJUSTMENT CATEGORY
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,102)
 .;ADJUSTMENT TYPE
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,103)
 .;A/R ACCOUNT
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,6)
 .;PATIENT
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$VAL^XBDIQ1(90050.03,BUDAIEN,5)
 .;VISIT LOCATION
 .S BUDDILL=$$VALI^XBDIQ1(90050.03,BUDAIEN,4)
 .I BUDDILL S Z=$$VAL^XBDIQ1(90050.01,BUDDILL,108)
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=Z
 .;CLINIC TYPE
 .I BUDDILL S Z=$$VAL^XBDIQ1(90050.01,BUDDILL,112)
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=Z
 .;DOS BEGIN
 .I BUDDILL S Z=$$VAL^XBDIQ1(90050.01,BUDDILL,102)
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=Z
 .;BILL TYPE
 .I BUDDILL S Z=$$VAL^XBDIQ1(90050.01,BUDDILL,4)
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=Z
 .;PRIMARY PROVIDER
 .I BUDDILL S Z=$$VAL^XBDIQ1(90050.01,BUDDILL,113)
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=Z
 .;HRN
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$HRN^AUPNPAT(DFN,DUZ(2))
 .;DOB
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$FMTE^XLFDT($$DOB^AUPNPAT(DFN))
 .;COMMUNITY
 .S BUDPIEC=BUDPIEC+1
 .S $P(BUDREC,U,BUDPIEC)=$$COMMRES^AUPNPAT(DFN,"E")
 .D SET
 .Q
 Q
SET ;
 S BUDT9C=BUDT9C+1
 S ^XTMP("BUDARP9DEL",BUDJ,BUDH,BUDDATE,BUDT9C)=BUDREC
 Q
OPIC ;EP
 ; I = IEN
 ; Y = 1:yes, 0:no
 ; X = Pointer to INSURER file.
 I '$G(P) Q 0
 I '$G(D) Q 0
 NEW I,Y,X,G
 S Y=0,U="^"
 I '$D(^DPT(P,0)) G OPICX
 I $P(^DPT(P,0),U,19) G OPICX
 I '$D(^AUPNPAT(P,0)) G OPICX
 I '$D(^AUPNPRVT(P,11)) G OPICX
 I $D(^DPT(P,.35)),$P(^(.35),U)]"",$P(^(.35),U)<D G OPICX
 S I=0,G=0
 F  S I=$O(^AUPNPRVT(P,11,I)) Q:I'=+I  D
 . Q:$P(^AUPNPRVT(P,11,I,0),U)=""
 . S G=0
 . S X=$P(^AUPNPRVT(P,11,I,0),U) Q:X=""
 . I X,$D(^BUDESITE(BUDSITE,12,"B",X)),$P(^BUDESITE(BUDSITE,12,X,0),U,2)="NI" Q
 . I $D(^BUDESITE(BUDSITE,12,"B",X)) S T=$P(^BUDESITE(BUDSITE,12,X,0),U,2) I T'="P" Q
 . I $P($G(^AUTNINS(X,2)),U,1)=T S G=1
 . Q:'G
 . Q:$P(^AUPNPRVT(P,11,I,0),U,6)>D
 . I $P(^AUPNPRVT(P,11,I,0),U,7)]"",$P(^(0),U,7)<D Q
 . S Y=1
 .Q
 I Y Q Y
OPICX ;EP
 Q Y
OPI ;EP
 ; I = IEN
 ; Y = 1:yes, 0:no
 ; X = Pointer to INSURER file.
 I '$G(P) Q 0
 I '$G(D) Q 0
 NEW I,Y,X,G
 S Y=0,U="^"
 I '$D(^DPT(P,0)) G OPIX
 I $P(^DPT(P,0),U,19) G OPIX
 I '$D(^AUPNPAT(P,0)) G OPIX
 I '$D(^AUPNPRVT(P,11)) G OPIX
 I $D(^DPT(P,.35)),$P(^(.35),U)]"",$P(^(.35),U)<D G OPIX
 S I=0,G=0
 F  S I=$O(^AUPNPRVT(P,11,I)) Q:I'=+I  D
 . Q:$P(^AUPNPRVT(P,11,I,0),U)=""
 . S G=0
 . S X=$P(^AUPNPRVT(P,11,I,0),U) Q:X=""
 . I $D(^BUDESITE(BUDSITE,12,"B",X)) S T=$P(^BUDESITE(BUDSITE,12,X,0),U,2) I T'="P" Q
 . I X,$D(^BUDESITE(BUDSITE,12,"B",X)),$P(^BUDESITE(BUDSITE,12,X,0),U,2)="NI" Q
 . ;I $P($G(^AUTNINS(X,2)),U,1)="G" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="I" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="SEP" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="T" S G=1
 . Q:$P(^AUPNPRVT(P,11,I,0),U,6)>D
 . I $P(^AUPNPRVT(P,11,I,0),U,7)]"",$P(^(0),U,7)<D Q
 . S Y=1
 .Q
 I Y Q Y
OPIX ;
 Q Y
PI ;EP
 ; I = IEN
 ; Y = 1:yes, 0:no
 ; X = Pointer to INSURER file.
 I '$G(P) Q 0
 I '$G(D) Q 0
 NEW I,Y,X,G,Z,T,HOLDT
 S Y=0,U="^"
 I '$D(^DPT(P,0)) G PIX
 I $P(^DPT(P,0),U,19) G PIX
 I '$D(^AUPNPAT(P,0)) G PIX
 I '$D(^AUPNPRVT(P,11)) G PIX
 I $D(^DPT(P,.35)),$P(^(.35),U)]"",$P(^(.35),U)<D G PIX
 S I=0,T="",HOLDT=""
 F  S I=$O(^AUPNPRVT(P,11,I)) Q:I'=+I  D
 . Q:$P(^AUPNPRVT(P,11,I,0),U)=""
 . S X=$P(^AUPNPRVT(P,11,I,0),U) Q:X=""
 . I X,$D(^BUDESITE(BUDSITE,12,"B",X)),$P(^BUDESITE(BUDSITE,12,X,0),U,2)="NI" Q
 . I $D(^BUDESITE(BUDSITE,12,"B",X)) S T=$P(^BUDESITE(BUDSITE,12,X,0),U,2) I T'="P" Q
 . Q:$P(^AUTNINS(X,0),U)["AHCCCS"
 . S G=0
 . I $P($G(^AUTNINS(X,2)),U,1)="C" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="F" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="H" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="M" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="P" S G=1
 . I $P($G(^AUTNINS(X,2)),U,1)="W" S G=1
 . Q:'G
 . Q:$P(^AUPNPRVT(P,11,I,0),U,6)>D
 . I $P(^AUPNPRVT(P,11,I,0),U,7)]"",$P(^(0),U,7)<D Q
 . S Y=1
 .Q
PIX ;
 I Y Q Y
 ;now check medicare eligible if any overrides to medicare
 I '$$OV(BUDSITE,"P") Q Y
 S I=0
 F  S I=$O(^AUPNMCR(P,11,I)) Q:I'=+I  D
 . Q:$P(^AUPNMCR(P,11,I,0),U)>D
 . S Z=$P(^AUPNMCR(P,11,I,0),U,4)
 . Q:'Z
 . Q:'$D(^BUDESITE(BUDSITE,12,"B",Z))
 . Q:$P(^BUDESITE(BUDSITE,12,Z,0),U,2)'="P"
 . I $P(^AUPNMCR(P,11,I,0),U,2)]"",$P(^(0),U,2)<D Q
 . S Y=1
 .Q
 I Y Q Y
 ;now check medicaid file
 S I=0 F  S I=$O(^AUPNMCD("B",P,I)) Q:I'=+I  D
 .Q:'$D(^AUPNMCD(I,11))
 .;S Z=$P(^AUPNMCD(I,0),U,2)
 .;get plan name/INSURER TYPE OF PLAN NAME
 .S N=$$VALI^XBDIQ1(9000004,I,.11)
 .Q:'N
 .Q:'$D(^BUDESITE(BUDSITE,12,"B",N))
 .Q:$P(^BUDESITE(BUDSITE,12,N,0),U,2)'="P"  ;not to be counted as PI
 .;I N S N=$$VALI^XBDIQ1(9999999.18,N,.21)
 .;I T="K" Q:N'="K"
 .;I T=""  Q:N="K"
 .S J=0 F  S J=$O(^AUPNMCD(I,11,J)) Q:J'=+J  D
 ..Q:J>D
 ..I $P(^AUPNMCD(I,11,J,0),U,2)]"",$P(^(0),U,2)<D Q
 ..S Y=1
 ..Q
 .Q
 Q Y
OV(BUDSITE,T) ;
 NEW X,G,Y
 S G=""
 S X=0 F  S X=$O(^BUDESITE(BUDSITE,12,X)) Q:X'=+X!(G)  D
 .S Y=$P(^BUDESITE(BUDSITE,12,X,0),U,2)
 .I Y=T S G=1
 Q G
ZIPINS(DFN,BUDLASTV) ;EP - ZIP INSURANCE
 NEW BUDHAS
 S BUDHAS=0
 S BUDHAS=$$PI^BUDERPC2(DFN,$$VD^APCLV(BUDLASTV))
 I BUDHAS=1 Q "e"
 S BUDHAS=$$MCR^BUDERPC2(DFN,$$VD^APCLV(BUDLASTV))
 I BUDHAS=1 Q "d"
 ;S BUDHAS=$$OPI(DFN,$$VD^APCLV(BUDLASTV),"W")
 ;I BUDHAS=1 D TINS(BUDAGE,"10a") Q
 S BUDHAS=$$RR^AUPNPAT(DFN,$$VD^APCLV(BUDLASTV))
 I BUDHAS=1 Q "c"
 S BUDHAS=$$OPI^BUDERPC2(DFN,$$VD^APCLV(BUDLASTV))
 I BUDHAS=1 Q "c"
 S BUDHAS=$$OPIC^BUDERPC2(DFN,$$VD^APCLV(BUDLASTV),"K")
 I BUDHAS=1 Q "c"
 S BUDHAS=$$MCD^BUDERPC2(DFN,$$VD^APCLV(BUDLASTV),"D")
 I BUDHAS=1 Q "c"
 S BUDHAS=$$MCD^BUDERPC2(DFN,$$VD^APCLV(BUDLASTV),"K")
 I BUDHAS=1 Q "c"
 ;now check workman's comp and 3rd party liability
 S BUDHAS=$$WC^BUDERPC2(DFN,BUDBD,BUDED)
 I BUDHAS=1 Q "e"
 S BUDHAS=$$TPL^BUDERPC2(DFN,BUDBD,BUDED)
 I BUDHAS=1 Q "c"
 ;now check guarantor file
 ;S BUDHAS=$$GUAR(DFN,BUDBD,BUDED)
 ;I BUDHAS=1 D TINS(BUDAGE,"7") Q
 Q "b"