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

BGP7D41.m

Go to the documentation of this file.
BGP7D41 ; IHS/CMI/LAB - measure 3 ;
 ;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
 ;
 ;IHS/CMI/LAB - patch 1 7-7-03 added HDL and Triglyceride check to 30-1
 ;  - fixed IMM Refusal check for null reason
I0302A ;EP
 S BGPHTN="",BGPIHD=""
 I BGPAGEB<22 S BGPSTOP=1 Q
 ;I 'BGPACTCL S BGPSTOP=1 Q  ;must be active clinical
 ;S BGPIHD=$$IHDCCVD^BGP7D729(DFN,BGPBDATE,BGPEDATE)
 S BGPCHD=0
 S BGPCHD=$$CHD^BGP7D729(DFN,BGPBDATE,BGPEDATE)
 I 'BGPCHD S BGPSTOP=1 Q  ;CHD
I0302ASC ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPN13,BGPN14,BGPN15,BGPN16,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7)=0
 ;I BGPIHD S BGPD1=1
 ;I BGPIHD,BGPDMD2 S BGPD3=1
 ;I BGPIHD,'BGPDMD2 S BGPD2=1
 I BGPCHD S BGPD7=1  ;USER POP
 I $G(BGPCHD),BGPACTCL S BGPD4=1
 I $G(BGPCHD),BGPACTCL,BGPDMD2 S BGPD6=1
 I $G(BGPCHD),BGPACTCL,'BGPDMD2 S BGPD5=1
 S BGPBPC=""
 S BGPBP=$$MEANBP^BGP7D26(DFN,$$FMADD^XLFDT(BGPEDATE,-(2*365)),BGPEDATE)
 I BGPBP["unknown" S BGPBPC=$$BPCPT^BGP7D22(DFN,$$FMADD^XLFDT(BGPEDATE,-(2*365)),BGPEDATE) I BGPBPC]"" S BGPBP=$P(BGPBPC,U,2)_"^1"
 S BGPBPDEV=$$MEANBP^BGP7D26(DFN,$$FMADD^XLFDT(BGPEDATE,-(2*365)),BGPEDATE,1)
 I BGPBPDEV["unknown" S BGPBPCD=$$BPCPT^BGP7D22(DFN,$$FMADD^XLFDT(BGPEDATE,-(2*365)),BGPEDATE,1) I BGPBPCD]"" S BGPBPDEV=$P(BGPBPCD,U,2)_"^1"
 S BGPN1=$S($P(BGPBP,U,2):1,1:0)
 S BGPN16=$S($P(BGPBPDEV,U,2):1,1:0)
 ;S BGPLDL=$$LDL^BGP7D2(DFN,$$FMADD^XLFDT(BGPEDATE,-(5*365)),BGPEDATE,1) ;date^value
 ;I $P(BGPLDL,U) S BGPN11=1  ;had ldl done
 ;S BGPLDL1=$$LDL^BGP7D2(DFN,BGPBDATE,BGPEDATE,1) ;date^value
 ;I $P(BGPLDL1,U) S BGPN2=1  ;had ldl done
 S BGPTOB=$$TOBACCO(DFN,BGP365,BGPEDATE)
 I $P(BGPTOB,U) S BGPN3=1
 S BGPBMI=$$BMI^BGP7D6(DFN,BGPEDATE,BGPAGEE),BGPN4=$S(BGPBMI]"":1,1:0)
 ;S BGPBMIR="" I 'BGPN4 S BGPBMIR=$$REF^BGP7D6(DFN,BGPBDATE,BGPEDATE,BGPAGEE) I $P(BGPBMIR,U) S BGPN4=1,BGPN8=1,BGPBMIR=1_U_"BMI: Ref ht "_$$DATE^BGP7UTL($P(BGPBMIR,U,3))_" wt "_$$DATE^BGP7UTL($P(BGPBMIR,U,6))
 ;S BGPLIFE=$$LIFE(DFN,BGP365,BGPEDATE),BGPN5=$S($P(BGPLIFE,U):1,1:0)
 S BGPLIFED=$$LIFED(DFN,BGP365,BGPEDATE),BGPN15=$S($P(BGPLIFED,U):1,1:0)
 S BGPDEP=$$DEP(DFN,BGP365,BGPEDATE),BGPN6=$S($P(BGPDEP,U):1,1:0)
 ;I 'BGPN6 S BGPDEP=$$DEPREF^BGP7D25(DFN,BGPBDATE,BGPEDATE) I BGPDEP S BGPN6=1
 S BGPDEPS=$$DEPCHD(DFN,BGPBDATE,BGPEDATE),BGPN12=$S($P(BGPDEPS,U):1,1:0)
 ;I BGPN1,BGPN2,BGPN3,BGPN10,BGPN5,BGPN12 S BGPN13=1
 I BGPN4,'BGPN8 S BGPN10=1
 I BGPN1,BGPN3,BGPN4,BGPN5 S BGPN7=1
 I BGPN1,BGPN3,BGPN10,BGPN5 S BGPN9=1  ;IHD GPRA
 I BGPN16,BGPN3,BGPN10,BGPN15 S BGPN14=1  ;CHD GPRA
 S BGPALL=0 I BGPN1,BGPN3,BGPN10,BGPN5,BGPN6 S BGPALL=1  ;IHD ALL
 S BGPALL1=0 I BGPN16,BGPN3,BGPN10,BGPN15,BGPN12 S BGPALL1=1 ;CHD ALL
 S BGPVALUE="UP"_$S(BGPD4:",AC",1:"")_" CHD"_$S(BGPD6:",AD",1:"")
 ;S BGPVALUE=BGPVALUE_"|||"_$S(BGPN14:"GPRA DEV  ",1:"")_$S(BGPALL1:"ALL  ",1:"")_$S(BGPN16:"BP: "_$P($P(BGPBPDEV,U)," ",1,3),1:"")
 S BGPVALUE=BGPVALUE_"|||"_$S(BGPN14:"ALL: ",1:"")_$S(BGPN16:"BP: "_$P(BGPBPDEV,U),1:"")
 ;S %=$S($P(BGPLDL1,U,2):"LDL: "_$$DATE^BGP7UTL($P(BGPLDL1,U,2)),1:"")
 ;I %]"" S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":";",1:"") S BGPVALUE=BGPVALUE_" "_%
 S %="" I $P(BGPTOB,U) S %="TOB: "_$S($P(BGPTOB,U,3)["/":$P(BGPTOB,U,3),1:$$DATE^BGP7UTL($P(BGPTOB,U,3)))_" "_$P(BGPTOB,U,2)
 I %]"" S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":";",1:"") S BGPVALUE=BGPVALUE_" "_%
 I BGPN10 D
 .S %=$S($P(BGPBMI,U)]"":"BMI: "_$J(BGPBMI,5,1),1:$P(BGPBMIR,U,2))
 .I %]"" S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":";",1:"") S BGPVALUE=BGPVALUE_" "_%
 S %=$S($P(BGPLIFED,U):"LIFE: "_$$DATE^BGP7UTL($P(BGPLIFED,U,2))_" "_$P(BGPLIFED,U,3),1:"")
 I %]"" S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":";",1:"") S BGPVALUE=BGPVALUE_" "_%
 S %=$S($P(BGPDEPS,U):"DEP: "_$P(BGPDEPS,U,2),1:"")
 I %]"" S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":";",1:"") S BGPVALUE=BGPVALUE_" "_%
 I $G(BGPIISO) Q
