1 | using System;
|
---|
2 | using System.Collections;
|
---|
3 | using System.Data;
|
---|
4 | using System.Data.OleDb;
|
---|
5 | using System.Diagnostics;
|
---|
6 | using System.Drawing;
|
---|
7 | using System.Windows.Forms;
|
---|
8 | using IndianHealthService.BMXNet;
|
---|
9 |
|
---|
10 | namespace IndianHealthService.ClinicalScheduling
|
---|
11 | {
|
---|
12 | /// <summary>
|
---|
13 | /// Contains the array of appointments and availabily that make up the document class
|
---|
14 | /// </summary>
|
---|
15 | public class CGDocument : System.Object
|
---|
16 | {
|
---|
17 |
|
---|
18 | public CGDocument()
|
---|
19 | {
|
---|
20 | m_appointments = new CGAppointments();
|
---|
21 | m_pAvArray = new ArrayList();
|
---|
22 | m_sResourcesArray = new ArrayList();
|
---|
23 | }
|
---|
24 |
|
---|
25 | #region Member Variables
|
---|
26 | public int m_nColumnCount; //todo: this should point to the view's member for column count
|
---|
27 | public int m_nTimeUnits;
|
---|
28 | private string m_sDocName;
|
---|
29 | public ArrayList m_sResourcesArray; //keeps the resources
|
---|
30 | public ScheduleType m_ScheduleType;
|
---|
31 | private DateTime m_dSelectedDate; //Holds the user's selection from the dtpicker
|
---|
32 | private DateTime m_dStartDate; //Beginning date of document data
|
---|
33 | private DateTime m_dEndDate; //Ending date of document data
|
---|
34 | public CGAppointments m_appointments;
|
---|
35 | private ArrayList m_pAvArray;
|
---|
36 | private CGDocumentManager m_DocManager;
|
---|
37 | private DateTime m_dLastRefresh = DateTime.Now;
|
---|
38 |
|
---|
39 | #endregion
|
---|
40 |
|
---|
41 | #region Properties
|
---|
42 |
|
---|
43 | /// <summary>
|
---|
44 | /// Returns the latest refresh time for this document
|
---|
45 | /// </summary>
|
---|
46 | public DateTime LastRefreshed
|
---|
47 | {
|
---|
48 | get
|
---|
49 | {
|
---|
50 | return m_dLastRefresh;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | /// <summary>
|
---|
55 | /// The list of Resource names
|
---|
56 | /// </summary>
|
---|
57 | public ArrayList Resources
|
---|
58 | {
|
---|
59 | get
|
---|
60 | {
|
---|
61 | return this.m_sResourcesArray;
|
---|
62 | }
|
---|
63 | set
|
---|
64 | {
|
---|
65 | this.m_sResourcesArray = value;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /// <summary>
|
---|
70 | /// The array of CGAvailabilities that contains appt type and slots
|
---|
71 | /// </summary>
|
---|
72 | public ArrayList AvailabilityArray
|
---|
73 | {
|
---|
74 | get
|
---|
75 | {
|
---|
76 | return this.m_pAvArray;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public CGDocumentManager DocManager
|
---|
81 | {
|
---|
82 | get
|
---|
83 | {
|
---|
84 | return m_DocManager;
|
---|
85 | }
|
---|
86 | set
|
---|
87 | {
|
---|
88 | m_DocManager = value;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | /// <summary>
|
---|
93 | /// Contains the hashtable of appointments
|
---|
94 | /// </summary>
|
---|
95 | public CGAppointments Appointments
|
---|
96 | {
|
---|
97 | get
|
---|
98 | {
|
---|
99 | return m_appointments;
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | /// <summary>
|
---|
104 | /// Holds the date selected by the user in CGView.dateTimePicker1
|
---|
105 | /// </summary>
|
---|
106 | public DateTime SelectedDate
|
---|
107 | {
|
---|
108 | get
|
---|
109 | {
|
---|
110 | return this.m_dSelectedDate;
|
---|
111 | }
|
---|
112 | set
|
---|
113 | {
|
---|
114 | this.m_dSelectedDate = value;
|
---|
115 | bool bRet = false;
|
---|
116 | if (m_sResourcesArray.Count == 1)
|
---|
117 | {
|
---|
118 | bRet = this.WeekNeedsRefresh(1, m_dSelectedDate, out this.m_dStartDate, out this.m_dEndDate);
|
---|
119 | }
|
---|
120 | else
|
---|
121 | {
|
---|
122 | this.m_dStartDate = m_dSelectedDate;
|
---|
123 | this.m_dEndDate = m_dSelectedDate;
|
---|
124 | this.m_dEndDate = this.m_dEndDate.AddHours(23);
|
---|
125 | this.m_dEndDate = this.m_dEndDate.AddMinutes(59);
|
---|
126 | this.m_dEndDate = this.m_dEndDate.AddSeconds(59);
|
---|
127 | }
|
---|
128 |
|
---|
129 | bRet = RefreshSchedule();
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /// <summary>
|
---|
134 | /// Contains the beginning date of the appointment document
|
---|
135 | /// </summary>
|
---|
136 | public DateTime StartDate
|
---|
137 | {
|
---|
138 | get
|
---|
139 | {
|
---|
140 | return this.m_dStartDate;
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | public string DocName
|
---|
145 | {
|
---|
146 | get
|
---|
147 | {
|
---|
148 | return this.m_sDocName;
|
---|
149 | }
|
---|
150 | set
|
---|
151 | {
|
---|
152 | this.m_sDocName = value;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | #endregion
|
---|
157 |
|
---|
158 | #region Methods
|
---|
159 |
|
---|
160 | public void UpdateAllViews()
|
---|
161 | {
|
---|
162 | //iterate through all views and call update.
|
---|
163 | Hashtable h = CGDocumentManager.Current.Views;
|
---|
164 |
|
---|
165 | CGDocument d;
|
---|
166 | foreach (CGView v in h.Keys)
|
---|
167 | {
|
---|
168 | d = (CGDocument) h[v];
|
---|
169 | if (d == this)
|
---|
170 | {
|
---|
171 | v.UpdateArrays();
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | }
|
---|
176 |
|
---|
177 | /// <summary>
|
---|
178 | /// Update schedule based on info in RPMS
|
---|
179 | /// </summary>
|
---|
180 | private bool RefreshDaysSchedule()
|
---|
181 | {
|
---|
182 | try
|
---|
183 | {
|
---|
184 | string sPatientName;
|
---|
185 | string sPatientID;
|
---|
186 | DateTime dStart;
|
---|
187 | DateTime dEnd;
|
---|
188 | DateTime dCheckIn;
|
---|
189 | DateTime dAuxTime;
|
---|
190 | int nKeyID;
|
---|
191 | string sNote;
|
---|
192 | string sResource;
|
---|
193 | bool bNoShow = false;
|
---|
194 | string sNoShow = "0";
|
---|
195 | string sHRN = "";
|
---|
196 | int nAccessTypeID; //used in autorebook
|
---|
197 | string sWalkIn = "0";
|
---|
198 | bool bWalkIn;
|
---|
199 | CGAppointment pAppointment;
|
---|
200 | CGDocumentManager pApp = CGDocumentManager.Current;
|
---|
201 | DataTable rAppointmentSchedule;
|
---|
202 |
|
---|
203 | //Nice to know that it gets set here!!!
|
---|
204 | m_dLastRefresh = DateTime.Now;
|
---|
205 |
|
---|
206 | this.m_appointments.ClearAllAppointments();
|
---|
207 |
|
---|
208 | // calls RPC to get appointments
|
---|
209 | rAppointmentSchedule = CGSchedLib.CreateAppointmentSchedule(m_DocManager, m_sResourcesArray, this.m_dStartDate, this.m_dEndDate);
|
---|
210 |
|
---|
211 | // Datatable dumper into Debug Log (nice to know that this exists)
|
---|
212 | CGSchedLib.OutputArray(rAppointmentSchedule, "rAppointmentSchedule");
|
---|
213 |
|
---|
214 |
|
---|
215 | foreach (DataRow r in rAppointmentSchedule.Rows)
|
---|
216 | {
|
---|
217 |
|
---|
218 | if (r["APPOINTMENTID"].ToString() == "0")
|
---|
219 | {
|
---|
220 | string sMsg = r["NOTE"].ToString();
|
---|
221 | throw new BMXNetException(sMsg);
|
---|
222 | }
|
---|
223 | nKeyID = Convert.ToInt32(r["APPOINTMENTID"].ToString());
|
---|
224 | sResource = r["RESOURCENAME"].ToString();
|
---|
225 | sPatientName =r["PATIENTNAME"].ToString();
|
---|
226 | sPatientID =r["PATIENTID"].ToString();
|
---|
227 | dStart = (DateTime) r["START_TIME"];
|
---|
228 | dEnd = (DateTime) r["END_TIME"];
|
---|
229 | dCheckIn = new DateTime();
|
---|
230 | dAuxTime = new DateTime();
|
---|
231 |
|
---|
232 | if (r["CHECKIN"].GetType() != typeof(System.DBNull))
|
---|
233 | dCheckIn = (DateTime) r["CHECKIN"];
|
---|
234 | if (r["AUXTIME"].GetType() != typeof(System.DBNull))
|
---|
235 | dCheckIn = (DateTime) r["AUXTIME"];
|
---|
236 | sNote = r["NOTE"].ToString();
|
---|
237 | sNoShow = r["NOSHOW"].ToString();
|
---|
238 | bNoShow = (sNoShow == "1")?true: false;
|
---|
239 | sHRN = r["HRN"].ToString();
|
---|
240 | nAccessTypeID = (int) r["ACCESSTYPEID"];
|
---|
241 | sWalkIn = r["WALKIN"].ToString();
|
---|
242 | bWalkIn = (sWalkIn == "1")?true: false;
|
---|
243 |
|
---|
244 | pAppointment = new CGAppointment();
|
---|
245 | pAppointment.CreateAppointment(dStart, dEnd, sNote, nKeyID, sResource);
|
---|
246 | pAppointment.PatientName = sPatientName;
|
---|
247 | pAppointment.PatientID = Convert.ToInt32(sPatientID);
|
---|
248 | if (dCheckIn.Ticks > 0)
|
---|
249 | pAppointment.CheckInTime = dCheckIn;
|
---|
250 | if (dAuxTime.Ticks > 0)
|
---|
251 | pAppointment.AuxTime = dAuxTime;
|
---|
252 | pAppointment.NoShow = bNoShow;
|
---|
253 | pAppointment.HealthRecordNumber = sHRN;
|
---|
254 | pAppointment.AccessTypeID = nAccessTypeID;
|
---|
255 | pAppointment.WalkIn = bWalkIn;
|
---|
256 | this.m_appointments.AddAppointment(pAppointment);
|
---|
257 |
|
---|
258 | }
|
---|
259 |
|
---|
260 | return true;
|
---|
261 | }
|
---|
262 | catch(Exception Ex)
|
---|
263 | {
|
---|
264 | Debug.Write("CGDocument.RefreshDaysSchedule error: " + Ex.Message + "\n");
|
---|
265 | return false;
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | public void OnNewDocument()
|
---|
271 | {
|
---|
272 | /*
|
---|
273 | * TEST EXCEPTION -- REMOVE AFTER TESTING
|
---|
274 | */
|
---|
275 | // throw new Exception("Simulated Uncaught Exception");
|
---|
276 | /*
|
---|
277 | * TEST EXCEPTION -- REMOVE AFTER TESTING
|
---|
278 | */
|
---|
279 |
|
---|
280 | //Open an empty document
|
---|
281 | m_sResourcesArray.Clear();
|
---|
282 | m_ScheduleType = ScheduleType.Resource;
|
---|
283 |
|
---|
284 | //Set initial From and To dates based on current day
|
---|
285 | // DateTime dDate = new DateTime(2001,12,05); //Testing line
|
---|
286 | DateTime dDate = DateTime.Today;
|
---|
287 |
|
---|
288 | //smh: Question: Where does bRet get used? It's a useless varaible so far.
|
---|
289 | bool bRet = this.WeekNeedsRefresh(2,dDate, out this.m_dStartDate, out this.m_dEndDate);
|
---|
290 |
|
---|
291 | //Create new View
|
---|
292 | CGView view = new CGView();
|
---|
293 | view.InitializeDocView(this,
|
---|
294 | this.DocManager,
|
---|
295 | m_dStartDate,
|
---|
296 | this.Appointments,
|
---|
297 | DocManager.WindowText);
|
---|
298 |
|
---|
299 | view.Show();
|
---|
300 | view.SyncTree();
|
---|
301 | view.Activate();
|
---|
302 | this.UpdateAllViews();
|
---|
303 | }
|
---|
304 |
|
---|
305 | private void SetDate(DateTime dDate)
|
---|
306 | {
|
---|
307 | bool bRet = false;
|
---|
308 | if (m_ScheduleType == ScheduleType.Resource)
|
---|
309 | {
|
---|
310 | bRet = this.WeekNeedsRefresh(2,dDate, out this.m_dStartDate, out this.m_dEndDate);
|
---|
311 | }
|
---|
312 | else
|
---|
313 | {
|
---|
314 | this.m_dStartDate = dDate;
|
---|
315 | this.m_dEndDate = dDate;
|
---|
316 | this.m_dEndDate = this.m_dEndDate.AddHours(23);
|
---|
317 | this.m_dEndDate = this.m_dEndDate.AddMinutes(59);
|
---|
318 | this.m_dEndDate = this.m_dEndDate.AddSeconds(59);
|
---|
319 | }
|
---|
320 |
|
---|
321 | bRet = RefreshSchedule();
|
---|
322 | this.UpdateAllViews();
|
---|
323 | }
|
---|
324 |
|
---|
325 | public void RefreshDocument()
|
---|
326 | {
|
---|
327 | bool bRet = RefreshSchedule();
|
---|
328 | this.UpdateAllViews();
|
---|
329 | }
|
---|
330 |
|
---|
331 | public void OnOpenDocument()
|
---|
332 | {
|
---|
333 | try
|
---|
334 | {
|
---|
335 | //Create new Document
|
---|
336 | m_ScheduleType = (m_sResourcesArray.Count == 1) ? ScheduleType.Resource: ScheduleType.Clinic;
|
---|
337 | bool bRet = false;
|
---|
338 |
|
---|
339 | //Set initial From and To dates based on current day
|
---|
340 | DateTime dDate = DateTime.Today;
|
---|
341 | if (m_ScheduleType == ScheduleType.Resource)
|
---|
342 | {
|
---|
343 | bRet = this.WeekNeedsRefresh(1,dDate, out this.m_dStartDate, out this.m_dEndDate);
|
---|
344 | }
|
---|
345 | else
|
---|
346 | {
|
---|
347 | this.m_dStartDate = dDate;
|
---|
348 | this.m_dEndDate = dDate;
|
---|
349 | this.m_dEndDate = this.m_dEndDate.AddHours(23);
|
---|
350 | this.m_dEndDate = this.m_dEndDate.AddMinutes(59);
|
---|
351 | this.m_dEndDate = this.m_dEndDate.AddSeconds(59);
|
---|
352 | }
|
---|
353 |
|
---|
354 | bRet = RefreshSchedule();
|
---|
355 |
|
---|
356 | CGView view = null;
|
---|
357 | //If this document already has a view, the use it
|
---|
358 | Hashtable h = CGDocumentManager.Current.Views;
|
---|
359 | CGDocument d;
|
---|
360 | bool bReuseView = false;
|
---|
361 | foreach (CGView v in h.Keys)
|
---|
362 | {
|
---|
363 | d = (CGDocument) h[v];
|
---|
364 | if (d == this)
|
---|
365 | {
|
---|
366 | view = v;
|
---|
367 | bReuseView = true;
|
---|
368 | v.InitializeDocView(this.DocName);
|
---|
369 | break;
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 | //Otherwise, create new View
|
---|
374 | if (bReuseView == false)
|
---|
375 | {
|
---|
376 | view = new CGView();
|
---|
377 |
|
---|
378 | view.InitializeDocView(this,
|
---|
379 | this.DocManager,
|
---|
380 | m_dStartDate,
|
---|
381 | this.Appointments,
|
---|
382 | this.DocName);
|
---|
383 |
|
---|
384 | view.Show();
|
---|
385 | view.SyncTree();
|
---|
386 |
|
---|
387 | }
|
---|
388 | this.UpdateAllViews();
|
---|
389 | }
|
---|
390 | catch (BMXNetException bmxEx)
|
---|
391 | {
|
---|
392 | throw bmxEx;
|
---|
393 | }
|
---|
394 | catch (Exception ex)
|
---|
395 | {
|
---|
396 | throw new BMXNet.BMXNetException("ClinicalScheduling.OnOpenDocument error: " + ex.Message);
|
---|
397 | }
|
---|
398 | }
|
---|
399 |
|
---|
400 | /// <summary>
|
---|
401 | /// Refreshes Availablility and Schedules from RPMS.
|
---|
402 | /// </summary>
|
---|
403 | /// <returns>Success or Failure. Should be always Success.</returns>
|
---|
404 | private bool RefreshSchedule()
|
---|
405 | {
|
---|
406 | try
|
---|
407 | {
|
---|
408 | bool bRet = this.RefreshAvailabilitySchedule();
|
---|
409 | if (bRet == false)
|
---|
410 | {
|
---|
411 | return bRet;
|
---|
412 | }
|
---|
413 | bRet = this.RefreshDaysSchedule();
|
---|
414 | return bRet;
|
---|
415 | }
|
---|
416 | catch (ApplicationException aex)
|
---|
417 | {
|
---|
418 | Debug.Write("CGDocument.RefreshSchedule Application Error: " + aex.Message + "\n");
|
---|
419 | return false;
|
---|
420 | }
|
---|
421 | catch (Exception ex)
|
---|
422 | {
|
---|
423 | MessageBox.Show("CGDocument.RefreshSchedule error: " + ex.Message + "\n");
|
---|
424 | return false;
|
---|
425 | }
|
---|
426 | }
|
---|
427 |
|
---|
428 | private bool RefreshAvailabilitySchedule()
|
---|
429 | {
|
---|
430 | try
|
---|
431 | {
|
---|
432 | if (this.m_DocManager.ConnectInfo.Connected == false)
|
---|
433 | {
|
---|
434 | m_DocManager.ConnectInfo.LoadConnectInfo();
|
---|
435 | }
|
---|
436 |
|
---|
437 | m_pAvArray.Clear();
|
---|
438 |
|
---|
439 | ArrayList saryApptTypes = new ArrayList();
|
---|
440 | int nApptTypeID = 0;
|
---|
441 |
|
---|
442 | //Refresh Availability schedules
|
---|
443 | DataTable rAvailabilitySchedule;
|
---|
444 | rAvailabilitySchedule = CGSchedLib.CreateAvailabilitySchedule(m_DocManager, m_sResourcesArray, this.m_dStartDate, this.m_dEndDate, saryApptTypes,/**/ m_ScheduleType, "0");
|
---|
445 | CGSchedLib.OutputArray(rAvailabilitySchedule, "rAvailabilitySchedule");
|
---|
446 |
|
---|
447 | //Refresh Type Schedule
|
---|
448 | string sResourceName = "";
|
---|
449 | DataTable rTypeSchedule = new DataTable();;
|
---|
450 | for (int j = 0; j < m_sResourcesArray.Count; j++)
|
---|
451 | {
|
---|
452 | sResourceName = m_sResourcesArray[j].ToString();
|
---|
453 | DataTable dtTemp = CGSchedLib.CreateAssignedTypeSchedule(m_DocManager, sResourceName, this.m_dStartDate, this.m_dEndDate, m_ScheduleType);
|
---|
454 | CGSchedLib.OutputArray(dtTemp, "dtTemp");
|
---|
455 | if (j == 0)
|
---|
456 | {
|
---|
457 | rTypeSchedule = dtTemp;
|
---|
458 | }
|
---|
459 | else
|
---|
460 | {
|
---|
461 | rTypeSchedule = CGSchedLib.UnionBlocks(rTypeSchedule, dtTemp);
|
---|
462 | }
|
---|
463 | }
|
---|
464 | CGSchedLib.OutputArray(rTypeSchedule, "rTypeSchedule");
|
---|
465 |
|
---|
466 | DateTime dStart;
|
---|
467 | DateTime dEnd;
|
---|
468 | DateTime dTypeStart;
|
---|
469 | DateTime dTypeEnd;
|
---|
470 | int nSlots;
|
---|
471 | Rectangle crRectA = new Rectangle(0,0,1,0);
|
---|
472 | Rectangle crRectB= new Rectangle(0,0,1,0);
|
---|
473 | bool bIsect;
|
---|
474 | string sResourceList;
|
---|
475 | string sAccessRuleList;
|
---|
476 |
|
---|
477 |
|
---|
478 | foreach (DataRow rTemp in rAvailabilitySchedule.Rows)
|
---|
479 | {
|
---|
480 | //get StartTime, EndTime and Slots
|
---|
481 | dStart = (DateTime) rTemp["START_TIME"];
|
---|
482 | dEnd = (DateTime) rTemp["END_TIME"];
|
---|
483 |
|
---|
484 | //TODO: Fix this slots datatype problem
|
---|
485 | string sSlots = rTemp["SLOTS"].ToString();
|
---|
486 | nSlots = Convert.ToInt16(sSlots);
|
---|
487 |
|
---|
488 | sResourceList = rTemp["RESOURCE"].ToString();
|
---|
489 | sAccessRuleList = rTemp["ACCESS_TYPE"].ToString();
|
---|
490 |
|
---|
491 | string sNote = rTemp["NOTE"].ToString();
|
---|
492 |
|
---|
493 | if ((nSlots < -1000)||(sAccessRuleList == ""))
|
---|
494 | {
|
---|
495 | nApptTypeID = 0;
|
---|
496 | }
|
---|
497 | else
|
---|
498 | {
|
---|
499 | foreach (DataRow rType in rTypeSchedule.Rows)
|
---|
500 | {
|
---|
501 |
|
---|
502 | dTypeStart = (DateTime) rType["StartTime"];
|
---|
503 | dTypeEnd = (DateTime) rType["EndTime"];
|
---|
504 | //if start & end times overlap, then
|
---|
505 | string sTypeResource = rType["ResourceName"].ToString();
|
---|
506 | if ((dTypeStart.DayOfYear == dStart.DayOfYear) && (sResourceList == sTypeResource))
|
---|
507 | {
|
---|
508 | crRectA.Y = GetTotalMinutes(dStart);
|
---|
509 | crRectA.Height = GetTotalMinutes(dEnd) - crRectA.Top;
|
---|
510 | crRectB.Y = GetTotalMinutes(dTypeStart);
|
---|
511 | crRectB.Height = GetTotalMinutes(dTypeEnd) - crRectB.Top;
|
---|
512 | bIsect = crRectA.IntersectsWith(crRectB);
|
---|
513 | if (bIsect == true)
|
---|
514 | {
|
---|
515 | //TODO: This code:
|
---|
516 | // nApptTypeID = (int) rType["AppointmentTypeID"];
|
---|
517 | //Causes this exception:
|
---|
518 | //Unhandled Exception: System.InvalidCastException: Specified cast is not valid.
|
---|
519 | string sTemp = rType["AppointmentTypeID"].ToString();
|
---|
520 | nApptTypeID = Convert.ToInt16(sTemp);
|
---|
521 | break;
|
---|
522 | }
|
---|
523 | }
|
---|
524 | }//end foreach datarow rType
|
---|
525 | }
|
---|
526 |
|
---|
527 | AddAvailability(dStart, dEnd, nApptTypeID, nSlots, false, sResourceList, sAccessRuleList, sNote);
|
---|
528 | }//end foreach datarow rTemp
|
---|
529 |
|
---|
530 | return true;
|
---|
531 | }
|
---|
532 | catch (Exception ex)
|
---|
533 | {
|
---|
534 | Debug.Write("CGDocument.RefreshAvailabilitySchedule error: " + ex.Message + "\n");
|
---|
535 | return false;
|
---|
536 | }
|
---|
537 | }
|
---|
538 |
|
---|
539 | private int GetTotalMinutes(DateTime dDate)
|
---|
540 | {
|
---|
541 | return ((dDate.Hour * 60) + dDate.Minute);
|
---|
542 | }
|
---|
543 |
|
---|
544 | public int AddAvailability(DateTime StartTime, DateTime EndTime, int nType, int nSlots, bool UpdateView, string sResourceList, string sAccessRuleList, string sNote)
|
---|
545 | {
|
---|
546 | //adds it to the object array
|
---|
547 | //Returns the index in the array
|
---|
548 |
|
---|
549 | CGAvailability pNewAv = new CGAvailability();
|
---|
550 | pNewAv.Create(StartTime, EndTime, nType, nSlots, sResourceList, sAccessRuleList);
|
---|
551 |
|
---|
552 | pNewAv.Note = sNote;
|
---|
553 |
|
---|
554 | //Look up the color and type name using the AppointmentTypes datatable
|
---|
555 | DataTable dtType = this.m_DocManager.GlobalDataSet.Tables["AccessTypes"];
|
---|
556 | DataRow dRow = dtType.Rows.Find(nType.ToString());
|
---|
557 | if (dRow != null)
|
---|
558 | {
|
---|
559 | string sColor = dRow["DISPLAY_COLOR"].ToString();
|
---|
560 | pNewAv.DisplayColor = sColor;
|
---|
561 | string sTemp = dRow["RED"].ToString();
|
---|
562 | sTemp = (sTemp == "")?"0":sTemp;
|
---|
563 | int nRed = Convert.ToInt16(sTemp);
|
---|
564 | pNewAv.Red = nRed;
|
---|
565 | sTemp = dRow["GREEN"].ToString();
|
---|
566 | sTemp = (sTemp == "")?"0":sTemp;
|
---|
567 | int nGreen = Convert.ToInt16(sTemp);
|
---|
568 | pNewAv.Green = nGreen;
|
---|
569 | sTemp = dRow["BLUE"].ToString();
|
---|
570 | sTemp = (sTemp == "")?"0":sTemp;
|
---|
571 | int nBlue = Convert.ToInt16(sTemp);
|
---|
572 | pNewAv.Blue = nBlue;
|
---|
573 |
|
---|
574 | string sName = dRow["ACCESS_TYPE_NAME"].ToString();
|
---|
575 | pNewAv.AccessTypeName = sName;
|
---|
576 | }
|
---|
577 |
|
---|
578 | int nIndex = 0;
|
---|
579 | nIndex = m_pAvArray.Add(pNewAv);
|
---|
580 | if (UpdateView == true)
|
---|
581 | {
|
---|
582 | this.UpdateAllViews();
|
---|
583 | }
|
---|
584 | return nIndex;
|
---|
585 | }
|
---|
586 |
|
---|
587 |
|
---|
588 | public void AddResource(string sResource)
|
---|
589 | {
|
---|
590 | //TODO: Test that resource is not currently in list, that it IS a resource, etc
|
---|
591 | this.m_sResourcesArray.Add(sResource);
|
---|
592 | //UpdateAllViews: Redraws all the open views. But does not call server.
|
---|
593 | this.UpdateAllViews();
|
---|
594 | }
|
---|
595 |
|
---|
596 | public void ClearResources()
|
---|
597 | {
|
---|
598 | this.m_sResourcesArray.Clear();
|
---|
599 | }
|
---|
600 |
|
---|
601 | public int SlotsAvailable(DateTime dSelStart, DateTime dSelEnd, string sResource, out string sAccessType, out string sAvailabilityMessage)
|
---|
602 | {
|
---|
603 | sAccessType = "";
|
---|
604 | sAvailabilityMessage = "";
|
---|
605 | DateTime dStart;
|
---|
606 | DateTime dEnd;
|
---|
607 | int nAvailableSlots = 999;
|
---|
608 | int nSlots = 0;
|
---|
609 | int i = 0;
|
---|
610 | CGAvailability pAv;
|
---|
611 | Rectangle crRectA = new Rectangle(0,0,1,0);
|
---|
612 | Rectangle crRectB = new Rectangle(0,0,1,0);
|
---|
613 | bool bIsect;
|
---|
614 | crRectB.Y = GetTotalMinutes(dSelStart);
|
---|
615 | crRectB.Height = GetTotalMinutes(dSelEnd)- crRectB.Y;
|
---|
616 |
|
---|
617 | // //loop thru m_pAvArray
|
---|
618 | // //Compare the start time and end time of eachblock
|
---|
619 | while (i < m_pAvArray.Count)
|
---|
620 | {
|
---|
621 | pAv = (CGAvailability) m_pAvArray[i];
|
---|
622 | dStart = pAv.StartTime;
|
---|
623 | dEnd = pAv.EndTime;
|
---|
624 | if ((sResource == pAv.ResourceList) &&
|
---|
625 | ((dSelStart.Date == dStart.Date) || (dSelStart.Date == dEnd.Date)))
|
---|
626 | {
|
---|
627 | crRectA.Y = (dStart.Date < dSelStart.Date) ? 0 : GetTotalMinutes(dStart);
|
---|
628 | crRectA.Height = (dEnd.Date > dSelEnd.Date) ? 1440 : GetTotalMinutes(dEnd);
|
---|
629 | crRectA.Height = crRectA.Height - crRectA.Y;
|
---|
630 | bIsect = crRectA.IntersectsWith(crRectB);
|
---|
631 | if (bIsect != false)
|
---|
632 | {
|
---|
633 | nSlots = pAv.Slots;
|
---|
634 | if (nSlots < 1)
|
---|
635 | {
|
---|
636 | nAvailableSlots = 0;
|
---|
637 | break;
|
---|
638 | }
|
---|
639 | if (nSlots < nAvailableSlots)
|
---|
640 | {
|
---|
641 | nAvailableSlots = nSlots;
|
---|
642 | sAccessType = pAv.AccessTypeName;
|
---|
643 | sAvailabilityMessage = pAv.Note;
|
---|
644 |
|
---|
645 | }
|
---|
646 | }
|
---|
647 | }
|
---|
648 | i++;
|
---|
649 | }
|
---|
650 | if (nAvailableSlots == 999)
|
---|
651 | {
|
---|
652 | nAvailableSlots = 0;
|
---|
653 | }
|
---|
654 | return nAvailableSlots;
|
---|
655 | }
|
---|
656 |
|
---|
657 | /// <summary>
|
---|
658 | /// Given a selected date,
|
---|
659 | /// Calculates StartDay and End Day and returns them in output params.
|
---|
660 | /// nWeeks == number of Weeks to display
|
---|
661 | /// nColumnCount is number of days displayed per week.
|
---|
662 | /// If 5 columns, begin on Second Day of Week
|
---|
663 | /// If 7 Columns, begin on First Day of Week
|
---|
664 | /// (this is a change from the hardcoded behavior for US-based calendars)
|
---|
665 | ///
|
---|
666 | /// Returns TRUE if the document's data needs refreshing based on
|
---|
667 | /// this newly selected date.
|
---|
668 | /// </summary>
|
---|
669 | public bool WeekNeedsRefresh(int nWeeks, DateTime SelectedDate,
|
---|
670 | out DateTime WeekStartDay, out DateTime WeekEndDay)
|
---|
671 | {
|
---|
672 | DateTime OldStartDay = m_dStartDate;
|
---|
673 | DateTime OldEndDay = m_dEndDate;
|
---|
674 | // Week start based on thread locale
|
---|
675 | int nStartWeekDay = (int)System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
|
---|
676 | // Current Day
|
---|
677 | int nWeekDay = (int) SelectedDate.DayOfWeek; //0 == Sunday
|
---|
678 |
|
---|
679 | // this offset gets approrpriate day based on locale.
|
---|
680 | int nOff = (nStartWeekDay + 1) % 7;
|
---|
681 | TimeSpan ts = new TimeSpan(nWeekDay - nOff,0,0,0); //d,h,m,s
|
---|
682 |
|
---|
683 | // if ts is negative, we will jump to the next week in the logic.
|
---|
684 | // to show the correct week, add 7. Confusing, I know.
|
---|
685 | if (ts < new TimeSpan() ) ts = ts + new TimeSpan(7,0,0,0);
|
---|
686 |
|
---|
687 | if (m_nColumnCount == 1) // if one column start and end on the same day.
|
---|
688 | {
|
---|
689 | ts = new TimeSpan(0,23,59,59);
|
---|
690 | WeekStartDay = SelectedDate;
|
---|
691 | WeekEndDay = WeekStartDay + ts;
|
---|
692 | }
|
---|
693 | else if (m_nColumnCount == 5 || m_nColumnCount == 0) // if 5 column start (or default) at the 2nd day of this week and end in 4:23:59:59 days.
|
---|
694 | {
|
---|
695 | // if picked day is start of week (Sunday in US), start in the next day since that's the first day of work week
|
---|
696 | // else, just substract the calculated time span to get to the start of week (first work day)
|
---|
697 | WeekStartDay = (nWeekDay == nStartWeekDay) ? SelectedDate + new TimeSpan(1,0,0,0): SelectedDate - ts;
|
---|
698 | // End day calculation
|
---|
699 | int nEnd = 3;
|
---|
700 | ts = new TimeSpan((7 * nWeeks) - nEnd, 23, 59, 59);
|
---|
701 | WeekEndDay = WeekStartDay + ts;
|
---|
702 | }
|
---|
703 | else // if 7 column start at the 1st day of this week and end in 6:23:59:59 days.
|
---|
704 | {
|
---|
705 | // if picked day is start of week, use that. Otherwise, go to the fist work day and substract one to get to start of week.
|
---|
706 | WeekStartDay = (nWeekDay == nStartWeekDay) ? SelectedDate : SelectedDate - ts - new TimeSpan(1,0,0,0);
|
---|
707 | // End day calculation
|
---|
708 | int nEnd = 1;
|
---|
709 | ts = new TimeSpan((7 * nWeeks) - nEnd, 23, 59, 59);
|
---|
710 | WeekEndDay = WeekStartDay + ts;
|
---|
711 | }
|
---|
712 |
|
---|
713 | bool bRet = (( WeekStartDay.Date != OldStartDay.Date) || (WeekEndDay.Date != OldEndDay.Date));
|
---|
714 | return bRet;
|
---|
715 | }
|
---|
716 |
|
---|
717 | /// <summary>
|
---|
718 | /// Calls RPMS to create appointment then
|
---|
719 | /// adds appointment to the m_appointments collection
|
---|
720 | /// Returns the IEN of the appointment in the RPMS BSDX APPOINTMENT file.
|
---|
721 | /// </summary>
|
---|
722 | /// <param name="rApptInfo"></param>
|
---|
723 | /// <returns></returns>
|
---|
724 | public int CreateAppointment(CGAppointment rApptInfo)
|
---|
725 | {
|
---|
726 | return CreateAppointment(rApptInfo, false);
|
---|
727 | }
|
---|
728 |
|
---|
729 | /// <summary>
|
---|
730 | /// Use this overload to create a walkin appointment
|
---|
731 | /// </summary>
|
---|
732 | /// <param name="rApptInfo"></param>
|
---|
733 | /// <param name="bWalkin"></param>
|
---|
734 | /// <returns></returns>
|
---|
735 | public int CreateAppointment(CGAppointment rApptInfo, bool bWalkin)
|
---|
736 | {
|
---|
737 | string sStart;
|
---|
738 | string sEnd;
|
---|
739 | string sPatID;
|
---|
740 | string sResource;
|
---|
741 | string sNote;
|
---|
742 | string sLen;
|
---|
743 | string sApptID;
|
---|
744 |
|
---|
745 | //sStart = rApptInfo.StartTime.ToString("M-d-yyyy@HH:mm");
|
---|
746 | //sEnd = rApptInfo.EndTime.ToString("M-d-yyyy@HH:mm");
|
---|
747 |
|
---|
748 | // i18n code -- Use culture neutral FMDates
|
---|
749 | sStart = FMDateTime.Create(rApptInfo.StartTime).FMDateString;
|
---|
750 | sEnd = FMDateTime.Create(rApptInfo.EndTime).FMDateString;
|
---|
751 |
|
---|
752 | TimeSpan sp = rApptInfo.EndTime - rApptInfo.StartTime;
|
---|
753 | sLen = sp.TotalMinutes.ToString();
|
---|
754 | sPatID = rApptInfo.PatientID.ToString();
|
---|
755 | sNote = rApptInfo.Note;
|
---|
756 | sResource = rApptInfo.Resource;
|
---|
757 | if (bWalkin == true)
|
---|
758 | {
|
---|
759 | sApptID = "WALKIN";
|
---|
760 | }
|
---|
761 | else
|
---|
762 | {
|
---|
763 | sApptID = rApptInfo.AccessTypeID.ToString();
|
---|
764 | }
|
---|
765 |
|
---|
766 | CGAppointment aCopy = new CGAppointment();
|
---|
767 | aCopy.CreateAppointment(rApptInfo.StartTime, rApptInfo.EndTime, sNote, 0, sResource);
|
---|
768 | aCopy.PatientID = rApptInfo.PatientID;
|
---|
769 | aCopy.PatientName = rApptInfo.PatientName;
|
---|
770 | aCopy.HealthRecordNumber = rApptInfo.HealthRecordNumber;
|
---|
771 | aCopy.AccessTypeID = rApptInfo.AccessTypeID;
|
---|
772 |
|
---|
773 | string sSql = "BSDX ADD NEW APPOINTMENT^" + sStart + "^" + sEnd + "^" + sPatID + "^" + sResource + "^" + sLen + "^" + sNote + "^" + sApptID ;
|
---|
774 | System.Data.DataTable dtAppt = m_DocManager.RPMSDataTable(sSql, "NewAppointment");
|
---|
775 | int nApptID;
|
---|
776 |
|
---|
777 | Debug.Assert(dtAppt.Rows.Count == 1);
|
---|
778 | DataRow r = dtAppt.Rows[0];
|
---|
779 | nApptID =Convert.ToInt32(r["APPOINTMENTID"]);
|
---|
780 | string sErrorID;
|
---|
781 | sErrorID = r["ERRORID"].ToString();
|
---|
782 | if ((sErrorID != "")||(nApptID < 1))
|
---|
783 | throw new Exception(sErrorID);
|
---|
784 | aCopy.AppointmentKey = nApptID;
|
---|
785 | this.m_appointments.AddAppointment(aCopy);
|
---|
786 |
|
---|
787 | bool bRet = RefreshAvailabilitySchedule();
|
---|
788 |
|
---|
789 | UpdateAllViews();
|
---|
790 |
|
---|
791 | return nApptID;
|
---|
792 | }
|
---|
793 |
|
---|
794 | public void EditAppointment(CGAppointment pAppt, string sNote)
|
---|
795 | {
|
---|
796 | try
|
---|
797 | {
|
---|
798 | int nApptID = pAppt.AppointmentKey;
|
---|
799 | string sSql = "BSDX EDIT APPOINTMENT^" + nApptID.ToString() + "^" + sNote;
|
---|
800 |
|
---|
801 | System.Data.DataTable dtAppt = m_DocManager.RPMSDataTable(sSql, "EditAppointment");
|
---|
802 |
|
---|
803 | Debug.Assert(dtAppt.Rows.Count == 1);
|
---|
804 | DataRow r = dtAppt.Rows[0];
|
---|
805 | string sErrorID = r["ERRORID"].ToString();
|
---|
806 | if (sErrorID == "-1")
|
---|
807 | pAppt.Note = sNote;
|
---|
808 |
|
---|
809 | if (this.m_appointments.AppointmentTable.ContainsKey(nApptID))
|
---|
810 | {
|
---|
811 | bool bRet = RefreshAvailabilitySchedule();
|
---|
812 | UpdateAllViews();
|
---|
813 | }
|
---|
814 | }
|
---|
815 | catch (Exception ex)
|
---|
816 | {
|
---|
817 | Debug.Write("CGDocument.EditAppointment Failed: " + ex.Message);
|
---|
818 | }
|
---|
819 | }
|
---|
820 |
|
---|
821 | public void CheckInAppointment(int nApptID, DateTime dCheckIn)
|
---|
822 | {
|
---|
823 | string sCheckIn = FMDateTime.Create(dCheckIn).FMDateString;
|
---|
824 |
|
---|
825 | string sSql = "BSDX CHECKIN APPOINTMENT^" + nApptID.ToString() + "^" + sCheckIn; // +"^";
|
---|
826 | //sSql += ClinicStopIEN + "^" + ProviderIEN + "^" + PrintRouteSlip + "^";
|
---|
827 | //sSql += PCCClinicIEN + "^" + PCCFormIEN + "^" + PCCOutGuide;
|
---|
828 |
|
---|
829 | System.Data.DataTable dtAppt = m_DocManager.RPMSDataTable(sSql, "CheckInAppointment");
|
---|
830 |
|
---|
831 | Debug.Assert(dtAppt.Rows.Count == 1);
|
---|
832 | DataRow r = dtAppt.Rows[0];
|
---|
833 | string sErrorID = r["ERRORID"].ToString();
|
---|
834 |
|
---|
835 | if (this.m_appointments.AppointmentTable.ContainsKey(nApptID))
|
---|
836 | {
|
---|
837 | bool bRet = RefreshSchedule();
|
---|
838 | UpdateAllViews();
|
---|
839 | }
|
---|
840 | }
|
---|
841 |
|
---|
842 | public string DeleteAppointment(int nApptID)
|
---|
843 | {
|
---|
844 | return DeleteAppointment(nApptID, true, 0, "");
|
---|
845 | }
|
---|
846 |
|
---|
847 | public string DeleteAppointment(int nApptID, bool bClinicCancelled, int nReason, string sRemarks)
|
---|
848 | {
|
---|
849 | //Returns "" if deletion successful
|
---|
850 | //Otherwise, returns reason for failure
|
---|
851 |
|
---|
852 | string sClinicCancelled = (bClinicCancelled == true)?"C":"PC";
|
---|
853 | string sReasonID = nReason.ToString();
|
---|
854 | string sSql = "BSDX CANCEL APPOINTMENT^" + nApptID.ToString();
|
---|
855 | sSql += "^" + sClinicCancelled;
|
---|
856 | sSql += "^" + sReasonID;
|
---|
857 | sSql += "^" + sRemarks;
|
---|
858 | DataTable dtAppt = m_DocManager.RPMSDataTable(sSql, "DeleteAppointment");
|
---|
859 |
|
---|
860 | Debug.Assert(dtAppt.Rows.Count == 1);
|
---|
861 | DataRow r = dtAppt.Rows[0];
|
---|
862 | string sErrorID = r["ERRORID"].ToString();
|
---|
863 | if (sErrorID != "")
|
---|
864 | return sErrorID;
|
---|
865 |
|
---|
866 | if (this.m_appointments.AppointmentTable.ContainsKey(nApptID))
|
---|
867 | {
|
---|
868 | this.m_appointments.RemoveAppointment(nApptID);
|
---|
869 | bool bRet = RefreshAvailabilitySchedule();
|
---|
870 | UpdateAllViews();
|
---|
871 | }
|
---|
872 | return "";
|
---|
873 | }
|
---|
874 |
|
---|
875 | public string AutoRebook(CGAppointment a, int nSearchType, int nMinimumDays, int nMaximumDays, out CGAppointment aRebook)
|
---|
876 | {
|
---|
877 | //If successful Returns "1" and new start date and time returned in aRebook
|
---|
878 | //Otherwise, returns error message
|
---|
879 |
|
---|
880 | CGAppointment aCopy = new CGAppointment();
|
---|
881 | aCopy.CreateAppointment(a.StartTime, a.EndTime, a.Note, 0, a.Resource);
|
---|
882 | aCopy.PatientID = a.PatientID;
|
---|
883 | aCopy.PatientName = a.PatientName;
|
---|
884 | aCopy.HealthRecordNumber = a.HealthRecordNumber;
|
---|
885 | aCopy.AccessTypeID = a.AccessTypeID;
|
---|
886 | aRebook = aCopy;
|
---|
887 |
|
---|
888 | //Determine Rebook access type
|
---|
889 | //nSearchType = -1: use current, -2: use any non-zero type, >0 use this access type id
|
---|
890 | int nAVType = 0;
|
---|
891 |
|
---|
892 | switch (nSearchType)
|
---|
893 | {
|
---|
894 | case -1:
|
---|
895 | nAVType = a.AccessTypeID;
|
---|
896 | break;
|
---|
897 | case -2:
|
---|
898 | nAVType = 0;
|
---|
899 | break;
|
---|
900 | default:
|
---|
901 | nAVType = nSearchType;
|
---|
902 | break;
|
---|
903 | }
|
---|
904 |
|
---|
905 | int nSlots = 0;
|
---|
906 | string sSlots = "";
|
---|
907 | int nAccessTypeID; //To compare with nAVType
|
---|
908 |
|
---|
909 | DateTime dResult = new DateTime(); //StartTime of access block to autorebook into
|
---|
910 |
|
---|
911 | //Next two are empty, but needed to pass to CreateAvailabilitySchedule
|
---|
912 | ArrayList alAccessTypes = new ArrayList();
|
---|
913 | string sSearchInfo = "";
|
---|
914 |
|
---|
915 | //Find the StartTime of first availability block of this type for this clinic
|
---|
916 | //between nMinimumDays and nMaximumDays
|
---|
917 |
|
---|
918 | string sAVStart = a.StartTime.AddDays(nMinimumDays).ToString("M/d/yyyy@H:mm");
|
---|
919 |
|
---|
920 | //dtAVEnd is the last day to search
|
---|
921 | DateTime dtAVEnd = a.StartTime.AddDays(nMinimumDays + nMaximumDays);
|
---|
922 | string sAVEnd = dtAVEnd.ToString("M/d/yyyy@H:mm");
|
---|
923 |
|
---|
924 | //Increment start day to search a week (or so) at a time
|
---|
925 | //30 is a test increment. Need to test different values for performance
|
---|
926 | int nIncrement = (nMaximumDays < 30)?nMaximumDays:30;
|
---|
927 |
|
---|
928 | //nCount and nCountEnd are the 'moving' counters
|
---|
929 | //that I add to start and end to get the bracket
|
---|
930 | //At the beginning of the DO loop, nCount and nCountEnd are already set
|
---|
931 | bool bFinished = false;
|
---|
932 | bool bFound = false;
|
---|
933 |
|
---|
934 | DateTime dStart = a.StartTime.AddDays(nMinimumDays);
|
---|
935 | // v 1.3 i18n support - FM Date passed insated of American Date
|
---|
936 | string sStart = FMDateTime.Create(dStart).DateOnly.FMDateString;
|
---|
937 | DateTime dEnd = dStart.AddDays(nIncrement);
|
---|
938 | do
|
---|
939 | {
|
---|
940 | string sSql = "BSDX REBOOK NEXT BLOCK^" + sStart + "^" + a.Resource + "^" + nAVType.ToString();
|
---|
941 | DataTable dtNextBlock = this.DocManager.RPMSDataTable(sSql, "NextBlock");
|
---|
942 | Debug.Assert(dtNextBlock.Rows.Count == 1);
|
---|
943 | DataRow drNextBlockRow = dtNextBlock.Rows[0];
|
---|
944 |
|
---|
945 | object oNextBlock;
|
---|
946 | oNextBlock = drNextBlockRow["NEXTBLOCK"];
|
---|
947 | if (oNextBlock.GetType() == typeof(System.DBNull))
|
---|
948 | break;
|
---|
949 | DateTime dNextBlock = (DateTime) drNextBlockRow["NEXTBLOCK"];
|
---|
950 | if (dNextBlock > dtAVEnd)
|
---|
951 | {
|
---|
952 | break;
|
---|
953 | }
|
---|
954 |
|
---|
955 | dStart = dNextBlock;
|
---|
956 | dEnd = dStart.AddDays(nIncrement);
|
---|
957 | if (dEnd > dtAVEnd)
|
---|
958 | dEnd = dtAVEnd;
|
---|
959 |
|
---|
960 | DataTable dtResult = CGSchedLib.CreateAvailabilitySchedule(m_DocManager, this.Resources, dStart, dEnd, alAccessTypes, ScheduleType.Resource, sSearchInfo);
|
---|
961 | //Loop thru dtResult looking for a slot having the required availability type.
|
---|
962 | //If found, set bFinished = true;
|
---|
963 | foreach (DataRow dr in dtResult.Rows)
|
---|
964 | {
|
---|
965 |
|
---|
966 | sSlots = dr["SLOTS"].ToString();
|
---|
967 | if (sSlots == "")
|
---|
968 | sSlots = "0";
|
---|
969 | nSlots = Convert.ToInt16(sSlots);
|
---|
970 | if (nSlots > 0)
|
---|
971 | {
|
---|
972 | nAccessTypeID = 0; //holds the access type id of the availability block
|
---|
973 | if (dr["ACCESS_TYPE"].ToString() != "")
|
---|
974 | nAccessTypeID =Convert.ToInt16(dr["ACCESS_TYPE"].ToString());
|
---|
975 | if ((nSearchType == -2) && (nAccessTypeID > 0)) //Match on any non-zero type
|
---|
976 | {
|
---|
977 | bFinished = true;
|
---|
978 | bFound = true;
|
---|
979 | dResult = (DateTime) dr["START_TIME"];
|
---|
980 | break;
|
---|
981 | }
|
---|
982 | if (nAccessTypeID == nAVType)
|
---|
983 | {
|
---|
984 | bFinished = true;
|
---|
985 | bFound = true;
|
---|
986 | dResult = (DateTime) dr["START_TIME"];
|
---|
987 | break;
|
---|
988 | }
|
---|
989 | }
|
---|
990 | }
|
---|
991 | dStart = dEnd.AddDays(1);
|
---|
992 | dEnd = dStart.AddDays(nIncrement);
|
---|
993 | if (dEnd > dtAVEnd)
|
---|
994 | dEnd = dtAVEnd;
|
---|
995 | } while (bFinished == false);
|
---|
996 |
|
---|
997 | if (bFound == true)
|
---|
998 | {
|
---|
999 | aCopy.StartTime = dResult;
|
---|
1000 | aCopy.EndTime = dResult.AddMinutes(a.Duration);
|
---|
1001 | //Create the appointment
|
---|
1002 | //Set the AUTOREBOOKED flag
|
---|
1003 | //and store the "AutoRebooked To DateTime"
|
---|
1004 | //in each autorebooked appointment
|
---|
1005 | this.CreateAppointment(aCopy);
|
---|
1006 | SetAutoRebook(a, dResult);
|
---|
1007 | return "1";
|
---|
1008 | }
|
---|
1009 | else
|
---|
1010 | {
|
---|
1011 | return "0";
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | private void SetAutoRebook(CGAppointment a, DateTime dtRebookedTo)
|
---|
1016 | {
|
---|
1017 | string sApptKey = a.AppointmentKey.ToString();
|
---|
1018 | //string sRebookedTo = dtRebookedTo.ToString("M/d/yyyy@HH:mm");
|
---|
1019 | // i18n
|
---|
1020 | string sRebookedTo = FMDateTime.Create(dtRebookedTo).FMDateString;
|
---|
1021 | string sSql = "BSDX REBOOK SET^" + sApptKey + "^" + sRebookedTo;
|
---|
1022 | System.Data.DataTable dtRebook = m_DocManager.RPMSDataTable(sSql, "AutoRebook");
|
---|
1023 |
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | public string AppointmentNoShow(int nApptID, bool bNoShow)
|
---|
1027 | {
|
---|
1028 | /*
|
---|
1029 | * BSDX NOSHOW RPC Returns 1 in ERRORID if successfully sets NOSHOW flag in BSDX APPOINTMENT and, if applicable, File 2
|
---|
1030 | *Otherwise, returns negative numbers for failure and errormessage in ERRORTXT
|
---|
1031 | *
|
---|
1032 | */
|
---|
1033 |
|
---|
1034 | string sTest = bNoShow.ToString();
|
---|
1035 | string sNoShow = (bNoShow == true)?"1":"0";
|
---|
1036 | string sSql = "BSDX NOSHOW^" + nApptID.ToString();
|
---|
1037 | sSql += "^";
|
---|
1038 | sSql += sNoShow;
|
---|
1039 |
|
---|
1040 | DataTable dtAppt = m_DocManager.RPMSDataTable(sSql, "AppointmentNoShow");
|
---|
1041 |
|
---|
1042 | Debug.Assert(dtAppt.Rows.Count == 1);
|
---|
1043 | DataRow r = dtAppt.Rows[0];
|
---|
1044 | string sErrorID = r["ERRORID"].ToString();
|
---|
1045 | if (sErrorID != "1")
|
---|
1046 | {
|
---|
1047 | return r["ERRORTEXT"].ToString();
|
---|
1048 | }
|
---|
1049 |
|
---|
1050 | bool bRet = RefreshSchedule();
|
---|
1051 |
|
---|
1052 | return sErrorID;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | #endregion Methods
|
---|
1056 |
|
---|
1057 | }//End class
|
---|
1058 | }//End namespace
|
---|