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

BGP8PC8.m

Go to the documentation of this file.
BGP8PC8 ; IHS/CMI/LAB - measure I2 ; 02 Feb 2018  11:25 AM
 ;;18.1;IHS CLINICAL REPORTING;;MAY 25, 2018;Build 66
 ;
CCS ;EP
 S (BGPN1,BGPD1)=0
 S BGPDV=""
 I $P(^DPT(DFN,0),U,2)'="F" S BGPSTOP=1 Q  ;female only
 I BGPAGEE<23 S BGPSTOP=1 Q  ;18 or greater during time period
 I BGPAGEB>63 S BGPSTOP=1 Q  ;63 or less during time period
 ;
 S BGPDV=$$ENC8(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 $$HYSTER(DFN,BGPEDATE) S BGPSTOP=1 Q
 ;
 S BGPD1=1
 ;
 S BGPVAL=""
 S X=$$PAP(DFN,BGPEDATE,3)  ;PAP IN 3 YRS?
 I $E(X)=1 S BGPN1=1,BGPVAL=X
 I 'BGPN1,BGPAGEB>29,BGPAGEB<65 S X=$$PAPHPV(DFN,BGPEDATE,5)  I $E(X)=1 S BGPN1=1,BGPVAL=X ;PAP AND HPV IN PAST 5 YEARS ON SAME DAY
 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
ENC8(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,$$OFFCPT8(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,$$OFFCPT8(Y) S G=1_U_$$DATE^BGP8UTL(D)_" CPT: "_$P($$CPT^ICPTCOD(Y),U,2) Q
 Q G
OFFCPT8(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
 Q ""
PAP(P,EDATE,YEARS,REFUSAL) ;EP
 NEW BGPC,BGPLPAP,T,BGPLT,B,D,E,L,X,J,BGP
 S BGPC=""
 S BGPLPAP=""
 S BDATE=($E(EDATE,1,3)-YEARS)_$E(EDATE,4,7)
 ;S BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
 S T=$O(^ATXAX("B","BGP IPC PAP LOINC CODES",0))
 S BGPLT=$O(^ATXLAB("B","BGP PAP SMEAR TAX",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)=""
 ...I BGPLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(BGPLT,21,"B",$P(^AUPNVLAB(X,0),U))) S BGPC="1^"_(9999999-D)_"^Lab" Q
 ...Q:'T
 ...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
 ...Q:'$$LOINC(J,T)
 ...S BGPC="1^"_(9999999-D)_"^Lab-loinc" Q
 ...Q
 S BGPLPAP=BGPC
 I BGPLPAP]"" Q BGPLPAP
 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 ""
HYSTER(P,EDATE) ;EP 
 I '$G(P) Q ""
 NEW X,T
 S X=$$LASTPRC^BGP8UTL1(P,"BGP HYSTERECTOMY PROCEDURES",$$DOB^AUPNPAT(P),EDATE)
 I X Q 1
 S T="HYSTERECTOMY",T=$O(^BWPN("B",T,0))
 I T D  I X]"" Q 1
 .S X=$$WH^BGP8DU(P,$$DOB^AUPNPAT(P),EDATE,T,2)
 S T=$O(^ATXAX("B","BGP IPC HYSTERECTOMY CPTS",0))
 I T D  I X]"" Q 1
 .S X=$$CPT^BGP8DU(P,$P(^DPT(P,0),U,3),EDATE,T,3) I X]"" Q
 .S X=$$TRAN^BGP8DU(P,$P(^DPT(P,0),U,3),EDATE,T,3)
 S X=$$LASTDX^BGP8UTL1(P,"BGP HYSTERECTOMY DXS",$$DOB^AUPNPAT(P),EDATE)
 I X Q 1
 S X=$$PLTAXND^BGP8DU(P,"BGP HYSTERECTOMY DXS",EDATE)
 I X Q 1
 S X=$$IPLSNOND^BGP8DU(P,"PXRM BGP HYSTERECTOMY DX",EDATE)
 I X Q 1
 Q ""
PAPHPV(P,EDATE,YEARS) ;EP  - PAP AND HPV ON THE SAME DAY
 NEW BGPC,BGPLPAP,T,BGPLT,B,D,E,L,X,J,BGP,BGPAPAP,BGPG,BGPAHPV
 ;GATHER UP ALL PAP SMEARS BY DATE
 ;BGPAPAP(INVERSE DATE)=1^INTERNAL DATE^VALUE
 S BGPC="",BGPLPAP="",BGPAHPV="",BGPAPAP=""
 ;S BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
 S BDATE=($E(EDATE,1,3)-YEARS)_$E(EDATE,4,7)
 S T=$O(^ATXAX("B","BGP IPC PAP LOINC CODES",0))
 S BGPLT=$O(^ATXLAB("B","BGP PAP SMEAR TAX",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)  D
 .S L=0 F  S L=$O(^AUPNVLAB("AE",P,D,L)) Q:L'=+L  D
 ..S X=0 F  S X=$O(^AUPNVLAB("AE",P,D,L,X)) Q:X'=+X  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 BGPAPAP(D)="1^"_(9999999-D)_"^Lab" Q
 ...Q:'T
 ...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
 ...Q:'$$LOINC(J,T)
 ...S BGPAPAP(D)="1^"_(9999999-D)_"^Lab-loinc" Q
 ...Q
 ;GATHER UP ALL HPV TESTS
HPV ;
 S BGPC=""
 K BGPAHPV
 S BDATE=($E(EDATE,1,3)-YEARS)_$E(EDATE,4,7)
 ;S BDATE=$$FMADD^XLFDT(EDATE,-(365*YEARS))
 S T=$O(^ATXAX("B","BGP IPC HPV LOINC CODES",0))
 S BGPLT=$O(^ATXLAB("B","BGP HPV TESTS TAX",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)  D
 .S L=0 F  S L=$O(^AUPNVLAB("AE",P,D,L)) Q:L'=+L  D
 ..S X=0 F  S X=$O(^AUPNVLAB("AE",P,D,L,X)) Q:X'=+X  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 BGPAHPV(D)="1^"_(9999999-D)_"^Lab" Q
 ...Q:'T
 ...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
 ...Q:'$$LOINC(J,T)
 ...S BGPAHPV(D)="1^"_(9999999-D)_"^Lab-loinc" Q
 ...Q
 ;LOOP ALL PAPS AND SEE IF HPV ON SAME DAY, IF SO CHECK AGAINST BGPLPAP AND IF LATER QUIT
 S D=0 F  S D=$O(BGPAPAP(D)) Q:D'=+D  D
 .I $D(BGPAHPV(D)),$P(BGPAPAP(D),U,2)>$P(BGPLPAP,U,2) S BGPLPAP="1^"_$P(BGPAPAP(D),U,2)_U_"PAP&HPV 5YRS SAME DAY"
 Q BGPLPAP