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

BQITD13.m

Go to the documentation of this file.
BQITD13 ;VNGT/HS/ALA-Pregnancy ; 15 Jun 2011  9:13 AM
 ;;2.4;ICARE MANAGEMENT SYSTEM;;Apr 01, 2015;Build 41
 ;
 ;
POP(BQARY,TGLOB) ; EP
 ;
 ;Description
 ;  Finds all patients who meet the criteria for currently pregnant
 ;Input
 ;  BQARY - Array of taxonomies and other information
 ;  TGLOB - Global where data is to be stored
 ;          Structure:
 ;          TGLOB(DFN,"CRITERIA",criteria or taxonomy,visit or problem ien)=date/time
 ;
 NEW BQFLG,BQTIME,BQTM
 S BQFLG=$P($G(^BQI(90508,1,16)),U,1),BQTIME=$P($G(^BQI(90508,1,16)),U,2)
 ; ILI Algorithm
 I BQFLG="L" D
 . NEW BQDFN
 . S BQDFN=0
 . F  S BQDFN=$O(^DPT(BQDFN)) Q:'BQDFN  D
 .. I $$PNM^APCLSIL1(BQDFN,DT)="Y" S @TGLOB@(BQDFN)=""
 ;
 ; iCare Algorithm
 I BQFLG="I" D
 . NEW REVPER,TREF,NREF,TAX,EDATE,TMGL,BDFN,BDTM,VIS,IEN,DXN
 . S BQTM=(BQTIME*30.4167)
 . S EDATE=DT
 . S REVPER=$$FMADD^XLFDT(EDATE,-(BQTM))
 . S TREF=$NA(^TMP("BQITAX",UID)) K @TREF
 . F TAX="BQI PREGNANCY DXS" D BLD^BQITUTL(TAX,TREF)
 . S TMGL=$NA(^TMP("BQIPREG",UID)) K @TMGL
 . D POV(.TMGL,TREF,REVPER,"")
 . ;
 . ; Exceptions
 . S NREF="ARRAY" K @NREF
 . F TAX="BGP MISCARRIAGE/ABORTION DXS","SURVEILLANCE H1N1 DELIVERY DX" D BLD^BQITUTL(TAX,NREF)
 . D EPOV(.TMGL,.NREF,REVPER,"")
 . K @NREF,@TREF
 . ; Procedures
 . S NREF="ARRAY" K @NREF
 . F TAX="BGP ABORTION PROCEDURES","BQI DELIVERY PROCEDURES" D BLD^BQITUTL(TAX,NREF)
 . D EPRC(.TMGL,.NREF,REVPER,"")
 . ; CPTs
 . S TREF="BQITAX" K @TREF
 . F TAX="BGP CPT ABORTION","BGP CPT MISCARRIAGE","SURVEILLANCE H1N1 DELIVERY CPT" D BLD^BQITUTL(TAX,TREF)
 . D ECPT(.TMGL,.TREF,REVPER,"")
 . K @TREF
 . ;
 . S BDFN=""
 . F  S BDFN=$O(@TMGL@(BDFN)) Q:BDFN=""  D PARS(BDFN,TGLOB)
 Q
 ;
POV(GLB,TREF,REVPER,BQDFN) ;EP
 NEW TIEN,VDATA,PDATA,VISIT,VSDTM,IEN,DFN,BGDT,ENDT
 I $G(BQDFN)="" D
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVPOV("B",TIEN,IEN),-1) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVPOV(IEN,0)) I PDATA="" Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 ... I VSDTM<REVPER!(VSDTM>EDATE) Q
 ... S TYP=@TREF@(TIEN),DFN=$P(VDATA,U,5)
 ... S @GLB@(DFN,VSDTM,VISIT,IEN)=TYP_U_TAX
 ;
 I $G(BQDFN)'="" D
 . S BGDT=(9999999-DT)-1,ENDT=9999999-REVPER
 . F  S BGDT=$O(^AUPNVPOV("AA",BQDFN,BGDT)) Q:BGDT=""!(BGDT>ENDT)  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVPOV("AA",BQDFN,BGDT,IEN)) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVPOV(IEN,0)) I PDATA="" Q
 ... S TIEN=$P(PDATA,U,1)
 ... I '$D(@TREF@(TIEN)) Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 ... S TYP=@TREF@(TIEN),DFN=$P(VDATA,U,5)
 ... S @GLB@(DFN,VSDTM,VISIT,IEN)=TYP_U_TAX
 Q
 ;
