source: cprs/trunk/CPRS-Chart/fPrintLocation.pas@ 1701

Last change on this file since 1701 was 1679, checked in by healthsevak, 10 years ago

Updating the working copy to CPRS version 28

File size: 19.2 KB
Line 
1unit fPrintLocation;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, fAutoSz, StdCtrls, ExtCtrls, ORCtrls,ORFn, rCore, uCore, oRNet, Math, fOrders, ORClasses, rOrders,
8 fMeds, rMeds, CheckLst, Grids, fFrame, fClinicWardMeds,
9 VA508AccessibilityManager;
10
11type
12 TfrmPrintLocation = class(TfrmAutoSz)
13 pnlTop: TPanel;
14 pnlBottom: TORAutoPanel;
15 orderGrid: TStringGrid;
16 pnlOrder: TPanel;
17 btnOK: TButton;
18 lblText: TLabel;
19 btnClinic: TButton;
20 btnWard: TButton;
21 lblEncounter: TLabel;
22 cbolocation: TORComboBox;
23 ORpnlBottom: TORAutoPanel;
24 orpnlTopBottom: TORAutoPanel;
25 cboEncLoc: TComboBox;
26 procedure pnlFieldsResize(Sender: TObject);
27 procedure orderGridMouseDown(Sender: TObject; Button: TMouseButton;
28 Shift: TShiftState; X, Y: Integer);
29 procedure OrderGridDrawCell(Sender: TObject; ACol, ARow: Integer;
30 Rect: TRect; State: TGridDrawState);
31 procedure orderGridKeyPress(Sender: TObject; var Key: Char);
32 procedure btnClinicClick(Sender: TObject);
33 procedure btnWardClick(Sender: TObject);
34 procedure cbolocationChange(Sender: TObject);
35 procedure cbolocationExit(Sender: TObject);
36 procedure btnOKClick(Sender: TObject);
37 procedure FormResize(Sender: TObject);
38 procedure FormClose(Sender: TObject; var Action: TCloseAction);
39 procedure FormDestroy(Sender: TObject);
40 private
41 { Private declarations }
42 CLoc,WLoc: string;
43 CIEN,WIEN: integer;
44 function ValFor(FieldID, ARow: Integer): string;
45 procedure ShowEditor(ACol, ARow: Integer; AChar: Char);
46 procedure ProcessClinicOrders(WardList, ClinicList: TStringList; WardIEN, ClinicIEN: integer; ContainsIMO: boolean);
47 procedure rpcChangeOrderLocation(pOrderList:TStringList; ContainsIMO: boolean);
48 function ClinicText(ALoc: integer): string;
49 public
50 { Public declarations }
51 CloseOK: boolean;
52 DisplayOrders: boolean;
53 procedure PrintLocation(OrderLst: TStringList; pEncounterLoc: integer; pEncounterLocName, pEncounterLocText: string;
54 pEncounterDT: TFMDateTime; pEncounterVC: Char; var ClinicLst, WardLst: TStringList;
55 var wardIEN: integer; var wardLocation: string; ContainsIMOOrders: boolean; displayEncSwitch: boolean = false);
56 procedure SwitchEncounterLoction(pEncounterLoc: integer; pEncounterLocName, pEncounterLocText: string; pEncounterDT: TFMDateTime; pEncounterVC: Char);
57 function rpcIsPatientOnWard(Patient: string): string;
58 end;
59
60var
61 frmPrintLocation: TfrmPrintLocation;
62 ClinicIEN, WardIen: integer;
63 ASvc, ClinicLocation, WardLocation: string;
64 ClinicArr: TStringList;
65 WardArr: TStringList;
66
67implementation
68
69{$R *.dfm}
70//uses
71//fFrame;
72
73Const
74COL_ORDERINFO = 0;
75COL_ORDERTEXT = 1;
76COL_LOCATION = 2;
77TAB = #9;
78 LOCATION_CHANGE_1 = 'The patient is admitted to ward';
79 LOCATION_CHANGE_2 = 'You have the chart open to a clinic location of';
80 LOCATION_CHANGE_2W = 'You have the chart open with the patient still on ward';
81 LOCATION_CHANGE_3 = 'What Location are these orders associated with?';
82 LOCATION_CHANGE_4 = 'The patient has now been admitted to ward: ';
83
84
85{ TfrmPrintLocation }
86
87
88
89procedure TfrmPrintLocation.btnClinicClick(Sender: TObject);
90var
91i: integer;
92begin
93 inherited;
94 for i := 1 to self.orderGrid.RowCount do
95 begin
96 self.orderGrid.Cells[COL_LOCATION,i] := frmPrintLocation.CLoc;
97 end;
98end;
99
100procedure TfrmPrintLocation.btnOKClick(Sender: TObject);
101var
102i: integer;
103Action: TCloseAction;
104begin
105if ClinicArr = nil then ClinicArr := TStringList.Create;
106if WardArr = nil then wardArr := TStringList.Create;
107 if (frmPrintLocation.cboEncLoc.Enabled = true) and (frmPrintLocation.cboEncLoc.ItemIndex = -1) then
108 begin
109 infoBox('A location must be selected to continue processing patient data', 'Warning', MB_OK);
110 exit;
111 end;
112if frmPrintLocation.DisplayOrders = true then
113 begin
114 for i := 1 to self.orderGrid.RowCount-1 do
115 begin
116 if ValFor(COL_LOCATION, i) = '' then
117 begin
118 infoBox('Every order must have a location define.','Location error', MB_OK);
119 exit;
120 end;
121 if ValFor(COL_LOCATION, i) = frmPrintLocation.CLoc then ClinicArr.Add(ValFor(COL_ORDERINFO, i))
122 else if ValFor(COL_LOCATION, i) = frmPrintLocation.WLoc then WardArr.Add(ValFor(COL_ORDERINFO, i));
123 end;
124 end;
125 CloseOK := True;
126 Action := caFree;
127 frmPrintLocation.FormClose(frmPrintLocation, Action);
128 if Action = caFree then frmPrintLocation.Close;
129end;
130
131procedure TfrmPrintLocation.btnWardClick(Sender: TObject);
132var
133i: integer;
134begin
135 inherited;
136 for i := 1 to self.orderGrid.RowCount do
137 begin
138 self.orderGrid.Cells[COL_LOCATION,i] := frmPrintLocation.WLoc;
139 end;
140end;
141
142procedure TfrmPrintLocation.cbolocationChange(Sender: TObject);
143begin
144self.orderGrid.Cells[COL_LOCATION, self.orderGrid.Row] := self.cbolocation.Text;
145end;
146
147procedure TfrmPrintLocation.cbolocationExit(Sender: TObject);
148begin
149cboLocation.Hide;
150end;
151
152procedure TfrmPrintLocation.FormClose(Sender: TObject;
153 var Action: TCloseAction);
154var
155i :Integer;
156//Action1: TCloseAction;
157begin
158 inherited;
159 if not CloseOK then
160 begin
161 if ClinicArr = nil then ClinicArr := TStringList.Create;
162 if WardArr = nil then wardArr := TStringList.Create;
163 if (frmPrintLocation.cboEncLoc.Enabled = true) and (frmPrintLocation.cboEncLoc.ItemIndex = -1) then
164 begin
165 infoBox('A location must be selected to continue processing patient data', 'Warning', MB_OK);
166 Action := caNone;
167 exit;
168 end;
169 for i := 1 to self.orderGrid.RowCount-1 do
170 begin
171 if ValFor(COL_LOCATION, i) = '' then
172 begin
173 infoBox('Every order must have a location define.','Location error', MB_OK);
174 Action := caNone;
175 exit;
176 end;
177 if ValFor(COL_LOCATION, i) = frmPrintLocation.CLoc then ClinicArr.Add(ValFor(COL_ORDERINFO, i))
178 else if ValFor(COL_LOCATION, i) = frmPrintLocation.WLoc then WardArr.Add(ValFor(COL_ORDERINFO, i));
179 end;
180 CloseOK := True;
181 end;
182 Action := caFree;
183end;
184
185procedure TfrmPrintLocation.FormDestroy(Sender: TObject);
186begin
187 inherited;
188 frmPrintLocation := nil;
189end;
190
191procedure TfrmPrintLocation.FormResize(Sender: TObject);
192begin
193 inherited;
194 pnlFieldsResize(Sender)
195end;
196
197function TfrmPrintLocation.ClinicText(ALoc: integer): string;
198begin
199 if SCallV('ORIMO ISCLOC', [ALoc]) = '1' then Result := LOCATION_CHANGE_2
200 else Result := LOCATION_CHANGE_2W
201end;
202
203procedure TfrmPrintLocation.OrderGridDrawCell(Sender: TObject; ACol,
204 ARow: Integer; Rect: TRect; State: TGridDrawState);
205begin
206 inherited;
207 OrderGrid.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2,
208 Piece(OrderGrid.Cells[ACol, ARow], TAB, 1));
209end;
210
211procedure TfrmPrintLocation.orderGridKeyPress(Sender: TObject; var Key: Char);
212begin
213 inherited;
214 if Key in [#32..#127] then ShowEditor(OrderGrid.Col, OrderGrid.Row, Key);
215end;
216
217procedure TfrmPrintLocation.orderGridMouseDown(Sender: TObject;
218 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
219var
220 ACol, ARow: Integer;
221begin
222 inherited;
223 OrderGrid.MouseToCell(X, Y, ACol, ARow);
224 if (ARow < 0) or (ACol < 0) then Exit;
225 if ACol > COL_ORDERINFO then ShowEditor(ACol, ARow, #0) else
226 begin
227 OrderGrid.Col := COL_ORDERTEXT;
228 OrderGrid.Row := ARow;
229 end;
230 //if OrderGrid.Col <> COL_ORDERTEXT then
231 //DropLastSequence;
232end;
233
234
235procedure TfrmPrintLocation.pnlFieldsResize(Sender: TObject);
236Const
237 REL_ORDER = 0.85;
238 REL_LOCATION = 0.15;
239var
240 i, center, diff, ht, RowCountShowing: Integer;
241 ColControl: TWinControl;
242begin
243 inherited;
244 if frmPrintLocation = nil then exit;
245 with frmPrintLocation do
246 begin
247 if (frmPrintLocation.WLoc = '') and (frmPrintLocation.CLoc = '') then exit;
248 lblText.Caption := LOCATION_CHANGE_1 + ': ' + frmPrintLocation.WLoc + CRLF;
249 if frmPrintLocation.DisplayOrders = false then
250 begin
251 if frmPrintlocation.CLoc = '' then
252 begin
253 lblText.Caption := LOCATION_CHANGE_4 + frmPrintLocation.WLoc + CRLF;
254 cboEncLoc.Enabled := false;
255 lblEncounter.Enabled := false;
256 end
257 else lblText.Caption := lblText.Caption + ClinicText(frmPrintLocation.CIEN) + ': ' + frmPrintLocation.CLoc + CRLF;
258 btnClinic.Visible := false;
259 btnWard.Visible := false;
260 pnlTop.Height := lbltext.Top + lbltext.Height * 2;
261 pnlbottom.Top := pnltop.Top + pnltop.Height + 3;
262 ordergrid.Height := 1;
263 pnlBottom.Height := 1;
264 lblEncounter.Top := pnlBottom.Top + pnlBottom.Height;
265 cboEncLoc.Top := lblEncounter.Top;
266 cboEncLoc.Left := lblEncounter.Left + lblEncounter.Width + 4;
267 orpnlBottom.Top := cboEncLoc.Top + cboEncLoc.Height +10;
268 end
269 else
270 begin
271 lblText.Caption := lblText.Caption + ClinicText(frmPrintLocation.CIEN) + ': ' + frmPrintLocation.CLoc + CRLF + CRLF;
272 lblText.Caption := lblText.Caption + LOCATION_CHANGE_3;
273 //lblText.Caption := lblText.Caption + CRLF + 'One clinic location allowed; ' + frmPrintLocation.CLoc + ' will be used';
274 btnClinic.Caption := 'All ' + frmPrintLocation.CLoc;
275 btnWard.Caption := 'All ' + frmPrintLocation.WLoc;
276 btnClinic.Width := TextWidthByFont(btnClinic.Handle, btnClinic.Caption);
277 btnWard.Width := TextWidthByFont(btnWard.Handle, btnWard.Caption);
278 center := frmPrintLocation.Width div 2;
279 btnClinic.Left := center - (btnClinic.Width + 3);
280 btnWard.Left := center + 3;
281 end;
282 if pnlTop.Width > width then
283 begin
284 pnltop.Width := width - 8;
285 orpnlTopBottom.Width := pnltop.Width;
286 end;
287 if orpnlTopBottom.Width > pnltop.Width then orpnlTopBottom.Width := pnltop.Width;
288
289 if pnlBottom.Width > width then
290 begin
291 pnlBottom.Width := width - 8;
292 ordergrid.Width := pnlBottom.Width - 2;
293 end;
294 if orderGrid.Width > pnlBottom.Width then orderGrid.Width := pnlBottom.Width - 2;
295 if frmPrintLocation.DisplayOrders = true then
296 begin
297 i := OrderGrid.Width - 12;
298 i := i - GetSystemMetrics(SM_CXVSCROLL);
299 orderGrid.ColWidths[0] := 0;
300 orderGrid.ColWidths[1] := Round(REL_ORDER * i);
301 orderGrid.ColWidths[2] := Round(REL_LOCATION * i);
302 orderGrid.Cells[1,0] := 'Order';
303 orderGrid.Cells[2,0] := 'Location';
304 cboEncLoc.Left := lblEncounter.Left + lblEncounter.Width + 4;
305 ht := pnlBottom.Top - orderGrid.Top - 6;
306 ht := ht div (orderGrid.DefaultRowHeight+1);
307 ht := ht * (orderGrid.DefaultRowHeight+1);
308 Inc(ht, 3);
309 OrderGrid.Height := ht;
310 ColControl := nil;
311 Case OrderGrid.Col of
312 COL_ORDERTEXT:ColCOntrol := pnlOrder;
313 COL_LOCATION:ColControl := cboLocation;
314 End;
315 if assigned(ColControl) and ColControl.Showing then
316 begin
317 RowCountShowing := (Height - 25) div (orderGrid.defaultRowHeight+1);
318 if (OrderGrid.Row <= RowCountShowing) then
319 ShowEditor(OrderGrid.Col, orderGrid.Row, #0)
320 else
321 ColControl.Hide;
322 end;
323 end;
324 diff := frmPrintLocation.btnOK.top;
325 //diff := (frmPrintLocation.ORpnlBottom.Top + frmPrintlocation.btnOK.Top) - frmPrintLocation.ORpnlBottom.Top;
326 frmPrintLocation.ORpnlBottom.Height := frmPrintLocation.btnOK.Top + frmPrintLocation.btnOK.Height + diff;
327 frmprintLocation.Height := frmprintLocation.orpnlBottom.Top + frmprintLocation.orpnlBottom.Height + 25;
328 end;
329end;
330
331
332procedure TfrmPrintLocation.PrintLocation(OrderLst: TStringList; pEncounterLoc:integer; pEncounterLocName,
333 pEncounterLocText: string; pEncounterDT: TFMDateTime; pEncounterVC: Char;
334 var ClinicLst, WardLst: TStringList; var wardIEN: integer; var wardLocation: string;
335 ContainsIMOOrders: boolean; displayEncSwitch: boolean = false);
336var
337OrderInfo, OrderText: string;
338cidx, i, widx: integer;
339begin
340 frmPrintLocation := TfrmPrintLocation.Create(Application);
341 try
342 frmPrintLocation.DisplayOrders := true;
343 frmPrintLocation.CloseOK := false;
344 ClinicArr := TStringList.Create;
345 WardArr := TStringList.Create;
346 frmPrintlocation.orderGrid.RowCount := OrderLst.Count + 1;
347 CurrentLocationForPatient(Patient.DFN, WardIEN, WardLocation, ASvc);
348 frmPrintLocation.lblEncounter.Enabled := displayEncSwitch;
349 frmPrintLocation.cboEncLoc.Enabled := displayEncSwitch;
350 frmPrintLocation.Cloc := pEncounterLocName;
351 frmPrintLocation.WLoc := WardLocation;
352 frmPrintLocation.CIEN := pEncounterLoc;
353 frmPrintLocation.WIEN := wardIEN;
354 ResizeAnchoredFormToFont(frmPrintLocation);
355 frmPrintLocation.orderGrid.DefaultRowHeight := frmPrintLocation.cbolocation.Height;
356 for i := 0 to OrderLst.Count - 1 do
357 begin
358 OrderInfo := Piece(OrderLst.Strings[i],':',1);
359 OrderText := AnsiReplaceText(Piece(OrderLst.Strings[i],':',2),CRLF,'');
360 frmPrintLocation.orderGrid.Cells[COL_ORDERINFO,i+1] := OrderInfo;
361 frmPrintLocation.orderGrid.Cells[COL_ORDERTEXT,i+1] := OrderText;
362 end;
363 frmPrintLocation.cbolocation.Items.Add(frmPrintLocation.CLoc);
364 frmPrintLocation.cbolocation.Items.Add(frmPrintLocation.WLoc);
365 if frmPrintLocation.cboEncLoc.Enabled = True then
366 begin
367 frmPrintLocation.cboEncLoc.Items.Add(frmPrintLocation.CLoc);
368 frmPrintLocation.cboEncLoc.Items.Add(frmPrintLocation.WLoc);
369 end;
370 frmPrintLocation.ShowModal;
371 if assigned(ClinicArr) then ClinicLst.AddStrings(ClinicArr);
372 if assigned(WardArr) then WardLst.AddStrings(WardArr);
373 ProcessClinicOrders(WardLst, ClinicLst, WardIEN, pEncounterLoc, ContainsIMOOrders);
374 cidx := frmPrintLocation.cboEncLoc.Items.IndexOf(frmPrintLocation.CLoc);
375 widx := frmPrintLocation.cboEncLoc.Items.IndexOf(frmPrintLocation.WLoc);
376 if frmPrintLocation.cboEncLoc.ItemIndex = cidx then
377 begin
378 uCore.Encounter.EncounterSwitch(pEncounterLoc, pEncounterLocName, pEncounterLocText, pEncounterDT, pEncounterVC);
379 fframe.frmFrame.DisplayEncounterText;
380 fframe.frmFrame.OrderPrintForm := True;
381 end
382 else if frmPrintLocation.cboEncLoc.ItemIndex = widx then
383 begin
384 uCore.Encounter.EncounterSwitch(WardIEN, WardLocation, WardLocation, Patient.AdmitTime, 'H');
385 fFrame.frmFrame.DisplayEncounterText;
386 end;
387 finally
388 frmPrintLocation.Destroy;
389 end;
390end;
391
392procedure TfrmPrintLocation.ProcessClinicOrders(WardList, ClinicList: TStringList;
393 WardIEN, ClinicIEN: integer; ContainsIMO: boolean);
394var
395i: integer;
396OrderArr: TStringList;
397begin
398 OrderArr := TStringList.Create;
399 for i := 0 to WardList.Count -1 do
400 begin
401 OrderArr.Add(WardList.Strings[i] + U + InttoStr(WardIen));
402 end;
403 for i := 0 to ClinicList.Count -1 do
404 begin
405 OrderArr.Add(ClinicList.Strings[i] + U + InttoStr(ClinicIen));
406 end;
407 rpcChangeOrderLocation(OrderArr, ContainsIMO);
408 WardArr.Free;
409end;
410
411
412procedure TfrmPrintLocation.rpcChangeOrderLocation(pOrderList:TStringList; ContainsIMO: boolean);
413var
414IMO: string;
415begin
416// OrderIEN^Location^ISIMO -- used to alter location if ward is selected.
417 if ContainsIMO = True then IMO := '1'
418 else IMO := '0';
419 CallV('ORWDX CHANGE',[pOrderList, Patient.DFN, IMO]);
420end;
421
422
423function TfrmPrintLocation.rpcIsPatientOnWard(Patient: string): string;
424begin
425 //Ward Loction Name^Ward Location IEN
426 result := sCallV('ORWDX1 PATWARD',[Patient]);
427end;
428
429procedure TfrmPrintLocation.ShowEditor(ACol, ARow: Integer; AChar: Char);
430var
431 tmpText: string;
432
433 procedure PlaceControl(AControl: TWinControl);
434 var
435 ARect: TRect;
436 begin
437 with AControl do
438 begin
439 ARect := OrderGrid.CellRect(ACol, ARow);
440 SetBounds(ARect.Left + OrderGrid.Left + 1, ARect.Top + OrderGrid.Top + 1,
441 ARect.Right - ARect.Left + 1, ARect.Bottom - ARect.Top + 1);
442 Tag := ARow;
443 BringToFront;
444 Show;
445 SetFocus;
446 end;
447 end;
448
449 procedure SynchCombo(ACombo: TORComboBox; const ItemText, EditText: string);
450 var
451 i: Integer;
452 begin
453 ACombo.ItemIndex := -1;
454 for i := 0 to Pred(ACombo.Items.Count) do
455 if ACombo.Items[i] = ItemText then ACombo.ItemIndex := i;
456 if ACombo.ItemIndex < 0 then ACombo.Text := EditText;
457 end;
458
459begin
460 inherited;
461 if ARow = 0 then Exit;
462 Case ACol of
463 COL_LOCATION: begin
464 TmpText := ValFor(COL_Location, ARow);
465 SynchCombo(cboLocation, tmpText, tmpText);
466 PlaceControl(cboLocation);
467 end;
468 end;
469
470end;
471
472procedure TfrmPrintLocation.SwitchEncounterLoction(pEncounterLoc: integer; pEncounterLocName, pEncounterLocText: string;
473 pEncounterDT: TFMDateTime; pEncounterVC: Char);
474var
475cidx, widx, WardIEN: integer;
476Asvc, WardLocation: string;
477begin
478 frmPrintLocation := TfrmPrintLocation.Create(Application);
479 try
480 frmPrintLocation.DisplayOrders := false;
481 frmPrintLocation.CloseOK := false;
482 CurrentLocationForPatient(Patient.DFN, WardIEN, WardLocation, ASvc);
483 frmPrintLocation.lblEncounter.Enabled := True;
484 frmPrintLocation.cboEncLoc.Enabled := True;
485 frmPrintLocation.Cloc := pEncounterLocName;
486 frmPrintLocation.WLoc := WardLocation;
487 frmPrintLocation.CIEN := pEncounterLoc;
488 frmPrintLocation.WIEN := wardIEN;
489 ResizeAnchoredFormToFont(frmPrintLocation);
490 frmPrintLocation.cboEncLoc.Items.Add(frmPrintLocation.CLoc);
491 frmPrintLocation.cboEncLoc.Items.Add(frmPrintLocation.WLoc);
492 frmPrintLocation.Caption := 'Refresh Encounter Location Form';
493 frmPrintLocation.ShowModal;
494 cidx := frmPrintLocation.cboEncLoc.Items.IndexOf(frmPrintLocation.CLoc);
495 widx := frmPrintLocation.cboEncLoc.Items.IndexOf(frmPrintLocation.WLoc);
496 if frmPrintLocation.cboEncLoc.Enabled = FALSE then frmPrintLocation.cboEncLoc.ItemIndex := widx;
497
498 if frmPrintLocation.cboEncLoc.ItemIndex = cidx then
499 begin
500 Encounter.Location := pEncounterLoc;
501 Encounter.LocationName := pEncounterLocName;
502 Encounter.LocationText := pEncounterLocText;
503 fframe.frmFrame.DisplayEncounterText;
504 end
505 else if frmPrintLocation.cboEncLoc.ItemIndex = widx then
506 begin
507 uCore.Encounter.EncounterSwitch(WardIEN, WardLocation, '', Patient.AdmitTime, 'H');
508 fFrame.frmFrame.DisplayEncounterText;
509 end;
510 finally
511 frmPrintLocation.Destroy;
512 end;
513end;
514
515function TfrmPrintLocation.ValFor(FieldID, ARow: Integer): string;
516
517begin
518 Result := '';
519 if (ARow < 1) or (ARow >= OrderGrid.RowCount) then Exit;
520 with OrderGrid do
521 case FieldID of
522 COL_ORDERINFO : Result := Piece(Cells[COL_ORDERINFO, ARow], TAB, 1);
523 COL_ORDERTEXT : Result := Piece(Cells[COL_ORDERTEXT, ARow], TAB, 1);
524 COL_LOCATION : Result := Piece(Cells[COL_LOCATION, ARow], TAB, 1);
525 end;
526end;
527
528end.
Note: See TracBrowser for help on using the repository browser.