예제 #1
0
        /// <summary>
        /// Processes the single aggregate.
        /// </summary>
        /// <param name="dto">The dto to process.</param>
        /// <param name="patient">The patient.</param>
        /// <returns>A <see cref="System.Boolean"/></returns>
        protected override bool ProcessSingleAggregate(PatientProfileDto dto, Patient patient)
        {
            var name = new PersonNameBuilder()
                       .WithFirst(dto.FirstName)
                       .WithMiddle(dto.MiddleName)
                       .WithLast(dto.LastName)
                       .WithSuffix(dto.SuffixName)
                       .Build();

            if (patient.Name != name)
            {
                patient.Rename(name);
            }

            var patientGender     = (dto.PatientGender == null) ? null : _mappingHelper.MapLookupField <PatientGender> (dto.PatientGender);
            var contactPreference = _mappingHelper.MapLookupField <ContactPreference> (dto.ContactPreference);

            var patientProfile = new PatientProfileBuilder()
                                 .WithPatientGender(patientGender)
                                 .WithBirthDate(dto.BirthDate)
                                 .WithDeathDate(dto.DeathDate)
                                 .WithContactPreference(contactPreference)
                                 .WithEmailAddress(string.IsNullOrWhiteSpace(dto.EmailAddress) ? null : new EmailAddress(dto.EmailAddress))
                                 .Build();

            patient.ReviseProfile(patientProfile);

            return(true);
        }
예제 #2
0
        public void Rename_GivenValidName_PatientRenamedEventWithCorrectInfoIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                Patient patientArgumentInEvent = null;
                DomainEvent.Register <PatientRenamedEvent> (p => patientArgumentInEvent = p.Patient);

                var agencyMock = new Mock <Agency>();
                var name       = new PersonNameBuilder()
                                 .WithFirst("Albert")
                                 .WithLast("Smith");
                var patient = new Patient(agencyMock.Object, name, new PatientProfileBuilder().Build());

                var newName = new PersonNameBuilder()
                              .WithFirst("Fred")
                              .WithLast("Thomas");

                // Exercise
                patient.Rename(newName);

                // Verify
                Assert.IsTrue(ReferenceEquals(patient, patientArgumentInEvent) && patientArgumentInEvent.Name == newName);
            }
        }
예제 #3
0
        public void Rename_GivenValidName_ValidationFailureEventIsNotRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                bool eventRaised = false;
                DomainEvent.Register <RuleViolationEvent> (p => eventRaised = true);

                var agency = new Mock <Agency>();
                var name   = new PersonNameBuilder()
                             .WithFirst("Albert")
                             .WithLast("Smith");
                var patient = new Patient(agency.Object, name, new PatientProfileBuilder().Build());

                var newName = new PersonNameBuilder()
                              .WithFirst("Fred")
                              .WithLast("Thomas");

                // Exercise
                patient.Rename(newName);

                // Verify
                Assert.IsFalse(eventRaised);
            }
        }
        /// <summary>
        /// Handles the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void HandleRequest(CreateNewPatientRequest request, CreateNewPatientResponse response)
        {
            var session = SessionProvider.GetSession();
            var agency  = session.Load <Agency> (request.AgencyKey);

            var name = new PersonNameBuilder()
                       .WithFirst(request.FirstName)
                       .WithMiddle(request.MiddleName)
                       .WithLast(request.LastName)
                       .WithSuffix(request.Suffix == null ? null : request.Suffix.Name)
                       .Build();

            PatientGender patientGender = null;

            if (request.Gender != null)
            {
                patientGender = _mappingHelper.MapLookupField <PatientGender> (request.Gender);
            }

            var patientProfile = new PatientProfileBuilder()
                                 .WithPatientGender(patientGender)
                                 .WithBirthDate(request.BirthDate)
                                 .Build();

            var patient = _patientFactory.CreatePatient(agency, name, patientProfile);

            if (Success)
            {
                response.PatientDto = Mapper.Map <Patient, PatientDto> (patient);
            }
        }
