protected async override Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetAsync($"api/case/{context.CaseId}/vaccinehistory");

                response.EnsureSuccessStatusCode();

                var vaccines = response.Content.ReadAsAsync <VaccineHistoryDto>();

                context.SetAnswer(vaccines);
            }
        }
Exemplo n.º 2
0
        protected async override Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetAsync($"api/case/{context.CaseId}/healthcarevisits");

                response.EnsureSuccessStatusCode();

                var visits = response.Content.ReadAsAsync <HealthCareVisitDto>();

                context.SetAnswer(visits);
            }
        }
Exemplo n.º 3
0
        protected override async Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetAsync($"api/case/{context.CaseId}/symptoms");

                response.EnsureSuccessStatusCode();

                var symptoms = response.Content.ReadAsAsync <CaseSymptomDto>();

                context.SetAnswer(symptoms);
            }
        }
Exemplo n.º 4
0
        protected async override Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetAsync($"api/case/{context.CaseId}/epilinks");

                response.EnsureSuccessStatusCode();

                var epiLinks = response.Content.ReadAsAsync <EpiLinkDto>();

                context.SetAnswer(epiLinks);
            }
        }
Exemplo n.º 5
0
        protected async override Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            var questions = context.CurrentItem.Items.GetAll("question").
                            Select(item => item.Id).
                            ToList();

            var existingAnswers = await context.DB.SurveyAnswers
                                  .Where(answer => questions.Contains(answer.IdQuestion) &&
                                         answer.IdSurveyInstance == context.SurveyInstanceId).ToListAsync();

            int nRows = existingAnswers
                        .Select(x => x.IdQuestionSub).Max() ?? 0;

            //var jArray = new List<object>();

            //for (int i= 0; i <= nRows; i++)
            //{
            //    dynamic jObject = new ExpandoObject();
            //    jObject.index = i;
            //    foreach (var question in questions)
            //    {
            //        string answer = existingAnswers
            //            .Where(x => x.IdQuestion == question && x.IdQuestionSub == i)
            //            .Select(x => x.DsAnswer)
            //            .FirstOrDefault();
            //        //JProperty jProp = new JProperty(question, answer);
            //        ((IDictionary <string, object>) jObject)[question] = answer;
            //    }
            //    jArray.Add(jObject);
            //}
            var jArray = new JArray();

            for (int i = 0; i <= nRows; i++)
            {
                dynamic jObject = new JObject();
                jObject.index = i;
                foreach (var question in questions)
                {
                    string answer = existingAnswers
                                    .Where(x => x.IdQuestion == question && x.IdQuestionSub == i)
                                    .Select(x => x.DsAnswer)
                                    .FirstOrDefault();
                    jObject.Add(question, answer);
                }
                jArray.Add(jObject);
            }
            context.SetAnswer(jArray);
        }
Exemplo n.º 6
0
        protected async override Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            //need to handle multi-select and check groups
            //go get the answer from survey answers where survey instance and question are the same
            var existingAnswers = await context.DB.SurveyAnswers
                                  .Where(answer => answer.IdQuestion == context.CurrentKey &&
                                         answer.IdSurveyInstance == context.SurveyInstanceId)
                                  .ToListAsync();

            if (context.IsSingle)
            {
                if (existingAnswers.Any())
                {
                    context.SetAnswer(existingAnswers[0].DsAnswer);
                }
            }
            else
            {
                var answers = existingAnswers
                              .Select(a => a.DsAnswer)
                              .ToList();
                context.SetAnswer(answers);
            }
        }
Exemplo n.º 7
0
 protected override bool CanHandle(SurveyAnswerReadContext context)
 {
     return(true); //this is the default handler; it takes whatever isn't handled by all other handlers
 }
Exemplo n.º 8
0
        protected override Task HandleInnerAsync(SurveyAnswerReadContext context)
        {
            context.SetAnswer(string.Empty);

            return(Task.CompletedTask);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 protected override bool CanHandle(SurveyAnswerReadContext context)
 {
     return(context.CurrentKey.StartsWith(answerKey, StringComparison.OrdinalIgnoreCase));
 }