BGP7D811 ; IHS/CMI/LAB - PCR, MMR ;
;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
;
PCR(P,BDATE,EDATE) ;EP
NEW BGPG,%,E,A,T,X,G,J,I
S %=P_"^LAST LAB [BGP HIV VIRAL LOAD TAX;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,"BGPG(")
I $D(BGPG(1)) Q 1_U_$P(BGPG(1),U,1)_U_$P(BGPG(1),U,2)
S E=+$$CODEN^ICPTCOD(87536),%=$$CPTI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^87536"
S E=+$$CODEN^ICPTCOD(87539),%=$$CPTI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^87539"
S E=+$$CODEN^ICPTCOD("G9242"),%=$$CPTI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^G9242"
S E=+$$CODEN^ICPTCOD("G9243"),%=$$CPTI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^G9243"
S E=+$$CODEN^ICPTCOD(87536),%=$$TRANI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^87536 TRAN"
S E=+$$CODEN^ICPTCOD(87539),%=$$TRANI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^87539 TRAN"
S E=+$$CODEN^ICPTCOD("G9242"),%=$$TRANI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^G9242 TRAN"
S E=+$$CODEN^ICPTCOD("G9243"),%=$$TRANI^BGP7DU(P,BDATE,EDATE,E) I %]"" Q 1_U_$P(%,U,2)_"^G9243 TRAN"
;now go through all labs and check loinc codes
K ^TMP($J,"A")
S A="^TMP($J,""A"",",%=P_"^ALL LAB;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,A)
I '$D(^TMP($J,"A",1)) Q ""
;now go through all lab tests and see if any are the loinc codes in the taxonomy
S T=$O(^ATXAX("B","BGP VIRAL LOAD LOINC CODES",0))
I 'T Q ""
S (X,G)=0 F S X=$O(^TMP($J,"A",X)) Q:X'=+X!(G) S I=+$P(^TMP($J,"A",X),U,4) I $P($G(^AUPNVLAB(I,11)),U,13)]"" D
.S J=$P(^AUPNVLAB(I,11),U,13)
.I $$LOINC^BGP7D21(J,T) S G=1_U_$$VD^APCLV($P(^AUPNVLAB(I,0),U,3))_U_$$VAL^XBDIQ1(9000010.09,I,.01)
Q G
ART(P,BDATE,EDATE) ;EP -antiviral med?
NEW A,C,G,BGPMEDS1,T,M
K BGPMEDS1,^TMP($J,"A")
D GETMEDS^BGP7UTL2(P,BDATE,EDATE,"BGP PQA ANTIRETROVIRAL MEDS","BGP PQA ANTIRETROVIRAL NDC",,,.BGPMEDS1)
S C=""
I '$D(BGPMEDS1) Q C ; no meds
S A=0,C="",T=0 F S A=$O(BGPMEDS1(A)) Q:A'=+A!(T>0) D
.S M=$P(BGPMEDS1(A),U,4) ;IEN OF V MED
.Q:'$D(^AUPNVMED(M,0))
.I $$UP^XLFSTR($P($G(^AUPNVMED(M,11)),U))["RETURNED TO STOCK" K BGPMEDS1(A) Q
.;I $$STATDC(M) K BGPMEDS1(A) Q ;d/c'ed BY PROVIDER OR EDIT
.S V=$P(BGPMEDS1(A),U,5)
.S V1D=$$VD^APCLV(V)
.S T=T+1
.S C=1_U_""_$$DATE^BGP7UTL(V1D)_" "_$$VAL^XBDIQ1(9000010.14,M,.01)
Q C
MMR(P,EDATE) ;EP
NEW BGPC,BGPG,BGPX,BGPMMR,ED,BD,V,X,Y,C,D,BGPME,BGPMU,BGPRUB,BGPMR,BGPRM,BGPNMI,BGPIMM
K ^TMP($J,"CPT")
S ED=9999999-EDATE,BD=9999999-$$DOB^AUPNPAT(P),G=0
F S ED=$O(^AUPNVSIT("AA",P,ED)) Q:ED=""!($P(ED,".")>BD) D
.S V=0 F S V=$O(^AUPNVSIT("AA",P,ED,V)) Q:V'=+V D
..Q:'$D(^AUPNVSIT(V,0))
..S X=0 F S X=$O(^AUPNVCPT("AD",V,X)) Q:X'=+X D
...S Y=$P(^AUPNVCPT(X,0),U),Y=$P($$CPT^ICPTCOD(Y),U,2) I Y=+Y,$T(@Y)]"" S ^TMP($J,"CPT",9999999-ED,Y)=""
..S X=0 F S X=$O(^AUPNVTC("AD",V,X)) Q:X'=+X D
...S Y=$P(^AUPNVTC(X,0),U,7) Q:'Y S Y=$P($$CPT^ICPTCOD(Y),U,2) I Y=+Y,$T(@Y)]"" S ^TMP($J,"CPT",9999999-ED,Y)=""
S BGPMMR=0
S C="3^94"
K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPMMR)
S X=0 F S X=$O(BGPX(X)) Q:X'=+X S BGPMMR(X)=""
S D=0 F S D=$O(^TMP($J,"CPT",D)) Q:D'=+D S Y="" F S Y=$O(^TMP($J,"CPT",D,Y)) Q:Y="" D
.I Y=90707!(Y=90710) S BGPMMR(D)=""
S X="",Y="",C=0 F S X=$O(BGPMMR(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMMR(X) Q
.S Y=X
;now count them and see if there are 2 of them
S BGPMMR=0,X=0 F S X=$O(BGPMMR(X)) Q:X'=+X S BGPMMR=BGPMMR+1
I BGPMMR>1 Q 1_U_"2 MMR"
MR ;see if one M/R, Mumps or R/M
S (BGPMR,BGPRM,BGPME,BGPMU,BGPRUB)=0
S C=4
K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
S X=0 F S X=$O(BGPX(X)) Q:X'=+X S BGPMR(X)=""
S D=0 F S D=$O(^TMP($J,"CPT",D)) Q:D'=+D S Y="" F S Y=$O(^TMP($J,"CPT",D,Y)) Q:Y="" D
.I Y=90708 S BGPMR(D)=""
;now check to see if they are all spaced 10 days apart, if not, kill off the odd ones
S X="",Y="",C=0 F S X=$O(BGPMR(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMR(X) Q
.S Y=X
;count them
S X=0 F S X=$O(BGPMR(X)) Q:X'=+X S BGPMR=BGPMR+1
RM ;
S C=38
K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
S X=0 F S X=$O(BGPX(X)) Q:X'=+X S BGPRM(X)=""
S D=0 F S D=$O(^TMP($J,"CPT",D)) Q:D'=+D S Y="" F S Y=$O(^TMP($J,"CPT",D,Y)) Q:Y="" D
.I Y=90709 S BGPRM(D)=""
;now check to see if they are all spaced 10 days apart, if not, kill off the odd ones
S X="",Y="",C=0 F S X=$O(BGPRM(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPRM(X) Q
.S Y=X
;count them
S X=0 F S X=$O(BGPRM(X)) Q:X'=+X S BGPRM=BGPRM+1
ME S C=5
K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
S X=0 F S X=$O(BGPX(X)) Q:X'=+X S BGPME(X)=""
S D=0 F S D=$O(^TMP($J,"CPT",D)) Q:D'=+D S Y="" F S Y=$O(^TMP($J,"CPT",D,Y)) Q:Y="" D
.I Y=90705 S BGPME(D)=""
;now check to see if they are all spaced 10 days apart, if not, kill off the odd ones
S X="",Y="",C=0 F S X=$O(BGPME(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPME(X) Q
.S Y=X
;count them
S X=0 F S X=$O(BGPME(X)) Q:X'=+X S BGPME=BGPME+1
MU S C=7
K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
S X=0 F S X=$O(BGPX(X)) Q:X'=+X S BGPMU(X)=""
S D=0 F S D=$O(^TMP($J,"CPT",D)) Q:D'=+D S Y="" F S Y=$O(^TMP($J,"CPT",D,Y)) Q:Y="" D
.I Y=90704 S BGPMU(D)=""
S X="",Y="",C=0 F S X=$O(BGPMU(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMU(X) Q
.S Y=X
;count them
S X=0 F S X=$O(BGPMU(X)) Q:X'=+X S BGPMU=BGPMU+1
RUB S C=6
K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
S X=0 F S X=$O(BGPX(X)) Q:X'=+X S BGPRUB(X)=""
S D=0 F S D=$O(^TMP($J,"CPT",D)) Q:D'=+D S Y="" F S Y=$O(^TMP($J,"CPT",D,Y)) Q:Y="" D
.I Y=90706 S BGPRUB(D)=""
S X="",Y="",C=0 F S X=$O(BGPRUB(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPRUB(X) Q
.S Y=X
;count them
S X=0 F S X=$O(BGPRUB(X)) Q:X'=+X S BGPRUB=BGPRUB+1
I BGPMR>1,BGPMU>1 Q 1_U_"2 m/r 2 mu"
I BGPRM>1,BGPME>1 Q 1_U_"2 r/m 2 me"
I BGPME>1,BGPMU>1,BGPRUB>1 Q 1_U_"2 me 2 mu 2 rub"
;now add diagnoses and proc codes for code 2
PVS ;
K BGPG S %=P_"^ALL DX [BGP MMR IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPMMR($P(BGPG(X),U))=""
S X="",Y="",C=0 F S X=$O(BGPMMR(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMMR(X) Q
.S Y=X
;now count them and see if there are 4 of them
S BGPMMR=0,X=0 F S X=$O(BGPMMR(X)) Q:X'=+X S BGPMMR=BGPMMR+1
I BGPMMR>1 Q 2_U_"2 MMR (DX/IMM)"
K BGPG
S X="",Y="",C=0 F S X=$O(BGPMMR(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMMR(X) Q
.S Y=X
;
S BGPMMR=0,X=0 F S X=$O(BGPMMR(X)) Q:X'=+X S BGPMMR=BGPMMR+1
I BGPMMR>1 Q 2_U_"2 MMR (PROC/IMM)"
MEPV ;
K BGPG S %=P_"^ALL DX [BGP MEASLES IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPME($P(BGPG(X),U))=""
S X="",Y="",C=0 F S X=$O(BGPME(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPME(X) Q
.S Y=X
;
S BGPME=0,X=0 F S X=$O(BGPME(X)) Q:X'=+X S BGPME=BGPME+1
K BGPG
S X="",Y="",C=0 F S X=$O(BGPME(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPME(X) Q
.S Y=X
;
S BGPME=0,X=0 F S X=$O(BGPME(X)) Q:X'=+X S BGPME=BGPME+1
MUPV ;
K BGPG S %=P_"^ALL DX [BGP MUMPS IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPMU($P(BGPG(X),U))=""
S X="",Y="",C=0 F S X=$O(BGPMU(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMU(X) Q
.S Y=X
;now count them and see if there are 4 of them
S BGPMU=0,X=0 F S X=$O(BGPMU(X)) Q:X'=+X S BGPMU=BGPMU+1
K BGPG ;D SETPRC^BGP7UTL1(P,$$DOB^AUPNPAT(P),EDATE,"BGP MUMPS IZ PROCS",.BGPG)
;S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPMU($P(BGPG(X),U))=""
S X="",Y="",C=0 F S X=$O(BGPMU(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPMU(X) Q
.S Y=X
;
S BGPMU=0,X=0 F S X=$O(BGPMU(X)) Q:X'=+X S BGPMU=BGPMU+1
RUBPV ;
K BGPG S %=P_"^ALL DX [BGP RUBELLA IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPRUB($P(BGPG(X),U))=""
S X="",Y="",C=0 F S X=$O(BGPRUB(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPRUB(X) Q
.S Y=X
;now count them and see if there are 4 of them
S BGPRUB=0,X=0 F S X=$O(BGPRUB(X)) Q:X'=+X S BGPRUB=BGPRUB+1
K BGPG ;D SETPRC^BGP7UTL1(P,$$DOB^AUPNPAT(P),EDATE,"BGP RUBELLA IZ PROCS",.BGPG)
;S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPRUB($P(BGPG(X),U))=""
S X="",Y="",C=0 F S X=$O(BGPRUB(X)) Q:X'=+X S C=C+1 D
.I C=1 S Y=X Q
.I $$FMDIFF^XLFDT(X,Y)<11 K BGPRUB(X) Q
.S Y=X
;now count them and see if there are 4 of them
S BGPRUB=0,X=0 F S X=$O(BGPRUB(X)) Q:X'=+X S BGPRUB=BGPRUB+1
;
I BGPMR>1,BGPMU>1 Q 2_U_"m/r mu"
I BGPRM>1,BGPME>1 Q 2_U_"r/m me"
I BGPME>1,BGPMU>1,BGPRUB>1 Q 2_U_"me mu rub"
REF ;
;now get a Refusal of MMR if there is one
S B=$$DOB^AUPNPAT(P),E=EDATE,BGPNMI="",BGPMMR=0,R=""
F BGPIMM=3,94 D
.S I=$O(^AUTTIMM("C",BGPIMM,0)) Q:'I
.S X=0 F S X=$O(^AUPNPREF("AA",P,9999999.14,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,9999999.14,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPNMI=1 S R=1
I R Q $S(BGPNMI:4,1:3)_U_$S(BGPNMI:"NMI MMR",1:"Ref MMR")
F BGPIMM=90707,90710 D
.S I=+$$CODEN^ICPTCOD(BGPIMM) Q:'I
.S X=0 F S X=$O(^AUPNPREF("AA",P,81,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,81,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPNMI=1 S R=1
I R Q $S(BGPNMI:4,1:3)_U_$S(BGPNMI:"NMI MMR",1:"Ref MMR")
MMRC ;
;
F BGPZ=3,94 S X=$$MMRCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
I X]"" Q 4_U_"Contra MMR"
REFMR ;
I BGPMR=0 D
.S B=$$DOB^AUPNPAT(P),E=EDATE,BGPNMI=""
.F BGPIMM=4 D
..S I=$O(^AUTTIMM("C",BGPIMM,0)) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,9999999.14,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,9999999.14,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPMR=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
.F BGPIMM=90708 D
..S I=+$$CODEN^ICPTCOD(BGPIMM) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,81,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,81,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPMR=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
REFRM I BGPRM=0 D
.S B=$$DOB^AUPNPAT(P),E=EDATE
.F BGPIMM=38 D
..S I=$O(^AUTTIMM("C",BGPIMM,0)) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,9999999.14,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,9999999.14,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPRM=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
.F BGPIMM=90709 D
..S I=+$$CODEN^ICPTCOD(BGPIMM) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,81,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,81,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPRM=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
;F BGPIMM=38 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPRM=3
MEX ;
S (BGPMEEV,BGPMUEV,BGPRUEV)=""
I BGPME=0 K BGPG S %=P_"^LAST DX [BGP MEASLES EVIDENCE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(") I $D(BGPG(1)) S BGPME=4,BGPMEEV=1
;I $$PLTAX^BGP7DU(P,"BGP MEASLES EVIDENCE") S BGPME=4,BGPMEEV=1
I $$PLTAXND^BGP7DU(P,"BGP MEASLES EVIDENCE",EDATE) S BGPME=4,BGPMEEV=1
I $$IPLSNOND^BGP7DU(P,"PXRM BGP MEASLES",EDATE) S BGPME=4,BGPMEEV=1
I BGPME=0 D
.S B=$$DOB^AUPNPAT(P),E=EDATE
.F BGPIMM=5 D
..S I=$O(^AUTTIMM("C",BGPIMM,0)) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,9999999.14,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,9999999.14,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPME=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
.F BGPIMM=90705 D
..S I=+$$CODEN^ICPTCOD(BGPIMM) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,81,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,81,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPME=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
;F BGPIMM=7 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPME=3
MUX ;
I BGPMU=0 K BGPG S %=P_"^LAST DX [BGP MUMPS EVIDENCE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(") I $D(BGPG(1)) S BGPMU=4,BGPMUEV=1
I $$PLTAX^BGP7DU(P,"BGP MUMPS EVIDENCE") S BGPMU=4,BGPMUEV=1
I BGPMU=0 D
.S B=$$DOB^AUPNPAT(P),E=EDATE
.F BGPIMM=7 D
..S I=$O(^AUTTIMM("C",BGPIMM,0)) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,9999999.14,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,9999999.14,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPMU=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
.F BGPIMM=90704 D
..S I=+$$CODEN^ICPTCOD(BGPIMM) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,81,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,81,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPMU=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
;now check Refusals in imm pkg
;F BGPIMM="7" I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPMU=3
RUBX ;
I BGPRUB=0 K BGPG S %=P_"^LAST DX [BGP RUBELLA EVIDENCE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(") I $D(BGPG(1)) S BGPRUB=4,BGPRUEV=1
;I $$PLTAX^BGP7DU(P,"BGP RUBELLA EVIDENCE") S BGPRUB=4,BGPRUEV=1
I $$PLTAXND^BGP7DU(P,"BGP RUBELLA EVIDENCE",EDATE) S BGPRUB=4,BGPRUEV=1
I $$IPLSNOND^BGP7DU(P,"PXRM BGP RUBELLA",EDATE) S BGPRUB=4,BGPRUEV=1
I BGPRUB=0 D
.S B=$$DOB^AUPNPAT(P),E=EDATE
.F BGPIMM=6 D
..S I=$O(^AUTTIMM("C",BGPIMM,0)) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,9999999.14,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,9999999.14,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPRUB=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
.F BGPIMM=90706 D
..S I=+$$CODEN^ICPTCOD(BGPIMM) Q:'I
..S X=0 F S X=$O(^AUPNPREF("AA",P,81,I,X)) Q:X'=+X S Y=0 F S Y=$O(^AUPNPREF("AA",P,81,I,X,Y)) Q:Y'=+Y S D=$P(^AUPNPREF(Y,0),U,3) I D'<B&(D'>E) S BGPRUB=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:"")
;F BGPIMM=6 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPRUB=3
I BGPMR,BGPMU S X=1 S:BGPMR=3 X=3 S:BGPMU=3 X=3 S:BGPMR=4 X=4 S:BGPMU=4 X=4 Q X_U_"mr & mu"_$S(BGPMUEV:" (Evid)",1:"")_$S(X=4:" NMI",X=3:" Ref",1:"")
I BGPRM,BGPME S X=1 S:BGPRM=3 X=3 S:BGPME=3 X=3 S:BGPRM=4 X=4 S:BGPME=4 X=4 Q X_U_"RM & ME"_$S(BGPMEEV:" (Evid)",1:"")_$S(X=4:" NMI",X=3:" Ref",1:"")
I BGPME,BGPMU,BGPRUB D Q X_U_"ME"_$S(BGPMEEV:" (Evid)",1:"")_"&MU"_$S(BGPMUEV:" (Evid)",1:"")_"&RUB"_$S(BGPRUEV:" (Evid)",1:"")_$S(X=4:" NMI",X=3:" Ref",1:"")
.S X=1 S:BGPME=3 X=3 S:BGPMU=3 X=3 S:BGPRUB=3 X=3 S:BGPME=4 X=4 S:BGPMU=4 X=4 S:BGPRUB=4 X=4
Q ""
90707 ;;
90710 ;;
90708 ;;
90709 ;;
90705 ;;
90704 ;;
90706 ;;
BGP7D811 ; IHS/CMI/LAB - PCR, MMR ;
+1 ;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
+2 ;
PCR(P,BDATE,EDATE) ;EP
+1 NEW BGPG,%,E,A,T,X,G,J,I
+2 SET %=P_"^LAST LAB [BGP HIV VIRAL LOAD TAX;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(%,"BGPG(")
+3 IF $DATA(BGPG(1))
QUIT 1_U_$PIECE(BGPG(1),U,1)_U_$PIECE(BGPG(1),U,2)
+4 SET E=+$$CODEN^ICPTCOD(87536)
SET %=$$CPTI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^87536"
+5 SET E=+$$CODEN^ICPTCOD(87539)
SET %=$$CPTI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^87539"
+6 SET E=+$$CODEN^ICPTCOD("G9242")
SET %=$$CPTI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^G9242"
+7 SET E=+$$CODEN^ICPTCOD("G9243")
SET %=$$CPTI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^G9243"
+8 SET E=+$$CODEN^ICPTCOD(87536)
SET %=$$TRANI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^87536 TRAN"
+9 SET E=+$$CODEN^ICPTCOD(87539)
SET %=$$TRANI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^87539 TRAN"
+10 SET E=+$$CODEN^ICPTCOD("G9242")
SET %=$$TRANI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^G9242 TRAN"
+11 SET E=+$$CODEN^ICPTCOD("G9243")
SET %=$$TRANI^BGP7DU(P,BDATE,EDATE,E)
IF %]""
QUIT 1_U_$PIECE(%,U,2)_"^G9243 TRAN"
+12 ;now go through all labs and check loinc codes
+13 KILL ^TMP($JOB,"A")
+14 SET A="^TMP($J,""A"","
SET %=P_"^ALL LAB;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(%,A)
+15 IF '$DATA(^TMP($JOB,"A",1))
QUIT ""
+16 ;now go through all lab tests and see if any are the loinc codes in the taxonomy
+17 SET T=$ORDER(^ATXAX("B","BGP VIRAL LOAD LOINC CODES",0))
+18 IF 'T
QUIT ""
+19 SET (X,G)=0
FOR
SET X=$ORDER(^TMP($JOB,"A",X))
IF X'=+X!(G)
QUIT
SET I=+$PIECE(^TMP($JOB,"A",X),U,4)
IF $PIECE($GET(^AUPNVLAB(I,11)),U,13)]""
Begin DoDot:1
+20 SET J=$PIECE(^AUPNVLAB(I,11),U,13)
+21 IF $$LOINC^BGP7D21(J,T)
SET G=1_U_$$VD^APCLV($PIECE(^AUPNVLAB(I,0),U,3))_U_$$VAL^XBDIQ1(9000010.09,I,.01)
End DoDot:1
+22 QUIT G
ART(P,BDATE,EDATE) ;EP -antiviral med?
+1 NEW A,C,G,BGPMEDS1,T,M
+2 KILL BGPMEDS1,^TMP($JOB,"A")
+3 DO GETMEDS^BGP7UTL2(P,BDATE,EDATE,"BGP PQA ANTIRETROVIRAL MEDS","BGP PQA ANTIRETROVIRAL NDC",,,.BGPMEDS1)
+4 SET C=""
+5 ; no meds
IF '$DATA(BGPMEDS1)
QUIT C
+6 SET A=0
SET C=""
SET T=0
FOR
SET A=$ORDER(BGPMEDS1(A))
IF A'=+A!(T>0)
QUIT
Begin DoDot:1
+7 ;IEN OF V MED
SET M=$PIECE(BGPMEDS1(A),U,4)
+8 IF '$DATA(^AUPNVMED(M,0))
QUIT
+9 IF $$UP^XLFSTR($PIECE($GET(^AUPNVMED(M,11)),U))["RETURNED TO STOCK"
KILL BGPMEDS1(A)
QUIT
+10 ;I $$STATDC(M) K BGPMEDS1(A) Q ;d/c'ed BY PROVIDER OR EDIT
+11 SET V=$PIECE(BGPMEDS1(A),U,5)
+12 SET V1D=$$VD^APCLV(V)
+13 SET T=T+1
+14 SET C=1_U_""_$$DATE^BGP7UTL(V1D)_" "_$$VAL^XBDIQ1(9000010.14,M,.01)
End DoDot:1
+15 QUIT C
MMR(P,EDATE) ;EP
+1 NEW BGPC,BGPG,BGPX,BGPMMR,ED,BD,V,X,Y,C,D,BGPME,BGPMU,BGPRUB,BGPMR,BGPRM,BGPNMI,BGPIMM
+2 KILL ^TMP($JOB,"CPT")
+3 SET ED=9999999-EDATE
SET BD=9999999-$$DOB^AUPNPAT(P)
SET G=0
+4 FOR
SET ED=$ORDER(^AUPNVSIT("AA",P,ED))
IF ED=""!($PIECE(ED,".")>BD)
QUIT
Begin DoDot:1
+5 SET V=0
FOR
SET V=$ORDER(^AUPNVSIT("AA",P,ED,V))
IF V'=+V
QUIT
Begin DoDot:2
+6 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+7 SET X=0
FOR
SET X=$ORDER(^AUPNVCPT("AD",V,X))
IF X'=+X
QUIT
Begin DoDot:3
+8 SET Y=$PIECE(^AUPNVCPT(X,0),U)
SET Y=$PIECE($$CPT^ICPTCOD(Y),U,2)
IF Y=+Y
IF $TEXT(@Y)]""
SET ^TMP($JOB,"CPT",9999999-ED,Y)=""
End DoDot:3
+9 SET X=0
FOR
SET X=$ORDER(^AUPNVTC("AD",V,X))
IF X'=+X
QUIT
Begin DoDot:3
+10 SET Y=$PIECE(^AUPNVTC(X,0),U,7)
IF 'Y
QUIT
SET Y=$PIECE($$CPT^ICPTCOD(Y),U,2)
IF Y=+Y
IF $TEXT(@Y)]""
SET ^TMP($JOB,"CPT",9999999-ED,Y)=""
End DoDot:3
End DoDot:2
End DoDot:1
+11 SET BGPMMR=0
+12 SET C="3^94"
+13 KILL BGPX
DO GETIMMS^BGP7D32(P,EDATE,C,.BGPMMR)
+14 SET X=0
FOR
SET X=$ORDER(BGPX(X))
IF X'=+X
QUIT
SET BGPMMR(X)=""
+15 SET D=0
FOR
SET D=$ORDER(^TMP($JOB,"CPT",D))
IF D'=+D
QUIT
SET Y=""
FOR
SET Y=$ORDER(^TMP($JOB,"CPT",D,Y))
IF Y=""
QUIT
Begin DoDot:1
+16 IF Y=90707!(Y=90710)
SET BGPMMR(D)=""
End DoDot:1
+17 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMMR(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+18 IF C=1
SET Y=X
QUIT
+19 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMMR(X)
QUIT
+20 SET Y=X
End DoDot:1
+21 ;now count them and see if there are 2 of them
+22 SET BGPMMR=0
SET X=0
FOR
SET X=$ORDER(BGPMMR(X))
IF X'=+X
QUIT
SET BGPMMR=BGPMMR+1
+23 IF BGPMMR>1
QUIT 1_U_"2 MMR"
MR ;see if one M/R, Mumps or R/M
+1 SET (BGPMR,BGPRM,BGPME,BGPMU,BGPRUB)=0
+2 SET C=4
+3 KILL BGPX
DO GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
+4 SET X=0
FOR
SET X=$ORDER(BGPX(X))
IF X'=+X
QUIT
SET BGPMR(X)=""
+5 SET D=0
FOR
SET D=$ORDER(^TMP($JOB,"CPT",D))
IF D'=+D
QUIT
SET Y=""
FOR
SET Y=$ORDER(^TMP($JOB,"CPT",D,Y))
IF Y=""
QUIT
Begin DoDot:1
+6 IF Y=90708
SET BGPMR(D)=""
End DoDot:1
+7 ;now check to see if they are all spaced 10 days apart, if not, kill off the odd ones
+8 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMR(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+9 IF C=1
SET Y=X
QUIT
+10 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMR(X)
QUIT
+11 SET Y=X
End DoDot:1
+12 ;count them
+13 SET X=0
FOR
SET X=$ORDER(BGPMR(X))
IF X'=+X
QUIT
SET BGPMR=BGPMR+1
RM ;
+1 SET C=38
+2 KILL BGPX
DO GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
+3 SET X=0
FOR
SET X=$ORDER(BGPX(X))
IF X'=+X
QUIT
SET BGPRM(X)=""
+4 SET D=0
FOR
SET D=$ORDER(^TMP($JOB,"CPT",D))
IF D'=+D
QUIT
SET Y=""
FOR
SET Y=$ORDER(^TMP($JOB,"CPT",D,Y))
IF Y=""
QUIT
Begin DoDot:1
+5 IF Y=90709
SET BGPRM(D)=""
End DoDot:1
+6 ;now check to see if they are all spaced 10 days apart, if not, kill off the odd ones
+7 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPRM(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+8 IF C=1
SET Y=X
QUIT
+9 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPRM(X)
QUIT
+10 SET Y=X
End DoDot:1
+11 ;count them
+12 SET X=0
FOR
SET X=$ORDER(BGPRM(X))
IF X'=+X
QUIT
SET BGPRM=BGPRM+1
ME SET C=5
+1 KILL BGPX
DO GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
+2 SET X=0
FOR
SET X=$ORDER(BGPX(X))
IF X'=+X
QUIT
SET BGPME(X)=""
+3 SET D=0
FOR
SET D=$ORDER(^TMP($JOB,"CPT",D))
IF D'=+D
QUIT
SET Y=""
FOR
SET Y=$ORDER(^TMP($JOB,"CPT",D,Y))
IF Y=""
QUIT
Begin DoDot:1
+4 IF Y=90705
SET BGPME(D)=""
End DoDot:1
+5 ;now check to see if they are all spaced 10 days apart, if not, kill off the odd ones
+6 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPME(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+7 IF C=1
SET Y=X
QUIT
+8 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPME(X)
QUIT
+9 SET Y=X
End DoDot:1
+10 ;count them
+11 SET X=0
FOR
SET X=$ORDER(BGPME(X))
IF X'=+X
QUIT
SET BGPME=BGPME+1
MU SET C=7
+1 KILL BGPX
DO GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
+2 SET X=0
FOR
SET X=$ORDER(BGPX(X))
IF X'=+X
QUIT
SET BGPMU(X)=""
+3 SET D=0
FOR
SET D=$ORDER(^TMP($JOB,"CPT",D))
IF D'=+D
QUIT
SET Y=""
FOR
SET Y=$ORDER(^TMP($JOB,"CPT",D,Y))
IF Y=""
QUIT
Begin DoDot:1
+4 IF Y=90704
SET BGPMU(D)=""
End DoDot:1
+5 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMU(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+6 IF C=1
SET Y=X
QUIT
+7 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMU(X)
QUIT
+8 SET Y=X
End DoDot:1
+9 ;count them
+10 SET X=0
FOR
SET X=$ORDER(BGPMU(X))
IF X'=+X
QUIT
SET BGPMU=BGPMU+1
RUB SET C=6
+1 KILL BGPX
DO GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
+2 SET X=0
FOR
SET X=$ORDER(BGPX(X))
IF X'=+X
QUIT
SET BGPRUB(X)=""
+3 SET D=0
FOR
SET D=$ORDER(^TMP($JOB,"CPT",D))
IF D'=+D
QUIT
SET Y=""
FOR
SET Y=$ORDER(^TMP($JOB,"CPT",D,Y))
IF Y=""
QUIT
Begin DoDot:1
+4 IF Y=90706
SET BGPRUB(D)=""
End DoDot:1
+5 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPRUB(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+6 IF C=1
SET Y=X
QUIT
+7 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPRUB(X)
QUIT
+8 SET Y=X
End DoDot:1
+9 ;count them
+10 SET X=0
FOR
SET X=$ORDER(BGPRUB(X))
IF X'=+X
QUIT
SET BGPRUB=BGPRUB+1
+11 IF BGPMR>1
IF BGPMU>1
QUIT 1_U_"2 m/r 2 mu"
+12 IF BGPRM>1
IF BGPME>1
QUIT 1_U_"2 r/m 2 me"
+13 IF BGPME>1
IF BGPMU>1
IF BGPRUB>1
QUIT 1_U_"2 me 2 mu 2 rub"
+14 ;now add diagnoses and proc codes for code 2
PVS ;
+1 KILL BGPG
SET %=P_"^ALL DX [BGP MMR IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
+2 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET BGPMMR($PIECE(BGPG(X),U))=""
+3 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMMR(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+4 IF C=1
SET Y=X
QUIT
+5 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMMR(X)
QUIT
+6 SET Y=X
End DoDot:1
+7 ;now count them and see if there are 4 of them
+8 SET BGPMMR=0
SET X=0
FOR
SET X=$ORDER(BGPMMR(X))
IF X'=+X
QUIT
SET BGPMMR=BGPMMR+1
+9 IF BGPMMR>1
QUIT 2_U_"2 MMR (DX/IMM)"
+10 KILL BGPG
+11 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMMR(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+12 IF C=1
SET Y=X
QUIT
+13 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMMR(X)
QUIT
+14 SET Y=X
End DoDot:1
+15 ;
+16 SET BGPMMR=0
SET X=0
FOR
SET X=$ORDER(BGPMMR(X))
IF X'=+X
QUIT
SET BGPMMR=BGPMMR+1
+17 IF BGPMMR>1
QUIT 2_U_"2 MMR (PROC/IMM)"
MEPV ;
+1 KILL BGPG
SET %=P_"^ALL DX [BGP MEASLES IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
+2 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET BGPME($PIECE(BGPG(X),U))=""
+3 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPME(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+4 IF C=1
SET Y=X
QUIT
+5 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPME(X)
QUIT
+6 SET Y=X
End DoDot:1
+7 ;
+8 SET BGPME=0
SET X=0
FOR
SET X=$ORDER(BGPME(X))
IF X'=+X
QUIT
SET BGPME=BGPME+1
+9 KILL BGPG
+10 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPME(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+11 IF C=1
SET Y=X
QUIT
+12 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPME(X)
QUIT
+13 SET Y=X
End DoDot:1
+14 ;
+15 SET BGPME=0
SET X=0
FOR
SET X=$ORDER(BGPME(X))
IF X'=+X
QUIT
SET BGPME=BGPME+1
MUPV ;
+1 KILL BGPG
SET %=P_"^ALL DX [BGP MUMPS IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
+2 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET BGPMU($PIECE(BGPG(X),U))=""
+3 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMU(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+4 IF C=1
SET Y=X
QUIT
+5 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMU(X)
QUIT
+6 SET Y=X
End DoDot:1
+7 ;now count them and see if there are 4 of them
+8 SET BGPMU=0
SET X=0
FOR
SET X=$ORDER(BGPMU(X))
IF X'=+X
QUIT
SET BGPMU=BGPMU+1
+9 ;D SETPRC^BGP7UTL1(P,$$DOB^AUPNPAT(P),EDATE,"BGP MUMPS IZ PROCS",.BGPG)
KILL BGPG
+10 ;S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPMU($P(BGPG(X),U))=""
+11 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPMU(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+12 IF C=1
SET Y=X
QUIT
+13 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPMU(X)
QUIT
+14 SET Y=X
End DoDot:1
+15 ;
+16 SET BGPMU=0
SET X=0
FOR
SET X=$ORDER(BGPMU(X))
IF X'=+X
QUIT
SET BGPMU=BGPMU+1
RUBPV ;
+1 KILL BGPG
SET %=P_"^ALL DX [BGP RUBELLA IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
+2 SET X=0
FOR
SET X=$ORDER(BGPG(X))
IF X'=+X
QUIT
SET BGPRUB($PIECE(BGPG(X),U))=""
+3 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPRUB(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+4 IF C=1
SET Y=X
QUIT
+5 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPRUB(X)
QUIT
+6 SET Y=X
End DoDot:1
+7 ;now count them and see if there are 4 of them
+8 SET BGPRUB=0
SET X=0
FOR
SET X=$ORDER(BGPRUB(X))
IF X'=+X
QUIT
SET BGPRUB=BGPRUB+1
+9 ;D SETPRC^BGP7UTL1(P,$$DOB^AUPNPAT(P),EDATE,"BGP RUBELLA IZ PROCS",.BGPG)
KILL BGPG
+10 ;S X=0 F S X=$O(BGPG(X)) Q:X'=+X S BGPRUB($P(BGPG(X),U))=""
+11 SET X=""
SET Y=""
SET C=0
FOR
SET X=$ORDER(BGPRUB(X))
IF X'=+X
QUIT
SET C=C+1
Begin DoDot:1
+12 IF C=1
SET Y=X
QUIT
+13 IF $$FMDIFF^XLFDT(X,Y)<11
KILL BGPRUB(X)
QUIT
+14 SET Y=X
End DoDot:1
+15 ;now count them and see if there are 4 of them
+16 SET BGPRUB=0
SET X=0
FOR
SET X=$ORDER(BGPRUB(X))
IF X'=+X
QUIT
SET BGPRUB=BGPRUB+1
+17 ;
+18 IF BGPMR>1
IF BGPMU>1
QUIT 2_U_"m/r mu"
+19 IF BGPRM>1
IF BGPME>1
QUIT 2_U_"r/m me"
+20 IF BGPME>1
IF BGPMU>1
IF BGPRUB>1
QUIT 2_U_"me mu rub"
REF ;
+1 ;now get a Refusal of MMR if there is one
+2 SET B=$$DOB^AUPNPAT(P)
SET E=EDATE
SET BGPNMI=""
SET BGPMMR=0
SET R=""
+3 FOR BGPIMM=3,94
Begin DoDot:1
+4 SET I=$ORDER(^AUTTIMM("C",BGPIMM,0))
IF 'I
QUIT
+5 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
IF $PIECE(^AUPNPREF(Y,0),U,7)="N"
SET BGPNMI=1
SET R=1
End DoDot:1
+6 IF R
QUIT $SELECT(BGPNMI:4,1:3)_U_$SELECT(BGPNMI:"NMI MMR",1:"Ref MMR")
+7 FOR BGPIMM=90707,90710
Begin DoDot:1
+8 SET I=+$$CODEN^ICPTCOD(BGPIMM)
IF 'I
QUIT
+9 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,81,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,81,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
IF $PIECE(^AUPNPREF(Y,0),U,7)="N"
SET BGPNMI=1
SET R=1
End DoDot:1
+10 IF R
QUIT $SELECT(BGPNMI:4,1:3)_U_$SELECT(BGPNMI:"NMI MMR",1:"Ref MMR")
MMRC ;
+1 ;
+2 FOR BGPZ=3,94
SET X=$$MMRCONT^BGP7D31(P,BGPZ,EDATE)
IF X]""
QUIT
+3 IF X]""
QUIT 4_U_"Contra MMR"
REFMR ;
+1 IF BGPMR=0
Begin DoDot:1
+2 SET B=$$DOB^AUPNPAT(P)
SET E=EDATE
SET BGPNMI=""
+3 FOR BGPIMM=4
Begin DoDot:2
+4 SET I=$ORDER(^AUTTIMM("C",BGPIMM,0))
IF 'I
QUIT
+5 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPMR=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
+6 FOR BGPIMM=90708
Begin DoDot:2
+7 SET I=+$$CODEN^ICPTCOD(BGPIMM)
IF 'I
QUIT
+8 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,81,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,81,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPMR=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
End DoDot:1
REFRM IF BGPRM=0
Begin DoDot:1
+1 SET B=$$DOB^AUPNPAT(P)
SET E=EDATE
+2 FOR BGPIMM=38
Begin DoDot:2
+3 SET I=$ORDER(^AUTTIMM("C",BGPIMM,0))
IF 'I
QUIT
+4 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPRM=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
+5 FOR BGPIMM=90709
Begin DoDot:2
+6 SET I=+$$CODEN^ICPTCOD(BGPIMM)
IF 'I
QUIT
+7 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,81,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,81,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPRM=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
End DoDot:1
+8 ;F BGPIMM=38 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPRM=3
MEX ;
+1 SET (BGPMEEV,BGPMUEV,BGPRUEV)=""
+2 IF BGPME=0
KILL BGPG
SET %=P_"^LAST DX [BGP MEASLES EVIDENCE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
IF $DATA(BGPG(1))
SET BGPME=4
SET BGPMEEV=1
+3 ;I $$PLTAX^BGP7DU(P,"BGP MEASLES EVIDENCE") S BGPME=4,BGPMEEV=1
+4 IF $$PLTAXND^BGP7DU(P,"BGP MEASLES EVIDENCE",EDATE)
SET BGPME=4
SET BGPMEEV=1
+5 IF $$IPLSNOND^BGP7DU(P,"PXRM BGP MEASLES",EDATE)
SET BGPME=4
SET BGPMEEV=1
+6 IF BGPME=0
Begin DoDot:1
+7 SET B=$$DOB^AUPNPAT(P)
SET E=EDATE
+8 FOR BGPIMM=5
Begin DoDot:2
+9 SET I=$ORDER(^AUTTIMM("C",BGPIMM,0))
IF 'I
QUIT
+10 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPME=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
+11 FOR BGPIMM=90705
Begin DoDot:2
+12 SET I=+$$CODEN^ICPTCOD(BGPIMM)
IF 'I
QUIT
+13 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,81,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,81,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPME=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
End DoDot:1
+14 ;F BGPIMM=7 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPME=3
MUX ;
+1 IF BGPMU=0
KILL BGPG
SET %=P_"^LAST DX [BGP MUMPS EVIDENCE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
IF $DATA(BGPG(1))
SET BGPMU=4
SET BGPMUEV=1
+2 IF $$PLTAX^BGP7DU(P,"BGP MUMPS EVIDENCE")
SET BGPMU=4
SET BGPMUEV=1
+3 IF BGPMU=0
Begin DoDot:1
+4 SET B=$$DOB^AUPNPAT(P)
SET E=EDATE
+5 FOR BGPIMM=7
Begin DoDot:2
+6 SET I=$ORDER(^AUTTIMM("C",BGPIMM,0))
IF 'I
QUIT
+7 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPMU=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
+8 FOR BGPIMM=90704
Begin DoDot:2
+9 SET I=+$$CODEN^ICPTCOD(BGPIMM)
IF 'I
QUIT
+10 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,81,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,81,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPMU=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
End DoDot:1
+11 ;now check Refusals in imm pkg
+12 ;F BGPIMM="7" I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPMU=3
RUBX ;
+1 IF BGPRUB=0
KILL BGPG
SET %=P_"^LAST DX [BGP RUBELLA EVIDENCE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE
SET E=$$START1^APCLDF(%,"BGPG(")
IF $DATA(BGPG(1))
SET BGPRUB=4
SET BGPRUEV=1
+2 ;I $$PLTAX^BGP7DU(P,"BGP RUBELLA EVIDENCE") S BGPRUB=4,BGPRUEV=1
+3 IF $$PLTAXND^BGP7DU(P,"BGP RUBELLA EVIDENCE",EDATE)
SET BGPRUB=4
SET BGPRUEV=1
+4 IF $$IPLSNOND^BGP7DU(P,"PXRM BGP RUBELLA",EDATE)
SET BGPRUB=4
SET BGPRUEV=1
+5 IF BGPRUB=0
Begin DoDot:1
+6 SET B=$$DOB^AUPNPAT(P)
SET E=EDATE
+7 FOR BGPIMM=6
Begin DoDot:2
+8 SET I=$ORDER(^AUTTIMM("C",BGPIMM,0))
IF 'I
QUIT
+9 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,9999999.14,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPRUB=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
+10 FOR BGPIMM=90706
Begin DoDot:2
+11 SET I=+$$CODEN^ICPTCOD(BGPIMM)
IF 'I
QUIT
+12 SET X=0
FOR
SET X=$ORDER(^AUPNPREF("AA",P,81,I,X))
IF X'=+X
QUIT
SET Y=0
FOR
SET Y=$ORDER(^AUPNPREF("AA",P,81,I,X,Y))
IF Y'=+Y
QUIT
SET D=$PIECE(^AUPNPREF(Y,0),U,3)
IF D'<B&(D'>E)
SET BGPRUB=$SELECT($PIECE(^AUPNPREF(Y,0),U,7)="N":4,1:"")
End DoDot:2
End DoDot:1
+13 ;F BGPIMM=6 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPRUB=3
+14 IF BGPMR
IF BGPMU
SET X=1
IF BGPMR=3
SET X=3
IF BGPMU=3
SET X=3
IF BGPMR=4
SET X=4
IF BGPMU=4
SET X=4
QUIT X_U_"mr & mu"_$SELECT(BGPMUEV:" (Evid)",1:"")_$SELECT(X=4:" NMI",X=3:" Ref",1:"")
+15 IF BGPRM
IF BGPME
SET X=1
IF BGPRM=3
SET X=3
IF BGPME=3
SET X=3
IF BGPRM=4
SET X=4
IF BGPME=4
SET X=4
QUIT X_U_"RM & ME"_$SELECT(BGPMEEV:" (Evid)",1:"")_$SELECT(X=4:" NMI",X=3:" Ref",1:"")
+16 IF BGPME
IF BGPMU
IF BGPRUB
Begin DoDot:1
+17 SET X=1
IF BGPME=3
SET X=3
IF BGPMU=3
SET X=3
IF BGPRUB=3
SET X=3
IF BGPME=4
SET X=4
IF BGPMU=4
SET X=4
IF BGPRUB=4
SET X=4
End DoDot:1
QUIT X_U_"ME"_$SELECT(BGPMEEV:" (Evid)",1:"")_"&MU"_$SELECT(BGPMUEV:" (Evid)",1:"")_"&RUB"_$SELECT(BGPRUEV:" (Evid)",1:"")_$SELECT(X=4:" NMI",X=3:" Ref",1:"")
+18 QUIT ""
90707 ;;
90710 ;;
90708 ;;
90709 ;;
90705 ;;
90704 ;;
90706 ;;