예제 #5
0
        private void BuildTaddYoungPatient()
        {
            PersonName name = new PersonNameBuilder()
                              .WithFirst("Tadd")
                              .WithLast("Young")
                              .Build();
            PatientProfile profile = new PatientProfileBuilder()
                                     .WithBirthDate(DateTime.Parse("5/10/2000"))
                                     .WithPatientGender(MaleGender)
                                     .Build();

            TaddYoungPatient = new Patient(SafeHarborAgency, name, profile);
            TaddYoungPatient.UpdateUniqueIdentifier("taddyoung");

            TaddYoungPatient.AddPhoneNumber(new PatientPhone(HomePatientPhoneType, "555-255-5454"));

            var patientRace = new PatientRace(WhiteRace);

            TaddYoungPatient.AddPatientRace(patientRace);
            TaddYoungPatient.SetPrimaryRace(WhiteRace);

            TaddYoungPatient.AddAlias(new PatientAlias(NicknamePatientAliasType, "Tadd"));

            TaddYoungPatient.AddPatientDisability(new PatientDisability(DeafDisability));

            Session.SaveOrUpdate(TaddYoungPatient);
        }
예제 #6
0
        public void PersonNameBuilder_BuildsPersonNameAsExpected(string name, string expectedForenames, string expectedSurname)
        {
            //arrange
            //act
            var personName = new PersonNameBuilder().Build(name);

            //assert
            Assert.AreEqual(expectedForenames, personName.Forenames);
            Assert.AreEqual(expectedSurname, personName.Surname);
        }
예제 #7
0
        public void PersonService_AddNewWithValidDetails_ReturnsTrueAndAddsToRepo()
        {
            //arrange
            var sampleGroup = new Group {
                Id = 1, Name = "Test People", CreatedUtc = DateTime.UtcNow
            };
            var samplePeople = new List <Person>(new[]
            {
                new Person {
                    Id = 1, Forenames = "Roscoe", Surname = "Melton", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 2, Forenames = "Elvis Aaron", Surname = "Presley", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 3, Forenames = "Chesney", Surname = "Hawks", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 4, Forenames = "Sasha", Surname = "Baron-Cohen", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 5, Forenames = "Ross", Surname = "Kemp", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                }
            });

            var mockContext        = new Mock <IApplicationDbContext>();
            var mockContextFactory = new Mock <IApplicationDbContextFactory>();

            mockContextFactory.Setup(m => m.Create(It.IsAny <QueryTrackingBehavior>())).Returns(mockContext.Object);
            var mockPersonRepo = new Mock <IRepository <Person> >();

            mockPersonRepo
            .Setup(m => m.AddNew(It.IsAny <Person>(), It.IsAny <IApplicationDbContext>()))
            .Returns <Person, IApplicationDbContext>((person, _) =>
            {
                samplePeople.Add(person);
                return(true);
            });
            var mockGroupRepo = new Mock <IRepository <Group> >();

            mockGroupRepo
            .Setup(m => m.FindById(It.IsAny <int>(), It.IsAny <IApplicationDbContext>()))
            .Returns(sampleGroup);
            var personNameBuilder = new PersonNameBuilder();
            var personService     = new PersonService(mockContextFactory.Object, mockPersonRepo.Object, mockGroupRepo.Object, personNameBuilder);

            //act
            var result = personService.AddNew("Ainsley Harriot", 1);

            //assert
            Assert.IsTrue(result);
            Assert.IsTrue(samplePeople.Any(p => p.Surname == "Harriot"));
            //assert addnew called
            //assert findbyid caled
        }
