PSOORRLO ;BHAM ISC/SJA - returns patient's outpatient meds-original sort ;10/12/06
;;7.0;OUTPATIENT PHARMACY;**225**;DEC 1997;Build 29
;External reference to ^PS(55 supported by DBIA 2228
;External reference to ^PSDRUG supported by DBIA 221
;External reference to ^VA(200 supported by DBIA 10060
;External reference to(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
;External reference to OCL^PSJORRE supported by DBIA 2383
OCL ;entry point to return condensed list
;BHW;PSO*7*159;New SD* Variables
N SD,SDT,SDT1,ST,STT,PSEX,PSG,PST,GP,EXDT1
D:$P($G(^PS(55,DFN,0)),"^",6)'=2 EN^PSOHLUP(DFN)
K ^TMP("PS",$J),^TMP("PSO",$J),^TMP("PS1",$J)
S TFN=0,PSBDT=$G(BDT),PSEDT=$G(EDT) I +$G(PSBDT)<1 S X1=DT,X2=-120 D C^%DTC S PSBDT=X
S EXDT=PSBDT-1,IFN=0
F S EXDT=$O(^PS(55,DFN,"P","A",EXDT)) Q:'EXDT F S IFN=$O(^PS(55,DFN,"P","A",EXDT,IFN)) Q:'IFN D:$D(^PSRX(IFN,0))
.S EXDT1=9999999-EXDT
.Q:$P($G(^PSRX(IFN,"STA")),"^")=13
.S TFN=TFN+1,RX0=^PSRX(IFN,0),RX2=$G(^(2)),RX3=$G(^(3)),STA=+$G(^("STA")),TRM=0,LSTFD=$P(RX2,"^",2),LSTRD=$P(RX2,"^",13),LSTDS=$P(RX0,"^",8)
.F I=0:0 S I=$O(^PSRX(IFN,1,I)) Q:'I S TRM=TRM+1,LSTFD=$P(^PSRX(IFN,1,I,0),"^"),LSTDS=$P(^(0),"^",10) S:$P(^(0),"^",18)]"" LSTRD=$P(^(0),"^",18)
.S ST0=$S(STA<12&($P(RX2,"^",6)
80 IEN=IEN+1,SD=SD+1,^TMP("PSO",$J,GP,PSEX,TFN,"SIO",0)=SD D
...S ^TMP("PSO",$J,GP,PSEX,TFN,"SIO",IEN,0)=$G(^TMP("PSO",$J,GP,PSEX,TFN,"SIO",IEN,0))_" "_$P(MIG," ",SG)
D NVA
S PSG=0,J=1 F S PSG=$O(^TMP("PSO",$J,PSG)) Q:'PSG S PST="" F S PST=$O(^TMP("PSO",$J,PSG,PST)) Q:PST="" S I=0 F S I=$O(^TMP("PSO",$J,PSG,PST,I)) Q:'I D
.M ^TMP("PS",$J,J)=^TMP("PSO",$J,PSG,PST,I) S J=J+1
S PSG=0 F S PSG=$O(^TMP("PS1",$J,PSG)) Q:'PSG S I=0 F S I=$O(^TMP("PS1",$J,PSG,I)) Q:'I D
.M ^TMP("PS",$J,J)=^TMP("PS1",$J,PSG,I) S J=J+1
K ^TMP("PSO",$J),^TMP("PS1",$J)
D OCL^PSJORRE(DFN,BDT,EDT,.TFN,+$G(VIEW)) D END^PSOORRL1
K SDT,SDT1,GP,PSEX,PSG,PST,EDT,EDT1,BDT,DBT1,X
Q
WAIT ; IF PENDING ENTRY STILL BEING BUILT SEE IF IT COMPLETES WITHIN ANOTHER SECOND
H 1 S PSOR=$G(^PS(52.41,IFN,0))
Q
;
NVA ; Set Non-VA Med Orders in the ^TMP Global
;BHW;PSO*7*159;New SDT,SDT1 Variables
N SDT,SDT1
F I=0:0 S I=$O(^PS(55,DFN,"NVA",I)) Q:'I S X=$G(^PS(55,DFN,"NVA",I,0)) D
.Q:'$P(X,"^")
.S DRG=$S($P(X,"^",2):$P($G(^PSDRUG($P(X,"^",2),0)),"^"),1:$P(^PS(50.7,$P(X,"^"),0),"^")_" "_$P(^PS(50.606,$P(^PS(50.7,$P(X,"^"),0),"^",2),0),"^"))
.S SDT=$P(X,"^",9) I 'SDT D TMPBLD Q
.I $E(SDT,4,5),$E(SDT,6,7) D
..;I $P(X,"^",9) D Q
..I $G(BDT),SDTEDT Q
..I $G(BDT),$P(X,"^",7),$P(X,"^",7)EDT1 Q
..I $G(BDT1),$P(X,"^",7),$E($P(X,"^",7),1,5)EDT1 Q
..I $G(BDT1),$P(X,"^",7),$E($P(X,"^",7),1,3)