public void Validate_RaisesValidationFailedEvent_WhenPatientDoesNotAttendForTheSecondTimeAndOnAPeriodWhereIsAbleToNotAttendFirstEventAndPeriodIsNotStopped() { // Arrange var period = new CancerPeriod { Pathway = new Pathway { Patient = new Patient { DateOfBirth = new DateTime(1990, 3, 5) } } }; var completedEvent = new ClockStartingCompletedEvent { Name = new EventName { Code = EventCode.DidNotAttend }, EventDate = new DateTime(2001, 1, 8), Period = period }; period.Add(new ClockStartingCompletedEvent { Name = new EventName { Code = EventCode.DidNotAttend }, EventDate = new DateTime(2001, 1, 9) }); var eventRaised = false; completedEvent.ValidationFailed += delegate { eventRaised = true; }; // Act completedEvent.Validate(); // Assert Assert.IsTrue(eventRaised); }
public void IsSecondCancelByPatient_ReturnsTrue_WhenPatientCancelsThreeTimesAndHospitalOnce() { // Arrange var rttPeriod = new CancerPeriod(); rttPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.PatientCancelEvent } }); 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.IsTrue(result); }
private Period GetCancerPeriod() { var period = new CancerPeriod { Pathway = new Pathway { Patient = new Patient { Name = "John Doe", DateOfBirth = new DateTime(1990, 2, 2) } } }; period.Add(new ClockStartingCompletedEvent { EventDate = new DateTime(2000, 12, 25), TargetDate = new DateTime(2000, 12, 25) }); period.Add(new ClockPausingCompletedEvent { EventDate = new DateTime(2000, 12, 27) }); period.Add(new ClockStartingCompletedEvent { EventDate = new DateTime(2000, 12, 29), TargetDate = new DateTime(2000, 12, 30) }); period.Add(new ClockPausingCompletedEvent { EventDate = new DateTime(2000, 12, 30), TargetDate = new DateTime(2001, 1, 3) }); period.Add(new ClockStartingCompletedEvent { EventDate = new DateTime(2001, 1, 1), TargetDate = new DateTime(2001, 1, 3) }); period.Add(new ClockStoppingCompletedEvent { EventDate = new DateTime(2001, 1, 2), TargetDate = new DateTime(2001, 1, 6) }); return(period); }
public void ApplyTo_CorrectlyOverwritesDateReferenceForTarget_WhenEventCodeIsOutpatientFirstAppointmentAttended() { // Arrange var period = new CancerPeriod(); period.Add(new ClockStartingCompletedEvent { EventDate = new DateTime(2000, 6, 1), Name = new EventName { Code = EventCode.ReferralReceived } }); var eventMilestone = new EventMilestone { DateReferenceForTarget = new DateTime(2000, 12, 1), Name = new EventName { Code = EventCode.AttendedOutpatientFirstAppointment }, CompletedEvent = new ClockTickingCompletedEvent { Cancer = true, Period = period } }; var sut = new EventMilestoneDateReferenceForTargetCancerPolicy(); // Act sut.ApplyTo(eventMilestone); // Assert Assert.AreEqual(new DateTime(2000, 6, 1), eventMilestone.DateReferenceForTarget); }
public void IsSecondDidNotAttend_ReturnsFalse_WhenPatientDoesNotAttendFirstTime() { // Arrange var rttPeriod = new CancerPeriod(); // Act var result = rttPeriod.IsSecondDidNotAttend(EventCode.DidNotAttend); // Assert Assert.IsFalse(result); }
public void Add_DoesNotRaiseValidationFailedEvent_WhenCurrentEventHasTargetReferenceEvent() { //Arrange var completedEvent = new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.AttendedOutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 20) }; var cancerPeriod = new CancerPeriod(); cancerPeriod.Add(new ClockStartingCompletedEvent { Name = new EventName { Code = EventCode.ReferralReceived }, EventDate = new DateTime(2014, 5, 6) }); cancerPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.ReferralReview }, EventDate = new DateTime(2014, 5, 10) }); cancerPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.BookedOutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 12) }); cancerPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.OutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 14) }); cancerPeriod.Add(completedEvent); var eventMilestone = new EventMilestone { Name = new EventName { Code = EventCode.OutcomedOutpatientFirstAppointment } }; var eventRaised = false; cancerPeriod.ValidationFailed += delegate { eventRaised = true; }; //Act cancerPeriod.MapEventMilestoneToCompletedEvent(completedEvent, eventMilestone, new EventName { Code = EventCode.AttendedOutpatientFirstAppointment, Description = "Attended Outpatient First Appointment" }); //Assert Assert.IsFalse(eventRaised); }
public void IsSecondDidNotAttend_ReturnsTrue_WhenPatientDoesNotAttendSecondTime() { // Arrange var rttPeriod = new CancerPeriod(); rttPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.DidNotAttend } }); // Act var result = rttPeriod.IsSecondDidNotAttend(EventCode.DidNotAttend); // Assert Assert.IsTrue(result); }
private Period GetCancerPeriodWithoutDiagnosticTestResultAvailable() { var period = new CancerPeriod { StartDate = new DateTime(2000, 12, 01), Pathway = new Pathway() }; period.Add(new ClockStartingCompletedEvent { EventDate = new DateTime(2000, 12, 01), TargetDate = new DateTime(2000, 12, 01), Name = new EventName { Code = EventCode.ReferralReceived } }); period.Add(new ClockTickingCompletedEvent { EventDate = new DateTime(2000, 12, 10), Name = new EventName { Code = EventCode.DiagnosticsOrderPlaced } }); return(period); }
public void Add_RaisesValidationFailedEvent_WhenCurrentEventDoesNotHaveTargetReferenceEvent() { //Arrange var completedEvent = new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.AttendedOutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 20), Period = new RTT18WeekPeriod { Pathway = new Pathway { PPINumber = "ppi" }, Name = "period 1" } }; var cancerPeriod = new CancerPeriod(); cancerPeriod.Add(new ClockStartingCompletedEvent { Name = new EventName { Code = EventCode.ReferralReceived }, EventDate = new DateTime(2014, 5, 6), Period = new RTT18WeekPeriod { Pathway = new Pathway { PPINumber = "ppi" }, Name = "period 1" } }); cancerPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.ReferralReview }, EventDate = new DateTime(2014, 5, 10), Period = new RTT18WeekPeriod { Pathway = new Pathway { PPINumber = "ppi" }, Name = "period 1" } }); cancerPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.BookedOutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 12), Period = new RTT18WeekPeriod { Pathway = new Pathway { PPINumber = "ppi" }, Name = "period 1" } }); cancerPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.OutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 14), Period = new RTT18WeekPeriod { Pathway = new Pathway { PPINumber = "ppi" }, Name = "period 1" } }); var eventMilestone = new EventMilestone { Name = new EventName { Code = EventCode.OutcomedOutpatientFirstAppointment } }; var eventRaised = false; cancerPeriod.ValidationFailed += delegate { eventRaised = true; }; //Act cancerPeriod.MapEventMilestoneToCompletedEvent(completedEvent, eventMilestone, new EventName { Code = EventCode.AttendedOutpatientFirstAppointment, Description = "Attended Outpatient First Appointment" }); //Assert Assert.IsTrue(eventRaised); }
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)); }