예제 #8
0
        public void PersonService_GetFilteredListOfPeopleWithFilter_ReturnsMatchingPeople(string filter, string expectedIdList)
        {
            //arrange
            var sampleGroup = new Group {
                Id = 1, Name = "Test People", CreatedUtc = DateTime.UtcNow
            };
            var samplePeople = new[]
            {
                new Person {
                    Id = 1, Forenames = "Roscoe", Surname = "Melton", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 2, Forenames = "Elvis Aaron", Surname = "Presley", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 3, Forenames = "Chesney", Surname = "Hawks", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 4, Forenames = "Sasha", Surname = "Baron-Cohen", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 5, Forenames = "Ross", Surname = "Kemp", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                }
            };

            var mockContext        = new Mock <IApplicationDbContext>();
            var mockContextFactory = new Mock <IApplicationDbContextFactory>();

            mockContextFactory.Setup(m => m.Create(It.IsAny <QueryTrackingBehavior>())).Returns(mockContext.Object);
            var mockPersonRepo = new Mock <IRepository <Person> >();

            mockPersonRepo.Setup(m => m.FetchAll(It.IsAny <IApplicationDbContext>(), person => person.Group)).Returns(samplePeople.AsQueryable());
            mockPersonRepo
            .Setup(m => m.Fetch(
                       It.IsAny <Expression <Func <Person, bool> > >(),
                       It.IsAny <IApplicationDbContext>(),
                       person => person.Group))
            .Returns <Expression <Func <Person, bool> >, IApplicationDbContext, Expression <Func <Person, Group> > >
                ((filterExpression, _, __) => samplePeople.AsQueryable().Where(filterExpression));
            var mockGroupRepo     = new Mock <IRepository <Group> >();
            var personNameBuilder = new PersonNameBuilder();
            var personService     = new PersonService(mockContextFactory.Object, mockPersonRepo.Object, mockGroupRepo.Object, personNameBuilder);

            //act
            var results = personService.GetFilteredListOfPeople(filter);

            //assert
            var expectedIds = expectedIdList.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var actualIds   = results.Select(p => p.Id);

            CollectionAssert.AreEquivalent(expectedIds, actualIds);
        }
예제 #9
0
        public void Rename_GivenNullPatientProfile_ThrowsArgumentException()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var agencyMock = new Mock <Agency>();
                var name       = new PersonNameBuilder()
                                 .WithFirst("Albert")
                                 .WithLast("Smith");
                var patient = new Patient(agencyMock.Object, name, null);

                // Exercise
                patient.Rename(null);

                // Verify
            }
        }
예제 #10
0
        public void PersonService_AddNewWithInvalidName_ReturnsFalseAndDoesNotAddToRepo(string name, int groupId)
        {
            //arrange
            var mockContext        = new Mock <IApplicationDbContext>();
            var mockContextFactory = new Mock <IApplicationDbContextFactory>();

            mockContextFactory.Setup(m => m.Create(It.IsAny <QueryTrackingBehavior>())).Returns(mockContext.Object);
            var mockPersonRepo    = new Mock <IRepository <Person> >();
            var mockGroupRepo     = new Mock <IRepository <Group> >();
            var personNameBuilder = new PersonNameBuilder();
            var personService     = new PersonService(mockContextFactory.Object, mockPersonRepo.Object, mockGroupRepo.Object, personNameBuilder);

            //act
            var result = personService.AddNew(name, groupId);

            //assert
            Assert.IsFalse(result);
            //assert groupRepo.FindById() NOT called
            //assert personRepo.AddNew() NOT called
        }
예제 #11
0
        private void BuildAlbertSmithPatient()
        {
            PersonName name = new PersonNameBuilder()
                              .WithFirst("Albert")
                              .WithLast("Smith")
                              .Build();
            PatientProfile profile = new PatientProfileBuilder()
                                     .WithBirthDate(DateTime.Parse("5/10/1971"))
                                     .WithPatientGender(MaleGender)
                                     .Build();

            AlbertSmithPatient = new Patient(SafeHarborAgency, name, profile);
            AlbertSmithPatient.UpdateUniqueIdentifier("albertsmith");

            var address = new AddressBuilder()
                          .WithFirstStreetAddress("14235 South St")
                          .WithCityName("Baltimore")
                          .WithPostalCode(new PostalCode("21075"))
                          .WithStateProvince(MarylandStateProvince)
                          .Build();

            PatientAddress albertSmithAddress = new PatientAddressBuilder()
                                                .WithPatientAddressType(HomePatientAddressType)
                                                .WithAddress(address)
                                                .Build();

            AlbertSmithPatient.AddAddress(albertSmithAddress);

            AlbertSmithPatient.AddPhoneNumber(new PatientPhone(HomePatientPhoneType, "555-255-5454"));

            var patientRace = new PatientRace(WhiteRace);

            AlbertSmithPatient.AddPatientRace(patientRace);
            AlbertSmithPatient.SetPrimaryRace(WhiteRace);

            AlbertSmithPatient.AddAlias(new PatientAlias(NicknamePatientAliasType, "Al-bear"));

            AlbertSmithPatient.AddPatientDisability(new PatientDisability(DeafDisability));

            Session.SaveOrUpdate(AlbertSmithPatient);
        }
