public void GivenNidaSingleQuestionScreener_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(), NidaSingleQuestionScreener.AssessmentCodedConcept.Name); nidaWorkflowEngine.Run(assessmentInstance); Assert.IsNotNull(ruleEngineContext); foreach (var rule in ruleEngineContext.RuleSelector.SelectRules(nidaWorkflowRuleCollection, ruleEngineContext)) { Assert.IsTrue(nidaWorkflowRuleCollection.NidaSingleQuestionScreenerRuleSet.Any(r => r.Name == rule.Name)); } } }
private static ItemDto CreateQuestion(ItemDefinition itemDefinition, AssessmentInstance assessmentInstance) { var itemInstance = assessmentInstance.ItemInstances.FirstOrDefault( i => i.ItemDefinitionCode == itemDefinition.CodedConcept.Code); var item = new ItemDto { Metadata = itemDefinition.ItemMetadata, Key = assessmentInstance.Key, ItemDefinitionCode = itemDefinition.CodedConcept.Code, ItemDefinitionName = itemDefinition.CodedConcept.Name, Options = Mapper.Map <IEnumerable <Lookup>, IEnumerable <LookupDto> > (itemDefinition.Options), ItemType = itemDefinition.ItemType.CodedConcept.Code }; if (itemInstance == null || itemInstance.Value == null) { item.Value = null; } else if (itemInstance.Value is Lookup) { item.Value = Mapper.Map <Lookup, LookupDto> (itemInstance.Value as Lookup); } else if (itemInstance.Value is IEnumerable && !(itemInstance.Value is string)) { item.Value = Mapper.Map(itemInstance.Value, itemInstance.Value.GetType(), typeof(IEnumerable <LookupDto>)); } else { item.Value = itemInstance.Value; } return(item); }
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); } }
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); } }
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); } }
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 assessmentInstance = new AssessmentInstance(Guid.NewGuid(), Guid.NewGuid(), ""); 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); } }
public void CalculateScoreShouldReturnFalseWhenNoCriteriaMet() { 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("", ""); 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, false); } }
public void CalculateScoreShouldReturnTrueWhenHasDilyuseOfAnySubstance() { 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("3269979", new Lookup(new CodedConcept(CodeSystems.Obhita, "", ""), Frequency.DailyOrAlmostDaily.Value)); 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, true); } }
/// <summary>Initializes a new instance of the <see cref="NidaAssessFurther" /> class.</summary> /// <param name="assessmentInstance">The assessment instance.</param> public NidaAssessFurther(AssessmentInstance assessmentInstance) : base(assessmentInstance) { DrugUseFrequencyGroup = new DrugUseFrequencyGroup(assessmentInstance); InjectionGroup = new InjectionGroup(assessmentInstance); SudTreatmentGroup = new SudTreatmentGroup(assessmentInstance); }
/// <summary> /// Initializes a new instance of the <see cref="NidaAssessFurtherScoring" /> class. /// </summary> /// <param name="assessment">The assessment.</param> public NidaAssessFurtherScoring(AssessmentInstance assessment) { var nidaAssessFurther = new NidaAssessFurther(assessment); var hasDailyUseSubstance = nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceMarijuanaPersonalMedicalHistoryFrequency == DrugUseFrequency.DailyOrAlmostDaily || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceCocainePersonalMedicalHistoryFrequency == DrugUseFrequency.DailyOrAlmostDaily || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceOpioidPersonalMedicalHistoryFrequency == DrugUseFrequency.DailyOrAlmostDaily || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceStimulantPersonalMedicalHistoryFrequency == DrugUseFrequency.DailyOrAlmostDaily || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceSedativePersonalMedicalHistoryFrequency == DrugUseFrequency.DailyOrAlmostDaily || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceOtherSubstanceofAbusePersonalMedicalHistoryFrequency == DrugUseFrequency.DailyOrAlmostDaily; var hasWeeklyUseSubstance = nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceOpioidPersonalMedicalHistoryFrequency == DrugUseFrequency.Weekly || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceCocainePersonalMedicalHistoryFrequency == DrugUseFrequency.Weekly || nidaAssessFurther.DrugUseFrequencyGroup.SubstanceAbuseIllicitSubstanceStimulantPersonalMedicalHistoryFrequency == DrugUseFrequency.Weekly; var score = hasDailyUseSubstance || hasWeeklyUseSubstance || ( nidaAssessFurther.InjectionGroup.SubstanceAbuseIllicitSubstanceIntravenousRouteofAdministrationPersonalMedicalHistoryInd2 && nidaAssessFurther.InjectionGroup.SubstanceAbuseIllicitSubstanceIntravenousRouteofAdministrationPersonalMedicalHistoryFrequency == InjectionFrequency.InThePast90Days ) || nidaAssessFurther.SudTreatmentGroup.SubstanceAbuseSubstanceRelatedDisorderCurrentTherapyPersonalMedicalHistoryInd2; TotalScore = score; }
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); } }
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); } }
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); } }
/// <summary>Initializes a new instance of the <see cref="Assessment" /> class.</summary> /// <param name="assessmentInstance">The assessment instance.</param> protected Assessment(AssessmentInstance assessmentInstance) : base(assessmentInstance) { var type = GetType(); Name = type.Name; AssessmentInstance = assessmentInstance; }
/// <summary> /// Initializes a new instance of the <see cref="TotalDisorderScreenerGroup"/> class. /// </summary> /// <param name="assessmentInstance">The assessment instance.</param> public TotalDisorderScreenerGroup(AssessmentInstance assessmentInstance) : base(assessmentInstance) { InternalizingDisorderScreenerGroup = new InternalizingDisorderScreenerGroup(assessmentInstance); ExternalizingDisorderScreenerGroup = new ExternalizingDisorderScreenerGroup(assessmentInstance); SubstanceDisorderScreenerGroup = new SubstanceDisorderScreenerGroup(assessmentInstance); CrimeViolenceScreenerGroup = new CrimeViolenceScreenerGroup(assessmentInstance); }
/// <summary> /// Calculates the score. /// </summary> /// <param name="assessment">The assessment.</param> public void CalculateScore(AssessmentInstance assessment) { var value = int.Parse(assessment.ItemInstances.First().Value.ToString()); var guidance = value > 0 ? new CodedConcept(CodeSystems.Obhita, "guidance_1_and_up", "guidance_1_and_up") : new CodedConcept(CodeSystems.Obhita, "guidance_0", "guidance_0"); assessment.ScoreComplete(new CodedConcept(CodeSystems.Obhita, string.Empty, string.Empty), value, false, guidance); }
/// <summary> /// Initializes a new instance of the <see cref="NihHealthBehaviorsAssessment"/> class. /// </summary> /// <param name="assessmentInstance">The assessment instance.</param> public NihHealthBehaviorsAssessment(AssessmentInstance assessmentInstance) : base(assessmentInstance) { DietGroup = new DietGroup(assessmentInstance); ExerciseGroup = new ExerciseGroup(assessmentInstance); ProblemGroup = new ProblemGroup(assessmentInstance); SmokeGroup = new SmokeGroup(assessmentInstance); BasicInformationGroup = new BasicInformationGroup(assessmentInstance); }
public void CalculateScore(AssessmentInstance assessment) { var value = assessment.ItemInstances.Count(i => (bool.Parse(i.Value.ToString()))); var guidance = value <= 2 ? new CodedConcept(CodeSystems.Obhita, "guidance_0_to_2", "guidance_0_to_2") : new CodedConcept(CodeSystems.Obhita, "guidance_3_and_up", "guidance_3_and_up"); assessment.ScoreComplete(new CodedConcept(CodeSystems.Obhita, "", ""), value, guidance); }
public void Run(AssessmentInstance assessmentInstance) { //TODO:If Required //Need to update pillar to allow for named rule collections _ruleCollectionFactory.CreateRuleCollection<AssessmentInstance>("NidaWorkflow"); var ruleCollection = IoC.CurrentContainer.Resolve <NidaWorkflowRuleCollection>(); var ruleEngine = _ruleEngineFactory.CreateRuleEngine(assessmentInstance, ruleCollection); var ruleEngineContext = new RuleEngineContext <AssessmentInstance>(assessmentInstance, new SelectAllRulesInRuleSetSelector(assessmentInstance.AssessmentName + "RuleSet")); ruleEngineContext.WorkingMemory.AddContextObject(_messageCollector, "MessageCollector"); ruleEngine.ExecuteRules(ruleEngineContext); }
private SectionSummaryDto CreateSection(AssessmentInstance assessmentInstance, ItemDefinition sectionItemDefinition) { var sectionSummaryDto = new SectionSummaryDto { ItemDefinitionCode = sectionItemDefinition.CodedConcept.Code, PercentComplete = _assessmentCompletenessManager.CalculateCompleteness(assessmentInstance, sectionItemDefinition).PercentComplete }; return(sectionSummaryDto); }
/// <summary>Calculates the completeness.</summary> /// <param name="assessment">The assessment.</param> /// <param name="sectionDefinition">The section definition.</param> /// <returns>A <see cref="CompletenessResults" />.</returns> public CompletenessResults CalculateCompleteness(AssessmentInstance assessment, ItemDefinition sectionDefinition = null) { if (sectionDefinition != null) { var requiredQuestions = AssessmentDefinition.GetAllItemDefinitionsOfTypeInContainer(sectionDefinition, ItemType.Question).Where(i => i.GetIsRequired()); var totalRequired = requiredQuestions.Count( ); var skippedTotal = requiredQuestions.Select(i => i.CodedConcept.Code).Intersect(assessment.SkippedItemDefinitions.Select(i => i.CodedConcept.Code)).Count(); var answeredTotal = requiredQuestions.Select(i => i.CodedConcept.Code).Intersect(assessment.ItemInstances.Select(i => i.ItemDefinitionCode)).Count(); return(new CompletenessResults("Report", totalRequired - skippedTotal, answeredTotal)); } return(assessment.CalculateCompleteness()); }
public void CalculateScore(AssessmentInstance assessment) { //• No daily use of any substance //• No weekly use of opioids, cocaine, or methamphetamine //• No injection drug use in the past three months //• Not currently in drug abuse treatment var value = false; var dailyUseSubstances = new List <string> { "3269979", "3269980", "3269981", "3269982", "3269983", "3269985", "3269984" }; var weeklyUseOpioidsCocaineMethamphetamine = new List <string> { "3269981", "3269980", "3269982" }; value = assessment.ItemInstances.Any( i => dailyUseSubstances.Contains(i.ItemDefinitionCode) && i.Value != null && Equals(double.Parse((i.Value as Lookup).Value.ToString()), Frequency.DailyOrAlmostDaily.Value)) || assessment.ItemInstances.Any( i => weeklyUseOpioidsCocaineMethamphetamine.Contains(i.ItemDefinitionCode) && i.Value != null && Equals(double.Parse((i.Value as Lookup).Value.ToString()), Frequency.Weekly.Value)) || ( assessment.ItemInstances.Any( i => i.ItemDefinitionCode == "3269978" && bool.Parse(i.Value.ToString())) && assessment.ItemInstances.Any( i => i.ItemDefinitionCode == "3269986" && Equals(double.Parse((i.Value as Lookup).Value.ToString()), Frequency.InThePast90Days.Value)) ) || assessment.ItemInstances.Any( i => i.ItemDefinitionCode == "3269976" && bool.Parse(i.Value.ToString())); assessment.ScoreComplete(new CodedConcept(CodeSystems.Obhita, "", ""), value); }
/// <summary> /// Calculates the score. /// </summary> /// <param name="assessment">The assessment.</param> public void CalculateScore(AssessmentInstance assessment) { var dast = new DrugAbuseScreeningTest(assessment); var count = assessment.ItemInstances.Count(i => (bool.Parse(i.Value.ToString()))); if (dast.SubstanceAbusePrescriptionIllicitSubstanceOvertheCounterProductCessationAbilityPersonalMedicalHistoryInd2) { count--; } var guidance = count <= 2 ? new CodedConcept(CodeSystems.Obhita, "guidance_0_to_2", "guidance_0_to_2") : new CodedConcept(CodeSystems.Obhita, "guidance_3_and_up", "guidance_3_and_up"); assessment.ScoreComplete(new CodedConcept(CodeSystems.Obhita, string.Empty, string.Empty), count, false, guidance); }
private static int CalculatePercentComplete(AssessmentInstance assessmentInstance, ItemDefinition itemDefinition, string completenessCategory, int total, ref int numberComplete) { if (itemDefinition.ItemType == ItemType.Question) { if (itemDefinition.ItemMetadata.MetadataItemExists <RequiredForCompletenessMetadataItem>(m => m.CompletenessCategory == completenessCategory)) { total++; var itemInstance = assessmentInstance.ItemInstances.FirstOrDefault(i => i.ItemDefinitionCode == itemDefinition.CodedConcept.Code); if (itemInstance != null && itemInstance.Value != null) { numberComplete++; } } } return(total); }
private static ItemDto CreateQuestion(ItemDefinition itemDefinition, AssessmentInstance assessmentInstance) { var itemInstance = assessmentInstance.ItemInstances.FirstOrDefault( i => i.ItemDefinitionCode == itemDefinition.CodedConcept.Code); return(new ItemDto { Metadata = itemDefinition.ItemMetadata, Key = assessmentInstance.Key, ItemDefinitionCode = itemDefinition.CodedConcept.Code, ItemDefinitionName = itemDefinition.CodedConcept.Name, Options = Mapper.Map <IEnumerable <Lookup>, IEnumerable <LookupDto> >(itemDefinition.Options), Value = itemInstance == null ? null : itemInstance.Value is Lookup?Mapper.Map <Lookup, LookupDto>(itemInstance.Value as Lookup) : itemInstance.Value, ItemType = itemDefinition.ItemType.CodedConcept.Code }); }
public void CalculateCompleteness_NothingSkipped_CompletenessTotalCorrect() { using (var serviceLocatorFixture = new ServiceLocatorFixture()) { // Setup SetupServiceLocatorFixture(serviceLocatorFixture); var assessmentDefinition = Substitute.For <AssessmentDefinition> (); var itemDefinitions = GetItemDefinitions(); 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()), completeness.Total); } }
/// <summary> /// Calculates the score. /// </summary> /// <param name="assessment">The assessment.</param> public void CalculateScore(AssessmentInstance assessment) { var total = (assessment.ItemInstances.Where(item => item.Value.GetType() == typeof(TimeFrequency)) .Select(item => (TimeFrequency)item.Value) .Select(tf => int.Parse(tf.Value.ToString()))).Sum(); var patient = _patientRepository.GetByKey(assessment.PatientKey); var youthPediatricSymptonChecklist = new YouthPediatricSymptonChecklist(assessment); var values = new List <TimeFrequency> { youthPediatricSymptonChecklist.YouthChildsEmotionalAndBehaviorProblemsGroup.HasTroubleWithTeacher, youthPediatricSymptonChecklist.YouthChildsEmotionalAndBehaviorProblemsGroup.LessInterestedInSchool, youthPediatricSymptonChecklist.YouthChildsEmotionalAndBehaviorProblemsGroup.AbsentFromSchool, youthPediatricSymptonChecklist.YouthChildsEmotionalAndBehaviorProblemsGroup.SchoolGradesDropping }; total -= Common.AdjustScoreBasedOnAge(patient, values); assessment.ScoreComplete(new CodedConcept(CodeSystems.Obhita, string.Empty, string.Empty), total, true); }
/// <summary> /// Sends the email. /// </summary> /// <param name="assessmentInstanceUrl">The assessment instance URL.</param> /// <param name="assessmentInstance">The assessment instance.</param> private void SendEmail(string assessmentInstanceUrl, AssessmentInstance assessmentInstance) { var patient = _patientRepository.GetByKey(assessmentInstance.PatientKey); var url = string.Format(assessmentInstanceUrl + "/{0}?patientKey={1}", assessmentInstance.Key, assessmentInstance.PatientKey); DateTime?emailSentDate, emailFailedDate; string patientAccountEmail; using (var connection = _dbConnectionFactory.CreateConnection()) { patientAccountEmail = connection.Query <string>("SELECT Email FROM SecurityModule.SystemAccount WHERE PatientKey=@PatientKey", new { assessmentInstance.PatientKey }) .FirstOrDefault(); } if (patientAccountEmail != null) { var emailMessage = new EmailMessage(); emailMessage.ToAddresses.Add(patientAccountEmail); emailMessage.Body = string.Format(AssessmentResources.SelfAdministrableAssessmentCreatedEmailBody, patient.Name.FirstName, url); emailMessage.Subject = AssessmentResources.SelfAdministrableAssessmentCreatedEmailSubject; emailMessage.IsHtml = true; var emailNotifier = IoC.CurrentContainer.Resolve <IEmailNotifier>(); var isEmailNotificationSuccessful = emailNotifier.Send(emailMessage); if (isEmailNotificationSuccessful) { emailSentDate = DateTime.Now; emailFailedDate = null; } else { emailSentDate = assessmentInstance.EmailSentDate; emailFailedDate = DateTime.Now; } } else { emailSentDate = assessmentInstance.EmailSentDate; emailFailedDate = DateTime.Now; } assessmentInstance.UpdateEmailSentDate(emailSentDate, emailFailedDate); }
private static CompletenessResults CalculateCompleteness(AssessmentInstance assessmentInstance, IContainItemDefinitions itemDefinitionContainer, string completenessCategory) { var total = 0; var numbercomplete = 0; foreach (var itemDefinition in itemDefinitionContainer.ItemDefinitions) { total = CalculatePercentComplete(assessmentInstance, itemDefinition, completenessCategory, total, ref numbercomplete); if (itemDefinition.ItemType == ItemType.Group) { total = itemDefinition.ItemDefinitions.Aggregate(total, (current, childItemDefinition) => CalculatePercentComplete(assessmentInstance, childItemDefinition, completenessCategory, current, ref numbercomplete)); } } return(new CompletenessResults(completenessCategory, total, numbercomplete)); }
public void AssessmentSubmittedEventIsRaisedWhenSubmit() { using (var serviceLocatorFixture = new ServiceLocatorFixture()) { //Setup SetupServiceLocatorFixture(serviceLocatorFixture); bool eventRaised = false; DomainEvent.Register <AssessmentSubmittedEvent>(s => eventRaised = true); // Exercise Guid defGuid = CombGuid.NewCombGuid(); Guid patientGuid = CombGuid.NewCombGuid(); var source = new AssessmentInstance(defGuid, patientGuid, "testName"); source.Submit(); // Verify Assert.IsTrue(eventRaised); } }