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

BGP7D33.m

Go to the documentation of this file.
BGP7D33 ; IHS/CMI/LAB - measure C ;
 ;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
 ;
OPV(P,EDATE) ;EP
 K BGPC,BGPG,BGPX
 ;gather up all immunizations, cpts, povs and check for 3 each ten days apart
 K BGPOPV,BGPAPOV
 ;get all immunizations
 S C="2^89^10^110^120^130^132^146"
 K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
 ;go through and set into array if 10 days apart
 S X=0 F  S X=$O(BGPX(X)) Q:X'=+X  S BGPOPV(X)="",BGPAPOV(X)=""
 ;now get cpts
 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=90712!(Y=90698)!(Y=90711)!(Y=90713)!(Y=90723)!(Y=90696)!(Y=90697) S BGPOPV(9999999-$P(ED,"."))="",BGPAPOV(9999999-$P(ED,"."))=""
 ..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=90712!(Y=90698)!(Y=90711)!(Y=90713)!(Y=90723)!(Y=90696)!(Y=90697) S BGPOPV(9999999-$P(ED,"."))="",BGPAPOV(9999999-$P(ED,"."))=""
 ;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(BGPOPV(X)) Q:X'=+X  S C=C+1 D
 .I C=1 S Y=X Q
 .I $$FMDIFF^XLFDT(X,Y)<11 K BGPOPV(X) Q
 .S Y=X
 ;now count them and see if there are 4 of them
 S BGPOPV=0,X=0 F  S X=$O(BGPOPV(X)) Q:X'=+X  S BGPOPV=BGPOPV+1
 I BGPOPV>2 Q 1_U_"3 Polio"
 ;now get povs
 K BGPPOV M BGPPOV=BGPAPOV
 K BGPG S %=P_"^ALL DX [BGP IPV IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 I $D(BGPG(1)) S X=0 F  S X=$O(BGPG(X)) Q:X'=+X  S BGPOPV($P(BGPG(X),U))="",BGPAOPV($P(BGPG(X),U))=""
 K BGPG ;D SETPRC^BGP7UTL1(P,$$DOB^AUPNPAT(P),EDATE,"BGP IPV IZ PROCS",.BGPG)
 ;I $D(BGPG(1)) S X=0 F  S X=$O(BGPG(X)) Q:X'=+X  S BGPOPV($P(BGPG(X),U))="",BGPAPOV($P(BGPG(X),U))=""
 ;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(BGPOPV(X)) Q:X'=+X  S C=C+1 D
 .I C=1 S Y=X Q
 .I $$FMDIFF^XLFDT(X,Y)<11 K BGPOPV(X) Q
 .S Y=X
 ;now count them and see if there are 4 of them
 S BGPOPV=0,X=0 F  S X=$O(BGPOPV(X)) Q:X'=+X  S BGPOPV=BGPOPV+1
 I BGPOPV>2 Q 2_U_"3 Polio"
 ;check for Evidence of desease and Contraindications and if yes, then quit
 K BGPG S %=P_"^LAST DX [BGP OPV EVID DISEASE;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 I $D(BGPG(1)) Q 4_U_"Evid Polio"
 I $$PLTAXND^BGP7DU(P,"BGP OPV EVID DISEASE",EDATE) Q 4_U_"Evid Polio"
 I $$IPLSNOND^BGP7DU(P,"PXRM BGP POLIO",EDATE) Q 4_U_"Evid Polio"
 ;K BGPG S %=P_"^LAST DX [BGP OPV CONTRAINDICATIONS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 ;I $D(BGPG(1)) Q 4_U_"Contra Polio"
 ;I $$PLTAX^BGP7DU(P,"BGP OPV CONTRAINDICATONS") Q 4_U_"Contra Polio"
 ;F BGPZ=2,89 S X=$$ANCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 ;I X]"" Q 4_U_"Contra Polio"
 F BGPZ=2,10,89,110,120,130,132,146 S X=$$ANNECONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" Q 4_U_"Contra Polio"
 ;now go to Refusals
 S B=$$DOB^AUPNPAT(P),E=EDATE,BGPNMI="",R=""
 F BGPIMM=2,89,10,110,120,130,132,146 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 Polio",1:"Ref Polio")
 F BGPIMM=90712,90696,90698,90711,90713,90723,90697 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 Polio",1:"Ref Polio")
 ;now check Refusals in imm pkg
 ;F BGPIMM=2,89,10,110,120,130,132,146 S R=$$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE)+R
 ;I R Q 3_U_"Ref Polio"
 Q ""
MMR(P,EDATE) ;EP
 K BGPC,BGPG,BGPX
 K ^TMP($J,"CPT")
 ;first gather up all cpt codes that relate in any way to dtap and store in ^TMP
 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))
 ..Q:'$D(^AUPNVCPT("AD",V))
 ..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-$P(ED,"."),Y)=""
 S BGPMMR=0
 ;get all immunizations
 S C="3^94"
 K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
 I $D(BGPX) Q 1_U_"MMR"
 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=1
 I BGPMMR Q 1_U_"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)
 I $D(BGPX) S BGPMR=1
 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=1
RM ;
 S C=38
 D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
 I $D(BGPX) S BGPRM=1
 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=1
ME S C=5
 K BGPX D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
 I $D(BGPX) S BGPME=1
 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=1
MU S C=7
 D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
 I $D(BGPX) S BGPMU=1
 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=1
