source: cprs/branches/tmg-cprs/CPRS-Chart/fNotes.pas@ 466

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

Initial upload of TMG-CPRS 1.0.26.69

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