source: cprs/branches/foia-cprs/CPRS-Chart/Orders/fOrderVw.pas@ 1071

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

Adding foia-cprs branch

File size: 8.7 KB
Line 
1unit fOrderVw;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 fAutoSz, StdCtrls, ComCtrls, ExtCtrls, ORCtrls, ORFn, rOrders, ORDtTm;
8
9type
10 TfrmOrderView = class(TfrmAutoSz)
11 pnlView: TPanel;
12 lblView: TLabel;
13 Panel1: TPanel;
14 Panel2: TPanel;
15 lblFilter: TLabel;
16 trFilters: TCaptionTreeView;
17 Panel3: TPanel;
18 treService: TCaptionTreeView;
19 lblService: TLabel;
20 Panel4: TPanel;
21 chkDateRange: TCheckBox;
22 GroupBox1: TGroupBox;
23 lblFrom: TLabel;
24 lblThru: TLabel;
25 calFrom: TORDateBox;
26 calThru: TORDateBox;
27 chkInvChrono: TCheckBox;
28 chkByService: TCheckBox;
29 cmdOK: TButton;
30 cmdCancel: TButton;
31 Splitter1: TSplitter;
32 procedure FormCreate(Sender: TObject);
33 procedure treServiceClick(Sender: TObject);
34 procedure cmdCancelClick(Sender: TObject);
35 procedure cmdOKClick(Sender: TObject);
36 procedure chkDateRangeClick(Sender: TObject);
37 procedure calChange(Sender: TObject);
38 procedure trFiltersClick(Sender: TObject);
39 procedure Splitter1Moved(Sender: TObject);
40 private
41 FChanged: Boolean;
42 FDGroup: Integer;
43 FDGroupName: string;
44 FFilter: Integer;
45 FFilterName: string;
46 FInvChrono: Boolean;
47 FByService: Boolean;
48 FTimeFrom: TFMDateTime;
49 FTimeThru: TFMDateTime;
50 procedure LoadDGroups(const Parent: string; Node: TTreeNode);
51 procedure LoadFilters(const Parent: string; Node: TTreeNode);
52 procedure SynchViewData;
53 procedure UpdateViewName;
54 public
55 { Public declarations }
56 end;
57
58procedure SelectOrderView(var OrderView: TOrderView);
59
60implementation
61
62{$R *.DFM}
63
64const
65 TX_DATES = 'To list orders for a specific date range, both From & Thru dates are required.';
66 TC_DATES = 'Error in Date Range';
67
68var
69 uDGroupList: TStringList;
70 uFilterList: TStringList;
71
72procedure SelectOrderView(var OrderView: TOrderView);
73var
74 frmOrderView: TfrmOrderView;
75begin
76 frmOrderView := TfrmOrderView.Create(Application);
77 try
78 ResizeFormToFont(TForm(frmOrderView));
79 with frmOrderView do
80 begin
81 FDGroup := OrderView.DGroup;
82 FFilter := OrderView.Filter;
83 FInvChrono := OrderView.InvChrono;
84 FByService := OrderView.ByService;
85 FTimeFrom := OrderView.TimeFrom;
86 FTimeThru := OrderView.TimeThru;
87 SynchViewData;
88 ShowModal;
89 if FChanged then
90 begin
91 OrderView.Changed := FChanged;
92 OrderView.DGroup := FDGroup;
93 OrderView.Filter := FFilter;
94 OrderView.InvChrono := FInvChrono;
95 OrderView.ByService := FByService;
96 OrderView.TimeFrom := FTimeFrom;
97 OrderView.TimeThru := FTimeThru;
98 OrderView.CtxtTime := 0; // set by RefreshOrderList
99 OrderView.TextView := 0; // set by RefreshOrderList
100 OrderView.ViewName := lblView.Caption;
101 OrderView.EventDelay.EventType := 'C';
102 OrderView.EventDelay.Specialty := 0; // treating specialty only for event delayed
103 OrderView.EventDelay.Effective := 0; // effective date only for discharge orders
104 end
105 else OrderView.Changed := False;
106 end; {with}
107 finally
108 frmOrderView.Release;
109 end;
110end;
111
112procedure TfrmOrderView.FormCreate(Sender: TObject);
113begin
114 inherited;
115 FChanged := False;
116 uDGroupList := TStringList.Create;
117 uFilterList := TStringList.Create;
118 try
119 ListDGroupAll(uDGroupList);
120 LoadDGroups('0', nil);
121
122 ListOrderFiltersAll(uFilterList);
123 LoadFilters('0', nil);
124 finally
125 uDGroupList.Free;
126 uDGroupList := nil;
127 uFilterList.Free;
128 uFilterList := nil;
129 end;
130end;
131
132procedure TfrmOrderView.UpdateViewName;
133const
134 FMT_TIME = 'mm/dd/yy';
135var
136 DateText, FilterText: string;
137begin
138 if chkDateRange.Checked
139 then DateText := ' (' + FormatFMDateTime(FMT_TIME, calFrom.FMDateTime) +
140 ' thru ' + FormatFMDateTIme(FMT_TIME, calThru.FMDateTime) + ')'
141 else DateText := '';
142 if FFilter in [6, 8, 9, 10, 19, 20]
143 then FilterText := FFilterName
144 else FilterText := FFilterName + ' Orders';
145 lblView.Caption := FilterText + ' - ' + FDGroupName + DateText;
146end;
147
148procedure TfrmOrderView.SynchViewData;
149var
150 i: Integer;
151begin
152 with treService.Items do for i := 0 to Count - 1 do if Integer(Item[i].Data) = FDGroup then
153 begin
154 Item[i].Expanded := True;
155 Item[i].Selected := True;
156 FDGroupName := Item[i].Text;
157 Break;
158 end;
159
160 with trFilters.Items do for i := 0 to Count - 1 do if Integer(Item[i].Data) = FFilter then
161 begin
162 Item[i].Expanded := True;
163 Item[i].Selected := True;
164 FDGroupName := Item[i].Text;
165 Break;
166 end;
167
168 if (FTimeFrom > 0) or (FTimeThru > 0) then
169 begin
170 calFrom.FMDateTime := FTimeFrom;
171 calThru.FMDateTime := FTimeThru;
172 chkDateRange.Checked := True;
173 chkDateRangeClick(Self);
174 end;
175 UpdateViewName;
176 chkByService.Checked := FByService;
177 chkInvChrono.Checked := FInvChrono;
178end;
179
180procedure TfrmOrderView.LoadDGroups(const Parent: string; Node: TTreeNode);
181var
182 MyID, MyParent, Name: string;
183 i, IEN: Integer;
184 ChildNode: TTreeNode;
185 HasChildren: Boolean;
186begin
187 with uDGroupList do for i := 0 to Count - 1 do
188 begin
189 MyParent := Piece(Strings[i], U, 3);
190 if MyParent = Parent then
191 begin
192 MyID := Piece(Strings[i], U, 1);
193 IEN := StrToIntDef(MyID, 0);
194 Name := Piece(Strings[i], U, 2);
195 HasChildren := Piece(Strings[i], U, 4) = '+';
196 ChildNode := treService.Items.AddChildObject(Node, Name, Pointer(IEN));
197 if HasChildren then LoadDGroups(MyID, ChildNode);
198 end;
199 end;
200end;
201
202procedure TfrmOrderView.LoadFilters(const Parent: string; Node: TTreeNode);
203var
204 MyID, MyParent, Name: string;
205 i, IEN: Integer;
206 ChildNode: TTreeNode;
207 HasChildren: Boolean;
208begin
209 with uFilterList do for i := 0 to Count - 1 do
210 begin
211 MyParent := Piece(Strings[i], U, 3);
212 if MyParent = Parent then
213 begin
214 MyID := Piece(Strings[i], U, 1);
215 IEN := StrToIntDef(MyID, 0);
216 Name := Piece(Strings[i], U, 2);
217 HasChildren := Piece(Strings[i], U, 4) = '+';
218 ChildNode := trFilters.Items.AddChildObject(Node, Name, Pointer(IEN));
219 if HasChildren then LoadFilters(MyID, ChildNode);
220 end;
221 end;
222end;
223
224procedure TfrmOrderView.treServiceClick(Sender: TObject);
225var
226 Node: TTreeNode;
227begin
228 inherited;
229 Node := treService.Selected;
230 if Node <> nil then
231 begin
232 FDGroup := Integer(Node.Data);
233 FDGroupName := Node.Text;
234 UpdateViewName;
235 end;
236end;
237
238procedure TfrmOrderView.chkDateRangeClick(Sender: TObject);
239begin
240 inherited;
241 lblThru.Enabled := chkDateRange.Checked;
242 calThru.Enabled := chkDateRange.Checked;
243 lblFrom.Enabled := chkDateRange.Checked;
244 calFrom.Enabled := chkDateRange.Checked;
245 if chkDateRange.Checked then
246 begin
247 calFrom.Color := clWindow;
248 calThru.Color := clWindow;
249 if calThru.FMDateTime = 0 then calThru.Text := 'NOW';
250 end else
251 begin
252 calFrom.FMDateTime := 0;
253 calThru.FMDateTime := 0;
254 calFrom.Color := clBtnFace;
255 calThru.Color := clBtnFace;
256 end;
257 UpdateViewName;
258end;
259
260procedure TfrmOrderView.calChange(Sender: TObject);
261begin
262 inherited;
263 UpdateViewName;
264end;
265
266procedure TfrmOrderView.cmdOKClick(Sender: TObject);
267begin
268 inherited;
269 if chkDateRange.Checked and ((not calFrom.IsValid) or (not calThru.IsValid)) then
270 begin
271 InfoBox(TX_DATES, TC_DATES, MB_OK);
272 Exit;
273 end;
274 if chkDateRange.Checked then
275 begin
276 FTimeFrom := calFrom.FMDateTime;
277 FTimeThru := calThru.FMDateTime;
278 end else
279 begin
280 FTimeFrom := 0;
281 FTimeThru := 0;
282 end;
283 FChanged := True;
284 FInvChrono := chkInvChrono.Checked;
285 FByService := chkByService.Checked;
286 Close;
287end;
288
289procedure TfrmOrderView.cmdCancelClick(Sender: TObject);
290begin
291 inherited;
292 Close;
293end;
294
295procedure TfrmOrderView.trFiltersClick(Sender: TObject);
296var
297 Node: TTreeNode;
298begin
299 inherited;
300 Node := trFilters.Selected;
301 if Node <> nil then
302 begin
303 FFilter := Integer(Node.Data);
304 FFilterName := Node.Text;
305 if FFilter = 2 then // disallow date range for active orders view
306 begin
307 chkDateRange.Checked := False;
308 chkDateRangeClick(Self);
309 end;
310 if FFilter in [8, 9, 10, 20] then chkDateRange.Checked := True else
311 begin
312 if (calFrom.Text = '') and (calThru.Text = '') then chkDateRange.Checked := False;
313 end;
314 UpdateViewName;
315 end;
316end;
317
318procedure TfrmOrderView.Splitter1Moved(Sender: TObject);
319begin
320 inherited;
321 Splitter1.Align := alNone;
322 Splitter1.Align := alLeft;
323end;
324
325end.
Note: See TracBrowser for help on using the repository browser.