Beispiel #1
0
        public void IsSecondCancelByPatient_ReturnsFalse_WhenPatientCancelsTheSecondTimeAndHospitalOnce()
        {
            // Arrange
            var rttPeriod = new Non18WeekPeriod {
                Pathway = new Pathway {
                    Patient = new Patient {
                        Name = "John Doe", DateOfBirth = new DateTime(1990, 2, 2)
                    }
                }
            };

            rttPeriod.Add(new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.PatientCancelEvent
                }
            });
            rttPeriod.Add(new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.HospitalCancelEvent
                }
            });

            // Act
            var result = rttPeriod.IsSecondCancelByPatient(EventCode.PatientCancelEvent);

            // Assert
            Assert.IsFalse(result);
        }
Beispiel #2
0
        public void MapEventMilestoneToCompletedEvent_DoesNotRaiseValidationFailedEvent_WhenCurrentEventHasTargetReferenceEvent()
        {
            //Arrange
            var non18WeekPeriod = new Non18WeekPeriod {
                Pathway = new Pathway {
                    Patient = new Patient {
                        Name = "John Doe", DateOfBirth = new DateTime(1990, 2, 2)
                    }, PPINumber = "ppi"
                }, Name = "period 1"
            };
            var completedEvent = new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.AttendedOutpatientFirstAppointment
                }, EventDate = new DateTime(2014, 5, 20), Period = non18WeekPeriod
            };

            non18WeekPeriod.Add(new ClockStartingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.ReferralReceived
                }, EventDate = new DateTime(2014, 5, 6)
            });
            non18WeekPeriod.Add(new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.ReferralReview
                }, EventDate = new DateTime(2014, 5, 10)
            });
            non18WeekPeriod.Add(new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.BookedOutpatientFirstAppointment
                }, EventDate = new DateTime(2014, 5, 12)
            });
            non18WeekPeriod.Add(new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.OutpatientFirstAppointment
                }, EventDate = new DateTime(2014, 5, 14)
            });
            non18WeekPeriod.Add(completedEvent);

            var eventMilestone = new EventMilestone {
                Name = new EventName {
                    Code = EventCode.OutcomedOutpatientFirstAppointment
                }
            };

            RuleViolation eventRaised = null;

            non18WeekPeriod.ValidationFailed += delegate { eventRaised = new RuleViolation(); };

            //Act
            non18WeekPeriod.MapEventMilestoneToCompletedEvent(completedEvent, eventMilestone, new EventName {
                Code = EventCode.AttendedOutpatientFirstAppointment, Description = "Attended Outpatient First Appointment"
            });

            //Assert
            Assert.IsNull(eventRaised);
        }
Beispiel #3
0
        public void IsSecondDidNotAttend_ReturnsFalse_WhenPatientDoesNotAttendFirstTime()
        {
            // Arrange
            var rttPeriod = new Non18WeekPeriod {
                Pathway = new Pathway {
                    Patient = new Patient {
                        Name = "John Doe", DateOfBirth = new DateTime(1990, 2, 2)
                    }
                }
            };

            // Act
            var result = rttPeriod.IsSecondDidNotAttend(EventCode.DidNotAttend);

            // Assert
            Assert.IsFalse(result);
        }
Beispiel #4
0
        private Period GetNon18WeekPeriod()
        {
            var period = new Non18WeekPeriod {
                Pathway = new Pathway {
                    Patient = new Patient {
                        Name = "John Doe", DateOfBirth = new DateTime(1990, 2, 2)
                    }, PPINumber = "ppi"
                }, Name = "period 1"
            };

            period.Add(new ClockTickingCompletedEvent {
                EventDate = new DateTime(2000, 12, 25), TargetDate = new DateTime(2000, 12, 25)
            });
            period.Add(new ClockTickingCompletedEvent {
                EventDate = new DateTime(2000, 12, 27)
            });

            return(period);
        }
Beispiel #5
0
        public void IsSecondDidNotAttend_ReturnsTrue_WhenPatientDoesNotAttendSecondTime()
        {
            // Arrange
            var rttPeriod = new Non18WeekPeriod {
                Pathway = new Pathway {
                    Patient = new Patient {
                        Name = "John Doe", DateOfBirth = new DateTime(1990, 2, 2)
                    }
                }
            };

            rttPeriod.Add(new ClockTickingCompletedEvent {
                Name = new EventName {
                    Code = EventCode.DidNotAttend
                }
            });

            // Act
            var result = rttPeriod.IsSecondDidNotAttend(EventCode.DidNotAttend);

            // Assert
            Assert.IsTrue(result);
        }
