PSOP1 ;BHAM ISC/SAB - prints short medication profile ;02/25/94
;;7.0;OUTPATIENT PHARMACY;**15,46,103,132,148,233,326**;DEC 1997;Build 11
;External reference to ^PSDRUG supported by DBIA 221
;External reference to ^PS(50.605 supported by DBIA 696
K RX,DTOUT,DIRUT,DIROUT,DUOUT
D HD S DRUG="" F I=0:0 S DRUG=$O(^TMP($J,DRUG)) Q:DRUG=""!($G(PQT)) D G:$D(DTOUT)!($D(DUOUT))!($D(DIROUT)) Q
.F J=0:0 S J=$O(^TMP($J,DRUG,J)) Q:'J!($G(PQT)) S RX0=^(J),RX2=$G(^PSRX(J,2)),$P(RX0,"^",15)=$G(^("STA")),CP=$S(+$G(^PSRX(J,"IB")):"$",1:" ") S:$P(RX2,"^",15)&($P(RX2,"^",2)) RST($P(RX2,"^",2))=1 S:$P(RX0,"^",15)="" $P(RX0,"^",15)=-1 D W
D:'$G(PQT) PEND^PSOP2,NVA^PSOP2
Q D ^%ZISC K ^TMP($J),PQT,PSODTCT,ST,D0,DIC,DIR,DIRUT,DUOUT,G,II,K,RXD,RXF,ZX,DRUG,X,DFN,PHYS,PSRT,CT,AL,I1,PLS,REF
K LMI,PI,FN,Y,I,J,RX,DRX,ST,RX0,RX2,DA,PPPSTAT,PPP,EEEE,PPPCNT,PENDREX,PSOPEND,PPDIS,PPOI,PCOUNT,PP,FSIG,ZZZZ
S:$D(ZTQUEUED) ZTREQ="@"
Q
W I $Y+6>IOSL,$E(IOST)="C" D DIR W @IOF Q:$D(PQT) D HD
N PSOBADR
U IO I IO'=IO(0),$Y+6>IOSL W @IOF D HD
I $E(IOST)'="C",$Y+6>IOSL W @IOF D HD
D STAT^PSOFUNC S STA="A^N^R^H^P^S^^^^^^E^DC^^DC^DE^PH",ST=$P(STA,"^",(ST0+1)) K STA
S PSOBADR=$O(^PSRX(J,"L",9999),-1)
I PSOBADR'="" S PSOBADR=$G(^PSRX(J,"L",PSOBADR,0)) I PSOBADR["(BAD ADDRESS)" S PSOBADR="B"
I PSOBADR'="B" S PSOBADR=""
S ST=ST_PSOBADR
W !,CP_$P(RX0,"^"),$$ECME^PSOBPSUT(J),?13,$S($D(^PSDRUG(+$P(RX0,"^",6),0)):$P(^(0),"^"),1:"NOT ON FILE"),?54,$S($L(ST)=1:" "_ST,1:ST)
S RXD=$P($G(^PSRX(J,3)),"^"),RXF=$P(RX0,"^",9) F II=0:0 S II=$O(^PSRX(J,1,II)) Q:'II S RXF=RXF-1 S:$P(^PSRX(J,1,II,0),"^",16) RST($P(^(0),"^"))=1
W ?58,$S($L(RXF)=1:" "_RXF,1:RXF)
W ?61,$E($P(RX0,"^",13),4,5)_"-"_$E($P(RX0,"^",13),6,7)_"-"_$E($P(RX0,"^",13),2,3) W:RXD ?70,$E(RXD,4,5)_"-"_$E(RXD,6,7)_"-"_$E(RXD,2,3)_$S($G(RST(RXD)):"R",1:"")
S PSOPRSIG=$P($G(^PSRX(J,"SIG")),"^",2) K FSIG,BSIG D
.I PSOPRSIG D FSIG^PSOUTLA("R",J,50) Q
.D EN2^PSOUTLA1(J,50) F GGGG=0:0 S GGGG=$O(BSIG(GGGG)) Q:'GGGG S FSIG(GGGG)=BSIG(GGGG)
K PSOPRSIG,GGGG,BSIG
W !?5,"QTY: ",$P(RX0,"^",7),?24,"SIG: ",$G(FSIG(1)) D:$O(FSIG(1))
.F GGGG=1:0 S GGGG=$O(FSIG(GGGG)) Q:'GGGG!($G(PQT)) W !,?29,$G(FSIG(GGGG)) D:$Y+5>IOSL&($E(IOST)="C") DIR Q:$G(PQT) I '$G(PQT),($Y+5>IOSL) W @IOF D HD
K GGGG,FSIG Q:$G(PQT)
;D SIG
K RST Q
HD D:PAGE>1
.W !,"Patient: "_$P(^DPT(DFN,0),"^"),?70,"Page: "_PAGE
.W !?(80-$L("Medication Profile Sorted by "_HDR))/2,"Medication Profile Sorted by "_HDR W:$G(FR)]"" !?(80-$L(FR_" to "_TO))/2,FR_" to "_TO
W !?57,"REF",!?1,"Rx#",?13,"Drug",?54,"ST",?57,"REM",?62,"Issued",?70,"Last Fill",!,PSOPLINE S PAGE=PAGE+1
Q
SORT K DIR,DUOUT,DTOUT
S DIR("B")="All",DIR("A",1)=" ",DIR("A")="All Medications or Selection (A/S): ",DIR(0)="SAM^A:All;S:Select Range",DIR("?",1)="Enter 'A' to Print Entire Medication Profile",DIR("?")=" or 'S' for Selection Range" D ^DIR
K DIR Q:$D(DIRUT)!(Y="A")!(Y="E") D @PSRT
Q
DATE ;asks date range
W ! K %DT S %DT="AEX",%DT("A")="Starting Date: " D ^%DT I "^"[X S DUOUT=1 Q
G:Y<0 DATE S SDT=+Y,%DT(0)=SDT,FR=$E(SDT,4,5)_"/"_$E(SDT,6,7)_"/"_$E(SDT,2,3)
EDT S %DT("A")="Ending Date: " D ^%DT I "^"[X S DUOUT=1 Q
G:Y<0 EDT S EDT=+Y,DTS=1,TO=$E(EDT,4,5)_"/"_$E(EDT,6,7)_"/"_$E(EDT,2,3)
K %DT Q
DRUG ;asks drug list
W ! S DIC("A")="Start with Drug: ",DIC(0)="AEMQ",DIC=50
S DIC("S")="I $S('$D(^PSDRUG(Y,""I"")):1,'^(""I""):1,DT'>^(""I""):1,1:0),$S('$D(^PSDRUG(Y,2)):1,$P(^(2),""^"",3)'[""O"":0,1:1)"
D ^DIC I "^"[X S DUOUT=1 K DIC Q
G:Y<0 DRUG S FR=$P(Y,"^",2)
F %=$L($E(FR,1,30)):-1:1 S M=$A(FR,%) I M>32 S Y1=$E(FR,1,%-1)_$C(M-1)_$C(122) Q
S PSFR=Y1 K Y1,Y,X
TO S DIC("A")="To Drug: " D ^DIC I "^"[X S DUOUT=1 K DIC Q
G:Y<0 TO I FR]$P(Y,"^",2) W !,$C(7),"Less Than 'Start' Value" K X,Y G TO
S TO=$P(Y,"^",2),DRS=1
F %=$L($E(TO,1,30)):-1:1 S M=$A(TO,%) I M>32 S Y1=$E(TO,1,%-1)_$C(M+1)_$C(122) Q
S PSTO=Y1 K Y1,Y,X,DIC
Q
CLSS ;asks drug class list
W ! S DIC("A")="Start with Drug Class: ",DIC(0)="AEQ",DIC=50.605 D ^DIC I "^"[X S DUOUT=1 Q
G:Y<0 CLSS S FR=$P(Y,"^",2)
F %=$L($E(FR,1,30)):-1:1 S M=$A(FR,%) I M>32 S Y1=$E(FR,1,%-1)_$C(M-1)_$C(122) Q
S PSFR=Y1 K Y1,Y,X
TO1 S DIC("A")="To Drug Class: " D ^DIC I "^"[X S DUOUT=1 Q
G:Y<0 TO1 I FR]$P(Y,"^",2) W !,$C(7),"Less Than 'Start' Value" K X,Y G TO1
S TO=$P(Y,"^",2)
F %=$L($E(TO,1,30)):-1:1 S M=$A(TO,%) I M>32 S Y1=$E(TO,1,%-1)_$C(M+1)_$C(122) Q
S PSTO=Y1,CLS=1 K Y,Y1,X
Q
DIR K PQT,DTOUT,DUOUT,DIR,DIRUT S DIR(0)="E" D ^DIR S:$D(DUOUT)!($D(DTOUT)) PQT=1 Q
SIG I '$P(^PSRX(J,"SIG"),"^",2) D Q
.S X=$P(^PSRX(J,"SIG"),"^") D SIGONE^PSOHELP S SIG=$E($G(INS1),2,250)
.F SG=1:1:$L(SIG) W:($X+$L($P(SIG," ",SG)_" "))>$S(IOST["C-":IOM,1:70) !?6 W:$P(SIG," ",SG)]"" $P(SIG," ",SG)_" "
S MIG=$P(^PSRX(J,"SIG"),"^"),SIGOK=1 D
.F SG=1:1:$L(MIG) Q:$P(MIG," ",SG)="" W:($X+$L($P(MIG," ",SG)_" "))>$S(IOST["C-":IOM,1:70) !?6 W $P(MIG," ",SG)_" "
F I=0:0 S I=$O(^PSRX(RXN,"SIG1",I)) Q:'I S MIG=$P(^PSRX(RXN,"SIG1",I,0),"^") D
.F SG=1:1:$L(MIG) Q:$P(MIG," ",SG)="" W:($X+$L($P(MIG," ",SG)_" "))>$S(IOST["C-":IOM,1:70) !?6 W $P(MIG," ",SG)_" "
Q
PSOP1 ;BHAM ISC/SAB - prints short medication profile ;02/25/94
+1 ;;7.0;OUTPATIENT PHARMACY;**15,46,103,132,148,233,326**;DEC 1997;Build 11
+2 ;External reference to ^PSDRUG supported by DBIA 221
+3 ;External reference to ^PS(50.605 supported by DBIA 696
+4 KILL RX,DTOUT,DIRUT,DIROUT,DUOUT
+5 DO HD
SET DRUG=""
FOR I=0:0
SET DRUG=$ORDER(^TMP($JOB,DRUG))
IF DRUG=""!($GET(PQT))
QUIT
Begin DoDot:1
+6 FOR J=0:0
SET J=$ORDER(^TMP($JOB,DRUG,J))
IF 'J!($GET(PQT))
QUIT
SET RX0=^(J)
SET RX2=$GET(^PSRX(J,2))
SET $PIECE(RX0,"^",15)=$GET(^("STA"))
SET CP=$SELECT(+$GET(^PSRX(J,"IB")):"$",1:" ")
IF $PIECE(RX2,"^",15)&($PIECE(RX2,"^",2))
SET RST($PIECE(RX2,"^",2))=1
IF $PIECE(RX0,"^",15)=""
SET $PIECE(RX0,"^",15)=-1
DO W
End DoDot:1
IF $DATA(DTOUT)!($DATA(DUOUT))!($DATA(DIROUT))
GOTO Q
+7 IF '$GET(PQT)
DO PEND^PSOP2
DO NVA^PSOP2
Q DO ^%ZISC
KILL ^TMP($JOB),PQT,PSODTCT,ST,D0,DIC,DIR,DIRUT,DUOUT,G,II,K,RXD,RXF,ZX,DRUG,X,DFN,PHYS,PSRT,CT,AL,I1,PLS,REF
+1 KILL LMI,PI,FN,Y,I,J,RX,DRX,ST,RX0,RX2,DA,PPPSTAT,PPP,EEEE,PPPCNT,PENDREX,PSOPEND,PPDIS,PPOI,PCOUNT,PP,FSIG,ZZZZ
+2 IF $DATA(ZTQUEUED)
SET ZTREQ="@"
+3 QUIT
W IF $Y+6>IOSL
IF $EXTRACT(IOST)="C"
DO DIR
WRITE @IOF
IF $DATA(PQT)
QUIT
DO HD
+1 NEW PSOBADR
+2 USE IO
IF IO'=IO(0)
IF $Y+6>IOSL
WRITE @IOF
DO HD
+3 IF $EXTRACT(IOST)'="C"
IF $Y+6>IOSL
WRITE @IOF
DO HD
+4 DO STAT^PSOFUNC
SET STA="A^N^R^H^P^S^^^^^^E^DC^^DC^DE^PH"
SET ST=$PIECE(STA,"^",(ST0+1))
KILL STA
+5 SET PSOBADR=$ORDER(^PSRX(J,"L",9999),-1)
+6 IF PSOBADR'=""
SET PSOBADR=$GET(^PSRX(J,"L",PSOBADR,0))
IF PSOBADR["(BAD ADDRESS)"
SET PSOBADR="B"
+7 IF PSOBADR'="B"
SET PSOBADR=""
+8 SET ST=ST_PSOBADR
+9 WRITE !,CP_$PIECE(RX0,"^"),$$ECME^PSOBPSUT(J),?13,$SELECT($DATA(^PSDRUG(+$PIECE(RX0,"^",6),0)):$PIECE(^(0),"^"),1:"NOT ON FILE"),?54,$SELECT($LENGTH(ST)=1:" "_ST,1:ST)
+10 SET RXD=$PIECE($GET(^PSRX(J,3)),"^")
SET RXF=$PIECE(RX0,"^",9)
FOR II=0:0
SET II=$ORDER(^PSRX(J,1,II))
IF 'II
QUIT
SET RXF=RXF-1
IF $PIECE(^PSRX(J,1,II,0),"^",16)
SET RST($PIECE(^(0),"^"))=1
+11 WRITE ?58,$SELECT($LENGTH(RXF)=1:" "_RXF,1:RXF)
+12 WRITE ?61,$EXTRACT($PIECE(RX0,"^",13),4,5)_"-"_$EXTRACT($PIECE(RX0,"^",13),6,7)_"-"_$EXTRACT($PIECE(RX0,"^",13),2,3)
IF RXD
WRITE ?70,$EXTRACT(RXD,4,5)_"-"_$EXTRACT(RXD,6,7)_"-"_$EXTRACT(RXD,2,3)_$SELECT($GET(RST(RXD)):"R",1:"")
+13 SET PSOPRSIG=$PIECE($GET(^PSRX(J,"SIG")),"^",2)
KILL FSIG,BSIG
Begin DoDot:1
+14 IF PSOPRSIG
DO FSIG^PSOUTLA("R",J,50)
QUIT
+15 DO EN2^PSOUTLA1(J,50)
FOR GGGG=0:0
SET GGGG=$ORDER(BSIG(GGGG))
IF 'GGGG
QUIT
SET FSIG(GGGG)=BSIG(GGGG)
End DoDot:1
+16 KILL PSOPRSIG,GGGG,BSIG
+17 WRITE !?5,"QTY: ",$PIECE(RX0,"^",7),?24,"SIG: ",$GET(FSIG(1))
IF $ORDER(FSIG(1))
Begin DoDot:1
+18 FOR GGGG=1:0
SET GGGG=$ORDER(FSIG(GGGG))
IF 'GGGG!($GET(PQT))
QUIT
WRITE !,?29,$GET(FSIG(GGGG))
IF $Y+5>IOSL&($EXTRACT(IOST)="C")
DO DIR
IF $GET(PQT)
QUIT
IF '$GET(PQT)
IF ($Y+5>IOSL)
WRITE @IOF
DO HD
End DoDot:1
+19 KILL GGGG,FSIG
IF $GET(PQT)
QUIT
+20 ;D SIG
+21 KILL RST
QUIT
HD IF PAGE>1
Begin DoDot:1
+1 WRITE !,"Patient: "_$PIECE(^DPT(DFN,0),"^"),?70,"Page: "_PAGE
+2 WRITE !?(80-$LENGTH("Medication Profile Sorted by "_HDR))/2,"Medication Profile Sorted by "_HDR
IF $GET(FR)]""
WRITE !?(80-$LENGTH(FR_" to "_TO))/2,FR_" to "_TO
End DoDot:1
+3 WRITE !?57,"REF",!?1,"Rx#",?13,"Drug",?54,"ST",?57,"REM",?62,"Issued",?70,"Last Fill",!,PSOPLINE
SET PAGE=PAGE+1
+4 QUIT
SORT KILL DIR,DUOUT,DTOUT
+1 SET DIR("B")="All"
SET DIR("A",1)=" "
SET DIR("A")="All Medications or Selection (A/S): "
SET DIR(0)="SAM^A:All;S:Select Range"
SET DIR("?",1)="Enter 'A' to Print Entire Medication Profile"
SET DIR("?")=" or 'S' for Selection Range"
DO ^DIR
+2 KILL DIR
IF $DATA(DIRUT)!(Y="A")!(Y="E")
QUIT
DO @PSRT
+3 QUIT
DATE ;asks date range
+1 WRITE !
KILL %DT
SET %DT="AEX"
SET %DT("A")="Starting Date: "
DO ^%DT
IF "^"[X
SET DUOUT=1
QUIT
+2 IF Y<0
GOTO DATE
SET SDT=+Y
SET %DT(0)=SDT
SET FR=$EXTRACT(SDT,4,5)_"/"_$EXTRACT(SDT,6,7)_"/"_$EXTRACT(SDT,2,3)
EDT SET %DT("A")="Ending Date: "
DO ^%DT
IF "^"[X
SET DUOUT=1
QUIT
+1 IF Y<0
GOTO EDT
SET EDT=+Y
SET DTS=1
SET TO=$EXTRACT(EDT,4,5)_"/"_$EXTRACT(EDT,6,7)_"/"_$EXTRACT(EDT,2,3)
+2 KILL %DT
QUIT
DRUG ;asks drug list
+1 WRITE !
SET DIC("A")="Start with Drug: "
SET DIC(0)="AEMQ"
SET DIC=50
+2 SET DIC("S")="I $S('$D(^PSDRUG(Y,""I"")):1,'^(""I""):1,DT'>^(""I""):1,1:0),$S('$D(^PSDRUG(Y,2)):1,$P(^(2),""^"",3)'[""O"":0,1:1)"
+3 DO ^DIC
IF "^"[X
SET DUOUT=1
KILL DIC
QUIT
+4 IF Y<0
GOTO DRUG
SET FR=$PIECE(Y,"^",2)
+5 FOR %=$LENGTH($EXTRACT(FR,1,30)):-1:1
SET M=$ASCII(FR,%)
IF M>32
SET Y1=$EXTRACT(FR,1,%-1)_$CHAR(M-1)_$CHAR(122)
QUIT
+6 SET PSFR=Y1
KILL Y1,Y,X
TO SET DIC("A")="To Drug: "
DO ^DIC
IF "^"[X
SET DUOUT=1
KILL DIC
QUIT
+1 IF Y<0
GOTO TO
IF FR]$PIECE(Y,"^",2)
WRITE !,$CHAR(7),"Less Than 'Start' Value"
KILL X,Y
GOTO TO
+2 SET TO=$PIECE(Y,"^",2)
SET DRS=1
+3 FOR %=$LENGTH($EXTRACT(TO,1,30)):-1:1
SET M=$ASCII(TO,%)
IF M>32
SET Y1=$EXTRACT(TO,1,%-1)_$CHAR(M+1)_$CHAR(122)
QUIT
+4 SET PSTO=Y1
KILL Y1,Y,X,DIC
+5 QUIT
CLSS ;asks drug class list
+1 WRITE !
SET DIC("A")="Start with Drug Class: "
SET DIC(0)="AEQ"
SET DIC=50.605
DO ^DIC
IF "^"[X
SET DUOUT=1
QUIT
+2 IF Y<0
GOTO CLSS
SET FR=$PIECE(Y,"^",2)
+3 FOR %=$LENGTH($EXTRACT(FR,1,30)):-1:1
SET M=$ASCII(FR,%)
IF M>32
SET Y1=$EXTRACT(FR,1,%-1)_$CHAR(M-1)_$CHAR(122)
QUIT
+4 SET PSFR=Y1
KILL Y1,Y,X
TO1 SET DIC("A")="To Drug Class: "
DO ^DIC
IF "^"[X
SET DUOUT=1
QUIT
+1 IF Y<0
GOTO TO1
IF FR]$PIECE(Y,"^",2)
WRITE !,$CHAR(7),"Less Than 'Start' Value"
KILL X,Y
GOTO TO1
+2 SET TO=$PIECE(Y,"^",2)
+3 FOR %=$LENGTH($EXTRACT(TO,1,30)):-1:1
SET M=$ASCII(TO,%)
IF M>32
SET Y1=$EXTRACT(TO,1,%-1)_$CHAR(M+1)_$CHAR(122)
QUIT
+4 SET PSTO=Y1
SET CLS=1
KILL Y,Y1,X
+5 QUIT
DIR KILL PQT,DTOUT,DUOUT,DIR,DIRUT
SET DIR(0)="E"
DO ^DIR
IF $DATA(DUOUT)!($DATA(DTOUT))
SET PQT=1
QUIT
SIG IF '$PIECE(^PSRX(J,"SIG"),"^",2)
Begin DoDot:1
+1 SET X=$PIECE(^PSRX(J,"SIG"),"^")
DO SIGONE^PSOHELP
SET SIG=$EXTRACT($GET(INS1),2,250)
+2 FOR SG=1:1:$LENGTH(SIG)
IF ($X+$LENGTH($PIECE(SIG," ",SG)_" "))>$SELECT(IOST["C-"
WRITE !?6
IF $PIECE(SIG," ",SG)]""
WRITE $PIECE(SIG," ",SG)_" "
End DoDot:1
QUIT
+3 SET MIG=$PIECE(^PSRX(J,"SIG"),"^")
SET SIGOK=1
Begin DoDot:1
+4 FOR SG=1:1:$LENGTH(MIG)
IF $PIECE(MIG," ",SG)=""
QUIT
IF ($X+$LENGTH($PIECE(MIG," ",SG)_" "))>$SELECT(IOST["C-"
WRITE !?6
WRITE $PIECE(MIG," ",SG)_" "
End DoDot:1
+5 FOR I=0:0
SET I=$ORDER(^PSRX(RXN,"SIG1",I))
IF 'I
QUIT
SET MIG=$PIECE(^PSRX(RXN,"SIG1",I,0),"^")
Begin DoDot:1
+6 FOR SG=1:1:$LENGTH(MIG)
IF $PIECE(MIG," ",SG)=""
QUIT
IF ($X+$LENGTH($PIECE(MIG," ",SG)_" "))>$SELECT(IOST["C-"
WRITE !?6
WRITE $PIECE(MIG," ",SG)_" "
End DoDot:1
+7 QUIT