예제 #1
0
        public void Validate_RaisesValidationFailedEvent_WhenPatientIsAChildAndDoesNotAttendForTheSecondTimeAndPeriodIsNotStopped()
        {
            // Arrange
            var period = new RTT18WeekPeriod {
                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 ClockTickingCompletedEvent {
                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);
        }
예제 #2
0
        public void EventStatus_ReturnCorrectEventStatus_WhenEventTypeIsClockStartingEventAndIsNotBreached()
        {
            //Arrange
            var completedEvent = new ClockStartingCompletedEvent
            {
                Name = new EventName {
                    Code = EventCode.ReferralReceived
                },
                EventDate = new DateTime(2014, 8, 10)
            };

            //Act
            var result = completedEvent.EventStatus;

            //Assert
            Assert.AreEqual(EventStatus.Success, result);
        }
예제 #3
0
        public void EventStatus_ReturnCorrectEventStatus_WhenEventTypeIsClockStartingEventAndIsBreached()
        {
            //Arrange
            var completedEvent = new ClockStartingCompletedEvent
            {
                Name = new EventName {
                    Code = EventCode.InpatientTCIAgreed
                },
                EventDate  = new DateTime(2014, 8, 10),
                TargetDate = new DateTime(2014, 8, 9)
            };

            //Act
            var result = completedEvent.EventStatus;

            //Assert
            Assert.AreEqual(EventStatus.Breached, result);
        }
예제 #4
0
 public void PerTestSetup()
 {
     _clockStartingCompletedEvent = new ClockStartingCompletedEvent {
         EventDate = new DateTime(2000, 12, 25)
     };
 }
예제 #5
0
        private void GenerateCompletedEvents_Click(object sender, EventArgs e)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var sourceEvents = unitOfWork.SourceEvents
                                   .Include(s => s.NextPossibleEvents.Select(d => d.EventForDateReferenceForTarget))
                                   .Include(s => s.SourceName)
                                   .ToList();

                var possibleConnectionsList = (from sourceEvent in sourceEvents
                                               where sourceEvent.NextPossibleEvents != null
                                               from destinationEvent in sourceEvent.NextPossibleEvents
                                               select new EventConnection
                {
                    Parent = sourceEvent.SourceName.Code,
                    Child = destinationEvent.DestinationName.Code,
                    TargetNumberOfDays = destinationEvent.TargetNumberOfDays,
                    EventForDateReferenceForTarget = destinationEvent.EventForDateReferenceForTarget != null ? destinationEvent.EventForDateReferenceForTarget.Code : (EventCode?)null
                }).ToList();

                GenerateEventConnections(possibleConnectionsList, new List <EventConnection>(), EventCode.ReferralReceived);

                var pathways   = unitOfWork.Pathways.ToList();
                var clinicians = unitOfWork.Clinicians.ToList();

                var pathwayIndex = 0;

                var periodCount = string.IsNullOrEmpty(txtPeriodCount.Text) ? _eventConnections.Count : Int32.Parse(txtPeriodCount.Text);

                var eventNames = unitOfWork.EventNames.ToList();

                for (var periodIndex = 0; periodIndex < periodCount; periodIndex++)
                {
                    var eventList = _eventConnections[periodIndex];

                    var period = new RTT18WeekPeriod
                    {
                        Pathway   = pathways[pathwayIndex],
                        IsActive  = true,
                        Name      = "Period 1",
                        StartDate = new DateTime(DateTime.Now.Year, _random.Next(1, DateTime.Now.Month + 1), _random.Next(1, 28))
                    };

                    unitOfWork.Periods.Add(period);
                    Console.WriteLine("Added period {0} to UOW", period.Name);

                    pathwayIndex++;

                    for (var eventIndex = 0; eventIndex < eventList.Count; eventIndex++)
                    {
                        var eventCode = eventList[eventIndex].Parent;
                        var eventName = eventNames.FirstOrDefault(name => name.Code == (EventCode)eventCode);

                        var eventForReference = period.CompletedEvents.FirstOrDefault(completedEvent => completedEvent.Name.Code == (EventCode?)eventList[eventIndex].EventForDateReferenceForTarget);

                        if (eventIndex == 0)
                        {
                            var completedEvent = new ClockStartingCompletedEvent
                            {
                                Cancer     = false,
                                Period     = period,
                                Name       = eventName,
                                Comments   = string.Empty,
                                EventDate  = period.StartDate,
                                Clinician  = clinicians[_random.Next(0, clinicians.Count - 1)],
                                IsActive   = eventIndex == eventList.Count - 1,
                                TargetDate = null
                            };

                            unitOfWork.CompletedEvents.Add(completedEvent);
                            Console.WriteLine("Added completed event {0} to UOW", completedEvent.Name.Description);
                            GenerateEventMilestonesForEvent(period, completedEvent, eventNames, unitOfWork);
                            Console.WriteLine("Added event milestones for event {0} to UOW", completedEvent.Name.Description);
                        }
                        else
                        {
                            var targetDate = (eventForReference != null && eventList[eventIndex].TargetNumberOfDays != null)
                                ? eventForReference.EventDate.AddDays((int)eventList[eventIndex].TargetNumberOfDays)
                                : (DateTime?)null;
                            var lastCompletedEvent = period.CompletedEvents.LastOrDefault();

                            var eventDateBasedOnTarget = (targetDate != null)
                                ? targetDate.Value.AddDays(_random.Next(-5, 5))
                                : (DateTime?)null;

                            var eventDate = (eventDateBasedOnTarget != null && lastCompletedEvent != null)
                                ? (eventDateBasedOnTarget >= lastCompletedEvent.EventDate
                                    ? (DateTime)eventDateBasedOnTarget
                                    : lastCompletedEvent.EventDate.AddDays(_random.Next(0, 5)))
                                : lastCompletedEvent.EventDate.AddDays(_random.Next(0, 5));

                            var completedEvent = new ClockTickingCompletedEvent
                            {
                                Cancer     = false,
                                Period     = period,
                                Name       = eventName,
                                Comments   = string.Empty,
                                EventDate  = eventDate,
                                Clinician  = clinicians[_random.Next(0, clinicians.Count - 1)],
                                IsActive   = eventIndex == eventList.Count - 1,
                                TargetDate = targetDate
                            };
                            unitOfWork.CompletedEvents.Add(completedEvent);
                            Console.WriteLine("Added completed event {0} to UOW", completedEvent.Name.Description);

                            GenerateEventMilestonesForEvent(period, completedEvent, eventNames, unitOfWork);
                            Console.WriteLine("Added event milestones for event {0} to UOW", completedEvent.Name.Description);
                        }
                    }

                    Console.WriteLine("Persisting UOW to DB...");
                    unitOfWork.SaveChanges();
                    Console.WriteLine("Done Adding events!");
                }
            }
        }
