Exemple #1
0
        public async Task <FeedbackResultViewModel> FeedbackResultBuilder(FeedbackViewModel feedback)
        {
            feedback.DateAdded = DateTime.Now;
            feedback.PageData  = await _pageDateViewModelBuilder.PageDataBuilder(feedback.PageData);

            feedback.PageId = feedback.PageData.ToString();
            try
            {
                var request = new JsonRestRequest(_configuration.FeedbackAddFeedbackUrl, Method.POST);
                request.AddJsonBody(feedback);
                if (!string.IsNullOrEmpty(_configuration.FeedbackApiUsername) && !string.IsNullOrEmpty(_configuration.FeedbackApiPassword))
                {
                    request.Credentials = new NetworkCredential(_configuration.FeedbackApiUsername, _configuration.FeedbackApiPassword);
                }
                var response = await _restClient.ExecuteAsync(request);

                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
                {
                    return(new FeedbackConfirmationResultViewModel(feedback));
                }
            }
            catch
            {
                return(new FeedbackErrorResultViewModel(feedback));
            }
            return(new FeedbackErrorResultViewModel(feedback));
        }
        public async void GetFullPathwayJourney_returns_expected_journey(IEnumerable <JourneyStep> journey, int totalJourneyLength, int totalQuestions, int totalInlineCareAdvices, int totalInterimCareAdvice, int totalReads, int totalSets, string startingpPathwayId, string dispositionCode, string traumaType, IDictionary <string, string> state)
        {
            var fullPathwayJourney = new FullPathwayJourney
            {
                JourneySteps        = journey,
                StartingPathwayId   = startingpPathwayId,
                StartingPathwayType = traumaType,
                DispostionCode      = dispositionCode,
                State = state
            };
            var request = new JsonRestRequest(BusinessApiFullJourneyUrl, Method.POST);

            request.AddJsonBody(fullPathwayJourney);
            var result = await _restClient.ExecuteAsync <List <QuestionWithAnswers> >(request);

            //this checks a response is returned
            Assert.IsNotNull(result);

            var questions = result.Data;

            //check correct journey length and make up of nodes returned
            Assert.AreEqual(totalJourneyLength, questions.Count);
            Assert.AreEqual(totalQuestions, questions.Count(q => q.Labels.Contains("Question")));
            Assert.AreEqual(totalReads, questions.Count(q => q.Labels.Contains("Read")));
            Assert.AreEqual(totalSets, questions.Count(q => q.Labels.Contains("Set")));
            Assert.AreEqual(totalInterimCareAdvice, questions.Count(q => q.Labels.Contains("InterimCareAdvice")));
        }
Exemple #3
0
        private async Task <IRestResponse> SendRequestToDataCaptureApi <T>(string endPoint, T body)
        {
            var request = new JsonRestRequest(endPoint, Method.POST);

            request.AddJsonBody(body);

            return(await _restClientCaseDataCaptureApi.ExecuteAsync(request));
        }
        public async Task <IEnumerable <QuestionWithAnswers> > GetPathwayJourney(JourneyStep[] steps, string startingPathwayId, string dispositionCode, string gender, int age)
        {
            var request = new JsonRestRequest(_configuration.GetDomainApiPathwayJourneyUrl(startingPathwayId, dispositionCode, gender, age), Method.POST);

            request.AddJsonBody(steps);
            var pathwayJourney = await _restClient.ExecuteAsync <IEnumerable <QuestionWithAnswers> >(request);

            return(pathwayJourney.Data);
        }
Exemple #5
0
        private async Task <IRestResponse> SendItkMessage(ITKDispatchRequest itkRequestData)
        {
            var request = new JsonRestRequest(_configuration.ItkDispatcherApiSendItkMessageUrl, Method.POST);

            request.AddJsonBody(itkRequestData);
            var response = await _restClientItkDispatcherApi.ExecuteAsync(request);

            return(response);
        }
 public void Log(AuditEntry auditEntry)
 {
     Task.Run(() =>
     {
         var url     = _configuration.LoggingServiceApiAuditUrl;
         var request = new JsonRestRequest(url, Method.POST);
         request.AddJsonBody(auditEntry);
         _restClient.ExecuteAsync(request);
     });
 }
