Exemplo n.º 1
0
        public void CreateVitalSign_GivenValidArguments_VitalSignIsEditable()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                var activityType          = new Mock <ActivityType>();
                var lookupValueRepository = new Mock <ILookupValueRepository>();
                lookupValueRepository
                .Setup(l => l.GetLookupByWellKnownName <ActivityType>(It.IsAny <string>()))
                .Returns(activityType.Object);

                var vitalSignRepository = new Mock <IVitalSignRepository>();

                var vitalSignFactory = new VitalSignFactory(
                    vitalSignRepository.Object,
                    lookupValueRepository.Object);

                var visit        = new Mock <Visit>();
                var clinicalCase = new Mock <ClinicalCase>();
                var patient      = new Mock <Patient>();

                visit.Setup(v => v.ClinicalCase).Returns(clinicalCase.Object);
                clinicalCase.Setup(c => c.Patient).Returns(patient.Object);

                var vitalSign = vitalSignFactory.CreateVitalSign(visit.Object);

                vitalSign.ReviseHeight(new Height(100, null));
            }
        }
Exemplo n.º 2
0
        public void CreateSystemPermission_NoDuplicateGrantSystemPermissionWithContext_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

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

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository> ();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRole = systemRoleFactory.CreateSystemRole("RoleName", "Role description.", SystemRoleType.Task);

                var systemPermission1 = new SystemPermission("WellKnownName1", "Permission display name.", "Permission description.");
                systemRole.GrantSystemPermission(systemPermission1);

                var systemPermission2 = new SystemPermission("WellKnownName1", "Permission display name", "Permission description.");
                systemRole.GrantSystemPermission(systemPermission2);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Exemplo n.º 3
0
        public void CreateSystemRole_CannotGrantJobFunctionToTask_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

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

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository> ();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRoleJobFunction = systemRoleFactory.CreateSystemRole(
                    "RoleNameJobFunction", "Role description.", SystemRoleType.JobFunction);
                var systemRoleTask = systemRoleFactory.CreateSystemRole("RoleNameTask", "Role description.", SystemRoleType.Task);

                systemRoleTask.GrantSystemRole(systemRoleJobFunction);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Exemplo n.º 4
0
        public void CreatePatient_GivenValidParameters_PatientIsMadePersistent2()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                string uniqueIdentifier = "unique identifier";

                var patientRepositoryMock = new Mock <IPatientRepository>();

                var agency = new Mock <Agency>();

                var patientUniqueIdentifierCalculatorMock = new Mock <IPatientUniqueIdentifierGenerator>();

                patientUniqueIdentifierCalculatorMock
                .Setup(p => p.GenerateUniqueIdentifier(It.IsAny <Patient> ()))
                .Returns(() => uniqueIdentifier);

                var patientFactory = new PatientFactory(
                    patientRepositoryMock.Object, patientUniqueIdentifierCalculatorMock.Object);

                // Exercise
                var patient = patientFactory.CreatePatient(agency.Object, CreateValidName(), ValidPatientProfile());

                // Verify
                Assert.AreSame(uniqueIdentifier, patient.UniqueIdentifier, "Patient uniqueIdentifier is not assigned correctly.");
            }
        }
Exemplo n.º 5
0
        public void CreatePatient_GivenValidParameters_ValidationFailureEventIsNotRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

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

                var patientRepositoryMock = new Mock <IPatientRepository>();

                var agency = new Mock <Agency>();

                var patientUniqueIdentifierCalculatorMock = new Mock <IPatientUniqueIdentifierGenerator>();
                var patientFactory = new PatientFactory(
                    patientRepositoryMock.Object, patientUniqueIdentifierCalculatorMock.Object);

                // Exercise
                patientFactory.CreatePatient(agency.Object, CreateValidName(), ValidPatientProfile());

                // Verify
                Assert.IsFalse(eventRaised);
            }
        }
