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

BGPMUG05.m

Go to the documentation of this file.
BGPMUG05 ; IHS/MSC/MMT - MI measure NQF0036 ;20-Aug-2011 14:56;DU
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;Code to collect meaningful use report for Asthma Medications
ENTRY ;EP
 N START,END,STRING,STRING2
 N IEN,INV,VISIT,DATA,VDATE,VALUE,FIRST,VIEN
 N CNT,DEN,NUM,EXC,ASTHENC,ASTHMA,ASTDT,ASTDX,ASTPL,LASTVDT
 S (NUM,DEN,EXC)=0
 ;Pts must be between 5 and 50 years
 ;No need to check further if no age match
 Q:BGPAGEE<5!(BGPAGEE>50)
 S DEN=$$DEN(DFN,BGPBDATE,BGPEDATE)
 Q:'+DEN
 ;check to see if they are in the numerator
 S NUM=$$NUM(DFN,BGPBDATE,BGPEDATE)
 ;if not in NUM, check to see if excluded
 I '+NUM S EXC=$$EXCLUDE(DFN,BGPBDATE,BGPEDATE)
 D TOTAL(DFN,DEN,NUM,EXC)
 Q
TOTAL(DFN,DEN,NUM,EXC) ;See where this patient ends up
 D:BGPAGEE<12 TOTSUB(1)  ;ages 5-11
 D:BGPAGEE>11 TOTSUB(2)  ;ages 12-50
 D TOTSUB(3)  ;all ages (5-50)
 Q
TOTSUB(DENPOP) ;ADD Patient to a population's totals
 N TOTAL,PTCNT,DENCT,NUMCT,NOTNUM,EXCCT
 S TOTAL=$G(^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"DEN"))
 S NUMCT=+$G(^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"NUM"))
 S EXCCT=+$G(^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"EXC"))
 S NOTNUM=+$G(^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"NOT"))
 S PTCNT=TOTAL
 S PTCNT=PTCNT+1
 S DENCT=DENCT+1 S ^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"DEN")=DENCT
 I +NUM D
 .S NUMCT=NUMCT+1 S ^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"NUM")=NUMCT
 .I BGPMUTF="C" S ^TMP("BGPMU0036",$J,"PAT",BGPMUTF,DENPOP,"NUM",PTCNT)=DFN_U_$P(DEN,U,2)_U_"M:MED "_$$DATE^BGPMUUTL($P(NUM,U,3))
 I +EXC D
 .S EXCCT=EXCCT+1 S ^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"EXC")=EXCCT
 .I BGPMUTF="C" S ^TMP("BGPMU0036",$J,"PAT",BGPMUTF,DENPOP,"EXC",PTCNT)=DFN_U_$P(DEN,U,2)_U_"Excluded"
 I +NUM=0&(EXC=0) D
 .S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"NOT")=NOTNUM
 .I BGPMUTF="C" S ^TMP("BGPMU0036",$J,"PAT",BGPMUTF,DENPOP,"NOT",PTCNT)=DFN_U_$P(DEN,U,2)_U_"NM:"
 S ^TMP("BGPMU0036",$J,BGPMUTF,DENPOP,"TOT")=PTCNT
 ;Setup iCare array for patient only for the 3rd (all encompassing) population
 S:DENPOP=3 BGPICARE("MU.EP.0036.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_$P(DEN,U,2)_U_$P(NUM,U,2)_";"_$P(NUM,U,3)
 Q
ASTHMA(DFN,EDATE) ;Find if patient had a PROBLEM of Asthma on or before the end date
 N ASTHMA
 S ASTHMA=0
 S ASTPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU ASTHMA DX ICD","C")
 ;check date of problem
 I +ASTPL&($P($P(ASTPL,U,3),".")<=EDATE) S ASTHMA=ASTPL Q ASTHMA
 S BGPBIRTH=$$DOB^AUPNPAT(DFN)
 S ASTDX=$$LASTDX^BGPMUUT2(DFN,BGPBIRTH,EDATE,"BGPMU ASTHMA DX ICD")
 I +ASTDX S ASTHMA=ASTDX Q ASTHMA
 Q ASTHMA
NUM(DFN,BGPBDATE,BGPEDATE) ;Look for PRESCRIPTION
 N FOUND
 S FOUND=0
 S FOUND=$$FIND^BGPMUUT8(DFN,"BGPMU ASTHMA GENERAL NDCS",BGPBDATE,"",BGPEDATE)
 Q:+FOUND FOUND
 S FOUND=$$FIND^BGPMUUT8(DFN,"BGPMU ASTHMA INHALED NDCS",BGPBDATE,"",BGPEDATE)
 Q:+FOUND FOUND
 S FOUND=$$FIND^BGPMUUT8(DFN,"BGPMU ASTHMA LEUK NDCS",BGPBDATE,"",BGPEDATE)
 Q FOUND
DEN(DFN,BDATE,EDATE) ;CHECK IF PT IS IN DENOMINATOR
 ;Check for 1 IP or ED visit with a Dx of Asthma
 S START=9999999-$$FMADD^XLFDT(BDATE,-365),END=9999999-EDATE,VALUE=0
 S START=START_".2359"
 ;First check for Asthma Dx
 S ASTHMA=$$ASTHMA(DFN,BGPEDATE)
 G:'+ASTHMA DENMEDS  ;SKIP TO MED CHECK IF NO ASTHMA DX
 S CNT=0
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)  D
 .S IEN=0 F  S IEN=$O(^AUPNVSIT("AA",DFN,FIRST,IEN)) Q:'+IEN!(CNT>0)  D
 ..;Check provider, Only visits for chosen provider
 ..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
 ..S EDENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER ED CPT")
 ..I +EDENC D VSTSTORE Q
 ..S IPENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ACUTE INPT ENC")
 ..I +IPENC D VSTSTORE Q
 I CNT>0 D
 .S DEN=1_U_$$DENSTR1(ASTHMA,.STRING)
 Q:+DEN DEN
