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

BGP4D71.m

Go to the documentation of this file.
BGP4D71 ; IHS/CMI/LAB - measure C ;
 ;;14.1;IHS CLINICAL REPORTING;;MAY 29, 2014;Build 114
 ;
IC1 ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
 ;denominator 1 is active clinical, 6 and older and overweight
 S (BGPOW,BGPOB,BGPBMI)=""
 K BGPALLED,BGPSN,BGPMN,BGPSPEX
 I 'BGPACTUP S BGPSTOP=1 Q
 S BGPBMI=$$BMI^BGP4D6(DFN,BGPEDATE,BGPAGEE)
 S BGPOW=$$OW^BGP4D6(DFN,BGPBMI,BGPAGEE)
 S BGPOB=$$OB^BGP4D6(DFN,BGPBMI,BGPAGEE)
 S BGPOWOB=BGPOW+BGPOB
 I BGPAGEB>5,BGPOWOB,BGPACTCL S BGPD1=1
 I BGPDMD2 S BGPD2=1
 I BGPAGEB>5,BGPOB,BGPACTCL S BGPD3=1
 I BGPD3,BGPAGEB>5,BGPAGEB<12 S BGPD4=1
 I BGPD3,BGPAGEB>11,BGPAGEB<20 S BGPD5=1
 I BGPD3,BGPAGEB>19,BGPAGEB<40 S BGPD6=1
 I BGPD3,BGPAGEB>39,BGPAGEB<60 S BGPD7=1
 I BGPD3,BGPAGEB>59 S BGPD8=1
 I '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5+BGPD6+BGPD7+BGPD8) Q
 S BGPVALUE=""
 S BGPMN=$$MEDNUTRD^BGP4D711(DFN,BGP365,BGPEDATE) I BGPMN]"" S BGPN1=1
 S BGPSN=$$SPECNUTR^BGP4D711(DFN,BGP365,BGPEDATE) I BGPSN]"" S BGPN2=1
 S BGPSPEX=$$SPECEX^BGP4D711(DFN,BGP365,BGPEDATE) I BGPSPEX]"" S BGPN3=1
 S BGPOTH=$$OTHREL^BGP4D711(DFN,BGP365,BGPEDATE) I BGPOTH]"" S BGPN4=1
 I BGPMN]"" S BGPVALUE="MNT: "_$$DATE^BGP4UTL($P(BGPMN,U))_" "_$P(BGPMN,U,2)_$S(BGPMN]"":"; ",1:"")
 I BGPSN]"" S BGPVALUE=BGPVALUE_"NUTR: "_$$DATE^BGP4UTL($P(BGPSN,U))_" "_$P(BGPSN,U,2)_$S(BGPSN]"":"; ",1:"")
 I BGPSPEX]"" S BGPVALUE=BGPVALUE_"EXER ED: "_$$DATE^BGP4UTL($P(BGPSPEX,U))_" "_$P(BGPSPEX,U,2)_$S(BGPSPEX]"":"; ",1:"")
 I BGPOTH]"" S BGPVALUE=BGPVALUE_"LIFE: "_$$DATE^BGP4UTL($P(BGPOTH,U))_" "_$P(BGPOTH,U,2)
 S V=$S(BGPD1:"AC-OW",1:"")
 I BGPD3 S V=V_$S(V]"":",",1:"") S V=V_"AC-OB"
 I BGPD2 S V=V_$S(V]"":",",1:"") S V=V_"AD"  ;$S(BGPD2:"AD;",1:"")_$S(BGPD3:"OB",1:"")
 S V=V_"|||"_BGPVALUE
 S BGPVALUE=V
 K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P,V,S,F,T,BGPALLED,BGPBMI,BGPOW,BGPOB,BGPOWOB,BGPMN,BGPSN,BGPSPEX
 K ^TMP($J,"A")
 Q
