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

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

update

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