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

Last change on this file since 1675 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
Line 
1using System;
2using System.Windows.Forms;
3using System.Data;
4using System.Drawing.Printing;
5using System.Drawing;
6
7namespace IndianHealthService.ClinicalScheduling
8{
9 /// <summary>
10 /// Handles Printing of letters (Reminder, Rebook, Cancellation) and a Report. Contains a Print Preview dialog.
11 /// </summary>
12 public class DPatientLetter : VR.PrintPreview.EnhancedPrintPreviewDialog
13 {
14 /// <summary>
15 /// Required designer variable.
16 /// </summary>
17 private System.ComponentModel.Container components = null;
18 private System.Drawing.Printing.PrintDocument printAppts;
19 private System.Drawing.Printing.PrintDocument printReminderLetters;
20 private System.Drawing.Printing.PrintDocument printCancelLetters;
21 private System.Drawing.Printing.PrintDocument printRebookLetters;
22
23 #region Fields
24 DateTime _dtBegin, _dtEnd; //global fields to use in passing to printing method
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.
28 int _currentResourcePrinting = 0;
29 int _currentApptPrinting = 0;
30 int _pageNumber = 0;
31
32 //typed datasets to load the results of queries into and set to print routines
33 dsPatientApptDisplay2 _dsApptDisplay;
34 dsRebookAppts _dsRebookAppts;
35
36 #endregion Fields
37
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);
70 this.ClientSize = new System.Drawing.Size(748, 443);
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
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,
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
99 _dtBegin = dtBegin; // Global variable to use in Printing method below
100 _dtEnd = dtEnd; // ditto
101
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
109 _dsApptDisplay = new dsPatientApptDisplay2();
110 _dsApptDisplay.PatientAppts.Merge(PatientAppts);
111 _dsApptDisplay.BSDXResource.Merge(Resources);
112
113 this.Document = printAppts;
114 }
115 catch (Exception ex)
116 {
117 throw ex;
118 }
119 }
120
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,
129 string sClinicList,
130 DateTime dtBegin,
131 DateTime dtEnd)
132 {
133 try
134 {
135 if (sClinicList == "")
136 {
137 throw new Exception("At least one clinic must be selected.");
138 }
139
140 //Call RPC to get list of appt ids that have been rebooked for these clinics on these dates
141 DataTable PatientAppts = docManager.DAL.GetRebookedAppointments(sClinicList, dtBegin, dtEnd);
142 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
143
144 _dsRebookAppts = new dsRebookAppts();
145 _dsRebookAppts.PatientAppts.Merge(PatientAppts);
146 _dsRebookAppts.BSDXResource.Merge(Resources);
147
148 }
149 catch (Exception ex)
150 {
151 throw ex;
152 }
153
154 this.Document = printRebookLetters;
155
156 }
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>
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 }
174
175 DataTable PatientAppts = docManager.DAL.GetRebookedAppointments(sApptIDList);
176 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
177
178 _dsRebookAppts = new dsRebookAppts();
179 _dsRebookAppts.PatientAppts.Merge(PatientAppts);
180 _dsRebookAppts.BSDXResource.Merge(Resources);
181 }
182 catch (Exception ex)
183 {
184 throw ex;
185 }
186
187 this.Document = printRebookLetters;
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>
197 public void InitializeFormCancellationLetters(CGDocumentManager docManager,
198 string sClinicList,
199 DateTime dtBegin,
200 DateTime dtEnd)
201 {
202 try
203 {
204 if (sClinicList == "")
205 {
206 throw new Exception("At least one clinic must be selected.");
207 }
208
209 DataTable PatientAppts = docManager.DAL.GetCancelledAppointments(sClinicList, dtBegin, dtEnd);
210 DataTable Resources = docManager.DAL.GetResourceLetters(sClinicList);
211
212 _dsRebookAppts = new dsRebookAppts();
213 _dsRebookAppts.PatientAppts.Merge(PatientAppts);
214 _dsRebookAppts.BSDXResource.Merge(Resources);
215
216 this.Document = printCancelLetters;
217
218 }
219 catch (Exception ex)
220 {
221 throw ex;
222 }
223 }
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,
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
243 // Global variables to use in printing routine down below
244 _dtBegin = dtBegin;
245 _dtEnd = dtEnd;
246
247 this.Text = "Reminder Letters";
248
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
254 _dsApptDisplay = new dsPatientApptDisplay2();
255 _dsApptDisplay.PatientAppts.Merge(PatientAppts);
256 _dsApptDisplay.BSDXResource.Merge(Resources);
257
258 this.Document = printReminderLetters;
259
260 }
261 catch (Exception ex)
262 {
263 throw ex;
264 }
265 }
266
267 /// <summary>
268 /// Ctor
269 /// </summary>
270 public DPatientLetter() : base()
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
298 private void printAppts_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
299 {
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
303 // _currentResourcePrinting starts with zero. There will be at least this one.
304 CGDocumentManager.Current.PrintingObject.PrintAppointments(_dsApptDisplay, e, _dtBegin, _dtEnd,
305 _currentResourcePrinting, ref _currentApptPrinting, _pageNumber);
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
313 if (_currentResourcePrinting < _dsApptDisplay.BSDXResource.Rows.Count - 1)
314 {
315 _currentResourcePrinting++;
316 //reset _currentApptPrinting
317 _currentApptPrinting = 0;
318 e.HasMorePages = true;
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;
327 }
328
329 private void printReminderLetters_PrintPage(object sender, PrintPageEventArgs e)
330 {
331 // no patients
332 if (_dsApptDisplay.PatientAppts.Count == 0)
333 {
334 CGDocumentManager.Current.PrintingObject.PrintMessage("No Appointments found", e);
335 return;
336 }
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]);
342 CGDocumentManager.Current.PrintingObject.PrintReminderLetter(_dsApptDisplay.PatientAppts[_currentApptPrinting], e, c.LETTER_TEXT, "Reminder Letter");
343 _currentApptPrinting++;
344 if (_currentApptPrinting < _dsApptDisplay.PatientAppts.Count)
345 {
346 e.HasMorePages = true;
347 return;
348 }
349 }
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;
353
354 }
355
356 private void printCancelLetters_PrintPage(object sender, PrintPageEventArgs e)
357 {
358 // no patients
359 if (_dsRebookAppts.PatientAppts.Count == 0)
360 {
361 CGDocumentManager.Current.PrintingObject.PrintMessage("No Appointments found", e);
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]);
369 CGDocumentManager.Current.PrintingObject.PrintCancelLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.CLINIC_CANCELLATION_LETTER, "Cancellation Letter");
370 _currentApptPrinting++;
371 if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
372 {
373 e.HasMorePages = true;
374 return;
375 }
376 }
377 // If we reach this point, we need to reset the counter (ticket #15 on https://trac.opensourcevista.net/ticket/15)
378 _currentApptPrinting = 0;
379 }
380
381 private void printRebookLetters_PrintPage(object sender, PrintPageEventArgs e)
382 {
383 // no patients
384 if (_dsRebookAppts.PatientAppts.Count == 0)
385 {
386 CGDocumentManager.Current.PrintingObject.PrintMessage("No Appointments found", e);
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???
395 CGDocumentManager.Current.PrintingObject.PrintRebookLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.NO_SHOW_LETTER, "Rebook Letter");
396 _currentApptPrinting++;
397 if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
398 {
399 e.HasMorePages = true;
400 return;
401 }
402 }
403 // If we reach this point, we need to reset the counter (ticket #15 on https://trac.opensourcevista.net/ticket/15)
404 _currentApptPrinting = 0;
405 }
406
407 }
408}
Note: See TracBrowser for help on using the repository browser.