RUB S C=6
 D GETIMMS^BGP7D32(P,EDATE,C,.BGPX)
 I $D(BGPX) S BGPRUB=1
 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=1
 I BGPMR,BGPMU Q 1_U_"m/r mu"
 I BGPRM,BGPME Q 1_U_"r/m me"
 I BGPME,BGPMU,BGPRUB Q 1_U_"me mu 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(")
 I $D(BGPG(1)) Q 2_U_"MMR"
 K BGPG ;S BGPG(1)=$$LASTPRC^BGP7UTL1(P,"BGP MMR IZ PROCS",$$DOB^AUPNPAT(P),EDATE)
 ;I BGPG(1)]"" Q 2_U_"MMR"
MEPV ;
 K BGPG S %=P_"^ALL DX [BGP MEASLES IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 I $D(BGPG(1)) S BGPME=1
 K BGPG ;S BGPG(1)=$$LASTPRC^BGP7UTL1(P,"BGP MEASLES IZ PROCS",$$DOB^AUPNPAT(P),EDATE)
 ;I BGPG(1)]"" S BGPME=1
MUPV ;
 K BGPG S %=P_"^ALL DX [BGP MUMPS IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 I $D(BGPG(1)) S BGPMU=1
 K BGPG ;S BGPG(1)=$$LASTPRC^BGP7UTL1(P,"BGP MUMPS IZ PROCS",$$DOB^AUPNPAT(P),EDATE)
 ;I BGPG(1)]"" S BGPMU=1
RUBPV ;
 K BGPG S %=P_"^ALL DX [BGP RUBELLA IZ DXS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 I $D(BGPG(1)) S BGPRUB=1
 K BGPG ;S BGPG(1)=$$LASTPRC^BGP7UTL1(P,"BGP RUBELLA IZ PROCS",$$DOB^AUPNPAT(P),EDATE)
 ;I BGPG(1)]"" S BGPRUB=1
 I BGPMR,BGPMU Q 2_U_"m/r mu"
 I BGPRM,BGPME Q 2_U_"r/m me"
 I BGPME,BGPMU,BGPRUB 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")
 ;now check Refusals in imm pkg
 S R="" ;F BGPIMM=3,94 S R=$$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE)+R
 ;I R Q 3_U_"Ref MMR"
MMRC ;K BGPG S %=P_"^LAST DX [BGP MMR CONTRAINDICATIONS;DURING "_$$DOB^AUPNPAT(P)_"-"_EDATE,E=$$START1^APCLDF(%,"BGPG(")
 ;I $D(BGPG(1)) Q 4_U_"Contra MMR"
 ;I $$PLTAX^BGP7DU(P,"BGP MMR CONTRAINDICATIONS") Q 4_U_"Contra MMR"
 F BGPZ=3,94 S X=$$MMRCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" Q 4_U_"Contra MMR"
MRC ;
 F BGPZ=4 S X=$$ANCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" Q 4_U_"Contra MR"
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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPMR=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 .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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPMR=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 ;now check Refusals in imm pkg
 ;F BGPIMM=4 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPMR=3
RMC ;
 F BGPZ=38 S X=$$ANCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" Q 4_U_"Contra RM"
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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPRM=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 .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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPRM=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 ;F BGPIMM=38 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPRM=3
MEX ;
 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
 ;I $$PLTAX^BGP7DU(P,"BGP MEASLES EVIDENCE") S BGPME=4
 I $$PLTAXND^BGP7DU(P,"BGP MEASLES EVIDENCE",EDATE) S BGPME=4
 I $$IPLSNOND^BGP7DU(P,"PXRM BGP MEASLES",EDATE) S BGPME=4
 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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPME=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 .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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPME=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 ;F BGPIMM=7 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPME=3
 F BGPZ=5 S X=$$MMRCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" S BGPME=4
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
 I $$PLTAX^BGP7DU(P,"BGP MUMPS EVIDENCE") S BGPMU=4
 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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPMU=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 .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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPMU=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 ;now check Refusals in imm pkg
 ;F BGPIMM="7" I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPMU=3
 F BGPZ=7 S X=$$ANCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" S BGPMU=4
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
 ;I $$PLTAX^BGP7DU(P,"BGP RUBELLA EVIDENCE") S BGPRUB=4
 I $$PLTAXND^BGP7DU(P,"BGP RUBELLA EVIDENCE",EDATE) S BGPRUB=4
 I $$IPLSNOND^BGP7DU(P,"PXRM BGP RUBELLA",EDATE) S BGPRUB=4
 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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPRUB=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 .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) I $P(^AUPNPREF(Y,0),U,7)="N" S BGPRUB=$S($P(^AUPNPREF(Y,0),U,7)="N":4,1:3)
 ;F BGPIMM=6 I $$IMMREF^BGP7D32(P,BGPIMM,$$DOB^AUPNPAT(P),EDATE) S BGPRUB=3
 F BGPZ=6 S X=$$ANCONT^BGP7D31(P,BGPZ,EDATE) Q:X]""
 I X]"" S BGPRUB=4
 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_$S(X=4:" NMI",X=3:" Ref",1:"")_" MR & MU"
 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_$S(X=4:" NMI",X=3:" Ref",1:"")_" RM & ME"
 I BGPME,BGPMU,BGPRUB 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 X_U_$S(X=4:" NMI",X=3:" Ref",1:"")_" ME&MU&RUB"  ;_$S(X=4:" NMI",X=3:" Ref",1:"")
 Q ""
90707 ;;
90710 ;;
90708 ;;
90709 ;;
90705 ;;
90704 ;;
90706 ;;