[456] | 1 | unit rODMeds;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses SysUtils, Classes, ORNet, ORFn, uCore, uConst;
|
---|
| 6 |
|
---|
| 7 | function DEACheckFailed(AnOI: Integer; ForInpatient: Boolean): Boolean;
|
---|
| 8 | function DEACheckFailedForIVOnOutPatient(AnOI: Integer; AnOIType: Char): boolean;
|
---|
| 9 | procedure ListForOrderable(var AListIEN, ACount: Integer; const DGrpNm: string);
|
---|
| 10 | procedure SubsetOfOrderable(Dest: TStringList; Append: Boolean; ListIEN, First, Last: Integer);
|
---|
| 11 | function IndexOfOrderable(ListIEN: Integer; From: string): Integer;
|
---|
| 12 | procedure IsActivateOI(var AMsg: string; theOI: integer);
|
---|
| 13 | procedure ListForQuickOrders(var AListIEN, ACount: Integer; const DGrpNm: string);
|
---|
| 14 | procedure SubsetOfQuickOrders(Dest: TStringList; AListIEN, First, Last: Integer);
|
---|
| 15 | function IndexOfQuickOrder(AListIEN: Integer; From: string): Integer;
|
---|
| 16 | procedure LoadFormularyAltOI(AList: TStringList; AnIEN: Integer; ForInpatient: Boolean);
|
---|
| 17 | procedure LoadFormularyAltDose(AList: TStringList; DispDrug, OI: Integer; ForInpatient: Boolean);
|
---|
| 18 | procedure LoadAdminInfo(const Schedule: string; OrdItem: Integer; var StartText: string;
|
---|
| 19 | var AdminTime: TFMDateTime; var Duration: string);
|
---|
| 20 | function GetAdminTime(const StartText, Schedule: string; OrdItem: Integer): TFMDateTime;
|
---|
| 21 | procedure LoadSchedules(Dest: TStrings; IsInptDlg: boolean = False);
|
---|
| 22 | function QtyToDays(Quantity: Double; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
|
---|
| 23 | function DaysToQty(DaysSupply: Integer; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
|
---|
| 24 | function DurToQty(DaysSupply: Integer; const UnitStr, SchedStr: string): Integer;
|
---|
| 25 | function DefaultDays(const ADrug, UnitStr, SchedStr: string): Integer;
|
---|
| 26 | function CalcMaxRefills(const Drug: string; Days, OrdItem: Integer; Discharge: Boolean): Integer;
|
---|
| 27 | function ScheduleRequired(OrdItem: Integer; const ARoute, ADrug: string): Boolean;
|
---|
| 28 | function ODForMedsIn: TStrings;
|
---|
| 29 | function ODForMedsOut: TStrings;
|
---|
| 30 | function OIForMed(AnIEN: Integer; ForInpatient: Boolean; HavePI: boolean = True; PKIActive: Boolean = False): TStrings;
|
---|
| 31 | function GetPickupForLocation(const Loc: string): string;
|
---|
| 32 | function QOHasRouteDefined(AQOID: integer): boolean;
|
---|
| 33 | procedure CheckExistingPI(AOrderId: string; var APtI: string);
|
---|
| 34 |
|
---|
| 35 | implementation
|
---|
| 36 |
|
---|
| 37 | function DEACheckFailed(AnOI: Integer; ForInpatient: Boolean): Boolean;
|
---|
| 38 | var
|
---|
| 39 | PtType: Char;
|
---|
| 40 | begin
|
---|
| 41 | if ForInpatient then PtType := 'I' else PtType := 'O';
|
---|
| 42 | Result := sCallV('ORWDPS1 FAILDEA', [AnOI, Encounter.Provider, PtType]) = '1';
|
---|
| 43 | end;
|
---|
| 44 |
|
---|
| 45 | function DEACheckFailedForIVOnOutPatient(AnOI: Integer; AnOIType: Char): boolean;
|
---|
| 46 | begin
|
---|
| 47 | Result := sCallV('ORWDPS1 IVDEA',[AnOI,AnOIType,Encounter.Provider]) = '1';
|
---|
| 48 | end;
|
---|
| 49 |
|
---|
| 50 | procedure ListForOrderable(var AListIEN, ACount: Integer; const DGrpNm: string);
|
---|
| 51 | begin
|
---|
| 52 | CallV('ORWUL FV4DG', [DGrpNm]);
|
---|
| 53 | AListIEN := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 1), 0);
|
---|
| 54 | ACount := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0);
|
---|
| 55 | end;
|
---|
| 56 |
|
---|
| 57 | procedure SubsetOfOrderable(Dest: TStringList; Append: Boolean; ListIEN, First, Last: Integer);
|
---|
| 58 | var
|
---|
| 59 | i: Integer;
|
---|
| 60 | begin
|
---|
| 61 | CallV('ORWUL FVSUB', [ListIEN, First+1, Last+1]); // M side not 0-based
|
---|
| 62 | if Append then Dest.AddStrings(RPCBrokerV.Results) else
|
---|
| 63 | begin
|
---|
| 64 | for i := Pred(RPCBrokerV.Results.Count) downto 0 do Dest.Insert(0, RPCBrokerV.Results[i]);
|
---|
| 65 | end;
|
---|
| 66 | end;
|
---|
| 67 |
|
---|
| 68 | function IndexOfOrderable(ListIEN: Integer; From: string): Integer;
|
---|
| 69 | var
|
---|
| 70 | x: string;
|
---|
| 71 | begin
|
---|
| 72 | Result := -1;
|
---|
| 73 | if From = '' then Exit;
|
---|
| 74 | // decrement last char & concat '~' for $ORDER on M side, limit string length
|
---|
| 75 | x := UpperCase(Copy(From, 1, 220));
|
---|
| 76 | x := Copy(x, 1, Length(x) - 1) + Pred(x[Length(x)]) + '~';
|
---|
| 77 | x := sCallV('ORWUL FVIDX', [ListIEN, x]);
|
---|
| 78 | // use Pred to make the index 0-based (first value = 1 on M side)
|
---|
| 79 | if CompareText(Copy(Piece(x, U, 2), 1, Length(From)), From) = 0
|
---|
| 80 | then Result := Pred(StrToIntDef(Piece(x, U, 1), 0));
|
---|
| 81 | end;
|
---|
| 82 |
|
---|
| 83 | procedure IsActivateOI(var AMsg: string; theOI: integer);
|
---|
| 84 | begin
|
---|
| 85 | AMsg := SCallV('ORWDXA ISACTOI', [theOI]);
|
---|
| 86 | end;
|
---|
| 87 |
|
---|
| 88 | procedure ListForQuickOrders(var AListIEN, ACount: Integer; const DGrpNm: string);
|
---|
| 89 | begin
|
---|
| 90 | CallV('ORWUL QV4DG', [DGrpNm]);
|
---|
| 91 | AListIEN := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 1), 0);
|
---|
| 92 | ACount := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0);
|
---|
| 93 | end;
|
---|
| 94 |
|
---|
| 95 | procedure SubsetOfQuickOrders(Dest: TStringList; AListIEN, First, Last: Integer);
|
---|
| 96 | var
|
---|
| 97 | i: Integer;
|
---|
| 98 | begin
|
---|
| 99 | CallV('ORWUL QVSUB', [AListIEN,'','']);
|
---|
| 100 | for i := 0 to RPCBrokerV.Results.Count -1 do
|
---|
| 101 | Dest.Add(RPCBrokerV.Results[i]);
|
---|
| 102 | end;
|
---|
| 103 |
|
---|
| 104 | function IndexOfQuickOrder(AListIEN: Integer; From: string): Integer;
|
---|
| 105 | var
|
---|
| 106 | x: string;
|
---|
| 107 | begin
|
---|
| 108 | Result := -1;
|
---|
| 109 | if From = '' then Exit;
|
---|
| 110 | // decrement last char & concat '~' for $ORDER on M side, limit string length
|
---|
| 111 | x := UpperCase(Copy(From, 1, 220));
|
---|
| 112 | x := Copy(x, 1, Length(x) - 1) + Pred(x[Length(x)]) + '~';
|
---|
| 113 | x := sCallV('ORWUL QVIDX', [AListIEN, x]);
|
---|
| 114 | // use Pred to made the index 0-based (first value = 1 on M side)
|
---|
| 115 | if CompareText(Copy(Piece(x, U, 2), 1, Length(From)), From) = 0
|
---|
| 116 | then Result := Pred(StrToIntDef(Piece(x, U, 1), 0));
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 | procedure LoadFormularyAltOI(AList: TStringList; AnIEN: Integer; ForInpatient: Boolean);
|
---|
| 120 | var
|
---|
| 121 | PtType: Char;
|
---|
| 122 | begin
|
---|
| 123 | if ForInpatient then PtType := 'I' else PtType := 'O';
|
---|
| 124 | CallV('ORWDPS1 FORMALT', [AnIEN, PtType]);
|
---|
| 125 | AList.Assign(RPCBrokerV.Results);
|
---|
| 126 | end;
|
---|
| 127 |
|
---|
| 128 | procedure LoadFormularyAltDose(AList: TStringList; DispDrug, OI: Integer; ForInpatient: Boolean);
|
---|
| 129 | var
|
---|
| 130 | PtType: Char;
|
---|
| 131 | begin
|
---|
| 132 | if ForInpatient then PtType := 'I' else PtType := 'O';
|
---|
| 133 | CallV('ORWDPS1 DOSEALT', [DispDrug, OI, PtType]);
|
---|
| 134 | AList.Assign(RPCBrokerV.Results);
|
---|
| 135 | end;
|
---|
| 136 |
|
---|
| 137 | procedure LoadAdminInfo(const Schedule: string; OrdItem: Integer; var StartText: string;
|
---|
| 138 | var AdminTime: TFMDateTime; var Duration: string);
|
---|
| 139 | var
|
---|
| 140 | x: string;
|
---|
| 141 | begin
|
---|
| 142 | x := sCallV('ORWDPS2 ADMIN', [Patient.DFN, Schedule, OrdItem, Encounter.Location]);
|
---|
| 143 | StartText := Piece(x, U, 1);
|
---|
| 144 | AdminTime := MakeFMDateTime(Piece(x, U, 4));
|
---|
| 145 | Duration := Piece(x, U, 3);
|
---|
| 146 | end;
|
---|
| 147 |
|
---|
| 148 | function GetAdminTime(const StartText, Schedule: string; OrdItem: Integer): TFMDateTime;
|
---|
| 149 | var
|
---|
| 150 | x: string;
|
---|
| 151 | begin
|
---|
| 152 | x := sCallV('ORWDPS2 REQST', [Patient.DFN, Schedule, OrdItem, Encounter.Location, StartText]);
|
---|
| 153 | Result := MakeFMDateTime(x);
|
---|
| 154 | end;
|
---|
| 155 |
|
---|
| 156 | procedure LoadSchedules(Dest: TStrings; IsInptDlg: boolean);
|
---|
| 157 | begin
|
---|
| 158 | // if uMedSchedules = nil then CallV('ORWDPS ALLSCHD', [nil]); uMedSchedules.Assign(...);
|
---|
| 159 | CallV('ORWDPS1 SCHALL', [nil]);
|
---|
| 160 | Dest.Assign(RPCBrokerV.Results);
|
---|
| 161 | If (Dest.IndexOfName('OTHER') < 0) and IsInptDlg then
|
---|
| 162 | Dest.Add('OTHER');
|
---|
| 163 | end;
|
---|
| 164 |
|
---|
| 165 | function QtyToDays(Quantity: Double; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
|
---|
| 166 | begin
|
---|
| 167 | Result := StrToIntDef(sCallV('ORWDPS2 QTY2DAY',
|
---|
| 168 | [Quantity, UnitsPerDose, Schedule, Duration, Patient.DFN, Drug]), 0);
|
---|
| 169 | end;
|
---|
| 170 |
|
---|
| 171 | function DaysToQty(DaysSupply: Integer; const UnitsPerDose, Schedule, Duration, Drug: string): Integer;
|
---|
| 172 | begin
|
---|
| 173 | Result := StrToIntDef(sCallV('ORWDPS2 DAY2QTY',
|
---|
| 174 | [DaysSupply, UnitsPerDose, Schedule, Duration, Patient.DFN, Drug]), 0);
|
---|
| 175 | end;
|
---|
| 176 |
|
---|
| 177 | function DurToQty(DaysSupply: Integer; const UnitStr, SchedStr: string): Integer;
|
---|
| 178 | begin
|
---|
| 179 | Result := StrToIntDef(sCallV('ORWDPS2 DAY2QTY', [DaysSupply, UnitStr, SchedStr]), 0);
|
---|
| 180 | end;
|
---|
| 181 |
|
---|
| 182 | function DefaultDays(const ADrug, UnitStr, SchedStr: string): Integer;
|
---|
| 183 | begin
|
---|
| 184 | Result := StrToIntDef(sCallV('ORWDPS1 DFLTSPLY', [UnitStr, SchedStr, Patient.DFN, ADrug]), 0);
|
---|
| 185 | end;
|
---|
| 186 |
|
---|
| 187 | function CalcMaxRefills(const Drug: string; Days, OrdItem: Integer; Discharge: Boolean): Integer;
|
---|
| 188 | begin
|
---|
| 189 | Result := StrToIntDef(sCallV('ORWDPS2 MAXREF', [Patient.DFN, Drug, Days, OrdItem, Discharge]), 0);
|
---|
| 190 | end;
|
---|
| 191 |
|
---|
| 192 | function ScheduleRequired(OrdItem: Integer; const ARoute, ADrug: string): Boolean;
|
---|
| 193 | begin
|
---|
| 194 | Result := sCallV('ORWDPS2 SCHREQ', [OrdItem, ARoute, ADrug]) = '1';
|
---|
| 195 | end;
|
---|
| 196 |
|
---|
| 197 | function ODForMedsIn: TStrings;
|
---|
| 198 | { Returns init values for inpatient meds dialog. The results must be used immediately. }
|
---|
| 199 | begin
|
---|
| 200 | CallV('ORWDPS1 ODSLCT', [PST_UNIT_DOSE, Patient.DFN, Encounter.Location]);
|
---|
| 201 | Result := RPCBrokerV.Results;
|
---|
| 202 | end;
|
---|
| 203 |
|
---|
| 204 | function ODForMedsOut: TStrings;
|
---|
| 205 | { Returns init values for outpatient meds dialog. The results must be used immediately. }
|
---|
| 206 | begin
|
---|
| 207 | CallV('ORWDPS1 ODSLCT', [PST_OUTPATIENT, Patient.DFN, Encounter.Location]);
|
---|
| 208 | Result := RPCBrokerV.Results;
|
---|
| 209 | end;
|
---|
| 210 |
|
---|
| 211 | function OIForMed(AnIEN: Integer; ForInpatient: Boolean; HavePI: Boolean; PKIActive: Boolean): TStrings;
|
---|
| 212 | var
|
---|
| 213 | PtType: Char;
|
---|
| 214 | NeedPI: Char;
|
---|
| 215 | IsPKIActive: Char;
|
---|
| 216 | begin
|
---|
| 217 | if HavePI then NeedPI := 'Y' else NeedPI := 'N';
|
---|
| 218 | if ForInpatient then PtType := 'U' else PtType := 'O';
|
---|
| 219 | if PKIActive then IsPKIActive := 'Y' else IsPKIActive := 'N';
|
---|
| 220 | CallV('ORWDPS2 OISLCT', [AnIEN, PtType, Patient.DFN, NeedPI, IsPKIActive]);
|
---|
| 221 | Result := RPCBrokerV.Results;
|
---|
| 222 | end;
|
---|
| 223 |
|
---|
| 224 | function GetPickupForLocation(const Loc: string): string;
|
---|
| 225 | begin
|
---|
| 226 | Result := sCallV('ORWDPS1 LOCPICK',[Loc]);
|
---|
| 227 | end;
|
---|
| 228 |
|
---|
| 229 | function QOHasRouteDefined(AQOID: integer): boolean;
|
---|
| 230 | begin
|
---|
| 231 | Result := False;
|
---|
| 232 | if ( sCallV('ORWDPS1 HASROUTE',[AQOID])='1' ) then
|
---|
| 233 | Result := True;
|
---|
| 234 | end;
|
---|
| 235 |
|
---|
| 236 | procedure CheckExistingPI(AOrderId: string; var APtI: string);
|
---|
| 237 | begin
|
---|
| 238 | APtI := sCallV('ORWDPS2 CHKPI', [AOrderId]);
|
---|
| 239 | end;
|
---|
| 240 |
|
---|
| 241 | end.
|
---|