EPOV(GLB,TREF,REVPER,BQDFN) ;EP
 NEW TIEN,VDATA,PDATA,VISIT,VSDTM,IEN,DFN
 I $G(BQDFN)="" D
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVPOV("B",TIEN,IEN),-1) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVPOV(IEN,0)) I PDATA="" Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 ... I VSDTM<REVPER!(VSDTM>EDATE) Q
 ... S DFN=$P(VDATA,U,5)
 ... I $D(@GLB@(DFN)) D
 .... NEW PDTM
 .... S PDTM="" F  S PDTM=$O(@GLB@(DFN,PDTM)) Q:PDTM=""  D
 ..... I PDTM<VSDTM K @GLB@(DFN,PDTM)
 ;
 I $G(BQDFN)'="" D
 . S BGDT=(9999999-DT)-1,ENDT=9999999-REVPER
 . F  S BGDT=$O(^AUPNVPOV("AA",BQDFN,BGDT)) Q:BGDT=""!(BGDT>ENDT)  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVPOV("AA",BQDFN,BGDT,IEN)) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVPOV(IEN,0)) I PDATA="" Q
 ... S TIEN=$P(PDATA,U,1)
 ... I '$D(@TREF@(TIEN)) Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S DFN=$P(VDATA,U,5),VSDTM=$P(VDATA,U,1)\1
 ... I $D(@GLB@(DFN)) D
 .... NEW PDTM
 .... S PDTM="" F  S PDTM=$O(@GLB@(DFN,PDTM)) Q:PDTM=""  D
 ..... I PDTM<VSDTM K @GLB@(DFN,PDTM)
 Q
 ;
ECPT(GLB,TREF,REVPER,BQDFN) ;
 NEW TIEN,VDATA,PDATA,VISIT,VSDTM,DFN
 I $G(BQDFN)="" D
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVCPT("B",TIEN,IEN),-1) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVCPT(IEN,0)) I PDATA="" Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 ... I VSDTM<REVPER!(VSDTM>EDATE) Q
 ... S DFN=$P(VDATA,U,5)
 ... I $D(@GLB@(DFN)) D
 .... NEW PDTM
 .... S PDTM="" F  S PDTM=$O(@GLB@(DFN,PDTM)) Q:PDTM=""  D
 ..... I PDTM<VSDTM K @GLB@(DFN,PDTM)
 ;
 I $G(BQDFN)'="" D
 . S BGDT=(9999999-DT)-1,ENDT=9999999-REVPER
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. F  S BGDT=$O(^AUPNVCPT("AA",BQDFN,TIEN,BGDT)) Q:BGDT=""!(BGDT>ENDT)  D
 ... S IEN=""
 ... F  S IEN=$O(^AUPNVCPT("AA",BQDFN,TIEN,BGDT,IEN)) Q:IEN=""  D
 .... S PDATA=$G(^AUPNVCPT(IEN,0)) I PDATA="" Q
 .... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 .... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 .... I $P(VDATA,U,11)=1 Q
 .... Q:"AORSHI"'[$P(VDATA,U,7)
 .... S DFN=$P(VDATA,U,5),VSDTM=$P(VDATA,U,1)\1
 .... I $D(@GLB@(DFN)) D
 ..... NEW PDTM
 ..... S PDTM="" F  S PDTM=$O(@GLB@(DFN,PDTM)) Q:PDTM=""  D
 ...... I PDTM<VSDTM K @GLB@(DFN,PDTM)
 Q
 ;
EPRC(GLB,TREF,REVPER,BQDFN) ;EP
 NEW TIEN,VDATA,PDATA,VISIT,VSDTM,IEN,DFN
 I $G(BQDFN)="" D
 . S TIEN=""
 . F  S TIEN=$O(@TREF@(TIEN)) Q:TIEN=""  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVPRC("B",TIEN,IEN),-1) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVPRC(IEN,0)) I PDATA="" Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 ... I VSDTM<REVPER!(VSDTM>EDATE) Q
 ... S DFN=$P(VDATA,U,5)
 ... I $D(@GLB@(DFN)) D
 .... NEW PDTM
 .... S PDTM="" F  S PDTM=$O(@GLB@(DFN,PDTM)) Q:PDTM=""  D
 ..... I PDTM<VSDTM K @GLB@(DFN,PDTM)
 ;
 I $G(BQDFN)'="" D
 . S BGDT=(9999999-DT)-1,ENDT=9999999-REVPER
 . F  S BGDT=$O(^AUPNVPRC("AA",BQDFN,BGDT)) Q:BGDT=""!(BGDT>ENDT)  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVPRC("AA",BQDFN,BGDT,IEN)) Q:IEN=""  D
 ... S PDATA=$G(^AUPNVPRC(IEN,0)) I PDATA="" Q
 ... S TIEN=$P(PDATA,U,1)
 ... I '$D(@TREF@(TIEN)) Q
 ... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... Q:"AORSHI"'[$P(VDATA,U,7)
 ... S DFN=$P(VDATA,U,5),VSDTM=$P(VDATA,U,1)\1
 ... I $D(@GLB@(DFN)) D
 .... NEW PDTM
 .... S PDTM="" F  S PDTM=$O(@GLB@(DFN,PDTM)) Q:PDTM=""  D
 ..... I PDTM<VSDTM K @GLB@(DFN,PDTM)
 Q
 ;
