source: cprs/trunk/CPRS-Chart/Orders/fODMedIV.pas@ 877

Last change on this file since 877 was 829, checked in by Kevin Toppenberg, 14 years ago

Upgrade to version 27

File size: 70.7 KB
Line 
1unit fODMedIV;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 fODBase, Grids, StdCtrls, ORCtrls, ComCtrls, ExtCtrls, Buttons, Menus, IdGlobal, strUtils,
8 VA508AccessibilityManager, VAUtils, fIVRoutes;
9
10type
11 TfrmODMedIV = class(TfrmODBase)
12 lblInfusionRate: TLabel;
13 txtRate: TCaptionEdit;
14 lblComponent: TLabel;
15 lblAmount: TLabel;
16 grdSelected: TCaptionStringGrid;
17 cmdRemove: TButton;
18 lblComments: TLabel;
19 memComments: TCaptionMemo;
20 txtSelected: TCaptionEdit;
21 cboSelected: TCaptionComboBox;
22 pnlXDuration: TPanel;
23 txtXDuration: TCaptionEdit;
24 lblLimit: TLabel;
25 pnlCombo: TPanel;
26 cboAdditive: TORComboBox;
27 tabFluid: TTabControl;
28 cboSolution: TORComboBox;
29 lblPriority: TLabel;
30 cboPriority: TORComboBox;
31 Label1: TLabel;
32 cboRoute: TORComboBox;
33 cboSchedule: TORComboBox;
34 lblRoute: TLabel;
35 lblSchedule: TLabel;
36 cboType: TComboBox;
37 lblType: TLabel;
38 chkPRN: TCheckBox;
39 txtNSS: TLabel;
40 chkDoseNow: TCheckBox;
41 cboInfusionTime: TComboBox;
42 cboDuration: TComboBox;
43 lblAdminTime: TVA508StaticText;
44 lblFirstDose: TVA508StaticText;
45 txtAllIVRoutes: TLabel;
46 lblTypeHelp: TLabel;
47 procedure FormCreate(Sender: TObject);
48 procedure tabFluidChange(Sender: TObject);
49 procedure cboAdditiveNeedData(Sender: TObject; const StartFrom: string; Direction,
50 InsertAt: Integer);
51 procedure cboSolutionNeedData(Sender: TObject; const StartFrom: string; Direction,
52 InsertAt: Integer);
53 procedure cboAdditiveMouseClick(Sender: TObject);
54 procedure cboAdditiveExit(Sender: TObject);
55 procedure cboSolutionMouseClick(Sender: TObject);
56 procedure cboSolutionExit(Sender: TObject);
57 procedure FormDestroy(Sender: TObject);
58 procedure cmdRemoveClick(Sender: TObject);
59 procedure FormResize(Sender: TObject);
60 procedure txtSelectedExit(Sender: TObject);
61 procedure cboSelectedExit(Sender: TObject);
62 procedure ControlChange(Sender: TObject);
63 procedure txtSelectedChange(Sender: TObject);
64 procedure cboSelectedChange(Sender: TObject);
65 procedure grdSelectedDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
66 State: TGridDrawState);
67 procedure FormKeyDown(Sender: TObject; var Key: Word;
68 Shift: TShiftState);
69 procedure grdSelectedKeyPress(Sender: TObject; var Key: Char);
70 procedure grdSelectedMouseDown(Sender: TObject; Button: TMouseButton;
71 Shift: TShiftState; X, Y: Integer);
72 procedure txtXDurationChange(Sender: TObject);
73 procedure pnlXDurationEnter(Sender: TObject);
74 procedure txtXDurationExit(Sender: TObject);
75 procedure cboScheduleChange(Sender: TObject);
76 procedure cboTypeChange(Sender: TObject);
77 procedure cboRouteChange(Sender: TObject);
78 procedure txtRateChange(Sender: TObject);
79 procedure cboPriorityChange(Sender: TObject);
80 procedure cboPriorityExit(Sender: TObject);
81 procedure cboRouteExit(Sender: TObject);
82 procedure txtNSSClick(Sender: TObject);
83 procedure cboScheduleClick(Sender: TObject);
84 procedure chkPRNClick(Sender: TObject);
85 procedure chkDoseNowClick(Sender: TObject);
86 procedure loadExpectFirstDose;
87 procedure SetSchedule(const x: string);
88 procedure cboScheduleExit(Sender: TObject);
89 procedure cboInfusionTimeChange(Sender: TObject);
90 procedure cboDurationChange(Sender: TObject);
91 procedure cboDurationEnter(Sender: TObject);
92 procedure cboInfusionTimeEnter(Sender: TObject);
93 procedure txtAllIVRoutesClick(Sender: TObject);
94 procedure cboRouteClick(Sender: TObject);
95 procedure lblTypeHelpClick(Sender: TObject);
96 private
97 FInpatient: Boolean;
98 FNSSAdminTime: string;
99 FNSSScheduleType: string;
100 OSolIEN: integer;
101 OAddIEN: integer;
102 OSchedule: string;
103 oAdmin: string;
104 Action: integer;
105 OrderIEN: string;
106 FAdminTimeText: string;
107 JAWSON: boolean;
108 FOriginalDurationType: integer;
109 FOriginalInfusionType: integer;
110 FInitialOrderID: boolean;
111 procedure SetValuesFromResponses;
112 procedure DoSetFontSize( FontSize: integer);
113 procedure ClickOnGridCell;
114 procedure SetLimitationControl(aValue: string);
115 function CreateOtherSchedule: string;
116 function CreateOtherRoute: string;
117 procedure UpdateRoute;
118 procedure DisplayDoseNow(Status: boolean);
119 procedure UpdateDuration(SchType: string);
120 procedure ClearAllFields;
121 public
122 procedure InitDialog; override;
123 procedure SetupDialog(OrderAction: Integer; const ID: string); override;
124 procedure Validate(var AnErrMsg: string); override;
125 procedure SetFontSize( FontSize: integer); override;
126 function ValidateInfusionRate(Rate: string): string;
127 function IVTypeHelpText: string;
128 property NSSAdminTime: string read FNSSAdminTime write FNSSAdminTime;
129 property NSSScheduleType: string read FNSSScheduleType write FNSSScheduleType;
130 end;
131
132var
133 frmODMedIV: TfrmODMedIV;
134
135implementation
136
137{$R *.DFM}
138
139uses ORFn, uConst, rODMeds, rODBase, fFrame, uCore, fOtherSchedule, rCore;
140
141const
142 TX_NO_DEA = 'Provider must have a DEA# or VA# to order this medication';
143 TC_NO_DEA = 'DEA# Required';
144
145type
146 TIVComponent = class
147 private
148 IEN: Integer;
149 Name: string;
150 Fluid: Char;
151 Amount: Integer;
152 Units: string;
153 Volumes: string;
154 end;
155
156const
157 TC_RESTRICT = 'Ordering Restrictions';
158 TX_NO_BASE = 'A solution must be selected.';
159 TX_NO_AMOUNT = 'A valid strength or volume must be entered for ';
160 TX_NO_UNITS = 'Units must be entered for ';
161 TX_NO_RATE = 'An infusion rate must be entered.';
162 //TX_BAD_RATE = 'The infusion rate must be: # ml/hr or text@labels per day';
163 TX_BAD_RATE = 'Infusion rate can only be up to 4 digits long or' + CRLF + 'Infusion rate must be # ml/hr or text@labels per day';
164 TX_NO_INFUSION_TIME = 'An Infusion length must be entered or the Unit of Time for the Infuse Over Time field needs to be cleared out.';
165 TX_NO_SCHEDULE = 'A schedule is required for an intermittent order.';
166 TX_BAD_SCHEDULE = 'Unable to resolve non-standard schedule.';
167 TX_NO_INFUSION_UNIT = 'Invalid Unit of Time, select either "Minutes" or "Hours" for the Infusion Length';
168 TX_BAD_ROUTE = 'Route cannot be free-text';
169 TX_LEADING_NUMERIC = 'this additive must start with a leading numeric value';
170
171(*
172 { TIVComponent methods }
173
174procedure TIVComponent.Clear;
175begin
176 IEN := 0;
177 Name := '';
178 Fluid := #0;
179 Amount := 0;
180 Units := '';
181 Volumes := '';
182end;
183*)
184
185{ Form methods }
186
187procedure TfrmODMedIV.FormCreate(Sender: TObject);
188var
189 Restriction: string;
190begin
191 frmFrame.pnlVisit.Enabled := false;
192 //AutoSizeDisabled := true;
193 inherited;
194 AllowQuickOrder := True;
195 CheckAuthForMeds(Restriction);
196 if Length(Restriction) > 0 then
197 begin
198 InfoBox(Restriction, TC_RESTRICT, MB_OK);
199 Close;
200 Exit;
201 end;
202 DoSetFontSize(MainFontSize);
203 FillerID := 'PSIV'; // does 'on Display' order check **KCM**
204 StatusText('Loading Dialog Definition');
205 Responses.Dialog := 'PSJI OR PAT FLUID OE'; // loads formatting info
206 StatusText('Loading Default Values');
207 CtrlInits.LoadDefaults(ODForIVFluids); // ODForIVFluids returns TStrings with defaults
208 InitDialog;
209end;
210
211procedure TfrmODMedIV.FormDestroy(Sender: TObject);
212var
213 i: Integer;
214begin
215 with grdSelected do for i := 0 to RowCount - 1 do TIVComponent(Objects[0, i]).Free;
216 inherited;
217 frmFrame.pnlVisit.Enabled := True;
218end;
219
220procedure TfrmODMedIV.FormResize(Sender: TObject);
221var
222bottom: integer;
223begin
224 inherited;
225 with grdSelected do
226 begin
227 ColWidths[1] := Canvas.TextWidth(' 10000 ') + GetSystemMetrics(SM_CXVSCROLL);
228 ColWidths[2] := Canvas.TextWidth('meq.') + GetSystemMetrics(SM_CXVSCROLL);
229 ColWidths[0] := ClientWidth - ColWidths[1] - ColWidths[2] - 4;
230 end;
231 lblAmount.Left := grdSelected.Left + grdSelected.ColWidths[0];
232 self.cboType.SelLength := 0;
233 self.cboInfusionTime.SelLength := 0;
234 self.cboDuration.SelLength := 0;
235 bottom := self.cboPriority.Top + self.cboPriority.Height;
236 if self.chkDoseNow.Top < bottom then self.chkDoseNow.Top := bottom + 5;
237 self.txtRate.Height := self.cboInfusionTime.Height;
238 self.txtXDuration.Height := self.cboDuration.Height;
239 self.lblAdminTime.Height := TextHeightByFont(self.lblAdminTime.Font.Handle, 'A');
240 self.lblFirstDose.Height := TextHeightByFont(self.lblFirstDose.Font.Handle, 'A');
241 self.lblAdminTime.Width := TextWidthByFont(self.lblAdminTime.Font.Handle, self.lblAdminTime.Caption + ' ');
242 self.lblFirstDose.Width := TextWidthByFont(self.lblFirstDose.Font.Handle, self.lblFirstDose.Caption + ' ');
243 self.lblAdminTime.Top := self.chkDoseNow.Top + self.chkDoseNow.Height + 2;
244 self.lblFirstDose.Top := self.lblAdminTime.Top + self.lblAdminTime.Height + 2;
245 if self.Label1.Top < (self.lblFirstDose.Top + self.lblFirstDose.Height) then
246 begin
247 self.Label1.Top := self.lblFirstDose.Top + self.lblFirstDose.Height + 2;
248 self.memOrder.Top := self.Label1.Top + self.Label1.Height;
249 end;
250end;
251
252{ TfrmODBase overrides }
253
254procedure TfrmODMedIV.InitDialog;
255const
256 NOSELECTION: TGridRect = (Left: -1; Top: -1; Right: -1; Bottom: -1);
257var
258 i: Integer;
259begin
260 inherited;
261 //grdSelected.Selection := NOSELECTION;
262 //FRouteConflict := False;
263 //lblTypeHelp.Hint := IVTypeHelpText;
264 lblType.Hint := IVTypeHelpText;
265 cboType.Hint := IVTYpeHelpText;
266 with grdSelected do for i := 0 to RowCount - 1 do
267 begin
268 TIVComponent(Objects[0, i]).Free;
269 Rows[i].Clear;
270 end;
271 grdSelected.RowCount := 1;
272 //txtRate.Text := ' ml/hr'; {*kcm*}
273 with CtrlInits do
274 begin
275 SetControl(cboSolution, 'ShortList');
276 cboSolution.InsertSeparator;
277 SetControl(cboPriority, 'Priorities');
278 cboType.Items.Add('Continuous');
279 cboType.Items.Add('Intermittent');
280 cboType.ItemIndex := -1;
281 cboType.SelLength := 0;
282 //SetControl(cboRoute, 'Route');
283 if (cboRoute.ItemIndex = -1) and (cboRoute.Text <> '') then cboRoute.Text := '';
284 //SetControl(cboSchedule, 'Schedules');
285 LoadSchedules(cboSchedule.Items, patient.Inpatient);
286 //if (Patient.Inpatient) and (cboSchedule.Items.IndexOfName('Other')<0) then
287 if cboSchedule.Items.IndexOf('Other') = -1 then cboSchedule.Items.Add('OTHER');
288
289 cboSchedule.Enabled := False;
290 lblschedule.Enabled := False;
291 if cboInfusionTime.Items.Count = 0 then
292 begin
293 cboInfusionTime.Items.add('Minutes');
294 cboInfusionTime.Items.Add('Hours');
295 end;
296 cboInfusionTime.Enabled := false;
297 updateDuration('');
298 if cboDuration.Items.Count = 0 then
299 begin
300 cboDuration.Items.Add('L');
301 cboDuration.Items.Add('ml');
302 cboDuration.Items.Add('days');
303 cboDuration.Items.Add('hours');
304 end;
305 cboDuration.ItemIndex := -1;
306 cboDuration.Text := '';
307 if self.txtXDuration.Text <> '' then self.txtXDuration.Text := '';
308 txtNSS.Visible := false;
309 if (chkDoseNow.Visible = true) and (chkDoseNow.Checked = true) then chkDoseNow.Checked := false;
310 chkDoseNow.Visible := false;
311 chkPRN.Enabled := false;
312 end;
313 tabFluid.TabIndex := 0;
314 tabFluidChange(Self); // this makes cboSolution visible
315 cboSolution.InitLongList('');
316 cboAdditive.InitLongList('');
317 JAWSON := true;
318 if ScreenReaderActive = false then
319 begin
320 lblAdminTime.TabStop := false;
321 lblFirstDose.TabStop := false;
322 memOrder.TabStop := false;
323 JAWSON := false;
324 end;
325 ActiveControl := cboSolution; //SetFocusedControl(cboSolution);
326 StatusText('');
327 OSolIEN := 0;
328 OAddIEN := 0;
329 OSchedule := '';
330 oAdmin := '';
331 self.txtAllIVRoutes.Visible := false;
332end;
333
334function TfrmODMedIV.IVTypeHelpText: string;
335begin
336 result := 'Continuous Type:' + CRLF + ' IV’s that run at a specified “Rate” ( __ml/hr, __mcg/kg/min, etc)' +
337 CRLF + CRLF + 'Intermittent Type:' + CRLF +
338 ' IV’s administered at scheduled intervals (Q4H, QDay) or One-Time only, ' +
339 CRLF + ' “over a specified time period” (e.g. “Infuse over 30 min.”).' + CRLF + CRLF +
340 'Examples:' + CRLF + 'Continuous = Infusion/drip' + CRLF + 'Intermittent = IVP/IVPB';
341end;
342
343procedure TfrmODMedIV.lblTypeHelpClick(Sender: TObject);
344var
345str: string;
346begin
347 inherited;
348 str := IVTypeHelpText;
349 infoBox(str, 'Informational Help Text', MB_OK);
350end;
351
352
353procedure TfrmODMedIV.loadExpectFirstDose;
354var
355i: integer;
356AnIVComponent: TIVComponent;
357fAddIEN, fSolIEN, Interval, idx: integer;
358AdminTime: TFMDateTime;
359Admin, Duration, ShowText, SchTxt, SchType, IVType: string;
360doseNow, calFirstDose: boolean;
361begin
362 idx := self.cboSchedule.ItemIndex;
363 IVType := self.cboType.Items.Strings[self.cboType.itemindex];
364 if idx = -1 then
365 begin
366 if IVType = 'Continuous' then
367 begin
368 self.lblFirstDose.Caption := '';
369 self.lblFirstDose.Visible := false;
370 end;
371 exit;
372 end;
373 doseNow := true;
374 SchType := Piece(self.cboSchedule.Items.Strings[idx],U,3);
375 if self.EvtID > 0 then doseNow := false;
376 if (IVType = 'Continuous') or ((idx > -1) and ((SchType = 'P') or (SchType = 'O') or (SchType = 'OC')) or
377 (self.chkPRN.Checked = True)) then
378 begin
379 self.lblFirstDose.Caption := '';
380 self.lblAdminTime.Caption := '';
381 self.lblFirstDose.Visible := false;
382 self.lblAdminTime.Visible := false;
383 self.lblAdminTime.TabStop := false;
384 self.lblFirstDose.TabStop := false;
385 if (self.cboType.Text = 'Continuous') or (Piece(self.cboSchedule.Items.Strings[idx],U,3) = 'O') then doseNow := false;
386 if chkDoseNow.Checked = true then lblFirstDose.Visible := false;
387 if idx > -1 then oSchedule := Piece(self.cboSchedule.Items.Strings[idx],U,1);
388 if (self.chkPRN.Checked = True) and (idx > -1) and (LeftStr(Piece(self.cboSchedule.Items.Strings[idx],U,1),3)<> 'PRN') then
389 OSchedule := Piece(self.cboSchedule.Items.Strings[idx],U,1) + ' PRN';
390 DisplayDoseNow(doseNow);
391 exit;
392 // end;
393 end
394 else if SchType <> 'O' then
395 begin
396 self.lblAdminTime.Visible := true;
397 if FAdminTimeText <> '' then self.lblAdminTime.Caption := 'Admin. Time: ' + FAdminTimeText
398 else if Piece(self.cboSchedule.Items[idx],U,4) <> '' then
399 self.lblAdminTime.Caption := 'Admin. Time: ' + Piece(self.cboSchedule.Items[idx],U,4)
400 else self.lblAdminTime.Caption := 'Admin. Time: Not Defined';
401 end;
402 DisplayDoseNow(doseNow);
403 if chkDoseNow.Checked = true then
404 begin
405 lblFirstDose.Visible := false;
406 Exit;
407 end;
408 self.lblFirstDose.Visible := True;
409 fSolIEN := 0;
410 fAddIEN := 0;
411 for i := 0 to self.grdSelected.RowCount - 1 do
412 begin
413 AniVComponent := TIVComponent(self.grdSelected.Objects[0, i]);
414 if AnIVComponent = nil then Continue;
415 if (AnIVComponent.Fluid = 'B') and (fSolIEN = 0) then fSolIEN := AnIVComponent.IEN;
416 if (AnIVComponent.Fluid = 'A') and (fAddIEN = 0) then fAddIEN := AnIVComponent.IEN;
417 if (fSolIEN > 0) and (fAddIEN > 0) then break;
418 end;
419 SchTxt := self.cboSchedule.Text;
420 Admin := '';
421 if (self.lblAdminTime.visible = True) and (self.lblAdminTime.Caption <> '') then
422 begin
423 Admin := Copy(self.lblAdminTime.Caption, 14, (Length(self.lblAdminTime.Caption)-1));
424 if not (Admin[1] in ['0'..'9']) then Admin := '';
425 end;
426 if (fSolIEN = oSolIEN) and (fAddIEN = oAddIEN) and (OSchedule = SchTxt) and (oAdmin = Admin) then CalFirstDose := false
427 else
428 begin
429 CalFirstDose := True;
430 oSolIEN := fSolIEN;
431 oAddIEN := fAddIEN;
432 oSchedule := SchTxt;
433 oAdmin := Admin;
434 end;
435 if CalFirstDose = True then
436 begin
437 if fAddIEN > 0 then LoadAdminInfo(';' + schTxt, fAddIEN, ShowText, AdminTime, Duration, Admin)
438 else LoadAdminInfo(';' + schTxt, fSolIEN, ShowText, AdminTime, Duration, Admin);
439 if AdminTime > 0 then
440 begin
441 ShowText := 'Expected First Dose: ';
442 Interval := Trunc(FMDateTimeToDateTime(AdminTime) - FMDateTimeToDateTime(FMToday));
443 case Interval of
444 0: ShowText := ShowText + 'TODAY ' + FormatFMDateTime('(mmm dd, yy) at hh:nn', AdminTime);
445 1: ShowText := ShowText + 'TOMORROW ' + FormatFMDateTime('(mmm dd, yy) at hh:nn', AdminTime);
446 else ShowText := ShowText + FormatFMDateTime('mmm dd, yy at hh:nn', AdminTime);
447 end;
448 end;
449 self.lblFirstDose.Caption := ShowText;
450 end;
451 if (self.lblFirstDose.Visible = true) and (self.lblFirstDose.Caption <> '') and (JAWSON = true) then self.lblFirstDose.TabStop := true
452 else self.lblFirstDose.TabStop := false;
453 if (self.lblAdminTime.Visible = true) and (self.lblAdminTime.Caption <> '') and (JAWSON = true) then self.lblAdminTime.TabStop := true
454 else self.lblAdminTime.TabStop := false;
455end;
456
457procedure TfrmODMedIV.Validate(var AnErrMsg: string);
458var
459 DispWarning, ItemOK, Result: Boolean;
460 LDec,RDec,x, tempStr, iunit, infError: string;
461 digits, i, j, Len, temp, Value: Integer;
462
463 procedure SetError(const x: string);
464 begin
465 if Length(AnErrMsg) > 0 then AnErrMsg := AnErrMsg + CRLF;
466 AnErrMsg := AnErrMsg + x;
467 end;
468
469begin
470 inherited;
471 with grdSelected do
472 begin
473 ItemOK := False;
474 for i := 0 to RowCount - 1 do
475 if (Objects[0,i] <> nil) and (TIVComponent(Objects[0, i]).Fluid = 'B') then ItemOK := True;
476 if (not ItemOK) and ((self.cboType.ItemIndex = -1) or (MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Continuous')) then
477 SetError(TX_NO_BASE);
478 for i := 0 to RowCount - 1 do
479 begin
480 if (Objects[0, i] <> nil) and ((Length(Cells[1, i]) = 0) or (StrToFloat(Cells[1,i])=0))
481 then SetError(TX_NO_AMOUNT + Cells[0, i]);
482 if (Objects[0, i] <> nil) and (Length(Cells[2, i]) = 0)
483 then SetError(TX_NO_UNITS + Cells[0, i]);
484 if (Objects[0,i] <> nil) and (TIVComponent(Objects[0, i]).Fluid = 'A') then
485 begin
486 temp := Pos('.', Cells[1, i]);
487 if temp > 0 then
488 begin
489 tempStr := Cells[1, i];
490 if temp = 1 then
491 begin
492 SetError(cells[0, i] + TX_LEADING_NUMERIC);
493 Exit;
494 end;
495 for j := 1 to temp -1 do if not (tempStr[j] in ['0'..'9']) then
496 begin
497 SetError(cells[0, i] + TX_LEADING_NUMERIC);
498 Exit;
499 end;
500 end;
501 end;
502 end;
503 end;
504 if Pos(U, self.memComments.Text) > 0 then SetError('Comments cannot contain a "^".');
505 if cboSchedule.ItemIndex > -1 then updateDuration(Piece(cboSchedule.Items.Strings[cboSchedule.itemIndex], U, 3));
506 if self.cboPriority.Text = '' then SetError('Priority is required');
507 if (cboRoute.ItemIndex = -1) and (cboRoute.Text <> '') then SetError(TX_BAD_ROUTE);
508 if (cboRoute.ItemIndex > -1) and (cboRoute.ItemIndex = cboRoute.Items.IndexOf('OTHER')) then
509 SetError('A valid route must be selected');
510 if self.cboRoute.Text = '' then SetError('Route is required');
511 if (self.txtXDuration.Text <> '') and (self.cboduration.Items.IndexOf(SELF.cboDuration.Text) = -1) then
512 SetError('A valid duration type is required');
513 if (self.txtXDuration.Text = '') and (self.cboduration.Items.IndexOf(SELF.cboDuration.Text) > -1) then
514 SetError('Cannot have a duration type without a duration value');
515
516 if self.cboType.ItemIndex = -1 then
517 begin
518 SetError('IV Type is required');
519 Exit;
520 end;
521 if MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Continuous' then
522 begin
523 if Length(txtRate.Text) = 0 then SetError(TX_NO_RATE) else
524 begin
525 x := Trim(txtRate.Text);
526 if pos('@', X) > 0 then
527 begin
528 LDec := Piece(x, '@', 1);
529 RDec := Piece(x, '@', 2);
530 if (Length(RDec) = 0) or (Length(RDec) > 2) then x := '';
531 end
532 else if Pos('.',X)>0 then
533 begin
534 LDec := Piece(x, '.', 1);
535 RDec := Piece(x, '.', 2);
536 if Length(LDec) = 0 then SetError('Infusion Rate required a leading numeric value');
537 if Length(RDec) > 1 then SetError('Infusion Rate cannot exceed one decimal place');
538 end
539 else if LeftStr(txtRate.Text, 1) = '0' then
540 SetError('Infusion Rate cannot start with a zero.');
541 if ( Pos('@',x)=0) then
542 begin
543 if (Length(x) > 4) then
544 begin
545 seterror(TX_BAD_RATE);
546 exit;
547 end;
548 for i := 1 to Length(x) do
549 begin
550 if not (x[i] in ['0'..'9']) and (x[i] <> '.') then
551 begin
552 SetError(TX_BAD_RATE);
553 exit;
554 end;
555 end;
556 end;
557 if (pos('ml/hr', X) = 0) and (Length(x) > 0) and (pos('@', X) = 0) then X := X + ' ml/hr';
558 if Length(x) = 0 then SetError(TX_BAD_RATE) else Responses.Update('RATE', 1, x, x);
559 end;
560 if cboduration.text = 'doses' then SetError('Continuous Orders cannot have "doses" as a duration type');
561 end
562 else if MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Intermittent' then
563 begin
564 if (cboInfusionTime.ItemIndex = -1) and (txtRate.Text <> '') then SetError(TX_NO_INFUSION_UNIT);
565 if (txtRate.Text = '') and (cboInfusionTime.ItemIndex > -1) then SetError(TX_NO_INFUSION_TIME);
566 if (txtRate.Text <> '') then
567 begin
568 infError := '';
569 InfError := ValidateInfusionRate(txtRate.Text);
570 if infError <> '' then SetError(InfError);
571 Len := Length(txtRate.Text);
572 iunit := MixedCase(self.cboInfusionTime.Items.Strings[cboInfusionTime.ItemIndex]);
573 if (iunit = 'Minutes') and (Len > 4) then setError('Infuse Over Time cannot exceed 4 spaces for ' + iunit)
574 else if (iunit = 'Hours') and (Len > 2) then setError('Infuse Over Time cannot exceed 2 spaces for ' + iunit);
575 end;
576 if (cboSchedule.ItemIndex = -1) and (cboSchedule.Text = '') then SetError(TX_NO_SCHEDULE);
577 if (cboSchedule.ItemIndex = -1) and (cboSchedule.Text <> '') then SetError(TX_BAD_SCHEDULE);
578 end;
579 if txtXDuration.Text = '' then
580 begin
581 if AnErrMsg = '' then self.FInitialOrderID := True;
582 exit;
583 end;
584 Len := Length(txtXDuration.Text);
585 if LeftStr(txtXDuration.Text,1) <> '.' then
586 begin
587 DispWarning := false;
588 Digits := 2;
589 if cboDuration.text = 'ml' then digits := 4;
590 if ((cboDuration.text = 'days') or (cboDuration.text = 'hours')) and (Len > digits) then
591 DispWarning := true
592 else if (cboduration.text = 'ml') and (Len > digits) then DispWarning := true
593 else if (cboduration.text = 'L') and (Len > digits) and (Pos('.',txtXDuration.Text) = 0) then DispWarning := True;
594 if DispWarning = true then SetError('Duration for ' + cboduration.text + ' cannot be greater than ' + InttoStr(digits) + ' digits.');
595 end;
596 if (Pos('.', txtXDuration.Text)>0) then
597 begin
598 SetError('Invalid Duration, please enter a whole numbers for a duration.');
599 end
600 else if LeftStr(txtXDuration.text, 1) = '0' then
601 SetError('Duration cannot start with a zero.');
602 if (cboduration.text = 'doses') then
603 begin
604 if TryStrToInt(txtXDuration.Text, Value) = false then
605 SetError('Duration with a unit of "doses" must be a whole number between 0 and 2000000')
606 else if (Value < 0) or (Value > 2000000) then
607 SetError('Duration with a unit of "doses" must be greater then 0 and less then 2000000');
608 end;
609 if AnErrMsg = '' then self.FInitialOrderID := True;
610
611end;
612
613function TFrmODMedIV.ValidateInfusionRate(Rate: string): string;
614var
615Temp: Boolean;
616i: integer;
617begin
618 Temp := False;
619 if Pos('.',Rate) >0 then
620 begin
621 Result := 'Infuse Over Time can only be a whole number';
622 exit;
623 end
624 else if LeftStr(Rate, 1) = '0' then Result := 'Infuse Over Time cannot start with a zero.';
625 for i := 1 to Length(Rate) do if not (Rate[i] in ['0'..'9']) then Temp := True;
626 if Temp = True then Result := 'The Infusion time can only be a whole number';
627end;
628
629procedure TfrmODMedIV.SetValuesFromResponses;
630var
631 x, addRoute, tempSch, AdminTime, TempOrder, tmpSch, tempIRoute, tempRoute: string;
632 AnInstance, i, idx: Integer;
633 AResponse: TResponse;
634 AnIVComponent: TIVComponent;
635 AllIVRoute: TStringList;
636 PQO: boolean;
637begin
638 Changing := True;
639 self.FInitialOrderID := false;
640 with Responses do
641 begin
642 FInpatient := OrderForInpatient;
643 AnInstance := NextInstance('ORDERABLE', 0);
644 while AnInstance > 0 do
645 begin
646 AResponse := FindResponseByName('ORDERABLE', AnInstance);
647 if AResponse <> nil then
648 begin
649 x := AmountsForIVFluid(StrToIntDef(AResponse.IValue, 0), 'B');
650 AnIVComponent := TIVComponent.Create;
651 AnIVComponent.IEN := StrToIntDef(AResponse.IValue, 0);
652 if not FInpatient then
653 begin
654 if DEACheckFailedForIVOnOutPatient(AnIVComponent.IEN,'S') then
655 begin
656 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
657 cboAdditive.Text := '';
658 AbortOrder := True;
659 Exit;
660 end;
661 end else
662 begin
663 if DEACheckFailed(AnIVComponent.IEN, FInpatient) then
664 begin
665 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
666 cboAdditive.Text := '';
667 AbortOrder := True;
668 Exit;
669 end;
670 end;
671 AnIVComponent.Name := AResponse.EValue;
672 AnIVComponent.Fluid := 'B';
673 AnIVComponent.Amount := StrToIntDef(Piece(x, U, 2), 0);
674 AnIVComponent.Units := Piece(x, U, 1);
675 AnIVComponent.Volumes := Copy(x, Pos(U, x) + 1, Length(x));
676 with grdSelected do
677 begin
678 if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
679 Objects[0, RowCount - 1] := AnIVComponent;
680 Cells[0, RowCount - 1] := AnIVComponent.Name;
681 if AnIVComponent.Amount <> 0 then
682 Cells[1, RowCount - 1] := IntToStr(AnIVComponent.Amount);
683 Cells[2, RowCount - 1] := AnIVComponent.Units;
684 end;
685 end;
686 AResponse := FindResponseByName('VOLUME', AnInstance);
687 if AResponse <> nil then with grdSelected do Cells[1, RowCount - 1] := AResponse.EValue;
688 AnInstance := NextInstance('ORDERABLE', AnInstance);
689 end; {while AnInstance - ORDERABLE}
690 AnInstance := NextInstance('ADDITIVE', 0);
691 while AnInstance > 0 do
692 begin
693 AResponse := FindResponseByName('ADDITIVE', AnInstance);
694 if AResponse <> nil then
695 begin
696 x := AmountsForIVFluid(StrToIntDef(AResponse.IValue, 0), 'A');
697 AnIVComponent := TIVComponent.Create;
698 AnIVComponent.IEN := StrToIntDef(AResponse.IValue, 0);
699 if not FInpatient then
700 begin
701 if DEACheckFailedForIVOnOutPatient(AnIVComponent.IEN,'A') then
702 begin
703 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
704 cboAdditive.Text := '';
705 AbortOrder := True;
706 Exit;
707 end;
708 end else
709 begin
710 if DEACheckFailed(AnIVComponent.IEN, FInpatient) then
711 begin
712 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
713 cboAdditive.Text := '';
714 AbortOrder := true;
715 Exit;
716 end;
717 end;
718 AnIVComponent.Name := AResponse.EValue;
719 AnIVComponent.Fluid := 'A';
720 AnIVComponent.Amount := StrToIntDef(Piece(x, U, 2), 0);
721 AnIVComponent.Units := Piece(x, U, 1);
722 AnIVComponent.Volumes := Copy(x, Pos(U, x) + 1, Length(x));
723 with grdSelected do
724 begin
725 if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
726 Objects[0, RowCount - 1] := AnIVComponent;
727 Cells[0, RowCount - 1] := AnIVComponent.Name;
728 if AnIVComponent.Amount <> 0 then
729 Cells[1, RowCount - 1] := IntToStr(AnIVComponent.Amount);
730 Cells[2, RowCount - 1] := AnIVComponent.Units;
731 end;
732 end;
733 AResponse := FindResponseByName('STRENGTH', AnInstance);
734 if AResponse <> nil then with grdSelected do Cells[1, RowCount - 1] := AResponse.EValue;
735 AResponse := FindResponseByName('UNITS', AnInstance);
736 if AResponse <> nil then with grdSelected do Cells[2, RowCount - 1] := AResponse.EValue;
737 AnInstance := NextInstance('ADDITIVE', AnInstance);
738 end; {while AnInstance - ADDITIVE}
739 SetControl(cboType, 'TYPE', 1);
740 if self.grdSelected.RowCount > 0 then self.txtAllIVRoutes.Visible := True;
741 updateRoute;
742 AResponse := FindResponseByName('ROUTE', 1);
743 if AResponse <> nil then
744 begin
745 tempRoute := AResponse.EValue;
746 if tempRoute <> '' then
747 begin
748 idx := self.cboRoute.Items.IndexOf(tempRoute);
749 if idx > -1 then self.cboRoute.ItemIndex := idx
750 else begin
751 tempIRoute := AResponse.IValue;
752 if tempIRoute <> '' then
753 begin
754 AllIVRoute := TStringList.Create;
755 LoadAllIVRoutes(AllIVRoute);
756 idx := -1;
757 for i := 0 to AllIVRoute.Count - 1 do
758 begin
759 if Piece(AllIVRoute.Strings[i], U, 1) = tempIRoute then
760 begin
761 idx := i;
762 break;
763 end;
764 end;
765 if idx > -1 then
766 begin
767 self.cboRoute.Items.Add(AllIVRoute.Strings[idx]);
768 idx := self.cboRoute.Items.IndexOf(tempRoute);
769 if idx > -1 then self.cboRoute.ItemIndex := idx;
770 end;
771 AllIVRoute.Free;
772 //if Pos(U, tempIRoute) = 0 then tempIRoute := tempIRoute + U + tempRoute;
773 //self.cboRoute.Items.Add(tempIRoute);
774 //idx := self.cboRoute.Items.IndexOf(tempRoute);
775 //if idx > -1 then self.cboRoute.ItemIndex := idx;
776 end;
777 end;
778 end;
779 end;
780 //SetControl(cboRoute, 'ROUTE', 1);
781 if (cboRoute.ItemIndex = -1) and (cboRoute.Text <> '') then cboRoute.Text := '';
782 if self.cboType.Text = 'Intermittent' then
783 begin
784 lblInfusionRate.Caption := 'Infuse Over Time (Optional)';
785 lblSchedule.Enabled := True;
786 cboschedule.Enabled := True;
787 //if popDuration.Items.IndexOf(popDoses) = -1 then popDuration.Items.Add(popDoses);
788 if cboDuration.Items.IndexOf('doses') = -1 then cboDuration.Items.Add('doses');
789 txtNss.Visible := true;
790 chkDoseNow.Visible := true;
791 chkPRN.Enabled := True;
792 tempSch := '';
793 AdminTime := '';
794 AResponse := FindResponseByName('SCHEDULE', 1);
795 if AResponse <> nil then tempSch := AResponse.EValue;
796 lblAdminTime.Visible := True;
797 lblAdminTime.Hint := AdminTimeHelpText;
798 lblAdminTime.ShowHint := True;
799 //AResponse := Responses.FindResponseByName('ADMIN', 1);
800 //if AResponse <> nil then AdminTime := AResponse.EValue;
801 //if Action = Order_Copy then FOriginalAdminTime := AdminTime;
802 SetSchedule(tempSch);
803 //if (cboSchedule.ItemIndex > -1) then lblAdminTime.Caption := 'Admin. Time: ' + Piece(cboSchedule.Items.strings[cboSchedule.itemindex],U,5);
804 //if (cboSchedule.ItemIndex > -1) and (Piece(lblAdminTime.Caption, ':' ,2) = ' ') then lblAdminTime.Caption := 'Admin. Time: ' + AdminTime;
805 if (Action in [ORDER_COPY, ORDER_EDIT]) then
806 begin
807 TempOrder := Piece(OrderIEN,';',1);
808 TempOrder := Copy(tempOrder, 2, Length(tempOrder));
809 if DifferentOrderLocations(tempOrder, Patient.Location) = false then
810 begin
811 AResponse := Responses.FindResponseByName('ADMIN', 1);
812 if AResponse <> nil then AdminTime := AResponse.EValue;
813 //lblAdminTime.Caption := 'Admin. Time: ' + AdminTime;
814 if cboSchedule.ItemIndex > -1 then
815 begin
816 tmpSch := cboSchedule.Items.Strings[cboSchedule.itemindex];
817 setPiece(tmpSch,U,4,AdminTime);
818 cboSchedule.Items.Strings[cboSchedule.ItemIndex] := tmpSch;
819 end;
820 end;
821 end;
822 //if Piece(lblAdminTime.Caption, ':' ,2) = ' ' then lblAdminTime.Caption := 'Admin. Time: Not Defined';
823 SetControl(txtRate, 'RATE', 1);
824 cboInfusionTime.Enabled := true;
825 PQO := false;
826 if Pos('INFUSE OVER',UpperCase(txtRate.Text)) > 0 then
827 begin
828 txtRate.Text := Copy(txtRate.Text,Length('Infuse over ')+1,Length(txtRate.text));
829 PQO := True;
830 end;
831 if Pos('MINUTE',UpperCase(txtRate.Text))>0 then
832 begin
833 cboInfusionTime.Text := 'Minutes';
834 cboInfusionTime.itemindex := 0;
835 //txtRate.Text := Copy(txtRate.Text,Length('Infuse over ')+1,Length(txtRate.text));
836 txtRate.Text := Copy(txtRate.Text, 1, Length(txtRate.Text) - 8);
837 end
838 else if Pos('HOUR',UpperCase(txtRate.Text))>0 then
839 begin
840 cboInfusionTime.Text := 'Hours';
841 cboInfusionTime.ItemIndex := 1;
842 //txtRate.Text := Copy(txtRate.Text,Length('Infuse over ')+1,Length(txtRate.text));
843 txtRate.Text := Copy(txtRate.Text, 1, Length(txtRate.Text) - 6);
844 end
845 else if (txtRate.Text <> '') and (PQO = false) and (ValidateInfusionRate(txtRate.Text) ='') then
846 begin
847 cboInfusionTime.Text := 'Minutes';
848 cboInfusionTime.itemindex := 0;
849 end;
850 end
851 else
852 begin
853 lblSchedule.Enabled := false;
854 cboSchedule.ItemIndex := -1;
855 cboSchedule.Enabled := false;
856 if chkDoseNow.Visible = true then chkDoseNow.Checked := false;
857 chkDoseNow.Visible := false;
858 txtNSS.Visible := false;
859 cboInfusionTime.ItemIndex := -1;
860 cboInfusionTime.Text := '';
861 cboInfusionTime.Enabled := false;
862 chkPRN.Checked := false;
863 chkPRN.Enabled := false;
864 txtRate.Text := '';
865 cboDuration.ItemIndex := -1;
866 cboDuration.Text := '';
867 txtXDuration.Text := '';
868 SetControl(txtRate, 'RATE', 1);
869 if LowerCase(Copy(ReverseStr(txtRate.Text), 1, 6)) = 'rh/lm ' {*kcm*}
870 then txtRate.Text := Copy(txtRate.Text, 1, Length(txtRate.Text) - 6);
871 end;
872 SetControl(cboPriority, 'URGENCY', 1);
873 SetControl(memComments, 'COMMENT', 1);
874
875 AnInstance := NextInstance('DAYS', 0);
876 if AnInstance > 0 then
877 begin
878 AResponse := FindResponseByName('DAYS', AnInstance);
879 if AResponse <> nil then
880 SetLimitationControl(AResponse.EValue);
881 end;
882 end; {if...with Responses}
883 Changing := False;
884 if self.cboSchedule.ItemIndex > -1 then updateDuration(Piece(cboSchedule.Items.Strings[cboSchedule.itemindex],U,3));
885 loadExpectFirstDose;
886 ControlChange(Self);
887end;
888
889procedure TfrmODMedIV.SetupDialog(OrderAction: Integer; const ID: string);
890begin
891 inherited;
892 Action := OrderAction;
893 OrderIEN := id;
894 self.FInitialOrderID := True;
895 if self.EvtID > 0 then FAdminTimeText := 'To Be Determined';
896 if (isIMO) or ((patient.Inpatient = true) and (encounter.Location <> patient.Location)) and (FAdminTimeText = '') then
897 FAdminTimeText := 'Not defined for Clinic Locations';
898 if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then
899 begin
900
901 SetValuesFromResponses;
902 end;
903end;
904
905{ tabFluid events }
906
907procedure TfrmODMedIV.tabFluidChange(Sender: TObject);
908begin
909 inherited;
910 case TabFluid.TabIndex of
911 0: begin
912 cboSolution.Visible := True;
913 cboAdditive.Visible := False;
914 end;
915 1: begin
916 cboAdditive.Visible := True;
917 cboSolution.Visible := False;
918 end;
919 end;
920 if cboSolution.Visible then
921 ActiveControl := cboSolution;
922 if cboAdditive.Visible then
923 ActiveControl := cboAdditive;
924end;
925
926{ cboSolution events }
927
928procedure TfrmODMedIV.cboSolutionNeedData(Sender: TObject; const StartFrom: string;
929 Direction, InsertAt: Integer);
930var
931 CurString: string;
932begin
933 inherited;
934 if (Direction = 1) then
935 CurString := AnsiUpperCase(StartFrom) + ' ';
936 cboSolution.ForDataUse(SubSetOfOrderItems(CurString, Direction, 'S.IVB RX'));
937end;
938
939procedure TfrmODMedIV.cbotypeChange(Sender: TObject);
940begin
941 inherited;
942 //if (self.cbotype.Text = 'Intermittent') or (self.cboType.itemIndex = 1) then
943 if (self.cboType.itemIndex = 1) then
944 begin
945 cboSchedule.ItemIndex := -1;
946 lblAdminTime.Caption := '';
947 lblAdminTime.Visible := false;
948 lblschedule.Enabled := True;
949 cboSchedule.Enabled := True;
950 txtNSS.Visible := true;
951 chkDoseNow.Checked := false;
952 chkDoseNow.Visible := true;
953 chkPRN.Checked := false;
954 chkPRN.Enabled := True;
955 lblInfusionRate.Caption := 'Infuse Over Time (Optional)';
956 cboInfusionTime.Enabled := true;
957 cboDuration.Items.Add('doses');
958 end
959 //else if (self.cbotype.Text = 'Continuous') or (self.cboType.itemIndex = 0) then
960 else
961 begin
962 lblschedule.Enabled := False;
963 cboSchedule.ItemIndex := -1;
964 cboSchedule.Enabled := False;
965 txtNSS.Visible := false;
966 chkPRN.Checked := false;
967 chkPRN.Enabled := false;
968 if chkDoseNow.Visible = true then chkDoseNow.Checked := false;
969 chkDoseNow.Visible := false;
970 lblInfusionRate.Caption := 'Infusion Rate (ml/hr)*';
971 cboInfusionTime.ItemIndex := -1;
972 cboInfusionTime.Text := '';
973 cboInfusionTime.Enabled := false;
974 lblAdminTime.Visible := false;
975 updateDuration('');
976 cboduration.Items.Delete(cboDuration.Items.IndexOf('doses'));
977 end;
978 self.txtRate.Text := '';
979 ControlChange(Sender);
980end;
981
982procedure TfrmODMedIV.chkDoseNowClick(Sender: TObject);
983Const
984 T = '"';
985 T1 = 'By checking the "Give additional dose now" box, you have actually entered two orders for the same medication.';
986 T2 = #13#13'The first order''s administrative schedule is "';
987 T3 = #13'The second order''s administrative schedule is "';
988 T4 = #13#13'Do you want to continue?';
989 T1A = 'By checking the "Give additional dose now" box, you have actually entered a new order with the schedule "NOW"';
990 T2A = ' in addition to the one you are placing for the same medication.';
991var
992 medNm: string;
993 theSch: string;
994 //SchID: integer;
995begin
996 inherited;
997 if (chkDoseNow.Checked) then
998 begin
999 medNm := 'Test';
1000 //SchID := cboSchedule.ItemIndex;
1001 theSch := cboSchedule.Text;
1002 if length(theSch)>0 then
1003 begin
1004 //if (InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL)then
1005 if (InfoBox(T1+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL)then
1006 begin
1007 chkDoseNow.Checked := False;
1008 Exit;
1009 end;
1010 end else
1011 begin
1012 //if InfoBox(T1A+T2A+medNm+T+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL then
1013 if InfoBox(T1A+T2A+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL then
1014 begin
1015 chkDoseNow.Checked := False;
1016 Exit;
1017 end;
1018 end;
1019 end;
1020 ControlChange(self);
1021end;
1022
1023procedure TfrmODMedIV.chkPRNClick(Sender: TObject);
1024begin
1025 inherited;
1026 ControlChange(Self);
1027end;
1028
1029procedure TfrmODMedIV.cboSolutionMouseClick(Sender: TObject);
1030var
1031 AnIVComponent: TIVComponent;
1032 x,routeIEN: string;
1033 i: integer;
1034begin
1035 inherited;
1036 if CharAt(cboSolution.ItemID, 1) = 'Q' then // setup quick order
1037 begin
1038 //Clear pre-existing values
1039 for i := 0 to self.grdSelected.RowCount do
1040 begin
1041 if self.grdSelected.Objects[0,i] <> nil then
1042 begin
1043 TIVComponent(self.grdSelected.Objects[0,i]).Free;
1044 self.grdSelected.Rows[i].Clear;
1045 end
1046 else self.grdSelected.Rows[i].clear;
1047 end;
1048 self.grdSelected.RowCount := 0;
1049 ControlChange(Sender);
1050 Responses.QuickOrder := ExtractInteger(cboSolution.ItemID);
1051 SetValuesFromResponses;
1052 cboSolution.ItemIndex := -1;
1053 Exit;
1054 end;
1055 if cboSolution.ItemIEN <= 0 then Exit; // process selection of solution
1056 FInpatient := OrderForInpatient;
1057 if not FInpatient then
1058 begin
1059 if DEACheckFailedForIVOnOutPatient(cboSolution.ItemIEN,'S') then
1060 begin
1061 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
1062 cboSolution.Text := '';
1063 Exit;
1064 end;
1065 end else
1066 begin
1067 if DEACheckFailed(cboSolution.ItemIEN, FInpatient) then
1068 begin
1069 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
1070 cboSolution.Text := '';
1071 Exit;
1072 end;
1073 end;
1074 RouteIEN := Piece(cboSolution.Items.Strings[cboSolution.itemindex],U,4);
1075 x := AmountsForIVFluid(cboSolution.ItemIEN, 'B');
1076 AnIVComponent := TIVComponent.Create;
1077 AnIVComponent.IEN := cboSolution.ItemIEN;
1078 AnIVComponent.Name := Piece(cboSolution.Items[cboSolution.ItemIndex], U, 3);
1079 AnIVComponent.Fluid := 'B';
1080 AnIVComponent.Amount := StrToIntDef(Piece(x, U, 2), 0);
1081 AnIVComponent.Units := Piece(x, U, 1);
1082 AnIVComponent.Volumes := Copy(x, Pos(U, x) + 1, Length(x));
1083 cboSolution.ItemIndex := -1;
1084 with grdSelected do
1085 begin
1086 if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
1087 Objects[0, RowCount - 1] := AnIVComponent;
1088 Cells[0, RowCount - 1] := AnIVComponent.Name;
1089 Cells[1, RowCount - 1] := IntToStr(AnIVComponent.Amount);
1090 Cells[2, RowCount - 1] := AnIVComponent.Units;
1091 Row := RowCount - 1;
1092 if Length(Piece(AnIVComponent.Volumes, U, 2)) > 0 then Col := 1 else Col := 0;
1093 if RowCount = 1 then // switch to additives after 1st IV
1094 begin
1095 tabFluid.TabIndex := 1;
1096 tabFluidChange(Self);
1097 end;
1098 end;
1099 Application.ProcessMessages; //CQ: 10157
1100 ClickOnGridCell;
1101 updateRoute;
1102 ControlChange(Sender);
1103 //updateRoute(routeIEN);
1104end;
1105
1106procedure TfrmODMedIV.cboSolutionExit(Sender: TObject);
1107begin
1108 inherited;
1109 if EnterIsPressed then //CQ: 15097
1110 if (cboSolution.ItemIEN > 0) or
1111 ((cboSolution.ItemIEN = 0) and (CharAt(cboSolution.ItemID, 1) = 'Q')) then
1112 cboSolutionMouseClick(Self);
1113end;
1114
1115{ cboAdditive events }
1116
1117procedure TfrmODMedIV.cboAdditiveNeedData(Sender: TObject; const StartFrom: string;
1118 Direction, InsertAt: Integer);
1119var
1120 CurString: string;
1121begin
1122 inherited;
1123 if (Direction = 1) then
1124 CurString := AnsiUpperCase(StartFrom) + ' ';
1125 cboAdditive.ForDataUse(SubSetOfOrderItems(CurString, Direction, 'S.IVA RX'));
1126end;
1127
1128procedure TfrmODMedIV.cboDurationChange(Sender: TObject);
1129begin
1130 inherited;
1131 if (FOriginalDurationType > -1) and (FOriginalDurationType <> cboDuration.ItemIndex) then
1132 begin
1133 self.txtXDuration.Text := '';
1134 FOriginalDurationType := cboDuration.ItemIndex;
1135 end;
1136 if (FOriginalDurationType = -1) and (cboDuration.ItemIndex > -1) then FOriginalDurationType := cboDuration.ItemIndex;
1137 controlchange(sender);
1138end;
1139
1140procedure TfrmODMedIV.cboDurationEnter(Sender: TObject);
1141begin
1142 inherited;
1143 FOriginalDurationType := cboDuration.ItemIndex;
1144end;
1145
1146
1147procedure TfrmODMedIV.cboInfusionTimeChange(Sender: TObject);
1148begin
1149 inherited;
1150 if (FOriginalInfusionType > -1) and (FOriginalInfusionType <> cboInfusionTime.ItemIndex) then
1151 begin
1152 self.txtRate.Text := '';
1153 FOriginalInfusionType := cboInfusionTime.ItemIndex;
1154 end;
1155 if (FOriginalInfusionType = -1) and (cboInfusionTime.ItemIndex > -1) then FOriginalInfusionType := cboInfusionTime.ItemIndex;
1156 ControlChange(Sender);
1157end;
1158
1159procedure TfrmODMedIV.cboInfusionTimeEnter(Sender: TObject);
1160begin
1161 inherited;
1162 FOriginalInfusionType := self.cboInfusionTime.ItemIndex;
1163end;
1164
1165procedure TfrmODMedIV.cboPriorityChange(Sender: TObject);
1166begin
1167 inherited;
1168 ControlChange(sender);
1169end;
1170
1171procedure TfrmODMedIV.cboPriorityExit(Sender: TObject);
1172begin
1173 inherited;
1174 if cboPriority.Text = '' then
1175 begin
1176 infoBox('Priority must have a value assigned to it', 'Warning', MB_OK);
1177 cboPriority.SetFocus;
1178 end;
1179end;
1180
1181procedure TfrmODMedIV.cboRouteChange(Sender: TObject);
1182begin
1183 inherited;
1184 if cboRoute.ItemIndex = cboRoute.Items.IndexOf('OTHER') then cboRouteClick(cboRoute);
1185 ControlChange(sender);
1186end;
1187
1188procedure TfrmODMedIV.cboRouteClick(Sender: TObject);
1189var
1190otherRoute, temp: string;
1191idx, oidx: integer;
1192begin
1193 inherited;
1194 oidx := cboRoute.Items.IndexOf('OTHER');
1195 if oidx = -1 then exit;
1196
1197 if cboRoute.ItemIndex = oidx then
1198 begin
1199 otherRoute := CreateOtherRoute;
1200 if length(otherRoute) > 1 then
1201 begin
1202 idx := cboRoute.Items.IndexOf(Piece(OtherRoute, U, 2));
1203 if idx > -1 then
1204 begin
1205 temp := cboRoute.Items.Strings[idx];
1206 //setPiece(temp,U,5,'1');
1207 cboRoute.Items.Strings[idx] := temp;
1208 end
1209 else
1210 begin
1211 cboRoute.Items.Add(otherRoute);
1212 idx := cboRoute.Items.IndexOf(Piece(OtherRoute, U, 2));
1213 end;
1214 cboRoute.ItemIndex := idx;
1215 end
1216 else
1217 begin
1218 cboRoute.ItemIndex := -1;
1219 cboRoute.SetFocus;
1220 end;
1221 end;
1222end;
1223
1224procedure TfrmODMedIV.cboRouteExit(Sender: TObject);
1225begin
1226 inherited;
1227(* if (cboRoute.Text <> '') and (cboRoute.ItemIndex = -1) then
1228 begin
1229 infoBox(TX_BAD_ROUTE,'Warning',MB_OK);
1230 cboRoute.SetFocus;
1231 end; *)
1232end;
1233
1234procedure TfrmODMedIV.cboAdditiveMouseClick(Sender: TObject);
1235var
1236 AnIVComponent: TIVComponent;
1237 x, routeIEN: string;
1238begin
1239 inherited;
1240 if cboAdditive.ItemIEN <= 0 then Exit;
1241 FInpatient := OrderForInpatient;
1242 if not FInpatient then
1243 begin
1244 if DEACheckFailedForIVOnOutPatient(cboAdditive.ItemIEN,'A') then
1245 begin
1246 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
1247 cboAdditive.Text := '';
1248 Exit;
1249 end;
1250 end else
1251 begin
1252 if DEACheckFailed(cboAdditive.ItemIEN, FInpatient) then
1253 begin
1254 InfoBox(TX_NO_DEA, TC_NO_DEA, MB_OK);
1255 cboAdditive.Text := '';
1256 Exit;
1257 end;
1258 end;
1259 routeIEN := Piece(cboAdditive.Items.Strings[cboAdditive.itemindex],U,4);
1260 x := AmountsForIVFluid(cboAdditive.ItemIEN, 'A');
1261 AnIVComponent := TIVComponent.Create;
1262 AnIVComponent.IEN := cboAdditive.ItemIEN;
1263 AnIVComponent.Name := Piece(cboAdditive.Items[cboAdditive.ItemIndex], U, 3);
1264 AnIVComponent.Fluid := 'A';
1265 AnIVComponent.Amount := 0;
1266 AnIVComponent.Units := Piece(x, U, 1);
1267 AnIVComponent.Volumes := '';
1268 cboAdditive.ItemIndex := -1;
1269 with grdSelected do
1270 begin
1271 if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
1272 Objects[0, RowCount - 1] := AnIVComponent;
1273 Cells[0, RowCount - 1] := AnIVComponent.Name;
1274 Cells[2, RowCount - 1] := AnIVComponent.Units;
1275 Row := RowCount - 1;
1276 Col := 1;
1277 end;
1278 Application.ProcessMessages; //CQ: 10157
1279 ClickOnGridCell;
1280 updateRoute;
1281 ControlChange(Sender);
1282 //UpdateRoute(RouteIEN);
1283end;
1284
1285procedure TfrmODMedIV.cboAdditiveExit(Sender: TObject);
1286begin
1287 inherited;
1288 if (cboAdditive.ItemIEN > 0) and (EnterIsPressed) then
1289 cboAdditiveMouseClick(Self);
1290end;
1291
1292{ grdSelected events }
1293
1294procedure TfrmODMedIV.ClearAllFields;
1295begin
1296 self.cboType.ItemIndex := -1;
1297 self.cboType.Text := '';
1298 self.memComments.Text := '';
1299 self.txtRate.Text := '';
1300 self.txtXDuration.text := '';
1301 self.cboDuration.ItemIndex := -1;
1302 self.cboDuration.Text := '';
1303 self.txtAllIVRoutes.Visible := false;
1304 self.FInitialOrderID := True;
1305 cbotypeChange(self.cboType);
1306 if self.cboroute.Items.Count > 0 then self.cboRoute.Clear;
1307end;
1308
1309procedure TfrmODMedIV.ClickOnGridCell;
1310var
1311 AnIVComponent: TIVComponent;
1312
1313 procedure PlaceControl(AControl: TWinControl);
1314 var
1315 ARect: TRect;
1316 begin
1317 with AControl do
1318 begin
1319 ARect := grdSelected.CellRect(grdSelected.Col, grdSelected.Row);
1320 SetBounds(ARect.Left + grdSelected.Left + 1, ARect.Top + grdSelected.Top + 1,
1321 ARect.Right - ARect.Left + 1, ARect.Bottom - ARect.Top + 1);
1322 BringToFront;
1323 Show;
1324 SetFocus;
1325 if AControl is TComboBox then //CQ: 10157
1326 TComboBox(AControl).DroppedDown := True;
1327 end;
1328 end;
1329
1330begin
1331 AnIVComponent := TIVComponent(grdSelected.Objects[0, grdSelected.Row]);
1332 if (AnIVComponent = nil) or (grdSelected.Col = 0) then Exit;
1333 // allow selection if more the 1 unit to choose from
1334 if (grdSelected.Col = 2) and (Length(Piece(AnIVComponent.Units, U, 2)) > 0) then
1335 begin
1336 PiecesToList(AnIVComponent.Units, U, cboSelected.Items);
1337 cboSelected.ItemIndex := cboSelected.Items.IndexOf(grdSelected.Cells[grdSelected.Col, grdSelected.Row]);
1338 cboSelected.Tag := (grdSelected.Col * 256) + grdSelected.Row;
1339 PlaceControl(cboSelected);
1340 end;
1341 // allow selection if more than 1 volume to choose from
1342 if (grdSelected.Col = 1) and (Length(Piece(AnIVComponent.Volumes, U, 2)) > 0) then
1343 begin
1344 PiecesToList(AnIVComponent.Volumes, U, cboSelected.Items);
1345 cboSelected.ItemIndex := cboSelected.Items.IndexOf(grdSelected.Cells[grdSelected.Col, grdSelected.Row]);
1346 cboSelected.Tag := (grdSelected.Col * 256) + grdSelected.Row;
1347 PlaceControl(cboSelected);
1348 end;
1349 // display text box to enter strength if the entry is an additive
1350 if (grdSelected.Col = 1) and (AnIVComponent.Fluid = 'A') then
1351 begin
1352 txtSelected.Text := grdSelected.Cells[grdSelected.Col, grdSelected.Row];
1353 txtSelected.Tag := (grdSelected.Col * 256) + grdSelected.Row;
1354 PlaceControl(txtSelected);
1355 end;
1356end;
1357
1358procedure TfrmODMedIV.txtSelectedChange(Sender: TObject); // text editor for grid
1359begin
1360 inherited;
1361 with txtSelected do
1362 begin
1363 if Tag < 0 then Exit;
1364 grdSelected.Cells[Tag div 256, Tag mod 256] := Text;
1365 end;
1366 ControlChange(Sender);
1367end;
1368
1369procedure TfrmODMedIV.txtSelectedExit(Sender: TObject);
1370begin
1371 inherited;
1372 with txtSelected do
1373 begin
1374 grdSelected.Cells[Tag div 256, Tag mod 256] := Text;
1375 Tag := -1;
1376 Hide;
1377 end;
1378end;
1379
1380procedure TfrmODMedIV.cboScheduleChange(Sender: TObject);
1381begin
1382 inherited;
1383 if self.txtXDuration.Enabled = true then
1384 begin
1385 self.txtXDuration.Text := '';
1386 self.cboDuration.ItemIndex := -1;
1387 end;
1388 if self.cboSchedule.ItemIndex > -1 then updateDuration(Piece(cboSchedule.Items.Strings[cboSchedule.itemindex],U,3));
1389 ControlChange(sender);
1390end;
1391
1392procedure TfrmODMedIV.cboScheduleClick(Sender: TObject);
1393var
1394 othSch: string;
1395 idx, i : integer;
1396begin
1397 inherited;
1398 if cboSchedule.ItemIndex = cboSchedule.Items.IndexOf('Other') then
1399 begin
1400 othSch := CreateOtherSchedule;
1401 if length(trim(othSch)) > 1 then
1402 begin
1403 cboSchedule.Items.Add(othSch + U + U + NSSScheduleType + U + NSSAdminTime);
1404 idx := -1;
1405 for I := 0 to cboSchedule.Items.Count - 1 do
1406 if Piece(cboSchedule.Items.Strings[i], U, 1) = othSch then
1407 begin
1408 idx := i;
1409 break;
1410 end;
1411 //idx := cboSchedule.Items.IndexOfName(othSch);
1412 cboSchedule.ItemIndex := idx;
1413 end;
1414 end
1415 else
1416 begin
1417 NSSAdminTime := '';
1418 NSSScheduleType := '';
1419 end;
1420end;
1421
1422procedure TfrmODMedIV.cboScheduleExit(Sender: TObject);
1423begin
1424 inherited;
1425 if (cboSchedule.ItemIndex = -1) and (cboSchedule.Text <> '') then
1426 begin
1427 infoBox('Please select a valid schedule from the list.'+ CRLF + CRLF +
1428 'If you would like to create a Day-of-Week schedule please select ''OTHER'' from the list.',
1429 'Incorrect Schedule.', MB_OK);
1430 cboSchedule.Text := '';
1431 cboSchedule.SetFocus;
1432 end;
1433end;
1434
1435procedure TfrmODMedIV.cboSelectedChange(Sender: TObject); // combo editor for grid
1436begin
1437 inherited;
1438 with cboSelected do
1439 begin
1440 if Tag < 0 then Exit;
1441 grdSelected.Cells[Tag div 256, Tag mod 256] := Text;
1442 end;
1443 ControlChange(Sender);
1444end;
1445
1446procedure TfrmODMedIV.cboSelectedExit(Sender: TObject);
1447begin
1448 inherited;
1449 with cboSelected do
1450 begin
1451 grdSelected.Cells[Tag div 256, Tag mod 256] := Text;
1452 Tag := -1;
1453 Hide;
1454 end;
1455end;
1456
1457procedure TfrmODMedIV.cmdRemoveClick(Sender: TObject); // remove button for grid
1458var
1459 i, stRow, stRowCount: Integer;
1460begin
1461 inherited;
1462 with grdSelected do
1463 begin
1464 if Row < 0 then Exit;
1465 stRow := Row;
1466 stRowCount := RowCount;
1467 if Objects[0, Row] <> nil then TIVComponent(Objects[0, Row]).Free;
1468 for i := Row to RowCount - 2 do Rows[i] := Rows[i + 1];
1469 Rows[RowCount - 1].Clear;
1470 RowCount := RowCount - 1;
1471 end;
1472 updateRoute;
1473 if (stRowCount = 1) and (stRow = 0) then
1474 begin
1475 //self.cboRoute.ItemIndex := -1;
1476 ClearAllFields;
1477 end;
1478 ControlChange(Sender);
1479end;
1480
1481{ update Responses & Create Order Text }
1482
1483procedure TfrmODMedIV.ControlChange(Sender: TObject);
1484var
1485 i, CurAdd, CurBase, idx: Integer;
1486 adminTime,x,xlimIn,xLimEx,eSch,iSch,iType, tmpdur, tmpSch, tmpRate: string;
1487 AnIVComponent: TIVComponent;
1488 FQOSchedule: TResponse;
1489
1490 function IsNumericRate(const x: string): Boolean;
1491 var
1492 i: Integer;
1493 begin
1494 Result := True;
1495 for i := 1 to Length(x) do if not (x[i] in ['0'..'9','.']) then Result := False;
1496 end;
1497
1498begin
1499 inherited;
1500 if Changing then Exit;
1501 loadExpectFirstDose;
1502// FQOSchedule := TResponse.Create;
1503 FQOSchedule := Responses.FindResponseByName('SCHEDULE',1);
1504 if FQOSchedule <> nil then
1505 begin
1506 eSch := FQOSchedule.EValue;
1507 iSch := FQOSchedule.IValue;
1508 end;
1509 //if Sender <> Self then Responses.Clear; // Sender=Self when called from SetupDialog
1510 Responses.Clear; // want this to clear even after SetupDialog in case instances don't match
1511 CurAdd := 1; CurBase := 1;
1512 tmpRate := '';
1513 with grdSelected do for i := 0 to RowCount - 1 do
1514 begin
1515 AnIVComponent := TIVComponent(Objects[0, i]);
1516 if AnIVComponent = nil then Continue;
1517 with AnIVComponent do
1518 begin
1519 if Fluid = 'B' then // Solutions
1520 begin
1521 if IEN > 0 then Responses.Update('ORDERABLE', CurBase, IntToStr(IEN), Name);
1522 if Length(Cells[1,i]) > 0 then Responses.Update('VOLUME', CurBase, Cells[1,i], Cells[1,i]);
1523 Inc(CurBase);
1524 end; {if Fluid B}
1525 if Fluid = 'A' then // Additives
1526 begin
1527 if IEN > 0 then Responses.Update('ADDITIVE', CurAdd, IntToStr(IEN), Name);
1528 if Length(Cells[1,i]) > 0 then Responses.Update('STRENGTH', CurAdd, Cells[1,i], Cells[1,i]);
1529 if Length(Cells[2,i]) > 0 then Responses.Update('UNITS', CurAdd, Cells[2,i], Cells[2,i]);
1530 Inc(CurAdd);
1531 end; {if Fluid A}
1532 end; {with AnIVComponent}
1533 end; {with grdSelected}
1534 x := txtRate.Text;
1535 xlimIn := '';
1536 xlimEx := '';
1537 if length(txtXDuration.Text) > 0 then
1538 begin
1539 tmpDur := LowerCase(cboDuration.Text);
1540 if (tmpDur = 'l') or (tmpDur = 'ml') then
1541 begin
1542 xlimEx := 'with total volume ' + txtXDuration.Text + self.cboDuration.items.strings[self.cboDuration.itemindex];
1543 xlimIn := 'with total volume ' + txtXDuration.Text + self.cboDuration.items.strings[self.cboDuration.itemindex];
1544 end
1545 else if (tmpDur = 'days') or (tmpDur = 'hours') then
1546 begin
1547 xlimEx := 'for ' + txtXDuration.Text + ' ' + self.cboDuration.items.strings[self.cboDuration.itemindex];
1548 xlimIn := 'for ' + txtXDuration.Text + ' ' + self.cboDuration.items.strings[self.cboDuration.itemindex];
1549 end
1550 else if tmpDur = 'doses' then
1551 begin
1552 xlimEx := 'for a total of ' + txtXDuration.Text + ' ' + self.cboDuration.items.strings[self.cboDuration.itemindex];
1553 xlimIn := 'for a total of ' + txtXDuration.Text + ' ' + self.cboDuration.items.strings[self.cboDuration.itemindex];
1554 end
1555 else begin
1556 xlimIn := '';
1557 xlimEx := '';
1558 end;
1559 end;
1560 if cboType.Text = 'Intermittent' then iType := 'I'
1561 else iType := 'C';
1562 Responses.Update('TYPE',1,iType,cboType.Text);
1563 Responses.Update('ROUTE',1,cboRoute.ItemID,cboRoute.Text);
1564 tmpSch := UpperCase(Trim(cboSchedule.Text));
1565 if chkPRN.Checked then tmpSch := tmpSch + ' PRN';
1566 if UpperCase(Copy(tmpSch, Length(tmpSch) - 6, Length(tmpSch))) = 'PRN PRN'
1567 then tmpSch := Copy(tmpSch, 1, Length(tmpSch) - 4);
1568 Responses.Update('SCHEDULE',1,tmpSch,tmpSch);
1569 (*adminTime := Piece(lblAdminTime.Caption,':',2);
1570 adminTime := Copy(adminTime,1,Length(adminTime));
1571 if (Action in [ORDER_COPY, ORDER_EDIT]) and ((FAdminTimeDelay <> '') or (FAdminTimeClinic <> '')) and
1572 (cboSchedule.ItemIndex = FOriginalScheduleIndex) then Responses.Update('ADMIN',1,FOriginalAdminTime,FOriginalAdminTime)
1573 else Responses.Update('ADMIN',1,adminTime,adminTime);*)
1574 idx := self.cboSchedule.ItemIndex;
1575 if idx > -1 then
1576 begin
1577 adminTime := Piece(lblAdminTime.Caption,':',2);
1578 adminTime := Copy(adminTime,2,Length(adminTime));
1579 if FAdminTimeText <> '' then AdminTime := '';
1580 if AdminTime = 'Not Defined' then AdminTime := '';
1581 Responses.Update('ADMIN',1,adminTime,adminTime);
1582 end;
1583 if IsNumericRate(x) then
1584 begin
1585 if cboInfusionTime.Enabled = true then
1586 begin
1587 idx := cboInfusionTime.Items.IndexOf(cboInfusionTime.Text);
1588 if idx > -1 then x := x + ' ' + cboInfusionTime.Items.Strings[idx];
1589 tmpRate := 'Infuse Over ' + x;
1590 end
1591 else
1592 if pos('ml/hr', x)= 0 then x := x + ' ml/hr';
1593 end;
1594 if (Pos('@',x)>0) and (Piece(x,'@',1) = IntToStr(StrToIntDef(Piece(x,'@',1), -1))) and (cboInfusionTime.Enabled = false) then
1595 begin
1596 if Pos('ml/hr', x) = 0 then
1597 x := Piece(x,'@',1) + ' ml/hr@' + Copy(x, Pos('@',x) + 1, Length(x));
1598 end;
1599 with txtRate do if (Length(Text) > 0) then
1600 begin
1601 if tmpRate = '' then Responses.Update('RATE', 1, x, x)
1602 else Responses.Update('RATE', 1, 'INFUSE OVER ' + x, tmpRate);
1603 end;
1604 with cboPriority do if ItemIndex > -1 then Responses.Update('URGENCY', 1, ItemID, Text);
1605 if Length(xlimIn)>0 then Responses.Update('DAYS',1, xlimIn, xlimEx);
1606 with memComments do if GetTextLen > 0 then Responses.Update('COMMENT', 1, TX_WPTYPE, Text);
1607 if (chkDoseNow.Visible = True) and (chkDoseNow.Checked = True) then
1608 Responses.Update('NOW', 1, '1', 'NOW')
1609 else Responses.Update('NOW', 1, '', '');
1610 memOrder.Text := Responses.OrderText;
1611 (* (Length(eSch)>0) or (Length(iSch)>0) then
1612 Responses.Update('SCHEDULE',1,iSch,eSch); *)
1613end;
1614
1615function TfrmODMedIV.CreateOtherRoute: string;
1616var
1617 aRoute: string;
1618begin
1619 aRoute := '';
1620 Result := '';
1621 if not ShowOtherRoutes(aRoute) then
1622 begin
1623 cboRoute.ItemIndex := -1;
1624 cboRoute.Text := '';
1625 end
1626 else
1627 begin
1628 Result := aRoute;
1629 end;
1630end;
1631
1632function TfrmODMedIV.CreateOtherSchedule: string;
1633var
1634 aSchedule: string;
1635begin
1636 aSchedule := '';
1637 if not ShowOtherSchedule(aSchedule) then
1638 begin
1639 cboSchedule.ItemIndex := -1;
1640 cboSchedule.Text := '';
1641 end
1642 else
1643 begin
1644 Result := Piece(aSchedule,U,1);
1645 NSSAdminTime := Piece(aschedule,u,2);
1646 NSSScheduleType := Piece(ASchedule, U, 3);
1647 end;
1648end;
1649
1650procedure TfrmODMedIV.grdSelectedDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
1651 State: TGridDrawState);
1652begin
1653 inherited;
1654 if Sender = ActiveControl then Exit;
1655 if not (gdSelected in State) then Exit;
1656 with Sender as TStringGrid do
1657 begin
1658 Canvas.Brush.Color := Color;
1659 Canvas.Font := Font;
1660 Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
1661 end;
1662end;
1663
1664procedure TfrmODMedIV.SetFontSize( FontSize: integer);
1665begin
1666 inherited SetFontSize( FontSize );
1667 DoSetFontSize( FontSize );
1668end;
1669
1670procedure TfrmODMedIV.DisplayDoseNow(Status: boolean);
1671begin
1672 if self.EvtID > 0 then Status := false;
1673 if status = false then
1674 begin
1675 if (self.chkDoseNow.Visible = true) and (self.chkDoseNow.Checked = true) then self.chkDoseNow.Checked := false;
1676 self.chkDoseNow.Visible := false;
1677 end;
1678 if status = true then self.chkDoseNow.Visible := true;
1679end;
1680
1681procedure TfrmODMedIV.DoSetFontSize( FontSize: integer);
1682begin
1683 tabFluid.TabHeight := Abs(Font.Height) + 4;
1684 grdSelected.DefaultRowHeight := Abs(Font.Height) + 8;
1685end;
1686
1687procedure TfrmODMedIV.FormKeyDown(Sender: TObject; var Key: Word;
1688 Shift: TShiftState);
1689begin
1690 inherited;
1691 if (Key = VK_TAB) and (ssCtrl in Shift) then
1692 begin
1693 //Back-tab works the same as forward-tab because there are only two tabs.
1694 tabFluid.TabIndex := (tabFluid.TabIndex + 1) mod tabFluid.Tabs.Count;
1695 Key := 0;
1696 tabFluidChange(tabFluid);
1697 end;
1698end;
1699
1700procedure TfrmODMedIV.grdSelectedKeyPress(Sender: TObject; var Key: Char);
1701begin
1702 inherited;
1703 ClickOnGridCell;
1704end;
1705
1706procedure TfrmODMedIV.grdSelectedMouseDown(Sender: TObject;
1707 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
1708begin
1709 inherited;
1710 ClickOnGridCell;
1711end;
1712
1713procedure TfrmODMedIV.txtXDurationChange(Sender: TObject);
1714begin
1715 inherited;
1716 if Changing then Exit;
1717 ControlChange(Sender);
1718end;
1719
1720
1721procedure TfrmODMedIV.pnlXDurationEnter(Sender: TObject);
1722begin
1723 inherited;
1724 txtXDuration.SetFocus;
1725end;
1726
1727procedure TfrmODMedIV.SetLimitationControl(aValue: string);
1728var
1729 limitUnit,limitValue,tempval: string;
1730begin
1731 limitUnit := '';
1732 limitValue := '';
1733 tempVal := '';
1734 if pos('dose',AValue)>0 then
1735 begin
1736 limitValue := Piece(aValue,' ',5);
1737 limitUnit := 'doses';
1738 end;
1739 if (( CharAt(aValue,1)= 'f') or ( CharAt(aValue,1)= 'F')) and (pos('dose',aValue)=0) then //days, hours
1740 begin
1741 limitValue := Piece(aValue,' ',2);
1742 limitUnit := Piece(aValue,' ',3);
1743 end;
1744 if (CharAt(aValue,1)= 'w') or (CharAt(aValue,1)= 'W') then //L, ml
1745 begin
1746 tempval := Piece(aValue,' ',4);
1747 limitValue := FloatToStr(ExtractFloat(tempVal));
1748 limitUnit := Copy(tempVal,length(limitValue)+1,Length(tempVal));
1749 end;
1750 if isNumeric(CharAt(aValue,1)) then
1751 begin
1752 if LeftStr(avalue,1) = '0' then AValue := Copy(aValue,2,Length(aValue));
1753 limitValue := FloatToStr(ExtractFloat(aValue));
1754 limitUnit := Copy(aValue,length(limitValue)+1,Length(aValue));
1755 if limitUnit = 'D' then limitUnit := 'days'
1756 else if limitUnit = 'H' then limitUnit := 'hours'
1757 else if limitUnit = 'ML' then limitUnit := 'ml';
1758 end;
1759 if ( Length(limitUnit)> 0) and ( (Length(limitValue) > 0 ) ) then
1760 begin
1761 txtXDuration.Text := limitValue;
1762 if Trim(UpperCase(limitUnit))='CC' then
1763 limitUnit := 'ml';
1764 cboduration.text := limitUnit;
1765 if cboDuration.Text <> '' then cboDuration.ItemIndex := cboDuration.Items.IndexOf(cboDuration.Text)
1766 end;
1767
1768end;
1769
1770procedure TfrmODMedIV.SetSchedule(const x: string);
1771var
1772NonPRNPart,tempSch: string;
1773idx: integer;
1774begin
1775 cboSchedule.ItemIndex := -1;
1776 chkPRN.Checked := False;
1777 //Check to see if schedule is already define in the schedule list
1778 idx := cboSchedule.Items.IndexOf(X);
1779 if idx > -1 then
1780 begin
1781 cboSchedule.ItemIndex := idx;
1782 exit;
1783 end;
1784 //Check to see if schedule is a Day-of-Week Schedule (MO-WE-FR@BID)
1785 if (Pos('@', x) > 0) then
1786 begin
1787 tempSch := Piece(x, '@', 2);
1788 idx := cboSchedule.Items.IndexOf(tempSch);
1789 if idx > -1 then
1790 begin
1791 //tempSch := U + Piece(x, '@', 1) + '@' + Pieces(cboSchedule.Items.Strings[idx], U, 2, 5);
1792 tempSch := Piece(x, '@', 1) + '@' + cboSchedule.Items.Strings[idx];
1793 cboSchedule.Items.Add(tempSch);
1794 cboSchedule.Text := (Piece(tempSch,U,1));
1795 cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(Piece(tempSch,U,1));
1796 EXIT;
1797 end;
1798 //Check to see if schedule is a Day-of-Week PRN Schedule (MO-WE-FR@BID PRN)
1799 if Pos('PRN', tempSch) > 0 then
1800 begin
1801 NonPRNPart := Trim(Copy(tempSch, 1, Pos('PRN', tempSch) - 1));
1802 idx := cboSchedule.Items.IndexOf(NonPRNPart);
1803 if idx > -1 then
1804 begin
1805 //tempSch := U + Piece(x, '@', 1) + '@' + Pieces(cboSchedule.Items.Strings[idx], U, 2, 5);
1806 tempSch := Piece(x, '@', 1) + '@' + cboSchedule.Items.Strings[idx];
1807 cboSchedule.Items.Add(tempSch);
1808 cboSchedule.Text := (Piece(tempSch,U,1));
1809 cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(Piece(tempSch, U, 1));
1810 chkPRN.Checked := True;
1811 EXIT;
1812 end
1813 else
1814 //Add Day-of-Week PRN schedule built off Time Prompt (MO-WE-FR@0800-1000 PRN)
1815 begin
1816 NonPRNPart := Trim(Copy(X, 1, Pos('PRN', X) - 1));
1817 chkPRN.Checked := True;
1818 //cboSchedule.Items.Add(U + NonPRNPart + U + U + U + AdminTime);
1819 //cboSchedule.Items.Add(U + NonPRNPart + U + U + U + Piece(NonPRNPart, '@', 2));
1820 cboSchedule.Items.Add(NonPRNPart + U + U + U + Piece(NonPRNPart, '@', 2));
1821 cboSchedule.Text := NonPRNPart;
1822 cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(NonPRNPart);
1823 EXIT;
1824 end;
1825 end;
1826 //Add Non PRN Day-of-Week Schedule built off Time Prompt (MO-WE-FR@0800-1000)
1827 //cboSchedule.Items.Add(U + x + U + U + U + AdminTime);
1828 //cboSchedule.Items.Add(U + x + U + U + U + tempSch);
1829 cboSchedule.Items.Add(x + U + U + U + tempSch);
1830 cboSchedule.Text := x;
1831 cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(X);
1832 end
1833 else
1834 begin
1835 //Handle standard schedule mark as PRN (Q4H PRN)
1836 if Pos('PRN', X) > 0 then
1837 begin
1838 NonPRNPart := Trim(Copy(X, 1, Pos('PRN', X) - 1));
1839 idx := cboSchedule.Items.IndexOf(NonPRNPart);
1840 if idx > -1 then
1841 begin
1842 cboSchedule.ItemIndex := idx;
1843 tempSch := cboSchedule.Items.Strings[idx];
1844 //setPiece(tempSch,U,5,AdminTime);
1845 cboSchedule.Items.Strings[idx] := tempSch;
1846 chkPRN.Checked := True;
1847 exit;
1848 end;
1849 end;
1850 end;
1851end;
1852
1853
1854procedure TfrmODMedIV.txtXDurationExit(Sender: TObject);
1855var
1856 Code: double;
1857begin
1858 inherited;
1859 if (txtXDuration.Text <> '0') and (txtXDuration.Text <> '') then
1860 begin
1861 try
1862 code := StrToFloat(txtXDuration.Text);
1863 except
1864 code := 0;
1865 end;
1866 if code < 0.0001 then
1867 begin
1868 ShowMsg('Can not save order.' + #13#10 + 'Reason: Invalid Duration or Total Volume!');
1869 txtXDuration.Text := '';
1870 txtXDuration.SetFocus;
1871 Exit;
1872 end;
1873 end;
1874 try
1875 if (Length(txtXDuration.Text)>0) and (StrToFloat(txtXDuration.Text)<0) then
1876 begin
1877 ShowMsg('Can not save order.' + #13#10 + 'Reason: Invalid Duration or total volume!');
1878 txtXDuration.Text := '';
1879 txtXDuration.SetFocus;
1880 Exit;
1881 end;
1882 except
1883 txtXDuration.Text := '';
1884 end;
1885 ControlChange(Sender);
1886end;
1887
1888procedure TfrmODMedIV.UpdateDuration(SchType: string);
1889begin
1890if SchType = 'O' then
1891 begin
1892 self.cboDuration.ItemIndex := -1;
1893 self.txtXDuration.Text := '';
1894 self.cboDuration.Enabled := false;
1895 self.txtXDuration.Enabled := false;
1896 self.lblLimit.Enabled := false;
1897 end
1898else
1899 begin
1900 self.cboDuration.Enabled := true;
1901 self.txtXDuration.Enabled := true;
1902 self.lblLimit.Enabled := true;
1903 end;
1904end;
1905
1906procedure TfrmODMedIV.UpdateRoute;
1907var
1908AnIVComponent: TIVComponent;
1909i: integer;
1910OrderIds, TempIVRoute: TStringList;
1911Default: boolean;
1912begin
1913 if self.grdSelected.RowCount > 0 then self.txtAllIVRoutes.Visible := True;
1914 TempIVRoute := TStringList.Create;
1915 for I := (self.cboRoute.Items.Count -1) downto 0 do
1916 begin
1917 if Piece(self.cboRoute.Items.Strings[i], U, 5) = '1' then
1918 TempIVRoute.Add(self.cboRoute.Items.Strings[i]);
1919 self.cboRoute.Items.Delete(i);
1920 end;
1921 if self.cboRoute.ItemIndex = -1 then self.cboRoute.Text := '';
1922 OrderIds := TStringList.Create;
1923 for i := 0 to self.grdSelected.RowCount -1 do
1924 begin
1925 AniVComponent := TIVComponent(self.grdSelected.Objects[0, i]);
1926 if AnIVComponent <> nil then orderIds.Add(InttoStr(AniVComponent.IEN));
1927 end;
1928 if OrderIds.Count > 0 then
1929 begin
1930 if (self.FInitialOrderID = True) and (self.grdSelected.RowCount = 1) then Default := True
1931 else Default := False;
1932 LoadDosageFormIVRoutes(self.cboRoute.Items, OrderIds, Default);
1933 if default = True then
1934 begin
1935 for I := 0 to cboRoute.items.Count - 1 do
1936 if Piece(cboRoute.Items.Strings[i], U, 5) = 'D' then
1937 begin
1938 cboRoute.ItemIndex := i;
1939 break;
1940 end;
1941 self.FInitialOrderID := false;
1942 end;
1943 OrderIds.Free;
1944 end;
1945 if TempIVRoute.Count > 0 then
1946 begin
1947 for I := 0 to tempIVRoute.Count - 1 do cboRoute.Items.Add(tempIVRoute.Strings[i]);
1948 TempIVRoute.Free;
1949 end;
1950 cboRoute.Items.Add(U + 'OTHER');
1951end;
1952
1953
1954procedure TfrmODMedIV.txtAllIVRoutesClick(Sender: TObject);
1955var
1956i: integer;
1957begin
1958 inherited;
1959 if MessageDlg('You can also select "OTHER" from the Route list'
1960 + ' to select a Route from the Expanded Med Route List.'
1961 + #13#10 + 'Click OK to launch the Expanded Med Route List.',
1962 mtInformation, [mbOK, mbCancel],0) = mrOK then
1963 begin
1964 for I := 0 to cboRoute.Items.Count - 1 do if cboRoute.Items.Strings[i] = U + 'OTHER' then break;
1965 cboRoute.ItemIndex := i;
1966 cboRouteClick(self);
1967 cboRouteChange(self.cboRoute);
1968 end;
1969end;
1970
1971procedure TfrmODMedIV.txtNSSClick(Sender: TObject);
1972var
1973i: integer;
1974begin
1975 inherited;
1976 if MessageDlg('You can also select ' + '"' + 'Other' + '"' + ' from the schedule list'
1977 + ' to create a day-of-week schedule.'
1978 + #13#10 + 'Click OK to launch schedule builder',
1979 mtInformation, [mbOK, mbCancel],0) = mrOK then
1980 begin
1981 //cboSchedule.Items.Add(U + 'OTHER');
1982 for I := 0 to cboSchedule.Items.Count - 1 do if cboSchedule.Items.Strings[i] = 'OTHER' then break;
1983 cboSchedule.ItemIndex := i;
1984 //cboSchedule.SelectByID(U+'OTHER');
1985 cboScheduleClick(Self);
1986 cboScheduleChange(self.cboSchedule);
1987 end;
1988end;
1989
1990procedure TfrmODMedIV.txtRateChange(Sender: TObject);
1991begin
1992 inherited;
1993 if Changing then Exit;
1994 ControlChange(Sender);
1995end;
1996
1997end.
Note: See TracBrowser for help on using the repository browser.