BQITDINS ;GDIT/HS/ALA-Active Insurance ; 17 Dec 2014 7:48 AM
;;2.5;ICARE MANAGEMENT SYSTEM;;May 24, 2016;Build 27
;
;
EN ; EP
NEW DFN,BQI,BQIDATA
S DFN=0
F S DFN=$O(^BQIPAT(DFN)) Q:'DFN D
. ; Remove previous insurance
. NEW DA,DIK
. S DA(1)=DFN,DA=0,DIK="^BQIPAT("_DA(1)_",70,"
. F S DA=$O(^BQIPAT(DFN,70,DA)) Q:'DA D ^DIK
. K BQIDATA
. D GET(DFN)
. I BQI=0 Q
. ; if the patient doesn't already exist in the iCare Patient file, add them
. I $G(^BQIPAT(DFN,0))="" D NPT^BQITASK(DFN)
. S DA(1)=DFN
. I '$D(^BQIPAT(DFN,70,0)) S ^BQIPAT(DFN,20,0)="^90507.57^^"
. F I=1:1:BQI D
.. NEW DIC,DLAYGO,X,IENS,X,Y
.. S DIC(0)="L",DIC="^BQIPAT("_DA(1)_",70,",DLAYGO=90507.57,DIC("P")=DLAYGO
.. S X=$P(BQIDATA(I),"^",1)
.. K DO,DD D FILE^DICN
.. S DA=+Y S:DA=-1 DA=1
.. S IENS=$$IENS^DILF(.DA)
.. S BQIUPD(90507.57,IENS,.01)=X,BQIUPD(90507.57,IENS,.02)=$P(BQIDATA(I),"^",2)
.. S BQIUPD(90507.57,IENS,.03)=$P(BQIDATA(I),"^",3)
.. D FILE^DIE("","BQIUPD","ERROR")
;
Q
;
GET(DFN) ; EP -- BQI PATIENT INSURANCE
;
S BQI=0
;
; Check for Medicare
I $G(^AUPNMCR(DFN,0))'="" D
. S INSCO=$$GET1^DIQ(9000003,DFN_",",.02,"E")
. S IEN=0
. F S IEN=$O(^AUPNMCR(DFN,11,IEN)) Q:'IEN D
.. NEW DA,IENS,EFF,EXP,INSC
.. S DA(1)=DFN,DA=IEN,IENS=$$IENS^DILF(.DA)
.. S EFF=$$GET1^DIQ(9000003.11,IENS,.01,"I")
.. S EXP=$$GET1^DIQ(9000003.11,IENS,.02,"I")
.. I '$$ISACTIVE(EFF,EXP) Q
.. S INSC=$$GET1^DIQ(9000003,DFN_",",.02,"I")
.. S BQI=BQI+1
.. S BQIDATA(BQI)=INSCO_" "_$$GET1^DIQ(9000003.11,IENS,.03,"E")_"^"_INSC_"^"_$$FMTE^BQIUL1($$GET1^DIQ(9000003.11,IENS,.01,"I"))
;
; Check for Railroad
I $G(^AUPNRRE(DFN,0))'="" D
. S INSCO=$$GET1^DIQ(9000005,DFN_",",.02,"E")
. S IEN=0
. F S IEN=$O(^AUPNRRE(DFN,11,IEN)) Q:'IEN D
.. NEW DA,IENS,EFF,EXP,INSC
.. S DA(1)=DFN,DA=IEN,IENS=$$IENS^DILF(.DA)
.. S EFF=$$GET1^DIQ(9000005.11,IENS,.01,"I")
.. S EXP=$$GET1^DIQ(9000005.11,IENS,.02,"I")
.. I '$$ISACTIVE(EFF,EXP) Q
.. S INSC=$$GET1^DIQ(9000005,DFN_",",.02,"I")
.. S BQI=BQI+1
.. S BQIDATA(BQI)=INSCO_" "_$$GET1^DIQ(9000005.11,IENS,.03,"E")_"^"_INSC_"^"_$$FMTE^BQIUL1($$GET1^DIQ(9000005.11,IENS,.01,"I"))
;
; Check for Medicaid
S IEN=""
F S IEN=$O(^AUPNMCD("B",DFN,IEN)) Q:IEN="" D
. S INSCO=$$GET1^DIQ(9000004,IEN_",",.02,"E")
. S MN=0
. F S MN=$O(^AUPNMCD(IEN,11,MN)) Q:'MN D
.. NEW DA,IENS,EFF,EXP,INSC
.. S DA(1)=IEN,DA=MN,IENS=$$IENS^DILF(.DA)
.. S EFF=$$GET1^DIQ(9000004.11,IENS,.01,"I")
.. S EXP=$$GET1^DIQ(9000004.11,IENS,.02,"I")
.. I '$$ISACTIVE(EFF,EXP) Q
.. S INSC=$$GET1^DIQ(9000004,IEN_",",.02,"I")
.. S BQI=BQI+1
.. S BQIDATA(BQI)=INSCO_" "_$$GET1^DIQ(9000004.11,IENS,.03,"E")_"^"_INSC_"^"_$$FMTE^BQIUL1($$GET1^DIQ(9000004.11,IENS,.01,"I"))
;
; Check for Private Insurance
N AGD S AGD=0
F S AGD=$O(^AUPNPRVT(DFN,11,AGD)) Q:'AGD D
. N DA,IENS,EFF,EXP,POLH,COV,INSC
. S DA(1)=DFN,DA=AGD,IENS=$$IENS^DILF(.DA)
. S EFF=$$GET1^DIQ(9000006.11,IENS,".06","I")
. S EXP=$$GET1^DIQ(9000006.11,IENS,".07","I")
. I '$$ISACTIVE(EFF,EXP) Q
. S POLH=$$GET1^DIQ(9000006.11,IENS,".08","I")
. S INSC=$$GET1^DIQ(9000006.11,IENS,".01","I")
. S COV="" S:POLH]"" COV=$$GET1^DIQ(9000003.1,POLH_",",".05","E")
. S BQI=BQI+1
. S BQIDATA(BQI)=$$GET1^DIQ(9000006.11,IENS,".01","E")_" "_COV_"^"_INSC_"^"_$$FMTE^BQIUL1(EFF)
Q
;
;
ISACTIVE(EFFDT,ENDDT) ;EP - POL. ACTIVE TODAY?
N OPENEND
I EFFDT="",(ENDDT="") Q 0
S ENDDT=ENDDT
S OPENEND=ENDDT=""
I OPENEND I DT=EFFDT!(DT>EFFDT) Q 1
I DT=EFFDT!(DT=ENDDT) Q 1
I DT>EFFDT&(DT<ENDDT) Q 1
Q 0
BQITDINS ;GDIT/HS/ALA-Active Insurance ; 17 Dec 2014 7:48 AM
+1 ;;2.5;ICARE MANAGEMENT SYSTEM;;May 24, 2016;Build 27
+2 ;
+3 ;
EN ; EP
+1 NEW DFN,BQI,BQIDATA
+2 SET DFN=0
+3 FOR
SET DFN=$ORDER(^BQIPAT(DFN))
IF 'DFN
QUIT
Begin DoDot:1
+4 ; Remove previous insurance
+5 NEW DA,DIK
+6 SET DA(1)=DFN
SET DA=0
SET DIK="^BQIPAT("_DA(1)_",70,"
+7 FOR
SET DA=$ORDER(^BQIPAT(DFN,70,DA))
IF 'DA
QUIT
DO ^DIK
+8 KILL BQIDATA
+9 DO GET(DFN)
+10 IF BQI=0
QUIT
+11 ; if the patient doesn't already exist in the iCare Patient file, add them
+12 IF $GET(^BQIPAT(DFN,0))=""
DO NPT^BQITASK(DFN)
+13 SET DA(1)=DFN
+14 IF '$DATA(^BQIPAT(DFN,70,0))
SET ^BQIPAT(DFN,20,0)="^90507.57^^"
+15 FOR I=1:1:BQI
Begin DoDot:2
+16 NEW DIC,DLAYGO,X,IENS,X,Y
+17 SET DIC(0)="L"
SET DIC="^BQIPAT("_DA(1)_",70,"
SET DLAYGO=90507.57
SET DIC("P")=DLAYGO
+18 SET X=$PIECE(BQIDATA(I),"^",1)
+19 KILL DO,DD
DO FILE^DICN
+20 SET DA=+Y
IF DA=-1
SET DA=1
+21 SET IENS=$$IENS^DILF(.DA)
+22 SET BQIUPD(90507.57,IENS,.01)=X
SET BQIUPD(90507.57,IENS,.02)=$PIECE(BQIDATA(I),"^",2)
+23 SET BQIUPD(90507.57,IENS,.03)=$PIECE(BQIDATA(I),"^",3)
+24 DO FILE^DIE("","BQIUPD","ERROR")
End DoDot:2
End DoDot:1
+25 ;
+26 QUIT
+27 ;
GET(DFN) ; EP -- BQI PATIENT INSURANCE
+1 ;
+2 SET BQI=0
+3 ;
+4 ; Check for Medicare
+5 IF $GET(^AUPNMCR(DFN,0))'=""
Begin DoDot:1
+6 SET INSCO=$$GET1^DIQ(9000003,DFN_",",.02,"E")
+7 SET IEN=0
+8 FOR
SET IEN=$ORDER(^AUPNMCR(DFN,11,IEN))
IF 'IEN
QUIT
Begin DoDot:2
+9 NEW DA,IENS,EFF,EXP,INSC
+10 SET DA(1)=DFN
SET DA=IEN
SET IENS=$$IENS^DILF(.DA)
+11 SET EFF=$$GET1^DIQ(9000003.11,IENS,.01,"I")
+12 SET EXP=$$GET1^DIQ(9000003.11,IENS,.02,"I")
+13 IF '$$ISACTIVE(EFF,EXP)
QUIT
+14 SET INSC=$$GET1^DIQ(9000003,DFN_",",.02,"I")
+15 SET BQI=BQI+1
+16 SET BQIDATA(BQI)=INSCO_" "_$$GET1^DIQ(9000003.11,IENS,.03,"E")_"^"_INSC_"^"_$$FMTE^BQIUL1($$GET1^DIQ(9000003.11,IENS,.01,"I"))
End DoDot:2
End DoDot:1
+17 ;
+18 ; Check for Railroad
+19 IF $GET(^AUPNRRE(DFN,0))'=""
Begin DoDot:1
+20 SET INSCO=$$GET1^DIQ(9000005,DFN_",",.02,"E")
+21 SET IEN=0
+22 FOR
SET IEN=$ORDER(^AUPNRRE(DFN,11,IEN))
IF 'IEN
QUIT
Begin DoDot:2
+23 NEW DA,IENS,EFF,EXP,INSC
+24 SET DA(1)=DFN
SET DA=IEN
SET IENS=$$IENS^DILF(.DA)
+25 SET EFF=$$GET1^DIQ(9000005.11,IENS,.01,"I")
+26 SET EXP=$$GET1^DIQ(9000005.11,IENS,.02,"I")
+27 IF '$$ISACTIVE(EFF,EXP)
QUIT
+28 SET INSC=$$GET1^DIQ(9000005,DFN_",",.02,"I")
+29 SET BQI=BQI+1
+30 SET BQIDATA(BQI)=INSCO_" "_$$GET1^DIQ(9000005.11,IENS,.03,"E")_"^"_INSC_"^"_$$FMTE^BQIUL1($$GET1^DIQ(9000005.11,IENS,.01,"I"))
End DoDot:2
End DoDot:1
+31 ;
+32 ; Check for Medicaid
+33 SET IEN=""
+34 FOR
SET IEN=$ORDER(^AUPNMCD("B",DFN,IEN))
IF IEN=""
QUIT
Begin DoDot:1
+35 SET INSCO=$$GET1^DIQ(9000004,IEN_",",.02,"E")
+36 SET MN=0
+37 FOR
SET MN=$ORDER(^AUPNMCD(IEN,11,MN))
IF 'MN
QUIT
Begin DoDot:2
+38 NEW DA,IENS,EFF,EXP,INSC
+39 SET DA(1)=IEN
SET DA=MN
SET IENS=$$IENS^DILF(.DA)
+40 SET EFF=$$GET1^DIQ(9000004.11,IENS,.01,"I")
+41 SET EXP=$$GET1^DIQ(9000004.11,IENS,.02,"I")
+42 IF '$$ISACTIVE(EFF,EXP)
QUIT
+43 SET INSC=$$GET1^DIQ(9000004,IEN_",",.02,"I")
+44 SET BQI=BQI+1
+45 SET BQIDATA(BQI)=INSCO_" "_$$GET1^DIQ(9000004.11,IENS,.03,"E")_"^"_INSC_"^"_$$FMTE^BQIUL1($$GET1^DIQ(9000004.11,IENS,.01,"I"))
End DoDot:2
End DoDot:1
+46 ;
+47 ; Check for Private Insurance
+48 NEW AGD
SET AGD=0
+49 FOR
SET AGD=$ORDER(^AUPNPRVT(DFN,11,AGD))
IF 'AGD
QUIT
Begin DoDot:1
+50 NEW DA,IENS,EFF,EXP,POLH,COV,INSC
+51 SET DA(1)=DFN
SET DA=AGD
SET IENS=$$IENS^DILF(.DA)
+52 SET EFF=$$GET1^DIQ(9000006.11,IENS,".06","I")
+53 SET EXP=$$GET1^DIQ(9000006.11,IENS,".07","I")
+54 IF '$$ISACTIVE(EFF,EXP)
QUIT
+55 SET POLH=$$GET1^DIQ(9000006.11,IENS,".08","I")
+56 SET INSC=$$GET1^DIQ(9000006.11,IENS,".01","I")
+57 SET COV=""
IF POLH]""
SET COV=$$GET1^DIQ(9000003.1,POLH_",",".05","E")
+58 SET BQI=BQI+1
+59 SET BQIDATA(BQI)=$$GET1^DIQ(9000006.11,IENS,".01","E")_" "_COV_"^"_INSC_"^"_$$FMTE^BQIUL1(EFF)
End DoDot:1
+60 QUIT
+61 ;
+62 ;
ISACTIVE(EFFDT,ENDDT) ;EP - POL. ACTIVE TODAY?
+1 NEW OPENEND
+2 IF EFFDT=""
IF (ENDDT="")
QUIT 0
+3 SET ENDDT=ENDDT
+4 SET OPENEND=ENDDT=""
+5 IF OPENEND
IF DT=EFFDT!(DT>EFFDT)
QUIT 1
+6 IF DT=EFFDT!(DT=ENDDT)
QUIT 1
+7 IF DT>EFFDT&(DT<ENDDT)
QUIT 1
+8 QUIT 0