PSOCSTD ;BHAM ISC/SAB - daily rx cost compilation ;9/14/05 1:13pm ;;7.0;OUTPATIENT PHARMACY;**4,17,28,89,198,212**;DEC 1997 ;External Ref to ^DPT DBIA# 10035 ;External Ref to ^PS(55 DBIA# 2228 ;External Ref to ^PSDRUG DBIA# 221 ; ;PSO*198 correct For loops to begin on the previous day @ time 999999 ;PSO*212 quit if it is the 1st day & monthly compile is running ; I $E(DT,6,7)="01",$$MTHLCK^PSOCSTM(0) Q ;PSO*212 K BEGDATE,ENDDATE S %DT(0)=$E(DT,1,5)_"00" W !!,"**** Date Range Selection ****" I '$O(^PS(59,0)) W $C(7),!,"PLEASE ENTER SITE PARAMETERS !!",!,$C(7) G EX BEG W ! S %DT="APE",%DT("A")=" Beginning DATE : " D ^%DT G:"^"[X EX G:Y<0 BEG S (%DT(0),BEGDATE)=Y EN W ! S %DT="APE",%DT("A")=" Ending DATE : " D ^%DT K %DT G:"^"[X EX G:Y<0 EN W ! S ENDDATE=Y S ZTIO="",ZTRTN="START^PSOCSTD",ZTDESC="Rx Daily Cost Compile" F G="BEGDATE","ENDDATE" S:$D(@G) ZTSAVE(G)="" D ^%ZTLOAD W:$D(ZTSK) !,"Task #"_ZTSK_" Queued !" K G,BEGDATE,ENDDATE,ZTSAVE,ZTIO,ZTSK,ZTRTN,ZTDESC Q START K ^TMP($J) G:$E(DT,6,7)="01" MTH I '$D(BEGDATE)!('$D(ENDDATE)) S X1=DT,X2=-1 D C^%DTC S (BEGDATE,ENDDATE)=X K BDT S PSG=0 F I=1:1 S X=$T(G+I) Q:$P(X,";",3)="" S PSOA(I)=$P(X,";",3),PSOB(I)=$P(X,";",4),PSG=PSG+1,PSOA1(I)=$P(X,";",5),PSOB1(I)=$P(X,";",6) S PSD=0 F I=1:1 S X=$T(D+I) Q:X="" S PSOC(I)=$P(X,";",3),PSOD(I)=$P(X,";",4),PSD=PSD+1,PSOC1(I)=$P(X,";",5),PSOD1(I)=$P(X,";",6) F PSDT=BEGDATE:1:ENDDATE K ^PSCST(PSDT),^PSCST("B",PSDT) S (TNR,TNO,TNP)=0 ;PSO*198 fix begin value of $O loops SRCH S PSDT=BEGDATE-1+.999999 F S PSDT=$O(^PSRX("AL",PSDT)) Q:'PSDT!($E(PSDT,1,7)>ENDDATE) S (OR,RF)=0 D SRCH1 S:'$D(BDT) BDT=PSDT S PSDT=BEGDATE-1+.999999 F S PSDT=$O(^PSRX("AM",PSDT)) Q:'PSDT!($E(PSDT,1,7)>ENDDATE) D SRCH2 S:'$D(BDT) BDT=PSDT S PSOCNT=0 F PSDT=0:0 S PSDT=$O(^PSCST("B",PSDT)) Q:'PSDT S PSD=PSDT,PSOCNT=PSOCNT+1 S ^PSCST(0)="DRUG COST^50.9D^"_PSD_"^"_PSOCNT,EDT=ENDDATE F PSDT=BEGDATE:1:ENDDATE F II=2:1:7 S:$D(^PSCST(PSDT,0)) $P(^PSCST(PSDT,0),"^",II)=0 S PSDT=BEGDATE-1 F S PSDT=$O(^PSCST(PSDT)) Q:'PSDT!(PSDT>ENDDATE) D .S DRG=0 F S DRG=$O(^PSCST(PSDT,"D",DRG)) Q:'DRG S DRC=^PSCST(PSDT,"D",DRG,0) D ..F II=2:1:7 S $P(^PSCST(PSDT,0),"^",II)=$P(^PSCST(PSDT,0),"^",II)+$P(DRC,"^",II) S PSDT=0 F S PSDT=$O(^TMP($J,"PAT",PSDT)) Q:'PSDT D SDFN D:$D(BDT) ZNODE^PSOCSTM EX K ^TMP($J),FL,%DT,A,B,BEGDATE,COST,DATA,DATA1,DATA2,DRUG,DFN,ENDDATE,I,II,ML,OR,PAST,PHYS,PSOCNT,DIV,PSD,PSDT,PSFILL,PSG,QTY,RF,RX0 K RXF,PAR,NDZ1,NDZ2,BDT,D,CLINIC,RX1,RX2,RXN,C,VALUE,VISITS,WD,X,X1,X2,Y,BDT,EDT,PSOA1,PSOB1,PSOC1,PSOD1,PSOC K TDFN,TDIV S:$D(ZTQUEUED) ZTREQ="@" L -^PSOCSTM ;PSO*212 Q SDFN S (TDFN,DIV)=0 F S DIV=$O(^TMP($J,"PAT",PSDT,DIV)) Q:'DIV D SDFN1 S ^PSCST(PSDT,1)=DT_"^"_TDFN Q SDFN1 S (DFN,TDIV)=0 F S DFN=$O(^TMP($J,"PAT",PSDT,DIV,DFN)) Q:'DFN S TDIV=TDIV+1,TDFN=TDFN+1 S $P(^PSCST(PSDT,"V",DIV,0),"^",8)=TDIV Q SRCH1 S RXF="" F RXN=0:0 S RXN=$O(^PSRX("AL",PSDT,RXN)) Q:'RXN F S RXF=$O(^PSRX("AL",PSDT,RXN,RXF)) Q:RXF="" S PAR=0 D CHK S (OR,RF)=0 Q SRCH2 S (RXN,RXF)=0 F S RXN=$O(^PSRX("AM",PSDT,RXN)) Q:'RXN F S RXF=$O(^PSRX("AM",PSDT,RXN,RXF)) Q:'RXF S PAR=1 D CHK S (OR,RF)=0 Q CHK Q:'$D(^PSRX(RXN,0)) I '$D(^PSRX(RXN,2)) Q S RX0=^PSRX(RXN,0) S RX2=^PSRX(RXN,2) S DFN=+$P(RX0,"^",2) Q:'$D(^DPT(DFN,0)) D:$P($G(^PS(55,DFN,0)),"^",6)'=2 EN^PSOHLUP(DFN) S DRUG=+$P(RX0,"^",6) Q:'$D(^PSDRUG(DRUG,0)) ;S CLASS=+$P(^(0),"^",2) Q:'$D(^PS(50.605,CLASS,0)) S DIV=+$P(RX2,"^",9) Q:'$D(^PS(59,DIV,0)) S PHYS=+$P(RX0,"^",4) Q:'$D(^VA(200,PHYS,0)) S PAST=+$P(RX0,"^",3) Q:'$D(^PS(53,PAST,0)) S CLINIC=+$P(RX0,"^",5) K:'$D(^SC(CLINIC,0)) CLINIC S COST=$S(+$P(RX0,"^",17):+$P(RX0,"^",17),$D(^PSDRUG(DRUG,660)):+$P(^(660),"^",6),1:0) S QTY=+$P(RX0,"^",7),ML=$S($P(RX0,"^",11)="M":1,1:0),WD=$S($P(RX0,"^",11)="W":1,1:0) I $G(PAR) D S PR=0 Q .I '$D(^PSRX(RXN,"P",RXF,0)) K ^PSRX("AM",PSDT,RXN,RXF) Q .I $P(^PSRX(RXN,"P",RXF,0),"^",19) S RF=0,RX1=^PSRX(RXN,"P",RXF,0),DIV=$S($P(RX1,"^",9):$P(RX1,"^",9),1:$P(RX2,"^",9)) D SET,REF S TNP=TNP+1 I $P(RX2,"^",13),'RXF S OR=OR+1,COST=QTY*COST D SET,SF S TNO=TNO+1 Q D:RXF .I '$D(^PSRX(RXN,1,RXF,0)) K ^PSRX("AL",PSDT,RXN,RXF) Q .I $P(^PSRX(RXN,1,RXF,0),"^",18) S RF=0,RX1=^PSRX(RXN,1,RXF,0),DIV=$S($P(RX1,"^",9):$P(RX1,"^",9),1:$P(RX2,"^",9)) D SET,REF S TNR=TNR+1 Q SF S DATA="^"_OR_"^"_RF_"^"_COST_"^"_QTY_"^"_ML_"^"_WD S:'$D(^TMP($J,"PAT",$P(PSDT,"."),DIV,DFN)) ^TMP($J,"PAT",$P(PSDT,"."),DIV,DFN)="" F I=1:1:PSG Q:('$D(CLINIC))&(I=PSG) S DATA1=$S(($D(@(PSOA(I)))#2):^(0),1:@(PSOB(I))_"^0^0^0^0") S DATA2=+$P(DATA1,"^") D .F II=2:1:7 S VALUE=$P(DATA,"^",II)+$P(DATA1,"^",II),DATA2=DATA2_"^"_VALUE S:II=7 @PSOA(I)=DATA2 .S:'$D(@PSOA1(I)) @PSOA1(I)=PSOB1(I) S $P(@PSOA1(I),"^",4)=+$P(@PSOA1(I),"^",4)+1,$P(@PSOA1(I),"^",3)=@PSOB(I) F I=1:1:PSD S DATA1=$S(($D(@(PSOC(I)))#2):$G(^(0)),1:@(PSOD(I))_"^0^0^0^0") S DATA2=+$P(DATA1,"^") D .F II=2:1:7 S VALUE=$P(DATA,"^",II)+$P(DATA1,"^",II),DATA2=DATA2_"^"_VALUE S:II=7 @PSOC(I)=DATA2 D .S:'$D(@PSOC1(I)) @PSOC1(I)=PSOD1(I) S $P(@PSOC1(I),"^",4)=+$P(@PSOC1(I),"^",4)+1,$P(@PSOC1(I),"^",3)=@PSOD(I) Q SET S ^PSCST($P(PSDT,"."),0)=$P(PSDT,"."),^PSCST("B",$P(PSDT,"."),$P(PSDT,"."))="" Q ; MTH S X1=DT,X2=-1 D C^%DTC S (BDT,EDT)=$E(X,1,5)_"00" F PSDT=(BDT+1):1:X K ^PSCST(PSDT),^PSCST("B",PSDT) D START^PSOCSTM G EX Q REF S OR=0,COST=$S(+$P(RX1,"^",11):+$P(RX1,"^",11),$D(^PSDRUG(DRUG,660)):+$P(^(660),"^",6),1:0) S RF=RF+1,QTY=+$P(RX1,"^",4),ML=$S($P(RX1,"^",2)="M":1,1:0),WD=$S($P(RX1,"^",2)="W":1,1:0) S COST=QTY*COST S PHYS=$S($P(RX1,"^",17):$P(RX1,"^",17),1:$P(RX0,"^",4)) D SF Q ; G ;; ;;^PSCST($P(PSDT,"."),0);PSDT;^TMP($J,"A1");1 ;;^PSCST($P(PSDT,"."),"P",PHYS,0);PHYS;^PSCST($P(PSDT,"."),"P",0);^50.9001PA^^ ;;^PSCST($P(PSDT,"."),"P",PHYS,"D",DRUG,0);DRUG;^PSCST($P(PSDT,"."),"P",PHYS,"D",0);^50.9002PA^^ ;;^PSCST($P(PSDT,"."),"D",DRUG,0);DRUG;^PSCST($P(PSDT,"."),"D",0);^50.9003PA^^ ;;^PSCST($P(PSDT,"."),"D",DRUG,"P",PHYS,0);PHYS;^PSCST($P(PSDT,"."),"D",DRUG,"P",0);^50.9004PA^^ ;;^PSCST($P(PSDT,"."),"PS",PAST,0);PAST;^PSCST($P(PSDT,"."),"PS",0);^50.9005PA^^ ;;^PSCST($P(PSDT,"."),"S",CLINIC,0);CLINIC;^PSCST($P(PSDT,"."),"S",0);^50.9008PA^^ ;; D ;; ;;^PSCST($P(PSDT,"."),"V",DIV,0);DIV;^PSCST($P(PSDT,"."),"V",0);^50.9006PA^^ ;;^PSCST($P(PSDT,"."),"V",DIV,"D",DRUG,0);DRUG;^PSCST($P(PSDT,"."),"V",DIV,"D",0);^50.9007PA^^ ;;^PSCST($P(PSDT,"."),"V",DIV,"P",PHYS,0);PHYS;^PSCST($P(PSDT,"."),"V",DIV,"P",0);^50.901PA^^