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