Exemplo n.º 6
0
        public void GivenNidaAssessFurther_CorrectRuleSetExecuted()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                IRuleEngineContext ruleEngineContext = null;

                var ruleEngineMock = new Mock <IRuleEngine <AssessmentInstance> > ();
                ruleEngineMock.Setup(re => re.ExecuteRules(It.IsAny <IRuleEngineContext> ())).Callback <IRuleEngineContext> (ctx => ruleEngineContext = ctx);

                var ruleEngineFactoryMock = new Mock <IRuleEngineFactory> ();
                ruleEngineFactoryMock.Setup(f => f.CreateRuleEngine(It.IsAny <AssessmentInstance> (), It.IsAny <IRuleCollection <AssessmentInstance> > ()))
                .Returns(ruleEngineMock.Object);

                var nidaWorkflowRuleCollection = serviceLocatorFixture.StructureMapContainer.GetInstance <NidaWorkflowRuleCollection> ();
                var nidaWorkflowEngine         = new NidaWorkflowEngine(null, ruleEngineFactoryMock.Object, new MessageCollector());

                var assessmentInstance = new AssessmentInstance(Guid.NewGuid(), Guid.NewGuid(), NidaAssessFurther.AssessmentCodedConcept.Name);

                nidaWorkflowEngine.Run(assessmentInstance);

                Assert.IsNotNull(ruleEngineContext);
                foreach (var rule in ruleEngineContext.RuleSelector.SelectRules(nidaWorkflowRuleCollection, ruleEngineContext))
                {
                    Assert.IsTrue(nidaWorkflowRuleCollection.NidaAssessFurtherRuleSet.Any(r => r.Name == rule.Name));
                }
            }
        }
        public void CalculateScoreShouldReturnTrueWhenHasDilyuseOfAnySubstance()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid patientGuid          = CombGuid.NewCombGuid();
                var  assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessment = new AssessmentInstanceFactory().Create(assessmentDefinition, patientGuid, "TestName");
                assessment.UpdateItem(new ItemDefinition(new CodedConcept(new CodeSystem("1", "1", "Test"), "3269979", "Test"), ItemType.Question, null),
                                      DrugUseFrequency.DailyOrAlmostDaily);

                var nidaAssessFurtherScoringEngine = new NidaAssessFurtherScoringEngine();
                nidaAssessFurtherScoringEngine.CalculateScore(assessment);

                // Verify
                var scoredEvent = events.FirstOrDefault(e => e.GetType() == typeof(AssessmentScoredEvent)) as AssessmentScoredEvent;
                Assert.IsNotNull(scoredEvent);
                Assert.AreEqual(scoredEvent.Value.ToString(), "True");
            }
        }
Exemplo n.º 8
0
        public void ShouldApplyItemUpdatedEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid patientGuid          = CombGuid.NewCombGuid();
                var  assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessment = new AssessmentInstanceFactory().Create(assessmentDefinition, patientGuid, "TestName", false);
                assessment.UpdateItem(new ItemDefinition(new CodedConcept(new CodeSystem("1", "1", "Test"), "1", "Test"), ItemType.Question, null), 0);

                // Verify
                Assert.AreEqual(2, events.Count);
                var itemUpdatedEvent = events[1];
                Assert.IsNotNull(itemUpdatedEvent);
                Assert.AreEqual(typeof(ItemUpdatedEvent), itemUpdatedEvent.GetType());
                Assert.AreEqual((itemUpdatedEvent as ItemUpdatedEvent).Value, 0);
                Assert.AreEqual(2, assessment.Version);
            }
        }
Exemplo n.º 9
0
        public void SetPrimaryLocation_GivenLocationNotInAgencyLocations_PrimaryLocationIsNotChanged()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var location1Mock = new Mock <Location>();
                location1Mock.SetupGet(p => p.Key).Returns(1);
                var location2Mock = new Mock <Location>();
                location2Mock.SetupGet(p => p.Key).Returns(2);

                var agencyMock = new Mock <Agency>();
                agencyMock.SetupGet(p => p.Locations).Returns(new[] { location1Mock.Object, location2Mock.Object });

                var staff = new Staff(agencyMock.Object,
                                      new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                staff.SetPrimaryLocation(null);

                // Exercise
                staff.SetPrimaryLocation(new Mock <Location>().Object);

                // Verify
                Assert.IsTrue(staff.PrimaryLocation == null);
            }
        }
