BGP3D3 ; IHS/CMI/LAB - measure 11 17 Oct 2009 12:40 PM ;
;;13.0;IHS CLINICAL REPORTING;**1**;NOV 20, 2012;Build 7
;
;
I10 ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7)=0
S (BGPSEAL,BGPSEALD)=""
K BGPSEALS,BGPSELDS
D SEAL^BGP3D3A(DFN,BGPBDATE,BGPEDATE) ;this is for the number of sealants only
S BGPN1=$P(BGPSEAL,U)
I BGPAGEB>1,BGPAGEB<16 S BGPN2=BGPN1
I BGPAGEB>1,BGPAGEB<16,BGPN1 S BGPN7=1
I BGPAGEB>15 S BGPN3=BGPN1
I BGPAGEB>18 S BGPN4=BGPN1
I101 ;
;get new sealant definition 2013 gpra dev
S BGPSEALD=""
I 'BGPN1 S BGPSEALD=$$SEALDEV^BGP3D3A(DFN,BGPBDATE,BGPEDATE)
I BGPSEALD S BGPN7=1
I BGPAGEB>2,BGPAGEB<6,BGPN7 S BGPN5=1
I BGPAGEB>5,BGPAGEB<10,BGPN7 S BGPN6=1
I BGPAGEB>9,BGPAGEB<13,BGPN7 S BGPN8=1
I BGPAGEB>12,BGPAGEB<16,BGPN7 S BGPN9=1
I BGPAGEB>1,BGPAGEB<16 S BGPD7=1
;I 'BGPN1,'BGPD7 S BGPSTOP=1 Q
S BGPVALUE="UP|||" ; _+BGPN1_" sealants"
I 'BGPN1,BGPD7 S BGPVALUE=BGPVALUE_$P(BGPSEALD,U,2)
I BGPN1 S BGPVALUE=BGPVALUE_"; "_+BGPN1_" sealants" S X=0 F S X=$O(BGPSEALS(X)) Q:X'=+X S D=0 F S D=$O(BGPSEALS(X,D)) Q:D'=+D S BGPVALUE=BGPVALUE_$S(X=1:"",1:"; ")_$$DATE^BGP3UTL(D)_" "_BGPSEALS(X,D)
K BGPSEAL,BGPSEALD
Q
I11 ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPD1,BGPD2)=0
NEW BGPFLUOR
I '$G(BGPACTUP) S BGPSTOP=1 Q
I BGPACTUP S BGPD1=1
S BGPFLUOR=$$TF^BGP3D3A(DFN,BGPBDATE,BGPEDATE)
;I $P(BGPFLUOR,U,3)["Refused" S BGPN2=1 G I111
S BGPN1=$P(BGPFLUOR,U)
I BGPN1>4 S BGPN1=4
I BGPAGEB>0,BGPAGEB<16 S BGPD2=1,BGPN3=$S(BGPN1:1,1:0)
;I BGPD1,'BGPD2 S BGPD3=1
I111 ;
S BGPVALUE="UP|||"_+BGPN1_" topical fluoride"
I +BGPN1 S BGPVALUE=BGPVALUE_": " F X=2:1:5 I $P(BGPFLUOR,U,X)]"" S BGPVALUE=BGPVALUE_$S(X>2:", ",1:"")_$$DATE^BGP3UTL($P($P(BGPFLUOR,U,X),"|",1))_" "_$P($P(BGPFLUOR,U,X),"|",2)
;I BGPN2 S BGPVALUE=BGPVALUE_": "_$$DATE^BGP3UTL($P(BGPFLUOR,U,2))_" "_$P(BGPFLUOR,U,3)
S BGPVALUD="UP|||"
I +BGPN1 S BGPVALUD=BGPVALUD_+BGPN1_" topical fluoride" I +BGPN1 S BGPVALUD=BGPVALUD_": " F X=2:1:5 I $P(BGPFLUOR,U,X)]"" S BGPVALUD=BGPVALUD_$S(X>2:", ",1:"")_$$DATE^BGP3UTL($P($P(BGPFLUOR,U,X),"|",1))_" "_$P($P(BGPFLUOR,U,X),"|",2)
;I BGPN2 S BGPVALUD=BGPVALUD_": "_$$DATE^BGP3UTL($P(BGPFLUOR,U,2))_" "_$P(BGPFLUOR,U,3)
K ^TMP($J,"A"),BGPFLUOR
Q
I12 ;EP
NEW BGPHR,V
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9,BGPD10,BGPD11,BGPD12,BGPD13,BGPD14,BGPD15,BGPHR)=0
S BGPHR=$$HIGHR^BGP3D3A(DFN,BGPEDATE)
I BGPAGEB>49,BGPACTUP S BGPD5=1
I BGPAGEB>49,BGPAGEB<65,BGPACTUP S BGPD6=1
I BGPAGEB>64,BGPACTUP S BGPD7=1
I BGPDMD2 S BGPD4=1
I BGPAGEB>49,BGPACTCL S BGPD1=1
I BGPAGEB>49,BGPAGEB<65,BGPACTCL S BGPD2=1
I BGPAGEB>64,BGPACTCL S BGPD3=1
I BGPACTCL S BGPD8=1
I BGPAGEB<18,BGPACTCL S BGPD9=1
I BGPAGEB>17,BGPAGEB<50,BGPACTCL S BGPD10=1
I BGPAGEB>17,BGPAGEB<50,BGPACTCL,BGPHR S BGPD11=1
I BGPACTUP S BGPD12=1
I BGPAGEB<18,BGPACTUP S BGPD13=1
I BGPAGEB>17,BGPAGEB<50,BGPACTUP S BGPD14=1
I BGPAGEB>17,BGPAGEB<50,BGPACTUP,BGPHR S BGPD15=1
I '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5+BGPD6+BGPD7+BGPD8+BGPD9+BGPD10+BGPD11+BGPD12+BGPD13+BGPD14+BGPD15) S BGPSTOP=1 Q
S BGPVALUE=$$FLU(DFN,,BGPEDATE) ;set to date of flu shot
I $P(BGPVALUE,U,3)=1 S BGPN1=1
;I $P(BGPVALUE,U,3)=2 S BGPN2=1
I $P(BGPVALUE,U,3)=3 S BGPN3=1,BGPN1=1
I BGPN1 S BGPN7=1
S BGPDV=""
I BGPRTYPE=4 S BGPDV=$S(BGPACTUP:"UP",1:"") D
.I BGPACTCL S BGPDV=BGPDV_$S(BGPDV]"":",AC",1:"AC")
.I BGPD4 S BGPDV=BGPDV_$S(BGPDV]"":",AD",1:"AD")
.I BGPHR S BGPDV=BGPDV_$S(BGPDV]"":",HR",1:"HR")
I BGPRTYPE=1 S BGPDV=$S(BGPD3!(BGPD2):"AC",1:"") I BGPD4 S BGPDV=BGPDV_$S(BGPDV]"":",AD",1:"AD")
I BGPRTYPE=3!(BGPRTYPE=8) S BGPDV="AC"
I BGPRTYPE=7 D
.I BGPACTCL S BGPDV="AC"
.I BGPD4 S BGPDV=BGPDV_$S(BGPDV]"":",AD",1:"AD")
.I BGPHR S BGPDV=BGPDV_$S(BGPDV]"":",HR",1:"HR")
I BGPRTYPE'=1 S BGPVALUE=BGPDV_"|||"_$$DATE^BGP3UTL($P(BGPVALUE,U,1))_" "_$P(BGPVALUE,U,2)
I BGPRTYPE=1 D
.S BGPDV=BGPDV_"|||"
.I BGPN7 S BGPVALUE=BGPDV_$$DATE^BGP3UTL($P(BGPVALUE,U,1))_" "_$P(BGPVALUE,U,2) Q
.S BGPVALUE=BGPDV
K BGPLFLU,BGPDV,BGPHR
Q
I13 ;EP
NEW BGPTDAP,BGPTD
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
I BGPAGEB>64,BGPACTUP S BGPD3=1
I BGPDMD2 S BGPD2=1
I BGPAGEB>64,BGPACTCL S BGPD1=1
I BGPAGEB>17,BGPAGEB<65,BGPACTCL,$$HIGHRP^BGP3D3A(DFN,BGPEDATE) S BGPD4=1
I BGPAGEB>17,BGPAGEB<65,BGPACTUP,$$HIGHRP^BGP3D3A(DFN,BGPEDATE) S BGPD5=1
I BGPAGEB>17,BGPAGEB<65,BGPACTCL S BGPD6=1
I BGPAGEB>17,BGPAGEB<65,BGPACTUP S BGPD7=1
I BGPAGEB>17,BGPACTCL S BGPD8=1
I BGPAGEB>17,BGPACTUP S BGPD9=1
I '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5+BGPD6+BGPD7+BGPD8+BGPD9) S BGPSTOP=1 Q
I BGPRTYPE=3,'BGPD1 S BGPSTOP=1 Q
PN ;EP - called from elder
S BGPVALUE=$$PNEU^BGP3D31(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE) ;set to date of PNEU shot
;I BGPVALUE]"" S BGPN1=1
I $P(BGPVALUE,U,3)=1!($P(BGPVALUE,U,3)=3) S BGPN1=1
;I $P(BGPVALUE,U,3)=2 S BGPN2=1 ;REF
I $P(BGPVALUE,U,3)=3 S BGPN3=1 ;NMI
S BGPVAL=$$PNEU^BGP3D31(DFN,$$FMADD^XLFDT(BGPEDATE,-(5*365)),BGPEDATE)
I $P(BGPVAL,U,3)=1!($P(BGPVAL,U,3)=3) S BGPN4=1 ;HAD IN PAST 5 YEARS SO "UP TO DATE"
;I $P(BGPVAL,U,3)=2 S BGPN5=1
I $P(BGPVAL,U,3)=3 S BGPN6=1
S BGPN7=0,BGPA65="" I BGPAGEB>65 S BGPA65=$$PNEU^BGP3D31(DFN,$$FMADD^XLFDT($$DOB^AUPNPAT(DFN),+(65*365)),BGPEDATE) I $P(BGPA65,U,3)=1!($P(BGPA65,U,3)=3) S BGPN4=1,BGPN7=1 ;over 65 and had one after 65
I BGPAGEB<65,BGPN1 S BGPN4=1 ;anyone under and had 1 ever
;GPRA DEVELOPMENTAL
S BGPN8=0
I BGPAGEB<66,BGPN1 S BGPN8=1
I BGPAGEB>65,BGPN1,(BGPN4+BGPN7) S BGPN8=1 ;IF UNDER 66 HAD 1 EVER, IF OVER 65 HAD ONE IN PAST 5 YEARS OR AFTER AGE 65
S BGPDV=""
I BGPRTYPE=1 S BGPDV="" D
.I BGPD1 S BGPDV=BGPDV_$S(BGPDV]"":",AC",1:"AC")
.I BGPD2 S BGPDV=BGPDV_$S(BGPDV]"":",AD",1:"AD")
.I BGPN1 S BGPVALH=BGPVALUE,BGPVALUE=BGPDV_"|||" I BGPVALH]"" S BGPVALUE=BGPVALUE_"Pneumo: "_$$DATE^BGP3UTL($P(BGPVALH,U,1))_" "_$P(BGPVALH,U,2)_$S(BGPVALH]""&($P(BGPVALH,U,2)'["Ref"):" (ever)",1:"") Q
.S BGPVALUE=BGPDV_"|||"
I BGPRTYPE=4 D
.S BGPDV="UP"
.I BGPD6!(BGPD1)!(BGPD8) S BGPDV=BGPDV_$S(BGPDV]"":",AC",1:"AC")
.I BGPD4!(BGPD5) S BGPDV=BGPDV_$S(BGPDV]"":",HR",1:"HR")
.;I BGPD3 S BGPDV=BGPDV_$S(BGPDV]"":",UP >64",1:"UP >64")
.;I BGPD7 S BGPDV=BGPDV_$S(BGPDV]"":",UP 18-64",1:"UP 18-64")
.;I BGPD5 S BGPDV=BGPDV_$S(BGPDV]"":",UP 18-64HR",1:"UP 18-64HR")
.I BGPD2 S BGPDV=BGPDV_$S(BGPDV]"":",AD",1:"AD")
I BGPRTYPE=7 S BGPDV=$S(BGPD6:"AC",1:"") S:BGPD4 BGPDV=BGPDV_$S(BGPDV]"":",HR",1:"HR") S:BGPD2 BGPDV=BGPDV_$S(BGPDV]"":",AD",1:"AD")
I BGPRTYPE=3!(BGPRTYPE=5) S BGPVALUE="AC"_"|||"_$$DATE^BGP3UTL($P(BGPVALUE,U,1))_" "_$P(BGPVALUE,U,2) I 1
E D
.I BGPRTYPE'=1 S BGPVALH=BGPVALUE,BGPVALUE=BGPDV_"|||" I BGPVALH]"" S BGPVALUE=BGPVALUE_"Pneumo: "_$$DATE^BGP3UTL($P(BGPVALH,U,1))_" "_$P(BGPVALH,U,2)_$S(BGPVALH]""&($P(BGPVALH,U,2)'["Ref"):" (ever)",1:"")_" "_$S(BGPN8:" (up-to-date)",1:"")
.S BGPVALUD="AC"_"|||"
.I BGPN4 S BGPVALUD=BGPVALUD_"Pneumo: "_$$DATE^BGP3UTL($P(BGPVALH,U,1))_" "_$P(BGPVALH,U,2)_$S(BGPVALH]""&($P(BGPVALH,U,2)'["Ref"):" (ever)",1:"")_" "
.S BGPVALUD=BGPVALUD_$S(BGPN8:"(up-to-date)",1:"")
TD ;new tdap and td stuff for v11.1
S BGPTDAP=$$DTAP^BGP3D3A(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
I BGPTDAP S BGPN9=1
S BGPTD=$$DTAPTD^BGP3D3A(DFN,$$FMADD^XLFDT(BGPEDATE,-(10*365)),BGPEDATE)
I BGPTD S BGPN10=1
I BGPRTYPE=1 G TDE
I BGPTDAP S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:""),BGPVALUE=BGPVALUE_"TDAP: "_$P(BGPTDAP,U,2)_" (ever)"
;I BGPTDAP,'BGPTD S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:""),BGPVALUE=BGPVALUE_"TDAP: "_$P(BGPTDAP,U,2)_" (ever)"
I BGPTD S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:""),BGPVALUE=BGPVALUE_"TDAP/TD: "_$P(BGPTD,U,2)_" (past 10 yrs)"
;I BGPTD S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:"") S BGPVALUE=BGPVALUE_"TDAP/TD PAST 10 YRS: "_$P(BGPTD,U,2)
TDE K BGPLPNU,BGPVAL,BGPA65,BGPVALH
Q
I15 ;EP
K BGPN1,BGPN2,BGPN3,BGPN4,BGPVALUE,BGPPAP,BGPI7,BGPI7DA,BGPI7DB,BGPI7DC,BGPI7DD,BGPPAP4,BGPPAP6
S BGPI7DA=0,BGPI7DB=0,BGPI7DC=0,BGPI7DD=0,BGPN1=0,BGPN2=0,BGPN3=0,BGPPAP4="",BGPN4=0,BGPPAP6="",BGPHPV=""
S (BGPD1,BGPD2,BGPD3,BGPD4,BGPN5,BGPN6)=0
S BGPI7=$$DEN7(DFN,BGPAGEB,BGPAGEE,BGPSEX,BGPEDATE)
I BGPACTUP,BGPI7 S BGPI7DA=1
I BGPACTCL,BGPI7 S BGPI7DB=1
I BGPACTCL,BGPI7,BGPAGEB>24,BGPAGEE<65 S BGPI7DC=1,BGPD4=1 ;2013 GPRA DEV
I BGPACTUP,BGPI7,BGPAGEB>24,BGPAGEE<65 S BGPI7DD=1
I BGPACTCL,BGPI7,BGPAGEB>29,BGPAGEE<65 S BGPD1=1
I BGPACTCL,BGPI7,BGPAGEB>24,BGPAGEB<30 S BGPD2=1
I 'BGPI7DC,'BGPI7DD S BGPSTOP=1 Q ;not in either denom so quit
;I BGPTIME=1,BGPD4,'(BGPD1+BGPD2) W !,DFN,?10,"BGPD4=",BGPD4,?20,"BGPD2=",BGPD2,?30,"BGPD1=",BGPD1,?40,"AGEB: ",BGPAGEB,?50,"AGEE: ",BGPAGEE
S BGPPAP=$$PAP(DFN,BGPEDATE,3,1)
S BGPPAP4=$$PAP(DFN,BGPEDATE,4,1)
S BGPN1=0 I $P(BGPPAP,U)=1 S BGPN1=1
I $P(BGPPAP,U,3)["Ref" S BGPN2=1
I BGPN1,'BGPN2 S BGPN3=1
S BGPN4=0 I $P(BGPPAP4,U,1)=1 S BGPN4=1 ;PAP IN 4 YRS, NO REFUSALS
;for gpra dev, if they didn't have pap in 4 years check HPV
I 'BGPN4,BGPD1 D
.S BGPPAP6=$$PAP(DFN,BGPEDATE,6)
.S BGPHPV=$$HPV(DFN,BGPEDATE,6)
.I BGPHPV,BGPPAP6 S BGPN5=1
I BGPN4!(BGPN5) S BGPN6=1
;I BGPTIME=1 W ?40,"BGPN4=",BGPN4,?50,"BGPN5=",?60,"BGPN6=",BGPN6
S BGPVALUE=$S(BGPI7DD:"UP",1:"")_$S(BGPI7DC:",AC",1:"")_"|||"_$$DATE^BGP3UTL($P(BGPPAP4,U,2))_" "_$P(BGPPAP4,U,3)
;I BGPRTYPE=1 S BGPVALUE=$S(BGPI7DA:"UP",1:"")_$S(BGPI7DB:",AC",1:"")_"|||" I BGPN3 S BGPVALUE=BGPVALUE_$$DATE^BGP3UTL($P(BGPPAP,U,2))_" "_$P(BGPPAP,U,3)
;I BGPRTYPE=3 S BGPVALUE="AC|||"_$$DATE^BGP3UTL($P(BGPPAP,U,2))_" "_$P(BGPPAP,U,3)
S BGPVALUD="AC|||" I BGPN4 S BGPVALUD=BGPVALUD_$$DATE^BGP3UTL($P(BGPPAP4,U,2))_" "_$P(BGPPAP4,U,3)
I BGPN6,'BGPN4 S BGPVALUD=BGPVALUD_"HPV: "_$$DATE^BGP3UTL($P(BGPHPV,U,2))_" PAP: "_$$DATE^BGP3UTL($P(BGPPAP6,U,2))
K BGPLPAP,BGPPAP,BGPHPV,BGPPAP4,BGPPAP6
Q
;
HPV(P,EDATE,YEARS) ;
NEW BGPC,BGPLPAP,T,BGPLT,B,D,E,L,X,J,BGP
S BGPC=""
S BGPLPAP=""
S BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
S T=$O(^ATXAX("B","BGP HPV LOINC CODES",0))
S BGPLT=$O(^ATXLAB("B","BGP HPV TESTS TAX",0))
S B=9999999-BDATE,E=9999999-EDATE S D=E-1 F S D=$O(^AUPNVLAB("AE",P,D)) Q:D'=+D!(D>B)!(BGPC]"") D
.S L=0 F S L=$O(^AUPNVLAB("AE",P,D,L)) Q:L'=+L!(BGPC]"") D
..S X=0 F S X=$O(^AUPNVLAB("AE",P,D,L,X)) Q:X'=+X!(BGPC]"") D
...Q:'$D(^AUPNVLAB(X,0))
...S Z=$P(^AUPNVLAB(X,0),U),Z=$P($G(^LAB(60,Z,0)),U) I Z="HPV" S BGPC="1^"_(9999999-D)_"^Lab" Q
...I BGPLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(BGPLT,21,"B",$P(^AUPNVLAB(X,0),U))) S BGPC="1^"_(9999999-D)_"^Lab" Q
...Q:'T
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,T)
...S BGPC="1^"_(9999999-D)_"^Lab-loinc" Q
...Q
S BGPLPAP=BGPC
K BGP
S T="BGP HPV DXS"
S X=$$LASTDX^BGP3UTL1(P,T,BDATE,EDATE) I X,$P(BGPLPAP,U,2)<$P(X,U,3) S BGPLPAP="1^"_$P(X,U,3)_"^POV "_$P(X,U,2)
S T=$O(^ATXAX("B","BGP HPV CPTS",0))
I T D I X]"",$P(BGPLPAP,U,2)<$P(X,U,1) S BGPLPAP="1^"_$P(X,U)_"^CPT "_$P(X,U,2)
.S X=$$CPT^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5)
Q BGPLPAP
;
FLU(P,BD,ED,FORE) ;EP
G FLU^BGP3D37
BI() ;
Q $S($O(^AUTTIMM(0))>100:1,1:0)
DEN7(P,AGEB,AGEE,SEX,EDATE) ;EP
I SEX'="F" Q 0
I AGEB<25 Q 0
I AGEE>64 Q 0
I $$HYSTER(P,EDATE) Q 0
Q 1
H1(I) ;
I $P($G(^ICPT(I,0)),U,1)=90664 Q 1
I $P($G(^ICPT(I,0)),U,1)=90666 Q 1
I $P($G(^ICPT(I,0)),U,1)=90667 Q 1
I $P($G(^ICPT(I,0)),U,1)=90668 Q 1
Q ""
PAP(P,EDATE,YEARS,REFUSAL) ;EP
NEW BGPC,BGPLPAP,T,BGPLT,B,D,E,L,X,J,BGP
S BGPC=""
S BGPLPAP=""
S BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
S T=$O(^ATXAX("B","BGP PAP LOINC CODES",0))
S BGPLT=$O(^ATXLAB("B","BGP PAP SMEAR TAX",0))
S B=9999999-BDATE,E=9999999-EDATE S D=E-1 F S D=$O(^AUPNVLAB("AE",P,D)) Q:D'=+D!(D>B)!(BGPC]"") D
.S L=0 F S L=$O(^AUPNVLAB("AE",P,D,L)) Q:L'=+L!(BGPC]"") D
..S X=0 F S X=$O(^AUPNVLAB("AE",P,D,L,X)) Q:X'=+X!(BGPC]"") D
...Q:'$D(^AUPNVLAB(X,0))
...S Z=$P(^AUPNVLAB(X,0),U),Z=$P($G(^LAB(60,Z,0)),U) I Z="PAP SMEAR" S BGPC="1^"_(9999999-D)_"^Lab" Q
...I BGPLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(BGPLT,21,"B",$P(^AUPNVLAB(X,0),U))) S BGPC="1^"_(9999999-D)_"^Lab" Q
...Q:'T
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,T)
...S BGPC="1^"_(9999999-D)_"^Lab-loinc" Q
...Q
S BGPLPAP=BGPC
K BGP
S T="BGP PAP SMEAR DXS"
I BGPRTYPE=3 S T="BGP HEDIS PAP SMEAR DXS"
S X=$$LASTDX^BGP3UTL1(P,T,BDATE,EDATE) I X,$P(BGPLPAP,U,2)<$P(X,U,3) S BGPLPAP="1^"_$P(X,U,3)_"^POV "_$P(X,U,2)
K BGP S BGP(1)=$$LASTPRC^BGP3UTL1(P,"BGP PAP PROCEDURES",BDATE,EDATE)
I $D(BGP(1)),$P(BGPLPAP,U,2)<$P(BGP(1),U,3) S BGPLPAP="1^"_$P(BGP(1),U,3)_"^PROC "_$P(BGP(1),U,2)
S T=$O(^ATXAX("B","BGP CPT PAP",0))
I T D I X]"",$P(BGPLPAP,U,2)<$P(X,U,1) S BGPLPAP="1^"_$P(X,U)_"^CPT "_$P(X,U,2)
.S X=$$CPT^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5)
S T="PAP SMEAR",T=$O(^BWPN("B",T,0))
I T D I X]"",$P(BGPLPAP,U,2)<X S BGPLPAP="1^"_X_"^WH"
.S X=$$WH^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,3)
I BGPLPAP]"" Q BGPLPAP
I $G(REFUSAL) Q "" ;no Refusals counted
S T=$$REFUSAL^BGP3UTL1(P,60,$O(^LAB(60,"B","PAP SMEAR",0)),$$FMADD^XLFDT(EDATE,-365),EDATE)
I T Q "1^"_$P(T,U,2)_"^Refused Lab"
S BGPLT=$O(^ATXLAB("B","BGP PAP SMEAR TAX",0))
I 'BGPLT Q 0
S X=0,T="" F S X=$O(^ATXLAB(BGPLT,21,X)) Q:X'=+X!($P(T,U)=1) D
.S T=""
.S Y=$P(^ATXLAB(BGPLT,21,X,0),U)
.Q:'Y
.S T=$$REFUSAL^BGP3UTL1(P,60,Y,$$FMADD^XLFDT(EDATE,-365),EDATE)
I T Q 1_"^"_$P(T,U,2)_"^Refused Lab "
;add cpt Refusals v11.1
S T=$$CPTREFT^BGP3UTL1(P,$$FMADD^XLFDT(EDATE,-365),EDATE,$O(^ATXAX("B","BGP CPT PAP",0)))
I T S T="1^"_$P(T,U,2)_"^Refused CPT "_$P(T,U,4) Q T
Q ""
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 ""
HYSTER(P,EDATE) ;EP
I '$G(P) Q ""
NEW X,T
S X=$$LASTPRC^BGP3UTL1(P,"BGP HYSTERECTOMY PROCEDURES",$$DOB^AUPNPAT(P),EDATE)
I X Q 1
S T="HYSTERECTOMY",T=$O(^BWPN("B",T,0))
I T D I X]"" Q 1
.S X=$$WH^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,2)
S T=$O(^ATXAX("B","BGP HYSTERECTOMY CPTS",0))
I T D I X]"" Q 1
.S X=$$CPT^BGP3DU(P,$P(^DPT(P,0),U,3),EDATE,T,3) I X]"" Q
.S X=$$TRAN^BGP3DU(P,$P(^DPT(P,0),U,3),EDATE,T,3)
S X=$$LASTDX^BGP3UTL1(P,"BGP HYSTERECTOMY DXS",$$DOB^AUPNPAT(P),EDATE)
I X Q 1
S X=$$PLTAX^BGP3DU(P,"BGP HYSTERECTOMY DXS")
I X Q 1
Q ""
BGP3D3 ; IHS/CMI/LAB - measure 11 17 Oct 2009 12:40 PM ;
+1 ;;13.0;IHS CLINICAL REPORTING;**1**;NOV 20, 2012;Build 7
+2 ;
+3 ;
I10 ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7)=0
+2 SET (BGPSEAL,BGPSEALD)=""
+3 KILL BGPSEALS,BGPSELDS
+4 ;this is for the number of sealants only
DO SEAL^BGP3D3A(DFN,BGPBDATE,BGPEDATE)
+5 SET BGPN1=$PIECE(BGPSEAL,U)
+6 IF BGPAGEB>1
IF BGPAGEB<16
SET BGPN2=BGPN1
+7 IF BGPAGEB>1
IF BGPAGEB<16
IF BGPN1
SET BGPN7=1
+8 IF BGPAGEB>15
SET BGPN3=BGPN1
+9 IF BGPAGEB>18
SET BGPN4=BGPN1
I101 ;
+1 ;get new sealant definition 2013 gpra dev
+2 SET BGPSEALD=""
+3 IF 'BGPN1
SET BGPSEALD=$$SEALDEV^BGP3D3A(DFN,BGPBDATE,BGPEDATE)
+4 IF BGPSEALD
SET BGPN7=1
+5 IF BGPAGEB>2
IF BGPAGEB<6
IF BGPN7
SET BGPN5=1
+6 IF BGPAGEB>5
IF BGPAGEB<10
IF BGPN7
SET BGPN6=1
+7 IF BGPAGEB>9
IF BGPAGEB<13
IF BGPN7
SET BGPN8=1
+8 IF BGPAGEB>12
IF BGPAGEB<16
IF BGPN7
SET BGPN9=1
+9 IF BGPAGEB>1
IF BGPAGEB<16
SET BGPD7=1
+10 ;I 'BGPN1,'BGPD7 S BGPSTOP=1 Q
+11 ; _+BGPN1_" sealants"
SET BGPVALUE="UP|||"
+12 IF 'BGPN1
IF BGPD7
SET BGPVALUE=BGPVALUE_$PIECE(BGPSEALD,U,2)
+13 IF BGPN1
SET BGPVALUE=BGPVALUE_"; "_+BGPN1_" sealants"
SET X=0
FOR
SET X=$ORDER(BGPSEALS(X))
IF X'=+X
QUIT
SET D=0
FOR
SET D=$ORDER(BGPSEALS(X,D))
IF D'=+D
QUIT
SET BGPVALUE=BGPVALUE_$SELECT(X=1:"",1:"; ")_$$DATE^BGP3UTL(D)_" "_BGPSEALS(X,D)
+14 KILL BGPSEAL,BGPSEALD
+15 QUIT
I11 ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPD1,BGPD2)=0
+2 NEW BGPFLUOR
+3 IF '$GET(BGPACTUP)
SET BGPSTOP=1
QUIT
+4 IF BGPACTUP
SET BGPD1=1
+5 SET BGPFLUOR=$$TF^BGP3D3A(DFN,BGPBDATE,BGPEDATE)
+6 ;I $P(BGPFLUOR,U,3)["Refused" S BGPN2=1 G I111
+7 SET BGPN1=$PIECE(BGPFLUOR,U)
+8 IF BGPN1>4
SET BGPN1=4
+9 IF BGPAGEB>0
IF BGPAGEB<16
SET BGPD2=1
SET BGPN3=$SELECT(BGPN1:1,1:0)
+10 ;I BGPD1,'BGPD2 S BGPD3=1
I111 ;
+1 SET BGPVALUE="UP|||"_+BGPN1_" topical fluoride"
+2 IF +BGPN1
SET BGPVALUE=BGPVALUE_": "
FOR X=2:1:5
IF $PIECE(BGPFLUOR,U,X)]""
SET BGPVALUE=BGPVALUE_$SELECT(X>2:", ",1:"")_$$DATE^BGP3UTL($PIECE($PIECE(BGPFLUOR,U,X),"|",1))_" "_$PIECE($PIECE(BGPFLUOR,U,X),"|",2)
+3 ;I BGPN2 S BGPVALUE=BGPVALUE_": "_$$DATE^BGP3UTL($P(BGPFLUOR,U,2))_" "_$P(BGPFLUOR,U,3)
+4 SET BGPVALUD="UP|||"
+5 IF +BGPN1
SET BGPVALUD=BGPVALUD_+BGPN1_" topical fluoride"
IF +BGPN1
SET BGPVALUD=BGPVALUD_": "
FOR X=2:1:5
IF $PIECE(BGPFLUOR,U,X)]""
SET BGPVALUD=BGPVALUD_$SELECT(X>2:", ",1:"")_$$DATE^BGP3UTL($PIECE($PIECE(BGPFLUOR,U,X),"|",1))_" "_$PIECE($PIECE(BGPFLUOR,U,X),"|",2)
+6 ;I BGPN2 S BGPVALUD=BGPVALUD_": "_$$DATE^BGP3UTL($P(BGPFLUOR,U,2))_" "_$P(BGPFLUOR,U,3)
+7 KILL ^TMP($JOB,"A"),BGPFLUOR
+8 QUIT
I12 ;EP
+1 NEW BGPHR,V
+2 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9,BGPD10,BGPD11,BGPD12,BGPD13,BGPD14,BGPD15,BGPHR)=0
+3 SET BGPHR=$$HIGHR^BGP3D3A(DFN,BGPEDATE)
+4 IF BGPAGEB>49
IF BGPACTUP
SET BGPD5=1
+5 IF BGPAGEB>49
IF BGPAGEB<65
IF BGPACTUP
SET BGPD6=1
+6 IF BGPAGEB>64
IF BGPACTUP
SET BGPD7=1
+7 IF BGPDMD2
SET BGPD4=1
+8 IF BGPAGEB>49
IF BGPACTCL
SET BGPD1=1
+9 IF BGPAGEB>49
IF BGPAGEB<65
IF BGPACTCL
SET BGPD2=1
+10 IF BGPAGEB>64
IF BGPACTCL
SET BGPD3=1
+11 IF BGPACTCL
SET BGPD8=1
+12 IF BGPAGEB<18
IF BGPACTCL
SET BGPD9=1
+13 IF BGPAGEB>17
IF BGPAGEB<50
IF BGPACTCL
SET BGPD10=1
+14 IF BGPAGEB>17
IF BGPAGEB<50
IF BGPACTCL
IF BGPHR
SET BGPD11=1
+15 IF BGPACTUP
SET BGPD12=1
+16 IF BGPAGEB<18
IF BGPACTUP
SET BGPD13=1
+17 IF BGPAGEB>17
IF BGPAGEB<50
IF BGPACTUP
SET BGPD14=1
+18 IF BGPAGEB>17
IF BGPAGEB<50
IF BGPACTUP
IF BGPHR
SET BGPD15=1
+19 IF '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5+BGPD6+BGPD7+BGPD8+BGPD9+BGPD10+BGPD11+BGPD12+BGPD13+BGPD14+BGPD15)
SET BGPSTOP=1
QUIT
+20 ;set to date of flu shot
SET BGPVALUE=$$FLU(DFN,,BGPEDATE)
+21 IF $PIECE(BGPVALUE,U,3)=1
SET BGPN1=1
+22 ;I $P(BGPVALUE,U,3)=2 S BGPN2=1
+23 IF $PIECE(BGPVALUE,U,3)=3
SET BGPN3=1
SET BGPN1=1
+24 IF BGPN1
SET BGPN7=1
+25 SET BGPDV=""
+26 IF BGPRTYPE=4
SET BGPDV=$SELECT(BGPACTUP:"UP",1:"")
Begin DoDot:1
+27 IF BGPACTCL
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AC",1:"AC")
+28 IF BGPD4
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AD",1:"AD")
+29 IF BGPHR
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",HR",1:"HR")
End DoDot:1
+30 IF BGPRTYPE=1
SET BGPDV=$SELECT(BGPD3!(BGPD2):"AC",1:"")
IF BGPD4
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AD",1:"AD")
+31 IF BGPRTYPE=3!(BGPRTYPE=8)
SET BGPDV="AC"
+32 IF BGPRTYPE=7
Begin DoDot:1
+33 IF BGPACTCL
SET BGPDV="AC"
+34 IF BGPD4
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AD",1:"AD")
+35 IF BGPHR
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",HR",1:"HR")
End DoDot:1
+36 IF BGPRTYPE'=1
SET BGPVALUE=BGPDV_"|||"_$$DATE^BGP3UTL($PIECE(BGPVALUE,U,1))_" "_$PIECE(BGPVALUE,U,2)
+37 IF BGPRTYPE=1
Begin DoDot:1
+38 SET BGPDV=BGPDV_"|||"
+39 IF BGPN7
SET BGPVALUE=BGPDV_$$DATE^BGP3UTL($PIECE(BGPVALUE,U,1))_" "_$PIECE(BGPVALUE,U,2)
QUIT
+40 SET BGPVALUE=BGPDV
End DoDot:1
+41 KILL BGPLFLU,BGPDV,BGPHR
+42 QUIT
I13 ;EP
+1 NEW BGPTDAP,BGPTD
+2 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPN8,BGPN9,BGPN10,BGPN11,BGPN12,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+3 IF BGPAGEB>64
IF BGPACTUP
SET BGPD3=1
+4 IF BGPDMD2
SET BGPD2=1
+5 IF BGPAGEB>64
IF BGPACTCL
SET BGPD1=1
+6 IF BGPAGEB>17
IF BGPAGEB<65
IF BGPACTCL
IF $$HIGHRP^BGP3D3A(DFN,BGPEDATE)
SET BGPD4=1
+7 IF BGPAGEB>17
IF BGPAGEB<65
IF BGPACTUP
IF $$HIGHRP^BGP3D3A(DFN,BGPEDATE)
SET BGPD5=1
+8 IF BGPAGEB>17
IF BGPAGEB<65
IF BGPACTCL
SET BGPD6=1
+9 IF BGPAGEB>17
IF BGPAGEB<65
IF BGPACTUP
SET BGPD7=1
+10 IF BGPAGEB>17
IF BGPACTCL
SET BGPD8=1
+11 IF BGPAGEB>17
IF BGPACTUP
SET BGPD9=1
+12 IF '(BGPD1+BGPD2+BGPD3+BGPD4+BGPD5+BGPD6+BGPD7+BGPD8+BGPD9)
SET BGPSTOP=1
QUIT
+13 IF BGPRTYPE=3
IF 'BGPD1
SET BGPSTOP=1
QUIT
PN ;EP - called from elder
+1 ;set to date of PNEU shot
SET BGPVALUE=$$PNEU^BGP3D31(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
+2 ;I BGPVALUE]"" S BGPN1=1
+3 IF $PIECE(BGPVALUE,U,3)=1!($PIECE(BGPVALUE,U,3)=3)
SET BGPN1=1
+4 ;I $P(BGPVALUE,U,3)=2 S BGPN2=1 ;REF
+5 ;NMI
IF $PIECE(BGPVALUE,U,3)=3
SET BGPN3=1
+6 SET BGPVAL=$$PNEU^BGP3D31(DFN,$$FMADD^XLFDT(BGPEDATE,-(5*365)),BGPEDATE)
+7 ;HAD IN PAST 5 YEARS SO "UP TO DATE"
IF $PIECE(BGPVAL,U,3)=1!($PIECE(BGPVAL,U,3)=3)
SET BGPN4=1
+8 ;I $P(BGPVAL,U,3)=2 S BGPN5=1
+9 IF $PIECE(BGPVAL,U,3)=3
SET BGPN6=1
+10 ;over 65 and had one after 65
SET BGPN7=0
SET BGPA65=""
IF BGPAGEB>65
SET BGPA65=$$PNEU^BGP3D31(DFN,$$FMADD^XLFDT($$DOB^AUPNPAT(DFN),+(65*365)),BGPEDATE)
IF $PIECE(BGPA65,U,3)=1!($PIECE(BGPA65,U,3)=3)
SET BGPN4=1
SET BGPN7=1
+11 ;anyone under and had 1 ever
IF BGPAGEB<65
IF BGPN1
SET BGPN4=1
+12 ;GPRA DEVELOPMENTAL
+13 SET BGPN8=0
+14 IF BGPAGEB<66
IF BGPN1
SET BGPN8=1
+15 ;IF UNDER 66 HAD 1 EVER, IF OVER 65 HAD ONE IN PAST 5 YEARS OR AFTER AGE 65
IF BGPAGEB>65
IF BGPN1
IF (BGPN4+BGPN7)
SET BGPN8=1
+16 SET BGPDV=""
+17 IF BGPRTYPE=1
SET BGPDV=""
Begin DoDot:1
+18 IF BGPD1
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AC",1:"AC")
+19 IF BGPD2
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AD",1:"AD")
+20 IF BGPN1
SET BGPVALH=BGPVALUE
SET BGPVALUE=BGPDV_"|||"
IF BGPVALH]""
SET BGPVALUE=BGPVALUE_"Pneumo: "_$$DATE^BGP3UTL($PIECE(BGPVALH,U,1))_" "_$PIECE(BGPVALH,U,2)_$SELECT(BGPVALH]""&($PIECE(BGPVALH,U,2)'["Ref"):" (ever)",1:"")
QUIT
+21 SET BGPVALUE=BGPDV_"|||"
End DoDot:1
+22 IF BGPRTYPE=4
Begin DoDot:1
+23 SET BGPDV="UP"
+24 IF BGPD6!(BGPD1)!(BGPD8)
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AC",1:"AC")
+25 IF BGPD4!(BGPD5)
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",HR",1:"HR")
+26 ;I BGPD3 S BGPDV=BGPDV_$S(BGPDV]"":",UP >64",1:"UP >64")
+27 ;I BGPD7 S BGPDV=BGPDV_$S(BGPDV]"":",UP 18-64",1:"UP 18-64")
+28 ;I BGPD5 S BGPDV=BGPDV_$S(BGPDV]"":",UP 18-64HR",1:"UP 18-64HR")
+29 IF BGPD2
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AD",1:"AD")
End DoDot:1
+30 IF BGPRTYPE=7
SET BGPDV=$SELECT(BGPD6:"AC",1:"")
IF BGPD4
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",HR",1:"HR")
IF BGPD2
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",AD",1:"AD")
+31 IF BGPRTYPE=3!(BGPRTYPE=5)
SET BGPVALUE="AC"_"|||"_$$DATE^BGP3UTL($PIECE(BGPVALUE,U,1))_" "_$PIECE(BGPVALUE,U,2)
IF 1
+32 IF '$TEST
Begin DoDot:1
+33 IF BGPRTYPE'=1
SET BGPVALH=BGPVALUE
SET BGPVALUE=BGPDV_"|||"
IF BGPVALH]""
SET BGPVALUE=BGPVALUE_"Pneumo: "_$$DATE^BGP3UTL($PIECE(BGPVALH,U,1))_" "_$PIECE(BGPVALH,U,2)_$SELECT(BGPVALH]""&($PIECE(BGPVALH,U,2)'["Ref"):" (ever)",1:"")_" "_$SELECT(BGPN8:" (up-to-date)",1:"")
+34 SET BGPVALUD="AC"_"|||"
+35 IF BGPN4
SET BGPVALUD=BGPVALUD_"Pneumo: "_$$DATE^BGP3UTL($PIECE(BGPVALH,U,1))_" "_$PIECE(BGPVALH,U,2)_$SELECT(BGPVALH]""&($PIECE(BGPVALH,U,2)'["Ref"):" (ever)",1:"")_" "
+36 SET BGPVALUD=BGPVALUD_$SELECT(BGPN8:"(up-to-date)",1:"")
End DoDot:1
TD ;new tdap and td stuff for v11.1
+1 SET BGPTDAP=$$DTAP^BGP3D3A(DFN,$$DOB^AUPNPAT(DFN),BGPEDATE)
+2 IF BGPTDAP
SET BGPN9=1
+3 SET BGPTD=$$DTAPTD^BGP3D3A(DFN,$$FMADD^XLFDT(BGPEDATE,-(10*365)),BGPEDATE)
+4 IF BGPTD
SET BGPN10=1
+5 IF BGPRTYPE=1
GOTO TDE
+6 IF BGPTDAP
SET BGPVALUE=BGPVALUE_$SELECT($PIECE(BGPVALUE,"|||",2)]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"TDAP: "_$PIECE(BGPTDAP,U,2)_" (ever)"
+7 ;I BGPTDAP,'BGPTD S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:""),BGPVALUE=BGPVALUE_"TDAP: "_$P(BGPTDAP,U,2)_" (ever)"
+8 IF BGPTD
SET BGPVALUE=BGPVALUE_$SELECT($PIECE(BGPVALUE,"|||",2)]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"TDAP/TD: "_$PIECE(BGPTD,U,2)_" (past 10 yrs)"
+9 ;I BGPTD S BGPVALUE=BGPVALUE_$S($P(BGPVALUE,"|||",2)]"":"; ",1:"") S BGPVALUE=BGPVALUE_"TDAP/TD PAST 10 YRS: "_$P(BGPTD,U,2)
TDE KILL BGPLPNU,BGPVAL,BGPA65,BGPVALH
+1 QUIT
I15 ;EP
+1 KILL BGPN1,BGPN2,BGPN3,BGPN4,BGPVALUE,BGPPAP,BGPI7,BGPI7DA,BGPI7DB,BGPI7DC,BGPI7DD,BGPPAP4,BGPPAP6
+2 SET BGPI7DA=0
SET BGPI7DB=0
SET BGPI7DC=0
SET BGPI7DD=0
SET BGPN1=0
SET BGPN2=0
SET BGPN3=0
SET BGPPAP4=""
SET BGPN4=0
SET BGPPAP6=""
SET BGPHPV=""
+3 SET (BGPD1,BGPD2,BGPD3,BGPD4,BGPN5,BGPN6)=0
+4 SET BGPI7=$$DEN7(DFN,BGPAGEB,BGPAGEE,BGPSEX,BGPEDATE)
+5 IF BGPACTUP
IF BGPI7
SET BGPI7DA=1
+6 IF BGPACTCL
IF BGPI7
SET BGPI7DB=1
+7 ;2013 GPRA DEV
IF BGPACTCL
IF BGPI7
IF BGPAGEB>24
IF BGPAGEE<65
SET BGPI7DC=1
SET BGPD4=1
+8 IF BGPACTUP
IF BGPI7
IF BGPAGEB>24
IF BGPAGEE<65
SET BGPI7DD=1
+9 IF BGPACTCL
IF BGPI7
IF BGPAGEB>29
IF BGPAGEE<65
SET BGPD1=1
+10 IF BGPACTCL
IF BGPI7
IF BGPAGEB>24
IF BGPAGEB<30
SET BGPD2=1
+11 ;not in either denom so quit
IF 'BGPI7DC
IF 'BGPI7DD
SET BGPSTOP=1
QUIT
+12 ;I BGPTIME=1,BGPD4,'(BGPD1+BGPD2) W !,DFN,?10,"BGPD4=",BGPD4,?20,"BGPD2=",BGPD2,?30,"BGPD1=",BGPD1,?40,"AGEB: ",BGPAGEB,?50,"AGEE: ",BGPAGEE
+13 SET BGPPAP=$$PAP(DFN,BGPEDATE,3,1)
+14 SET BGPPAP4=$$PAP(DFN,BGPEDATE,4,1)
+15 SET BGPN1=0
IF $PIECE(BGPPAP,U)=1
SET BGPN1=1
+16 IF $PIECE(BGPPAP,U,3)["Ref"
SET BGPN2=1
+17 IF BGPN1
IF 'BGPN2
SET BGPN3=1
+18 ;PAP IN 4 YRS, NO REFUSALS
SET BGPN4=0
IF $PIECE(BGPPAP4,U,1)=1
SET BGPN4=1
+19 ;for gpra dev, if they didn't have pap in 4 years check HPV
+20 IF 'BGPN4
IF BGPD1
Begin DoDot:1
+21 SET BGPPAP6=$$PAP(DFN,BGPEDATE,6)
+22 SET BGPHPV=$$HPV(DFN,BGPEDATE,6)
+23 IF BGPHPV
IF BGPPAP6
SET BGPN5=1
End DoDot:1
+24 IF BGPN4!(BGPN5)
SET BGPN6=1
+25 ;I BGPTIME=1 W ?40,"BGPN4=",BGPN4,?50,"BGPN5=",?60,"BGPN6=",BGPN6
+26 SET BGPVALUE=$SELECT(BGPI7DD:"UP",1:"")_$SELECT(BGPI7DC:",AC",1:"")_"|||"_$$DATE^BGP3UTL($PIECE(BGPPAP4,U,2))_" "_$PIECE(BGPPAP4,U,3)
+27 ;I BGPRTYPE=1 S BGPVALUE=$S(BGPI7DA:"UP",1:"")_$S(BGPI7DB:",AC",1:"")_"|||" I BGPN3 S BGPVALUE=BGPVALUE_$$DATE^BGP3UTL($P(BGPPAP,U,2))_" "_$P(BGPPAP,U,3)
+28 ;I BGPRTYPE=3 S BGPVALUE="AC|||"_$$DATE^BGP3UTL($P(BGPPAP,U,2))_" "_$P(BGPPAP,U,3)
+29 SET BGPVALUD="AC|||"
IF BGPN4
SET BGPVALUD=BGPVALUD_$$DATE^BGP3UTL($PIECE(BGPPAP4,U,2))_" "_$PIECE(BGPPAP4,U,3)
+30 IF BGPN6
IF 'BGPN4
SET BGPVALUD=BGPVALUD_"HPV: "_$$DATE^BGP3UTL($PIECE(BGPHPV,U,2))_" PAP: "_$$DATE^BGP3UTL($PIECE(BGPPAP6,U,2))
+31 KILL BGPLPAP,BGPPAP,BGPHPV,BGPPAP4,BGPPAP6
+32 QUIT
+33 ;
HPV(P,EDATE,YEARS) ;
+1 NEW BGPC,BGPLPAP,T,BGPLT,B,D,E,L,X,J,BGP
+2 SET BGPC=""
+3 SET BGPLPAP=""
+4 SET BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
+5 SET T=$ORDER(^ATXAX("B","BGP HPV LOINC CODES",0))
+6 SET BGPLT=$ORDER(^ATXLAB("B","BGP HPV TESTS TAX",0))
+7 SET B=9999999-BDATE
SET E=9999999-EDATE
SET D=E-1
FOR
SET D=$ORDER(^AUPNVLAB("AE",P,D))
IF D'=+D!(D>B)!(BGPC]"")
QUIT
Begin DoDot:1
+8 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L!(BGPC]"")
QUIT
Begin DoDot:2
+9 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X!(BGPC]"")
QUIT
Begin DoDot:3
+10 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+11 SET Z=$PIECE(^AUPNVLAB(X,0),U)
SET Z=$PIECE($GET(^LAB(60,Z,0)),U)
IF Z="HPV"
SET BGPC="1^"_(9999999-D)_"^Lab"
QUIT
+12 IF BGPLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(BGPLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET BGPC="1^"_(9999999-D)_"^Lab"
QUIT
+13 IF 'T
QUIT
+14 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+15 IF '$$LOINC(J,T)
QUIT
+16 SET BGPC="1^"_(9999999-D)_"^Lab-loinc"
QUIT
+17 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+18 SET BGPLPAP=BGPC
+19 KILL BGP
+20 SET T="BGP HPV DXS"
+21 SET X=$$LASTDX^BGP3UTL1(P,T,BDATE,EDATE)
IF X
IF $PIECE(BGPLPAP,U,2)<$PIECE(X,U,3)
SET BGPLPAP="1^"_$PIECE(X,U,3)_"^POV "_$PIECE(X,U,2)
+22 SET T=$ORDER(^ATXAX("B","BGP HPV CPTS",0))
+23 IF T
Begin DoDot:1
+24 SET X=$$CPT^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5)
IF X]""
QUIT
+25 SET X=$$TRAN^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5)
End DoDot:1
IF X]""
IF $PIECE(BGPLPAP,U,2)<$PIECE(X,U,1)
SET BGPLPAP="1^"_$PIECE(X,U)_"^CPT "_$PIECE(X,U,2)
+26 QUIT BGPLPAP
+27 ;
FLU(P,BD,ED,FORE) ;EP
+1 GOTO FLU^BGP3D37
BI() ;
+1 QUIT $SELECT($ORDER(^AUTTIMM(0))>100:1,1:0)
DEN7(P,AGEB,AGEE,SEX,EDATE) ;EP
+1 IF SEX'="F"
QUIT 0
+2 IF AGEB<25
QUIT 0
+3 IF AGEE>64
QUIT 0
+4 IF $$HYSTER(P,EDATE)
QUIT 0
+5 QUIT 1
H1(I) ;
+1 IF $PIECE($GET(^ICPT(I,0)),U,1)=90664
QUIT 1
+2 IF $PIECE($GET(^ICPT(I,0)),U,1)=90666
QUIT 1
+3 IF $PIECE($GET(^ICPT(I,0)),U,1)=90667
QUIT 1
+4 IF $PIECE($GET(^ICPT(I,0)),U,1)=90668
QUIT 1
+5 QUIT ""
PAP(P,EDATE,YEARS,REFUSAL) ;EP
+1 NEW BGPC,BGPLPAP,T,BGPLT,B,D,E,L,X,J,BGP
+2 SET BGPC=""
+3 SET BGPLPAP=""
+4 SET BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
+5 SET T=$ORDER(^ATXAX("B","BGP PAP LOINC CODES",0))
+6 SET BGPLT=$ORDER(^ATXLAB("B","BGP PAP SMEAR TAX",0))
+7 SET B=9999999-BDATE
SET E=9999999-EDATE
SET D=E-1
FOR
SET D=$ORDER(^AUPNVLAB("AE",P,D))
IF D'=+D!(D>B)!(BGPC]"")
QUIT
Begin DoDot:1
+8 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L!(BGPC]"")
QUIT
Begin DoDot:2
+9 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X!(BGPC]"")
QUIT
Begin DoDot:3
+10 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+11 SET Z=$PIECE(^AUPNVLAB(X,0),U)
SET Z=$PIECE($GET(^LAB(60,Z,0)),U)
IF Z="PAP SMEAR"
SET BGPC="1^"_(9999999-D)_"^Lab"
QUIT
+12 IF BGPLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(BGPLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET BGPC="1^"_(9999999-D)_"^Lab"
QUIT
+13 IF 'T
QUIT
+14 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+15 IF '$$LOINC(J,T)
QUIT
+16 SET BGPC="1^"_(9999999-D)_"^Lab-loinc"
QUIT
+17 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+18 SET BGPLPAP=BGPC
+19 KILL BGP
+20 SET T="BGP PAP SMEAR DXS"
+21 IF BGPRTYPE=3
SET T="BGP HEDIS PAP SMEAR DXS"
+22 SET X=$$LASTDX^BGP3UTL1(P,T,BDATE,EDATE)
IF X
IF $PIECE(BGPLPAP,U,2)<$PIECE(X,U,3)
SET BGPLPAP="1^"_$PIECE(X,U,3)_"^POV "_$PIECE(X,U,2)
+23 KILL BGP
SET BGP(1)=$$LASTPRC^BGP3UTL1(P,"BGP PAP PROCEDURES",BDATE,EDATE)
+24 IF $DATA(BGP(1))
IF $PIECE(BGPLPAP,U,2)<$PIECE(BGP(1),U,3)
SET BGPLPAP="1^"_$PIECE(BGP(1),U,3)_"^PROC "_$PIECE(BGP(1),U,2)
+25 SET T=$ORDER(^ATXAX("B","BGP CPT PAP",0))
+26 IF T
Begin DoDot:1
+27 SET X=$$CPT^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5)
IF X]""
QUIT
+28 SET X=$$TRAN^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,5)
End DoDot:1
IF X]""
IF $PIECE(BGPLPAP,U,2)<$PIECE(X,U,1)
SET BGPLPAP="1^"_$PIECE(X,U)_"^CPT "_$PIECE(X,U,2)
+29 SET T="PAP SMEAR"
SET T=$ORDER(^BWPN("B",T,0))
+30 IF T
Begin DoDot:1
+31 SET X=$$WH^BGP3DU(P,$$FMADD^XLFDT(EDATE,-(YEARS*365)),EDATE,T,3)
End DoDot:1
IF X]""
IF $PIECE(BGPLPAP,U,2)<X
SET BGPLPAP="1^"_X_"^WH"
+32 IF BGPLPAP]""
QUIT BGPLPAP
+33 ;no Refusals counted
IF $GET(REFUSAL)
QUIT ""
+34 SET T=$$REFUSAL^BGP3UTL1(P,60,$ORDER(^LAB(60,"B","PAP SMEAR",0)),$$FMADD^XLFDT(EDATE,-365),EDATE)
+35 IF T
QUIT "1^"_$PIECE(T,U,2)_"^Refused Lab"
+36 SET BGPLT=$ORDER(^ATXLAB("B","BGP PAP SMEAR TAX",0))
+37 IF 'BGPLT
QUIT 0
+38 SET X=0
SET T=""
FOR
SET X=$ORDER(^ATXLAB(BGPLT,21,X))
IF X'=+X!($PIECE(T,U)=1)
QUIT
Begin DoDot:1
+39 SET T=""
+40 SET Y=$PIECE(^ATXLAB(BGPLT,21,X,0),U)
+41 IF 'Y
QUIT
+42 SET T=$$REFUSAL^BGP3UTL1(P,60,Y,$$FMADD^XLFDT(EDATE,-365),EDATE)
End DoDot:1
+43 IF T
QUIT 1_"^"_$PIECE(T,U,2)_"^Refused Lab "
+44 ;add cpt Refusals v11.1
+45 SET T=$$CPTREFT^BGP3UTL1(P,$$FMADD^XLFDT(EDATE,-365),EDATE,$ORDER(^ATXAX("B","BGP CPT PAP",0)))
+46 IF T
SET T="1^"_$PIECE(T,U,2)_"^Refused CPT "_$PIECE(T,U,4)
QUIT T
+47 QUIT ""
LOINC(A,B) ;
+1 NEW %
+2 SET %=$PIECE($GET(^LAB(95.3,A,9999999)),U,2)
+3 IF %]""
IF $DATA(^ATXAX(B,21,"B",%))
QUIT 1
+4 SET %=$PIECE($GET(^LAB(95.3,A,0)),U)_"-"_$PIECE($GET(^LAB(95.3,A,0)),U,15)
+5 IF $DATA(^ATXAX(B,21,"B",%))
QUIT 1
+6 QUIT ""
HYSTER(P,EDATE) ;EP
+1 IF '$GET(P)
QUIT ""
+2 NEW X,T
+3 SET X=$$LASTPRC^BGP3UTL1(P,"BGP HYSTERECTOMY PROCEDURES",$$DOB^AUPNPAT(P),EDATE)
+4 IF X
QUIT 1
+5 SET T="HYSTERECTOMY"
SET T=$ORDER(^BWPN("B",T,0))
+6 IF T
Begin DoDot:1
+7 SET X=$$WH^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,2)
End DoDot:1
IF X]""
QUIT 1
+8 SET T=$ORDER(^ATXAX("B","BGP HYSTERECTOMY CPTS",0))
+9 IF T
Begin DoDot:1
+10 SET X=$$CPT^BGP3DU(P,$PIECE(^DPT(P,0),U,3),EDATE,T,3)
IF X]""
QUIT
+11 SET X=$$TRAN^BGP3DU(P,$PIECE(^DPT(P,0),U,3),EDATE,T,3)
End DoDot:1
IF X]""
QUIT 1
+12 SET X=$$LASTDX^BGP3UTL1(P,"BGP HYSTERECTOMY DXS",$$DOB^AUPNPAT(P),EDATE)
+13 IF X
QUIT 1
+14 SET X=$$PLTAX^BGP3DU(P,"BGP HYSTERECTOMY DXS")
+15 IF X
QUIT 1
+16 QUIT ""