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

BGP9D7.m

Go to the documentation of this file.
BGP9D7 ; IHS/CMI/LAB - measure 31 ; 
 ;;9.0;IHS CLINICAL REPORTING;**1**;JUL 01, 2009
 ;
I18 ;EP
 S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9,BGPXPND,BGP1320)=0
 I BGPAGEB<5 S BGPSTOP=1 Q
 I BGPACTUP S BGPD1=1
 I BGPAGEB>4,BGPAGEB<14 S BGPD2=1
 I BGPAGEB>13,BGPAGEB<18 S BGPD3=1
 I BGPAGEB>17,BGPAGEB<25 S BGPD4=1
 I BGPAGEB>24,BGPAGEB<45 S BGPD5=1
 I BGPAGEB>44,BGPAGEB<65 S BGPD6=1
 I BGPAGEB>64 S BGPD7=1
 I BGPSEX="F",$$PREG(DFN,$$FMADD^XLFDT(BGPEDATE,(-(30*20))),BGPEDATE) S BGPD8=1
 I '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5+BGPD6+BGPD7+BGPD8) S BGPSTOP=1 Q
 S BGP20M=$$FMADD^XLFDT(BGPEDATE,-600)
TA ;EP - called from elder
 S BGPTOB=$$TOBACCO(DFN,$S(BGPD8:BGP20M,1:BGP365),BGPEDATE)
 S BGPN1=$S(BGPTOB]"":1,1:0)
 S BGPSDX=$$DX(DFN,$S(BGPD8:BGP20M,1:BGP365),BGPEDATE)
 S BGPXPND=$$PED(DFN,$S(BGPD8:BGP20M,1:BGP365),BGPEDATE)
 S BGP1320=$$DENT(DFN,$S(BGPD8:BGP20M,1:BGP365),BGPEDATE)
 S BGPSCPT=$$CPTSM(DFN,$S(BGPD8:BGP20M,1:BGP365),BGPEDATE)
 I BGPSDX]"" S BGPN1=1
 I BGPXPND]"" S BGPN1=1
 I BGP1320]"" S BGPN1=1
 I BGPSCPT]"" S BGPN1=1
 S F=$P(BGPTOB,U)
 S %=""
 I BGPSDX]"",$P(BGPSDX,U,1)="305.13" S %=1
 I BGPSDX]"",$P(BGPSDX,U,1)="V15.82" S %=1
 I F["CURRENT"!(BGPSDX]""&(%=""))!(F["CESSATION")!($P(BGPSCPT,U)="1034F")!($P(BGPSCPT,U)="1035F")!($P(BGPSCPT,U)="G0376")!($P(BGPSCPT,U)="G0375")!($P(BGPSCPT,U)=99407)!($P(BGPSCPT,U)=99406) S BGPN2=1
 I F="CURRENT SMOKELESS"!(F="CURRENT SMOKER & SMOKELESS")!(F="CESSATION-SMOKELESS")!($P(BGPSCPT,U)="1035F") S BGPN4=1
 I 'BGPN4,F["CURRENT SMOKER"!(BGPSDX]""&(%=""))!(F="CESSATION-SMOKER")!($P(BGPSCPT,U)="1034F")!($P(BGPSCPT,U)="G0376")!($P(BGPSCPT,U)="G0375")!($P(BGPSCPT,U)=99407)!($P(BGPSCPT,U)=99406) S BGPN3=1
 ;I BGPN2,BGPXPND]"" S BGPN5=1
 I F="SMOKER IN HOME"!(F["ENVIRON") S BGPN5=1
 S V=$S(BGPD1:"UP",1:"")_$S(BGPACTCL:",AC",1:"")_$S(BGPD8:",PREG",1:"")
 S V=V_"|||"
 S S=$S(F="CURRENT SMOKER":"Cur Smk",F="CURRENT SMOKELESS":"Cur smkl",F["NON":"NTU",F="CURRENT SMOKER & SMOKELESS":"Cur smk/smkl",F["SMOKER IN HOME":"Smk Home",F["ENVIRON":"ETS",1:"")
 I S="" S S=$S(F="CESSATION-SMOKER":"Cess Smk",F["CESSATION-SMOKELESS":"Cess smkl",1:"")
 I S="" S S=$S(F="PREVIOUS SMOKER":"Prev smk",F="PREVIOUS SMOKELESS":"Prev smkl",F["PREVIOUS":"Prev smk/smkl",F="SMOKE FREE HOME":"Smk free home",1:"")
 I S="" S S=F
 I S]"" S S="HF "_S_" "_$P(BGPTOB,U,2)
 I BGP1320]"" S S=S_" 1320 ADA "_$$DATE^BGP9UTL($P(BGP1320,U,2))
 I BGPSDX]"" S S=S_" DX "_$S($P(BGPSDX,U,1)="305.13":"quit",$P(BGPSDX,U,1)="V15.82":"V15.82",1:"Cur smk")_" "_$$DATE^BGP9UTL($P(BGPSDX,U,2))
 I BGPXPND]"" S S=S_" PtEd "_$P(BGPXPND,U)_" "_$$DATE^BGP9UTL($P(BGPXPND,U,2))
 I BGPSCPT]"" S S=S_" CPT "_$P(BGPSCPT,U)_" "_$$DATE^BGP9UTL($P(BGPSCPT,U,2))
 S BGPVALUE=V_" "_S
 K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P,V,S,F,BGPSDX,BGPXPND,BGP1320,BGP20M
 K ^TMP($J,"A")
 Q
 ;
I023 ;EP - PHN
 K BGPN1,BGPN2,BGPN3,BGPN4,BGPVALUE
 I 'BGPACTUP S BGPSTOP=1 Q
 S (BGPN1,BGPN2)=0
 S BGPVALUE=$$PHNV(DFN,BGP365,BGPEDATE,BGPHOME)
 S BGPN1=BGPVALUE
 S BGPVALUE="UP|||"_$P(BGPVALUE,U)_" all PHN; "_$P(BGPVALUE,U,2)_" home; "_$P(BGPVALUE,U,12)_" driver all; "_$P(BGPVALUE,U,13)_" driver home"
 K ^TMP($J,"A")
 Q
PHNV(P,BDATE,EDATE,HOMELOC) ;
 S HOMELOC=$G(HOMELOC)
 K ^TMP($J,"A") S A="^TMP($J,""A"","
 S B=P_"^ALL VISITS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(B,A)
 I '$D(^TMP($J,"A",1)) Q "0^0^0^0^0^0^0^0^0^0^0^0^0"
 S (X,Y)=0,C="0^0^0^0^0^0^0^0^0^0^0^0^0" F  S X=$O(^TMP($J,"A",X)) Q:X'=+X  S V=$P(^TMP($J,"A",X),U,5) D
 .;S Y=0 I $$CLINIC^APCLV(V,"C")=45 S Y=1 Q
 .S (D,Y,Z)=0
 .F  S D=$O(^AUPNVPRV("AD",V,D)) Q:D'=+D  S Q=$P(^AUPNVPRV(D,0),U) D
 ..Q:Q=""
 ..S %=$$VALI^XBDIQ1($S($P(^DD(9000010.06,.01,0),U,2)["200":200,1:6),Q,$S($P(^DD(9000010.06,.01,0),U,2)["200":53.5,1:2))
 ..I % S %=$P($G(^DIC(7,+%,9999999)),U)
 ..I %'=13,%'=91 Q  ;not a phn or driver
 ..S $P(C,U,1)=$P(C,U,1)+1
 ..I %=91 S $P(C,U,12)=$P(C,U,12)+1
 ..D HOME
 ..D AGE
 Q C
 ;
HOME ;
 S HV=0
 I $$CLINIC^APCLV(V,"C")=11 S $P(C,U,2)=$P(C,U,2)+1,HV=1 S:%=91 $P(C,U,13)=$P(C,U,13)+1 Q
 Q:HOMELOC=""
 I HOMELOC=$P(^AUPNVSIT(V,0),U,6) S $P(C,U,2)=$P(C,U,2)+1,HV=1 S:%=91 $P(C,U,13)=$P(C,U,13)+1 Q
 Q
AGE ;
 S DAYS=$$FMDIFF^XLFDT($P($P(^AUPNVSIT(V,0),U),"."),$P(^DPT(P,0),U,3))
 S YRS=$$AGE^AUPNPAT(P,$P($P(^AUPNVSIT(V,0),U),"."))
 I DAYS<29 S $P(C,U,3)=$P(C,U,3)+1 S:HV=1 $P(C,U,4)=$P(C,U,4)+1 Q
 I DAYS>28,YRS<1 S $P(C,U,5)=$P(C,U,5)+1 S:HV=1 $P(C,U,6)=$P(C,U,6)+1 Q
 I YRS>0,YRS<65 S $P(C,U,7)=$P(C,U,7)+1 S:HV=1 $P(C,U,8)=$P(C,U,8)+1 Q
 I YRS>64 S $P(C,U,9)=$P(C,U,9)+1 S:HV=1 $P(C,U,10)=$P(C,U,10)+1 Q
 W BGPBOMB
 Q
DENT(P,BDATE,EDATE) ;EP
 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 (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)
 .S Z=0 F  S Z=$O(^AUPNVDEN("AD",V,Z)) Q:Z'=+Z!(G)  S B=$P($G(^AUPNVDEN(Z,0)),U) I B S B=$P($G(^AUTTADA(B,0)),U) I B=1320 S G=1_U_$P($P(^AUPNVSIT(V,0),U),".")
 .Q
 I G=0 Q ""
 Q "ADA 1320"_U_$P(G,U,2)
PED(P,BDATE,EDATE) ;EP
 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) Q ""
 S (X,D)=0,%="",T="" F  S X=$O(BGPG(X)) Q:X'=+X!(%]"")  D
 .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,"-")="TO" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-",2)="TO" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-",2)="SHS" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="305.1" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="305.10" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="305.11" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="305.12" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="305.13" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="649.00" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="649.01" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="649.02" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="649.03" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="649.04" S %=T_U_$P(BGPG(X),U) Q
 .I $P(T,"-")="V15.82" S %=T_U_$P(BGPG(X),U) Q
 Q %
