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

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

Provided framework for Rebook letters; but they don't work.
Added the appointment dates to the printed letters.
Made more shortcuts on the main menu.
Changed version to 1.1, to be more congruous with the state of the software.

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