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