PREG(P,BDATE,EDATE,NORXCHR) ;EP
 NEW BGPDX,B,CNT,BGPD,BGPG
 S B=0,CNT=0,BGPD=""  ;if there is one before time frame set this to 1
 S NORXCHR=$G(NORXCHR)
 K BGPG
 S Y="BGPG("
 S X=P_"^ALL DX [BGP GPRA PREGNANCY DIAGNOSES;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 ;now reorder by date of diagnosis and eliminate all chr and rx if necessary
 I '$D(BGPG) G PROB  ;no diagnoses
 S B=0,X=0 F  S X=$O(BGPG(X)) Q:X'=+X  D
 .;get date
 .S D=$P(BGPG(X),U,1)
 .S C=$$CLINIC^APCLV($P(BGPG(X),U,5),"C")
 .I NORXCHR,C=39 Q
 .S C=$$PRIMPROV^APCLV($P(BGPG(X),U,5),"D")
 .I NORXCHR,C=53 Q  ;no chr as primary provider
 .S BGPDX(D)="",CNT=CNT+1 I CNT=2 S BGPD=D
 .I D>$$FMADD^XLFDT(EDATE,-365) S B=1
 .Q
 I CNT>1,B G MA
PROB ;
 I '$G(B) Q ""  ;no pregnancy visit during time period  ;-Lori fix in 09
 S T=$O(^ATXAX("B","BGP GPRA PREGNANCY DIAGNOSES",0))
 S (X,G)=0 F  S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G)  D
 .Q:$P(^AUPNPROB(X,0),U,12)'="A"
 .Q:$P(^AUPNPROB(X,0),U,8)>EDATE
 .Q:$P(^AUPNPROB(X,0),U,8)<BDATE
 .S Y=$P(^AUPNPROB(X,0),U)
 .Q:'$$ICD^ATXCHK(Y,T,9)
 .S G=$P(^AUPNPROB(X,0),U,8)
 .Q
 I G=0,BGPD="" Q 0  ;no dxs and no problem list
 S BGPD=G
