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

BGP6D9.m

Go to the documentation of this file.
BGP6D9 ; IHS/CMI/LAB - measure J ;
 ;;16.1;IHS CLINICAL REPORTING;;MAR 22, 2016;Build 170
 ;
 ;
I0303 ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN9,BGPN10,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9,BGPHOSP,BGPHTN)=0
 S (BGPVALUE,BGPVALUD)=""
 I BGPAGEB<18 S BGPSTOP=1 Q
 I BGPAGEB>85 S BGPSTOP=1 Q
 I BGPRTYPE=4 I $$ESRD^BGP6D211(DFN,$P(^DPT(DFN,0),U,3),BGPEDATE) S BGPSTOP=1 Q  ;esrd anytime before end date
 I $$V1HTN(DFN,BGP365,BGPEDATE),$$FIRSTHTN(DFN,BGPEDATE),BGPACTCL S BGPHTN=1,BGPD1=1
 I 'BGPD1 S BGPSTOP=1 Q  ;not in denominator
 I BGPAGEB>17,BGPAGEB<46 S BGPD2=1
 I BGPAGEB>45,BGPAGEB<86 S BGPD3=1
 I BGPAGEB<60 S BGPD7=1
 I BGPAGEB>59 S BGPD8=1
 S BGPVALUE=$$MEANBP^BGP6D41(DFN,BGPBDATE,BGPEDATE,1)
 I BGPVALUE["unknown" S BGPVALUE=$$BPCPT^BGP6D22(DFN,BGPBDATE,BGPEDATE) I BGPVALUE]"" S BGPN1=1,BGPVALUE=$P(BGPVALUE,U,2)_U_0 G V
 S BGPN1=$S($P(BGPVALUE,U,2):1,1:0)  ;any value 2-6
 S BGPN2=$S($P(BGPVALUE,U,2)=2:1,1:0)
 S BGPN3=$S($P(BGPVALUE,U,2)=3:1,1:0)
 S BGPN4=$S($P(BGPVALUE,U,2)=4:1,1:0)
 S BGPN5=$S($P(BGPVALUE,U,2)=5:1,1:0)
 S BGPN6=$S($P(BGPVALUE,U,2)=6:1,1:0)
 S BGPN9="" I BGPN1,$P(BGPVALUE,U)'["CPT",$P(BGPVALUE,"/")<140,+$P(BGPVALUE,"/",2)<90 S BGPN9=1
V S X=$$MEANBPD^BGP6D2(DFN,BGPBDATE,BGPEDATE,1,BGPAGEB)
 ;I X="" S X=$$BPCPT^BGP6D22(DFN,BGPBDATE,BGPEDATE,1) I X]"" D  G V1
 ;.S BGPN10=$S($P(X,U)=1:1,1:0),X=$P(X,U,2)_"^"_$P(X,U,1) ;,BGPVALUD=$P(BGPBP,U,2) ;_" "_$S(BGPN5:"CON",1:"UNC")
 I $P(X,U,2)=4 S BGPN10=1
V1 S BGPVALUE=$S(BGPD1:"HTN PT",1:"")_"|||"_$S($P(BGPVALUE,U,2)="":"",1:$P(BGPVALUE,U))
 I BGPRTYPE=3 S BGPVALUE=BGPVALUE_$S(BGPN9:" - CONTROLLED BP",1:"")
 S BGPVALUD="HTN PT|||"_$S($P(X,U,2)="":"",1:$P(X,U)) ;S BGPVALUD=BGPVALUD_$S(BGPN10:"CON",1:"UNC")
 K ^TMP($J,"A")
 Q
IC2 ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
 I '$$MED(DFN,BGP365,BGPEDATE) S BGPSTOP=1 Q  ;no meds for this patient
 I BGPACTUP S BGPD1=1
 I BGPACTCL,BGPACTUP S BGPD2=1
 I '(BGPD1+BGPD2) Q
 S BGPVALUE=$$MEDPED(DFN,BGPBDATE,BGPEDATE)
 I $P(BGPVALUE,U,1) S BGPN1=1
 ;I 'BGPN1 S BGPVALUE=$$MEDPEDRF(DFN,BGPBDATE,BGPEDATE) I $P(BGPVALUE,U,1)]"" S BGPN2=1
 S V=$S(BGPD1:"UP")_$S(BGPD2:",AC",1:"")
 S V=V_"|||"_$$DATE^BGP6UTL($P(BGPVALUE,U,1))_" "_$P(BGPVALUE,U,2)
 S BGPVALUE=V
 K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P,V,S,F,T,BGPG
 K ^TMP($J,"A")
 Q
