BGP6D64 ; IHS/CMI/LAB - measure 31 01 Jul 2010 7:47 PM ;
;;16.1;IHS CLINICAL REPORTING;;MAR 22, 2016;Build 170
;
ICCS ;EP
S (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
I 'BGPACTCL S BGPSTOP=1 Q ;not active clinical and must be
;
S BGPCERV=$$DEN7(DFN,BGPAGEB,BGPAGEE,BGPSEX,BGPEDATE)
S BGPBREAS=$$DEN8^BGP6D4(DFN,BGPAGEB,BGPAGEE,BGPSEX,BGPEDATE)
S BGPCRCS="" I BGPAGEB>49,BGPAGEB<76,'$$CRC^BGP6D62(DFN,BGPEDATE) S BGPCRCS=1
;if cervical cancer, did they have a pap
S BGPPAP="" I BGPCERV S BGPPAP=$$PAP^BGP6D3(DFN,BGPEDATE,3,1)
I BGPAGEB>29,BGPAGEE<65 S BGPD2=1 ;CAN HAVE HPV/PAP
S BGPPAP6="",BGPHPV=""
I 'BGPPAP,BGPD2 D
.S BGPPAP6=$$PAP^BGP6D3(DFN,BGPEDATE,5)
.S BGPHPV=$$HPV^BGP6D3(DFN,BGPEDATE,5)
.I BGPHPV,BGPPAP6 S BGPN5=1
S BGPMAM="" I BGPBREAS S BGPMAM=$$MAM^BGP6D4(DFN,BGPEDATE,2,1)
S BGPCRC="" I BGPCRCS S BGPCRC=$$CRCS(DFN,BGPBDATE,BGPEDATE)
;W !,BGPCRC
;BGPN1 will be set to 1 if the patient had all eligible screenings
S BGPN1=1
I BGPCERV D
.I BGPPAP Q
.I BGPN5 Q
.S BGPN1=0
I BGPBREAS,BGPMAM="" S BGPN1=0
I BGPCRCS,BGPCRC="" S BGPN1=0
I (BGPCERV+BGPBREAS+BGPCRCS) S BGPD1=1
I 'BGPD1 Q ;not eligible for any
S BGPDV=""
I BGPCERV S BGPDV=BGPDV_$S(BGPDV]"":",",1:"")_"PAP"
I BGPBREAS S BGPDV=BGPDV_$S(BGPDV]"":",MAM",1:"MAM")
I BGPCRCS S BGPDV=BGPDV_$S(BGPDV]"":",CRCS",1:"CRCS")
S BGPVALUE=$S(BGPPAP]"":"PAP: "_$$DATE^BGP6UTL($P(BGPPAP,U,2))_" "_$P(BGPPAP,U,3),1:"")
I BGPVALUE="",BGPPAP6,BGPHPV S BGPVALUE="PAP: "_$$DATE^BGP6UTL($P(BGPPAP6,U,2))_" "_$P(BGPPAP6,U,3)_"; HPV: "_$$DATE^BGP6UTL($P(BGPHPV,U,2))_" "_$P(BGPHPV,U,3)
I BGPMAM]"" S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; " S BGPVALUE=BGPVALUE_$S(BGPMAM]"":"MAM: "_$$DATE^BGP6UTL($P(BGPMAM,U,2))_" "_$P(BGPMAM,U,3),1:"")
I BGPCRC]"" S:BGPVALUE]"" BGPVALUE=BGPVALUE_"; " S BGPVALUE=BGPVALUE_$S(BGPCRC]"":"CRCS: "_$P(BGPCRC,U,2)_" "_$P(BGPCRC,U,1),1:"")
S BGPVALUE=BGPDV_"|||"_BGPVALUE
K X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P
Q
DEN7(P,AGEB,AGEE,SEX,EDATE) ;EP
I SEX'="F" Q 0
I AGEB<24 Q 0
I AGEE>64 Q 0
I $$HYSTER^BGP6D3(P,EDATE) Q 0
Q 1
CRCS(P,BDATE,EDATE) ;
NEW VALUE
S VALUE=""
S VALUE=$$SIG^BGP6D62(P,EDATE)
I VALUE]"" Q VALUE
S VALUE=$$COLO^BGP6D62(P,EDATE)
I VALUE]"" Q VALUE
S VALUE=$$FOB^BGP6D62(P,BDATE,EDATE)
I VALUE]"" Q $P(VALUE,U,1)_"^"_$$DATE^BGP6UTL($P(VALUE,U,2))_"^"_VALUE
Q ""
SIG(P,EDATE,BDATE) ;EP
NEW BGPLSIG
S BGPLSIG=""
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,5*(-365))
S BGPG=$$LASTPRC^BGP6UTL1(P,"BGP SIG PROCS",BDATE,EDATE)
I $P(BGPG,U)=1 S BGPLSIG="SIG "_$P(BGPG,U,2)_"^"_$$DATE^BGP6UTL($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 SIG "_$P(X,U,2)_U_$$DATE^BGP6UTL($P(X,U,1))_U_$P(X,U,1)
.S X=$$CPT^BGP6DU(P,BDATE,EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP6DU(P,BDATE,EDATE,T,5)
Q BGPLSIG
COLO(P,EDATE,BDATE) ;EP
K BGPG
S BGPLCOLO=""
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,10*(-365))
S BGPG=$$LASTPRC^BGP6UTL1(P,"BGP COLO PROCS",BDATE,EDATE)
I $P(BGPG,U)=1 S BGPLCOLO="COLO "_$P(BGPG,U,2)_"^"_$$DATE^BGP6UTL($P(BGPG,U,3))_U_$P(BGPG,U,3)
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 COLO "_$P(X,U,2)_U_$$DATE^BGP6UTL($P(X,U,1))_U_$P(X,U,1)
.S X=$$CPT^BGP6DU(P,BDATE,EDATE,T,5) I X]"" Q
.S X=$$TRAN^BGP6DU(P,BDATE,EDATE,T,5)
Q BGPLCOLO
FOB(P,BDATE,EDATE) ;EP
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="V 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^BGP6DU(P,BDATE,EDATE,T,5) I X]"" Q
S %=P_"^LAST DIAGNOSIS [BGP COLO DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE),E=$$START1^APCLDF(%,"BGPG(")
I $D(BGPG(1)),$P(BGPLFOB,U,2)<$P(BGPG(1),U,1) S BGPLFOB="FOB DX "_$P(BGPG(1),U,2)_"^"_$P(BGPG(1),U)
I BGPLFOB="" Q ""
Q $P(BGPLFOB,U,1)_U_$$DATE^BGP6UTL($P(BGPLFOB,U,2))
;
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 ""
BGP6D64 ; IHS/CMI/LAB - measure 31 01 Jul 2010 7:47 PM ;
+1 ;;16.1;IHS CLINICAL REPORTING;;MAR 22, 2016;Build 170
+2 ;
ICCS ;EP
+1 SET (BGPN1,BGPN2,BGPN3,BGPN4,BGPN5,BGPN6,BGPN7,BGPD1,BGPD2,BGPD3,BGPD4,BGPD5,BGPD6,BGPD7,BGPD8,BGPD9)=0
+2 ;not active clinical and must be
IF 'BGPACTCL
SET BGPSTOP=1
QUIT
+3 ;
+4 SET BGPCERV=$$DEN7(DFN,BGPAGEB,BGPAGEE,BGPSEX,BGPEDATE)
+5 SET BGPBREAS=$$DEN8^BGP6D4(DFN,BGPAGEB,BGPAGEE,BGPSEX,BGPEDATE)
+6 SET BGPCRCS=""
IF BGPAGEB>49
IF BGPAGEB<76
IF '$$CRC^BGP6D62(DFN,BGPEDATE)
SET BGPCRCS=1
+7 ;if cervical cancer, did they have a pap
+8 SET BGPPAP=""
IF BGPCERV
SET BGPPAP=$$PAP^BGP6D3(DFN,BGPEDATE,3,1)
+9 ;CAN HAVE HPV/PAP
IF BGPAGEB>29
IF BGPAGEE<65
SET BGPD2=1
+10 SET BGPPAP6=""
SET BGPHPV=""
+11 IF 'BGPPAP
IF BGPD2
Begin DoDot:1
+12 SET BGPPAP6=$$PAP^BGP6D3(DFN,BGPEDATE,5)
+13 SET BGPHPV=$$HPV^BGP6D3(DFN,BGPEDATE,5)
+14 IF BGPHPV
IF BGPPAP6
SET BGPN5=1
End DoDot:1
+15 SET BGPMAM=""
IF BGPBREAS
SET BGPMAM=$$MAM^BGP6D4(DFN,BGPEDATE,2,1)
+16 SET BGPCRC=""
IF BGPCRCS
SET BGPCRC=$$CRCS(DFN,BGPBDATE,BGPEDATE)
+17 ;W !,BGPCRC
+18 ;BGPN1 will be set to 1 if the patient had all eligible screenings
+19 SET BGPN1=1
+20 IF BGPCERV
Begin DoDot:1
+21 IF BGPPAP
QUIT
+22 IF BGPN5
QUIT
+23 SET BGPN1=0
End DoDot:1
+24 IF BGPBREAS
IF BGPMAM=""
SET BGPN1=0
+25 IF BGPCRCS
IF BGPCRC=""
SET BGPN1=0
+26 IF (BGPCERV+BGPBREAS+BGPCRCS)
SET BGPD1=1
+27 ;not eligible for any
IF 'BGPD1
QUIT
+28 SET BGPDV=""
+29 IF BGPCERV
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",",1:"")_"PAP"
+30 IF BGPBREAS
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",MAM",1:"MAM")
+31 IF BGPCRCS
SET BGPDV=BGPDV_$SELECT(BGPDV]"":",CRCS",1:"CRCS")
+32 SET BGPVALUE=$SELECT(BGPPAP]"":"PAP: "_$$DATE^BGP6UTL($PIECE(BGPPAP,U,2))_" "_$PIECE(BGPPAP,U,3),1:"")
+33 IF BGPVALUE=""
IF BGPPAP6
IF BGPHPV
SET BGPVALUE="PAP: "_$$DATE^BGP6UTL($PIECE(BGPPAP6,U,2))_" "_$PIECE(BGPPAP6,U,3)_"; HPV: "_$$DATE^BGP6UTL($PIECE(BGPHPV,U,2))_" "_$PIECE(BGPHPV,U,3)
+34 IF BGPMAM]""
IF BGPVALUE]""
SET BGPVALUE=BGPVALUE_"; "
SET BGPVALUE=BGPVALUE_$SELECT(BGPMAM]"":"MAM: "_$$DATE^BGP6UTL($PIECE(BGPMAM,U,2))_" "_$PIECE(BGPMAM,U,3),1:"")
+35 IF BGPCRC]""
IF BGPVALUE]""
SET BGPVALUE=BGPVALUE_"; "
SET BGPVALUE=BGPVALUE_$SELECT(BGPCRC]"":"CRCS: "_$PIECE(BGPCRC,U,2)_" "_$PIECE(BGPCRC,U,1),1:"")
+36 SET BGPVALUE=BGPDV_"|||"_BGPVALUE
+37 KILL X,Y,Z,%,A,B,C,D,E,H,BDATE,EDATE,P
+38 QUIT
DEN7(P,AGEB,AGEE,SEX,EDATE) ;EP
+1 IF SEX'="F"
QUIT 0
+2 IF AGEB<24
QUIT 0
+3 IF AGEE>64
QUIT 0
+4 IF $$HYSTER^BGP6D3(P,EDATE)
QUIT 0
+5 QUIT 1
CRCS(P,BDATE,EDATE) ;
+1 NEW VALUE
+2 SET VALUE=""
+3 SET VALUE=$$SIG^BGP6D62(P,EDATE)
+4 IF VALUE]""
QUIT VALUE
+5 SET VALUE=$$COLO^BGP6D62(P,EDATE)
+6 IF VALUE]""
QUIT VALUE
+7 SET VALUE=$$FOB^BGP6D62(P,BDATE,EDATE)
+8 IF VALUE]""
QUIT $PIECE(VALUE,U,1)_"^"_$$DATE^BGP6UTL($PIECE(VALUE,U,2))_"^"_VALUE
+9 QUIT ""
SIG(P,EDATE,BDATE) ;EP
+1 NEW BGPLSIG
+2 SET BGPLSIG=""
+3 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,5*(-365))
+4 SET BGPG=$$LASTPRC^BGP6UTL1(P,"BGP SIG PROCS",BDATE,EDATE)
+5 IF $PIECE(BGPG,U)=1
SET BGPLSIG="SIG "_$PIECE(BGPG,U,2)_"^"_$$DATE^BGP6UTL($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^BGP6DU(P,BDATE,EDATE,T,5)
IF X]""
QUIT
+10 SET X=$$TRAN^BGP6DU(P,BDATE,EDATE,T,5)
End DoDot:1
IF X]""
IF $PIECE(BGPLSIG,U,3)<$PIECE(X,U,1)
SET BGPLSIG="CPT SIG "_$PIECE(X,U,2)_U_$$DATE^BGP6UTL($PIECE(X,U,1))_U_$PIECE(X,U,1)
+11 QUIT BGPLSIG
COLO(P,EDATE,BDATE) ;EP
+1 KILL BGPG
+2 SET BGPLCOLO=""
+3 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,10*(-365))
+4 SET BGPG=$$LASTPRC^BGP6UTL1(P,"BGP COLO PROCS",BDATE,EDATE)
+5 IF $PIECE(BGPG,U)=1
SET BGPLCOLO="COLO "_$PIECE(BGPG,U,2)_"^"_$$DATE^BGP6UTL($PIECE(BGPG,U,3))_U_$PIECE(BGPG,U,3)
+6 SET T=$ORDER(^ATXAX("B","BGP COLO CPTS",0))
+7 IF T
Begin DoDot:1
+8 SET X=$$CPT^BGP6DU(P,BDATE,EDATE,T,5)
IF X]""
QUIT
+9 SET X=$$TRAN^BGP6DU(P,BDATE,EDATE,T,5)
End DoDot:1
IF X]""
IF $PIECE(BGPLCOLO,U,3)<$PIECE(X,U,1)
SET BGPLCOLO="CPT COLO "_$PIECE(X,U,2)_U_$$DATE^BGP6UTL($PIECE(X,U,1))_U_$PIECE(X,U,1)
+10 QUIT BGPLCOLO
FOB(P,BDATE,EDATE) ;EP
+1 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,2*(-365))
+2 SET BGPC=""
SET BGPLFOB=""
+3 SET T=$ORDER(^ATXAX("B","BGP FOBT LOINC CODES",0))
+4 SET BGPLT=$ORDER(^ATXLAB("B","BGP GPRA FOB TESTS",0))
+5 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
+6 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L!(BGPC]"")
QUIT
Begin DoDot:2
+7 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X!(BGPC]"")
QUIT
Begin DoDot:3
+8 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+9 IF BGPLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(BGPLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET BGPC="V LAB"_U_(9999999-D)
QUIT
+10 IF 'T
QUIT
+11 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+12 IF '$$LOINC(J,T)
QUIT
+13 SET BGPC="LOINC"_U_(9999999-D)
QUIT
+14 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+15 SET BGPLFOB=BGPC
+16 SET T=$ORDER(^ATXAX("B","BGP FOBT CPTS",0))
+17 IF T
Begin DoDot:1
+18 SET X=$$CPT^BGP6DU(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)
+19 SET %=P_"^LAST DIAGNOSIS [BGP COLO DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(%,"BGPG(")
+20 IF $DATA(BGPG(1))
IF $PIECE(BGPLFOB,U,2)<$PIECE(BGPG(1),U,1)
SET BGPLFOB="FOB DX "_$PIECE(BGPG(1),U,2)_"^"_$PIECE(BGPG(1),U)
+21 IF BGPLFOB=""
QUIT ""
+22 QUIT $PIECE(BGPLFOB,U,1)_U_$$DATE^BGP6UTL($PIECE(BGPLFOB,U,2))
+23 ;
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 ""