Example #1
0
        public async Task <ActionResult> ServiceList([Bind(Prefix = "FindService")] OutcomeViewModel model, [FromUri] DateTime?overrideDate, [FromUri] bool?overrideFilterServices, DosEndpoint?endpoint)
        {
            // Set model.OutcomePage to "Other ways to get help" page so that survey link can be created correctly
            model.OutcomePage = OutcomePage.OtherServices;

            var reason = Request.Form["reason"];

            _auditLogger.LogPrimaryCareReason(model, reason);
            if (Request.Form["OtherServices"] != null)
            {
                _auditLogger.LogPrimaryCareReason(model, "Patient clicked other things you can do");
            }

            if (!ModelState.IsValidField("FindService.CurrentPostcode"))
            {
                return(View(model.CurrentView, model));
            }

            var postcodeValidatorResponse = await PostCodeAllowedValidator.IsAllowedPostcodeAsync(model.CurrentPostcode).ConfigureAwait(false);

            if (!postcodeValidatorResponse.IsInAreaForOutcome())
            {
                ModelState.AddModelError("FindService.CurrentPostcode", "Sorry, this service is not currently available in your area.  Please call NHS 111 for advice now");
                return(View(model.CurrentView, model));
            }

            var modelFilterServices = overrideFilterServices.HasValue ? overrideFilterServices.Value : model.FilterServices;
            //need to capture this value and reapply now we have other services option for Serivce first
            var isValidationRequery = model.DosCheckCapacitySummaryResult.IsValidationRequery;

            model.DosCheckCapacitySummaryResult = await GetServiceAvailability(model, overrideDate, modelFilterServices, endpoint).ConfigureAwait(false);

            model.DosCheckCapacitySummaryResult.IsValidationRequery = isValidationRequery;
            _auditLogger.LogDosResponse(model, model.DosCheckCapacitySummaryResult);

            model.NodeType = NodeType.Outcome;

            if (model.DosCheckCapacitySummaryResult.Error == null &&
                !model.DosCheckCapacitySummaryResult.ResultListEmpty)
            {
                if (model.OutcomeGroup.Is999NonUrgent && !model.DosCheckCapacitySummaryResult.HasITKServices)
                {
                    model.CurrentView = _viewRouter.Build(model, this.ControllerContext).ViewName;
                    return(View(model.CurrentView, model));
                }

                model.GroupedDosServices =
                    _dosBuilder.FillGroupedDosServices(model.DosCheckCapacitySummaryResult.Success.Services);

                model = await _outcomeViewModelBuilder.PrimaryCareBuilder(model, reason).ConfigureAwait(false);

                if (model.OutcomeGroup.IsAutomaticSelectionOfItkResult())
                {
                    AutoSelectFirstItkService(model);
                    if (model.SelectedService != null)
                    {
                        var personalDetailsController = DependencyResolver.Current.GetService <PersonalDetailsController>();
                        personalDetailsController.ControllerContext = new ControllerContext(ControllerContext.RequestContext, personalDetailsController);

                        return(await personalDetailsController.PersonalDetails(Mapper.Map <PersonalDetailViewModel>(model)).ConfigureAwait(false));
                    }
                }

                if (model.OutcomeGroup.IsServiceFirst ||
                    model.OutcomeGroup.IsPrimaryCare ||
                    model.OutcomeGroup.IsPharmacy ||
                    model.OutcomeGroup.IsAccidentAndEmergencySexualAssault)
                {
                    var otherServices =
                        await _recommendedServiceBuilder.BuildRecommendedServicesList(model.DosCheckCapacitySummaryResult.Success.Services).ConfigureAwait(false);

                    var otherServicesModel = Mapper.Map <OtherServicesViewModel>(model);

                    //Somehow got here despite only 1 service (refresh after service close) so go back to recommendedservice page.
                    if (otherServices.Count() == 1 && model.OutcomeGroup.IsServiceFirst)
                    {
                        otherServicesModel.RecommendedService = otherServices.First();
                        return(RecommendedService(otherServicesModel));
                    }

                    //Very weird mapper issue ignoring this property for some reason
                    //unit test specifically testing this passes fine so can really fathow what is going on
                    //forcing it instead
                    if (otherServicesModel.RecommendedService != null)
                    {
                        otherServicesModel.RecommendedService.ReasonText = model.RecommendedService.ReasonText;
                        otherServicesModel.OtherServices = otherServices.Skip(1);
                    }
                    else
                    {
                        otherServicesModel.OtherServices = otherServices;
                    }

                    if (model.OutcomeGroup.IsPharmacy)
                    {
                        var serviceTypeOffered = otherServices.GetServiceTypeOffered();
                        _auditLogger.LogEvent(otherServicesModel, EventType.CallbackServiceTypeOffered, serviceTypeOffered.ToString(), "~\\Views\\Outcome\\ServiceList.cshtml");
                    }
                    return(View("~\\Views\\Outcome\\Service_First\\OtherServices.cshtml", otherServicesModel));
                }

                return(View("~\\Views\\Outcome\\ServiceList.cshtml", model));
            }

            if (model.OutcomeGroup.Is999NonUrgent)
            {
                model.CurrentView = _viewRouter.Build(model, this.ControllerContext).ViewName;
            }

            return(View(model.OutcomeGroup.IsServiceFirst ? string.Format("~\\Views\\Outcome\\Service_First\\{0}\\ServiceNotOffered.cshtml", model.ServiceGroup.Id) : model.CurrentView, model));
        }