PSO52API ;BHAM ISC/SAB- Encap II API to return Rx data ;04/07/05 10:30 am
;;7.0;OUTPATIENT PHARMACY;**213,229,252**;DEC 1997;Build 12
;
;Reference to ^PS(55 supported by DBIA 2228
;
RX(DFN,LIST,IEN,RX,NODE,SDATE,EDATE) ;
;DFN: IEN from the PATIENT file (#2) [REQUIRED]
;LIST: Subscript name used in ^TMP global [REQUIRED]
;IEN: Internal prescription number [optional]
;RX#: RX # field (#.01) of the PRESCRIPTION file (#52) [optional]
;NODE: Determines data elements returned [optional]
;SDATE: Start Date [optional]
;EDATE: End Date [optional]
;
Q:'$G(DFN) Q:$G(LIST)=""
N DA,DR,PST,DIC,DIQ,ND,LK,DTE,DAT,I,X,D0 K ^TMP($J,LIST) S ^TMP($J,LIST,DFN,0)=0
I $G(IEN) D PROCESS G CLEAN
I $G(RX)]"",'$G(IEN) S IEN=$O(^PSRX("B",RX,0)) D G CLEAN
.I 'IEN S ^TMP($J,LIST,DFN,0)="-1^NO DATA FOUND" Q
.D PROCESS
D DATE
CLEAN F I=0:0 S I=$O(^TMP($J,LIST,DFN,I)) Q:'I S ^TMP($J,LIST,DFN,0)=^TMP($J,LIST,DFN,0)+1
I ^TMP($J,LIST,DFN,0)=0 S ^TMP($J,LIST,DFN,0)="-1^NO DATA FOUND"
K DA,DR,DIC,ND,DAT,PST,LK,DIQ,DTE,I,X
Q
PROCESS ;
I DFN'=$P($G(^PSRX(IEN,0)),"^",2) S ^TMP($J,LIST,IEN,0)="-1^NO DATA FOUND (MISMATCHED PATIENT)" Q
I $G(^PSRX(IEN,0))']"" S ^TMP($J,LIST,IEN,0)="-1^NO RX DATA FOUND" Q
I $G(NODE)']"" D ZE,TW,TH,MI,ST,RF,CM,AT,LB,PT^PSO52B,SD^PSO52B,TB^PSO52B,OI^PSO52B,MLT^PSO52B S DAT="I" D IB Q
D ST F LK=1:1:$L(NODE,",") S DAT=$P(NODE,",",LK),ND=$P(DAT,"^") D
.I ND=0 D ZE Q
.I ND=2 D ZE,TW Q
.I ND=3 D TW,TH Q
.I ND="R" D RF Q
.I ND="I" D IB Q
.I ND="P" D PT^PSO52B Q
.I ND="O" D OI^PSO52B Q
.I ND="T" D TB^PSO52B Q
.I ND="L" D LB Q
.I ND="S" D SD^PSO52B Q
.I ND="M" D MI Q
.I ND="C" D CM Q
.I ND="A" D AT Q
.I ND="ST" D ST Q
.I ND="ICD" D MLT^PSO52B Q
.S ^TMP($J,LIST,DFN,IEN,"INVALID REQUEST",ND)="Invalid Data Requested"
Q
ZE ;zero
K PST S DIC=52,DA=IEN,DR=".01:9;10.3;10.6;11;16;17" D DIQ
F DR=.01,1,2,3,4,5,6,6.5,7,8,9,10.3,10.6,11,16,17 D
.I PST(52,DA,DR,"E")'=PST(52,DA,DR,"I") S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")
K DA,DR,PST,DIC,DIQ
Q
TW ;two
Q:'$D(^PSRX(IEN,2))
K PST S DIC=52,DA=IEN,DR="20:31;32.1;32.2;32.3;104" D DIQ
F DR=20,21,22,23,24,25,26,27,28,29,30,31,32.1,32.2,32.3,104 D
.I PST(52,DA,DR,"E")'=PST(52,DA,DR,"I") S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")
K DA,DR,PST,DIC,DIQ
Q
TH ;three
Q:'$D(^PSRX(IEN,3))
K PST S DIC=52,DA=IEN,DR="12;26.1;34.1;101;102;102.1;102.2;109;112" D DIQ
F DR=12,26.1,34.1,101,102,102.1,102.2,109,112 D
.I PST(52,DA,DR,"E")'=PST(52,DA,DR,"I") S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")
K DA,DR,PST,DIC,DIQ
Q
MI ;sig
I $P($G(^PSRX(IEN,"SIG")),"^",2) D Q
.I '$O(^PSRX(IEN,"SIG1",0)) S ^TMP($J,LIST,DFN,IEN,"M",0)="-1^NO DATA FOUND" Q
.F I=0:0 S I=$O(^PSRX(IEN,"SIG1",I)) Q:'I S ^TMP($J,LIST,DFN,IEN,"M",I,0)=^PSRX(IEN,"SIG1",I,0),^TMP($J,LIST,DFN,IEN,"M",0)=$G(^TMP($J,LIST,DFN,IEN,"M",0))+1
I $P($G(^PSRX(IEN,"SIG")),"^")']"" S ^TMP($J,LIST,DFN,IEN,"M",0)="-1^NO DATA FOUND" Q
S X=$P($G(^PSRX(IEN,"SIG")),"^") D SIG^PSOHELP S ^TMP($J,LIST,DFN,IEN,"M",1,0)=$E(INS1,2,9999999),^TMP($J,LIST,DFN,IEN,"M",0)=1
K X,INS1
Q
ST ;status
I DT>$P(^PSRX(IEN,2),"^",6),$P(^PSRX(IEN,"STA"),"^")<11 D
.N PSOEXRX,PSOEXSTA,ORN,PIFN,PSUSD,PRFDT,PDA,PSST
.S PSOEXRX=IEN D EN2^PSOMAUEX K PSOEXRX,PSONM,PSONMX
K PST S DIC=52,DA=IEN,DR=".01;100" D DIQ
S ^TMP($J,LIST,DFN,IEN,100)=PST(52,DA,100,"I")_"^"_PST(52,DA,100,"E")
S ^TMP($J,LIST,"B",PST(52,DA,.01,"E"),IEN)=""
K DA,DR,PST,DIC,DIQ
Q
RF ;refill
I '$O(^PSRX(IEN,1,0)) S ^TMP($J,LIST,DFN,IEN,"RF",0)="-1^NO DATA FOUND" Q
I $P($G(DAT),"^",3) S DA(52.1)=$P(DAT,"^",3) D RFD K DA,DR,PST,DIC,DIQ Q
F RF=0:0 S RF=$O(^PSRX(IEN,1,RF)) Q:'RF S DA(52.1)=RF D RFD
K DA,DR,PST,DIC,DIQ,RF
Q
RFD K PST S DR(52.1)=".01:8;10.1;12;13;14;15;17",DIC=52,DA=IEN,DR=52 D DIQ
I $P($G(DAT),"^",3),'$G(PST(52.1,DA(52.1),.01,"I")) S ^TMP($J,LIST,DFN,IEN,"RF",0)="-1^NO DATA FOUND" Q
S ^TMP($J,LIST,DFN,IEN,"RF",0)=$G(^TMP($J,LIST,DFN,IEN,"RF",0))+1
F DR=.01,1,1.1,1.2,2,3,4,5,6,7,8,10.1,12,13,14,15,17 D
.I PST(52.1,DA(52.1),DR,"E")'=PST(52.1,DA(52.1),DR,"I") S ^TMP($J,LIST,DFN,IEN,"RF",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")_"^"_PST(52.1,DA(52.1),DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,"RF",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")
Q
IB ;ib ori
I $P($G(DAT),"^",2)="R" D IBR Q
I $G(^PSRX(IEN,"IB"))']"" S ^TMP($J,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND" Q
K PST S DIC=52,DA=IEN,DR="105;106;106.5;106.6" D DIQ
F DR=105,106,106.5,106.6 D
.I PST(52,DA,DR,"E")'=PST(52,DA,DR,"I") S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,DR)=PST(52,DA,DR,"E")
K DA,DR,PST,DIC,DIQ
I $P($G(DAT),"^",2)="" D IBR Q
Q
IBR ;ib ref
I '$O(^PSRX(IEN,1,0)) S ^TMP($J,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND" Q
I $P($G(DAT),"^",2)="R",$P($G(DAT),"^",3) S DA(52.1)=$P(DAT,"^",3) D IBS K DA,DR,PST,DIC,DIQ Q
N IB F IB=0:0 S IB=$O(^PSRX(IEN,1,IB)) Q:'IB S DA(52.1)=IB D IBS
I '$G(^TMP($J,LIST,DFN,IEN,"IB",0)) K ^TMP($J,LIST,DFN,IEN,"IB") S ^TMP($J,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND"
K DA,DR,PST,DIC,DIQ,IB
Q
IBS I $P($G(DAT),"^",3),'$G(^PSRX(IEN,1,DA(52.1),"IB")) S ^TMP($J,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND" Q
I '$D(^PSRX(IEN,1,DA(52.1),"IB")) S ^TMP($J,LIST,DFN,IEN,"IB",DA(52.1),0)="-1^NO DATA FOUND" Q
K PST S DR(52.1)="9;9.1",DIC=52,DA=IEN,DR=52 D DIQ
S ^TMP($J,LIST,DFN,IEN,"IB",0)=$G(^TMP($J,LIST,DFN,IEN,"IB",0))+1
F DR=9,9.1 D
.I PST(52.1,DA(52.1),DR,"E")'=PST(52.1,DA(52.1),DR,"I") S ^TMP($J,LIST,DFN,IEN,"IB",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")_"^"_PST(52.1,DA(52.1),DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,"IB",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")
Q
CM ;cmop
I '$O(^PSRX(IEN,4,0)) S ^TMP($J,LIST,DFN,IEN,"C",0)="-1^NO DATA FOUND" Q
N CM F CM=0:0 S CM=$O(^PSRX(IEN,4,CM)) Q:'CM S DA(52.01)=CM D CMP
K DA,DR,PST,DIC,DIQ,CM
Q
CMP S ^TMP($J,LIST,DFN,IEN,"C",0)=$G(^TMP($J,LIST,DFN,IEN,"C",0))+1
K PST S DR(52.01)="2;3;4",DIC=52,DA=IEN,DR=400 D DIQ
F DR=2,3,4 D
.I PST(52.01,DA(52.01),DR,"E")'=PST(52.01,DA(52.01),DR,"I") S ^TMP($J,LIST,DFN,IEN,"C",DA(52.01),DR)=PST(52.01,DA(52.01),DR,"I")_"^"_PST(52.01,DA(52.01),DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,"C",DA(52.01),DR)=PST(52.01,DA(52.01),DR,"I")
Q
AT ;activity log
I '$O(^PSRX(IEN,"A",0)) S ^TMP($J,LIST,DFN,IEN,"A",0)="-1^NO DATA FOUND" Q
N AT F AT=0:0 S AT=$O(^PSRX(IEN,"A",AT)) Q:'AT S DA(52.3)=AT D ATP
K DA,DR,PST,DIC,DIQ,AT
Q
ATP K PST S DR(52.3)=".01;.02;.03;.04;.05" S DIC=52,DA=IEN,DR=40 D DIQ
S ^TMP($J,LIST,DFN,IEN,"A",0)=$G(^TMP($J,LIST,DFN,IEN,"A",0))+1
F DR=.01,.02,.03,.04,.05 D
.I DR=.04 S ^TMP($J,LIST,DFN,IEN,"A",DA(52.3),DR)=PST(52.3,DA(52.3),DR,"E") Q
.I PST(52.3,DA(52.3),DR,"E")'=PST(52.3,DA(52.3),DR,"I") S ^TMP($J,LIST,DFN,IEN,"A",DA(52.3),DR)=PST(52.3,DA(52.3),DR,"I")_"^"_PST(52.3,DA(52.3),DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,"A",DA(52.3),DR)=PST(52.3,DA(52.3),DR,"I")
Q
LB ;label log
I '$O(^PSRX(IEN,"L",0)) S ^TMP($J,LIST,DFN,IEN,"L",0)="-1^NO DATA FOUND" Q
N LB F LB=0:0 S LB=$O(^PSRX(IEN,"L",LB)) Q:'LB S DA(52.032)=LB D LBP
K DA,DR,PST,DIC,DIQ,LB
Q
LBP S ^TMP($J,LIST,DFN,IEN,"L",0)=$G(^TMP($J,LIST,DFN,IEN,"L",0))+1
K PST S DR(52.032)=".01;1;2;3;4" S DIC=52,DA=IEN,DR=32 D DIQ
F DR=.01,1,2,3,4 D
.I DR=1 S ^TMP($J,LIST,DFN,IEN,"L",DA(52.032),DR)=PST(52.032,DA(52.032),DR,"E") Q
.I PST(52.032,DA(52.032),DR,"E")'=PST(52.032,DA(52.032),DR,"I") S ^TMP($J,LIST,DFN,IEN,"L",DA(52.032),DR)=PST(52.032,DA(52.032),DR,"I")_"^"_PST(52.032,DA(52.032),DR,"E") Q
.S ^TMP($J,LIST,DFN,IEN,"L",DA(52.032),DR)=PST(52.032,DA(52.032),DR,"I")
K DA,DR,PST,DIC,DIQ
Q
DATE ;date range
I $G(SDATE) S DTE=SDATE-1 D Q
.I $G(EDATE) D Q
..F S DTE=$O(^PS(55,DFN,"P","A",DTE)) Q:'DTE!(DTE>EDATE) F IEN=0:0 S IEN=$O(^PS(55,DFN,"P","A",DTE,IEN)) Q:'IEN D:$P($G(^PSRX(IEN,"STA")),"^")'=13 PROCESS
.F S DTE=$O(^PS(55,DFN,"P","A",DTE)) Q:'DTE F IEN=0:0 S IEN=$O(^PS(55,DFN,"P","A",DTE,IEN)) Q:'IEN D:$P($G(^PSRX(IEN,"STA")),"^")'=13 PROCESS
I $G(EDATE),'$G(SDATE) S DTE=DT-1 D Q
.F S DTE=$O(^PS(55,DFN,"P","A",DTE)) Q:'DTE!(DTE>EDATE) F IEN=0:0 S IEN=$O(^PS(55,DFN,"P","A",DTE,IEN)) Q:'IEN D:$P($G(^PSRX(IEN,"STA")),"^")'=13 PROCESS
S DTE=DT-1 F S DTE=$O(^PS(55,DFN,"P","A",DTE)) Q:'DTE F IEN=0:0 S IEN=$O(^PS(55,DFN,"P","A",DTE,IEN)) Q:'IEN D:$P($G(^PSRX(IEN,"STA")),"^")'=13 PROCESS
Q
PROF(DFN,LIST,SDATE,EDATE) ;
D ^PSO52AP1
Q
DIQ ;process fields
S DIQ="PST",DIQ(0)="IE" D EN^DIQ1
Q
PSO52API ;BHAM ISC/SAB- Encap II API to return Rx data ;04/07/05 10:30 am
+1 ;;7.0;OUTPATIENT PHARMACY;**213,229,252**;DEC 1997;Build 12
+2 ;
+3 ;Reference to ^PS(55 supported by DBIA 2228
+4 ;
RX(DFN,LIST,IEN,RX,NODE,SDATE,EDATE) ;
+1 ;DFN: IEN from the PATIENT file (#2) [REQUIRED]
+2 ;LIST: Subscript name used in ^TMP global [REQUIRED]
+3 ;IEN: Internal prescription number [optional]
+4 ;RX#: RX # field (#.01) of the PRESCRIPTION file (#52) [optional]
+5 ;NODE: Determines data elements returned [optional]
+6 ;SDATE: Start Date [optional]
+7 ;EDATE: End Date [optional]
+8 ;
+9 IF '$GET(DFN)
QUIT
IF $GET(LIST)=""
QUIT
+10 NEW DA,DR,PST,DIC,DIQ,ND,LK,DTE,DAT,I,X,D0
KILL ^TMP($JOB,LIST)
SET ^TMP($JOB,LIST,DFN,0)=0
+11 IF $GET(IEN)
DO PROCESS
GOTO CLEAN
+12 IF $GET(RX)]""
IF '$GET(IEN)
SET IEN=$ORDER(^PSRX("B",RX,0))
Begin DoDot:1
+13 IF 'IEN
SET ^TMP($JOB,LIST,DFN,0)="-1^NO DATA FOUND"
QUIT
+14 DO PROCESS
End DoDot:1
GOTO CLEAN
+15 DO DATE
CLEAN FOR I=0:0
SET I=$ORDER(^TMP($JOB,LIST,DFN,I))
IF 'I
QUIT
SET ^TMP($JOB,LIST,DFN,0)=^TMP($JOB,LIST,DFN,0)+1
+1 IF ^TMP($JOB,LIST,DFN,0)=0
SET ^TMP($JOB,LIST,DFN,0)="-1^NO DATA FOUND"
+2 KILL DA,DR,DIC,ND,DAT,PST,LK,DIQ,DTE,I,X
+3 QUIT
PROCESS ;
+1 IF DFN'=$PIECE($GET(^PSRX(IEN,0)),"^",2)
SET ^TMP($JOB,LIST,IEN,0)="-1^NO DATA FOUND (MISMATCHED PATIENT)"
QUIT
+2 IF $GET(^PSRX(IEN,0))']""
SET ^TMP($JOB,LIST,IEN,0)="-1^NO RX DATA FOUND"
QUIT
+3 IF $GET(NODE)']""
DO ZE
DO TW
DO TH
DO MI
DO ST
DO RF
DO CM
DO AT
DO LB
DO PT^PSO52B
DO SD^PSO52B
DO TB^PSO52B
DO OI^PSO52B
DO MLT^PSO52B
SET DAT="I"
DO IB
QUIT
+4 DO ST
FOR LK=1:1:$LENGTH(NODE,",")
SET DAT=$PIECE(NODE,",",LK)
SET ND=$PIECE(DAT,"^")
Begin DoDot:1
+5 IF ND=0
DO ZE
QUIT
+6 IF ND=2
DO ZE
DO TW
QUIT
+7 IF ND=3
DO TW
DO TH
QUIT
+8 IF ND="R"
DO RF
QUIT
+9 IF ND="I"
DO IB
QUIT
+10 IF ND="P"
DO PT^PSO52B
QUIT
+11 IF ND="O"
DO OI^PSO52B
QUIT
+12 IF ND="T"
DO TB^PSO52B
QUIT
+13 IF ND="L"
DO LB
QUIT
+14 IF ND="S"
DO SD^PSO52B
QUIT
+15 IF ND="M"
DO MI
QUIT
+16 IF ND="C"
DO CM
QUIT
+17 IF ND="A"
DO AT
QUIT
+18 IF ND="ST"
DO ST
QUIT
+19 IF ND="ICD"
DO MLT^PSO52B
QUIT
+20 SET ^TMP($JOB,LIST,DFN,IEN,"INVALID REQUEST",ND)="Invalid Data Requested"
End DoDot:1
+21 QUIT
ZE ;zero
+1 KILL PST
SET DIC=52
SET DA=IEN
SET DR=".01:9;10.3;10.6;11;16;17"
DO DIQ
+2 FOR DR=.01,1,2,3,4,5,6,6.5,7,8,9,10.3,10.6,11,16,17
Begin DoDot:1
+3 IF PST(52,DA,DR,"E")'=PST(52,DA,DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E")
QUIT
+4 SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")
End DoDot:1
+5 KILL DA,DR,PST,DIC,DIQ
+6 QUIT
TW ;two
+1 IF '$DATA(^PSRX(IEN,2))
QUIT
+2 KILL PST
SET DIC=52
SET DA=IEN
SET DR="20:31;32.1;32.2;32.3;104"
DO DIQ
+3 FOR DR=20,21,22,23,24,25,26,27,28,29,30,31,32.1,32.2,32.3,104
Begin DoDot:1
+4 IF PST(52,DA,DR,"E")'=PST(52,DA,DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E")
QUIT
+5 SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")
End DoDot:1
+6 KILL DA,DR,PST,DIC,DIQ
+7 QUIT
TH ;three
+1 IF '$DATA(^PSRX(IEN,3))
QUIT
+2 KILL PST
SET DIC=52
SET DA=IEN
SET DR="12;26.1;34.1;101;102;102.1;102.2;109;112"
DO DIQ
+3 FOR DR=12,26.1,34.1,101,102,102.1,102.2,109,112
Begin DoDot:1
+4 IF PST(52,DA,DR,"E")'=PST(52,DA,DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E")
QUIT
+5 SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")
End DoDot:1
+6 KILL DA,DR,PST,DIC,DIQ
+7 QUIT
MI ;sig
+1 IF $PIECE($GET(^PSRX(IEN,"SIG")),"^",2)
Begin DoDot:1
+2 IF '$ORDER(^PSRX(IEN,"SIG1",0))
SET ^TMP($JOB,LIST,DFN,IEN,"M",0)="-1^NO DATA FOUND"
QUIT
+3 FOR I=0:0
SET I=$ORDER(^PSRX(IEN,"SIG1",I))
IF 'I
QUIT
SET ^TMP($JOB,LIST,DFN,IEN,"M",I,0)=^PSRX(IEN,"SIG1",I,0)
SET ^TMP($JOB,LIST,DFN,IEN,"M",0)=$GET(^TMP($JOB,LIST,DFN,IEN,"M",0))+1
End DoDot:1
QUIT
+4 IF $PIECE($GET(^PSRX(IEN,"SIG")),"^")']""
SET ^TMP($JOB,LIST,DFN,IEN,"M",0)="-1^NO DATA FOUND"
QUIT
+5 SET X=$PIECE($GET(^PSRX(IEN,"SIG")),"^")
DO SIG^PSOHELP
SET ^TMP($JOB,LIST,DFN,IEN,"M",1,0)=$EXTRACT(INS1,2,9999999)
SET ^TMP($JOB,LIST,DFN,IEN,"M",0)=1
+6 KILL X,INS1
+7 QUIT
ST ;status
+1 IF DT>$PIECE(^PSRX(IEN,2),"^",6)
IF $PIECE(^PSRX(IEN,"STA"),"^")<11
Begin DoDot:1
+2 NEW PSOEXRX,PSOEXSTA,ORN,PIFN,PSUSD,PRFDT,PDA,PSST
+3 SET PSOEXRX=IEN
DO EN2^PSOMAUEX
KILL PSOEXRX,PSONM,PSONMX
End DoDot:1
+4 KILL PST
SET DIC=52
SET DA=IEN
SET DR=".01;100"
DO DIQ
+5 SET ^TMP($JOB,LIST,DFN,IEN,100)=PST(52,DA,100,"I")_"^"_PST(52,DA,100,"E")
+6 SET ^TMP($JOB,LIST,"B",PST(52,DA,.01,"E"),IEN)=""
+7 KILL DA,DR,PST,DIC,DIQ
+8 QUIT
RF ;refill
+1 IF '$ORDER(^PSRX(IEN,1,0))
SET ^TMP($JOB,LIST,DFN,IEN,"RF",0)="-1^NO DATA FOUND"
QUIT
+2 IF $PIECE($GET(DAT),"^",3)
SET DA(52.1)=$PIECE(DAT,"^",3)
DO RFD
KILL DA,DR,PST,DIC,DIQ
QUIT
+3 FOR RF=0:0
SET RF=$ORDER(^PSRX(IEN,1,RF))
IF 'RF
QUIT
SET DA(52.1)=RF
DO RFD
+4 KILL DA,DR,PST,DIC,DIQ,RF
+5 QUIT
RFD KILL PST
SET DR(52.1)=".01:8;10.1;12;13;14;15;17"
SET DIC=52
SET DA=IEN
SET DR=52
DO DIQ
+1 IF $PIECE($GET(DAT),"^",3)
IF '$GET(PST(52.1,DA(52.1),.01,"I"))
SET ^TMP($JOB,LIST,DFN,IEN,"RF",0)="-1^NO DATA FOUND"
QUIT
+2 SET ^TMP($JOB,LIST,DFN,IEN,"RF",0)=$GET(^TMP($JOB,LIST,DFN,IEN,"RF",0))+1
+3 FOR DR=.01,1,1.1,1.2,2,3,4,5,6,7,8,10.1,12,13,14,15,17
Begin DoDot:1
+4 IF PST(52.1,DA(52.1),DR,"E")'=PST(52.1,DA(52.1),DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,"RF",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")_"^"_PST(52.1,DA(52.1),DR,"E")
QUIT
+5 SET ^TMP($JOB,LIST,DFN,IEN,"RF",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")
End DoDot:1
+6 QUIT
IB ;ib ori
+1 IF $PIECE($GET(DAT),"^",2)="R"
DO IBR
QUIT
+2 IF $GET(^PSRX(IEN,"IB"))']""
SET ^TMP($JOB,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND"
QUIT
+3 KILL PST
SET DIC=52
SET DA=IEN
SET DR="105;106;106.5;106.6"
DO DIQ
+4 FOR DR=105,106,106.5,106.6
Begin DoDot:1
+5 IF PST(52,DA,DR,"E")'=PST(52,DA,DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"I")_"^"_PST(52,DA,DR,"E")
QUIT
+6 SET ^TMP($JOB,LIST,DFN,IEN,DR)=PST(52,DA,DR,"E")
End DoDot:1
+7 KILL DA,DR,PST,DIC,DIQ
+8 IF $PIECE($GET(DAT),"^",2)=""
DO IBR
QUIT
+9 QUIT
IBR ;ib ref
+1 IF '$ORDER(^PSRX(IEN,1,0))
SET ^TMP($JOB,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND"
QUIT
+2 IF $PIECE($GET(DAT),"^",2)="R"
IF $PIECE($GET(DAT),"^",3)
SET DA(52.1)=$PIECE(DAT,"^",3)
DO IBS
KILL DA,DR,PST,DIC,DIQ
QUIT
+3 NEW IB
FOR IB=0:0
SET IB=$ORDER(^PSRX(IEN,1,IB))
IF 'IB
QUIT
SET DA(52.1)=IB
DO IBS
+4 IF '$GET(^TMP($JOB,LIST,DFN,IEN,"IB",0))
KILL ^TMP($JOB,LIST,DFN,IEN,"IB")
SET ^TMP($JOB,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND"
+5 KILL DA,DR,PST,DIC,DIQ,IB
+6 QUIT
IBS IF $PIECE($GET(DAT),"^",3)
IF '$GET(^PSRX(IEN,1,DA(52.1),"IB"))
SET ^TMP($JOB,LIST,DFN,IEN,"IB",0)="-1^NO DATA FOUND"
QUIT
+1 IF '$DATA(^PSRX(IEN,1,DA(52.1),"IB"))
SET ^TMP($JOB,LIST,DFN,IEN,"IB",DA(52.1),0)="-1^NO DATA FOUND"
QUIT
+2 KILL PST
SET DR(52.1)="9;9.1"
SET DIC=52
SET DA=IEN
SET DR=52
DO DIQ
+3 SET ^TMP($JOB,LIST,DFN,IEN,"IB",0)=$GET(^TMP($JOB,LIST,DFN,IEN,"IB",0))+1
+4 FOR DR=9,9.1
Begin DoDot:1
+5 IF PST(52.1,DA(52.1),DR,"E")'=PST(52.1,DA(52.1),DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,"IB",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")_"^"_PST(52.1,DA(52.1),DR,"E")
QUIT
+6 SET ^TMP($JOB,LIST,DFN,IEN,"IB",DA(52.1),DR)=PST(52.1,DA(52.1),DR,"I")
End DoDot:1
+7 QUIT
CM ;cmop
+1 IF '$ORDER(^PSRX(IEN,4,0))
SET ^TMP($JOB,LIST,DFN,IEN,"C",0)="-1^NO DATA FOUND"
QUIT
+2 NEW CM
FOR CM=0:0
SET CM=$ORDER(^PSRX(IEN,4,CM))
IF 'CM
QUIT
SET DA(52.01)=CM
DO CMP
+3 KILL DA,DR,PST,DIC,DIQ,CM
+4 QUIT
CMP SET ^TMP($JOB,LIST,DFN,IEN,"C",0)=$GET(^TMP($JOB,LIST,DFN,IEN,"C",0))+1
+1 KILL PST
SET DR(52.01)="2;3;4"
SET DIC=52
SET DA=IEN
SET DR=400
DO DIQ
+2 FOR DR=2,3,4
Begin DoDot:1
+3 IF PST(52.01,DA(52.01),DR,"E")'=PST(52.01,DA(52.01),DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,"C",DA(52.01),DR)=PST(52.01,DA(52.01),DR,"I")_"^"_PST(52.01,DA(52.01),DR,"E")
QUIT
+4 SET ^TMP($JOB,LIST,DFN,IEN,"C",DA(52.01),DR)=PST(52.01,DA(52.01),DR,"I")
End DoDot:1
+5 QUIT
AT ;activity log
+1 IF '$ORDER(^PSRX(IEN,"A",0))
SET ^TMP($JOB,LIST,DFN,IEN,"A",0)="-1^NO DATA FOUND"
QUIT
+2 NEW AT
FOR AT=0:0
SET AT=$ORDER(^PSRX(IEN,"A",AT))
IF 'AT
QUIT
SET DA(52.3)=AT
DO ATP
+3 KILL DA,DR,PST,DIC,DIQ,AT
+4 QUIT
ATP KILL PST
SET DR(52.3)=".01;.02;.03;.04;.05"
SET DIC=52
SET DA=IEN
SET DR=40
DO DIQ
+1 SET ^TMP($JOB,LIST,DFN,IEN,"A",0)=$GET(^TMP($JOB,LIST,DFN,IEN,"A",0))+1
+2 FOR DR=.01,.02,.03,.04,.05
Begin DoDot:1
+3 IF DR=.04
SET ^TMP($JOB,LIST,DFN,IEN,"A",DA(52.3),DR)=PST(52.3,DA(52.3),DR,"E")
QUIT
+4 IF PST(52.3,DA(52.3),DR,"E")'=PST(52.3,DA(52.3),DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,"A",DA(52.3),DR)=PST(52.3,DA(52.3),DR,"I")_"^"_PST(52.3,DA(52.3),DR,"E")
QUIT
+5 SET ^TMP($JOB,LIST,DFN,IEN,"A",DA(52.3),DR)=PST(52.3,DA(52.3),DR,"I")
End DoDot:1
+6 QUIT
LB ;label log
+1 IF '$ORDER(^PSRX(IEN,"L",0))
SET ^TMP($JOB,LIST,DFN,IEN,"L",0)="-1^NO DATA FOUND"
QUIT
+2 NEW LB
FOR LB=0:0
SET LB=$ORDER(^PSRX(IEN,"L",LB))
IF 'LB
QUIT
SET DA(52.032)=LB
DO LBP
+3 KILL DA,DR,PST,DIC,DIQ,LB
+4 QUIT
LBP SET ^TMP($JOB,LIST,DFN,IEN,"L",0)=$GET(^TMP($JOB,LIST,DFN,IEN,"L",0))+1
+1 KILL PST
SET DR(52.032)=".01;1;2;3;4"
SET DIC=52
SET DA=IEN
SET DR=32
DO DIQ
+2 FOR DR=.01,1,2,3,4
Begin DoDot:1
+3 IF DR=1
SET ^TMP($JOB,LIST,DFN,IEN,"L",DA(52.032),DR)=PST(52.032,DA(52.032),DR,"E")
QUIT
+4 IF PST(52.032,DA(52.032),DR,"E")'=PST(52.032,DA(52.032),DR,"I")
SET ^TMP($JOB,LIST,DFN,IEN,"L",DA(52.032),DR)=PST(52.032,DA(52.032),DR,"I")_"^"_PST(52.032,DA(52.032),DR,"E")
QUIT
+5 SET ^TMP($JOB,LIST,DFN,IEN,"L",DA(52.032),DR)=PST(52.032,DA(52.032),DR,"I")
End DoDot:1
+6 KILL DA,DR,PST,DIC,DIQ
+7 QUIT
DATE ;date range
+1 IF $GET(SDATE)
SET DTE=SDATE-1
Begin DoDot:1
+2 IF $GET(EDATE)
Begin DoDot:2
+3 FOR
SET DTE=$ORDER(^PS(55,DFN,"P","A",DTE))
IF 'DTE!(DTE>EDATE)
QUIT
FOR IEN=0:0
SET IEN=$ORDER(^PS(55,DFN,"P","A",DTE,IEN))
IF 'IEN
QUIT
IF $PIECE($GET(^PSRX(IEN,"STA")),"^")'=13
DO PROCESS
End DoDot:2
QUIT
+4 FOR
SET DTE=$ORDER(^PS(55,DFN,"P","A",DTE))
IF 'DTE
QUIT
FOR IEN=0:0
SET IEN=$ORDER(^PS(55,DFN,"P","A",DTE,IEN))
IF 'IEN
QUIT
IF $PIECE($GET(^PSRX(IEN,"STA")),"^")'=13
DO PROCESS
End DoDot:1
QUIT
+5 IF $GET(EDATE)
IF '$GET(SDATE)
SET DTE=DT-1
Begin DoDot:1
+6 FOR
SET DTE=$ORDER(^PS(55,DFN,"P","A",DTE))
IF 'DTE!(DTE>EDATE)
QUIT
FOR IEN=0:0
SET IEN=$ORDER(^PS(55,DFN,"P","A",DTE,IEN))
IF 'IEN
QUIT
IF $PIECE($GET(^PSRX(IEN,"STA")),"^")'=13
DO PROCESS
End DoDot:1
QUIT
+7 SET DTE=DT-1
FOR
SET DTE=$ORDER(^PS(55,DFN,"P","A",DTE))
IF 'DTE
QUIT
FOR IEN=0:0
SET IEN=$ORDER(^PS(55,DFN,"P","A",DTE,IEN))
IF 'IEN
QUIT
IF $PIECE($GET(^PSRX(IEN,"STA")),"^")'=13
DO PROCESS
+8 QUIT
PROF(DFN,LIST,SDATE,EDATE) ;
+1 DO ^PSO52AP1
+2 QUIT
DIQ ;process fields
+1 SET DIQ="PST"
SET DIQ(0)="IE"
DO EN^DIQ1
+2 QUIT