source: cprs/trunk/CPRS-Chart/Encounter/fVisitType.pas@ 670

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

Initial Upload of Official WV CPRS 1.0.26.76

File size: 13.5 KB
Line 
1unit fVisitType;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 fPCEBase, StdCtrls, CheckLst, ORCtrls, ExtCtrls, Buttons, uPCE, rPCE, ORFn, rCore,
8 ComCtrls, mVisitRelated;
9
10type
11 TfrmVisitType = class(TfrmPCEBase)
12 lblVType: TLabel;
13 lblSCDisplay: TLabel;
14 lblVTypeSection: TLabel;
15 memSCDisplay: TCaptionMemo;
16 lbProviders: TORListBox;
17 lblCurrentProv: TLabel;
18 cboPtProvider: TORComboBox;
19 lblProvider: TLabel;
20 btnAdd: TButton;
21 btnDelete: TButton;
22 btnPrimary: TButton;
23 fraVisitRelated: TfraVisitRelated;
24 lstVTypeSection: TORListBox;
25 lbxVisits: TORListBox;
26 lbMods: TORListBox;
27 lblMod: TLabel;
28 pnlMain: TPanel;
29 pnlLeft: TPanel;
30 splLeft: TSplitter;
31 procedure lstVTypeSectionClick(Sender: TObject);
32 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
33 procedure FormCreate(Sender: TObject);
34 procedure btnAddClick(Sender: TObject);
35 procedure btnDeleteClick(Sender: TObject);
36 procedure btnPrimaryClick(Sender: TObject);
37 procedure cboPtProviderDblClick(Sender: TObject);
38 procedure cboPtProviderChange(Sender: TObject);
39 procedure cboPtProviderNeedData(Sender: TObject;
40 const StartFrom: String; Direction, InsertAt: Integer);
41 procedure lbProvidersChange(Sender: TObject);
42 procedure lbProvidersDblClick(Sender: TObject);
43 procedure FormResize(Sender: TObject);
44 procedure lbxVisitsClickCheck(Sender: TObject; Index: Integer);
45 procedure splLeftMoved(Sender: TObject);
46 procedure splRightMoved(Sender: TObject);
47 procedure lbModsClickCheck(Sender: TObject; Index: Integer);
48 procedure lbxVisitsClick(Sender: TObject);
49 protected
50 FSplitterMove: boolean;
51 procedure ShowModifiers;
52 procedure CheckModifiers;
53 private
54 FChecking: boolean;
55 FCheckingMods: boolean;
56 FLastCPTCodes: string;
57 FLastMods: string;
58 procedure RefreshProviders;
59 procedure UpdateProviderButtons;
60 public
61 procedure MatchVType;
62 end;
63
64var
65 frmVisitType: TfrmVisitType;
66 USCchecked:boolean = false;
67// PriProv: Int64;
68 PriProv: Int64;
69
70const
71 LBCheckWidthSpace = 18;
72
73implementation
74
75{$R *.DFM}
76
77uses
78 fEncounterFrame, uCore, uConst;
79
80const
81 FN_NEW_PERSON = 200;
82
83procedure TfrmVisitType.MatchVType;
84var
85 i: Integer;
86 Found: Boolean;
87begin
88 with uVisitType do
89 begin
90 if Code = '' then Exit;
91 Found := False;
92 with lstVTypeSection do for i := 0 to Items.Count - 1 do
93 if Piece(Items[i], U, 2) = Category then
94 begin
95 ItemIndex := i;
96 lstVTypeSectionClick(Self);
97 Found := True;
98 break;
99 end;
100 if Found then for i := 0 to lbxVisits.Items.Count - 1 do
101 if Pieces(lbxVisits.Items[i], U, 1, 2) = Code + U + Narrative then
102 begin
103 lbxVisits.ItemIndex := i;
104 FChecking := TRUE;
105 try
106 lbxVisits.Checked[i] := True;
107 lbxVisitsClickCheck(Self, i);
108 finally
109 FChecking := FALSE;
110 end;
111 end;
112 end;
113end;
114
115procedure TfrmVisitType.lstVTypeSectionClick(Sender: TObject);
116var
117 i: Integer;
118begin
119 inherited;
120 ListVisitTypeCodes(lbxVisits.Items, lstVTypeSection.ItemIEN);
121 with uVisitType do for i := 0 to lbxVisits.Items.Count - 1 do
122 begin
123 if ((uVisitType <> nil) and (Pieces(lbxVisits.Items[i], U, 1, 2) = Code + U + Narrative)) then
124 begin
125 FChecking := TRUE;
126 try
127 lbxVisits.Checked[i] := True;
128 lbxVisits.ItemIndex := i;
129 finally
130 FChecking := FALSE;
131 end;
132 end;
133 end;
134 lbxVisitsClick(Self);
135end;
136
137procedure TfrmVisitType.FormCloseQuery(Sender: TObject;
138 var CanClose: Boolean);
139begin
140 inherited;
141 //process before closing
142
143end;
144
145(*function ExposureAnswered: Boolean;
146begin
147 result := false;
148 //if SC answered set result = true
149end;*)
150
151
152procedure TfrmVisitType.RefreshProviders;
153var
154 i: integer;
155 ProvData: TPCEProviderRec;
156 ProvEntry: string;
157
158begin
159 lbProviders.Clear;
160 for i := 0 to uProviders.count-1 do
161 begin
162 ProvData := uProviders[i];
163 ProvEntry := IntToStr(ProvData.IEN) + U + ProvData.Name;
164 if(ProvData.Primary) then
165 ProvEntry := ProvEntry + ' (Primary)';
166 lbProviders.Items.Add(ProvEntry);
167 end;
168 UpdateProviderButtons;
169end;
170
171procedure TfrmVisitType.FormCreate(Sender: TObject);
172var
173 AIEN: Int64;
174
175begin
176 inherited;
177 FTabName := CT_VisitNm;
178 FSectionTabCount := 2;
179 FormResize(Self);
180 AIEN := uProviders.PendingIEN(TRUE);
181 if(AIEN = 0) then
182 begin
183 AIEN := uProviders.PendingIEN(FALSE);
184 if(AIEN = 0) then
185 begin
186 cboPtProvider.InitLongList(User.Name);
187 AIEN := User.DUZ;
188 end
189 else
190 cboPtProvider.InitLongList(uProviders.PendingName(FALSE));
191 cboPtProvider.SelectByIEN(AIEN);
192 end
193 else
194 begin
195 cboPtProvider.InitLongList(uProviders.PendingName(TRUE));
196 cboPtProvider.SelectByIEN(AIEN);
197 end;
198 RefreshProviders;
199 FLastMods := uEncPCEData.VisitType.Modifiers;
200end;
201
202(*procedure TfrmVisitType.SynchEncounterProvider;
203// add the Encounter.Provider if this note is for the current encounter
204var
205 ProviderFound, PrimaryFound: Boolean;
206 i: Integer;
207 AProvider: TPCEProvider;
208begin
209 if (FloatToStrF(uEncPCEData.DateTime, ffFixed, 15, 4) = // compensate rounding errors
210 FloatToStrF(Encounter.DateTime, ffFixed, 15, 4)) and
211 (uEncPCEData.Location = Encounter.Location) and
212 (Encounter.Provider > 0) then
213 begin
214 ProviderFound := False;
215 PrimaryFound := False;
216 for i := 0 to ProviderLst.Count - 1 do
217 begin
218 AProvider := TPCEProvider(ProviderLst.Items[i]);
219 if AProvider.IEN = Encounter.Provider then ProviderFound := True;
220 if AProvider.Primary = '1' then PrimaryFound := True;
221 end;
222 if not ProviderFound then
223 begin
224 AProvider := TPCEProvider.Create;
225 AProvider.IEN := Encounter.Provider;
226 AProvider.Name := ExternalName(Encounter.Provider, FN_NEW_PERSON);
227 if not PrimaryFound then
228 begin
229 AProvider.Primary := '1';
230 uProvider := Encounter.Provider;
231 end
232 else AProvider.Primary := '0';
233 AProvider.Delete := False;
234 ProviderLst.Add(AProvider);
235 end;
236 end;
237end;
238*)
239
240procedure TfrmVisitType.UpdateProviderButtons;
241var
242 ok: boolean;
243
244begin
245 ok := (lbProviders.ItemIndex >= 0);
246 btnDelete.Enabled := ok;
247 btnPrimary.Enabled := ok;
248 btnAdd.Enabled := (cboPtProvider.ItemIEN <> 0);
249end;
250
251procedure TfrmVisitType.btnAddClick(Sender: TObject);
252begin
253 inherited;
254 uProviders.AddProvider(IntToStr(cboPTProvider.ItemIEN), cboPTProvider.Text, FALSE);
255 RefreshProviders;
256 lbProviders.SelectByIEN(cboPTProvider.ItemIEN);
257end;
258
259procedure TfrmVisitType.btnDeleteClick(Sender: TObject);
260var
261 idx: integer;
262
263begin
264 inherited;
265 If lbProviders.ItemIndex = -1 then exit;
266 idx := uProviders.IndexOfProvider(lbProviders.ItemID);
267 if(idx >= 0) then
268 uProviders.Delete(idx);
269 RefreshProviders;
270end;
271
272procedure TfrmVisitType.btnPrimaryClick(Sender: TObject);
273var
274 idx: integer;
275 AIEN: Int64;
276
277begin
278 inherited;
279 if lbProviders.ItemIndex = -1 then exit;
280 AIEN := lbProviders.ItemIEN;
281 idx := uProviders.IndexOfProvider(IntToStr(AIEN));
282 if(idx >= 0) then
283 uProviders.PrimaryIdx := idx;
284 RefreshProviders;
285 lbProviders.SelectByIEN(AIEN);
286end;
287
288procedure TfrmVisitType.cboPtProviderDblClick(Sender: TObject);
289begin
290 inherited;
291 btnAddClick(Sender);
292end;
293
294procedure TfrmVisitType.cboPtProviderChange(Sender: TObject);
295begin
296 inherited;
297 UpdateProviderButtons;
298end;
299
300procedure TfrmVisitType.cboPtProviderNeedData(Sender: TObject;
301 const StartFrom: String; Direction, InsertAt: Integer);
302begin
303 inherited;
304 if(uEncPCEData.VisitCategory = 'E') then
305 cboPtProvider.ForDataUse(SubSetOfPersons(StartFrom, Direction))
306 else
307 cboPtProvider.ForDataUse(SubSetOfUsersWithClass(StartFrom, Direction,
308 FloatToStr(uEncPCEData.PersonClassDate)));
309end;
310
311procedure TfrmVisitType.lbProvidersChange(Sender: TObject);
312begin
313 inherited;
314 UpdateProviderButtons;
315end;
316
317procedure TfrmVisitType.lbProvidersDblClick(Sender: TObject);
318begin
319 inherited;
320 btnDeleteClick(Sender);
321end;
322
323procedure TfrmVisitType.FormResize(Sender: TObject);
324var
325 v, i: integer;
326 s: string;
327begin
328 if FSplitterMove then
329 FSplitterMove := FALSE
330 else
331 begin
332 inherited;
333 FSectionTabs[0] := -(lbxVisits.width - LBCheckWidthSpace - MainFontWidth - ScrollBarWidth);
334 FSectionTabs[1] := -(lbxVisits.width - (6*MainFontWidth) - ScrollBarWidth);
335 if(FSectionTabs[0] <= FSectionTabs[1]) then FSectionTabs[0] := FSectionTabs[1]+2;
336 lbxVisits.TabPositions := SectionString;
337 v := (lbMods.width - LBCheckWidthSpace - (4*MainFontWidth) - ScrollBarWidth);
338 s := '';
339 for i := 1 to 20 do
340 begin
341 if s <> '' then s := s + ',';
342 s := s + inttostr(v);
343 if(v<0) then
344 dec(v,32)
345 else
346 inc(v,32);
347 end;
348 lbMods.TabPositions := s;
349 end;
350end;
351
352procedure TfrmVisitType.lbxVisitsClickCheck(Sender: TObject;
353 Index: Integer);
354var
355 i: Integer;
356 x, CurCategory: string;
357begin
358 inherited;
359 if FChecking or FClosing then exit;
360 for i := 0 to lbxVisits.Items.Count - 1 do
361 if i <> lbxVisits.ItemIndex then
362 begin
363 FChecking := TRUE;
364 try
365 uVisitType.Modifiers := '';
366 lbxVisits.Checked[i] := False;
367 finally
368 FChecking := FALSE;
369 end;
370 end;
371 if lbxVisits.Checked[lbxVisits.ItemIndex] then with uVisitType do
372 begin
373 with lstVTypeSection do CurCategory := Piece(Items[ItemIndex], U, 2);
374 x := Pieces(lbxVisits.Items[lbxVisits.ItemIndex], U, 1, 2);
375 x := 'CPT' + U + Piece(x, U, 1) + U + CurCategory + U + Piece(x, U, 2) + U + '1' + U
376 + IntToStr(uProviders.PrimaryIEN);
377// + IntToStr(uProvider);
378 uVisitType.SetFromString(x);
379 end
380 else
381 begin
382 uVisitType.Clear;
383 //with lstVTypeSection do CurCategory := Piece(Items[ItemIndex], U, 2);
384 end;
385end;
386
387procedure TfrmVisitType.ShowModifiers;
388const
389 ModTxt = 'Modifiers';
390 ForTxt = ' for ';
391 Spaces = ' ';
392
393var
394 TopIdx: integer;
395// Needed,
396 Codes, VstName, Hint, Msg: string;
397
398begin
399 Codes := '';
400 VstName := '';
401 Hint := '';
402 if(Codes = '') and (lbxVisits.ItemIndex >= 0) then
403 begin
404 Codes := piece(lbxVisits.Items[lbxVisits.ItemIndex],U,1) + U;
405 VstName := piece(lbxVisits.Items[lbxVisits.ItemIndex],U,2);
406 Hint := VstName;
407// Needed := piece(lbxVisit.Items[lbxVisit.ItemIndex],U,4); Don't show expired codes!
408 end;
409 msg := ModTxt;
410 if(VstName <> '') then
411 msg := msg + ForTxt;
412 lblMod.Caption := msg + VstName;
413 lbMods.Caption := lblMod.Caption;
414 if(pos(CRLF,Hint)>0) then
415 Hint := ':' + CRLF + Spaces + Hint;
416 lblMod.Hint := msg + Hint;
417
418 if(FLastCPTCodes = Codes) then
419 TopIdx := lbMods.TopIndex
420 else
421 begin
422 TopIdx := 0;
423 FLastCPTCodes := Codes;
424 end;
425 ListCPTModifiers(lbMods.Items, Codes, ''); // Needed);
426 lbMods.TopIndex := TopIdx;
427 CheckModifiers;
428end;
429
430procedure TfrmVisitType.CheckModifiers;
431var
432 i, idx, cnt, mcnt: integer;
433 Code, Mods: string;
434 state: TCheckBoxState;
435
436begin
437 if lbMods.Items.Count < 1 then exit;
438 FCheckingMods := TRUE;
439 try
440 cnt := 0;
441 Mods := ';';
442 if uVisitType.Modifiers <> '' then
443 begin
444 inc(cnt);
445 Mods := Mods + uVisitType.Modifiers;
446 end;
447 if(cnt = 0) and (lbxVisits.ItemIndex >= 0) then
448 begin
449 Mods := ';' + UpdateVisitTypeModifierList(lbxVisits.Items, lbxVisits.ItemIndex);
450 lbxVisits.Checked[lbxVisits.ItemIndex] := True;
451 cnt := 1;
452 end;
453 for i := 0 to lbMods.Items.Count-1 do
454 begin
455 state := cbUnchecked;
456 if(cnt > 0) then
457 begin
458 Code := ';' + piece(lbMods.Items[i], U, 1) + ';';
459 mcnt := 0;
460 repeat
461 idx := pos(Code, Mods);
462 if(idx > 0) then
463 begin
464 inc(mcnt);
465 delete(Mods, idx, length(Code) - 1);
466 end;
467 until (idx = 0);
468 if mcnt >= cnt then
469 State := cbChecked
470 else
471 if(mcnt > 0) then
472 State := cbGrayed;
473 end;
474 lbMods.CheckedState[i] := state;
475 end;
476 finally
477 FCheckingMods := FALSE;
478 end;
479end;
480
481procedure TfrmVisitType.splLeftMoved(Sender: TObject);
482begin
483 inherited;
484 lblVType.Left := lbxVisits.Left + pnlMain.Left;
485 FSplitterMove := TRUE;
486 FormResize(Sender);
487end;
488
489procedure TfrmVisitType.splRightMoved(Sender: TObject);
490begin
491 inherited;
492 lblMod.Left := lbMods.Left + pnlMain.Left;
493 FSplitterMove := TRUE;
494 FormResize(Sender);
495end;
496
497procedure TfrmVisitType.lbModsClickCheck(Sender: TObject; Index: Integer);
498var
499 idx: integer;
500 ModIEN: string;
501 Add: boolean;
502begin
503 if FCheckingMods or (Index < 0) then exit;
504 Add := (lbMods.Checked[Index]);
505 ModIEN := piece(lbMods.Items[Index],U,1) + ';';
506 idx := pos(';' + ModIEN, ';' + uVisitType.Modifiers);
507 if(idx > 0) then
508 begin
509 if not Add then
510 begin
511 delete(uVisitType.Modifiers, idx, length(ModIEN));
512 end;
513 end
514 else
515 begin
516 if Add then
517 begin
518 uVisitType.Modifiers := uVisitType.Modifiers + ModIEN;
519 end;
520 end;
521end;
522
523procedure TfrmVisitType.lbxVisitsClick(Sender: TObject);
524begin
525 inherited;
526 ShowModifiers;
527end;
528
529initialization
530//frmVisitType.CreateProviderList;
531
532finalization
533//frmVisitType.FreeProviderList;
534
535end.
Note: See TracBrowser for help on using the repository browser.