/// <summary> /// Lookups the search active. /// </summary> /// <param name="page">The page.</param> /// <param name="pageSize">Size of the page.</param> /// <param name="assessmentDefinitionKey">The assessment definition key.</param> /// <param name="search">The search.</param> /// <returns> /// Returns FinderResults as type IItem. /// </returns> public FinderResults <IItem> GetLookupSearchActive(int page, int pageSize, string assessmentDefinitionKey, string search = null) { var questionsGroups = new List <IItem> (); var totalCount = 0; var assessmentDefinitionDto = GetAssessmentDefinitionForResponse(assessmentDefinitionKey); if (assessmentDefinitionDto != null) { var assessmentResourceManager = _resourcesManager.GetResourceManagerByName(assessmentDefinitionDto.AssessmentName); var assessmentName = assessmentResourceManager.GetString(SharedStringNames.ResourceKeyPrefix + assessmentDefinitionDto.AssessmentCode); var instance = _assessmentDefinitionRepository.GetByKey(_assessmentDefinitionRepository.GetKeyByCode(assessmentDefinitionDto.AssessmentCode)); foreach (var itemDef in instance.ItemDefinitions) { var str = assessmentResourceManager .GetString(SharedStringNames.ResourceKeyPrefix + itemDef.CodedConcept.Code); if (str == null) { str = assessmentResourceManager .GetString(SharedStringNames.ResourceKeyPrefix + itemDef.CodedConcept.Code + SharedStringNames.ResourceKeyPrefix + SharedStringNames.Instructions); if (str == null) { continue; } } if (itemDef.ItemType == ItemType.Question && IsMatch(search, str)) { var q = new Question { ItemType = ItemType.Question.DisplayName, Code = itemDef.CodedConcept.Code, Name = str, TemplateName = GetTemplateName(itemDef), AssessmentName = assessmentName, AssessmentCode = assessmentDefinitionDto.AssessmentCode }; questionsGroups.Add(q); totalCount += 1; } var groups = GetGroups(assessmentDefinitionDto, itemDef, search, assessmentName); var sections = GetSections(assessmentDefinitionDto, itemDef, search, assessmentName); totalCount += sections.Select(a => a.ItemType == ItemType.Question.DisplayName).Count() + groups.Select(a => a.ItemType == ItemType.Question.DisplayName).Count(); questionsGroups.AddRange(sections); questionsGroups.AddRange(groups); } questionsGroups = AssignLevels(questionsGroups); } var findResults = new FinderResults <IItem> { Data = questionsGroups, TotalCount = totalCount }; return(findResults); }
/// <summary> /// Gets the item definition. /// </summary> /// <param name="itemDefinitionCode">The item definition code.</param> /// <returns>Returns and ItemDefinition for the itemDefinitionCode if found by key.</returns> private ItemDefinition GetItemDefinition(string itemDefinitionCode) { if (!_pediatricSymptomCheckListAssessmentDefinitionKey.HasValue) { _pediatricSymptomCheckListAssessmentDefinitionKey = _assessmentDefinitionRepository.GetKeyByCode(PediatricSymptonChecklist.AssessmentCodedConcept.Code); } var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(_pediatricSymptomCheckListAssessmentDefinitionKey.Value); return(assessmentDefinition.GetItemDefinitionByCode(itemDefinitionCode)); }
/// <summary> /// Gets the item definition. /// </summary> /// <param name="itemDefinitionCode">The item definition code.</param> /// <returns>Returns and ItemDefinition for the itemDefinitionCode if found by key.</returns> private ItemDefinition GetItemDefinition(string itemDefinitionCode) { if (!_gainShortScreenerAssessmentDefinitionKey.HasValue) { _gainShortScreenerAssessmentDefinitionKey = _assessmentDefinitionRepository.GetKeyByCode(GainShortScreener.AssessmentCodedConcept.Code); } var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(_gainShortScreenerAssessmentDefinitionKey.Value); return(assessmentDefinition.GetItemDefinitionByCode(itemDefinitionCode)); }
private ItemDefinition GetItemDefinition(string itemDefinitionCode) { if (!_gpraAssessmentDefinitionKey.HasValue) { _gpraAssessmentDefinitionKey = _assessmentDefinitionRepository.GetKeyByCode(GpraInterview.AssessmentCodedConcept.Code); } var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(_gpraAssessmentDefinitionKey.Value); return(assessmentDefinition.GetItemDefinitionByCode(itemDefinitionCode)); }
/// <summary> /// Gets the item definition. /// </summary> /// <param name="itemDefinitionCode">The item definition code.</param> /// <returns>Returns and ItemDefinition for the itemDefinitionCode if found by key.</returns> private ItemDefinition GetItemDefinition(string itemDefinitionCode) { if (!_nihAssessmentDefinitionKey.HasValue) { _nihAssessmentDefinitionKey = _assessmentDefinitionRepository.GetKeyByCode(NihHealthBehaviorsAssessment.AssessmentCodedConcept.Code); } var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(_nihAssessmentDefinitionKey.Value); return(assessmentDefinition.GetItemDefinitionByCode(itemDefinitionCode)); }
/// <summary> /// Initializes a new instance of the <see cref="NidaWorkflowRuleCollection"/> class. /// </summary> /// <param name="assessmentDefinitionRepository">The assessment definition repository.</param> /// <param name="repository">The repository.</param> /// <param name="assessmentInstanceRepository">The assessment instance repository.</param> /// <param name="resourcesManager">The resources manager.</param> public NidaWorkflowRuleCollection( IAssessmentDefinitionRepository assessmentDefinitionRepository, IWorkflowMessageRepository repository, IAssessmentInstanceRepository assessmentInstanceRepository, IResourcesManager resourcesManager = null) { _resourcesManager = resourcesManager; NewRule(() => ShouldRecommendDastRule).When(assessment => (int)assessment.Score.Value > 0) .Then( (assessment, ctx) => { var messageReporter = ctx.WorkingMemory.GetContextObject <IMessageCollector> ("MessageCollector"); var assessmentDefinitionKey = assessmentDefinitionRepository.GetKeyByCode(DrugAbuseScreeningTest.AssessmentCodedConcept.Code); WorkflowMessage message = null; if (assessment.WorkflowKey.HasValue) { message = repository.GetByKey(assessment.WorkflowKey.Value); } message = message ?? new WorkflowMessage( assessment.PatientKey, assessment.Key, NidaSingleQuestionScreener.AssessmentCodedConcept.Code, assessmentDefinitionKey, DrugAbuseScreeningTest.AssessmentCodedConcept.Code, assessment.Score); if (assessment.CanSelfAdminister) { message.AllowSelfAdministration(); } assessment.AddToWorkflow(message.Key); messageReporter.AddMessage(message); }) .ElseThen( (assessment, ctx) => { WorkflowMessage message = null; if (assessment.WorkflowKey.HasValue) { message = repository.GetByKey(assessment.WorkflowKey.Value); } message = message ?? new WorkflowMessage( assessment.PatientKey, assessment.Key, NidaSingleQuestionScreener.AssessmentCodedConcept.Code, Guid.Empty, null, assessment.Score); if (assessment.CanSelfAdminister) { message.AllowSelfAdministration(); } message.Complete(NidaPatientSummaryReportModelBuilder.GetGreenReportModel()); }); NewRuleSet(() => NidaSingleQuestionScreenerRuleSet, ShouldRecommendDastRule); NewRule(() => ShouldRecommendNidaAssessFurtherRule).When(assessment => assessment.WorkflowKey.HasValue) .Then( (assessment, ctx) => { var messageReporter = ctx.WorkingMemory .GetContextObject <IMessageCollector> ("MessageCollector"); var assessmentDefinitionKey = assessmentDefinitionRepository.GetKeyByCode(NidaAssessFurther.AssessmentCodedConcept.Code); var message = repository.GetByKey(assessment.WorkflowKey.Value); message.Advance( assessment.Key, DrugAbuseScreeningTest.AssessmentCodedConcept.Code, assessmentDefinitionKey, NidaAssessFurther.AssessmentCodedConcept.Code, assessment.Score); messageReporter.AddMessage(message); }); NewRuleSet(() => DrugAbuseScreeningTestRuleSet, ShouldRecommendNidaAssessFurtherRule); NewRule(() => ShouldCompleteWorkflowStatusRule).When(assessment => assessment.WorkflowKey.HasValue) .Then( (assessment, ctx) => { var message = repository.GetByKey(assessment.WorkflowKey.Value); var dastKey = message.GetAssessmentKeyforCodeInWorkflow(DrugAbuseScreeningTest.AssessmentCodedConcept.Code); var dastInstance = assessmentInstanceRepository.GetByKey(dastKey.Value); ReportModel reportModel; if (((long)dastInstance.Score.Value) <= 2 && !(((NidaAssessFurtherScoring)assessment.Score.Value).TotalScore)) { reportModel = NidaPatientSummaryReportModelBuilder.GetAmberReportModel( _resourcesManager, dastInstance, assessment); } else { reportModel = NidaPatientSummaryReportModelBuilder.GetRedReportModel( _resourcesManager, dastInstance, assessment); } message.Complete(reportModel); }); NewRuleSet(() => NidaAssessFurtherRuleSet, ShouldCompleteWorkflowStatusRule); }
private void InsertResponses(AssessmentSubmittedEvent message) { var instance = _assessmentInstanceRepository.GetByKey(message.Key); const string Cmd = @"INSERT [AssessmentModule].[AssessmentInstanceResponse] ([AssessmentInstanceKey] ,[AssessmentName] ,[AssessmentCode] ,[AssessmentDefinitionKey] ,[OrganizationKey] ,[PatientKey] ,[ItemDefinitionCode] ,[ResponseType] ,[ResponseValue] ,[IsCode] ,[CodeValue]) VALUES ( "; using (var connection = _connectionFactory.CreateConnection()) { var assessmentCode = string.Empty; var assessmentDefinitionKey = string.Empty; var sql = "SELECT AssessmentDefinitionKey AS [Key], AssessmentCode FROM [AssessmentModule].[AssessmentDefinition] WHERE [AssessmentDefinitionKey]='" + message.AssessmentDefinitionKey + "'"; var rows = connection.Query <AssessmentDefinitionDto>(sql).ToList(); if (rows.Any()) { assessmentCode = rows.ElementAt(0).AssessmentCode; assessmentDefinitionKey = rows.ElementAt(0).Key.ToString(); } var assessmentDefinition = _assessmentDefinitionRepository.GetByKey(_assessmentDefinitionRepository.GetKeyByCode(assessmentCode)); var items = assessmentDefinition.GetAllItemDefinitionsOfType(ItemType.Question).ToList(); foreach (var item in instance.ItemInstances) { var isCode = false; var val = item.Value; int intVal = 0; var responseType = GetTemplateName(items, item); switch (responseType) { case "LookupDto": int.TryParse(((Lookup)item.Value).Value.ToString(), out intVal); val = ((Lookup)item.Value).CodedConcept.Code; responseType = item.Value.GetType().Name; isCode = true; break; case "MultipleSelect": foreach (var option in (IEnumerable <Lookup>)item.Value) { if (((IEnumerable <Lookup>)item.Value).Any()) { responseType = ((IEnumerable <Lookup>)item.Value).ElementAt(0).GetType().Name; int.TryParse(option.Value.ToString(), out intVal); } var fullQueryOption = Cmd + "'" + message.Key + "'," + "'" + instance.AssessmentName + "'," + "'" + assessmentCode + "'," + "'" + assessmentDefinitionKey + "'," + "'" + message.OrganizationKey + "'," + "'" + instance.PatientKey + "'," + "'" + item.ItemDefinitionCode + "'," + "'" + responseType + "'," + "'" + option.CodedConcept.Code + "'," + "'" + true + "'," + intVal + ")"; _logger.Info("InsertResponses Query: {0}", fullQueryOption); connection.Execute(fullQueryOption); } continue; } var fullQuery = Cmd + "'" + message.Key + "'," + "'" + instance.AssessmentName + "'," + "'" + assessmentCode + "'," + "'" + assessmentDefinitionKey + "'," + "'" + message.OrganizationKey + "'," + "'" + instance.PatientKey + "'," + "'" + item.ItemDefinitionCode + "'," + "'" + responseType + "'," + "'" + val + "'," + "'" + isCode + "'," + intVal + ")"; _logger.Info("InsertResponses Query: {0}", fullQuery); connection.Execute(fullQuery); } } }