BGPMUA13 ; IHS/MSC/MGH - MI measure NQF0387 ;01-Sep-2011 13:06;DU
;;11.1;IHS CLINICAL REPORTING SYSTEM;**1**;JUN 27, 2011;Build 106
;Code to collect meaningful use reports
ENTRY1 ;EP Entry point for breast cancer on Tamoxifen Aromatase
N START,END,STRING
N IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN
N CNT,BC,NUM,EXC,OUTENC
S START=9999999-BGPBDATE,END=9999999-BGPEDATE,VALUE=0
S START=START_".2359"
S (STRING,STRING2)=""
S (EXC,NUM)=0
;Pts must be >18 and <75
;No need to check further if no age match
Q:BGPAGEE<18
Q:BGPSEX="M"
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 ENC OFFICE VISIT")
..I +OUTENC D VSTSTORE Q
Q:CNT<2
;Next check to see if the patient is in the denominator
;Denominator is that the pt had a diagnosis of breast cancer
S BC=$$BREAST(DFN,BGPBDATE,BGPEDATE,CNT,.VIEN)
I +BC D
.;If the patient is in denominator, check to see if they are in the numerator
.S NUM=$$NUM1(DFN,BGPBDATE,BGPEDATE)
.;If not in the numerator,see if they are an exception
.I +NUM=0 S EXC=$$EXCEPT(DFN,BGPBDATE,BGPEDATE,.VIEN)
.D TOTAL1(DFN,BC,NUM,EXC)
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
S STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
Q
TOTAL1(DFN,BC,NUM,EXC) ;See where this patient ends up
N PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DXTIME,DEN
S TOTALS=+$G(^TMP("BGPMU0387",$J,BGPMUTF,"TOT"))
S DENCT=+$G(^TMP("BGPMU0387",$J,BGPMUTF,"DEN"))
S NUMCT=+$G(^TMP("BGPMU0387",$J,BGPMUTF,"NUM"))
S EXCCT=+$G(^TMP("BGPMU0387",$J,BGPMUTF,"EXC"))
S NOTNUM=+$G(^TMP("BGPMU0387",$J,BGPMUTF,"NOT"))
S PTCNT=TOTALS
S PTCNT=PTCNT+1
S DEN=""
S DENCT=DENCT+1 S ^TMP("BGPMU0387",$J,BGPMUTF,"DEN")=DENCT
S DEN=$P(BC,U,2)_";"_$P(BC,U,3)
I $D(STRING(1)) S DEN=DEN_";EN:"_STRING(1)
I $D(STRING(2)) S DEN=DEN_";EN:"_STRING(2)
I +EXC D
.S EXCCT=EXCCT+1 S ^TMP("BGPMU0387",$J,BGPMUTF,"EXC")=EXCCT
.I BGPMUTF="C" S ^TMP("BGPMU0387",$J,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"Excluded"
I +NUM D
.S NUMCT=NUMCT+1 S ^TMP("BGPMU0387",$J,BGPMUTF,"NUM")=NUMCT
.I BGPMUTF="C" S ^TMP("BGPMU0387",$J,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
I +NUM=0&(+EXC=0) D
.S NOTNUM=NOTNUM+1 S ^TMP("BGPMU0387",$J,BGPMUTF,"NOT")=NOTNUM
.I BGPMUTF="C" S ^TMP("BGPMU0387",$J,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$P(NUM,U,2)_";"_$P(NUM,U,3)
S ^TMP("BGPMU0387",$J,BGPMUTF,"TOT")=PTCNT
;Setup iCare array for patient
S BGPICARE("MU.EP.0387.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$P(NUM,U,2)_";"_$P(NUM,U,3)
Q
BREAST(DFN,BGPBDATE,BGPEDATE,CNT,VIEN) ;Check patient for Breast Cancer
N CANCER,LAST,DXA,DXB,HXA,HXB,STAGE,SAVE
S LAST=0,CANCER=0,STAGE=0,SAVE=0
S LAST=$P($P($G(VIEN(1)),U,2),".")
;First check for DX of breast cancer
S DXA=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER DX")
I +DXA S SAVE=DXA S STAGE=$$STAGE(DFN,LAST)
S DXB=$$PLTAX^BGPMUUT1(DFN,"BGPMU BREAST CANCER DX","C",LAST)
I +DXB S SAVE=DXB S STAGE=$$STAGE(DFN,LAST)
S HXA=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER HISTORY DX")
I +HXA S SAVE=HXA S STAGE=$$STAGE(DFN,LAST)
S HXB=$$PLTAX^BGPMUUT1(DFN,"BGPMU BREAST CANCER HISTORY DX","I",LAST)
I +HXB S SAVE=HXB S STAGE=$$STAGE(DFN,LAST)
I +STAGE D
.S CANCER=1_U_"BCDX:"_$$DATE^BGPMUUTL($P(SAVE,U,3))_U_$P(STAGE,U,2)
Q CANCER
STAGE(DFN,LAST) ;Check for stage of breast cancer
N STAGE1,STAGE2,A,B,C
S (STAGE1,STAGE2)=0
S A=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU BREAST CANCER STAGE CPT")
Q:'A 0
S STAGE1="BCST:"_$$DATE^BGPMUUTL($P(A,U,3))
S B=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER ER ICD")
I +B S STAGE2="BCP:"_$$DATE^BGPMUUTL($P(B,U,3)) G STAGEX
S C=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU BREAST CANCER ER CPT")
I +C S STAGE2="BCP:"_$$DATE^BGPMUUTL($P(C,U,3))
STAGEX Q $S(STAGE2=0:0,1:1_U_STAGE1_";"_STAGE2)
NUM1(DFN,BGPBDATE,BGPEDATE) ;Look for wide range of items to satisfy this measure
N FOUND,PMED
S FOUND=0
S PMED=$$FIND^BGPMUUT8(DFN,"BGPMU TAMOXIFEN AROMATASE NDCS",BGPBDATE,"",BGPEDATE)
I +PMED S FOUND=1_U_"MED:"_$$DATE^BGPMUUTL($P(PMED,U,3))
Q FOUND
EXCEPT(DFN,BGPBDATE,BGPEDATE,VIEN) ;Check Exception criteria
N LAST,RESULT,OOP,RAD,CHEMO,METDX,METPL,PMED,ALLER,REF,TAX
S RESULT=0
S LAST=$P($P($G(VIEN(1)),U,2),".")
S OOP=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU BILATERAL OOPHORECTOMY")
I +OOP S RESULT=OOP Q RESULT
S RAD=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU RADIATION THERAPY CPT")
I +RAD S RESULT=RAD Q RESULT
S CHEMO=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU CHEMOTHERAPY CPTS")
I +CHEMO S RESULT=CHEMO Q RESULT
;Check for metastisis
S METDX=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER METS DX")
I +METDX S RESULT=METDX Q RESULT
S METPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU BREAST CANCER METS DX","C",LAST)
I +METPL S RESULT=METPL Q RESULT
;Check if on another drug
S PMED=$$FIND^BGPMUUT8(DFN,"BGPMU GONODOTROPIN NDCS",BGPBDATE,"",BGPEDATE)
I +PMED S RESULT=1_U_$P(PMED,U,2)_U_$P(PMED,U,3)
;Next check for allergy
S ALLER=0
S ALLER=$$ALLER^BGPMUA10("","TAMOXIFEN")
I +ALLER S RESULT=1_U_$P(ALLER,U,1) Q RESULT
S ALLER=0
S ALLER=$$ALLER^BGPMUA10("","ANASTROZOLE")
I +ALLER S RESULT=1_U_$P(ALLER,U,1) Q RESULT
S ALLER=0
S ALLER=$$ALLER^BGPMUA10("","EXEMESTANE")
I +ALLER S RESULT=1_U_$P(ALLER,U,1) Q RESULT
S ALLER=0
S ALLER=$$ALLER^BGPMUA10("","LETROZOLE")
I +ALLER S RESULT=1_U_$P(ALLER,U,1) Q RESULT
;Check for refusals
S TAX="BGPMU TAMOXIFEN AROMATASE NDCS"
S REF=$$MEDREF^BGPMUUT2(DFN,0,BGPEDATE,TAX)
I +REF S RESULT=1_U_$P(REF,U,1) Q RESULT
Q RESULT
BGPMUA13 ; IHS/MSC/MGH - MI measure NQF0387 ;01-Sep-2011 13:06;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 breast cancer on Tamoxifen Aromatase
+1 NEW START,END,STRING
+2 NEW IEN,INV,VISIT,DATA,VDATE,VALUE,EXCEPT,FIRST,VIEN
+3 NEW CNT,BC,NUM,EXC,OUTENC
+4 SET START=9999999-BGPBDATE
SET END=9999999-BGPEDATE
SET VALUE=0
+5 SET START=START_".2359"
+6 SET (STRING,STRING2)=""
+7 SET (EXC,NUM)=0
+8 ;Pts must be >18 and <75
+9 ;No need to check further if no age match
+10 IF BGPAGEE<18
QUIT
+11 IF BGPSEX="M"
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 ENC OFFICE VISIT")
+18 IF +OUTENC
DO VSTSTORE
QUIT
End DoDot:2
End DoDot:1
+19 IF CNT<2
QUIT
+20 ;Next check to see if the patient is in the denominator
+21 ;Denominator is that the pt had a diagnosis of breast cancer
+22 SET BC=$$BREAST(DFN,BGPBDATE,BGPEDATE,CNT,.VIEN)
+23 IF +BC
Begin DoDot:1
+24 ;If the patient is in denominator, check to see if they are in the numerator
+25 SET NUM=$$NUM1(DFN,BGPBDATE,BGPEDATE)
+26 ;If not in the numerator,see if they are an exception
+27 IF +NUM=0
SET EXC=$$EXCEPT(DFN,BGPBDATE,BGPEDATE,.VIEN)
+28 DO TOTAL1(DFN,BC,NUM,EXC)
End DoDot:1
+29 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 SET STRING(CNT)=$$DATE^BGPMUUTL(VDATE)
+5 QUIT
TOTAL1(DFN,BC,NUM,EXC) ;See where this patient ends up
+1 NEW PTCNT,EXCCT,DENCT,NUMCT,NOTNUM,TOTALS,DXTIME,DEN
+2 SET TOTALS=+$GET(^TMP("BGPMU0387",$JOB,BGPMUTF,"TOT"))
+3 SET DENCT=+$GET(^TMP("BGPMU0387",$JOB,BGPMUTF,"DEN"))
+4 SET NUMCT=+$GET(^TMP("BGPMU0387",$JOB,BGPMUTF,"NUM"))
+5 SET EXCCT=+$GET(^TMP("BGPMU0387",$JOB,BGPMUTF,"EXC"))
+6 SET NOTNUM=+$GET(^TMP("BGPMU0387",$JOB,BGPMUTF,"NOT"))
+7 SET PTCNT=TOTALS
+8 SET PTCNT=PTCNT+1
+9 SET DEN=""
+10 SET DENCT=DENCT+1
SET ^TMP("BGPMU0387",$JOB,BGPMUTF,"DEN")=DENCT
+11 SET DEN=$PIECE(BC,U,2)_";"_$PIECE(BC,U,3)
+12 IF $DATA(STRING(1))
SET DEN=DEN_";EN:"_STRING(1)
+13 IF $DATA(STRING(2))
SET DEN=DEN_";EN:"_STRING(2)
+14 IF +EXC
Begin DoDot:1
+15 SET EXCCT=EXCCT+1
SET ^TMP("BGPMU0387",$JOB,BGPMUTF,"EXC")=EXCCT
+16 IF BGPMUTF="C"
SET ^TMP("BGPMU0387",$JOB,"PAT",BGPMUTF,"EXC",PTCNT)=DFN_U_DEN_U_"Excluded"
End DoDot:1
+17 IF +NUM
Begin DoDot:1
+18 SET NUMCT=NUMCT+1
SET ^TMP("BGPMU0387",$JOB,BGPMUTF,"NUM")=NUMCT
+19 IF BGPMUTF="C"
SET ^TMP("BGPMU0387",$JOB,"PAT",BGPMUTF,"NUM",PTCNT)=DFN_U_DEN_U_"M:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+20 IF +NUM=0&(+EXC=0)
Begin DoDot:1
+21 SET NOTNUM=NOTNUM+1
SET ^TMP("BGPMU0387",$JOB,BGPMUTF,"NOT")=NOTNUM
+22 IF BGPMUTF="C"
SET ^TMP("BGPMU0387",$JOB,"PAT",BGPMUTF,"NOT",PTCNT)=DFN_U_DEN_U_"NM:"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
End DoDot:1
+23 SET ^TMP("BGPMU0387",$JOB,BGPMUTF,"TOT")=PTCNT
+24 ;Setup iCare array for patient
+25 SET BGPICARE("MU.EP.0387.1",BGPMUTF)=1_U_+NUM_U_+EXC_U_DEN_";"_$PIECE(NUM,U,2)_";"_$PIECE(NUM,U,3)
+26 QUIT
BREAST(DFN,BGPBDATE,BGPEDATE,CNT,VIEN) ;Check patient for Breast Cancer
+1 NEW CANCER,LAST,DXA,DXB,HXA,HXB,STAGE,SAVE
+2 SET LAST=0
SET CANCER=0
SET STAGE=0
SET SAVE=0
+3 SET LAST=$PIECE($PIECE($GET(VIEN(1)),U,2),".")
+4 ;First check for DX of breast cancer
+5 SET DXA=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER DX")
+6 IF +DXA
SET SAVE=DXA
SET STAGE=$$STAGE(DFN,LAST)
+7 SET DXB=$$PLTAX^BGPMUUT1(DFN,"BGPMU BREAST CANCER DX","C",LAST)
+8 IF +DXB
SET SAVE=DXB
SET STAGE=$$STAGE(DFN,LAST)
+9 SET HXA=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER HISTORY DX")
+10 IF +HXA
SET SAVE=HXA
SET STAGE=$$STAGE(DFN,LAST)
+11 SET HXB=$$PLTAX^BGPMUUT1(DFN,"BGPMU BREAST CANCER HISTORY DX","I",LAST)
+12 IF +HXB
SET SAVE=HXB
SET STAGE=$$STAGE(DFN,LAST)
+13 IF +STAGE
Begin DoDot:1
+14 SET CANCER=1_U_"BCDX:"_$$DATE^BGPMUUTL($PIECE(SAVE,U,3))_U_$PIECE(STAGE,U,2)
End DoDot:1
+15 QUIT CANCER
STAGE(DFN,LAST) ;Check for stage of breast cancer
+1 NEW STAGE1,STAGE2,A,B,C
+2 SET (STAGE1,STAGE2)=0
+3 SET A=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU BREAST CANCER STAGE CPT")
+4 IF 'A
QUIT 0
+5 SET STAGE1="BCST:"_$$DATE^BGPMUUTL($PIECE(A,U,3))
+6 SET B=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER ER ICD")
+7 IF +B
SET STAGE2="BCP:"_$$DATE^BGPMUUTL($PIECE(B,U,3))
GOTO STAGEX
+8 SET C=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU BREAST CANCER ER CPT")
+9 IF +C
SET STAGE2="BCP:"_$$DATE^BGPMUUTL($PIECE(C,U,3))
STAGEX QUIT $SELECT(STAGE2=0:0,1:1_U_STAGE1_";"_STAGE2)
NUM1(DFN,BGPBDATE,BGPEDATE) ;Look for wide range of items to satisfy this measure
+1 NEW FOUND,PMED
+2 SET FOUND=0
+3 SET PMED=$$FIND^BGPMUUT8(DFN,"BGPMU TAMOXIFEN AROMATASE NDCS",BGPBDATE,"",BGPEDATE)
+4 IF +PMED
SET FOUND=1_U_"MED:"_$$DATE^BGPMUUTL($PIECE(PMED,U,3))
+5 QUIT FOUND
EXCEPT(DFN,BGPBDATE,BGPEDATE,VIEN) ;Check Exception criteria
+1 NEW LAST,RESULT,OOP,RAD,CHEMO,METDX,METPL,PMED,ALLER,REF,TAX
+2 SET RESULT=0
+3 SET LAST=$PIECE($PIECE($GET(VIEN(1)),U,2),".")
+4 SET OOP=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU BILATERAL OOPHORECTOMY")
+5 IF +OOP
SET RESULT=OOP
QUIT RESULT
+6 SET RAD=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU RADIATION THERAPY CPT")
+7 IF +RAD
SET RESULT=RAD
QUIT RESULT
+8 SET CHEMO=$$CPT^BGPMUUT1(DFN,"",LAST,"BGPMU CHEMOTHERAPY CPTS")
+9 IF +CHEMO
SET RESULT=CHEMO
QUIT RESULT
+10 ;Check for metastisis
+11 SET METDX=$$LASTDX^BGPMUUT2(DFN,"",LAST,"BGPMU BREAST CANCER METS DX")
+12 IF +METDX
SET RESULT=METDX
QUIT RESULT
+13 SET METPL=$$PLTAX^BGPMUUT1(DFN,"BGPMU BREAST CANCER METS DX","C",LAST)
+14 IF +METPL
SET RESULT=METPL
QUIT RESULT
+15 ;Check if on another drug
+16 SET PMED=$$FIND^BGPMUUT8(DFN,"BGPMU GONODOTROPIN NDCS",BGPBDATE,"",BGPEDATE)
+17 IF +PMED
SET RESULT=1_U_$PIECE(PMED,U,2)_U_$PIECE(PMED,U,3)
+18 ;Next check for allergy
+19 SET ALLER=0
+20 SET ALLER=$$ALLER^BGPMUA10("","TAMOXIFEN")
+21 IF +ALLER
SET RESULT=1_U_$PIECE(ALLER,U,1)
QUIT RESULT
+22 SET ALLER=0
+23 SET ALLER=$$ALLER^BGPMUA10("","ANASTROZOLE")
+24 IF +ALLER
SET RESULT=1_U_$PIECE(ALLER,U,1)
QUIT RESULT
+25 SET ALLER=0
+26 SET ALLER=$$ALLER^BGPMUA10("","EXEMESTANE")
+27 IF +ALLER
SET RESULT=1_U_$PIECE(ALLER,U,1)
QUIT RESULT
+28 SET ALLER=0
+29 SET ALLER=$$ALLER^BGPMUA10("","LETROZOLE")
+30 IF +ALLER
SET RESULT=1_U_$PIECE(ALLER,U,1)
QUIT RESULT
+31 ;Check for refusals
+32 SET TAX="BGPMU TAMOXIFEN AROMATASE NDCS"
+33 SET REF=$$MEDREF^BGPMUUT2(DFN,0,BGPEDATE,TAX)
+34 IF +REF
SET RESULT=1_U_$PIECE(REF,U,1)
QUIT RESULT
+35 QUIT RESULT