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

Last change on this file since 848 was 848, checked in by Sam Habiel, 14 years ago

More refactoring.

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