예제 #12
0
        public void Rename_GivenTheSameName_PatientRenamedEventIsNotRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                bool eventRaised = false;
                DomainEvent.Register <PatientRenamedEvent>(p => eventRaised = true);

                var agencyMock = new Mock <Agency>();
                var name       = new PersonNameBuilder()
                                 .WithFirst("Albert")
                                 .WithLast("Smith");
                var patient = new Patient(agencyMock.Object, name, new PatientProfileBuilder().Build());

                // Exercise
                patient.Rename(name);

                // Verify
                Assert.IsFalse(eventRaised);
            }
        }
예제 #13
0
        public void AddAddress_GivenDuplicate_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var eventRaised = false;
                DomainEvent.Register <RuleViolationEvent>(p => eventRaised = true);

                var agencyMock = new Mock <Agency>();
                var name       = new PersonNameBuilder()
                                 .WithFirst("Albert")
                                 .WithLast("Smith");

                var address = new AddressBuilder()
                              .WithFirstStreetAddress("123 Test Street")
                              .WithCityName("Testville")
                              .WithStateProvince(new StateProvince())
                              .WithPostalCode(new PostalCode("12345"))
                              .Build();

                var patientAddress = new PatientAddressBuilder()
                                     .WithPatientAddressType(new PatientAddressType())
                                     .WithAddress(address)
                                     .Build();

                var patient = new Patient(agencyMock.Object, name, new PatientProfileBuilder().Build());
                patient.AddAddress(patientAddress);

                // Exercise
                patient.AddAddress(patientAddress);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
예제 #14
0
        public void PersonService_GetFilteredListOfPeopleWithNoFilter_ReturnsFullList(string filter)
        {
            //arrange
            var sampleGroup = new Group {
                Id = 1, Name = "Test People", CreatedUtc = DateTime.UtcNow
            };
            var samplePeople = new[]
            {
                new Person {
                    Id = 1, Forenames = "Roscoe", Surname = "Melton", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 2, Forenames = "Elvis", Surname = "Presley", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                },
                new Person {
                    Id = 3, Forenames = "Chesney", Surname = "Hawks", Group = sampleGroup, CreatedUtc = DateTime.UtcNow
                }
            };

            var mockContext        = new Mock <IApplicationDbContext>();
            var mockContextFactory = new Mock <IApplicationDbContextFactory>();

            mockContextFactory.Setup(m => m.Create(It.IsAny <QueryTrackingBehavior>())).Returns(mockContext.Object);
            var mockPersonRepo = new Mock <IRepository <Person> >();

            mockPersonRepo.Setup(m => m.FetchAll(It.IsAny <IApplicationDbContext>(), person => person.Group)).Returns(samplePeople.AsQueryable());
            mockPersonRepo.Setup(m => m.Fetch(It.IsAny <Expression <Func <Person, bool> > >(), It.IsAny <IApplicationDbContext>(), person => person.Group)).Returns(samplePeople.AsQueryable());
            var mockGroupRepo     = new Mock <IRepository <Group> >();
            var personNameBuilder = new PersonNameBuilder();
            var personService     = new PersonService(mockContextFactory.Object, mockPersonRepo.Object, mockGroupRepo.Object, personNameBuilder);

            //act
            var results = personService.GetFilteredListOfPeople(filter);

            //assert
            CollectionAssert.AreEquivalent(samplePeople, results);
        }
