BGP1D52 ; IHS/CMI/LAB - measure 31 ;
;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
;
;
EAPT(P,BDATE,EDATE,BGPDAYS,BGPGAP,BGPDAYS1) ;EP
;get all ANTIDEPRESSANTS
K ^TMP($J,"MEDS")
K BGPZ,M
S (G,N,Y,X,T,T1,T2,M,K,S,C,R,A)=""
S K=0
S Y="^TMP($J,""MEDS"",",X=P_"^ALL MED;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE) S E=$$START1^APCLDF(X,Y)
S T=$O(^ATXAX("B","BGP HEDIS ANTIDEPRESSANT MEDS",0))
S T2=$O(^ATXAX("B","BGP HEDIS ANTIDEPRESSANT VA CLASS",0))
S X=0 F S X=$O(^TMP($J,"MEDS",X)) Q:X'=+X S Y=+$P(^TMP($J,"MEDS",X),U,4) D
.Q:'$D(^AUPNVMED(Y,0))
.S V=$P(^AUPNVMED(Y,0),U,3)
.Q:'$D(^AUPNVSIT(V,0))
.S G=0
.S D=$P(^AUPNVMED(Y,0),U)
.I T,$D(^ATXAX(T,21,"B",D)) S G=1 G EAPT1
.S C=$P($G(^PSDRUG(D,0)),U,2)
.I C]"",T2,$D(^ATXAX(T2,21,"B",C)) S G=1 G EAPT1
.Q:'G
EAPT1 .;
.S J=$P(^AUPNVMED(Y,0),U,8)
.S S=$$DAYS^BGP1D82(Y,V,EDATE)
.S K=S+K ;TOTAL DAYS SUPPLY
.I R]"" S R=R_";"
.S R=R_$$DATE^BGP1UTL($P($P(^AUPNVSIT(V,0),U),"."))_"("_S_")"
.S F=$P($P(^AUPNVSIT(V,0),U),".")
.S A=$$FMADD^XLFDT(F,$P(^AUPNVMED(Y,0),U,7))
.I J]"",J<A S A=J
.S M(F)=A ;$S(J:J,1:$$FMADD^XLFDT(F,$P(^AUPNVMED(Y,0),U,7)))
;I K>83 S BGPREG=1_U_Q 1_U_" total days beta blocker: "_K
GAP ;now FIGURE OUT GAP DAYS
S G=0 ;gap days
S B=0 F S B=$O(M(B)) Q:B'=+B S E=M(B) D
.S Y=$O(M(B)) ;NEXT BEGINNING
.;I Y="" S Y=$$FMADD^XLFDT(BDATE,BGPDAYS1)
.I Y="" Q
.I Y>EDATE Q
.S Z=$$FMDIFF^XLFDT(Y,E)
.I Z>0 S G=Z+G
.Q
I G>BGPGAP!(K<BGPDAYS) Q 0_U_R_U_"DAYS="_K_", GAP="_G
Q 1_U_R_U_"DAYS="_K_", GAP="_G
BGP1D52 ; IHS/CMI/LAB - measure 31 ;
+1 ;;11.1;IHS CLINICAL REPORTING SYSTEM;;JUN 27, 2011;Build 33
+2 ;
+3 ;
EAPT(P,BDATE,EDATE,BGPDAYS,BGPGAP,BGPDAYS1) ;EP
+1 ;get all ANTIDEPRESSANTS
+2 KILL ^TMP($JOB,"MEDS")
+3 KILL BGPZ,M
+4 SET (G,N,Y,X,T,T1,T2,M,K,S,C,R,A)=""
+5 SET K=0
+6 SET Y="^TMP($J,""MEDS"","
SET X=P_"^ALL MED;DURING "_$$FMTE^XLFDT(BDATE)_"-"_$$FMTE^XLFDT(EDATE)
SET E=$$START1^APCLDF(X,Y)
+7 SET T=$ORDER(^ATXAX("B","BGP HEDIS ANTIDEPRESSANT MEDS",0))
+8 SET T2=$ORDER(^ATXAX("B","BGP HEDIS ANTIDEPRESSANT VA CLASS",0))
+9 SET X=0
FOR
SET X=$ORDER(^TMP($JOB,"MEDS",X))
IF X'=+X
QUIT
SET Y=+$PIECE(^TMP($JOB,"MEDS",X),U,4)
Begin DoDot:1
+10 IF '$DATA(^AUPNVMED(Y,0))
QUIT
+11 SET V=$PIECE(^AUPNVMED(Y,0),U,3)
+12 IF '$DATA(^AUPNVSIT(V,0))
QUIT
+13 SET G=0
+14 SET D=$PIECE(^AUPNVMED(Y,0),U)
+15 IF T
IF $DATA(^ATXAX(T,21,"B",D))
SET G=1
GOTO EAPT1
+16 SET C=$PIECE($GET(^PSDRUG(D,0)),U,2)
+17 IF C]""
IF T2
IF $DATA(^ATXAX(T2,21,"B",C))
SET G=1
GOTO EAPT1
+18 IF 'G
QUIT
EAPT1 ;
+1 SET J=$PIECE(^AUPNVMED(Y,0),U,8)
+2 SET S=$$DAYS^BGP1D82(Y,V,EDATE)
+3 ;TOTAL DAYS SUPPLY
SET K=S+K
+4 IF R]""
SET R=R_";"
+5 SET R=R_$$DATE^BGP1UTL($PIECE($PIECE(^AUPNVSIT(V,0),U),"."))_"("_S_")"
+6 SET F=$PIECE($PIECE(^AUPNVSIT(V,0),U),".")
+7 SET A=$$FMADD^XLFDT(F,$PIECE(^AUPNVMED(Y,0),U,7))
+8 IF J]""
IF J<A
SET A=J
+9 ;$S(J:J,1:$$FMADD^XLFDT(F,$P(^AUPNVMED(Y,0),U,7)))
SET M(F)=A
End DoDot:1
+10 ;I K>83 S BGPREG=1_U_Q 1_U_" total days beta blocker: "_K
GAP ;now FIGURE OUT GAP DAYS
+1 ;gap days
SET G=0
+2 SET B=0
FOR
SET B=$ORDER(M(B))
IF B'=+B
QUIT
SET E=M(B)
Begin DoDot:1
+3 ;NEXT BEGINNING
SET Y=$ORDER(M(B))
+4 ;I Y="" S Y=$$FMADD^XLFDT(BDATE,BGPDAYS1)
+5 IF Y=""
QUIT
+6 IF Y>EDATE
QUIT
+7 SET Z=$$FMDIFF^XLFDT(Y,E)
+8 IF Z>0
SET G=Z+G
+9 QUIT
End DoDot:1
+10 IF G>BGPGAP!(K<BGPDAYS)
QUIT 0_U_R_U_"DAYS="_K_", GAP="_G
+11 QUIT 1_U_R_U_"DAYS="_K_", GAP="_G