PAT(DEF,BTGLOB,BDFN) ;EP -- Get value for a single patient
 NEW DXOK,BQDXN,BQREF,BQFLG,BQTIME,BQTM,EDATE,REVPER,TREF,TAX,TMGL,NREF
 S BQFLG=$P($G(^BQI(90508,1,16)),U,1),BQTIME=$P($G(^BQI(90508,1,16)),U,2)
 S DXOK=0
 ; ILI Algorithm
 I BQFLG="L" D
 . I $$PNM^APCLSIL1(BDFN,DT)="Y" S DXOK=1
 ;
 ; iCare Algorithm
 I BQFLG="I" D
 . S BQTM=(BQTIME*30.4167)
 . S EDATE=DT
 . S REVPER=$$FMADD^XLFDT(EDATE,-(BQTM))
 . S TREF=$NA(^TMP("BQITAX",UID)) K @TREF
 . F TAX="BQI PREGNANCY DXS" D BLD^BQITUTL(TAX,TREF)
 . S TMGL=$NA(^TMP("BQIPREG",UID)) K @TMGL
 . D POV(.TMGL,TREF,REVPER,BDFN)
 . ;
 . ; Exceptions
 . S NREF="ARRAY" K @NREF
 . F TAX="BGP MISCARRIAGE/ABORTION DXS","SURVEILLANCE H1N1 DELIVERY DX" D BLD^BQITUTL(TAX,NREF)
 . D EPOV(.TMGL,.NREF,REVPER,BDFN)
 . K @NREF,@TREF
 . ; Procedures
 . S NREF="ARRAY" K @NREF
 . F TAX="BGP ABORTION PROCEDURES","BQI DELIVERY PROCEDURES" D BLD^BQITUTL(TAX,NREF)
 . D EPRC(.TMGL,.NREF,REVPER,BDFN)
 . ; CPTs
 . S TREF="BQITAX" K @TREF
 . F TAX="BGP CPT ABORTION","BGP CPT MISCARRIAGE","SURVEILLANCE H1N1 DELIVERY CPT" D BLD^BQITUTL(TAX,TREF)
 . D ECPT(.TMGL,.TREF,REVPER,BDFN)
 . K @TREF
 . ;
 . I $D(@TMGL@(BDFN)) S DXOK=1 D PARS(BDFN,BTGLOB)
 Q DXOK
 ;
PARS(BQDFN,GLOB) ;EP
 NEW BDTM,VIS,IEN,DXN
 S BDTM="" F  S BDTM=$O(@TMGL@(BQDFN,BDTM)) Q:BDTM=""  D
 . S VIS="" F  S VIS=$O(@TMGL@(BQDFN,BDTM,VIS)) Q:VIS=""  D
 .. S IEN="" F  S IEN=$O(@TMGL@(BQDFN,BDTM,VIS,IEN)) Q:IEN=""  D
 ... S DXN=@TMGL@(BQDFN,BDTM,VIS,IEN)
 ... I $P(DXN,U,5)'="" S DXN=$P(DXN,U,5)
 ... S @GLOB@(BQDFN,"CRITERIA",DXN,"V",VIS,IEN)=$P(^AUPNVSIT(VIS,0),U,1)_U_U_IEN_U_9000010.07
 Q
 ;
EPG(BQIDFN) ;EP - Pregnancy ended?
 NEW X,NREF,TAX,X
 S NREF="ARRAY" K @NREF
 F TAX="BGP MISCARRIAGE/ABORTION DXS","SURVEILLANCE H1N1 DELIVERY DX" D BLD^BQITUTL(TAX,NREF)
 S X=$$TAX^BQITRUTL("T-8M","",1,BQIDFN,9000010.07,"","",.NREF)
 I X Q 1
 S NREF="ARRAY" K @NREF
 F TAX="BGP ABORTION PROCEDURES","BQI DELIVERY PROCEDURES" D BLD^BQITUTL(TAX,NREF)
 S X=$$TAX^BQITRUTL("T-8M","",1,BQIDFN,9000010.08,"","",.NREF)
 I X Q 1
 S NREF="BQITAX" K @NREF
 F TAX="BGP CPT ABORTION","BGP CPT MISCARRIAGE","SURVEILLANCE H1N1 DELIVERY CPT" D BLD^BQITUTL(TAX,NREF)
 S X=$$TAX^BQITRUTL("T-8M","",1,BQIDFN,9000010.18,"","",.NREF)
 I X Q 1
 Q 0