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

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

Updating the working copy to CPRS version 28

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