source: cprs/branches/foia-cprs/CPRS-Chart/fNotes.pas@ 1154

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

Uploading from OR_30_258

File size: 137.7 KB
Line 
1unit fNotes;
2{$O-}
3
4interface
5
6uses
7 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
8 fHSplit, StdCtrls, ExtCtrls, Menus, ComCtrls, ORCtrls, ORFn, uConst, ORDtTm,
9 uPCE, ORClasses, fDrawers, ImgList, rTIU, uTIU, uDocTree, fRptBox, fPrintList,
10 fNoteST, ORNet, fNoteSTStop;
11
12type
13 TfrmNotes = class(TfrmHSplit)
14 mnuNotes: TMainMenu;
15 mnuView: TMenuItem;
16 mnuViewChart: TMenuItem;
17 mnuChartReports: TMenuItem;
18 mnuChartLabs: TMenuItem;
19 mnuChartDCSumm: TMenuItem;
20 mnuChartCslts: TMenuItem;
21 mnuChartNotes: TMenuItem;
22 mnuChartOrders: TMenuItem;
23 mnuChartMeds: TMenuItem;
24 mnuChartProbs: TMenuItem;
25 mnuChartCover: TMenuItem;
26 Z1: TMenuItem;
27 mnuViewDetail: TMenuItem;
28 mnuAct: TMenuItem;
29 mnuActNew: TMenuItem;
30 Z2: TMenuItem;
31 mnuActSave: TMenuItem;
32 mnuActDelete: TMenuItem;
33 mnuActEdit: TMenuItem;
34 mnuActSign: TMenuItem;
35 mnuActAddend: TMenuItem;
36 lblNotes: TOROffsetLabel;
37 pnlRead: TPanel;
38 lblTitle: TOROffsetLabel;
39 memNote: TRichEdit;
40 pnlWrite: TPanel;
41 memNewNote: TRichEdit;
42 Z3: TMenuItem;
43 mnuViewAll: TMenuItem;
44 mnuViewByAuthor: TMenuItem;
45 mnuViewByDate: TMenuItem;
46 mnuViewUncosigned: TMenuItem;
47 mnuViewUnsigned: TMenuItem;
48 mnuActSignList: TMenuItem;
49 cmdNewNote: TORAlignButton;
50 cmdPCE: TORAlignButton;
51 lblSpace1: TLabel;
52 popNoteMemo: TPopupMenu;
53 popNoteMemoCut: TMenuItem;
54 popNoteMemoCopy: TMenuItem;
55 popNoteMemoPaste: TMenuItem;
56 Z10: TMenuItem;
57 popNoteMemoSignList: TMenuItem;
58 popNoteMemoDelete: TMenuItem;
59 popNoteMemoEdit: TMenuItem;
60 popNoteMemoSave: TMenuItem;
61 popNoteMemoSign: TMenuItem;
62 popNoteList: TPopupMenu;
63 popNoteListAll: TMenuItem;
64 popNoteListByAuthor: TMenuItem;
65 popNoteListByDate: TMenuItem;
66 popNoteListUncosigned: TMenuItem;
67 popNoteListUnsigned: TMenuItem;
68 sptVert: TSplitter;
69 memPCEShow: TRichEdit;
70 mnuActIdentifyAddlSigners: TMenuItem;
71 popNoteMemoAddlSign: TMenuItem;
72 Z11: TMenuItem;
73 popNoteMemoSpell: TMenuItem;
74 popNoteMemoGrammar: TMenuItem;
75 mnuViewCustom: TMenuItem;
76 N1: TMenuItem;
77 mnuViewSaveAsDefault: TMenuItem;
78 ReturntoDefault1: TMenuItem;
79 pnlDrawers: TPanel;
80 lstNotes: TORListBox;
81 splDrawers: TSplitter;
82 popNoteMemoTemplate: TMenuItem;
83 Z12: TMenuItem;
84 mnuOptions: TMenuItem;
85 mnuEditTemplates: TMenuItem;
86 mnuNewTemplate: TMenuItem;
87 N2: TMenuItem;
88 mnuEditSharedTemplates: TMenuItem;
89 mnuNewSharedTemplate: TMenuItem;
90 popNoteMemoAddend: TMenuItem;
91 pnlFields: TPanel;
92 lblNewTitle: TStaticText;
93 lblRefDate: TStaticText;
94 lblAuthor: TStaticText;
95 lblVisit: TStaticText;
96 lblCosigner: TStaticText;
97 cmdChange: TButton;
98 lblSubject: TStaticText;
99 txtSubject: TCaptionEdit;
100 timAutoSave: TTimer;
101 popNoteMemoPaste2: TMenuItem;
102 popNoteMemoReformat: TMenuItem;
103 Z4: TMenuItem;
104 mnuActChange: TMenuItem;
105 mnuActLoadBoiler: TMenuItem;
106 bvlNewTitle: TBevel;
107 popNoteMemoSaveContinue: TMenuItem;
108 N3: TMenuItem;
109 mnuEditDialgFields: TMenuItem;
110 tvNotes: TORTreeView;
111 lvNotes: TCaptionListView;
112 sptList: TSplitter;
113 N4: TMenuItem;
114 popNoteListExpandSelected: TMenuItem;
115 popNoteListExpandAll: TMenuItem;
116 popNoteListCollapseSelected: TMenuItem;
117 popNoteListCollapseAll: TMenuItem;
118 popNoteListCustom: TMenuItem;
119 mnuActDetachFromIDParent: TMenuItem;
120 N5: TMenuItem;
121 popNoteListDetachFromIDParent: TMenuItem;
122 popNoteListAddIDEntry: TMenuItem;
123 mnuActAddIDEntry: TMenuItem;
124 mnuIconLegend: TMenuItem;
125 N6: TMenuItem;
126 popNoteMemoFind: TMenuItem;
127 dlgFindText: TFindDialog;
128 dlgReplaceText: TReplaceDialog;
129 popNoteMemoReplace: TMenuItem;
130 N7: TMenuItem;
131 mnuChartSurgery: TMenuItem;
132 mnuActAttachtoIDParent: TMenuItem;
133 popNoteListAttachtoIDParent: TMenuItem;
134 N8: TMenuItem;
135 popNoteMemoPreview: TMenuItem;
136 popNoteMemoInsTemplate: TMenuItem;
137 popNoteMemoEncounter: TMenuItem;
138 mnuSearchForText: TMenuItem;
139 popSearchForText: TMenuItem;
140 mnuViewInformation: TMenuItem;
141 mnuViewDemo: TMenuItem;
142 mnuViewVisits: TMenuItem;
143 mnuViewPrimaryCare: TMenuItem;
144 mnuViewMyHealtheVet: TMenuItem;
145 mnuInsurance: TMenuItem;
146 mnuViewFlags: TMenuItem;
147 mnuViewReminders: TMenuItem;
148 mnuViewRemoteData: TMenuItem;
149 mnuViewPostings: TMenuItem;
150 procedure mnuChartTabClick(Sender: TObject);
151 procedure lstNotesClick(Sender: TObject);
152 procedure pnlRightResize(Sender: TObject);
153 procedure cmdNewNoteClick(Sender: TObject);
154 procedure mnuActNewClick(Sender: TObject);
155 procedure mnuActAddIDEntryClick(Sender: TObject);
156 procedure mnuActSaveClick(Sender: TObject);
157 procedure mnuViewClick(Sender: TObject);
158 procedure mnuActAddendClick(Sender: TObject);
159 procedure mnuActDetachFromIDParentClick(Sender: TObject);
160 procedure mnuActSignListClick(Sender: TObject);
161 procedure mnuActDeleteClick(Sender: TObject);
162 procedure mnuActEditClick(Sender: TObject);
163 procedure mnuActSignClick(Sender: TObject);
164 procedure cmdPCEClick(Sender: TObject);
165 procedure popNoteMemoCutClick(Sender: TObject);
166 procedure popNoteMemoCopyClick(Sender: TObject);
167 procedure popNoteMemoPasteClick(Sender: TObject);
168 procedure popNoteMemoPopup(Sender: TObject);
169 procedure pnlWriteResize(Sender: TObject);
170 procedure FormCreate(Sender: TObject);
171 procedure mnuViewDetailClick(Sender: TObject);
172 procedure FormClose(Sender: TObject; var Action: TCloseAction);
173 procedure mnuActIdentifyAddlSignersClick(Sender: TObject);
174 procedure popNoteMemoAddlSignClick(Sender: TObject);
175 procedure popNoteMemoSpellClick(Sender: TObject);
176 procedure popNoteMemoGrammarClick(Sender: TObject);
177 procedure mnuViewSaveAsDefaultClick(Sender: TObject);
178 procedure mnuViewReturntoDefaultClick(Sender: TObject);
179 procedure popNoteMemoTemplateClick(Sender: TObject);
180 procedure mnuEditTemplatesClick(Sender: TObject);
181 procedure mnuNewTemplateClick(Sender: TObject);
182 procedure mnuEditSharedTemplatesClick(Sender: TObject);
183 procedure mnuNewSharedTemplateClick(Sender: TObject);
184 procedure mnuOptionsClick(Sender: TObject);
185 procedure FormDestroy(Sender: TObject);
186 procedure cmdChangeClick(Sender: TObject);
187 procedure pnlFieldsResize(Sender: TObject);
188 procedure timAutoSaveTimer(Sender: TObject);
189 procedure memNewNoteChange(Sender: TObject);
190 procedure popNoteMemoReformatClick(Sender: TObject);
191 procedure mnuActChangeClick(Sender: TObject);
192 procedure mnuActLoadBoilerClick(Sender: TObject);
193 procedure popNoteMemoSaveContinueClick(Sender: TObject);
194 procedure mnuEditDialgFieldsClick(Sender: TObject);
195 procedure tvNotesChange(Sender: TObject; Node: TTreeNode);
196 procedure tvNotesClick(Sender: TObject);
197 procedure tvNotesCollapsed(Sender: TObject; Node: TTreeNode);
198 procedure tvNotesExpanded(Sender: TObject; Node: TTreeNode);
199 procedure tvNotesStartDrag(Sender: TObject;
200 var DragObject: TDragObject);
201 procedure tvNotesDragDrop(Sender, Source: TObject; X, Y: Integer);
202 procedure tvNotesDragOver(Sender, Source: TObject; X, Y: Integer;
203 State: TDragState; var Accept: Boolean);
204 procedure lvNotesColumnClick(Sender: TObject; Column: TListColumn);
205 procedure lvNotesCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
206 procedure lvNotesSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
207 procedure popNoteListExpandAllClick(Sender: TObject);
208 procedure popNoteListCollapseAllClick(Sender: TObject);
209 procedure popNoteListExpandSelectedClick(Sender: TObject);
210 procedure popNoteListCollapseSelectedClick(Sender: TObject);
211 procedure popNoteListPopup(Sender: TObject);
212 procedure lvNotesResize(Sender: TObject);
213 procedure mnuIconLegendClick(Sender: TObject);
214 procedure popNoteMemoFindClick(Sender: TObject);
215 procedure dlgFindTextFind(Sender: TObject);
216 procedure popNoteMemoReplaceClick(Sender: TObject);
217 procedure dlgReplaceTextReplace(Sender: TObject);
218 procedure dlgReplaceTextFind(Sender: TObject);
219 procedure mnuActAttachtoIDParentClick(Sender: TObject);
220 procedure memNewNoteKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
221 procedure sptHorzCanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean);
222 procedure popNoteMemoInsTemplateClick(Sender: TObject);
223 procedure popNoteMemoPreviewClick(Sender: TObject);
224 procedure tvNotesAddition(Sender: TObject; Node: TTreeNode);
225 procedure tvNotesDeletion(Sender: TObject; Node: TTreeNode);
226 procedure tvNotesExit(Sender: TObject);
227 procedure pnlReadExit(Sender: TObject);
228 procedure cmdNewNoteExit(Sender: TObject);
229 procedure FormHide(Sender: TObject);
230 procedure FormShow(Sender: TObject);
231 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
232 Y: Integer);
233 procedure memNewNoteKeyPress(Sender: TObject; var Key: Char);
234 procedure memNewNoteKeyUp(Sender: TObject; var Key: Word;
235 Shift: TShiftState);
236 procedure memPCEShowExit(Sender: TObject);
237 procedure cmdChangeExit(Sender: TObject);
238 procedure cmdPCEExit(Sender: TObject);
239 procedure ViewInfo(Sender: TObject);
240 procedure mnuViewInformationClick(Sender: TObject);
241 private
242 FNavigatingTab : Boolean; //Currently Using tab to navigate
243 FEditingIndex: Integer; // index of note being currently edited
244 FChanged: Boolean; // true if any text has changed in the note
245 FEditCtrl: TCustomEdit;
246 FSilent: Boolean;
247 FCurrentContext: TTIUContext;
248 FDefaultContext: TTIUContext;
249 FOrderID: string;
250 FImageFlag: TBitmap;
251 FEditNote: TEditNoteRec;
252 FVerifyNoteTitle: Integer;
253 FDocList: TStringList;
254 FConfirmed: boolean;
255 FLastNoteID: string;
256 FNewIDChild: boolean;
257 FEditingNotePCEObj: boolean;
258 FDeleted: boolean;
259 FOldFramePnlPatientExit: TNotifyEvent;
260 FOldDrawerPnlTemplatesButtonExit: TNotifyEvent;
261 FOldDrawerPnlEncounterButtonExit: TNotifyEvent;
262 FOldDrawerEdtSearchExit: TNotifyEvent;
263 FMousing: TDateTime;
264 FStarting: boolean;
265 procedure frmFramePnlPatientExit(Sender: TObject);
266 procedure frmDrawerPnlTemplatesButtonExit(Sender: TObject);
267 procedure frmDrawerPnlEncounterButtonExit(Sender: TObject);
268 procedure frmDrawerEdtSearchExit(Sender: TObject);
269 procedure ClearEditControls;
270 procedure DoAutoSave(Suppress: integer = 1);
271 function GetTitleText(AnIndex: Integer): string;
272 procedure InsertAddendum;
273 procedure InsertNewNote(IsIDChild: boolean; AnIDParent: integer);
274 function LacksRequiredForCreate: Boolean;
275 procedure LoadForEdit;
276 function LockConsultRequest(AConsult: Integer): Boolean;
277 function LockConsultRequestAndNote(AnIEN: Int64): Boolean;
278 procedure RemovePCEFromChanges(IEN: Int64; AVisitStr: string = '');
279 procedure SaveEditedNote(var Saved: Boolean);
280 procedure SaveCurrentNote(var Saved: Boolean);
281 procedure SetEditingIndex(const Value: Integer);
282 procedure SetSubjectVisible(ShouldShow: Boolean);
283 procedure ShowPCEControls(ShouldShow: Boolean);
284 function StartNewEdit(NewNoteType: integer): Boolean;
285 procedure UnlockConsultRequest(ANote: Int64; AConsult: Integer = 0);
286 procedure ProcessNotifications;
287 procedure SetViewContext(AContext: TTIUContext);
288 property EditingIndex: Integer read FEditingIndex write SetEditingIndex;
289 function GetDrawers: TFrmDrawers;
290 function CanFinishReminder: boolean;
291 procedure DisplayPCE;
292 function VerifyNoteTitle: Boolean;
293 // added for treeview
294 procedure LoadNotes;
295 procedure UpdateTreeView(DocList: TStringList; Tree: TORTreeView);
296 procedure EnableDisableIDNotes;
297 procedure ShowPCEButtons(Editing: boolean);
298 procedure DoAttachIDChild(AChild, AParent: TORTreeNode);
299 function SetNoteTreeLabel(AContext: TTIUContext): string;
300 procedure UpdateNoteAuthor(DocInfo: string);
301 public
302 function ActiveEditOf(AnIEN: Int64; ARequest: integer): Boolean;
303 function AllowContextChange(var WhyNot: string): Boolean; override;
304 procedure ClearPtData; override;
305 procedure DisplayPage; override;
306 procedure RequestPrint; override;
307 procedure RequestMultiplePrint(AForm: TfrmPrintList);
308 procedure SetFontSize(NewFontSize: Integer); override;
309 procedure SaveSignItem(const ItemID, ESCode: string);
310 procedure AssignRemForm;
311 property OrderID: string read FOrderID;
312 procedure LstNotesToPrint;
313 published
314 property Drawers: TFrmDrawers read GetDrawers; // Keep Drawers published
315 end;
316
317var
318 frmNotes: TfrmNotes;
319 SearchTextStopFlag: Boolean; // Text Search CQ: HDS00002856
320
321implementation
322
323{$R *.DFM}
324
325uses fFrame, fVisit, fEncnt, rCore, uCore, fNoteBA, fNoteBD, fSignItem, fEncounterFrame,
326 rPCE, Clipbrd, fNoteCslt, fNotePrt, rVitals, fAddlSigners, fNoteDR, fConsults, uSpell,
327 fTIUView, fTemplateEditor, uReminders, fReminderDialog, uOrders, rConsults, fReminderTree,
328 fNoteProps, fNotesBP, fTemplateFieldEditor, dShared, rTemplates,
329 FIconLegend, fPCEEdit, fNoteIDParents, rSurgery, uSurgery, uTemplates,
330 uAccessibleTreeView, uAccessibleTreeNode, fTemplateDialog, DateUtils;
331
332const
333
334 NT_NEW_NOTE = -10; // Holder IEN for a new note
335 NT_ADDENDUM = -20; // Holder IEN for a new addendum
336
337 NT_ACT_NEW_NOTE = 2;
338 NT_ACT_ADDENDUM = 3;
339 NT_ACT_EDIT_NOTE = 4;
340 NT_ACT_ID_ENTRY = 5;
341
342 TX_NEED_VISIT = 'A visit is required before creating a new progress note.';
343 TX_CREATE_ERR = 'Error Creating Note';
344 TX_UPDATE_ERR = 'Error Updating Note';
345 TX_NO_NOTE = 'No progress note is currently being edited';
346 TX_SAVE_NOTE = 'Save Progress Note';
347 TX_ADDEND_NO = 'Cannot make an addendum to a note that is being edited';
348 TX_DEL_OK = CRLF + CRLF + 'Delete this progress note?';
349 TX_DEL_ERR = 'Unable to Delete Note';
350 TX_SIGN = 'Sign Note';
351 TX_COSIGN = 'Cosign Note';
352 TX_SIGN_ERR = 'Unable to Sign Note';
353// TX_SCREQD = 'This progress note title requires the service connected questions to be '+
354// 'answered. The Encounter form will now be opened. Please answer all '+
355// 'service connected questions.';
356// TX_SCREQD_T = 'Response required for SC questions.';
357 TX_NONOTE = 'No progress note is currently selected.';
358 TX_NONOTE_CAP = 'No Note Selected';
359 TX_NOPRT_NEW = 'This progress note may not be printed until it is saved';
360 TX_NOPRT_NEW_CAP = 'Save Progress Note';
361 TX_NO_ALERT = 'There is insufficient information to process this alert.' + CRLF +
362 'Either the alert has already been deleted, or it contained invalid data.' + CRLF + CRLF +
363 'Click the NEXT button if you wish to continue processing more alerts.';
364 TX_CAP_NO_ALERT = 'Unable to Process Alert';
365 TX_ORDER_LOCKED = 'This record is locked by an action underway on the Consults tab';
366 TC_ORDER_LOCKED = 'Unable to access record';
367 TX_NO_ORD_CHG = 'The note is still associated with the previously selected request.' + CRLF +
368 'Finish the pending action on the consults tab, then try again.';
369 TC_NO_ORD_CHG = 'Locked Consult Request';
370 TX_NEW_SAVE1 = 'You are currently editing:' + CRLF + CRLF;
371 TX_NEW_SAVE2 = CRLF + CRLF + 'Do you wish to save this note and begin a new one?';
372 TX_NEW_SAVE3 = CRLF + CRLF + 'Do you wish to save this note and begin a new addendum?';
373 TX_NEW_SAVE4 = CRLF + CRLF + 'Do you wish to save this note and edit the one selected?';
374 TX_NEW_SAVE5 = CRLF + CRLF + 'Do you wish to save this note and begin a new Interdisciplinary entry?';
375 TC_NEW_SAVE2 = 'Create New Note';
376 TC_NEW_SAVE3 = 'Create New Addendum';
377 TC_NEW_SAVE4 = 'Edit Different Note';
378 TC_NEW_SAVE5 = 'Create New Interdisciplinary Entry';
379 TX_EMPTY_NOTE = CRLF + CRLF + 'This note contains no text and will not be saved.' + CRLF +
380 'Do you wish to delete this note?';
381 TC_EMPTY_NOTE = 'Empty Note';
382 TX_EMPTY_NOTE1 = 'This note contains no text and can not be signed.';
383 TC_NO_LOCK = 'Unable to Lock Note';
384 TX_ABSAVE = 'It appears the session terminated abnormally when this' + CRLF +
385 'note was last edited. Some text may not have been saved.' + CRLF + CRLF +
386 'Do you wish to continue and sign the note?';
387 TC_ABSAVE = 'Possible Missing Text';
388 TX_NO_BOIL = 'There is no boilerplate text associated with this title.';
389 TC_NO_BOIL = 'Load Boilerplate Text';
390 TX_BLR_CLEAR = 'Do you want to clear the previously loaded boilerplate text?';
391 TC_BLR_CLEAR = 'Clear Previous Boilerplate Text';
392 TX_DETACH_CNF = 'Confirm Detachment';
393 TX_DETACH_FAILURE = 'Detach failed';
394 TX_RETRACT_CAP = 'Retraction Notice';
395 TX_RETRACT = 'This document will now be RETRACTED. As Such, it has been removed' +CRLF +
396 ' from public view, and from typical Releases of Information,' +CRLF +
397 ' but will remain indefinitely discoverable to HIMS.' +CRLF +CRLF;
398 TX_AUTH_SIGNED = 'Author has not signed, are you SURE you want to sign.' +CRLF;
399{
400type
401 //CQ8300
402 ClipboardData = record
403 Text: array[0..255] of char;
404 end;
405}
406var
407 uPCEShow, uPCEEdit: TPCEData;
408 ViewContext: Integer;
409 frmDrawers: TfrmDrawers;
410 uTIUContext: TTIUContext;
411 ColumnToSort: Integer;
412 ColumnSortForward: Boolean;
413 uChanging: Boolean;
414 uIDNotesActive: Boolean;
415
416
417{ TPage common methods --------------------------------------------------------------------- }
418function TfrmNotes.AllowContextChange(var WhyNot: string): Boolean;
419begin
420 dlgFindText.CloseDialog;
421 Result := inherited AllowContextChange(WhyNot); // sets result = true
422 if Assigned(frmTemplateDialog) then
423 if Screen.ActiveForm = frmTemplateDialog then
424 //if (fsModal in frmTemplateDialog.FormState) then
425 case BOOLCHAR[frmFrame.CCOWContextChanging] of
426 '1': begin
427 WhyNot := 'A template in progress will be aborted. ';
428 Result := False;
429 end;
430 '0': begin
431 if WhyNot = 'COMMIT' then
432 begin
433 FSilent := True;
434 frmTemplateDialog.Silent := True;
435 frmTemplateDialog.ModalResult := mrCancel;
436 end;
437 end;
438 end;
439 if Assigned(frmRemDlg) then
440 case BOOLCHAR[frmFrame.CCOWContextChanging] of
441 '1': begin
442 WhyNot := 'All current reminder processing information will be discarded. ';
443 Result := False;
444 end;
445 '0': begin
446 if WhyNot = 'COMMIT' then
447 begin
448 FSilent := True;
449 frmRemDlg.Silent := True;
450 frmRemDlg.btnCancelClick(Self);
451 end;
452 end;
453 end;
454 if EditingIndex <> -1 then
455 case BOOLCHAR[frmFrame.CCOWContextChanging] of
456 '1': begin
457 if memNewNote.GetTextLen > 0 then
458 WhyNot := WhyNot + 'A note in progress will be saved as unsigned. '
459 else
460 WhyNot := WhyNot + 'An empty note in progress will be deleted. ';
461 Result := False;
462 end;
463 '0': begin
464 if WhyNot = 'COMMIT' then FSilent := True;
465 SaveCurrentNote(Result)
466 end;
467 end;
468 if Assigned(frmEncounterFrame) then
469 if Screen.ActiveForm = frmEncounterFrame then
470 //if (fsModal in frmEncounterFrame.FormState) then
471 case BOOLCHAR[frmFrame.CCOWContextChanging] of
472 '1': begin
473 WhyNot := WhyNot + 'Encounter information being edited will not be saved';
474 Result := False;
475 end;
476 '0': begin
477 if WhyNot = 'COMMIT' then
478 begin
479 FSilent := True;
480 frmEncounterFrame.Abort := False;
481 frmEncounterFrame.Cancel := True;
482 end;
483 end;
484 end;
485end;
486
487procedure TfrmNotes.LstNotesToPrint;
488var
489 AParentID: string;
490 SavedDocID: string;
491 Saved: boolean;
492begin
493 inherited;
494 if not uIDNotesActive then exit;
495 if lstNotes.ItemIEN = 0 then exit;
496 SavedDocID := lstNotes.ItemID;
497 if EditingIndex <> -1 then
498 begin
499 SaveCurrentNote(Saved);
500 if not Saved then Exit;
501 LoadNotes;
502 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
503 end;
504 if tvNotes.Selected = nil then exit;
505 AParentID := frmPrintList.SelectParentFromList(tvNotes,CT_NOTES);
506 if AParentID = '' then exit;
507 with tvNotes do Selected := FindPieceNode(AParentID, 1, U, Items.GetFirstNode);
508end;
509
510procedure TfrmNotes.ClearPtData;
511{ clear all controls that contain patient specific information }
512begin
513 inherited ClearPtData;
514 ClearEditControls;
515 uChanging := True;
516 tvNotes.Items.BeginUpdate;
517 KilldocTreeObjects(tvNotes);
518 tvNotes.Items.Clear;
519 tvNotes.Items.EndUpdate;
520 lvNotes.Items.Clear;
521 uChanging := False;
522 lstNotes.Clear;
523 memNote.Clear;
524 memPCEShow.Clear;
525 uPCEShow.Clear;
526 uPCEEdit.Clear;
527 frmDrawers.ResetTemplates;
528end;
529
530procedure TfrmNotes.DisplayPage;
531{ causes page to be visible and conditionally executes initialization code }
532begin
533 inherited DisplayPage;
534 frmFrame.ShowHideChartTabMenus(mnuViewChart);
535 frmFrame.mnuFilePrint.Tag := CT_NOTES;
536 frmFrame.mnuFilePrint.Enabled := True;
537 frmFrame.mnuFilePrintSetup.Enabled := True;
538 frmFrame.mnuFilePrintSelectedItems.Enabled := True;
539 if InitPage then
540 begin
541 EnableDisableIDNotes;
542 FDefaultContext := GetCurrentTIUContext;
543 FCurrentContext := FDefaultContext;
544 popNoteMemoSpell.Visible := SpellCheckAvailable;
545 popNoteMemoGrammar.Visible := popNoteMemoSpell.Visible;
546 Z11.Visible := popNoteMemoSpell.Visible;
547 timAutoSave.Interval := User.AutoSave * 1000; // convert seconds to milliseconds
548 SetEqualTabStops(memNewNote);
549 end;
550 // to indent the right margin need to set Paragraph.RightIndent for each paragraph?
551 if InitPatient and not (CallingContext = CC_NOTIFICATION) then
552 begin
553 SetViewContext(FDefaultContext);
554 end;
555 case CallingContext of
556 CC_INIT_PATIENT: if not InitPatient then
557 begin
558 SetViewContext(FDefaultContext);
559 end;
560 CC_NOTIFICATION: ProcessNotifications;
561 end;
562end;
563
564procedure TfrmNotes.RequestPrint;
565var
566 Saved: Boolean;
567begin
568 with lstNotes do
569 begin
570 if ItemIndex = EditingIndex then
571 //if ItemIEN < 0 then
572 begin
573 SaveCurrentNote(Saved);
574 if not Saved then Exit;
575 end;
576 if ItemIEN > 0 then PrintNote(ItemIEN, MakeNoteDisplayText(Items[ItemIndex])) else
577 begin
578 if ItemIEN = 0 then InfoBox(TX_NONOTE, TX_NONOTE_CAP, MB_OK);
579 if ItemIEN < 0 then InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
580 end;
581 end;
582end;
583
584{for printing multiple notes}
585procedure TfrmNotes.RequestMultiplePrint(AForm: TfrmPrintList);
586var
587 NoteIEN: int64;
588 i: integer;
589begin
590 with AForm.lbIDParents do
591 begin
592 for i := 0 to Items.Count - 1 do
593 begin
594 if Selected[i] then
595 begin
596 NoteIEN := StrToInt64def(Piece(TStringList(Items.Objects[i])[0],U,1),0);
597 if NoteIEN > 0 then PrintNote(NoteIEN, Items[i], TRUE) else
598 begin
599 if NoteIEN = 0 then InfoBox(TX_NONOTE, TX_NONOTE_CAP, MB_OK);
600 if NoteIEN < 0 then InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
601 end;
602 end; {if selected}
603 end; {for}
604 end; {with}
605end;
606
607procedure TfrmNotes.SetFontSize(NewFontSize: Integer);
608{ adjusts the font size of any controls that don't have ParentFont = True }
609begin
610 inherited SetFontSize(NewFontSize);
611 frmDrawers.Font.Size := NewFontSize;
612 SetEqualTabStops(memNewNote);
613end;
614
615procedure TfrmNotes.mnuChartTabClick(Sender: TObject);
616{ reroute to Chart Tab menu of the parent form: frmFrame }
617begin
618 inherited;
619 frmFrame.mnuChartTabClick(Sender);
620end;
621
622{ General procedures ----------------------------------------------------------------------- }
623
624procedure TfrmNotes.ClearEditControls;
625{ resets controls used for entering a new progress note }
626begin
627 // clear FEditNote (should FEditNote be an object with a clear method?)
628 with FEditNote do
629 begin
630 DocType := 0;
631 Title := 0;
632 TitleName := '';
633 DateTime := 0;
634 Author := 0;
635 AuthorName := '';
636 Cosigner := 0;
637 CosignerName := '';
638 Subject := '';
639 Location := 0;
640 LocationName := '';
641 PkgIEN := 0;
642 PkgPtr := '';
643 PkgRef := '';
644 NeedCPT := False;
645 Addend := 0;
646 {LastCosigner & LastCosignerName aren't cleared because they're used as default for next note.}
647 Lines := nil;
648 PRF_IEN := 0;
649 ActionIEN := '';
650 end;
651 // clear the editing controls (also clear the new labels?)
652 txtSubject.Text := '';
653 if memNewNote <> nil then memNewNote.Clear; //CQ7012 Added test for nil
654 timAutoSave.Enabled := False;
655 // clear the PCE object for editing
656 uPCEEdit.Clear;
657 // set the tracking variables to initial state
658 EditingIndex := -1;
659 FChanged := False;
660end;
661
662procedure TfrmNotes.ShowPCEControls(ShouldShow: Boolean);
663begin
664 sptVert.Visible := ShouldShow;
665 memPCEShow.Visible := ShouldShow;
666 if(ShouldShow) then
667 sptVert.Top := memPCEShow.Top - sptVert.Height;
668 memNote.Invalidate;
669end;
670
671procedure TfrmNotes.DisplayPCE;
672{ displays PCE information if appropriate & enables/disabled editing of PCE data }
673var
674 EnableList, ShowList: TDrawers;
675 VitalStr: TStringlist;
676 NoPCE: boolean;
677 ActionSts: TActionRec;
678 AnIEN: integer;
679begin
680 memPCEShow.Clear;
681 with lstNotes do if ItemIndex = EditingIndex then
682 begin
683 with uPCEEdit do
684 begin
685 AddStrData(memPCEShow.Lines);
686 NoPCE := (memPCEShow.Lines.Count = 0);
687 VitalStr := TStringList.create;
688 try
689 GetVitalsFromDate(VitalStr, uPCEEdit);
690 AddVitalData(VitalStr, memPCEShow.Lines);
691 finally
692 VitalStr.free;
693 end;
694 ShowPCEButtons(TRUE);
695 ShowPCEControls(cmdPCE.Enabled or (memPCEShow.Lines.Count > 0));
696 if(NoPCE and memPCEShow.Visible) then
697 memPCEShow.Lines.Insert(0, TX_NOPCE);
698 memPCEShow.SelStart := 0;
699
700 if(InteractiveRemindersActive) then
701 begin
702 if(GetReminderStatus = rsNone) then
703 EnableList := [odTemplates]
704 else
705 EnableList := [odTemplates, odReminders];
706 ShowList := [odTemplates, odReminders];
707 end
708 else
709 begin
710 EnableList := [odTemplates];
711 ShowList := [odTemplates];
712 end;
713 frmDrawers.DisplayDrawers(TRUE, EnableList, ShowList);
714 end;
715 end else
716 begin
717 ShowPCEButtons(FALSE);
718 frmDrawers.DisplayDrawers(TRUE, [odTemplates], [odTemplates]);
719 AnIEN := lstNotes.ItemIEN;
720 ActOnDocument(ActionSts, AnIEN, 'VIEW');
721 if ActionSts.Success then
722 begin
723 StatusText('Retrieving encounter information...');
724 with uPCEShow do
725 begin
726 NoteDateTime := MakeFMDateTime(Piece(lstNotes.Items[lstNotes.ItemIndex], U, 3));
727 PCEForNote(AnIEN, uPCEEdit);
728 AddStrData(memPCEShow.Lines);
729 NoPCE := (memPCEShow.Lines.Count = 0);
730 VitalStr := TStringList.create;
731 try
732 GetVitalsFromNote(VitalStr, uPCEShow, AnIEN);
733 AddVitalData(VitalStr, memPCEShow.Lines);
734 finally
735 VitalStr.free;
736 end;
737 ShowPCEControls(memPCEShow.Lines.Count > 0);
738 if(NoPCE and memPCEShow.Visible) then
739 memPCEShow.Lines.Insert(0, TX_NOPCE);
740 memPCEShow.SelStart := 0;
741 end;
742 StatusText('');
743 end
744 else
745 ShowPCEControls(FALSE);
746 end; {if ItemIndex}
747end;
748
749{ supporting calls for writing notes }
750
751function TfrmNotes.GetTitleText(AnIndex: Integer): string;
752{ returns non-tabbed text for the title of a note given the ItemIndex in lstNotes }
753begin
754 with lstNotes do
755 Result := FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(Items[AnIndex], U, 3))) +
756 ' ' + Piece(Items[AnIndex], U, 2) + ', ' + Piece(Items[AnIndex], U, 6) + ', ' +
757 Piece(Piece(Items[AnIndex], U, 5), ';', 2)
758end;
759
760function TfrmNotes.LacksRequiredForCreate: Boolean;
761{ determines if the fields required to create the note are present }
762var
763 CurTitle: Integer;
764begin
765 Result := False;
766 with FEditNote do
767 begin
768 if Title <= 0 then Result := True;
769 if Author <= 0 then Result := True;
770 if DateTime <= 0 then Result := True;
771 if IsConsultTitle(Title) and (PkgIEN = 0) then Result := True;
772 if IsSurgeryTitle(Title) and (PkgIEN = 0) then Result := True;
773 if IsPRFTitle(Title) and (PRF_IEN = 0) and (not DocType = TYP_ADDENDUM) then Result := True;
774 if (DocType = TYP_ADDENDUM) then
775 begin
776 if AskCosignerForDocument(Addend, Author) and (Cosigner <= 0) then Result := True;
777 end else
778 begin
779 if Title > 0 then CurTitle := Title else CurTitle := DocType;
780 if AskCosignerForTitle(CurTitle, Author, DateTime) and (Cosigner <= 0) then Result := True;
781 end;
782 end;
783end;
784
785function TfrmNotes.VerifyNoteTitle: Boolean;
786const
787 VNT_UNKNOWN = 0;
788 VNT_NO = 1;
789 VNT_YES = 2;
790var
791 AParam: string;
792begin
793 if FVerifyNoteTitle = VNT_UNKNOWN then
794 begin
795 AParam := GetUserParam('ORWOR VERIFY NOTE TITLE');
796 if AParam = '1' then FVerifyNoteTitle := VNT_YES else FVerifyNoteTitle := VNT_NO;
797 end;
798 Result := FVerifyNoteTitle = VNT_YES;
799end;
800
801procedure TfrmNotes.SetSubjectVisible(ShouldShow: Boolean);
802{ hide/show subject & resize panel accordingly - leave 6 pixel margin above memNewNote }
803begin
804 if ShouldShow then
805 begin
806 lblSubject.Visible := True;
807 txtSubject.Visible := True;
808 pnlFields.Height := txtSubject.Top + txtSubject.Height + 6;
809 end else
810 begin
811 lblSubject.Visible := False;
812 txtSubject.Visible := False;
813 pnlFields.Height := lblVisit.Top + lblVisit.Height + 6;
814 end;
815end;
816
817{ consult request and note locking }
818
819function TfrmNotes.LockConsultRequest(AConsult: Integer): Boolean;
820{ returns true if consult successfully locked }
821begin
822 // *** I'm not sure about the FOrderID field - if the user is editing one note and
823 // deletes another, FOrderID will be for editing note, then delete note, then null
824 Result := True;
825 FOrderID := GetConsultOrderIEN(AConsult);
826 if (FOrderID <> '') and (FOrderID = frmConsults.OrderID) then
827 begin
828 InfoBox(TX_ORDER_LOCKED, TC_ORDER_LOCKED, MB_OK);
829 Result := False;
830 Exit;
831 end;
832 if (FOrderId <> '') then
833 if not OrderCanBeLocked(FOrderID) then Result := False;
834 if not Result then FOrderID := '';
835end;
836
837function TfrmNotes.LockConsultRequestAndNote(AnIEN: Int64): Boolean;
838{ returns true if note and associated request successfully locked }
839var
840 AConsult: Integer;
841 LockMsg, x: string;
842begin
843 Result := True;
844 AConsult := 0;
845 if frmConsults.ActiveEditOf(AnIEN) then
846 begin
847 InfoBox(TX_ORDER_LOCKED, TC_ORDER_LOCKED, MB_OK);
848 Result := False;
849 Exit;
850 end;
851 if Changes.Exist(CH_DOC, IntToStr(AnIEN)) then Exit; // already locked
852 // try to lock the consult request first, if there is one
853 if IsConsultTitle(TitleForNote(AnIEN)) then
854 begin
855 x := GetPackageRefForNote(lstNotes.ItemIEN);
856 AConsult := StrToIntDef(Piece(x, ';', 1), 0);
857 Result := LockConsultRequest(AConsult);
858 end;
859 // now try to lock the note
860 if Result then
861 begin
862 LockDocument(AnIEN, LockMsg);
863 if LockMsg <> '' then
864 begin
865 Result := False;
866 // if can't lock the note, unlock the consult request that was just locked
867 if AConsult > 0 then
868 begin
869 UnlockOrderIfAble(FOrderID);
870 FOrderID := '';
871 end;
872 InfoBox(LockMsg, TC_NO_LOCK, MB_OK);
873 end;
874 end;
875end;
876
877procedure TfrmNotes.UnlockConsultRequest(ANote: Int64; AConsult: Integer = 0);
878(*var
879 x: string;*)
880begin
881(* if (AConsult = 0) and IsConsultTitle(TitleForNote(ANote)) then
882 begin
883 x := GetPackageRefForNote(ANote);
884 AConsult := StrToIntDef(Piece(x, ';', 1), 0);
885 end;
886 if AConsult = 0 then Exit;*)
887 if AConsult = 0 then AConsult := GetConsultIENForNote(ANote);
888 if AConsult <= 0 then exit;
889 FOrderID := GetConsultOrderIEN(AConsult);
890 UnlockOrderIfAble(FOrderID);
891 FOrderID := '';
892end;
893
894function TfrmNotes.ActiveEditOf(AnIEN: Int64; ARequest: integer): Boolean;
895begin
896 Result := False;
897 if EditingIndex < 0 then Exit;
898 if lstNotes.GetIEN(EditingIndex) = AnIEN then
899 begin
900 Result := True;
901 Exit;
902 end;
903 with FEditNote do if (PkgIEN = ARequest) and (PkgPtr = PKG_CONSULTS) then Result := True;
904end;
905
906{ create, edit & save notes }
907
908procedure TfrmNotes.InsertNewNote(IsIDChild: boolean; AnIDParent: integer);
909{ creates the editing context for a new progress note & inserts stub into top of view list }
910var
911 EnableAutosave, HaveRequired: Boolean;
912 CreatedNote: TCreatedDoc;
913 TmpBoilerPlate: TStringList;
914 tmpNode: TTreeNode;
915 x, WhyNot, DocInfo: string;
916begin
917 if frmFrame.Timedout then Exit;
918
919 FNewIDChild := IsIDChild;
920 EnableAutosave := FALSE;
921 TmpBoilerPlate := nil;
922 try
923 ClearEditControls;
924 FillChar(FEditNote, SizeOf(FEditNote), 0); //v15.7
925 with FEditNote do
926 begin
927 DocType := TYP_PROGRESS_NOTE;
928 IsNewNote := True;
929 Title := DfltNoteTitle;
930 TitleName := DfltNoteTitleName;
931 if IsIDChild and (not CanTitleBeIDChild(Title, WhyNot)) then
932 begin
933 Title := 0;
934 TitleName := '';
935 end;
936 if IsSurgeryTitle(Title) then // Don't want surgery title sneaking in unchallenged
937 begin
938 Title := 0;
939 TitleName := '';
940 end;
941 DateTime := FMNow;
942 Author := User.DUZ;
943 AuthorName := User.Name;
944 Location := Encounter.Location;
945 LocationName := Encounter.LocationName;
946 VisitDate := Encounter.DateTime;
947 if IsIDChild then
948 IDParent := AnIDParent
949 else
950 IDParent := 0;
951 // Cosigner & PkgRef, if needed, will be set by fNoteProps
952 end;
953 // check to see if interaction necessary to get required fields
954 GetUnresolvedConsultsInfo;
955 if LacksRequiredForCreate or VerifyNoteTitle or uUnresolvedConsults.UnresolvedConsultsExist
956 then HaveRequired := ExecuteNoteProperties(FEditNote, CT_NOTES, IsIDChild, FNewIDChild, '', 0)
957 else HaveRequired := True;
958 // lock the consult request if there is a consult
959 with FEditNote do if (PkgIEN > 0) and (PkgPtr = PKG_CONSULTS) then HaveRequired := LockConsultRequest(PkgIEN);
960 if HaveRequired then
961 begin
962 // set up uPCEEdit for entry of new note
963 uPCEEdit.UseEncounter := True;
964 uPCEEdit.NoteDateTime := FEditNote.DateTime;
965 uPCEEdit.PCEForNote(USE_CURRENT_VISITSTR, uPCEShow);
966 FEditNote.NeedCPT := uPCEEdit.CPTRequired;
967 // create the note
968 PutNewNote(CreatedNote, FEditNote);
969 uPCEEdit.NoteIEN := CreatedNote.IEN;
970 if CreatedNote.IEN > 0 then LockDocument(CreatedNote.IEN, CreatedNote.ErrorText);
971 if CreatedNote.ErrorText = '' then
972 begin
973 //x := $$RESOLVE^TIUSRVLO formatted string
974 //7348^Note Title^3000913^NERD, YOURA (N0165)^1329;Rich Vertigan;VERTIGAN,RICH^8E REHAB MED^complete^Adm: 11/05/98;2981105.095547^ ;^^0^^^2
975 with FEditNote do
976 begin
977 x := IntToStr(CreatedNote.IEN) + U + TitleName + U + FloatToStr(FEditNote.DateTime) + U +
978 Patient.Name + U + IntToStr(Author) + ';' + AuthorName + U + LocationName + U + 'new' + U +
979 U + U + U + U + U + U + U;
980 //Link Note to PRF Action
981 if PRF_IEN <> 0 then
982 if sCallV('TIU LINK TO FLAG', [CreatedNote.IEN,PRF_IEN,ActionIEN,Patient.DFN]) = '0' then
983 ShowMessage('TIU LINK TO FLAG: FAILED');
984 end;
985
986 lstNotes.Items.Insert(0, x);
987 uChanging := True;
988 tvNotes.Items.BeginUpdate;
989 if IsIDChild then
990 begin
991 tmpNode := tvNotes.FindPieceNode(IntToStr(AnIDParent), 1, U, tvNotes.Items.GetFirstNode);
992 tmpNode.ImageIndex := IMG_IDNOTE_OPEN;
993 tmpNode.SelectedIndex := IMG_IDNOTE_OPEN;
994 tmpNode := tvNotes.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeNoteTreeObject(x));
995 tmpNode.ImageIndex := IMG_ID_CHILD;
996 tmpNode.SelectedIndex := IMG_ID_CHILD;
997 end
998 else
999 begin
1000 tmpNode := tvNotes.Items.AddObjectFirst(tvNotes.Items.GetFirstNode, 'New Note in Progress',
1001 MakeNoteTreeObject('NEW^New Note in Progress^^^^^^^^^^^%^0'));
1002 TORTreeNode(tmpNode).StringData := 'NEW^New Note in Progress^^^^^^^^^^^%^0';
1003 tmpNode.ImageIndex := IMG_TOP_LEVEL;
1004 tmpNode := tvNotes.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeNoteTreeObject(x));
1005 tmpNode.ImageIndex := IMG_SINGLE;
1006 tmpNode.SelectedIndex := IMG_SINGLE;
1007 end;
1008 tmpNode.StateIndex := IMG_NO_IMAGES;
1009 TORTreeNode(tmpNode).StringData := x;
1010 tvNotes.Selected := tmpNode;
1011 tvNotes.Items.EndUpdate;
1012 uChanging := False;
1013 Changes.Add(CH_DOC, IntToStr(CreatedNote.IEN), GetTitleText(0), '', CH_SIGN_YES);
1014 lstNotes.ItemIndex := 0;
1015 EditingIndex := 0;
1016 SetSubjectVisible(AskSubjectForNotes);
1017 if not assigned(TmpBoilerPlate) then
1018 TmpBoilerPlate := TStringList.Create;
1019 LoadBoilerPlate(TmpBoilerPlate, FEditNote.Title);
1020 FChanged := False;
1021 cmdChangeClick(Self); // will set captions, sign state for Changes
1022 lstNotesClick(Self); // will make pnlWrite visible
1023 if timAutoSave.Interval <> 0 then EnableAutosave := TRUE;
1024 if txtSubject.Visible then txtSubject.SetFocus else memNewNote.SetFocus;
1025 end else
1026 begin
1027 // if note creation failed or failed to get note lock (both unlikely), unlock consult
1028 with FEditNote do if (PkgIEN > 0) and (PkgPtr = PKG_CONSULTS) then UnlockConsultRequest(0, PkgIEN);
1029 InfoBox(CreatedNote.ErrorText, TX_CREATE_ERR, MB_OK);
1030 HaveRequired := False;
1031 end; {if CreatedNote.IEN}
1032 end; {if HaveRequired}
1033 if not HaveRequired then
1034 begin
1035 ClearEditControls;
1036 ShowPCEButtons(False);
1037 end;
1038 finally
1039 if assigned(TmpBoilerPlate) then
1040 begin
1041 DocInfo := MakeXMLParamTIU(IntToStr(CreatedNote.IEN), FEditNote);
1042 ExecuteTemplateOrBoilerPlate(TmpBoilerPlate, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
1043 memNewNote.Lines.Assign(TmpBoilerPlate);
1044 UpdateNoteAuthor(DocInfo);
1045 TmpBoilerPlate.Free;
1046 end;
1047 if EnableAutosave then // Don't enable autosave until after dialog fields have been resolved
1048 timAutoSave.Enabled := True;
1049 end;
1050 frmNotes.pnlWriteResize(Self);
1051end;
1052
1053procedure TfrmNotes.InsertAddendum;
1054{ sets up fields of pnlWrite to write an addendum for the selected note }
1055const
1056 AS_ADDENDUM = True;
1057 IS_ID_CHILD = False;
1058var
1059 HaveRequired: Boolean;
1060 CreatedNote: TCreatedDoc;
1061 tmpNode: TTreeNode;
1062 x: string;
1063begin
1064 ClearEditControls;
1065 with FEditNote do
1066 begin
1067 DocType := TYP_ADDENDUM;
1068 IsNewNote := False;
1069 Title := TitleForNote(lstNotes.ItemIEN);
1070 TitleName := Piece(lstNotes.Items[lstNotes.ItemIndex], U, 2);
1071 if Copy(TitleName,1,1) = '+' then TitleName := Copy(TitleName, 3, 199);
1072 DateTime := FMNow;
1073 Author := User.DUZ;
1074 AuthorName := User.Name;
1075 x := GetPackageRefForNote(lstNotes.ItemIEN);
1076 if Piece(x, U, 1) <> '-1' then
1077 begin
1078 PkgRef := GetPackageRefForNote(lstNotes.ItemIEN);
1079 PkgIEN := StrToIntDef(Piece(PkgRef, ';', 1), 0);
1080 PkgPtr := Piece(PkgRef, ';', 2);
1081 end;
1082 Addend := lstNotes.ItemIEN;
1083 //Lines := memNewNote.Lines;
1084 // Cosigner, if needed, will be set by fNoteProps
1085 // Location info will be set after the encounter is loaded
1086 end;
1087 // check to see if interaction necessary to get required fields
1088 if LacksRequiredForCreate
1089 then HaveRequired := ExecuteNoteProperties(FEditNote, CT_NOTES, IS_ID_CHILD, False, '', 0)
1090 else HaveRequired := True;
1091 // lock the consult request if there is a consult
1092 if HaveRequired then
1093 with FEditNote do
1094 if (PkgIEN > 0) and (PkgPtr = PKG_CONSULTS) then HaveRequired := LockConsultRequest(PkgIEN);
1095 if HaveRequired then
1096 begin
1097 uPCEEdit.NoteDateTime := FEditNote.DateTime;
1098 uPCEEdit.PCEForNote(FEditNote.Addend, uPCEShow);
1099 FEditNote.Location := uPCEEdit.Location;
1100 FEditNote.LocationName := ExternalName(uPCEEdit.Location, 44);
1101 FEditNote.VisitDate := uPCEEdit.DateTime;
1102 PutAddendum(CreatedNote, FEditNote, FEditNote.Addend);
1103 uPCEEdit.NoteIEN := CreatedNote.IEN;
1104 if CreatedNote.IEN > 0 then LockDocument(CreatedNote.IEN, CreatedNote.ErrorText);
1105 if CreatedNote.ErrorText = '' then
1106 begin
1107 with FEditNote do
1108 begin
1109 x := IntToStr(CreatedNote.IEN) + U + 'Addendum to ' + TitleName + U + FloatToStr(DateTime) + U +
1110 Patient.Name + U + IntToStr(Author) + ';' + AuthorName + U + LocationName + U + 'new' + U +
1111 U + U + U + U + U + U + U;
1112 end;
1113
1114 lstNotes.Items.Insert(0, x);
1115 uChanging := True;
1116 tvNotes.Items.BeginUpdate;
1117 tmpNode := tvNotes.Items.AddObjectFirst(tvNotes.Items.GetFirstNode, 'New Addendum in Progress',
1118 MakeNoteTreeObject('ADDENDUM^New Addendum in Progress^^^^^^^^^^^%^0'));
1119 TORTreeNode(tmpNode).StringData := 'ADDENDUM^New Addendum in Progress^^^^^^^^^^^%^0';
1120 tmpNode.ImageIndex := IMG_TOP_LEVEL;
1121 tmpNode := tvNotes.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeNoteTreeObject(x));
1122 TORTreeNode(tmpNode).StringData := x;
1123
1124 tmpNode.ImageIndex := IMG_ADDENDUM;
1125 tmpNode.SelectedIndex := IMG_ADDENDUM;
1126 tvNotes.Selected := tmpNode;
1127 tvNotes.Items.EndUpdate;
1128 uChanging := False;
1129 Changes.Add(CH_DOC, IntToStr(CreatedNote.IEN), GetTitleText(0), '', CH_SIGN_YES);
1130 lstNotes.ItemIndex := 0;
1131 EditingIndex := 0;
1132 SetSubjectVisible(AskSubjectForNotes);
1133 cmdChangeClick(Self); // will set captions, sign state for Changes
1134 lstNotesClick(Self); // will make pnlWrite visible
1135 if timAutoSave.Interval <> 0 then timAutoSave.Enabled := True;
1136 memNewNote.SetFocus;
1137 end else
1138 begin
1139 // if note creation failed or failed to get note lock (both unlikely), unlock consult
1140 with FEditNote do if (PkgIEN > 0) and (PkgPtr = PKG_CONSULTS) then UnlockConsultRequest(0, PkgIEN);
1141 InfoBox(CreatedNote.ErrorText, TX_CREATE_ERR, MB_OK);
1142 HaveRequired := False;
1143 end; {if CreatedNote.IEN}
1144 end; {if HaveRequired}
1145 if not HaveRequired then ClearEditControls;
1146end;
1147
1148procedure TfrmNotes.LoadForEdit;
1149{ retrieves an existing note and places the data in the fields of pnlWrite }
1150var
1151 tmpNode: TTreeNode;
1152 x: string;
1153begin
1154 ClearEditControls;
1155 if not LockConsultRequestAndNote(lstNotes.ItemIEN) then Exit;
1156 EditingIndex := lstNotes.ItemIndex;
1157 Changes.Add(CH_DOC, lstNotes.ItemID, GetTitleText(EditingIndex), '', CH_SIGN_YES);
1158 GetNoteForEdit(FEditNote, lstNotes.ItemIEN);
1159 memNewNote.Lines.Assign(FEditNote.Lines);
1160 FChanged := False;
1161 if FEditNote.Title = TYP_ADDENDUM then
1162 begin
1163 FEditNote.DocType := TYP_ADDENDUM;
1164 FEditNote.TitleName := Piece(lstNotes.Items[lstNotes.ItemIndex], U, 2);
1165 if Copy(FEditNote.TitleName,1,1) = '+' then FEditNote.TitleName := Copy(FEditNote.TitleName, 3, 199);
1166 if CompareText(Copy(FEditNote.TitleName, 1, 8), 'Addendum') <> 0
1167 then FEditNote.TitleName := FEditNote.TitleName + 'Addendum to ';
1168 end;
1169
1170 uChanging := True;
1171 tvNotes.Items.BeginUpdate;
1172
1173 tmpNode := tvNotes.FindPieceNode('EDIT', 1, U, nil);
1174 if tmpNode = nil then
1175 begin
1176 tmpNode := tvNotes.Items.AddObjectFirst(tvNotes.Items.GetFirstNode, 'Note being edited',
1177 MakeNoteTreeObject('EDIT^Note being edited^^^^^^^^^^^%^0'));
1178 TORTreeNode(tmpNode).StringData := 'EDIT^Note being edited^^^^^^^^^^^%^0';
1179 end
1180 else
1181 tmpNode.DeleteChildren;
1182 x := lstNotes.Items[lstNotes.ItemIndex];
1183 tmpNode.ImageIndex := IMG_TOP_LEVEL;
1184 tmpNode := tvNotes.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeNoteTreeObject(x));
1185 TORTreeNode(tmpNode).StringData := x;
1186 if CompareText(Copy(FEditNote.TitleName, 1, 8), 'Addendum') <> 0 then
1187 tmpNode.ImageIndex := IMG_SINGLE
1188 else
1189 tmpNode.ImageIndex := IMG_ADDENDUM;
1190 tmpNode.SelectedIndex := tmpNode.ImageIndex;
1191 tvNotes.Selected := tmpNode;
1192 tvNotes.Items.EndUpdate;
1193 uChanging := False;
1194
1195 uPCEEdit.NoteDateTime := MakeFMDateTime(Piece(lstNotes.Items[lstNotes.ItemIndex], U, 3));
1196 uPCEEdit.PCEForNote(lstNotes.ItemIEN, uPCEShow);
1197 FEditNote.NeedCPT := uPCEEdit.CPTRequired;
1198 txtSubject.Text := FEditNote.Subject;
1199 SetSubjectVisible(AskSubjectForNotes);
1200 cmdChangeClick(Self); // will set captions, sign state for Changes
1201 lstNotesClick(Self); // will make pnlWrite visible
1202 if timAutoSave.Interval <> 0 then timAutoSave.Enabled := True;
1203 memNewNote.SetFocus;
1204end;
1205
1206procedure TfrmNotes.SaveEditedNote(var Saved: Boolean);
1207{ validates fields and sends the updated note to the server }
1208var
1209 UpdatedNote: TCreatedDoc;
1210 x: string;
1211begin
1212 Saved := False;
1213 if (memNewNote.GetTextLen = 0) or (not ContainsVisibleChar(memNewNote.Text)) then
1214 begin
1215 lstNotes.ItemIndex := EditingIndex;
1216 x := lstNotes.ItemID;
1217 uChanging := True;
1218 tvNotes.Selected := tvNotes.FindPieceNode(x, 1, U, tvNotes.Items.GetFirstNode);
1219 uChanging := False;
1220 tvNotesChange(Self, tvNotes.Selected);
1221 if FSilent or
1222 ((not FSilent) and
1223 (InfoBox(GetTitleText(EditingIndex) + TX_EMPTY_NOTE, TC_EMPTY_NOTE, MB_YESNO) = IDYES))
1224 then
1225 begin
1226 FConfirmed := True;
1227 mnuActDeleteClick(Self);
1228 Saved := True;
1229 FDeleted := True;
1230 end
1231 else
1232 FConfirmed := False;
1233 Exit;
1234 end;
1235 //ExpandTabsFilter(memNewNote.Lines, TAB_STOP_CHARS);
1236 FEditNote.Lines := memNewNote.Lines;
1237 //FEditNote.Lines:= SetLinesTo74ForSave(memNewNote.Lines, Self);
1238 FEditNote.Subject := txtSubject.Text;
1239 FEditNote.NeedCPT := uPCEEdit.CPTRequired;
1240 timAutoSave.Enabled := False;
1241 try
1242 PutEditedNote(UpdatedNote, FEditNote, lstNotes.GetIEN(EditingIndex));
1243 finally
1244 timAutoSave.Enabled := True;
1245 end;
1246 // there's no unlocking here since the note is still in Changes after a save
1247 if UpdatedNote.IEN > 0 then
1248 begin
1249 if lstNotes.ItemIndex = EditingIndex then
1250 begin
1251 EditingIndex := -1;
1252 lstNotesClick(Self);
1253 end;
1254 EditingIndex := -1; // make sure EditingIndex reset even if not viewing edited note
1255 Saved := True;
1256 FNewIDChild := False;
1257 FChanged := False;
1258 end else
1259 begin
1260 if not FSilent then
1261 InfoBox(TX_SAVE_ERROR1 + UpdatedNote.ErrorText + TX_SAVE_ERROR2, TC_SAVE_ERROR, MB_OK or MB_ICONWARNING);
1262 end;
1263end;
1264
1265procedure TfrmNotes.SaveCurrentNote(var Saved: Boolean);
1266{ called whenever a note should be saved - uses IEN to call appropriate save logic }
1267begin
1268 if EditingIndex < 0 then Exit;
1269 SaveEditedNote(Saved);
1270end;
1271
1272{ Form events ------------------------------------------------------------------------------ }
1273
1274procedure TfrmNotes.FormCreate(Sender: TObject);
1275begin
1276 inherited;
1277 PageID := CT_NOTES;
1278 memNote.Color := ReadOnlyColor;
1279 memPCEShow.Color := ReadOnlyColor;
1280 lblNewTitle.Color := ReadOnlyColor;
1281 EditingIndex := -1;
1282 FEditNote.LastCosigner := 0;
1283 FEditNote.LastCosignerName := '';
1284 FLastNoteID := '';
1285 frmDrawers := TfrmDrawers.CreateDrawers(Self, pnlDrawers, [],[]);
1286 frmDrawers.Align := alBottom;
1287 frmDrawers.RichEditControl := memNewNote;
1288 frmDrawers.NewNoteButton := cmdNewNote;
1289 frmDrawers.Splitter := splDrawers;
1290 frmDrawers.DefTempPiece := 1;
1291 tvNotes.Images := dmodShared.imgNotes;
1292 tvNotes.StateImages := dmodShared.imgImages;
1293 lvNotes.StateImages := dmodShared.imgImages;
1294 lvNotes.SmallImages := dmodShared.imgNotes;
1295 FImageFlag := TBitmap.Create;
1296 FDocList := TStringList.Create;
1297 TAccessibleTreeView.WrapControl(tvNotes);
1298end;
1299
1300procedure TfrmNotes.pnlRightResize(Sender: TObject);
1301{ memNote (TRichEdit) doesn't repaint appropriately unless it's parent panel is refreshed }
1302begin
1303 inherited;
1304 pnlRight.Refresh;
1305 memNote.Repaint;
1306end;
1307
1308procedure TfrmNotes.pnlWriteResize(Sender: TObject);
1309const
1310 LEFT_MARGIN = 4;
1311begin
1312 inherited;
1313 LimitEditWidth(memNewNote, MAX_PROGRESSNOTE_WIDTH - 1);
1314
1315 //CQ7012 Added test for nil
1316 if memNewNote <> nil then
1317 memNewNote.Constraints.MinWidth := TextWidthByFont(memNewNote.Font.Handle, StringOfChar('X', MAX_PROGRESSNOTE_WIDTH)) + (LEFT_MARGIN * 2) + ScrollBarWidth;
1318 //CQ7012 Added test for nil
1319 if (Self <> nil) and (pnlLeft <> nil) and (pnlWrite <> nil) and (sptHorz <> nil) then
1320 pnlLeft.Width := self.ClientWidth - pnlWrite.Width - sptHorz.Width;
1321end;
1322
1323{ Left panel (selector) events ------------------------------------------------------------- }
1324
1325procedure TfrmNotes.lstNotesClick(Sender: TObject);
1326{ loads the text for the selected note or displays the editing panel for the selected note }
1327begin
1328 inherited;
1329 with lstNotes do if ItemIndex = -1 then Exit
1330 else if ItemIndex = EditingIndex then
1331 begin
1332 pnlWrite.Visible := True;
1333 pnlRead.Visible := False;
1334 mnuViewDetail.Enabled := False;
1335 if (FEditNote.IDParent <> 0) and (not FNewIDChild) then
1336 mnuActChange.Enabled := False
1337 else
1338 mnuActChange.Enabled := True;
1339 mnuActLoadBoiler.Enabled := True;
1340 UpdateReminderFinish;
1341 end else
1342 begin
1343 StatusText('Retrieving selected progress note...');
1344 Screen.Cursor := crHourGlass;
1345 pnlRead.Visible := True;
1346 pnlWrite.Visible := False;
1347 UpdateReminderFinish;
1348 lblTitle.Caption := Piece(Piece(Items[ItemIndex], U, 8), ';', 1) + #9 + Piece(Items[ItemIndex], U, 2) + ', ' +
1349 Piece(Items[ItemIndex], U, 6) + ', ' + Piece(Piece(Items[ItemIndex], U, 5), ';', 2) +
1350 ' (' + FormatFMDateTime('mmm dd,yy@hh:nn', MakeFMDateTime(Piece(Items[ItemIndex], U, 3)))
1351 + ')';
1352 lvNotes.Caption := lblTitle.Caption;
1353 LoadDocumentText(memNote.Lines, ItemIEN);
1354 memNote.SelStart := 0;
1355 mnuViewDetail.Enabled := True;
1356 mnuViewDetail.Checked := False;
1357 mnuActChange.Enabled := False;
1358 mnuActLoadBoiler.Enabled := False;
1359 Screen.Cursor := crDefault;
1360 StatusText('');
1361 end;
1362 if(assigned(frmReminderTree)) then
1363 frmReminderTree.EnableActions;
1364 DisplayPCE;
1365 pnlRight.Refresh;
1366 memNewNote.Repaint;
1367 memNote.Repaint;
1368 NotifyOtherApps(NAE_REPORT, 'TIU^' + lstNotes.ItemID);
1369end;
1370
1371procedure TfrmNotes.cmdNewNoteClick(Sender: TObject);
1372{ maps 'New Note' button to the New Progress Note menu item }
1373begin
1374 inherited;
1375 mnuActNewClick(Self);
1376end;
1377
1378procedure TfrmNotes.cmdPCEClick(Sender: TObject);
1379var
1380 Refresh: boolean;
1381 ActionSts: TActionRec;
1382 AnIEN: integer;
1383 PCEObj, tmpPCEEdit: TPCEData;
1384
1385 procedure UpdateEncounterInfo;
1386 begin
1387 if not FEditingNotePCEObj then
1388 begin
1389 PCEObj := nil;
1390 AnIEN := lstNotes.ItemIEN;
1391 if (AnIEN <> 0) and (memNote.Lines.Count > 0) then
1392 begin
1393 ActOnDocument(ActionSts, AnIEN, 'VIEW');
1394 if ActionSts.Success then
1395 begin
1396 uPCEShow.CopyPCEData(uPCEEdit);
1397 PCEObj := uPCEEdit;
1398 end;
1399 end;
1400 Refresh := EditPCEData(PCEObj);
1401 end
1402 else
1403 begin
1404 UpdatePCE(uPCEEdit);
1405 Refresh := TRUE;
1406 end;
1407 if Refresh and (not frmFrame.Closing) then
1408 DisplayPCE;
1409 end;
1410
1411begin
1412 inherited;
1413 cmdPCE.Enabled := FALSE;
1414 if lstNotes.ItemIndex <> EditingIndex then
1415 // save uPCEEdit for note being edited, before updating current note's encounter, then restore (RV - TAM-0801-31056)
1416 begin
1417 tmpPCEEdit := TPCEData.Create;
1418 try
1419 uPCEEdit.CopyPCEData(tmpPCEEdit);
1420 UpdateEncounterInfo;
1421 tmpPCEEdit.CopyPCEData(uPCEEdit);
1422 finally
1423 tmpPCEEdit.Free;
1424 end;
1425 end
1426 else
1427 // no other note being edited, so just proceed as before.
1428 UpdateEncounterInfo;
1429 if cmdPCE <> nil then
1430 cmdPCE.Enabled := TRUE
1431end;
1432
1433{ Right panel (editor) events -------------------------------------------------------------- }
1434
1435procedure TfrmNotes.mnuActChangeClick(Sender: TObject);
1436begin
1437 inherited;
1438 if (FEditingIndex < 0) or (lstNotes.ItemIndex <> FEditingIndex) then Exit;
1439 cmdChangeClick(Sender);
1440end;
1441
1442procedure TfrmNotes.mnuActLoadBoilerClick(Sender: TObject);
1443var
1444 NoteEmpty: Boolean;
1445 BoilerText: TStringList;
1446 DocInfo: string;
1447
1448 procedure AssignBoilerText;
1449 begin
1450 ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
1451 memNewNote.Lines.Assign(BoilerText);
1452 UpdateNoteAuthor(DocInfo);
1453 FChanged := False;
1454 end;
1455
1456begin
1457 inherited;
1458 if (FEditingIndex < 0) or (lstNotes.ItemIndex <> FEditingIndex) then Exit;
1459 BoilerText := TStringList.Create;
1460 try
1461 NoteEmpty := memNewNote.Text = '';
1462 LoadBoilerPlate(BoilerText, FEditNote.Title);
1463 if (BoilerText.Text <> '') or
1464 assigned(GetLinkedTemplate(IntToStr(FEditNote.Title), ltTitle)) then
1465 begin
1466 DocInfo := MakeXMLParamTIU(IntToStr(lstNotes.ItemIEN), FEditNote);
1467 if NoteEmpty then AssignBoilerText else
1468 begin
1469 case QueryBoilerPlate(BoilerText) of
1470 0: { do nothing } ; // ignore
1471 1: begin
1472 ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
1473 memNewNote.Lines.AddStrings(BoilerText); // append
1474 UpdateNoteAuthor(DocInfo);
1475 end;
1476 2: AssignBoilerText; // replace
1477 end;
1478 end;
1479 end else
1480 begin
1481 if Sender = mnuActLoadBoiler
1482 then InfoBox(TX_NO_BOIL, TC_NO_BOIL, MB_OK)
1483 else
1484 begin
1485 if not NoteEmpty then
1486// if not FChanged and (InfoBox(TX_BLR_CLEAR, TC_BLR_CLEAR, MB_YESNO) = ID_YES)
1487 if (InfoBox(TX_BLR_CLEAR, TC_BLR_CLEAR, MB_YESNO) = ID_YES)
1488 then memNewNote.Lines.Clear;
1489 end;
1490 end; {if BoilerText.Text <> ''}
1491 finally
1492 BoilerText.Free;
1493 end;
1494end;
1495
1496procedure TfrmNotes.cmdChangeClick(Sender: TObject);
1497var
1498 LastTitle, LastConsult: Integer;
1499 OKPressed, IsIDChild: Boolean;
1500 x: string;
1501 DisAssoText : String;
1502begin
1503 inherited;
1504 IsIDChild := uIDNotesActive and (FEditNote.IDParent > 0);
1505 LastTitle := FEditNote.Title;
1506 FEditNote.IsNewNote := False;
1507 DisAssoText := '';
1508 if (FEditNote.PkgPtr = PKG_CONSULTS) then
1509 DisAssoText := 'Consults';
1510 if (FEditNote.PkgPtr = PKG_PRF) then
1511 DisAssoText := 'Patient Record Flags';
1512 if (DisAssoText <> '') and (Sender <> Self) then
1513 if InfoBox('If this title is changed, Any '+DisAssoText+' will be disassociated'+
1514 ' with this note',
1515 'Disassociate '+DisAssoText+'?',MB_OKCANCEL) = IDCANCEL then
1516 exit;
1517 if FEditNote.PkgPtr = PKG_CONSULTS then LastConsult := FEditNote.PkgIEN else LastConsult := 0;;
1518 if Sender <> Self then OKPressed := ExecuteNoteProperties(FEditNote, CT_NOTES, IsIDChild, FNewIDChild, '', 0)
1519 else OKPressed := True;
1520 if not OKPressed then Exit;
1521 // update display fields & uPCEEdit
1522 lblNewTitle.Caption := ' ' + FEditNote.TitleName + ' ';
1523 if (FEditNote.Addend > 0) and (CompareText(Copy(lblNewTitle.Caption, 2, 8), 'Addendum') <> 0)
1524 then lblNewTitle.Caption := ' Addendum to:' + lblNewTitle.Caption;
1525 with lblNewTitle do bvlNewTitle.SetBounds(Left - 1, Top - 1, Width + 2, Height + 2);
1526 lblRefDate.Caption := FormatFMDateTime('mmm dd,yyyy@hh:nn', FEditNote.DateTime);
1527 lblAuthor.Caption := FEditNote.AuthorName;
1528 if uPCEEdit.Inpatient then x := 'Adm: ' else x := 'Vst: ';
1529 x := x + FormatFMDateTime('mm/dd/yy', FEditNote.VisitDate) + ' ' + FEditNote.LocationName;
1530 lblVisit.Caption := x;
1531 if Length(FEditNote.CosignerName) > 0
1532 then lblCosigner.Caption := 'Expected Cosigner: ' + FEditNote.CosignerName
1533 else lblCosigner.Caption := '';
1534 uPCEEdit.NoteTitle := FEditNote.Title;
1535 // modify signature requirements if author or cosigner changed
1536 if (User.DUZ <> FEditNote.Author) and (User.DUZ <> FEditNote.Cosigner)
1537 then Changes.ReplaceSignState(CH_DOC, lstNotes.ItemID, CH_SIGN_NA)
1538 else Changes.ReplaceSignState(CH_DOC, lstNotes.ItemID, CH_SIGN_YES);
1539 x := lstNotes.Items[EditingIndex];
1540 SetPiece(x, U, 2, lblNewTitle.Caption);
1541 SetPiece(x, U, 3, FloatToStr(FEditNote.DateTime));
1542 tvNotes.Selected.Text := MakeNoteDisplayText(x);
1543 TORTreeNode(tvNotes.Selected).StringData := x;
1544 lstNotes.Items[EditingIndex] := x;
1545 Changes.ReplaceText(CH_DOC, lstNotes.ItemID, GetTitleText(EditingIndex));
1546 with FEditNote do
1547 begin
1548 if (PkgPtr = PKG_CONSULTS) and (LastConsult <> PkgIEN) then
1549 begin
1550 // try to lock the new consult, reset to previous if unable
1551 if (PkgIEN > 0) and not LockConsultRequest(PkgIEN) then
1552 begin
1553 Infobox(TX_NO_ORD_CHG, TC_NO_ORD_CHG, MB_OK);
1554 PkgIEN := LastConsult;
1555 end else
1556 begin
1557 // unlock the previous consult
1558 if LastConsult > 0 then UnlockOrderIfAble(GetConsultOrderIEN(LastConsult));
1559 if PkgIEN = 0 then FOrderID := '';
1560 end;
1561 end;
1562 //Link Note to PRF Action
1563 if PRF_IEN <> 0 then
1564 if sCallV('TIU LINK TO FLAG', [lstNotes.ItemIEN,PRF_IEN,ActionIEN,Patient.DFN]) = '0' then
1565 ShowMessage('TIU LINK TO FLAG: FAILED');
1566 end;
1567
1568 if LastTitle <> FEditNote.Title then mnuActLoadBoilerClick(Self);
1569end;
1570
1571procedure TfrmNotes.memNewNoteChange(Sender: TObject);
1572begin
1573 inherited;
1574 FChanged := True;
1575end;
1576
1577procedure TfrmNotes.pnlFieldsResize(Sender: TObject);
1578{ center the reference date on the panel }
1579begin
1580 inherited;
1581 lblRefDate.Left := (pnlFields.Width - lblRefDate.Width) div 2;
1582 if lblRefDate.Left < (lblNewTitle.Left + lblNewTitle.Width + 6)
1583 then lblRefDate.Left := (lblNewTitle.Left + lblNewTitle.Width);
1584end;
1585
1586procedure TfrmNotes.DoAutoSave(Suppress: integer = 1);
1587var
1588 ErrMsg: string;
1589begin
1590 if (EditingIndex > -1) and FChanged then
1591 begin
1592 StatusText('Autosaving note...');
1593 //PutTextOnly(ErrMsg, memNewNote.Lines, lstNotes.GetIEN(EditingIndex));
1594 timAutoSave.Enabled := False;
1595 try
1596 SetText(ErrMsg, memNewNote.Lines, lstNotes.GetIEN(EditingIndex), Suppress);
1597 finally
1598 timAutoSave.Enabled := True;
1599 end;
1600 FChanged := False;
1601 StatusText('');
1602 end;
1603 if ErrMsg <> '' then
1604 InfoBox(TX_SAVE_ERROR1 + ErrMsg + TX_SAVE_ERROR2, TC_SAVE_ERROR, MB_OK or MB_ICONWARNING);
1605 //Assert(ErrMsg = '', 'AutoSave: ' + ErrMsg);
1606end;
1607
1608procedure TfrmNotes.timAutoSaveTimer(Sender: TObject);
1609begin
1610 inherited;
1611 DoAutoSave;
1612end;
1613
1614{ View menu events ------------------------------------------------------------------------- }
1615
1616procedure TfrmNotes.mnuViewClick(Sender: TObject);
1617{ changes the list of notes available for viewing }
1618var
1619 AuthCtxt: TAuthorContext;
1620 SearchCtxt: TSearchContext; // Text Search CQ: HDS00002856
1621 DateRange: TNoteDateRange;
1622 Saved: Boolean;
1623begin
1624 inherited;
1625 // save note at EditingIndex?
1626 if EditingIndex <> -1 then
1627 begin
1628 SaveCurrentNote(Saved);
1629 if not Saved then Exit;
1630 end;
1631 FLastNoteID := lstNotes.ItemID;
1632 mnuViewDetail.Checked := False;
1633 StatusText('Retrieving progress note list...');
1634 if Sender is TMenuItem then ViewContext := TMenuItem(Sender).Tag
1635 else if FCurrentContext.Status <> '' then ViewContext := NC_CUSTOM
1636 else ViewContext := NC_RECENT;
1637 case ViewContext of
1638 NC_RECENT: begin
1639 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
1640 lblNotes.Caption := 'Last ' + IntToStr(ReturnMaxNotes) + ' Notes';
1641 FCurrentContext.Status := IntToStr(ViewContext);
1642 FCurrentContext.MaxDocs := ReturnMaxNotes;
1643 LoadNotes;
1644 end;
1645 NC_ALL: begin
1646 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
1647 lblNotes.Caption := 'All Signed Notes';
1648 FCurrentContext.Status := IntToStr(ViewContext);
1649 LoadNotes;
1650 end;
1651 NC_UNSIGNED: begin
1652 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
1653 lblNotes.Caption := 'Unsigned Notes';
1654 FCurrentContext.Status := IntToStr(ViewContext);
1655 LoadNotes;
1656 end;
1657 // Text Search CQ: HDS00002856 --------------------
1658 NC_SEARCHTEXT: begin;
1659 SearchTextStopFlag := False;
1660 SelectSearchText(Font.Size, FCurrentContext.SearchString, SearchCtxt );
1661 with SearchCtxt do if Changed then
1662 begin
1663 //FCurrentContext.Status := IntToStr(ViewContext);
1664 frmSearchStop.Show;
1665 lblNotes.Caption := 'Search: '+ SearchString;
1666 frmSearchStop.lblSearchStatus.Caption := lblNotes.Caption;
1667 FCurrentContext.SearchString := SearchString;
1668 LoadNotes;
1669 end;
1670 // Only do LoadNotes if something changed
1671 end;
1672 // Text Search CQ: HDS00002856 --------------------
1673 NC_UNCOSIGNED: begin
1674 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
1675 lblNotes.Caption := 'Uncosigned Notes';
1676 FCurrentContext.Status := IntToStr(ViewContext);
1677 LoadNotes;
1678 end;
1679 NC_BY_AUTHOR: begin
1680 SelectAuthor(Font.Size, FCurrentContext, AuthCtxt);
1681 with AuthCtxt do if Changed then
1682 begin
1683 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
1684 lblNotes.Caption := AuthorName + ': Signed Notes';
1685 FCurrentContext.Status := IntToStr(NC_BY_AUTHOR);
1686 FCurrentContext.Author := Author;
1687 FCurrentContext.TreeAscending := Ascending;
1688 LoadNotes;
1689 end;
1690 end;
1691 NC_BY_DATE: begin
1692 SelectNoteDateRange(Font.Size, FCurrentContext, DateRange);
1693 with DateRange do if Changed then
1694 begin
1695 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
1696 lblNotes.Caption := FormatFMDateTime('mmm dd,yy', FMBeginDate) + ' to ' +
1697 FormatFMDateTime('mmm dd,yy', FMEndDate) + ': Signed Notes';
1698 FCurrentContext.BeginDate := BeginDate;
1699 FCurrentContext.EndDate := EndDate;
1700 FCurrentContext.FMBeginDate := FMBeginDate;
1701 FCurrentContext.FMEndDate := FMEndDate;
1702 FCurrentContext.TreeAscending := Ascending;
1703 FCurrentContext.Status := IntToStr(NC_BY_DATE);
1704 LoadNotes;
1705 end;
1706 end;
1707 NC_CUSTOM: begin
1708 if Sender is TMenuItem then
1709 begin
1710 SelectTIUView(Font.Size, True, FCurrentContext, uTIUContext);
1711 //lblNotes.Caption := 'Custom List';
1712 end;
1713 with uTIUContext do if Changed then
1714 begin
1715 //if not (Sender is TMenuItem) then lblNotes.Caption := 'Default List';
1716 //if MaxDocs = 0 then MaxDocs := ReturnMaxNotes;
1717 FCurrentContext.BeginDate := BeginDate;
1718 FCurrentContext.EndDate := EndDate;
1719 FCurrentContext.FMBeginDate := FMBeginDate;
1720 FCurrentContext.FMEndDate := FMEndDate;
1721 FCurrentContext.Status := Status;
1722 FCurrentContext.Author := Author;
1723 FCurrentContext.MaxDocs := MaxDocs;
1724 FCurrentContext.ShowSubject := ShowSubject;
1725 // NEW PREFERENCES:
1726 FCurrentContext.SortBy := SortBy;
1727 FCurrentContext.ListAscending := ListAscending;
1728 FCurrentContext.GroupBy := GroupBy;
1729 FCurrentContext.TreeAscending := TreeAscending;
1730 FCurrentContext.SearchField := SearchField;
1731 FCurrentContext.Keyword := Keyword;
1732 FCurrentContext.Filtered := Filtered;
1733 LoadNotes;
1734 end;
1735 end;
1736 end; {case}
1737 lblNotes.Caption := SetNoteTreeLabel(FCurrentContext);
1738 // Text Search CQ: HDS00002856 --------------------
1739 If FCurrentContext.SearchString <> '' then
1740 lblNotes.Caption := lblNotes.Caption+', containing "'+FCurrentContext.SearchString+'"';
1741 If SearchTextStopFlag=True then begin;
1742 lblNotes.Caption := 'Search for "'+FCurrentContext.SearchString+'" was stopped!';
1743 end;
1744 frmSearchStop.Hide;
1745 // Text Search CQ: HDS00002856 --------------------
1746 lblNotes.hint := lblNotes.Caption;
1747 tvNotes.Caption := lblNotes.Caption;
1748 StatusText('');
1749end;
1750
1751{ Action menu events ----------------------------------------------------------------------- }
1752
1753function TfrmNotes.StartNewEdit(NewNoteType: integer): Boolean;
1754{ if currently editing a note, returns TRUE if the user wants to start a new one }
1755var
1756 Saved: Boolean;
1757 Msg, CapMsg: string;
1758begin
1759 FStarting := False;
1760 Result := True;
1761 cmdNewNote.Enabled := False;
1762 if EditingIndex > -1 then
1763 begin
1764 FStarting := True;
1765 case NewNoteType of
1766 NT_ACT_ADDENDUM: begin
1767 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE3;
1768 CapMsg := TC_NEW_SAVE3;
1769 end;
1770 NT_ACT_EDIT_NOTE: begin
1771 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE4;
1772 CapMsg := TC_NEW_SAVE4;
1773 end;
1774 NT_ACT_ID_ENTRY: begin
1775 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE5;
1776 CapMsg := TC_NEW_SAVE5;
1777 end;
1778 else
1779 begin
1780 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE2;
1781 CapMsg := TC_NEW_SAVE2;
1782 end;
1783 end;
1784 if InfoBox(Msg, CapMsg, MB_YESNO) = IDNO then
1785 begin
1786 Result := False;
1787 FStarting := False;
1788 end
1789 else
1790 begin
1791 SaveCurrentNote(Saved);
1792 if not Saved then Result := False else LoadNotes;
1793 FStarting := False;
1794 end;
1795 end;
1796 cmdNewNote.Enabled := (Result = False) and (FStarting = False);
1797end;
1798
1799procedure TfrmNotes.mnuActNewClick(Sender: TObject);
1800const
1801 IS_ID_CHILD = False;
1802{ switches to current new note or creates a new note if none is being edited already }
1803begin
1804 inherited;
1805 if not StartNewEdit(NT_ACT_NEW_NOTE) then Exit;
1806 //LoadNotes;
1807 // make sure a visit (time & location) is available before creating the note
1808 if Encounter.NeedVisit then
1809 begin
1810 UpdateVisit(Font.Size, DfltTIULocation);
1811 frmFrame.DisplayEncounterText;
1812 end;
1813 if Encounter.NeedVisit then
1814 begin
1815 InfoBox(TX_NEED_VISIT, TX_NO_VISIT, MB_OK or MB_ICONWARNING);
1816 ShowPCEButtons(False);
1817 Exit;
1818 end;
1819 InsertNewNote(IS_ID_CHILD, 0);
1820end;
1821
1822procedure TfrmNotes.mnuActAddIDEntryClick(Sender: TObject);
1823const
1824 IS_ID_CHILD = True;
1825var
1826 AnIDParent: integer;
1827{ switches to current new note or creates a new note if none is being edited already }
1828begin
1829 inherited;
1830 AnIDParent := lstNotes.ItemIEN;
1831 if not StartNewEdit(NT_ACT_ID_ENTRY) then Exit;
1832 //LoadNotes;
1833 with tvNotes do Selected := FindPieceNode(IntToStr(AnIDParent), U, Items.GetFirstNode);
1834 // make sure a visit (time & location) is available before creating the note
1835 if Encounter.NeedVisit then
1836 begin
1837 UpdateVisit(Font.Size, DfltTIULocation);
1838 frmFrame.DisplayEncounterText;
1839 end;
1840 if Encounter.NeedVisit then
1841 begin
1842 InfoBox(TX_NEED_VISIT, TX_NO_VISIT, MB_OK or MB_ICONWARNING);
1843 Exit;
1844 end;
1845 InsertNewNote(IS_ID_CHILD, AnIDParent);
1846end;
1847
1848procedure TfrmNotes.mnuActAddendClick(Sender: TObject);
1849{ make an addendum to an existing note }
1850var
1851 ActionSts: TActionRec;
1852 ANoteID: string;
1853begin
1854 inherited;
1855 if lstNotes.ItemIEN <= 0 then Exit;
1856 ANoteID := lstNotes.ItemID;
1857 if not StartNewEdit(NT_ACT_ADDENDUM) then Exit;
1858 //LoadNotes;
1859 with tvNotes do Selected := FindPieceNode(ANoteID, 1, U, Items.GetFirstNode);
1860 if lstNotes.ItemIndex = EditingIndex then
1861 begin
1862 InfoBox(TX_ADDEND_NO, TX_ADDEND_MK, MB_OK);
1863 Exit;
1864 end;
1865 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'MAKE ADDENDUM');
1866 if not ActionSts.Success then
1867 begin
1868 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1869 Exit;
1870 end;
1871 with lstNotes do if TitleForNote(lstNotes.ItemIEN) = TYP_ADDENDUM then
1872 begin
1873 InfoBox(TX_ADDEND_AD, TX_ADDEND_MK, MB_OK);
1874 Exit;
1875 end;
1876 InsertAddendum;
1877end;
1878
1879procedure TfrmNotes.mnuActDetachFromIDParentClick(Sender: TObject);
1880var
1881 DocID, WhyNot: string;
1882 Saved: boolean;
1883 SavedDocID: string;
1884begin
1885 if lstNotes.ItemIEN = 0 then exit;
1886 SavedDocID := lstNotes.ItemID;
1887 if EditingIndex <> -1 then
1888 begin
1889 SaveCurrentNote(Saved);
1890 if not Saved then Exit;
1891 LoadNotes;
1892 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
1893 end;
1894 if not CanBeAttached(PDocTreeObject(tvNotes.Selected.Data)^.DocID, WhyNot) then
1895 begin
1896 WhyNot := StringReplace(WhyNot, 'ATTACH', 'DETACH', [rfIgnoreCase]);
1897 WhyNot := StringReplace(WhyNot, 'to an ID', 'from an ID', [rfIgnoreCase]);
1898 InfoBox(WhyNot, TX_DETACH_FAILURE, MB_OK);
1899 Exit;
1900 end;
1901 if (InfoBox('DETACH: ' + tvNotes.Selected.Text + CRLF + CRLF +
1902 ' FROM: ' + tvNotes.Selected.Parent.Text + CRLF + CRLF +
1903 'Are you sure?', TX_DETACH_CNF, MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) <> IDYES)
1904 then Exit;
1905 DocID := PDocTreeObject(tvNotes.Selected.Data)^.DocID;
1906 SavedDocID := PDocTreeObject(tvNotes.Selected.Parent.Data)^.DocID;
1907 if DetachEntryFromParent(DocID, WhyNot) then
1908 begin
1909 LoadNotes;
1910 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
1911 if tvNotes.Selected <> nil then tvNotes.Selected.Expand(False);
1912 end
1913 else
1914 begin
1915 WhyNot := StringReplace(WhyNot, 'ATTACH', 'DETACH', [rfIgnoreCase]);
1916 WhyNot := StringReplace(WhyNot, 'to an ID', 'from an ID', [rfIgnoreCase]);
1917 InfoBox(WhyNot, TX_DETACH_FAILURE, MB_OK);
1918 end;
1919end;
1920
1921procedure TfrmNotes.mnuActSignListClick(Sender: TObject);
1922{ add the note to the Encounter object, see mnuActSignClick - copied}
1923const
1924 SIG_COSIGN = 'COSIGNATURE';
1925 SIG_SIGN = 'SIGNATURE';
1926var
1927 ActionType, SignTitle: string;
1928 ActionSts: TActionRec;
1929begin
1930 inherited;
1931 if lstNotes.ItemIEN = 0 then Exit;
1932 if lstNotes.ItemIndex = EditingIndex then Exit; // already in signature list
1933 if not NoteHasText(lstNotes.ItemIEN) then
1934 begin
1935 InfoBox(TX_EMPTY_NOTE1, TC_EMPTY_NOTE, MB_OK or MB_ICONERROR);
1936 Exit;
1937 end;
1938 if not LastSaveClean(lstNotes.ItemIEN) and
1939 (InfoBox(TX_ABSAVE, TC_ABSAVE, MB_YESNO or MB_DEFBUTTON2 or MB_ICONWARNING) <> IDYES) then Exit;
1940 if CosignDocument(lstNotes.ItemIEN) then
1941 begin
1942 SignTitle := TX_COSIGN;
1943 ActionType := SIG_COSIGN;
1944 end else
1945 begin
1946 SignTitle := TX_SIGN;
1947 ActionType := SIG_SIGN;
1948 end;
1949 ActOnDocument(ActionSts, lstNotes.ItemIEN, ActionType);
1950 if not ActionSts.Success then
1951 begin
1952 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1953 Exit;
1954 end;
1955 LockConsultRequestAndNote(lstNotes.ItemIEN);
1956 with lstNotes do Changes.Add(CH_DOC, ItemID, GetTitleText(ItemIndex), '', CH_SIGN_YES);
1957end;
1958
1959procedure TfrmNotes.RemovePCEFromChanges(IEN: Int64; AVisitStr: string = '');
1960begin
1961 if IEN = NT_ADDENDUM then Exit; // no PCE information entered for an addendum
1962 // do we need to call DeletePCE(AVisitStr), as was done with NT_NEW_NOTE (ien=-10)???
1963 if AVisitStr = '' then AVisitStr := VisitStrForNote(IEN);
1964 Changes.Remove(CH_PCE, 'V' + AVisitStr);
1965 Changes.Remove(CH_PCE, 'P' + AVisitStr);
1966 Changes.Remove(CH_PCE, 'D' + AVisitStr);
1967 Changes.Remove(CH_PCE, 'I' + AVisitStr);
1968 Changes.Remove(CH_PCE, 'S' + AVisitStr);
1969 Changes.Remove(CH_PCE, 'A' + AVisitStr);
1970 Changes.Remove(CH_PCE, 'H' + AVisitStr);
1971 Changes.Remove(CH_PCE, 'E' + AVisitStr);
1972 Changes.Remove(CH_PCE, 'T' + AVisitStr);
1973end;
1974
1975procedure TfrmNotes.mnuActDeleteClick(Sender: TObject);
1976{ delete the selected progress note & remove from the Encounter object if necessary }
1977var
1978 DeleteSts, ActionSts: TActionRec;
1979 SaveConsult, SavedDocIEN: Integer;
1980 ReasonForDelete, AVisitStr, SavedDocID, x: string;
1981 Saved: boolean;
1982begin
1983 inherited;
1984 if lstNotes.ItemIEN = 0 then Exit;
1985 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'DELETE RECORD');
1986 if ShowMsgOn(not ActionSts.Success, ActionSts.Reason, TX_IN_AUTH) then Exit;
1987 ReasonForDelete := SelectDeleteReason(lstNotes.ItemIEN);
1988 if ReasonForDelete = DR_CANCEL then Exit;
1989 // suppress prompt for deletion when called from SaveEditedNote (Sender = Self)
1990 if (Sender <> Self) and (InfoBox(MakeNoteDisplayText(lstNotes.Items[lstNotes.ItemIndex]) + TX_DEL_OK,
1991 TX_DEL_CNF, MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) <> IDYES) then Exit;
1992 // do the appropriate locking
1993 if not LockConsultRequestAndNote(lstNotes.ItemIEN) then Exit;
1994 // retraction notification message
1995 if JustifyDocumentDelete(lstNotes.ItemIEN) then
1996 InfoBox(TX_RETRACT, TX_RETRACT_CAP, MB_OK);
1997 SavedDocID := lstNotes.ItemID;
1998 SavedDocIEN := lstNotes.ItemIEN;
1999 if (EditingIndex > -1) and (not FConfirmed) and (lstNotes.ItemIndex <> EditingIndex) and (memNewNote.GetTextLen > 0) then
2000 begin
2001 SaveCurrentNote(Saved);
2002 if not Saved then Exit;
2003 end;
2004 EditingIndex := -1;
2005 FConfirmed := False;
2006 (* if Saved then
2007 begin
2008 EditingIndex := -1;
2009 mnuViewClick(Self);
2010 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
2011 end;*)
2012 // remove the note
2013 DeleteSts.Success := True;
2014 x := GetPackageRefForNote(SavedDocIEN);
2015 SaveConsult := StrToIntDef(Piece(x, ';', 1), 0);
2016 AVisitStr := VisitStrForNote(SavedDocIEN);
2017 RemovePCEFromChanges(SavedDocIEN, AVisitStr);
2018 if (SavedDocIEN > 0) and (lstNotes.ItemIEN = SavedDocIEN) then DeleteDocument(DeleteSts, SavedDocIEN, ReasonForDelete);
2019 if not Changes.Exist(CH_DOC, SavedDocID) then UnlockDocument(SavedDocIEN);
2020 Changes.Remove(CH_DOC, SavedDocID); // this will unlock the document if in Changes
2021 UnlockConsultRequest(0, SaveConsult); // note has been deleted, so 1st param = 0
2022 // reset the display now that the note is gone
2023 if DeleteSts.Success then
2024 begin
2025 DeletePCE(AVisitStr); // removes PCE data if this was the only note pointing to it
2026 ClearEditControls;
2027 //ClearPtData; WRONG - fixed in v15.10 - RV
2028 LoadNotes;
2029(* with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
2030 if tvNotes.Selected <> nil then tvNotesChange(Self, tvNotes.Selected) else
2031 begin*)
2032 pnlWrite.Visible := False;
2033 pnlRead.Visible := True;
2034 UpdateReminderFinish;
2035 ShowPCEControls(False);
2036 frmDrawers.DisplayDrawers(TRUE, [odTemplates], [odTemplates]); //FALSE);
2037 ShowPCEButtons(FALSE);
2038 //end; {if ItemIndex}
2039 end {if DeleteSts}
2040 else InfoBox(DeleteSts.Reason, TX_DEL_ERR, MB_OK or MB_ICONWARNING);
2041end;
2042
2043procedure TfrmNotes.mnuActEditClick(Sender: TObject);
2044{ load the selected progress note for editing }
2045var
2046 ActionSts: TActionRec;
2047 ANoteID: string;
2048begin
2049 inherited;
2050 if lstNotes.ItemIndex = EditingIndex then Exit;
2051 ANoteID := lstNotes.ItemID;
2052 if not StartNewEdit(NT_ACT_EDIT_NOTE) then Exit;
2053 //LoadNotes;
2054 with tvNotes do Selected := FindPieceNode(ANoteID, 1, U, Items.GetFirstNode);
2055 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'EDIT RECORD');
2056 if not ActionSts.Success then
2057 begin
2058 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
2059 Exit;
2060 end;
2061 LoadForEdit;
2062end;
2063
2064procedure TfrmNotes.mnuActSaveClick(Sender: TObject);
2065{ saves the note that is currently being edited }
2066var
2067 Saved: Boolean;
2068 SavedDocID: string;
2069begin
2070 inherited;
2071 if EditingIndex > -1 then
2072 begin
2073 SavedDocID := Piece(lstNotes.Items[EditingIndex], U, 1);
2074 FLastNoteID := SavedDocID;
2075 SaveCurrentNote(Saved);
2076 if Saved and (EditingIndex < 0) and (not FDeleted) then
2077 //if Saved then
2078 begin
2079 LoadNotes;
2080 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
2081 end;
2082 end
2083 else InfoBox(TX_NO_NOTE, TX_SAVE_NOTE, MB_OK or MB_ICONWARNING);
2084end;
2085
2086procedure TfrmNotes.mnuActSignClick(Sender: TObject);
2087{ sign the currently selected note, save first if necessary }
2088const
2089 SIG_COSIGN = 'COSIGNATURE';
2090 SIG_SIGN = 'SIGNATURE';
2091var
2092 Saved, NoteUnlocked: Boolean;
2093 ActionType, ESCode, SignTitle: string;
2094 ActionSts, SignSts: TActionRec;
2095 OK: boolean;
2096 SavedDocID, tmpItem: string;
2097 EditingID: string; //v22.12 - RV
2098 tmpNode: TTreeNode;
2099begin
2100 inherited;
2101(* if lstNotes.ItemIndex = EditingIndex then //v22.12 - RV
2102 begin //v22.12 - RV
2103 SaveCurrentNote(Saved); //v22.12 - RV
2104 if (not Saved) or FDeleted then Exit; //v22.12 - RV
2105 end //v22.12 - RV
2106 else if EditingIndex > -1 then //v22.12 - RV
2107 tmpItem := lstNotes.Items[EditingIndex]; //v22.12 - RV
2108 SavedDocID := lstNotes.ItemID;*) //v22.12 - RV
2109 SavedDocID := lstNotes.ItemID; //v22.12 - RV
2110 FLastNoteID := SavedDocID; //v22.12 - RV
2111 if lstNotes.ItemIndex = EditingIndex then //v22.12 - RV
2112 begin //v22.12 - RV
2113 SaveCurrentNote(Saved); //v22.12 - RV
2114 if (not Saved) or FDeleted then Exit; //v22.12 - RV
2115 end //v22.12 - RV
2116 else if EditingIndex > -1 then //v22.12 - RV
2117 begin //v22.12 - RV
2118 tmpItem := lstNotes.Items[EditingIndex]; //v22.12 - RV
2119 EditingID := Piece(tmpItem, U, 1); //v22.12 - RV
2120 end; //v22.12 - RV
2121 if not NoteHasText(lstNotes.ItemIEN) then
2122 begin
2123 InfoBox(TX_EMPTY_NOTE1, TC_EMPTY_NOTE, MB_OK or MB_ICONERROR);
2124 Exit;
2125 end;
2126 if not LastSaveClean(lstNotes.ItemIEN) and
2127 (InfoBox(TX_ABSAVE, TC_ABSAVE, MB_YESNO or MB_DEFBUTTON2 or MB_ICONWARNING) <> IDYES) then Exit;
2128 if CosignDocument(lstNotes.ItemIEN) then
2129 begin
2130 SignTitle := TX_COSIGN;
2131 ActionType := SIG_COSIGN;
2132 end else
2133 begin
2134 SignTitle := TX_SIGN;
2135 ActionType := SIG_SIGN;
2136 end;
2137 if not LockConsultRequestAndNote(lstNotes.ItemIEN) then Exit;
2138 // no exits after things are locked
2139 NoteUnlocked := False;
2140 ActOnDocument(ActionSts, lstNotes.ItemIEN, ActionType);
2141 if ActionSts.Success then
2142 begin
2143 OK := IsOK2Sign(uPCEShow, lstNotes.ItemIEN);
2144 if frmFrame.Closing then exit;
2145 if(uPCEShow.Updated) then
2146 begin
2147 uPCEShow.CopyPCEData(uPCEEdit);
2148 uPCEShow.Updated := FALSE;
2149 lstNotesClick(Self);
2150 end;
2151 if not AuthorSignedDocument(lstNotes.ItemIEN) then
2152 begin
2153 if (InfoBox(TX_AUTH_SIGNED +
2154 GetTitleText(lstNotes.ItemIndex),TX_SIGN ,MB_YESNO)= ID_NO) then exit;
2155 end;
2156 if(OK) then
2157 begin
2158 with lstNotes do SignatureForItem(Font.Size, MakeNoteDisplayText(Items[ItemIndex]), SignTitle, ESCode);
2159 if Length(ESCode) > 0 then
2160 begin
2161 SignDocument(SignSts, lstNotes.ItemIEN, ESCode);
2162 RemovePCEFromChanges(lstNotes.ItemIEN);
2163 NoteUnlocked := Changes.Exist(CH_DOC, lstNotes.ItemID);
2164 Changes.Remove(CH_DOC, lstNotes.ItemID); // this will unlock if in Changes
2165 if SignSts.Success then
2166 begin
2167 SendMessage(frmConsults.Handle, UM_NEWORDER, ORDER_SIGN, 0); {*REV*}
2168 lstNotesClick(Self);
2169 end
2170 else InfoBox(SignSts.Reason, TX_SIGN_ERR, MB_OK);
2171 end {if Length(ESCode)}
2172 else
2173 NoteUnlocked := Changes.Exist(CH_DOC, lstNotes.ItemID);
2174 end;
2175 end
2176 else InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
2177 if not NoteUnlocked then UnlockDocument(lstNotes.ItemIEN);
2178 UnlockConsultRequest(lstNotes.ItemIEN);
2179 //SetViewContext(FCurrentContext); //v22.12 - RV
2180 LoadNotes; //v22.12 - RV
2181 //if EditingIndex > -1 then //v22.12 - RV
2182 if (EditingID <> '') then //v22.12 - RV
2183 begin
2184 lstNotes.Items.Insert(0, tmpItem);
2185 tmpNode := tvNotes.Items.AddObjectFirst(tvNotes.Items.GetFirstNode, 'Note being edited',
2186 MakeNoteTreeObject('EDIT^Note being edited^^^^^^^^^^^%^0'));
2187 TORTreeNode(tmpNode).StringData := 'EDIT^Note being edited^^^^^^^^^^^%^0';
2188 tmpNode.ImageIndex := IMG_TOP_LEVEL;
2189 tmpNode := tvNotes.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(tmpItem), MakeNoteTreeObject(tmpItem));
2190 TORTreeNode(tmpNode).StringData := tmpItem;
2191 SetTreeNodeImagesAndFormatting(TORTreeNode(tmpNode), FCurrentContext, CT_NOTES);
2192 EditingIndex := lstNotes.SelectByID(EditingID); //v22.12 - RV
2193 end;
2194 //with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode); //v22.12 - RV
2195 with tvNotes do //v22.12 - RV
2196 begin //v22.12 - RV
2197 Selected := FindPieceNode(FLastNoteID, U, Items.GetFirstNode); //v22.12 - RV
2198 if Selected <> nil then
2199 tvNotesChange(Self, Selected) //v22.12 - RV
2200 else
2201 tvNotes.Selected := tvNotes.Items[0]; //first Node in treeview
2202 end; //v22.12 - RV
2203end;
2204
2205procedure TfrmNotes.SaveSignItem(const ItemID, ESCode: string);
2206{ saves and optionally signs a progress note or addendum }
2207const
2208 SIG_COSIGN = 'COSIGNATURE';
2209 SIG_SIGN = 'SIGNATURE';
2210var
2211 AnIndex, IEN, i: Integer;
2212 Saved, ContinueSign: Boolean; {*RAB* 8/26/99}
2213 ActionSts, SignSts: TActionRec;
2214 APCEObject: TPCEData;
2215 OK: boolean;
2216 ActionType, SignTitle: string;
2217begin
2218 AnIndex := -1;
2219 IEN := StrToIntDef(ItemID, 0);
2220 if IEN = 0 then Exit;
2221 if frmFrame.TimedOut and (EditingIndex <> -1) then FSilent := True;
2222 with lstNotes do for i := 0 to Items.Count - 1 do if lstNotes.GetIEN(i) = IEN then
2223 begin
2224 AnIndex := i;
2225 break;
2226 end;
2227 if (AnIndex > -1) and (AnIndex = EditingIndex) then
2228 begin
2229 SaveCurrentNote(Saved);
2230 if not Saved then Exit;
2231 if FDeleted then
2232 begin
2233 FDeleted := False;
2234 Exit;
2235 end;
2236 AnIndex := lstNotes.SelectByIEN(IEN);
2237 //IEN := lstNotes.GetIEN(AnIndex); // saving will change IEN
2238 end;
2239 if Length(ESCode) > 0 then
2240 begin
2241 if CosignDocument(IEN) then
2242 begin
2243 SignTitle := TX_COSIGN;
2244 ActionType := SIG_COSIGN;
2245 end else
2246 begin
2247 SignTitle := TX_SIGN;
2248 ActionType := SIG_SIGN;
2249 end;
2250 ActOnDocument(ActionSts, IEN, ActionType);
2251 if not ActionSts.Success then
2252 begin
2253 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
2254 ContinueSign := False;
2255 end
2256 else if not NoteHasText(IEN) then
2257 begin
2258 InfoBox(TX_EMPTY_NOTE1, TC_EMPTY_NOTE, MB_OK or MB_ICONERROR);
2259 ContinueSign := False;
2260 end
2261 else if not LastSaveClean(IEN) and
2262 (InfoBox(TX_ABSAVE, TC_ABSAVE, MB_YESNO or MB_DEFBUTTON2 or MB_ICONWARNING) <> IDYES)
2263 then ContinueSign := False
2264 else ContinueSign := True;
2265 if ContinueSign then
2266 begin
2267 if (AnIndex >= 0) and (AnIndex = lstNotes.ItemIndex) then
2268 APCEObject := uPCEShow
2269 else
2270 APCEObject := nil;
2271 OK := IsOK2Sign(APCEObject, IEN);
2272 if frmFrame.Closing then exit;
2273 if(assigned(APCEObject)) and (uPCEShow.Updated) then
2274 begin
2275 uPCEShow.CopyPCEData(uPCEEdit);
2276 uPCEShow.Updated := FALSE;
2277 lstNotesClick(Self);
2278 end
2279 else
2280 uPCEEdit.Clear;
2281 if(OK) then
2282 begin
2283 //if ((not FSilent) and IsSurgeryTitle(TitleForNote(IEN))) then DisplayOpTop(IEN);
2284 SignDocument(SignSts, IEN, ESCode);
2285 if not SignSts.Success then InfoBox(SignSts.Reason, TX_SIGN_ERR, MB_OK);
2286 end; {if OK}
2287 end; {if ContinueSign}
2288 end; {if Length(ESCode)}
2289
2290 UnlockConsultRequest(IEN);
2291 if (AnIndex = lstNotes.ItemIndex) and (not frmFrame.ContextChanging) then
2292 begin
2293 LoadNotes;
2294 with tvNotes do Selected := FindPieceNode(IntToStr(IEN), U, Items.GetFirstNode);
2295 end;
2296end;
2297
2298procedure TfrmNotes.popNoteMemoPopup(Sender: TObject);
2299begin
2300 inherited;
2301 if PopupComponent(Sender, popNoteMemo) is TCustomEdit
2302 then FEditCtrl := TCustomEdit(PopupComponent(Sender, popNoteMemo))
2303 else FEditCtrl := nil;
2304 if FEditCtrl <> nil then
2305 begin
2306 popNoteMemoCut.Enabled := FEditCtrl.SelLength > 0;
2307 popNoteMemoCopy.Enabled := popNoteMemoCut.Enabled;
2308 popNoteMemoPaste.Enabled := (not TORExposedCustomEdit(FEditCtrl).ReadOnly) and
2309 Clipboard.HasFormat(CF_TEXT);
2310 popNoteMemoTemplate.Enabled := frmDrawers.CanEditTemplates and popNoteMemoCut.Enabled;
2311 popNoteMemoFind.Enabled := FEditCtrl.GetTextLen > 0;
2312 end else
2313 begin
2314 popNoteMemoCut.Enabled := False;
2315 popNoteMemoCopy.Enabled := False;
2316 popNoteMemoPaste.Enabled := False;
2317 popNoteMemoTemplate.Enabled := False;
2318 end;
2319 if pnlWrite.Visible then
2320 begin
2321 popNoteMemoSpell.Enabled := True;
2322 popNoteMemoGrammar.Enabled := True;
2323 popNoteMemoReformat.Enabled := True;
2324 popNoteMemoReplace.Enabled := (FEditCtrl.GetTextLen > 0);
2325 popNoteMemoPreview.Enabled := (frmDrawers.TheOpenDrawer = odTemplates) and Assigned(frmDrawers.tvTemplates.Selected);
2326 popNoteMemoInsTemplate.Enabled := (frmDrawers.TheOpenDrawer = odTemplates) and Assigned(frmDrawers.tvTemplates.Selected);
2327 end else
2328 begin
2329 popNoteMemoSpell.Enabled := False;
2330 popNoteMemoGrammar.Enabled := False;
2331 popNoteMemoReformat.Enabled := False;
2332 popNoteMemoReplace.Enabled := False;
2333 popNoteMemoPreview.Enabled := False;
2334 popNoteMemoInsTemplate.Enabled := False;
2335 end;
2336end;
2337
2338procedure TfrmNotes.popNoteMemoCutClick(Sender: TObject);
2339begin
2340 inherited;
2341 FEditCtrl.CutToClipboard;
2342end;
2343
2344procedure TfrmNotes.popNoteMemoCopyClick(Sender: TObject);
2345begin
2346 inherited;
2347 FEditCtrl.CopyToClipboard;
2348end;
2349
2350procedure TfrmNotes.popNoteMemoPasteClick(Sender: TObject);
2351begin
2352 inherited;
2353 FEditCtrl.SelText := Clipboard.AsText; {*KCM*}
2354 frmNotes.pnlWriteResize(Self);
2355 //FEditCtrl.PasteFromClipboard; // use AsText to prevent formatting
2356end;
2357
2358procedure TfrmNotes.popNoteMemoReformatClick(Sender: TObject);
2359begin
2360 inherited;
2361 if Screen.ActiveControl <> memNewNote then Exit;
2362 ReformatMemoParagraph(memNewNote);
2363end;
2364
2365procedure TfrmNotes.popNoteMemoSaveContinueClick(Sender: TObject);
2366begin
2367 inherited;
2368 FChanged := True;
2369 DoAutoSave;
2370end;
2371
2372procedure TfrmNotes.popNoteMemoFindClick(Sender: TObject);
2373//var
2374 //hData: THandle; //CQ8300
2375 //pData: ^ClipboardData; //CQ8300
2376begin
2377 inherited;
2378 SendMessage(TRichEdit(popNoteMemo.PopupComponent).Handle, WM_VSCROLL, SB_TOP, 0);
2379 with dlgFindText do
2380 begin
2381 Position := Point(Application.MainForm.Left + pnlLeft.Width, Application.MainForm.Top);
2382 FindText := '';
2383 Options := [frDown, frHideUpDown];
2384{
2385 //CQ8300
2386 OpenClipboard(dlgFindText.Handle);
2387 hData := GetClipboardData(CF_TEXT);
2388 pData := GlobalLock(hData);
2389 FindText := pData^.Text;
2390 GlobalUnlock(hData);
2391 CloseClipboard;
2392 //end CQ8300
2393}
2394 Execute;
2395 end;
2396end;
2397
2398procedure TfrmNotes.dlgFindTextFind(Sender: TObject);
2399begin
2400 dmodShared.FindRichEditText(dlgFindText, TRichEdit(popNoteMemo.PopupComponent));
2401end;
2402
2403procedure TfrmNotes.popNoteMemoReplaceClick(Sender: TObject);
2404begin
2405 inherited;
2406 SendMessage(TRichEdit(popNoteMemo.PopupComponent).Handle, WM_VSCROLL, SB_TOP, 0);
2407 with dlgReplaceText do
2408 begin
2409 Position := Point(Application.MainForm.Left + pnlLeft.Width, Application.MainForm.Top);
2410 FindText := '';
2411 ReplaceText := '';
2412 Options := [frDown, frHideUpDown];
2413 Execute;
2414 end;
2415end;
2416
2417procedure TfrmNotes.dlgReplaceTextFind(Sender: TObject);
2418begin
2419 inherited;
2420 dmodShared.FindRichEditText(dlgFindText, TRichEdit(popNoteMemo.PopupComponent));
2421end;
2422
2423procedure TfrmNotes.dlgReplaceTextReplace(Sender: TObject);
2424begin
2425 inherited;
2426 dmodShared.ReplaceRichEditText(dlgReplaceText, TRichEdit(popNoteMemo.PopupComponent));
2427end;
2428
2429procedure TfrmNotes.popNoteMemoSpellClick(Sender: TObject);
2430begin
2431 inherited;
2432 DoAutoSave(0);
2433 timAutoSave.Enabled := False;
2434 try
2435 SpellCheckForControl(memNewNote);
2436 finally
2437 FChanged := True;
2438 DoAutoSave(0);
2439 timAutoSave.Enabled := True;
2440 end;
2441end;
2442
2443procedure TfrmNotes.popNoteMemoGrammarClick(Sender: TObject);
2444begin
2445 inherited;
2446 DoAutoSave(0);
2447 timAutoSave.Enabled := False;
2448 try
2449 GrammarCheckForControl(memNewNote);
2450 finally
2451 FChanged := True;
2452 DoAutoSave(0);
2453 timAutoSave.Enabled := True;
2454 end;
2455end;
2456
2457procedure TfrmNotes.mnuViewDetailClick(Sender: TObject);
2458begin
2459 inherited;
2460 if lstNotes.ItemIEN <= 0 then Exit;
2461 mnuViewDetail.Checked := not mnuViewDetail.Checked;
2462 if mnuViewDetail.Checked then
2463 begin
2464 StatusText('Retrieving progress note details...');
2465 Screen.Cursor := crHourGlass;
2466 LoadDetailText(memNote.Lines, lstNotes.ItemIEN);
2467 Screen.Cursor := crDefault;
2468 StatusText('');
2469 memNote.SelStart := 0;
2470 memNote.Repaint;
2471 end
2472 else
2473 lstNotesClick(Self);
2474 SendMessage(memNote.Handle, WM_VSCROLL, SB_TOP, 0);
2475end;
2476
2477procedure TfrmNotes.FormClose(Sender: TObject; var Action: TCloseAction);
2478var
2479 Saved: Boolean;
2480 IEN: Int64;
2481 ErrMsg: string;
2482 DeleteSts: TActionRec;
2483begin
2484 inherited;
2485 if frmFrame.TimedOut and (EditingIndex <> -1) then
2486 begin
2487 FSilent := True;
2488 if memNewNote.GetTextLen > 0 then SaveCurrentNote(Saved)
2489 else
2490 begin
2491 IEN := lstNotes.GetIEN(EditingIndex);
2492 if not LastSaveClean(IEN) then // means note hasn't been committed yet
2493 begin
2494 LockDocument(IEN, ErrMsg);
2495 if ErrMsg = '' then
2496 begin
2497 DeleteDocument(DeleteSts, IEN, '');
2498 UnlockDocument(IEN);
2499 end; {if ErrMsg}
2500 end; {if not LastSaveClean}
2501 end; {else}
2502 end; {if frmFrame}
2503end;
2504
2505procedure TfrmNotes.mnuActIdentifyAddlSignersClick(Sender: TObject);
2506var
2507 Exclusions: TStrings;
2508 Saved, x, y: boolean;
2509 SignerList: TSignerList;
2510 ActionSts: TActionRec;
2511 SigAction: integer;
2512 SavedDocID: string;
2513 ARefDate: TFMDateTime;
2514begin
2515 inherited;
2516 if lstNotes.ItemIEN = 0 then exit;
2517 SavedDocID := lstNotes.ItemID;
2518 if lstNotes.ItemIndex = EditingIndex then
2519 begin
2520 SaveCurrentNote(Saved);
2521 if not Saved then Exit;
2522 LoadNotes;
2523 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
2524 end;
2525 x := CanChangeCosigner(lstNotes.ItemIEN);
2526 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'IDENTIFY SIGNERS');
2527 y := ActionSts.Success;
2528 if x and not y then
2529 begin
2530 if InfoBox(ActionSts.Reason + CRLF + CRLF +
2531 'Would you like to change the cosigner?',
2532 TX_IN_AUTH, MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) = ID_YES then
2533 SigAction := SG_COSIGNER
2534 else
2535 Exit;
2536 end
2537 else if y and not x then SigAction := SG_ADDITIONAL
2538 else if x and y then SigAction := SG_BOTH
2539 else
2540 begin
2541 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
2542 Exit;
2543 end;
2544
2545 if not LockConsultRequestAndNote(lstNotes.ItemIEN) then Exit;
2546 Exclusions := GetCurrentSigners(lstNotes.ItemIEN);
2547 ARefDate := StrToFloat(Piece(lstNotes.Items[lstNotes.ItemIndex], U, 3));
2548 SelectAdditionalSigners(Font.Size, lstNotes.ItemIEN, SigAction, Exclusions, SignerList, CT_NOTES, ARefDate);
2549 with SignerList do
2550 begin
2551 case SigAction of
2552 SG_ADDITIONAL: if Changed and (Signers <> nil) and (Signers.Count > 0) then
2553 UpdateAdditionalSigners(lstNotes.ItemIEN, Signers);
2554 SG_COSIGNER: if Changed then ChangeCosigner(lstNotes.ItemIEN, Cosigner);
2555 SG_BOTH: if Changed then
2556 begin
2557 if (Signers <> nil) and (Signers.Count > 0) then
2558 UpdateAdditionalSigners(lstNotes.ItemIEN, Signers);
2559 ChangeCosigner(lstNotes.ItemIEN, Cosigner);
2560 end;
2561 end;
2562 lstNotesClick(Self);
2563 end;
2564 UnlockDocument(lstNotes.ItemIEN);
2565 UnlockConsultRequest(lstNotes.ItemIEN);
2566end;
2567
2568procedure TfrmNotes.popNoteMemoAddlSignClick(Sender: TObject);
2569begin
2570 inherited;
2571 mnuActIdentifyAddlSignersClick(Self);
2572end;
2573
2574procedure TfrmNotes.ProcessNotifications;
2575var
2576 x: string;
2577 Saved: boolean;
2578 tmpNode: TTreeNode;
2579 AnObject: PDocTreeObject;
2580begin
2581 if EditingIndex <> -1 then
2582 begin
2583 SaveCurrentNote(Saved);
2584 if not Saved then Exit;
2585 end;
2586 lblNotes.Caption := Notifications.Text;
2587 tvNotes.Caption := Notifications.Text;
2588 EditingIndex := -1;
2589 lstNotes.Enabled := True ;
2590 pnlRead.BringToFront ;
2591 // show ALL unsigned/uncosigned for a patient, not just the alerted one
2592 // what about cosignature? How to get correct list? ORB FOLLOWUP TYPE = OR alerts only
2593 x := Notifications.AlertData;
2594 if StrToIntDef(Piece(x, U, 1), 0) = 0 then
2595 begin
2596 InfoBox(TX_NO_ALERT, TX_CAP_NO_ALERT, MB_OK);
2597 Exit;
2598 end;
2599 uChanging := True;
2600 tvNotes.Items.BeginUpdate;
2601 lstNotes.Clear;
2602 KillDocTreeObjects(tvNotes);
2603 tvNotes.Items.Clear;
2604 lstNotes.Items.Add(x);
2605 AnObject := MakeNoteTreeObject('ALERT^Alerted Note^^^^^^^^^^^%^0');
2606 tmpNode := tvNotes.Items.AddObjectFirst(tvNotes.Items.GetFirstNode, AnObject.NodeText, AnObject);
2607 TORTreeNode(tmpNode).StringData := 'ALERT^Alerted Note^^^^^^^^^^^%^0';
2608 tmpNode.ImageIndex := IMG_TOP_LEVEL;
2609 AnObject := MakeNoteTreeObject(x);
2610 tmpNode := tvNotes.Items.AddChildObjectFirst(tmpNode, AnObject.NodeText, AnObject);
2611 TORTreeNode(tmpNode).StringData := x;
2612 SetTreeNodeImagesAndFormatting(TORTreeNode(tmpNode), FCurrentContext, CT_NOTES);
2613 tvNotes.Selected := tmpNode;
2614 tvNotes.Items.EndUpdate;
2615 uChanging := False;
2616 tvNotesChange(Self, tvNotes.Selected);
2617 case Notifications.Followup of
2618 NF_NOTES_UNSIGNED_NOTE: ; //Automatically deleted by sig action!!!
2619 end;
2620 if Copy(Piece(Notifications.RecordID, U, 2), 1, 6) = 'TIUADD' then Notifications.Delete;
2621 if Copy(Piece(Notifications.RecordID, U, 2), 1, 5) = 'TIUID' then Notifications.Delete;
2622end;
2623
2624procedure TfrmNotes.SetViewContext(AContext: TTIUContext);
2625var
2626 Saved: boolean;
2627begin
2628 if EditingIndex <> -1 then
2629 begin
2630 SaveCurrentNote(Saved);
2631 if not Saved then Exit;
2632 end;
2633 FCurrentContext := AContext;
2634 EditingIndex := -1;
2635 tvNotes.Enabled := True ;
2636 pnlRead.BringToFront ;
2637 if FCurrentContext.Status <> '' then with uTIUContext do
2638 begin
2639 BeginDate := FCurrentContext.BeginDate;
2640 EndDate := FCurrentContext.EndDate;
2641 FMBeginDate := FCurrentContext.FMBeginDate;
2642 FMEndDate := FCurrentContext.FMEndDate;
2643 Status := FCurrentContext.Status;
2644 Author := FCurrentContext.Author;
2645 MaxDocs := FCurrentContext.MaxDocs;
2646 ShowSubject := FCurrentContext.ShowSubject;
2647 GroupBy := FCurrentContext.GroupBy;
2648 SortBy := FCurrentContext.SortBy;
2649 ListAscending := FCurrentContext.ListAscending;
2650 TreeAscending := FCurrentContext.TreeAscending;
2651 Keyword := FCurrentContext.Keyword;
2652 SearchField := FCurrentContext.SearchField;
2653 Filtered := FCurrentContext.Filtered;
2654 Changed := True;
2655 mnuViewClick(Self);
2656 end
2657 else
2658 begin
2659 ViewContext := NC_RECENT ;
2660 mnuViewClick(Self);
2661 end;
2662end;
2663
2664procedure TfrmNotes.mnuViewSaveAsDefaultClick(Sender: TObject);
2665const
2666 TX_NO_MAX = 'You have not specified a maximum number of notes to be returned.' + CRLF +
2667 'If you save this preference, the result will be that ALL notes for every' + CRLF +
2668 'patient will be saved as your default view.' + CRLF + CRLF +
2669 'For patients with large numbers of notes, this could result in some lengthy' + CRLF +
2670 'delays in loading the list of notes.' + CRLF + CRLF +
2671 'Are you sure you mean to do this?';
2672 TX_REPLACE = 'Replace current defaults?';
2673begin
2674 inherited;
2675 if FCurrentContext.MaxDocs = 0 then
2676 if InfoBox(TX_NO_MAX,'Warning', MB_YESNO or MB_ICONWARNING) = IDNO then
2677 begin
2678 mnuViewClick(mnuViewCustom);
2679 Exit;
2680 end;
2681 if InfoBox(TX_REPLACE,'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then
2682 begin
2683 SaveCurrentTIUContext(FCurrentContext);
2684 FDefaultContext := FCurrentContext;
2685 //lblNotes.Caption := 'Default List';
2686 end;
2687end;
2688
2689procedure TfrmNotes.mnuViewReturntoDefaultClick(Sender: TObject);
2690begin
2691 inherited;
2692 SetViewContext(FDefaultContext);
2693end;
2694
2695procedure TfrmNotes.popNoteMemoTemplateClick(Sender: TObject);
2696begin
2697 inherited;
2698 EditTemplates(Self, TRUE, FEditCtrl.SelText);
2699end;
2700
2701procedure TfrmNotes.popNoteListPopup(Sender: TObject);
2702begin
2703 inherited;
2704 N4.Visible := (popNoteList.PopupComponent is TORTreeView);
2705 popNoteListExpandAll.Visible := N4.Visible;
2706 popNoteListExpandSelected.Visible := N4.Visible;
2707 popNoteListCollapseAll.Visible := N4.Visible;
2708 popNoteListCollapseSelected.Visible := N4.Visible;
2709end;
2710
2711procedure TfrmNotes.popNoteListExpandAllClick(Sender: TObject);
2712begin
2713 inherited;
2714 tvNotes.FullExpand;
2715end;
2716
2717procedure TfrmNotes.popNoteListCollapseAllClick(Sender: TObject);
2718begin
2719 inherited;
2720 tvNotes.Selected := nil;
2721 lvNotes.Items.Clear;
2722 memNote.Clear;
2723 tvNotes.FullCollapse;
2724 tvNotes.Selected := tvNotes.TopItem;
2725end;
2726
2727procedure TfrmNotes.popNoteListExpandSelectedClick(Sender: TObject);
2728begin
2729 inherited;
2730 if tvNotes.Selected = nil then exit;
2731 with tvNotes.Selected do if HasChildren then Expand(True);
2732end;
2733
2734procedure TfrmNotes.popNoteListCollapseSelectedClick(Sender: TObject);
2735begin
2736 inherited;
2737 if tvNotes.Selected = nil then exit;
2738 with tvNotes.Selected do if HasChildren then Collapse(True);
2739end;
2740
2741procedure TfrmNotes.mnuEditTemplatesClick(Sender: TObject);
2742begin
2743 inherited;
2744 EditTemplates(Self);
2745end;
2746
2747procedure TfrmNotes.mnuNewTemplateClick(Sender: TObject);
2748begin
2749 inherited;
2750 EditTemplates(Self, TRUE);
2751end;
2752
2753procedure TfrmNotes.mnuEditSharedTemplatesClick(Sender: TObject);
2754begin
2755 inherited;
2756 EditTemplates(Self, FALSE, '', TRUE);
2757end;
2758
2759procedure TfrmNotes.mnuNewSharedTemplateClick(Sender: TObject);
2760begin
2761 inherited;
2762 EditTemplates(Self, TRUE, '', TRUE);
2763end;
2764
2765procedure TfrmNotes.mnuOptionsClick(Sender: TObject);
2766begin
2767 inherited;
2768 mnuEditTemplates.Enabled := frmDrawers.CanEditTemplates;
2769 mnuNewTemplate.Enabled := frmDrawers.CanEditTemplates;
2770 mnuEditSharedTemplates.Enabled := frmDrawers.CanEditShared;
2771 mnuNewSharedTemplate.Enabled := frmDrawers.CanEditShared;
2772 mnuEditDialgFields.Enabled := CanEditTemplateFields;
2773end;
2774
2775procedure TfrmNotes.SetEditingIndex(const Value: Integer);
2776begin
2777 FEditingIndex := Value;
2778 if(FEditingIndex < 0) then
2779 KillReminderDialog(Self);
2780 if(assigned(frmReminderTree)) then
2781 frmReminderTree.EnableActions;
2782end;
2783
2784function TfrmNotes.CanFinishReminder: boolean;
2785begin
2786 if(EditingIndex < 0) then
2787 Result := FALSE
2788 else
2789 Result := (lstNotes.ItemIndex = EditingIndex);
2790end;
2791
2792procedure TfrmNotes.FormDestroy(Sender: TObject);
2793begin
2794 TAccessibleTreeView.UnwrapControl(tvNotes);
2795 FDocList.Free;
2796 FImageFlag.Free;
2797 KillDocTreeObjects(tvNotes);
2798 inherited;
2799end;
2800
2801function TfrmNotes.GetDrawers: TFrmDrawers;
2802begin
2803 Result := frmDrawers;
2804end;
2805
2806procedure TfrmNotes.AssignRemForm;
2807begin
2808 with RemForm do
2809 begin
2810 Form := Self;
2811 PCEObj := uPCEEdit;
2812 RightPanel := pnlRight;
2813 CanFinishProc := CanFinishReminder;
2814 DisplayPCEProc := DisplayPCE;
2815 Drawers := frmDrawers;
2816 NewNoteRE := memNewNote;
2817 NoteList := lstNotes;
2818 end;
2819end;
2820
2821procedure TfrmNotes.mnuEditDialgFieldsClick(Sender: TObject);
2822begin
2823 inherited;
2824 EditDialogFields;
2825end;
2826
2827//=================== Added for sort/search enhancements ======================
2828procedure TfrmNotes.LoadNotes;
2829const
2830 INVALID_ID = -1;
2831 INFO_ID = 1;
2832var
2833 tmpList: TStringList;
2834 ANode: TORTreeNode;
2835 x,xx,noteId: integer; // Text Search CQ: HDS00002856
2836 Dest: TStrings; // Text Search CQ: HDS00002856
2837 KeepFlag: Boolean; // Text Search CQ: HDS00002856
2838 NoteCount, NoteMatches: integer; // Text Search CQ: HDS00002856
2839begin
2840 tmpList := TStringList.Create;
2841 try
2842 FDocList.Clear;
2843 uChanging := True;
2844 RedrawSuspend(memNote.Handle);
2845 RedrawSuspend(lvNotes.Handle);
2846 tvNotes.Items.BeginUpdate;
2847 lstNotes.Items.Clear;
2848 KillDocTreeObjects(tvNotes);
2849 tvNotes.Items.Clear;
2850 tvNotes.Items.EndUpdate;
2851 lvNotes.Items.Clear;
2852 memNote.Clear;
2853 memNote.Invalidate;
2854 lblTitle.Caption := '';
2855 lvNotes.Caption := '';
2856 with FCurrentContext do
2857 begin
2858 if Status <> IntToStr(NC_UNSIGNED) then
2859 begin
2860 ListNotesForTree(tmpList, NC_UNSIGNED, 0, 0, 0, 0, TreeAscending);
2861 if tmpList.Count > 0 then
2862 begin
2863 CreateListItemsforDocumentTree(FDocList, tmpList, NC_UNSIGNED, GroupBy, TreeAscending, CT_NOTES);
2864 UpdateTreeView(FDocList, tvNotes);
2865 end;
2866 tmpList.Clear;
2867 FDocList.Clear;
2868 end;
2869 if Status <> IntToStr(NC_UNCOSIGNED) then
2870 begin
2871 ListNotesForTree(tmpList, NC_UNCOSIGNED, 0, 0, 0, 0, TreeAscending);
2872 if tmpList.Count > 0 then
2873 begin
2874 CreateListItemsforDocumentTree(FDocList, tmpList, NC_UNCOSIGNED, GroupBy, TreeAscending, CT_NOTES);
2875 UpdateTreeView(FDocList, tvNotes);
2876 end;
2877 tmpList.Clear;
2878 FDocList.Clear;
2879 end;
2880 ListNotesForTree(tmpList, StrToIntDef(Status, 0), FMBeginDate, FMEndDate, Author, MaxDocs, TreeAscending);
2881 CreateListItemsforDocumentTree(FDocList, tmpList, StrToIntDef(Status, 0), GroupBy, TreeAscending, CT_NOTES);
2882
2883 // Text Search CQ: HDS00002856 ---------------------------------------
2884 if FCurrentContext.SearchString<>'' then // Text Search CQ: HDS00002856
2885 begin
2886 NoteMatches := 0;
2887 Dest:=TStringList.Create;
2888 NoteCount:=FDocList.Count-1;
2889 if FDocList.Count>0 then
2890 for x := FDocList.Count-1 downto 1 do begin; // Don't do 0, because it's informational
2891 KeepFlag:=False;
2892 lblNotes.Caption:='Scanning '+IntToStr(NoteCount-x+1)+' of '+IntToStr(NoteCount)+', '+IntToStr(NoteMatches);
2893 If NoteMatches=1 then lblNotes.Caption:=lblNotes.Caption+' match' else
2894 lblNotes.Caption:=lblNotes.Caption+' matches';
2895 frmSearchStop.lblSearchStatus.Caption := lblNotes.Caption;
2896 frmSearchStop.lblSearchStatus.Repaint;
2897 lblNotes.Repaint;
2898 // Free up some ticks so they can click the "Stop" button
2899 application.processmessages;
2900 application.processmessages;
2901 application.processmessages;
2902 If SearchTextStopFlag = False then begin
2903 noteId := StrToIntDef(Piece(FDocList.Strings[x],'^',1),-1);
2904 if (noteId = INVALID_ID) or (noteId = INFO_ID) then
2905 Continue;
2906 CallV('TIU GET RECORD TEXT', [Piece(FDocList.Strings[x],'^',1)]);
2907 Dest.Assign(RPCBrokerV.Results);
2908 If Dest.Count > 0 then
2909 for xx := 0 to Dest.Count-1 do
2910 begin
2911 //Dest.Strings[xx] := StringReplace(Dest.Strings[xx],'#13',' ',[rfReplaceAll, rfIgnoreCase]);
2912 if Pos(Uppercase(FCurrentContext.SearchString),Uppercase(Dest.Strings[xx]))>0 then
2913 keepflag:=true;
2914 end;
2915 If KeepFlag=False then begin;
2916 if FDocList.Count >= x then
2917 FDocList.Delete(x);
2918 if (tmpList.Count >= x) and (x > 0) then
2919 tmpList.Delete(x-1);
2920 end else
2921 Inc(NoteMatches);
2922 end;
2923 end;
2924 Dest.Free;
2925 end;
2926 // Text Search CQ: HDS00002856 ---------------------------------------
2927
2928 UpdateTreeView(FDocList, tvNotes);
2929 end;
2930 with tvNotes do
2931 begin
2932 uChanging := True;
2933 tvNotes.Items.BeginUpdate;
2934 RemoveParentsWithNoChildren(tvNotes, FCurrentContext); // moved here in v15.9 (RV)
2935 if FLastNoteID <> '' then
2936 Selected := FindPieceNode(FLastNoteID, 1, U, nil);
2937 if Selected = nil then
2938 begin
2939 if (FCurrentContext.GroupBy <> '') or (FCurrentContext.Filtered) then
2940 begin
2941 ANode := TORTreeNode(Items.GetFirstNode);
2942 while ANode <> nil do
2943 begin
2944 ANode.Expand(False);
2945 Selected := ANode;
2946 ANode := TORTreeNode(ANode.GetNextSibling);
2947 end;
2948 end
2949 else
2950 begin
2951 ANode := tvNotes.FindPieceNode(FCurrentContext.Status, 1, U, nil);
2952 if ANode <> nil then ANode.Expand(False);
2953 ANode := tvNotes.FindPieceNode(IntToStr(NC_UNSIGNED), 1, U, nil);
2954 if ANode = nil then
2955 ANode := tvNotes.FindPieceNode(IntToStr(NC_UNCOSIGNED), 1, U, nil);
2956 if ANode = nil then
2957 ANode := tvNotes.FindPieceNode(FCurrentContext.Status, 1, U, nil);
2958 if ANode <> nil then
2959 begin
2960 if ANode.getFirstChild <> nil then
2961 Selected := ANode.getFirstChild
2962 else
2963 Selected := ANode;
2964 end;
2965 end;
2966 end;
2967 memNote.Clear;
2968 with lvNotes do
2969 begin
2970 Selected := nil;
2971 if FCurrentContext.SortBy <> '' then
2972 ColumnToSort := Pos(FCurrentContext.SortBy, 'RDSAL') - 1;
2973 if not FCurrentContext.ShowSubject then
2974 begin
2975 Columns[1].Width := 2 * (Width div 5);
2976 Columns[2].Width := 0;
2977 end
2978 else
2979 begin
2980 Columns[1].Width := Width div 5;
2981 Columns[2].Width := Columns[1].Width;
2982 end;
2983 end;
2984 //RemoveParentsWithNoChildren(tvNotes, FCurrentContext); // moved FROM here in v15.9 (RV)
2985 tvNotes.Items.EndUpdate;
2986 uChanging := False;
2987 SendMessage(tvNotes.Handle, WM_VSCROLL, SB_TOP, 0);
2988 if Selected <> nil then tvNotesChange(Self, Selected);
2989 end;
2990 finally
2991 RedrawActivate(memNote.Handle);
2992 RedrawActivate(lvNotes.Handle);
2993 tmpList.Free;
2994 end;
2995end;
2996
2997procedure TfrmNotes.UpdateTreeView(DocList: TStringList; Tree: TORTreeView);
2998begin
2999 with Tree do
3000 begin
3001 uChanging := True;
3002 Items.BeginUpdate;
3003 lstNotes.Items.AddStrings(DocList);
3004 BuildDocumentTree(DocList, '0', Tree, nil, FCurrentContext, CT_NOTES);
3005 Items.EndUpdate;
3006 uChanging := False;
3007 end;
3008end;
3009
3010procedure TfrmNotes.tvNotesChange(Sender: TObject; Node: TTreeNode);
3011var
3012 x, MySearch, MyNodeID: string;
3013 i: integer;
3014 WhyNot: string;
3015begin
3016 if uChanging then Exit;
3017 //This gives the change a chance to occur when keyboarding, so that WindowEyes
3018 //doesn't use the old value.
3019 Application.ProcessMessages;
3020 with tvNotes do
3021 begin
3022 memNote.Clear;
3023 if Selected = nil then Exit;
3024 if uIDNotesActive then
3025 begin
3026 mnuActDetachFromIDParent.Enabled := (Selected.ImageIndex in [IMG_ID_CHILD, IMG_ID_CHILD_ADD]);
3027 popNoteListDetachFromIDParent.Enabled := mnuActDetachFromIDParent.Enabled;
3028 if (Selected.ImageIndex in [IMG_SINGLE, IMG_PARENT, IMG_ID_CHILD, IMG_ID_CHILD_ADD]) then
3029 mnuActAttachtoIDParent.Enabled := CanBeAttached(PDocTreeObject(Selected.Data)^.DocID, WhyNot)
3030 else
3031 mnuActAttachtoIDParent.Enabled := False;
3032 popNoteListAttachtoIDParent.Enabled := mnuActAttachtoIDParent.Enabled;
3033 if (Selected.ImageIndex in [IMG_SINGLE, IMG_PARENT,
3034 IMG_IDNOTE_OPEN, IMG_IDNOTE_SHUT,
3035 IMG_IDPAR_ADDENDA_OPEN, IMG_IDPAR_ADDENDA_SHUT]) then
3036 mnuActAddIDEntry.Enabled := CanReceiveAttachment(PDocTreeObject(Selected.Data)^.DocID, WhyNot)
3037 else
3038 mnuActAddIDEntry.Enabled := False;
3039 popNoteListAddIDEntry.Enabled := mnuActAddIDEntry.Enabled
3040 end;
3041 RedrawSuspend(lvNotes.Handle);
3042 RedrawSuspend(memNote.Handle);
3043 popNoteListExpandSelected.Enabled := Selected.HasChildren;
3044 popNoteListCollapseSelected.Enabled := Selected.HasChildren;
3045 x := TORTreeNode(Selected).StringData;
3046 if (Selected.ImageIndex in [IMG_TOP_LEVEL, IMG_GROUP_OPEN, IMG_GROUP_SHUT]) then
3047 begin
3048 lvNotes.Visible := True;
3049 lvNotes.Items.Clear;
3050 lvNotes.Height := (2 * lvNotes.Parent.Height) div 5;
3051 with lblTitle do
3052 begin
3053 Caption := Trim(Selected.Text);
3054 if (FCurrentContext.SearchField <> '') and (FCurrentContext.Filtered) then
3055 begin
3056 case FCurrentContext.SearchField[1] of
3057 'T': MySearch := 'TITLE';
3058 'S': MySearch := 'SUBJECT';
3059 'B': MySearch := 'TITLE or SUBJECT';
3060 end;
3061 Caption := Caption + ' where ' + MySearch + ' contains "' + UpperCase(FCurrentContext.Keyword) + '"';
3062 end;
3063 lvNotes.Caption := Caption;
3064 end;
3065
3066 if Selected.ImageIndex = IMG_TOP_LEVEL then
3067 MyNodeID := Piece(TORTreeNode(Selected).StringData, U, 1)
3068 else if Selected.Parent.ImageIndex = IMG_TOP_LEVEL then
3069 MyNodeID := Piece(TORTreeNode(Selected.Parent).StringData, U, 1)
3070 else if Selected.Parent.Parent.ImageIndex = IMG_TOP_LEVEL then
3071 MyNodeID := Piece(TORTreeNode(Selected.Parent.Parent).StringData, U, 1);
3072
3073 uChanging := True;
3074 TraverseTree(tvNotes, lvNotes, Selected.GetFirstChild, MyNodeID, FCurrentContext);
3075 with lvNotes do
3076 begin
3077 for i := 0 to Columns.Count - 1 do
3078 Columns[i].ImageIndex := IMG_NONE;
3079 ColumnSortForward := FCurrentContext.ListAscending;
3080 if ColumnToSort = 5 then ColumnToSort := 0;
3081 if ColumnSortForward then
3082 Columns[ColumnToSort].ImageIndex := IMG_ASCENDING
3083 else
3084 Columns[ColumnToSort].ImageIndex := IMG_DESCENDING;
3085 if ColumnToSort = 0 then ColumnToSort := 5;
3086 AlphaSort;
3087 Columns[5].Width := 0;
3088 Columns[6].Width := 0;
3089 end;
3090 uChanging := False;
3091 with lvNotes do
3092 if Items.Count > 0 then
3093 begin
3094 Selected := Items[0];
3095 lvNotesSelectItem(Self, Selected, True);
3096 end
3097 else
3098 begin
3099 Selected := nil;
3100 lstNotes.ItemIndex := -1;
3101 memPCEShow.Clear;
3102 ShowPCEControls(False);
3103 end;
3104 pnlWrite.Visible := False;
3105 pnlRead.Visible := True;
3106 // uncommented next 4 lines in v17.5 (RV)
3107 //-----------------------------
3108 UpdateReminderFinish;
3109 ShowPCEControls(False);
3110 frmDrawers.DisplayDrawers(TRUE, [odTemplates], [odTemplates]); //FALSE);
3111 ShowPCEButtons(FALSE);
3112 //-----------------------------
3113 //memNote.Clear;
3114 end
3115 else if StrToIntDef(Piece(x, U, 1), 0) > 0 then
3116 begin
3117 memNote.Clear;
3118 lvNotes.Visible := False;
3119 lstNotes.SelectByID(Piece(x, U, 1));
3120 lstNotesClick(Self);
3121 SendMessage(memNote.Handle, WM_VSCROLL, SB_TOP, 0);
3122 end;
3123 SendMessage(tvNotes.Handle, WM_HSCROLL, SB_THUMBTRACK, 0);
3124 RedrawActivate(lvNotes.Handle);
3125 RedrawActivate(memNote.Handle);
3126 end;
3127end;
3128
3129procedure TfrmNotes.tvNotesCollapsed(Sender: TObject; Node: TTreeNode);
3130begin
3131 with Node do
3132 begin
3133 if (ImageIndex in [IMG_GROUP_OPEN, IMG_IDNOTE_OPEN, IMG_IDPAR_ADDENDA_OPEN]) then
3134 ImageIndex := ImageIndex - 1;
3135 if (SelectedIndex in [IMG_GROUP_OPEN, IMG_IDNOTE_OPEN, IMG_IDPAR_ADDENDA_OPEN]) then
3136 SelectedIndex := SelectedIndex - 1;
3137 end;
3138end;
3139
3140procedure TfrmNotes.tvNotesExpanded(Sender: TObject; Node: TTreeNode);
3141
3142 function SortByTitle(Node1, Node2: TTreeNode; Data: Longint): Integer; stdcall;
3143 begin
3144 { Within an ID parent node, sorts in ascending order by title
3145 BUT - addenda to parent document are always at the top of the sort, in date order}
3146 if (Copy(PDocTreeObject(Node1.Data)^.DocTitle, 1, 8) = 'Addendum') and
3147 (Copy(PDocTreeObject(Node2.Data)^.DocTitle, 1, 8) = 'Addendum') then
3148 begin
3149 Result := AnsiStrIComp(PChar(PDocTreeObject(Node1.Data)^.DocFMDate),
3150 PChar(PDocTreeObject(Node2.Data)^.DocFMDate));
3151 end
3152 else if Copy(PDocTreeObject(Node1.Data)^.DocTitle, 1, 8) = 'Addendum' then Result := -1
3153 else if Copy(PDocTreeObject(Node2.Data)^.DocTitle, 1, 8) = 'Addendum' then Result := 1
3154 else
3155 begin
3156 if Data = 0 then
3157 Result := AnsiStrIComp(PChar(PDocTreeObject(Node1.Data)^.DocTitle),
3158 PChar(PDocTreeObject(Node2.Data)^.DocTitle))
3159 else
3160 Result := -AnsiStrIComp(PChar(PDocTreeObject(Node1.Data)^.DocTitle),
3161 PChar(PDocTreeObject(Node2.Data)^.DocTitle));
3162 end
3163 end;
3164
3165 function SortByDate(Node1, Node2: TTreeNode; Data: Longint): Integer; stdcall;
3166 begin
3167 { Within an ID parent node, sorts in ascending order by document date
3168 BUT - addenda to parent document are always at the top of the sort, in date order}
3169 if (Copy(PDocTreeObject(Node1.Data)^.DocTitle, 1, 8) = 'Addendum') and
3170 (Copy(PDocTreeObject(Node2.Data)^.DocTitle, 1, 8) = 'Addendum') then
3171 begin
3172 Result := AnsiStrIComp(PChar(PDocTreeObject(Node1.Data)^.DocFMDate),
3173 PChar(PDocTreeObject(Node2.Data)^.DocFMDate));
3174 end
3175 else if Copy(PDocTreeObject(Node1.Data)^.DocTitle, 1, 8) = 'Addendum' then Result := -1
3176 else if Copy(PDocTreeObject(Node2.Data)^.DocTitle, 1, 8) = 'Addendum' then Result := 1
3177 else
3178 begin
3179 if Data = 0 then
3180 Result := AnsiStrIComp(PChar(PDocTreeObject(Node1.Data)^.DocFMDate),
3181 PChar(PDocTreeObject(Node2.Data)^.DocFMDate))
3182 else
3183 Result := -AnsiStrIComp(PChar(PDocTreeObject(Node1.Data)^.DocFMDate),
3184 PChar(PDocTreeObject(Node2.Data)^.DocFMDate));
3185 end;
3186 end;
3187
3188begin
3189 with Node do
3190 begin
3191 if Assigned(Data) then
3192 if (Pos('<', PDocTreeObject(Data)^.DocHasChildren) > 0) then
3193 begin
3194 if (PDocTreeObject(Node.Data)^.OrderByTitle) then
3195 CustomSort(@SortByTitle, 0)
3196 else
3197 CustomSort(@SortByDate, 0);
3198 end;
3199 if (ImageIndex in [IMG_GROUP_SHUT, IMG_IDNOTE_SHUT, IMG_IDPAR_ADDENDA_SHUT]) then
3200 ImageIndex := ImageIndex + 1;
3201 if (SelectedIndex in [IMG_GROUP_SHUT, IMG_IDNOTE_SHUT, IMG_IDPAR_ADDENDA_SHUT]) then
3202 SelectedIndex := SelectedIndex + 1;
3203 end;
3204end;
3205
3206procedure TfrmNotes.tvNotesClick(Sender: TObject);
3207begin
3208(* if tvNotes.Selected = nil then exit;
3209 if (tvNotes.Selected.ImageIndex in [IMG_TOP_LEVEL, IMG_GROUP_OPEN, IMG_GROUP_SHUT]) then
3210 begin
3211 uChanging := True;
3212 lvNotes.Selected := nil;
3213 uChanging := False;
3214 memNote.Clear;
3215 end;*)
3216end;
3217
3218procedure TfrmNotes.tvNotesDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
3219var
3220 AnItem: TORTreeNode;
3221begin
3222 Accept := False;
3223 if not uIDNotesActive then exit;
3224 AnItem := TORTreeNode(tvNotes.GetNodeAt(X, Y));
3225 if (AnItem = nil) or (AnItem.ImageIndex in [IMG_GROUP_OPEN, IMG_GROUP_SHUT, IMG_TOP_LEVEL]) then Exit;
3226 with tvNotes.Selected do
3227 if (ImageIndex in [IMG_SINGLE, IMG_PARENT, IMG_ID_CHILD, IMG_ID_CHILD_ADD]) then
3228 Accept := (AnItem.ImageIndex in [IMG_SINGLE, IMG_PARENT,
3229 IMG_IDNOTE_OPEN, IMG_IDNOTE_SHUT,
3230 IMG_IDPAR_ADDENDA_OPEN, IMG_IDPAR_ADDENDA_SHUT])
3231 else if (ImageIndex in [IMG_IDNOTE_OPEN, IMG_IDNOTE_SHUT, IMG_IDPAR_ADDENDA_OPEN, IMG_IDPAR_ADDENDA_SHUT]) then
3232 Accept := (AnItem.ImageIndex in [IMG_GROUP_OPEN, IMG_GROUP_SHUT, IMG_TOP_LEVEL])
3233 else if (ImageIndex in [IMG_ADDENDUM, IMG_GROUP_OPEN, IMG_GROUP_SHUT, IMG_TOP_LEVEL]) then
3234 Accept := False;
3235end;
3236
3237procedure TfrmNotes.tvNotesDragDrop(Sender, Source: TObject; X, Y: Integer);
3238var
3239 HT: THitTests;
3240 Saved: boolean;
3241 ADestNode: TORTreeNode;
3242begin
3243 if not uIDNotesActive then
3244 begin
3245 CancelDrag;
3246 exit;
3247 end;
3248 if tvNotes.Selected = nil then exit;
3249 if EditingIndex <> -1 then
3250 begin
3251 SaveCurrentNote(Saved);
3252 if not Saved then Exit;
3253 end;
3254 HT := tvNotes.GetHitTestInfoAt(X, Y);
3255 ADestNode := TORTreeNode(tvNotes.GetNodeAt(X, Y));
3256 DoAttachIDChild(TORTreeNode(tvNotes.Selected), ADestNode);
3257end;
3258
3259procedure TfrmNotes.tvNotesStartDrag(Sender: TObject; var DragObject: TDragObject);
3260const
3261 TX_CAP_NO_DRAG = 'Item cannot be moved';
3262 TX_NO_EDIT_DRAG = 'Items can not be dragged while a note is being edited.';
3263var
3264 WhyNot: string;
3265 //Saved: boolean;
3266begin
3267 if EditingIndex <> -1 then
3268 begin
3269 InfoBox(TX_NO_EDIT_DRAG, TX_CAP_NO_DRAG, MB_ICONERROR or MB_OK);
3270 CancelDrag;
3271 Exit;
3272 end;
3273 if (tvNotes.Selected.ImageIndex in [IMG_ADDENDUM, IMG_GROUP_OPEN, IMG_GROUP_SHUT, IMG_TOP_LEVEL]) or
3274 (not uIDNotesActive) or
3275 (lstNotes.ItemIEN = 0) then
3276 begin
3277 CancelDrag;
3278 Exit;
3279 end;
3280(* if EditingIndex <> -1 then
3281 begin
3282 SaveCurrentNote(Saved);
3283 if not Saved then Exit;
3284 end;*)
3285 if not CanBeAttached(PDocTreeObject(tvNotes.Selected.Data)^.DocID, WhyNot) then
3286 begin
3287 InfoBox(WhyNot, TX_CAP_NO_DRAG, MB_OK);
3288 CancelDrag;
3289 end;
3290end;
3291
3292//===================== Listview events =================================
3293
3294procedure TfrmNotes.lvNotesColumnClick(Sender: TObject; Column: TListColumn);
3295var
3296 i, ClickedColumn: Integer;
3297begin
3298 if Column.Index = 0 then ClickedColumn := 5 else ClickedColumn := Column.Index;
3299 if ClickedColumn = ColumnToSort then
3300 ColumnSortForward := not ColumnSortForward
3301 else
3302 ColumnSortForward := True;
3303 for i := 0 to lvNotes.Columns.Count - 1 do
3304 lvNotes.Columns[i].ImageIndex := IMG_NONE;
3305 if ColumnSortForward then lvNotes.Columns[Column.Index].ImageIndex := IMG_ASCENDING
3306 else lvNotes.Columns[Column.Index].ImageIndex := IMG_DESCENDING;
3307 ColumnToSort := ClickedColumn;
3308 case ColumnToSort of
3309 5: FCurrentContext.SortBy := 'R';
3310 1: FCurrentContext.SortBy := 'D';
3311 2: FCurrentContext.SortBy := 'S';
3312 3: FCurrentContext.SortBy := 'A';
3313 4: FCurrentContext.SortBy := 'L';
3314 else
3315 FCurrentContext.SortBy := 'R';
3316 end;
3317 FCurrentContext.ListAscending := ColumnSortForward;
3318 (Sender as TCustomListView).AlphaSort;
3319 //with lvNotes do if Selected <> nil then Scroll(0, Selected.Top - TopItem.Top);
3320end;
3321
3322procedure TfrmNotes.lvNotesCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
3323var
3324 ix: Integer;
3325begin
3326 if ColumnToSort = 0 then
3327 Compare := CompareText(Item1.Caption,Item2.Caption)
3328 else begin
3329 ix := ColumnToSort - 1;
3330 Compare := CompareText(Item1.SubItems[ix],Item2.SubItems[ix]);
3331 end;
3332 if not ColumnSortForward then Compare := -Compare;
3333end;
3334
3335procedure TfrmNotes.lvNotesSelectItem(Sender: TObject; Item: TListItem;
3336 Selected: Boolean);
3337begin
3338 if uChanging or (not Selected) then Exit;
3339 with lvNotes do
3340 begin
3341 StatusText('Retrieving selected progress note...');
3342 lstNotes.SelectByID(Item.SubItems[5]);
3343 lstNotesClick(Self);
3344 SendMessage(memNote.Handle, WM_VSCROLL, SB_TOP, 0);
3345 end;
3346end;
3347
3348procedure TfrmNotes.lvNotesResize(Sender: TObject);
3349begin
3350 inherited;
3351 with lvNotes do
3352 begin
3353 if not FCurrentContext.ShowSubject then
3354 begin
3355 Columns[1].Width := 2 * (Width div 5);
3356 Columns[2].Width := 0;
3357 end
3358 else
3359 begin
3360 Columns[1].Width := Width div 5;
3361 Columns[2].Width := Columns[1].Width;
3362 end;
3363 end;
3364end;
3365
3366procedure TfrmNotes.EnableDisableIDNotes;
3367begin
3368 uIDNotesActive := IDNotesInstalled;
3369 mnuActDetachFromIDParent.Visible := uIDNotesActive;
3370 popNoteListDetachFromIDParent.Visible := uIDNotesActive;
3371 mnuActAddIDEntry.Visible := uIDNotesActive;
3372 popNoteListAddIDEntry.Visible := uIDNotesActive;
3373 mnuActAttachtoIDParent.Visible := uIDNotesActive;
3374 popNoteListAttachtoIDParent.Visible := uIDNotesActive;
3375 if uIDNotesActive then
3376 tvNotes.DragMode := dmAutomatic
3377 else
3378 tvNotes.DragMode := dmManual;
3379end;
3380
3381procedure TfrmNotes.ShowPCEButtons(Editing: boolean);
3382begin
3383 if frmFrame.Timedout then Exit;
3384
3385 FEditingNotePCEObj := Editing;
3386 if Editing or AnytimeEncounters then
3387 begin
3388 cmdPCE.Visible := TRUE;
3389 if Editing then
3390 begin
3391 cmdPCE.Enabled := CanEditPCE(uPCEEdit);
3392 cmdNewNote.Visible := AnytimeEncounters;
3393 cmdNewNote.Enabled := FALSE;
3394 end
3395 else
3396 begin
3397 cmdPCE.Enabled := (GetAskPCE(0) <> apDisable);
3398 cmdNewNote.Visible := TRUE;
3399 cmdNewNote.Enabled := (FStarting = False); //TRUE;
3400 end;
3401 if cmdNewNote.Visible then
3402 cmdPCE.Top := cmdNewNote.Top-cmdPCE.Height;
3403 end
3404 else
3405 begin
3406 cmdPCE.Enabled := FALSE;
3407 cmdPCE.Visible := FALSE;
3408 cmdNewNote.Visible := TRUE;
3409 cmdNewNote.Enabled := (FStarting = False); //TRUE;
3410 end;
3411 if cmdPCE.Visible then
3412 lblSpace1.Top := cmdPCE.Top - lblSpace1.Height
3413 else
3414 lblSpace1.Top := cmdNewNote.Top - lblSpace1.Height;
3415 popNoteMemoEncounter.Enabled := cmdPCE.Enabled;
3416 popNoteMemoEncounter.Visible := cmdPCE.Visible;
3417end;
3418
3419procedure TfrmNotes.mnuIconLegendClick(Sender: TObject);
3420begin
3421 inherited;
3422 ShowIconLegend(ilNotes);
3423end;
3424
3425procedure TfrmNotes.mnuActAttachtoIDParentClick(Sender: TObject);
3426var
3427 AChildNode: TORTreeNode;
3428 AParentID: string;
3429 SavedDocID: string;
3430 Saved: boolean;
3431begin
3432 inherited;
3433 if not uIDNotesActive then exit;
3434 if lstNotes.ItemIEN = 0 then exit;
3435 SavedDocID := lstNotes.ItemID;
3436 if EditingIndex <> -1 then
3437 begin
3438 SaveCurrentNote(Saved);
3439 if not Saved then Exit;
3440 LoadNotes;
3441 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
3442 end;
3443 if tvNotes.Selected = nil then exit;
3444 AChildNode := TORTreeNode(tvNotes.Selected);
3445 AParentID := SelectParentNodeFromList(tvNotes);
3446 if AParentID = '' then exit;
3447 with tvNotes do Selected := FindPieceNode(AParentID, 1, U, Items.GetFirstNode);
3448 DoAttachIDChild(AChildNode, TORTreeNode(tvNotes.Selected));
3449end;
3450
3451procedure TfrmNotes.DoAttachIDChild(AChild, AParent: TORTreeNode);
3452const
3453 TX_ATTACH_CNF = 'Confirm Attachment';
3454 TX_ATTACH_FAILURE = 'Attachment failed';
3455var
3456 ErrMsg, WhyNot: string;
3457 SavedDocID: string;
3458begin
3459 if (AChild = nil) or (AParent = nil) then exit;
3460 ErrMsg := '';
3461 if not CanBeAttached(PDocTreeObject(AChild.Data)^.DocID, WhyNot) then
3462 ErrMsg := ErrMsg + WhyNot + CRLF + CRLF;
3463 if not CanReceiveAttachment(PDocTreeObject(AParent.Data)^.DocID, WhyNot) then
3464 ErrMsg := ErrMsg + WhyNot;
3465 if ErrMsg <> '' then
3466 begin
3467 InfoBox(ErrMsg, TX_ATTACH_FAILURE, MB_OK);
3468 Exit;
3469 end
3470 else
3471 begin
3472 WhyNot := '';
3473 if (InfoBox('ATTACH: ' + AChild.Text + CRLF + CRLF +
3474 ' TO: ' + AParent.Text + CRLF + CRLF +
3475 'Are you sure?', TX_ATTACH_CNF, MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) <> IDYES)
3476 then Exit;
3477 SavedDocID := PDocTreeObject(AParent.Data)^.DocID;
3478 end;
3479 if AChild.ImageIndex in [IMG_ID_CHILD, IMG_ID_CHILD_ADD] then
3480 begin
3481 if DetachEntryFromParent(PDocTreeObject(AChild.Data)^.DocID, WhyNot) then
3482 begin
3483 if AttachEntryToParent(PDocTreeObject(AChild.Data)^.DocID, PDocTreeObject(AParent.Data)^.DocID, WhyNot) then
3484 begin
3485 LoadNotes;
3486 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
3487 if tvNotes.Selected <> nil then tvNotes.Selected.Expand(False);
3488 end
3489 else
3490 InfoBox(WhyNot, TX_ATTACH_FAILURE, MB_OK);
3491 end
3492 else
3493 begin
3494 WhyNot := StringReplace(WhyNot, 'ATTACH', 'DETACH', [rfIgnoreCase]);
3495 WhyNot := StringReplace(WhyNot, 'to an ID', 'from an ID', [rfIgnoreCase]);
3496 InfoBox(WhyNot, TX_DETACH_FAILURE, MB_OK);
3497 Exit;
3498 end;
3499 end
3500 else
3501 begin
3502 if AttachEntryToParent(PDocTreeObject(AChild.Data)^.DocID, PDocTreeObject(AParent.Data)^.DocID, WhyNot) then
3503 begin
3504 LoadNotes;
3505 with tvNotes do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
3506 if tvNotes.Selected <> nil then tvNotes.Selected.Expand(False);
3507 end
3508 else
3509 InfoBox(WhyNot, TX_ATTACH_FAILURE, MB_OK);
3510 end;
3511end;
3512
3513function TfrmNotes.SetNoteTreeLabel(AContext: TTIUContext): string;
3514var
3515 x: string;
3516
3517 function SetDateRangeText(AContext: TTIUContext): string;
3518 var
3519 x1: string;
3520 begin
3521 with AContext do
3522 if BeginDate <> '' then
3523 begin
3524 x1 := ' from ' + UpperCase(BeginDate);
3525 if EndDate <> '' then x1 := x1 + ' to ' + UpperCase(EndDate)
3526 else x1 := x1 + ' to TODAY';
3527 end;
3528 Result := x1;
3529 end;
3530
3531begin
3532 with AContext do
3533 begin
3534 if MaxDocs > 0 then x := 'Last ' + IntToStr(MaxDocs) + ' ' else x := 'All ';
3535 case StrToIntDef(Status, 0) of
3536 NC_ALL : x := x + 'Signed Notes';
3537 NC_UNSIGNED : begin
3538 x := x + 'Unsigned Notes for ';
3539 if Author > 0 then x := x + ExternalName(Author, 200)
3540 else x := x + User.Name;
3541 x := x + SetDateRangeText(AContext);
3542 end;
3543 NC_UNCOSIGNED : begin
3544 x := x + 'Uncosigned Notes for ';
3545 if Author > 0 then x := x + ExternalName(Author, 200)
3546 else x := x + User.Name;
3547 x := x + SetDateRangeText(AContext);
3548 end;
3549 NC_BY_AUTHOR : x := x + 'Signed Notes for ' + ExternalName(Author, 200) + SetDateRangeText(AContext);
3550 NC_BY_DATE : x := x + 'Signed Notes ' + SetDateRangeText(AContext);
3551 else
3552 x := 'Custom List';
3553 end;
3554 end;
3555 Result := x;
3556end;
3557
3558procedure TfrmNotes.memNewNoteKeyDown(Sender: TObject; var Key: Word;
3559 Shift: TShiftState);
3560begin
3561 inherited;
3562 FNavigatingTab := (Key = VK_TAB) and ([ssShift,ssCtrl] * Shift <> []);
3563 if FNavigatingTab then
3564 Key := 0;
3565end;
3566
3567procedure TfrmNotes.UpdateNoteAuthor(DocInfo: string);
3568const
3569 TX_INVALID_AUTHOR1 = 'The author returned by the template (';
3570 TX_INVALID_AUTHOR2 = ') is not valid.' + #13#10 + 'The note''s author will remain as ';
3571 TC_INVALID_AUTHOR = 'Invalid Author';
3572 TX_COSIGNER_REQD = ' requires a cosigner for this note.';
3573 TC_COSIGNER_REQD = 'Cosigner Required';
3574var
3575 NewAuth, NewAuthName, AuthNameCheck, x: string;
3576 ADummySender: TObject;
3577begin
3578 if DocInfo = '' then Exit;
3579 NewAuth := GetXMLParamReturnValueTIU(DocInfo, 'AUTHOR_IEN');
3580 if NewAuth = '' then Exit;
3581 AuthNameCheck := ExternalName(StrToInt64Def(NewAuth, 0), 200);
3582 if AuthNameCheck = '' then
3583 begin
3584 NewAuthName := GetXMLParamReturnValueTIU(DocInfo, 'AUTHOR_NAME');
3585 InfoBox(TX_INVALID_AUTHOR1 + UpperCase(NewAuthName) + TX_INVALID_AUTHOR2 + UpperCase(FEditNote.AuthorName),
3586 TC_INVALID_AUTHOR, MB_OK and MB_ICONERROR);
3587 Exit;
3588 end;
3589 with FEditNote do if StrToInt64Def(NewAuth, 0) <> Author then
3590 begin
3591 Author := StrToInt64Def(NewAuth, 0);
3592 AuthorName := AuthNameCheck;
3593 x := lstNotes.Items[EditingIndex];
3594 SetPiece(x, U, 5, NewAuth + ';' + AuthNameCheck);
3595 lstNotes.Items[EditingIndex] := x;
3596 if AskCosignerForTitle(Title, Author, DateTime) then
3597 begin
3598 InfoBox(UpperCase(AuthNameCheck) + TX_COSIGNER_REQD, TC_COSIGNER_REQD, MB_OK);
3599 //Cosigner := 0; CosignerName := ''; // not sure about this yet
3600 ADummySender := TObject.Create;
3601 try
3602 cmdChangeClick(ADummySender);
3603 finally
3604 FreeAndNil(ADummySender);
3605 end;
3606 end
3607 else cmdChangeClick(Self);
3608 end;
3609end;
3610
3611procedure TfrmNotes.sptHorzCanResize(Sender: TObject; var NewSize: Integer;
3612 var Accept: Boolean);
3613begin
3614 inherited;
3615 if pnlWrite.Visible then
3616 if NewSize > frmNotes.ClientWidth - memNewNote.Constraints.MinWidth - sptHorz.Width then
3617 NewSize := frmNotes.ClientWidth - memNewNote.Constraints.MinWidth - sptHorz.Width;
3618end;
3619
3620procedure TfrmNotes.popNoteMemoInsTemplateClick(Sender: TObject);
3621begin
3622 frmDrawers.mnuInsertTemplateClick(Sender);
3623end;
3624
3625procedure TfrmNotes.popNoteMemoPreviewClick(Sender: TObject);
3626begin
3627 frmDrawers.mnuPreviewTemplateClick(Sender);
3628end;
3629
3630procedure TfrmNotes.tvNotesAddition(Sender: TObject; Node: TTreeNode);
3631begin
3632 inherited;
3633 TAccessibleTreeNode.WrapControl(Node as TORTreeNode);
3634end;
3635
3636procedure TfrmNotes.tvNotesDeletion(Sender: TObject; Node: TTreeNode);
3637begin
3638 TAccessibleTreeNode.UnwrapControl(Node as TORTreeNode);
3639 inherited;
3640end;
3641
3642{Tab Order tricks. Need to change
3643 tvNotes
3644
3645 frmDrawers.pnlTemplateButton
3646 frmDrawers.pnlEncounterButton
3647 cmdNewNote
3648 cmdPCE
3649
3650 lvNotes
3651 memNote
3652
3653to
3654 tvNotes
3655
3656 lvNotes
3657 memNote
3658
3659 frmDrawers.pnlTemplateButton
3660 frmDrawers.pnlEncounterButton
3661 cmdNewNote
3662 cmdPCE
3663}
3664
3665procedure TfrmNotes.tvNotesExit(Sender: TObject);
3666begin
3667 if IncSecond(FMousing,1) < Now then
3668 begin
3669 if (Screen.ActiveControl = frmDrawers.pnlTemplatesButton) or
3670 (Screen.ActiveControl = frmDrawers.pnlEncounterButton) or
3671 (Screen.ActiveControl = cmdNewNote) or
3672 (Screen.ActiveControl = cmdPCE) then
3673 FindNextControl( cmdPCE, True, True, False).SetFocus;
3674 end;
3675 FMousing := 0;
3676end;
3677
3678procedure TfrmNotes.pnlReadExit(Sender: TObject);
3679begin
3680 inherited;
3681 if IncSecond(FMousing,1) < Now then
3682 begin
3683 if (Screen.ActiveControl = frmFrame.pnlPatient) then
3684 FindNextControl( tvNotes, True, True, False).SetFocus
3685 else
3686 if (Screen.ActiveControl = frmDrawers.pnlTemplatesButton) or
3687 (Screen.ActiveControl = frmDrawers.pnlEncounterButton) or
3688 (Screen.ActiveControl = cmdNewNote) or
3689 (Screen.ActiveControl = cmdPCE) then
3690 FindNextControl( frmDrawers.pnlTemplatesButton, False, True, False).SetFocus;
3691 end;
3692 FMousing := 0;
3693end;
3694
3695procedure TfrmNotes.cmdNewNoteExit(Sender: TObject);
3696begin
3697 inherited;
3698 if IncSecond(FMousing,1) < Now then
3699 begin
3700 if (Screen.ActiveControl = lvNotes) or
3701 (Screen.ActiveControl = memNote) then
3702 frmFrame.pnlPatient.SetFocus
3703 else
3704 if (Screen.ActiveControl = tvNotes) then
3705 FindNextControl( frmFrame.pnlPatient, False, True, False).SetFocus;
3706 end;
3707 FMousing := 0;
3708end;
3709
3710procedure TfrmNotes.frmFramePnlPatientExit(Sender: TObject);
3711begin
3712 FOldFramePnlPatientExit(Sender);
3713 if IncSecond(FMousing,1) < Now then
3714 begin
3715 if (Screen.ActiveControl = lvNotes) or
3716 (Screen.ActiveControl = memNote) then
3717 FindNextControl( lvNotes, False, True, False).SetFocus;
3718 end;
3719 FMousing := 0;
3720end;
3721
3722procedure TfrmNotes.FormHide(Sender: TObject);
3723begin
3724 inherited;
3725 frmFrame.pnlPatient.OnExit := FOldFramePnlPatientExit;
3726 frmDrawers.pnlTemplatesButton.OnExit := FOldDrawerPnlTemplatesButtonExit;
3727 frmDrawers.pnlEncounterButton.OnExit := FOldDrawerPnlEncounterButtonExit;
3728 frmDrawers.edtSearch.OnExit := FOldDrawerEdtSearchExit;
3729end;
3730
3731procedure TfrmNotes.FormShow(Sender: TObject);
3732begin
3733 inherited;
3734 FOldFramePnlPatientExit := frmFrame.pnlPatient.OnExit;
3735 frmFrame.pnlPatient.OnExit := frmFramePnlPatientExit;
3736 FOldDrawerPnlTemplatesButtonExit := frmDrawers.pnlTemplatesButton.OnExit;
3737 frmDrawers.pnlTemplatesButton.OnExit := frmDrawerPnlTemplatesButtonExit;
3738 FOldDrawerPnlEncounterButtonExit := frmDrawers.pnlEncounterButton.OnExit;
3739 frmDrawers.pnlEncounterButton.OnExit := frmDrawerPnlEncounterButtonExit;
3740 FOldDrawerEdtSearchExit := frmDrawers.edtSearch.OnExit;
3741 frmDrawers.edtSearch.OnExit := frmDrawerEdtSearchExit;
3742end;
3743
3744procedure TfrmNotes.frmDrawerEdtSearchExit(Sender: TObject);
3745begin
3746 FOldDrawerEdtSearchExit(Sender);
3747 cmdNewNoteExit(Sender);
3748end;
3749
3750procedure TfrmNotes.frmDrawerPnlTemplatesButtonExit(Sender: TObject);
3751begin
3752 FOldDrawerPnlTemplatesButtonExit(Sender);
3753 if Boolean(Hi(GetKeyState(VK_TAB))) and (memNewNote.CanFocus) and
3754 Boolean(Hi(GetKeyState(VK_SHIFT))) then
3755 memNewNote.SetFocus
3756 else
3757 cmdNewNoteExit(Sender);
3758end;
3759
3760procedure TfrmNotes.frmDrawerPnlEncounterButtonExit(Sender: TObject);
3761begin
3762 FOldDrawerPnlEncounterButtonExit(Sender);
3763 cmdNewNoteExit(Sender);
3764end;
3765
3766procedure TfrmNotes.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
3767 Y: Integer);
3768begin
3769 inherited;
3770 FMousing := Now;
3771end;
3772
3773procedure TfrmNotes.memNewNoteKeyPress(Sender: TObject; var Key: Char);
3774begin
3775 inherited;
3776 if FNavigatingTab then
3777 Key := #0; //Disable shift-tab processinend;
3778end;
3779
3780procedure TfrmNotes.memNewNoteKeyUp(Sender: TObject; var Key: Word;
3781 Shift: TShiftState);
3782begin
3783 inherited;
3784 if FNavigatingTab then
3785 begin
3786 if ssShift in Shift then
3787 FindNextControl(Sender as TWinControl, False, True, False).SetFocus //previous control
3788 else if ssCtrl in Shift then
3789 if frmDrawers.pnlTemplatesButton.CanFocus then
3790 frmDrawers.pnlTemplatesButton.SetFocus
3791 else
3792 FindNextControl(Sender as TWinControl, True, True, False).SetFocus; //next control
3793 FNavigatingTab := False;
3794 end;
3795 if (key = VK_ESCAPE) then begin
3796 FindNextControl(Sender as TWinControl, False, True, False).SetFocus; //previous control
3797 key := 0;
3798 end;
3799end;
3800
3801procedure TfrmNotes.memPCEShowExit(Sender: TObject);
3802begin
3803 inherited;
3804 //Fix the Tab Order Make Drawers Buttons Accessible
3805 if Boolean(Hi(GetKeyState(VK_TAB))) then
3806 if Boolean(Hi(GetKeyState(VK_SHIFT))) then
3807 cmdPCE.SetFocus
3808 else
3809 frmFrame.pnlPatient.SetFocus;
3810end;
3811
3812procedure TfrmNotes.cmdChangeExit(Sender: TObject);
3813begin
3814 inherited;
3815 //Fix the Tab Order Make Drawers Buttons Accessible
3816 if Boolean(Hi(GetKeyState(VK_TAB))) and
3817 Boolean(Hi(GetKeyState(VK_SHIFT))) then
3818 tvNotes.SetFocus;
3819end;
3820
3821procedure TfrmNotes.cmdPCEExit(Sender: TObject);
3822begin
3823 inherited;
3824 //Fix the Tab Order Make Drawers Buttons Accessible
3825 if Boolean(Hi(GetKeyState(VK_TAB))) and
3826 Not Boolean(Hi(GetKeyState(VK_SHIFT))) then
3827 if memPCEShow.Visible then //CQ7120
3828 memPCEShow.SetFocus; //CQ7120
3829end;
3830
3831procedure TfrmNotes.ViewInfo(Sender: TObject);
3832begin
3833 inherited;
3834 frmFrame.ViewInfo(Sender);
3835end;
3836
3837procedure TfrmNotes.mnuViewInformationClick(Sender: TObject);
3838begin
3839 inherited;
3840 mnuViewDemo.Enabled := frmFrame.pnlPatient.Enabled;
3841 mnuViewVisits.Enabled := frmFrame.pnlVisit.Enabled;
3842 mnuViewPrimaryCare.Enabled := frmFrame.pnlPrimaryCare.Enabled;
3843 mnuViewMyHealtheVet.Enabled := not (Copy(frmFrame.laMHV.Hint, 1, 2) = 'No');
3844 mnuInsurance.Enabled := not (Copy(frmFrame.laVAA2.Hint, 1, 2) = 'No');
3845 mnuViewFlags.Enabled := frmFrame.lblFlag.Enabled;
3846 mnuViewRemoteData.Enabled := frmFrame.lblCirn.Enabled;
3847 mnuViewReminders.Enabled := frmFrame.pnlReminders.Enabled;
3848 mnuViewPostings.Enabled := frmFrame.pnlPostings.Enabled;
3849end;
3850
3851initialization
3852 uPCEEdit := TPCEData.Create;
3853 uPCEShow := TPCEData.Create;
3854
3855finalization
3856 if (uPCEEdit <> nil) then uPCEEdit.Free; //CQ7012 Added test for nil
3857 if (uPCEShow <> nil) then uPCEShow.Free; //CQ7012 Added test for nil
3858
3859end.
3860
Note: See TracBrowser for help on using the repository browser.