DNKA(V) ;EP - is this a DNKA visit?
 NEW D,N
 S D=$$PRIMPOV^APCLV(V,"C")
 I D=".0860" Q 1
 S N=$$PRIMPOV^APCLV(V,"N")
 I $E(D)="V",N["DNKA" Q 1
 I $E(D)="V",N["DID NOT KEEP APPOINTMENT" Q 1
 I $E(D)="V",N["DID NOT KEEP APPT" Q 1
 Q 0
TOMPED(P,BDATE,EDATE) ;EP
 K BGPALLED
 S BGPLPED=""
 S Y="BGPALLED("
 S X=P_"^ALL EDUC;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I $D(BGPALLED(1)) S %="" D  I %]"" S BGPLPED=%
 .S (X,D)=0,T="" F  S X=$O(BGPALLED(X)) Q:X'=+X  D
 ..S T=$P(^AUPNVPED(+$P(BGPALLED(X),U,4),0),U)
 ..Q:'T
 ..Q:'$D(^AUTTEDT(T,0))
 ..S T=$P(^AUTTEDT(T,0),U,2)
 ..I T'="TO-M" Q
 ..I $P(BGPLPED,U)<$P(BGPALLED(X),U) S %=$P(BGPALLED(X),U)_U_T
 I BGPLPED]"" Q BGPLPED  ;
TOMREF ; 
 ;EP - now check all Refusals of these education topics
 S G="",X=0 F  S X=$O(^AUPNPREF("AA",P,9999999.09,X)) Q:X=""!(G]"")  D
 .S D=0 F  S D=$O(^AUPNPREF("AA",P,9999999.09,X,D)) Q:D=""!(G]"")  D
 ..S I=0 F  S I=$O(^AUPNPREF("AA",P,9999999.09,X,D,I)) Q:I'=+I!(G]"")  D
 ...S Z=$P($G(^AUPNPREF(I,0)),U,3)
 ...Q:Z=""
 ...I Z<BDATE Q
 ...I Z>EDATE Q
 ...S Y=$P($G(^AUTTEDT(X,0)),U,2)
 ...I Y'="TO-M" Q
 ...S G=Z_U_"Ref "_Y
 Q G