E K BGPBP,BGPLDL,BGPTOB,BGPBMI,BGPLIFE,BGPDEP,BGPDV
 Q
I0302 ;EP
 NEW BGPX
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5)=0
 ;I BGPAGEB<20 S BGPSTOP=1 Q  ;no need to process
 I BGPACTUP,BGPAGEB>17 S BGPD1=1
 I BGPACTCL,BGPAGEB>17 S BGPD2=1
 I BGPACTCL,$$CHD^BGP7D729(DFN,BGP365,BGPEDATE) S BGPIHD=1,BGPD3=1
 I '(BGPD1+BGPD2+BGPD3) S BGPSTOP=1 Q  ;not in any denominator
BPCV ;EP - called from elder care routine
 S BGPVALUE=""
 S BGPVALUE=$$MEANBP1(DFN,BGPBDATE,BGPEDATE,1)
 I BGPVALUE["unknown" S BGPVALUE=$$BPCPT^BGP7D22(DFN,BGPBDATE,BGPEDATE) I BGPVALUE]"" S BGPN1=1,BGPVALUE=$P(BGPVALUE,U,2) G V  ;CPTS COUNT IN NUMERATOR 1 ONLY
 S BGPXPHV=$P(BGPVALUE,U,1),BGPXPHV=$P(BGPXPHV," ")
 I 'BGPN1 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)
V S BGPVALUE=$S(BGPD1:"UP",1:"")_$S(BGPD2:",AC",1:"")_$S(BGPD3:",CHD",1:"")_"|||"_$P(BGPVALUE,U)
 Q
DEP(P,BDATE,EDATE) ;EP
 S X=$$DEP^BGP7D25(P,BDATE,EDATE) I $P(X,U) Q X
 S X=$$DEPSCR^BGP7D25(P,BDATE,EDATE) I $P(X,U) Q X
 Q ""