MA ;now check for abortion or miscarriage
 ;abortion first
 K BGPG S Y="BGPG(" S X=P_"^LAST DX [BGP MISCARRIAGE/ABORTION DXS;DURING "_$$FMTE^XLFDT(BGPD)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
 I $D(BGPG(1)) Q 0  ;HAD MIS/AB
 S BGPG=$$LASTPRC^BGP9UTL1(P,"BGP ABORTION PROCEDURES",BDATE,EDATE)
 I BGPG Q 0
 S T=$O(^ATXAX("B","BGP MISCARRIAGE/ABORTION 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,12)'="A"
 .Q:$P(^AUPNPROB(X,0),U,8)<BGPD
 .Q:$P(^AUPNPROB(X,0),U,8)>EDATE
 .S Y=$P(^AUPNPROB(X,0),U)
 .Q:'$$ICD^ATXCHK(Y,T,9)
 .S G=1
 .Q
 I G Q 0
 ;now check CPTs for Abortion and Miscarriage
 S T=$O(^ATXAX("B","BGP CPT ABORTION",0))
 S %=$$CPT^BGP9DU(P,BGPD,EDATE,T,3)
 I %]"" Q 0
 S T=$O(^ATXAX("B","BGP CPT MISCARRIAGE",0))
 S %=$$CPT^BGP9DU(P,BGPD,EDATE,T,3)
 I %]"" Q 0
 S T=$O(^ATXAX("B","BGP CPT ABORTION",0))
 S %=$$TRAN^BGP9DU(P,BGPD,EDATE,T,3)
 I %]"" Q 0
 S T=$O(^ATXAX("B","BGP CPT MISCARRIAGE",0))
 S %=$$TRAN^BGP9DU(P,BGPD,EDATE,T,3)
 I %]"" Q 0
 Q 1