Exemplo n.º 10
0
        public void CalculateCompleteness_SkippedItems_CompletenessTotalCorrect()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var itemDefinitions = GetItemDefinitions();

                var ruleCollection = Substitute.For <IAssessmentRuleCollection> ();
                var rule           = Substitute.For <IItemSkippingRule> ();
                rule.SkippedItemDefinitions.Returns(itemDefinitions.Where(i => i.CodedConcept.Code == "3"));
                ruleCollection.ItemSkippingRules.Returns(new List <IItemSkippingRule> {
                    rule
                });
                serviceLocatorFixture.StructureMapContainer.Configure(
                    c => c.For <IAssessmentRuleCollection>().Use(ruleCollection).Named("Test"));


                var assessmentDefinition = Substitute.For <AssessmentDefinition>();
                assessmentDefinition.GetAllItemDefinitionsOfType(Arg.Any <ItemType>()).Returns(itemDefinitions);
                var assessmentInstance = new AssessmentInstance(assessmentDefinition, Guid.NewGuid(), "Test", false);

                var completeness = assessmentInstance.CalculateCompleteness();

                Assert.AreEqual(itemDefinitions.Count(i => i.GetIsRequired()) - 1, completeness.Total);
            }
        }
Exemplo n.º 11
0
        public void ShouldApplyCreatedEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid patientGuid          = CombGuid.NewCombGuid();
                var  assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessment = new AssessmentInstanceFactory().Create(assessmentDefinition, patientGuid, "TestName", false);

                // Verify
                Assert.AreEqual(1, events.Count);
                var createdEvent = events[0];
                Assert.IsNotNull(createdEvent);
                Assert.AreEqual(typeof(AssessmentCreatedEvent), createdEvent.GetType());
                Assert.AreEqual((createdEvent as AssessmentCreatedEvent).PatientKey, patientGuid);
                Assert.AreEqual((createdEvent as AssessmentCreatedEvent).AssessmentName, assessmentName);
                Assert.AreEqual(1, assessment.Version);
            }
        }
Exemplo n.º 12
0
        public void ShouldApplyAddedToWorkflowEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                var patientGuid          = CombGuid.NewCombGuid();
                var assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessment  = new AssessmentInstanceFactory().Create(assessmentDefinition, patientGuid, "TestName", false);
                var workflowKey = CombGuid.NewCombGuid();
                assessment.AddToWorkflow(workflowKey);

                // Verify
                Assert.AreEqual(2, events.Count);
                var addedToWorkflowEvent = events[1];
                Assert.IsNotNull(addedToWorkflowEvent);
                Assert.AreEqual(typeof(AssessmentAddedToWorkflowEvent), addedToWorkflowEvent.GetType());
                Assert.AreEqual((addedToWorkflowEvent as AssessmentAddedToWorkflowEvent).WorkflowKey, workflowKey);
                Assert.AreEqual(2, assessment.Version);
            }
        }
Exemplo n.º 13
0
        public void ShouldApplyScoredEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                var patientGuid          = CombGuid.NewCombGuid();
                var assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessment = new AssessmentInstanceFactory().Create(assessmentDefinition, patientGuid, "TestName", false);
                assessment.ScoreComplete(new CodedConcept(CodeSystems.Obhita, "dummayCode", ""), "result");

                // Verify
                Assert.AreEqual(2, events.Count);
                var scoredEvent = events[1];
                Assert.IsNotNull(scoredEvent);
                Assert.AreEqual(typeof(AssessmentScoredEvent), scoredEvent.GetType());
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Value, "result");
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).ScoreCode.Code, "dummayCode");
                Assert.IsNull((scoredEvent as AssessmentScoredEvent).Guidance);
                Assert.AreEqual(2, assessment.Version);
            }
        }