DEPCHD(P,BDATE,EDATE) ;EP
 S X=$$DEP^BGP7D25(P,BDATE,EDATE) I $P(X,U) Q X
 S X=$$DEPSCR^BGP7D25(P,BDATE,EDATE) I $P(X,U) Q X
 S X=$$DEPSUIC^BGP7D25(P,BDATE,EDATE) I $P(X,U) Q X
 Q ""
LIFE(P,BDATE,EDATE) ;EP
 S X=$$MEDNUTR^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$SPECNUTR^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$SPECEX^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$OTHREL^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 Q ""
LIFED(P,BDATE,EDATE) ;EP
 S X=$$MEDNUTRD^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$SPECNUTR^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$SPECEX^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$OTHREL^BGP7D711(P,BDATE,EDATE) I X]"" Q 1_U_X
 Q ""
TOBACCO(P,BDATE,EDATE) ;EP
 S X=$$TOBACCO^BGP7D7(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$TOBDX(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$PED^BGP7D7(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$DENT^BGP7D7(P,BDATE,EDATE) I X]"" Q 1_U_X
 S X=$$CPTSM^BGP7D7(P,BDATE,EDATE) I X]"" Q 1_U_X
 Q ""
MEANBP(P,BDATE,EDATE,GDEV) ;EP
 S GDEV=$G(GDEV)
 S X=$$BPS(P,BDATE,EDATE,"I",GDEV)
 S S=$$SYSMEAN(X) I S="" Q "unknown^^"
 S DS=$$DIAMEAN(X) I DS="" Q "unknown^^"
 ;I S>159!(DS>99) Q S_"/"_DS_" STG 2 HTN"_U_6
 ;I S>139&(S<160)!(DS>89&(DS<100)) Q S_"/"_DS_" STG 1 HTN"_U_5
 ;I S>129&(S<140)!(DS>80&(DS<90)) Q S_"/"_DS_" PRE HTN 2"_U_4
 ;I S>119&(S<130)!(DS=80) Q S_"/"_DS_" PRE HTN 1"_U_3
 ;I S<120&(DS<80) Q S_"/"_DS_" NORMAL"_U_2
 Q S_"/"_DS_U_1
 ;
MEANBPD(P,BDATE,EDATE,GDEV,A) ;EP
 NEW S,X,DS,Y
 S GDEV=$G(GDEV)
 S X=$$BPS(P,BDATE,EDATE,"I",GDEV)
 S S=$$SYSMEAN(X) I S="" Q "unknown^^"
 S DS=$$DIAMEAN(X) I DS="" Q "unknown^^"
 I A<60 D  Q Y
 .I S<140&(DS<90) S Y=S_"/"_DS_" CON"_U_4
 .S Y=S_"/"_DS_" UNC"_U_3
 I S<150&(DS<90) Q S_"/"_DS_" CON"_U_4
 Q S_"/"_DS_" UNC"_U_3
 ;
SYSMEAN(X) ;EP
 I X="" Q ""
 S C=0 F Y=1:1:3 I $P(X,";",Y)]"" S C=C+1
 I C<1 Q ""
 S T=0 F Y=1:1:3 S T=$P($P(X,";",Y),"/")+T
 Q T\C
 ;Q $$STRIP^XLFSTR($J((T/C),5,1)," ")
 ;
DIAMEAN(X) ;EP
 I X="" Q ""
 S C=0 F Y=1:1:3 I $P(X,";",Y)]"" S C=C+1
 I C<1 Q ""
 S T=0 F Y=1:1:3 S T=$P($P(X,";",Y),"/",2)+T
 Q T\C
 ;Q $$STRIP^XLFSTR($J((T/C),5,1)," ")
 ;
