source: cprs/trunk/CPRS-Chart/Orders/fODMedIn.pas@ 701

Last change on this file since 701 was 456, checked in by Kevin Toppenberg, 16 years ago

Initial Upload of Official WV CPRS 1.0.26.76

File size: 12.2 KB
Line 
1unit fODMedIn;
2
3{$OPTIMIZATION OFF}
4
5interface
6
7uses
8 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
9 fODBase, ORCtrls, StdCtrls, ORFn, ExtCtrls, uConst, ComCtrls, uCore,
10 Menus;
11
12type
13 TfrmODMedIn = class(TfrmODBase)
14 lblMedication: TLabel;
15 cboMedication: TORComboBox;
16 lblDosage: TLabel;
17 lblRoute: TLabel;
18 cboRoute: TORComboBox;
19 lblSchedule: TLabel;
20 cboSchedule: TORComboBox;
21 Label5: TLabel;
22 cboDispense: TORComboBox;
23 lblComments: TLabel;
24 memComments: TMemo;
25 lblPriority: TLabel;
26 cboPriority: TORComboBox;
27 txtDosage: TCaptionEdit;
28 Bevel1: TBevel;
29 cboMedAlt: TORComboBox;
30 procedure cboMedicationNeedData(Sender: TObject; const StartFrom: string;
31 Direction, InsertAt: Integer);
32 procedure cboMedicationSelect(Sender: TObject);
33 procedure FormCreate(Sender: TObject);
34 procedure ControlChange(Sender: TObject);
35 procedure cboDispenseExit(Sender: TObject);
36 procedure cboDispenseMouseClick(Sender: TObject);
37 private
38 { Private declarations }
39 FLastDrug: Integer;
40 FLastMedID: string;
41 FDispenseMsg: string;
42 FMedCombo: TORComboBox;
43 procedure CheckFormAlt;
44 procedure ResetOnMedChange;
45 procedure SetAltCombo;
46 procedure SetOnOISelect;
47 protected
48 procedure InitDialog; override;
49 procedure Validate(var AnErrMsg: string); override;
50 public
51 procedure SetupDialog(OrderAction: Integer; const ID: string); override;
52 end;
53
54implementation
55
56{$R *.DFM}
57
58uses rOrders, rODBase, fODMedFA;
59
60const
61 TX_NO_MED = 'Medication must be entered.';
62 TX_NO_DOSE = 'Dosage must be entered.';
63 TX_NO_AMPER = 'Dosage may not contain the ampersand (&) character.';
64 TX_NO_ROUTE = 'Route must be entered.';
65 TX_NF_ROUTE = 'Route not found in the Medication Routes file.';
66 TX_NO_SCHED = 'Schedule must be entered.';
67 TX_DOSE_AMT = 'Dosage must be the amount given, not simply the number of units.';
68 TX_SCH_QUOTE = 'Schedule must not have quotemarks in it.';
69 TX_SCH_MINUS = 'Schedule must not have a dash at the beginning.';
70 TX_SCH_SPACE = 'Schedule must have only one space in it.';
71 TX_SCH_LEN = 'Schedule must be less than 70 characters.';
72 TX_SCH_PRN = 'Schedule cannot include PRN - use Comments to enter PRN.';
73 TX_SCH_ZERO = 'Schedule cannot be Q0.';
74 TX_SCH_LSP = 'Schedule may not have leading spaces.';
75 TX_SCH_NS = 'Unable to resolve non-standard schedule.';
76 TX_OUTPT_IV = 'This patient has not been admitted. Only IV orders may be entered.';
77
78{ TfrmODBase common methods }
79
80procedure TfrmODMedIn.FormCreate(Sender: TObject);
81const
82 TC_RESTRICT = 'Ordering Restrictions';
83var
84 Restriction: string;
85begin
86 inherited;
87 AllowQuickOrder := True;
88 CheckAuthForMeds(Restriction);
89 if Length(Restriction) > 0 then
90 begin
91 InfoBox(Restriction, TC_RESTRICT, MB_OK);
92 Close;
93 Exit;
94 end;
95 FillerID := 'PSI'; // does 'on Display' order check **KCM**
96 StatusText('Loading Dialog Definition');
97 Responses.Dialog := 'PSJ OR PAT OE'; // loads formatting info
98 StatusText('Loading Default Values');
99 CtrlInits.LoadDefaults(ODForMedIn); // ODForMedIn returns TStrings with defaults
100 InitDialog;
101end;
102
103procedure TfrmODMedIn.InitDialog;
104begin
105 inherited;
106 FLastDrug := 0;
107 FLastMedID := '';
108 FDispenseMsg := '';
109 FMedCombo := cboMedication; // this must be before SetControl(cboMedication)
110 with CtrlInits do
111 begin
112 SetControl(cboMedication, 'ShortList');
113 cboMedication.InsertSeparator;
114 //SetControl(cboMedAlt, 'ShortList'); can't do this since it calls InitLongList
115 SetControl(cboSchedule, 'Schedules');
116 SetControl(cboPriority, 'Priorities');
117 end;
118 StatusText('Initializing Long List');
119 cboMedAlt.Visible := False;
120 cboMedication.Visible := True;
121 cboMedication.InitLongList('');
122 ActiveControl := cboMedication; //SetFocusedControl(FMedCombo);
123 StatusText('');
124end;
125
126procedure TfrmODMedIn.SetupDialog(OrderAction: Integer; const ID: string);
127begin
128 inherited;
129 if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses do
130 begin
131 Changing := True; //v12a
132 SetControl(cboMedication, 'ORDERABLE', 1);
133 ResetOnMedChange; //v12a
134 SetOnOISelect; //v12a
135 SetAltCombo; //v12a
136 //cboMedicationSelect(Self);
137 SetControl(cboDispense, 'DRUG', 1);
138 SetControl(txtDosage, 'INSTR', 1);
139 SetControl(cboRoute, 'ROUTE', 1);
140 SetControl(cboSchedule, 'SCHEDULE', 1);
141 SetControl(memComments, 'COMMENT', 1);
142 SetControl(cboPriority, 'URGENCY', 1);
143 { can't edit the orderable item for a med order that has been released }
144 if (OrderAction = ORDER_EDIT) and OrderIsReleased(EditOrder)
145 then FMedCombo.Enabled := False;
146 Changing := False; //v12a
147 ControlChange(Self); //v12a
148 end;
149 if OrderAction <> ORDER_EDIT then SetFocusedControl(FMedCombo);
150end;
151
152procedure TfrmODMedIn.Validate(var AnErrMsg: string);
153var
154 Sched: Integer;
155 RouteID, RouteAbbr: string;
156
157
158 procedure SetError(const x: string);
159 begin
160 if Length(AnErrMsg) > 0 then AnErrMsg := AnErrMsg + CRLF;
161 AnErrMsg := AnErrMsg + x;
162 end;
163
164begin
165 inherited;
166 if Length(cboMedAlt.Text) = 0 then SetError(TX_NO_MED);
167 if Length(txtDosage.Text) = 0 then SetError(TX_NO_DOSE);
168 if Pos('&', txtDosage.Text) > 0 then SetError(TX_NO_AMPER);
169 if Length(cboRoute.Text) = 0 then SetError(TX_NO_ROUTE);
170 if (Length(cboRoute.Text) > 0) and (cboRoute.ItemIndex < 0) then
171 begin
172 LookupRoute(cboRoute.Text, RouteID, RouteAbbr);
173 if RouteID = '0'
174 then SetError(TX_NF_ROUTE)
175 else Responses.Update('ROUTE', 1, RouteID, RouteAbbr);
176 end;
177 if Length(cboSchedule.Text) = 0 then SetError(TX_NO_SCHED);
178 with cboSchedule do if Length(Text) > 0 then
179 begin
180 Sched := ValidSchedule(Text);
181 if Sched = -1 then
182 begin
183 if Pos('"', Text) > 0 then SetError(TX_SCH_QUOTE);
184 if Copy(Text, 1, 1) = '-' then SetError(TX_SCH_MINUS);
185 if Pos(' ', Copy(Text, Pos(' ', Text) + 1, 999)) > 0 then SetError(TX_SCH_SPACE);
186 if Length(Text) > 70 then SetError(TX_SCH_LEN);
187 if (Pos('P RN', Text) > 0) or (Pos('PR N', Text) > 0) then SetError(TX_SCH_PRN);
188 if Pos('Q0', Text) > 0 then SetError(TX_SCH_ZERO);
189 if TrimLeft(Text) <> Text then SetError(TX_SCH_LSP);
190 end;
191 if Sched = 0 then SetError(TX_SCH_NS);
192 end;
193 if (Length(txtDosage.Text) > 0) and (not ContainsAlpha(txtDosage.Text))
194 then SetError(TX_DOSE_AMT);
195 if (not OrderForInpatient) and (not MedTypeIsIV(cboMedAlt.ItemIEN))
196 then SetError(TX_OUTPT_IV);
197end;
198
199{ cboMedication methods }
200
201procedure TfrmODMedIn.ResetOnMedChange;
202begin
203 ClearControl(cboDispense);
204 ClearControl(txtDosage);
205 ClearControl(cboRoute); // routes should be cached
206 ResetControl(cboSchedule);
207 ClearControl(memComments);
208 ClearControl(memOrder);
209end;
210
211procedure TfrmODMedIn.SetAltCombo;
212begin
213 with cboMedication do
214 begin
215 FMedCombo := cboMedAlt;
216 if cboMedAlt.Items.Count = 0 then
217 begin
218 CtrlInits.SetListOnly(cboMedAlt, 'ShortList');
219 cboMedAlt.InsertSeparator;
220 end;
221 cboMedAlt.SetExactByIEN(ItemIEN, TrimRight(Piece(Text, '<', 1)));
222 cboMedication.Visible := False;
223 cboMedAlt.Visible := True;
224 end;
225end;
226
227procedure TfrmODMedIn.SetOnOISelect;
228begin
229 with CtrlInits do
230 begin
231 FLastMedID := FMedCombo.ItemID;
232 LoadOrderItem(OIForMedIn(FMedCombo.ItemIEN));
233 SetControl(cboDispense, 'Dispense');
234 if cboDispense.Items.Count = 1 then cboDispense.ItemIndex := 0;
235 SetControl(txtDosage, 'Instruct');
236 SetControl(cboRoute, 'Route');
237 if cboRoute.Items.Count = 1 then cboRoute.ItemIndex := 0;
238 //cboRoute.InsertSeparator;
239 //AppendMedRoutes(cboRoute.Items);
240 if DefaultText('DefSched') <> '' then cboSchedule.SelectByID(DefaultText('DefSched'));
241 OrderMessage(TextOf('Message'));
242 end;
243end;
244
245procedure TfrmODMedIn.cboMedicationNeedData(Sender: TObject; const StartFrom: string;
246 Direction, InsertAt: Integer);
247{ retrieves a subset of inpatient medication orderable items }
248begin
249 inherited;
250 FMedCombo.ForDataUse(SubSetOfOrderItems(StartFrom, Direction, 'S.UD RX'));
251end;
252
253procedure TfrmODMedIn.cboMedicationSelect(Sender: TObject);
254{ sets related controls whenever orderable item changes (MouseClick or Exit) }
255begin
256 inherited;
257 with FMedCombo do
258 begin
259 if ItemID <> FLastMedID then FLastMedID := ItemID else Exit;
260 Changing := True;
261 if Sender <> Self then Responses.Clear; // Sender=Self when called from SetupDialog
262 ResetOnMedChange;
263 if CharAt(ItemID, 1) = 'Q' then
264 begin
265 Responses.QuickOrder := ExtractInteger(ItemID);
266 Responses.SetControl(FMedCombo, 'ORDERABLE', 1);
267 end;
268 if ItemIEN > 0 then SetOnOISelect;
269 end;
270 with Responses do if QuickOrder > 0 then
271 begin
272 SetControl(FMedCombo, 'ORDERABLE', 1);
273 SetControl(cboDispense, 'DRUG', 1);
274 SetControl(txtDosage, 'INSTR', 1);
275 SetControl(cboRoute, 'ROUTE', 1);
276 SetControl(cboSchedule, 'SCHEDULE', 1);
277 SetControl(memComments, 'COMMENT', 1);
278 SetControl(cboPriority, 'URGENCY', 1);
279 end;
280 Changing := False;
281 ControlChange(Self);
282 if FMedCombo = cboMedication then SetAltCombo;
283 // if the Dispense drug was stuffed - still do the checks (form alt, refills)
284 if cboDispense.ItemIndex > -1 then cboDispenseMouseClick(Self);
285end;
286
287{ cboDispense methods }
288
289procedure TfrmODMedIn.CheckFormAlt;
290var
291 DrugName, OIName: string;
292 Drug, OI: Integer;
293begin
294 with cboDispense do if (ItemIndex > -1) and (Piece(Items[ItemIndex], U, 4) = 'NF') then
295 begin
296 SelectFormularyAlt(ItemIEN, Drug, OI, DrugName, OIName, PST_UNIT_DOSE);
297 if Drug > 0 then
298 begin
299 if FMedCombo.ItemIEN <> OI then
300 begin
301 FMedCombo.InitLongList(OIName);
302 FMedCombo.SelectByIEN(OI);
303 cboMedicationSelect(Self);
304 end;
305 cboDispense.SelectByIEN(Drug);
306 end; {if FormAlt}
307 end; {if ItemIndex}
308end;
309
310procedure TfrmODMedIn.cboDispenseExit(Sender: TObject);
311var
312 AMsg: string;
313begin
314 inherited;
315 with cboDispense do
316 begin
317 if ItemIEN <> FLastDrug then CheckFormAlt;
318 if ItemIEN > 0 then
319 begin
320 AMsg := DispenseMessage(ItemIEN);
321 if memMessage.Text <> AMsg then OrderMessage(AMsg);
322 end;
323 FLastDrug := ItemIEN;
324 end;
325end;
326
327procedure TfrmODMedIn.cboDispenseMouseClick(Sender: TObject);
328begin
329 inherited;
330 with cboDispense do
331 begin
332 if ItemIEN <> FLastDrug then CheckFormAlt;
333 if ItemIEN > 0 then OrderMessage(DispenseMessage(ItemIEN));
334 FLastDrug := ItemIEN;
335 end;
336end;
337
338{ all controls }
339
340procedure TfrmODMedIn.ControlChange(Sender: TObject);
341begin
342 inherited;
343 if Changing then Exit;
344 with FMedCombo do if ItemIEN > 0
345 then Responses.Update('ORDERABLE', 1, ItemID, Piece(Items[ItemIndex], U, 3))
346 else Responses.Update('ORDERABLE', 1, '', '');
347 with cboDispense do if ItemIEN > 0
348 then Responses.Update('DRUG', 1, ItemID, Piece(Items[ItemIndex], U, 2));
349 with txtDosage do if Length(Text) > 0 then Responses.Update('INSTR', 1, Text, Text);
350 with cboRoute do if ItemIndex > -1
351 then Responses.Update('ROUTE', 1, ItemID, Piece(Items[ItemIndex], U, 3))
352 else Responses.Update('ROUTE', 1, Text, Text);
353 with cboSchedule do if Length(Text) > 0 then Responses.Update('SCHEDULE', 1, Text, Text);
354 with cboPriority do if ItemIndex > -1 then Responses.Update('URGENCY', 1, ItemID, Text);
355 with memComments do Responses.Update('COMMENT', 1, TX_WPTYPE, Text);
356 memOrder.Text := Responses.OrderText;
357end;
358
359end.
360
Note: See TracBrowser for help on using the repository browser.