예제 #6
0
        private CompletedEvent BuildCompletedEvent(ClockType clockType, EventCode eventCode, DateTime eventDate, Period period)
        {
            CompletedEvent newCompletedEvent;

            if (eventCode == EventCode.PatientCancelEvent && period.IsSecondCancelByPatient(EventCode.PatientCancelEvent))
            {
                newCompletedEvent = new ClockStoppingCompletedEvent();
            }
            else
            {
                if (eventCode == EventCode.HospitalCancelEvent)
                {
                    newCompletedEvent = new ClockTickingCompletedEvent();
                }
                else
                {
                    if (eventCode == EventCode.DidNotAttend &&
                        (period.IsSecondDidNotAttend(eventCode) && period.Pathway.Patient.IsChild(eventDate) ||
                         period.IsSecondDidNotAttend(eventCode) && period.AbleToNotAttendFirstEvent ||
                         !(period.Pathway.Patient.IsChild(eventDate) || period.AbleToNotAttendFirstEvent)))
                    {
                        newCompletedEvent = new ClockStoppingCompletedEvent();
                    }
                    else
                    {
                        switch (clockType)
                        {
                        case ClockType.ClockStarting:
                        {
                            newCompletedEvent = new ClockStartingCompletedEvent();
                            break;
                        }

                        case ClockType.ClockTicking:
                        {
                            newCompletedEvent = new ClockTickingCompletedEvent();
                            break;
                        }

                        case ClockType.ClockPausing:
                        {
                            newCompletedEvent = new ClockPausingCompletedEvent();
                            break;
                        }

                        case ClockType.ClockStopping:
                        {
                            newCompletedEvent = new ClockStoppingCompletedEvent();
                            break;
                        }

                        default:
                        {
                            newCompletedEvent = new ClockTickingCompletedEvent();
                            break;
                        }
                        }
                    }
                }
            }
            return(newCompletedEvent);
        }