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 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); }
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); } } }