[456] | 1 | unit fOrderVw;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
| 7 | fAutoSz, StdCtrls, ComCtrls, ExtCtrls, ORCtrls, ORFn, rOrders, ORDtTm;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 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 |
|
---|
| 58 | procedure SelectOrderView(var OrderView: TOrderView);
|
---|
| 59 |
|
---|
| 60 | implementation
|
---|
| 61 |
|
---|
| 62 | {$R *.DFM}
|
---|
| 63 |
|
---|
| 64 | const
|
---|
| 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 |
|
---|
| 68 | var
|
---|
| 69 | uDGroupList: TStringList;
|
---|
| 70 | uFilterList: TStringList;
|
---|
| 71 |
|
---|
| 72 | procedure SelectOrderView(var OrderView: TOrderView);
|
---|
| 73 | var
|
---|
| 74 | frmOrderView: TfrmOrderView;
|
---|
| 75 | begin
|
---|
| 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;
|
---|
| 110 | end;
|
---|
| 111 |
|
---|
| 112 | procedure TfrmOrderView.FormCreate(Sender: TObject);
|
---|
| 113 | begin
|
---|
| 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;
|
---|
| 130 | end;
|
---|
| 131 |
|
---|
| 132 | procedure TfrmOrderView.UpdateViewName;
|
---|
| 133 | const
|
---|
| 134 | FMT_TIME = 'mm/dd/yy';
|
---|
| 135 | var
|
---|
| 136 | DateText, FilterText: string;
|
---|
| 137 | begin
|
---|
| 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;
|
---|
| 146 | end;
|
---|
| 147 |
|
---|
| 148 | procedure TfrmOrderView.SynchViewData;
|
---|
| 149 | var
|
---|
| 150 | i: Integer;
|
---|
| 151 | begin
|
---|
| 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;
|
---|
| 178 | end;
|
---|
| 179 |
|
---|
| 180 | procedure TfrmOrderView.LoadDGroups(const Parent: string; Node: TTreeNode);
|
---|
| 181 | var
|
---|
| 182 | MyID, MyParent, Name: string;
|
---|
| 183 | i, IEN: Integer;
|
---|
| 184 | ChildNode: TTreeNode;
|
---|
| 185 | HasChildren: Boolean;
|
---|
| 186 | begin
|
---|
| 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;
|
---|
| 200 | end;
|
---|
| 201 |
|
---|
| 202 | procedure TfrmOrderView.LoadFilters(const Parent: string; Node: TTreeNode);
|
---|
| 203 | var
|
---|
| 204 | MyID, MyParent, Name: string;
|
---|
| 205 | i, IEN: Integer;
|
---|
| 206 | ChildNode: TTreeNode;
|
---|
| 207 | HasChildren: Boolean;
|
---|
| 208 | begin
|
---|
| 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;
|
---|
| 222 | end;
|
---|
| 223 |
|
---|
| 224 | procedure TfrmOrderView.treServiceClick(Sender: TObject);
|
---|
| 225 | var
|
---|
| 226 | Node: TTreeNode;
|
---|
| 227 | begin
|
---|
| 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;
|
---|
| 236 | end;
|
---|
| 237 |
|
---|
| 238 | procedure TfrmOrderView.chkDateRangeClick(Sender: TObject);
|
---|
| 239 | begin
|
---|
| 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;
|
---|
| 258 | end;
|
---|
| 259 |
|
---|
| 260 | procedure TfrmOrderView.calChange(Sender: TObject);
|
---|
| 261 | begin
|
---|
| 262 | inherited;
|
---|
| 263 | UpdateViewName;
|
---|
| 264 | end;
|
---|
| 265 |
|
---|
| 266 | procedure TfrmOrderView.cmdOKClick(Sender: TObject);
|
---|
| 267 | begin
|
---|
| 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;
|
---|
| 287 | end;
|
---|
| 288 |
|
---|
| 289 | procedure TfrmOrderView.cmdCancelClick(Sender: TObject);
|
---|
| 290 | begin
|
---|
| 291 | inherited;
|
---|
| 292 | Close;
|
---|
| 293 | end;
|
---|
| 294 |
|
---|
| 295 | procedure TfrmOrderView.trFiltersClick(Sender: TObject);
|
---|
| 296 | var
|
---|
| 297 | Node: TTreeNode;
|
---|
| 298 | begin
|
---|
| 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;
|
---|
| 316 | end;
|
---|
| 317 |
|
---|
| 318 | procedure TfrmOrderView.Splitter1Moved(Sender: TObject);
|
---|
| 319 | begin
|
---|
| 320 | inherited;
|
---|
| 321 | Splitter1.Align := alNone;
|
---|
| 322 | Splitter1.Align := alLeft;
|
---|
| 323 | end;
|
---|
| 324 |
|
---|
| 325 | end.
|
---|