Exemple #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Response.HeadersWritten)
            {
                return;
            }

            var model             = filterContext.ActionParameters.Values.OfType <JourneyViewModel>().FirstOrDefault() ?? new JourneyViewModel();
            var hasCookie         = filterContext.HttpContext.Request.Cookies.AllKeys.Contains(SessionCookieName);
            var hasSessionInModel = model.SessionId != Guid.Empty;

            if (hasCookie && hasSessionInModel)
            {
                return;
            }

            // When the user first lands on the site, store browser info. BrowserInfo is a wrapper that lets us increase accuracy manually.
            var browserInfo = new BrowserInfo(filterContext.HttpContext.Request);
            var pageName    = string.Format("{0}/{1}", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor.ActionName);

            if (!hasCookie && !hasSessionInModel)
            {
                model.SessionId = Guid.NewGuid();
                SetCookieValue(filterContext.HttpContext.Response.Cookies, model.SessionId);

                // Check if the referrer is NHS App, ideally should use the cookie but that is not set till after this.
                // That's not an issue as the app will always be using the query string on session start.
                var isNHSApp      = filterContext.HttpContext.Request.QueryString["utm_medium"] == "nhs app";
                var isSMSReferral = !string.IsNullOrEmpty(filterContext.HttpContext.Request.QueryString["d"]);
                var referrer      = isNHSApp ? "NHS App" : isSMSReferral ? "SMS Text" : browserInfo.Referer;
                var campaign      = filterContext.HttpContext.Request.QueryString["Campaign"];
                model.Campaign = campaign;

                _auditLogger.LogEvent(model, EventType.Browser, browserInfo.Browser, pageName);
                _auditLogger.LogEvent(model, EventType.BrowserVersion, browserInfo.MajorVersionString, pageName);
                _auditLogger.LogEvent(model, EventType.OperatingSystem, browserInfo.Platform, pageName);
                _auditLogger.LogEvent(model, EventType.DeviceType, browserInfo.DeviceType, pageName);
                _auditLogger.LogEvent(model, EventType.Referer, referrer, pageName);
            }
            else if (hasCookie)
            {
                var sessionId = filterContext.HttpContext.Request.Cookies[SessionCookieName];
                model.SessionId = Guid.Parse(sessionId.Value);
            }

            if (!string.IsNullOrEmpty(filterContext.HttpContext.Request.QueryString["d"]))
            {
                var covidValue = filterContext.HttpContext.Request.QueryString["d"];
                _auditLogger.LogEvent(model, EventType.Clicked, string.Format("External COVID-19 SMS Text : {0}", covidValue), pageName);
            }
        }
        public void LogEventSendsEventToLogger()
        {
            string        projectName = "Test Project";
            string        userName    = "******";
            SecurityEvent eventType   = SecurityEvent.ForceBuild;
            SecurityRight eventRight  = SecurityRight.Allow;
            string        message     = "A message";

            IAuditLogger logger = mocks.CreateMock <IAuditLogger>();

            Expect.Call(delegate { logger.LogEvent(projectName, userName, eventType, eventRight, message); });

            mocks.ReplayAll();
            manager.AuditLoggers = new IAuditLogger[] {
                logger
            };
            manager.Initialise();
            manager.LogEvent(projectName, userName, eventType, eventRight, message);
        }