IMTM ;EP
 S (BGPN1,BGPD1)=""
 Q:BGPAGEB<18
 I '$$MED(DFN,BGP365,BGPEDATE) S BGPSTOP=1 Q  ;no meds for this patient
 I BGPACTCL S BGPD1=1
 I 'BGPD1 Q
 S BGPVALUE=$$MTM(DFN,BGPBDATE,BGPEDATE)
 I $P(BGPVALUE,U,1) S BGPN1=1
 S V="AC"
 S V=V_"|||"_$P(BGPVALUE,U,2)
 S BGPVALUE=V
 K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P,V,S,F,T,BGPG
 K ^TMP($J,"A")
 Q
MTM(P,BDATE,EDATE) ;
 NEW %
 S %=""
 S %=$$CPT^BGP6DU(P,BDATE,EDATE,$O(^ATXAX("B","BGP CPT MTM",0)),5)
 I %]"" Q 1_U_$$DATE^BGP1UTL($P(%,U,1))_" CPT "_$P(%,U,2)
 ;now check clinic visits
 NEW G,B,C,D,V,E
 S G=""
 S B=9999999-BDATE,C=0,E=9999999-EDATE  ;get inverse date and begin at edate-1 and end when greater than begin date
 S D=E-1,D=D_".9999" F  S D=$O(^AUPNVSIT("AA",P,D)) Q:D=""!($P(D,".")>B)!(G]"")  D
 .S V=0 F  S V=$O(^AUPNVSIT("AA",P,D,V)) Q:V'=+V  D
 ..S C=$$CLINIC^APCLV(V,"C")
 ..I C'="D1",C'="D2",C'="D5" Q
 ..S G=1_U_$$DATE^BGP6UTL($$VD^APCLV(V))_" Cl "_C
 I G]"" Q G
 Q ""
ISMT ;
 S (BGPD1,BGPN1)=0
 I 'BGPACTCL Q  ;only active clinical in this measure
 S BGPVALUE=$$LASTHF^BGP6D7(DFN,"CONFIDENCE IN MANAGING HEALTH PROBLEMS",BGPBDATE,BGPEDATE)
 I BGPVALUE="" Q  ;not assessed
 S BGPD1=1
 I $P(BGPVALUE,U,1)="VERY SURE" S BGPN1=1
 S BGPVALUE="AC"_"|||"_$S(BGPN1:$P(BGPVALUE,U,2),1:"")
 Q
 ;
MEDPED(P,BDATE,EDATE) ;
 K BGPG
 S Y="BGPG("
 S X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I '$D(BGPG(1)) Q ""
 S (X,P,D,E)=0,%="",T="" F  S X=$O(BGPG(X)) Q:X'=+X!(E)  D
 .Q:$P($G(^AUPNVPED(+$P(BGPG(X),U,4),0)),U,6)=5
 .S T=$P(^AUPNVPED(+$P(BGPG(X),U,4),0),U)
 .Q:'T
 .Q:'$D(^AUTTEDT(T,0))
 .S T=$P(^AUTTEDT(T,0),U,2)
 .I $P(T,"-",2)="M"!($P(T,"-",1)="M")!(T="DMC-IN")!(T="FP-DPO")!(T="FP-OC")!($P(T,"-",2)="NEB")!($P(T,"-",2)="MDI")!(T="FP-TD") S E=1,$P(%,U,1)=$P(BGPG(X),U),$P(%,U,2)=T Q
 Q %
 ;
MED(P,BDATE,EDATE) ;
 K ^TMP($J,"A")
 S Y="^TMP($J,""A"","
 S X=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I '$D(^TMP($J,"A",1)) Q ""
 S (X,Y,G)=0 F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(G)  D
 .S V=$P(^TMP($J,"A",X),U,5)
 .Q:'$O(^AUPNVMED("AD",V,0))
 .Q:$P(^AUPNVSIT(V,0),U,6)'=DUZ(2)
 .Q:$P(^AUPNVSIT(V,0),U,7)="E"
 .Q:$P(^AUPNVSIT(V,0),U,3)="C"
 .S G=1
 Q G
