BGP1D5A ; IHS/CMI/LAB - measure calc ;
;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
;
ALDX(P,BDATE,EDATE) ;EP
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^BGP1UTL($P(BGPG(1),U))_U_$P(BGPG(1),U)
S BGPC=""
;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 BGPP=10 S BGPC=1_U_"BH POV 10"_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D) Q
..I BGPP=27 S BGPC=1_U_"BH POV 27"_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D) Q
..I BGPP=29 S BGPC=1_U_"BH POV 29"_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,3)=303 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,5)=305.0 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,3)=291 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D) Q
..I $E(BGPP,1,5)=357.5 S BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((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)'="A"
.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^ATXCHK(Y,T,9)
.S D=$P(^AUPNPROB(X,0),U,3)
.S G=1_U_"PROB LIST "_$P($$ICDDX^ICDCODE(Y),U,2)_U_$$DATE^BGP1UTL((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^BGP1UTL($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^BGP1UTL($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^BGP1UTL($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^BGP1UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I Y=10 S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I Y=27 S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($P(^AMHPPROB(X,0),U,3))_U_$P(^AMHPPROB(X,0),U,3) Q
.I Y=29 S G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($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
BGP1D5A ; IHS/CMI/LAB - measure calc ;
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
+2 ;
ALDX(P,BDATE,EDATE) ;EP
+1 SET BGPLAL=""
+2 IF $GET(P)=""
QUIT ""
+3 KILL BGPG
+4 SET Y="BGPG("
+5 SET X=P_"^LAST DX [BGP ALCOHOL DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+6 IF $DATA(BGPG(1))
SET BGPLAL=1_U_"POV "_$PIECE(BGPG(1),U,2)_U_$$DATE^BGP1UTL($PIECE(BGPG(1),U))_U_$PIECE(BGPG(1),U)
+7 SET BGPC=""
+8 ;go through BH record file and find up to 1 visits in date range
+9 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
+10 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
+11 IF 'BGPP
QUIT
+12 SET BGPP=$PIECE($GET(^AMHPROB(BGPP,0)),U)
+13 IF BGPP=10
SET BGPC=1_U_"BH POV 10"_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D)
QUIT
+14 IF BGPP=27
SET BGPC=1_U_"BH POV 27"_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D)
QUIT
+15 IF BGPP=29
SET BGPC=1_U_"BH POV 29"_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D)
QUIT
+16 IF $EXTRACT(BGPP,1,3)=303
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D)
QUIT
+17 IF $EXTRACT(BGPP,1,5)=305.0
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D)
QUIT
+18 IF $EXTRACT(BGPP,1,3)=291
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((9999999-D))_U_(9999999-D)
QUIT
+19 IF $EXTRACT(BGPP,1,5)=357.5
SET BGPC=1_U_"BH POV "_BGPP_U_$$DATE^BGP1UTL((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)'="A"
QUIT
+26 IF $PIECE(^AUPNPROB(X,0),U,3)>EDATE
QUIT
+27 IF $PIECE(^AUPNPROB(X,0),U,3)<BDATE
QUIT
+28 SET Y=$PIECE(^AUPNPROB(X,0),U)
+29 IF '$$ICD^ATXCHK(Y,T,9)
QUIT
+30 SET D=$PIECE(^AUPNPROB(X,0),U,3)
+31 SET G=1_U_"PROB LIST "_$PIECE($$ICDDX^ICDCODE(Y),U,2)_U_$$DATE^BGP1UTL((D))_U_(D)
+32 QUIT
End DoDot:1
+33 IF $PIECE(BGPLAL,U,4)<$PIECE(G,U,4)
SET BGPLAL=G
+34 SET (X,G)=0
FOR
SET X=$ORDER(^AMHPPROB("AC",P,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+35 IF $PIECE(^AMHPPROB(X,0),U,12)'="A"
QUIT
+36 IF $PIECE(^AMHPPROB(X,0),U,3)>EDATE
QUIT
+37 IF $PIECE(^AMHPPROB(X,0),U,3)<BDATE
QUIT
+38 SET Y=$PIECE(^AMHPPROB(X,0),U)
+39 SET Y=$PIECE($GET(^AMHPROB(Y,0)),U)
+40 IF $EXTRACT(Y,1,3)="303"
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+41 IF $EXTRACT(Y,1,5)="305.0"
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+42 IF $EXTRACT(Y,1,3)=291
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+43 IF $EXTRACT(Y,1,5)=357.5
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+44 IF Y=10
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+45 IF Y=27
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+46 IF Y=29
SET G=1_U_"BH PROB LIST "_Y_U_$$DATE^BGP1UTL($PIECE(^AMHPPROB(X,0),U,3))_U_$PIECE(^AMHPPROB(X,0),U,3)
QUIT
+47 QUIT
End DoDot:1
+48 IF $PIECE(BGPLAL,U,4)<$PIECE(G,U,4)
SET BGPLAL=G
+49 QUIT BGPLAL