Exemple #1
0
        public static CrisisPlan ToModel(CrisisPlanViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel), "Cannot map null CrisisPlan");
            }

            var model = new CrisisPlan
            {
                Version             = viewModel.Version,
                RecordType          = viewModel.RecordType.ToString(),
                ActionForDependants = viewModel.ActionForDependants,
                Active = viewModel.Active,
                InvolveFamilyOrCarer  = viewModel.InvolveFamilyOrCarer,
                PatientAcceptsPlan    = viewModel.PatientAcceptsPlan,
                PatientNhsNumber      = viewModel.PatientNhsNumber,
                PlanCreated           = viewModel.PlanCreated,
                PlanCreatedBy         = viewModel.PlanCreatedBy,
                PlanCreatedByJobTitle = viewModel.PlanCreatedByJobTitle,
                PlanUpdated           = viewModel.PlanUpdated,
                PotentialTriggers     = viewModel.PotentialTriggers,
                SignsFeelingUnwell    = viewModel.SignsFeelingUnwell,
                WhatHelpsInCrisis     = viewModel.WhatHelpsInCrisis
            };

            return(model);
        }
        public EprControllerTests()
        {
            var model = new CrisisPlanViewModel
            {
                InvolveFamilyOrCarer  = true,
                SignsFeelingUnwell    = "SignsFeelingUnwell",
                PotentialTriggers     = "PotentialTriggers",
                WhatHelpsInCrisis     = "WhatHelpsInCrisis",
                ActionForDependants   = "ActionForDependants",
                EmergencyLocation     = "EmergencyLocation",
                EmergencyNumber       = "EmergencyNumber",
                CrisisNumber          = "CrisisNumber",
                PatientAcceptsPlan    = true,
                PlanCreatedBy         = "PlanCreatedBy",
                PlanCreatedByJobTitle = "PlanCreatedByJobTitle",
                Version          = 1,
                RecordType       = RecordType.MentalHealthCrisisPlan,
                Active           = true,
                PatientNhsNumber = "PatientNhsNumber",
                Id      = "5a82f9ffcb969daa58d33377",
                OrgCode = "Org1",
                Asid    = "1234567890"
            };

            var crisisPlanService = new Mock <ICrisisPlanService>();

            crisisPlanService.Setup(x => x.GetForPatient(It.Is <string>(y => y == "1234567890"), It.IsAny <bool>())).Returns(Task.Run(() => model));
            crisisPlanService.Setup(x => x.GetForPatient(It.Is <string>(y => y == "1234567899"), It.IsAny <bool>())).Returns(Task.Run(() => (CrisisPlanViewModel)null));
            crisisPlanService.Setup(x => x.GetById(It.Is <string>(y => y == "5a82f9ffcb969daa58d33377"))).Returns(Task.Run(() => model));
            crisisPlanService.Setup(x => x.GetById(It.Is <string>(y => y == "5a82f9ffcb969daa58d33378"))).Returns(Task.Run(() => (CrisisPlanViewModel)null));

            _crisisPlanService = crisisPlanService.Object;
        }
Exemple #3
0
        public static CrisisPlanViewModel ToViewModel(CrisisPlan model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model), "Cannot map null CrisisPlanViewModel");
            }

            var viewModel = new CrisisPlanViewModel
            {
                Id                    = model.Id.ToString(),
                Version               = model.Version,
                RecordType            = EnumHelpers.GetEnum <RecordType>(model.RecordType),
                ActionForDependants   = model.ActionForDependants,
                Active                = model.Active,
                CrisisNumber          = "0800 0001 001",
                EmergencyLocation     = "Leeds General Infirmary",
                EmergencyNumber       = "0113 225 8088",
                InvolveFamilyOrCarer  = model.InvolveFamilyOrCarer,
                PatientAcceptsPlan    = model.PatientAcceptsPlan,
                PatientNhsNumber      = model.PatientNhsNumber,
                PlanCreated           = model.PlanCreated,
                PlanCreatedBy         = model.PlanCreatedBy,
                PlanCreatedByJobTitle = model.PlanCreatedByJobTitle,
                PlanUpdated           = model.PlanUpdated,
                PotentialTriggers     = model.PotentialTriggers,
                SignsFeelingUnwell    = model.SignsFeelingUnwell,
                WhatHelpsInCrisis     = model.WhatHelpsInCrisis
            };

            return(viewModel);
        }
        public async Task <IActionResult> Create([FromBody] CrisisPlanViewModel crisisPlan)
        {
            SetHeaders(crisisPlan);

            var newCrisisPlan = await _crisisPlanService.SavePlan(crisisPlan);

            return(Created($"api/Epr/CrisisPlan/{newCrisisPlan.Id}", newCrisisPlan));
        }
        public async Task <IActionResult> Update([FromBody] CrisisPlanViewModel crisisPlan)
        {
            SetHeaders(crisisPlan);

            //Update just creates a new one (versioning)
            var newCrisisPlan = await _crisisPlanService.SavePlan(crisisPlan);

            return(Created($"api/Epr/CrisisPlan/{newCrisisPlan.Id}", newCrisisPlan));
        }
