Example #1
0
        /// <summary>
        /// Handles the visit-moved event from Docplanner
        /// </summary>
        /// <param name="notification"></param>
        /// <returns></returns>
        public bool MoveVisit(Booking oldVisit, Booking newVisit, DPFacility facility, DPDoctor doctor, Address address)
        {
            var visit = _visitRepository.GetByForeignId(oldVisit.Id);

            if (_scheduleManager.IsSlotExist(newVisit.StartAt.LocalDateTime.ChangeTimeZone(timeZone), newVisit.EndAt.LocalDateTime.ChangeTimeZone(timeZone), visit.DoctorFacility))
            {
                visit.ForeignVisitId = newVisit.Id;
                visit.StartAt        = newVisit.StartAt.LocalDateTime.ChangeTimeZone(timeZone);
                visit.EndAt          = newVisit.EndAt.LocalDateTime.ChangeTimeZone(timeZone);

                var oldSchedule = visit.DoctorSchedule;
                var newSchedule = _scheduleManager.FindDoctorSchedule(visit.DoctorFacility, visit.StartAt, visit.EndAt, newVisit.Service.Id);

                visit.DoctorSchedule   = newSchedule;
                visit.DoctorScheduleId = newSchedule.Id;

                _scheduleManager.RestoreSchedule(oldSchedule);
                _scheduleManager.ArrangeSchedule(visit);

                return(true);
            }
            else
            {
                CancelVisit(visit, false);
                CancelVisitDP(visit);
                CancelVisitDP(facility.Id, doctor.Id, address.Id, newVisit.Id);

                return(false);
            }
        }