예제 #1
0
        /// <summary>
        /// Create a list of all visits preceding the supplied visit
        /// </summary>
        /// <param name="visit">The visit for which the history of visits is requested</param>
        /// <returns></returns>
        public ICollection <Visit> GetPastVisits(Visit visit)
        {
            if (visit == null)
            {
                return(null);
            }
            var pastVisits = new ObservableCollection <Visit>();

            var list = Visits.OrderBy(v => v.PlannedStart);

            foreach (var pastVisit in list)
            {
                if (pastVisit.Id == visit.Id)
                {
                    break;
                }
                pastVisits.Add(pastVisit);
            }
            return(pastVisits);
        }
예제 #2
0
        public static LogOff Create(Visit visit, ILoggedPart part, string login)
        {
            if (visit == null)
            {
                return(null);
            }
            if (part == null)
            {
                return(null);
            }

            var logOff = new LogOff
            {
                VisitId = visit.Id,
                Visit   = visit,
                PartId  = part.Id,
                Part    = (Part)part
            };

            logOff.SetAuditInfo(login);
            return(logOff);
        }
예제 #3
0
        public void UpdateStatusDueToAppointmentBooking(Visit bookedVisit, BookingRemark bookingRemark, UserRole userRole)
        {
            if (bookingRemark == null)
            {
                return;
            }

            // preconditions
            if (Status != WorkStatusType.VisitNeeded &&
                Status != WorkStatusType.VisitOpen)
            {
                return;
            }
            if (bookedVisit != null ||
                bookingRemark.ResultCode.Outcome != ResultCodeOutcomeType.Done)
            {
                WorkOrderRemarks.Add(bookingRemark);
            }

            // check when status VISIT_NEEDED
            if (Status == WorkStatusType.VisitNeeded)
            {
                if (bookingRemark.ResultCode.Outcome == ResultCodeOutcomeType.Done)
                {
                    if (bookedVisit != null)
                    {
                        var visit = Visits.FirstOrDefault(v => v.Id == bookedVisit.Id);
                        if (visit == null)
                        {
                            Visits.Add(bookedVisit);
                        }
                        else
                        {
                            visit.AppointmentWindowId = bookedVisit.AppointmentWindowId;
                            visit.AppointmentWindow   = bookedVisit.AppointmentWindow;
                            visit.WindowStart         = bookedVisit.WindowStart;
                            visit.WindowEnd           = bookedVisit.WindowEnd;
                        }
                    }
                }
                if (bookingRemark.ResultCode.Outcome == ResultCodeOutcomeType.Abort)
                {
                    ChangeStatusTo(WorkStatusType.Closed, userRole);
                }
            }

            // check when status VISIT_OPEN
            if (Status == WorkStatusType.VisitOpen)
            {
                var visit = Visits.OrderByDescending(v => v.WindowStart)
                            .FirstOrDefault();
                if (visit != null && visit.SuperState == VisitSuperStateType.Provisional)
                {
                    if (bookingRemark.ResultCode.Outcome == ResultCodeOutcomeType.Done &&
                        bookedVisit != null)
                    {
                        visit.AppointmentWindowId = bookedVisit.AppointmentWindowId;
                        visit.AppointmentWindow   = bookedVisit.AppointmentWindow;
                        visit.WindowStart         = bookedVisit.WindowStart;
                        visit.WindowEnd           = bookedVisit.WindowEnd;
                    }
                    if (bookingRemark.ResultCode.Outcome == ResultCodeOutcomeType.Abort)
                    {
                        visit.ChangeStatusTo(VisitStatusType.Closed, userRole);
                        ChangeStatusTo(WorkStatusType.Closed, userRole);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Update the WorkOrder's Status based on the status from (last) visit
        /// </summary>
        /// <param name="visit">The visit that will trigger the Workorder's status change</param>
        /// <param name="currentUserRole">The user requesting the status change</param>
        public void UpdateStatus(UserRole currentUserRole, Visit visit = null, bool doForce = false)
        {
            if (currentUserRole == null)
            {
                throw new ArgumentNullException(nameof(currentUserRole));
            }

            #region check transition NotReady => VisitNeeded
            if (Status == WorkStatusType.NotReady)
            {
                var doStatusChange = false;
                // rule: check all data is complete
                doStatusChange = ((WorkSpecificationId > 0 || WorkSpecification != null) &&
                                  (LocationId > 0 || Location != null) &&
                                  (TaskInfos.Any()));

                // rule: No visit exists yet or last visit has status closed with redo.
                var closedVisit = Visits.OrderByDescending(v => v.WindowStart)
                                  .FirstOrDefault();
                var isLastVisitClosedWithRedo = doForce || (closedVisit?.ResultCode != null &&
                                                            closedVisit.Status == VisitStatusType.Closed &&
                                                            closedVisit.ResultCode.Outcome == ResultCodeOutcomeType.Redo);
                doStatusChange = doStatusChange &&
                                 (!Visits.Any() || isLastVisitClosedWithRedo);
                if (doStatusChange)
                {
                    ChangeStatusTo(WorkStatusType.VisitNeeded, currentUserRole);
                }
            }
            #endregion

            #region check transition VisitNeeded => VisitOpen (or Aborted)
            if (Status == WorkStatusType.VisitNeeded)
            {
                // rule: at least one visit and last visit not in status closed
                var lastVisit = Visits.OrderByDescending(v => v.WindowStart)
                                .FirstOrDefault(v => v.Status != VisitStatusType.Closed);

                // rule: there is an appointment booked
                if (lastVisit != null && lastVisit.IsAppointmentBooked)
                {
                    ChangeStatusTo(WorkStatusType.VisitOpen, currentUserRole);
                }
            }
            #endregion

            #region check transition VisitOpen => Closed (or Aborted)
            if (Status == WorkStatusType.VisitOpen)
            {
                // (OR) rule: at least one ans last visit is closed with outcome done
                var lastVisit = Visits.OrderByDescending(v => v.WindowStart)
                                .FirstOrDefault(v => v.Status == VisitStatusType.Closed);
                if (lastVisit?.ResultCode != null &&
                    lastVisit.ResultCode.Outcome == ResultCodeOutcomeType.Done)
                {
                    ChangeStatusTo(WorkStatusType.Closed, currentUserRole);
                }
                else
                {
                    // (OR) rule: last remark booking with result code abort
                    var lastRemark = WorkOrderRemarks.OfType <BookingRemark>()
                                     .OrderByDescending(br => br.EnteredDate)
                                     .FirstOrDefault();
                    if (lastRemark?.ResultCode != null &&
                        lastRemark.ResultCode.Outcome == ResultCodeOutcomeType.Abort)
                    {
                        ChangeStatusTo(WorkStatusType.Closed, currentUserRole);
                    }
                }
            }
            #endregion

            // TODO Alain still relevatnt?
            #region check if the supplied visit is the last one in workorder
            if (visit != null)
            {
                var lastVisit = Visits.OrderByDescending(v => v.PlannedStart).First();
                if (visit.Id != lastVisit.Id)
                {
                    return;
                }

                if (visit.Status == VisitStatusType.Closed)
                {
                    if (visit.ResultCode == null)
                    {
                        throw new NotSupportedException(Translations.WorkOrderResultCodeRequired);
                    }
                    switch (visit.ResultCode.Outcome)
                    {
                    case ResultCodeOutcomeType.Abort:
                        ChangeStatusTo(WorkStatusType.Aborted, currentUserRole);
                        break;

                    case ResultCodeOutcomeType.Redo:
                        ChangeStatusTo(WorkStatusType.VisitNeeded, currentUserRole);
                        break;

                    case ResultCodeOutcomeType.Done:
                        ChangeStatusTo(WorkStatusType.Closed, currentUserRole);
                        break;
                    }
                }
                if (visit.Status == VisitStatusType.Aborted)
                {
                    ChangeStatusTo(WorkStatusType.Aborted, currentUserRole);
                }
            }
            #endregion
        }