Changeset 1106 for Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocument.cs
- Timestamp:
- Mar 20, 2011, 3:22:11 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocument.cs
r1097 r1106 8 8 using IndianHealthService.BMXNet; 9 9 using System.Linq; 10 using System.Collections.Generic; 10 11 11 12 namespace IndianHealthService.ClinicalScheduling … … 321 322 } 322 323 323 public void OnOpenDocument( )324 public void OnOpenDocument(DateTime dDate) 324 325 { 325 326 try … … 328 329 m_ScheduleType = (m_sResourcesArray.Count == 1) ? ScheduleType.Resource : ScheduleType.Clinic; 329 330 bool bRet = false; 330 331 //Set initial From and To dates based on current day 332 DateTime dDate = DateTime.Today; 331 333 332 if (m_ScheduleType == ScheduleType.Resource) 334 333 { … … 396 395 private bool RefreshSchedule() 397 396 { 398 try 399 { 400 bool bRet = this.RefreshAvailabilitySchedule(); 401 if (bRet == false) 402 { 403 return bRet; 404 } 405 bRet = this.RefreshDaysSchedule(); 406 return bRet; 407 } 408 catch (ApplicationException aex) 409 { 410 Debug.Write("CGDocument.RefreshSchedule Application Error: " + aex.Message + "\n"); 411 return false; 412 } 413 catch (Exception ex) 414 { 415 MessageBox.Show("CGDocument.RefreshSchedule error: " + ex.Message + "\n"); 416 return false; 417 } 397 this.RefreshAvailabilitySchedule(); 398 this.RefreshDaysSchedule(); 399 return true; 418 400 } 419 401 … … 637 619 /// <param name="sAvailabilityMessage">Out: Access Note</param> 638 620 /// <returns>Number of slots</returns> 639 public int SlotsAvailable(DateTime dSelStart, DateTime dSelEnd, string sResource, out string sAccessType, out string sAvailabilityMessage) 640 { 641 642 643 sAccessType = ""; //default out value 644 sAvailabilityMessage = ""; //default out value 621 public int SlotsAvailable(DateTime dSelStart, DateTime dSelEnd, string sResource, int viewTimeScale, out CGAvailability resultantAV) 622 { 623 624 resultantAV = null; 645 625 646 626 double slotsAvailable = 0; //defalut return value 627 628 double effectiveSlotsAvailable = 0; //Slots available based on the time scale. 629 647 630 648 631 //NOTE: What's this lock? This lock makes sure that nobody is editing the availability array … … 660 643 { 661 644 //This foreach loop looks for an availability that overlaps where the user clicked. 662 // There can only be one, as availabilites cannot overlap each other (enforced at the DB level)645 //Availabilites cannot overlap each other (enforced at the DB level) 663 646 //If selection hits multiple blocks, get the block with the most slots (reflected by the sorting here) 664 CGAvailability[] pAVs = (from pAV in this.m_pAvArray.Cast<CGAvailability>() 665 where (sResource == pAV.ResourceList && CalendarGrid.TimesOverlap(dSelStart, dSelEnd, pAV.StartTime, pAV.EndTime)) 666 orderby pAV.Slots descending 667 select pAV) 668 .ToArray<CGAvailability>(); 669 670 if ((pAVs.Length) == 0) return 0; 671 672 slotsAvailable = pAVs[0].Slots; 673 sAccessType = pAVs[0].AccessTypeName; 674 sAvailabilityMessage = pAVs[0].Note; 675 647 List<CGAvailability> lstAV = (from avail in this.m_pAvArray.Cast<CGAvailability>() 648 where (sResource == avail.ResourceList && CalendarGrid.TimesOverlap(dSelStart, dSelEnd, avail.StartTime, avail.EndTime)) 649 select avail).ToList(); 650 651 //if we don't have any availabilities, then return with zero slots. 652 if (lstAV.Count == 0) return 0; 653 654 CGAvailability pAV; 655 656 //if there is just one, that's it. 657 if (lstAV.Count == 1) pAV = lstAV.First(); 658 //otherwise... 659 else 660 { 661 //if availabilities are contigous to each other, need to join them together. 662 663 //First, are they the same? 664 string firsttype = lstAV.First().AccessTypeName; 665 bool bAllSameType = lstAV.All(av => av.AccessTypeName == firsttype); 666 667 //Second are they ALL contigous? 668 DateTime lastEndTime = DateTime.Today; //bogus value to please compiler who wants it assigned. 669 int index = 0; 670 671 bool bContigous = lstAV.OrderBy(av => av.StartTime) 672 .All(av => 673 { 674 index++; 675 if (index == 1) 676 { 677 lastEndTime = av.EndTime; 678 return true; 679 } 680 if (av.StartTime == lastEndTime) 681 { 682 lastEndTime = av.EndTime; 683 return true; 684 } 685 686 return false; 687 }); 688 689 690 691 if (bContigous && bAllSameType) 692 { 693 var enumAVOrdered = lstAV.OrderBy(av => av.StartTime); 694 695 pAV = new CGAvailability 696 { 697 StartTime = enumAVOrdered.First().StartTime, 698 EndTime = enumAVOrdered.Last().EndTime, 699 Slots = enumAVOrdered.Sum(av => av.Slots), 700 AccessTypeName = enumAVOrdered.First().AccessTypeName, 701 Note = enumAVOrdered.First().Note 702 }; 703 } 704 else 705 { 706 pAV = lstAV.OrderByDescending(av => av.Slots).First(); 707 } 708 } 709 710 resultantAV = pAV; // out var 711 712 slotsAvailable = pAV.Slots; 713 676 714 //Subtract total slots current appointments take up. 677 715 slotsAvailable -= (from appt in this.Appointments.AppointmentTable.Values.Cast<CGAppointment>() 678 716 //If the resource is the same and the user selection overlaps, then... 679 where (sResource == appt.Resource && CalendarGrid.TimesOverlap(pAV s[0].StartTime, pAVs[0].EndTime, appt.StartTime, appt.EndTime))717 where (sResource == appt.Resource && CalendarGrid.TimesOverlap(pAV.StartTime, pAV.EndTime, appt.StartTime, appt.EndTime)) 680 718 // if appt starttime is before avail start time, only count against the avail starting from the availability start time 681 let startTimeToCountAgainstBlock = appt.StartTime < pAV s[0].StartTime ? pAVs[0].StartTime : appt.StartTime719 let startTimeToCountAgainstBlock = appt.StartTime < pAV.StartTime ? pAV.StartTime : appt.StartTime 682 720 // if appt endtime is after the avail ends, only count against the avail up to where the avail ends 683 let endTimeToCountAgainstBlock = appt.EndTime > pAV s[0].EndTime ? pAVs[0].EndTime : appt.EndTime721 let endTimeToCountAgainstBlock = appt.EndTime > pAV.EndTime ? pAV.EndTime : appt.EndTime 684 722 // theoretical minutes per slot for the availability 685 let minPerSlot = (pAV s[0].EndTime - pAVs[0].StartTime).TotalMinutes / pAVs[0].Slots723 let minPerSlot = (pAV.EndTime - pAV.StartTime).TotalMinutes / pAV.Slots 686 724 // how many minutes does this appointment take away from the slot 687 725 let minPerAppt = (endTimeToCountAgainstBlock - startTimeToCountAgainstBlock).TotalMinutes … … 691 729 // add up SlotsConsumed to substract from slotsAvailable 692 730 .Sum(); 693 } 694 695 return (int)slotsAvailable; 731 732 //theoretical minutes per slot for the availability 733 double minPerSlot2 = (pAV.EndTime - pAV.StartTime).TotalMinutes / pAV.Slots; 734 735 //Convert it to the view's time scale. 736 effectiveSlotsAvailable = (minPerSlot2 / viewTimeScale) * slotsAvailable; 737 738 } 739 740 //round it down. 741 return (int)effectiveSlotsAvailable; 696 742 697 743 /* OLD ALGOTHRIM 2
Note:
See TracChangeset
for help on using the changeset viewer.