GETALLHF ;
 K BGPALLH
 S C=$O(^AUTTHF("B","TOBACCO (SMOKING)",0)) ;ien of category passed
 D GETHF1
 ;If it is a current or cessation, use it and quit
 I $P(BGPTOBS,U,2)["CURRENT"!($P(BGPTOBS,U,2)["CESSATION")!($P(BGPTOBS,U,2)["HEAVY")!($P(BGPTOBS,U,2)["LIGHT") Q
 S C=$O(^AUTTHF("B","TOBACCO (SMOKELESS - CHEWING/DIP)",0)) ;ien of category passed
 D GETHF1
 ;If it is a current or cessation, use it and quit
 I $P(BGPTOBS,U,2)["CURRENT"!($P(BGPTOBS,U,2)["CESSATION") Q
 S C=$O(^AUTTHF("B","TOBACCO",0)) ;ien of category passed
 D GETHF1
 ;If it is a current or cessation, use it and quit
 I $P(BGPTOBS,U,2)["CURRENT"!($P(BGPTOBS,U,2)["CESSATION") Q
 ;now get lastest of any of the categories
 S D=$O(BGPALLH(0))
 I D S BGPTOBS=BGPALLH(D) Q
 S BGPTOBS=""
 Q
GETHF1 ;
 I '$G(C) S BGPTOBS="" Q
 NEW ED,BD
 K BGPTOBS
 S ED=BGPEDX
 S BD=BGPBDX
 S (H,D)=0 K O
 F  S H=$O(^AUTTHF("AC",C,H))  Q:'+H  D
 .Q:'$D(^AUPNVHF("AA",DFN,H))
 .S D="" F  S D=$O(^AUPNVHF("AA",DFN,H,D)) Q:D'=+D  D
 ..Q:(9999999-D)>ED  ;after time frame
 ..Q:(9999999-D)<BD  ;before time frame
 ..I $D(BGPTOBS(D)),$P(BGPTOBS(D),U,2)["CESSATION" Q
 ..I $D(BGPTOBS(D)),$P(BGPTOBS(D),U,2)["CURRENT SMOKE",$P(^AUTTHF(H,0),U)'["CESSATION" Q
 ..S BGPTOBS(D)=$O(^AUPNVHF("AA",DFN,H,D,""))_U_$P(^AUTTHF(H,0),U)
 .Q
 ;NOW if there are multiples , take the USER one, if no USER ONE TAKE THE LATEST ONE
 S BGPTOBS=""
 S (D,H)=$O(BGPTOBS(0)) I 'D S BGPTOBS="" Q
 S Y=0 F  S Y=$O(BGPTOBS(Y)) Q:Y'=+Y  D  Q:BGPTOBS]""
 .I $P(BGPTOBS(Y),U,2)["CESSATION"!($P(BGPTOBS(Y),U,2)["CURRENT") S BGPTOBS=BGPTOBS(Y)_U_(9999999-Y),BGPALLH(Y)=BGPTOBS(Y)_U_(9999999-Y)
 Q:BGPTOBS]""
 S D=BGPTOBS(D)_U_(9999999-D)
 K BGPTOBS
 S BGPTOBS=D,BGPALLH(H)=D
 Q
QUIT(P,BD,ED) ;
 NEW Y,X,G,T
 S Y=$$LASTDX^BGP4UTL1(P,"BGP TOBACCO PAST USE DXS",BD,ED)
 I Y Q 1_U_"QUIT: "_$$DATE^BGP4UTL($P(Y,U,3))_" POV "_$P(Y,U,2)
 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)>ED
 .Q:$P(^AUPNPROB(X,0),U,3)<BD
 .S Y=$P(^AUPNPROB(X,0),U)
 .S T=$P($$ICDDX^BGP4UTL2(Y),U,2)
 .I '$$ICD^BGP4UTL2(Y,$O(^ATXAX("B","BGP TOBACCO PAST USE DXS",0)),9) Q
 .S G=1_U_"QUIT: "_$$DATE^BGP4UTL($P(^AUPNPROB(X,0),U,3))_" PL "_$P(^ICD9(Y,0),U)
 I G Q G
 S G=$$LASTHF^BGP4D7(P,"TOBACCO",BD,ED)
 I $P(G,U)["PREVIOUS" Q 1_U_"QUIT: "_$P(G,U,2)_" HF: "_$P(G,U,1)
 S G=$$LASTHF^BGP4D7(P,"TOBACCO (SMOKING)",BD,ED)
 I $P(G,U)["PREVIOUS" Q 1_U_"QUIT: "_$P(G,U,2)_" HF: "_$P(G,U,1)
 S G=$$LASTHF^BGP4D7(P,"TOBACCO (SMOKELESS - CHEWING/DIP)",BD,ED)
 I $P(G,U)["PREVIOUS" Q 1_U_"QUIT: "_$P(G,U,2)_" HF: "_$P(G,U,1)
 Q ""
 ;
GETLAST(P,BD,ED) ;
 NEW BGPLAST
 S G=$$LASTHF^BGP4D7(P,"TOBACCO",BD,ED)
 I G]"" S BGPLAST(9999999-$P(G,U,3))=G
 S G=$$LASTHF^BGP4D7(P,"TOBACCO (SMOKING)",BD,ED)
 I G]"" S BGPLAST(9999999-$P(G,U,3))=G
 S G=$$LASTHF^BGP4D7(P,"TOBACCO (SMOKELESS - CHEWING/DIP)",BD,ED)
 I G]"" S BGPLAST(9999999-$P(G,U,3))=G
 S G=$O(BGPLAST(0))
 I 'G Q ""
 Q BGPLAST(G)
I91 ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9,BGPD10)=0
 K BGPTOB,BGPSDX,BGP1320,BGPTC,BGPTQ,BGPTOM,BGPTOBS,BGPTC1,BGPTOBD,BGPQ
 S (BGPTUHF,BGPTUQ,BGPTU,BGPTUC,BGPREM,BGPTOBD,BGPTOBX,BGPTC,BGPTC1,BGPQ)=""
 I 'BGPACTUP S BGPSTOP=1 Q  ;must be at least user pop
 D NEWSTUFF Q
 ;
NEWSTUFF ;new stuff
 ;BGPD6 - is a tobacco user or user in cessation
 ;BGPD7 - active clinical tobacco user or user in cessation
 ;BGPD8 - ditto, less than 12
 ;BGPD9 - ditto, 12-17
 ;BGPD10 - ditto over 17
 K BGPTOBS
 S BGPBDX=BGPBDATE,BGPEDX=BGPEDATE D GETALLHF
 I BGPTOBS]"" D  G:BGPTU SET
 .I $P(BGPTOBS,U,2)["CESSATION" S BGPTUC=1,BGPTUQ=1,BGPTU=1,BGPTOBD=$P(BGPTOBS,U,3),BGPTOBX=$P(BGPTOBS,U,2)  ;cessation and quit
 .I $P(BGPTOBS,U,2)["CURRENT"!($P(BGPTOBS,U,2)["HEAVY TOBACCO SMOKER")!($P(BGPTOBS,U,2)["LIGHT TOBACCO SMOKER") S BGPTU=1,BGPTOBD=$P(BGPTOBS,U,3),BGPTOBX=$P(BGPTOBS,U,2)
 .I $P(BGPTOBS,U,2)]"",'BGPTU D
 ..S X=$P(BGPTOBS,U,3)
 ..S Y=$$CPTI^BGP4DU(DFN,$$FMADD^XLFDT(X,1),BGPEDATE,+$$CODEN^ICPTCOD("1034F"))
 ..I Y S BGPTU=1,BGPTOBD=$P(Y,U,2),BGPTOBX="CPT 1034F" Q
 ..S Y=$$CPTI^BGP4DU(DFN,$$FMADD^XLFDT(X,1),BGPEDATE,+$$CODEN^ICPTCOD("1035F"))
 ..I Y S BGPTU=1,BGPTOBD=$P(Y,U,2),BGPTOBX="CPT 1035F"
 ;
 I BGPTOBS="" D  G:Y SET
 .S Y=$$LASTDX^BGP4UTL1(DFN,"BGP TOBACCO USER DXS",BGPBDATE,BGPEDATE)
 .I Y S BGPTU=1,BGPTOBD=$P(Y,U,3),BGPTOBX=$P(Y,U,2) Q
 .S Y=$$CPT^BGP4DU(DFN,BGPBDATE,BGPEDATE,$O(^ATXAX("B","BGP TOBACCO USER CPTS",0)),6)
 .I Y S BGPTU=1,BGPTOBD=$P(Y,U,2),BGPTOBX=$P(Y,U,3) Q
 .;problem list diagnosis
 .S T=$O(^ATXAX("B","BGP TOBACCO USER DXS",0))
 .S X=0,G="",Y="" F  S X=$O(^AUPNPROB("AC",DFN,X)) Q:X'=+X  D
 ..Q:$P(^AUPNPROB(X,0),U,12)="D"
 ..Q:$P(^AUPNPROB(X,0),U,12)="I"
 ..Q:$P(^AUPNPROB(X,0),U,3)>BGPEDX
 ..S Z=$P(^AUPNPROB(X,0),U)
 ..Q:'$$ICD^BGP4UTL2(Z,T,9)
 ..S Y=1,BGPTU=1,BGPTOBD=$P(^AUPNPROB(X,0),U,3),BGPTOBX="PL: "_$P(^ICD9(Z,0),U,1)
 ;
 S BGPBDX=$$DOB^AUPNPAT(DFN),BGPEDX=$$FMADD^XLFDT(BGPBDATE,-1) S BGPTOBS=$$GETLAST(DFN,BGPBDX,BGPEDX)  ;EXPANDED TIME FRAME
 ;
 I BGPTOBS]"" D  G POT
 .I $P(BGPTOBS,U,1)["CESSATION" S BGPTUC=1,BGPTUQ=1,BGPTU=1,BGPTOBD=$P(BGPTOBS,U,3),BGPTOBX=$P(BGPTOBS,U,2)  ;cessation and quit
 .I $P(BGPTOBS,U,1)["CURRENT" S BGPTU=1,BGPTOBD=$P(BGPTOBS,U,3),BGPTOBX=$P(BGPTOBS,U,2)
 .I $P(BGPTOBS,U,1)]"",'BGPTU D
 ..S X=$P(BGPTOBS,U,3)
 ..S Y=$$CPTI^BGP4DU(DFN,$$FMADD^XLFDT(X,1),BGPEDATE,+$$CODEN^ICPTCOD("1034F"))
 ..I Y S BGPTU=1,BGPTOBD=$P(Y,U,2),BGPTOBX="CPT: 1034F" Q
 ..S Y=$$CPTI^BGP4DU(DFN,$$FMADD^XLFDT(X,1),BGPEDATE,+$$CODEN^ICPTCOD("1035F"))
 ..I Y S BGPTU=1,BGPTOBD=$P(Y,U,2),BGPTOBX="CPT: 1035F"
 ;
 I BGPTOBS="" D  G:Y POT
 .S Y=$$LASTDX^BGP4UTL1(DFN,"BGP TOBACCO USER DXS",BGPBDX,BGPEDX)
 .I Y S BGPTU=1,BGPTOBD=$P(Y,U,3),BGPTOBX=$P(Y,U,2) Q
 .S Y=$$CPT^BGP4DU(DFN,BGPBDX,BGPEDX,$O(^ATXAX("B","BGP TOBACCO USER CPTS",0)),6)
 .I Y S BGPTU=1,BGPTOBD=$P(Y,U,2),BGPTOBX=$P(Y,U,3) Q
 .;problem list diagnosis
 .S T=$O(^ATXAX("B","BGP TOBACCO USER DXS",0))
 .S X=0,G="",Y="" F  S X=$O(^AUPNPROB("AC",DFN,X)) Q:X'=+X  D
 ..Q:$P(^AUPNPROB(X,0),U,12)="D"
 ..Q:$P(^AUPNPROB(X,0),U,12)="I"
 ..Q:$P(^AUPNPROB(X,0),U,3)>BGPEDX
 ..S Z=$P(^AUPNPROB(X,0),U)
 ..Q:'$$ICD^BGP4UTL2(Z,T,9)
 ..S Y=1,BGPTU=1,BGPTOBD=$P(^AUPNPROB(X,0),U,3),BGPTOBX="PL: "_$P(^ICD9(Z,0),U,1)
 ;
 I 'BGPTU G SET  ;not a tobacco user
POT ;if potential check for 2 codes
 S X=BGPTOBD
 S Y=$$LASTDX^BGP4UTL1(DFN,"BGP TOBACCO PAST USE DXS",$$FMADD^XLFDT(X,1),BGPBDATE)
 I Y S BGPTU="" G SET
 S X=0,G="",BGPREM="" F  S X=$O(^AUPNPROB("AC",DFN,X)) Q:X'=+X!(BGPREM)  D
 .Q:$P(^AUPNPROB(X,0),U,12)="D"
 .Q:$P(^AUPNPROB(X,0),U,12)="I"
 .Q:$P(^AUPNPROB(X,0),U,3)>BGPBDATE
 .Q:$P(^AUPNPROB(X,0),U,3)<X
 .S Y=$P(^AUPNPROB(X,0),U)
 .S T=$O(^ATXAX("B","BGP TOBACCO PAST USE DXS",0))
 .I $$ICD^BGP4UTL2(Y,T,9) S BGPREM=1 Q
 .Q
 ;
 I BGPREM S BGPTU=""
 ;BGPTU - tobacco user  BGPTUQ - quit tobacco use BGPTUC - tobacco user in cessation
SET ;
 I 'BGPTU S BGPSTOP=1 D KVARS Q  ;not in this denominator at all
 S BGPD6=1
 I BGPD6,BGPACTCL S BGPD7=1
 I BGPD7,BGPAGEB<12 S BGPD8=1
 I BGPD7,BGPAGEB>11,BGPAGEB<18 S BGPD9=1
 I BGPD7,BGPAGEB>17 S BGPD10=1
 ;get numerator stuff
 ;BGPN6=tobacco cessation counseling  bgpn7 - REFUSED counseling  
 ;I 'BGPTUC S BGPTC1=$$PED^BGP4D711(DFN,BGPBDATE,BGPEDATE,1)
 S BGPTC1=$$PED^BGP4D711(DFN,BGPBDATE,BGPEDATE,1)
 I $P(BGPTC1,U)]"" S BGPN6=1 I $P(BGPTC1,U,2)["Ref" S BGPN7=1
 ;BGPN8 - quit   bgpn9-cessation
 S Y=$$FMADD^XLFDT(BGPTOBD,1)
 I Y<BGPBDATE S Y=BGPBDATE
 S BGPQ=$$QUIT(DFN,Y,BGPEDATE)  ;any quit after BGPTOBD
 I BGPQ S BGPN8=1
 ;I BGPTUQ S BGPN8=1
 I BGPN8,BGPTUQ S BGPN9=1
 I BGPN6!(BGPN8) S BGPN10=1
 ;SET BGPVALUE
 S BGPVALUE=$S(BGPRTYPE=3:"",1:"")_$S(BGPD7:"AC",1:"")_" TOB USER: "_$$DATE^BGP4UTL(BGPTOBD)
 D
 .S BGPVALUE=BGPVALUE_"|||"_$S($P(BGPTC1,U):"COUNSEL: "_$$DATE^BGP4UTL($P(BGPTC1,U))_" "_$P(BGPTC1,U,2),1:"")
 .I BGPN8,BGPQ S BGPVALUE=BGPVALUE_"; "_$P(BGPQ,U,2) ;_" "_$P(BGPQ,U,3)
KVARS ;
 Q:$G(BGPINFO)
 K BGPQ,X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P,V,S,F,T,BGPQ,BGPALLED,BGPTQ,BGPTC
 K BGPTC1,BGPTOB,BGPSDX,BGP1320,BGPTOM,BGPTOBS,BGPTUHF,BGPTU,BGPTUC,BGPTUQ,BGPTOBD,BGPREM
 Q