Exemplo n.º 14
0
        public void CanRegisterAllEventsAndHandlers()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                //Arrange
                SetServiceLocatorFixture(serviceLocatorFixture);

                var readSidePersistenceDispatcher = new ReadSidePersistenceDispatcher(IoC.CurrentContainer);

                //Act
                readSidePersistenceDispatcher.Execute();
                //var eventUpdaters = readSidePersistenceDispatcher.GetEventUpdaters;

                ////Assert
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(AssessmentDefinitionCreatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(AssessmentCreatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(ItemUpdatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(AssessmentSubmittedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(PatientCreatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(PatientChangedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(RoleCreatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(RoleNameRevisedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(StaffCreatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(StaffChangedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(TeamCreatedEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(StaffAddedToTeamEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(PatientAddedToTeamEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(StaffRemovedFromTeamEvent)));
                //Assert.IsNotNull(eventUpdaters.FirstOrDefault(e => e.Key == typeof(PatientRemovedFromTeamEvent)));
            }
        }
Exemplo n.º 15
0
        public void ShouldApplyItemAddedEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  source      = new AssessmentInstance(defGuid, patientGuid, assessmentName);
                source.UpdateItem("", 0);

                // Verify
                Assert.AreEqual(2, events.Count);
                var itemUpdatedEvent = events[1];
                Assert.IsNotNull(itemUpdatedEvent);
                Assert.AreEqual(typeof(ItemUpdatedEvent), itemUpdatedEvent.GetType());
                Assert.AreEqual((itemUpdatedEvent as ItemUpdatedEvent).Value, 0);
                Assert.AreEqual(2, source.Version);
            }
        }
Exemplo n.º 16
0
        public void SetPrimaryLocation_GivenLocationNotInAgencyLocations_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var location1Mock = new Mock <Location>();
                location1Mock.SetupGet(p => p.Key).Returns(1);
                var location2Mock = new Mock <Location>();
                location2Mock.SetupGet(p => p.Key).Returns(2);

                var agencyMock = new Mock <Agency>();
                agencyMock.SetupGet(p => p.Locations).Returns(new[] { location1Mock.Object, location2Mock.Object });

                var staff = new Staff(agencyMock.Object,
                                      new StaffProfileBuilder().WithStaffName(new PersonNameBuilder().WithFirst("first name").WithLast("last name")));

                staff.SetPrimaryLocation(null);

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

                // Exercise
                staff.SetPrimaryLocation(new Mock <Location>().Object);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Exemplo n.º 17
0
        public void CreatePatientDocument_GivenValidArguments_EntityIsEditable()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var bytes = new byte[] { 0, 0, 0 };
                var patientDocumentRepositoryMock = new Mock <IPatientDocumentRepository>();
                var hashingUtility = new Mock <IHashingUtility>();
                hashingUtility.Setup(m => m.ComputeHash(bytes)).Returns("XXXXXXXXXXX");

                var patientDocumentFactory = new PatientDocumentFactory(
                    patientDocumentRepositoryMock.Object, hashingUtility.Object);
                var patient             = new Mock <Patient>();
                var patientDocumentType = new Mock <PatientDocumentType>();


                PatientDocument patientDocument = patientDocumentFactory.CreatePatientDocument(
                    patient.Object,
                    patientDocumentType.Object,
                    bytes,
                    "filename");

                patientDocument.ReviseOtherDocumentTypeName("Other");
            }
        }
        public void SynchronizePatientAccount_GivenPatientWithoutExistingBillingOffice_ThrowsArgumentException()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                var fixture = new Fixture().Customize(new AutoMoqCustomization());

                var billingOfficeRepository = new Mock <IBillingOfficeRepository> ();
                billingOfficeRepository.Setup(p => p.GetByAgencyKey(It.IsAny <long> ())).Returns(() => null);
                fixture.Register(() => billingOfficeRepository.Object);

                var agencyProfile = fixture.CreateAnonymous <AgencyProfile> ();

                var agency = new Mock <Agency> ();
                agency.SetupGet(p => p.Key).Returns(fixture.CreateAnonymous <long>());
                agency.SetupGet(p => p.AgencyProfile).Returns(agencyProfile);

                var patient = new Mock <Patient> ();
                patient.SetupGet(p => p.Key).Returns(fixture.CreateAnonymous <long>());
                patient.SetupGet(p => p.Agency).Returns(agency.Object);

                var patientAccountSynchronizationService = fixture.CreateAnonymous <PatientAccountSynchronizationService> ();

                // Exercise
                patientAccountSynchronizationService.SynchronizePatientAccount(patient.Object);

                // Verify
            }
        }
Exemplo n.º 19
0
        public void ExecuteShouldRecommendDastRuleThenClause_WorkflowMessageCreated()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);
                var assessmentDefKey = Guid.NewGuid();
                var ruleCollection   =
                    new NidaWorkflowRuleCollection(
                        BuildIAssessmentDefinitionRepositoryMock(assessmentDefKey).Object,
                        BuildIRepositoryMock(null).Object,
                        new Mock <IAssessmentInstanceRepository>().Object);

                var assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessmentInstance = new AssessmentInstanceFactory().Create(assessmentDefinition, Guid.NewGuid(), "TestName");
                assessmentInstance.ScoreComplete(new CodedConcept(new CodeSystem("", "", ""), "", ""), "test");
                var messageCollector  = new MessageCollector();
                var ruleEngineContext = new RuleEngineContext <AssessmentInstance>(assessmentInstance);
                ruleEngineContext.WorkingMemory.AddContextObject <IMessageCollector>(messageCollector, "MessageCollector");

                foreach (var action in ruleCollection.ShouldRecommendDastRule.ThenClauses)
                {
                    action(ruleEngineContext);
                }

                Assert.AreEqual(1, messageCollector.Messages.Count(), "Incorrect Number of messages.");
                Assert.AreEqual(typeof(WorkflowMessage), messageCollector.Messages.First().GetType());
                var workflowMessage = messageCollector.Messages.First() as WorkflowMessage;
                Assert.AreEqual(assessmentInstance.Key, workflowMessage.InitiatingAssessmentKey);
                Assert.AreEqual(DrugAbuseScreeningTest.AssessmentCodedConcept.Code, workflowMessage.RecommendedAssessmentDefinitionCode);
            }
        }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
