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

BGPMUA12.m

Go to the documentation of this file.
BGPMUA12 ; IHS/MSC/MGH - MI measure NQF0002  ;20-Jul-2011 14:39;DU
 ;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
 ;Code to collect meaningful use reports
ENTRY1 ;EP Entry point for NQA0002 for pharyngitis
 N START,END,BGPNUM,BGPDEN,BGPNUM,STRING,BGPHYPER,BGPHYPL
 N IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN,EXCEPT,RESULT
 N CNT,THROAT,NUM,EXC,OUTENC,VENC,DIABDX,ERENC
 S (BGPDEN,BGPNUM,RESULT)=0
 S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
 S START=START_".2359"
 S (STRING,STRING2)="",DIABDX=0
 S (DIAB,EXC,NUM)=0
 ;Pts must be >=2 and <19
 ;No need to check further if no age match
 Q:BGPAGEE<2!(BGPAGEE>18)
 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  D
 ..;Check provider, Only visits for chosen provider
 ..Q:'$$PRV^BGPMUUT1(IEN,BGPPROV)
 ..S OUTENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER OUTPT")
 ..I +OUTENC D VSTSTORE Q
 ..S ERENC=$$VSTCPT^BGPMUUT1(DFN,IEN,"BGPMU ENCOUNTER ED CPT")
 ..I +ERENC D VSTSTORE Q
 ..S VENC=$$VSTPOV^BGPMUUT3(DFN,IEN,"BGPMU ENC OUTPATIENT ICD")
 ..I +VENC D VSTSTORE Q
 ;Next check to see if the patient is in the denominator
 ;Need a DX of phargngitis on one of the visits AND a prescription for antibiotics
 I $D(VIEN)>0 D
 .S THROAT=$$PHARYNG(DFN,CNT,.VIEN)
 .I +THROAT D
 ..;If the patient has pharyngitis and a DX for antibiotics, check to see if they are in the numerator
 ..S NUM=$$NUM1(DFN,THROAT)
 ..D TOTAL1(DFN,THROAT,NUM)
 Q
VSTSTORE ;Store compliant visit in array
 S CNT=CNT+1
 S VDATE=$P($G(^AUPNVSIT(IEN,0)),U,1)
 S VIEN(CNT)=IEN_U_VDATE
 Q