DENMEDS ;
 N MEDTAX,INHTAX,LEUKTAX,MEDS,LEUKS,MCNT,LCNT,MEVT
 ;now check for meds
 S MEDTAX=$O(^ATXAX("B","BGPMU ASTHMA GENERAL NDCS",0))
 S BETATAX=$O(^ATXAX("B","BGPMU ASTHMA BETA NDCS",0))
 S INHTAX=$O(^ATXAX("B","BGPMU ASTHMA INHALED NDCS",0))
 S LEUKTAX=$O(^ATXAX("B","BGPMU ASTHMA LEUK NDCS",0))
 K VIEN,STRING,CNT
 S (CNT,MCNT,LCNT,M,E)=0
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)  D
 .S IEN=0 F  S IEN=$O(^AUPNVSIT("AA",DFN,FIRST,IEN)) Q:'+IEN  D
 ..;Check provider, Only visits for chosen provider
 ..I $$PRV^BGPMUUT1(IEN,BGPPROV) D
 ...S OPENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
 ...I +OPENC D VSTSTORE  ;count it
 ...E  D
 ....S VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
 ....I +VENC D VSTSTORE
 ..;look for meds
 ..S Y=0 F  S Y=$O(^AUPNVMED("AD",IEN,Y)) Q:Y'=+Y  D
 ...S S=0
 ...Q:'$D(^AUPNVMED(Y,0))
 ...Q:$$UP^XLFSTR($P($G(^AUPNVMED(Y,11)),U))["RETURNED TO STOCK"
 ...S Z=$P($G(^AUPNVMED(Y,0)),U) ;get drug ien
 ...Q:$P($G(^AUPNVMED(Y,12)),U,2)'=BGPPROV  ;don't check this med if not ordered by EP
 ...I ($$NDC(Z,INHTAX)!($$NDC(Z,BETATAX))),$P(^AUPNVMED(Y,0),U,8)="" D  Q
 ....S M=M+1 ;it is an inhaled steroid that wasn't d/c'ed so 1 dispensing event
 ....S MEVT=$P($G(^AUPNVMED(Y,12)),U)
 ....S MCNT=MCNT+1,MEDS(MCNT)=Z_U_$S(MEVT'="":MEVT,1:$P($P(^AUPNVSIT(IEN,0),U),"."))
 ...I $$NDC(Z,MEDTAX) D
 ....Q:$$NDC(Z,LEUKTAX)  ;don't count if it is a leukotriene
 ....S J=$P(^AUPNVMED(Y,0),U,8)
 ....I J]"" S S=$$FMDIFF^XLFDT($P($P(^AUPNVSIT(IEN,0),U),"."),J,1)
 ....I J="" S S=$P(^AUPNVMED(Y,0),U,7)
 ....S K=S\30 S:K<1 K=1
 ....S M=M+K
 ....S MEVT=$P($G(^AUPNVMED(Y,12)),U)
 ....S MCNT=MCNT+1,MEDS(MCNT)=Z_U_$S(MEVT'="":MEVT,1:$P($P(^AUPNVSIT(IEN,0),U),"."))
 ...I $$NDC(Z,LEUKTAX) D  Q
 ....S J=$P(^AUPNVMED(Y,0),U,8)
 ....I J]"" S S=$$FMDIFF^XLFDT($P($P(^AUPNVSIT(IEN,0),U),"."),J,1)
 ....I J="" S S=$P(^AUPNVMED(Y,0),U,7)
 ....S K=S\30 S:K<1 K=1
 ....S M=M+K,E=E+K
 ....S MEVT=$P($G(^AUPNVMED(Y,12)),U)
 ....S MCNT=MCNT+1,MEDS(MCNT)=Z_U_$S(MEVT'="":MEVT,1:$P($P(^AUPNVSIT(IEN,0),U),"."))
 ....S LCNT=LCNT+1,LEUKS(LCNT)=Z_U_$S(MEVT'="":MEVT,1:$P($P(^AUPNVSIT(IEN,0),U),"."))
 I +ASTHMA,CNT>3,M>1 Q 1_U_$$DENSTR2(.VIEN,.MEDS)  ;had 4 povs and 2 dispensing events
 I M>3,E<M Q 1_U_$$DENSTR3(.VIEN,.MEDS)  ;had 4 meds, not all were leuko
 I +ASTHMA,M>3,E>3 Q 1_U_$$DENSTR4(.VIEN,.LEUKS)  ;had all leuk and 1 dx
 Q ""
 ;
NDC(A,B) ;
 ;a is drug ien
 ;b is taxonomy ien
 S BGPNDC=$P($G(^PSDRUG(A,2)),U,4)
 Q:'BGPNDC 0
 ;Setup the NDC code for a proper lookup in the taxonomy
 S NDCCODE=$$RJ^XLFSTR($P(BGPNDC,"-"),5,0)_$$RJ^XLFSTR($P(BGPNDC,"-",2),4,0)_$$RJ^XLFSTR($P(BGPNDC,"-",3),2,0)
 I NDCCODE]"",B,$D(^ATXAX(B,21,"B",NDCCODE)) Q 1
 Q 0
VSTSTORE ;Store compliant visit into array
 S CNT=CNT+1
 S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
 S VIEN(CNT)=IEN_U_VDATE
 S STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
 Q
DENSTR1(ASTHMA,STRING) ;generate display string for denom criteria 1 - Dx present with IP/ED visit 
 Q "AST:"_$$DATE^BGPMUUTL($P(ASTHMA,U,3))_";EN:"_STRING(1)
DENSTR2(VIEN,MEDS) ;generate display string for denom criteria 2 - 4 povs and 2 dispensing events
 N DENSTR,VI
 S DENSTR="AST:"_$$DATE^BGPMUUTL($P(ASTHMA,U,3))
 S DENSTR=DENSTR_";MED:"_$$DATE^BGPMUUTL($P($G(MEDS(1)),U,2))_$S($G(MEDS(2))'="":";MED:"_$$DATE^BGPMUUTL($P(MEDS(2),U,2)),1:"")
 F VI=1:1:4 D
 .S:$G(STRING(VI))'="" DENSTR=DENSTR_";EN:"_STRING(VI)
 Q DENSTR
DENSTR3(VIEN,MEDS) ;generate display string for denom criteria 3 - 4 meds, not all were leuko
 N DENSTR,MI
 S DENSTR=""
 F MI=1:1:4 D
 .S:$G(MEDS(MI))'="" DENSTR=DENSTR_$S(MI>1:";",1:"")_"MED:"_$$DATE^BGPMUUTL($P(MEDS(MI),U,2))
 Q DENSTR
DENSTR4(VIEN,LEUKS) ;generate display string for denom criteria 4 - all leuk and 1 dx
 N DENSTR
 S DENSTR="AST:"_$$DATE^BGPMUUTL($P(ASTHMA,U,3))
 F MI=1:1:4 D
 .S:$G(MEDS(MI))'="" DENSTR=DENSTR_";MED:"_$$DATE^BGPMUUTL($P(MEDS(MI),U,2))
 Q DENSTR
EXCLUDE(DFN,BGPBDATE,BGPEDATE) ;Look for exclusions
 N EXDX,EXPL
 S EXDX=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU ASTHMA EXCLUDES DX ICD")
 I +EXDX Q EXDX
 S EXPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU ASTHMA EXCLUDES DX ICD","C",BGPEDATE)
 Q:+EXPL EXPL
 Q 0