0
        public void CalculateScoreShouldRaiseScoredEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                const int itemValue = 2;

                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  assessment  = new AssessmentInstance(defGuid, patientGuid, "TestName");
                assessment.UpdateItem("", itemValue);

                var nidaSingleQuestionScreenerScoringEngine = new NidaSingleQuestionScreenerScoringEngine();
                nidaSingleQuestionScreenerScoringEngine.CalculateScore(assessment);

                // Verify
                Assert.AreEqual(3, events.Count);
                var scoredEvent = events[2];
                Assert.IsNotNull(scoredEvent);
                Assert.AreEqual(typeof(AssessmentScoredEvent), scoredEvent.GetType());
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Value, itemValue);
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Guidance.Code, "guidance_1_and_up");
                Assert.AreEqual(3, assessment.Version);
            }
        }
Exemplo n.º 22
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);
            }
        }
Exemplo n.º 23
0
        public void CreatePatient_GivenValidParameters_PatientIsMadePersistent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var isPersistent = false;

                var patientRepositoryMock = new Mock <IPatientRepository>();
                patientRepositoryMock
                .Setup(p => p.MakePersistent(It.IsAny <Patient>()))
                .Callback(() => isPersistent = true);
                var agency = new Mock <Agency>();

                var patientUniqueIdentifierCalculatorMock = new Mock <IPatientUniqueIdentifierGenerator>();
                var patientFactory = new PatientFactory(
                    patientRepositoryMock.Object, patientUniqueIdentifierCalculatorMock.Object);

                // Exercise
                patientFactory.CreatePatient(agency.Object, CreateValidName(), ValidPatientProfile());

                // Verify
                Assert.IsTrue(isPersistent);
            }
        }
Exemplo n.º 24
0
        public void ShouldApplyScoredEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  source      = new AssessmentInstance(defGuid, patientGuid, assessmentName);
                source.ScoreComplete(new CodedConcept(CodeSystems.Obhita, "dummayCode", ""), "result");

                // Verify
                Assert.AreEqual(2, events.Count);
                var scoredEvent = events[1];
                Assert.IsNotNull(scoredEvent);
                Assert.AreEqual(typeof(AssessmentScoredEvent), scoredEvent.GetType());
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Value, "result");
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).ScoreCode.Code, "dummayCode");
                Assert.IsNull((scoredEvent as AssessmentScoredEvent).Guidance);
                Assert.AreEqual(2, source.Version);
            }
        }
Exemplo n.º 25
0
        public void CreateSystemRole_NoDuplicateGrantSystemRoleWithContext_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

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

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository>();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRoleDuplicate1 = systemRoleFactory.CreateSystemRole("RoleName1", "Role description.", SystemRoleType.Task);

                var assignedToSystemRole = systemRoleFactory.CreateSystemRole("AssignedToRoleName", "Role description.", SystemRoleType.JobFunction);
                assignedToSystemRole.GrantSystemRole(systemRoleDuplicate1);
                assignedToSystemRole.GrantSystemRole(systemRoleDuplicate1);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Exemplo n.º 26
0
        public void ShouldApplyAddedToWorkflowEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  source      = new AssessmentInstance(defGuid, patientGuid, assessmentName);
                Guid workflowKey = CombGuid.NewCombGuid();
                source.AddToWorkflow(workflowKey);

                // Verify
                Assert.AreEqual(2, events.Count);
                var addedToWorkflowEvent = events[1];
                Assert.IsNotNull(addedToWorkflowEvent);
                Assert.AreEqual(typeof(AssessmentAddedToWorkflowEvent), addedToWorkflowEvent.GetType());
                Assert.AreEqual((addedToWorkflowEvent as AssessmentAddedToWorkflowEvent).WorkflowKey, workflowKey);
                Assert.AreEqual(2, source.Version);
            }
        }
