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

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

Some debugging code to attach the program to the console to print messages.
Letters:

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