BGP0D54 ; IHS/CMI/LAB - measure calc 02 Jul 2009 8:08 AM ;
;;10.0;IHS CLINICAL REPORTING;**1**;JUN 18, 2010
;
;
DVDX ;EP
I $G(P)="" Q ""
K BGPG
S Y="BGPG(",BGPLDV=""
S X=P_"^LAST DX [BGP DV DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
I $D(BGPG(1)) S BGPLDV=1_"^"_$P(BGPG(1),U)_"^Dv Dx "_$P(BGPG(1),U,2)_U_"POV "_$P(BGPG(1),U,2)_U_$$DATE^BGP0UTL($P(BGPG(1),U,1))
S BGPC=0,BGPV="" ;I $D(BGPG(1)) S BGPC=1
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 $E(BGPP,1,2)=43 S BGPC=1,BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D)) Q
..I $E(BGPP,1,2)=44 S BGPC=1,BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D)) Q
..I BGPP=995.80 S BGPC=1,BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D)) Q
..I BGPP=995.81 S BGPC=1,BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D)) Q
..Q
I BGPV,$P(BGPLDV,U,2)<$P(BGPV,U,2) S BGPLDV=BGPV
;now check pcc problem list
S T=$O(^ATXAX("B","BGP DV DXS",0))
S (X,G)=0,BGPDXPLE="" 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 G=1_U_$P(^AUPNPROB(X,0),U,3),BGPDXPLE=X
.Q
I G,$P(BGPLDV,U,2)<$P(G,U,2) S BGPLDV=1_U_$P(G,U,2)_U_"PL"_U_"PL "_$$VAL^XBDIQ1(9000011,BGPDXPLE,.01)_U_$$VAL^XBDIQ1(9000011,BGPDXPLE,.03)
S (X,G)=0,BGPDXPLE="" 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,2)="43" S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.I $E(Y,1,2)="44" S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.I Y=995.80 S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.I Y=995.81 S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.I Y=995.82 S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.I Y=995.83 S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.I Y=995.85 S G=1_U_$P(^AMHPPROB(X,0),U,3),BGPDXPLE=X Q
.Q
I G,$P(BGPLDV,U,2)<$P(G,U,2) S BGPLDV=1_U_$P(G,U,2)_U_"PL"_U_"BH PL "_$$VAL^XBDIQ1(9002011.51,BGPDXPLE,.01)_U_$$VAL^XBDIQ1(9002011.51,BGPDXPLE,.03)
Q BGPLDV
BGP0D54 ; IHS/CMI/LAB - measure calc 02 Jul 2009 8:08 AM ;
+1 ;;10.0;IHS CLINICAL REPORTING;**1**;JUN 18, 2010
+2 ;
+3 ;
DVDX ;EP
+1 IF $GET(P)=""
QUIT ""
+2 KILL BGPG
+3 SET Y="BGPG("
SET BGPLDV=""
+4 SET X=P_"^LAST DX [BGP DV DXS;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+5 IF $DATA(BGPG(1))
SET BGPLDV=1_"^"_$PIECE(BGPG(1),U)_"^Dv Dx "_$PIECE(BGPG(1),U,2)_U_"POV "_$PIECE(BGPG(1),U,2)_U_$$DATE^BGP0UTL($PIECE(BGPG(1),U,1))
+6 ;I $D(BGPG(1)) S BGPC=1
SET BGPC=0
SET BGPV=""
+7 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
+8 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
+9 IF 'BGPP
QUIT
+10 SET BGPP=$PIECE($GET(^AMHPROB(BGPP,0)),U)
+11 IF $EXTRACT(BGPP,1,2)=43
SET BGPC=1
SET BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D))
QUIT
+12 IF $EXTRACT(BGPP,1,2)=44
SET BGPC=1
SET BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D))
QUIT
+13 IF BGPP=995.80
SET BGPC=1
SET BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D))
QUIT
+14 IF BGPP=995.81
SET BGPC=1
SET BGPV=1_"^"_(9999999-D)_"^BH "_BGPP_U_"BH POV "_BGPP_U_$$DATE^BGP0UTL((9999999-D))
QUIT
+15 QUIT
End DoDot:2
End DoDot:1
+16 IF BGPV
IF $PIECE(BGPLDV,U,2)<$PIECE(BGPV,U,2)
SET BGPLDV=BGPV
+17 ;now check pcc problem list
+18 SET T=$ORDER(^ATXAX("B","BGP DV DXS",0))
+19 SET (X,G)=0
SET BGPDXPLE=""
FOR
SET X=$ORDER(^AUPNPROB("AC",P,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+20 IF $PIECE(^AUPNPROB(X,0),U,12)'="A"
QUIT
+21 IF $PIECE(^AUPNPROB(X,0),U,3)>EDATE
QUIT
+22 IF $PIECE(^AUPNPROB(X,0),U,3)<BDATE
QUIT
+23 SET Y=$PIECE(^AUPNPROB(X,0),U)
+24 IF '$$ICD^ATXCHK(Y,T,9)
QUIT
+25 SET G=1_U_$PIECE(^AUPNPROB(X,0),U,3)
SET BGPDXPLE=X
+26 QUIT
End DoDot:1
+27 IF G
IF $PIECE(BGPLDV,U,2)<$PIECE(G,U,2)
SET BGPLDV=1_U_$PIECE(G,U,2)_U_"PL"_U_"PL "_$$VAL^XBDIQ1(9000011,BGPDXPLE,.01)_U_$$VAL^XBDIQ1(9000011,BGPDXPLE,.03)
+28 SET (X,G)=0
SET BGPDXPLE=""
FOR
SET X=$ORDER(^AMHPPROB("AC",P,X))
IF X'=+X!(G)
QUIT
Begin DoDot:1
+29 IF $PIECE(^AMHPPROB(X,0),U,12)'="A"
QUIT
+30 IF $PIECE(^AMHPPROB(X,0),U,3)>EDATE
QUIT
+31 IF $PIECE(^AMHPPROB(X,0),U,3)<BDATE
QUIT
+32 SET Y=$PIECE(^AMHPPROB(X,0),U)
+33 SET Y=$PIECE($GET(^AMHPROB(Y,0)),U)
+34 IF $EXTRACT(Y,1,2)="43"
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+35 IF $EXTRACT(Y,1,2)="44"
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+36 IF Y=995.80
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+37 IF Y=995.81
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+38 IF Y=995.82
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+39 IF Y=995.83
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+40 IF Y=995.85
SET G=1_U_$PIECE(^AMHPPROB(X,0),U,3)
SET BGPDXPLE=X
QUIT
+41 QUIT
End DoDot:1
+42 IF G
IF $PIECE(BGPLDV,U,2)<$PIECE(G,U,2)
SET BGPLDV=1_U_$PIECE(G,U,2)_U_"PL"_U_"BH PL "_$$VAL^XBDIQ1(9002011.51,BGPDXPLE,.01)_U_$$VAL^XBDIQ1(9002011.51,BGPDXPLE,.03)
+43 QUIT BGPLDV