Exemplo n.º 27
0
        public void CreateSystemRole_GrantNonDuplicateSystemRolesToJobFunction_ValidationFailureEventIsNotRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

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

                // Exercise
                var systemRoleDuplicate1 = new Mock <SystemRole> ();
                systemRoleDuplicate1.SetupGet(p => p.Key).Returns(1);
                var systemRoleDuplicate2 = new Mock <SystemRole>();
                systemRoleDuplicate1.SetupGet(p => p.Key).Returns(2);

                var assignedToSystemRole = new Mock <SystemRole>();
                assignedToSystemRole.SetupGet(p => p.Key).Returns(3);

                assignedToSystemRole.Object.GrantSystemRole(systemRoleDuplicate1.Object);
                assignedToSystemRole.Object.GrantSystemRole(systemRoleDuplicate2.Object);

                // Verify
                Assert.IsFalse(eventRaised);
            }
        }
Exemplo n.º 28
0
        public void ShouldApplyCreatedEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  source      = new AssessmentInstance(defGuid, patientGuid, assessmentName);

                // Verify
                Assert.AreEqual(1, events.Count);
                var createdEvent = events[0];
                Assert.IsNotNull(createdEvent);
                Assert.AreEqual(typeof(AssessmentCreatedEvent), createdEvent.GetType());
                Assert.AreEqual((createdEvent as AssessmentCreatedEvent).PatientKey, patientGuid);
                Assert.AreEqual((createdEvent as AssessmentCreatedEvent).AssessmentName, assessmentName);
                Assert.AreEqual(1, source.Version);
            }
        }
Exemplo n.º 29
0
        public void CalculateScoreShouldRaiseScoredEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                var patientGuid          = CombGuid.NewCombGuid();
                var assessmentDefinition = Substitute.For <AssessmentDefinition> ();

                var assessment = new AssessmentInstanceFactory().Create(assessmentDefinition, patientGuid, "TestName");
                assessment.UpdateItem(new ItemDefinition(new CodedConcept(new CodeSystem("1", "1", "Test"), "1", "Test"), ItemType.Question, null), "true");
                assessment.UpdateItem(new ItemDefinition(new CodedConcept(new CodeSystem("1", "1", "Test"), "2", "Test"), ItemType.Question, null), "false");

                var drugAbuseScreeningTestScoringEngine = new DrugAbuseScreeningTestScoringEngine();
                drugAbuseScreeningTestScoringEngine.CalculateScore(assessment);

                // Verify
                Assert.AreEqual(4, events.Count);
                var scoredEvent = events[3];
                Assert.IsNotNull(scoredEvent);
                Assert.AreEqual(typeof(AssessmentScoredEvent), scoredEvent.GetType());
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Value, 1);
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Guidance.Code, "guidance_0_to_2");
                Assert.AreEqual(4, assessment.Version);
            }
        }
Exemplo n.º 30
0
        public void CalculateScoreShouldRaiseScoredEvent()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                var events = new List <IDomainEvent>();
                CommitEvent.RegisterAll(events.Add);

                // Exercise
                Guid defGuid     = CombGuid.NewCombGuid();
                Guid patientGuid = CombGuid.NewCombGuid();
                var  assessment  = new AssessmentInstance(defGuid, patientGuid, "TestName");
                assessment.UpdateItem("1", "true");
                assessment.UpdateItem("2", "false");

                var drugAbuseScreeningTestScoringEngine = new DrugAbuseScreeningTestScoringEngine();
                drugAbuseScreeningTestScoringEngine.CalculateScore(assessment);

                // Verify
                Assert.AreEqual(4, events.Count);
                var scoredEvent = events[3];
                Assert.IsNotNull(scoredEvent);
                Assert.AreEqual(typeof(AssessmentScoredEvent), scoredEvent.GetType());
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Value, 1);
                Assert.AreEqual((scoredEvent as AssessmentScoredEvent).Guidance.Code, "guidance_0_to_2");
                Assert.AreEqual(4, assessment.Version);
            }
        }