TOTAL1(DFN,THROAT,NUM) ;See where this patient ends up
 N PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DXTIME,DEN
 S TOTALS=$G(^TMP("BGPMU0002",$J,BGPMUTF,"TOT"))
 S DENCT=+$G(^TMP("BGPMU0002",$J,BGPMUTF,"DEN"))
 S NUMCT=+$G(^TMP("BGPMU0002",$J,BGPMUTF,"NUM"))
 S NOTNUM=+$G(^TMP("BGPMU0002",$J,BGPMUTF,"NOT"))
 S PTCNT=TOTALS
 S PTCNT=PTCNT+1
 S (DEN,DXTIME)=""
 S DENCT=DENCT+1 S ^TMP("BGPMU0002",$J,BGPMUTF,"DEN")=DENCT
 I $P(THROAT,U,3)'="" S DXTIME=$$DATE^BGPMUUTL($P(DIAB,U,3))
 ;S DEN=$P(THROAT,U,2)_" "_DXTIME
 I $D(STRING(1)) S DEN="EN:"_STRING(1)
 I $D(STRING(2)) S DEN=DEN_";PHA: "_STRING(2)
 I $D(STRING(3)) S DEN=DEN_";MED:"_STRING(3)
 I +NUM D
 .S NUMCT=NUMCT+1 S ^TMP("BGPMU0002",$J,BGPMUTF,"NUM")=NUMCT
 .I BGPMUTF="C" S ^TMP("BGPMU0002",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
 E  D
 .S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0002",$J,BGPMUTF,"NOT")=NOTNUM
 .I BGPMUTF="C" S ^TMP("BGPMU0002",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
 S ^TMP("BGPMU0002",$J,BGPMUTF,"TOT")=PTCNT
 ;Setup iCare array for patient
 S BGPICARE("MU.EP.0002.1",BGPMUTF)=1_U_+NUM_U_U_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
 Q
NUM1(DFN,DATA) ;Look for wide range of items to satisfy this measure
 N FOUND,DT1,DT2,IEN,RESULT,TAX,VST,MDTE,PHARCPT
 N LABIEN,MICRO,VAL,VAL2,DATA2,RESULT2,PHARLNC,PHARMI
 S FOUND=0
 S VST=$P(DATA,U,2),MDTE=$P(DATA,U,3)
 ;Set date 3 days before medication and 3 days after
 N X1,X2,X S X1=MDTE,X2=-3 D C^%DTC S DT1=X
 N X1,X2,X S X1=MDTE_".2359",X2=+3 D C^%DTC S DT2=X
 ;Check for lab results between these 2 dates
 ;First, check V Lab
 S PHARLNC=$$COLD^BGPMUUT2(DFN,DT1,DT2,"BGPMU LAB LOINC STREP TEST")
 I +PHARLNC S FOUND=1_U_"LAB "_$$DATE^BGPMUUTL($P(PHARLNC,U,3)) Q FOUND
 D LABCPT^BGPMUUT5(.DATA,DFN,"BGPMU LAB CPT STREP TEST",BGPBDATE,BGPEDATE)
 S VAL="" S VAL=$O(DATA(VAL))
 I +VAL S FOUND=1_U_"LAB "_$$DATE^BGPMUUTL(9999999-VAL) Q FOUND
 ;Second, check for a micro test in V MICRO
 S MICROLNC=$$MICRO^BGPMUUT5(DFN,DT1,DT2,"BGPMU LAB LOINC STREP TEST")
 I +MICROLNC S FOUND=1_U_"LAB "_$$DATE^BGPMUUTL($P(MICROLNC,U,1)) Q FOUND
  ;Finally, check V CPT
 S PHARCPT=$$CPT^BGPMUUT1(DFN,DT1,DT2,"BGPMU LAB CPT STREP TEST")
 I +PHARCPT S FOUND=1_U_"CPT "_$$DATE^BGPMUUTL($P(PHARCPT,U,3))
 Q FOUND
PHARYNG(DFN,CNT,VIEN) ;Check patient for Pharyngitis
 N DX,MEDS,FOUND,IX,VST,VDATE,TAX
 S FOUND=0,MEDS=0
 S IX=0 F  S IX=$O(VIEN(IX)) Q:IX=""!(IX>CNT)!(+FOUND)  D
 .S VST=$P(VIEN(IX),U,1)
 .S VDATE=$P(VIEN(IX),U,2)
 .S TAX="BGPMU PHARYNGITIS DX"
 .S DX=$$VSTPOV^BGPMUUT3(DFN,VST,TAX)
 .;If this visit has a DX of pharyngitis, check for prescription within 3 days
 .I +DX S MEDS=$$MED(DFN,VST,VDATE)
 .I +MEDS D
 ..S STRING(1)=$$DATE^BGPMUUTL(VDATE)
 ..S STRING(2)=$$DATE^BGPMUUTL($P(DX,U,3))
 ..S STRING(3)=$$DATE^BGPMUUTL($P(MEDS,U,3))
 ..S FOUND=1_U_VST_U_$P(MEDS,U,3)
 Q FOUND
MED(DFN,VISIT,VDTE) ;If we have found a DX of pharyngitis, we need to find the prescription
 N RX,TAX,DT1,DT2,DRUG,OLDDRUG,VALID
 S RX=0,VALID=1
 S VDTE=$P(VDTE,".",1)
 S VDTE2=VDTE_".2359"
 ;Check for RX on up to 3 days later
 N X1,X2,X S X1=VDTE2,X2=+3 D C^%DTC S DT1=X
 S TAX="BGPMU PHARYNGITIS MEDS NDCS"
 S DRUG=$$FIND^BGPMUUT8(DFN,TAX,VDTE,BGPPROV,DT1,VALID)
 ;Prescription found, now go back and make sure pt hasn't been on antibiotics in the last 30 days
 I +DRUG D
 .N X1,X2,X S X1=VDTE,X2=-30 D C^%DTC S DT2=X
 .S OLDDRUG=$$FIND^BGPMUUT8(DFN,TAX,DT2,"",VDTE,VALID)
 .I +OLDDRUG=0 S RX=DRUG
 Q RX