BPS(P,BDATE,EDATE,F,GDEV) ;EP ;
 I $G(F)="" S F="E"
 S GDEV=$G(GDEV)
 NEW BGPGLL,BGPGV,BGPG,X,Y,BGPBP,V,T,Z
 S BGPGLL=0,BGPGV=""
 K BGPG
 K ^TMP($J,"BPV")
 S A="^TMP($J,""BPV"",",B=P_"^LAST 365 VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
 I '$D(^TMP($J,"BPV",1)) Q ""
 ;S X=P_"^LAST 50 MEAS BP;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,"BGPG(")
 ;S BGPGL=0 F  S BGPGL=$O(BGPG(BGPGL)) Q:BGPGL'=+BGPGL!(BGPGLL=3)  S BGPGBP=$P($G(BGPG(BGPGL)),U,2) D
 S Y=0 F  S Y=$O(^TMP($J,"BPV",Y)) Q:Y'=+Y!(BGPGLL=3)  D
 .S V=$P(^TMP($J,"BPV",Y),U,5)
 .Q:$$CLINIC^APCLV(V,"C")=30  ;NO ER CLINIC VISITS COUNTED
 .I $G(GDEV) Q:$$GDEV^BGP7D2(V)
 .Q:'$D(^AUPNVMSR("AD",V))  ;no measurements to look at
 .;NOW GET ALL BPS ON THIS VISIT
 .S BGPBP=""
 .S X=0 F  S X=$O(^AUPNVMSR("AD",V,X)) Q:X'=+X  D
 ..Q:'$D(^AUPNVMSR(X,0))  ;BAD AD XREF
 ..Q:$P($G(^AUPNVMSR(X,2)),U,1)
 ..S T=$P($G(^AUPNVMSR(X,0)),U)
 ..Q:T=""  ;BAD AD XREF
 ..Q:$P($G(^AUTTMSR(T,0)),U)'="BP"  ;not a BP measurement type
 ..S Z=$P(^AUPNVMSR(X,0),U,4)  ;blood pressure value
 ..I BGPBP="" S BGPBP=Z Q
 ..I $P(Z,"/")'>$P(BGPBP,"/") S BGPBP=Z
 .Q:BGPBP=""
 .S BGPGLL=BGPGLL+1
 .I F="E" S $P(BGPGV,";",BGPGLL)=BGPBP_"  "_$$FMTE^XLFDT($P(^TMP($J,"BPV",V),U))
 .I F="I" S $P(BGPGV,";",BGPGLL)=$P(BGPBP," ")
 K ^TMP($J,"BPV")
 Q BGPGV
TOBDX(P,BDATE,EDATE) ;EP
 K BGPG
 S X=P_"^LAST DX [BGP TOBACCO DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,"BGPG(")
 I $D(BGPG(1)) Q $P(BGPG(1),U,2)_U_$P(BGPG(1),U)
 ;S X=P_"^LAST DX V15.82;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,"BGPG(")
 ;I $D(BGPG(1)) Q $P(BGPG(1),U,2)_U_$P(BGPG(1),U)
 S X=0,G="" F  S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G]"")  D
 .Q:$P(^AUPNPROB(X,0),U,12)="D"
 .Q:$P(^AUPNPROB(X,0),U,12)="I"
 .Q:$P(^AUPNPROB(X,0),U,3)>EDATE
 .Q:$P(^AUPNPROB(X,0),U,3)<BDATE
 .S Y=$P(^AUPNPROB(X,0),U)
 .I $E($P($$ICDDX^BGP7UTL2(Y),U,2),1,5)'="305.1",$P($$ICDDX^BGP7UTL2(Y),U,2)'="V15.82" Q
 .S G=$P($$ICDDX^BGP7UTL2(Y),U,2)_" PL"
 .Q
 Q G
MEANBP1(P,BDATE,EDATE,GDEV) ;EP
 S GDEV=$G(GDEV)
 S X=$$BPS(P,BDATE,EDATE,"I",GDEV)
 S S=$$SYSMEAN1(X) I S="" Q "unknown^^"
 S DS=$$DIAMEAN1(X) I DS="" Q "unknown^^"
 ;I S>159!(DS>99) Q S_"/"_DS_" STG 2 HTN"_U_6
 ;I S>139&(S<160)!(DS>89&(DS<100)) Q S_"/"_DS_" STG 1 HTN"_U_5
 ;I S>129&(S<140)!(DS>80&(DS<90)) Q S_"/"_DS_" PRE HTN 2"_U_4
 ;I S>119&(S<130)!(DS=80) Q S_"/"_DS_" PRE HTN 1"_U_3
 ;I S<120&(DS<80) Q S_"/"_DS_" NORMAL"_U_2
 Q S_"/"_DS_U_1
 ;
SYSMEAN1(X) ;EP
 I X="" Q ""
 S C=0 F Y=1:1:3 I $P(X,";",Y)]"" S C=C+1
 I C<1 Q ""
 S T=0 F Y=1:1:3 S T=$P($P(X,";",Y),"/")+T
 Q T\C
 ;Q $$STRIP^XLFSTR($J((T/C),5,1)," ")
 ;
DIAMEAN1(X) ;EP
 I X="" Q ""
 S C=0 F Y=1:1:3 I $P(X,";",Y)]"" S C=C+1
 I C<1 Q ""
 S T=0 F Y=1:1:3 S T=$P($P(X,";",Y),"/",2)+T
 Q T\C
 ;Q $$STRIP^XLFSTR($J((T/C),5,1)," ")
 ;