Exemple #3
0
        public async Task <Tuple <string, QuestionViewModel> > JustToBeSafeFirstBuilder(JustToBeSafeViewModel model)
        {
            if (model.PathwayId != null)
            {
                model = await DoWorkPreviouslyDoneInQuestionBuilder(model); //todo refactor away
            }
            var identifiedModel = await BuildIdentifiedModel(model);

            var questionsWithAnswers = await _restClient.ExecuteAsync <IEnumerable <QuestionWithAnswers> >(new JsonRestRequest(_configuration.GetBusinessApiJustToBeSafePartOneUrl(identifiedModel.PathwayId), Method.GET));

            CheckResponse(questionsWithAnswers);

            if (!questionsWithAnswers.Data.Any())
            {
                var questionViewModel = new QuestionViewModel
                {
                    PathwayId          = identifiedModel.PathwayId,
                    PathwayNo          = identifiedModel.PathwayNo,
                    PathwayTitle       = identifiedModel.PathwayTitle,
                    PathwayTraumaType  = identifiedModel.PathwayTraumaType,
                    DigitalTitle       = string.IsNullOrEmpty(identifiedModel.DigitalTitle) ? identifiedModel.PathwayTitle : identifiedModel.DigitalTitle,
                    UserInfo           = identifiedModel.UserInfo,
                    JourneyJson        = identifiedModel.JourneyJson,
                    State              = JsonConvert.DeserializeObject <Dictionary <string, string> >(identifiedModel.StateJson),
                    StateJson          = identifiedModel.StateJson,
                    CollectedKeywords  = identifiedModel.CollectedKeywords,
                    Journey            = JsonConvert.DeserializeObject <Journey>(identifiedModel.JourneyJson),
                    SessionId          = model.SessionId,
                    JourneyId          = Guid.NewGuid(),
                    FilterServices     = model.FilterServices,
                    Campaign           = model.Campaign,
                    Source             = model.Source,
                    CurrentPostcode    = model.CurrentPostcode,
                    EntrySearchTerm    = model.EntrySearchTerm,
                    ViaGuidedSelection = model.ViaGuidedSelection,
                    StartParameter     = model.StartParameter
                };

                var question = await _restClient.ExecuteAsync <QuestionWithAnswers>(new JsonRestRequest(_configuration.GetBusinessApiFirstQuestionUrl(identifiedModel.PathwayId, identifiedModel.StateJson), Method.GET));

                CheckResponse(question);

                _mappingEngine.Mapper.Map(question.Data, questionViewModel);

                if (questionViewModel.IsViaGuidedSelection)
                {
                    _auditLogger.LogEvent(model, EventType.GuidedSelection, questionViewModel.PathwayTitle, "/GuidedSelection");
                }


                _userZoomDataBuilder.SetFieldsForQuestion(questionViewModel);
                if (questionViewModel.NodeType == NodeType.Page)
                {
                    // This replicates logic in ViewDeterminer so in future should ideally use that instead.
                    string viewName = "../Question/Page";
                    if (questionViewModel.PathwayNo.Equals("PC111"))
                    {
                        viewName = "../Question/Custom/NHSUKPage";
                    }
                    //replace placeholder for covid specific logic.
                    var covidPathways = await GetCovidPathways(model.UserInfo.Demography.Gender, new AgeCategory(model.UserInfo.Demography.Age));

                    questionViewModel.Content = PageCustomContent.ReplaceCovidPlaceHolderInPageContent(questionViewModel, covidPathways);
                    return(new Tuple <string, QuestionViewModel>(viewName, questionViewModel));
                }

                return(new Tuple <string, QuestionViewModel>("../Question/Question", questionViewModel));
            }
            identifiedModel.Part           = 1;
            identifiedModel.JourneyId      = Guid.NewGuid();
            identifiedModel.Questions      = questionsWithAnswers.Data.ToList();
            identifiedModel.QuestionsJson  = JsonConvert.SerializeObject(questionsWithAnswers.Data);
            identifiedModel.JourneyJson    = string.IsNullOrEmpty(identifiedModel.JourneyJson) ? JsonConvert.SerializeObject(new Journey()) : identifiedModel.JourneyJson;
            identifiedModel.FilterServices = model.FilterServices;
            return(new Tuple <string, QuestionViewModel>("../JustToBeSafe/JustToBeSafe", identifiedModel));
        }
Exemple #4
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));
        }
Exemple #5
0
 public ActionResult StartPortsmouthJourney(JourneyViewModel model)
 {
     model.StartParameter = "portsmouth";
     _auditLogger.LogEvent(model, EventType.CustomStart, model.StartParameter, string.Format("../Home/{0}", model.StartParameter));
     return(View("../Location/Home", model));
 }