Module

fODMedIV

Path

C:\CPRS\CPRS30\Orders\fODMedIV.pas

Last Modified

7/15/2014 3:26:42 PM

Units Used in Interface

Name Comments
fIVRoutes -
fODBase -

Units Used in Implementation

Name Comments
fFrame -
fOtherSchedule -
rCore -
rODBase -
rODMeds -
uConst -
uCore -

Classes

Name Comments
TfrmODMedIV -
TIVComponent -

Procedures

Name Owner Declaration Scope Comments
cboAddFreqCloseUp TfrmODMedIV procedure cboAddFreqCloseUp(Sender: TObject); Public/Published -
cboAddFreqKeyDown TfrmODMedIV procedure cboAddFreqKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboAdditiveExit TfrmODMedIV procedure cboAdditiveExit(Sender: TObject); Public/Published -
cboAdditiveMouseClick TfrmODMedIV procedure cboAdditiveMouseClick(Sender: TObject); Public/Published -
cboAdditiveNeedData TfrmODMedIV procedure cboAdditiveNeedData(Sender: TObject; const StartFrom: string; Direction, InsertAt: Integer); Public/Published CboAdditive events
cboDurationChange TfrmODMedIV procedure cboDurationChange(Sender: TObject); Public/Published -
cboDurationEnter TfrmODMedIV procedure cboDurationEnter(Sender: TObject); Public/Published -
cboInfusionTimeChange TfrmODMedIV procedure cboInfusionTimeChange(Sender: TObject); Public/Published -
cboInfusionTimeEnter TfrmODMedIV procedure cboInfusionTimeEnter(Sender: TObject); Public/Published -
cboPriorityChange TfrmODMedIV procedure cboPriorityChange(Sender: TObject); Public/Published -
cboPriorityExit TfrmODMedIV procedure cboPriorityExit(Sender: TObject); Public/Published -
cboPriorityKeyUp TfrmODMedIV procedure cboPriorityKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboRouteChange TfrmODMedIV procedure cboRouteChange(Sender: TObject); Public/Published -
cboRouteClick TfrmODMedIV procedure cboRouteClick(Sender: TObject); Public/Published -
cboRouteExit TfrmODMedIV procedure cboRouteExit(Sender: TObject); Public/Published -
cboRouteKeyDown TfrmODMedIV procedure cboRouteKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboRouteKeyUp TfrmODMedIV procedure cboRouteKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboScheduleChange TfrmODMedIV procedure cboScheduleChange(Sender: TObject); Public/Published -
cboScheduleClick TfrmODMedIV procedure cboScheduleClick(Sender: TObject); Public/Published -
cboScheduleExit TfrmODMedIV procedure cboScheduleExit(Sender: TObject); Public/Published -
cboScheduleKeyDown TfrmODMedIV procedure cboScheduleKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboScheduleKeyUp TfrmODMedIV procedure cboScheduleKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboSelectedCloseUp TfrmODMedIV procedure cboSelectedCloseUp(Sender: TObject); Public/Published -
cboSelectedKeyDown TfrmODMedIV procedure cboSelectedKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
cboSolutionExit TfrmODMedIV procedure cboSolutionExit(Sender: TObject); Public/Published -
cboSolutionMouseClick TfrmODMedIV procedure cboSolutionMouseClick(Sender: TObject); Public/Published -
cboSolutionNeedData TfrmODMedIV procedure cboSolutionNeedData(Sender: TObject; const StartFrom: string; Direction, InsertAt: Integer); Public/Published CboSolution events
cboTypeChange TfrmODMedIV procedure cboTypeChange(Sender: TObject); Public/Published -
cboTypeKeyDown TfrmODMedIV procedure cboTypeKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
chkDoseNowClick TfrmODMedIV procedure chkDoseNowClick(Sender: TObject); Public/Published SchID: integer;
chkPRNClick TfrmODMedIV procedure chkPRNClick(Sender: TObject); Public/Published -
ClearAllFields TfrmODMedIV procedure ClearAllFields; Private GrdSelected events
ClickOnGridCell TfrmODMedIV procedure ClickOnGridCell; Private -
cmdRemoveClick TfrmODMedIV procedure cmdRemoveClick(Sender: TObject); Public/Published Remove button for grid
ControlChange TfrmODMedIV procedure ControlChange(Sender: TObject); Public/Published Update Responses & Create Order Text
DisplayDoseNow TfrmODMedIV procedure DisplayDoseNow(Status: boolean); Private -
DoSetFontSize TfrmODMedIV procedure DoSetFontSize( FontSize: integer); Private -
FormCreate TfrmODMedIV procedure FormCreate(Sender: TObject); Public/Published Form methods
FormDestroy TfrmODMedIV procedure FormDestroy(Sender: TObject); Public/Published -
FormKeyDown TfrmODMedIV procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
FormKeyPress TfrmODMedIV procedure FormKeyPress(Sender: TObject; var Key: Char); Public/Published -
FormResize TfrmODMedIV procedure FormResize(Sender: TObject); Public/Published -
grdSelectedDrawCell TfrmODMedIV procedure grdSelectedDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); Public/Published -
grdSelectedKeyPress TfrmODMedIV procedure grdSelectedKeyPress(Sender: TObject; var Key: Char); Public/Published -
grdSelectedMouseDown TfrmODMedIV procedure grdSelectedMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
InitDialog TfrmODMedIV procedure InitDialog; override; Public TfrmODBase overrides
lblTypeHelpClick TfrmODMedIV procedure lblTypeHelpClick(Sender: TObject); Public/Published -
loadExpectFirstDose TfrmODMedIV procedure loadExpectFirstDose; Public/Published -
PlaceControl - procedure PlaceControl(AControl: TWinControl); Local -
pnlXDurationEnter TfrmODMedIV procedure pnlXDurationEnter(Sender: TObject); Public/Published -
SetCtrlAlt_L_LabelAccessText TfrmODMedIV procedure SetCtrlAlt_L_LabelAccessText(var Text: string; theLabel : TLabel); Private -
SetError - procedure SetError(const x: string); Local -
SetFontSize TfrmODMedIV procedure SetFontSize( FontSize: integer); override; Public -
SetLimitationControl TfrmODMedIV procedure SetLimitationControl(aValue: string); Private -
SetSchedule TfrmODMedIV procedure SetSchedule(const x: string); Public/Published -
SetupDialog TfrmODMedIV procedure SetupDialog(OrderAction: Integer; const ID: string); override; Public -
SetValuesFromResponses TfrmODMedIV procedure SetValuesFromResponses; Private FInitialOrderID: boolean;
tabFluidChange TfrmODMedIV procedure tabFluidChange(Sender: TObject); Public/Published TabFluid events
txtAllIVRoutesClick TfrmODMedIV procedure txtAllIVRoutesClick(Sender: TObject); Public/Published -
txtNSSClick TfrmODMedIV procedure txtNSSClick(Sender: TObject); Public/Published -
txtRateChange TfrmODMedIV procedure txtRateChange(Sender: TObject); Public/Published -
txtSelectedChange TfrmODMedIV procedure txtSelectedChange(Sender: TObject); Public/Published Text editor for grid
txtSelectedExit TfrmODMedIV procedure txtSelectedExit(Sender: TObject); Public/Published -
txtSelectedKeyDown TfrmODMedIV procedure txtSelectedKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
txtXDurationChange TfrmODMedIV procedure txtXDurationChange(Sender: TObject); Public/Published -
txtXDurationExit TfrmODMedIV procedure txtXDurationExit(Sender: TObject); Public/Published -
UpdateDuration TfrmODMedIV procedure UpdateDuration(SchType: string); Private -
UpdateRoute TfrmODMedIV procedure UpdateRoute; Private Default: boolean;
VA508CompGrdSelectedCaptionQuery TfrmODMedIV procedure VA508CompGrdSelectedCaptionQuery(Sender: TObject; var Text: string); Public/Published -
VA508CompOrderSigStateQuery TfrmODMedIV procedure VA508CompOrderSigStateQuery(Sender: TObject; var Text: string); Public/Published -
VA508CompRouteInstructionsQuery TfrmODMedIV procedure VA508CompRouteInstructionsQuery(Sender: TObject; var Text: string); Public/Published -
VA508CompScheduleInstructionsQuery TfrmODMedIV procedure VA508CompScheduleInstructionsQuery(Sender: TObject; var Text: string); Public/Published -
VA508CompTypeInstructionsQuery TfrmODMedIV procedure VA508CompTypeInstructionsQuery(Sender: TObject; var Text: string); Public/Published -
Validate TfrmODMedIV procedure Validate(var AnErrMsg: string); override; Public -

Functions

Name Owner Declaration Scope Comments
CreateOtherRoute TfrmODMedIV function CreateOtherRoute: string; Private -
CreateOtherSchedule TfrmODMedIV function CreateOtherSchedule: string; Private -
IsAltCtrl_L_Pressed TfrmODMedIV function IsAltCtrl_L_Pressed(Shift : TShiftState; Key : Word) : Boolean; Private -
IsNumericRate - function IsNumericRate(const x: string): Boolean; Local -
IVTypeHelpText TfrmODMedIV function IVTypeHelpText: string; Public -
UpdateAddFreq TfrmODMedIV function UpdateAddFreq(OI: integer): string; Private -
ValidateInfusionRate TfrmODMedIV function ValidateInfusionRate(Rate: string): string; Public -

Global Variables

Name Type Declaration Comments
frmODMedIV TfrmODMedIV frmODMedIV: TfrmODMedIV; -

Constants

Name Declaration Scope Comments
TC_RESTRICT 'Ordering Restrictions' Global -
TX_BAD_BAG 'A valid additive frequency must be entered for ' Global -
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' Global TX_BAD_RATE = 'The infusion rate must be: # ml/hr or text@labels per day';
TX_BAD_ROUTE 'Route cannot be free-text' Global -
TX_BAD_SCHEDULE 'Unable to resolve non-standard schedule.' Global -
Tx_BAG_NO_COMMENTS '"See Comments" entered for additive ' Global -
TX_BAG_NO_COMMENTS1 ' no comments defined for this order.' Global -
TX_LEADING_NUMERIC 'this additive must start with a leading numeric value' Global -
TX_NO_AMOUNT 'A valid strength or volume must be entered for ' Global -
TX_NO_BASE 'A solution must be selected.' Global -
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.' Global -
TX_NO_INFUSION_UNIT 'Invalid Unit of Time, select either "Minutes" or "Hours" for the Infusion Length' Global -
TX_NO_RATE 'An infusion rate must be entered.' Global -
TX_NO_SCHEDULE 'A schedule is required for an intermittent order.' Global -
TX_NO_UNITS 'Units must be entered for ' Global -


Module Source

