APCHPWH4 ; IHS/CMI/LAB - PCC HEALTH SUMMARY - MAIN DRIVER PART 2 ;
;;2.0;IHS PCC SUITE;**3,6,7,11**;MAY 14, 2009;Build 58
;
;EO MEASURES IN PWH
EO ;EP - EO measures
Q ;;PLEASE NOTE THIS COMPONENT IS BEING DISABLE, I DIDN'T DELETE IT SINCE IT MAY BE
;;POINTED TO BUT NOTHING WILL DISPLAY
I '$O(^APCHPWHT(APCHPWHT,1,APCHSORD,11,0)) Q ;no measures defined
NEW APCHSTO,APCHSTM,APCHSTCE
D SUBHEAD^APCHPWHU
D S^APCHPWH1("QUALITY OF CARE TRANSPARENCY REPORT CARD - This report looks at")
D S^APCHPWH1("6 quality measures. This report card enables you to compare your")
D S^APCHPWH1("personal results to those on the IHS Quality of Care website at:")
D S^APCHPWH1("http://www.ihs.gov/NonMedicalPrograms/quality/. Your personal ")
D S^APCHPWH1("information is listed below.")
;
;go through each one
S APCHSTO=0 F S APCHSTO=$O(^APCHPWHT(APCHPWHT,1,APCHSORD,11,APCHSTO)) Q:APCHSTO'=+APCHSTO D
.S APCHSTM=$P($G(^APCHPWHT(APCHPWHT,1,APCHSORD,11,APCHSTO,0)),U,2)
.Q:'APCHSTM
.Q:'$D(^APCHPWHE(APCHSTM,0))
.S APCHSTCE=$G(^APCHPWHE(APCHSTM,1))
.I APCHSTCE="" Q
.X APCHSTCE
.Q
Q
;
DGC ;EP - diabetes and glycemic control
NEW APCHX
Q:$$AGE^AUPNPAT(APCHSDFN,DT)<18
D S^APCHPWH1("Diabetes and Glycemic (A1c) Control",1)
I '$$DMDX^APCHPWH2(APCHSDFN) D Q
.D S^APCHPWH1("This section only reports on people who have diabetes. You do not")
.D S^APCHPWH1("have diabetes, so you are not included in this report.")
.Q
S APCHX=$$HGBA1C(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT) ;365 days ago
I APCHX="" D K APCHX Q
.D S^APCHPWH1("Your A1c was not checked in the past year. We recommend that you have ")
.D S^APCHPWH1("your A1c checked at least twice a year.")
.Q
I $P(APCHX,U,2)="" D Q
.D S^APCHPWH1("Your A1c was checked on "_$P(APCHX,U)_" but there is no result on file. We")
.D S^APCHPWH1("recommend that you ask your provider about your A1c value.")
D S^APCHPWH1("Your A1c value on "_$P(APCHX,U)_" was "_$P(APCHX,U,2)_". An A1c")
D S^APCHPWH1("less than 7% means good blood sugar control. An A1c of more than 9% means")
D S^APCHPWH1("that you may need better blood sugar control.")
Q
HGBA1C(P,BDATE,EDATE,APCHRR) ;EP - get result of HGBA1c in past year. If no result pass null
;pass back date_u_result
S APCHRR=$G(APCHRR)
I $G(BDATE)="" S BDATE=$$DOB^AUPNPAT(P)
I $G(EDATE)="" S EDATE=DT
NEW APCHG,APCHT,APCHC,E,%,L,T,APCHLT,D,X,J,C,G
S APCHC=0
I 'APCHRR S G=$$LASTCPTT^APCLAPIU(P,BDATE,EDATE,"BGP HGBA1C CPTS","A") I G]"" S APCHC=APCHC+1,APCHT((9999999-$P(G,U,1)),APCHC)=U_$P(G,U,2)
;now get all loinc/taxonomy tests
S T=$O(^ATXAX("B","BGP HGBA1C LOINC CODES",0))
S APCHLT=$O(^ATXLAB("B","DM AUDIT HGB A1C 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))
...I APCHRR,$P(^AUPNVLAB(X,0),U,4)="" Q
...I APCHRR,$$UP^XLFSTR($P(^AUPNVLAB(X,0),U,4))="COMMENT" Q
...I APCHLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCHLT,21,"B",$P(^AUPNVLAB(X,0),U))) S APCHC=APCHC+1,APCHT(D,APCHC)=$P(^AUPNVLAB(X,0),U,4)_U_"LAB: "_$$VAL^XBDIQ1(9000010.09,X,.01) Q
...Q:'T
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,T)
...S APCHC=APCHC+1,APCHT(D,APCHC)=$P(^AUPNVLAB(X,0),U,4)_U_"LAB LOINC: "_$$VAL^XBDIQ1(9000010.09,X,.01)_" "_$P(^AUPNVLAB(X,11),U,13)
...Q
I '$D(APCHT) Q "" ;no tests
; now get rid of all on same day where 1 has a result and the other doesn't
S D=0,APCHC=0 F S D=$O(APCHT(D)) Q:D'=+D S C=0,G=0 F S C=$O(APCHT(D,C)) Q:C'=+C D
.I $P(APCHT(D,C),U,1)]"" S APCHC=APCHC+1
.I APCHC>0,$P(APCHT(D,C),U,1)="" K APCHT(D,C)
S D=0,G=""
S D=$O(APCHT(D))
S C=0,C=$O(APCHT(D,C))
S X=$P(APCHT(D,C),U,1)
I X="",$G(APCHRR) Q ""
I X="" D Q G
.S G=""
.I $P(APCHT(D,C),U,2)="CPT: 3046F" S G=$$FMTE^XLFDT(9999999-D)_U_">9.0%"_U_(9999999-D) Q
.I $P(APCHT(D,C),U,2)="CPT: 3047F" S G=$$FMTE^XLFDT(9999999-D)_U_"<= 9.0%"_U_(9999999-D) Q
.I $P(APCHT(D,C),U,2)="CPT: 3044F" S G=$$FMTE^XLFDT(9999999-D)_U_"< 7.0%"_U_(9999999-D) Q
.I $P(APCHT(D,C),U,2)="CPT: 3045F" S G=$$FMTE^XLFDT(9999999-D)_U_"7.0-9.0%"_U_(9999999-D) Q
.Q
Q $$FMTE^XLFDT((9999999-D))_U_X_U_(9999999-D)
;
DLDL ;EP - LDL
NEW APCHX
Q:$$AGE^AUPNPAT(APCHSDFN,DT)<18
D S^APCHPWH1("Diabetes and LDL Control",1)
I '$$DMDX^APCHPWH2(APCHSDFN) D Q
.D S^APCHPWH1("This section only reports on people who have diabetes. You do not")
.D S^APCHPWH1("have diabetes, so you are not included in this report.")
.Q
S APCHX=$$LDL(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT,1) ;365 days ago
I APCHX="" D K APCHX Q
.D S^APCHPWH1("Your LDL was not checked in the past year. We recommend that you have ")
.D S^APCHPWH1("your LDL checked at least once a year.")
.Q
D S^APCHPWH1("Your LDL value on "_$$FMTE^XLFDT($P(APCHX,U))_" was "_$P(APCHX,U,2)_$S($P(APCHX,U,3)]"":" "_$P(APCHX,U,3),1:"")_". An LDL less than 100 mg/dl")
D S^APCHPWH1("is good. Sometimes it is better to have a lower LDL value. Talk to your")
D S^APCHPWH1("health care provider about an LDL value that is good for you.")
Q
;
LDL(P,BDATE,EDATE,NORES) ;EP
NEW APCHG,APCHT,APCHC,APCHLT,T,B,E,D,L,X,R,G,C,%
K APCHG,APCHT,APCHC
S APCHC=0
S NORES=$G(NORES)
;now get all loinc/taxonomy tests
S T=$O(^ATXAX("B","BGP LDL LOINC CODES",0))
S APCHLT=$O(^ATXLAB("B","DM AUDIT LDL CHOLESTEROL 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))
...I $G(NORES) Q:$P(^AUPNVLAB(X,0),U,4)=""
...S R=$P(^AUPNVLAB(X,0),U,4)
...I $G(NORES),'R Q
...I $G(NORES),$$UP^XLFSTR(X)["COMMENT" Q
...I APCHLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCHLT,21,"B",$P(^AUPNVLAB(X,0),U))) S APCHC=APCHC+1,APCHT(D,APCHC)=$P(^AUPNVLAB(X,0),U,4)_U_$P($G(^AUPNVLAB(X,11)),U,1) Q
...Q:'T
...S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
...Q:'$$LOINC(J,T)
...S R=$P(^AUPNVLAB(X,0),U,4)
...S APCHC=APCHC+1,APCHT(D,APCHC)=R_U_$P($G(^AUPNVLAB(X,11)),U,1)
...Q
; now got though and set return value of done 1 or 0^VALUE^date
S D=0,G="" F S D=$O(APCHT(D)) Q:D'=+D!(G]"") D
.S C=0 F S C=$O(APCHT(D,C)) Q:C'=+C!(G]"") D
..S X=$P(APCHT(D,C),U)
..S G=(9999999-D)_U_X_U_$P(APCHT(D,C),U,2)
..Q
Q G
;
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 ""
;
DBP ;EP
Q:$$AGE^AUPNPAT(APCHSDFN,DT)<18
NEW APCHX
D S^APCHPWH1("Diabetes and BP Control",1)
I '$$DMDX^APCHPWH2(APCHSDFN) D Q
.D S^APCHPWH1("This section only reports on people who have diabetes. You do not")
.D S^APCHPWH1("have diabetes, so you are not included in this report.")
.Q
S APCHX=$$LASTITEM^APCLAPIU(APCHSDFN,"BP","MEASUREMENT",$$FMADD^XLFDT(DT,-365),DT,"A")
I APCHX="" D K APCHX Q
.D S^APCHPWH1("Your Blood Pressure was not checked in the past year. We recommend that")
.D S^APCHPWH1("you have your Blood Pressure checked at least three times a year.")
.Q
D S^APCHPWH1("Your Blood Pressure on "_$$FMTE^XLFDT($P(APCHX,U))_" was "_$P(APCHX,U,3)_". A blood pressure that is")
D S^APCHPWH1("less than or equal to 140/90 is good for some people. If you have diabetes")
D S^APCHPWH1("or kidney problems, you may want your blood pressure to be less than 130/80.")
D S^APCHPWH1("Talk to your health care provider about a blood pressure that is good for you.")
Q
;
FLU ;EP - FLU
NEW APCHX
D S^APCHPWH1("Flu Shot (Influenza) Vaccine",1)
I $$AGE^AUPNPAT(APCHSDFN,DT)<50 D Q
.D S^APCHPWH1("This section only reports on people who are 50 years of age or older.")
.D S^APCHPWH1("You are younger than 50, so you are not included in this report.")
.Q
S APCHX=$$LASTFLU^APCLAPI4(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT,"A")
I APCHX="" D K APCHX Q
.D S^APCHPWH1("You did not have a flu shot this year. We recommend that you have a flu shot")
.D S^APCHPWH1("every year.")
.Q
D S^APCHPWH1("You had your flu shot on "_$$FMTE^XLFDT($P(APCHX,U))_". We recommend that you have a ")
D S^APCHPWH1("flu shot every year.")
Q
;
O2 ;EP - OXYGEN ASSESSMENT
NEW APCHX,X,Y
I $$AGE^AUPNPAT(APCHSDFN,DT)<18 D Q
.D S^APCHPWH1("")
D S^APCHPWH1("Assessment of Oxygen Status",1)
D PNEUOX(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT,.APCHX)
;
I 'APCHX("DENOM")!($$AGE^AUPNPAT(APCHSDFN,DT)<18) D Q
.D S^APCHPWH1("This section only reports on people who came to the clinic or emergency")
.D S^APCHPWH1("room with pneumonia. You did not come to the clinic this year with")
.D S^APCHPWH1("pneumonia so you are not included in this report.")
.Q
S X=0 F S X=$O(APCHX(X)) Q:X'=+X D
.S Y=$$FMTE^XLFDT($P(APCHX(X),U,3))
.D S^APCHPWH1("You came to the hospital with pneumonia on "_Y_". The goal is to have",1)
.D S^APCHPWH1("your oxygen level checked within 24 hours of your hospital visit. Your")
.D S^APCHPWH1("oxygen level was "_$S($P(APCHX(X),U,2)["NOT MET":"not ",1:"")_"checked within 24 hours of your hospital visit.")
Q
;
PNEUOX(P,BDATE,EDATE,APCHR) ;EP
NEW A,B,C,D,E,F,G,APCHG,APCHX,APCHD,APCHV,APCHC
K APCHG,APCHR
S APCHR="",APCHR(0)=""
S X=P_"^ALL DX [BGP CMS PNEUMONIA;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,"APCHG(")
I '$D(APCHG(1)) S APCHR("DENOM")=0 Q
;now go through and get rid of CHS or service category not A, O, S
S A=0 F S A=$O(APCHG(A)) Q:A'=+A D
.S V=$P(APCHG(A),U,5)
.I '$D(^AUPNVSIT(V,0)) K APCHG(A)
.I $P(^AUPNVSIT(V,0),U,3)="C" K APCHG(A)
.I "AOS"'[$P(^AUPNVSIT(V,0),U,7) K APCHG(A)
I '$D(APCHG) S APCHR("DENOM")=0 Q ;got rid of them all
;reorder the diagnoses by visit date
S A=0 F S A=$O(APCHG(A)) Q:A'=+A S V=$P(APCHG(A),U,5),D=$P($P($G(^AUPNVSIT(V,0)),U),"."),APCHX(D,V)=APCHG(A)
;now get the first one
S APCHD=0,APCHC=0 F S APCHD=$O(APCHX(APCHD)) Q:APCHD'=+APCHD D
.S APCHV=0 F S APCHV=$O(APCHX(APCHD,APCHV)) Q:APCHV'=+APCHV D
..S APCHC=APCHC+1,APCHR(APCHC)=APCHC_") "_$$FMTE^XLFDT(APCHD)_" "_$P(APCHX(APCHD,APCHV),U,2) ;set denominator
..S G=$$OXSAT(APCHV) ; any o2 saturation on this visit?
..S $P(APCHR(APCHC),U,2)=APCHC_") "_$P(G,U,1) ;set numerator column
..S $P(APCHR(APCHC),U,3)=APCHD
..S $P(APCHR(0),U,$P(G,U,2))=$P(APCHR(0),U,$P(G,U,2))+1
..;now delete out all visits that are <46 days difference and all other visits on the same day
..S V=APCHV F S V=$O(APCHX(APCHD,V)) Q:V'=+V K APCHX(APCHD,V)
..S D=APCHD,V=APCHV F S D=$O(APCHX(D)) Q:D'=+D D
...S V=0 F S V=$O(APCHX(D,V)) Q:V'=+V I $$FMDIFF^XLFDT(D,APCHD)<46 K APCHX(D,V)
S APCHR("DENOM")=APCHC
Q
;
OXSAT(V) ;was there ox sat at the visit
;get all O2 measurements on or after admission date
NEW APCHD,X,N,E,Y,T,D,C,APCHLT,L,J,APCHG,M,M1
S APCHG=""
S APCHD=$P($P(^AUPNVSIT(V,0),U),".")
;K APCHG S Y="APCHG(",X=P_"^ALL MEAS O2;DURING "_$$FMTE^XLFDT(BD)_"-"_$$FMTE^XLFDT(ED) S E=$$START1^APCLDF(X,Y)
S X=0 F S X=$O(^AUPNVMSR("AD",V,X)) Q:X'=+X!(APCHG]"") I $$VAL^XBDIQ1(9000010.01,X,.01)="O2",'$P($G(^AUPNVMSR(X,2)),U,1) S APCHG=$$FMTE^XLFDT(APCHD)_" MET O2 SAT^1"
I APCHG]"" Q APCHG
;now check for cpts
S T=$O(^ATXAX("B","BGP CMS ABG CPTS",0))
S X=0 F S X=$O(^AUPNVCPT("AD",V,X)) Q:X'=+X!(APCHG]"") D
.Q:'$D(^AUPNVCPT(X,0))
.S C=$P(^AUPNVCPT(X,0),U)
.Q:'$$ICD^ATXAPI(C,T,1)
.S M=$$VAL^XBDIQ1(9000010.18,X,.08)
.S M1=$$VAL^XBDIQ1(9000010.18,X,.09)
.I $P(^ICPT(C,0),U)="3028F",(M="1P"!(M="2P")!(M="3P")!(M="4P")!(M="8P")) Q ;3028f and has modifier
.I $P(^ICPT(C,0),U)="3028F",(M1="1P"!(M="2P")!(M="3P")!(M="4P")!(M="8P")) Q ;3028f and has modifier
.S APCHG=$$FMTE^XLFDT(APCHD)_" MET CPT ["_$P($$CPT^ICPTCOD(C),U,2)_"]^1"
.Q
I APCHG]"" Q APCHG
;now check v tran
S T=$O(^ATXAX("B","BGP CMS ABG CPTS",0))
S X=0 F S X=$O(^AUPNVTC("AD",V,X)) Q:X'=+X!(APCHG]"") D
.Q:'$D(^AUPNVTC(X,0))
.S C=$P(^AUPNVTC(X,0),U,7)
.Q:C=""
.Q:'$$ICD^ATXAPI(C,T,1)
.S APCHG=$$FMTE^XLFDT(APCHD)_" MET CPT/TRAN ["_$P($$CPT^ICPTCOD(C),U,2)_"]^1"
.Q
I APCHG]"" Q APCHG
;now check for lab tests
S T=$O(^ATXAX("B","BGP CMS ABG LOINC",0))
S APCHLT=$O(^ATXLAB("B","BGP CMS ABG TESTS",0))
S X=0 F S X=$O(^AUPNVLAB("AD",V,X)) Q:X'=+X!(APCHG]"") D
.Q:'$D(^AUPNVLAB(X,0))
.I APCHLT,$P(^AUPNVLAB(X,0),U),$D(^ATXLAB(APCHLT,21,"B",$P(^AUPNVLAB(X,0),U))) S APCHG=$$FMTE^XLFDT(APCHD)_" MET "_$$VAL^XBDIQ1(9000010.09,X,.01)_"^1" Q
.Q:'T
.S J=$P($G(^AUPNVLAB(X,11)),U,13) Q:J=""
.Q:'$$LOINC(J,T)
.S APCHG=$$FMTE^XLFDT(APCHD)_" MET "_$$VAL^XBDIQ1(9000010.09,X,.01)_"^1" Q
I APCHG]"" Q APCHG
;now go get refusals of any of the above
;
S G=$$REFUSAL^APCHSMU(P,9999999.07,$O(^AUTTMSR("B","O2",0)),APCHD,APCHD)
I G Q $$FMTE^XLFDT(APCHD)_" NOT MET DECLINED O2 SAT^2"
;refusal of lab tests
S T=$O(^ATXLAB("B","BGP CMS ABG TESTS",0))
S L=0 F S L=$O(^ATXLAB(T,21,"B",L)) Q:L'=+L!(APCHG]"") D
.S G=$$REFUSAL^APCHSMU(P,60,L,APCHD,APCHD)
.I G S APCHG=$$FMTE^XLFDT(APCHD)_" NOT MET DECLINED LAB^2"
I APCHG]"" Q APCHG
S G=$$CPTREFT^APCHSMU(P,APCHD,APCHD,$O(^ATXAX("B","BGP CMS ABG CPTS",0)))
I G Q $$FMTE^XLFDT(APCHD)_" NOT MET DECLINED CPT^2"
Q $$FMTE^XLFDT(APCHD)_" NOT MET; NO ASSMT^3"
;
APCHPWH4 ; IHS/CMI/LAB - PCC HEALTH SUMMARY - MAIN DRIVER PART 2 ;
+1 ;;2.0;IHS PCC SUITE;**3,6,7,11**;MAY 14, 2009;Build 58
+2 ;
+3 ;EO MEASURES IN PWH
EO ;EP - EO measures
+1 ;;PLEASE NOTE THIS COMPONENT IS BEING DISABLE, I DIDN'T DELETE IT SINCE IT MAY BE
QUIT
+2 ;;POINTED TO BUT NOTHING WILL DISPLAY
+3 ;no measures defined
IF '$ORDER(^APCHPWHT(APCHPWHT,1,APCHSORD,11,0))
QUIT
+4 NEW APCHSTO,APCHSTM,APCHSTCE
+5 DO SUBHEAD^APCHPWHU
+6 DO S^APCHPWH1("QUALITY OF CARE TRANSPARENCY REPORT CARD - This report looks at")
+7 DO S^APCHPWH1("6 quality measures. This report card enables you to compare your")
+8 DO S^APCHPWH1("personal results to those on the IHS Quality of Care website at:")
+9 DO S^APCHPWH1("http://www.ihs.gov/NonMedicalPrograms/quality/. Your personal ")
+10 DO S^APCHPWH1("information is listed below.")
+11 ;
+12 ;go through each one
+13 SET APCHSTO=0
FOR
SET APCHSTO=$ORDER(^APCHPWHT(APCHPWHT,1,APCHSORD,11,APCHSTO))
IF APCHSTO'=+APCHSTO
QUIT
Begin DoDot:1
+14 SET APCHSTM=$PIECE($GET(^APCHPWHT(APCHPWHT,1,APCHSORD,11,APCHSTO,0)),U,2)
+15 IF 'APCHSTM
QUIT
+16 IF '$DATA(^APCHPWHE(APCHSTM,0))
QUIT
+17 SET APCHSTCE=$GET(^APCHPWHE(APCHSTM,1))
+18 IF APCHSTCE=""
QUIT
+19 XECUTE APCHSTCE
+20 QUIT
End DoDot:1
+21 QUIT
+22 ;
DGC ;EP - diabetes and glycemic control
+1 NEW APCHX
+2 IF $$AGE^AUPNPAT(APCHSDFN,DT)<18
QUIT
+3 DO S^APCHPWH1("Diabetes and Glycemic (A1c) Control",1)
+4 IF '$$DMDX^APCHPWH2(APCHSDFN)
Begin DoDot:1
+5 DO S^APCHPWH1("This section only reports on people who have diabetes. You do not")
+6 DO S^APCHPWH1("have diabetes, so you are not included in this report.")
+7 QUIT
End DoDot:1
QUIT
+8 ;365 days ago
SET APCHX=$$HGBA1C(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT)
+9 IF APCHX=""
Begin DoDot:1
+10 DO S^APCHPWH1("Your A1c was not checked in the past year. We recommend that you have ")
+11 DO S^APCHPWH1("your A1c checked at least twice a year.")
+12 QUIT
End DoDot:1
KILL APCHX
QUIT
+13 IF $PIECE(APCHX,U,2)=""
Begin DoDot:1
+14 DO S^APCHPWH1("Your A1c was checked on "_$PIECE(APCHX,U)_" but there is no result on file. We")
+15 DO S^APCHPWH1("recommend that you ask your provider about your A1c value.")
End DoDot:1
QUIT
+16 DO S^APCHPWH1("Your A1c value on "_$PIECE(APCHX,U)_" was "_$PIECE(APCHX,U,2)_". An A1c")
+17 DO S^APCHPWH1("less than 7% means good blood sugar control. An A1c of more than 9% means")
+18 DO S^APCHPWH1("that you may need better blood sugar control.")
+19 QUIT
HGBA1C(P,BDATE,EDATE,APCHRR) ;EP - get result of HGBA1c in past year. If no result pass null
+1 ;pass back date_u_result
+2 SET APCHRR=$GET(APCHRR)
+3 IF $GET(BDATE)=""
SET BDATE=$$DOB^AUPNPAT(P)
+4 IF $GET(EDATE)=""
SET EDATE=DT
+5 NEW APCHG,APCHT,APCHC,E,%,L,T,APCHLT,D,X,J,C,G
+6 SET APCHC=0
+7 IF 'APCHRR
SET G=$$LASTCPTT^APCLAPIU(P,BDATE,EDATE,"BGP HGBA1C CPTS","A")
IF G]""
SET APCHC=APCHC+1
SET APCHT((9999999-$PIECE(G,U,1)),APCHC)=U_$PIECE(G,U,2)
+8 ;now get all loinc/taxonomy tests
+9 SET T=$ORDER(^ATXAX("B","BGP HGBA1C LOINC CODES",0))
+10 SET APCHLT=$ORDER(^ATXLAB("B","DM AUDIT HGB A1C TAX",0))
+11 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)
QUIT
Begin DoDot:1
+12 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:2
+13 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:3
+14 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+15 IF APCHRR
IF $PIECE(^AUPNVLAB(X,0),U,4)=""
QUIT
+16 IF APCHRR
IF $$UP^XLFSTR($PIECE(^AUPNVLAB(X,0),U,4))="COMMENT"
QUIT
+17 IF APCHLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCHLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET APCHC=APCHC+1
SET APCHT(D,APCHC)=$PIECE(^AUPNVLAB(X,0),U,4)_U_"LAB: "_$$VAL^XBDIQ1(9000010.09,X,.01)
QUIT
+18 IF 'T
QUIT
+19 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+20 IF '$$LOINC(J,T)
QUIT
+21 SET APCHC=APCHC+1
SET APCHT(D,APCHC)=$PIECE(^AUPNVLAB(X,0),U,4)_U_"LAB LOINC: "_$$VAL^XBDIQ1(9000010.09,X,.01)_" "_$PIECE(^AUPNVLAB(X,11),U,13)
+22 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+23 ;no tests
IF '$DATA(APCHT)
QUIT ""
+24 ; now get rid of all on same day where 1 has a result and the other doesn't
+25 SET D=0
SET APCHC=0
FOR
SET D=$ORDER(APCHT(D))
IF D'=+D
QUIT
SET C=0
SET G=0
FOR
SET C=$ORDER(APCHT(D,C))
IF C'=+C
QUIT
Begin DoDot:1
+26 IF $PIECE(APCHT(D,C),U,1)]""
SET APCHC=APCHC+1
+27 IF APCHC>0
IF $PIECE(APCHT(D,C),U,1)=""
KILL APCHT(D,C)
End DoDot:1
+28 SET D=0
SET G=""
+29 SET D=$ORDER(APCHT(D))
+30 SET C=0
SET C=$ORDER(APCHT(D,C))
+31 SET X=$PIECE(APCHT(D,C),U,1)
+32 IF X=""
IF $GET(APCHRR)
QUIT ""
+33 IF X=""
Begin DoDot:1
+34 SET G=""
+35 IF $PIECE(APCHT(D,C),U,2)="CPT: 3046F"
SET G=$$FMTE^XLFDT(9999999-D)_U_">9.0%"_U_(9999999-D)
QUIT
+36 IF $PIECE(APCHT(D,C),U,2)="CPT: 3047F"
SET G=$$FMTE^XLFDT(9999999-D)_U_"<= 9.0%"_U_(9999999-D)
QUIT
+37 IF $PIECE(APCHT(D,C),U,2)="CPT: 3044F"
SET G=$$FMTE^XLFDT(9999999-D)_U_"< 7.0%"_U_(9999999-D)
QUIT
+38 IF $PIECE(APCHT(D,C),U,2)="CPT: 3045F"
SET G=$$FMTE^XLFDT(9999999-D)_U_"7.0-9.0%"_U_(9999999-D)
QUIT
+39 QUIT
End DoDot:1
QUIT G
+40 QUIT $$FMTE^XLFDT((9999999-D))_U_X_U_(9999999-D)
+41 ;
DLDL ;EP - LDL
+1 NEW APCHX
+2 IF $$AGE^AUPNPAT(APCHSDFN,DT)<18
QUIT
+3 DO S^APCHPWH1("Diabetes and LDL Control",1)
+4 IF '$$DMDX^APCHPWH2(APCHSDFN)
Begin DoDot:1
+5 DO S^APCHPWH1("This section only reports on people who have diabetes. You do not")
+6 DO S^APCHPWH1("have diabetes, so you are not included in this report.")
+7 QUIT
End DoDot:1
QUIT
+8 ;365 days ago
SET APCHX=$$LDL(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT,1)
+9 IF APCHX=""
Begin DoDot:1
+10 DO S^APCHPWH1("Your LDL was not checked in the past year. We recommend that you have ")
+11 DO S^APCHPWH1("your LDL checked at least once a year.")
+12 QUIT
End DoDot:1
KILL APCHX
QUIT
+13 DO S^APCHPWH1("Your LDL value on "_$$FMTE^XLFDT($PIECE(APCHX,U))_" was "_$PIECE(APCHX,U,2)_$SELECT($PIECE(APCHX,U,3)]"":" "_$PIECE(APCHX,U,3),1:"")_". An LDL less than 100 mg/dl")
+14 DO S^APCHPWH1("is good. Sometimes it is better to have a lower LDL value. Talk to your")
+15 DO S^APCHPWH1("health care provider about an LDL value that is good for you.")
+16 QUIT
+17 ;
LDL(P,BDATE,EDATE,NORES) ;EP
+1 NEW APCHG,APCHT,APCHC,APCHLT,T,B,E,D,L,X,R,G,C,%
+2 KILL APCHG,APCHT,APCHC
+3 SET APCHC=0
+4 SET NORES=$GET(NORES)
+5 ;now get all loinc/taxonomy tests
+6 SET T=$ORDER(^ATXAX("B","BGP LDL LOINC CODES",0))
+7 SET APCHLT=$ORDER(^ATXLAB("B","DM AUDIT LDL CHOLESTEROL TAX",0))
+8 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)
QUIT
Begin DoDot:1
+9 SET L=0
FOR
SET L=$ORDER(^AUPNVLAB("AE",P,D,L))
IF L'=+L
QUIT
Begin DoDot:2
+10 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AE",P,D,L,X))
IF X'=+X
QUIT
Begin DoDot:3
+11 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+12 IF $GET(NORES)
IF $PIECE(^AUPNVLAB(X,0),U,4)=""
QUIT
+13 SET R=$PIECE(^AUPNVLAB(X,0),U,4)
+14 IF $GET(NORES)
IF 'R
QUIT
+15 IF $GET(NORES)
IF $$UP^XLFSTR(X)["COMMENT"
QUIT
+16 IF APCHLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCHLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET APCHC=APCHC+1
SET APCHT(D,APCHC)=$PIECE(^AUPNVLAB(X,0),U,4)_U_$PIECE($GET(^AUPNVLAB(X,11)),U,1)
QUIT
+17 IF 'T
QUIT
+18 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+19 IF '$$LOINC(J,T)
QUIT
+20 SET R=$PIECE(^AUPNVLAB(X,0),U,4)
+21 SET APCHC=APCHC+1
SET APCHT(D,APCHC)=R_U_$PIECE($GET(^AUPNVLAB(X,11)),U,1)
+22 QUIT
End DoDot:3
End DoDot:2
End DoDot:1
+23 ; now got though and set return value of done 1 or 0^VALUE^date
+24 SET D=0
SET G=""
FOR
SET D=$ORDER(APCHT(D))
IF D'=+D!(G]"")
QUIT
Begin DoDot:1
+25 SET C=0
FOR
SET C=$ORDER(APCHT(D,C))
IF C'=+C!(G]"")
QUIT
Begin DoDot:2
+26 SET X=$PIECE(APCHT(D,C),U)
+27 SET G=(9999999-D)_U_X_U_$PIECE(APCHT(D,C),U,2)
+28 QUIT
End DoDot:2
End DoDot:1
+29 QUIT G
+30 ;
LOINC(A,B) ;EP
+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 ""
+7 ;
DBP ;EP
+1 IF $$AGE^AUPNPAT(APCHSDFN,DT)<18
QUIT
+2 NEW APCHX
+3 DO S^APCHPWH1("Diabetes and BP Control",1)
+4 IF '$$DMDX^APCHPWH2(APCHSDFN)
Begin DoDot:1
+5 DO S^APCHPWH1("This section only reports on people who have diabetes. You do not")
+6 DO S^APCHPWH1("have diabetes, so you are not included in this report.")
+7 QUIT
End DoDot:1
QUIT
+8 SET APCHX=$$LASTITEM^APCLAPIU(APCHSDFN,"BP","MEASUREMENT",$$FMADD^XLFDT(DT,-365),DT,"A")
+9 IF APCHX=""
Begin DoDot:1
+10 DO S^APCHPWH1("Your Blood Pressure was not checked in the past year. We recommend that")
+11 DO S^APCHPWH1("you have your Blood Pressure checked at least three times a year.")
+12 QUIT
End DoDot:1
KILL APCHX
QUIT
+13 DO S^APCHPWH1("Your Blood Pressure on "_$$FMTE^XLFDT($PIECE(APCHX,U))_" was "_$PIECE(APCHX,U,3)_". A blood pressure that is")
+14 DO S^APCHPWH1("less than or equal to 140/90 is good for some people. If you have diabetes")
+15 DO S^APCHPWH1("or kidney problems, you may want your blood pressure to be less than 130/80.")
+16 DO S^APCHPWH1("Talk to your health care provider about a blood pressure that is good for you.")
+17 QUIT
+18 ;
FLU ;EP - FLU
+1 NEW APCHX
+2 DO S^APCHPWH1("Flu Shot (Influenza) Vaccine",1)
+3 IF $$AGE^AUPNPAT(APCHSDFN,DT)<50
Begin DoDot:1
+4 DO S^APCHPWH1("This section only reports on people who are 50 years of age or older.")
+5 DO S^APCHPWH1("You are younger than 50, so you are not included in this report.")
+6 QUIT
End DoDot:1
QUIT
+7 SET APCHX=$$LASTFLU^APCLAPI4(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT,"A")
+8 IF APCHX=""
Begin DoDot:1
+9 DO S^APCHPWH1("You did not have a flu shot this year. We recommend that you have a flu shot")
+10 DO S^APCHPWH1("every year.")
+11 QUIT
End DoDot:1
KILL APCHX
QUIT
+12 DO S^APCHPWH1("You had your flu shot on "_$$FMTE^XLFDT($PIECE(APCHX,U))_". We recommend that you have a ")
+13 DO S^APCHPWH1("flu shot every year.")
+14 QUIT
+15 ;
O2 ;EP - OXYGEN ASSESSMENT
+1 NEW APCHX,X,Y
+2 IF $$AGE^AUPNPAT(APCHSDFN,DT)<18
Begin DoDot:1
+3 DO S^APCHPWH1("")
End DoDot:1
QUIT
+4 DO S^APCHPWH1("Assessment of Oxygen Status",1)
+5 DO PNEUOX(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT,.APCHX)
+6 ;
+7 IF 'APCHX("DENOM")!($$AGE^AUPNPAT(APCHSDFN,DT)<18)
Begin DoDot:1
+8 DO S^APCHPWH1("This section only reports on people who came to the clinic or emergency")
+9 DO S^APCHPWH1("room with pneumonia. You did not come to the clinic this year with")
+10 DO S^APCHPWH1("pneumonia so you are not included in this report.")
+11 QUIT
End DoDot:1
QUIT
+12 SET X=0
FOR
SET X=$ORDER(APCHX(X))
IF X'=+X
QUIT
Begin DoDot:1
+13 SET Y=$$FMTE^XLFDT($PIECE(APCHX(X),U,3))
+14 DO S^APCHPWH1("You came to the hospital with pneumonia on "_Y_". The goal is to have",1)
+15 DO S^APCHPWH1("your oxygen level checked within 24 hours of your hospital visit. Your")
+16 DO S^APCHPWH1("oxygen level was "_$SELECT($PIECE(APCHX(X),U,2)["NOT MET":"not ",1:"")_"checked within 24 hours of your hospital visit.")
End DoDot:1
+17 QUIT
+18 ;
PNEUOX(P,BDATE,EDATE,APCHR) ;EP
+1 NEW A,B,C,D,E,F,G,APCHG,APCHX,APCHD,APCHV,APCHC
+2 KILL APCHG,APCHR
+3 SET APCHR=""
SET APCHR(0)=""
+4 SET X=P_"^ALL DX [BGP CMS PNEUMONIA;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,"APCHG(")
+5 IF '$DATA(APCHG(1))
SET APCHR("DENOM")=0
QUIT
+6 ;now go through and get rid of CHS or service category not A, O, S
+7 SET A=0
FOR
SET A=$ORDER(APCHG(A))
IF A'=+A
QUIT
Begin DoDot:1
+8 SET V=$PIECE(APCHG(A),U,5)
+9 IF '$DATA(^AUPNVSIT(V,0))
KILL APCHG(A)
+10 IF $PIECE(^AUPNVSIT(V,0),U,3)="C"
KILL APCHG(A)
+11 IF "AOS"'[$PIECE(^AUPNVSIT(V,0),U,7)
KILL APCHG(A)
End DoDot:1
+12 ;got rid of them all
IF '$DATA(APCHG)
SET APCHR("DENOM")=0
QUIT
+13 ;reorder the diagnoses by visit date
+14 SET A=0
FOR
SET A=$ORDER(APCHG(A))
IF A'=+A
QUIT
SET V=$PIECE(APCHG(A),U,5)
SET D=$PIECE($PIECE($GET(^AUPNVSIT(V,0)),U),".")
SET APCHX(D,V)=APCHG(A)
+15 ;now get the first one
+16 SET APCHD=0
SET APCHC=0
FOR
SET APCHD=$ORDER(APCHX(APCHD))
IF APCHD'=+APCHD
QUIT
Begin DoDot:1
+17 SET APCHV=0
FOR
SET APCHV=$ORDER(APCHX(APCHD,APCHV))
IF APCHV'=+APCHV
QUIT
Begin DoDot:2
+18 ;set denominator
SET APCHC=APCHC+1
SET APCHR(APCHC)=APCHC_") "_$$FMTE^XLFDT(APCHD)_" "_$PIECE(APCHX(APCHD,APCHV),U,2)
+19 ; any o2 saturation on this visit?
SET G=$$OXSAT(APCHV)
+20 ;set numerator column
SET $PIECE(APCHR(APCHC),U,2)=APCHC_") "_$PIECE(G,U,1)
+21 SET $PIECE(APCHR(APCHC),U,3)=APCHD
+22 SET $PIECE(APCHR(0),U,$PIECE(G,U,2))=$PIECE(APCHR(0),U,$PIECE(G,U,2))+1
+23 ;now delete out all visits that are <46 days difference and all other visits on the same day
+24 SET V=APCHV
FOR
SET V=$ORDER(APCHX(APCHD,V))
IF V'=+V
QUIT
KILL APCHX(APCHD,V)
+25 SET D=APCHD
SET V=APCHV
FOR
SET D=$ORDER(APCHX(D))
IF D'=+D
QUIT
Begin DoDot:3
+26 SET V=0
FOR
SET V=$ORDER(APCHX(D,V))
IF V'=+V
QUIT
IF $$FMDIFF^XLFDT(D,APCHD)<46
KILL APCHX(D,V)
End DoDot:3
End DoDot:2
End DoDot:1
+27 SET APCHR("DENOM")=APCHC
+28 QUIT
+29 ;
OXSAT(V) ;was there ox sat at the visit
+1 ;get all O2 measurements on or after admission date
+2 NEW APCHD,X,N,E,Y,T,D,C,APCHLT,L,J,APCHG,M,M1
+3 SET APCHG=""
+4 SET APCHD=$PIECE($PIECE(^AUPNVSIT(V,0),U),".")
+5 ;K APCHG S Y="APCHG(",X=P_"^ALL MEAS O2;DURING "_$$FMTE^XLFDT(BD)_"-"_$$FMTE^XLFDT(ED) S E=$$START1^APCLDF(X,Y)
+6 SET X=0
FOR
SET X=$ORDER(^AUPNVMSR("AD",V,X))
IF X'=+X!(APCHG]"")
QUIT
IF $$VAL^XBDIQ1(9000010.01,X,.01)="O2"
IF '$PIECE($GET(^AUPNVMSR(X,2)),U,1)
SET APCHG=$$FMTE^XLFDT(APCHD)_" MET O2 SAT^1"
+7 IF APCHG]""
QUIT APCHG
+8 ;now check for cpts
+9 SET T=$ORDER(^ATXAX("B","BGP CMS ABG CPTS",0))
+10 SET X=0
FOR
SET X=$ORDER(^AUPNVCPT("AD",V,X))
IF X'=+X!(APCHG]"")
QUIT
Begin DoDot:1
+11 IF '$DATA(^AUPNVCPT(X,0))
QUIT
+12 SET C=$PIECE(^AUPNVCPT(X,0),U)
+13 IF '$$ICD^ATXAPI(C,T,1)
QUIT
+14 SET M=$$VAL^XBDIQ1(9000010.18,X,.08)
+15 SET M1=$$VAL^XBDIQ1(9000010.18,X,.09)
+16 ;3028f and has modifier
IF $PIECE(^ICPT(C,0),U)="3028F"
IF (M="1P"!(M="2P")!(M="3P")!(M="4P")!(M="8P"))
QUIT
+17 ;3028f and has modifier
IF $PIECE(^ICPT(C,0),U)="3028F"
IF (M1="1P"!(M="2P")!(M="3P")!(M="4P")!(M="8P"))
QUIT
+18 SET APCHG=$$FMTE^XLFDT(APCHD)_" MET CPT ["_$PIECE($$CPT^ICPTCOD(C),U,2)_"]^1"
+19 QUIT
End DoDot:1
+20 IF APCHG]""
QUIT APCHG
+21 ;now check v tran
+22 SET T=$ORDER(^ATXAX("B","BGP CMS ABG CPTS",0))
+23 SET X=0
FOR
SET X=$ORDER(^AUPNVTC("AD",V,X))
IF X'=+X!(APCHG]"")
QUIT
Begin DoDot:1
+24 IF '$DATA(^AUPNVTC(X,0))
QUIT
+25 SET C=$PIECE(^AUPNVTC(X,0),U,7)
+26 IF C=""
QUIT
+27 IF '$$ICD^ATXAPI(C,T,1)
QUIT
+28 SET APCHG=$$FMTE^XLFDT(APCHD)_" MET CPT/TRAN ["_$PIECE($$CPT^ICPTCOD(C),U,2)_"]^1"
+29 QUIT
End DoDot:1
+30 IF APCHG]""
QUIT APCHG
+31 ;now check for lab tests
+32 SET T=$ORDER(^ATXAX("B","BGP CMS ABG LOINC",0))
+33 SET APCHLT=$ORDER(^ATXLAB("B","BGP CMS ABG TESTS",0))
+34 SET X=0
FOR
SET X=$ORDER(^AUPNVLAB("AD",V,X))
IF X'=+X!(APCHG]"")
QUIT
Begin DoDot:1
+35 IF '$DATA(^AUPNVLAB(X,0))
QUIT
+36 IF APCHLT
IF $PIECE(^AUPNVLAB(X,0),U)
IF $DATA(^ATXLAB(APCHLT,21,"B",$PIECE(^AUPNVLAB(X,0),U)))
SET APCHG=$$FMTE^XLFDT(APCHD)_" MET "_$$VAL^XBDIQ1(9000010.09,X,.01)_"^1"
QUIT
+37 IF 'T
QUIT
+38 SET J=$PIECE($GET(^AUPNVLAB(X,11)),U,13)
IF J=""
QUIT
+39 IF '$$LOINC(J,T)
QUIT
+40 SET APCHG=$$FMTE^XLFDT(APCHD)_" MET "_$$VAL^XBDIQ1(9000010.09,X,.01)_"^1"
QUIT
End DoDot:1
+41 IF APCHG]""
QUIT APCHG
+42 ;now go get refusals of any of the above
+43 ;
+44 SET G=$$REFUSAL^APCHSMU(P,9999999.07,$ORDER(^AUTTMSR("B","O2",0)),APCHD,APCHD)
+45 IF G
QUIT $$FMTE^XLFDT(APCHD)_" NOT MET DECLINED O2 SAT^2"
+46 ;refusal of lab tests
+47 SET T=$ORDER(^ATXLAB("B","BGP CMS ABG TESTS",0))
+48 SET L=0
FOR
SET L=$ORDER(^ATXLAB(T,21,"B",L))
IF L'=+L!(APCHG]"")
QUIT
Begin DoDot:1
+49 SET G=$$REFUSAL^APCHSMU(P,60,L,APCHD,APCHD)
+50 IF G
SET APCHG=$$FMTE^XLFDT(APCHD)_" NOT MET DECLINED LAB^2"
End DoDot:1
+51 IF APCHG]""
QUIT APCHG
+52 SET G=$$CPTREFT^APCHSMU(P,APCHD,APCHD,$ORDER(^ATXAX("B","BGP CMS ABG CPTS",0)))
+53 IF G
QUIT $$FMTE^XLFDT(APCHD)_" NOT MET DECLINED CPT^2"
+54 QUIT $$FMTE^XLFDT(APCHD)_" NOT MET; NO ASSMT^3"
+55 ;