TIULMED ; SLC/JM,JH,AJB - Active/Recent Med Objects Routine ;Apr 11, 2024@10:22:13
;;1.0;TEXT INTEGRATION UTILITIES;**38,73,92,94,183,193,197,198,202,213,238,290,289,318**;Jun 20, 1997;Build 120
;
; Reference to *^XLFDT in ICR #10103
; Reference to ISCLORD^ORUTL in ICR #7357
; Reference to *^XPDUTL in ICR #10141
; Reference to PEN^PSO5241 in ICR #4821
; Reference to RX^PSO52API in ICR #4820
; Reference to OCL^PSOORRL in ICR #2400
; Reference to OCL^PSOQ0496 in ICR #5197
; Reference to DRGIEN^PSS50P7 in ICR #4662
; Reference to *^PSS55 in ICR #4826
; Reference to ^PS(53.1 in ICR #2907
;
Q
LIST(DFN,TARGET,ACTVONLY,DETAILED,ALLMEDS,ONELIST,CLASSORT,SUPPLIES) ;
; This is the TIU Medication objects API. Optional parameters not
; provided default to 0 (with the exception of SUPPLIES).
;Required Parameters:
; DFN Patient identifier
; TARGET Where the medication data will be stored
;Optional Parameters:
; ACTVONLY 0 - Active and recently expired meds
; 1 - Active meds only
; 2 - Recently expired meds only
; DETAILED 0 - One line per med only
; 1 - Detailed information on each med
; ALLMEDS 0 - Specifies Inpatient Meds if patient is an
; Inpatient, or Outpatient Meds if patient
; is an Outpatient
; 1 - Specifies Inpatient, Outpatient, & Clinic
; 2 or "I" - Specifies Inpatient only
; 3 or "O" - Specifies Outpatient only
; 4 or "C" - Specifies Clinic only
; 5 or "CI" or "IC" - Specifies Clinic and Inpatient Only
; 6 or "CO" or "OC" - Specifies Clinic and Outpatient Only
; ONELIST 0 - Separates Active, Pending and Inactive
; medications into separate lists
; 1 - Combines Active, Pending and Inactive
; medications into the same list
; CLASSORT 0 - Sort meds alphabetically
; 1 - Sort meds by drug class, and within the
; same drug class, sort alphabetically
; 2 - Same as #1, but show drug class in header
; SUPPLIES 0 - Supplies are excluded
; 1 - Supplies are included (Default)
N NEXTLINE,EMPTY,INDEX,NODE,ISINP,KEEPMED,STATUS,ASTATS,PSTATS,OK
N STATIDX,INPTYPE,OUTPTYPE,TYPE,MEDTYPE,MED,IDATE,XSTR,LLEN
N SPACE60,DASH73,LINE,TAB,HEADER
N DRUGCLAS,DRUGIDX,UNKNOWNS,CLINORD
N NVATYPE,NVAMED,NVASTR,TIUXSTAT
N %,%H,STOP,LSTFD ;Clean up after external calls...
S (NEXTLINE,TAB,HEADER,UNKNOWNS)=0,LLEN=47
S $P(SPACE60," ",60)=" ",$P(DASH73,"=",73)="="
K @TARGET,^TMP("PS",$J)
; Check for Pharmacy Package and required patches
I '$$PATCHSOK^TIULMED3 G LISTX ;P213
I '+$G(ACTVONLY) S ACTVONLY=0
I '+$G(DETAILED) S DETAILED=0
I +$D(ALLMEDS) D
.I ALLMEDS="I" S ALLMEDS=2
.E I ALLMEDS="O" S ALLMEDS=3
.E I ALLMEDS="C" S ALLMEDS=4 ; ajb 290
.E I ALLMEDS="CI"!(ALLMEDS="IC") S ALLMEDS=5 ; ajb 290
.E I ALLMEDS="CO"!(ALLMEDS="OC") S ALLMEDS=6 ; ajb 290
I '+$G(ALLMEDS) S ALLMEDS=0
I '+$G(ONELIST) S ONELIST=0
I '+$G(CLASSORT) S CLASSORT=0
I $G(SUPPLIES)'="0" S SUPPLIES=1
S (EMPTY,HEADER)=1
I ONELIST,'ALLMEDS,'DETAILED,'CLASSORT S HEADER=0
I 'DETAILED S LLEN=60
;COMMENTED OUT THE FOLLOWING LINE OF CODE IN FAVOUR OF THE NEXT LINE OF PAPI CODE
;S ASTATS="^ACTIVE^REFILL^HOLD^PROVIDER HOLD^ON CALL^ACTIVE (S)^"
S ASTATS="^ACTIVE^REFILL^HOLD^PROVIDER HOLD^ON CALL^ACTIVE (S)^ACTIVE/PARKED^"
S PSTATS="^NON-VERIFIED^DRUG INTERACTIONS^INCOMPLETE^PENDING^"
S ISINP=($G(^DPT(DFN,.1))'="") ; Is this an inpatient? IA 10035
I ISINP S INPTYPE=1,OUTPTYPE=2
E S INPTYPE=2,OUTPTYPE=1
S NVATYPE=3
D ADDTITLE^TIULMED1
;
; *** Scan medication data and skip unwanted meds ***
; Changes for *238 required by PSO*7*294
D
. I $$PATCH^XPDUTL("PSO*7.0*294"),+$D(TIUDATE) S TIUDATE=$$FMADD^XLFDT(DT,-$G(TIUDATE)) D OCL^PSOQ0496(DFN,TIUDATE,"") Q ; IA 2400
. D OCL^PSOORRL(DFN,"","") ; IA 2400
;
S INDEX=0
F S INDEX=$O(^TMP("PS",$J,INDEX)) Q:INDEX'>0 D
.S NODE=$G(^TMP("PS",$J,INDEX,0))
.S KEEPMED=($L($P(NODE,U,2))>0) ;Discard Blank Meds
.I KEEPMED D
..;ajb 290 check if clinic order
.. S CLINORD=0
.. D ISCLORD^ORUTL(.CLINORD,$P(NODE,U,8))
..;ajb 290
..S STATUS=$P(NODE,U,9)
..I STATUS="ACTIVE/SUSP" S STATUS="ACTIVE (S)"
..I $F(ASTATS,"^"_STATUS_"^")>0 S STATIDX=1
..E I ($F(PSTATS,"^"_STATUS_"^")>0) S STATIDX=2
..E S STATIDX=3
..S TIUXSTAT=STATUS
..I ACTVONLY=1 S KEEPMED=(STATIDX<3)
..I ACTVONLY=2 S KEEPMED=(STATIDX=3)
..I +ONELIST S STATIDX=1
..; Changes for *238 required by PSO*7*294
..I $$PATCH^XPDUTL("PSO*7.0*294"),+$D(TIUDATE),STATUS["DISCONTINUED" S KEEPMED=0
.I KEEPMED D
..S TYPE=$P($P(NODE,U),";",2)
..S TYPE=$S(TYPE="O":"OP",TYPE="I":"UD",1:"")
..S NVAMED=$P($P(NODE,U),";")
..S NVAMED=$E(NVAMED,$L(NVAMED))
..S KEEPMED=(TYPE'="")
.I KEEPMED D
..I $O(^TMP("PS",$J,INDEX,"A",0))>0 S TYPE="IV"
..E I $O(^TMP("PS",$J,INDEX,"B",0))>0 S TYPE="IV"
..I TYPE="OP" S MEDTYPE=OUTPTYPE
..E S MEDTYPE=INPTYPE
..I NVAMED="N" S MEDTYPE=NVATYPE
..I ALLMEDS=0 D I 1
...I MEDTYPE=INPTYPE S KEEPMED=ISINP
...E S KEEPMED='ISINP
...I +CLINORD S KEEPMED=0 ; ajb 290 check to see if clinic meds
..E I ALLMEDS=2 S KEEPMED=(MEDTYPE=INPTYPE) I +CLINORD S KEEPMED=0 ; inpatient only
..E I ALLMEDS=3 S KEEPMED=(MEDTYPE=OUTPTYPE!(MEDTYPE=NVATYPE)) I +CLINORD S KEEPMED=0 ; outpatient only
..E I ALLMEDS=4,'+CLINORD S KEEPMED=0 ; clinic only
..E I ALLMEDS=5 S KEEPMED=0 I +CLINORD!(MEDTYPE=INPTYPE) S KEEPMED=1 ; clinic & inpatient
..E I ALLMEDS=6 S KEEPMED=0 I +CLINORD!(MEDTYPE=OUTPTYPE) S KEEPMED=1 ; clinic & outpatient
.S DRUGCLAS=" "
.S MED=$P(NODE,U,2)
.I KEEPMED,(CLASSORT!('SUPPLIES)) D
..S DRUGIDX=$$IENNAME^TIULMED2(MED)
..D GETCLASS
.. ; If DRUGIDX="" (MED not in Drug File 50), get info
.. ; via Orderable Item instead.
..I KEEPMED,+DRUGIDX=0 D
...N IDX,ID,ORDIDX,TMPCLASS,CDONE,SDONE,TMPIDX,TMPNODE,ISSUPPLY
...S ID=$P(NODE,U),IDX=+ID,ID=$E(ID,$L(IDX)+1,$L(ID))
...S (DRUGIDX,ORDIDX)=0
...K ^TMP($J,"TIULMED")
...; IDX is Order #; ID indicates what file. See IA 2400
...; R;O MED will always be in Drug File (Unless Drug File entry was
...; changed after ordering.
...I ID="R;O" D ;R;O = prescription (file #52). P213
....D RX^PSO52API(DFN,"TIULMED",IDX,"","0,O") ; IA 4820
....S DRUGIDX=+$G(^TMP($J,"TIULMED",DFN,IDX,6))
....S ORDIDX=+$G(^TMP($J,"TIULMED",DFN,IDX,"OI"))
...;
...I ID="P;O" D ;P;O = pending outpatient order (file #52.41). P213
....D PEN^PSO5241(DFN,"TIULMED",IDX) ; IA 4821
....S DRUGIDX=+$G(^TMP($J,"TIULMED",DFN,IDX,11))
....S ORDIDX=+$G(^TMP($J,"TIULMED",DFN,IDX,8))
...;
...I ID="P;I" D ;P;I = pending inpatient order (file #53.1)
....I $P($G(^PS(53.1,IDX,1,0)),U,4)=1 D ; IA 2907
.....S TMPIDX=$O(^PS(53.1,IDX,1,0)) I +TMPIDX D
......S DRUGIDX=$P($G(^PS(53.1,IDX,1,TMPIDX,0)),U)
....S ORDIDX=+$P($G(^PS(53.1,IDX,.2)),U)
...;
...I ID="U;I" D ;U;I = unit dose order (file #55, subfile 55.06) P213
....D PSS431^PSS55(DFN,IDX,"","","TIULMED") ; IA 4826
....I +$G(^TMP($J,"TIULMED",IDX,"DDRUG",0))=1 D
.....S TMPIDX=$O(^TMP($J,"TIULMED",IDX,"DDRUG",0)) Q:TMPIDX'>0
.....S DRUGIDX=+$G(^TMP($J,"TIULMED",IDX,"DDRUG",TMPIDX,.01))
.....S ORDIDX=+$G(^TMP($J,"TIULMED",IDX,108))
...;
...I ID="V;I" D ;V;I = IV order (file #55, subfile 55.01). P213
....D PSS436^PSS55(DFN,IDX,"TIULMED") ; IA 4826
....; Get ORDIDX before DRUGIDX since global is not there after DRUGIDX
....S ORDIDX=+$G(^TMP($J,"TIULMED",IDX,130))
....I ^TMP($J,"TIULMED",IDX,"ADD",0)=1 D
.....S TMPIDX=$O(^TMP($J,"TIULMED",IDX,"ADD",0)) I +TMPIDX D
......S TMPIDX=+$G(^TMP($J,"TIULMED",IDX,"ADD",TMPIDX,.01))
......I +TMPIDX S DRUGIDX=$$DRGIEN^TIULMED2(TMPIDX) ; IA 4662
...;
...S DRUGCLAS=""
...D GETCLASS
...I KEEPMED,+DRUGIDX=0,+ORDIDX,DRUGCLAS="" D
....S IDX=0,ISSUPPLY=2,CDONE='CLASSORT,SDONE=+SUPPLIES
....N LIST S LIST="TIULMED" K ^TMP($J,LIST)
....D DRGIEN^PSS50P7(ORDIDX,"",LIST) ; IA 4662
....F S IDX=$O(^TMP($J,LIST,IDX)) Q:'IDX D Q:(CDONE&SDONE)
.....S TMPCLASS=$$DRGCLASS^TIULMED2(IDX)
.....S TMPNODE=U_TMPCLASS_U_$$DEA^TIULMED2(IDX)
.....I 'CDONE,TMPCLASS="" S CDONE=1,DRUGCLAS=""
.....I 'CDONE D
......I DRUGCLAS="" S DRUGCLAS=TMPCLASS
......E I DRUGCLAS'=TMPCLASS S CDONE=1,DRUGCLAS=""
.....I 'SDONE D
......S ISSUPPLY=(($E(TMPCLASS,1,2)="XA")&($P(TMPNODE,U,3)["S"))
......I 'ISSUPPLY S SDONE=1
....I 'SUPPLIES,(ISSUPPLY=1) S KEEPMED=0
..I (DRUGCLAS="")!('CLASSORT) S DRUGCLAS=" "
.;
.; *** Save wanted meds in "B" temp xref, removing duplicates ***
.;
.I KEEPMED D
..D ADDMED^TIULMED1(1) ; Get XSTR to check for duplicates
..;VMP OIFO BAY PINES;ELR;TIU*1.0*198;ADDED TIUXSTAT TO TMP GLOBAL
..S IDATE=$P(NODE,U,15)
..S OK='$D(@TARGET@("B",MED,XSTR,TIUXSTAT))
..I 'OK,(IDATE>@TARGET@("B",MED,XSTR,TIUXSTAT)) S OK=1
..I OK D
...S @TARGET@("B",MED,XSTR,TIUXSTAT)=IDATE_U_INDEX_U_MEDTYPE_STATIDX_U_TYPE_U_DRUGCLAS
...S EMPTY=0
...I DRUGCLAS=" " S UNKNOWNS=1
;
D SORTSAVE^TIULMED3 K @TARGET@("B"),@TARGET@("C") ;P213
LISTX K ^TMP("PS",$J),^TMP($J,"TIULMED"),TIUDATE ; K TIUDATE added for PSO*7*294
Q "~@"_$NA(@TARGET)
;
GETCLASS ;
D GETCLASS^TIULMED3
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HTIULMED 9335 printed Oct 16, 2024@18:42:52 Page 2
TIULMED ; SLC/JM,JH,AJB - Active/Recent Med Objects Routine ;Apr 11, 2024@10:22:13
+1 ;;1.0;TEXT INTEGRATION UTILITIES;**38,73,92,94,183,193,197,198,202,213,238,290,289,318**;Jun 20, 1997;Build 120
+2 ;
+3 ; Reference to *^XLFDT in ICR #10103
+4 ; Reference to ISCLORD^ORUTL in ICR #7357
+5 ; Reference to *^XPDUTL in ICR #10141
+6 ; Reference to PEN^PSO5241 in ICR #4821
+7 ; Reference to RX^PSO52API in ICR #4820
+8 ; Reference to OCL^PSOORRL in ICR #2400
+9 ; Reference to OCL^PSOQ0496 in ICR #5197
+10 ; Reference to DRGIEN^PSS50P7 in ICR #4662
+11 ; Reference to *^PSS55 in ICR #4826
+12 ; Reference to ^PS(53.1 in ICR #2907
+13 ;
+14 QUIT
LIST(DFN,TARGET,ACTVONLY,DETAILED,ALLMEDS,ONELIST,CLASSORT,SUPPLIES) ;
+1 ; This is the TIU Medication objects API. Optional parameters not
+2 ; provided default to 0 (with the exception of SUPPLIES).
+3 ;Required Parameters:
+4 ; DFN Patient identifier
+5 ; TARGET Where the medication data will be stored
+6 ;Optional Parameters:
+7 ; ACTVONLY 0 - Active and recently expired meds
+8 ; 1 - Active meds only
+9 ; 2 - Recently expired meds only
+10 ; DETAILED 0 - One line per med only
+11 ; 1 - Detailed information on each med
+12 ; ALLMEDS 0 - Specifies Inpatient Meds if patient is an
+13 ; Inpatient, or Outpatient Meds if patient
+14 ; is an Outpatient
+15 ; 1 - Specifies Inpatient, Outpatient, & Clinic
+16 ; 2 or "I" - Specifies Inpatient only
+17 ; 3 or "O" - Specifies Outpatient only
+18 ; 4 or "C" - Specifies Clinic only
+19 ; 5 or "CI" or "IC" - Specifies Clinic and Inpatient Only
+20 ; 6 or "CO" or "OC" - Specifies Clinic and Outpatient Only
+21 ; ONELIST 0 - Separates Active, Pending and Inactive
+22 ; medications into separate lists
+23 ; 1 - Combines Active, Pending and Inactive
+24 ; medications into the same list
+25 ; CLASSORT 0 - Sort meds alphabetically
+26 ; 1 - Sort meds by drug class, and within the
+27 ; same drug class, sort alphabetically
+28 ; 2 - Same as #1, but show drug class in header
+29 ; SUPPLIES 0 - Supplies are excluded
+30 ; 1 - Supplies are included (Default)
+31 NEW NEXTLINE,EMPTY,INDEX,NODE,ISINP,KEEPMED,STATUS,ASTATS,PSTATS,OK
+32 NEW STATIDX,INPTYPE,OUTPTYPE,TYPE,MEDTYPE,MED,IDATE,XSTR,LLEN
+33 NEW SPACE60,DASH73,LINE,TAB,HEADER
+34 NEW DRUGCLAS,DRUGIDX,UNKNOWNS,CLINORD
+35 NEW NVATYPE,NVAMED,NVASTR,TIUXSTAT
+36 ;Clean up after external calls...
NEW %,%H,STOP,LSTFD
+37 SET (NEXTLINE,TAB,HEADER,UNKNOWNS)=0
SET LLEN=47
+38 SET $PIECE(SPACE60," ",60)=" "
SET $PIECE(DASH73,"=",73)="="
+39 KILL @TARGET,^TMP("PS",$JOB)
+40 ; Check for Pharmacy Package and required patches
+41 ;P213
IF '$$PATCHSOK^TIULMED3
GOTO LISTX
+42 IF '+$GET(ACTVONLY)
SET ACTVONLY=0
+43 IF '+$GET(DETAILED)
SET DETAILED=0
+44 IF +$DATA(ALLMEDS)
Begin DoDot:1
+45 IF ALLMEDS="I"
SET ALLMEDS=2
+46 IF '$TEST
IF ALLMEDS="O"
SET ALLMEDS=3
+47 ; ajb 290
IF '$TEST
IF ALLMEDS="C"
SET ALLMEDS=4
+48 ; ajb 290
IF '$TEST
IF ALLMEDS="CI"!(ALLMEDS="IC")
SET ALLMEDS=5
+49 ; ajb 290
IF '$TEST
IF ALLMEDS="CO"!(ALLMEDS="OC")
SET ALLMEDS=6
End DoDot:1
+50 IF '+$GET(ALLMEDS)
SET ALLMEDS=0
+51 IF '+$GET(ONELIST)
SET ONELIST=0
+52 IF '+$GET(CLASSORT)
SET CLASSORT=0
+53 IF $GET(SUPPLIES)'="0"
SET SUPPLIES=1
+54 SET (EMPTY,HEADER)=1
+55 IF ONELIST
IF 'ALLMEDS
IF 'DETAILED
IF 'CLASSORT
SET HEADER=0
+56 IF 'DETAILED
SET LLEN=60
+57 ;COMMENTED OUT THE FOLLOWING LINE OF CODE IN FAVOUR OF THE NEXT LINE OF PAPI CODE
+58 ;S ASTATS="^ACTIVE^REFILL^HOLD^PROVIDER HOLD^ON CALL^ACTIVE (S)^"
+59 SET ASTATS="^ACTIVE^REFILL^HOLD^PROVIDER HOLD^ON CALL^ACTIVE (S)^ACTIVE/PARKED^"
+60 SET PSTATS="^NON-VERIFIED^DRUG INTERACTIONS^INCOMPLETE^PENDING^"
+61 ; Is this an inpatient? IA 10035
SET ISINP=($GET(^DPT(DFN,.1))'="")
+62 IF ISINP
SET INPTYPE=1
SET OUTPTYPE=2
+63 IF '$TEST
SET INPTYPE=2
SET OUTPTYPE=1
+64 SET NVATYPE=3
+65 DO ADDTITLE^TIULMED1
+66 ;
+67 ; *** Scan medication data and skip unwanted meds ***
+68 ; Changes for *238 required by PSO*7*294
+69 Begin DoDot:1
+70 ; IA 2400
IF $$PATCH^XPDUTL("PSO*7.0*294")
IF +$DATA(TIUDATE)
SET TIUDATE=$$FMADD^XLFDT(DT,-$GET(TIUDATE))
DO OCL^PSOQ0496(DFN,TIUDATE,"")
QUIT
+71 ; IA 2400
DO OCL^PSOORRL(DFN,"","")
End DoDot:1
+72 ;
+73 SET INDEX=0
+74 FOR
SET INDEX=$ORDER(^TMP("PS",$JOB,INDEX))
if INDEX'>0
QUIT
Begin DoDot:1
+75 SET NODE=$GET(^TMP("PS",$JOB,INDEX,0))
+76 ;Discard Blank Meds
SET KEEPMED=($LENGTH($PIECE(NODE,U,2))>0)
+77 IF KEEPMED
Begin DoDot:2
+78 ;ajb 290 check if clinic order
+79 SET CLINORD=0
+80 DO ISCLORD^ORUTL(.CLINORD,$PIECE(NODE,U,8))
+81 ;ajb 290
+82 SET STATUS=$PIECE(NODE,U,9)
+83 IF STATUS="ACTIVE/SUSP"
SET STATUS="ACTIVE (S)"
+84 IF $FIND(ASTATS,"^"_STATUS_"^")>0
SET STATIDX=1
+85 IF '$TEST
IF ($FIND(PSTATS,"^"_STATUS_"^")>0)
SET STATIDX=2
+86 IF '$TEST
SET STATIDX=3
+87 SET TIUXSTAT=STATUS
+88 IF ACTVONLY=1
SET KEEPMED=(STATIDX<3)
+89 IF ACTVONLY=2
SET KEEPMED=(STATIDX=3)
+90 IF +ONELIST
SET STATIDX=1
+91 ; Changes for *238 required by PSO*7*294
+92 IF $$PATCH^XPDUTL("PSO*7.0*294")
IF +$DATA(TIUDATE)
IF STATUS["DISCONTINUED"
SET KEEPMED=0
End DoDot:2
+93 IF KEEPMED
Begin DoDot:2
+94 SET TYPE=$PIECE($PIECE(NODE,U),";",2)
+95 SET TYPE=$SELECT(TYPE="O":"OP",TYPE="I":"UD",1:"")
+96 SET NVAMED=$PIECE($PIECE(NODE,U),";")
+97 SET NVAMED=$EXTRACT(NVAMED,$LENGTH(NVAMED))
+98 SET KEEPMED=(TYPE'="")
End DoDot:2
+99 IF KEEPMED
Begin DoDot:2
+100 IF $ORDER(^TMP("PS",$JOB,INDEX,"A",0))>0
SET TYPE="IV"
+101 IF '$TEST
IF $ORDER(^TMP("PS",$JOB,INDEX,"B",0))>0
SET TYPE="IV"
+102 IF TYPE="OP"
SET MEDTYPE=OUTPTYPE
+103 IF '$TEST
SET MEDTYPE=INPTYPE
+104 IF NVAMED="N"
SET MEDTYPE=NVATYPE
+105 IF ALLMEDS=0
Begin DoDot:3
+106 IF MEDTYPE=INPTYPE
SET KEEPMED=ISINP
+107 IF '$TEST
SET KEEPMED='ISINP
+108 ; ajb 290 check to see if clinic meds
IF +CLINORD
SET KEEPMED=0
End DoDot:3
IF 1
+109 ; inpatient only
IF '$TEST
IF ALLMEDS=2
SET KEEPMED=(MEDTYPE=INPTYPE)
IF +CLINORD
SET KEEPMED=0
+110 ; outpatient only
IF '$TEST
IF ALLMEDS=3
SET KEEPMED=(MEDTYPE=OUTPTYPE!(MEDTYPE=NVATYPE))
IF +CLINORD
SET KEEPMED=0
+111 ; clinic only
IF '$TEST
IF ALLMEDS=4
IF '+CLINORD
SET KEEPMED=0
+112 ; clinic & inpatient
IF '$TEST
IF ALLMEDS=5
SET KEEPMED=0
IF +CLINORD!(MEDTYPE=INPTYPE)
SET KEEPMED=1
+113 ; clinic & outpatient
IF '$TEST
IF ALLMEDS=6
SET KEEPMED=0
IF +CLINORD!(MEDTYPE=OUTPTYPE)
SET KEEPMED=1
End DoDot:2
+114 SET DRUGCLAS=" "
+115 SET MED=$PIECE(NODE,U,2)
+116 IF KEEPMED
IF (CLASSORT!('SUPPLIES))
Begin DoDot:2
+117 SET DRUGIDX=$$IENNAME^TIULMED2(MED)
+118 DO GETCLASS
+119 ; If DRUGIDX="" (MED not in Drug File 50), get info
+120 ; via Orderable Item instead.
+121 IF KEEPMED
IF +DRUGIDX=0
Begin DoDot:3
+122 NEW IDX,ID,ORDIDX,TMPCLASS,CDONE,SDONE,TMPIDX,TMPNODE,ISSUPPLY
+123 SET ID=$PIECE(NODE,U)
SET IDX=+ID
SET ID=$EXTRACT(ID,$LENGTH(IDX)+1,$LENGTH(ID))
+124 SET (DRUGIDX,ORDIDX)=0
+125 KILL ^TMP($JOB,"TIULMED")
+126 ; IDX is Order #; ID indicates what file. See IA 2400
+127 ; R;O MED will always be in Drug File (Unless Drug File entry was
+128 ; changed after ordering.
+129 ;R;O = prescription (file #52). P213
IF ID="R;O"
Begin DoDot:4
+130 ; IA 4820
DO RX^PSO52API(DFN,"TIULMED",IDX,"","0,O")
+131 SET DRUGIDX=+$GET(^TMP($JOB,"TIULMED",DFN,IDX,6))
+132 SET ORDIDX=+$GET(^TMP($JOB,"TIULMED",DFN,IDX,"OI"))
End DoDot:4
+133 ;
+134 ;P;O = pending outpatient order (file #52.41). P213
IF ID="P;O"
Begin DoDot:4
+135 ; IA 4821
DO PEN^PSO5241(DFN,"TIULMED",IDX)
+136 SET DRUGIDX=+$GET(^TMP($JOB,"TIULMED",DFN,IDX,11))
+137 SET ORDIDX=+$GET(^TMP($JOB,"TIULMED",DFN,IDX,8))
End DoDot:4
+138 ;
+139 ;P;I = pending inpatient order (file #53.1)
IF ID="P;I"
Begin DoDot:4
+140 ; IA 2907
IF $PIECE($GET(^PS(53.1,IDX,1,0)),U,4)=1
Begin DoDot:5
+141 SET TMPIDX=$ORDER(^PS(53.1,IDX,1,0))
IF +TMPIDX
Begin DoDot:6
+142 SET DRUGIDX=$PIECE($GET(^PS(53.1,IDX,1,TMPIDX,0)),U)
End DoDot:6
End DoDot:5
+143 SET ORDIDX=+$PIECE($GET(^PS(53.1,IDX,.2)),U)
End DoDot:4
+144 ;
+145 ;U;I = unit dose order (file #55, subfile 55.06) P213
IF ID="U;I"
Begin DoDot:4
+146 ; IA 4826
DO PSS431^PSS55(DFN,IDX,"","","TIULMED")
+147 IF +$GET(^TMP($JOB,"TIULMED",IDX,"DDRUG",0))=1
Begin DoDot:5
+148 SET TMPIDX=$ORDER(^TMP($JOB,"TIULMED",IDX,"DDRUG",0))
if TMPIDX'>0
QUIT
+149 SET DRUGIDX=+$GET(^TMP($JOB,"TIULMED",IDX,"DDRUG",TMPIDX,.01))
+150 SET ORDIDX=+$GET(^TMP($JOB,"TIULMED",IDX,108))
End DoDot:5
End DoDot:4
+151 ;
+152 ;V;I = IV order (file #55, subfile 55.01). P213
IF ID="V;I"
Begin DoDot:4
+153 ; IA 4826
DO PSS436^PSS55(DFN,IDX,"TIULMED")
+154 ; Get ORDIDX before DRUGIDX since global is not there after DRUGIDX
+155 SET ORDIDX=+$GET(^TMP($JOB,"TIULMED",IDX,130))
+156 IF ^TMP($JOB,"TIULMED",IDX,"ADD",0)=1
Begin DoDot:5
+157 SET TMPIDX=$ORDER(^TMP($JOB,"TIULMED",IDX,"ADD",0))
IF +TMPIDX
Begin DoDot:6
+158 SET TMPIDX=+$GET(^TMP($JOB,"TIULMED",IDX,"ADD",TMPIDX,.01))
+159 ; IA 4662
IF +TMPIDX
SET DRUGIDX=$$DRGIEN^TIULMED2(TMPIDX)
End DoDot:6
End DoDot:5
End DoDot:4
+160 ;
+161 SET DRUGCLAS=""
+162 DO GETCLASS
+163 IF KEEPMED
IF +DRUGIDX=0
IF +ORDIDX
IF DRUGCLAS=""
Begin DoDot:4
+164 SET IDX=0
SET ISSUPPLY=2
SET CDONE='CLASSORT
SET SDONE=+SUPPLIES
+165 NEW LIST
SET LIST="TIULMED"
KILL ^TMP($JOB,LIST)
+166 ; IA 4662
DO DRGIEN^PSS50P7(ORDIDX,"",LIST)
+167 FOR
SET IDX=$ORDER(^TMP($JOB,LIST,IDX))
if 'IDX
QUIT
Begin DoDot:5
+168 SET TMPCLASS=$$DRGCLASS^TIULMED2(IDX)
+169 SET TMPNODE=U_TMPCLASS_U_$$DEA^TIULMED2(IDX)
+170 IF 'CDONE
IF TMPCLASS=""
SET CDONE=1
SET DRUGCLAS=""
+171 IF 'CDONE
Begin DoDot:6
+172 IF DRUGCLAS=""
SET DRUGCLAS=TMPCLASS
+173 IF '$TEST
IF DRUGCLAS'=TMPCLASS
SET CDONE=1
SET DRUGCLAS=""
End DoDot:6
+174 IF 'SDONE
Begin DoDot:6
+175 SET ISSUPPLY=(($EXTRACT(TMPCLASS,1,2)="XA")&($PIECE(TMPNODE,U,3)["S"))
+176 IF 'ISSUPPLY
SET SDONE=1
End DoDot:6
End DoDot:5
if (CDONE&SDONE)
QUIT
+177 IF 'SUPPLIES
IF (ISSUPPLY=1)
SET KEEPMED=0
End DoDot:4
End DoDot:3
+178 IF (DRUGCLAS="")!('CLASSORT)
SET DRUGCLAS=" "
End DoDot:2
+179 ;
+180 ; *** Save wanted meds in "B" temp xref, removing duplicates ***
+181 ;
+182 IF KEEPMED
Begin DoDot:2
+183 ; Get XSTR to check for duplicates
DO ADDMED^TIULMED1(1)
+184 ;VMP OIFO BAY PINES;ELR;TIU*1.0*198;ADDED TIUXSTAT TO TMP GLOBAL
+185 SET IDATE=$PIECE(NODE,U,15)
+186 SET OK='$DATA(@TARGET@("B",MED,XSTR,TIUXSTAT))
+187 IF 'OK
IF (IDATE>@TARGET@("B",MED,XSTR,TIUXSTAT))
SET OK=1
+188 IF OK
Begin DoDot:3
+189 SET @TARGET@("B",MED,XSTR,TIUXSTAT)=IDATE_U_INDEX_U_MEDTYPE_STATIDX_U_TYPE_U_DRUGCLAS
+190 SET EMPTY=0
+191 IF DRUGCLAS=" "
SET UNKNOWNS=1
End DoDot:3
End DoDot:2
End DoDot:1
+192 ;
+193 ;P213
DO SORTSAVE^TIULMED3
KILL @TARGET@("B"),@TARGET@("C")
LISTX ; K TIUDATE added for PSO*7*294
KILL ^TMP("PS",$JOB),^TMP($JOB,"TIULMED"),TIUDATE
+1 QUIT "~@"_$NAME(@TARGET)
+2 ;
GETCLASS ;
+1 DO GETCLASS^TIULMED3
+2 QUIT