예제 #15
0
        public void Rename_GivenTheSameName_NameIsNotChanged()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var agencyMock = new Mock <Agency>();
                var name       = new PersonNameBuilder()
                                 .WithFirst("Albert")
                                 .WithLast("Smith");
                var patient = new Patient(agencyMock.Object, name, new PatientProfileBuilder().Build());

                var newName = new PersonNameBuilder()
                              .WithFirst("Albert")
                              .WithLast("Smith");

                // Exercise
                patient.Rename(newName);

                // Verify
                Assert.IsTrue(patient.Name == name);
            }
        }
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(SaveDtoRequest <PayorCoverageCacheDto> request)
        {
            var requestDto = request.DataTransferObject;

            DomainEvent.Register <RuleViolationEvent> (failure => _validationFailureOccurred = true);

            LogicalTreeWalker.Walk <IDataTransferObject> (requestDto, dto => dto.ClearAllDataErrorInfo());

            var response = CreateTypedResponse();

            if (requestDto.EditStatus == EditStatus.Create || requestDto.EditStatus == EditStatus.Update)
            {
                var patient                = _patientRepository.GetByKeyOrThrow(requestDto.PatientKey, "Patient");
                var payorCache             = _payorCacheRepository.GetByKeyOrThrow(requestDto.PayorCache.Key, "Payor");
                var effectiveDateRange     = new DateRange(requestDto.StartDate, requestDto.EndDate);
                var payorCoverageCacheType = _mappingHelper.MapLookupField <PayorCoverageCacheType> (requestDto.PayorCoverageCacheType);

                var countyArea    = _mappingHelper.MapLookupField <CountyArea> (requestDto.PayorSubscriberCache.Address.CountyArea);
                var stateProvince = _mappingHelper.MapLookupField <StateProvince> (requestDto.PayorSubscriberCache.Address.StateProvince);
                var country       = _mappingHelper.MapLookupField <Country> (requestDto.PayorSubscriberCache.Address.Country);

                var address = new Address(
                    requestDto.PayorSubscriberCache.Address.FirstStreetAddress,
                    requestDto.PayorSubscriberCache.Address.SecondStreetAddress,
                    requestDto.PayorSubscriberCache.Address.CityName,
                    countyArea,
                    stateProvince,
                    country,
                    new PostalCode(requestDto.PayorSubscriberCache.Address.PostalCode));

                var gender = _mappingHelper.MapLookupField <AdministrativeGender>(requestDto.PayorSubscriberCache.AdministrativeGender);

                var patientName = new PersonNameBuilder()
                                  .WithFirst(requestDto.PayorSubscriberCache.FirstName)
                                  .WithMiddle(requestDto.PayorSubscriberCache.MiddleName)
                                  .WithLast(requestDto.PayorSubscriberCache.LastName);

                var payorSubscriberRelationshipCacheType =
                    _mappingHelper.MapLookupField <PayorSubscriberRelationshipCacheType> (requestDto.PayorSubscriberCache.PayorSubscriberRelationshipCacheType);

                var payorSubscriberCache = new PayorSubscriberCache(
                    address, requestDto.PayorSubscriberCache.BirthDate, gender, patientName, payorSubscriberRelationshipCacheType);

                PayorCoverageCache payorCoverageCache;

                if (requestDto.EditStatus == EditStatus.Create)
                {
                    payorCoverageCache = _payorCoverageCacheFactory.CreatePayorCoverage(
                        patient, payorCache, effectiveDateRange, requestDto.MemberNumber, payorSubscriberCache, payorCoverageCacheType);
                }
                else
                {
                    payorCoverageCache = _payorCoverageCacheRepository.GetByKeyOrThrow(requestDto.Key, "Payor");
                    payorCoverageCache.RevisePayorCoverageCacheInfo(payorCoverageCacheType, effectiveDateRange, requestDto.MemberNumber);
                    payorCoverageCache.RevisePayorCache(payorCache);
                    payorCoverageCache.RevisePayorSubscriberCache(payorSubscriberCache);
                }

                response.DataTransferObject = payorCoverageCache == null ? requestDto : Mapper.Map <PayorCoverageCache, PayorCoverageCacheDto>(payorCoverageCache);
            }
            else if (requestDto.EditStatus == EditStatus.Delete)
            {
                var payorCoverageCache = _payorCoverageCacheRepository.GetByKey(requestDto.Key);
                if (payorCoverageCache != null)
                {
                    _payorCoverageCacheFactory.DestroyPayorCoverage(payorCoverageCache);
                }
                response.DataTransferObject = requestDto;
            }
            else
            {
                var payorCoverageCache = _payorCoverageCacheRepository.GetByKeyOrThrow(requestDto.Key, "Payor");
                response.DataTransferObject = Mapper.Map <PayorCoverageCache, PayorCoverageCacheDto>(payorCoverageCache);
            }

            var processSucceeded = !_validationFailureOccurred;

            if (processSucceeded)
            {
                Session.Flush();
                Session.Clear();
            }
            else
            {
                if (requestDto.EditStatus == EditStatus.Create)
                {
                    response.DataTransferObject.Key = 0;
                }
            }

            return(response);
        }