Exemple #6
0
        public void Returns_CleanedModel()
        {
            var model = new CrisisPlanViewModel {
                ActionForDependants = "test <",
                Active            = true,
                Asid              = "test <",
                CrisisNumber      = "test <",
                EmergencyLocation = "test <",
                EmergencyNumber   = "test <",
                Id = "test <",
                InvolveFamilyOrCarer = true,
                OrgCode               = "test <",
                PatientAcceptsPlan    = true,
                PatientNhsNumber      = "test <",
                PlanCreatedBy         = "test <",
                PlanCreatedByJobTitle = "test <",
                PotentialTriggers     = "test <",
                RecordType            = RecordType.MentalHealthCrisisPlan,
                SignsFeelingUnwell    = "test <",
                Version               = 1,
                WhatHelpsInCrisis     = "test <"
            };

            var cleanedModel = model.Cleaned();

            var expected = new CrisisPlanViewModel
            {
                ActionForDependants = "test ",
                Active            = true,
                Asid              = "test ",
                CrisisNumber      = "test ",
                EmergencyLocation = "test ",
                EmergencyNumber   = "test ",
                Id = "test ",
                InvolveFamilyOrCarer = true,
                OrgCode               = "test ",
                PatientAcceptsPlan    = true,
                PatientNhsNumber      = "test ",
                PlanCreatedBy         = "test ",
                PlanCreatedByJobTitle = "test ",
                PotentialTriggers     = "test ",
                RecordType            = RecordType.MentalHealthCrisisPlan,
                SignsFeelingUnwell    = "test ",
                Version               = 1,
                WhatHelpsInCrisis     = "test "
            };

            Assert.Equal(expected, cleanedModel, Comparers.ModelComparer <CrisisPlanViewModel>());
        }
        public async SystemTasks.Task <CrisisPlanViewModel> SavePlan(CrisisPlanViewModel crisisPlan)
        {
            try
            {
                crisisPlan = crisisPlan.Cleaned();

                var currentPlan = await this.GetForPatient(crisisPlan.PatientNhsNumber, true);

                int version = 1;

                if (currentPlan != null)
                {
                    version          = currentPlan.Version + 1;
                    currentPlan.Asid = crisisPlan.Asid;
                    //Should really archive plans after update rather than mark as delete
                    //Delete only when an active delete request is made
                    var deleted = await DeletePlan(currentPlan);
                }

                crisisPlan.Version = version;
                crisisPlan.Active  = true;

                //Create new plan
                var newCrisisPlan = CrisisPlan.ToModel(crisisPlan);

                _context.CrisisPlans.InsertOne(newCrisisPlan);

                //Hardcoded values - this is a demo with urls to ficticious documents
                var pointerRequest = NrlsPointerRequest.Create(crisisPlan.OrgCode, crisisPlan.OrgCode, crisisPlan.PatientNhsNumber, $"https://spine-proxy.national.ncrs.nhs.uk/{newCrisisPlan.Id}/mental-health-care-plan.pdf", "application/pdf", MentalHealthCrisisPlanTypeCode, MentalHealthCrisisPlanTypeDisplay, crisisPlan.Asid);

                //Create new NRLS pointer
                var newPointer = await _documentReferenceServices.GenerateAndCreatePointer(pointerRequest);

                //Create map between NRLS Pointer and Medical Record
                _pointerMapService.CreatePointerMap(newPointer.ResourceId, newCrisisPlan.Id, RecordType.MentalHealthCrisisPlan);

                return(await SystemTasks.Task.Run(() => CrisisPlan.ToViewModel(newCrisisPlan)));
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }
        public static CrisisPlanViewModel Cleaned(this CrisisPlanViewModel plan)
        {
            plan.SignsFeelingUnwell  = StringHelper.CleanInput(plan.SignsFeelingUnwell);
            plan.PotentialTriggers   = StringHelper.CleanInput(plan.PotentialTriggers);
            plan.WhatHelpsInCrisis   = StringHelper.CleanInput(plan.WhatHelpsInCrisis);
            plan.ActionForDependants = StringHelper.CleanInput(plan.ActionForDependants);

            plan.EmergencyLocation = StringHelper.CleanInput(plan.EmergencyLocation);
            plan.EmergencyNumber   = StringHelper.CleanInput(plan.EmergencyNumber);
            plan.CrisisNumber      = StringHelper.CleanInput(plan.CrisisNumber);

            plan.PlanCreatedBy         = StringHelper.CleanInput(plan.PlanCreatedBy);
            plan.PlanCreatedByJobTitle = StringHelper.CleanInput(plan.PlanCreatedByJobTitle);
            plan.CrisisNumber          = StringHelper.CleanInput(plan.CrisisNumber);

            plan.PatientNhsNumber = StringHelper.CleanInput(plan.PatientNhsNumber);

            plan.Id      = StringHelper.CleanInput(plan.Id);
            plan.OrgCode = StringHelper.CleanInput(plan.OrgCode);
            plan.Asid    = StringHelper.CleanInput(plan.Asid);

            return(plan);
        }