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

APCHS9B1.m

Go to the documentation of this file.
  1. APCHS9B1 ; IHS/CMI/LAB - DIABETIC CARE SUMMARY SUPPLEMENT ;
  1. ;;2.0;IHS PCC SUITE;**2,4,5,11**;MAY 14, 2009;Build 58
  1. ;
  1. ;IHS/CMI/LAB patch 3 many changes
  1. ;patch 14 added depression screening
  1. ;patch 14 added loinc code lookups
  1. ;cmi/anch/maw 8/27/2007 code set versioning in DMPN and DEPPL
  1. ;
  1. EP ;EP - called from component
  1. Q:'$G(APCHSPAT)
  1. I $E(IOST)="C",IO=IO(0) W !! S DIR("A")="DIABETES SUMMARY WILL NOW BE DISPLAYED (^ TO EXIT, RETURN TO CONTINUE)",DIR(0)="E" D ^DIR I $D(DIRUT) S APCHSQIT=1 Q ;IHS/CMI/LAB fixed for slave printing
  1. ;NEW X S X="BDMS9B1" X ^%ZOSF("TEST") I $T D ^BDMS9B1 D EOJ Q
  1. D EP2(APCHSPAT)
  1. W ;write out array
  1. W:$D(IOF) @IOF
  1. K APCHQUIT
  1. S APCHX=0 F S APCHX=$O(^TMP("APCHS",$J,"DCS",APCHX)) Q:APCHX'=+APCHX!($D(APCHQUIT)) D
  1. .I $Y>(IOSL-3) D HEADER Q:$D(APCHQUIT)
  1. .W !,^TMP("APCHS",$J,"DCS",APCHX)
  1. .Q
  1. I $D(APCHQUIT) S APCHSQIT=1
  1. D EOJ
  1. Q
  1. ;
  1. EOJ ;
  1. K APCHX,APCHQUIT,APCHY,APCHSDFN,APCHSBEG,APCHSTOB,APCHSUPI,APCHSED,APCHTOBN,APCHTOB,APCHSTEX
  1. K N,%,T,F,X,Y,B,C,E,F,H,L,N,P,T,W
  1. Q
  1. K DIR I $E(IOST)="C",IO=IO(0) W ! S DIR(0)="EO" D ^DIR K DIR I Y=0!(Y="^")!($D(DTOUT)) S APCHQUIT="" Q
  1. HEAD1 ;
  1. W:$D(IOF) @IOF
  1. W !,APCHSHDR,!
  1. W !,"Diabetes Patient Care Summary - continued"
  1. W !,"Patient: ",$P(^DPT(APCHSPAT,0),U)," HRN: ",$$HRN^AUPNPAT(APCHSPAT,DUZ(2)),!
  1. Q
  1. EP2(APCHSDFN) ;PEP - PASS DFN get back array of patient care summary
  1. ;at this point you are stuck with ^TMP("APCHS",$J,"DCS"
  1. NEW X S X="BDMS9B1" X ^%ZOSF("TEST") I $T D EP2^BDMS9B1(APCHSDFN) Q
  1. K ^TMP("APCHS",$J,"DCS")
  1. S ^TMP("APCHS",$J,"DCS",0)=0
  1. I '$D(APCHSCVD) S APCHSCVD="S:Y]"""" Y=+Y,Y=$E(Y,4,5)_""/""_$S($E(Y,6,7):$E(Y,6,7)_""/"",1:"""")_$E(Y,2,3)"
  1. D SETARRAY
  1. Q
  1. SETARRAY ;set up array containing dm care summary
  1. ;CHECK TO SEE IF START1^APCLDF EXISTS
  1. S X="APCLDF" X ^%ZOSF("TEST") I '$T Q
  1. S X="DIABETES PATIENT CARE SUMMARY Report Date: "_$$FMTE^XLFDT(DT) D S(X)
  1. S X="Patient Name: "_$P(^DPT(APCHSDFN,0),U)_" HRN: "_$$HRN^AUPNPAT(APCHSDFN,DUZ(2)) D S(X)
  1. I $$DOD^AUPNPAT(APCHSDFN)]"" S X="DATE OF DEATH: "_$$FMTE^XLFDT($$DOD^AUPNPAT(APCHSDFN)) D S(X,1),S(" ")
  1. S X="Age: "_$$AGE^AUPNPAT(APCHSDFN),$E(X,15)="Sex: "_$$SEX^AUPNPAT(APCHSDFN),$E(X,31)="Date of DM Onset: "_$$DOO(APCHSDFN) D S(X)
  1. S X="",X="Dob: "_$$FMTE^XLFDT($$DOB^AUPNPAT(APCHSDFN)) S Y=$$DMPN(APCHSDFN),$E(X,31)="DM Problem #: "_$S(Y]"":Y,1:"*** NONE RECORDED ***") D S(X)
  1. S X="" I '$$NOTREG(APCHSDFN) S X="**NOT ON DIABETES REGISTER**"
  1. S $E(X,31)="Designated PCP: "_$$VAL^XBDIQ1(9000001,APCHSDFN,.14) D S(X)
  1. D GETHWB(APCHSDFN) S X="Last Height: "_APCHX("HT")_$S(APCHX("HT")]"":" inches",1:""),$E(X,31)=APCHX("HTD") D S(X)
  1. S X="Last Weight: "_$S(APCHX("WT")]"":$J(APCHX("WT"),3,0),1:"")_$S(APCHX("WT")]"":" lbs",1:""),$E(X,31)=APCHX("WTD"),$E(X,45)="BMI: "_APCHX("BMI") D S(X)
  1. I APCHX("WC")]"" S X="Last Waist Circumference: "_APCHX("WC"),$E(X,31)=APCHX("WCD") D S(X)
  1. D TOBACCO^APCHS9B6
  1. S X="Tobacco Use: "_$G(APCHTOB) D S(X)
  1. S X="HTN Diagnosed: "_$$HTN(APCHSDFN) D S(X)
  1. S APCHSBEG=$$FMADD^XLFDT(DT,-(6*30.5))
  1. S %=$$ACE^APCHS9B5(APCHSDFN,APCHSBEG) ;get date of last ACE in last year
  1. S X="",X="ON ACE Inhibitor/ARB in past 6 months: "_% D S(X)
  1. K APCHSX S APCHSBEG=$$FMADD^XLFDT(DT,-365) S X="Aspirin Use/Anti-platelet (in past yr): "_$E($$ASPIRIN(APCHSDFN,APCHSBEG),1,32) D S(X)
  1. S X="",X=$$ASPREF^APCHS9B5(APCHSDFN) I X]"" S X=" "_X D S(X)
  1. S APCHDEPP=$$DEPPL(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT)
  1. S APCHDEPS=$$DEPSCR(APCHSDFN,$$FMADD^XLFDT(DT,-365),DT)
  1. S B=$$BP(APCHSDFN)
  1. S X="Last 3 BP: "_$P($G(APCHX(1)),U,2)_" "_$$FMTE^XLFDT($P($G(APCHX(1)),U))
  1. S $E(X,40)="Is Depression on the Problem List?"
  1. D S(X)
  1. S X="(non ER)" I $D(APCHX(2)) S $E(X,13)=$P(APCHX(2),U,2)_" "_$$FMTE^XLFDT($P(APCHX(2),U))
  1. S $E(X,42)=APCHDEPP
  1. D S(X)
  1. S X="" I $D(APCHX(3)) S X="",$E(X,13)=$P(APCHX(3),U,2)_" "_$$FMTE^XLFDT($P(APCHX(3),U))
  1. I $E(APCHDEPP,1)="N" S $E(X,40)="If no, Depression Screening in past year?"
  1. D S(X)
  1. S X="" I $E(APCHDEPP,1)="N" S $E(X,42)=APCHDEPS
  1. D S(X)
  1. M12 ;
  1. ;determine date range
  1. S APCHSBEG=$$FMADD^XLFDT(DT,-365)
  1. S X="In past 12 months:" D S(X)
  1. S X="Diabetic Foot Exam:",$E(X,23)=$$DFE^APCHS9B4(APCHSDFN,APCHSBEG) D S(X)
  1. S X="Diabetic Eye Exam:",$E(X,23)=$$EYE^APCHS9B4(APCHSDFN,APCHSBEG) D S(X)
  1. S X="Dental Exam:",$E(X,23)=$$DENTAL^APCHS9B6(APCHSDFN,APCHSBEG) D S(X)
  1. ;S X="Rectal Exam (age>40):",$E(X,27)=$$RECTAL^APCHS9B4(APCHSDFN,APCHSBEG) D S(X)
  1. K APCHSTEX,APCHSDAT,APCHX
  1. I $P(^DPT(APCHSDFN,0),U,2)="F" D
  1. .S X="(Females Only)" D S(X)
  1. .K APCHSTEX,APCHSDAT
  1. .S APCHX=$$PAP^APCHS9B4(APCHSDFN) ;get date of last pap in pcc/refusal
  1. .S X="Last Pap Smear documented in PCC/WH: "_$$FMTE^XLFDT($P(APCHX,U)) D S(X)
  1. .I $P(APCHX,U,2)]"" S X=$P(APCHX,U,2) D S(X)
  1. .D PAP^APCHS9B5
  1. .S X="",$E(X,17)="WH Cervical TX Need:",$E(X,38)=$G(APCHSTEX(1)) D S(X)
  1. .S X="",Y=1 F S Y=$O(APCHSTEX(Y)) Q:Y="" S X="",$E(X,12)=APCHSTEX(Y) D S(X)
  1. .;S X=" Breast exam:",$E(X,27)=$$BREAST^APCHS9B4(APCHSDFN,APCHSBEG) D S(X)
  1. .K APCHSTEX,APCHSDAT D MAM^APCHS9B5 S X="Mammogram:",$E(X,12)=$$FMTE^XLFDT(APCHSDAT)_" "_$G(APCHSTEX(1)) D S(X)
  1. .S X="",Y=1 F S Y=$O(APCHSTEX(Y)) Q:Y="" S X="",$E(X,23)=APCHSTEX(Y) D S(X)
  1. D MORE^APCHS9B2
  1. S X=$P(^DPT(APCHSDFN,0),U),$E(X,35)="DOB: "_$$DOB^AUPNPAT(APCHSDFN,"S"),$E(X,55)="Chart #"_$$HRN^AUPNPAT(APCHSDFN,DUZ(2),2) D S(X,1) ;IHS/CMI/LAB - X,3 to X,2
  1. ;S X="" D S(X,1)
  1. Q
  1. S(Y,F,C,T) ;set up array
  1. I '$G(F) S F=0
  1. I '$G(T) S T=0
  1. NEW %,X
  1. ;blank lines
  1. F F=1:1:F S X="" D S1
  1. S X=Y
  1. I $G(C) S L=$L(Y),T=(80-L)/2 D D S1 Q
  1. .F %=1:1:(T-1) S X=" "_X
  1. F %=1:1:T S X=" "_Y
  1. D S1
  1. Q
  1. S1 ;
  1. S %=$P(^TMP("APCHS",$J,"DCS",0),U)+1,$P(^TMP("APCHS",$J,"DCS",0),U)=%
  1. S ^TMP("APCHS",$J,"DCS",%)=X
  1. Q
  1. HTN(P) ;
  1. ;check problem list OR must have 3 diagnoses
  1. N T S T=$O(^ATXAX("B","SURVEILLANCE HYPERTENSION",0))
  1. I 'T Q ""
  1. N X,Y,I S (X,Y,I)=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(I) I $D(^AUPNPROB(X,0)),$P(^AUPNPROB(X,0),U,12)'="D" S Y=$P(^AUPNPROB(X,0),U) I $$ICD^ATXAPI(Y,T,9) S I=1
  1. I I Q "Yes"
  1. NEW APCHX
  1. S APCHX=""
  1. S X=P_"^LAST 3 DX [SURVEILLANCE HYPERTENSION" S E=$$START1^APCLDF(X,"APCHX(") G:E HTNX I $D(APCHX(3)) S APCHX="Yes"
  1. I $G(APCHX)="" S APCHX="No"
  1. HTNX ;
  1. Q APCHX
  1. DMPN(P) ;return problem number of lowest DM code
  1. I '$G(P) Q ""
  1. NEW T S T=$O(^ATXAX("B","SURVEILLANCE DIABETES",0))
  1. I 'T Q ""
  1. NEW D,X,I S D="",X=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X D
  1. .Q:$P(^AUPNPROB(X,0),U,12)="D"
  1. .S I=$P(^AUPNPROB(X,0),U)
  1. .I $$ICD^ATXAPI(I,T,9) D
  1. ..;S D(+$P(^ICD9(I,0),U))=X cmi/anch/maw 8/27/2007 orig line
  1. ..S D(+$P($$ICDDX^ICDEX(I,,,"I"),U,2))=X ;cmi/anch/maw 8/27/2007 code set versioning
  1. ..Q
  1. .Q
  1. S D=$O(D(""))
  1. I D="" Q D
  1. S X=D(D) ;ien of problem now return problem #
  1. NEW L S L=$P(^AUPNPROB(X,0),U,6)
  1. NEW Y S Y=$S(L:$P(^AUTTLOC(L,0),U,7),1:"???")_$P(^AUPNPROB(X,0),U,7)
  1. Q Y
  1. BP(P) ;last 3 BPs
  1. ;IHS/CMI/LAB - fixed to exclude ER visits for BP's
  1. NEW APCHD,APCHC
  1. K APCHX
  1. S APCHX="",APCHD="",APCHC=0
  1. ;S X=P_"^LAST 3 MEASUREMENTS BP" S E=$$START1^APCLDF(X,"APCHX(") G:E BPX I $D(APCHX(1)) D
  1. S T=$O(^AUTTMSR("B","BP",""))
  1. F S APCHD=$O(^AUPNVMSR("AA",P,T,APCHD)) Q:APCHD=""!(APCHC=3) D
  1. .S M=0 F S M=$O(^AUPNVMSR("AA",P,T,APCHD,M)) Q:M'=+M!(APCHC=3) D
  1. ..S V=$P($G(^AUPNVMSR(M,0)),U,3) Q:'V
  1. ..Q:'$D(^AUPNVSIT(V,0))
  1. ..Q:$P($G(^AUPNVMSR(M,2)),U,1) ;entered in error
  1. ..Q:$$CLINIC^APCLV(V,"C")=30
  1. ..S APCHC=APCHC+1,APCHX(APCHC)=(9999999-APCHD)_U_$P(^AUPNVMSR(M,0),U,4)
  1. ..Q
  1. .Q
  1. I '$D(APCHX(1)) S APCHX(1)="None recorded"
  1. BPX ;
  1. K APCHD,APCHC
  1. Q APCHX
  1. GETHWB(P) ;get last height, height date, weight, weight date and BMI for patient P, return in APCHX("HT"),APCHX("HTD"),APCHX("WT"),APCHX("WTD"),APCHX("BMI")
  1. K APCHX
  1. S APCHX("HT")="",APCHX("HTD")="",APCHX("WT")="",APCHX("WTD")="",APCHX("BMI")="",APCHX("WC")="",APCHX("WCD")=""
  1. LASTHT ;
  1. Q:'$D(^AUPNVSIT("AC",P))
  1. Q:'$D(^AUPNVMSR("AC",P))
  1. NEW APCHY
  1. S %=P_"^LAST MEAS HT" NEW X S E=$$START1^APCLDF(%,"APCHY(") S APCHX("HT")=$P($G(APCHY(1)),U,2),APCHX("HTD")=$$FMTE^XLFDT($P($G(APCHY(1)),U))
  1. S APCHX("HT")=$S(APCHX("HT")]"":$J(APCHX("HT"),2,0),1:"")
  1. LASTWT ;
  1. K APCHY S %=P_"^LAST MEAS WT" NEW X S E=$$START1^APCLDF(%,"APCHY(") S APCHX("WT")=$P($G(APCHY(1)),U,2),APCHX("WTD")=$$FMTE^XLFDT($P($G(APCHY(1)),U))
  1. LASTWC ;
  1. K APCHY S %=P_"^LAST MEAS WC" NEW X S E=$$START1^APCLDF(%,"APCHY(") S APCHX("WC")=$P($G(APCHY(1)),U,2),APCHX("WCD")=$$FMTE^XLFDT($P($G(APCHY(1)),U))
  1. BMI ;
  1. I $$AGE^AUPNPAT(P)<19,(APCHX("WTD")'=APCHX("HTD")) Q
  1. I APCHX("WT")=""!('APCHX("HT")) Q
  1. S %=""
  1. ;S W=(APCHX("WT")/5)*2.3,H=(APCHX("HT")*2.5),H=(H*H)/10000,%=(W/H),%=$J(%,4,1)
  1. S W=APCHX("WT")*.45359,H=(APCHX("HT")*0.0254),H=(H*H),%=(W/H),%=$J(%,4,1)
  1. S APCHX("BMI")=%
  1. Q
  1. ASPIRIN(P,D) ;
  1. I '$G(P) Q ""
  1. I '$G(D) S D=0 ;if don't pass date look at all time
  1. NEW V,I,%
  1. S %=""
  1. NEW T,T1 S T=$O(^ATXAX("B","DM AUDIT ASPIRIN DRUGS",0))
  1. S T1=$O(^ATXAX("B","DM AUDIT ANTI-PLATELET DRUGS",0))
  1. I 'T Q ""
  1. S I=0 F S I=$O(^AUPNVMED("AA",P,I)) Q:I'=+I!(%)!(I>(9999999-D)) D
  1. .S V=0 F S V=$O(^AUPNVMED("AA",P,I,V)) Q:V'=+V!(%) S G=$P(^AUPNVMED(V,0),U) D
  1. ..I $D(^ATXAX(T,21,"B",G)) S %=V Q
  1. ..I T1,$D(^ATXAX(T1,21,"B",G)) S %=V Q
  1. I %]"" D Q %
  1. .I $P(^AUPNVMED(%,0),U,8)="" S %="Yes - "_$$FMTE^XLFDT($P($P(^AUPNVSIT($P(^AUPNVMED(%,0),U,3),0),U),"."))_" "_$$VAL^XBDIQ1(9000010.14,%,.01) Q
  1. .I $P(^AUPNVMED(%,0),U,8)]"" S %="Discontinued - "_$$FMTE^XLFDT($P($P(^AUPNVSIT($P(^AUPNVMED(%,0),U,3),0),U),"."))_" "_$$VAL^XBDIQ1(9000010.14,%,.01) Q
  1. Q "No"
  1. DOO(P) ;get earliest date of onset
  1. NEW X,DOO
  1. S X=$$CMSFDX^APCHS9B4(P,"I")
  1. I X]"",'$D(DOO(X)) S DOO(X)="Diabetes Register"
  1. S DOO="" S X=$$PLDMDOO^APCHS9B4(P,"I")
  1. I X]"" S DOO(X)="Problem List"
  1. I $O(DOO(0))="" Q ""
  1. S X=$O(DOO(0)) Q $$FMTE^XLFDT(X)_" ("_DOO(X)_")"
  1. NOTREG(P) ;is patient on any Diabetes register 1 if on reg, "" if not
  1. I $G(P)="" Q ""
  1. NEW X,Y
  1. S X=0,Y="" F S X=$O(^ACM(41,"AC",P,X)) Q:X'=+X!(Y) D
  1. .S N=$$UP^XLFSTR($P($G(^ACM(41.1,X,0)),U))
  1. .I N["DIABETES" S Y=1
  1. .I N["DIAB" S Y=1
  1. .I N["DM " S Y=1
  1. .I N[" DM" S Y=1
  1. .Q
  1. Q Y
  1. DEPPL(P,BDATE,EDATE) ;EP
  1. NEW APCH,X
  1. K APCH
  1. S (G,X,I)=""
  1. ;is depression on the problem list?
  1. S T=$O(^ATXAX("B","DM AUDIT DEPRESSIVE DISORDERS",0))
  1. S X=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G]"") D
  1. .Q:$P(^AUPNPROB(X,0),U,12)'="A"
  1. .S I=$P($G(^AUPNPROB(X,0)),U)
  1. .Q:'$$ICD^ATXAPI(I,T,9)
  1. .;S G="Yes - Problem List "_$P(^ICD9(I,0),U) cmi/anch/maw 8/27/2007 orig line
  1. .S G="Yes - Problem List "_$P($$ICDDX^ICDEX(I,,"I"),U,2) ;cmi/anch/maw 8/27/2007 code set versioning
  1. .Q
  1. I G]"" Q G
  1. S (G,X,I)=""
  1. ;is depression on the BH problem list?
  1. S T=$O(^ATXAX("B","DM AUDIT DEPRESSIVE DISORDERS",0))
  1. S X=0 F S X=$O(^AMHPPROB("AC",P,X)) Q:X'=+X!(G]"") D
  1. .S I=$P($G(^AMHPPROB(X,0)),U)
  1. .S I=$P($G(^AMHPROB(I,0)),U,5)
  1. .Q:I=""
  1. .S I=+$$IEN^ICDEX(I,80,1)
  1. .Q:I=""
  1. .Q:'$$ICD^ATXAPI(I,T,9)
  1. .;S G="Yes - BH Problem List "_$P(^ICD9(I,0),U) cmi/anch/maw 8/27/2007 orig line
  1. .S G="Yes - BH Problem List "_$P($$ICDDX^ICDEX(I,,,"I"),U,2) ;cmi/anch/maw 8/27/2007 code set versioning
  1. .Q
  1. I G]"" Q G
  1. ;now check for 2 dxs in past year
  1. S Y="APCH("
  1. S X=P_"^LAST 2 DX [DM AUDIT DEPRESSIVE DISORDERS;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(X,Y)
  1. I $D(APCH(2)) Q "Yes 2 or more dxs in past year"
  1. S APCH=0,APCHV="" I $D(APCH(1)) S APCH=1,APCHV=$P(APCH(1),U,5)
  1. S X=BDATE,%DT="P" D ^%DT S BD=Y
  1. S X=EDATE,%DT="P" D ^%DT S ED=Y
  1. ;go through BH record file and find up to 2 visits in date range
  1. S E=9999999-BDATE,D=9999999-EDATE-1_".99" F S D=$O(^AMHREC("AE",P,D)) Q:D'=+D!($P(D,".")>E)!(APCH>1) S V=0 F S V=$O(^AMHREC("AE",P,D,V)) Q:V'=+V!(APCH>1) D
  1. .Q:'$D(^AMHREC(V,0))
  1. .I $P(^AMHREC(V,0),U,16)]"",APCHV]"",$P(^AMHREC(V,0),U,16)=APCHV Q ;don't use same visit
  1. .S X=0 F S X=$O(^AMHRPRO("AD",V,X)) Q:X'=+X!(APCH>1) S APCHP=$P($G(^AMHRPRO(X,0)),U) D
  1. ..Q:'APCHP
  1. ..S APCHP=$P($G(^AMHPROB(APCHP,0)),U)
  1. ..I APCHP=14 S APCH=APCH+1 Q
  1. ..I APCHP=15 S APCH=APCH+1 Q
  1. ..I APCHP=18 S APCH=APCH+1 Q
  1. ..I APCHP=24 S APCH=APCH+1 Q
  1. ..I $E(APCHP,1,3)=296 S APCH=APCH+1 Q
  1. ..I $E(APCHP,1,3)=300 S APCH=APCH+1 Q
  1. ..I $E(APCHP,1,3)=309 S APCH=APCH+1 Q
  1. ..I APCHP="301.13" S APCH=APCH+1 Q
  1. ..I APCHP=308.3 S APCH=APCH+1 Q
  1. ..I APCHP="311." S APCH=APCH+1 Q
  1. ..Q
  1. I APCH>1 Q "Yes 2 or more dxs in past year"
  1. Q "No"
  1. DEPSCR(P,BDATE,EDATE) ;EP
  1. NEW X
  1. I $G(P)="" Q ""
  1. K APCH S APCHLAST=""
  1. S Y="APCH("
  1. S X=P_"^LAST DX V79.0;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(X,Y)
  1. I $D(APCH(1)) S APCHLAST=$P(APCH(1),U)_U_"Yes V79.0"_" "_$$FMTE^XLFDT($P(APCH(1),U),5)
  1. K APCH
  1. S Y="APCH("
  1. S X=P_"^LAST EXAM 36;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(X,Y)
  1. I $D(APCH(1)),$P(APCH(1),U)>$P(APCHLAST,U) S APCHLAST=$P(APCH(1),U)_U_"Yes Exam 36-Dep Screen "_$$FMTE^XLFDT($P(APCH(1),U),5)
  1. K APCH
  1. S Y="APCH("
  1. S X=P_"^ALL EDUC;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(X,Y)
  1. I '$D(APCH(1)) G BHSCR
  1. S (X,E)=0,%="",T="",D="" F S X=$O(APCH(X)) Q:X'=+X!(D) D
  1. .S T=$P(^AUPNVPED(+$P(APCH(X),U,4),0),U)
  1. .Q:'T
  1. .Q:'$D(^AUTTEDT(T,0))
  1. .S T=$P(^AUTTEDT(T,0),U,2)
  1. .I T="DEP-SCR",$P(APCH(X),U)>$P(APCHLAST,U) S APCHLAST=$P(APCH(X),U)_U_"Yes Pt Ed "_T_" "_$$FMTE^XLFDT($P(APCH(X),U),5)
  1. K APCH
  1. BHSCR ;
  1. S APCHRF="",D=0,APCHC="",E=9999999-BDATE,D=9999999-EDATE-1_".99" F S D=$O(^AMHREC("AE",P,D)) Q:D'=+D!($P(D,".")>E) S V=0 F S V=$O(^AMHREC("AE",P,D,V)) Q:V'=+V D
  1. .S APCHRF=$P($G(^AMHREC(V,14)),U,5) I APCHRF]"",$E(APCHRF)'="R",$E(APCHRF)'="U",(9999999-$P(D,"."))>$P(APCHLAST,U) S APCHLAST=(9999999-$P(D,"."))_U_"Yes BH Dep Scr "_$$FMTE^XLFDT((9999999-$P(D,".")),5) Q
  1. .I APCHRF]"" S APCHRF=$$VAL^XBDIQ1(9002011,V,1405)_" on "_$$FMTE^XLFDT((9999999-$P(D,".")),5)
  1. .S X=0 F S X=$O(^AMHRPRO("AD",V,X)) Q:X'=+X!(APCHC]"") S APCHP=$P($G(^AMHRPRO(X,0)),U) D
  1. ..Q:'APCHP
  1. ..S APCHP=$P($G(^AMHPROB(APCHP,0)),U)
  1. ..I APCHP=14.1,(9999999-$P(D,"."))>$P(APCHLAST,U) S APCHLAST=(9999999-$P(D,"."))_U_"Yes BH 14.1 "_$$FMTE^XLFDT((9999999-$P(D,".")),5) Q
  1. ..I '$D(^AMHREDU("AD",V)) Q
  1. ..S Y=0 F S Y=$O(^AMHREDU("AD",V,Y)) Q:Y'=+Y D
  1. ...S T=$P(^AMHREDU(Y,0),U)
  1. ...Q:'T
  1. ...Q:'$D(^AUTTEDT(T,0))
  1. ...S T=$P(^AUTTEDT(T,0),U,2)
  1. ...I T="DEP-SCR",(9999999-$P(D,"."))>$P(APCHLAST,U) S APCHLAST=(9999999-$P(D,"."))_U_"Yes BH PT Ed "_T_" "_$$FMTE^XLFDT((9999999-$P(D,".")),5)
  1. ...Q
  1. I APCHLAST]"" Q $P(APCHLAST,U,2,99)
  1. ;now check for refusals
  1. S APCHC=$$REFDF^APCHS9B3(P,9999999.15,$O(^AUTTEXAM("B","DEPRESSION SCREENING",0)))
  1. I APCHC]"" S X=$P(APCHC,"DEPRESSION SCREENING ",1)_$P(APCHC,"DEPRESSION SCREENING ",2) Q X
  1. I APCHRF]"" Q APCHRF
  1. Q "No"