ESRD(P,EDATE) ;
 K BGPG
 S Y="BGPG("
 S X=P_"^LAST DX [BGP ESRD DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE S E=$$START1^APCLDF(X,Y)
 I $D(BGPG(1)) Q 1
 S E=+$$CODEN^ICPTCOD(90921),X=$$CPTI^BGP6DU(P,$$DOB^AUPNPAT(P),EDATE,E)
 I $P(X,U) Q 1
 S E=+$$CODEN^ICPTCOD(90925),X=$$CPTI^BGP6DU(P,$$DOB^AUPNPAT(P),EDATE,E)
 I $P(X,U) Q 1
 S E=+$$CODEN^ICPTCOD(90921),X=$$TRANI^BGP6DU(P,$$DOB^AUPNPAT(P),EDATE,E)
 I $P(X,U) Q 1
 S E=+$$CODEN^ICPTCOD(90925),X=$$TRANI^BGP6DU(P,$$DOB^AUPNPAT(P),EDATE,E)
 I $P(X,U) Q 1
 Q ""
FIRSTIHD(P,EDATE) ;EP
 I $G(P)="" Q ""
 K BGPG
 S Y="BGPG("
 S X=P_"^FIRST DX [BGP ISCHEMIC HEART DXS" S E=$$START1^APCLDF(X,Y)
 I '$D(BGPG(1)) Q ""
 S X=$$FMDIFF^XLFDT(EDATE,$P(BGPG(1),U))
 Q $S(X>365:1,1:"")
 ;
V2IHD(P,BDATE,EDATE) ;EP
 I '$G(P) Q ""
 I '$D(^AUPNVSIT("AC",P)) Q ""
 K ^TMP($J,"A")
 S A="^TMP($J,""A"",",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
 I '$D(^TMP($J,"A",1)) Q ""
 S T=$O(^ATXAX("B","BGP ISCHEMIC HEART DXS",0))
 I 'T Q ""
 S (X,G)=0 F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(G>2)  S V=$P(^TMP($J,"A",X),U,5) D
 .Q:'$D(^AUPNVSIT(V,0))
 .Q:'$P(^AUPNVSIT(V,0),U,9)
 .Q:$P(^AUPNVSIT(V,0),U,11)
 .Q:"SAHO"'[$P(^AUPNVSIT(V,0),U,7)
 .S (D,Y)=0 F  S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y!(D)  I $D(^AUPNVPOV(Y,0)) S %=$P(^AUPNVPOV(Y,0),U) I $$ICD^BGP6UTL2(%,T,9) S D=1
 .Q:'D
 .S G=G+1
 .Q
 Q $S(G<2:"",1:1)
FIRSTHTN(P,EDATE) ;EP
 S X=$$FIRSTPV(P,EDATE) I X Q 1
 ;now check problem list
 S BDATE=$$FMADD^XLFDT(EDATE,-365)
 S T=$O(^ATXAX("B","BGP HYPERTENSION DXS",0))
 S (X,G)=0 F  S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G)  D
 .Q:$P(^AUPNPROB(X,0),U,8)>BDATE  ;if added to pl after beginning of time period, no go
 .S Y=$P(^AUPNPROB(X,0),U)
 .Q:$P(^AUPNPROB(X,0),U,12)="I"
 .Q:$P(^AUPNPROB(X,0),U,12)="D"
 .Q:'$$ICD^BGP6UTL2(Y,T,9)
 .S G=1
 .Q
 Q G
FIRSTPV(P,EDATE) ;EP
 I $G(P)="" Q ""
 K BGPG
 S Y="BGPG("
 S X=P_"^FIRST DX [BGP HYPERTENSION DXS" S E=$$START1^APCLDF(X,Y)
 I '$D(BGPG(1)) Q ""
 S X=$$FMDIFF^XLFDT(EDATE,$P(BGPG(1),U))
 Q $S(X>365:1,1:"")
 ;