Exemple #7
0
        private async Task <List <QuestionWithAnswers> > GetFullJourney(QuestionViewModel model)
        {
            var request = new JsonRestRequest(_configuration.BusinessApiGetFullPathwayJourneyUrl, Method.POST);

            request.AddJsonBody(model.Journey.Steps.ToArray());
            var response = await _restClientBusinessApi.ExecuteAsync <List <QuestionWithAnswers> >(request)
                           .ConfigureAwait(false);

            return(response.Data);
        }
 public async Task <QuestionWithAnswers> GetNextQuestion(string id, string nodeLabel, string answer)
 {
     return(await _cacheStore.GetOrAdd(new QuestionWithAnswersCacheKey(id, nodeLabel, answer), async() =>
     {
         var request = new JsonRestRequest(_configuration.GetDomainApiNextQuestionUrl(id, nodeLabel), Method.POST);
         request.AddJsonBody(answer);
         var questions = await _restClient.ExecuteAsync <QuestionWithAnswers>(request);
         return HandleRestResponse(questions);
     }));
 }
        public async Task <QuestionWithAnswers> GetNextNode(QuestionViewModel model)
        {
            var answer          = JsonConvert.DeserializeObject <Answer>(model.SelectedAnswer);
            var serialisedState = HttpUtility.UrlEncode(model.StateJson);
            var request         = new JsonRestRequest(_configuration.GetBusinessApiNextNodeUrl(model.PathwayId, model.NodeType, model.Id, serialisedState, true), Method.POST);

            request.AddJsonBody(answer.Title);
            var response = await _restClientBusinessApi.ExecuteAsync <QuestionWithAnswers>(request).ConfigureAwait(false);

            return(response.Data);
        }
        private async Task <IEnumerable <QuestionWithAnswers> > GetModuleZeroJourney(string gender, int age, string traumaType)
        {
            var pathwayJourney = _modZeroJourneyStepsBuilder.GetModZeroJourney(gender, age, traumaType);
            var steps          = pathwayJourney.Steps;

            var request = new JsonRestRequest(_configuration.GetDomainApiPathwayJourneyUrl(pathwayJourney.PathwayId, pathwayJourney.DispositionId, gender, age), Method.POST);

            request.AddJsonBody(steps);
            var moduleZeroJourney = await _restClient.ExecuteAsync <IEnumerable <QuestionWithAnswers> >(request);

            var state = BuildState(gender, age, pathwayJourney.State);
            var filteredModZeroJourney = NavigateReadNodeLogic(steps.ToArray(), moduleZeroJourney.Data.ToList(), state);

            return(filteredModZeroJourney);
        }
Exemple #11
0
        public async Task <IEnumerable <CareAdvice> > GetCareAdvice(string ageCategory, string gender, string keywords, string dxCode)
        {
            return(await _cacheStore.GetOrAdd(new CareAdviceCacheKey(ageCategory, gender, keywords, dxCode), async() =>
            {
                var domainApiCareAdviceUrl = _configuration.GetDomainApiCareAdviceUrl(dxCode, ageCategory, gender);
                var request = new JsonRestRequest(domainApiCareAdviceUrl, Method.POST);
                request.AddJsonBody(keywords);

                var response = await _restClient.ExecuteAsync <IEnumerable <CareAdvice> >(request);
                if (!response.IsSuccessful)
                {
                    throw new Exception(string.Format("A problem occured requesting {0}. {1}", domainApiCareAdviceUrl, response.ErrorMessage));
                }

                return response.Data;
            }));
        }
