public async Task <IActionResult> GetAnswersForOutbreakAsync([FromRoute] GetSurveyAnswers query) { var currentAnswers = await surveyAnswerRepository.Get(query); return(Ok(currentAnswers)); }
public async Task <Dictionary <string, object> > Get(GetSurveyAnswers query) { //need to build a chain here var answerReader = COR <SurveyAnswerReadContext> .CreateChain( new EpiLinksReadHandler(), new HealthCareVisitsReadHandler(), new LabResultReadHandler(), new LabSummaryReadHandler(), new SymptomReadHandler(), new TravelHistoryReadHandler(), new MappedReadHandler(dataServices), new ReadOnlyReadHandler("Outbreak Lab List"), new RepeaterReadHandler(), new DefaultReadHandler()); //need to build the AnswerDictionary var existingLayout = await readContext.SurveyLayout .FirstOrDefaultAsync(layout => layout.Surveys .Any(survey => survey.UID == query.SurveyId)); var items = JsonConvert.DeserializeObject <IList <LayoutItemDto> >(existingLayout.JsLayout) .GetAll("control", "question", "repeatingQuestionsGroup"); var answers = new Dictionary <string, object>(); foreach (var item in items) { if (item.QuestionType == QuestionType.Check) { answers[item.Id.ToUpper()] = new List <string>(); } else { answers[item.Id.ToUpper()] = string.Empty; } } //need to get the survey instance ID var surveyInstanceId = await GetSurveyInstanceId(query.ProfileId, query.CaseId, query.OutbreakId); var handlingContext = new SurveyAnswerReadContext { DB = readContext, CaseId = query.CaseId, ProfileId = query.ProfileId, OutbreakId = query.OutbreakId, QuestionStorageMap = await GetQuestionStorageMap(query.SurveyId), SurveyInstanceId = surveyInstanceId.Value, Answers = answers }; var connection = readContext.Database.GetDbConnection().EnsureOpen(); handlingContext.Connection = connection; foreach (var item in items) { handlingContext.CurrentKey = item.Id.ToUpper(); handlingContext.CurrentItem = item; await answerReader.HandleAsync(handlingContext); } return(answers); }