BDMD113 ; IHS/CMI/LAB - 2011 DIABETES AUDIT ;
;;2.0;DIABETES MANAGEMENT SYSTEM;**4**;JUN 14, 2007
;
LASTFLU(BDMPDFN,BDMBD,BDMED,BDMFORM) ;PEP - date of last FLU
; Return the last recorded FLU:
; - V Immunization: 15, 16, 88, 111
; - V CPT [dm audit seasonal flu cpts]
; If APCLFORM is A returns the string:
; date^text of item found^value if appropriate^visit ien^File found in^ien of file found in
;
I $G(BDMPDFN)="" Q ""
I $G(BDMBD)="" S BDMBD=$$DOB^AUPNPAT(BDMPDFN)
I $G(BDMED)="" S BDMED=DT
I $G(BDMFORM)="" S BDMFORM="D"
NEW BDMLAST,BDMVAL,BDMX,R,X,Y,V,E,T,G,BDMY,BDMF
S BDMLAST=""
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"88","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"15","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"16","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"111","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"135","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"140","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"141","IMMUNIZATION",$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"A")
D E
S BDMVAL=$$LASTCPTT^APCLAPIU(BDMPDFN,$S($P(BDMLAST,U)]"":$P(BDMLAST,U),1:BDMBD),BDMED,"DM AUDIT SEASONAL FLU CPTS","A")
D E
I BDMFORM="D" Q $P(BDMLAST,U)
Q BDMLAST
E ;
I $P(BDMVAL,U,1)>$P(BDMLAST,U,1) S BDMLAST=BDMVAL
Q
FLU(P,BDATE,EDATE,R,F) ;EP
NEW BDM,X,E,%,%DT,BD,B,D,C,Y,LFLU,TFLU,Z,G,T
I $G(F)="" S F="E"
I $G(R)="" S R=0
I $G(BDATE)="" S BDATE=$$FMADD^XLFDT(EDATE,-366)
S LFLU=$$LASTFLU(P,BDATE,EDATE,"D")
I LFLU]"" Q $S(F="E":"1 Yes "_$$FMTE^XLFDT(LFLU),1:LFLU)
;
I R Q ""
NEW G S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",$S($$BI:88,1:12),0)),BDATE,EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated"
S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",15,0)),BDATE,EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated "_$$FMTE^XLFDT($P(G,U,3))
S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",16,0)),BDATE,EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated "_$$FMTE^XLFDT($P(G,U,3))
S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",111,0)),BDATE,EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated "_$$FMTE^XLFDT($P(G,U,3))
S G="" F Z=15,16,88,111 Q:G S X=0,Y=$O(^AUTTIMM("C",Z,0)) I Y F S X=$O(^BIPC("AC",P,Y,X)) Q:X'=+X!(G) D
.S R=$P(^BIPC(X,0),U,3)
.Q:R=""
.Q:'$D(^BICONT(R,0))
.Q:$P(^BICONT(R,0),U,1)'["Refusal"
.S D=$P(^BIPC(X,0),U,4)
.Q:D=""
.Q:$P(^BIPC(X,0),U,4)<BDATE
.Q:$P(^BIPC(X,0),U,4)>EDATE
.S G=1_U_D
I G Q "3 Refused (Immunization package) "_$$FMTE^XLFDT($P(D,U,2))
Q "2 No"
PNEU(P,EDATE,R,F) ;EP
NEW BDM,X,E,B,%DT,Y,TPN,D,LPN,G,C,Z,T
K TPN
I $G(F)="" S F="E"
I $G(R)="" S R=0
S LPN=$$LASTPNEU^APCLAPI4(P,"",EDATE,"D")
I LPN]"" Q $S(F="E":"1 Yes "_$$FMTE^XLFDT(LPN),1:LPN)
I R Q ""
S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",$S($$BI:33,1:19),0)),$$FMTE^XLFDT($$FMADD^XLFDT(EDATE,-365)),EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated "_$$FMTE^XLFDT($P(G,U,3))
I '$$BI Q "2 No"
S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",100,0)),$$FMTE^XLFDT($$FMADD^XLFDT(EDATE,-365)),EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated "_$$FMTE^XLFDT($P(G,U,3))
S G=$$REFUSAL^BDMD117(P,9999999.14,$O(^AUTTIMM("C",109,0)),$$FMTE^XLFDT($$FMADD^XLFDT(EDATE,-365)),EDATE)
I G,$P(G,U,2)'="N" Q "3 Refused "_$$FMTE^XLFDT($P(G,U,3))
I G Q "2 No - Not Medically Indicated "_$$FMTE^XLFDT($P(G,U,3))
S X=EDATE,%DT="P" D ^%DT S E=Y
S G="" F Z=33,100,109 Q:G S X=0,Y=$O(^AUTTIMM("C",Z,0)) I Y F S X=$O(^BIPC("AC",P,Y,X)) Q:X'=+X!(G) D
.S R=$P(^BIPC(X,0),U,3)
.Q:R=""
.Q:'$D(^BICONT(R,0))
.;Q:$P(^BICONT(R,0),U,1)'["Refusal"
.S D=$P(^BIPC(X,0),U,4)
.Q:D=""
.Q:$P(^BIPC(X,0),U,4)>EDATE
.S G=1_U_D
I G Q "3 Refused "_$$FMTE^XLFDT($P(D,U,2))_" Immunization package"
Q "2 No"
LASTFLUN ;
S X=0 F S X=$O(^AUPNVIMM("AC",P,X)) Q:X'=+X D
.S Y=$P(^AUPNVIMM(X,0),U) Q:'Y
.Q:'$D(^AUTTIMM(Y,0))
.S Y=$P(^AUTTIMM(Y,0),U,3)
.S D=$P(^AUPNVIMM(X,0),U,3) Q:'D
.S D=$P($P($G(^AUPNVSIT(D,0)),U),".")
.I D<B Q ;too early
.I D>E Q ;after time frame
.I Y=88 S TFLU(9999999-D)="" Q
.I Y=15 S TFLU(9999999-D)="" Q
.I Y=16 S TFLU(9999999-D)="" Q
.I Y=111 S TFLU(9999999-D)="" Q
Q
LASTFLUO ;
S X=0 F S X=$O(^AUPNVIMM("AC",P,X)) Q:X'=+X D
.S Y=$P(^AUPNVIMM(X,0),U) Q:'Y
.S Y=$P(^AUTTIMM(Y,0),U,3)
.S D=$P(^AUPNVIMM(X,0),U,3) Q:'D
.S D=$P($P($G(^AUPNVSIT(D,0)),U),".")
.I D<B Q ;too early
.I D>E Q ;after time frame
.I Y=12 S TFLU(9999999-D)="" Q
Q
LASTPNN ;
S X=0 F S X=$O(^AUPNVIMM("AC",P,X)) Q:X'=+X D
.S Y=$P(^AUPNVIMM(X,0),U) Q:'Y
.Q:'$D(^AUTTIMM(Y,0))
.S Y=$P(^AUTTIMM(Y,0),U,3)
.S D=$P(^AUPNVIMM(X,0),U,3) Q:'D
.S D=$P($P($G(^AUPNVSIT(D,0)),U),".")
.I D<B Q ;too early
.I D>E Q ;after time frame
.I Y=33 S TPN(9999999-D)="" Q
.I Y=100 S TPN(9999999-D)="" Q
.I Y=109 S TPN(9999999-D)="" Q
Q
LASTPNO ;
S X=0 F S X=$O(^AUPNVIMM("AC",P,X)) Q:X'=+X D
.S Y=$P(^AUPNVIMM(X,0),U) Q:'Y
.S Y=$P(^AUTTIMM(Y,0),U,3)
.S D=$P(^AUPNVIMM(X,0),U,3) Q:'D
.S D=$P($P($G(^AUPNVSIT(D,0)),U),".")
.I D<B Q ;too early
.I D>E Q ;after time frame
.I Y=19 S TPN(9999999-D)="" Q
Q
BI() ;
Q $S($O(^AUTTIMM(0))>100:1,1:0)
BPS(P,BDATE,EDATE,F) ;EP ;
I $G(F)="" S F="E"
NEW X,BDM,E,BDML,BDMLL,BDMV,BDMVF
S BDMLL=0,BDMV=""
K BDM
S X=P_"^LAST 50 MEAS BP;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(X,"BDM(")
S BDML=0 F S BDML=$O(BDM(BDML)) Q:BDML'=+BDML!(BDMLL=3) S BDMBP=$P($G(BDM(BDML)),U,2) D
.S BDMVF=+$P(BDM(BDML),U,4)
.Q:$P($G(^AUPNVMSR(BDMVF,2)),U,1) ;entered in error
.Q:$$CLINIC^APCLV($P(BDM(BDML),U,5),"C")=30
.S BDMLL=BDMLL+1
.I F="E" S $P(BDMV,";",BDMLL)=BDMBP_" mm Hg "_$$FMTE^XLFDT($P(BDM(BDML),U))
.I F="I" S $P(BDMV,";",BDMLL)=$P(BDMBP," ")
Q BDMV
HTNDX(P,EDATE) ;EP - is HTN on problem list
I '$G(P) Q ""
I '$D(^DPT(P)) Q ""
NEW %,BDM,E,X
K BDM
S %=P_"^PROBLEM [DM AUDIT PROBLEM HTN DIAGNOSES" S E=$$START1^APCLDF(%,"BDM(")
I $D(BDM(1)) Q "1 Yes"
K BDM
S X=P_"^LAST 3 DX [SURVEILLANCE HYPERTENSION;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_EDATE S E=$$START1^APCLDF(X,"BDM(")
I $D(BDM(3)) S Y=$$FMTE^XLFDT($P(BDM(3),U,1))_" "_$$FMTE^XLFDT($P(BDM(2),U))_" "_$$FMTE^XLFDT($P(BDM(1),U)) Q "1 Yes - DX on "_Y
Q "2 No"
LASTHT(P,EDATE,F) ;PEP - return last ht and date
I 'P Q ""
I $G(F)="" S F="E"
I '$D(^AUPNVSIT("AC",P)) Q ""
NEW %,BDMARRY,H,E,W,BDATE,D
S %DT="P",X=EDATE D ^%DT S EDATE=Y
S BDATE=$P(^DPT(P,0),U,3)
;S %=P_"^LAST MEAS HT;DURING "_BDATE_"-"_EDATE NEW X S E=$$START1^APCLDF(%,"BDMARRY(") S H=$P($G(BDMARRY(1)),U,2)
S E=$O(^AUTTMSR("B","HT",0))
S H=""
S D=0 F S D=$O(^AUPNVMSR("AA",P,E,D)) Q:D'=+D!(H]"") D
.S W=0 F S W=$O(^AUPNVMSR("AA",P,E,D,W)) Q:W'=+W!(H]"") D
..Q:'$D(^AUPNVMSR(W,0))
..Q:$P($G(^AUPNVMSR(W,2)),U,1) ;entered in error
..S H=$P(^AUPNVMSR(W,0),U,4)
..S BDMARRY(1)=$$VD^APCLV($P(^AUPNVMSR(W,0),U,3))
I H="" Q H
I F="I" Q H
S H=$J(H,5,2)
Q H_" inches "_$$FMTE^XLFDT($P(BDMARRY(1),U))
LASTWT(P,BDATE,EDATE,F) ;PEP - return last wt
I 'P Q ""
I $G(F)="" S F="E"
NEW %,BDMARRY,E,BDMW,X,BDMN,BDM,BDMD,BDMZ,BDMX,W,H,BDMVF
;S %DT="P",X=EDATE D ^%DT S EDATE=Y
;S BDATE=$$FMADD^XLFDT(EDATE,-365)
NEW BDMV221 S BDMV221=$P($$ICDDX^ICDCODE("V22.1"),U,1)
K BDM S BDMW="" S BDMX=P_"^LAST 24 MEAS WT;DURING "_BDATE_"-"_EDATE S E=$$START1^APCLDF(BDMX,"BDM(")
S BDMN=0 F S BDMN=$O(BDM(BDMN)) Q:BDMN'=+BDMN!(BDMW]"") D
. S BDMVF=+$P(BDM(BDMN),U,4)
. Q:$P($G(^AUPNVMSR(BDMVF,2)),U,1) ;entered in error
. S BDMZ=$P(BDM(BDMN),U,5)
. I '$D(^AUPNVPOV("AD",BDMZ)) S BDMW=$P(BDM(BDMN),U,2)_" lbs "_$$FMTE^XLFDT($P(BDM(BDMN),U)) Q
. S BDMD=0 F S BDMD=$O(^AUPNVPOV("AD",BDMZ,BDMD)) Q:'BDMD!(BDMW]"") D
.. S ICD=$P($$ICDDX^ICDCODE($P(^AUPNVPOV(BDMD,0),U)),U,2) D ;cmi/anch/maw 9/12/2007 csv
...I $E(ICD,1,3)="V22" Q
...I $E(ICD,1,3)="V23" Q
...I $E(ICD,1,3)="V27" Q
...I $E(ICD,1,3)="V28" Q
...I ICD>629.9999&(ICD<676.95) Q
...I ICD>61.49&(ICD<61.71) Q
...S BDMW=$P(BDM(BDMN),U,2)_" lbs "_$$FMTE^XLFDT($P(BDM(BDMN),U))
..Q
Q $S(F="E":BDMW,1:+BDMW)
CMSFDX(P,R,T) ;EP - return date/dx of dm in register
I '$G(P) Q ""
I '$G(R) Q ""
I $G(T)="" Q ""
NEW D1,Y,X,D,G S X=0,(D,Y)="" F S X=$O(^ACM(44,"C",P,X)) Q:X'=+X I $P(^ACM(44,X,0),U,4)=R D
.S D=$P($G(^ACM(44,X,"SV")),U,2),D1=D,D=$$FMTE^XLFDT(D)
.S Y=$$VAL^XBDIQ1(9002244,X,.01)
.I D1="" S D1=0
.S G(9999999-D1)=D_"^"_D1_"^"_Y
I '$O(G(0)) Q ""
S Y=0,G=$O(G(Y))
S D=$P(G(G),U),D1=$P(G(G),U,2),Y=$P(G(G),U,3)
Q $S(T="D":$G(D),T="DX":$G(Y),T="ID":$G(D1),1:"")
;
PLDMDOO(P,F) ;EP
I '$G(P) Q ""
I $G(F)="" S F="E"
NEW T S T=$O(^ATXAX("B","SURVEILLANCE DIABETES",0))
I 'T Q ""
NEW D,X,I S D="",X=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X D
.S I=$P(^AUPNPROB(X,0),U)
.I $$ICD^ATXCHK(I,T,9) D
..I $P(^AUPNPROB(X,0),U,13)]"" S D($P(^AUPNPROB(X,0),U,13))=""
..Q
.Q
S D=$O(D(0)) Q $S(F="E":$$FMTE^XLFDT(D),1:$O(D(0)))
PLDMDXS(P) ;EP - get all DM dxs from problem list
I '$G(P) Q ""
NEW T S T=$O(^ATXAX("B","SURVEILLANCE DIABETES",0))
I 'T Q "<diabetes taxonomy missing>"
NEW D,X,I S D="",X=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X D
.S I=$P(^AUPNPROB(X,0),U)
.;I $$ICD^ATXCHK(I,T,9) S:D]"" D=D_";" S D=D_$P(^ICD9(I,0),U) ;cmi/anch/maw 9/12/2007 orig line
.I $$ICD^ATXCHK(I,T,9) S:D]"" D=D_";" S D=D_$P($$ICDDX^ICDCODE(I),U,2) ;cmi/anch/maw 9/12/2007 csv
.Q
Q D
;
FRSTDMDX(P,F) ;EP return date of first dm dx
I '$G(P) Q ""
I $G(F)="" S F="E"
NEW X,E,BDM,Y
S Y="BDM("
S X=P_"^FIRST DX [SURVEILLANCE DIABETES" S E=$$START1^APCLDF(X,Y) S Y=$P($G(BDM(1)),U)
Q $S(F="E":$$FMTE^XLFDT(Y),1:Y)
LASTDMDX(P,D) ;EP - last pcc dm dx
I '$G(P) Q ""
NEW X,E,BDM,Y
S Y="BDM("
S X=P_"^LAST DX [DM AUDIT TYPE II DXS;DURING "_$$DOB^AUPNPAT(P,"E")_"-"_D S E=$$START1^APCLDF(X,Y)
I $D(BDM(1)) Q "Type 2"
K BDM S X=P_"^LAST DX [DM AUDIT TYPE I DXS;DURING "_$$DOB^AUPNPAT(P,"E")_"-"_D S E=$$START1^APCLDF(X,Y)
I $D(BDM(1)) Q "Type 1"
Q ""
INCHES ;
NEW F,FI,Z
S (X,Z)=$$LASTHT^BDMD113(BDMPD,BDMRED,"I")
Q:X=""
S X=X/12 ;get feet
S F=$P(X,".")
S FI=F*12 ;GET INCHES
S X=Z-FI
;S X=$J(X,5,2)
Q
DATE(D) ;EP
I D="" Q D
Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_$E(D,2,3)
BDMD113 ; IHS/CMI/LAB - 2011 DIABETES AUDIT ;
+1 ;;2.0;DIABETES MANAGEMENT SYSTEM;**4**;JUN 14, 2007
+2 ;
LASTFLU(BDMPDFN,BDMBD,BDMED,BDMFORM) ;PEP - date of last FLU
+1 ; Return the last recorded FLU:
+2 ; - V Immunization: 15, 16, 88, 111
+3 ; - V CPT [dm audit seasonal flu cpts]
+4 ; If APCLFORM is A returns the string:
+5 ; date^text of item found^value if appropriate^visit ien^File found in^ien of file found in
+6 ;
+7 IF $GET(BDMPDFN)=""
QUIT ""
+8 IF $GET(BDMBD)=""
SET BDMBD=$$DOB^AUPNPAT(BDMPDFN)
+9 IF $GET(BDMED)=""
SET BDMED=DT
+10 IF $GET(BDMFORM)=""
SET BDMFORM="D"
+11 NEW BDMLAST,BDMVAL,BDMX,R,X,Y,V,E,T,G,BDMY,BDMF
+12 SET BDMLAST=""
+13 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"88","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+14 DO E
+15 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"15","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+16 DO E
+17 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"16","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+18 DO E
+19 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"111","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+20 DO E
+21 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"135","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+22 DO E
+23 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"140","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+24 DO E
+25 SET BDMVAL=$$LASTITEM^APCLAPIU(BDMPDFN,"141","IMMUNIZATION",$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"A")
+26 DO E
+27 SET BDMVAL=$$LASTCPTT^APCLAPIU(BDMPDFN,$SELECT($PIECE(BDMLAST,U)]"":$PIECE(BDMLAST,U),1:BDMBD),BDMED,"DM AUDIT SEASONAL FLU CPTS","A")
+28 DO E
+29 IF BDMFORM="D"
QUIT $PIECE(BDMLAST,U)
+30 QUIT BDMLAST
E ;
+1 IF $PIECE(BDMVAL,U,1)>$PIECE(BDMLAST,U,1)
SET BDMLAST=BDMVAL
+2 QUIT
FLU(P,BDATE,EDATE,R,F) ;EP
+1 NEW BDM,X,E,%,%DT,BD,B,D,C,Y,LFLU,TFLU,Z,G,T
+2 IF $GET(F)=""
SET F="E"
+3 IF $GET(R)=""
SET R=0
+4 IF $GET(BDATE)=""
SET BDATE=$$FMADD^XLFDT(EDATE,-366)
+5 SET LFLU=$$LASTFLU(P,BDATE,EDATE,"D")
+6 IF LFLU]""
QUIT $SELECT(F="E":"1 Yes "_$$FMTE^XLFDT(LFLU),1:LFLU)
+7 ;
+8 IF R
QUIT ""
+9 NEW G
SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",$SELECT($$BI:88,1:12),0)),BDATE,EDATE)
+10 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+11 IF G
QUIT "2 No - Not Medically Indicated"
+12 SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",15,0)),BDATE,EDATE)
+13 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+14 IF G
QUIT "2 No - Not Medically Indicated "_$$FMTE^XLFDT($PIECE(G,U,3))
+15 SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",16,0)),BDATE,EDATE)
+16 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+17 IF G
QUIT "2 No - Not Medically Indicated "_$$FMTE^XLFDT($PIECE(G,U,3))
+18 SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",111,0)),BDATE,EDATE)
+19 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+20 IF G
QUIT "2 No - Not Medically Indicated "_$$FMTE^XLFDT($PIECE(G,U,3))
+21 SET G=""
FOR Z=15,16,88,111
IF G
QUIT
SET X=0
SET Y=$ORDER(^AUTTIMM("C",Z,0))
IF Y
FOR
SET X=$ORDER(^BIPC("AC",P,Y,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+22 SET R=$PIECE(^BIPC(X,0),U,3)
+23 IF R=""
QUIT
+24 IF '$DATA(^BICONT(R,0))
QUIT
+25 IF $PIECE(^BICONT(R,0),U,1)'["Refusal"
QUIT
+26 SET D=$PIECE(^BIPC(X,0),U,4)
+27 IF D=""
QUIT
+28 IF $PIECE(^BIPC(X,0),U,4)<BDATE
QUIT
+29 IF $PIECE(^BIPC(X,0),U,4)>EDATE
QUIT
+30 SET G=1_U_D
End DoDot:1
+31 IF G
QUIT "3 Refused (Immunization package) "_$$FMTE^XLFDT($PIECE(D,U,2))
+32 QUIT "2 No"
PNEU(P,EDATE,R,F) ;EP
+1 NEW BDM,X,E,B,%DT,Y,TPN,D,LPN,G,C,Z,T
+2 KILL TPN
+3 IF $GET(F)=""
SET F="E"
+4 IF $GET(R)=""
SET R=0
+5 SET LPN=$$LASTPNEU^APCLAPI4(P,"",EDATE,"D")
+6 IF LPN]""
QUIT $SELECT(F="E":"1 Yes "_$$FMTE^XLFDT(LPN),1:LPN)
+7 IF R
QUIT ""
+8 SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",$SELECT($$BI:33,1:19),0)),$$FMTE^XLFDT($$FMADD^XLFDT(EDATE,-365)),EDATE)
+9 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+10 IF G
QUIT "2 No - Not Medically Indicated "_$$FMTE^XLFDT($PIECE(G,U,3))
+11 IF '$$BI
QUIT "2 No"
+12 SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",100,0)),$$FMTE^XLFDT($$FMADD^XLFDT(EDATE,-365)),EDATE)
+13 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+14 IF G
QUIT "2 No - Not Medically Indicated "_$$FMTE^XLFDT($PIECE(G,U,3))
+15 SET G=$$REFUSAL^BDMD117(P,9999999.14,$ORDER(^AUTTIMM("C",109,0)),$$FMTE^XLFDT($$FMADD^XLFDT(EDATE,-365)),EDATE)
+16 IF G
IF $PIECE(G,U,2)'="N"
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(G,U,3))
+17 IF G
QUIT "2 No - Not Medically Indicated "_$$FMTE^XLFDT($PIECE(G,U,3))
+18 SET X=EDATE
SET %DT="P"
DO ^%DT
SET E=Y
+19 SET G=""
FOR Z=33,100,109
IF G
QUIT
SET X=0
SET Y=$ORDER(^AUTTIMM("C",Z,0))
IF Y
FOR
SET X=$ORDER(^BIPC("AC",P,Y,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+20 SET R=$PIECE(^BIPC(X,0),U,3)
+21 IF R=""
QUIT
+22 IF '$DATA(^BICONT(R,0))
QUIT
+23 ;Q:$P(^BICONT(R,0),U,1)'["Refusal"
+24 SET D=$PIECE(^BIPC(X,0),U,4)
+25 IF D=""
QUIT
+26 IF $PIECE(^BIPC(X,0),U,4)>EDATE
QUIT
+27 SET G=1_U_D
End DoDot:1
+28 IF G
QUIT "3 Refused "_$$FMTE^XLFDT($PIECE(D,U,2))_" Immunization package"
+29 QUIT "2 No"
LASTFLUN ;
+1 SET X=0
FOR
SET X=$ORDER(^AUPNVIMM("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+2 SET Y=$PIECE(^AUPNVIMM(X,0),U)
IF 'Y
QUIT
+3 IF '$DATA(^AUTTIMM(Y,0))
QUIT
+4 SET Y=$PIECE(^AUTTIMM(Y,0),U,3)
+5 SET D=$PIECE(^AUPNVIMM(X,0),U,3)
IF 'D
QUIT
+6 SET D=$PIECE($PIECE($GET(^AUPNVSIT(D,0)),U),".")
+7 ;too early
IF D<B
QUIT
+8 ;after time frame
IF D>E
QUIT
+9 IF Y=88
SET TFLU(9999999-D)=""
QUIT
+10 IF Y=15
SET TFLU(9999999-D)=""
QUIT
+11 IF Y=16
SET TFLU(9999999-D)=""
QUIT
+12 IF Y=111
SET TFLU(9999999-D)=""
QUIT
End DoDot:1
+13 QUIT
LASTFLUO ;
+1 SET X=0
FOR
SET X=$ORDER(^AUPNVIMM("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+2 SET Y=$PIECE(^AUPNVIMM(X,0),U)
IF 'Y
QUIT
+3 SET Y=$PIECE(^AUTTIMM(Y,0),U,3)
+4 SET D=$PIECE(^AUPNVIMM(X,0),U,3)
IF 'D
QUIT
+5 SET D=$PIECE($PIECE($GET(^AUPNVSIT(D,0)),U),".")
+6 ;too early
IF D<B
QUIT
+7 ;after time frame
IF D>E
QUIT
+8 IF Y=12
SET TFLU(9999999-D)=""
QUIT
End DoDot:1
+9 QUIT
LASTPNN ;
+1 SET X=0
FOR
SET X=$ORDER(^AUPNVIMM("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+2 SET Y=$PIECE(^AUPNVIMM(X,0),U)
IF 'Y
QUIT
+3 IF '$DATA(^AUTTIMM(Y,0))
QUIT
+4 SET Y=$PIECE(^AUTTIMM(Y,0),U,3)
+5 SET D=$PIECE(^AUPNVIMM(X,0),U,3)
IF 'D
QUIT
+6 SET D=$PIECE($PIECE($GET(^AUPNVSIT(D,0)),U),".")
+7 ;too early
IF D<B
QUIT
+8 ;after time frame
IF D>E
QUIT
+9 IF Y=33
SET TPN(9999999-D)=""
QUIT
+10 IF Y=100
SET TPN(9999999-D)=""
QUIT
+11 IF Y=109
SET TPN(9999999-D)=""
QUIT
End DoDot:1
+12 QUIT
LASTPNO ;
+1 SET X=0
FOR
SET X=$ORDER(^AUPNVIMM("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+2 SET Y=$PIECE(^AUPNVIMM(X,0),U)
IF 'Y
QUIT
+3 SET Y=$PIECE(^AUTTIMM(Y,0),U,3)
+4 SET D=$PIECE(^AUPNVIMM(X,0),U,3)
IF 'D
QUIT
+5 SET D=$PIECE($PIECE($GET(^AUPNVSIT(D,0)),U),".")
+6 ;too early
IF D<B
QUIT
+7 ;after time frame
IF D>E
QUIT
+8 IF Y=19
SET TPN(9999999-D)=""
QUIT
End DoDot:1
+9 QUIT
BI() ;
+1 QUIT $SELECT($ORDER(^AUTTIMM(0))>100:1,1:0)
BPS(P,BDATE,EDATE,F) ;EP ;
+1 IF $GET(F)=""
SET F="E"
+2 NEW X,BDM,E,BDML,BDMLL,BDMV,BDMVF
+3 SET BDMLL=0
SET BDMV=""
+4 KILL BDM
+5 SET X=P_"^LAST 50 MEAS BP;DURING "_BDATE_"-"_EDATE
SET E=$$START1^APCLDF(X,"BDM(")
+6 SET BDML=0
FOR
SET BDML=$ORDER(BDM(BDML))
IF BDML'=+BDML!(BDMLL=3)
QUIT
SET BDMBP=$PIECE($GET(BDM(BDML)),U,2)
Begin DoDot:1
+7 SET BDMVF=+$PIECE(BDM(BDML),U,4)
+8 ;entered in error
IF $PIECE($GET(^AUPNVMSR(BDMVF,2)),U,1)
QUIT
+9 IF $$CLINIC^APCLV($PIECE(BDM(BDML),U,5),"C")=30
QUIT
+10 SET BDMLL=BDMLL+1
+11 IF F="E"
SET $PIECE(BDMV,";",BDMLL)=BDMBP_" mm Hg "_$$FMTE^XLFDT($PIECE(BDM(BDML),U))
+12 IF F="I"
SET $PIECE(BDMV,";",BDMLL)=$PIECE(BDMBP," ")
End DoDot:1
+13 QUIT BDMV
HTNDX(P,EDATE) ;EP - is HTN on problem list
+1 IF '$GET(P)
QUIT ""
+2 IF '$DATA(^DPT(P))
QUIT ""
+3 NEW %,BDM,E,X
+4 KILL BDM
+5 SET %=P_"^PROBLEM [DM AUDIT PROBLEM HTN DIAGNOSES"
SET E=$$START1^APCLDF(%,"BDM(")
+6 IF $DATA(BDM(1))
QUIT "1 Yes"
+7 KILL BDM
+8 SET X=P_"^LAST 3 DX [SURVEILLANCE HYPERTENSION;DURING "_$$FMTE^XLFDT($$DOB^AUPNPAT(P))_"-"_EDATE
SET E=$$START1^APCLDF(X,"BDM(")
+9 IF $DATA(BDM(3))
SET Y=$$FMTE^XLFDT($PIECE(BDM(3),U,1))_" "_$$FMTE^XLFDT($PIECE(BDM(2),U))_" "_$$FMTE^XLFDT($PIECE(BDM(1),U))
QUIT "1 Yes - DX on "_Y
+10 QUIT "2 No"
LASTHT(P,EDATE,F) ;PEP - return last ht and date
+1 IF 'P
QUIT ""
+2 IF $GET(F)=""
SET F="E"
+3 IF '$DATA(^AUPNVSIT("AC",P))
QUIT ""
+4 NEW %,BDMARRY,H,E,W,BDATE,D
+5 SET %DT="P"
SET X=EDATE
DO ^%DT
SET EDATE=Y
+6 SET BDATE=$PIECE(^DPT(P,0),U,3)
+7 ;S %=P_"^LAST MEAS HT;DURING "_BDATE_"-"_EDATE NEW X S E=$$START1^APCLDF(%,"BDMARRY(") S H=$P($G(BDMARRY(1)),U,2)
+8 SET E=$ORDER(^AUTTMSR("B","HT",0))
+9 SET H=""
+10 SET D=0
FOR
SET D=$ORDER(^AUPNVMSR("AA",P,E,D))
IF D'=+D!(H]"")
QUIT
Begin DoDot:1
+11 SET W=0
FOR
SET W=$ORDER(^AUPNVMSR("AA",P,E,D,W))
IF W'=+W!(H]"")
QUIT
Begin DoDot:2
+12 IF '$DATA(^AUPNVMSR(W,0))
QUIT
+13 ;entered in error
IF $PIECE($GET(^AUPNVMSR(W,2)),U,1)
QUIT
+14 SET H=$PIECE(^AUPNVMSR(W,0),U,4)
+15 SET BDMARRY(1)=$$VD^APCLV($PIECE(^AUPNVMSR(W,0),U,3))
End DoDot:2
End DoDot:1
+16 IF H=""
QUIT H
+17 IF F="I"
QUIT H
+18 SET H=$JUSTIFY(H,5,2)
+19 QUIT H_" inches "_$$FMTE^XLFDT($PIECE(BDMARRY(1),U))
LASTWT(P,BDATE,EDATE,F) ;PEP - return last wt
+1 IF 'P
QUIT ""
+2 IF $GET(F)=""
SET F="E"
+3 NEW %,BDMARRY,E,BDMW,X,BDMN,BDM,BDMD,BDMZ,BDMX,W,H,BDMVF
+4 ;S %DT="P",X=EDATE D ^%DT S EDATE=Y
+5 ;S BDATE=$$FMADD^XLFDT(EDATE,-365)
+6 NEW BDMV221
SET BDMV221=$PIECE($$ICDDX^ICDCODE("V22.1"),U,1)
+7 KILL BDM
SET BDMW=""
SET BDMX=P_"^LAST 24 MEAS WT;DURING "_BDATE_"-"_EDATE
SET E=$$START1^APCLDF(BDMX,"BDM(")
+8 SET BDMN=0
FOR
SET BDMN=$ORDER(BDM(BDMN))
IF BDMN'=+BDMN!(BDMW]"")
QUIT
Begin DoDot:1
+9 SET BDMVF=+$PIECE(BDM(BDMN),U,4)
+10 ;entered in error
IF $PIECE($GET(^AUPNVMSR(BDMVF,2)),U,1)
QUIT
+11 SET BDMZ=$PIECE(BDM(BDMN),U,5)
+12 IF '$DATA(^AUPNVPOV("AD",BDMZ))
SET BDMW=$PIECE(BDM(BDMN),U,2)_" lbs "_$$FMTE^XLFDT($PIECE(BDM(BDMN),U))
QUIT
+13 SET BDMD=0
FOR
SET BDMD=$ORDER(^AUPNVPOV("AD",BDMZ,BDMD))
IF 'BDMD!(BDMW]"")
QUIT
Begin DoDot:2
+14 ;cmi/anch/maw 9/12/2007 csv
SET ICD=$PIECE($$ICDDX^ICDCODE($PIECE(^AUPNVPOV(BDMD,0),U)),U,2)
Begin DoDot:3
+15 IF $EXTRACT(ICD,1,3)="V22"
QUIT
+16 IF $EXTRACT(ICD,1,3)="V23"
QUIT
+17 IF $EXTRACT(ICD,1,3)="V27"
QUIT
+18 IF $EXTRACT(ICD,1,3)="V28"
QUIT
+19 IF ICD>629.9999&(ICD<676.95)
QUIT
+20 IF ICD>61.49&(ICD<61.71)
QUIT
+21 SET BDMW=$PIECE(BDM(BDMN),U,2)_" lbs "_$$FMTE^XLFDT($PIECE(BDM(BDMN),U))
End DoDot:3
+22 QUIT
End DoDot:2
End DoDot:1
+23 QUIT $SELECT(F="E":BDMW,1:+BDMW)
CMSFDX(P,R,T) ;EP - return date/dx of dm in register
+1 IF '$GET(P)
QUIT ""
+2 IF '$GET(R)
QUIT ""
+3 IF $GET(T)=""
QUIT ""
+4 NEW D1,Y,X,D,G
SET X=0
SET (D,Y)=""
FOR
SET X=$ORDER(^ACM(44,"C",P,X))
IF X'=+X
QUIT
IF $PIECE(^ACM(44,X,0),U,4)=R
Begin DoDot:1
+5 SET D=$PIECE($GET(^ACM(44,X,"SV")),U,2)
SET D1=D
SET D=$$FMTE^XLFDT(D)
+6 SET Y=$$VAL^XBDIQ1(9002244,X,.01)
+7 IF D1=""
SET D1=0
+8 SET G(9999999-D1)=D_"^"_D1_"^"_Y
End DoDot:1
+9 IF '$ORDER(G(0))
QUIT ""
+10 SET Y=0
SET G=$ORDER(G(Y))
+11 SET D=$PIECE(G(G),U)
SET D1=$PIECE(G(G),U,2)
SET Y=$PIECE(G(G),U,3)
+12 QUIT $SELECT(T="D":$GET(D),T="DX":$GET(Y),T="ID":$GET(D1),1:"")
+13 ;
PLDMDOO(P,F) ;EP
+1 IF '$GET(P)
QUIT ""
+2 IF $GET(F)=""
SET F="E"
+3 NEW T
SET T=$ORDER(^ATXAX("B","SURVEILLANCE DIABETES",0))
+4 IF 'T
QUIT ""
+5 NEW D,X,I
SET D=""
SET X=0
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+6 SET I=$PIECE(^AUPNPROB(X,0),U)
+7 IF $$ICD^ATXCHK(I,T,9)
Begin DoDot:2
+8 IF $PIECE(^AUPNPROB(X,0),U,13)]""
SET D($PIECE(^AUPNPROB(X,0),U,13))=""
+9 QUIT
End DoDot:2
+10 QUIT
End DoDot:1
+11 SET D=$ORDER(D(0))
QUIT $SELECT(F="E":$$FMTE^XLFDT(D),1:$ORDER(D(0)))
PLDMDXS(P) ;EP - get all DM dxs from problem list
+1 IF '$GET(P)
QUIT ""
+2 NEW T
SET T=$ORDER(^ATXAX("B","SURVEILLANCE DIABETES",0))
+3 IF 'T
QUIT "<diabetes taxonomy missing>"
+4 NEW D,X,I
SET D=""
SET X=0
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X
QUIT
Begin DoDot:1
+5 SET I=$PIECE(^AUPNPROB(X,0),U)
+6 ;I $$ICD^ATXCHK(I,T,9) S:D]"" D=D_";" S D=D_$P(^ICD9(I,0),U) ;cmi/anch/maw 9/12/2007 orig line
+7 ;cmi/anch/maw 9/12/2007 csv
IF $$ICD^ATXCHK(I,T,9)
IF D]""
SET D=D_";"
SET D=D_$PIECE($$ICDDX^ICDCODE(I),U,2)
+8 QUIT
End DoDot:1
+9 QUIT D
+10 ;
FRSTDMDX(P,F) ;EP return date of first dm dx
+1 IF '$GET(P)
QUIT ""
+2 IF $GET(F)=""
SET F="E"
+3 NEW X,E,BDM,Y
+4 SET Y="BDM("
+5 SET X=P_"^FIRST DX [SURVEILLANCE DIABETES"
SET E=$$START1^APCLDF(X,Y)
SET Y=$PIECE($GET(BDM(1)),U)
+6 QUIT $SELECT(F="E":$$FMTE^XLFDT(Y),1:Y)
LASTDMDX(P,D) ;EP - last pcc dm dx
+1 IF '$GET(P)
QUIT ""
+2 NEW X,E,BDM,Y
+3 SET Y="BDM("
+4 SET X=P_"^LAST DX [DM AUDIT TYPE II DXS;DURING "_$$DOB^AUPNPAT(P,"E")_"-"_D
SET E=$$START1^APCLDF(X,Y)
+5 IF $DATA(BDM(1))
QUIT "Type 2"
+6 KILL BDM
SET X=P_"^LAST DX [DM AUDIT TYPE I DXS;DURING "_$$DOB^AUPNPAT(P,"E")_"-"_D
SET E=$$START1^APCLDF(X,Y)
+7 IF $DATA(BDM(1))
QUIT "Type 1"
+8 QUIT ""
INCHES ;
+1 NEW F,FI,Z
+2 SET (X,Z)=$$LASTHT^BDMD113(BDMPD,BDMRED,"I")
+3 IF X=""
QUIT
+4 ;get feet
SET X=X/12
+5 SET F=$PIECE(X,".")
+6 ;GET INCHES
SET FI=F*12
+7 SET X=Z-FI
+8 ;S X=$J(X,5,2)
+9 QUIT
DATE(D) ;EP
+1 IF D=""
QUIT D
+2 QUIT $EXTRACT(D,4,5)_"/"_$EXTRACT(D,6,7)_"/"_$EXTRACT(D,2,3)