Exemple #12
0
        public async Task <IEnumerable <CareAdvice> > FillCareAdviceBuilder(string dxCode, string ageGroup, string gender, IList <string> careAdviceKeywords)
        {
            if (!careAdviceKeywords.Any())
            {
                return(Enumerable.Empty <CareAdvice>());
            }

            var businessApiInterimCareAdviceUrl = _configuration.GetBusinessApiInterimCareAdviceUrl(dxCode, ageGroup, gender);
            var request = new JsonRestRequest(businessApiInterimCareAdviceUrl, Method.POST);

            request.AddJsonBody(GenerateKeywordsList(careAdviceKeywords));
            var careAdvices = await _restClient.ExecuteAsync <IEnumerable <CareAdvice> >(request);

            CheckResponse(careAdvices);

            return(careAdvices.Data);
        }
Exemple #13
0
        public async Task <DosCheckCapacitySummaryResult> FillCheckCapacitySummaryResult(DosViewModel dosViewModel, bool filterServices, DosEndpoint?endpoint)
        {
            var checkCapacitySummaryUrl = string.Format("{0}?filterServices={1}&endpoint={2}", _configuration.BusinessDosApiCheckCapacitySummaryUrl, filterServices, endpoint);
            var dosFilterdCase          = dosViewModel as DosFilteredCase;

            var request = new JsonRestRequest(checkCapacitySummaryUrl, Method.POST);

            request.AddJsonBody(dosFilterdCase);

            _logger.Debug(string.Format("DOSBuilder.FillCheckCapacitySummaryResult(): URL: {0} BODY: {1}", checkCapacitySummaryUrl, JsonConvert.SerializeObject(dosFilterdCase)));
            var response = await _restClient.ExecuteAsync <DosCheckCapacitySummaryResult>(request);

            if (!response.IsSuccessful || response.Data.Error != null)
            {
                return(response.Data);
            }

            var services = new List <ServiceViewModel>();

            if (response.Data.Success != null)
            {
                var checkCapacitySummaryResults = JsonConvert.SerializeObject(response.Data.Success.Services);
                var jArray = (JArray)JsonConvert.DeserializeObject(checkCapacitySummaryResults);
                services = jArray.ToObject <List <ServiceViewModel> >();
            }

            var checkCapacitySummaryResult = new DosCheckCapacitySummaryResult()
            {
                Success = new SuccessObject <ServiceViewModel>()
                {
                    Code     = (int)response.StatusCode,
                    Services = FilterCallbackEnabled(services)
                }
            };

            return(checkCapacitySummaryResult);
        }
        //Test to show answer nodes are checked in the correct order so that 'evaluate variables' are handled correctly.
        public async void TestGetQuestion_returns_expected_Next_QuestionAgeVariable()
        {
            var expectedNexQuestionId = "PW628.13100";
            var NodeId     = "PW628.10700";
            var state      = "{\"PATIENT_AGE\":\"50\",\"PATIENT_GENDER\":\"\\\"F\\\"\",\"PATIENT_PARTY\":\"1\",\"PATIENT_AGEGROUP\":\"Adult\"}";
            var requestUrl = string.Format(BusinessApiNextNodeUrl, _testPathwayNo3, "Question", NodeId, HttpUtility.UrlEncode(state));

            var request = new JsonRestRequest(requestUrl, Method.POST);

            request.AddJsonBody("No");
            var response = await _restClient.ExecuteAsync(request);

            //this checks a responce is returned
            Assert.IsNotNull(response);

            var content = response.Content;

            //these check the right fields are returned
            Assert.IsTrue(content.Contains("\"id\":\"" + expectedNexQuestionId + "\""));
            SchemaValidation.AssertValidResponseSchema(content, SchemaValidation.ResponseSchemaType.Question);

            //this next one checks the right question has returned
            Assert.IsTrue(content.Contains("\"questionNo\":\"TX220118"));
        }