BGP3D61 ; IHS/CMI/LAB - measure 31 01 Jul 2010 7:47 PM ;
;;13.0;IHS CLINICAL REPORTING;;NOV 20, 2012;Build 81
;
I17 ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
I BGPAGEB<51 S BGPSTOP=1 Q
I BGPAGEB>80 S BGPSTOP=1 Q
I $$CRC(DFN,BGPEDATE) S BGPSTOP=1 Q ;has colorectal cancer
I BGPACTUP S BGPD1=1
I BGPACTCL S BGPD2=1
I 'BGPD1 S BGPSTOP=1 Q ;need to be at least in user pop
CRCP ;EP - called from elder
S BGPFOB=$$FOB(DFN,BGPBDATE,BGPEDATE)
I BGPFOB]"" S BGPN3=1,BGPN1=1
S BGPOTH=""
I BGPN1=0 S BGPOTH=$$IBH(DFN,BGPEDATE)
I BGPOTH]"" S BGPN1=1
S BGPSIG=$$SIG(DFN,BGPEDATE)
S BGPCOLO=$$COLO(DFN,BGPEDATE)
S BGPBE=$$BE(DFN,BGPEDATE)
I BGPSIG]""!(BGPBE]"")!(BGPCOLO]"") S BGPN4=1
I BGPSIG]""!(BGPCOLO]"") S BGPN5=1
I BGPSIG]""&(BGPBE]"")!(BGPCOLO]"") S BGPN6=1
S BGPREF="" I 'BGPN1 S BGPREF=$$REF(DFN,$$FMADD^XLFDT(BGPEDATE,-365),BGPEDATE) I BGPREF S BGPN1=1,BGPN2=1
I BGPN1,'BGPN2 S BGPN7=1
S BGPVALUE=""
I BGPFOB]"" S BGPVALUE="FOB: "_$$DATE^BGP3UTL($P(BGPFOB,U,2))_" "_$P(BGPFOB,U)
;I BGPOTH]"" S BGPVALUE=BGPVALUE_$P(BGPOTH,U)_":"_$P(BGPOTH,U,2)_" "
I BGPSIG]"" S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"") S BGPVALUE=BGPVALUE_"SIG: "_$P(BGPSIG,U,2)_" "_$P(BGPSIG,U,1)
I BGPCOLO]"" S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"") S BGPVALUE=BGPVALUE_"COLO: "_$P(BGPCOLO,U,2)_" "_$P(BGPCOLO,U,1)
I BGPBE]"" S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"") S BGPVALUE=BGPVALUE_"BE: "_$P(BGPBE,U,2)_" "_$P(BGPBE,U,1)
I BGPREF]"" S BGPVALUE=BGPVALUE_$S(BGPVALUE]"":"; ",1:"") S BGPVALUE=BGPVALUE_$$DATE^BGP3UTL($P(BGPREF,U,2))_" "_$P(BGPREF,U,3)
S BGPDV=$S(BGPD1:"UP",1:"")_$S(BGPD2:",AC",1:"")
I BGPRTYPE'=1 S BGPVALUE=BGPDV_"|||"_BGPVALUE
I BGPRTYPE=1 S BGPDV=BGPDV_"|||" S:BGPN7 BGPVALUE=BGPDV_BGPVALUE S:'BGPN7 BGPVALUE=BGPDV
K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P
Q
IBH(P,EDATE) ;EP
NEW VALUE
S VALUE=""
S VALUE=$$SIG(P,EDATE)
I VALUE]"" Q VALUE
S VALUE=$$BE(P,EDATE)
I VALUE]"" Q VALUE
S VALUE=$$COLO(P,EDATE)
I VALUE]"" Q VALUE
Q ""
CRC(P,EDATE) ;EP
K BGPG
S Y="BGPG("
S X=P_"^LAST DX [BGP COLORECTAL CANCER DXS;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) Q 1 ;has a dx
S T=$O(^ATXAX("B","BGP COLORECTAL CANCER CPTS",0))
I T D I X]"" Q 1
.S X=$$CPT^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
S BGPG=$$LASTPRC^BGP3UTL1(P,"BGP TOTAL COLECTOMY PROCS",$$DOB^AUPNPAT(P),EDATE)
I BGPG Q 1
S T=$O(^ATXAX("B","BGP TOTAL COLECTOMY CPTS",0))
I T D I X]"" Q 1
.S X=$$CPT^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
Q 0
SIG(P,EDATE,BDATE) ;EP
NEW BGPLSIG,BGPG,T,X
S BGPLSIG=""
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,5*(-365))
S BGPG=$$LASTPRC^BGP3UTL1(P,"BGP SIG PROCS",BDATE,EDATE)
I $P(BGPG,U)=1 S BGPLSIG="Proc "_$P(BGPG,U,2)_"^"_$$DATE^BGP3UTL($P(BGPG,U,3))_U_$P(BGPG,U,3)
;
S T=$O(^ATXAX("B","BGP SIG CPTS",0))
I T D I X]"",$P(BGPLSIG,U,3)<$P(X,U,1) S BGPLSIG="CPT "_$P(X,U,2)_U_$$DATE^BGP3UTL($P(X,U,1))_U_$P(X,U,1)
.S X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,BDATE,EDATE,T,5)
Q BGPLSIG
COLO(P,EDATE,BDATE) ;EP
NEW BGPG,BGPLCOLO,%,T,X
K BGPG
S BGPLCOLO=""
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,10*(-365))
S BGPG=$$LASTPRC^BGP3UTL1(P,"BGP COLO PROCS",BDATE,EDATE)
I $P(BGPG,U)=1 S BGPLCOLO="Proc "_$P(BGPG,U,2)_"^"_$$DATE^BGP3UTL($P(BGPG,U,3))_U_$P(BGPG,U,3)
S %=P_"^LAST DIAGNOSIS [BGP COLO DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,"BGPG(")
I $D(BGPG(1)),$P(BGPLCOLO,U,3)<$P(BGPG(1),U,1) S BGPLCOLO="POV "_$P(BGPG(1),U,2)_"^"_$$DATE^BGP3UTL($P(BGPG(1),U))
S T=$O(^ATXAX("B","BGP COLO CPTS",0))
I T D I X]"",$P(BGPLCOLO,U,3)<$P(X,U,1) S BGPLCOLO="CPT "_$P(X,U,2)_U_$$DATE^BGP3UTL($P(X,U,1))_U_$P(X,U,1)
.S X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,BDATE,EDATE,T,5)
Q BGPLCOLO
FOB(P,BDATE,EDATE) ;EP
NEW BGPC,BGPLFOB,BGPLT,B,E,D,L,X,T
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,2*(-365))
S BGPC="",BGPLFOB=""
S T=$O(^ATXAX("B","BGP FOBT LOINC CODES",0))
S BGPLT=$O(^ATXLAB("B","BGP GPRA FOB TESTS",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))
...I BGPLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(BGPLT,21,"B",$P(^AUPNVLAB(X,0),U))) S BGPC="LAB"_U_(9999999-D) Q
...Q:'T
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,T)
...S BGPC="LOINC"_U_(9999999-D) Q
...Q
S BGPLFOB=BGPC
S T=$O(^ATXAX("B","BGP FOBT CPTS",0))
I T D I X]"",$P(BGPLFOB,U,2)<$P(X,U,1) S BGPLFOB="CPT "_$P(X,"^",2)_"^"_$P(X,U,1)
.S X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5) I X]"" Q
Q BGPLFOB
BE(P,EDATE,BDATE) ;EP
NEW BGPLBE,T,X
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,5*(-365))
S BGPLBE=""
S T=$O(^ATXAX("B","BGP BE CPTS",0))
I T D I X]"" S BGPLBE="CPT "_$P(X,U,2)_U_$$DATE^BGP3UTL($P(X,U,1))_U_$P(X,U,1)
.S X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP3DU(P,BDATE,EDATE,T,5)
.Q
S T=$O(^ATXAX("B","BGP BE CPTS",0))
I T D I X]"",$P(BGPLBE,U,3)<X Q "RAD "_$P(X,U,2)_U_$$DATE^BGP3UTL(X)_U_X
.S X=$$RAD^BGP3DU(P,BDATE,EDATE,T,5)
.Q
Q BGPLBE
;
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 ""
REF(P,BDATE,EDATE) ;EP
;Refusal
S BGPT=$O(^ATXLAB("B","BGP GPRA FOB TESTS",0))
I BGPT D I $P(G,U) Q "1^"_$P(G,U,2)_U_"FOB: Refused Lab "
.S (G,BGPT1)=0 F S BGPT1=$O(^ATXLAB(BGPT,21,"B",BGPT1)) Q:BGPT1=""!($P(G,U)) D
..S G=$$REFUSAL^BGP3UTL1(P,60,BGPT1,BDATE,EDATE)
F BGPT=82270,82274,89205,"G0107","G0328","G0394" D Q:$P(T,U)=1
.S C=+$$CODEN^ICPTCOD(BGPT) Q:C'>0
.S T=""
.S T=$$REFUSAL^BGP3UTL1(P,81,+$$CODEN^ICPTCOD(BGPT),$$FMADD^XLFDT(EDATE,-365),EDATE)
.I T S T="1^"_$P(T,U,2)_"^FOB: Refused CPT"
I $P(T,U)=1 Q T
S BGPT=$O(^ATXAX("B","BGP SIG CPTS",0))
I BGPT S G=$$RADREF^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"SIG: Refused CPT"
;S BGPT=$O(^ATXAX("B","BGP BE CPTS",0))
;I BGPT S G=$$RADREF^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"BE: Refused CPT"
S BGPT=$O(^ATXAX("B","BGP COLO CPTS",0))
I BGPT S G=$$RADREF^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"COLO: Refused CPT"
S BGPT=$O(^ATXAX("B","BGP SIG CPTS",0))
I BGPT S G=$$CPTREFT^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"SIG: Refused CPT"
;S BGPT=$O(^ATXAX("B","BGP BE CPTS",0))
;I BGPT S G=$$CPTREFT^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"BE: Refused CPT"
S BGPT=$O(^ATXAX("B","BGP COLO CPTS",0))
I BGPT S G=$$CPTREFT^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"COLO: Refused CPT"
S T=$$PRCREFT^BGP3UTL1(P,BDATE,EDATE,$O(^ATXAX("B","BGP COLO/SIG PROCS",0)))
;F BGPT=45.24,45.42,45.22,45.23,45.25,45.43 D Q:$P(T,U)=1
I T Q "1^"_$P(T,U,2)_"^"_$S($P(T,U,4)="45.24":"SIG: ",1:"COLO: ")_"Refused Proc"
Q ""
BGP3D61 ; IHS/CMI/LAB - measure 31 01 Jul 2010 7:47 PM ;
+1 ;;13.0;IHS CLINICAL REPORTING;;NOV 20, 2012;Build 81
+2 ;
I17 ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+2 IF BGPAGEB<51
SET BGPSTOP=1
QUIT
+3 IF BGPAGEB>80
SET BGPSTOP=1
QUIT
+4 ;has colorectal cancer
IF $$CRC(DFN,BGPEDATE)
SET BGPSTOP=1
QUIT
+5 IF BGPACTUP
SET BGPD1=1
+6 IF BGPACTCL
SET BGPD2=1
+7 ;need to be at least in user pop
IF 'BGPD1
SET BGPSTOP=1
QUIT
CRCP ;EP - called from elder
+1 SET BGPFOB=$$FOB(DFN,BGPBDATE,BGPEDATE)
+2 IF BGPFOB]""
SET BGPN3=1
SET BGPN1=1
+3 SET BGPOTH=""
+4 IF BGPN1=0
SET BGPOTH=$$IBH(DFN,BGPEDATE)
+5 IF BGPOTH]""
SET BGPN1=1
+6 SET BGPSIG=$$SIG(DFN,BGPEDATE)
+7 SET BGPCOLO=$$COLO(DFN,BGPEDATE)
+8 SET BGPBE=$$BE(DFN,BGPEDATE)
+9 IF BGPSIG]""!(BGPBE]"")!(BGPCOLO]"")
SET BGPN4=1
+10 IF BGPSIG]""!(BGPCOLO]"")
SET BGPN5=1
+11 IF BGPSIG]""&(BGPBE]"")!(BGPCOLO]"")
SET BGPN6=1
+12 SET BGPREF=""
IF 'BGPN1
SET BGPREF=$$REF(DFN,$$FMADD^XLFDT(BGPEDATE,-365),BGPEDATE)
IF BGPREF
SET BGPN1=1
SET BGPN2=1
+13 IF BGPN1
IF 'BGPN2
SET BGPN7=1
+14 SET BGPVALUE=""
+15 IF BGPFOB]""
SET BGPVALUE="FOB: "_$$DATE^BGP3UTL($PIECE(BGPFOB,U,2))_" "_$PIECE(BGPFOB,U)
+16 ;I BGPOTH]"" S BGPVALUE=BGPVALUE_$P(BGPOTH,U)_":"_$P(BGPOTH,U,2)_" "
+17 IF BGPSIG]""
SET BGPVALUE=BGPVALUE_$SELECT(BGPVALUE]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"SIG: "_$PIECE(BGPSIG,U,2)_" "_$PIECE(BGPSIG,U,1)
+18 IF BGPCOLO]""
SET BGPVALUE=BGPVALUE_$SELECT(BGPVALUE]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"COLO: "_$PIECE(BGPCOLO,U,2)_" "_$PIECE(BGPCOLO,U,1)
+19 IF BGPBE]""
SET BGPVALUE=BGPVALUE_$SELECT(BGPVALUE]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_"BE: "_$PIECE(BGPBE,U,2)_" "_$PIECE(BGPBE,U,1)
+20 IF BGPREF]""
SET BGPVALUE=BGPVALUE_$SELECT(BGPVALUE]"":"; ",1:"")
SET BGPVALUE=BGPVALUE_$$DATE^BGP3UTL($PIECE(BGPREF,U,2))_" "_$PIECE(BGPREF,U,3)
+21 SET BGPDV=$SELECT(BGPD1:"UP",1:"")_$SELECT(BGPD2:",AC",1:"")
+22 IF BGPRTYPE'=1
SET BGPVALUE=BGPDV_"|||"_BGPVALUE
+23 IF BGPRTYPE=1
SET BGPDV=BGPDV_"|||"
IF BGPN7
SET BGPVALUE=BGPDV_BGPVALUE
IF 'BGPN7
SET BGPVALUE=BGPDV
+24 KILL X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P
+25 QUIT
IBH(P,EDATE) ;EP
+1 NEW VALUE
+2 SET VALUE=""
+3 SET VALUE=$$SIG(P,EDATE)
+4 IF VALUE]""
QUIT VALUE
+5 SET VALUE=$$BE(P,EDATE)
+6 IF VALUE]""
QUIT VALUE
+7 SET VALUE=$$COLO(P,EDATE)
+8 IF VALUE]""
QUIT VALUE
+9 QUIT ""
CRC(P,EDATE) ;EP
+1 KILL BGPG
+2 SET Y="BGPG("
+3 SET X=P_"^LAST DX [BGP COLORECTAL CANCER DXS;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+4 ;has a dx
IF $DATA(BGPG(1))
QUIT 1
+5 SET T=$ORDER(^ATXAX("B","BGP COLORECTAL CANCER CPTS",0))
+6 IF T
Begin DoDot:1
+7 SET X=$$CPT^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
IF X]""
QUIT
+8 SET X=$$TRAN^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
End DoDot:1
IF X]""
QUIT 1
+9 SET BGPG=$$LASTPRC^BGP3UTL1(P,"BGP TOTAL COLECTOMY PROCS",$$DOB^AUPNPAT(P),EDATE)
+10 IF BGPG
QUIT 1
+11 SET T=$ORDER(^ATXAX("B","BGP TOTAL COLECTOMY CPTS",0))
+12 IF T
Begin DoDot:1
+13 SET X=$$CPT^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
IF X]""
QUIT
+14 SET X=$$TRAN^BGP3DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
End DoDot:1
IF X]""
QUIT 1
+15 QUIT 0
SIG(P,EDATE,BDATE) ;EP
+1 NEW BGPLSIG,BGPG,T,X
+2 SET BGPLSIG=""
+3 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,5*(-365))
+4 SET BGPG=$$LASTPRC^BGP3UTL1(P,"BGP SIG PROCS",BDATE,EDATE)
+5 IF $PIECE(BGPG,U)=1
SET BGPLSIG="Proc "_$PIECE(BGPG,U,2)_"^"_$$DATE^BGP3UTL($PIECE(BGPG,U,3))_U_$PIECE(BGPG,U,3)
+6 ;
+7 SET T=$ORDER(^ATXAX("B","BGP SIG CPTS",0))
+8 IF T
Begin DoDot:1
+9 SET X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5)
IF X]""
QUIT
+10 SET X=$$TRAN^BGP3DU(P,BDATE,EDATE,T,5)
End DoDot:1
IF X]""
IF $PIECE(BGPLSIG,U,3)<$PIECE(X,U,1)
SET BGPLSIG="CPT "_$PIECE(X,U,2)_U_$$DATE^BGP3UTL($PIECE(X,U,1))_U_$PIECE(X,U,1)
+11 QUIT BGPLSIG
COLO(P,EDATE,BDATE) ;EP
+1 NEW BGPG,BGPLCOLO,%,T,X
+2 KILL BGPG
+3 SET BGPLCOLO=""
+4 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,10*(-365))
+5 SET BGPG=$$LASTPRC^BGP3UTL1(P,"BGP COLO PROCS",BDATE,EDATE)
+6 IF $PIECE(BGPG,U)=1
SET BGPLCOLO="Proc "_$PIECE(BGPG,U,2)_"^"_$$DATE^BGP3UTL($PIECE(BGPG,U,3))_U_$PIECE(BGPG,U,3)
+7 SET %=P_"^LAST DIAGNOSIS [BGP COLO DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(%,"BGPG(")
+8 IF $DATA(BGPG(1))
IF $PIECE(BGPLCOLO,U,3)<$PIECE(BGPG(1),U,1)
SET BGPLCOLO="POV "_$PIECE(BGPG(1),U,2)_"^"_$$DATE^BGP3UTL($PIECE(BGPG(1),U))
+9 SET T=$ORDER(^ATXAX("B","BGP COLO CPTS",0))
+10 IF T
Begin DoDot:1
+11 SET X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5)
IF X]""
QUIT
+12 SET X=$$TRAN^BGP3DU(P,BDATE,EDATE,T,5)
End DoDot:1
IF X]""
IF $PIECE(BGPLCOLO,U,3)<$PIECE(X,U,1)
SET BGPLCOLO="CPT "_$PIECE(X,U,2)_U_$$DATE^BGP3UTL($PIECE(X,U,1))_U_$PIECE(X,U,1)
+13 QUIT BGPLCOLO
FOB(P,BDATE,EDATE) ;EP
+1 NEW BGPC,BGPLFOB,BGPLT,B,E,D,L,X,T
+2 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,2*(-365))
+3 SET BGPC=""
SET BGPLFOB=""
+4 SET T=$ORDER(^ATXAX("B","BGP FOBT LOINC CODES",0))
+5 SET BGPLT=$ORDER(^ATXLAB("B","BGP GPRA FOB TESTS",0))
+6 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
+7 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L!(BGPC]"")
QUIT
Begin DoDot:2
+8 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X!(BGPC]"")
QUIT
Begin DoDot:3
+9 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+10 IF BGPLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(BGPLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET BGPC="LAB"_U_(9999999-D)
QUIT
+11 IF 'T
QUIT
+12 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+13 IF '$$LOINC(J,T)
QUIT
+14 SET BGPC="LOINC"_U_(9999999-D)
QUIT
+15 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+16 SET BGPLFOB=BGPC
+17 SET T=$ORDER(^ATXAX("B","BGP FOBT CPTS",0))
+18 IF T
Begin DoDot:1
+19 SET X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5)
IF X]""
QUIT
End DoDot:1
IF X]""
IF $PIECE(BGPLFOB,U,2)<$PIECE(X,U,1)
SET BGPLFOB="CPT "_$PIECE(X,"^",2)_"^"_$PIECE(X,U,1)
+20 QUIT BGPLFOB
BE(P,EDATE,BDATE) ;EP
+1 NEW BGPLBE,T,X
+2 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,5*(-365))
+3 SET BGPLBE=""
+4 SET T=$ORDER(^ATXAX("B","BGP BE CPTS",0))
+5 IF T
Begin DoDot:1
+6 SET X=$$CPT^BGP3DU(P,BDATE,EDATE,T,5)
IF X]""
QUIT
+7 SET X=$$TRAN^BGP3DU(P,BDATE,EDATE,T,5)
+8 QUIT
End DoDot:1
IF X]""
SET BGPLBE="CPT "_$PIECE(X,U,2)_U_$$DATE^BGP3UTL($PIECE(X,U,1))_U_$PIECE(X,U,1)
+9 SET T=$ORDER(^ATXAX("B","BGP BE CPTS",0))
+10 IF T
Begin DoDot:1
+11 SET X=$$RAD^BGP3DU(P,BDATE,EDATE,T,5)
+12 QUIT
End DoDot:1
IF X]""
IF $PIECE(BGPLBE,U,3)<X
QUIT "RAD "_$PIECE(X,U,2)_U_$$DATE^BGP3UTL(X)_U_X
+13 QUIT BGPLBE
+14 ;
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 ""
REF(P,BDATE,EDATE) ;EP
+1 ;Refusal
+2 SET BGPT=$ORDER(^ATXLAB("B","BGP GPRA FOB TESTS",0))
+3 IF BGPT
Begin DoDot:1
+4 SET (G,BGPT1)=0
FOR
SET BGPT1=$ORDER(^ATXLAB(BGPT,21,"B",BGPT1))
IF BGPT1=""!($PIECE(G,U))
QUIT
Begin DoDot:2
+5 SET G=$$REFUSAL^BGP3UTL1(P,60,BGPT1,BDATE,EDATE)
End DoDot:2
End DoDot:1
IF $PIECE(G,U)
QUIT "1^"_$PIECE(G,U,2)_U_"FOB: Refused Lab "
+6 FOR BGPT=82270,82274,89205,"G0107","G0328","G0394"
Begin DoDot:1
+7 SET C=+$$CODEN^ICPTCOD(BGPT)
IF C'>0
QUIT
+8 SET T=""
+9 SET T=$$REFUSAL^BGP3UTL1(P,81,+$$CODEN^ICPTCOD(BGPT),$$FMADD^XLFDT(EDATE,-365),EDATE)
+10 IF T
SET T="1^"_$PIECE(T,U,2)_"^FOB: Refused CPT"
End DoDot:1
IF $PIECE(T,U)=1
QUIT
+11 IF $PIECE(T,U)=1
QUIT T
+12 SET BGPT=$ORDER(^ATXAX("B","BGP SIG CPTS",0))
+13 IF BGPT
SET G=$$RADREF^BGP3UTL1(P,BDATE,EDATE,BGPT)
IF $PIECE(G,U,1)=1
QUIT 1_"^"_$PIECE(G,U,2)_"^"_"SIG: Refused CPT"
+14 ;S BGPT=$O(^ATXAX("B","BGP BE CPTS",0))
+15 ;I BGPT S G=$$RADREF^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"BE: Refused CPT"
+16 SET BGPT=$ORDER(^ATXAX("B","BGP COLO CPTS",0))
+17 IF BGPT
SET G=$$RADREF^BGP3UTL1(P,BDATE,EDATE,BGPT)
IF $PIECE(G,U,1)=1
QUIT 1_"^"_$PIECE(G,U,2)_"^"_"COLO: Refused CPT"
+18 SET BGPT=$ORDER(^ATXAX("B","BGP SIG CPTS",0))
+19 IF BGPT
SET G=$$CPTREFT^BGP3UTL1(P,BDATE,EDATE,BGPT)
IF $PIECE(G,U,1)=1
QUIT 1_"^"_$PIECE(G,U,2)_"^"_"SIG: Refused CPT"
+20 ;S BGPT=$O(^ATXAX("B","BGP BE CPTS",0))
+21 ;I BGPT S G=$$CPTREFT^BGP3UTL1(P,BDATE,EDATE,BGPT) I $P(G,U,1)=1 Q 1_"^"_$P(G,U,2)_"^"_"BE: Refused CPT"
+22 SET BGPT=$ORDER(^ATXAX("B","BGP COLO CPTS",0))
+23 IF BGPT
SET G=$$CPTREFT^BGP3UTL1(P,BDATE,EDATE,BGPT)
IF $PIECE(G,U,1)=1
QUIT 1_"^"_$PIECE(G,U,2)_"^"_"COLO: Refused CPT"
+24 SET T=$$PRCREFT^BGP3UTL1(P,BDATE,EDATE,$ORDER(^ATXAX("B","BGP COLO/SIG PROCS",0)))
+25 ;F BGPT=45.24,45.42,45.22,45.23,45.25,45.43 D Q:$P(T,U)=1
+26 IF T
QUIT "1^"_$PIECE(T,U,2)_"^"_$SELECT($PIECE(T,U,4)="45.24":"SIG: ",1:"COLO: ")_"Refused Proc"
+27 QUIT ""