V1HTN(P,BDATE,EDATE) ;EP
 I '$G(P) Q ""
 I '$D(^AUPNVSIT("AC",P)) Q ""
 K ^TMP($J,"A")
 S A="^TMP($J,""A"",",B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
 I '$D(^TMP($J,"A",1)) Q ""
 S T=$O(^ATXAX("B","BGP HYPERTENSION DXS",0))
 I 'T Q ""
 S (X,G)=0 F  S X=$O(^TMP($J,"A",X)) Q:X'=+X!(G)  S V=$P(^TMP($J,"A",X),U,5) D
 .Q:'$D(^AUPNVSIT(V,0))
 .Q:'$P(^AUPNVSIT(V,0),U,9)
 .Q:$P(^AUPNVSIT(V,0),U,11)
 .Q:"SAHO"'[$P(^AUPNVSIT(V,0),U,7)
 .S (D,Y)=0 F  S Y=$O(^AUPNVPOV("AD",V,Y)) Q:Y'=+Y!(D)  I $D(^AUPNVPOV(Y,0)) S %=$P(^AUPNVPOV(Y,0),U) I $$ICD^BGP6UTL2(%,T,9) S D=1
 .Q:'D
 .S G=G+1
 .Q
 Q G
 ;
MH ;EP
 S (BGPN1,BGPN2,BGPD1,BGPD2,BGPD3)=0
 I 'BGPACTUP S BGPSTOP=1 Q
 I BGPAGEE<18 S BGPSTOP=1 Q
 I BGPAGEE>85 S BGPSTOP=1 Q
 I $$ESRD^BGP6D211(DFN,$P(^DPT(DFN,0),U,3),BGPEDATE) S BGPSTOP=1 Q  ;esrd anytime before end date
 S X=$$PREG^BGP6D7(DFN,BGPBDATE,BGPEDATE,1,1) I X S BGPSTOP=1 Q
 I '$$MHHTN(DFN,BGPBDATE,BGPEDATE) S BGPSTOP=1 Q  ;no htn per definition
 S BGPD1=1
 I BGPAGEE>17,BGPAGEE<60 S BGPD2=1
 I BGPAGEE>59,BGPAGEE<86 S BGPD3=1
 S BGPBP=$$LASTBP(DFN,BGPBDATE,BGPEDATE)
 I BGPBP]"" D
 .S X=BGPBP
 .I $P(X,"/",1)<140,$P(X,"/",2)<90 S BGPN1=1
 .I BGPD3,$P(X,"/",1)<150,$P(X,"/",2)<90 S BGPN2=1
VMH S BGPVALUE="HTN PT|||"_$S(BGPN1!(BGPN2):BGPBP,1:"") I BGPD3 S BGPVALUE=BGPVALUE_$S(BGPN2&('BGPN1):" <150/90",1:"")
 Q
MHHTN(P,BDATE,EDATE) ;EP
 I '$G(P) Q ""
 I '$D(^DPT(P,0)) Q ""
 NEW S,X,B
 S B=$$DOB^AUPNPAT(P)
 S S=$$FMADD^XLFDT(BDATE,182)  ;6 months
 S X=$$LASTDX^BGP6UTL1(P,"BGP HYPERTENSION DXS",B,S)
 I 'X D  I 'G Q ""  ;no dx/PROBLEM through 1st 6 months of time period
 .S T=$O(^ATXAX("B","BGP HYPERTENSION DXS",0))
 .S (X,G)=0 F  S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G)  D
 ..Q:$P(^AUPNPROB(X,0),U,8)>S  ;if added to pl after 6 MONTHS of time period, no go
 ..S Y=$P(^AUPNPROB(X,0),U)
 ..Q:$P(^AUPNPROB(X,0),U,12)="I"
 ..Q:$P(^AUPNPROB(X,0),U,12)="D"
 ..Q:'$$ICD^BGP6UTL2(Y,T,9)
 ..S G=1
 ..Q
 ;now did they have 1 pov in time period?
 S X=$$LASTDX^BGP6UTL1(P,"BGP HYPERTENSION DXS",BDATE,EDATE)
 I X Q 1
 Q 0
LASTBP(P,BDATE,EDATE) ;EP
 NEW X
 S X=$$BPS^BGP6D2(P,BDATE,EDATE,"I",1)
 I X="" Q ""
 Q $P(X,";",1)