Beispiel #6
0
        public ActionResult Add(AddCompletedEventInputModel addCompletedEventInputModel)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = new UnitOfWork())
                {
                    var currentPeriod = GetCurrentActivePeriod(addCompletedEventInputModel.SelectedPPINumber, unitOfWork) ??
                                        GetLastPeriod(addCompletedEventInputModel.SelectedPPINumber, unitOfWork);

                    Period period;
                    if (addCompletedEventInputModel.SelectedEventCode == EventCode.ReferralReceived)
                    {
                        var pathway =
                            unitOfWork.Pathways.Include(p => p.Patient).Include(p => p.Periods).FirstOrDefault(p => p.PPINumber == addCompletedEventInputModel.SelectedPPINumber);

                        if (addCompletedEventInputModel.Cancer)
                        {
                            period = new CancerPeriod
                            {
                                IsActive  = true,
                                Pathway   = pathway,
                                Name      = GetNextPeriodName(currentPeriod),
                                StartDate = addCompletedEventInputModel.Date.Value
                            };
                        }
                        else
                        {
                            period = new RTT18WeekPeriod
                            {
                                IsActive  = true,
                                Pathway   = pathway,
                                Name      = GetNextPeriodName(currentPeriod),
                                StartDate = addCompletedEventInputModel.Date.Value
                            };
                        }

                        SetCurrentPeriodToInactive(currentPeriod);
                        SetStopDateForNon18WPeriod(currentPeriod, addCompletedEventInputModel.Date.Value);

                        AddPeriodToPathway(pathway, period, unitOfWork);
                    }
                    else
                    {
                        period = currentPeriod;

                        if (period == null || !period.IsActive)
                        {
                            if (period == null || period.StopDate != null)
                            {
                                var periodName = (period != null && !string.IsNullOrEmpty(period.Name))
                                    ? GetNextPeriodName(period)
                                    : string.Concat(PeriodName, "1");

                                var pathway =
                                    unitOfWork.Pathways.FirstOrDefault(
                                        p => p.PPINumber == addCompletedEventInputModel.SelectedPPINumber);

                                period = new Non18WeekPeriod
                                {
                                    IsActive  = true,
                                    Pathway   = pathway,
                                    Name      = periodName,
                                    StartDate = addCompletedEventInputModel.Date.Value
                                };

                                AddPeriodToPathway(pathway, period, unitOfWork);
                            }
                        }
                        else
                        {
                            if (addCompletedEventInputModel.Cancer && !(period.GetType() == typeof(CancerPeriod)))
                            {
                                var cancerPeriod = new CancerPeriod
                                {
                                    IsActive  = period.IsActive,
                                    Name      = period.Name,
                                    Pathway   = period.Pathway,
                                    StartDate = period.StartDate,
                                    StopDate  = period.StopDate
                                };

                                AddPeriodToPathway(period.Pathway, cancerPeriod, unitOfWork);

                                unitOfWork.Periods.Add(cancerPeriod);
                                unitOfWork.SaveChanges();

                                foreach (var completedEvent in period.CompletedEvents)
                                {
                                    completedEvent.Period = cancerPeriod;
                                    cancerPeriod.Add(completedEvent);
                                }

                                unitOfWork.Periods.Remove(period);
                                unitOfWork.SaveChanges();

                                period = cancerPeriod;
                            }
                        }
                    }

                    var eventNames        = unitOfWork.EventNames.ToList();
                    var newCompletedEvent = BuildCompletedEvent(addCompletedEventInputModel.SelectedClockType, addCompletedEventInputModel.SelectedEventCode, addCompletedEventInputModel.Date.Value, period);

                    newCompletedEvent.Comments  = addCompletedEventInputModel.Comments;
                    newCompletedEvent.EventDate = addCompletedEventInputModel.Date.Value;
                    newCompletedEvent.Clinician = GetClinician(addCompletedEventInputModel.SelectedClinician, unitOfWork);
                    newCompletedEvent.Name      = eventNames.FirstOrDefault(eventName => eventName.Code == addCompletedEventInputModel.SelectedEventCode);
                    newCompletedEvent.Cancer    = addCompletedEventInputModel.Cancer;
                    newCompletedEvent.IsActive  = true;
                    if (newCompletedEvent.GetType() == typeof(ClockStoppingCompletedEvent))
                    {
                        newCompletedEvent.IsActive = false;
                        period.IsActive            = false;
                        period.StopDate            = newCompletedEvent.EventDate;
                    }
                    period.ValidationFailed += ruleViolation =>
                    {
                        ruleViolation.CreatedAt = DateTime.UtcNow;
                        unitOfWork.RuleViolations.Add(ruleViolation);
                    };
                    period.Add(newCompletedEvent);

                    newCompletedEvent.Period = period;

                    newCompletedEvent.TargetDate = GetTargetReferenceDate(newCompletedEvent, unitOfWork);
                    new CompletedEventTargetDateCancerPolicy().ApplyTo(newCompletedEvent);

                    newCompletedEvent.IsBreached = newCompletedEvent.PostBreachDays != null;

                    SetCurrentCompletedEventToInactive(addCompletedEventInputModel.SelectedPPINumber, unitOfWork);

                    newCompletedEvent.ValidationFailed += ruleViolation =>
                    {
                        ruleViolation.CreatedAt = DateTime.UtcNow;
                        unitOfWork.RuleViolations.Add(ruleViolation);
                    };
                    newCompletedEvent.Validate();

                    unitOfWork.CompletedEvents.Add(newCompletedEvent);
                    unitOfWork.SaveChanges();

                    if (newCompletedEvent.Period.GetType() != typeof(Non18WeekPeriod))
                    {
                        AddEventMilestonesForCompletedEvent(period, newCompletedEvent, eventNames, unitOfWork);
                        unitOfWork.SaveChanges();
                    }
                }

                return(RedirectToAction("Add"));
            }

            InitializeViewModel(addCompletedEventInputModel);

            return(View(addCompletedEventInputModel));
        }