source: Scheduling/trunk/cs/bsdx0200GUISourceCode/DPatientLetter.cs@ 1301

Last change on this file since 1301 was 1248, checked in by Sam Habiel, 13 years ago

Scheduling v 1.61. Dll and exes. Added new control to handle print previewing; control located in PrintPreview.dll.
PrintPreview.dll is now added to project.
DPatientLetter.cs now uses the new print preview control.

File size: 15.5 KB
RevLine 
[614]1using System;
2using System.Windows.Forms;
3using System.Data;
[772]4using System.Drawing.Printing;
5using System.Drawing;
[614]6
7namespace IndianHealthService.ClinicalScheduling
8{
9 /// <summary>
[850]10 /// Handles Printing of letters (Reminder, Rebook, Cancellation) and a Report. Contains a Print Preview dialog.
[614]11 /// </summary>
[1248]12 public class DPatientLetter : VR.PrintPreview.EnhancedPrintPreviewDialog
[772]13 {
[614]14 /// <summary>
15 /// Required designer variable.
16 /// </summary>
[772]17 private System.ComponentModel.Container components = null;
[788]18 private System.Drawing.Printing.PrintDocument printAppts;
19 private System.Drawing.Printing.PrintDocument printReminderLetters;
[850]20 private System.Drawing.Printing.PrintDocument printCancelLetters;
21 private System.Drawing.Printing.PrintDocument printRebookLetters;
[614]22
23 #region Fields
[772]24 DateTime _dtBegin, _dtEnd; //global fields to use in passing to printing method
[788]25
26 //stuff to track what got printed and where we are -- very ugly, I know
27 //but I don't know if there is a better way to do it.
[772]28 int _currentResourcePrinting = 0;
29 int _currentApptPrinting = 0;
[788]30 int _pageNumber = 0;
31
[850]32 //typed datasets to load the results of queries into and set to print routines
[788]33 dsPatientApptDisplay2 _dsApptDisplay;
34 dsRebookAppts _dsRebookAppts;
[850]35
[614]36 #endregion Fields
37
[850]38 #region Windows Form Designer generated code
39 /// <summary>
40 /// Required method for Designer support - do not modify
41 /// the contents of this method with the code editor.
42 /// </summary>
43 private void InitializeComponent()
44 {
45 this.printAppts = new System.Drawing.Printing.PrintDocument();
46 this.printReminderLetters = new System.Drawing.Printing.PrintDocument();
47 this.printCancelLetters = new System.Drawing.Printing.PrintDocument();
48 this.printRebookLetters = new System.Drawing.Printing.PrintDocument();
49 this.SuspendLayout();
50 //
51 // printAppts
52 //
53 this.printAppts.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printAppts_PrintPage);
54 //
55 // printReminderLetters
56 //
57 this.printReminderLetters.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printReminderLetters_PrintPage);
58 //
59 // printCancelLetters
60 //
61 this.printCancelLetters.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printCancelLetters_PrintPage);
62 //
63 // printRebookLetters
64 //
65 this.printRebookLetters.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printRebookLetters_PrintPage);
66 //
67 // DPatientLetter
68 //
69 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
[1117]70 this.ClientSize = new System.Drawing.Size(748, 443);
[850]71 this.Name = "DPatientLetter";
72 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
73 this.Text = "Patient Letter";
74 this.ResumeLayout(false);
75
76 }
77 #endregion
78
79
[788]80 /// <summary>
81 /// Print Clinic Schedules
82 /// </summary>
83 /// <param name="docManager">This docManger</param>
84 /// <param name="sClinicList">Clinics for which to print</param>
85 /// <param name="dtBegin">Beginning Date</param>
86 /// <param name="dtEnd">End Date</param>
87 public void InitializeFormClinicSchedule(CGDocumentManager docManager,
[614]88 string sClinicList,
89 DateTime dtBegin,
90 DateTime dtEnd)
91 {
92 try
93 {
94 if (sClinicList == "")
95 {
96 throw new Exception("At least one clinic must be selected.");
97 }
98
[848]99 _dtBegin = dtBegin; // Global variable to use in Printing method below
100 _dtEnd = dtEnd; // ditto
[614]101
[848]102 this.Text="Clinic Schedules";
103
104 // Get Data
105 DataTable PatientAppts = docManager.DAL.GetClinicSchedules(sClinicList, dtBegin, dtEnd);
106 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
107
108 // Merge tables into typed dataset
[788]109 _dsApptDisplay = new dsPatientApptDisplay2();
[848]110 _dsApptDisplay.PatientAppts.Merge(PatientAppts);
111 _dsApptDisplay.BSDXResource.Merge(Resources);
[788]112
[1248]113 this.Document = printAppts;
[772]114 }
[614]115 catch (Exception ex)
116 {
117 throw ex;
118 }
119 }
120
[789]121 /// <summary>
122 /// Print Rebook Letters by Date
123 /// </summary>
124 /// <param name="docManager">This docManger</param>
125 /// <param name="sClinicList">Clinics for which to print</param>
126 /// <param name="dtBegin">Beginning Date</param>
127 /// <param name="dtEnd">End Date</param>
128 public void InitializeFormRebookLetters(CGDocumentManager docManager,
[614]129 string sClinicList,
[788]130 DateTime dtBegin,
131 DateTime dtEnd)
[614]132 {
133 try
134 {
135 if (sClinicList == "")
136 {
137 throw new Exception("At least one clinic must be selected.");
138 }
139
[788]140 //Call RPC to get list of appt ids that have been rebooked for these clinics on these dates
[850]141 DataTable PatientAppts = docManager.DAL.GetRebookedAppointments(sClinicList, dtBegin, dtEnd);
142 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
[789]143
144 _dsRebookAppts = new dsRebookAppts();
[850]145 _dsRebookAppts.PatientAppts.Merge(PatientAppts);
146 _dsRebookAppts.BSDXResource.Merge(Resources);
[789]147
[788]148 }
[614]149 catch (Exception ex)
150 {
151 throw ex;
152 }
[789]153
[1248]154 this.Document = printRebookLetters;
[789]155
[614]156 }
[789]157
158 /// <summary>
159 /// Print Rebook Letters by Date
160 /// </summary>
161 /// <param name="docManager">This docManger</param>
162 /// <param name="sClinicList">Clinics for which to print</param>
163 /// <param name="sApptIDList">List of appointments IENs in ^BSDXAPPT, delimited by |</param>
[788]164 public void InitializeFormRebookLetters(CGDocumentManager docManager,
165 string sClinicList,
166 string sApptIDList)
167 {
168 try
169 {
170 if (sClinicList == "")
171 {
172 throw new Exception("At least one clinic must be selected.");
173 }
[614]174
[850]175 DataTable PatientAppts = docManager.DAL.GetRebookedAppointments(sApptIDList);
176 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
[788]177
[789]178 _dsRebookAppts = new dsRebookAppts();
[850]179 _dsRebookAppts.PatientAppts.Merge(PatientAppts);
180 _dsRebookAppts.BSDXResource.Merge(Resources);
[788]181 }
182 catch (Exception ex)
183 {
184 throw ex;
185 }
[789]186
[1248]187 this.Document = printRebookLetters;
[788]188 }
189
190 /// <summary>
191 /// Print Cancellation letters to mail to patients
192 /// </summary>
193 /// <param name="docManager">This Docmanager</param>
194 /// <param name="sClinicList">| delemited clinic list (IEN's)</param>
195 /// <param name="dtBegin">Beginning Date</param>
196 /// <param name="dtEnd">Ending Date</param>
[614]197 public void InitializeFormCancellationLetters(CGDocumentManager docManager,
198 string sClinicList,
[788]199 DateTime dtBegin,
200 DateTime dtEnd)
201 {
[614]202 try
203 {
204 if (sClinicList == "")
205 {
206 throw new Exception("At least one clinic must be selected.");
207 }
[850]208
209 DataTable PatientAppts = docManager.DAL.GetCancelledAppointments(sClinicList, dtBegin, dtEnd);
210 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
211
[788]212 _dsRebookAppts = new dsRebookAppts();
[850]213 _dsRebookAppts.PatientAppts.Merge(PatientAppts);
214 _dsRebookAppts.BSDXResource.Merge(Resources);
215
[1248]216 this.Document = printCancelLetters;
[788]217
[614]218 }
219 catch (Exception ex)
220 {
221 throw ex;
222 }
223 }
[788]224 /// <summary>
225 /// Print Reminder Letters to give or mail to patients
226 /// </summary>
227 /// <param name="docManager">This docManger</param>
228 /// <param name="sClinicList">Clinics for which to print</param>
229 /// <param name="dtBegin">Beginning Date</param>
230 /// <param name="dtEnd">End Date</param>
231 public void InitializeFormPatientReminderLetters(CGDocumentManager docManager,
[614]232 string sClinicList,
233 DateTime dtBegin,
234 DateTime dtEnd)
235 {
236 try
237 {
238 if (sClinicList == "")
239 {
240 throw new Exception("At least one clinic must be selected.");
241 }
242
[850]243 // Global variables to use in printing routine down below
[788]244 _dtBegin = dtBegin;
245 _dtEnd = dtEnd;
[614]246
[850]247 this.Text = "Reminder Letters";
[788]248
[850]249 // Get Data
250 DataTable PatientAppts = docManager.DAL.GetClinicSchedules(sClinicList, dtBegin, dtEnd);
251 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
252
253 // Merge tables into typed dataset
[788]254 _dsApptDisplay = new dsPatientApptDisplay2();
[850]255 _dsApptDisplay.PatientAppts.Merge(PatientAppts);
256 _dsApptDisplay.BSDXResource.Merge(Resources);
[788]257
[1248]258 this.Document = printReminderLetters;
[614]259
260 }
261 catch (Exception ex)
262 {
263 throw ex;
264 }
265 }
266
[789]267 /// <summary>
268 /// Ctor
269 /// </summary>
[788]270 public DPatientLetter() : base()
[614]271 {
272 //
273 // Required for Windows Form Designer support
274 //
275 InitializeComponent();
276
277 //
278 // TODO: Add any constructor code after InitializeComponent call
279 //
280 }
281
282 /// <summary>
283 /// Clean up any resources being used.
284 /// </summary>
285 protected override void Dispose( bool disposing )
286 {
287 if( disposing )
288 {
289 if(components != null)
290 {
291 components.Dispose();
292 }
293 }
294 base.Dispose( disposing );
295 }
296
297
[788]298 private void printAppts_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
[1248]299 {
[788]300 //Each time we enter here, we start off with a new page number - we start off with zero
301 _pageNumber++; //becomes one first time through
302
[772]303 // _currentResourcePrinting starts with zero. There will be at least this one.
[1110]304 CGDocumentManager.Current.PrintingObject.PrintAppointments(_dsApptDisplay, e, _dtBegin, _dtEnd,
[788]305 _currentResourcePrinting, ref _currentApptPrinting, _pageNumber);
[772]306
307 //If the printing routine says it needs more pages to print the appointments,
308 //return here and have it print again.
309 if (e.HasMorePages == true) return;
310
311 // if there are more resouces to print, increment. Setting HasMorePages to true
312 // calls this routine again, so printing will happen with the incremented _currentResourcePrinting
[788]313 if (_currentResourcePrinting < _dsApptDisplay.BSDXResource.Rows.Count - 1)
[772]314 {
315 _currentResourcePrinting++;
[788]316 //reset _currentApptPrinting
317 _currentApptPrinting = 0;
[772]318 e.HasMorePages = true;
[884]319 return;
320 }
321
322 // if neither of these conditions is true, then we are done with printing.
323 // So reset counters for next one. Fixes ticket #15 on https://trac.opensourcevista.net/ticket/15
324 _currentResourcePrinting = 0;
325 _currentApptPrinting = 0;
326 _pageNumber = 0;
[788]327 }
328
329 private void printReminderLetters_PrintPage(object sender, PrintPageEventArgs e)
330 {
331 // no patients
332 if (_dsApptDisplay.PatientAppts.Count == 0)
333 {
[1110]334 CGDocumentManager.Current.PrintingObject.PrintMessage("No Appointments found", e);
[788]335 return;
[772]336 }
[788]337 // if there are patients
338 else if (_currentApptPrinting < _dsApptDisplay.PatientAppts.Count)
339 {
340 dsPatientApptDisplay2.BSDXResourceRow c = (dsPatientApptDisplay2.BSDXResourceRow)
341 _dsApptDisplay.PatientAppts[_currentApptPrinting].GetParentRow(_dsApptDisplay.Relations[0]);
[1110]342 CGDocumentManager.Current.PrintingObject.PrintReminderLetter(_dsApptDisplay.PatientAppts[_currentApptPrinting], e, c.LETTER_TEXT, "Reminder Letter");
[788]343 _currentApptPrinting++;
344 if (_currentApptPrinting < _dsApptDisplay.PatientAppts.Count)
[884]345 {
[788]346 e.HasMorePages = true;
[884]347 return;
348 }
[788]349 }
[884]350
351 // If we reach this point, we need to reset the counter (ticket #15 on https://trac.opensourcevista.net/ticket/15)
352 _currentApptPrinting = 0;
[772]353
354 }
[788]355
356 private void printCancelLetters_PrintPage(object sender, PrintPageEventArgs e)
357 {
358 // no patients
359 if (_dsRebookAppts.PatientAppts.Count == 0)
360 {
[1110]361 CGDocumentManager.Current.PrintingObject.PrintMessage("No Appointments found", e);
[788]362 return;
363 }
364 // if there are patients
365 else if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
366 {
367 dsRebookAppts.BSDXResourceRow c = (dsRebookAppts.BSDXResourceRow)
368 _dsRebookAppts.PatientAppts[_currentApptPrinting].GetParentRow(_dsRebookAppts.Relations[0]);
[1110]369 CGDocumentManager.Current.PrintingObject.PrintCancelLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.CLINIC_CANCELLATION_LETTER, "Cancellation Letter");
[788]370 _currentApptPrinting++;
371 if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
[884]372 {
[788]373 e.HasMorePages = true;
[884]374 return;
375 }
[788]376 }
[884]377 // If we reach this point, we need to reset the counter (ticket #15 on https://trac.opensourcevista.net/ticket/15)
378 _currentApptPrinting = 0;
[788]379 }
[789]380
381 private void printRebookLetters_PrintPage(object sender, PrintPageEventArgs e)
382 {
383 // no patients
384 if (_dsRebookAppts.PatientAppts.Count == 0)
385 {
[1110]386 CGDocumentManager.Current.PrintingObject.PrintMessage("No Appointments found", e);
[789]387 return;
388 }
389 // if there are patients
390 else if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
391 {
392 dsRebookAppts.BSDXResourceRow c = (dsRebookAppts.BSDXResourceRow)
393 _dsRebookAppts.PatientAppts[_currentApptPrinting].GetParentRow(_dsRebookAppts.Relations[0]);
394 //XXX: Rebook letter rather oddly currently stored in NO SHOW LETTER field. What gives???
[1110]395 CGDocumentManager.Current.PrintingObject.PrintRebookLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.NO_SHOW_LETTER, "Rebook Letter");
[789]396 _currentApptPrinting++;
397 if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
[884]398 {
[789]399 e.HasMorePages = true;
[884]400 return;
401 }
[789]402 }
[884]403 // If we reach this point, we need to reset the counter (ticket #15 on https://trac.opensourcevista.net/ticket/15)
404 _currentApptPrinting = 0;
[789]405 }
[1117]406
[614]407 }
408}
Note: See TracBrowser for help on using the repository browser.