source: cprs/branches/tmg-cprs/CPRS-Chart/fSurgery.pas@ 732

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

Initial upload of TMG-CPRS 1.0.26.69

File size: 107.2 KB
Line 
1//kt -- Modified with SourceScanner on 8/7/2007
2unit fSurgery;
3
4interface
5
6uses
7 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
8 fHSplit, StdCtrls, ExtCtrls, Menus, ComCtrls, ORCtrls, ORFn, uConst, ORDtTm,
9 uPCE, ORClasses, fDrawers, ImgList, fSurgeryView, rSurgery, uSurgery,
10 uCaseTree, uTIU, DKLang;
11
12type
13 TfrmSurgery = class(TfrmHSplit)
14 mnuNotes: TMainMenu;
15 mnuView: TMenuItem;
16 mnuViewChart: TMenuItem;
17 mnuChartReports: TMenuItem;
18 mnuChartLabs: TMenuItem;
19 mnuChartDCSumm: TMenuItem;
20 mnuChartCslts: TMenuItem;
21 mnuChartNotes: TMenuItem;
22 mnuChartOrders: TMenuItem;
23 mnuChartMeds: TMenuItem;
24 mnuChartProbs: TMenuItem;
25 mnuChartCover: TMenuItem;
26 Z1: TMenuItem;
27 mnuViewDetail: TMenuItem;
28 mnuAct: TMenuItem;
29 mnuActNew: TMenuItem;
30 Z2: TMenuItem;
31 mnuActSave: TMenuItem;
32 mnuActDelete: TMenuItem;
33 mnuActEdit: TMenuItem;
34 mnuActSign: TMenuItem;
35 mnuActAddend: TMenuItem;
36 lblCases: TOROffsetLabel;
37 pnlRead: TPanel;
38 lblTitle: TOROffsetLabel;
39 memSurgery: TRichEdit;
40 pnlWrite: TPanel;
41 memNewNote: TRichEdit;
42 Z3: TMenuItem;
43 mnuViewAll: TMenuItem;
44 mnuViewBySurgeon: TMenuItem;
45 mnuViewByDate: TMenuItem;
46 mnuViewUncosigned: TMenuItem;
47 mnuViewUnsigned: TMenuItem;
48 mnuActSignList: TMenuItem;
49 cmdNewNote: TORAlignButton;
50 lblSpace1: TLabel;
51 popNoteMemo: TPopupMenu;
52 popNoteMemoCut: TMenuItem;
53 popNoteMemoCopy: TMenuItem;
54 popNoteMemoPaste: TMenuItem;
55 Z10: TMenuItem;
56 popNoteMemoSignList: TMenuItem;
57 popNoteMemoDelete: TMenuItem;
58 popNoteMemoEdit: TMenuItem;
59 popNoteMemoSave: TMenuItem;
60 popNoteMemoSign: TMenuItem;
61 popNoteList: TPopupMenu;
62 popNoteListAll: TMenuItem;
63 popNoteListByDate: TMenuItem;
64 mnuActIdentifyAddlSigners: TMenuItem;
65 popNoteMemoAddlSign: TMenuItem;
66 Z11: TMenuItem;
67 popNoteMemoSpell: TMenuItem;
68 popNoteMemoGrammar: TMenuItem;
69 mnuViewCustom: TMenuItem;
70 N1: TMenuItem;
71 mnuViewSaveAsDefault: TMenuItem;
72 ReturntoDefault1: TMenuItem;
73 pnlDrawers: TPanel;
74 splDrawers: TSplitter;
75 popNoteMemoTemplate: TMenuItem;
76 Z12: TMenuItem;
77 mnuOptions: TMenuItem;
78 mnuEditTemplates: TMenuItem;
79 mnuNewTemplate: TMenuItem;
80 N2: TMenuItem;
81 mnuEditSharedTemplates: TMenuItem;
82 mnuNewSharedTemplate: TMenuItem;
83 popNoteMemoAddend: TMenuItem;
84 pnlFields: TPanel;
85 lblNewTitle: TLabel;
86 lblRefDate: TLabel;
87 lblAuthor: TLabel;
88 lblVisit: TLabel;
89 lblCosigner: TLabel;
90 cmdChange: TButton;
91 lblSubject: TLabel;
92 txtSubject: TCaptionEdit;
93 timAutoSave: TTimer;
94 popNoteMemoPaste2: TMenuItem;
95 popNoteMemoReformat: TMenuItem;
96 Z4: TMenuItem;
97 mnuActChange: TMenuItem;
98 mnuActLoadBoiler: TMenuItem;
99 bvlNewTitle: TBevel;
100 popNoteMemoSaveContinue: TMenuItem;
101 N3: TMenuItem;
102 mnuEditDialgFields: TMenuItem;
103 N4: TMenuItem;
104 popNoteListExpandSelected: TMenuItem;
105 popNoteListExpandAll: TMenuItem;
106 popNoteListCollapseSelected: TMenuItem;
107 popNoteListCollapseAll: TMenuItem;
108 popNoteListCustom: TMenuItem;
109 mnuActDetachFromIDParent: TMenuItem;
110 N5: TMenuItem;
111 popNoteListDetachFromIDParent: TMenuItem;
112 popNoteListAddIDEntry: TMenuItem;
113 mnuActAddIDEntry: TMenuItem;
114 mnuIconLegend: TMenuItem;
115 N6: TMenuItem;
116 popNoteMemoFind: TMenuItem;
117 dlgFindText: TFindDialog;
118 dlgReplaceText: TReplaceDialog;
119 popNoteMemoReplace: TMenuItem;
120 N7: TMenuItem;
121 tvSurgery: TORTreeView;
122 mnuChartSurgery: TMenuItem;
123 lstNotes: TORListBox;
124 sptVert: TSplitter;
125 memPCEShow: TRichEdit;
126 cmdPCE: TORAlignButton;
127 popNoteListBySurgeon: TMenuItem;
128 popNoteListUnsigned: TMenuItem;
129 popNoteListUncosigned: TMenuItem;
130 N8: TMenuItem;
131 popNoteMemoPreview: TMenuItem;
132 popNoteMemoInsTemplate: TMenuItem;
133 popNoteMemoEncounter: TMenuItem;
134 mnuViewInformation: TMenuItem;
135 mnuViewDemo: TMenuItem;
136 mnuViewVisits: TMenuItem;
137 mnuViewPrimaryCare: TMenuItem;
138 mnuViewMyHealtheVet: TMenuItem;
139 mnuInsurance: TMenuItem;
140 mnuViewFlags: TMenuItem;
141 mnuViewReminders: TMenuItem;
142 mnuViewRemoteData: TMenuItem;
143 mnuViewPostings: TMenuItem;
144 procedure mnuChartTabClick(Sender: TObject);
145 procedure pnlRightResize(Sender: TObject);
146 procedure cmdNewNoteClick(Sender: TObject);
147 procedure mnuActNewClick(Sender: TObject);
148 procedure mnuActSaveClick(Sender: TObject);
149 procedure mnuViewClick(Sender: TObject);
150 procedure mnuActAddendClick(Sender: TObject);
151 procedure mnuActSignListClick(Sender: TObject);
152 procedure mnuActDeleteClick(Sender: TObject);
153 procedure mnuActEditClick(Sender: TObject);
154 procedure mnuActSignClick(Sender: TObject);
155 procedure cmdPCEClick(Sender: TObject);
156 procedure popNoteMemoCutClick(Sender: TObject);
157 procedure popNoteMemoCopyClick(Sender: TObject);
158 procedure popNoteMemoPasteClick(Sender: TObject);
159 procedure popNoteMemoPopup(Sender: TObject);
160 procedure pnlWriteResize(Sender: TObject);
161 procedure FormCreate(Sender: TObject);
162 procedure mnuViewDetailClick(Sender: TObject);
163 procedure FormClose(Sender: TObject; var Action: TCloseAction);
164 procedure mnuActIdentifyAddlSignersClick(Sender: TObject);
165 procedure popNoteMemoAddlSignClick(Sender: TObject);
166 procedure popNoteMemoSpellClick(Sender: TObject);
167 procedure popNoteMemoGrammarClick(Sender: TObject);
168 procedure mnuViewSaveAsDefaultClick(Sender: TObject);
169 procedure mnuViewReturntoDefaultClick(Sender: TObject);
170 procedure popNoteMemoTemplateClick(Sender: TObject);
171 procedure mnuEditTemplatesClick(Sender: TObject);
172 procedure mnuNewTemplateClick(Sender: TObject);
173 procedure mnuEditSharedTemplatesClick(Sender: TObject);
174 procedure mnuNewSharedTemplateClick(Sender: TObject);
175 procedure mnuOptionsClick(Sender: TObject);
176 procedure FormDestroy(Sender: TObject);
177 procedure cmdChangeClick(Sender: TObject);
178 procedure pnlFieldsResize(Sender: TObject);
179 procedure timAutoSaveTimer(Sender: TObject);
180 procedure memNewNoteChange(Sender: TObject);
181 procedure popNoteMemoReformatClick(Sender: TObject);
182 procedure mnuActChangeClick(Sender: TObject);
183 procedure mnuActLoadBoilerClick(Sender: TObject);
184 procedure popNoteMemoSaveContinueClick(Sender: TObject);
185 procedure mnuEditDialgFieldsClick(Sender: TObject);
186 procedure popNoteListExpandAllClick(Sender: TObject);
187 procedure popNoteListCollapseAllClick(Sender: TObject);
188 procedure popNoteListExpandSelectedClick(Sender: TObject);
189 procedure popNoteListCollapseSelectedClick(Sender: TObject);
190 procedure popNoteListPopup(Sender: TObject);
191 procedure mnuIconLegendClick(Sender: TObject);
192 procedure popNoteMemoFindClick(Sender: TObject);
193 procedure dlgFindTextFind(Sender: TObject);
194 procedure popNoteMemoReplaceClick(Sender: TObject);
195 procedure dlgReplaceTextReplace(Sender: TObject);
196 procedure dlgReplaceTextFind(Sender: TObject);
197 procedure tvSurgeryClick(Sender: TObject);
198 procedure tvSurgeryChange(Sender: TObject; Node: TTreeNode);
199 procedure tvSurgeryExpanded(Sender: TObject; Node: TTreeNode);
200 procedure tvSurgeryCollapsed(Sender: TObject; Node: TTreeNode);
201 procedure lstNotesClick(Sender: TObject);
202 procedure memNewNoteKeyDown(Sender: TObject; var Key: Word;
203 Shift: TShiftState);
204 procedure sptHorzCanResize(Sender: TObject; var NewSize: Integer; var Accept: Boolean);
205 procedure popNoteMemoPreviewClick(Sender: TObject);
206 procedure popNoteMemoInsTemplateClick(Sender: TObject);
207 procedure tvSurgeryAddition(Sender: TObject; Node: TTreeNode);
208 procedure tvSurgeryDeletion(Sender: TObject; Node: TTreeNode);
209 procedure ViewInfo(Sender: TObject);
210 procedure mnuViewInformationClick(Sender: TObject);
211 private
212 FEditingIndex: Integer; // index of note being currently edited
213 FCurrentContext: TSurgCaseContext;
214 FDefaultContext: TSurgCaseContext;
215 FImageFlag: TBitmap;
216 FCaseList: TStringList;
217 FChanged: Boolean; // true if any text has changed in the note
218 FEditCtrl: TCustomEdit;
219 FSilent: Boolean;
220 FEditNote: TEditNoteRec;
221 FVerifyNoteTitle: Integer;
222 FConfirmed: boolean;
223 FLastNoteID: string;
224 FEditingNotePCEObj: boolean;
225 FDeleted: boolean;
226 procedure ClearEditControls;
227 procedure DoAutoSave(Suppress: integer = 1);
228 function GetTitleText(AnIndex: Integer): string;
229 procedure InsertAddendum;
230 procedure InsertNewNote(IsIDChild: boolean; AnIDParent: integer);
231 function LacksRequiredForCreate: Boolean;
232 procedure LoadForEdit;
233 procedure LoadSurgeryCases;
234 procedure UpdateTreeView(DocList: TStringList; Tree: TORTreeView);
235 procedure SetViewContext(AContext: TSurgCaseContext);
236 function GetDrawers: TFrmDrawers;
237 procedure SetEditingIndex(const Value: Integer);
238 property EditingIndex: Integer read FEditingIndex write SetEditingIndex;
239 procedure ProcessNotifications;
240 function SetSurgTreeLabel(AContext: TSurgCaseContext): string;
241 procedure RemovePCEFromChanges(IEN: Int64; AVisitStr: string = '');
242 procedure SaveEditedNote(var Saved: Boolean);
243 procedure SaveCurrentNote(var Saved: Boolean);
244 procedure SetSubjectVisible(ShouldShow: Boolean);
245 procedure ShowPCEControls(ShouldShow: Boolean);
246 function StartNewEdit(NewNoteType: integer): Boolean;
247 //function CanFinishReminder: boolean;
248 procedure DisplayPCE;
249 function VerifyNoteTitle: Boolean;
250 procedure ShowPCEButtons(Editing: boolean);
251 procedure EnableDisableMenus(IsTIUDocument: boolean);
252 public
253 function AllowContextChange(var WhyNot: string): Boolean; override;
254 procedure ClearPtData; override;
255 procedure DisplayPage; override;
256 procedure RequestPrint; override;
257 procedure SetFontSize(NewFontSize: Integer); override;
258 procedure SaveSignItem(const ItemID, ESCode: string);
259 procedure AssignRemForm;
260 published
261 property Drawers: TFrmDrawers read GetDrawers; // Keep Drawers published
262 end;
263
264var
265 frmSurgery: TfrmSurgery;
266 uSurgeryContext: TSurgCaseContext;
267
268implementation
269
270{$R *.DFM}
271
272uses fFrame, fVisit, fEncnt, rCore, uCore, fNoteBA, fNoteBD, fSignItem, fEncounterFrame,
273 rPCE, Clipbrd, fNoteCslt, fNotePrt, rVitals, fAddlSigners, fNoteDR, fConsults, uSpell,
274 fTIUView, fTemplateEditor, uReminders, fReminderDialog, uOrders, rConsults, fReminderTree,
275 fNoteProps, fNotesBP, fTemplateFieldEditor, uTemplates, dShared, rTemplates,
276 FIconLegend, fPCEEdit, rTIU, fRptBox, uAccessibleTreeView,
277 uAccessibleTreeNode, fTemplateDialog;
278
279const
280 CT_SURGERY = 11; // chart tab - surgery
281
282 NT_NEW_NOTE = -10; // Holder IEN for a new note
283 NT_ADDENDUM = -20; // Holder IEN for a new addendum
284
285 NT_ACT_NEW_NOTE = 2;
286 NT_ACT_ADDENDUM = 3;
287 NT_ACT_EDIT_NOTE = 4;
288 NT_ACT_ID_ENTRY = 5;
289
290//TX_NEED_VISIT = 'A visit is required before creating a new surgery report.'; <-- original line. //kt 8/7/2007
291//TX_CREATE_ERR = 'Error Creating Report'; <-- original line. //kt 8/7/2007
292//TX_UPDATE_ERR = 'Error Updating Report'; <-- original line. //kt 8/7/2007
293//TX_NO_NOTE = 'No surgery report is currently being edited'; <-- original line. //kt 8/7/2007
294//TX_SAVE_NOTE = 'Save Surgery Report'; <-- original line. //kt 8/7/2007
295//TX_ADDEND_NO = 'Cannot make an addendum to a report that is being edited'; <-- original line. //kt 8/7/2007
296//TX_DEL_OK = CRLF + CRLF + 'Delete this surgery report?'; <-- original line. //kt 8/7/2007
297//TX_DEL_ERR = 'Unable to Delete Report'; <-- original line. //kt 8/7/2007
298//TX_SIGN = 'Sign Report'; <-- original line. //kt 8/7/2007
299//TX_COSIGN = 'Cosign Report'; <-- original line. //kt 8/7/2007
300//TX_SIGN_ERR = 'Unable to Sign Report'; <-- original line. //kt 8/7/2007
301// TX_SCREQD = 'This progress note title requires the service connected questions to be '+
302// 'answered. The Encounter form will now be opened. Please answer all '+
303// 'service connected questions.';
304// TX_SCREQD_T = 'Response required for SC questions.';
305//TX_NONOTE = 'No surgery report is currently selected.'; <-- original line. //kt 8/7/2007
306//TX_NONOTE_CAP = 'No Report Selected'; <-- original line. //kt 8/7/2007
307//TX_NOPRT_NEW = 'This surgery report may not be printed until it is saved'; <-- original line. //kt 8/7/2007
308//TX_NOPRT_NEW_CAP = 'Save Surgery Report'; <-- original line. //kt 8/7/2007
309//TX_NO_ALERT = 'There is insufficient information to process this alert.' + CRLF + <-- original line. //kt 8/7/2007
310// 'Either the alert has already been deleted, or it contained invalid data.' + CRLF + CRLF + <-- original line. //kt 8/7/2007
311// 'Click the NEXT button if you wish to continue processing more alerts.'; <-- original line. //kt 8/7/2007
312//TX_CAP_NO_ALERT = 'Unable to Process Alert'; <-- original line. //kt 8/7/2007
313 //TX_ORDER_LOCKED = 'This record is locked by an action underway on the Consults tab';
314 //TC_ORDER_LOCKED = 'Unable to access record';
315 //TX_NO_ORD_CHG = 'The note is still associated with the previously selected request.' + CRLF +
316 // 'Finish the pending action on the consults tab, then try again.';
317 //TC_NO_ORD_CHG = 'Locked Consult Request';
318//TX_NEW_SAVE1 = 'You are currently editing:' + CRLF + CRLF; <-- original line. //kt 8/7/2007
319//TX_NEW_SAVE2 = CRLF + CRLF + 'Do you wish to save this report and begin a new one?'; <-- original line. //kt 8/7/2007
320//TX_NEW_SAVE3 = CRLF + CRLF + 'Do you wish to save this report and begin a new addendum?'; <-- original line. //kt 8/7/2007
321//TX_NEW_SAVE4 = CRLF + CRLF + 'Do you wish to save this report and edit the one selected?'; <-- original line. //kt 8/7/2007
322 //TX_NEW_SAVE5 = CRLF + CRLF + 'Do you wish to save this report and begin a new Interdisciplinary entry?';
323//TC_NEW_SAVE2 = 'Create New Report'; <-- original line. //kt 8/7/2007
324//TC_NEW_SAVE3 = 'Create New Addendum'; <-- original line. //kt 8/7/2007
325//TC_NEW_SAVE4 = 'Edit Different Report'; <-- original line. //kt 8/7/2007
326 //TC_NEW_SAVE5 = 'Create New Interdisciplinary Entry';
327//TX_EMPTY_NOTE = CRLF + CRLF + 'This report contains no text and will not be saved.' + CRLF + <-- original line. //kt 8/7/2007
328// 'Do you wish to delete this report?'; <-- original line. //kt 8/7/2007
329//TC_EMPTY_NOTE = 'Empty Report'; <-- original line. //kt 8/7/2007
330//TX_EMPTY_NOTE1 = 'This report contains no text and can not be signed.'; <-- original line. //kt 8/7/2007
331//TC_NO_LOCK = 'Unable to Lock Report'; <-- original line. //kt 8/7/2007
332//TX_ABSAVE = 'It appears the session terminated abnormally when this' + CRLF + <-- original line. //kt 8/7/2007
333// 'report was last edited. Some text may not have been saved.' + CRLF + CRLF + <-- original line. //kt 8/7/2007
334// 'Do you wish to continue and sign the report?'; <-- original line. //kt 8/7/2007
335//TC_ABSAVE = 'Possible Missing Text'; <-- original line. //kt 8/7/2007
336//TX_NO_BOIL = 'There is no boilerplate text associated with this title.'; <-- original line. //kt 8/7/2007
337//TC_NO_BOIL = 'Load Boilerplate Text'; <-- original line. //kt 8/7/2007
338//TX_BLR_CLEAR = 'Do you want to clear the previously loaded boilerplate text?'; <-- original line. //kt 8/7/2007
339//TC_BLR_CLEAR = 'Clear Previous Boilerplate Text'; <-- original line. //kt 8/7/2007
340//TX_DETACH_CNF = 'Confirm Detachment'; <-- original line. //kt 8/7/2007
341//TX_DETACH_FAILURE = 'Detach failed'; <-- original line. //kt 8/7/2007
342//TX_RETRACT_CAP = 'Retraction Notice'; <-- original line. //kt 8/7/2007
343//TX_RETRACT = 'This document will now be RETRACTED. As Such, it has been removed' +CRLF + <-- original line. //kt 8/7/2007
344// ' from public view, and from typical Releases of Information,' +CRLF + <-- original line. //kt 8/7/2007
345// ' but will remain indefinitely discoverable to HIMS.' +CRLF +CRLF; <-- original line. //kt 8/7/2007
346
347var
348 TX_NEED_VISIT : string; //kt
349 TX_CREATE_ERR : string; //kt
350 TX_UPDATE_ERR : string; //kt
351 TX_NO_NOTE : string; //kt
352 TX_SAVE_NOTE : string; //kt
353 TX_ADDEND_NO : string; //kt
354 TX_DEL_OK : string; //kt
355 TX_DEL_ERR : string; //kt
356 TX_SIGN : string; //kt
357 TX_COSIGN : string; //kt
358 TX_SIGN_ERR : string; //kt
359 TX_NONOTE : string; //kt
360 TX_NONOTE_CAP : string; //kt
361 TX_NOPRT_NEW : string; //kt
362 TX_NOPRT_NEW_CAP : string; //kt
363 TX_NO_ALERT : string; //kt
364 TX_CAP_NO_ALERT : string; //kt
365 TX_NEW_SAVE1 : string; //kt
366 TX_NEW_SAVE2 : string; //kt
367 TX_NEW_SAVE3 : string; //kt
368 TX_NEW_SAVE4 : string; //kt
369 TC_NEW_SAVE2 : string; //kt
370 TC_NEW_SAVE3 : string; //kt
371 TC_NEW_SAVE4 : string; //kt
372 TX_EMPTY_NOTE : string; //kt
373 TC_EMPTY_NOTE : string; //kt
374 TX_EMPTY_NOTE1 : string; //kt
375 TC_NO_LOCK : string; //kt
376 TX_ABSAVE : string; //kt
377 TC_ABSAVE : string; //kt
378 TX_NO_BOIL : string; //kt
379 TC_NO_BOIL : string; //kt
380 TX_BLR_CLEAR : string; //kt
381 TC_BLR_CLEAR : string; //kt
382 TX_DETACH_CNF : string; //kt
383 TX_DETACH_FAILURE : string; //kt
384 TX_RETRACT_CAP : string; //kt
385 TX_RETRACT : string; //kt
386
387procedure SetupVars;
388//kt Added entire function to replace constant declarations 8/7/2007
389begin
390 TX_NEED_VISIT := DKLangConstW('fSurgery_A_visit_is_required_before_creating_a_new_surgery_reportx');
391 TX_CREATE_ERR := DKLangConstW('fSurgery_Error_Creating_Report');
392 TX_UPDATE_ERR := DKLangConstW('fSurgery_Error_Updating_Report');
393 TX_NO_NOTE := DKLangConstW('fSurgery_No_surgery_report_is_currently_being_edited');
394 TX_SAVE_NOTE := DKLangConstW('fSurgery_Save_Surgery_Report');
395 TX_ADDEND_NO := DKLangConstW('fSurgery_Cannot_make_an_addendum_to_a_report_that_is_being_edited');
396 TX_DEL_OK := CRLF + CRLF + DKLangConstW('fSurgery_Delete_this_surgery_reportx');
397 TX_DEL_ERR := DKLangConstW('fSurgery_Unable_to_Delete_Report');
398 TX_SIGN := DKLangConstW('fSurgery_Sign_Report');
399 TX_COSIGN := DKLangConstW('fSurgery_Cosign_Report');
400 TX_SIGN_ERR := DKLangConstW('fSurgery_Unable_to_Sign_Report');
401 TX_NONOTE := DKLangConstW('fSurgery_No_surgery_report_is_currently_selectedx');
402 TX_NONOTE_CAP := DKLangConstW('fSurgery_No_Report_Selected');
403 TX_NOPRT_NEW := DKLangConstW('fSurgery_This_surgery_report_may_not_be_printed_until_it_is_saved');
404 TX_NOPRT_NEW_CAP := DKLangConstW('fSurgery_Save_Surgery_Report');
405 TX_NO_ALERT := DKLangConstW('fSurgery_There_is_insufficient_information_to_process_this_alertx') + CRLF +
406 DKLangConstW('fSurgery_Either_the_alert_has_already_been_deletedx_or_it_contained_invalid_datax') + CRLF + CRLF +
407 DKLangConstW('fSurgery_Click_the_NEXT_button_if_you_wish_to_continue_processing_more_alertsx');
408 TX_CAP_NO_ALERT := DKLangConstW('fSurgery_Unable_to_Process_Alert');
409 TX_NEW_SAVE1 := DKLangConstW('fSurgery_You_are_currently_editingx') + CRLF + CRLF;
410 TX_NEW_SAVE2 := CRLF + CRLF + DKLangConstW('fSurgery_Do_you_wish_to_save_this_report_and_begin_a_new_onex');
411 TX_NEW_SAVE3 := CRLF + CRLF + DKLangConstW('fSurgery_Do_you_wish_to_save_this_report_and_begin_a_new_addendumx');
412 TX_NEW_SAVE4 := CRLF + CRLF + DKLangConstW('fSurgery_Do_you_wish_to_save_this_report_and_edit_the_one_selectedx');
413 TC_NEW_SAVE2 := DKLangConstW('fSurgery_Create_New_Report');
414 TC_NEW_SAVE3 := DKLangConstW('fSurgery_Create_New_Addendum');
415 TC_NEW_SAVE4 := DKLangConstW('fSurgery_Edit_Different_Report');
416 TX_EMPTY_NOTE := CRLF + CRLF + DKLangConstW('fSurgery_This_report_contains_no_text_and_will_not_be_savedx') + CRLF +
417 DKLangConstW('fSurgery_Do_you_wish_to_delete_this_reportx');
418 TC_EMPTY_NOTE := DKLangConstW('fSurgery_Empty_Report');
419 TX_EMPTY_NOTE1 := DKLangConstW('fSurgery_This_report_contains_no_text_and_can_not_be_signedx');
420 TC_NO_LOCK := DKLangConstW('fSurgery_Unable_to_Lock_Report');
421 TX_ABSAVE := DKLangConstW('fSurgery_It_appears_the_session_terminated_abnormally_when_this') + CRLF +
422 DKLangConstW('fSurgery_report_was_last_editedx_Some_text_may_not_have_been_savedx') + CRLF + CRLF +
423 DKLangConstW('fSurgery_Do_you_wish_to_continue_and_sign_the_reportx');
424 TC_ABSAVE := DKLangConstW('fSurgery_Possible_Missing_Text');
425 TX_NO_BOIL := DKLangConstW('fSurgery_There_is_no_boilerplate_text_associated_with_this_titlex');
426 TC_NO_BOIL := DKLangConstW('fSurgery_Load_Boilerplate_Text');
427 TX_BLR_CLEAR := DKLangConstW('fSurgery_Do_you_want_to_clear_the_previously_loaded_boilerplate_textx');
428 TC_BLR_CLEAR := DKLangConstW('fSurgery_Clear_Previous_Boilerplate_Text');
429 TX_DETACH_CNF := DKLangConstW('fSurgery_Confirm_Detachment');
430 TX_DETACH_FAILURE := DKLangConstW('fSurgery_Detach_failed');
431 TX_RETRACT_CAP := DKLangConstW('fSurgery_Retraction_Notice');
432 TX_RETRACT := DKLangConstW('fSurgery_This_document_will_now_be_RETRACTEDx__As_Suchx_it_has_been_removed') +CRLF +
433 DKLangConstW('fSurgery_from_public_viewx_and_from_typical_Releases_of_Informationx') +CRLF +
434 DKLangConstW('fSurgery_but_will_remain_indefinitely_discoverable_to_HIMSx') +CRLF +CRLF;
435end;
436
437var
438 uPCEShow, uPCEEdit: TPCEData;
439 ViewContext: Integer;
440 frmDrawers: TfrmDrawers;
441 uChanging: Boolean;
442
443{ TPage common methods --------------------------------------------------------------------- }
444
445function TfrmSurgery.AllowContextChange(var WhyNot: string): Boolean;
446begin
447 dlgFindText.CloseDialog;
448 Result := inherited AllowContextChange(WhyNot); // sets result = true
449 if Assigned(frmTemplateDialog) then
450 if Screen.ActiveForm = frmTemplateDialog then
451 //if (fsModal in frmTemplateDialog.FormState) then
452 case BOOLCHAR[frmFrame.CCOWContextChanging] of
453 '1': begin
454// WhyNot := 'A template in progress will be aborted. '; <-- original line. //kt 8/7/2007
455 WhyNot := DKLangConstW('fSurgery_A_template_in_progress_will_be_abortedx'); //kt added 8/7/2007
456 Result := False;
457 end;
458 '0': begin
459 if WhyNot = 'COMMIT' then
460 begin
461 FSilent := True;
462 frmTemplateDialog.Silent := True;
463 frmTemplateDialog.ModalResult := mrCancel;
464 end;
465 end;
466 end;
467 if EditingIndex <> -1 then
468 case BOOLCHAR[frmFrame.CCOWContextChanging] of
469 '1': begin
470 if memNewNote.GetTextLen > 0 then
471// WhyNot := 'A report in progress will be saved as unsigned. ' <-- original line. //kt 8/7/2007
472 WhyNot := DKLangConstW('fSurgery_A_report_in_progress_will_be_saved_as_unsignedx') //kt added 8/7/2007
473 else
474// WhyNot := 'An empty report in progress will be deleted. '; <-- original line. //kt 8/7/2007
475 WhyNot := DKLangConstW('fSurgery_An_empty_report_in_progress_will_be_deletedx'); //kt added 8/7/2007
476 Result := False;
477 end;
478 '0': begin
479 if WhyNot = 'COMMIT' then FSilent := True;
480 SaveCurrentNote(Result)
481 end;
482 end;
483 if Assigned(frmEncounterFrame) then
484 if Screen.ActiveForm = frmEncounterFrame then
485 //if (fsModal in frmEncounterFrame.FormState) then
486 case BOOLCHAR[frmFrame.CCOWContextChanging] of
487 '1': begin
488// WhyNot := WhyNot + 'Encounter information being edited will not be saved'; <-- original line. //kt 8/7/2007
489 WhyNot := WhyNot + DKLangConstW('fSurgery_Encounter_information_being_edited_will_not_be_saved'); //kt added 8/7/2007
490 Result := False;
491 end;
492 '0': begin
493 if WhyNot = 'COMMIT' then
494 begin
495 FSilent := True;
496 frmEncounterFrame.Abort := False;
497 frmEncounterFrame.Cancel := True;
498 end;
499 end;
500 end;
501end;
502
503procedure TfrmSurgery.ClearPtData;
504{ clear all controls that contain patient specific information }
505begin
506 inherited ClearPtData;
507 ClearEditControls;
508 uChanging := True;
509 tvSurgery.Items.BeginUpdate;
510 KillCaseTreeObjects(tvSurgery);
511 tvSurgery.Items.Clear;
512 tvSurgery.Items.EndUpdate;
513 lstNotes.Clear;
514 uChanging := False;
515 memSurgery.Clear;
516 uPCEShow.Clear;
517 uPCEEdit.Clear;
518 frmDrawers.ResetTemplates;
519end;
520
521procedure TfrmSurgery.DisplayPage;
522{ causes page to be visible and conditionally executes initialization code }
523begin
524 inherited DisplayPage;
525 frmFrame.ShowHideChartTabMenus(mnuViewChart);
526 frmFrame.mnuFilePrint.Tag := CT_SURGERY;
527 frmFrame.mnuFilePrint.Enabled := True;
528 frmFrame.mnuFilePrintSetup.Enabled := True;
529 if InitPage then
530 begin
531 FDefaultContext := GetCurrentSurgCaseContext;
532 FCurrentContext := FDefaultContext;
533 popNoteMemoSpell.Visible := SpellCheckAvailable;
534 popNoteMemoGrammar.Visible := popNoteMemoSpell.Visible;
535 Z11.Visible := popNoteMemoSpell.Visible;
536 timAutoSave.Interval := User.AutoSave * 1000; // convert seconds to milliseconds
537 SetEqualTabStops(memNewNote);
538 end;
539 // to indent the right margin need to set Paragraph.RightIndent for each paragraph?
540 if InitPatient and not (CallingContext = CC_NOTIFICATION) then
541 begin
542 SetViewContext(FDefaultContext);
543 end;
544 case CallingContext of
545 CC_INIT_PATIENT: if not InitPatient then
546 begin
547 SetViewContext(FDefaultContext);
548 end;
549 CC_NOTIFICATION: ProcessNotifications;
550 end;
551end;
552
553{ Form events ------------------------------------------------------------------------------ }
554
555procedure TfrmSurgery.FormCreate(Sender: TObject);
556begin
557 inherited;
558 PageID := CT_SURGERY;
559 memSurgery.Color := ReadOnlyColor;
560 memPCEShow.Color := ReadOnlyColor;
561 lblNewTitle.Color := ReadOnlyColor;
562 EditingIndex := -1;
563 FEditNote.LastCosigner := 0;
564 FEditNote.LastCosignerName := '';
565 FLastNoteID := '';
566 frmDrawers := TfrmDrawers.CreateDrawers(Self, pnlDrawers, [],[]);
567 frmDrawers.Align := alBottom;
568 frmDrawers.RichEditControl := memNewNote;
569 frmDrawers.NewNoteButton := cmdNewNote;
570 frmDrawers.Splitter := splDrawers;
571 frmDrawers.DefTempPiece := 1;
572 tvSurgery.Images := dmodShared.imgSurgery;
573 tvSurgery.StateImages := dmodShared.imgImages;
574 FImageFlag := TBitmap.Create;
575 FCaseList := TStringList.Create;
576 TAccessibleTreeView.WrapControl(tvSurgery);
577end;
578
579procedure TfrmSurgery.pnlRightResize(Sender: TObject);
580{ memSurgery (TRichEdit) doesn't repaint appropriately unless it's parent panel is refreshed }
581begin
582 inherited;
583 pnlRight.Refresh;
584 memSurgery.Repaint;
585end;
586
587procedure TfrmSurgery.pnlWriteResize(Sender: TObject);
588const
589 LEFT_MARGIN = 4;
590begin
591 inherited;
592 LimitEditWidth(memNewNote, MAX_ENTRY_WIDTH - 1);
593 memNewNote.Constraints.MinWidth := TextWidthByFont(memNewNote.Font.Handle, StringOfChar('X', MAX_ENTRY_WIDTH)) + (LEFT_MARGIN * 2) + ScrollBarWidth;
594 pnlLeft.Width := self.ClientWidth - pnlWrite.Width - sptHorz.Width;
595end;
596
597procedure TfrmSurgery.SetViewContext(AContext: TSurgCaseContext);
598var
599 Saved: boolean;
600begin
601 inherited;
602 if EditingIndex <> -1 then
603 begin
604 SaveCurrentNote(Saved);
605 if not Saved then Exit;
606 end;
607 FCurrentContext := AContext;
608 EditingIndex := -1;
609 tvSurgery.Enabled := True ;
610 pnlRead.BringToFront ;
611 with uSurgeryContext do
612 begin
613 Changed := True;
614 OpProc := FCurrentContext.OpProc;
615 BeginDate := FCurrentContext.BeginDate;
616 EndDate := FCurrentContext.EndDate;
617 FMBeginDate := FCurrentContext.FMBeginDate;
618 FMEndDate := FCurrentContext.FMEndDate;
619 MaxDocs := FCurrentContext.MaxDocs;
620 Status := FCurrentContext.Status;
621 GroupBy := FCurrentContext.GroupBy;
622 TreeAscending := FCurrentContext.TreeAscending;
623 mnuViewClick(Self);
624 end;
625end;
626
627procedure TfrmSurgery.FormDestroy(Sender: TObject);
628begin
629 TAccessibleTreeView.UnwrapControl(tvSurgery);
630 FCaseList.Free;
631 FImageFlag.Free;
632 KillCaseTreeObjects(tvSurgery);
633 inherited;
634end;
635
636function TfrmSurgery.GetDrawers: TFrmDrawers;
637begin
638 Result := frmDrawers ;
639end;
640
641procedure TfrmSurgery.UpdateTreeView(DocList: TStringList; Tree: TORTreeView);
642var
643 i: integer;
644begin
645 with Tree do
646 begin
647 uChanging := True;
648 Items.BeginUpdate;
649 for i := 0 to DocList.Count - 1 do
650 begin
651 if Piece(DocList[i], U, 10) <> '' then
652 lstNotes.Items.Add(DocList[i]);
653 end;
654 BuildCaseTree(DocList, '0', Tree, nil, uSurgeryContext);
655 Items.EndUpdate;
656 uChanging := False;
657 end;
658end;
659
660procedure TfrmSurgery.RequestPrint;
661var
662 Saved: Boolean;
663begin
664 SetupVars; //kt added 8/7/2007 to replace constants with vars.
665 with lstNotes do
666 begin
667 if ItemIndex = EditingIndex then
668 begin
669 SaveCurrentNote(Saved);
670 if not Saved then Exit;
671 end;
672 if ItemIEN > 0 then PrintNote(ItemIEN, MakeNoteDisplayText(Items[ItemIndex])) else
673 begin
674 if ItemIEN = 0 then InfoBox(TX_NONOTE, TX_NONOTE_CAP, MB_OK);
675 if ItemIEN < 0 then InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
676 end;
677 end;
678end;
679
680procedure TfrmSurgery.mnuChartTabClick(Sender: TObject);
681{ reroute to Chart Tab menu of the parent form: frmFrame }
682begin
683 inherited;
684 frmFrame.mnuChartTabClick(Sender);
685end;
686
687procedure TfrmSurgery.SetFontSize(NewFontSize: Integer);
688{ adjusts the font size of any controls that don't have ParentFont = True }
689begin
690 inherited SetFontSize(NewFontSize);
691 pnlLeft.Width := pnlLeft.Constraints.MinWidth;
692 sptHorz.Left := pnlLeft.Width;
693 memSurgery.Font.Size := NewFontSize;
694 memNewNote.Font.Size := NewFontSize;
695 lblTitle.Font.Size := NewFontSize;
696 frmDrawers.Font.Size := NewFontSize;
697 SetEqualTabStops(memNewNote);
698 // adjust heights of pnlAction, pnlFields, and lstEncntShow
699end;
700
701procedure TfrmSurgery.mnuViewClick(Sender: TObject);
702{ changes the list of notes available for viewing }
703var
704 //AuthCtxt: TAuthorContext;
705 //DateRange: TNoteDateRange;
706 AContext: TSurgCaseContext;
707 Saved: Boolean;
708begin
709 inherited;
710 // save note at EditingIndex?
711 if EditingIndex <> -1 then
712 begin
713 SaveCurrentNote(Saved);
714 if not Saved then Exit;
715 end;
716 FLastNoteID := lstNotes.ItemID;
717 mnuViewDetail.Checked := False;
718 uChanging := True;
719 AContext := GetCurrentSurgCaseContext;
720//StatusText('Retrieving surgery case list...'); <-- original line. //kt 8/7/2007
721 StatusText(DKLangConstW('fSurgery_Retrieving_surgery_case_listxxx')); //kt added 8/7/2007
722 if Sender is TMenuItem then ViewContext := TMenuItem(Sender).Tag
723 else with AContext do
724 begin
725 if ((BeginDate + EndDate + Status + GroupBy + IntToStr(MaxDocs)) <> '0') then
726 ViewContext := SR_CUSTOM
727 else
728 ViewContext := SR_ALL;
729 end;
730 with tvSurgery do if (Selected <> nil) and (Piece(TORTreeNode(Selected).StringData, U, 10) <> '') then
731 FLastNoteID := Piece(TORTreeNode(Selected).StringData, U, 1);
732 case ViewContext of
733 SR_RECENT, SR_ALL: begin
734 FillChar(FCurrentContext, SizeOf(FCurrentContext), 0);
735 FillChar(uSurgeryContext, SizeOf(uSurgeryContext), 0);
736 //FCurrentContext.MaxDocs := uSurgeryContext.MaxDocs;
737 FCurrentContext.Status := IntToStr(ViewContext);
738 LoadSurgeryCases;
739 end;
740 SR_CUSTOM: begin
741 if Sender is TMenuItem then
742 begin
743 SelectSurgeryView(Font.Size, True, FCurrentContext, uSurgeryContext);
744 end;
745 with uSurgeryContext do (*if Changed then*)
746 begin
747 FCurrentContext.OpProc := OpProc;
748 FCurrentContext.BeginDate := BeginDate;
749 FCurrentContext.EndDate := EndDate;
750 FCurrentContext.FMBeginDate := FMBeginDate;
751 FCurrentContext.FMEndDate := FMEndDate;
752 if (FMBeginDate > 0) and (FMEndDate > 0) then
753 FCurrentContext.Status := IntToStr(SR_BY_DATE)
754 else
755 FCurrentContext.Status := Status;
756 FCurrentContext.MaxDocs := MaxDocs;
757 FCurrentContext.GroupBy := GroupBy;
758 FCurrentContext.TreeAscending := TreeAscending;
759 LoadSurgeryCases;
760 end;
761 end;
762 end; {case}
763 lblCases.Caption := SetSurgTreeLabel(FCurrentContext);
764 tvSurgery.Caption := lblCases.Caption;
765 StatusText('');
766end;
767
768procedure TfrmSurgery.popNoteMemoFindClick(Sender: TObject);
769begin
770 inherited;
771 SendMessage(TRichEdit(popNoteMemo.PopupComponent).Handle, WM_VSCROLL, SB_TOP, 0);
772 with dlgFindText do
773 begin
774 Position := Point(Application.MainForm.Left + pnlLeft.Width, Application.MainForm.Top);
775 FindText := '';
776 Options := [frDown, frHideUpDown];
777 Execute;
778 end;
779end;
780
781procedure TfrmSurgery.dlgFindTextFind(Sender: TObject);
782begin
783 dmodShared.FindRichEditText(dlgFindText, TRichEdit(popNoteMemo.PopupComponent));
784end;
785
786{ General procedures ----------------------------------------------------------------------- }
787
788procedure TfrmSurgery.ClearEditControls;
789{ resets controls used for entering a new progress note }
790begin
791 // clear FEditNote (should FEditNote be an object with a clear method?)
792 with FEditNote do
793 begin
794 DocType := 0;
795 Title := 0;
796 TitleName := '';
797 DateTime := 0;
798 Author := 0;
799 AuthorName := '';
800 Cosigner := 0;
801 CosignerName := '';
802 Subject := '';
803 Location := 0;
804 LocationName := '';
805 PkgRef := '';
806 PkgIEN := 0;
807 PkgPtr := '';
808 NeedCPT := False;
809 Addend := 0;
810 {LastCosigner & LastCosignerName aren't cleared because they're used as default for next note.}
811 Lines := nil;
812 end;
813 // clear the editing controls (also clear the new labels?)
814 txtSubject.Text := '';
815 memNewNote.Clear;
816 timAutoSave.Enabled := False;
817 // clear the PCE object for editing
818 uPCEEdit.Clear;
819 // set the tracking variables to initial state
820 EditingIndex := -1;
821 FChanged := False;
822end;
823
824procedure TfrmSurgery.ShowPCEControls(ShouldShow: Boolean);
825begin
826 sptVert.Visible := ShouldShow;
827 memPCEShow.Visible := ShouldShow;
828 if(ShouldShow) then
829 sptVert.Top := memPCEShow.Top - sptVert.Height;
830 memSurgery.Invalidate;
831end;
832
833procedure TfrmSurgery.DisplayPCE;
834{ displays PCE information if appropriate & enables/disabled editing of PCE data }
835var
836 EnableList, ShowList: TDrawers;
837 VitalStr: TStringlist;
838 NoPCE: boolean;
839 ActionSts: TActionRec;
840 AnIEN: integer;
841
842begin
843 memPCEShow.Clear;
844 with lstNotes do if ItemIndex = -1 then
845 begin
846 ShowPCEControls(FALSE);
847 frmDrawers.DisplayDrawers(FALSE);
848 end
849 else if ItemIndex = EditingIndex then
850 begin
851 with uPCEEdit do
852 begin
853 AddStrData(memPCEShow.Lines);
854 NoPCE := (memPCEShow.Lines.Count = 0);
855 VitalStr := TStringList.create;
856 try
857 GetVitalsFromDate(VitalStr, uPCEEdit);
858 AddVitalData(VitalStr, memPCEShow.Lines);
859 finally
860 VitalStr.free;
861 end;
862 ShowPCEButtons(TRUE);
863 ShowPCEControls(cmdPCE.Enabled or (memPCEShow.Lines.Count > 0));
864 if(NoPCE and memPCEShow.Visible) then
865 memPCEShow.Lines.Insert(0, TX_NOPCE);
866
867 if(InteractiveRemindersActive) then
868 begin
869 if(GetReminderStatus = rsNone) then
870 EnableList := [odTemplates]
871 else
872 EnableList := [odTemplates, odReminders];
873 ShowList := [odTemplates, odReminders];
874 end
875 else
876 begin
877 EnableList := [odTemplates];
878 ShowList := [odTemplates];
879 end;
880 frmDrawers.DisplayDrawers(TRUE, EnableList, ShowList);
881 end;
882 end else
883 begin
884 ShowPCEButtons(FALSE);
885 frmDrawers.DisplayDrawers(TRUE, [odTemplates], [odTemplates]);
886 AnIEN := lstNotes.ItemIEN;
887 ActOnDocument(ActionSts, AnIEN, 'VIEW');
888 if ActionSts.Success then
889 begin
890// StatusText('Retrieving encounter information...'); <-- original line. //kt 8/7/2007
891 StatusText(DKLangConstW('fSurgery_Retrieving_encounter_informationxxx')); //kt added 8/7/2007
892 with uPCEShow do
893 begin
894 NoteDateTime := MakeFMDateTime(Piece(lstNotes.Items[lstNotes.ItemIndex], U, 3));
895 PCEForNote(AnIEN, uPCEEdit);
896 AddStrData(memPCEShow.Lines);
897 NoPCE := (memPCEShow.Lines.Count = 0);
898 VitalStr := TStringList.create;
899 try
900 GetVitalsFromNote(VitalStr, uPCEShow, AnIEN);
901 AddVitalData(VitalStr, memPCEShow.Lines);
902 finally
903 VitalStr.free;
904 end;
905 ShowPCEControls(memPCEShow.Lines.Count > 0);
906 if(NoPCE and memPCEShow.Visible) then
907 memPCEShow.Lines.Insert(0, TX_NOPCE);
908 end;
909 StatusText('');
910 end
911 else
912 ShowPCEControls(FALSE);
913 end; {if ItemIndex}
914end;
915
916{ supporting calls for writing notes }
917
918function TfrmSurgery.GetTitleText(AnIndex: Integer): string;
919{ returns non-tabbed text for the title of a note given the ItemIndex in lstNotes }
920begin
921 with lstNotes do if ItemIndex > -1 then
922 Result := FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(Items[AnIndex], U, 3))) +
923 ' ' + Piece(Items[AnIndex], U, 2) + ', ' + Piece(Items[AnIndex], U, 6) + ', ' +
924 Piece(Piece(Items[AnIndex], U, 5), ';', 2)
925end;
926
927function TfrmSurgery.LacksRequiredForCreate: Boolean;
928{ determines if the fields required to create the note are present }
929var
930 CurTitle: Integer;
931begin
932 Result := False;
933 with FEditNote do
934 begin
935 if Title <= 0 then Result := True;
936 if Author <= 0 then Result := True;
937 if DateTime <= 0 then Result := True;
938 if (DocType = TYP_ADDENDUM) then
939 begin
940 if AskCosignerForDocument(Addend, Author) and (Cosigner <= 0) then Result := True;
941 end else
942 begin
943 if Title > 0 then CurTitle := Title else CurTitle := DocType;
944 if AskCosignerForTitle(CurTitle, Author, DateTime) and (Cosigner <= 0) then Result := True;
945 end;
946 end;
947end;
948
949function TfrmSurgery.VerifyNoteTitle: Boolean;
950const
951 VNT_UNKNOWN = 0;
952 VNT_NO = 1;
953 VNT_YES = 2;
954var
955 AParam: string;
956begin
957 if FVerifyNoteTitle = VNT_UNKNOWN then
958 begin
959 AParam := GetUserParam('ORWOR VERIFY NOTE TITLE');
960 if AParam = '1' then FVerifyNoteTitle := VNT_YES else FVerifyNoteTitle := VNT_NO;
961 end;
962 Result := FVerifyNoteTitle = VNT_YES;
963end;
964
965procedure TfrmSurgery.SetSubjectVisible(ShouldShow: Boolean);
966{ hide/show subject & resize panel accordingly - leave 6 pixel margin above memNewNote }
967begin
968 if ShouldShow then
969 begin
970 lblSubject.Visible := True;
971 txtSubject.Visible := True;
972 pnlFields.Height := txtSubject.Top + txtSubject.Height + 6;
973 end else
974 begin
975 lblSubject.Visible := False;
976 txtSubject.Visible := False;
977 pnlFields.Height := lblVisit.Top + lblVisit.Height + 6;
978 end;
979end;
980
981
982{ create, edit & save notes }
983
984procedure TfrmSurgery.InsertNewNote(IsIDChild: boolean; AnIDParent: integer);
985{ creates the editing context for a new progress note & inserts stub into top of view list }
986const
987 IS_ID_CHILD = False;
988var
989 EnableAutosave, HaveRequired: Boolean;
990 CreatedNote: TCreatedDoc;
991 TmpBoilerPlate: TStringList;
992 tmpNode: TTreeNode;
993 x, AClassName: string;
994 DocInfo: string;
995begin
996 SetupVars; //kt added 8/7/2007 to replace constants with vars.
997 if tvSurgery.Selected = nil then exit;
998 if PCaseTreeObject(tvSurgery.Selected.Data)^.OperativeProc = '' then
999 begin
1000// InfoBox('You must first select the case to which this document will apply', 'Select a case', 0); <-- original line. //kt 8/7/2007
1001 InfoBox(DKLangConstW('fSurgery_You_must_first_select_the_case_to_which_this_document_will_apply'), DKLangConstW('fSurgery_Select_a_case'), 0); //kt added 8/7/2007
1002 exit;
1003 end;
1004 EnableAutosave := FALSE;
1005 TmpBoilerPlate := nil;
1006 try
1007 ClearEditControls;
1008 FillChar(FEditNote, SizeOf(FEditNote), 0); //v15.7
1009 with FEditNote do
1010 begin
1011 DocType := TYP_PROGRESS_NOTE;
1012 Title := DfltNoteTitle;
1013 TitleName := DfltNoteTitleName;
1014 DateTime := FMNow;
1015 Author := User.DUZ;
1016 AuthorName := User.Name;
1017 Location := Encounter.Location;
1018 LocationName := Encounter.LocationName;
1019 VisitDate := Encounter.DateTime;
1020 if IsIDChild then
1021 IDParent := AnIDParent
1022 else
1023 IDParent := 0;
1024 // Cosigner & PkgRef, if needed, will be set by fNoteProps
1025 end;
1026 // check to see if interaction necessary to get required fields
1027 if PCaseTreeObject(tvSurgery.Selected.Data)^.IsNonORProc then AClassName := DCL_SURG_NON_OR else AClassName := DCL_SURG_OR;
1028 if LacksRequiredForCreate or VerifyNoteTitle
1029 then HaveRequired := ExecuteNoteProperties(FEditNote, CT_SURGERY, IS_ID_CHILD, IS_ID_CHILD, AClassName, 0)
1030 else HaveRequired := True;
1031 if HaveRequired then
1032 begin
1033 // set up uPCEEdit for entry of new note
1034 uPCEEdit.UseEncounter := True;
1035 uPCEEdit.NoteDateTime := FEditNote.DateTime;
1036 uPCEEdit.PCEForNote(USE_CURRENT_VISITSTR, uPCEShow);
1037 FEditNote.NeedCPT := uPCEEdit.CPTRequired;
1038 // create the note
1039 PutNewNote(CreatedNote, FEditNote);
1040 uPCEEdit.NoteIEN := CreatedNote.IEN;
1041 if CreatedNote.IEN > 0 then LockDocument(CreatedNote.IEN, CreatedNote.ErrorText);
1042 if CreatedNote.ErrorText = '' then
1043 begin
1044 //x := $$RESOLVE^TIUSRVLO formatted string
1045 //7348^Note Title^3000913^NERD, YOURA (N0165)^1329;Rich Vertigan;VERTIGAN,RICH^8E REHAB MED^complete^Adm: 11/05/98;2981105.095547^ ;^^0^^^2
1046 with FEditNote do
1047 begin
1048 x := IntToStr(CreatedNote.IEN) + U + TitleName + U + FloatToStr(FEditNote.DateTime) + U +
1049 Patient.Name + U + IntToStr(Author) + ';' + AuthorName + U + LocationName + U + 'new' + U +
1050 U + U + U + U + U + U + U;
1051 end;
1052
1053 lstNotes.Items.Insert(0, x);
1054 uChanging := True;
1055 tvSurgery.Items.BeginUpdate;
1056(* if IsIDChild then
1057 begin
1058 tmpNode := tvSurgery.FindPieceNode(IntToStr(AnIDParent), 1, U, tvSurgery.Items.GetFirstNode);
1059 tmpNode.ImageIndex := IMG_IDNOTE_OPEN;
1060 tmpNode.SelectedIndex := IMG_IDNOTE_OPEN;
1061 tmpNode := tvSurgery.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeCaseTreeObject(x));
1062 tmpNode.ImageIndex := IMG_ID_CHILD;
1063 tmpNode.SelectedIndex := IMG_ID_CHILD;
1064 end
1065 else*)
1066 begin
1067// tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, 'New Note in Progress', <-- original line. //kt 8/7/2007
1068 tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, DKLangConstW('fSurgery_New_Note_in_Progress'), //kt added 8/7/2007
1069 MakeCaseTreeObject('NEW^New Note in Progress^^^^^^^^^^^%^0'));
1070 TORTreeNode(tmpNode).StringData := 'NEW^New Note in Progress^^^^^^^^^^^%^0';
1071 tmpNode.ImageIndex := IMG_SURG_TOP_LEVEL;
1072 tmpNode := tvSurgery.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeCaseTreeObject(x));
1073 tmpNode.ImageIndex := IMG_SURG_RPT_SINGLE;
1074 tmpNode.SelectedIndex := IMG_SURG_RPT_SINGLE;
1075 end;
1076 tmpNode.StateIndex := IMG_NO_IMAGES;
1077 TORTreeNode(tmpNode).StringData := x;
1078 tvSurgery.Selected := tmpNode;
1079 tvSurgery.Items.EndUpdate;
1080 uChanging := False;
1081 Changes.Add(CH_SUR, IntToStr(CreatedNote.IEN), GetTitleText(0), '', CH_SIGN_YES);
1082 lstNotes.ItemIndex := 0;
1083 EditingIndex := 0;
1084 SetSubjectVisible(AskSubjectForNotes);
1085 if not assigned(TmpBoilerPlate) then
1086 TmpBoilerPlate := TStringList.Create;
1087 LoadBoilerPlate(TmpBoilerPlate, FEditNote.Title);
1088 FChanged := False;
1089 cmdChangeClick(Self); // will set captions, sign state for Changes
1090 lstNotesClick(Self); // will make pnlWrite visible
1091 if timAutoSave.Interval <> 0 then EnableAutosave := TRUE;
1092 if txtSubject.Visible then txtSubject.SetFocus else memNewNote.SetFocus;
1093 end else
1094 begin
1095 // if note creation failed or failed to get note lock (both unlikely), unlock consult
1096 InfoBox(CreatedNote.ErrorText, TX_CREATE_ERR, MB_OK);
1097 HaveRequired := False;
1098 end; {if CreatedNote.IEN}
1099 end; {if HaveRequired}
1100 if not HaveRequired then ClearEditControls;
1101 finally
1102 if assigned(TmpBoilerPlate) then
1103 begin
1104 DocInfo := MakeXMLParamTIU(IntToStr(CreatedNote.IEN), FEditNote);
1105 ExecuteTemplateOrBoilerPlate(TmpBoilerPlate, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
1106 memNewNote.Lines.Assign(TmpBoilerPlate);
1107 TmpBoilerPlate.Free;
1108 end;
1109 if EnableAutosave then // Don't enable autosave until after dialog fields have been resolved
1110 timAutoSave.Enabled := True;
1111 end;
1112end;
1113
1114procedure TfrmSurgery.InsertAddendum;
1115{ sets up fields of pnlWrite to write an addendum for the selected note }
1116const
1117 AS_ADDENDUM = True;
1118 IS_ID_CHILD = False;
1119var
1120 HaveRequired: Boolean;
1121 CreatedNote: TCreatedDoc;
1122 tmpNode: TTreeNode;
1123 x: string;
1124begin
1125 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1126 ClearEditControls;
1127 with FEditNote do
1128 begin
1129 DocType := TYP_ADDENDUM;
1130 Title := TitleForNote(lstNotes.ItemIEN);
1131 TitleName := Piece(lstNotes.Items[lstNotes.ItemIndex], U, 2);
1132 if Copy(TitleName,1,1) = '+' then TitleName := Copy(TitleName, 3, 199);
1133 DateTime := FMNow;
1134 Author := User.DUZ;
1135 AuthorName := User.Name;
1136 Addend := lstNotes.ItemIEN;
1137 x := GetPackageRefForNote(lstNotes.ItemIEN);
1138 if Piece(x, U, 1) <> '-1' then
1139 begin
1140 PkgRef := GetPackageRefForNote(lstNotes.ItemIEN);
1141 PkgIEN := StrToIntDef(Piece(PkgRef, ';', 1), 0);
1142 PkgPtr := Piece(PkgRef, ';', 2);
1143 end;
1144 //Lines := memNewNote.Lines;
1145 // Cosigner, if needed, will be set by fNoteProps
1146 // Location info will be set after the encounter is loaded
1147 end;
1148 // check to see if interaction necessary to get required fields
1149 if LacksRequiredForCreate
1150 then HaveRequired := ExecuteNoteProperties(FEditNote, CT_SURGERY, IS_ID_CHILD, False, '', 0)
1151 else HaveRequired := True;
1152 if HaveRequired then
1153 begin
1154 uPCEEdit.NoteDateTime := FEditNote.DateTime;
1155 uPCEEdit.PCEForNote(FEditNote.Addend, uPCEShow);
1156 FEditNote.Location := uPCEEdit.Location;
1157 FEditNote.LocationName := ExternalName(uPCEEdit.Location, 44);
1158 FEditNote.VisitDate := uPCEEdit.DateTime;
1159 PutAddendum(CreatedNote, FEditNote, FEditNote.Addend);
1160 uPCEEdit.NoteIEN := CreatedNote.IEN;
1161 if CreatedNote.IEN > 0 then LockDocument(CreatedNote.IEN, CreatedNote.ErrorText);
1162 if CreatedNote.ErrorText = '' then
1163 begin
1164 with FEditNote do
1165 begin
1166 x := IntToStr(CreatedNote.IEN) + U + 'Addendum to ' + TitleName + U + FloatToStr(DateTime) + U +
1167 Patient.Name + U + IntToStr(Author) + ';' + AuthorName + U + LocationName + U + 'new' + U +
1168 U + U + PkgRef + U + U + U + U + U;
1169 end;
1170
1171
1172 lstNotes.Items.Insert(0, x);
1173 uChanging := True;
1174 tvSurgery.Items.BeginUpdate;
1175// tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, 'New Addendum in Progress', <-- original line. //kt 8/7/2007
1176 tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, DKLangConstW('fSurgery_New_Addendum_in_Progress'), //kt added 8/7/2007
1177 MakeCaseTreeObject('ADDENDUM^New Addendum in Progress^^^^^^^^^^^%^0'));
1178 TORTreeNode(tmpNode).StringData := 'ADDENDUM^New Addendum in Progress^^^^^^^^^^^%^0';
1179 tmpNode.ImageIndex := IMG_SURG_TOP_LEVEL;
1180 tmpNode := tvSurgery.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeCaseTreeObject(x));
1181 TORTreeNode(tmpNode).StringData := x;
1182
1183 tmpNode.ImageIndex := IMG_SURG_ADDENDUM;
1184 tmpNode.SelectedIndex := IMG_SURG_ADDENDUM;
1185 tvSurgery.Selected := tmpNode;
1186 tvSurgery.Items.EndUpdate;
1187 uChanging := False;
1188 Changes.Add(CH_SUR, IntToStr(CreatedNote.IEN), GetTitleText(0), '', CH_SIGN_YES);
1189 lstNotes.ItemIndex := 0;
1190 EditingIndex := 0;
1191 SetSubjectVisible(AskSubjectForNotes);
1192 cmdChangeClick(Self); // will set captions, sign state for Changes
1193 lstNotesClick(Self); // will make pnlWrite visible
1194 if timAutoSave.Interval <> 0 then timAutoSave.Enabled := True;
1195 memNewNote.SetFocus;
1196 end else
1197 begin
1198 // if note creation failed or failed to get note lock (both unlikely), unlock consult
1199 InfoBox(CreatedNote.ErrorText, TX_CREATE_ERR, MB_OK);
1200 HaveRequired := False;
1201 end; {if CreatedNote.IEN}
1202 end; {if HaveRequired}
1203 if not HaveRequired then ClearEditControls;
1204end;
1205
1206procedure TfrmSurgery.LoadForEdit;
1207{ retrieves an existing note and places the data in the fields of pnlWrite }
1208var
1209 tmpNode: TTreeNode;
1210 x: string;
1211begin
1212 ClearEditControls;
1213 EditingIndex := lstNotes.ItemIndex;
1214 Changes.Add(CH_SUR, lstNotes.ItemID, GetTitleText(EditingIndex), '', CH_SIGN_YES);
1215 GetNoteForEdit(FEditNote, lstNotes.ItemIEN);
1216 memNewNote.Lines.Assign(FEditNote.Lines);
1217 FChanged := False;
1218 if FEditNote.Title = TYP_ADDENDUM then
1219 begin
1220 FEditNote.DocType := TYP_ADDENDUM;
1221 FEditNote.TitleName := Piece(lstNotes.Items[lstNotes.ItemIndex], U, 2);
1222 if Copy(FEditNote.TitleName,1,1) = '+' then FEditNote.TitleName := Copy(FEditNote.TitleName, 3, 199);
1223 if CompareText(Copy(FEditNote.TitleName, 1, 8), 'Addendum') <> 0
1224// then FEditNote.TitleName := FEditNote.TitleName + 'Addendum to '; <-- original line. //kt 8/7/2007
1225 then FEditNote.TitleName := FEditNote.TitleName + DKLangConstW('fSurgery_Addendum_to'); //kt added 8/7/2007
1226 end;
1227
1228 uChanging := True;
1229 tvSurgery.Items.BeginUpdate;
1230
1231 tmpNode := tvSurgery.FindPieceNode('EDIT', 1, U, nil);
1232 if tmpNode = nil then
1233 begin
1234// tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, 'Note being edited', <-- original line. //kt 8/7/2007
1235 tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, DKLangConstW('fSurgery_Note_being_edited'), //kt added 8/7/2007
1236 MakeCaseTreeObject('EDIT^Note being edited^^^^^^^^^^^%^0'));
1237 TORTreeNode(tmpNode).StringData := 'EDIT^Note being edited^^^^^^^^^^^%^0';
1238 end
1239 else
1240 tmpNode.DeleteChildren;
1241 x := lstNotes.Items[lstNotes.ItemIndex];
1242 tmpNode.ImageIndex := IMG_SURG_TOP_LEVEL;
1243 tmpNode := tvSurgery.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(x), MakeCaseTreeObject(x));
1244 TORTreeNode(tmpNode).StringData := x;
1245//if CompareText(Copy(FEditNote.TitleName, 1, 8), 'Addendum') <> 0 then <-- original line. //kt 8/7/2007
1246 if CompareText(Copy(FEditNote.TitleName, 1, 8), DKLangConstW('fSurgery_Addendum')) <> 0 then //kt added 8/7/2007
1247 tmpNode.ImageIndex := IMG_SURG_RPT_SINGLE
1248 else
1249 tmpNode.ImageIndex := IMG_SURG_ADDENDUM;
1250 tmpNode.SelectedIndex := tmpNode.ImageIndex;
1251 tvSurgery.Selected := tmpNode;
1252 tvSurgery.Items.EndUpdate;
1253 uChanging := False;
1254
1255 uPCEEdit.NoteDateTime := MakeFMDateTime(Piece(lstNotes.Items[lstNotes.ItemIndex], U, 3));
1256 uPCEEdit.PCEForNote(lstNotes.ItemIEN, uPCEShow);
1257 FEditNote.NeedCPT := uPCEEdit.CPTRequired;
1258 txtSubject.Text := FEditNote.Subject;
1259 SetSubjectVisible(AskSubjectForNotes);
1260 cmdChangeClick(Self); // will set captions, sign state for Changes
1261 lstNotesClick(Self); // will make pnlWrite visible
1262 if timAutoSave.Interval <> 0 then timAutoSave.Enabled := True;
1263 memNewNote.SetFocus;
1264end;
1265
1266procedure TfrmSurgery.SaveEditedNote(var Saved: Boolean);
1267{ validates fields and sends the updated note to the server }
1268var
1269 UpdatedNote: TCreatedDoc;
1270 x: string;
1271begin
1272 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1273 Saved := False;
1274 if (memNewNote.GetTextLen = 0) or (not ContainsVisibleChar(memNewNote.Text)) then
1275 begin
1276 lstNotes.ItemIndex := EditingIndex;
1277 x := lstNotes.ItemID;
1278 uChanging := True;
1279 with tvSurgery do Selected := FindPieceNode(x, 1, U, Items.GetFirstNode);
1280 uChanging := False;
1281 tvSurgeryChange(Self, tvSurgery.Selected);
1282 if FSilent or
1283 ((not FSilent) and
1284 (InfoBox(GetTitleText(EditingIndex) + TX_EMPTY_NOTE, TC_EMPTY_NOTE, MB_YESNO) = IDYES))
1285 then
1286 begin
1287 FConfirmed := True;
1288 mnuActDeleteClick(Self);
1289 Saved := True;
1290 FDeleted := True;
1291 end
1292 else
1293 FConfirmed := False;
1294 Exit;
1295 end;
1296 //ExpandTabsFilter(memNewNote.Lines, TAB_STOP_CHARS);
1297 FEditNote.Lines := memNewNote.Lines;
1298 FEditNote.Subject := txtSubject.Text;
1299 FEditNote.NeedCPT := uPCEEdit.CPTRequired;
1300 timAutoSave.Enabled := False;
1301 try
1302 PutEditedNote(UpdatedNote, FEditNote, lstNotes.GetIEN(EditingIndex));
1303 finally
1304 timAutoSave.Enabled := True;
1305 end;
1306 // there's no unlocking here since the note is still in Changes after a save
1307 if UpdatedNote.IEN > 0 then
1308 begin
1309 if lstNotes.ItemIndex = EditingIndex then
1310 begin
1311 EditingIndex := -1;
1312 lstNotesClick(Self);
1313 end;
1314 EditingIndex := -1; // make sure EditingIndex reset even if not viewing edited note
1315 Saved := True;
1316 FChanged := False;
1317 end else
1318 begin
1319 if not FSilent then
1320 InfoBox(TX_SAVE_ERROR1 + UpdatedNote.ErrorText + TX_SAVE_ERROR2, TC_SAVE_ERROR, MB_OK or MB_ICONWARNING);
1321 end;
1322end;
1323
1324procedure TfrmSurgery.SaveCurrentNote(var Saved: Boolean);
1325{ called whenever a note should be saved - uses IEN to call appropriate save logic }
1326begin
1327 if EditingIndex < 0 then Exit;
1328 SaveEditedNote(Saved);
1329end;
1330
1331{ Left panel (selector) events ------------------------------------------------------------- }
1332
1333procedure TfrmSurgery.cmdNewNoteClick(Sender: TObject);
1334{ maps 'New Note' button to the New Progress Note menu item }
1335begin
1336 inherited;
1337 mnuActNewClick(Self);
1338end;
1339
1340procedure TfrmSurgery.cmdPCEClick(Sender: TObject);
1341var
1342 Refresh: boolean;
1343 ActionSts: TActionRec;
1344 AnIEN: integer;
1345 PCEObj: TPCEData;
1346
1347begin
1348 inherited;
1349 cmdPCE.Enabled := False;
1350 if not FEditingNotePCEObj then
1351 begin
1352 PCEObj := nil;
1353 AnIEN := lstNotes.ItemIEN;
1354 if (AnIEN <> 0) and (memSurgery.Lines.Count > 0) then
1355 begin
1356 ActOnDocument(ActionSts, AnIEN, 'VIEW');
1357 if ActionSts.Success then
1358 begin
1359 uPCEShow.CopyPCEData(uPCEEdit);
1360 PCEObj := uPCEEdit;
1361 end;
1362 end;
1363 Refresh := EditPCEData(PCEObj);
1364 end
1365 else
1366 begin
1367 UpdatePCE(uPCEEdit);
1368 Refresh := TRUE;
1369 end;
1370 cmdPCE.Enabled := True;
1371 if Refresh and (not frmFrame.Closing) then
1372 DisplayPCE;
1373end;
1374
1375{ Right panel (editor) events -------------------------------------------------------------- }
1376
1377procedure TfrmSurgery.mnuActChangeClick(Sender: TObject);
1378begin
1379 inherited;
1380 if (FEditingIndex < 0) or (lstNotes.ItemIndex <> FEditingIndex) then Exit;
1381 cmdChangeClick(Sender);
1382end;
1383
1384procedure TfrmSurgery.mnuActLoadBoilerClick(Sender: TObject);
1385var
1386 NoteEmpty: Boolean;
1387 BoilerText: TStringList;
1388 DocInfo: string;
1389
1390 procedure AssignBoilerText;
1391 begin
1392 ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
1393 memNewNote.Lines.Assign(BoilerText);
1394 FChanged := False;
1395 end;
1396
1397begin
1398 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1399 inherited;
1400 if (FEditingIndex < 0) or (lstNotes.ItemIndex <> FEditingIndex) then Exit;
1401 BoilerText := TStringList.Create;
1402 try
1403 NoteEmpty := memNewNote.Text = '';
1404 LoadBoilerPlate(BoilerText, FEditNote.Title);
1405 if (BoilerText.Text <> '') or
1406 assigned(GetLinkedTemplate(IntToStr(FEditNote.Title), ltTitle)) then
1407 begin
1408 if NoteEmpty then AssignBoilerText else
1409 begin
1410 DocInfo := MakeXMLParamTIU(IntToStr(lstNotes.ItemIEN), FEditNote);
1411 case QueryBoilerPlate(BoilerText) of
1412 0: { do nothing } ; // ignore
1413 1: begin
1414 ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
1415 memNewNote.Lines.AddStrings(BoilerText); // append
1416 end;
1417 2: AssignBoilerText; // replace
1418 end;
1419 end;
1420 end else
1421 begin
1422 if Sender = mnuActLoadBoiler
1423 then InfoBox(TX_NO_BOIL, TC_NO_BOIL, MB_OK)
1424 else
1425 begin
1426 if not NoteEmpty then
1427 if not FChanged and (InfoBox(TX_BLR_CLEAR, TC_BLR_CLEAR, MB_YESNO) = ID_YES)
1428 then memNewNote.Lines.Clear;
1429 end;
1430 end; {if BoilerText.Text <> ''}
1431 finally
1432 BoilerText.Free;
1433 end;
1434end;
1435
1436procedure TfrmSurgery.cmdChangeClick(Sender: TObject);
1437const
1438 IS_ID_CHILD = False;
1439var
1440 LastTitle: Integer;
1441 OKPressed: boolean;
1442 x, AClassName: string;
1443begin
1444 inherited;
1445 LastTitle := FEditNote.Title;
1446 if IsNonORProcedure(FEditNote.PkgIEN) then AClassName := DCL_SURG_NON_OR else AClassName := DCL_SURG_OR;
1447 if Sender <> Self then OKPressed := ExecuteNoteProperties(FEditNote, CT_SURGERY, IS_ID_CHILD, IS_ID_CHILD, AClassName, 0)
1448 else OKPressed := True;
1449 if not OKPressed then Exit;
1450 // update display fields & uPCEEdit
1451 lblNewTitle.Caption := ' ' + FEditNote.TitleName + ' ';
1452//if (FEditNote.Addend > 0) and (CompareText(Copy(lblNewTitle.Caption, 2, 8), 'Addendum') <> 0) <-- original line. //kt 8/7/2007
1453 if (FEditNote.Addend > 0) and (CompareText(Copy(lblNewTitle.Caption, 2, 8), DKLangConstW('fSurgery_Addendum')) <> 0) //kt added 8/7/2007
1454// then lblNewTitle.Caption := ' Addendum to:' + lblNewTitle.Caption; <-- original line. //kt 8/7/2007
1455 then lblNewTitle.Caption := DKLangConstW('fSurgery_Addendum_tox') + lblNewTitle.Caption; //kt added 8/7/2007
1456 with lblNewTitle do bvlNewTitle.SetBounds(Left - 1, Top - 1, Width + 2, Height + 2);
1457 lblRefDate.Caption := FormatFMDateTime('mmm dd,yyyy@hh:nn', FEditNote.DateTime);
1458 lblAuthor.Caption := FEditNote.AuthorName;
1459 if uPCEEdit.Inpatient then x := 'Adm: ' else x := 'Vst: ';
1460 x := x + FormatFMDateTime('mm/dd/yy', FEditNote.VisitDate) + ' ' + FEditNote.LocationName;
1461 lblVisit.Caption := x;
1462 if Length(FEditNote.CosignerName) > 0
1463// then lblCosigner.Caption := 'Expected Cosigner: ' + FEditNote.CosignerName <-- original line. //kt 8/7/2007
1464 then lblCosigner.Caption := DKLangConstW('fSurgery_Expected_Cosignerx') + FEditNote.CosignerName //kt added 8/7/2007
1465 else lblCosigner.Caption := '';
1466 uPCEEdit.NoteTitle := FEditNote.Title;
1467 // modify signature requirements if author or cosigner changed
1468 if (User.DUZ <> FEditNote.Author) and (User.DUZ <> FEditNote.Cosigner)
1469 then Changes.ReplaceSignState(CH_SUR, lstNotes.ItemID, CH_SIGN_NA)
1470 else Changes.ReplaceSignState(CH_SUR, lstNotes.ItemID, CH_SIGN_YES);
1471 x := lstNotes.Items[EditingIndex];
1472 SetPiece(x, U, 2, lblNewTitle.Caption);
1473 SetPiece(x, U, 3, FloatToStr(FEditNote.DateTime));
1474 tvSurgery.Selected.Text := MakeNoteDisplayText(x);
1475 TORTreeNode(tvSurgery.Selected).StringData := x;
1476 lstNotes.Items[EditingIndex] := x;
1477 Changes.ReplaceText(CH_SUR, lstNotes.ItemID, GetTitleText(EditingIndex));
1478 if LastTitle <> FEditNote.Title then mnuActLoadBoilerClick(Self);
1479end;
1480
1481procedure TfrmSurgery.memNewNoteChange(Sender: TObject);
1482begin
1483 inherited;
1484 FChanged := True;
1485end;
1486
1487procedure TfrmSurgery.pnlFieldsResize(Sender: TObject);
1488{ center the reference date on the panel }
1489begin
1490 inherited;
1491 lblRefDate.Left := (pnlFields.Width - lblRefDate.Width) div 2;
1492 if lblRefDate.Left < (lblNewTitle.Left + lblNewTitle.Width + 6)
1493 then lblRefDate.Left := (lblNewTitle.Left + lblNewTitle.Width);
1494end;
1495
1496procedure TfrmSurgery.DoAutoSave(Suppress: integer = 1);
1497var
1498 ErrMsg: string;
1499begin
1500 if (EditingIndex > -1) and FChanged then
1501 begin
1502// StatusText('Autosaving note...'); <-- original line. //kt 8/7/2007
1503 StatusText(DKLangConstW('fSurgery_Autosaving_notexxx')); //kt added 8/7/2007
1504 //PutTextOnly(ErrMsg, memNewNote.Lines, lstNotes.GetIEN(EditingIndex));
1505 timAutoSave.Enabled := False;
1506 try
1507 SetText(ErrMsg, memNewNote.Lines, lstNotes.GetIEN(EditingIndex), Suppress);
1508 finally
1509 timAutoSave.Enabled := True;
1510 end;
1511 FChanged := False;
1512 StatusText('');
1513 end;
1514 if ErrMsg <> '' then
1515 InfoBox(TX_SAVE_ERROR1 + ErrMsg + TX_SAVE_ERROR2, TC_SAVE_ERROR, MB_OK or MB_ICONWARNING);
1516 //Assert(ErrMsg = '', 'AutoSave: ' + ErrMsg);
1517end;
1518
1519procedure TfrmSurgery.timAutoSaveTimer(Sender: TObject);
1520begin
1521 inherited;
1522 DoAutoSave;
1523end;
1524
1525{ Action menu events ----------------------------------------------------------------------- }
1526
1527function TfrmSurgery.StartNewEdit(NewNoteType: integer): Boolean;
1528{ if currently editing a note, returns TRUE if the user wants to start a new one }
1529var
1530 Saved: Boolean;
1531 Msg, CapMsg: string;
1532begin
1533 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1534 Result := True;
1535 if EditingIndex > -1 then
1536 begin
1537 case NewNoteType of
1538 NT_ACT_ADDENDUM: begin
1539 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE3;
1540 CapMsg := TC_NEW_SAVE3;
1541 end;
1542 NT_ACT_EDIT_NOTE: begin
1543 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE4;
1544 CapMsg := TC_NEW_SAVE4;
1545 end;
1546 else
1547 begin
1548 Msg := TX_NEW_SAVE1 + MakeNoteDisplayText(lstNotes.Items[EditingIndex]) + TX_NEW_SAVE2;
1549 CapMsg := TC_NEW_SAVE2;
1550 end;
1551 end;
1552 if InfoBox(Msg, CapMsg, MB_YESNO) = IDNO then Result := False
1553 else
1554 begin
1555 SaveCurrentNote(Saved);
1556 if not Saved then Result := False else LoadSurgeryCases;
1557 end;
1558 end;
1559end;
1560
1561procedure TfrmSurgery.mnuActNewClick(Sender: TObject);
1562const
1563 IS_ID_CHILD = False;
1564{ switches to current new note or creates a new note if none is being edited already }
1565begin
1566 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1567 inherited;
1568 if not StartNewEdit(NT_ACT_NEW_NOTE) then Exit;
1569 //LoadNotes;
1570 // make sure a visit (time & location) is available before creating the note
1571 if Encounter.NeedVisit then
1572 begin
1573 UpdateVisit(Font.Size, DfltTIULocation);
1574 frmFrame.DisplayEncounterText;
1575 end;
1576 if Encounter.NeedVisit then
1577 begin
1578 InfoBox(TX_NEED_VISIT, TX_NO_VISIT, MB_OK or MB_ICONWARNING);
1579 Exit;
1580 end;
1581 InsertNewNote(IS_ID_CHILD, 0);
1582end;
1583
1584
1585procedure TfrmSurgery.mnuActAddendClick(Sender: TObject);
1586{ make an addendum to an existing note }
1587var
1588 ActionSts: TActionRec;
1589 ANoteID: string;
1590begin
1591 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1592 inherited;
1593 if lstNotes.ItemIEN <= 0 then Exit;
1594 ANoteID := lstNotes.ItemID;
1595 if not StartNewEdit(NT_ACT_ADDENDUM) then Exit;
1596 //LoadNotes;
1597 with tvSurgery do Selected := FindPieceNode(ANoteID, 1, U, Items.GetFirstNode);
1598 if lstNotes.ItemIndex = EditingIndex then
1599 begin
1600 InfoBox(TX_ADDEND_NO, TX_ADDEND_MK, MB_OK);
1601 Exit;
1602 end;
1603 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'MAKE ADDENDUM');
1604 if not ActionSts.Success then
1605 begin
1606 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1607 Exit;
1608 end;
1609 with lstNotes do if TitleForNote(lstNotes.ItemIEN) = TYP_ADDENDUM then
1610 begin
1611 InfoBox(TX_ADDEND_AD, TX_ADDEND_MK, MB_OK);
1612 Exit;
1613 end;
1614 InsertAddendum;
1615end;
1616
1617
1618procedure TfrmSurgery.mnuActSignListClick(Sender: TObject);
1619{ add the note to the Encounter object, see mnuActSignClick - copied}
1620const
1621 SIG_COSIGN = 'COSIGNATURE';
1622 SIG_SIGN = 'SIGNATURE';
1623var
1624 ActionType, SignTitle: string;
1625 ActionSts: TActionRec;
1626begin
1627 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1628 inherited;
1629 if lstNotes.ItemIEN = 0 then Exit;
1630 if lstNotes.ItemIndex = EditingIndex then Exit; // already in signature list
1631 if not NoteHasText(lstNotes.ItemIEN) then
1632 begin
1633 InfoBox(TX_EMPTY_NOTE1, TC_EMPTY_NOTE, MB_OK or MB_ICONERROR);
1634 Exit;
1635 end;
1636 if not LastSaveClean(lstNotes.ItemIEN) and
1637 (InfoBox(TX_ABSAVE, TC_ABSAVE, MB_YESNO or MB_DEFBUTTON2 or MB_ICONWARNING) <> IDYES) then Exit;
1638 if CosignDocument(lstNotes.ItemIEN) then
1639 begin
1640 SignTitle := TX_COSIGN;
1641 ActionType := SIG_COSIGN;
1642 end else
1643 begin
1644 SignTitle := TX_SIGN;
1645 ActionType := SIG_SIGN;
1646 end;
1647 ActOnDocument(ActionSts, lstNotes.ItemIEN, ActionType);
1648 if not ActionSts.Success then
1649 begin
1650 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1651 Exit;
1652 end;
1653 with lstNotes do Changes.Add(CH_SUR, ItemID, GetTitleText(ItemIndex), '', CH_SIGN_YES);
1654end;
1655
1656procedure TfrmSurgery.RemovePCEFromChanges(IEN: Int64; AVisitStr: string = '');
1657begin
1658 if IEN = NT_ADDENDUM then Exit; // no PCE information entered for an addendum
1659 // do we need to call DeletePCE(AVisitStr), as was done with NT_NEW_NOTE (ien=-10)???
1660 if AVisitStr = '' then AVisitStr := VisitStrForNote(IEN);
1661 Changes.Remove(CH_PCE, 'V' + AVisitStr);
1662 Changes.Remove(CH_PCE, 'P' + AVisitStr);
1663 Changes.Remove(CH_PCE, 'D' + AVisitStr);
1664 Changes.Remove(CH_PCE, 'I' + AVisitStr);
1665 Changes.Remove(CH_PCE, 'S' + AVisitStr);
1666 Changes.Remove(CH_PCE, 'A' + AVisitStr);
1667 Changes.Remove(CH_PCE, 'H' + AVisitStr);
1668 Changes.Remove(CH_PCE, 'E' + AVisitStr);
1669 Changes.Remove(CH_PCE, 'T' + AVisitStr);
1670end;
1671
1672procedure TfrmSurgery.mnuActDeleteClick(Sender: TObject);
1673{ delete the selected progress note & remove from the Encounter object if necessary }
1674var
1675 DeleteSts, ActionSts: TActionRec;
1676 SavedDocIEN: Integer;
1677 ReasonForDelete, AVisitStr, SavedDocID, ErrMsg: string;
1678 Saved: boolean;
1679begin
1680 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1681 inherited;
1682 if lstNotes.ItemIEN = 0 then Exit;
1683 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'DELETE RECORD');
1684 if ShowMsgOn(not ActionSts.Success, ActionSts.Reason, TX_IN_AUTH) then Exit;
1685 ReasonForDelete := SelectDeleteReason(lstNotes.ItemIEN);
1686 if ReasonForDelete = DR_CANCEL then Exit;
1687 // suppress prompt for deletion when called from SaveEditedNote (Sender = Self)
1688 if (Sender <> Self) and (InfoBox(MakeNoteDisplayText(lstNotes.Items[lstNotes.ItemIndex]) + TX_DEL_OK,
1689 TX_DEL_CNF, MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) <> IDYES) then Exit;
1690 // do the appropriate locking
1691 ErrMsg := '';
1692 LockDocument(lstNotes.ItemIEN, ErrMsg);
1693 if ErrMsg <> '' then
1694 begin
1695 InfoBox(ErrMsg, TC_NO_LOCK, MB_OK);
1696 Exit;
1697 end;
1698 // retraction notification message
1699 if JustifyDocumentDelete(lstNotes.ItemIEN) then
1700 InfoBox(TX_RETRACT, TX_RETRACT_CAP, MB_OK);
1701 SavedDocID := lstNotes.ItemID;
1702 SavedDocIEN := lstNotes.ItemIEN;
1703 if (EditingIndex > -1) and (not FConfirmed) and (lstNotes.ItemIndex <> EditingIndex) and (memNewNote.GetTextLen > 0) then
1704 begin
1705 SaveCurrentNote(Saved);
1706 if not Saved then Exit;
1707 end;
1708 EditingIndex := -1;
1709 FConfirmed := False;
1710 // remove the note
1711 DeleteSts.Success := True;
1712 AVisitStr := VisitStrForNote(SavedDocIEN);
1713 RemovePCEFromChanges(SavedDocIEN, AVisitStr);
1714 if (SavedDocIEN > 0) and (lstNotes.ItemIEN = SavedDocIEN) then DeleteDocument(DeleteSts, SavedDocIEN, ReasonForDelete);
1715 if not Changes.Exist(CH_SUR, SavedDocID) then UnlockDocument(SavedDocIEN);
1716 Changes.Remove(CH_SUR, SavedDocID); // this will unlock the document if in Changes
1717 // reset the display now that the note is gone
1718 if DeleteSts.Success then
1719 begin
1720 DeletePCE(AVisitStr); // removes PCE data if this was the only note pointing to it
1721 ClearEditControls;
1722 LoadSurgeryCases;
1723 pnlWrite.Visible := False;
1724 pnlRead.Visible := True;
1725 UpdateReminderFinish;
1726 ShowPCEControls(False);
1727 frmDrawers.DisplayDrawers(TRUE, [odTemplates], [odTemplates]); //FALSE);
1728 ShowPCEButtons(FALSE);
1729 //end; {if ItemIndex}
1730 end {if DeleteSts}
1731 else InfoBox(DeleteSts.Reason, TX_DEL_ERR, MB_OK or MB_ICONWARNING);
1732end;
1733
1734procedure TfrmSurgery.mnuActEditClick(Sender: TObject);
1735{ load the selected progress note for editing }
1736var
1737 ActionSts: TActionRec;
1738 ANoteID: string;
1739begin
1740 inherited;
1741 if lstNotes.ItemIndex = EditingIndex then Exit;
1742 ANoteID := lstNotes.ItemID;
1743 if not StartNewEdit(NT_ACT_EDIT_NOTE) then Exit;
1744 //LoadNotes;
1745 with tvSurgery do Selected := FindPieceNode(ANoteID, 1, U, Items.GetFirstNode);
1746 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'EDIT RECORD');
1747 if not ActionSts.Success then
1748 begin
1749 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1750 Exit;
1751 end;
1752 LoadForEdit;
1753end;
1754
1755procedure TfrmSurgery.mnuActSaveClick(Sender: TObject);
1756{ saves the note that is currently being edited }
1757var
1758 Saved: Boolean;
1759 SavedDocID: string;
1760begin
1761 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1762 inherited;
1763 if EditingIndex > -1 then
1764 begin
1765 SavedDocID := Piece(lstNotes.Items[EditingIndex], U, 1);
1766 FLastNoteID := SavedDocID;
1767 SaveCurrentNote(Saved);
1768 if Saved and (EditingIndex < 0) and (not FDeleted) then
1769 //if Saved then
1770 begin
1771 LoadSurgeryCases;
1772 with tvSurgery do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
1773 end;
1774 end
1775 else InfoBox(TX_NO_NOTE, TX_SAVE_NOTE, MB_OK or MB_ICONWARNING);
1776end;
1777
1778procedure TfrmSurgery.mnuActSignClick(Sender: TObject);
1779{ sign the currently selected note, save first if necessary }
1780const
1781 SIG_COSIGN = 'COSIGNATURE';
1782 SIG_SIGN = 'SIGNATURE';
1783var
1784 Saved, NoteUnlocked: Boolean;
1785 ActionType, ESCode, SignTitle: string;
1786 ActionSts, SignSts: TActionRec;
1787 OK: boolean;
1788 SavedDocID, tmpItem: string;
1789 EditingID: string; //v22.12 - RV
1790 tmpNode: TTreeNode;
1791begin
1792 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1793 inherited;
1794(* if lstNotes.ItemIndex = EditingIndex then //v22.12 - RV
1795 begin //v22.12 - RV
1796 SaveCurrentNote(Saved); //v22.12 - RV
1797 if (not Saved) or FDeleted then Exit; //v22.12 - RV
1798 end //v22.12 - RV
1799 else if EditingIndex > -1 then //v22.12 - RV
1800 tmpItem := lstNotes.Items[EditingIndex]; //v22.12 - RV
1801 SavedDocID := lstNotes.ItemID;*) //v22.12 - RV
1802 SavedDocID := lstNotes.ItemID; //v22.12 - RV
1803 FLastNoteID := SavedDocID; //v22.12 - RV
1804 if lstNotes.ItemIndex = EditingIndex then //v22.12 - RV
1805 begin //v22.12 - RV
1806 SaveCurrentNote(Saved); //v22.12 - RV
1807 if (not Saved) or FDeleted then Exit; //v22.12 - RV
1808 end //v22.12 - RV
1809 else if EditingIndex > -1 then //v22.12 - RV
1810 begin //v22.12 - RV
1811 tmpItem := lstNotes.Items[EditingIndex]; //v22.12 - RV
1812 EditingID := Piece(tmpItem, U, 1); //v22.12 - RV
1813 end; //v22.12 - RV
1814 if not NoteHasText(lstNotes.ItemIEN) then
1815 begin
1816 InfoBox(TX_EMPTY_NOTE1, TC_EMPTY_NOTE, MB_OK or MB_ICONERROR);
1817 Exit;
1818 end;
1819 if not LastSaveClean(lstNotes.ItemIEN) and
1820 (InfoBox(TX_ABSAVE, TC_ABSAVE, MB_YESNO or MB_DEFBUTTON2 or MB_ICONWARNING) <> IDYES) then Exit;
1821 if CosignDocument(lstNotes.ItemIEN) then
1822 begin
1823 SignTitle := TX_COSIGN;
1824 ActionType := SIG_COSIGN;
1825 end else
1826 begin
1827 SignTitle := TX_SIGN;
1828 ActionType := SIG_SIGN;
1829 end;
1830 // no exits after things are locked
1831 NoteUnlocked := False;
1832 ActOnDocument(ActionSts, lstNotes.ItemIEN, ActionType);
1833 if ActionSts.Success then
1834 begin
1835 OK := IsOK2Sign(uPCEShow, lstNotes.ItemIEN);
1836 if frmFrame.Closing then exit;
1837 if(uPCEShow.Updated) then
1838 begin
1839 uPCEShow.CopyPCEData(uPCEEdit);
1840 uPCEShow.Updated := FALSE;
1841 lstNotesClick(Self);
1842 end;
1843 if(OK) then
1844 begin
1845 //DisplayOpTop(lstNotes.ItemIEN); v24.2 - RV
1846 with lstNotes do SignatureForItem(Font.Size, MakeNoteDisplayText(Items[ItemIndex]), SignTitle, ESCode);
1847 if Length(ESCode) > 0 then
1848 begin
1849 SignDocument(SignSts, lstNotes.ItemIEN, ESCode);
1850 RemovePCEFromChanges(lstNotes.ItemIEN);
1851 NoteUnlocked := Changes.Exist(CH_SUR, lstNotes.ItemID);
1852 Changes.Remove(CH_SUR, lstNotes.ItemID); // this will unlock if in Changes
1853 if SignSts.Success then
1854 begin
1855 SendMessage(frmConsults.Handle, UM_NEWORDER, ORDER_SIGN, 0); {*REV*}
1856 lstNotesClick(Self);
1857 end
1858 else InfoBox(SignSts.Reason, TX_SIGN_ERR, MB_OK);
1859 end; {if Length(ESCode)}
1860 end;
1861 end
1862 else InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1863 if not NoteUnlocked then UnlockDocument(lstNotes.ItemIEN);
1864 LoadSurgeryCases;
1865 //if EditingIndex > -1 then //v22.12 - RV
1866 if (EditingID <> '') then //v22.12 - RV
1867 begin
1868 lstNotes.Items.Insert(0, tmpItem);
1869// tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, 'Note being edited', <-- original line. //kt 8/7/2007
1870 tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, DKLangConstW('fSurgery_Note_being_edited'), //kt added 8/7/2007
1871 MakeCaseTreeObject('EDIT^Note being edited^^^^^^^^^^^%^0'));
1872 TORTreeNode(tmpNode).StringData := 'EDIT^Note being edited^^^^^^^^^^^%^0';
1873 tmpNode.ImageIndex := IMG_SURG_TOP_LEVEL;
1874 tmpNode := tvSurgery.Items.AddChildObjectFirst(tmpNode, MakeNoteDisplayText(tmpItem), MakeCaseTreeObject(tmpItem));
1875 TORTreeNode(tmpNode).StringData := tmpItem;
1876 SetCaseTreeNodeImagesAndFormatting(TORTreeNode(tmpNode), FCurrentContext);
1877 EditingIndex := lstNotes.SelectByID(EditingID); //v22.12 - RV
1878 end;
1879 //with tvSurgery do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode); //v22.12 - RV
1880 with tvSurgery do //v22.12 - RV
1881 begin //v22.12 - RV
1882 Selected := FindPieceNode(FLastNoteID, U, Items.GetFirstNode); //v22.12 - RV
1883 if Selected <> nil then tvSurgeryChange(Self, Selected); //v22.12 - RV
1884 end; //v22.12 - RV
1885end;
1886
1887procedure TfrmSurgery.SaveSignItem(const ItemID, ESCode: string);
1888{ saves and optionally signs a progress note or addendum }
1889const
1890 SIG_COSIGN = 'COSIGNATURE';
1891 SIG_SIGN = 'SIGNATURE';
1892var
1893 AnIndex, IEN, i: Integer;
1894 Saved, ContinueSign: Boolean; {*RAB* 8/26/99}
1895 ActionSts, SignSts: TActionRec;
1896 APCEObject: TPCEData;
1897 OK: boolean;
1898 ActionType, SignTitle: string;
1899begin
1900 SetupVars; //kt added 8/7/2007 to replace constants with vars.
1901 AnIndex := -1;
1902 IEN := StrToIntDef(ItemID, 0);
1903 if IEN = 0 then Exit;
1904 if frmFrame.TimedOut and (EditingIndex <> -1) then FSilent := True;
1905 with lstNotes do for i := 0 to Items.Count - 1 do if lstNotes.GetIEN(i) = IEN then
1906 begin
1907 AnIndex := i;
1908 break;
1909 end;
1910 if (AnIndex > -1) and (AnIndex = EditingIndex) then
1911 begin
1912 SaveCurrentNote(Saved);
1913 if not Saved then Exit;
1914 if FDeleted then
1915 begin
1916 FDeleted := False;
1917 Exit;
1918 end;
1919 AnIndex := lstNotes.SelectByIEN(IEN);
1920 //IEN := lstNotes.GetIEN(AnIndex); // saving will change IEN
1921 end;
1922 if Length(ESCode) > 0 then
1923 begin
1924 if CosignDocument(IEN) then
1925 begin
1926 SignTitle := TX_COSIGN;
1927 ActionType := SIG_COSIGN;
1928 end else
1929 begin
1930 SignTitle := TX_SIGN;
1931 ActionType := SIG_SIGN;
1932 end;
1933 ActOnDocument(ActionSts, IEN, ActionType);
1934 if not ActionSts.Success then
1935 begin
1936 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
1937 ContinueSign := False;
1938 end
1939 else if not NoteHasText(IEN) then
1940 begin
1941 InfoBox(TX_EMPTY_NOTE1, TC_EMPTY_NOTE, MB_OK or MB_ICONERROR);
1942 ContinueSign := False;
1943 end
1944 else if not LastSaveClean(IEN) and
1945 (InfoBox(TX_ABSAVE, TC_ABSAVE, MB_YESNO or MB_DEFBUTTON2 or MB_ICONWARNING) <> IDYES)
1946 then ContinueSign := False
1947 else ContinueSign := True;
1948 if ContinueSign then
1949 begin
1950 if (AnIndex >= 0) and (AnIndex = lstNotes.ItemIndex) then
1951 APCEObject := uPCEShow
1952 else
1953 APCEObject := nil;
1954 OK := IsOK2Sign(APCEObject, IEN);
1955 if frmFrame.Closing then exit;
1956 if(assigned(APCEObject)) and (uPCEShow.Updated) then
1957 begin
1958 uPCEShow.CopyPCEData(uPCEEdit);
1959 uPCEShow.Updated := FALSE;
1960 lstNotesClick(Self);
1961 end
1962 else
1963 uPCEEdit.Clear;
1964 if(OK) then
1965 begin
1966 //if not FSilent then DisplayOpTop(IEN);
1967 SignDocument(SignSts, IEN, ESCode);
1968 if not SignSts.Success then InfoBox(SignSts.Reason, TX_SIGN_ERR, MB_OK);
1969 end; {if OK}
1970 end; {if ContinueSign}
1971 end; {if Length(ESCode)}
1972
1973 if (AnIndex = lstNotes.ItemIndex) and (not frmFrame.ContextChanging) then
1974 begin
1975 LoadSurgeryCases; //????????????????
1976 with tvSurgery do Selected := FindPieceNode(IntToStr(IEN), U, Items.GetFirstNode);
1977 end;
1978end;
1979
1980procedure TfrmSurgery.popNoteMemoPopup(Sender: TObject);
1981begin
1982 inherited;
1983 if PopupComponent(Sender, popNoteMemo) is TCustomEdit
1984 then FEditCtrl := TCustomEdit(PopupComponent(Sender, popNoteMemo))
1985 else FEditCtrl := nil;
1986 if FEditCtrl <> nil then
1987 begin
1988 popNoteMemoCut.Enabled := FEditCtrl.SelLength > 0;
1989 popNoteMemoCopy.Enabled := popNoteMemoCut.Enabled;
1990 popNoteMemoPaste.Enabled := (not TORExposedCustomEdit(FEditCtrl).ReadOnly) and
1991 Clipboard.HasFormat(CF_TEXT);
1992 popNoteMemoTemplate.Enabled := frmDrawers.CanEditTemplates and popNoteMemoCut.Enabled;
1993 popNoteMemoFind.Enabled := FEditCtrl.GetTextLen > 0;
1994 end else
1995 begin
1996 popNoteMemoCut.Enabled := False;
1997 popNoteMemoCopy.Enabled := False;
1998 popNoteMemoPaste.Enabled := False;
1999 popNoteMemoTemplate.Enabled := False;
2000 end;
2001 if pnlWrite.Visible then
2002 begin
2003 popNoteMemoSpell.Enabled := True;
2004 popNoteMemoGrammar.Enabled := True;
2005 popNoteMemoReformat.Enabled := True;
2006 popNoteMemoReplace.Enabled := (FEditCtrl.GetTextLen > 0);
2007 popNoteMemoPreview.Enabled := (frmDrawers.TheOpenDrawer = odTemplates) and Assigned(frmDrawers.tvTemplates.Selected);
2008 popNoteMemoInsTemplate.Enabled := (frmDrawers.TheOpenDrawer = odTemplates) and Assigned(frmDrawers.tvTemplates.Selected);
2009 end else
2010 begin
2011 popNoteMemoSpell.Enabled := False;
2012 popNoteMemoGrammar.Enabled := False;
2013 popNoteMemoReformat.Enabled := False;
2014 popNoteMemoReplace.Enabled := False;
2015 popNoteMemoPreview.Enabled := False;
2016 popNoteMemoInsTemplate.Enabled := False;
2017 end;
2018end;
2019
2020procedure TfrmSurgery.popNoteMemoCutClick(Sender: TObject);
2021begin
2022 inherited;
2023 FEditCtrl.CutToClipboard;
2024end;
2025
2026procedure TfrmSurgery.popNoteMemoCopyClick(Sender: TObject);
2027begin
2028 inherited;
2029 FEditCtrl.CopyToClipboard;
2030end;
2031
2032procedure TfrmSurgery.popNoteMemoPasteClick(Sender: TObject);
2033begin
2034 inherited;
2035 FEditCtrl.SelText := Clipboard.AsText; {*KCM*}
2036 //FEditCtrl.PasteFromClipboard; // use AsText to prevent formatting
2037end;
2038
2039procedure TfrmSurgery.popNoteMemoReformatClick(Sender: TObject);
2040begin
2041 inherited;
2042 if Screen.ActiveControl <> memNewNote then Exit;
2043 ReformatMemoParagraph(memNewNote);
2044end;
2045
2046procedure TfrmSurgery.popNoteMemoSaveContinueClick(Sender: TObject);
2047begin
2048 inherited;
2049 FChanged := True;
2050 DoAutoSave;
2051end;
2052
2053procedure TfrmSurgery.popNoteMemoReplaceClick(Sender: TObject);
2054begin
2055 inherited;
2056 SendMessage(TRichEdit(popNoteMemo.PopupComponent).Handle, WM_VSCROLL, SB_TOP, 0);
2057 with dlgReplaceText do
2058 begin
2059 Position := Point(Application.MainForm.Left + pnlLeft.Width, Application.MainForm.Top);
2060 FindText := '';
2061 ReplaceText := '';
2062 Options := [frDown, frHideUpDown];
2063 Execute;
2064 end;
2065end;
2066
2067procedure TfrmSurgery.dlgReplaceTextFind(Sender: TObject);
2068begin
2069 inherited;
2070 dmodShared.FindRichEditText(dlgFindText, TRichEdit(popNoteMemo.PopupComponent));
2071end;
2072
2073procedure TfrmSurgery.dlgReplaceTextReplace(Sender: TObject);
2074begin
2075 inherited;
2076 dmodShared.ReplaceRichEditText(dlgReplaceText, TRichEdit(popNoteMemo.PopupComponent));
2077end;
2078
2079procedure TfrmSurgery.popNoteMemoSpellClick(Sender: TObject);
2080begin
2081 inherited;
2082 DoAutoSave(0);
2083 timAutoSave.Enabled := False;
2084 try
2085 SpellCheckForControl(memNewNote);
2086 finally
2087 FChanged := True;
2088 DoAutoSave(0);
2089 timAutoSave.Enabled := True;
2090 end;
2091end;
2092
2093procedure TfrmSurgery.popNoteMemoGrammarClick(Sender: TObject);
2094begin
2095 inherited;
2096 DoAutoSave(0);
2097 timAutoSave.Enabled := False;
2098 try
2099 GrammarCheckForControl(memNewNote);
2100 finally
2101 FChanged := True;
2102 DoAutoSave(0);
2103 timAutoSave.Enabled := True;
2104 end;
2105end;
2106
2107procedure TfrmSurgery.mnuViewDetailClick(Sender: TObject);
2108var
2109 x: string;
2110begin
2111 inherited;
2112 with tvSurgery do
2113 begin
2114 if Selected = nil then exit;
2115 if not (Selected.ImageIndex in [IMG_SURG_TOP_LEVEL, IMG_SURG_GROUP_SHUT, IMG_SURG_GROUP_OPEN,
2116 IMG_SURG_NON_OR_CASE_EMPTY, IMG_SURG_NON_OR_CASE_SHUT, IMG_SURG_NON_OR_CASE_OPEN,
2117 IMG_SURG_CASE_EMPTY, IMG_SURG_CASE_SHUT, IMG_SURG_CASE_OPEN]) then
2118 begin
2119 mnuViewDetail.Checked := not mnuViewDetail.Checked;
2120 if mnuViewDetail.Checked then
2121 begin
2122 x := TORTreeNode(Selected).StringData;
2123// StatusText('Retrieving selected surgery report details...'); <-- original line. //kt 8/7/2007
2124 StatusText(DKLangConstW('fSurgery_Retrieving_selected_surgery_report_detailsxxx')); //kt added 8/7/2007
2125 pnlRead.Visible := True;
2126 pnlWrite.Visible := False;
2127 Screen.Cursor := crHourGlass;
2128 LoadSurgReportDetail(memSurgery.Lines, StrToIntDef(Piece(x, U, 1), 0));
2129 Screen.Cursor := crDefault;
2130 StatusText('');
2131 memSurgery.SelStart := 0;
2132 memSurgery.Repaint;
2133 end
2134 else
2135 tvSurgeryChange(Self, Selected);
2136 end;
2137 end;
2138 SendMessage(memSurgery.Handle, WM_VSCROLL, SB_TOP, 0);
2139end;
2140
2141procedure TfrmSurgery.FormClose(Sender: TObject; var Action: TCloseAction);
2142var
2143 Saved: Boolean;
2144 IEN: Int64;
2145 ErrMsg: string;
2146 DeleteSts: TActionRec;
2147begin
2148 inherited;
2149 if frmFrame.TimedOut and (EditingIndex <> -1) then
2150 begin
2151 FSilent := True;
2152 if memNewNote.GetTextLen > 0 then SaveCurrentNote(Saved)
2153 else
2154 begin
2155 IEN := lstNotes.GetIEN(EditingIndex);
2156 if not LastSaveClean(IEN) then // means note hasn't been committed yet
2157 begin
2158 LockDocument(IEN, ErrMsg);
2159 if ErrMsg = '' then
2160 begin
2161 DeleteDocument(DeleteSts, IEN, '');
2162 UnlockDocument(IEN);
2163 end; {if ErrMsg}
2164 end; {if not LastSaveClean}
2165 end; {else}
2166 end; {if frmFrame}
2167end;
2168
2169procedure TfrmSurgery.mnuActIdentifyAddlSignersClick(Sender: TObject);
2170var
2171 Exclusions: TStrings;
2172 Saved, x, y: boolean;
2173 SignerList: TSignerList;
2174 ActionSts: TActionRec;
2175 SigAction: integer;
2176 SavedDocID: string;
2177 ARefDate: TFMDateTime;
2178begin
2179 inherited;
2180 if lstNotes.ItemIEN = 0 then exit;
2181 SavedDocID := lstNotes.ItemID;
2182 if lstNotes.ItemIndex = EditingIndex then
2183 begin
2184 SaveCurrentNote(Saved);
2185 if not Saved then Exit;
2186 LoadSurgeryCases;
2187 with tvSurgery do Selected := FindPieceNode(SavedDocID, U, Items.GetFirstNode);
2188 end;
2189 x := CanChangeCosigner(lstNotes.ItemIEN);
2190 ActOnDocument(ActionSts, lstNotes.ItemIEN, 'IDENTIFY SIGNERS');
2191 y := ActionSts.Success;
2192 if x and not y then
2193 begin
2194 if InfoBox(ActionSts.Reason + CRLF + CRLF +
2195// 'Would you like to change the cosigner?', <-- original line. //kt 8/7/2007
2196 DKLangConstW('fSurgery_Would_you_like_to_change_the_cosignerx'), //kt added 8/7/2007
2197 TX_IN_AUTH, MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) = ID_YES then
2198 SigAction := SG_COSIGNER
2199 else
2200 Exit;
2201 end
2202 else if y and not x then SigAction := SG_ADDITIONAL
2203 else if x and y then SigAction := SG_BOTH
2204 else
2205 begin
2206 InfoBox(ActionSts.Reason, TX_IN_AUTH, MB_OK);
2207 Exit;
2208 end;
2209
2210 Exclusions := GetCurrentSigners(lstNotes.ItemIEN);
2211 ARefDate := StrToFloat(Piece(lstNotes.Items[lstNotes.ItemIndex], U, 3));
2212 SelectAdditionalSigners(Font.Size, lstNotes.ItemIEN, SigAction, Exclusions, SignerList, CT_NOTES, ARefDate);
2213 with SignerList do
2214 begin
2215 case SigAction of
2216 SG_ADDITIONAL: if Changed and (Signers <> nil) and (Signers.Count > 0) then
2217 UpdateAdditionalSigners(lstNotes.ItemIEN, Signers);
2218 SG_COSIGNER: if Changed then ChangeCosigner(lstNotes.ItemIEN, Cosigner);
2219 SG_BOTH: if Changed then
2220 begin
2221 if (Signers <> nil) and (Signers.Count > 0) then
2222 UpdateAdditionalSigners(lstNotes.ItemIEN, Signers);
2223 ChangeCosigner(lstNotes.ItemIEN, Cosigner);
2224 end;
2225 end;
2226 lstNotesClick(Self);
2227 end;
2228 UnlockDocument(lstNotes.ItemIEN);
2229end;
2230
2231procedure TfrmSurgery.popNoteMemoAddlSignClick(Sender: TObject);
2232begin
2233 inherited;
2234 mnuActIdentifyAddlSignersClick(Self);
2235end;
2236
2237procedure TfrmSurgery.ProcessNotifications;
2238var
2239 x: string;
2240 Saved: boolean;
2241 //tmpNode: TTreeNode;
2242 //AnObject: PCaseTreeObject;
2243 tmpList: TStringList;
2244begin
2245 SetupVars; //kt added 8/7/2007 to replace constants with vars.
2246 if EditingIndex <> -1 then
2247 begin
2248 SaveCurrentNote(Saved);
2249 if not Saved then Exit;
2250 end;
2251 lblCases.Caption := Notifications.Text;
2252 tvSurgery.Caption := lblCases.Caption;
2253 EditingIndex := -1;
2254 lstNotes.Enabled := True ;
2255 pnlRead.BringToFront ;
2256 // show ALL unsigned/uncosigned for a patient, not just the alerted one
2257 // what about cosignature? How to get correct list? ORB FOLLOWUP TYPE = OR alerts only
2258 x := Notifications.AlertData;
2259 if StrToIntDef(Piece(x, U, 1), 0) = 0 then
2260 begin
2261 InfoBox(TX_NO_ALERT, TX_CAP_NO_ALERT, MB_OK);
2262 Exit;
2263 end;
2264 tmpList := TStringList.Create;
2265 try
2266 FCaseList.Clear;
2267 uChanging := True;
2268 tvSurgery.Items.BeginUpdate;
2269 lstNotes.Clear;
2270 KillCaseTreeObjects(tvSurgery);
2271 tvSurgery.Items.Clear;
2272 GetSingleCaseListItemWithDocs(tmpList, StrToIntDef(Piece(x, U, 1), 0));
2273 with FCurrentContext do CreateListItemsForCaseTree(FCaseList, tmpList, SR_ALL, GroupBy, TreeAscending);
2274 UpdateTreeView(FCaseList, tvSurgery);
2275 with tvSurgery do Selected := FindPieceNode(Piece(x, U, 1), 1, U, Items.GetFirstNode);
2276 (* lstNotes.Items.Add(x);
2277 AnObject := MakeCaseTreeObject('ALERT^Alerted Note^^^^^^^^^^^%^0');
2278 tmpNode := tvSurgery.Items.AddObjectFirst(tvSurgery.Items.GetFirstNode, AnObject.NodeText, AnObject);
2279 TORTreeNode(tmpNode).StringData := 'ALERT^Alerted Note^^^^^^^^^^^%^0';
2280 tmpNode.ImageIndex := IMG_SURG_TOP_LEVEL;
2281 AnObject := MakeCaseTreeObject(x);
2282 tmpNode := tvSurgery.Items.AddChildObjectFirst(tmpNode, AnObject.NodeText, AnObject);
2283 TORTreeNode(tmpNode).StringData := x;
2284 SetCaseTreeNodeImagesAndFormatting(TORTreeNode(tmpNode), FCurrentContext);
2285 tvSurgery.Selected := tmpNode;*)
2286 tvSurgery.Items.EndUpdate;
2287 uChanging := False;
2288 tvSurgeryChange(Self, tvSurgery.Selected);
2289 case Notifications.Followup of
2290 NF_SURGERY_UNSIGNED_NOTE: ; //Automatically deleted by sig action!!!
2291 end;
2292 if Copy(Piece(Notifications.RecordID, U, 2), 1, 6) = 'TIUADD' then Notifications.Delete;
2293 if Copy(Piece(Notifications.RecordID, U, 2), 1, 5) = 'TIUID' then Notifications.Delete;
2294 finally
2295 tmpList.Free;
2296 end;
2297end;
2298
2299procedure TfrmSurgery.mnuViewSaveAsDefaultClick(Sender: TObject);
2300begin
2301 inherited;
2302//if InfoBox('Replace current defaults?', 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then <-- original line. //kt 8/7/2007
2303 if InfoBox(DKLangConstW('fSurgery_Replace_current_defaultsx'), DKLangConstW('fSurgery_Confirmation'), MB_YESNO or MB_ICONQUESTION) = IDYES then //kt added 8/7/2007
2304 begin
2305 SaveCurrentSurgCaseContext(FCurrentContext);
2306 FDefaultContext := FCurrentContext;
2307// lblCases.Caption := 'Default List'; <-- original line. //kt 8/7/2007
2308 lblCases.Caption := DKLangConstW('fSurgery_Default_List'); //kt added 8/7/2007
2309 tvSurgery.Caption := lblCases.Caption;
2310 end;
2311end;
2312
2313procedure TfrmSurgery.mnuViewReturntoDefaultClick(Sender: TObject);
2314begin
2315 inherited;
2316 SetViewContext(FDefaultContext);
2317end;
2318
2319procedure TfrmSurgery.popNoteMemoTemplateClick(Sender: TObject);
2320begin
2321 inherited;
2322 EditTemplates(Self, TRUE, FEditCtrl.SelText);
2323end;
2324
2325procedure TfrmSurgery.popNoteListPopup(Sender: TObject);
2326begin
2327 inherited;
2328 N4.Visible := (popNoteList.PopupComponent is TORTreeView);
2329 popNoteListExpandAll.Visible := N4.Visible;
2330 popNoteListExpandSelected.Visible := N4.Visible;
2331 popNoteListCollapseAll.Visible := N4.Visible;
2332 popNoteListCollapseSelected.Visible := N4.Visible;
2333end;
2334
2335procedure TfrmSurgery.popNoteListExpandAllClick(Sender: TObject);
2336begin
2337 inherited;
2338 tvSurgery.FullExpand;
2339end;
2340
2341procedure TfrmSurgery.popNoteListCollapseAllClick(Sender: TObject);
2342begin
2343 inherited;
2344 tvSurgery.Selected := nil;
2345 memSurgery.Clear;
2346 tvSurgery.FullCollapse;
2347 tvSurgery.Selected := tvSurgery.TopItem;
2348end;
2349
2350procedure TfrmSurgery.popNoteListExpandSelectedClick(Sender: TObject);
2351begin
2352 inherited;
2353 if tvSurgery.Selected = nil then exit;
2354 with tvSurgery.Selected do if HasChildren then Expand(True);
2355end;
2356
2357procedure TfrmSurgery.popNoteListCollapseSelectedClick(Sender: TObject);
2358begin
2359 inherited;
2360 if tvSurgery.Selected = nil then exit;
2361 with tvSurgery.Selected do if HasChildren then Collapse(True);
2362end;
2363
2364procedure TfrmSurgery.mnuEditTemplatesClick(Sender: TObject);
2365begin
2366 inherited;
2367 EditTemplates(Self);
2368end;
2369
2370procedure TfrmSurgery.mnuNewTemplateClick(Sender: TObject);
2371begin
2372 inherited;
2373 EditTemplates(Self, TRUE);
2374end;
2375
2376procedure TfrmSurgery.mnuEditSharedTemplatesClick(Sender: TObject);
2377begin
2378 inherited;
2379 EditTemplates(Self, FALSE, '', TRUE);
2380end;
2381
2382procedure TfrmSurgery.mnuNewSharedTemplateClick(Sender: TObject);
2383begin
2384 inherited;
2385 EditTemplates(Self, TRUE, '', TRUE);
2386end;
2387
2388procedure TfrmSurgery.mnuOptionsClick(Sender: TObject);
2389begin
2390 inherited;
2391 mnuEditTemplates.Enabled := frmDrawers.CanEditTemplates;
2392 mnuNewTemplate.Enabled := frmDrawers.CanEditTemplates;
2393 mnuEditSharedTemplates.Enabled := frmDrawers.CanEditShared;
2394 mnuNewSharedTemplate.Enabled := frmDrawers.CanEditShared;
2395 mnuEditDialgFields.Enabled := CanEditTemplateFields;
2396end;
2397
2398procedure TfrmSurgery.SetEditingIndex(const Value: Integer);
2399begin
2400 FEditingIndex := Value;
2401 if(FEditingIndex < 0) then
2402 KillReminderDialog(Self);
2403 if(assigned(frmReminderTree)) then
2404 frmReminderTree.EnableActions;
2405end;
2406
2407(*function TfrmSurgery.CanFinishReminder: boolean;
2408begin
2409 Result := False;
2410 if(EditingIndex < 0) then
2411 Result := FALSE
2412 else
2413 Result := (lstNotes.ItemIndex = EditingIndex);
2414end;*)
2415
2416procedure TfrmSurgery.AssignRemForm;
2417begin
2418(* with RemForm do
2419 begin
2420 Form := Self;
2421 PCEObj := uPCEEdit;
2422 RightPanel := pnlRight;
2423 CanFinishProc := CanFinishReminder;
2424 DisplayPCEProc := DisplayPCE;
2425 Drawers := frmDrawers;
2426 NewNoteRE := memNewNote;
2427 NoteList := lstNotes;
2428 end;*)
2429end;
2430
2431procedure TfrmSurgery.mnuEditDialgFieldsClick(Sender: TObject);
2432begin
2433 inherited;
2434 EditDialogFields;
2435end;
2436
2437
2438procedure TfrmSurgery.tvSurgeryClick(Sender: TObject);
2439begin
2440 if tvSurgery.Selected = nil then exit;
2441 if (tvSurgery.Selected.ImageIndex in [IMG_SURG_TOP_LEVEL, IMG_SURG_GROUP_OPEN, IMG_SURG_GROUP_SHUT]) then
2442 memSurgery.Clear;
2443end;
2444
2445procedure TfrmSurgery.ShowPCEButtons(Editing: boolean);
2446begin
2447 FEditingNotePCEObj := Editing;
2448 if Editing or AnytimeEncounters then
2449 begin
2450 cmdPCE.Visible := TRUE;
2451 if Editing then
2452 begin
2453 cmdPCE.Enabled := CanEditPCE(uPCEEdit);
2454{ TODO -oRich V. -cSurgery/TIU : Uncomment if allow new notes from Surgery tab }
2455 //cmdNewNote.Visible := AnytimeEncounters;
2456 //cmdNewNote.Enabled := FALSE;
2457 end
2458 else
2459 begin
2460 cmdPCE.Enabled := (GetAskPCE(0) <> apDisable);
2461{ TODO -oRich V. -cSurgery/TIU : Uncomment if allow new notes from Surgery tab }
2462 //cmdNewNote.Visible := TRUE;
2463 //cmdNewNote.Enabled := TRUE;
2464 end;
2465 if cmdNewNote.Visible then
2466 cmdPCE.Top := cmdNewNote.Top-cmdPCE.Height;
2467 end
2468 else
2469 begin
2470 cmdPCE.Enabled := FALSE;
2471 cmdPCE.Visible := FALSE;
2472{ TODO -oRich V. -cSurgery/TIU : Uncomment if allow new notes from Surgery tab }
2473 //cmdNewNote.Visible := TRUE;
2474 //cmdNewNote.Enabled := TRUE;
2475 end;
2476 if cmdPCE.Visible then
2477 lblSpace1.Top := cmdPCE.Top - lblSpace1.Height
2478 else
2479 lblSpace1.Top := cmdNewNote.Top - lblSpace1.Height;
2480 popNoteMemoEncounter.Enabled := cmdPCE.Enabled;
2481 popNoteMemoEncounter.Visible := cmdPCE.Visible;
2482end;
2483
2484procedure TfrmSurgery.mnuIconLegendClick(Sender: TObject);
2485begin
2486 inherited;
2487 ShowIconLegend(ilSurgery);
2488end;
2489
2490procedure TfrmSurgery.tvSurgeryChange(Sender: TObject;
2491 Node: TTreeNode);
2492var
2493 x: string;
2494 IsTIUDocument: boolean;
2495 //ShowReport: boolean;
2496begin
2497 if uChanging then Exit;
2498 //This gives the change a chance to occur when keyboarding, so that WindowEyes
2499 //doesn't use the old value.
2500 Application.ProcessMessages;
2501 //ShowReport := True;
2502 with tvSurgery do
2503 begin
2504 if Selected = nil then Exit;
2505 popNoteListExpandSelected.Enabled := Selected.HasChildren;
2506 popNoteListCollapseSelected.Enabled := Selected.HasChildren;
2507 RedrawSuspend(memSurgery.Handle);
2508 memSurgery.Clear;
2509 if not (Selected.ImageIndex in [IMG_SURG_TOP_LEVEL, IMG_SURG_GROUP_OPEN, IMG_SURG_GROUP_SHUT]) then
2510 begin
2511 x := TORTreeNode(Selected).StringData;
2512 memSurgery.Clear;
2513// StatusText('Retrieving selected surgery report...'); <-- original line. //kt 8/7/2007
2514 StatusText(DKLangConstW('fSurgery_Retrieving_selected_surgery_reportxxx')); //kt added 8/7/2007
2515 Screen.Cursor := crHourGlass;
2516 pnlRead.Visible := True;
2517 pnlWrite.Visible := False;
2518 //UpdateReminderFinish;
2519 IsTIUDocument := PCaseTreeObject(Selected.Data)^.PkgRef <> '';
2520 EnableDisableMenus(IsTIUDocument);
2521 if not IsTIUDocument then
2522 begin
2523 lblTitle.Caption := MakeSurgeryCaseDisplayText(x);
2524 lblTitle.Hint := lblTitle.Caption;
2525 //LoadOpTop(memSurgery.Lines, StrToIntDef(Piece(x, U, 1), 0), PCaseTreeObject(Selected.Data)^.IsNonORProc, ShowReport);
2526 NotifyOtherApps(NAE_REPORT, 'SUR^' + Piece(x, U, 1));
2527 lstNotes.ItemIndex := -1;
2528 end
2529 else
2530 begin
2531 lstNotes.SelectByID(Piece(x, U, 1));
2532 lstNotesClick(Self);
2533 end;
2534 Screen.Cursor := crDefault;
2535 StatusText('');
2536 SendMessage(memSurgery.Handle, WM_VSCROLL, SB_TOP, 0);
2537 end
2538 else
2539 begin
2540 lblTitle.Caption := '';
2541 lblTitle.Hint := lblTitle.Caption;
2542 pnlWrite.Visible := False;
2543 pnlRead.Visible := True;
2544 //UpdateReminderFinish;
2545 ShowPCEControls(False);
2546 frmDrawers.DisplayDrawers(TRUE, [odTemplates], [odTemplates]); //FALSE);
2547 ShowPCEButtons(FALSE);
2548 memSurgery.Clear;
2549 end;
2550 if(assigned(frmReminderTree)) then
2551 frmReminderTree.EnableActions;
2552 DisplayPCE;
2553 pnlRight.Refresh;
2554 memNewNote.Repaint;
2555 memSurgery.Repaint;
2556 SendMessage(tvSurgery.Handle, WM_HSCROLL, SB_THUMBTRACK, 0);
2557 RedrawActivate(memSurgery.Handle);
2558 end;
2559end;
2560
2561procedure TfrmSurgery.tvSurgeryExpanded(Sender: TObject;
2562 Node: TTreeNode);
2563begin
2564 with Node do
2565 begin
2566 if (ImageIndex in [IMG_SURG_GROUP_SHUT, IMG_SURG_CASE_SHUT, IMG_SURG_NON_OR_CASE_SHUT]) then
2567 ImageIndex := ImageIndex + 1;
2568 if (SelectedIndex in [IMG_SURG_GROUP_SHUT, IMG_SURG_CASE_SHUT, IMG_SURG_NON_OR_CASE_SHUT]) then
2569 SelectedIndex := SelectedIndex + 1;
2570 end;
2571 SendMessage(tvSurgery.Handle, WM_HSCROLL, SB_THUMBTRACK, 0);
2572end;
2573
2574procedure TfrmSurgery.tvSurgeryCollapsed(Sender: TObject;
2575 Node: TTreeNode);
2576begin
2577 with Node do
2578 begin
2579 if (ImageIndex in [IMG_SURG_GROUP_OPEN, IMG_SURG_CASE_OPEN, IMG_SURG_NON_OR_CASE_OPEN]) then
2580 ImageIndex := ImageIndex - 1;
2581 if (SelectedIndex in [IMG_SURG_GROUP_OPEN, IMG_SURG_CASE_OPEN, IMG_SURG_NON_OR_CASE_OPEN]) then
2582 SelectedIndex := SelectedIndex - 1;
2583 end;
2584end;
2585
2586procedure TfrmSurgery.LoadSurgeryCases;
2587var
2588 tmpList: TStringList;
2589 ANode: TORTreeNode;
2590begin
2591 tmpList := TStringList.Create;
2592 try
2593 FCaseList.Clear;
2594 uChanging := True;
2595 RedrawSuspend(memSurgery.Handle);
2596 tvSurgery.Items.BeginUpdate;
2597 KillCaseTreeObjects(tvSurgery);
2598 tvSurgery.Items.Clear;
2599 tvSurgery.Items.EndUpdate;
2600 lstNotes.Items.Clear;
2601 memSurgery.Clear;
2602 memSurgery.Invalidate;
2603 lblTitle.Caption := '';
2604 lblTitle.Hint := lblTitle.Caption;
2605 ShowPCEControls(FALSE);
2606 with FCurrentContext do
2607 begin
2608 GetSurgCaseList(tmpList, FMBeginDate, FMEndDate, SR_ALL, MaxDocs);
2609 CreateListItemsForCaseTree(FCaseList, tmpList, SR_ALL, GroupBy, TreeAscending);
2610 UpdateTreeView(FCaseList, tvSurgery);
2611 end;
2612 tmpList.Clear;
2613 FCaseList.Clear;
2614 with tvSurgery do
2615 begin
2616 uChanging := True;
2617 tvSurgery.Items.BeginUpdate;
2618 if FLastNoteID <> '' then
2619 Selected := FindPieceNode(FLastNoteID, 1, U, nil);
2620 if Selected = nil then
2621 begin
2622 if (uSurgeryContext.GroupBy <> '') then
2623 begin
2624 ANode := TORTreeNode(Items.GetFirstNode);
2625 while ANode <> nil do
2626 begin
2627 ANode.Expand(False);
2628 Selected := ANode;
2629 ANode := TORTreeNode(ANode.GetNextSibling);
2630 end;
2631 end
2632 else
2633 begin
2634 ANode := tvSurgery.FindPieceNode(IntToStr(SR_ALL), 1, U, nil);
2635 if ANode <> nil then Selected := ANode.getFirstChild;
2636 end;
2637 end;
2638 memSurgery.Clear;
2639 RemoveParentsWithNoChildren(tvSurgery, uSurgeryContext);
2640 tvSurgery.Items.EndUpdate;
2641 uChanging := False;
2642 lblCases.Caption := SetSurgTreeLabel(FCurrentContext);
2643 tvSurgery.Caption := lblCases.Caption;
2644 SendMessage(tvSurgery.Handle, WM_VSCROLL, SB_TOP, 0);
2645 if Selected <> nil then tvSurgeryChange(Self, Selected);
2646 end;
2647 finally
2648 RedrawActivate(memSurgery.Handle);
2649 tmpList.Free;
2650 end;
2651end;
2652
2653function TfrmSurgery.SetSurgTreeLabel(AContext: TSurgCaseContext): string;
2654var
2655 x: string;
2656
2657 function SetDateRangeText(AContext: TSurgCaseContext): string;
2658 var
2659 x1: string;
2660 begin
2661 with AContext do
2662 if BeginDate <> '' then
2663 begin
2664// x1 := 'from ' + UpperCase(BeginDate); <-- original line. //kt 8/7/2007
2665 x1 := DKLangConstW('fSurgery_from') + UpperCase(BeginDate); //kt added 8/7/2007
2666 if EndDate <> '' then x1 := x1 + ' to ' + UpperCase(EndDate)
2667// else x1 := x1 + ' to TODAY'; <-- original line. //kt 8/7/2007
2668 else x1 := x1 + DKLangConstW('fSurgery_to_TODAY'); //kt added 8/7/2007
2669 end;
2670 Result := x1;
2671 end;
2672
2673begin
2674 with AContext do
2675 begin
2676 if MaxDocs > 0 then x := 'Last ' + IntToStr(MaxDocs) + ' ' else x := 'All ';
2677 case StrToIntDef(Status, 0) of
2678// SR_RECENT : x := x + 'Surgery Cases'; <-- original line. //kt 8/7/2007
2679 SR_RECENT : x := x + DKLangConstW('fSurgery_Surgery_Cases'); //kt added 8/7/2007
2680// SR_ALL : x := x + 'Surgery Cases'; <-- original line. //kt 8/7/2007
2681 SR_ALL : x := x + DKLangConstW('fSurgery_Surgery_Cases'); //kt added 8/7/2007
2682 //SG_BY_SURGEON : x := x + 'Surgery Cases for ' + ExternalName(Surgeon, 200) + SetDateRangeText(AContext);
2683// SR_BY_DATE : x := x + 'Surgery Cases ' + SetDateRangeText(AContext); <-- original line. //kt 8/7/2007
2684 SR_BY_DATE : x := x + DKLangConstW('fSurgery_Surgery_Cases') + SetDateRangeText(AContext); //kt added 8/7/2007
2685 else
2686// x := 'Custom List'; <-- original line. //kt 8/7/2007
2687 x := DKLangConstW('fSurgery_Custom_List'); //kt added 8/7/2007
2688 end;
2689 end;
2690 Result := x;
2691end;
2692
2693procedure TfrmSurgery.lstNotesClick(Sender: TObject);
2694{ loads the text for the selected note or displays the editing panel for the selected note }
2695begin
2696 inherited;
2697 with lstNotes do if ItemIndex = -1 then Exit
2698 else if ItemIndex = EditingIndex then
2699 begin
2700 pnlWrite.Visible := True;
2701 pnlRead.Visible := False;
2702 mnuViewDetail.Enabled := False;
2703 mnuActChange.Enabled := True;
2704 mnuActLoadBoiler.Enabled := True;
2705 //UpdateReminderFinish;
2706 end else
2707 begin
2708// StatusText('Retrieving selected surgery report...'); <-- original line. //kt 8/7/2007
2709 StatusText(DKLangConstW('fSurgery_Retrieving_selected_surgery_reportxxx')); //kt added 8/7/2007
2710 Screen.Cursor := crHourGlass;
2711 pnlRead.Visible := True;
2712 pnlWrite.Visible := False;
2713 //UpdateReminderFinish;
2714 lblTitle.Caption := MakeSurgeryReportDisplayText(Items[ItemIndex]);
2715 lblTitle.Hint := lblTitle.Caption;
2716 LoadSurgReportText(memSurgery.Lines, ItemIEN);
2717 mnuViewDetail.Enabled := True;
2718 mnuViewDetail.Checked := False;
2719 mnuActChange.Enabled := False;
2720 mnuActLoadBoiler.Enabled := False;
2721 Screen.Cursor := crDefault;
2722 StatusText('');
2723 end;
2724 if(assigned(frmReminderTree)) then
2725 frmReminderTree.EnableActions;
2726 DisplayPCE;
2727 pnlRight.Refresh;
2728 memNewNote.Repaint;
2729 memSurgery.Repaint;
2730 NotifyOtherApps(NAE_REPORT, 'TIU^' + lstNotes.ItemID);
2731end;
2732
2733procedure TfrmSurgery.EnableDisableMenus(IsTIUDocument: boolean);
2734begin
2735{ TODO -oRich V. -cSurgery/TIU : Reset NewNoteMenu enabled if allow new notes from Surgery tab }
2736 mnuActNew.Enabled := False;
2737 mnuActAddend.Enabled := IsTIUDocument;
2738 mnuActAddIDEntry.Enabled := False;
2739 mnuActDetachFromIDParent.Enabled := False;
2740 mnuActEdit.Enabled := IsTIUDocument;
2741 mnuActDelete.Enabled := IsTIUDocument;
2742 mnuActSign.Enabled := IsTIUDocument;
2743 mnuActSignList.Enabled := IsTIUDocument;
2744 mnuActSave.Enabled := IsTIUDocument;
2745 mnuActIdentifyAddlSigners.Enabled := IsTIUDocument;
2746 mnuActChange.Enabled := IsTIUDocument;
2747 mnuActLoadBoiler.Enabled := IsTIUDocument;
2748 popNoteMemoSignList.Enabled := IsTIUDocument;
2749 popNoteMemoSign.Enabled := IsTIUDocument;
2750 popNoteMemoSave.Enabled := IsTIUDocument;
2751 popNoteMemoEdit.Enabled := IsTIUDocument;
2752 popNoteMemoDelete.Enabled := IsTIUDocument;
2753 popNoteMemoAddlSign.Enabled := IsTIUDocument;
2754 popNoteMemoAddend.Enabled := IsTIUDocument;
2755 mnuViewDetail.Enabled := IsTIUDocument;
2756 popNoteMemoPreview.Enabled := IsTIUDocument and Assigned(frmDrawers.tvTemplates.Selected);
2757 popNoteMemoInsTemplate.Enabled := IsTIUDocument and Assigned(frmDrawers.tvTemplates.Selected);
2758 if not IsTIUDocument then mnuViewDetail.Checked := False;
2759 frmFrame.mnuFilePrint.Enabled := IsTIUDocument;
2760end;
2761
2762procedure TfrmSurgery.memNewNoteKeyDown(Sender: TObject; var Key: Word;
2763 Shift: TShiftState);
2764begin
2765 inherited;
2766 if (Key = VK_TAB) then
2767 begin
2768 if ssShift in Shift then
2769 begin
2770 FindNextControl(Sender as TWinControl, False, True, False).SetFocus; //previous control
2771 Key := 0;
2772 end
2773 else if ssCtrl in Shift then
2774 begin
2775 FindNextControl(Sender as TWinControl, True, True, False).SetFocus; //next control
2776 Key := 0;
2777 end;
2778 end;
2779 if (key = VK_ESCAPE) then begin
2780 FindNextControl(Sender as TWinControl, False, True, False).SetFocus; //previous control
2781 key := 0;
2782 end;
2783end;
2784
2785procedure TfrmSurgery.sptHorzCanResize(Sender: TObject; var NewSize: Integer;
2786 var Accept: Boolean);
2787begin
2788 inherited;
2789 if pnlWrite.Visible then
2790 if NewSize > frmSurgery.ClientWidth - memNewNote.Constraints.MinWidth - sptHorz.Width then
2791 NewSize := frmSurgery.ClientWidth - memNewNote.Constraints.MinWidth - sptHorz.Width;
2792end;
2793
2794procedure TfrmSurgery.popNoteMemoPreviewClick(Sender: TObject);
2795begin
2796 frmDrawers.mnuPreviewTemplateClick(Sender);
2797end;
2798
2799procedure TfrmSurgery.popNoteMemoInsTemplateClick(Sender: TObject);
2800begin
2801 frmDrawers.mnuInsertTemplateClick(Sender);
2802end;
2803
2804procedure TfrmSurgery.tvSurgeryAddition(Sender: TObject; Node: TTreeNode);
2805begin
2806 inherited;
2807 TAccessibleTreeNode.WrapControl(Node as TORTreeNode);
2808end;
2809
2810procedure TfrmSurgery.tvSurgeryDeletion(Sender: TObject; Node: TTreeNode);
2811begin
2812 TAccessibleTreeNode.UnwrapControl(Node as TORTreeNode);
2813 inherited;
2814end;
2815
2816procedure TfrmSurgery.ViewInfo(Sender: TObject);
2817begin
2818 inherited;
2819 frmFrame.ViewInfo(Sender);
2820end;
2821
2822procedure TfrmSurgery.mnuViewInformationClick(Sender: TObject);
2823begin
2824 inherited;
2825 mnuViewDemo.Enabled := frmFrame.pnlPatient.Enabled;
2826 mnuViewVisits.Enabled := frmFrame.pnlVisit.Enabled;
2827 mnuViewPrimaryCare.Enabled := frmFrame.pnlPrimaryCare.Enabled;
2828 mnuViewMyHealtheVet.Enabled := not (Copy(frmFrame.laMHV.Hint, 1, 2) = 'No');
2829 mnuInsurance.Enabled := not (Copy(frmFrame.laVAA2.Hint, 1, 2) = 'No');
2830 mnuViewFlags.Enabled := frmFrame.lblFlag.Enabled;
2831 mnuViewRemoteData.Enabled := frmFrame.lblCirn.Enabled;
2832 mnuViewReminders.Enabled := frmFrame.pnlReminders.Enabled;
2833 mnuViewPostings.Enabled := frmFrame.pnlPostings.Enabled;
2834end;
2835
2836initialization
2837 uPCEEdit := TPCEData.Create;
2838 uPCEShow := TPCEData.Create;
2839
2840finalization
2841 uPCEEdit.Free;
2842 uPCEShow.Free;
2843
2844end.
2845
Note: See TracBrowser for help on using the repository browser.