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