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); }
private bool IsEventMilestoneMatched(EventMilestone eventMilestone, PeriodEventsFilterInputInfo periodEventsFilterInput) { if ((periodEventsFilterInput == null)) { return(true); } var daysToBreachAt = eventMilestone.GetDaysToBreachAt(_clock.TodayDate); var isEventMilestoneMatched = (String.IsNullOrEmpty(periodEventsFilterInput.Specialty) || eventMilestone.CompletedEvent.Clinician.Specialty.Name.ToLowerInvariant().Contains(periodEventsFilterInput.Specialty.ToLowerInvariant())) && (periodEventsFilterInput.TargetYear == null || (eventMilestone.BreachDate != null && eventMilestone.BreachDate.Value.Year == periodEventsFilterInput.TargetYear)) && (periodEventsFilterInput.ActualYear == null) && (string.IsNullOrEmpty(periodEventsFilterInput.EventDescription) || eventMilestone.Name.Description.Contains(periodEventsFilterInput.EventDescription)); if (periodEventsFilterInput.Breaches == null) { return(isEventMilestoneMatched); } if (daysToBreachAt == null) { return(false); } if (periodEventsFilterInput.Breaches < 0) { return(isEventMilestoneMatched && (((int)daysToBreachAt) < 0)); } if (periodEventsFilterInput.Breaches == FourDaysToBreach) { return(isEventMilestoneMatched && (((int)daysToBreachAt) >= FourDaysToBreach)); } return(isEventMilestoneMatched && daysToBreachAt == periodEventsFilterInput.Breaches); }
public void GetRemainingDays_ReturnsComputedDaysNumber_WhenBreachDateIsNotNull() { // Arrange var period = new RTT18WeekPeriod(); period.Add(new ClockStartingCompletedEvent { EventDate = new DateTime(2014, 7, 1), TargetDate = new DateTime(2014, 7, 1) }); var @event = new ClockTickingCompletedEvent { Period = period, EventDate = new DateTime(2014, 7, 1) }; var eventMilestone = new EventMilestone { TargetNumberOfDays = 3, DateReferenceForTarget = new DateTime(2014, 7, 1), Id = 1, CompletedEvent = @event }; // Act var result = eventMilestone.GetDaysToBreachAt(new DateTime(2014, 7, 6)); // Assert Assert.AreEqual(-2, result); }
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); }
public void MapEventMilestoneToCompletedEvent_RaisesValidationFailedEvent_WhenCurrentEventDoesNotHaveTargetReferenceEvent() { //Arrange var rttPeriod = new RTT18WeekPeriod { Pathway = new Pathway() }; var completedEvent = new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.AttendedOutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 20), Period = rttPeriod }; rttPeriod.Add(new ClockStartingCompletedEvent { Name = new EventName { Code = EventCode.ReferralReceived }, EventDate = new DateTime(2014, 5, 6) }); rttPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.ReferralReview }, EventDate = new DateTime(2014, 5, 10) }); rttPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.BookedOutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 12) }); rttPeriod.Add(new ClockTickingCompletedEvent { Name = new EventName { Code = EventCode.OutpatientFirstAppointment }, EventDate = new DateTime(2014, 5, 14) }); var eventMilestone = new EventMilestone { Name = new EventName { Code = EventCode.OutcomedOutpatientFirstAppointment } }; RuleViolation eventRaised = null; rttPeriod.ValidationFailed += delegate { eventRaised = new RuleViolation(); }; //Act rttPeriod.MapEventMilestoneToCompletedEvent(completedEvent, eventMilestone, new EventName { Code = EventCode.AttendedOutpatientFirstAppointment, Description = "Attended Outpatient First Appointment" }); //Assert Assert.IsNotNull(eventRaised); }
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 BreachDate_ReturnsNull_WhenTargetNumberOfDaysIsNull() { // Arrange var eventMilestone = new EventMilestone { TargetNumberOfDays = null, DateReferenceForTarget = new DateTime(2014, 7, 1), Id = 1 }; // Act var result = eventMilestone.BreachDate; // Assert Assert.IsNull(result); }
public void GetRemainingDays_ReturnsNull_WhenBreachDateIsNull() { // Arrange var eventMilestone = new EventMilestone { TargetNumberOfDays = null, DateReferenceForTarget = new DateTime(2014, 7, 1), Id = 1 }; // Act var result = eventMilestone.GetDaysToBreachAt(new DateTime(2014, 7, 6)); // Assert Assert.IsNull(result); }
public void ApplyTo_DoesntOverwriteTargetNumberOfDays_WhenEventIsNotCancer() { // Arrange var eventMilestone = new EventMilestone { TargetNumberOfDays = 5, CompletedEvent = new ClockTickingCompletedEvent() }; var sut = new EventMilestoneTargetNumberOfDaysCancerPolicy(); // Act sut.ApplyTo(eventMilestone); // Assert Assert.AreEqual(5, eventMilestone.TargetNumberOfDays); }
public void ApplyTo_DoesntOverwriteDateReferenceForTarget_WhenEventIsNotCancer() { // Arrange var eventMilestone = new EventMilestone { DateReferenceForTarget = new DateTime(2000, 12, 1), CompletedEvent = new ClockTickingCompletedEvent() }; var sut = new EventMilestoneDateReferenceForTargetCancerPolicy(); // Act sut.ApplyTo(eventMilestone); // Assert Assert.AreEqual(new DateTime(2000, 12, 1), eventMilestone.DateReferenceForTarget); }
public void ApplyTo(EventMilestone eventMilestone) { if (!eventMilestone.CompletedEvent.Cancer) { return; } if (eventMilestone.Name.Code == EventCode.DiagnosticsTestResultAvailable) { eventMilestone.TargetNumberOfDays = Constants.DignosticTestResultAvailableTargetNumberOfDaysForCancer; } if (eventMilestone.Name.Code == EventCode.AttendedOutpatientFirstAppointment) { eventMilestone.TargetNumberOfDays = Constants.OutpatientFirstAppointmentAttendedTargetNumberOfDaysForCancer; } }
public void ApplyTo_CorrectlyOverwritesTargetNumberOfDays_WhenEventCodeIsOutpatientFirstAppointmentAttended() { // Arrange var eventMilestone = new EventMilestone { TargetNumberOfDays = 5, Name = new EventName { Code = EventCode.AttendedOutpatientFirstAppointment }, CompletedEvent = new ClockTickingCompletedEvent { Cancer = true } }; var sut = new EventMilestoneTargetNumberOfDaysCancerPolicy(); // Act sut.ApplyTo(eventMilestone); // Assert Assert.AreEqual(Constants.OutpatientFirstAppointmentAttendedTargetNumberOfDaysForCancer, eventMilestone.TargetNumberOfDays); }
public void ApplyTo_CorrectlyOverwritesTargetNumberOfDays_WhenEventCodeIsDiagnosticTestResultAvailable() { // Arrange var eventMilestone = new EventMilestone { TargetNumberOfDays = 5, Name = new EventName { Code = EventCode.DiagnosticsTestResultAvailable }, CompletedEvent = new ClockTickingCompletedEvent { Cancer = true } }; var sut = new EventMilestoneTargetNumberOfDaysCancerPolicy(); // Act sut.ApplyTo(eventMilestone); // Assert Assert.AreEqual(Constants.DignosticTestResultAvailableTargetNumberOfDaysForCancer, eventMilestone.TargetNumberOfDays); }
private void GenerateEventMilestonesForEvent(Period period, CompletedEvent currentCompletedEvent, List <EventName> eventNames, UnitOfWork unitOfWork) { var eventMilestoneDateReferenceForTargetCancerPolicy = new EventMilestoneDateReferenceForTargetCancerPolicy(); var eventMilestoneTargetNumberOfDaysCancerPolicy = new EventMilestoneTargetNumberOfDaysCancerPolicy(); var destinationEvents = GetDestinationEventsForSourceEventType(currentCompletedEvent.Name.Code, unitOfWork); foreach (var destinationEvent in destinationEvents) { var dateReferenceForTarget = ComputeDateReference(destinationEvent, currentCompletedEvent, period); var eventMilestone = new EventMilestone { CompletedEvent = currentCompletedEvent, IsMandatory = destinationEvent.IsMandatory, TargetNumberOfDays = destinationEvent.TargetNumberOfDays, Name = eventNames.FirstOrDefault(name => name.Code == destinationEvent.DestinationName.Code), DateReferenceForTarget = dateReferenceForTarget }; eventMilestoneDateReferenceForTargetCancerPolicy.ApplyTo(eventMilestone); eventMilestoneTargetNumberOfDaysCancerPolicy.ApplyTo(eventMilestone); if (((currentCompletedEvent.Name.Code == EventCode.PatientCancelEvent || currentCompletedEvent.Name.Code == EventCode.HospitalCancelEvent || currentCompletedEvent.Name.Code == EventCode.DidNotAttend) && (period.CompletedEvents.Any(e => e.Name.Code == destinationEvent.EventForDateReferenceForTarget.Code))) || (currentCompletedEvent.Name.Code != EventCode.PatientCancelEvent && currentCompletedEvent.Name.Code != EventCode.HospitalCancelEvent && currentCompletedEvent.Name.Code != EventCode.DidNotAttend)) { if (destinationEvent.EventForDateReferenceForTarget != null) { period.MapEventMilestoneToCompletedEvent(currentCompletedEvent, eventMilestone, eventNames.FirstOrDefault(name => name.Code == destinationEvent.EventForDateReferenceForTarget.Code)); } unitOfWork.EventMilestones.Add(eventMilestone); } } }
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); }