コード例 #1
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);
            }
        }
コード例 #2
0
        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");
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
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 assessmentDefinition = Substitute.For <AssessmentDefinition>();

                var assessmentInstance = new AssessmentInstanceFactory().Create(assessmentDefinition, Guid.NewGuid(), NidaAssessFurther.AssessmentCodedConcept.Name, false);

                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));
                }
            }
        }
コード例 #9
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 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), 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);
            }
        }
コード例 #10
0
        protected override void Handle(CreateAssessmentRequest request, CreateAssessmentResponse response)
        {
            var assessmentDefinition      = _assessmentDefinitionRepository.GetByKey(request.AssessmentDefinitionKey);
            var assessmentInstanceFactory = new AssessmentInstanceFactory();
            var assessmentInstance        = assessmentInstanceFactory.Create(request.AssessmentDefinitionKey, request.PatientKey, assessmentDefinition.CodedConcept.Name);

            if (assessmentInstance != null)
            {
                if (request.ForSelfAdministration)
                {
                    assessmentInstance.AllowSelfAdministration();
                }
                if (request.WorkflowKey.HasValue)
                {
                    assessmentInstance.AddToWorkflow(request.WorkflowKey.Value);
                }
                response.AssessmentInstanceKey = assessmentInstance.Key;
            }
        }
コード例 #11
0
        public void AssessmentSubmittedEventIsRaisedWhenSubmit()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                //Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                bool eventRaised = false;
                DomainEvent.Register <AssessmentSubmittedEvent>(s => eventRaised = true);

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

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

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
コード例 #12
0
        public void AssessmentScoredEventIsRaisedWhenScoreComplete()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                //Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                bool eventRaised = false;
                DomainEvent.Register <AssessmentScoredEvent>(s => eventRaised = true);

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


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

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }