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

BGP8PC10.m

Go to the documentation of this file.
BGP8PC10 ; IHS/CMI/LAB - measure I2 ; 02 Feb 2018  11:25 AM
 ;;18.1;IHS CLINICAL REPORTING;;MAY 25, 2018;Build 66
 ;
CRC ;EP
 I BGPAGEE<50 S BGPSTOP=1 Q  ;18 or greater during time period
 I BGPAGEB>74 S BGPSTOP=1 Q  ;LESS THAN 75 during time period
 ;
 S BGPDV=$$ENC10(DFN,BGPBDATE,BGPEDATE) I BGPDV="" S BGPSTOP=1 Q  ;no office visit
 ;
 ;now what about exclusions?
 I $$HOSPIND^BGP8PC2(DFN,BGPBDATE,BGPEDATE) S BGPSTOP=1 Q  ;no hospice pts
 ;Hysterectomy?
 I $$CRCCOLE(DFN,BGPEDATE) S BGPSTOP=1 Q
 ;
 S (BGPN1,BGPD1)=0
 ;
 S BGPD1=1
 ;
 S BGPVAL=""
 S X=$$SCREEN(DFN,BGPBDATE,BGPEDATE)
 I X S BGPN1=1,BGPVAL=$P(X,U,2)_" "_$P(X,U,3)
SV ;
 S BGPVALUE=""
 S BGPVALUE="ENC "_$P(BGPDV,U,2)_"|||"  ;hit denominator
 I BGPN1 S BGPVALUE=BGPVALUE_"*** "_$$DATE^BGP8UTL($P(X,U,2))_" "_$P(X,U,3)
 K V,BGPDV,BGPVAL
 Q
ENC10(P,BDATE,EDATE) ;EP  - have encounter per CMS122v6
 ;HAS one of the following
 ;1.  cpt in BGP IPC OFFICE VISIT CPTS
 ;2.  snomed in PXRM BGP IPC FACE2FACE
 ;3.  CPT in BGP IPC PREVCARE EOV >=18 CPTS
 ;4.  CPT in BGP IPC PREVCARE IOV >=18 CPTS
 ;5.  CPT in BGP IPC HOMEHEALTH VISIT CPTS
 NEW X,Y,Z,G,BGPV,D
 ;Let's check all Visits, looping through once
 S G=""  ;return variable
 ;get all visits in date range in BGPV
 D ALLV^APCLAPIU(P,BDATE,EDATE,"BGPV")
 ;now loop through and check Face to Face and .17 in visit and check v cpts attached to the visit
 S X=0 F  S X=$O(BGPV(X)) Q:X'=+X!(G)  S V=$P(BGPV(X),U,5)  D
 .Q:'$P(^AUPNVSIT(V,0),U,9)  ;no dependent entries
 .Q:$P(^AUPNVSIT(V,0),U,11)  ;deleted
 .S D=$$VD^APCLV(V)
 .S Y=$$FTOF^BGP8PC2(V) I Y]"" S G=1_U_$$DATE^BGP8UTL(D)_" FTOF: "_Y Q
 .;is .17 a cpt we want?
 .S Y=$$VALI^XBDIQ1(9000010,V,.17)
 .I Y,$$OFFCPT10(Y) S G=1_U_$$DATE^BGP8UTL(D)_" CPT: "_$P($$CPT^ICPTCOD(Y),U,2) Q
 .;now check all V CPTs
 .S Z=0 F  S Z=$O(^AUPNVCPT("AD",V,Z)) Q:Z'=+Z!(G)  D
 ..S Y=$P($G(^AUPNVCPT(Z,0)),U,1)
 ..I Y,$$OFFCPT10(Y) S G=1_U_$$DATE^BGP8UTL(D)_" CPT: "_$P($$CPT^ICPTCOD(Y),U,2) Q
 Q G
OFFCPT10(C) ;EP
 I $$ICD^ATXAPI(C,$O(^ATXAX("B","BGP IPC OFFICE VISIT CPTS",0)),1) Q 1
 I $$ICD^ATXAPI(C,$O(^ATXAX("B","BGP IPC PREVCARE EOV >=18 CPTS",0)),1) Q 1
 I $$ICD^ATXAPI(C,$O(^ATXAX("B","BGP IPC PREVCARE IOV >=18 CPTS",0)),1) Q 1
 I $$ICD^ATXAPI(C,$O(^ATXAX("B","BGP IPC HOMEHEALTH VISIT CPTS",0)),1) Q 1
 I $$ICD^ATXAPI(C,$O(^ATXAX("B","BGP IPC ANNUAL WELLNESS CPTS",0)),1) Q 1
 Q ""
