source: cprs/trunk/CPRS-Chart/fNotes.pas@ 1298

Last change on this file since 1298 was 830, checked in by Kevin Toppenberg, 14 years ago

Upgrading to version 27

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