DX(P,BDATE,EDATE) ;EP
 K BGPG
 S BGPG(1)=$$LASTDX^BGP9UTL1(P,"BGP GPRA SMOKING DXS",BDATE,EDATE)
 I BGPG(1)]"" Q $P($$ICDDX^ICDCODE($P(BGPG(1),U,4),$P(BGPG(1),U,1)),U,2)_U_$P(BGPG(1),U,3)
 S T=$O(^ATXAX("B","BGP GPRA SMOKING DXS",0))
 S X=0,G="" F  S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G]"")  D
 .Q:$P(^AUPNPROB(X,0),U,12)'="A"
 .Q:$P(^AUPNPROB(X,0),U,3)>EDATE
 .Q:$P(^AUPNPROB(X,0),U,3)<BDATE
 .S Y=$P(^AUPNPROB(X,0),U)
 .Q:'$$ICD^ATXCHK(Y,T,9)
 .S G=$P($$ICDDX^ICDCODE(Y),U,2)_" PL"_U_$P(^AUPNPROB(X,0),U,3)
 .Q
 Q G
TOBACCO(P,BDATE,EDATE) ;EP
 K BGPTOB,BGP
 D TOBACCO1
 I BGPTOB]"" Q BGPTOB
 D TOBACCO0
 I $D(BGPTOB) Q BGPTOB
 Q ""
TOBACCO1 ;check for tobacco documented in health factors
 K BGPTOB S BGPTOB=$$LASTHF(P,"TOBACCO",BDATE,EDATE) K O,D,H
 Q
TOBACCO0 ;lookup in health status
 S (X,Y)=0 F  S X=$O(^AUPNHF("AA",P,X)) Q:X'=+X!(Y)  I $$VAL^XBDIQ1(9999999.64,X,.03)="TOBACCO" S Y=X
 Q:'Y
 S E=$O(^AUPNHF("AA",P,Y,0)) Q:'E
 I (9999999-E)>EDATE Q  ;documented after time frame
 I (9999999-E)<BDATE Q  ;documented before year
 S Y=$P(^AUTTHF(Y,0),U)
 S BGPTOB=Y_"^"_$$DATE^BGP9UTL(9999999-E)_"^"_(9999999-E)
 K Y,E,X
 Q
 ;
LASTHF(P,C,BDATE,EDATE) ;EP - get last factor in category C for patient P
 S C=$O(^AUTTHF("B",C,0)) ;ien of category passed
 I '$G(C) Q ""
 S (H,D)=0 K O
 F  S H=$O(^AUTTHF("AC",C,H))  Q:'+H  D
 .Q:'$D(^AUPNVHF("AA",P,H))
 .S D="" F  S D=$O(^AUPNVHF("AA",P,H,D)) Q:D'=+D  D
 ..Q:(9999999-D)>EDATE  ;after time frame
 ..Q:(9999999-D)<BDATE  ;before time frame
 ..S O(D)=$O(^AUPNVHF("AA",P,H,D,""))
 .Q
 S D=$O(O(0))
 I D="" Q D
 Q $$VAL^XBDIQ1(9000010.23,O(D),.01)_"^"_$$DATE^BGP9UTL(9999999-D)_"^"_(9999999-D)
 ;
LOINC(A,B) ;
 NEW %
 S %=$P($G(^LAB(95.3,A,9999999)),U,2)
 I %]"",$D(^ATXAX(B,21,"B",%)) Q 1
 S %=$P($G(^LAB(95.3,A,0)),U)_"-"_$P($G(^LAB(95.3,A,0)),U,15)
 I $D(^ATXAX(B,21,"B",%)) Q 1
 Q ""
 ;
CPTSM(P,BDATE,EDATE) ;EP - did pat have smoking cpt?
 NEW X
 S X=$$CPT^BGP9DU(P,BDATE,EDATE,$O(^ATXAX("B","BGP SMOKING CPTS",0)),5)
 I X]"" Q $P(X,U,2)_U_$P(X,U,1)
 ;S X=$$CPTI^BGP9DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("1034F"))
 ;I X Q "1034F"_U_$P(X,U,2)
 ;S X=$$CPTI^BGP9DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("1035F"))
 ;I X Q "1035F"_U_$P(X,U,2)
 ;S X=$$CPTI^BGP9DU(P,BDATE,EDATE,+$$CODEN^ICPTCOD("1036F"))
 ;I X Q "1036F"_U_$P(X,U,2)
 Q ""