PSOMHV1 ;BIR/MHA - MHV API, Build patient medication ; 4/20/05 8:54am ;;7.0;OUTPATIENT PHARMACY;**204**;DEC 1997 ;External reference ^PS(55 supported by DBIA 2228 ;External reference ^PSDRUG( supported by DBIA 221 ;External reference to ^PS(51 supported by DBIA 2224 ;External reference to ^PS(51.2 supported by DBIA 2226 ;External reference to ^PS(50.7 supported by DBIA 2223 ;External reference to ^PS(50.606 supported by DBIA 2174 ; Input variables: dfn, start date, cut off date EN(DFN,BDT,EDT) ;entry point to return medication list Q:'$G(DFN) N DRG,DRGN,EXD,I,IFN,MIG,LSTFD,ORD,PEN,PSOBD,PSOED,PSODD,PSOOI,PSOSD,RX,RX0,RX2,RX3,TFN,TD,TR,TRM,SC,SCH,ST0,STA,PSODIV I '$G(DT) S DT=$$DT^XLFDT K ^TMP("PSO",$J) S PSOBD=$G(BDT),PSOED=$G(EDT) I +$G(PSOBD)<1 S X1=DT,X2=-120 D C^%DTC S PSOBD=X S EXD=PSOBD-1 I PSOED="" S PSOED=9999999 F S EXD=$O(^PS(55,DFN,"P","A",EXD)) Q:'EXD Q:EXD>PSOED D .S RX=0 F S RX=$O(^PS(55,DFN,"P","A",EXD,RX)) Q:'RX D:$D(^PSRX(RX,0)) GET S STA="ACT^NVR^REF^HLD^NVR^SUS^^^^^^EXP^DCD^DEL^DCD^DCD^HLD" S DRG="" F S DRG=$O(PSOSD(DRG)) Q:DRG="" D:$G(PSOSD(DRG))]"" .S PSOSD($P(STA,"^",$P(PSOSD(DRG),"^",2)+1),DRG)=PSOSD(DRG) K PSOSD(DRG) D PEN D:$D(PSOSD) BLD Q EN2(DFN,RXLIST) ;Entry point to return data for specified RX #s Q:DFN<1 Q:'RXLIST N DRG,DRGN,EXD,I,IFN,MIG,LSTFD,ORD,PEN,PSOBD,PSOED,PSODD,PSOOI,PSOSD,RX,RX0,RX2,RX3,TFN,TD,TR,TRM,SC,SCH,ST0,STA,PSORX,J,PSOERR,RX,PSRXD,PSODIV,PSOSTA I '$G(DT) S DT=$$DT^XLFDT K ^TMP("PSO",$J) S PSOSTA="ACT^NVR^REF^HLD^NVR^SUS^^^^^^EXP^DCD^DEL^DCD^DCD^HLD" F J=1:1 S PSORX=$P(RXLIST,"^",J) Q:PSORX="" D . I '$D(^PSRX("B",PSORX)) Q . I $O(^PSRX("B",PSORX,""))="" Q . S RX=$O(^PSRX("B",PSORX,"")),PSRXD=$G(^PSRX(RX,0)) . Q:PSRXD="" . Q:$P(PSRXD,"^",2)'=DFN . Q:$P($G(^PSRX(RX,"STA")),"^")=13 . Q:$P($G(^PSRX(RX,"STA")),"^")=15 . Q:'$D(^PSDRUG($P(PSRXD,"^",6),0)) . S IFN=RX,TR=$P(PSOSTA,"^",$P($G(^PSRX(RX,"STA")),"^")+1) . S TD=$P(^PSDRUG($P(PSRXD,"^",6),0),"^") . D RXD . Q Q ; EN3(DFN,BDT,EDT) ;entry point to return prescription history Q:'$G(DFN) N DRG,DRGN,EXD,I,IFN,MIG,LSTFD,ORD,PEN,PSOBD,PSOED,PSODD,PSOOI,PSOSD,RX,RX0,RX2,RX3,TFN,TD,TR,TRM,SC,SCH,ST0,STA,PSODIV I '$G(DT) S DT=$$DT^XLFDT K ^TMP("PSO",$J) S PSOBD=$G(BDT),PSOED=$G(EDT) I +$G(PSOBD)<1 S X1=DT,X2=-120 D C^%DTC S PSOBD=X S EXD=PSOBD-1 I PSOED="" S PSOED=9999999 F S EXD=$O(^PS(55,DFN,"P","A",EXD)) Q:'EXD Q:EXD>PSOED D .S RX=0 F S RX=$O(^PS(55,DFN,"P","A",EXD,RX)) Q:'RX D:$D(^PSRX(RX,0)) GET1 S STA="ACT^NVR^REF^HLD^NVR^SUS^^^^^^EXP^DCD^DEL^DCD^DCD^HLD" ; Uses RX (Rx IEN) instead of DRUG as a subscript in PSOSD and thus ; in ^TMP("PSO",$J). Other entry points use DRUG S RX="" F S RX=$O(PSOSD(RX)) Q:RX="" D:$G(PSOSD(RX))]"" .S PSOSD($P(STA,"^",$P(PSOSD(RX),"^",2)+1),RX)=PSOSD(RX) K PSOSD(RX) D:$D(PSOSD) BLD Q ; PEN F PEN=0:0 S PEN=$O(^PS(52.41,"P",DFN,PEN)) Q:'PEN D .S ORD=^PS(52.41,PEN,0) Q:$P(ORD,"^",2)'=DFN S DRG="" .Q:$P(ORD,"^",3)="DC"!($P(ORD,"^",3)="DE")!($P(ORD,"^",3)="")!($P(ORD,"^",3)="RF") .S PSOOI=$P(ORD,"^",8),PSODD=+$P(ORD,"^",9) .S DRG=$S(PSODD:$P($G(^PSDRUG(PSODD,0)),"^"),+PSOOI&('PSODD):$P(^PS(50.7,+PSOOI,0),"^")_" "_$P(^PS(50.606,$P(^PS(50.7,+PSOOI,0),"^",2),0),"^"),1:"") .Q:DRG']"" .I $D(PSOSD("PEN",DRG)) S DRG=DRG_"^"_PEN .S PSOSD("PEN",DRG)=PEN Q GET ; Q:$P($G(^PSRX(RX,"STA")),"^")=13 Q:$P($G(^PSRX(RX,"STA")),"^")=15 Q:'$P(^PSRX(RX,0),"^",2) Q:$P(^PSRX(RX,0),"^",2)'=DFN S RX0=^PSRX(RX,0),RX2=^PSRX(RX,2) S DRG=$P(^PSRX(RX,0),"^",6),STA=+^("STA") Q:'$D(^PSDRUG(DRG,0)) S DRGN=$P(^PSDRUG(DRG,0),"^"),ST0=$S(STA<12&($P(RX2,"^",6)