Ignore:
Timestamp:
Mar 20, 2011, 3:22:11 AM (13 years ago)
Author:
Sam Habiel
Message:

CalendarGrid:

  • Support for Autoscrolling corrected.
  • A little optimization: Grid is only drawn once now when starting, not twice (don't know why original code did that).

CGAppointment:

  • Added member Patient (new Class)

CGDocument:

  • OnOpenDocument now accepts input of DateTime to decide where to open document.
  • SlotsAvailable algorithm now includes code for scaling according to timescale and code to merge Blocks if they are adjacent.

CGDocumentManager:

  • Fix bug having to do with canceling log-in after first retry. BMX lib threw an exception which was not caught.

CGView: Many changes:

  • SlotsAvailable signature changed in CGDocument. All references to it had to be changed.
  • Opening a node in the tvSchedules by clicking on the plus sign did not select it. Code changes to make it select it.
  • UpdateStatusBar now uses a string builder; and shows a more comprehensive message on the availability in the Status Bar.
  • Focus issues on various controls.
  • Support for printing a slip after an appointment is made automatically has been added.

CustomPrinting:

  • now includes a method to print a single appointment slip

DAppointPage:

  • Checkbox to decide whether to print appt slip added.
  • New readonly property to get the appointment that has been made (of type CGAppointment).

DApptSearch:

  • StartDate and EndDate now autoadjust based on each other.
  • lblMessage added to show user message if no appointments are found.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Scheduling/trunk/cs/bsdx0200GUISourceCode/CGDocument.cs

    r1097 r1106  
    88using IndianHealthService.BMXNet;
    99using System.Linq;
     10using System.Collections.Generic;
    1011
    1112namespace IndianHealthService.ClinicalScheduling
     
    321322        }
    322323
    323         public void OnOpenDocument()
     324        public void OnOpenDocument(DateTime dDate)
    324325        {
    325326            try
     
    328329                m_ScheduleType = (m_sResourcesArray.Count == 1) ? ScheduleType.Resource : ScheduleType.Clinic;
    329330                bool bRet = false;
    330 
    331                 //Set initial From and To dates based on current day
    332                 DateTime dDate = DateTime.Today;
     331               
    333332                if (m_ScheduleType == ScheduleType.Resource)
    334333                {
     
    396395        private bool RefreshSchedule()
    397396        {
    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;
    418400        }
    419401
     
    637619        /// <param name="sAvailabilityMessage">Out: Access Note</param>
    638620        /// <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;
    645625
    646626            double slotsAvailable = 0;      //defalut return value
     627
     628            double effectiveSlotsAvailable = 0;    //Slots available based on the time scale.
     629
    647630
    648631            //NOTE: What's this lock? This lock makes sure that nobody is editing the availability array
     
    660643            {
    661644                //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)
    663646                //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               
    676714                //Subtract total slots current appointments take up.
    677715                slotsAvailable -= (from appt in this.Appointments.AppointmentTable.Values.Cast<CGAppointment>()
    678716                                   //If the resource is the same and the user selection overlaps, then...
    679                                    where (sResource == appt.Resource && CalendarGrid.TimesOverlap(pAVs[0].StartTime, pAVs[0].EndTime, appt.StartTime, appt.EndTime))
     717                                   where (sResource == appt.Resource && CalendarGrid.TimesOverlap(pAV.StartTime, pAV.EndTime, appt.StartTime, appt.EndTime))
    680718                                   // if appt starttime is before avail start time, only count against the avail starting from the availability start time
    681                                    let startTimeToCountAgainstBlock = appt.StartTime < pAVs[0].StartTime ? pAVs[0].StartTime : appt.StartTime
     719                                   let startTimeToCountAgainstBlock = appt.StartTime < pAV.StartTime ? pAV.StartTime : appt.StartTime
    682720                                   // if appt endtime is after the avail ends, only count against the avail up to where the avail ends
    683                                    let endTimeToCountAgainstBlock = appt.EndTime > pAVs[0].EndTime ? pAVs[0].EndTime : appt.EndTime
     721                                   let endTimeToCountAgainstBlock = appt.EndTime > pAV.EndTime ? pAV.EndTime : appt.EndTime
    684722                                   // theoretical minutes per slot for the availability
    685                                    let minPerSlot = (pAVs[0].EndTime - pAVs[0].StartTime).TotalMinutes / pAVs[0].Slots
     723                                   let minPerSlot = (pAV.EndTime - pAV.StartTime).TotalMinutes / pAV.Slots
    686724                                   // how many minutes does this appointment take away from the slot
    687725                                   let minPerAppt = (endTimeToCountAgainstBlock - startTimeToCountAgainstBlock).TotalMinutes
     
    691729                                   // add up SlotsConsumed to substract from slotsAvailable
    692730                                   .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;
    696742
    697743            /* OLD ALGOTHRIM 2
Note: See TracChangeset for help on using the changeset viewer.