LOINC(A,B) ;EP
 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 ""
CRCCOLE(P,EDATE) ;EP
 K BGPG
 S Y="BGPG("
 S X=P_"^LAST DX [BGP IPC COLON 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 X=$$PLTAXND^BGP8DU(P,"BGP IPC COLON CANCER DXS",EDATE)
 I X Q 1
 S X=$$IPLSNOND^BGP8DU(P,"PXRM BGP IPC COLON CANCER",EDATE)
 I X Q 1
 S T=$O(^ATXAX("B","BGP IPC TOTAL COLECTOMY CPTS",0))
 I T D  I X]"" Q 1
 .S X=$$CPT^BGP8DU(P,$$DOB^AUPNPAT(P),EDATE,T,5) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,$$DOB^AUPNPAT(P),EDATE,T,5)
 Q 0
SCREEN(P,BDATE,EDATE) ;
 NEW X,Y,Z,BGPC,G,V,D
 S G=$$COLO(P,($E(EDATE,1,3)-9)_$E(EDATE,4,7),EDATE)
 I G Q G
 S G=$$FOBT(P,BDATE,EDATE)
 I G Q G
 S G=$$SIG(P,($E(EDATE,1,3)-4)_$E(EDATE,4,7),EDATE)
 I G Q G
 S G=$$FIT(P,($E(EDATE,1,3)-2)_$E(EDATE,4,7),EDATE)
 I G Q G
 S G=$$CT(P,($E(EDATE,1,3)-4)_$E(EDATE,4,7),EDATE)
 I G Q G
 Q ""
COLO(P,BDATE,EDATE) ;
 NEW BGPG,BGPLCOLO,T,X
 K BGPG
 S BGPLCOLO=""
 S T=$O(^ATXAX("B","BGP IPC COLONOSCOPY CPTS",0))
 I T D  I X]"",$P(BGPLCOLO,U,3)<$P(X,U,1) S BGPLCOLO=1_U_$P(X,U,1)_U_"COLO CPT "_$P(X,U,2)
 .S X=$$CPT^BGP8DU(P,BDATE,EDATE,T,5) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,BDATE,EDATE,T,5)
 Q BGPLCOLO
SIG(P,BDATE,EDATE) ;
 NEW BGPG,BGPLCOLO,T,X
 K BGPG
 S BGPLCOLO=""
 S T=$O(^ATXAX("B","BGP IPC SIG CPT CODES",0))
 I T D  I X]"",$P(BGPLCOLO,U,3)<$P(X,U,1) S BGPLCOLO=1_U_$P(X,U,1)_U_"SIG CPT "_$P(X,U,2)
 .S X=$$CPT^BGP8DU(P,BDATE,EDATE,T,5) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,BDATE,EDATE,T,5)
 Q BGPLCOLO
FOBT(P,BDATE,EDATE) ;EP
 NEW BGPLT,T,BGPC,BGPLFOB,B,E,D,X,J
 S BGPC="",BGPLFOB=""
 S T=$O(^ATXAX("B","BGP IPC 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))
 ...Q:$P(^AUPNVLAB(X,0),U,4)=""  ;must have a result
 ...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
 I BGPC]"" Q 1_U_$P(BGPC,U,2)_U_"FOBT "_$P(BGPC,U,1)
 Q ""
 ;
CT(P,BDATE,EDATE) ;EP - CT COLONOGRAPHY
 NEW BGPLCT,T,X,BGPG
 S BGPLCT=""
 ;
 S T=$O(^ATXAX("B","BGP IPC CT COLONOGRAPHY CPTS",0))
 I T D  I X]"" S BGPLCT=1_U_$P(X,U,1)_U_"CT CPT "_$P(X,U,2)
 .S X=$$CPT^BGP8DU(P,BDATE,EDATE,T,5) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,BDATE,EDATE,T,5)
 Q BGPLCT
 ;
FIT(P,BDATE,EDATE) ;EP
 NEW BGPLT,T,BGPC,BGPLFOB,B,E,D,X,J
 S BGPC="",BGPLFOB=""
 S T=$O(^ATXAX("B","BGP IPC FIT-DNA LOINC CODES",0))
 S BGPLT=$O(^ATXLAB("B","BGP FIT-DNA 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 $P(^AUPNVLAB(X,0),U,4)="" Q
 ...I BGPLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(BGPLT,21,"B",$P(^AUPNVLAB(X,0),U))) S BGPC="FIT-DNA 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
 I BGPC]"" Q 1_U_$P(BGPC,U,2)_U_"FIT-DNA "_$P(BGPC,U,1)
 Q ""
 ;