BGP7D5A ; IHS/CMI/LAB - measure calc ;
;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
;
ALDX(P,BDATE,EDATE) ;EP
NEW BGPLAL,BGPG,X,Y,E,BGPC,BGPP,D,G,T,V
S BGPLAL=""
I $G(P)="" Q ""
K BGPG
S Y="BGPG("
S X=P_"^LAST DX [BGP ALCOHOL DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) S BGPLAL=1_U_"POV "_$P(BGPG(1),U,2)_U_$$DATE^BGP7UTL($P(BGPG(1),U))_U_$P(BGPG(1),U)
S BGPC=""
S T=$O(^BGPCTRL("B",2017,0))
;go through BH record file and find up to 1 visits in date range
S E=9999999-BDATE,D=9999999-EDATE-1_".99" F S D=$O(^AMHREC("AE",P,D)) Q:D'=+D!($P(D,".")>E)!(BGPC) S V=0 F S V=$O(^AMHREC("AE",P,D,V)) Q:V'=+V!(BGPC) D
.S X=0 F S X=$O(^AMHRPRO("AD",V,X)) Q:X'=+X!(BGPC) S BGPP=$P($G(^AMHRPRO(X,0)),U) D
..Q:'BGPP
..S BGPP=$P($G(^AMHPROB(BGPP,0)),U)
..I $D(^BGPCTRL(T,30,"B",BGPP)) S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,3)=303 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,5)=305.0 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,3)=291 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,5)=357.5 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D) Q
..Q
I $P(BGPLAL,U,4)<$P(BGPC,U,4) S BGPLAL=BGPC
;now check pcc and bh problem lists
S T=$O(^ATXAX("B","BGP ALCOHOL DXS",0))
S (X,G)=0 F S X=$O(^AUPNPROB("AC",P,X)) Q:X'=+X!(G) D
.Q:$P(^AUPNPROB(X,0),U,12)="D"
.Q:$P(^AUPNPROB(X,0),U,12)="I"
.Q:$P(^AUPNPROB(X,0),U,3)>EDATE
.Q:$P(^AUPNPROB(X,0),U,3)<BDATE
.S Y=$P(^AUPNPROB(X,0),U)
.Q:'$$ICD^BGP7UTL2(Y,T,9)
.S D=$P(^AUPNPROB(X,0),U,3)
.S G=1_U_"PROB LIST "_$P($$ICDDX^BGP7UTL2(Y),U,2)_U_$$DATE^BGP7UTL((D))_U_(D)
.Q
I $P(BGPLAL,U,4)<$P(G,U,4) S BGPLAL=G
S (X,G)=0 F S X=$O(^AMHPPROB("AC",P,X)) Q:X'=+X!(G) D
.Q:$P(^AMHPPROB(X,0),U,12)'="A"
.Q:$P(^AMHPPROB(X,0),U,3)>EDATE
.Q:$P(^AMHPPROB(X,0),U,3)<BDATE
.S Y=$P(^AMHPPROB(X,0),U)
.S Y=$P($G(^AMHPROB(Y,0)),U)
.I $E(Y,1,3)="303" S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I $E(Y,1,5)="305.0" S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I $E(Y,1,3)=291 S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I $E(Y,1,5)=357.5 S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I $D(^BGPCTRL(T,30,"B",Y)) S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.Q
I $P(BGPLAL,U,4)<$P(G,U,4) S BGPLAL=G
Q BGPLAL
BGP7D5A ; IHS/CMI/LAB - measure calc ;
+1 ;;17.1;IHS CLINICAL REPORTING;;MAY 10, 2017;Build 29
+2 ;
ALDX(P,BDATE,EDATE) ;EP
+1 NEW BGPLAL,BGPG,X,Y,E,BGPC,BGPP,D,G,T,V
+2 SET BGPLAL=""
+3 IF $GET(P)=""
QUIT ""
+4 KILL BGPG
+5 SET Y="BGPG("
+6 SET X=P_"^LAST DX [BGP ALCOHOL DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+7 IF $DATA(BGPG(1))
SET BGPLAL=1_U_"POV "_$PIECE(BGPG(1),U,2)_U_$$DATE^BGP7UTL($PIECE(BGPG(1),U))_U_$PIECE(BGPG(1),U)
+8 SET BGPC=""
+9 SET T=$ORDER(^BGPCTRL("B",2017,0))
+10 ;go through BH record file and find up to 1 visits in date range
+11 SET E=9999999-BDATE
SET D=9999999-EDATE-1_".99"
FOR
SET D=$ORDER(^AMHREC("AE",P,D))
IF D'=+D!($PIECE(D,".")>E)!(BGPC)
QUIT
SET V=0
FOR
SET V=$ORDER(^AMHREC("AE",P,D,V))
IF V'=+V!(BGPC)
QUIT
Begin DoDot:1
+12 SET X=0
FOR
SET X=$ORDER(^AMHRPRO("AD",V,X))
IF X'=+X!(BGPC)
QUIT
SET BGPP=$PIECE($GET(^AMHRPRO(X,0)),U)
Begin DoDot:2
+13 IF 'BGPP
QUIT
+14 SET BGPP=$PIECE($GET(^AMHPROB(BGPP,0)),U)
+15 IF $DATA(^BGPCTRL(T,30,"B",BGPP))
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D)
QUIT
+16 IF $EXTRACT(BGPP,1,3)=303
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D)
QUIT
+17 IF $EXTRACT(BGPP,1,5)=305.0
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D)
QUIT
+18 IF $EXTRACT(BGPP,1,3)=291
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D)
QUIT
+19 IF $EXTRACT(BGPP,1,5)=357.5
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP7UTL((9999999-D))_U_(9999999-D)
QUIT
+20 QUIT
End DoDot:2
End DoDot:1
+21 IF $PIECE(BGPLAL,U,4)<$PIECE(BGPC,U,4)
SET BGPLAL=BGPC
+22 ;now check pcc and bh problem lists
+23 SET T=$ORDER(^ATXAX("B","BGP ALCOHOL DXS",0))
+24 SET (X,G)=0
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+25 IF $PIECE(^AUPNPROB(X,0),U,12)="D"
QUIT
+26 IF $PIECE(^AUPNPROB(X,0),U,12)="I"
QUIT
+27 IF $PIECE(^AUPNPROB(X,0),U,3)>EDATE
QUIT
+28 IF $PIECE(^AUPNPROB(X,0),U,3)<BDATE
QUIT
+29 SET Y=$PIECE(^AUPNPROB(X,0),U)
+30 IF '$$ICD^BGP7UTL2(Y,T,9)
QUIT
+31 SET D=$PIECE(^AUPNPROB(X,0),U,3)
+32 SET G=1_U_"PROB LIST "_$PIECE($$ICDDX^BGP7UTL2(Y),U,2)_U_$$DATE^BGP7UTL((D))_U_(D)
+33 QUIT
End DoDot:1
+34 IF $PIECE(BGPLAL,U,4)<$PIECE(G,U,4)
SET BGPLAL=G
+35 SET (X,G)=0
FOR
SET X=$ORDER(^AMHPPROB("AC",P,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+36 IF $PIECE(^AMHPPROB(X,0),U,12)'="A"
QUIT
+37 IF $PIECE(^AMHPPROB(X,0),U,3)>EDATE
QUIT
+38 IF $PIECE(^AMHPPROB(X,0),U,3)<BDATE
QUIT
+39 SET Y=$PIECE(^AMHPPROB(X,0),U)
+40 SET Y=$PIECE($GET(^AMHPROB(Y,0)),U)
+41 IF $EXTRACT(Y,1,3)="303"
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+42 IF $EXTRACT(Y,1,5)="305.0"
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+43 IF $EXTRACT(Y,1,3)=291
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+44 IF $EXTRACT(Y,1,5)=357.5
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+45 IF $DATA(^BGPCTRL(T,30,"B",Y))
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP7UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+46 QUIT
End DoDot:1
+47 IF $PIECE(BGPLAL,U,4)<$PIECE(G,U,4)
SET BGPLAL=G
+48 QUIT BGPLAL