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

BQIDCAH.m

Go to the documentation of this file.
BQIDCAH ;PRXM/HC/ALA-Ad Hoc Search ; 16 Nov 2005  6:26 PM
 ;;2.6;ICARE MANAGEMENT SYSTEM;;Jul 07, 2017;Build 72
 ;
 Q
 ;
PARMS(DATA,CDATA,FGLOB,PARMS,MPARMS,APARMS,MAPARMS) ;EP -  Execute Ad Hoc Search
 ;
 ;Description
 ;  Ad Hoc Search which can be an assortment of parameters including;
 ;  GENDER, COMMUNITY, PROVIDER, VISIT DATES, AGE
 ;Input
 ;  FGLOB = From global (only sent for filters)
 ;  PARMS = Array of parameters and their values
 ;  MPARMS = Multiple array of a parameter
 ;Expected to return DATA
 ;
 NEW JJ,KK,UID,TGLOB,SEX,COMM,PROV,FROM,THRU,AGE,CRIT1,MRANGE,MRFROM,MRTHRU
 NEW CRIT2,NM,DXCAT,PLIDEN,NUMVIS,COMMTX,BEN,VDATA,VNDATA,VODATA,EMPL,VISOP
 NEW CLIN,DXOP,RANGE,RFROM,RTHRU,DEC,DECCOD,BNEW,VCRIT1,VCRIT2,DECFDT,DECTDT
 NEW ALLERGY,ALLOP,LFROM,LTHRU,LRANGE,LRFROM,LRTHRU,LAB,MED,MFROM,MTHRU,VSDTM
 NEW VIS,MEDTX,LABTX,MDOP,LIV,LBOP,INAC,IEN,CPOP,CFROM,CTHRU,CRANGE,CPT,CPTX
 NEW PROB,PROP,PPFROM,PPTHRU,PRANGE,PRSTAT,NUMLAB,SETLAB,ETHN,RACE,PLANG,PCOMM
 NEW DBFROM,DBTHRU,PRNDC,PRNRV,PRNAC,CRIT,ALNAS,ALNKN,LNOT,MNOT,PFROM,PTHRU
 NEW CNOT,CPTTX,CPFROM,CPTHRU,MD,PRFROM,PRTHRU,PROBTX,EDUFROM,EDUTHRU,EDURANGE
 NEW EDUTX,EDUC,EDUPICK,EDUTOP,EDUNOT,EDUOP,EDFROM,EDTHRU,EFROM,ETHRU,MDNAC
 NEW MDNDC,MDNRV,REMCODE,RMDFROM,RMDTHRU,RMDRANGE,OVD,FUT,RMFROM,RDFROM,RMTHRU
 NEW RDTHRU,DEMO,POV,POVTX,PVFROM,PVTHRU,PVRANGE,POVS,POVSB,MEAS,MSNOT,MSFROM,MSTHRU
 NEW MSRANGE,MSOP,PVOP,BPOP,ABPOP
 ;
 I '$D(PARMS),'$D(MPARMS),'$D(APARMS),'$D(MAPARMS) Q
 S NM=""
 F  S NM=$O(PARMS(NM)) Q:NM=""  S @NM=PARMS(NM)
 ;
 S SEX=$G(SEX,""),COMM=$G(COMM,"")
 S ETHN=$G(ETHN,""),RACE=$G(RACE,""),PLANG=$G(PLANG,""),PCOMM=$G(PCOMM,"")
 S DBFROM=$G(DBFROM,""),DBTHRU=$G(DBTHRU,"")
 S FROM=$G(FROM,""),THRU=$G(THRU,""),FGLOB=$G(FGLOB,"")
 S DXCAT=$G(DXCAT,""),PLIDEN=$G(PLIDEN,"")
 S BEN=$G(BEN,"") ; Beneficiary
 S DXOP=$G(DXOP,"!"),VISOP=$G(VISOP,"!"),BPOP=$G(BPOP,"!"),ABPOP=$G(ABPOP,"!")
 S RANGE=$G(RANGE,"")
 S DEC=$G(DEC,"N"),DECCOD=$G(DECCOD,"") ; Deceased
 S LIV=$G(LIV,"Y") ; Living
 S DEMO=$G(DEMO,"E") ; Demo patients
 S INAC=$G(INAC,"N") ; Inactive patients
 S DECFDT=$G(DECFDT,""),DECTDT=$G(DECTDT,"") ;Deceased Date Range
 S DECCOD=$G(DECCOD,"")
 S ALLERGY=$G(ALLERGY,""),ALLOP=$G(ALLOP,"!"),ALNAS=$G(ALNAS,""),ALNKN=$G(ALNKN,"")
 S LAB=$G(LAB,""),MED=$G(MED,""),CPT=$G(CPT,""),POV=$G(POV,""),POVS=$G(POVS,""),MEAS=$G(MEAS,"")
 S LABTX=$G(LABTX,""),MEDTX=$G(MEDTX,""),CPTTX=$G(CPTTX,""),POVTX=$G(POVTX,""),POVSB=$G(POVSB,"")
 S LBOP=$G(LBOP,"!"),MDOP=$G(MDOP,"!"),CPOP=$G(CPOP,"!"),PROP=$G(PROP,"!"),EDUOP=$G(EDUOP,"!"),PVOP=$G(PVOP,"!"),MSOP=$G(MSOP,"!")
 S EMPL=$G(EMPL,"")
 S LNOT=$S($G(LNOT)="Y":1,1:0),MNOT=$S($G(MNOT)="Y":1,1:0),CNOT=$S($G(CNOT)="Y":1,1:0),EDUNOT=$S($G(EDUNOT)="Y":1,1:0)
 S MSNOT=$S($G(MSNOT)="Y":1,1:0)
 S PROB=$G(PROB,""),PRSTAT=$G(PRSTAT,""),PRNDC=$G(PRNDC,""),PRNRV=$G(PRNRV,""),PRNAC=$G(PRNAC,"")
 S PROBTX=$G(PROBTX,"")
 S EDUTX=$G(EDUTX,""),EDUC=$G(EDUC,""),EDUPICK=$G(EDUPICK,""),EDUTOP=$G(EDUTOP,"")
 S OVD=$G(OVD,0),FUT=$G(FUT,0)
 ;
 ; If timeframe is selected populate start and end dates
 I RANGE'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(RANGE,PPIEN,"RANGE") S RFROM=$G(RFROM,""),RTHRU=$G(RTHRU,"")
 S FROM=$S($G(RFROM)'="":RFROM,1:$G(FROM))
 S THRU=$S($G(RTHRU)'="":RTHRU,1:$G(THRU))
 K RFROM,RTHRU
 ;
 I $G(LRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(LRANGE,PPIEN,"LRANGE") S LRFROM=$G(RFROM,""),LRTHRU=$G(RTHRU,"")
 S LFROM=$S($G(LRFROM)'="":LRFROM,1:$G(LFROM))
 S LTHRU=$S($G(LRTHRU)'="":LRTHRU,1:$G(LTHRU))
 K RFROM,RTHRU
 ;
 I $G(MRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(MRANGE,PPIEN,"MRANGE") S MRFROM=$G(RFROM,""),MRTHRU=$G(RTHRU,"")
 S MFROM=$S($G(MRFROM)'="":MRFROM,1:$G(MFROM))
 S MTHRU=$S($G(MRTHRU)'="":MRTHRU,1:$G(MTHRU))
 K RFROM,RTHRU
 ;
 I $G(CRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(CRANGE,PPIEN,"CRANGE") S CPFROM=$G(RFROM,""),CPTHRU=$G(RTHRU,"")
 S CFROM=$S($G(CPFROM)'="":CPFROM,1:$G(CFROM))
 S CTHRU=$S($G(CPTHRU)'="":CPTHRU,1:$G(CTHRU))
 K RFROM,RTHRU
 ;
 I $G(PRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(PRANGE,PPIEN,"PRANGE") S PPFROM=$G(RFROM,""),PPTHRU=$G(RTHRU,"")
 S PFROM=$S($G(PPFROM)'="":PPFROM,1:$G(PRFROM))
 S PTHRU=$S($G(PPTHRU)'="":PPTHRU,1:$G(PRTHRU))
 K RFROM,RTHRU
 ;
 I $G(EDURANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(EDURANGE,PPIEN,"EDURANGE") S EDFROM=$G(RFROM,""),EDTHRU=$G(RTHRU,"")
 S EFROM=$S($G(EDFROM)'="":EDFROM,1:$G(EDUFROM))
 S ETHRU=$S($G(EDTHRU)'="":EDTHRU,1:$G(EDUTHRU))
 K RFROM,RTHRU
 ;
 I $G(RMDRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(RMDRANGE,PPIEN,"RMDRANGE") S RDFROM=$G(RFROM,""),RDTHRU=$G(RTHRU,"")
 S RMFROM=$S($G(RDFROM)'="":RDFROM,1:$G(RMDFROM))
 S RMTHRU=$S($G(RDTHRU)'="":RDTHRU,1:$G(RMDTHRU))
 K RFROM,RTHRU,RDFROM,RDTHRU
 ;
 I $G(PVRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(PVRANGE,PPIEN,"PVRANGE") S RDFROM=$G(RFROM,""),RDTHRU=$G(RTHRU,"")
 S PVFROM=$S($G(RDFROM)'="":RDFROM,1:$G(PVFROM))
 S PVTHRU=$S($G(RDTHRU)'="":RDTHRU,1:$G(PVTHRU))
 K RFROM,RTHRU,RDFROM,RDTHRU
 ;
 I $G(MSRANGE)'="",$G(PPIEN)'="" D RANGE^BQIDCAH1(MSRANGE,PPIEN,"MSRANGE") S RDFROM=$G(RFROM,""),RDTHRU=$G(RTHRU,"")
 S MSFROM=$S($G(RDFROM)'="":RDFROM,1:$G(MSFROM))
 S MSTHRU=$S($G(RDTHRU)'="":RDTHRU,1:$G(MSTHRU))
 K RFROM,RTHRU,RDFROM,RDTHRU
 ;
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 F KK=0:1:10 K ^TMP("BQITO"_KK,UID)
 S VDATA=$NA(^TMP("BQIAVIS",UID)),VNDATA=$NA(^TMP("BQINOVIS",UID))
 S VODATA=$NA(^TMP("BQIOTHVIS",UID)),CRIT=$NA(^TMP("BQICRIT",UID))
 K @VDATA,@VNDATA,@VODATA
 ;
 S JJ=0
 S TGLOB=$NA(^TMP("BQITO"_JJ,UID))
 ;
 ;If DEMO="O" Only include DEMO patients set up patients in file
 I $G(DEMO)="O" D  D UPD
 . NEW DIEN,DN
 . S DIEN=$O(^DIBT("B","RPMS DEMO PATIENT NAMES","")) I DIEN'="" D
 .. S DN="" F  S DN=$O(^DIBT(DIEN,1,DN)) Q:DN=""  S @TGLOB@(DN)=""
 . S DIEN="DEMO,PATIENT",DN="" F  S DN=$O(^DPT("B",DIEN,DN)) Q:DN=""  S @TGLOB@(DN)=""
 . F  S DIEN=$O(^DPT("B",DIEN)) Q:DIEN'["DEMO,PATIENT"  S DN="" F  S DN=$O(^DPT("B",DIEN,DN)) Q:DN=""  S @TGLOB@(DN)=""
 ;
 ;Alternate cross-reference test
 ;I $G(FROM)'="",$G(PROV)'="" D PRVS^BQIDCAH2(TGLOB,PROV,FROM,THRU),UPD
 ;
 I $G(EMPL)'="" D EMP^BQIDCAH4(FGLOB,TGLOB,EMPL,.MPARMS),UPD
 ;
 I $G(PLIDEN)'=""!$D(MPARMS("PLIDEN")) D PNL^BQIDCAH4(FGLOB,TGLOB,PLIDEN,.MPARMS),UPD
 ;
 I $G(DXCAT)'=""!$D(MPARMS("DXCAT")) D DIAG^BQIDCAH1(FGLOB,TGLOB,DXCAT,.MPARMS),UPD
 ;
 I $G(COMM)'=""!$D(MPARMS("COMM")) D COMM(FGLOB,TGLOB,COMM,.MPARMS),UPD
 ;
 I $G(COMMTX)'=""!$D(MPARMS("COMMTX")) D
 . N COM,COMLST,IEN,PCOMM
 . I $G(COMMTX)'="" D COMMTX(COMMTX,.COMLST)
 . I $D(MPARMS("COMMTX")) D
 .. S COM=""
 .. F  S COM=$O(MPARMS("COMMTX",COM)) Q:COM=""  D COMMTX(COM,.COMLST)
 . I $G(FGLOB)="" D
 .. S COM=""
 .. F  S COM=$O(COMLST(COM)) Q:COM=""  D COMM(FGLOB,TGLOB,COM,.MPARMS)
 . I $G(FGLOB)'="",$D(COMLST) D
 .. S IEN=0
 .. F  S IEN=$O(@FGLOB@(IEN)) Q:'IEN  D
 ... S PCOMM=$P($G(^AUPNPAT(IEN,11)),U,18)
 ... Q:PCOMM=""
 ... I $D(COMLST(PCOMM)) S @TGLOB@(IEN)=""
 . D UPD
 ;
 I $G(BEN)'=""!$D(MPARMS("BEN")) D BEN^BQIDCAH1(FGLOB,TGLOB,BEN,.MPARMS),UPD
 I $G(SEX)'="" D GEN^BQIDCAH5(FGLOB,TGLOB,SEX),UPD
 I $G(RACE)'=""!$D(MPARMS("RACE")) D RACE^BQIDCAH5(FGLOB,TGLOB,RACE,.MPARMS),UPD
 I $G(ETHN)'=""!$D(MPARMS("ETHN")) D ETHN^BQIDCAH5(FGLOB,TGLOB,ETHN,.MPARMS),UPD
 I $G(PCOMM)'="" D PCOMM^BQIDCAH5(FGLOB,TGLOB,PCOMM),UPD
 I $G(PLANG)'="" D PLANG^BQIDCAH5(FGLOB,TGLOB,PLANG),UPD
 ;
 I $G(DBFROM)'="" D DOB^BQIDCAH5(FGLOB,TGLOB,DBFROM,DBTHRU),UPD
 ;
 ; If age is a single value then that is criteria 1 and criteria 2 is blank
 I $G(AGE)'="" D
 . S CRIT1=AGE,CRIT2=""
 . D AGE(FGLOB,TGLOB,CRIT1,CRIT2),UPD
 ;
 ; If age is a multiple value then criteria 1 is the first and criteria 2 is the second MPARMS("AGE",#)
 I $D(MPARMS("AGE")) D
 . NEW N
 . S N="",N=$O(MPARMS("AGE",N)),CRIT1=N
 . S N=$O(MPARMS("AGE",N)) I N'="" S CRIT2=N
 . S CRIT1=$G(CRIT1,""),CRIT2=$G(CRIT2,"")
 . D AGE(FGLOB,TGLOB,CRIT1,CRIT2),UPD
 ;
 I $G(PROB)'=""!$D(MPARMS("PROB"))!($G(PROBTX)'="") D PROB^BQIDCAH4(FGLOB,TGLOB,PROB,PROBTX,PFROM,PTHRU,.MPARMS),UPD
 I $G(PRNDC)'="" D NDC^BQIDCAH4(FGLOB,TGLOB),UPD
 I $G(PRNRV)'="" S PFROM=$$DATE^BQIUL1("T-365"),PTHRU=DT D NRV^BQIDCAH4(FGLOB,TGLOB,PFROM,PTHRU),UPD
 I $G(PRNAC)'="" D NAC^BQIDCAH4(FGLOB,TGLOB,PFROM,PTHRU),UPD
 ;
 I $G(FROM)'="" D VIS^BQIDCAH2(FGLOB,TGLOB,FROM,THRU,.MAPARMS),UPD
 I $G(FROM)="",$G(RANGE)'="" D VIS^BQIDCAH2(FGLOB,TGLOB,FROM,THRU,.MAPARMS),UPD
 ;
 I $G(LAB)'=""!$D(MPARMS("LAB"))!($G(LABTX)'="") D LAB^BQIDCAH3(FGLOB,TGLOB,LAB,LABTX,LFROM,LTHRU,LNOT,.MPARMS,.MAPARMS),UPD
 ;
 I $G(EDUC)'=""!($D(MPARMS("EDUC"))!($G(EDUTX)'="")!($G(EDUTOP)'="")!($G(EDUPICK)'="")) D EDU^BQIDCAH5(FGLOB,TGLOB,EDUC,EDUTX,EFROM,ETHRU,EDUNOT,.MPARMS),UPD
 ;
 I $G(MED)'=""!$D(MPARMS("MED"))!($G(MEDTX)'="") D MED^BQIDCAH3(FGLOB,TGLOB,MED,MEDTX,MFROM,MTHRU,MNOT,.MPARMS),UPD
 I $G(MDNDC)'="" D MND^BQIDCAH4(FGLOB,TGLOB),UPD
 I $G(MDNRV)'="" S MFROM=$$DATE^BQIUL1("T-365"),MTHRU=DT D MLR^BQIDCAH4(FGLOB,TGLOB,MFROM,MTHRU),UPD
 I $G(MDNAC)'="" D NAM^BQIDCAH4(FGLOB,TGLOB,MFROM,MTHRU),UPD
 ;
 I $G(CPT)'=""!$D(MPARMS("CPT"))!($G(CPTTX)'="") D CPT^BQIDCAH3(FGLOB,TGLOB,CPT,CPTTX,CFROM,CTHRU,CNOT,.MPARMS),UPD
 ;
 I $G(POV)'=""!$D(MPARMS("POV"))!($G(POVTX)'="") D POV^BQIDCAH6(FGLOB,TGLOB,POV,POVTX,PVFROM,PVTHRU,CNOT,.MPARMS),UPD
 I $G(POVS)'=""!$D(MPARMS("POVS"))!($G(POVSB)'="") D POVS^BQIDCAH6(FGLOB,TGLOB,POVS,POVSB,PVFROM,PVTHRU,CNOT,.MPARMS),UPD
 ;
 I $G(MEAS)'=""!($D(MPARMS("MEAS"))) D MEAS^BQIDCAH7(FGLOB,TGLOB,MEAS,MSFROM,MSTHRU,MSNOT,.MPARMS),UPD
 I $G(REMCODE)'=""!($D(MPARMS("REMCODE"))) D REM^BQIDCAH6(FGLOB,TGLOB,REMCODE,RMFROM,RMTHRU,OVD,FUT,.MPARMS),UPD
 ;
 ;I $G(PROV)'="" D PROV^BQIDCAH2(FGLOB,TGLOB,PROV),UPD
 ;
 I $G(ALLERGY)'=""!$D(MPARMS("ALLERGY"))!($G(ALNAS)'="")!($G(ALNKN)'="") D ALGY^BQIDCAH6(FGLOB,TGLOB,ALLERGY,.MPARMS),UPD
 ;
 D STAT(FGLOB,TGLOB,LIV,DEC,INAC),UPD
 ;
 S DATA=$NA(^TMP("BQIAHOC",UID)),CDATA=$NA(^TMP("BQIAHOCC",UID))
 K @DATA,@CDATA
 M @CDATA=@CRIT
 I $D(@TGLOB)>0 D
 . S IEN="" F  S IEN=$O(@TGLOB@(IEN)) Q:IEN=""  D
 .. I $G(DEMO)="E",$$DEMO^APCLUTL(IEN,"E")=1 Q
 .. S @DATA@(IEN)=""
 ;
 I $D(@TGLOB)'>0,$G(FGLOB)'="" D
 . S IEN="" F  S IEN=$O(@FGLOB@(IEN)) Q:IEN=""  D
 .. I $G(DEMO)="E",$$DEMO^APCLUTL(IEN,"E")=1 Q
 .. S @DATA@(IEN)=""
 ;
 F KK=0:1:JJ K ^TMP("BQITO"_KK,UID)
 K @VDATA,@VODATA
 I $D(@CRIT) K @CRIT
 Q
 ;
UPD ;EP
 S JJ=JJ+1,FGLOB=TGLOB,TGLOB=$NA(^TMP("BQITO"_JJ,UID))
 Q
 ;
AGE(FGLOB,TGLOB,CRIT1,CRIT2) ;EP - Age search
 I $G(TGLOB)="" Q
 I $G(CRIT1)="" Q
 ;
 NEW IEN,AGE,DOD
 S IEN=0
 I $G(FGLOB)'="" D
 . F  S IEN=$O(@FGLOB@(IEN)) Q:'IEN  D ACHK^BQIDCAH1(.IEN)
 ;
 I $G(FGLOB)="" D
 . F  S IEN=$O(^AUPNPAT(IEN)) Q:'IEN  D ACHK^BQIDCAH1(.IEN)
 Q
 ;
COMM(FGLOB,TGLOB,COM,MPARMS) ;EP - Community search
 I $G(TGLOB)="" Q
 I $G(COM)]"" D COMM1
 I $D(MPARMS("COMM")) S COM="" F  S COM=$O(MPARMS("COMM",COM)) Q:COM=""  D COMM1
 Q
 ;
COMM1 ;EP
 ; Get Community Name and use x-ref for speed improvement.
 ; If community ien is passed use it to determine if patient community matches ***
 NEW COMM,COMMNM ;***
 S (COMM,COMMNM)=COM ;***
 I COMM?1.N S COMMNM=$$GET1^DIQ(9999999.05,COM,.01,"E") ;***
 ;
 NEW IEN
 S IEN=0
 I $G(FGLOB)'="" D
 . F  S IEN=$O(@FGLOB@(IEN)) Q:'IEN  D
 .. I COMM?.N,$P($G(^AUPNPAT(IEN,11)),U,17)'=COMM Q  ;***
 .. I COMM'?.N,$P($G(^AUPNPAT(IEN,11)),U,18)'=COMMNM Q  ;***
 .. S @TGLOB@(IEN)=""
 ;
 I $G(FGLOB)="" D
 . F  S IEN=$O(^AUPNPAT("AC",COMMNM,IEN)) Q:IEN=""  D
 .. ;I $P($G(^AUPNPAT(IEN,41,DUZ(2),0)),U,3)'="" Q
 .. I COMM?.N,$P($G(^AUPNPAT(IEN,11)),U,17)'=COMM Q  ;***
 .. S @TGLOB@(IEN)=""
 Q
 ;
COMMTX(TAX,COML) ;EP
 ; Get a list of communities for the specified community taxonomy
 I $G(TAX)="" Q
 N TAXNM,COMM,IEN
 I TAX'?.N S TAXNM=TAX,TAX=$O(^ATXAX("B",TAXNM,"")) I TAX=""!($O(^ATXAX("B",TAXNM,TAX))'="") Q
 ; Currently CRS only uses community names and matches these to the patient's
 ; community without regard to state, etc.
 S COMM=""
 F  S COMM=$O(^ATXAX(TAX,21,"B",COMM)) Q:COMM=""  D
 . I '$D(^AUTTCOM("B",COMM)) Q
 . S COML(COMM)=""
 Q
 ;
DECHK(DDFN) ;EP Is patient eligible based on date of death
 NEW DOD,DFLG,DCD
 S DOD=$P($G(^DPT(DDFN,.35)),U,1)
 I DOD="" Q 0
 ;
 ;Date of Death Checks
 ;
 ;New Method - Date Range
 I $G(DECFDT)="",$G(DECTDT)="",DOD'="" S DFLG=1 Q DFLG
 I $G(DECFDT)'=""!($G(DECTDT)'="") S DFLG=1 D  Q DFLG
 . I $G(DECFDT)'="",DOD<DECFDT S DFLG=0 Q
 . I $G(DECTDT)'="",DOD>DECTDT S DFLG=0
 ;
 ;Old Method - Single Deceased as of Date
 ;I DECDT="" Q 1
 ;I $G(DECDT)'="",DOD'>DECDT Q 1
 ;
 ; Multiple causes of death
 I $D(MPARMS("DECCOD")) S DFLG=0 D  Q DFLG
 . S DCD="" F  S DCD=$O(MPARMS("DECCOD",DCD)) Q:DCD=""  I $P($G(^AUPNPAT(DDFN,11)),U,14)=DCD S DFLG=1
 ; single cause of death
 I $G(DECCOD)'="",$P($G(^AUPNPAT(DDFN,11)),U,14)=DECCOD Q 1
 ;
 Q 0
 ;
STAT(FGLOB,TGLOB,LIV,DEC,INAC) ;EP Check patients status
 I $G(TGLOB)="" Q
 NEW IEN
 S IEN=0
 I $G(FGLOB)'="" D  Q
 . F  S IEN=$O(@FGLOB@(IEN)) Q:'IEN  D STCK
 ;
 I $G(FGLOB)="" D
 . F  S IEN=$O(^AUPNPAT(IEN)) Q:'IEN  D STCK
 Q
 ;
STCK ;EP - Check
 ; If all are checked for yes, all patients are included
 I LIV="Y",DEC="Y",INAC="Y" S @TGLOB@(IEN)="" Q
 ; If none are checked, no patients are included
 I LIV="N",DEC="N",INAC="N" Q
 ; if living and deceased are included but not inactives
 I LIV="Y",DEC="Y",INAC="N" D
 . ; Active HRN, include
 . I $$HRN^BQIUL1(IEN) S @TGLOB@(IEN)="" Q
 ; Include living but not deceased
 I LIV="Y",DEC="N",INAC="Y" D
 . ; If they are not active and not deceased, include
 . I '$$HRN^BQIUL1(IEN),'$$DECHK(IEN) S @TGLOB@(IEN)="" Q
 ; If living, not deceased and not inactive, include
 I LIV="Y",DEC="N",INAC="N" D
 . I $$HRN^BQIUL1(IEN),'$$DECHK(IEN) S @TGLOB@(IEN)="" Q
 I LIV="N",DEC="Y",INAC="Y" D
 . ; Decease but active
 . I $$DECHK(IEN),$$HRN^BQIUL1(IEN) S @TGLOB@(IEN)="" Q
 I LIV="N",DEC="N",INAC="Y" D
 . ; inactive
 . I '$$HRN^BQIUL1(IEN) S @TGLOB@(IEN)="" Q
 I LIV="N",DEC="Y",INAC="N" D
 . ; Deceased but not inactive
 . I $$DECHK(IEN),$$HRN^BQIUL1(IEN) S @TGLOB@(IEN)="" Q
 Q