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

BGPMUD08.m

Go to the documentation of this file.
BGPMUD08 ; IHS/MSC/SAT - MI measure NQF0033 ;25-AUG-2011 14:56
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;
 ; BGPMUD01 = tobacco use assessment               0028a
 ; BGPMUD02 = tobacco use cessation                0028b
 ; BGPMUD03 = Heart Failure w/ACE Inhibitor or ARB 0081
 ; BGPMUD04 = Prenatal HIV Screening               0012
 ; BGPMUD05 = Prenatal Anti-D Immune Globulin      0014
 ; BGPMUD06 = Control High Blood Pressure          0018
 ; BGPMUD07 = SMOKING CESSATION MEDICAL ASSIST     0027
 ; BGPMUD08 = Chlamydia Measure                    0033
 ; BGPMUD09 = Antidepressant Medication Management 0105
 ; BGPMUD10 = Oncology Colon Cancer Stage III      0385
 ;
 ;Code to collect meaningful use report for Chlamydia Measure 0033
ENTRY ;EP
 N START,END,BGPNUM,STRING,STRING2
 N IEN,INV,RFOUND,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN
 N CNT,DIAB,NUM,DIAB,DIABDX,OUTENC,OPHENC,NONENC,VENC,INENC,ERENC
 N BGPALL,BGPAR,BGPEXC,BGPH
 ; BGPDEN1 = ages 15-24
 ; BGPDEN2 = ages 15-19
 ; BGPDEN3 = ages 20-24
 S (BGPDEN1,BGPDEN2,BGPDEN3,BGPEXC,BGPNUM,BGPNOT)=""
 S BGPALL=""
 S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
 S START=START_".2359"
 ;only check female
 S BGPSEX=$$SEX^AUPNPAT(DFN)
 Q:BGPSEX'="F"
 ;Pts must be >=15 and <=24
 S BGPAGEB=$$AGE^AUPNPAT(DFN,BGPBDATE)
 S BGPAGEE=$$AGE^AUPNPAT(DFN,BGPEDATE)
 ;No need to check further if no age match
 Q:BGPAGEE<15!(BGPAGEB>24)  ;determine if the patient was between 15 & 24 yrs during the reporting period
 S X=0
 ;look for 1 outpatient encounter with the EP back to 365 days prior to the end of the reporting period
 S START=9999999-$$FMADD^XLFDT(BGPEDATE,-365),END=9999999-BGPEDATE
 S FIRST=END-0.1 F  S FIRST=$O(^AUPNVSIT("AA",DFN,FIRST)) Q:FIRST=""!($P(FIRST,".",1)>START)  D  Q:+X
 .S VIEN=0 F  S VIEN=$O(^AUPNVSIT("AA",DFN,FIRST,VIEN)) Q:'+VIEN  D  Q:+X
 ..S BGPDT=$P($P($G(^AUPNVSIT(VIEN,0)),U,1),".",1)
 ..;Check provider, determine if there are visits with E&M codes
 ..I $$PRV^BGPMUUT1(VIEN,BGPPROV) D
 ...S X=$$VSTCPT^BGPMUUT1(DFN,VIEN,"BGPMU ENCOUNTER OUTPT")
 ...I '+X S X=$$VSTPOV^BGPMUUT3(DFN,VIEN,"BGPMU ENC OUTPATIENT ICD")
 ;
 Q:'+X  ;quit if no encounter found
 ;check if sexually active
 S X=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU SEXUALLY ACTIVE FEM CPT")
 I +X S X=$P(X,U,3) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"PROC")
 S X=$$LASTPRC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU SEXUALLY ACTIVE FEM ICD0")
 I +X S X=$P(X,U,3) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"PROC")
 ;check for pregnancy
 K LABDATA
 D LAB^BGPMUD04(.LABDATA,DFN,"BGPMU LAB LOINC PREGNANCY","BGPMU LAB CPT PREGNANCY",BGPBDATE,BGPEDATE)
 I +LABDATA S X=$S($P(LABDATA,U,5)'="":$P($P(LABDATA,U,5),".",1),$P(LABDATA,U,2)'="":$P($P(LABDATA,U,2),".",1),1:BGPDT) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"LABP")
 ;check for pregnancy encounter
 S X=$$LASTDX^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU PREGNANCY ENC ICD")
 I +X S X=$P(X,U,3) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"PREG")
 ;check lab indicative of sexually active (anytime prior to the report period end date)
 K LABDATA
 D LAB^BGPMUD04(.LABDATA,DFN,"BGPMU LAB LOINC SEX ACTIVE FEM","BGPMU LAB CPT SEX ACTIVE FEM",0,BGPEDATE)
 I +LABDATA S X=$S($P(LABDATA,U,5)'="":$P($P(LABDATA,U,5),".",1),$P(LABDATA,U,2)'="":$P($P(LABDATA,U,2),".",1),1:BGPDT) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"LAB")
 ;check VPOV for DX indicative of sexually active (anytime prior to the report period end date)
 S X=$$LASTDX^BGPMUUT2(DFN,0,BGPEDATE,"BGPMU SEXUALLY ACTIVE FEM DX")
 I +X S X=$P(X,U,3) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"DX")
 ;check PRESCRIPTION for contraceptives
 S X=$$FIND^BGPMUUT8(DFN,"BGPMU CONTRACEPTIVES NDCS",BGPBDATE,"",BGPEDATE,"")
 I +X S X=$P(X,U,3) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"MED")
 ;check IUD device use
 S X=$$LASTDX^BGPMUUT2(DFN,0,BGPEDATE,"BGPMU IUD ENC ICD")
 S:'+X X=$$LASTPRC^BGPMUUT2(DFN,BGPBDATE,BGPEDATE,"BGPMU IUD ICD0")
 S:'+X X=$$CPT^BGPMUUT1(DFN,BGPBDATE,BGPEDATE,"BGPMU IUD CPT")
 I '+X D
 .S BGPIEN=$O(^AUPNREP("B",DFN,""))
 .S BGPRF=$$GET1^DIQ(9000017,BGPIEN_",",3)
 .S:BGPRF="IUD" X=1_U_U_$P(^AUPNREP(BGPIEN,0),U,7)
 I +X S X=$P(X,U,3) D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"IUD")
 ;check PATIENT ALLERGIES for allergy to IUD
 S BGPH="" F  S BGPH=$O(^GMR(120.8,"B",DFN,BGPH)) Q:BGPH=""  D  Q:(BGPALL="LEVONORGESTREL")!(BGPALL="COPPER IUD")!(BGPALL="PARAGARD IUD")
 .S BGPALL=$P(^GMR(120.8,BGPH,0),U,2)
 .I (BGPALL="LEVONORGESTREL")!(BGPALL="COPPER IUD")!(BGPALL="PARAGARD IUD") D
 ..S X=$P($P(^GMR(120.8,BGPH,0),U,4),".",1)
 ..D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"ALR")
 ;
 ;check V PATIENT EDUCATION
 S TIEN="" S TIEN=$O(^ATXAX("B","BGPMU CONTRACEPTIVE EDU",0))
 S EIEN="" F  S EIEN=$O(^AUPNVPED("AC",DFN,EIEN)) Q:EIEN=""  D
 .S ETOPIC=$P($G(^AUPNVPED(EIEN,0)),U,1)
 .Q:'ETOPIC
 .Q:'$D(^AUTTEDT(ETOPIC,0))
 .S BGPNMEM=$P($G(^AUTTEDT(ETOPIC,0)),U,2)  ;get mnemonic
 .I BGPNMEM'="" D
 ..I $D(^ATXAX(TIEN,21,"B",BGPNMEM)) D
 ...S EDATE=$P($G(^AUPNVPED(EIEN,12)),U,1)
 ...I EDATE="" S EDATE=BGPDT
 ...S BGPAR(EDATE)=$P(EDATE,".",1)
 I +$D(BGPAR) D
 .S X=$O(BGPAR(0))
 .S X=BGPAR(X)
 .D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"EDU")
 ;
 ;check REPRODUCTIVE FACTORS
 S RFOUND=0
 S EIEN=$O(^AUPNREP("B",DFN,""))
 I EIEN'="" D
 .S BGPREC0=^AUPNREP(EIEN,0)
 .S BGPREC11=$G(^AUPNREP(EIEN,11))
 .S:($P(BGPREC0,U,6)'="")&($P($P(BGPREC0,U,7),".",1)<(BGPEDATE+1)) RFOUND=1
 .I '+RFOUND S:($P(BGPREC11,U,3)&($P($P(BGPREC11,U,4),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,4),".",1)    ;gravida (# of pregnancies)
 .I '+RFOUND S:($P(BGPREC11,U,5)&($P($P(BGPREC11,U,6),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,6),".",1)    ;multiple births
 .I '+RFOUND S:($P(BGPREC11,U,7)&($P($P(BGPREC11,U,8),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,8),".",1)    ;full term births
 .I '+RFOUND S:($P(BGPREC11,U,9)&($P($P(BGPREC11,U,10),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,10),".",1)  ;premature births
 .I '+RFOUND S:($P(BGPREC11,U,11)&($P($P(BGPREC11,U,12),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,12),".",1) ;ectopic pregnancies
 .I '+RFOUND S:($P(BGPREC11,U,13)&($P($P(BGPREC11,U,14),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,14),".",1) ;living children
 .I '+RFOUND S:($P(BGPREC11,U,31)&($P($P(BGPREC11,U,32),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,32),".",1) ;therapeutic abortions
 .I '+RFOUND S:($P(BGPREC11,U,33)&($P($P(BGPREC11,U,34),".",1)<(BGPEDATE+1))) RFOUND=1_U_$P($P(BGPREC11,U,34),".",1) ;spontaneous abortions
 .I +RFOUND D
 ..S X=$P(RFOUND,U,2)
 ..D DENPOP(DFN,BGPAGEE,X,.BGPDEN2,.BGPDEN3,"RF")
 ;
 Q:(BGPDEN2="")&(BGPDEN3="")
 D:BGPDEN2'="" DENPOP(DFN,BGPAGEE,BGPDT,.BGPDEN2,"","EN")
 D:BGPDEN3'="" DENPOP(DFN,BGPAGEE,BGPDT,"",.BGPDEN3,"EN")
 S DENFLG=$S(BGPDEN2'="":2,BGPDEN3'="":3,1:0)
 S BGPDEN1=$S(DENFLG=2:BGPDEN2,DENFLG=3:BGPDEN3,1:"")
 ;
 ;check if patient is in the numerator
 ;  check lab for chlamydia screening
 ;check lab for chlamydia screening test
 K LABDATA
 D LAB^BGPMUD04(.LABDATA,DFN,"BGPMU LAB LOINC CHLAMYDIA","BGPMU LAB CPT CHLAMYDIA",0,BGPEDATE)
 I +LABDATA S BGPNUM="M:CHL "_$$DATE^BGPMUUTL($P($P(LABDATA,U,2),".",1))
 ;I BGPNUM1'="" X "S BGPNUM"_DENFLG_"=BGPNUM1"
 I BGPNUM="" S BGPNOT="NM:"
 ;
 ;check for exclusions
 S X=0
 I BGPNUM="" S X=$$EXCLUDE(DFN)
 I +X S BGPEXC="Excluded" S (BGPNUM,BGPNOT)=""
 ;
 D TOTAL(DFN)
 Q
 ;
TOTAL(DFN) ;See where this patient ends up
 N PTCNT,EXCCT,DENCT1,DENCT2,DENCT3,NUMCT,NOTNUM,TOTALS
 S TOTALS=$G(^TMP("BGPMU0033",$J,BGPMUTF,"TOT"))
 S DENCT1=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"DEN",1))
 S DENCT2=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"DEN",2))
 S DENCT3=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"DEN",3))
 S NUMCT1=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"NUM",1))
 S NUMCT2=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"NUM",2))
 S NUMCT3=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"NUM",3))
 S EXCCT1=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"EXC",1))
 S EXCCT2=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"EXC",2))
 S EXCCT3=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"EXC",3))
 S NOTNUM1=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"NOT",1))
 S NOTNUM2=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"NOT",2))
 S NOTNUM3=+$G(^TMP("BGPMU0033",$J,BGPMUTF,"NOT",3))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S DENCT1=DENCT1+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"DEN",1)=DENCT1
 I BGPDEN2'="" S DENCT2=DENCT2+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"DEN",2)=DENCT2
 I BGPDEN3'="" S DENCT3=DENCT3+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"DEN",3)=DENCT3
 ;
 I BGPNOT'="" D
 .S NOTNUM1=NOTNUM1+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"NOT",1)=NOTNUM1
 .I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"NOT",1,PTCNT)=DFN_U_BGPDEN1_U_BGPNOT
 .I DENFLG=2 D
 ..S NOTNUM2=NOTNUM2+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"NOT",2)=NOTNUM2
 ..I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"NOT",2,PTCNT)=DFN_U_BGPDEN2_U_BGPNOT
 .I DENFLG=3 D
 ..S NOTNUM3=NOTNUM3+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"NOT",3)=NOTNUM3
 ..I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"NOT",3,PTCNT)=DFN_U_BGPDEN3_U_BGPNOT
 ;
 I BGPNUM'="" D
 .S NUMCT1=NUMCT1+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"NUM",1)=NUMCT1
 .I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"NUM",1,PTCNT)=DFN_U_BGPDEN1_U_BGPNUM
 .I DENFLG=2 D
 ..S NUMCT2=NUMCT2+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"NUM",2)=NUMCT2
 ..I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"NUM",2,PTCNT)=DFN_U_BGPDEN2_U_BGPNUM
 .I DENFLG=3 D
 ..S NUMCT3=NUMCT3+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"NUM",3)=NUMCT3
 ..I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"NUM",3,PTCNT)=DFN_U_BGPDEN3_U_BGPNUM
 ;
 I BGPEXC'="" D
 .S EXCCT1=EXCCT1+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"EXC",1)=EXCCT1
 .I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"EXC",1,PTCNT)=DFN_U_BGPDEN1_U_BGPEXC
 .I DENFLG=2 D
 ..S EXCCT2=EXCCT2+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"EXC",2)=EXCCT2
 ..I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"EXC",2,PTCNT)=DFN_U_BGPDEN2_U_BGPEXC
 .I DENFLG=3 D
 ..S EXCCT3=EXCCT3+1 S ^TMP("BGPMU0033",$J,BGPMUTF,"EXC",3)=EXCCT3
 ..I BGPMUTF="C" S ^TMP("BGPMU0033",$J,"PAT",BGPMUTF,"EXC",3,PTCNT)=DFN_U_BGPDEN3_U_BGPEXC
 S ^TMP("BGPMU0033",$J,BGPMUTF,"TOT")=PTCNT
 ;Setup iCare array for patient
 ; BGPICARE(INDICATOR_ID,Timeframe)=Denom Flag
 ;                                    ^ Num Flag     ^ Excl Flag    ^ Denom disp ; Num disp ^ Excl disp
 S BGPICARE("MU.EP.0033.1",BGPMUTF)=1_U_(BGPNUM'="")_U_(BGPEXC'="")_U_BGPDEN1_";"_$S(BGPNUM'="":BGPNUM,1:"")_U_$S(BGPEXC="":BGPEXC,1:"")
 Q
 ;
DENPOP(DFN,BGPAGEE,X,BGPDEN2,BGPDEN3,TXT) ;create population text for pt
 S:(BGPAGEE>14)&(BGPAGEE<20) BGPDEN2=$S(BGPDEN2'="":BGPDEN2_";",1:"")_TXT_":"_$$DATE^BGPMUUTL(X)
 S:(BGPAGEE>19)&(BGPAGEE<25) BGPDEN3=$S(BGPDEN3'="":BGPDEN3_";",1:"")_TXT_":"_$$DATE^BGPMUUTL(X)
 Q
 ;
EXCLUDE(DFN) ;check exclusions
 ;check lab for chlamydia screening test
 K EXAM,LABDATA,LABDT,RAMIS,TIEN
 S (EXAM,LABDATA,LABDT,LABX,RAMIS)=0
 D LAB^BGPMUD04(.LABDATA,DFN,"BGPMU LAB LOINC PREGNANCY","BGPMU LAB CPT PREGNANCY",BGPBDATE,BGPEDATE)
 I +LABDATA D
 .S LABDT=$S($P(LABDATA,U,5)'="":$P($P(LABDATA,U,5),".",1),$P(LABDATA,U,2)'="":$P($P(LABDATA,U,2),".",1),1:0)
 .Q:LABDT=0
 .S LABX=$$FIND^BGPMUUT8(DFN,"BGPMU RETINOID NDCS",LABDT,"",$$FMADD^XLFDT(LABDT,7),"")
 .I '+LABX D
 ..S TIEN="" S TIEN=$O(^ATXAX("B","BGPMU X-RAY STUDY CPT",0))
 ..S RIEN=$O(^RADPT("B",DFN,""))
 ..Q:RIEN=""
 ..S RE="" F  S RE=$O(^RADPT(RIEN,"DT",RE)) Q:RE=""  D
 ...S EXAM=0 F  S EXAM=$O(^RADPT(RIEN,"DT",RE,"P",EXAM)) Q:EXAM=""  D
 ....S RAMIS=$P($G(^RADPT(RIEN,"DT",RE,"P",EXAM,0)),U,2)
 ....Q:RAMIS=""
 ....S CPT=$P($G(^RAMIS(71,RAMIS,0)),U,9)
 ....Q:CPT=""
 ....I $D(^ATXAX(TIEN,21,"B",CPT)) S LABX=1
 .I '+LABX D
 ..S LABX=$$RAD^BGPMUUT1(DFN,0,BGPEDATE,"BGPMU X-RAY STUDY CPT",1)
 Q +LABX
 ;
TEST ; debug target
 S U="^"
 S DT=$$DT^XLFDT()
 S DFN=469             ;  DFN      = patient code from VA PATIENT file
 S BGPBDATE=3100101   ;  BGPBDATE = begin date of report
 S BGPEDATE=3101231   ;  BGPEDATE = end date of report
 S BGPPROV=2          ;  BGPPROV   = provider code from NEW PERSON file
 S BGPMUTF="C"        ;  BGPMUTF  = timeframe variable - "C"=current year; "P"=previous year; "B"=baseline year
 D ENTRY
 Q