1 | using System;
|
---|
2 | using System.Windows.Forms;
|
---|
3 | using System.Data;
|
---|
4 | using System.Drawing.Printing;
|
---|
5 | using System.Drawing;
|
---|
6 |
|
---|
7 | namespace 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 : 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 | 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(648, 398);
|
---|
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.PrintPreviewControl.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 | PrintPreviewControl.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 | PrintPreviewControl.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 | PrintPreviewControl.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.PrintPreviewControl.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 | ClinicalScheduling.Printing.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 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | private void printReminderLetters_PrintPage(object sender, PrintPageEventArgs e)
|
---|
323 | {
|
---|
324 | // no patients
|
---|
325 | if (_dsApptDisplay.PatientAppts.Count == 0)
|
---|
326 | {
|
---|
327 | ClinicalScheduling.Printing.PrintMessage("No Appointments found", e);
|
---|
328 | return;
|
---|
329 | }
|
---|
330 | // if there are patients
|
---|
331 | else if (_currentApptPrinting < _dsApptDisplay.PatientAppts.Count)
|
---|
332 | {
|
---|
333 | dsPatientApptDisplay2.BSDXResourceRow c = (dsPatientApptDisplay2.BSDXResourceRow)
|
---|
334 | _dsApptDisplay.PatientAppts[_currentApptPrinting].GetParentRow(_dsApptDisplay.Relations[0]);
|
---|
335 | ClinicalScheduling.Printing.PrintReminderLetter(_dsApptDisplay.PatientAppts[_currentApptPrinting], e, c.LETTER_TEXT, "Reminder Letter");
|
---|
336 | _currentApptPrinting++;
|
---|
337 | if (_currentApptPrinting < _dsApptDisplay.PatientAppts.Count)
|
---|
338 | e.HasMorePages = true;
|
---|
339 | }
|
---|
340 |
|
---|
341 | }
|
---|
342 |
|
---|
343 | private void printCancelLetters_PrintPage(object sender, PrintPageEventArgs e)
|
---|
344 | {
|
---|
345 | // no patients
|
---|
346 | if (_dsRebookAppts.PatientAppts.Count == 0)
|
---|
347 | {
|
---|
348 | ClinicalScheduling.Printing.PrintMessage("No Appointments found", e);
|
---|
349 | return;
|
---|
350 | }
|
---|
351 | // if there are patients
|
---|
352 | else if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
|
---|
353 | {
|
---|
354 | dsRebookAppts.BSDXResourceRow c = (dsRebookAppts.BSDXResourceRow)
|
---|
355 | _dsRebookAppts.PatientAppts[_currentApptPrinting].GetParentRow(_dsRebookAppts.Relations[0]);
|
---|
356 | ClinicalScheduling.Printing.PrintCancelLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.CLINIC_CANCELLATION_LETTER, "Cancellation Letter");
|
---|
357 | _currentApptPrinting++;
|
---|
358 | if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
|
---|
359 | e.HasMorePages = true;
|
---|
360 | }
|
---|
361 |
|
---|
362 | }
|
---|
363 |
|
---|
364 | private void printRebookLetters_PrintPage(object sender, PrintPageEventArgs e)
|
---|
365 | {
|
---|
366 | // no patients
|
---|
367 | if (_dsRebookAppts.PatientAppts.Count == 0)
|
---|
368 | {
|
---|
369 | ClinicalScheduling.Printing.PrintMessage("No Appointments found", e);
|
---|
370 | return;
|
---|
371 | }
|
---|
372 | // if there are patients
|
---|
373 | else if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
|
---|
374 | {
|
---|
375 | dsRebookAppts.BSDXResourceRow c = (dsRebookAppts.BSDXResourceRow)
|
---|
376 | _dsRebookAppts.PatientAppts[_currentApptPrinting].GetParentRow(_dsRebookAppts.Relations[0]);
|
---|
377 | //XXX: Rebook letter rather oddly currently stored in NO SHOW LETTER field. What gives???
|
---|
378 | ClinicalScheduling.Printing.PrintRebookLetter(_dsRebookAppts.PatientAppts[_currentApptPrinting], e, c.NO_SHOW_LETTER, "Rebook Letter");
|
---|
379 | _currentApptPrinting++;
|
---|
380 | if (_currentApptPrinting < _dsRebookAppts.PatientAppts.Count)
|
---|
381 | e.HasMorePages = true;
|
---|
382 | }
|
---|
383 | }
|
---|
384 | }
|
---|
385 | }
|
---|