Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PSO52API

PSO52API.m

Go to the documentation of this file.
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