1     unit fODMedIV;
2     
3     interface
4     
5     uses
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     
10    type
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        cboAddFreq: TCaptionComboBox;
48        lblAddFreq: TLabel;
49        lblPrevAddFreq: TLabel;
50        lbl508Required: TVA508StaticText;
51        VA508CompOrderSig: TVA508ComponentAccessibility;
52        VA508CompRoute: TVA508ComponentAccessibility;
53        VA508CompType: TVA508ComponentAccessibility;
54        VA508CompSchedule: TVA508ComponentAccessibility;
55        VA508CompGrdSelected: TVA508ComponentAccessibility;
56        procedure FormCreate(Sender: TObject);
57        procedure tabFluidChange(Sender: TObject);
58        procedure  cboAdditiveNeedData(Sender: TObject; const StartFrom: string; Direction,
59          InsertAt: Integer);
60        procedure cboSolutionNeedData(Sender: TObject; const StartFrom: string; Direction,
61          InsertAt: Integer);
62        procedure cboAdditiveMouseClick(Sender: TObject);
63        procedure cboAdditiveExit(Sender: TObject);
64        procedure cboSolutionMouseClick(Sender: TObject);
65        procedure cboSolutionExit(Sender: TObject);
66        procedure FormDestroy(Sender: TObject);
67        procedure cmdRemoveClick(Sender: TObject);
68        procedure FormResize(Sender: TObject);
69        procedure txtSelectedExit(Sender: TObject);
70        procedure ControlChange(Sender: TObject);
71        procedure txtSelectedChange(Sender: TObject);
72        procedure grdSelectedDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
73          State: TGridDrawState);
74        procedure FormKeyDown(Sender: TObject; var Key: Word;
75          Shift: TShiftState);
76        procedure grdSelectedKeyPress(Sender: TObject; var Key: Char);
77        procedure grdSelectedMouseDown(Sender: TObject; Button: TMouseButton;
78          Shift: TShiftState; X, Y: Integer);
79        procedure txtXDurationChange(Sender: TObject);
80        procedure pnlXDurationEnter(Sender: TObject);
81        procedure txtXDurationExit(Sender: TObject);
82        procedure cboScheduleChange(Sender: TObject);
83        procedure cboTypeChange(Sender: TObject);
84        procedure cboRouteChange(Sender: TObject);
85        procedure txtRateChange(Sender: TObject);
86        procedure cboPriorityChange(Sender: TObject);
87        procedure cboPriorityExit(Sender: TObject);
88        procedure cboRouteExit(Sender: TObject);
89        procedure txtNSSClick(Sender: TObject);
90        procedure cboScheduleClick(Sender: TObject);
91        procedure chkPRNClick(Sender: TObject);
92        procedure chkDoseNowClick(Sender: TObject);
93        procedure loadExpectFirstDose;
94        procedure SetSchedule(const x: string);
95        procedure cboScheduleExit(Sender: TObject);
96        procedure cboInfusionTimeChange(Sender: TObject);
97        procedure cboDurationChange(Sender: TObject);
98        procedure cboDurationEnter(Sender: TObject);
99        procedure cboInfusionTimeEnter(Sender: TObject);
100       procedure txtAllIVRoutesClick(Sender: TObject);
101       procedure cboRouteClick(Sender: TObject);
102       procedure lblTypeHelpClick(Sender: TObject);
103       procedure cboSelectedCloseUp(Sender: TObject);
104       procedure cboRouteKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
105       procedure cboScheduleKeyUp(Sender: TObject; var Key: Word;
106         Shift: TShiftState);
107       procedure cboPriorityKeyUp(Sender: TObject; var Key: Word;
108         Shift: TShiftState);
109       procedure cboAddFreqKeyDown(Sender: TObject; var Key: Word;
110         Shift: TShiftState);
111       procedure cboAddFreqCloseUp(Sender: TObject);
112       procedure FormKeyPress(Sender: TObject; var Key: Char);
113       procedure txtSelectedKeyDown(Sender: TObject; var Key: Word;
114         Shift: TShiftState);
115       procedure cboSelectedKeyDown(Sender: TObject; var Key: Word;
116         Shift: TShiftState);
117       procedure cboTypeKeyDown(Sender: TObject; var Key: Word;
118         Shift: TShiftState);
119       procedure cboRouteKeyDown(Sender: TObject; var Key: Word;
120         Shift: TShiftState);
121       procedure cboScheduleKeyDown(Sender: TObject; var Key: Word;
122         Shift: TShiftState);
123       procedure VA508CompOrderSigStateQuery(Sender: TObject; var Text: string);
124       procedure VA508CompRouteInstructionsQuery(Sender: TObject;
125         var Text: string);
126       procedure VA508CompTypeInstructionsQuery(Sender: TObject; var Text: string);
127       procedure VA508CompScheduleInstructionsQuery(Sender: TObject;
128         var Text: string);
129       procedure VA508CompGrdSelectedCaptionQuery(Sender: TObject;
130         var Text: string);
131     private
132       FInpatient: Boolean;
133       FNSSAdminTime: string;
134       FNSSScheduleType: string;
135       OSolIEN: integer;
136       OAddIEN: integer;
137       OSchedule: string;
138       oAdmin: string;
139       OrderIEN: string;
140       FAdminTimeText: string;
141       JAWSON: boolean;
142       FOriginalDurationType: integer;
143       FOriginalInfusionType: integer;
144       FIVTypeDefined: boolean;
145       //FInitialOrderID: boolean;
146       procedure SetValuesFromResponses;
147       procedure DoSetFontSize( FontSize: integer);
148       procedure ClickOnGridCell;
149       procedure SetLimitationControl(aValue: string);
150       function CreateOtherSchedule: string;
151       function CreateOtherRoute: string;
152       procedure UpdateRoute;
153       procedure DisplayDoseNow(Status: boolean);
154       procedure UpdateDuration(SchType: string);
155       procedure ClearAllFields;
156       function UpdateAddFreq(OI: integer): string;
157       function IsAltCtrl_L_Pressed(Shift : TShiftState; Key : Word) : Boolean;
158       procedure SetCtrlAlt_L_LabelAccessText(var Text: string; theLabel : TLabel);
159     public
160       OrdAction: integer;
161       procedure InitDialog; override;
162       procedure SetupDialog(OrderAction: Integer; const ID: string); override;
163       procedure Validate(var AnErrMsg: string); override;
164       procedure SetFontSize( FontSize: integer); override;
165       function ValidateInfusionRate(Rate: string): string;
166       function IVTypeHelpText: string;
167       property NSSAdminTime: string read FNSSAdminTime write FNSSAdminTime;
168       property NSSScheduleType: string read FNSSScheduleType write FNSSScheduleType;
169     end;
170   
171   var
172     frmODMedIV: TfrmODMedIV;
173   
174   implementation
175   
176   {$R *.DFM}
177   
178   uses ORFn, uConst, rODMeds, rODBase, fFrame, uCore, fOtherSchedule, rCore;
179   
180   type
181     TIVComponent = class
182     private
183       IEN: Integer;
184       Name: string;
185       Fluid: Char;
186       Amount: Integer;
187       Units: string;
188       Volumes: string;
189       AddFreq: string;
190     end;
191   
192   const
193     TC_RESTRICT  = 'Ordering Restrictions';
194     TX_NO_BASE   = 'A solution must be selected.';
195     TX_NO_AMOUNT = 'A valid strength or volume must be entered for ';
196     TX_NO_UNITS  = 'Units must be entered for ';
197     TX_NO_RATE   = 'An infusion rate must be entered.';
198     //TX_BAD_RATE  = 'The infusion rate must be:  # ml/hr  or  text@labels per day';
199     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';
200     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.';
201     TX_NO_SCHEDULE = 'A schedule is required for an intermittent order.';
202     TX_BAD_SCHEDULE = 'Unable to resolve non-standard schedule.';
203     TX_NO_INFUSION_UNIT = 'Invalid Unit of Time, select either "Minutes" or "Hours" for the Infusion Length';
204     TX_BAD_ROUTE = 'Route cannot be free-text';
205     TX_LEADING_NUMERIC = 'this additive must start with a leading numeric value';
206     TX_BAD_BAG = 'A valid additive frequency must be entered for ';
207     Tx_BAG_NO_COMMENTS ='"See Comments" entered for additive ';
208     TX_BAG_NO_COMMENTS1 = ' no comments defined for this order.';
209   
210   (*
211     { TIVComponent methods }
212   
213   procedure TIVComponent.Clear;
214   begin
215     IEN     := 0;
216     Name    := '';
217     Fluid   := #0;
218     Amount  := 0;
219     Units   := '';
220     Volumes := '';
221   end;
222   *)
223   
224   { Form methods }
225   
226   procedure TfrmODMedIV.FormCreate(Sender: TObject);
227   var
228     Restriction: string;
229   begin
230     frmFrame.pnlVisit.Enabled := false;
231     //AutoSizeDisabled := true;
232     inherited;
233     AllowQuickOrder := True;
234     CheckAuthForMeds(Restriction);
235     if Length(Restriction) > 0 then
236     begin
237       InfoBox(Restriction, TC_RESTRICT, MB_OK);
238       Close;
239       Exit;
240     end;
241     OrdAction := -1;
242     DoSetFontSize(MainFontSize);
243     FillerID := 'PSIV';                            // does 'on Display' order check **KCM**
244     StatusText('Loading Dialog Definition');
245     Responses.Dialog := 'PSJI OR PAT FLUID OE';    // loads formatting info
246     StatusText('Loading Default Values');
247     CtrlInits.LoadDefaults(ODForIVFluids);         // ODForIVFluids returns TStrings with defaults
248     InitDialog;
249   end;
250   
251   procedure TfrmODMedIV.FormDestroy(Sender: TObject);
252   var
253     i: Integer;
254   begin
255     with grdSelected do for i := 0 to RowCount - 1 do TIVComponent(Objects[0, i]).Free;
256     inherited;
257     frmFrame.pnlVisit.Enabled := True;
258   end;
259   
260   procedure TfrmODMedIV.FormResize(Sender: TObject);
261   var
262   bottom: integer;
263   isNewOrder: boolean;
264   begin
265     inherited;
266     if OrdAction in [ORDER_COPY, ORDER_EDIT] then isNewOrder := false
267     else isNewOrder := True;
268     with grdSelected do
269     begin
270       ColWidths[1] := Canvas.TextWidth(' 10000 ') + GetSystemMetrics(SM_CXVSCROLL);
271       ColWidths[2] := Canvas.TextWidth('meq.') + GetSystemMetrics(SM_CXVSCROLL);
272       //AGP ADDITIVE FREQUENCY CHANGES
273       ColWidths[3] := Canvas.TextWidth(lblAddFreq.Caption + '  ') + GetSystemMetrics(SM_CXVSCROLL);
274        if IsNewOrder = false then
275         begin
276           ColWidths[4] := Canvas.TextWidth(lblPrevAddFreq.Caption) + GetSystemMetrics(SM_CXVSCROLL);
277           ColWidths[0] := ClientWidth - ColWidths[1] - ColWidths[2] - ColWidths[3] - ColWidths[4] - 5;
278         end
279       else
280         begin
281           ColWidths[4] := 0;
282           ColWidths[0] := ClientWidth - ColWidths[1] - ColWidths[2] - ColWidths[3] - ColWidths[4] - 25;
283         end;
284     end;
285     lblAmount.Left := grdSelected.Left + grdSelected.ColWidths[0];
286     lblAddFreq.Left := grdSelected.Left +  grdSelected.ColWidths[0] +  grdSelected.ColWidths[1] + grdSelected.ColWidths[2];
287     if isNewOrder = false then
288       begin
289         lblPrevAddFreq.Visible := True;
290         lblPrevAddFreq.Left := grdSelected.Left +  grdSelected.ColWidths[0] +  grdSelected.ColWidths[1] + grdSelected.ColWidths[2] + grdSelected.ColWidths[3];
291       end
292     else lblPrevAddFreq.Visible := False;
293     self.cboType.SelLength := 0;
294     self.cboInfusionTime.SelLength := 0;
295     self.cboDuration.SelLength := 0;
296     bottom := self.cboPriority.Top + self.cboPriority.Height;
297     if self.chkDoseNow.Top < bottom then self.chkDoseNow.Top := bottom + 5;
298     self.txtRate.Height := self.cboInfusionTime.Height;
299     self.txtXDuration.Height := self.cboDuration.Height;
300     self.lblAdminTime.Height := TextHeightByFont(self.lblAdminTime.Font.Handle, 'A');
301     self.lblFirstDose.Height := TextHeightByFont(self.lblFirstDose.Font.Handle, 'A');
302     self.lblAdminTime.Width := TextWidthByFont(self.lblAdminTime.Font.Handle, self.lblAdminTime.Caption + '  ');
303     self.lblFirstDose.Width := TextWidthByFont(self.lblFirstDose.Font.Handle, self.lblFirstDose.Caption + '  ');
304     self.lblAdminTime.Top := self.chkDoseNow.Top + self.chkDoseNow.Height + 2;
305     self.lblFirstDose.Top := self.lblAdminTime.Top + self.lblAdminTime.Height + 2;
306     self.lbl508Required.Top := self.lblFirstDose.Top + self.lblFirstDose.Height + 5;
307     if self.Label1.Top < (self.lbl508Required.Top + self.lbl508Required.Height) then
308       begin
309         self.Label1.Top := self.lbl508Required.Top + self.lbl508Required.Height + 5;
310         self.memOrder.Top := self.Label1.Top + self.Label1.Height;
311       end;
312   end;
313   
314   { TfrmODBase overrides }
315   
316   procedure TfrmODMedIV.InitDialog;
317   const
318     NOSELECTION: TGridRect = (Left: -1; Top: -1; Right: -1; Bottom: -1);
319   var
320     i: Integer;
321   begin
322     inherited;
323     //grdSelected.Selection := NOSELECTION;
324     //FRouteConflict := False;
325     //lblTypeHelp.Hint := IVTypeHelpText;
326     ClearAllFields;
327     //FIVTypeDefined := false;
328     lblType.Hint := IVTypeHelpText;
329     cboType.Hint := IVTypeHelpText;
330     with grdSelected do for i := 0 to RowCount - 1 do
331     begin
332        TIVComponent(Objects[0, i]).Free;
333        Rows[i].Clear;
334     end;
335     grdSelected.RowCount := 1;
336     //txtRate.Text := ' ml/hr';   {*kcm*}
337     with CtrlInits do
338     begin
339       SetControl(cboSolution, 'ShortList');
340       cboSolution.InsertSeparator;
341       SetControl(cboPriority, 'Priorities');
342       cboType.Items.Add('Continuous');
343       cboType.Items.Add('Intermittent');
344       cboType.ItemIndex := -1;
345       cboType.SelLength := 0;
346       //SetControl(cboRoute, 'Route');
347       if (cboRoute.ItemIndex = -1) and (cboRoute.Text <> '') then cboRoute.Text := '';
348       //SetControl(cboSchedule, 'Schedules');
349       LoadSchedules(cboSchedule.Items, patient.Inpatient);
350       //if (Patient.Inpatient) and (cboSchedule.Items.IndexOfName('Other')<0) then
351       if cboSchedule.Items.IndexOf('Other') = -1 then cboSchedule.Items.Add('OTHER');
352       cboSchedule.Enabled := False;
353       lblschedule.Enabled := False;
354       if cboInfusionTime.Items.Count = 0 then
355          begin
356           cboInfusionTime.Items.add('Minutes');
357           cboInfusionTime.Items.Add('Hours');
358          end;
359       cboInfusionTime.Enabled := false;
360       UpdateDuration('');
361       if cboDuration.Items.Count = 0 then
362         begin
363           cboDuration.Items.Add('L');
364           cboDuration.Items.Add('ml');
365           cboDuration.Items.Add('days');
366           cboDuration.Items.Add('hours');
367         end;
368       cboDuration.ItemIndex := -1;
369       cboDuration.Text := '';
370       if self.txtXDuration.Text <> '' then self.txtXDuration.Text := '';
371       txtNSS.Visible := false;
372       if (chkDoseNow.Visible = true) and (chkDoseNow.Checked = true) then chkDoseNow.Checked := false;
373       chkDoseNow.Visible := false;
374       chkPRN.Enabled := false;
375       //AGP ADDITIVE FREQUENCY CHANGES
376       if cboAddFreq.Items.Count = 0 then
377         begin
378           cboAddFreq.Items.Add('1 Bag/Day');
379           cboAddFreq.Items.Add('All Bags');
380           cboAddFreq.Items.Add('See Comments');
381         end;
382     end;
383     tabFluid.TabIndex := 0;
384     tabFluidChange(Self);            // this makes cboSolution visible
385     cboSolution.InitLongList('');
386     cboAdditive.InitLongList('');
387     JAWSON := true;
388     if ScreenReaderActive = false then
389       begin
390         lblAdminTime.TabStop := false;
391         lblFirstDose.TabStop := false;
392         memOrder.TabStop := false;
393         JAWSON := false;
394       end;
395     ActiveControl := cboSolution;  //SetFocusedControl(cboSolution);
396     StatusText('');
397     OSolIEN := 0;
398     OAddIEN := 0;
399     OSchedule := '';
400     oAdmin := '';
401     self.txtAllIVRoutes.Visible := false;
402     memorder.text := '';
403     memOrder.Lines.Clear;
404   end;
405   
406   function TfrmODMedIV.IVTypeHelpText: string;
407   begin
408      result := 'Continuous Type:' + CRLF + '     IV’s that run at a specified “Rate” ( __ml/hr, __mcg/kg/min, etc)' +
409                CRLF + CRLF + 'Intermittent Type:' + CRLF +
410                '     IV’s administered at scheduled intervals (Q4H, QDay) or One-Time only, ' +
411                CRLF + '     “over a specified time period” (e.g. “Infuse over 30 min.”).' + CRLF + CRLF +
412                'Examples:' + CRLF + 'Continuous = Infusion/drip' + CRLF + 'Intermittent = IVP/IVPB';
413   end;
414   
415   procedure TfrmODMedIV.SetCtrlAlt_L_LabelAccessText(var Text: string; theLabel : TLabel);
416   begin
417     if theLabel.Visible then
418       Text := 'Press Ctrl + Alt + L to access ' + theLabel.Caption;
419   end;
420   
421   procedure TfrmODMedIV.lblTypeHelpClick(Sender: TObject);
422   var
423   str: string;
424   begin
425     inherited;
426       str := IVTypeHelpText;
427       infoBox(str, 'Informational Help Text', MB_OK);
428   end;
429   
430   
431   procedure TfrmODMedIV.loadExpectFirstDose;
432   var
433   i: integer;
434   AnIVComponent: TIVComponent;
435   fAddIEN, fSolIEN, Interval, idx: integer;
436   AdminTime:    TFMDateTime;
437   Admin, Duration, ShowText, SchTxt, SchType, IVType: string;
438   doseNow, calFirstDose: boolean;
439   begin
440     idx := self.cboSchedule.ItemIndex;
441     IVType := self.cboType.Items.Strings[self.cboType.itemindex];
442     if idx = -1 then
443       begin
444         if IVType = 'Continuous' then
445           begin
446             self.lblFirstDose.Caption := '';
447             self.lblFirstDose.Visible := false;
448           end;
449         exit;
450       end;
451     doseNow := true;
452     SchType := Piece(self.cboSchedule.Items.Strings[idx],U,3);
453     if self.EvtID > 0 then doseNow := false;
454     if (IVType = 'Continuous') or ((idx > -1) and ((SchType = 'P') or (SchType = 'O') or (SchType = 'OC')) or
455        (self.chkPRN.Checked = True))  then
456        begin
457          self.lblFirstDose.Caption := '';
458          self.lblAdminTime.Caption := '';
459          self.lblFirstDose.Visible := false;
460          self.lblAdminTime.Visible := false;
461          self.lblAdminTime.TabStop := false;
462          self.lblFirstDose.TabStop := false;
463          if (self.cboType.Text = 'Continuous') or (Piece(self.cboSchedule.Items.Strings[idx],U,3) = 'O') then doseNow := false;
464          if chkDoseNow.Checked = true then lblFirstDose.Visible := false;
465          if idx > -1 then oSchedule := Piece(self.cboSchedule.Items.Strings[idx],U,1);
466          if (self.chkPRN.Checked = True) and (idx > -1) and (LeftStr(Piece(self.cboSchedule.Items.Strings[idx],U,1),3)<> 'PRN') then
467             OSchedule := Piece(self.cboSchedule.Items.Strings[idx],U,1) + ' PRN';
468          DisplayDoseNow(doseNow);
469          exit;
470          //  end;
471        end
472     else if SchType <> 'O' then
473       begin
474         self.lblAdminTime.Visible := true;
475         if FAdminTimeText <> '' then self.lblAdminTime.Caption := 'Admin. Time: ' + FAdminTimeText
476         else if Piece(self.cboSchedule.Items[idx],U,4) <> '' then
477              self.lblAdminTime.Caption := 'Admin. Time: ' + Piece(self.cboSchedule.Items[idx],U,4)
478         else self.lblAdminTime.Caption := 'Admin. Time: Not Defined';
479       end;
480    DisplayDoseNow(doseNow);
481    if chkDoseNow.Checked = true then
482      begin
483        lblFirstDose.Visible := false;
484        Exit;
485      end;
486    self.lblFirstDose.Visible := True;
487    fSolIEN := 0;
488    fAddIEN := 0;
489    for i := 0 to self.grdSelected.RowCount - 1 do
490     begin
491      AniVComponent := TIVComponent(self.grdSelected.Objects[0, i]);
492      if AnIVComponent = nil then Continue;
493      if (AnIVComponent.Fluid = 'B') and (fSolIEN = 0) then fSolIEN := AnIVComponent.IEN;
494      if (AnIVComponent.Fluid = 'A') and (fAddIEN = 0) then fAddIEN := AnIVComponent.IEN;
495      if (fSolIEN > 0) and (fAddIEN > 0) then break;
496     end;
497     SchTxt := self.cboSchedule.Text;
498     Admin := '';
499     if (self.lblAdminTime.visible = True) and (self.lblAdminTime.Caption <> '') then
500       begin
501         Admin := Copy(self.lblAdminTime.Caption,  14, (Length(self.lblAdminTime.Caption)-1));
502         if not (Admin[1] in ['0'..'9']) then Admin := '';
503       end;
504     if (fSolIEN = oSolIEN) and (fAddIEN = oAddIEN) and (OSchedule = SchTxt) and (oAdmin = Admin) then CalFirstDose := false
505     else
506       begin
507         CalFirstDose := True;
508         oSolIEN := fSolIEN;
509         oAddIEN := fAddIEN;
510         oSchedule := SchTxt;
511         oAdmin := Admin;
512       end;
513     if CalFirstDose = True then
514     begin
515       if fAddIEN > 0 then LoadAdminInfo(';' + schTxt, fAddIEN, ShowText, AdminTime, Duration, Admin)
516       else LoadAdminInfo(';' + schTxt, fSolIEN, ShowText, AdminTime, Duration, Admin);
517       if AdminTime > 0 then
518         begin
519           ShowText := 'Expected First Dose: ';
520           Interval := Trunc(FMDateTimeToDateTime(AdminTime) - FMDateTimeToDateTime(FMToday));
521           case Interval of
522           0: ShowText := ShowText + 'TODAY ' + FormatFMDateTime('(mmm dd, yy) at hh:nn', AdminTime);
523           1: ShowText := ShowText + 'TOMORROW ' + FormatFMDateTime('(mmm dd, yy) at hh:nn', AdminTime);
524           else ShowText := ShowText + FormatFMDateTime('mmm dd, yy at hh:nn', AdminTime);
525         end;
526       end;
527       self.lblFirstDose.Caption := ShowText;
528     end;
529     if (self.lblFirstDose.Visible = true) and (self.lblFirstDose.Caption <> '') and (JAWSON = true) then self.lblFirstDose.TabStop := true
530     else self.lblFirstDose.TabStop := false;
531     if (self.lblAdminTime.Visible = true) and (self.lblAdminTime.Caption <> '') and (JAWSON = true) then self.lblAdminTime.TabStop := true
532     else self.lblAdminTime.TabStop := false;
533   end;
534   
535   procedure TfrmODMedIV.VA508CompRouteInstructionsQuery(
536     Sender: TObject; var Text: string);
537   begin
538     inherited;
539     SetCtrlAlt_L_LabelAccessText(Text, txtAllIVRoutes);
540   end;
541   
542   procedure TfrmODMedIV.VA508CompScheduleInstructionsQuery(Sender: TObject;
543     var Text: string);
544   begin
545     inherited;
546     SetCtrlAlt_L_LabelAccessText(Text, txtNSS);
547   end;
548   
549   procedure TfrmODMedIV.VA508CompTypeInstructionsQuery(Sender: TObject;
550     var Text: string);
551   begin
552     inherited;
553     SetCtrlAlt_L_LabelAccessText(Text, lblTypeHelp);
554   end;
555   
556   procedure TfrmODMedIV.VA508CompGrdSelectedCaptionQuery(Sender: TObject;
557     var Text: string);
558   begin
559     inherited;
560     if grdSelected.Col = 0 then
561       Text := lblComponent.Caption
562     else if grdSelected.Col = 1 then
563       Text := lblAmount.Caption
564     else if grdSelected.Col = 2 then
565       Text := lblAmount.Caption + ', Unit'
566     else if grdSelected.Col = 3 then
567       Text := lblAddFreq.Caption
568     else if grdSelected.Col = 4 then
569       Text := lblPrevAddFreq.Caption;
570   end;
571   
572   procedure TfrmODMedIV.VA508CompOrderSigStateQuery(Sender: TObject;
573     var Text: string);
574   begin
575     inherited;
576     Text := memOrder.Text;
577   end;
578   
579   procedure TfrmODMedIV.Validate(var AnErrMsg: string);
580   var
581     DispWarning, ItemOK, Result: Boolean;
582     LDec,RDec,x, tempStr, iunit, infError, Bag: string;
583     digits, i, j, Len, temp, Value: Integer;
584   
585     procedure SetError(const x: string);
586     begin
587       if Length(AnErrMsg) > 0 then AnErrMsg := AnErrMsg + CRLF;
588       AnErrMsg := AnErrMsg + x;
589     end;
590   
591   begin
592     inherited;
593     with grdSelected do
594     begin
595       ItemOK := False;
596       for i := 0 to RowCount - 1 do
597         if (Objects[0,i] <> nil) and (TIVComponent(Objects[0, i]).Fluid = 'B') then ItemOK := True;
598       if (not ItemOK) and ((self.cboType.ItemIndex = -1) or (MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Continuous')) then
599           SetError(TX_NO_BASE);
600       for i := 0 to RowCount - 1 do
601       begin
602         if (Objects[0, i] <> nil) and ((Length(Cells[1, i]) = 0) or (StrToFloat(Cells[1,i])=0))
603           then SetError(TX_NO_AMOUNT + Cells[0, i]);
604         if (Objects[0, i] <> nil) and (Length(Cells[2, i]) = 0)
605           then SetError(TX_NO_UNITS + Cells[0, i]);
606         if (Objects[0,i] <> nil) and (TIVComponent(Objects[0, i]).Fluid = 'A') then
607           begin
608             temp := Pos('.', Cells[1, i]);
609             if temp > 0 then
610               begin
611                 tempStr := Cells[1, i];
612                  if temp = 1 then
613                    begin
614                      SetError(cells[0, i] + TX_LEADING_NUMERIC);
615                      Exit;
616                    end;
617                 for j := 1 to temp -1 do if not (tempStr[j] in ['0'..'9']) then
618                   begin
619                     SetError(cells[0, i] + TX_LEADING_NUMERIC);
620                     Exit;
621                   end;
622               end;
623              //AGP ADDITIVE FREQUENCY CHANGES
624              if MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Continuous' then
625                begin
626                  Bag := (Cells[3, i]);
627                  if Length(Bag) = 0 then
628                    begin
629                      SetError(TX_BAD_BAG + cells[0, i]);
630                    end
631                  else if cboAddFreq.Items.IndexOf(Bag) = -1 then
632                     begin
633                       SetError(TX_BAD_BAG + cells[0, i]);
634                     end
635                  else if (MixedCase(Bag) = 'See Comments') and ((self.memComments.Text = '') or (self.memComments.Text = CRLF)) then
636                     begin
637                       SetError(Tx_BAG_NO_COMMENTS + cells[0,i] + Tx_BAG_NO_COMMENTS1);
638                     end;
639                       
640                end;
641           end;
642     end;
643     end;
644     if Pos(U, self.memComments.Text) > 0 then SetError('Comments cannot contain a "^".');  
645     if cboSchedule.ItemIndex > -1 then UpdateDuration(Piece(cboSchedule.Items.Strings[cboSchedule.itemIndex], U, 3));
646     if self.cboPriority.Text = '' then SetError('Priority is required');
647     if (cboRoute.ItemIndex = -1) and (cboRoute.Text <> '') then SetError(TX_BAD_ROUTE);
648     if (cboRoute.ItemIndex > -1) and (cboRoute.ItemIndex = cboRoute.Items.IndexOf('OTHER')) then
649         SetError('A valid route must be selected');
650     if self.cboRoute.Text = '' then SetError('Route is required');
651     if (self.txtXDuration.Text <> '') and (self.cboduration.Items.IndexOf(SELF.cboDuration.Text) = -1) then
652         SetError('A valid duration type is required');
653     if (self.txtXDuration.Text = '') and (self.cboduration.Items.IndexOf(SELF.cboDuration.Text) > -1) then
654        SetError('Cannot have a duration type without a duration value');
655   
656     if self.cboType.ItemIndex = -1 then
657       begin
658         SetError('IV Type is required');
659         Exit;
660       end;
661     if MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Continuous' then
662        begin
663         if Length(txtRate.Text) = 0 then SetError(TX_NO_RATE) else
664           begin
665             x := Trim(txtRate.Text);
666             if pos('@', X) > 0 then
667               begin
668               LDec := Piece(x, '@', 1);
669               RDec := Piece(x, '@', 2);
670               if (Length(RDec) = 0) or (Length(RDec) > 2) then x := '';
671               end
672             else if Pos('.',X)>0 then
673               begin
674                 LDec := Piece(x, '.', 1);
675                 RDec := Piece(x, '.', 2);
676                 if Length(LDec) = 0 then SetError('Infusion Rate required a leading numeric value');
677                 if Length(RDec) > 1 then SetError('Infusion Rate cannot exceed one decimal place');
678               end
679               else if LeftStr(txtRate.Text, 1) = '0' then
680                  SetError('Infusion Rate cannot start with a zero.');
681             if ( Pos('@',x)=0) then
682               begin
683                 if (Length(x) > 4) then
684                   begin
685                     seterror(TX_BAD_RATE);
686                     exit;
687                   end;
688                 for i := 1 to Length(x) do
689                   begin
690                     if  not (x[i] in ['0'..'9']) and (x[i] <> '.') then
691                       begin
692                         SetError(TX_BAD_RATE);
693                         exit;
694                       end;
695                   end;
696               end;
697             if (pos('ml/hr', X) = 0) and (Length(x) > 0) and (pos('@', X) = 0) then X := X + ' ml/hr';
698             if Length(x) = 0 then SetError(TX_BAD_RATE) else Responses.Update('RATE', 1, x, x);
699           end;
700         if cboduration.text = 'doses' then SetError('Continuous Orders cannot have "doses" as a duration type');
701       end
702     else if MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Intermittent' then
703        begin
704         if (cboInfusionTime.ItemIndex = -1) and (txtRate.Text <> '') then SetError(TX_NO_INFUSION_UNIT);
705         if (txtRate.Text = '') and (cboInfusionTime.ItemIndex > -1) then SetError(TX_NO_INFUSION_TIME);
706         if (txtRate.Text <> '') then
707           begin
708             infError := '';
709             InfError := ValidateInfusionRate(txtRate.Text);
710             if infError <> '' then SetError(InfError);
711             Len := Length(txtRate.Text);
712             iunit := MixedCase(self.cboInfusionTime.Items.Strings[cboInfusionTime.ItemIndex]);
713             if (iunit = 'Minutes') and (Len > 4) then setError('Infuse Over Time cannot exceed 4 spaces for ' + iunit)
714             else if (iunit = 'Hours') and (Len > 2) then setError('Infuse Over Time cannot exceed 2 spaces for ' + iunit);
715           end;
716         if (cboSchedule.ItemIndex = -1) and (cboSchedule.Text = '') and (chkPRN.Checked = false) then SetError(TX_NO_SCHEDULE);
717         if (cboSchedule.ItemIndex > -1) and (cboSchedule.Text = '') then
718           begin
719             cboSchedule.ItemIndex := -1;
720             SetError(TX_NO_SCHEDULE)
721           end;
722         if (cboSchedule.ItemIndex = -1) and (cboSchedule.Text <> '') then SetError(TX_BAD_SCHEDULE);
723       end;
724     if txtXDuration.Text = '' then
725       begin
726         if AnErrMsg = '' then exit;
727         //if AnErrMsg = '' then self.FInitialOrderID := True;
728         //exit;
729       end;
730     Len := Length(txtXDuration.Text);
731     if LeftStr(txtXDuration.Text,1) <> '.' then
732       begin
733         DispWarning := false;
734         Digits := 2;
735         if cboDuration.text = 'ml' then digits := 4;
736         if ((cboDuration.text = 'days') or (cboDuration.text = 'hours')) and (Len > digits) then
737             DispWarning := true
738         else if (cboduration.text = 'ml') and (Len > digits) then  DispWarning := true
739         else if (cboduration.text = 'L') and (Len > digits) and (Pos('.',txtXDuration.Text) = 0) then DispWarning := True;
740         if DispWarning = true then SetError('Duration for ' + cboduration.text + ' cannot be greater than ' + InttoStr(digits) + ' digits.');
741       end;
742     if (Pos('.', txtXDuration.Text)>0)  then
743     begin
744       SetError('Invalid Duration, please enter a whole numbers for a duration.');
745     end
746     else if LeftStr(txtXDuration.text, 1) = '0' then
747          SetError('Duration cannot start with a zero.');
748     if (cboduration.text = 'doses') then
749        begin
750          if TryStrToInt(txtXDuration.Text, Value) = false then
751            SetError('Duration with a unit of "doses" must be a whole number between 0 and 2000000')
752          else if (Value < 0) or (Value > 2000000) then
753            SetError('Duration with a unit of "doses" must be greater then 0 and less then 2000000');
754        end;
755     //if AnErrMsg = '' then self.FInitialOrderID := True;
756     
757   end;
758   
759   function TFrmODMedIV.ValidateInfusionRate(Rate: string): string;
760   var
761   Temp: Boolean;
762   i: integer;
763   begin
764     Temp := False;
765     if Pos('.',Rate) >0 then
766       begin
767         Result := 'Infuse Over Time can only be a whole number';
768         exit;
769       end
770     else if LeftStr(Rate, 1) = '0' then Result := 'Infuse Over Time cannot start with a zero.';
771     for i := 1 to Length(Rate) do if not (Rate[i] in ['0'..'9']) then Temp := True;
772     if Temp = True then Result := 'The Infusion time can only be a whole number';
773   end;
774   
775   procedure TfrmODMedIV.SetValuesFromResponses;
776   var
777     x, addRoute, tempSch, AdminTime, TempOrder, tmpSch, tempIRoute, tempRoute, PreAddFreq, DEAFailStr, TX_INFO: string;
778     AnInstance, i, idx, j: Integer;
779     AResponse, AddFreqResp: TResponse;
780     AnIVComponent: TIVComponent;
781     AllIVRoute: TStringList;
782     PQO: boolean;
783   begin
784     Changing := True;
785     //self.FInitialOrderID := false;
786     with Responses do
787     begin
788       SetControl(cboType, 'TYPE', 1);
789       if cboType.ItemIndex > -1 then  FIVTypeDefined := True;
790       FInpatient := OrderForInpatient;
791       AnInstance := NextInstance('ORDERABLE', 0);
792       while AnInstance > 0 do
793       begin
794         AResponse := FindResponseByName('ORDERABLE', AnInstance);
795         if AResponse <> nil then
796         begin
797           x := AmountsForIVFluid(StrToIntDef(AResponse.IValue, 0), 'B');
798           AnIVComponent := TIVComponent.Create;
799           AnIVComponent.IEN     := StrToIntDef(AResponse.IValue, 0);
800           DEAFailStr := '';
801           if not FInpatient then
802           begin
803             DEAFailStr := DEACheckFailedForIVOnOutPatient(AnIVComponent.IEN,'S');
804             while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
805               begin
806                 case StrToIntDef(Piece(DEAFailStr,U,1),0) of
807                   1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
808                   2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
809                   3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
810                   4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
811                   5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
812                 end;
813                 if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
814                   begin
815                     DEAContext := True;
816                     fFrame.frmFrame.mnuFileEncounterClick(self);
817                     DEAFailStr := '';
818                     DEAFailStr := DEACheckFailedForIVOnOutPatient(AnIVComponent.IEN,'S');
819                   end
820                 else
821                   begin
822                     cboAdditive.Text := '';
823                     AbortOrder := True;
824                     Exit;
825                   end;
826               end
827           end else
828           begin
829             DEAFailStr := DEACheckFailed(AnIVComponent.IEN, FInpatient);
830             while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
831               begin
832                 case StrToIntDef(Piece(DEAFailStr,U,1),0) of
833                   1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
834                   2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
835                   3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
836                   4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
837                   5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
838                 end;
839                 if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
840                   begin
841                     DEAContext := True;
842                     fFrame.frmFrame.mnuFileEncounterClick(self);
843                     DEAFailStr := '';
844                     DEAFailStr := DEACheckFailed(AnIVComponent.IEN, FInpatient);
845                   end
846                 else
847                   begin
848                     cboAdditive.Text := '';
849                     AbortOrder := True;
850                     Exit;
851                   end;
852               end
853           end;
854           AnIVComponent.Name    := AResponse.EValue;
855           AnIVComponent.Fluid   := 'B';
856           AnIVComponent.Amount  := StrToIntDef(Piece(x, U, 2), 0);
857           AnIVComponent.Units   := Piece(x, U, 1);
858           AnIVComponent.Volumes := Copy(x, Pos(U, x) + 1, Length(x));
859           with grdSelected do
860           begin
861             if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
862             Objects[0, RowCount - 1] := AnIVComponent;
863             Cells[0, RowCount - 1] := AnIVComponent.Name;
864             if AnIVComponent.Amount <> 0 then
865               Cells[1, RowCount - 1] := IntToStr(AnIVComponent.Amount);
866             Cells[2, RowCount - 1] := AnIVComponent.Units;
867             Cells[3, RowCount - 1] := 'N/A';
868           end;
869         end;
870         AResponse := FindResponseByName('VOLUME', AnInstance);
871         if AResponse <> nil then with grdSelected do Cells[1, RowCount - 1] := AResponse.EValue;
872         AnInstance := NextInstance('ORDERABLE', AnInstance);
873       end; {while AnInstance - ORDERABLE}
874       AnInstance := NextInstance('ADDITIVE', 0);
875       while AnInstance > 0 do
876       begin
877         AResponse := FindResponseByName('ADDITIVE', AnInstance);
878         if AResponse <> nil then
879         begin
880           x := AmountsForIVFluid(StrToIntDef(AResponse.IValue, 0), 'A');
881           AnIVComponent := TIVComponent.Create;
882           AnIVComponent.IEN     := StrToIntDef(AResponse.IValue, 0);
883           DEAFailStr := '';
884           if not FInpatient then
885           begin
886             DEAFailStr := DEACheckFailedForIVOnOutPatient(AnIVComponent.IEN,'A');
887             while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
888               begin
889                 case StrToIntDef(Piece(DEAFailStr,U,1),0) of
890                   1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
891                   2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
892                   3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
893                   4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
894                   5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
895                 end;
896                 if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
897                   begin
898                     DEAContext := True;
899                     fFrame.frmFrame.mnuFileEncounterClick(self);
900                     DEAFailStr := '';
901                     DEAFailStr := DEACheckFailedForIVOnOutPatient(AnIVComponent.IEN,'A');
902                   end
903                 else
904                   begin
905                     cboAdditive.Text := '';
906                     AbortOrder := True;
907                     Exit;
908                   end;
909               end
910           end else
911           begin
912             DEAFailStr := DEACheckFailed(AnIVComponent.IEN, FInpatient);
913             while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
914               begin
915                 case StrToIntDef(Piece(DEAFailStr,U,1),0) of
916                   1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
917                   2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
918                   3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
919                   4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
920                   5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
921                 end;
922                 if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
923                   begin
924                     DEAContext := True;
925                     fFrame.frmFrame.mnuFileEncounterClick(self);
926                     DEAFailStr := '';
927                     DEAFailStr := DEACheckFailed(AnIVComponent.IEN, FInpatient);
928                   end
929                 else
930                   begin
931                     cboAdditive.Text := '';
932                     AbortOrder := True;
933                     Exit;
934                   end;
935               end
936           end;
937           AnIVComponent.Name    := AResponse.EValue;
938           AnIVComponent.Fluid   := 'A';
939           AnIVComponent.Amount  := StrToIntDef(Piece(x, U, 2), 0);
940           AnIVComponent.Units   := Piece(x, U, 1);
941           AnIVComponent.Volumes := Copy(x, Pos(U, x) + 1, Length(x));
942           //AGP ADDITIVE FREQUENCY CHANGES
943           AnIVComponent.AddFreq := '';
944           PreAddFreq := '';
945           AddFreqResp := FindResponseByName('ADDFREQ', AnInstance);
946           if AddFreqResp <> nil then
947             begin
948               if cboAddFreq.Items.IndexOf(AddFreqResp.IValue) = -1 then
949                    begin
950                      AnIvComponent.AddFreq := '';
951                    end
952               else AnIvComponent.AddFreq := AddFreqResp.IValue;
953               PreAddFreq := AddFreqResp.IValue;
954             end;
955           with grdSelected do
956           begin
957             if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
958             Objects[0, RowCount - 1] := AnIVComponent;
959             Cells[0, RowCount - 1] := AnIVComponent.Name;
960             if AnIVComponent.Amount <> 0 then
961               Cells[1, RowCount - 1] := IntToStr(AnIVComponent.Amount);
962             Cells[2, RowCount - 1] := AnIVComponent.Units;
963             Cells[3, RowCount -1] := AnIVComponent.AddFreq;
964             if OrdAction in [ORDER_COPY, ORDER_EDIT] then Cells[4, RowCount -1] := PreAddFreq;
965           end;
966         end;
967         AResponse := FindResponseByName('STRENGTH', AnInstance);
968         if AResponse <> nil then with grdSelected do Cells[1, RowCount - 1] := AResponse.EValue;
969         AResponse := FindResponseByName('UNITS', AnInstance);
970         if AResponse <> nil then with grdSelected do Cells[2, RowCount - 1] := AResponse.EValue;
971         AnInstance := NextInstance('ADDITIVE', AnInstance);
972       end; {while AnInstance - ADDITIVE}
973       SetControl(cboType, 'TYPE', 1);
974       if self.grdSelected.RowCount > 0 then self.txtAllIVRoutes.Visible := True;    
975       UpdateRoute;
976       AResponse := FindResponseByName('ROUTE', 1);
977       if AResponse <> nil then
978         begin
979           tempRoute := AResponse.EValue;
980           if tempRoute <> '' then
981             begin
982              idx := self.cboRoute.Items.IndexOf(tempRoute);
983              if idx > -1 then self.cboRoute.ItemIndex := idx
984              else begin
985                tempIRoute := AResponse.IValue;
986                if tempIRoute <> '' then
987                  begin
988                   AllIVRoute := TStringList.Create;
989                   LoadAllIVRoutes(AllIVRoute);
990                   idx := -1;
991                   for i := 0 to AllIVRoute.Count - 1 do
992                     begin
993                       if Piece(AllIVRoute.Strings[i], U, 1) = tempIRoute then
994                         begin
995                           idx := i;
996                           break;
997                         end;
998                     end;
999                   if idx > -1 then
1000                    begin
1001                      self.cboRoute.Items.Add(AllIVRoute.Strings[idx]);
1002                      idx := self.cboRoute.Items.IndexOf(tempRoute);
1003                      if idx > -1 then self.cboRoute.ItemIndex := idx;
1004                    end;
1005                    AllIVRoute.Free;
1006                  //if Pos(U, tempIRoute) = 0 then tempIRoute := tempIRoute + U + tempRoute;
1007                  //self.cboRoute.Items.Add(tempIRoute);
1008                  //idx := self.cboRoute.Items.IndexOf(tempRoute);
1009                  //if idx > -1 then self.cboRoute.ItemIndex := idx;
1010                 end;
1011             end;
1012            end;
1013        end;
1014      //SetControl(cboRoute, 'ROUTE', 1);
1015      if (cboRoute.ItemIndex = -1) and (cboRoute.Text <> '') then cboRoute.Text := '';
1016      if self.cboType.Text = 'Intermittent' then
1017        begin
1018           lblInfusionRate.Caption := 'Infuse Over Time (Optional)';
1019           lblSchedule.Enabled := True;
1020           cboschedule.Enabled := True;
1021           //if popDuration.Items.IndexOf(popDoses) = -1 then popDuration.Items.Add(popDoses);
1022           if cboDuration.Items.IndexOf('doses') = -1 then cboDuration.Items.Add('doses');         
1023           txtNss.Visible := true;
1024           chkDoseNow.Visible := true;
1025           chkPRN.Enabled := True;
1026           tempSch := '';
1027           AdminTime := '';
1028           AResponse := FindResponseByName('SCHEDULE', 1);
1029           if AResponse <> nil then tempSch := AResponse.EValue;
1030           lblAdminTime.Visible := True;
1031           lblAdminTime.Hint := AdminTimeHelpText;
1032           lblAdminTime.ShowHint := True;
1033           //AResponse := Responses.FindResponseByName('ADMIN', 1);
1034           //if AResponse <> nil then AdminTime := AResponse.EValue;
1035           //if Action = Order_Copy then FOriginalAdminTime := AdminTime;
1036           SetSchedule(tempSch);
1037           //if (cboSchedule.ItemIndex > -1) then lblAdminTime.Caption := 'Admin. Time: ' + Piece(cboSchedule.Items.strings[cboSchedule.itemindex],U,5);
1038           //if (cboSchedule.ItemIndex > -1) and (Piece(lblAdminTime.Caption, ':' ,2) = ' ') then lblAdminTime.Caption := 'Admin. Time: ' + AdminTime;
1039           if (OrdAction in [ORDER_COPY, ORDER_EDIT])  then
1040             begin
1041              TempOrder := Piece(OrderIEN,';',1);
1042              TempOrder := Copy(tempOrder, 2, Length(tempOrder));
1043               if DifferentOrderLocations(tempOrder, Patient.Location) = false then
1044                begin
1045                  AResponse := Responses.FindResponseByName('ADMIN', 1);
1046                  if AResponse <> nil then AdminTime := AResponse.EValue;
1047                  //lblAdminTime.Caption := 'Admin. Time: ' + AdminTime;
1048                  if (cboSchedule.ItemIndex > -1) and (AdminTime <> '') then
1049                    begin
1050                      tmpSch := cboSchedule.Items.Strings[cboSchedule.itemindex];
1051                      setPiece(tmpSch,U,4,AdminTime);
1052                      cboSchedule.Items.Strings[cboSchedule.ItemIndex] := tmpSch;
1053                    end;
1054                end;
1055             end;
1056           //if Piece(lblAdminTime.Caption, ':' ,2) = ' ' then lblAdminTime.Caption := 'Admin. Time: Not Defined';
1057           SetControl(txtRate,     'RATE',    1);
1058           cboInfusionTime.Enabled := true;
1059           PQO := false;
1060           if Pos('INFUSE OVER',UpperCase(txtRate.Text)) > 0 then
1061             begin
1062               txtRate.Text := Copy(txtRate.Text,Length('Infuse over ')+1,Length(txtRate.text));
1063               PQO := True;
1064             end;
1065           if Pos('MINUTE',UpperCase(txtRate.Text))>0 then
1066             begin
1067               cboInfusionTime.Text := 'Minutes';
1068               cboInfusionTime.itemindex := 0;
1069               //txtRate.Text := Copy(txtRate.Text,Length('Infuse over ')+1,Length(txtRate.text));
1070               txtRate.Text := Copy(txtRate.Text, 1, Length(txtRate.Text) - 8);
1071             end
1072           else if Pos('HOUR',UpperCase(txtRate.Text))>0 then
1073             begin
1074               cboInfusionTime.Text := 'Hours';
1075               cboInfusionTime.ItemIndex := 1;
1076               //txtRate.Text := Copy(txtRate.Text,Length('Infuse over ')+1,Length(txtRate.text));
1077               txtRate.Text := Copy(txtRate.Text, 1, Length(txtRate.Text) - 6);
1078             end
1079           else if (txtRate.Text <> '') and (PQO = false) and (ValidateInfusionRate(txtRate.Text) ='') then
1080             begin
1081               cboInfusionTime.Text := 'Minutes';
1082               cboInfusionTime.itemindex := 0;
1083             end;
1084            For j := 0 to grdSelected.RowCount -1 do
1085              grdSelected.Cells[3,j] := 'N/A';
1086        end
1087      else
1088        begin
1089          lblSchedule.Enabled := false;
1090          cboSchedule.ItemIndex := -1;
1091          cboSchedule.Enabled := false;
1092          if chkDoseNow.Visible = true then  chkDoseNow.Checked := false;
1093          chkDoseNow.Visible := false;
1094          txtNSS.Visible := false;
1095          cboInfusionTime.ItemIndex := -1;
1096          cboInfusionTime.Text := '';
1097          cboInfusionTime.Enabled := false;
1098          chkPRN.Checked := false;
1099          chkPRN.Enabled := false;
1100          txtRate.Text := '';
1101          cboDuration.ItemIndex := -1;
1102          cboDuration.Text := '';
1103          txtXDuration.Text := '';
1104          SetControl(txtRate,     'RATE',    1);
1105          if LowerCase(Copy(ReverseStr(txtRate.Text), 1, 6)) = 'rh/lm '             {*kcm*}
1106            then txtRate.Text := Copy(txtRate.Text, 1, Length(txtRate.Text) - 6);
1107        end;
1108      SetControl(cboPriority, 'URGENCY', 1);
1109      SetControl(memComments, 'COMMENT', 1);
1110  
1111      AnInstance := NextInstance('DAYS', 0);
1112      if AnInstance > 0 then
1113      begin
1114        AResponse := FindResponseByName('DAYS', AnInstance);
1115        if AResponse <> nil then
1116            SetLimitationControl(AResponse.EValue);
1117      end;
1118    end; {if...with Responses}
1119    Changing := False;
1120    if self.cboSchedule.ItemIndex > -1 then UpdateDuration(Piece(cboSchedule.Items.Strings[cboSchedule.itemindex],U,3));
1121    loadExpectFirstDose;
1122    ControlChange(Self);
1123  end;
1124  
1125  procedure TfrmODMedIV.SetupDialog(OrderAction: Integer; const ID: string);
1126  begin
1127    inherited;
1128    OrdAction := OrderAction;
1129    OrderIEN := id;
1130    //self.FInitialOrderID := True;
1131    if self.EvtID > 0 then FAdminTimeText := 'To Be Determined';
1132    if isIMO = true then self.Caption := 'Clinic ' + self.Caption;
1133    if (isIMO) or ((patient.Inpatient = true) and (encounter.Location <> patient.Location)) and (FAdminTimeText = '') then
1134        FAdminTimeText := 'Not defined for Clinic Locations';
1135    if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then
1136      begin
1137        SetValuesFromResponses;
1138      end;
1139  end;
1140  
1141  { tabFluid events }
1142  
1143  procedure TfrmODMedIV.tabFluidChange(Sender: TObject);
1144  begin
1145    inherited;
1146    case TabFluid.TabIndex of
1147    0: begin
1148         cboSolution.Visible := True;
1149         cboAdditive.Visible := False;
1150       end;
1151    1: begin
1152         cboAdditive.Visible := True;
1153         cboSolution.Visible := False;
1154       end;
1155    end;
1156    if cboSolution.Visible then
1157      ActiveControl := cboSolution;
1158    if cboAdditive.Visible then
1159      ActiveControl := cboAdditive;
1160  end;
1161  
1162  { cboSolution events }
1163  
1164  procedure TfrmODMedIV.cboSolutionNeedData(Sender: TObject; const StartFrom: string;
1165    Direction, InsertAt: Integer);
1166  begin
1167    cboSolution.ForDataUse(SubSetOfOrderItems(StartFrom, Direction, 'S.IVB RX'));
1168  end;
1169  
1170  procedure TfrmODMedIV.cboTypeChange(Sender: TObject);
1171  var
1172  i: integer;
1173  begin
1174    inherited;
1175    //if (self.cbotype.Text = 'Intermittent') or (self.cboType.itemIndex = 1) then
1176    if (self.cboType.itemIndex = 1) then
1177      begin
1178        cboSchedule.ItemIndex := -1;
1179        lblAdminTime.Caption := '';
1180        lblAdminTime.Visible := false;
1181        lblschedule.Enabled := True;
1182        cboSchedule.Enabled := True;
1183        txtNSS.Visible := true;
1184        chkDoseNow.Checked := false;
1185        chkDoseNow.Visible := true;
1186        chkPRN.Checked := false;
1187        chkPRN.Enabled := True;
1188        lblInfusionRate.Caption := 'Infuse Over Time (Optional)';
1189        cboInfusionTime.Enabled := true;
1190        if cboDuration.items.IndexOf('doses') = -1 then cboDuration.Items.Add('doses');
1191        //AGP ADDITIVE FREQUECNY CHANGES
1192        lblAddFreq.Caption := 'Additive Frequency';
1193        for i := 0 to grdselected.RowCount - 1 do
1194          begin
1195            if (TIVComponent(grdselected.Objects[0, i]) <> nil) and (TIVComponent(grdselected.Objects[0, i]).Fluid = 'A') then
1196              begin
1197                grdSelected.Cells[3, i] := 'N/A';
1198              end;
1199          end;
1200      end
1201    //else if (self.cbotype.Text = 'Continuous') or (self.cboType.itemIndex = 0) then
1202    else
1203      begin
1204        lblschedule.Enabled := False;
1205        cboSchedule.ItemIndex := -1;
1206        cboSchedule.Enabled := False;
1207        txtNSS.Visible := false;
1208        chkPRN.Checked := false;
1209        chkPRN.Enabled := false;
1210        if chkDoseNow.Visible = true then chkDoseNow.Checked := false;
1211        chkDoseNow.Visible := false;
1212        lblInfusionRate.Caption := 'Infusion Rate (ml/hr)*';
1213        cboInfusionTime.ItemIndex := -1;
1214        cboInfusionTime.Text := '';
1215        cboInfusionTime.Enabled := false;
1216        lblAdminTime.Visible := false;
1217        UpdateDuration('');
1218        cboduration.Items.Delete(cboDuration.Items.IndexOf('doses'));
1219        lblAddFreq.Caption := 'Additive Frequency*';
1220        if FIVTypeDefined = True then
1221          begin
1222            for i := 0 to grdselected.RowCount - 1 do
1223              begin
1224                if (TIVComponent(grdselected.Objects[0, i]) <> nil) and (TIVComponent(grdselected.Objects[0, i]).Fluid = 'A') then
1225                  begin
1226                    grdSelected.Cells[3, i] := '';
1227                  end;
1228              end;
1229          end;
1230      end;
1231    FIVTypeDefined := True;
1232    self.txtRate.Text := '';
1233    ControlChange(Sender);
1234  end;
1235  
1236  procedure TfrmODMedIV.cboTypeKeyDown(Sender: TObject; var Key: Word;
1237    Shift: TShiftState);
1238  begin
1239    inherited;
1240    if IsAltCtrl_L_Pressed(Shift, Key) then
1241      lblTypeHelpClick(lblTypeHelp);
1242  end;
1243  
1244  function TfrmODMedIV.IsAltCtrl_L_Pressed(Shift : TShiftState; Key : Word) : Boolean;
1245  begin
1246    Result := (ssCtrl in Shift) and (ssAlt in Shift) and (Key = Ord('L'));
1247  end;
1248  
1249  procedure TfrmODMedIV.chkDoseNowClick(Sender: TObject);
1250  Const
1251    T  = '"';
1252    T1 = 'By checking the "Give additional dose now" box, you have actually entered two orders for the same medication.';
1253    T2 = #13#13'The first order''s administrative schedule is "';
1254    T3 = #13'The second order''s administrative schedule is "';
1255    T4 = #13#13'Do you want to continue?';    
1256    T5 = '" and a priority of "';
1257    T1A = 'By checking the "Give additional dose now" box, you have actually entered a new order with the schedule "NOW"';
1258    T2A = ' in addition to the one you are placing for the same medication.';
1259  var
1260    medNm: string;
1261    theSch: string;
1262    ordPriority: string;
1263    //SchID: integer;
1264  begin
1265    inherited;
1266    if (chkDoseNow.Checked) then
1267    begin
1268      medNm := 'Test';
1269      //SchID := cboSchedule.ItemIndex;
1270      theSch := cboSchedule.Text;
1271      ordPriority := cboPriority.SelText;
1272      if length(theSch)>0 then
1273      begin
1274        //if (InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL)then
1275        //if (InfoBox(T1+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL)then
1276        if (InfoBox(T1+T2+'NOW'+T5+ordPriority+T+T3+theSch+T5+ordPriority+T+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL)then
1277        begin
1278          chkDoseNow.Checked := False;
1279          Exit;
1280        end;
1281      end else
1282      begin
1283        //if InfoBox(T1A+T2A+medNm+T+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL then
1284        if InfoBox(T1A+T2A+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL then
1285        begin
1286          chkDoseNow.Checked := False;
1287          Exit;
1288        end;
1289      end;
1290    end;
1291    ControlChange(self);
1292  end;
1293  
1294  procedure TfrmODMedIV.chkPRNClick(Sender: TObject);
1295  begin
1296    inherited;
1297    ControlChange(Self);
1298  end;
1299  
1300  procedure TfrmODMedIV.cboSolutionMouseClick(Sender: TObject);
1301  var
1302    AnIVComponent: TIVComponent;
1303    x,routeIEN, DEAFailStr, TX_INFO: string;
1304    i: integer;
1305  begin
1306    inherited;
1307    if CharAt(cboSolution.ItemID, 1) = 'Q' then              // setup quick order
1308    begin
1309      //Clear pre-existing values
1310      for i := 0 to self.grdSelected.RowCount do
1311        begin
1312           if self.grdSelected.Objects[0,i] <> nil then
1313             begin
1314               TIVComponent(self.grdSelected.Objects[0,i]).Free;
1315               self.grdSelected.Rows[i].Clear;
1316             end
1317           else self.grdSelected.Rows[i].clear;
1318        end;
1319      self.grdSelected.RowCount := 0;
1320      ControlChange(Sender);
1321      Responses.QuickOrder := ExtractInteger(cboSolution.ItemID);
1322      SetValuesFromResponses;
1323      cboSolution.ItemIndex := -1;
1324      Exit;
1325    end;
1326    if cboSolution.ItemIEN <= 0 then Exit;                   // process selection of solution
1327    FInpatient := OrderForInpatient;
1328    DEAFailStr := '';
1329    if not FInpatient then
1330    begin
1331      DEAFailStr := DEACheckFailedForIVOnOutPatient(cboSolution.ItemIEN,'S');
1332      while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
1333        begin
1334          case StrToIntDef(Piece(DEAFailStr,U,1),0) of
1335            1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
1336            2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
1337            3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
1338            4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
1339            5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
1340          end;
1341          if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
1342            begin
1343              DEAContext := True;
1344              fFrame.frmFrame.mnuFileEncounterClick(self);
1345              DEAFailStr := '';
1346              DEAFailStr := DEACheckFailedForIVOnOutPatient(cboSolution.ItemIEN,'S');
1347            end
1348          else
1349            begin
1350              cboSolution.Text := '';
1351              Exit;
1352            end;
1353        end
1354    end else
1355    begin
1356      DEAFailStr := DEACheckFailed(cboSolution.ItemIEN, FInpatient);
1357      while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
1358        begin
1359          case StrToIntDef(Piece(DEAFailStr,U,1),0) of
1360            1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
1361            2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
1362            3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
1363            4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
1364            5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
1365          end;
1366          if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
1367            begin
1368              DEAContext := True;
1369              fFrame.frmFrame.mnuFileEncounterClick(self);
1370              DEAFailStr := '';
1371              DEAFailStr := DEACheckFailed(cboSolution.ItemIEN, FInpatient);
1372            end
1373          else
1374            begin
1375              cboSolution.Text := '';
1376              Exit;
1377            end;
1378        end
1379    end;
1380    RouteIEN := Piece(cboSolution.Items.Strings[cboSolution.itemindex],U,4);
1381    x := AmountsForIVFluid(cboSolution.ItemIEN, 'B');
1382    AnIVComponent := TIVComponent.Create;
1383    AnIVComponent.IEN     := cboSolution.ItemIEN;
1384    AnIVComponent.Name    := Piece(cboSolution.Items[cboSolution.ItemIndex], U, 3);
1385    AnIVComponent.Fluid   := 'B';
1386    AnIVComponent.Amount  := StrToIntDef(Piece(x, U, 2), 0);
1387    AnIVComponent.Units   := Piece(x, U, 1);
1388    AnIVComponent.Volumes := Copy(x, Pos(U, x) + 1, Length(x));
1389    cboSolution.ItemIndex := -1;
1390    with grdSelected do
1391    begin
1392      if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
1393      Objects[0, RowCount - 1] := AnIVComponent;
1394      Cells[0, RowCount - 1] := AnIVComponent.Name;
1395      Cells[1, RowCount - 1] := IntToStr(AnIVComponent.Amount);
1396      Cells[2, RowCount - 1] := AnIVComponent.Units;
1397      Cells[3, RowCount - 1] := 'N/A';
1398      Row := RowCount - 1;
1399      if Length(Piece(AnIVComponent.Volumes, U, 2)) > 0 then Col := 1 else Col := 0;
1400    (*  if RowCount = 1 then        // switch to additives after 1st IV
1401      begin
1402         tabFluid.TabIndex := 1;
1403         tabFluidChange(Self);
1404      end;  *)
1405    end;
1406    Application.ProcessMessages;         //CQ: 10157
1407    UpdateRoute;
1408    ClickOnGridCell;
1409    //updateRoute;
1410    ControlChange(Sender);
1411    //updateRoute(routeIEN);
1412  end;
1413  
1414  procedure TfrmODMedIV.cboSolutionExit(Sender: TObject);
1415  begin
1416    inherited;
1417    if EnterIsPressed then //CQ: 15097
1418      if (cboSolution.ItemIEN > 0) or
1419         ((cboSolution.ItemIEN = 0) and (CharAt(cboSolution.ItemID, 1) = 'Q')) then
1420        cboSolutionMouseClick(Self);
1421  end;
1422  
1423  { cboAdditive events }
1424  
1425  procedure TfrmODMedIV.cboAdditiveNeedData(Sender: TObject; const StartFrom: string;
1426    Direction, InsertAt: Integer);
1427  begin
1428    cboAdditive.ForDataUse(SubSetOfOrderItems(StartFrom, Direction, 'S.IVA RX'));
1429  end;
1430  
1431  procedure TfrmODMedIV.cboAddFreqCloseUp(Sender: TObject);
1432  begin
1433    inherited;
1434    with cboAddFreq do
1435    begin
1436      if tag < 0 then exit;
1437      grdSelected.Cells[Tag div 256, Tag mod 256] := MixedCase(items.Strings[itemindex]);
1438      Tag := -1;
1439      Hide;
1440      ControlChange(Sender);
1441      TControl(self.grdSelected).Enabled := True;
1442      ActiveControl := self.grdSelected;
1443    end;
1444    grdSelected.Refresh;
1445  end;
1446  
1447  procedure TfrmODMedIV.cboAddFreqKeyDown(Sender: TObject; var Key: Word;
1448    Shift: TShiftState);
1449  begin
1450    inherited;
1451    if (Key = VK_RETURN) or (Key = VK_Tab) then
1452    begin
1453      cboAddFreqCloseUp(cboAddFreq);
1454      Key := 0;
1455    end;
1456  end;
1457  
1458  procedure TfrmODMedIV.cboDurationChange(Sender: TObject);
1459  begin
1460    inherited;
1461    if (FOriginalDurationType > -1) and (FOriginalDurationType <> cboDuration.ItemIndex) then
1462      begin
1463        self.txtXDuration.Text := '';
1464        FOriginalDurationType := cboDuration.ItemIndex;
1465      end;
1466    if (FOriginalDurationType = -1) and (cboDuration.ItemIndex > -1) then FOriginalDurationType := cboDuration.ItemIndex;
1467    ControlChange(sender);
1468  end;
1469  
1470  procedure TfrmODMedIV.cboDurationEnter(Sender: TObject);
1471  begin
1472    inherited;
1473    FOriginalDurationType := cboDuration.ItemIndex;
1474  end;
1475  
1476  
1477  procedure TfrmODMedIV.cboInfusionTimeChange(Sender: TObject);
1478  begin
1479    inherited;
1480    if (FOriginalInfusionType > -1) and (FOriginalInfusionType <> cboInfusionTime.ItemIndex) then
1481       begin
1482         self.txtRate.Text := '';
1483         FOriginalInfusionType := cboInfusionTime.ItemIndex;
1484       end;
1485    if (FOriginalInfusionType = -1) and (cboInfusionTime.ItemIndex > -1) then FOriginalInfusionType := cboInfusionTime.ItemIndex;
1486    ControlChange(Sender);
1487  end;
1488  
1489  procedure TfrmODMedIV.cboInfusionTimeEnter(Sender: TObject);
1490  begin
1491    inherited;
1492    FOriginalInfusionType := self.cboInfusionTime.ItemIndex;
1493  end;
1494  
1495  procedure TfrmODMedIV.cboPriorityChange(Sender: TObject);
1496  begin
1497    inherited;
1498    ControlChange(sender);
1499  end;
1500  
1501  procedure TfrmODMedIV.cboPriorityExit(Sender: TObject);
1502  begin
1503    inherited;
1504    if cboPriority.Text = '' then
1505      begin
1506        infoBox('Priority must have a value assigned to it', 'Warning', MB_OK);
1507        cboPriority.SetFocus;
1508      end;
1509  end;
1510  
1511  procedure TfrmODMedIV.cboPriorityKeyUp(Sender: TObject; var Key: Word;
1512    Shift: TShiftState);
1513  begin
1514    inherited;
1515    if (Key = VK_BACK) and (cboPriority.Text = '') then cboPriority.ItemIndex := -1;
1516  end;
1517  
1518  procedure TfrmODMedIV.cboRouteChange(Sender: TObject);
1519  begin
1520    inherited;
1521    if cboRoute.ItemIndex = cboRoute.Items.IndexOf('OTHER') then cboRouteClick(cboRoute);
1522    ControlChange(sender);
1523  end;
1524  
1525  procedure TfrmODMedIV.cboRouteClick(Sender: TObject);
1526  var
1527  otherRoute, temp: string;
1528  idx, oidx: integer;
1529  begin
1530    inherited;
1531    oidx := cboRoute.Items.IndexOf('OTHER');
1532    if oidx = -1 then exit;
1533    
1534    if cboRoute.ItemIndex = oidx then
1535      begin
1536        otherRoute := CreateOtherRoute;
1537        if length(otherRoute) > 1 then
1538          begin
1539            idx := cboRoute.Items.IndexOf(Piece(OtherRoute, U, 2));
1540            if idx > -1 then
1541              begin
1542                temp := cboRoute.Items.Strings[idx];
1543                //setPiece(temp,U,5,'1');
1544                cboRoute.Items.Strings[idx] := temp;
1545              end
1546            else
1547            begin
1548               cboRoute.Items.Add(otherRoute);
1549               idx := cboRoute.Items.IndexOf(Piece(OtherRoute, U, 2));
1550            end;
1551            cboRoute.ItemIndex := idx;
1552          end
1553        else
1554          begin
1555            cboRoute.ItemIndex := -1;
1556            cboRoute.SetFocus;
1557          end;
1558      end;
1559  end;
1560  
1561  procedure TfrmODMedIV.cboRouteExit(Sender: TObject);
1562  begin
1563    inherited;
1564  (*  if (cboRoute.Text <> '') and (cboRoute.ItemIndex = -1)  then
1565      begin
1566        infoBox(TX_BAD_ROUTE,'Warning',MB_OK);
1567        cboRoute.SetFocus;
1568      end; *)
1569  end;
1570  
1571  procedure TfrmODMedIV.cboRouteKeyDown(Sender: TObject; var Key: Word;
1572    Shift: TShiftState);
1573  begin
1574    inherited;
1575    if IsAltCtrl_L_Pressed(Shift, Key) then
1576      txtAllIVRoutesClick(txtAllIVRoutes);
1577  end;
1578  
1579  procedure TfrmODMedIV.cboRouteKeyUp(Sender: TObject; var Key: Word;
1580    Shift: TShiftState);
1581  begin
1582    inherited;
1583    if (Key = VK_BACK) and (cboRoute.Text = '') then cboRoute.ItemIndex := -1;  
1584  end;
1585  
1586  procedure TfrmODMedIV.cboAdditiveMouseClick(Sender: TObject);
1587  var
1588    AnIVComponent: TIVComponent;
1589    x, routeIEN, DEAFailStr, TX_INFO: string;
1590  begin
1591    inherited;
1592    if cboAdditive.ItemIEN <= 0 then Exit;
1593    FInpatient := OrderForInpatient;
1594    DEAFailStr := '';
1595    if not FInpatient then
1596    begin
1597      DEAFailStr := DEACheckFailedForIVOnOutPatient(cboAdditive.ItemIEN,'A');
1598      while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
1599        begin
1600          case StrToIntDef(Piece(DEAFailStr,U,1),0) of
1601            1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
1602            2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
1603            3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
1604            4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
1605            5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
1606          end;
1607          if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
1608            begin
1609              DEAContext := True;
1610              fFrame.frmFrame.mnuFileEncounterClick(self);
1611              DEAFailStr := '';
1612              DEAFailStr := DEACheckFailedForIVOnOutPatient(cboAdditive.ItemIEN,'A');
1613            end
1614          else
1615            begin
1616              cboAdditive.Text := '';
1617              Exit;
1618            end;
1619        end;
1620    end else
1621    begin
1622      DEAFailStr := DEACheckFailed(cboAdditive.ItemIEN, FInpatient);
1623      while StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5] do
1624        begin
1625          case StrToIntDef(Piece(DEAFailStr,U,1),0) of
1626            1:  TX_INFO := TX_DEAFAIL;  //prescriber has an invalid or no DEA#
1627            2:  TX_INFO := TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
1628            3:  TX_INFO := TX_NO_DETOX;  //prescriber has an invalid or no Detox#
1629            4:  TX_INFO := TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
1630            5:  TX_INFO := TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
1631          end;
1632          if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
1633            begin
1634              DEAContext := True;
1635              fFrame.frmFrame.mnuFileEncounterClick(self);
1636              DEAFailStr := '';
1637              DEAFailStr := DEACheckFailed(cboAdditive.ItemIEN, FInpatient);
1638            end
1639          else
1640            begin
1641              cboAdditive.Text := '';
1642              Exit;
1643            end;
1644        end;
1645    end;
1646    routeIEN := Piece(cboAdditive.Items.Strings[cboAdditive.itemindex],U,4);
1647    x := AmountsForIVFluid(cboAdditive.ItemIEN, 'A');
1648    AnIVComponent := TIVComponent.Create;
1649    AnIVComponent.IEN     := cboAdditive.ItemIEN;
1650    AnIVComponent.Name    := Piece(cboAdditive.Items[cboAdditive.ItemIndex], U, 3);
1651    AnIVComponent.Fluid   := 'A';
1652    AnIVComponent.Amount  := 0;
1653    AnIVComponent.Units   := Piece(x, U, 1);
1654    AnIVComponent.Volumes := '';
1655    cboAdditive.ItemIndex := -1;
1656    with grdSelected do
1657    begin
1658      if Objects[0, RowCount - 1] <> nil then RowCount := RowCount + 1;
1659      Objects[0, RowCount - 1] := AnIVComponent;
1660      Cells[0, RowCount - 1] := AnIVComponent.Name;
1661      Cells[2, RowCount - 1] := AnIVComponent.Units;
1662      Cells[3, RowCount -1] :=  UpdateAddFreq(AnIVComponent.IEN);
1663      Row := RowCount - 1;
1664      Col := 1;
1665    end;
1666    Application.ProcessMessages;         //CQ: 10157
1667    ClickOnGridCell;
1668    UpdateRoute;
1669    ControlChange(Sender);
1670    //UpdateRoute(RouteIEN);
1671  end;
1672  
1673  procedure TfrmODMedIV.cboAdditiveExit(Sender: TObject);
1674  begin
1675    inherited;
1676    if (cboAdditive.ItemIEN > 0) and (EnterIsPressed) then
1677      cboAdditiveMouseClick(Self);
1678  end;
1679  
1680  { grdSelected events }
1681  
1682  procedure TfrmODMedIV.ClearAllFields;
1683  begin
1684    self.cboType.ItemIndex := -1;
1685    self.cboType.Text := '';
1686    self.memComments.Text := '';
1687    self.txtRate.Text := '';
1688    self.txtXDuration.text := '';
1689    self.cboDuration.ItemIndex := -1;
1690    self.cboDuration.Text := '';
1691    self.txtAllIVRoutes.Visible := false;
1692    //self.FInitialOrderID := True;
1693    cboTypeChange(self.cboType);
1694    if self.cboroute.Items.Count > 0 then self.cboRoute.Clear;
1695    FIVTypeDefined := false;
1696  end;
1697  
1698  procedure TfrmODMedIV.ClickOnGridCell;
1699  var
1700    AnIVComponent: TIVComponent;
1701  
1702    procedure PlaceControl(AControl: TWinControl);
1703    var
1704      ARect: TRect;
1705    begin
1706      with AControl do
1707      begin
1708        ARect := grdSelected.CellRect(grdSelected.Col, grdSelected.Row);
1709        SetBounds(ARect.Left + grdSelected.Left + 1,  ARect.Top  + grdSelected.Top + 1,
1710                  ARect.Right - ARect.Left + 1,       ARect.Bottom - ARect.Top + 1);
1711        BringToFront;
1712        Show;
1713        SetFocus;
1714        if AControl is TComboBox then                    //CQ: 10157
1715          begin
1716            TComboBox(AControl).DroppedDown := True;
1717            TControl(self.grdSelected).Enabled := false;
1718          end;
1719      end;
1720    end;
1721  
1722  begin
1723    AnIVComponent := TIVComponent(grdSelected.Objects[0, grdSelected.Row]);
1724    if (AnIVComponent = nil) or (grdSelected.Col = 0) then
1725      begin
1726        if (AnIVComponent <> nil) and (grdSelected.Col = 0) then grdSelected.Refresh;
1727        Exit;
1728      end;
1729    // allow selection if more the 1 unit to choose from
1730    if (grdSelected.Col = 2) and (Length(Piece(AnIVComponent.Units, U, 2)) > 0) then
1731    begin
1732      PiecesToList(AnIVComponent.Units, U, cboSelected.Items);
1733      cboSelected.ItemIndex := cboSelected.Items.IndexOf(grdSelected.Cells[grdSelected.Col, grdSelected.Row]);
1734      cboSelected.Tag  := (grdSelected.Col * 256) + grdSelected.Row;
1735      PlaceControl(cboSelected);
1736    end;
1737    // allow selection if more than 1 volume to choose from
1738    if (grdSelected.Col = 1) and (Length(Piece(AnIVComponent.Volumes, U, 2)) > 0) then
1739    begin
1740      PiecesToList(AnIVComponent.Volumes, U, cboSelected.Items);
1741      cboSelected.ItemIndex := cboSelected.Items.IndexOf(grdSelected.Cells[grdSelected.Col, grdSelected.Row]);
1742      cboSelected.Tag  := (grdSelected.Col * 256) + grdSelected.Row;
1743      PlaceControl(cboSelected);
1744    end;
1745    // display text box to enter strength if the entry is an additive
1746    if (grdSelected.Col = 1) and (AnIVComponent.Fluid = 'A') then
1747    begin
1748      txtSelected.Text := grdSelected.Cells[grdSelected.Col, grdSelected.Row];
1749      txtSelected.Tag  := (grdSelected.Col * 256) + grdSelected.Row;
1750      PlaceControl(txtSelected);
1751    end;
1752    // AGP ADDITIVE FREQUENCY CHANGES
1753    if (Self.cboType.ItemIndex < 1) and (grdSelected.Col = 3) and (AnIVComponent.Fluid = 'A') then
1754    begin
1755      cboAddFreq.ItemIndex := cboAddFreq.Items.IndexOf(grdSelected.Cells[grdSelected.Col, grdSelected.Row]);
1756      cboAddFreq.Tag  := (grdSelected.Col * 256) + grdSelected.Row;
1757      PlaceControl(cboAddFreq);
1758    end;
1759  end;
1760  
1761  procedure TfrmODMedIV.txtSelectedChange(Sender: TObject);   // text editor for grid
1762  begin
1763    inherited;
1764    with txtSelected do
1765    begin
1766      if Tag < 0 then Exit;
1767      grdSelected.Cells[Tag div 256, Tag mod 256] := Text;
1768    end;
1769    ControlChange(Sender);
1770  end;
1771  
1772  procedure TfrmODMedIV.txtSelectedExit(Sender: TObject);
1773  begin
1774    inherited;
1775    with txtSelected do
1776    begin
1777      grdSelected.Cells[Tag div 256, Tag mod 256] := Text;
1778      Tag := -1;
1779      Hide;
1780    end;
1781    grdSelected.Refresh;
1782  end;
1783  
1784  
1785  
1786  procedure TfrmODMedIV.txtSelectedKeyDown(Sender: TObject; var Key: Word;
1787    Shift: TShiftState);
1788  begin
1789    inherited;
1790    if (Key = VK_RETURN) or (Key = VK_Tab) then
1791      begin
1792        ActiveControl := grdSelected;
1793        Key := 0;
1794      end;
1795  end;
1796  
1797  procedure TfrmODMedIV.cboScheduleChange(Sender: TObject);
1798  var
1799  othSch: string;
1800  idx: integer;
1801  begin
1802    inherited;
1803     if self.txtXDuration.Enabled = true then
1804       begin
1805         self.txtXDuration.Text := '';
1806         self.cboDuration.ItemIndex := -1;
1807       end;
1808     if self.cboSchedule.ItemIndex > -1 then
1809        begin
1810          if cboSchedule.ItemIndex = cboSchedule.Items.IndexOf('Other') then
1811            begin
1812              othSch := CreateOtherSchedule;
1813              if length(trim(othSch)) > 1 then
1814                begin
1815                  cboSchedule.Items.Add(othSch + U + U + NSSScheduleType + U + NSSAdminTime);
1816                  idx := cboSchedule.Items.IndexOf(Piece(OthSch, U, 1));
1817                  cboSchedule.ItemIndex := idx;
1818              end
1819              else cboSchedule.itemindex := -1;
1820          end;
1821          if cboSchedule.itemIndex > -1  then  UpdateDuration(Piece(cboSchedule.Items.Strings[cboSchedule.itemindex],U,3));
1822        end;
1823    ControlChange(sender);
1824  end;
1825  
1826  procedure TfrmODMedIV.cboScheduleClick(Sender: TObject);
1827  var
1828    othSch: string;
1829    idx: integer;
1830  begin
1831    inherited;
1832    if cboSchedule.ItemIndex = cboSchedule.Items.IndexOf('Other') then
1833      begin
1834        othSch := CreateOtherSchedule;
1835        if length(trim(othSch)) > 1 then
1836          begin
1837            cboSchedule.Items.Add(othSch + U + U + NSSScheduleType + U + NSSAdminTime);
1838            idx := cboSchedule.Items.IndexOf(Piece(OthSch, U, 1));
1839            cboSchedule.ItemIndex := idx;
1840          end;
1841      end
1842    else
1843      begin
1844        NSSAdminTime := '';
1845        NSSScheduleType := '';
1846      end;
1847  end;
1848  
1849  procedure TfrmODMedIV.cboScheduleExit(Sender: TObject);
1850  begin
1851    inherited;
1852      if (cboSchedule.ItemIndex = -1) and (cboSchedule.Text <> '') then
1853      begin
1854        infoBox('Please select a valid schedule from the list.'+ CRLF + CRLF +
1855                'If you would like to create a Day-of-Week schedule please select ''OTHER'' from the list.',
1856                'Incorrect Schedule.', MB_OK);
1857        cboSchedule.Text := '';
1858        cboSchedule.SetFocus;
1859      end;
1860      if (cboSchedule.ItemIndex > -1) and (cboSchedule.Text = '') then cboSchedule.ItemIndex := -1;
1861  end;
1862  
1863  procedure TfrmODMedIV.cboScheduleKeyDown(Sender: TObject; var Key: Word;
1864    Shift: TShiftState);
1865  begin
1866    inherited;
1867    if IsAltCtrl_L_Pressed(Shift, Key) then
1868      txtNSSClick(txtNSS);
1869  end;
1870  
1871  procedure TfrmODMedIV.cboScheduleKeyUp(Sender: TObject; var Key: Word;
1872    Shift: TShiftState);
1873  begin
1874    inherited;
1875    if (Key = VK_BACK) and (cboSchedule.Text = '') then cboSchedule.ItemIndex := -1;  
1876  end;
1877  
1878  procedure TfrmODMedIV.cboSelectedCloseUp(Sender: TObject);
1879  begin
1880    inherited;
1881    with cboSelected do
1882    begin
1883      if tag < 0 then exit;
1884      grdSelected.Cells[Tag div 256, Tag mod 256] := MixedCase(items.Strings[itemindex]);
1885      Tag := -1;
1886      Hide;
1887      ControlChange(Sender);
1888      TControl(self.grdSelected).Enabled := True;
1889      ActiveControl := self.grdSelected;
1890    end;
1891    grdSelected.Refresh;
1892  end;
1893  
1894  procedure TfrmODMedIV.cboSelectedKeyDown(Sender: TObject; var Key: Word;
1895    Shift: TShiftState);
1896  begin
1897    inherited;
1898    if (Key = VK_RETURN) or (Key = VK_Tab) then
1899    begin
1900      cboSelectedCloseUp(cboSelected);
1901      Key := 0;
1902    end;
1903  end;
1904  
1905  procedure TfrmODMedIV.cmdRemoveClick(Sender: TObject);  // remove button for grid
1906  var
1907    i, stRow, stRowCount: Integer;
1908  begin
1909    inherited;
1910    with grdSelected do
1911    begin
1912      if Row < 0 then Exit;
1913      stRow := Row;
1914      stRowCount := RowCount;
1915      if Objects[0, Row] <> nil then TIVComponent(Objects[0, Row]).Free;
1916      for i := Row to RowCount - 2 do Rows[i] := Rows[i + 1];
1917      Rows[RowCount - 1].Clear;
1918      RowCount := RowCount - 1;
1919    end;
1920    UpdateRoute;
1921    if (stRowCount = 1) and (stRow = 0) then
1922      begin
1923        //self.cboRoute.ItemIndex := -1;
1924        ClearAllFields;
1925      end;
1926    ControlChange(Sender);
1927  end;
1928  
1929  { update Responses & Create Order Text }
1930  
1931  procedure TfrmODMedIV.ControlChange(Sender: TObject);
1932  var
1933    i, CurAdd, CurBase, idx: Integer;
1934    adminTime,x,xlimIn,xLimEx,eSch,iSch,iType, tmpdur, tmpSch, tmpRate: string;
1935    AnIVComponent: TIVComponent;
1936    FQOSchedule: TResponse;
1937  
1938    function IsNumericRate(const x: string): Boolean;
1939    var
1940      i: Integer;
1941    begin
1942      Result := True;
1943      for i := 1 to Length(x) do if not (x[i] in ['0'..'9','.']) then Result := False;
1944    end;
1945  
1946  begin
1947    inherited;
1948    if Changing then Exit;
1949    loadExpectFirstDose;
1950  //  FQOSchedule := TResponse.Create;
1951    FQOSchedule := Responses.FindResponseByName('SCHEDULE',1);
1952    if FQOSchedule <> nil then
1953    begin
1954      eSch := FQOSchedule.EValue;
1955      iSch := FQOSchedule.IValue;
1956    end;
1957    //if Sender <> Self then Responses.Clear;       // Sender=Self when called from SetupDialog
1958    Responses.Clear;   // want this to clear even after SetupDialog in case instances don't match
1959    CurAdd := 1; CurBase := 1;
1960    tmpRate := '';
1961    with grdSelected do for i := 0 to RowCount - 1 do
1962    begin
1963      AnIVComponent := TIVComponent(Objects[0, i]);
1964      if AnIVComponent = nil then Continue;
1965      with AnIVComponent do
1966      begin
1967        if Fluid = 'B' then                        // Solutions
1968        begin
1969          if IEN > 0                then Responses.Update('ORDERABLE', CurBase, IntToStr(IEN), Name);
1970          if Length(Cells[1,i]) > 0 then Responses.Update('VOLUME',    CurBase, Cells[1,i], Cells[1,i]);
1971          Inc(CurBase);
1972        end; {if Fluid B}
1973        if Fluid = 'A' then                        // Additives
1974        begin
1975          if IEN > 0                then Responses.Update('ADDITIVE', CurAdd, IntToStr(IEN), Name);
1976          if Length(Cells[1,i]) > 0 then Responses.Update('STRENGTH', CurAdd, Cells[1,i], Cells[1,i]);
1977          if Length(Cells[2,i]) > 0 then Responses.Update('UNITS',    CurAdd, Cells[2,i], Cells[2,i]);
1978          //AGP ADDITIVE FREQUECNY CHANGES
1979          if (Length(Cells[3,i]) > 0) and (Cells[3,i] <> 'N/A') then Responses.Update('ADDFREQ',    CurAdd, Cells[3,i], Cells[3,i]);
1980          Inc(CurAdd);
1981        end; {if Fluid A}
1982      end; {with AnIVComponent}
1983    end; {with grdSelected}
1984    x := txtRate.Text;
1985    xlimIn := '';
1986    xlimEx := '';
1987    if length(txtXDuration.Text) > 0 then
1988    begin
1989      tmpDur := LowerCase(cboDuration.Text);
1990      if (tmpDur = 'l') or (tmpDur = 'ml') then
1991      begin
1992        xlimEx := 'with total volume ' +  txtXDuration.Text + self.cboDuration.items.strings[self.cboDuration.itemindex];
1993        xlimIn := 'with total volume ' +  txtXDuration.Text + self.cboDuration.items.strings[self.cboDuration.itemindex];
1994      end
1995      else if (tmpDur = 'days') or (tmpDur = 'hours') then
1996      begin
1997        xlimEx := 'for ' + txtXDuration.Text + ' ' +  self.cboDuration.items.strings[self.cboDuration.itemindex];
1998        xlimIn := 'for ' + txtXDuration.Text + ' ' +  self.cboDuration.items.strings[self.cboDuration.itemindex];
1999      end
2000      else if tmpDur = 'doses' then
2001        begin
2002           xlimEx := 'for a total of ' + txtXDuration.Text + ' ' +  self.cboDuration.items.strings[self.cboDuration.itemindex];
2003           xlimIn := 'for a total of ' + txtXDuration.Text + ' ' +  self.cboDuration.items.strings[self.cboDuration.itemindex];
2004        end
2005     else  begin
2006        xlimIn := '';
2007        xlimEx := '';
2008      end;
2009    end;
2010    if (cboType.ItemIndex > -1) and (cboType.Items.Strings[cboType.ItemIndex] = 'Intermittent') then iType := 'I'
2011    else if (cboType.ItemIndex > -1) and (cboType.Items.Strings[cboType.ItemIndex] = 'Continuous') then iType := 'C'
2012    else iType := '';
2013    Responses.Update('TYPE',1,iType,cboType.Text);
2014    Responses.Update('ROUTE',1,cboRoute.ItemID,cboRoute.Text);
2015    tmpSch := UpperCase(Trim(cboSchedule.Text));
2016    if chkPRN.Checked then tmpSch := tmpSch + ' PRN';
2017    if UpperCase(Copy(tmpSch, Length(tmpSch) - 6, Length(tmpSch))) = 'PRN PRN'
2018    then tmpSch := Copy(tmpSch, 1, Length(tmpSch) - 4);
2019    Responses.Update('SCHEDULE',1,tmpSch,tmpSch);
2020    (*adminTime := Piece(lblAdminTime.Caption,':',2);
2021    adminTime := Copy(adminTime,1,Length(adminTime));
2022    if (Action in [ORDER_COPY, ORDER_EDIT]) and ((FAdminTimeDelay <> '') or (FAdminTimeClinic <> '')) and
2023        (cboSchedule.ItemIndex = FOriginalScheduleIndex) then  Responses.Update('ADMIN',1,FOriginalAdminTime,FOriginalAdminTime)
2024    else Responses.Update('ADMIN',1,adminTime,adminTime);*)
2025    idx := self.cboSchedule.ItemIndex;
2026    if idx > -1 then
2027       begin
2028         adminTime := Piece(lblAdminTime.Caption,':',2);
2029         adminTime := Copy(adminTime,2,Length(adminTime));
2030         if FAdminTimeText <> '' then AdminTime :=  '';
2031         if AdminTime = 'Not Defined' then AdminTime := '';
2032         Responses.Update('ADMIN',1,adminTime,adminTime);
2033       end;
2034    if IsNumericRate(x) then
2035      begin
2036        if cboInfusionTime.Enabled = true then
2037          begin
2038             idx := cboInfusionTime.Items.IndexOf(cboInfusionTime.Text);
2039             if idx > -1 then x := x + ' ' + cboInfusionTime.Items.Strings[idx];
2040             tmpRate := 'Infuse Over ' + x;
2041          end
2042        else
2043          if pos('ml/hr', x)= 0 then  x := x + ' ml/hr';
2044      end;
2045    if (Pos('@',x)>0) and (Piece(x,'@',1) = IntToStr(StrToIntDef(Piece(x,'@',1), -1))) and (cboInfusionTime.Enabled = false) then
2046      begin
2047        if Pos('ml/hr', x) = 0 then
2048           x := Piece(x,'@',1) + ' ml/hr@' + Copy(x, Pos('@',x) + 1, Length(x));
2049      end;
2050    with txtRate     do if (Length(Text) > 0) then
2051      begin
2052        if tmpRate = '' then Responses.Update('RATE', 1, x, x)
2053        else Responses.Update('RATE', 1, 'INFUSE OVER ' + x, tmpRate);
2054      end;
2055    with cboPriority do if ItemIndex > -1     then Responses.Update('URGENCY', 1, ItemID, Text);
2056    if Length(xlimIn)>0 then Responses.Update('DAYS',1, xlimIn, xlimEx);
2057    with memComments do if GetTextLen > 0     then Responses.Update('COMMENT', 1, TX_WPTYPE, Text);
2058    if (chkDoseNow.Visible = True) and (chkDoseNow.Checked = True) then
2059      Responses.Update('NOW', 1, '1', 'NOW')
2060    else Responses.Update('NOW', 1, '', '');
2061    memOrder.Text := Responses.OrderText;
2062    (* (Length(eSch)>0) or (Length(iSch)>0) then
2063      Responses.Update('SCHEDULE',1,iSch,eSch);  *)
2064  end;
2065  
2066  function TfrmODMedIV.CreateOtherRoute: string;
2067  var
2068    aRoute: string;
2069  begin
2070    aRoute := '';
2071    Result := '';
2072    if not ShowOtherRoutes(aRoute) then
2073      begin
2074        cboRoute.ItemIndex := -1;
2075        cboRoute.Text := '';
2076      end
2077    else
2078      begin
2079        Result := aRoute;
2080      end;
2081  end;
2082  
2083  function TfrmODMedIV.CreateOtherSchedule: string;
2084  var
2085    aSchedule: string;
2086  begin
2087    aSchedule := '';
2088    cboSchedule.ItemIndex := -1;
2089    cboSchedule.Text      := '';
2090    cboSchedule.DroppedDown := false;
2091    if ShowOtherSchedule(aSchedule) then
2092      begin
2093          Result := Piece(aSchedule,U,1);
2094          NSSAdminTime := Piece(aschedule,u,2);
2095          NSSScheduleType := Piece(ASchedule, U, 3);
2096      end;
2097  end;
2098  
2099  procedure TfrmODMedIV.grdSelectedDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
2100    State: TGridDrawState);
2101  begin
2102    inherited;
2103    //if Sender = ActiveControl then Exit;
2104    //if not (gdSelected in State) then Exit;
2105    with Sender as TStringGrid do
2106    begin
2107      if State = [gdSelected..gdFocused] then
2108        begin
2109          Canvas.Font.Color := Get508CompliantColor(clWhite);
2110          Canvas.Brush.Color := clHighlight;
2111          //Canvas.Font.Color := clHighlightText;
2112          Canvas.Font.Style := [fsBold];
2113          Canvas.MoveTo(Rect.Left,Rect.top);
2114        end
2115      else
2116        begin
2117          if (ACol = 4) and (ColWidths[4] > 0) then
2118            Canvas.Brush.Color := clInactiveBorder
2119          else  Canvas.Brush.Color := clWindow;
2120          Canvas.Font := Font;
2121        end;
2122      Canvas.FillRect(Rect);
2123      //Canvas.Brush.Color := Color;
2124  
2125      Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[ACol, ARow]);
2126    end;
2127  end;
2128  
2129  procedure TfrmODMedIV.SetFontSize( FontSize: integer);
2130  begin
2131    inherited SetFontSize( FontSize );
2132    DoSetFontSize( FontSize );
2133  end;
2134  
2135  procedure TfrmODMedIV.DisplayDoseNow(Status: boolean);
2136  begin
2137    if self.EvtID > 0 then Status := false;
2138    if status = false then
2139      begin
2140        if (self.chkDoseNow.Visible = true) and (self.chkDoseNow.Checked = true) then self.chkDoseNow.Checked := false;
2141        self.chkDoseNow.Visible := false;
2142      end;
2143    if status = true then self.chkDoseNow.Visible := true;
2144  end;
2145  
2146  procedure TfrmODMedIV.DoSetFontSize( FontSize: integer);
2147  begin
2148    tabFluid.TabHeight := Abs(Font.Height) + 4;
2149    grdSelected.DefaultRowHeight := Abs(Font.Height) + 8;
2150  end;
2151  
2152  procedure TfrmODMedIV.FormKeyDown(Sender: TObject; var Key: Word;
2153    Shift: TShiftState);
2154  begin
2155    inherited;
2156    if (Key = VK_TAB) and (ssCtrl in Shift) then
2157    begin
2158      //Back-tab works the same as forward-tab because there are only two tabs.
2159      tabFluid.TabIndex := (tabFluid.TabIndex + 1) mod tabFluid.Tabs.Count;
2160      Key := 0;
2161      tabFluidChange(tabFluid);
2162    end;
2163  end;
2164  
2165  procedure TfrmODMedIV.FormKeyPress(Sender: TObject; var Key: Char);
2166  begin
2167    if (Key = #13) and (ActiveControl = grdSelected) then
2168    Key := #0;   //Don't let the base class turn it into a forward tab!
2169    inherited;
2170  end;
2171  
2172  procedure TfrmODMedIV.grdSelectedKeyPress(Sender: TObject; var Key: Char);
2173  begin
2174    inherited;
2175    ClickOnGridCell;
2176  end;
2177  
2178  procedure TfrmODMedIV.grdSelectedMouseDown(Sender: TObject;
2179    Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
2180  begin
2181    inherited;
2182    ClickOnGridCell;
2183  end;
2184  
2185  procedure TfrmODMedIV.txtXDurationChange(Sender: TObject);
2186  begin
2187    inherited;
2188    if Changing then Exit;
2189    ControlChange(Sender);
2190  end;
2191  
2192  
2193  procedure TfrmODMedIV.pnlXDurationEnter(Sender: TObject);
2194  begin
2195    inherited;
2196    txtXDuration.SetFocus;
2197  end;
2198  
2199  procedure TfrmODMedIV.SetLimitationControl(aValue: string);
2200  var
2201    limitUnit,limitValue,tempval: string;
2202  begin
2203    limitUnit  := '';
2204    limitValue := '';
2205    tempVal := '';
2206    if pos('dose',AValue)>0 then
2207      begin
2208        limitValue := Piece(aValue,' ',5);
2209        limitUnit := 'doses';
2210      end;
2211    if (( CharAt(aValue,1)= 'f') or ( CharAt(aValue,1)= 'F')) and (pos('dose',aValue)=0) then  //days, hours
2212    begin
2213       limitValue := Piece(aValue,' ',2);
2214       limitUnit  := Piece(aValue,' ',3);
2215    end;
2216    if (CharAt(aValue,1)= 'w') or (CharAt(aValue,1)= 'W') then  //L, ml
2217    begin
2218       tempval  := Piece(aValue,' ',4);
2219       limitValue := FloatToStr(ExtractFloat(tempVal));
2220       limitUnit  := Copy(tempVal,length(limitValue)+1,Length(tempVal));
2221    end;
2222    if isNumeric(CharAt(aValue,1)) then
2223    begin
2224      if LeftStr(avalue,1) = '0' then AValue := Copy(aValue,2,Length(aValue));
2225      limitValue := FloatToStr(ExtractFloat(aValue));
2226      limitUnit  := Copy(aValue,length(limitValue)+1,Length(aValue));
2227      if limitUnit = 'D' then limitUnit := 'days'
2228      else if limitUnit = 'H' then limitUnit := 'hours'
2229      else if limitUnit = 'ML' then limitUnit := 'ml';
2230    end;
2231    if ( Length(limitUnit)> 0)  and ( (Length(limitValue) > 0 ) ) then
2232    begin
2233      txtXDuration.Text := limitValue;
2234      if Trim(UpperCase(limitUnit))='CC' then
2235        limitUnit := 'ml';
2236      cboduration.text := limitUnit;
2237      if cboDuration.Text <> '' then cboDuration.ItemIndex := cboDuration.Items.IndexOf(cboDuration.Text)
2238    end;
2239  
2240  end;
2241  
2242  procedure TfrmODMedIV.SetSchedule(const x: string);
2243  var
2244  NonPRNPart,tempSch: string;
2245  idx: integer;
2246  begin
2247      cboSchedule.ItemIndex := -1;
2248      chkPRN.Checked := False;
2249      //Check to see if schedule is already define in the schedule list
2250      idx := cboSchedule.Items.IndexOf(X);
2251      if idx > -1 then
2252        begin
2253          cboSchedule.ItemIndex := idx;
2254          exit;
2255        end;
2256      //if PRN schedule than set the checkbox than exit
2257      if (X = ' PRN') or (X = 'PRN') then
2258        begin
2259          chkPRN.Checked := True;
2260          Exit;
2261        end;
2262        //Check to see if schedule is a Day-of-Week Schedule (MO-WE-FR@BID)
2263        if (Pos('@', x) > 0) then
2264          begin
2265            tempSch := Piece(x, '@', 2);
2266            idx := cboSchedule.Items.IndexOf(tempSch);
2267            if idx > -1 then
2268              begin
2269               //tempSch := U + Piece(x, '@', 1) + '@' + Pieces(cboSchedule.Items.Strings[idx], U, 2, 5);
2270               tempSch := Piece(x, '@', 1) + '@' + cboSchedule.Items.Strings[idx];
2271               cboSchedule.Items.Add(tempSch);
2272               cboSchedule.Text := (Piece(tempSch,U,1));
2273               cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(Piece(tempSch,U,1));
2274               EXIT;
2275              end;
2276            //Check to see if schedule is a Day-of-Week PRN Schedule (MO-WE-FR@BID PRN)
2277            if Pos('PRN', tempSch) > 0 then
2278              begin
2279                NonPRNPart := Trim(Copy(tempSch, 1, Pos('PRN', tempSch) - 1));
2280                idx := cboSchedule.Items.IndexOf(NonPRNPart);
2281                if idx > -1 then
2282                  begin
2283                    //tempSch := U + Piece(x, '@', 1) + '@' + Pieces(cboSchedule.Items.Strings[idx], U, 2, 5);
2284                    tempSch := Piece(x, '@', 1) + '@' + cboSchedule.Items.Strings[idx];
2285                    cboSchedule.Text := (Piece(tempSch,U,1));
2286                    cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(Piece(tempSch, U, 1));
2287                    chkPRN.Checked := True;
2288                    EXIT;
2289                  end
2290                else
2291                 //Add Day-of-Week PRN schedule built off Time Prompt (MO-WE-FR@0800-1000 PRN)
2292                 begin
2293                    NonPRNPart := Trim(Copy(X, 1, Pos('PRN', X) - 1));
2294                    chkPRN.Checked := True;
2295                    //cboSchedule.Items.Add(U + NonPRNPart + U + U + U + AdminTime);
2296                    //cboSchedule.Items.Add(U + NonPRNPart + U + U + U + Piece(NonPRNPart, '@', 2));
2297                    cboSchedule.Items.Add(NonPRNPart + U + U + U + Piece(NonPRNPart, '@', 2));
2298                    cboSchedule.Text := NonPRNPart;
2299                    cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(NonPRNPart);
2300                    EXIT;
2301                 end;
2302              end;
2303           //Add Non PRN Day-of-Week Schedule built off Time Prompt (MO-WE-FR@0800-1000)
2304           //cboSchedule.Items.Add(U + x + U + U + U + AdminTime);
2305           //cboSchedule.Items.Add(U + x + U + U + U + tempSch);
2306           cboSchedule.Items.Add(x + U + U + U + tempSch);
2307           cboSchedule.Text := x;
2308           cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(X);
2309          end
2310          else
2311            begin
2312              //Handle standard schedule mark as PRN (Q4H PRN)
2313              if Pos('PRN', X) > 0 then
2314                begin
2315                  NonPRNPart := Trim(Copy(X, 1, Pos('PRN', X) - 1));
2316                  idx := cboSchedule.Items.IndexOf(NonPRNPart);
2317                  if idx > -1 then
2318                    begin
2319                      cboSchedule.ItemIndex := idx;
2320                      tempSch := cboSchedule.Items.Strings[idx];
2321                      //setPiece(tempSch,U,5,AdminTime);
2322                      cboSchedule.Items.Strings[idx] := tempSch;
2323                      chkPRN.Checked := True;
2324                      exit;
2325                    end;
2326                end;
2327            end;
2328  end;
2329  
2330  
2331  procedure TfrmODMedIV.txtXDurationExit(Sender: TObject);
2332  var
2333    Code: double;
2334  begin
2335    inherited;
2336    if (txtXDuration.Text <> '0') and (txtXDuration.Text <> '') then
2337    begin
2338      try
2339        code := StrToFloat(txtXDuration.Text);
2340      except
2341        code := 0;
2342      end;
2343      if code < 0.0001 then
2344      begin
2345        ShowMsg('Can not save order.' + #13#10 + 'Reason: Invalid Duration or Total Volume!');
2346        txtXDuration.Text := '';
2347        txtXDuration.SetFocus;
2348        Exit;
2349      end;
2350    end;
2351    try
2352      if (Length(txtXDuration.Text)>0) and (StrToFloat(txtXDuration.Text)<0) then
2353      begin
2354        ShowMsg('Can not save order.' + #13#10 + 'Reason: Invalid Duration or total volume!');
2355        txtXDuration.Text := '';
2356        txtXDuration.SetFocus;
2357        Exit;
2358      end;
2359    except
2360      txtXDuration.Text := '';
2361    end;
2362    ControlChange(Sender);
2363  end;
2364  
2365  function TfrmODMedIV.UpdateAddFreq(OI: integer): string;
2366  begin
2367    if (self.cboType.ItemIndex = -1) or (MixedCase(self.cboType.Items.Strings[self.cboType.ItemIndex]) = 'Continuous') then
2368       Result := GetDefaultAddFreq(OI)
2369    else Result := '';
2370  end;
2371  
2372  procedure TfrmODMedIV.UpdateDuration(SchType: string);
2373  begin
2374  if SchType = 'O' then
2375     begin
2376       self.cboDuration.ItemIndex := -1;
2377       self.txtXDuration.Text := '';
2378       self.cboDuration.Enabled := false;
2379       self.txtXDuration.Enabled := false;
2380       self.lblLimit.Enabled := false;
2381     end
2382  else
2383    begin
2384       self.cboDuration.Enabled := true;
2385       self.txtXDuration.Enabled := true;
2386       self.lblLimit.Enabled := true;
2387    end;
2388  end;
2389  
2390  procedure TfrmODMedIV.UpdateRoute;
2391  var
2392  AnIVComponent: TIVComponent;
2393  i: integer;
2394  OrderIds, TempIVRoute: TStringList;
2395  //Default: boolean;
2396  begin
2397    if self.grdSelected.RowCount > 0 then self.txtAllIVRoutes.Visible := True;
2398    TempIVRoute := TStringList.Create;
2399    for I := (self.cboRoute.Items.Count -1) downto 0 do
2400      begin
2401        if Piece(self.cboRoute.Items.Strings[i], U, 5) = '1' then
2402          TempIVRoute.Add(self.cboRoute.Items.Strings[i]);
2403          self.cboRoute.Items.Delete(i);
2404      end;
2405    if self.cboRoute.ItemIndex = -1 then self.cboRoute.Text := '';
2406    OrderIds := TStringList.Create;
2407    for i := 0 to self.grdSelected.RowCount -1  do
2408      begin
2409        AniVComponent := TIVComponent(self.grdSelected.Objects[0, i]);
2410        if AnIVComponent <> nil then  orderIds.Add(InttoStr(AniVComponent.IEN));
2411      end;
2412   if OrderIds.Count > 0 then
2413     begin
2414       //if (self.FInitialOrderID = True) and (self.grdSelected.RowCount = 1) then Default := True
2415       //else Default := False;
2416       LoadDosageFormIVRoutes(self.cboRoute.Items, OrderIds);
2417       //if default = True then
2418       //  begin
2419       for I := 0 to cboRoute.items.Count - 1 do
2420         begin
2421          if Piece(cboRoute.Items.Strings[i], U, 5) = 'D' then
2422            begin
2423             cboRoute.ItemIndex := i;
2424             break;
2425            end;
2426         end;
2427         //  self.FInitialOrderID := false;
2428         //end;
2429       OrderIds.Free;
2430     end;
2431   if TempIVRoute.Count > 0 then
2432     begin
2433       for I := 0 to tempIVRoute.Count - 1 do cboRoute.Items.Add(tempIVRoute.Strings[i]);
2434       TempIVRoute.Free;
2435     end;
2436   cboRoute.Items.Add(U + 'OTHER');
2437  end;
2438  
2439  
2440  procedure TfrmODMedIV.txtAllIVRoutesClick(Sender: TObject);
2441  var
2442    i: integer;
2443    msg : String;
2444  begin
2445    inherited;
2446    msg := 'You can also select "OTHER" from the Route list'
2447       + ' to select a Route from the Expanded Med Route List.'
2448       + #13#10 + 'Click OK to launch the Expanded Med Route List.';
2449    if ShowMsg(msg, smiInfo, smbOKCancel) = smrOk then
2450    begin
2451        for I := 0 to cboRoute.Items.Count - 1 do if cboRoute.Items.Strings[i] = U + 'OTHER' then break;
2452        cboRoute.ItemIndex := i;
2453        cboRouteClick(self);
2454        cboRouteChange(self.cboRoute);
2455    end;
2456  end;
2457  
2458  procedure TfrmODMedIV.txtNSSClick(Sender: TObject);
2459  var
2460    i: integer;
2461    msg : String;
2462  begin
2463    inherited;
2464    msg := 'You can also select ' + '"' + 'Other' + '"' + ' from the schedule list'
2465      + ' to create a day-of-week schedule.'
2466      + #13#10 + 'Click OK to launch schedule builder';
2467    if ShowMsg(msg, smiInfo, smbOKCancel) = smrOK then
2468    begin
2469        //cboSchedule.Items.Add(U + 'OTHER');
2470        for I := 0 to cboSchedule.Items.Count - 1 do if cboSchedule.Items.Strings[i] = 'OTHER' then break;
2471        cboSchedule.ItemIndex := i;
2472        //cboSchedule.SelectByID(U+'OTHER');
2473        cboScheduleClick(Self);
2474        cboScheduleChange(self.cboSchedule);
2475    end;
2476  end;
2477  
2478  procedure TfrmODMedIV.txtRateChange(Sender: TObject);
2479  begin
2480    inherited;
2481    if Changing then Exit;
2482    ControlChange(Sender);
2483  end;
2484  
2485  end.

Module Calls (2 levels)


fODMedIV
 ├fODBase
 │ ├fAutoSz
 │ ├uConst
 │ ├rOrders
 │ ├rODBase
 │ ├uCore
 │ ├UBAGlobals
 │ ├UBACore
 │ ├fOCAccept
 │ ├uODBase
 │ ├rCore
 │ ├rMisc
 │ ├fTemplateDialog
 │ ├uEventHooks
 │ ├uTemplates
 │ ├rConsults
 │ ├fOrders
 │ ├uOrders
 │ ├fFrame
 │ ├fODDietLT
 │ └rODDiet
 ├fIVRoutes
 │ ├rMisc...
 │ ├rODMeds
 │ └fAutoSz...
 ├uConst
 ├rODMeds...
 ├rODBase...
 ├fFrame...
 ├uCore...
 ├fOtherSchedule
 │ ├fAutoSz...
 │ ├rMisc...
 │ └rODMeds...
 └rCore...

Module Called-By (2 levels)


                    fODMedIV
                   uOrders┘ 
                   uCore┤   
                 fODBase┤   
                 rODBase┤   
                  fFrame┤   
                 fOrders┤   
             fOrdersSign┤   
                   fMeds┤   
               fARTAllgy┤   
                  fNotes┤   
               fConsults┤   
         fReminderDialog┤   
                 fReview┤   
            fOrdersRenew┤   
               fOrdersCV┤   
                 fODMeds┤   
                 fOMNavA┤   
         fOrderSaveQuick┤   
                  fOMSet┤   
          fOrdersRelease┤   
                 fOMHTML┤   
               fODMedNVA┤   
fODChangeUnreleasedRenew┤   
          fOrdersOnChart┤   
         fODReleaseEvent┤   
               fODActive┘