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

BQITDINS.m

Go to the documentation of this file.
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