public IActionResult EditPatientVisit(int id)
        {
            _patientVisitManager = new PatientVisitManager(_context, ViewBag, Request.Form);
            var patientVisit = _patientVisitManager.GetPatientVisitById(id);

            this.CheckVisitDate(patientVisit);

            NewPatientVisitViewModel patientVM;
            List <IGrouping <string, PatientExamination> > patientExaminations;

            GetPatientExaminationsWithVisitViewModel(id, patientVisit, out patientVM, out patientExaminations);

            var selectedItems = _patientVisitManager.UpdateSelectedItemsForPatientVisit(patientVisit);

            this.CheckIfAtLeastOneIsSelected(selectedItems.Count);

            if (TryValidateModel(patientVisit))
            {
                _context.SaveChanges();
                return(Json("ok"));
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }
        }
        public async Task <IActionResult> Create(CaseReportFormOptionGroupViewModel optionGroupVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var optionGroup = new CaseReportFormOptionGroup();
                    optionGroup.Name    = optionGroupVM.Name;
                    optionGroup.Choices = new List <CaseReportFormOptionChoice>();
                    foreach (string choiceName in optionGroupVM.Options)
                    {
                        var optionChoice = new CaseReportFormOptionChoice();
                        optionChoice.Name = choiceName;
                        optionChoice.CaseReportFormOptionGroup = optionGroup;
                        optionGroup.Choices.Add(optionChoice);
                    }

                    _context.Add(optionGroup);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
Пример #3
0
        public IActionResult EditRadiologyItem(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            dynamic foundItem = FindDynamicItemById(id, Request.Form["RadiologyViewModel.Klass"]);

            foundItem.Name = Request.Form["RadiologyViewModel.Name"];
            var patientVM = SetupViewModel(foundItem);

            patientVM.ID = int.Parse(Request.Form["RadiologyViewModel.ID"]);
            //ValidateUniqueName(patientVM.Name, patientVM.Klass);
            if (TryValidateModel(patientVM))
            {
                try
                {
                    _context.Update(foundItem);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }
Пример #4
0
        public IActionResult Create(int patientId, PatientImmunoglobulin patientIg)
        {
            var patient = _context.Patients.Where(p => p.ID == patientId).SingleOrDefault();

            if (patient == null)
            {
                return(NotFound());
            }

            patientIg.PatientId = patient.ID;
            if (ModelState.IsValid)
            {
                _context.Add(patientIg);
                _context.SaveChanges();
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(StatusCode(422, Json(new { success = false, errors })));
            }
            var igs = _context.PatientImmunoglobulins.
                      Include(pi => pi.ImmunoglobulinType).
                      Where(pm => pm.PatientId == patientId).
                      OrderByDescending(pm => pm.DateTaken).
                      ToList();

            ViewBag.SelectedIg = new List <int>();
            return(PartialView(igs));
        }
        public IActionResult Create(int patientId, PatientSTGQuestionnaire sgrq)
        {
            var patient = _context.Patients.Where(p => p.ID == patientId).SingleOrDefault();

            if (patient == null)
            {
                return(NotFound());
            }

            sgrq.PatientId = patient.ID;
            if (ModelState.IsValid)
            {
                _context.Add(sgrq);
                _context.SaveChanges();
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(StatusCode(422, Json(new { success = false, errors })));
            }
            var questionnaires = _context.PatientSTGQuestionnaires.
                                 Where(pm => pm.PatientId == patientId).
                                 OrderByDescending(pm => pm.DateTaken).
                                 ToList();

            ViewBag.SelectedSGRQ = new List <int>();
            return(PartialView(questionnaires));
        }
Пример #6
0
        public IActionResult Update(NewPatientViewModel patient)
        {
            ModelState.Remove("PatientID");
            var newPatient = _mapper.Map <Patient>(patient);

            if (ModelState.IsValid)
            {
                try
                {
                    _dbContext.Patients.Update(newPatient);
                    _dbContext.SaveChanges();
                    return(Ok());
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("PatientID", "Please verify if a patient with this RM2 Number or NHS Number already exists in the database");
                    var errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { errors = errors }));
                }
            }
            else
            {
                var errors = ModelStateHelper.Errors(ModelState);
                return(Json(new{ errors = errors }));
            }
        }
        public IActionResult Create(int patientId, PatientMeasurement measurementExamination)
        {
            var patient = _context.Patients.Where(p => p.ID == patientId).SingleOrDefault();

            if (patient == null)
            {
                return(NotFound());
            }

            measurementExamination.PatientId = patient.ID;
            CheckIfAtLeastHeightOrWeightArePresent(measurementExamination);
            if (ModelState.IsValid)
            {
                _context.Add(measurementExamination);
                _context.SaveChanges();
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(StatusCode(422, Json(new { success = false, errors })));
            }
            var patientMeasurments = _context.PatientMeasurements.
                                     Where(pm => pm.PatientId == patientId).
                                     OrderByDescending(pm => pm.DateTaken).
                                     ToList();

            ViewBag.SelectedMeasurements = new List <int>();
            return(PartialView(patientMeasurments));
        }
Пример #8
0
        public IActionResult Create(int patientId, PatientRadiologyFinding finding)
        {
            var patient = _context.Patients.Where(p => p.ID == patientId).SingleOrDefault();

            if (patient == null)
            {
                return(NotFound());
            }

            finding.PatientId = patient.ID;
            if (ModelState.IsValid)
            {
                _context.Add(finding);
                _context.SaveChanges();
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(StatusCode(422, Json(new { success = false, errors })));
            }
            var radiologyFindings = _context.PatientRadiologyFindings.
                                    Include(prf => prf.Finding).
                                    Include(prf => prf.RadiologyType).
                                    Include(prf => prf.TreatmentResponse).
                                    Include(prf => prf.Grade).
                                    Include(prf => prf.ChestDistribution).
                                    Include(prf => prf.ChestLocation).
                                    Where(pm => pm.PatientId == patientId).
                                    OrderByDescending(pm => pm.DateTaken).
                                    ToList();

            ViewBag.SelectedRadiology = new List <int>();
            return(PartialView(radiologyFindings));
        }
        public async Task <IActionResult> Create(CaseReportFormViewModel caseReportFormViewModel)
        {
            try
            {
                CaseReportForm caseReportForm;
                List <CaseReportFormFormSection> sections;
                BuildFormWithSections(caseReportFormViewModel, out caseReportForm, out sections);

                if (caseReportFormViewModel.SectionsIds == null && caseReportFormViewModel.Fields == null)
                {
                    ModelState.AddModelError("Base",
                                             "Add least one section or field needs to be present on any form");
                }

                if (ModelState.IsValid)
                {
                    _context.CaseReportFormFormSections.AddRange(sections);
                    _context.CaseReportForms.Add(caseReportForm);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
Пример #10
0
        public async Task <IActionResult> EditDrug(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var sideEffect = await _context.SideEffects
                             .AsNoTracking()
                             .SingleOrDefaultAsync(m => m.ID == id);

            sideEffect.Name = Request.Form["Name"];
            if (TryValidateModel(sideEffect))
            {
                try
                {
                    _context.SideEffects.Update(sideEffect);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }
        public async Task <IActionResult> EditMedicalTrial(int?id, MedicalTrial medicalTrial)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var dbMedicalTrial = await _context.MedicalTrials
                                 .AsNoTracking()
                                 .SingleOrDefaultAsync(m => m.ID == id);

            UpdateMedicalTrial(dbMedicalTrial, medicalTrial);
            if (TryValidateModel(dbMedicalTrial))
            {
                try
                {
                    _context.MedicalTrials.Update(dbMedicalTrial);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("Name, Klass")] RadiologyViewModel radiologyViewModel)
        {
            try
            {
                _modelResolver = new RadiologyModelResolver(radiologyViewModel.Klass, radiologyViewModel.Name);
                dynamic modelToSave = _modelResolver.Resolve();

                ValidateUniqueName(radiologyViewModel.Name, radiologyViewModel.Klass);
                if (ModelState.IsValid)
                {
                    _context.Add(modelToSave);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
Пример #13
0
        public async Task <IActionResult> EditUser(string id,
                                                   ApplicationUser user,
                                                   List <string> roles)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var userToUpdate = _userManager.FindByIdAsync(id).Result;

            userToUpdate.FirstName = user.FirstName;
            userToUpdate.LastName  = user.LastName;

            if (ModelState.IsValid)
            {
                try
                {
                    await _userManager.UpdateAsync(userToUpdate);

                    var uiSelectedRoles = roles;
                    if (uiSelectedRoles.Count() == 0 || !uiSelectedRoles.Contains("Anonymous Role"))
                    {
                        uiSelectedRoles.Add("Anonymous Role");
                    }
                    var currentRoles  = _userManager.GetRolesAsync(userToUpdate).Result;
                    var toDeleteRoles = currentRoles.Except(uiSelectedRoles);
                    var toInsertRoles = uiSelectedRoles.Except(currentRoles);

                    if (toDeleteRoles.Count() > 0)
                    {
                        await _userManager.RemoveFromRolesAsync(userToUpdate, toDeleteRoles);
                    }

                    if (toInsertRoles.Count() > 0)
                    {
                        await _userManager.AddToRolesAsync(userToUpdate, toInsertRoles);
                    }
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }
            return(Json(new { result = "ok" }));
        }
        public async Task <IActionResult> Create(CaseReportFormSectionViewModel formSectionVM)
        {
            if (ModelState.IsValid)
            {
                CaseReportFormSectionViewModel.BuildSection(_context, formSectionVM);
                await _context.SaveChangesAsync();

                return(Json(new { result = "ok" }));
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }
        }
 public IActionResult EditFormSection(int?id,
                                      CaseReportFormSection section,
                                      CaseReportFormField[] fields)
 {
     section.CaseReportFormResultFields = fields;
     foreach (var field in section.CaseReportFormResultFields.OrderBy(f => f.ID))
     {
         var dbOptionsIds = _context.CaseReportFormFieldOptions.Where(fo => fo.CaseReportFormFieldId == field.ID).Select(fo => fo.CaseReportFormOptionChoiceId).ToList();
         var formIds      = new List <int>();
         if (field.SelectedOptionsIds != null)
         {
             formIds = field.SelectedOptionsIds.ToList();
         }
         var toDeleteOptions = dbOptionsIds.Except(formIds);
         var toInsertOptions = formIds.Except(dbOptionsIds);
         if (toDeleteOptions.Count() > 0)
         {
             var fieldOptions = _context.CaseReportFormFieldOptions.Where(fo => fo.CaseReportFormFieldId == field.ID &&
                                                                          toDeleteOptions.Contains(fo.CaseReportFormOptionChoiceId));
             _context.RemoveRange(fieldOptions);
         }
         if (toInsertOptions.Count() > 0)
         {
             foreach (var optionId in toInsertOptions)
             {
                 var fieldOption = new CaseReportFormFieldOption();
                 fieldOption.CaseReportFormFieldId        = field.ID;
                 fieldOption.CaseReportFormOptionChoiceId = optionId;
                 _context.Add(fieldOption);
             }
         }
     }
     if (ModelState.IsValid)
     {
         _context.Update(section);
         _context.SaveChanges();
         return(Json(new { valid = true }));
     }
     else
     {
         var errors = ModelStateHelper.Errors(ModelState);
         return(Json(new { errors = errors, valid = false }));
     }
 }
Пример #16
0
        public async Task <IActionResult> EditPassword(string id, ResetPasswordViewModel passwordResetViewModel)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var user = await _userManager.FindByIdAsync(id);

            var passwordResetVM = new ResetPasswordViewModel();

            passwordResetVM.userId = id;

            if (ModelState.IsValid)
            {
                IdentityResult removeResult = await _userManager.RemovePasswordAsync(user);

                IdentityResult addResult = await _userManager.AddPasswordAsync(user, passwordResetViewModel.Password);

                if (removeResult.Succeeded && addResult.Succeeded)
                {
                    await _userManager.UpdateAsync(user);
                }
                else
                {
                    var updateResultErrors = removeResult.Errors.Concat(addResult.Errors);
                    foreach (var error in updateResultErrors)
                    {
                        ModelState.AddModelError("Password", error.Description);
                        Hashtable errors = ModelStateHelper.Errors(ModelState);
                        return(Json(new { success = false, errors }));
                    }
                }
                return(Json(new { result = "ok" }));
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }
        }
Пример #17
0
        public async Task <IActionResult> EditPassword(ResetPasswordViewModel passwordResetViewModel)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var passwordResetVM = new ResetPasswordViewModel();

            passwordResetVM.userId = user.Id;

            if (ModelState.IsValid)
            {
                IdentityResult removeResult = await _userManager.RemovePasswordAsync(user);

                IdentityResult addResult = await _userManager.AddPasswordAsync(user, passwordResetViewModel.Password);

                if (removeResult.Succeeded && addResult.Succeeded)
                {
                    await _userManager.UpdateAsync(user);
                }
                else
                {
                    var updateResultErrors = removeResult.Errors.Concat(addResult.Errors);
                    foreach (var error in updateResultErrors)
                    {
                        ModelState.AddModelError("Password", error.Description);
                        Hashtable errors = ModelStateHelper.Errors(ModelState);
                        passwordResetVM.Errors = errors;
                        SetFlash(FlashMessageType.Warning, "Failed to Change Password");
                        return(RedirectToAction("Index", passwordResetVM));
                    }
                }
                SetFlash(FlashMessageType.Success, "Password Changed");
                return(RedirectToAction("Index", passwordResetVM));
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                passwordResetVM.Errors = errors;
                SetFlash(FlashMessageType.Warning, "Failed to Change Password");
                return(RedirectToAction("Index", passwordResetVM));
            }
        }
Пример #18
0
        public async Task <IActionResult> Create([Bind("FirstName, LastName, PersonTitleId")] MedicalTrialPrincipalInvestigator investigator)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(investigator);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
 public async Task<IActionResult> Create(CaseReportFormCategory formCategory)
 {
     try
     {
         formCategory.Name = Request.Form["Name"];
         if (ModelState.IsValid)
         {
             _context.Add(formCategory);
             await _context.SaveChangesAsync();
             return Json(new { result = "ok" });
         }
         else
         {
             Hashtable errors = ModelStateHelper.Errors(ModelState);
             return Json(new { success = false, errors });
         }
     }
     catch (DbUpdateException)
     {
         return null;
     }
 }
Пример #20
0
        public async Task <IActionResult> EditPrincipalInvestigator(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var investigator = await _context.MedicalTrialsPrincipalInvestigators
                               .AsNoTracking()
                               .SingleOrDefaultAsync(m => m.ID == id);

            investigator.FirstName = Request.Form["Name"];
            investigator.LastName  = Request.Form["Description"];
            int personTitleId = string.IsNullOrEmpty(Request.Form["PersonTitleId"]) ? 0 : Int32.Parse(Request.Form["PersonTitleId"]);

            investigator.PersonTitleId = personTitleId;

            if (TryValidateModel(investigator))
            {
                try
                {
                    _context.MedicalTrialsPrincipalInvestigators.Update(investigator);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }
Пример #21
0
        public async Task <IActionResult> Create([Bind("Name")] SideEffect sideEffect)
        {
            try
            {
                this.CheckFieldUniqueness(_context.SideEffects, "Name", sideEffect.Name);
                if (ModelState.IsValid)
                {
                    _context.Add(sideEffect);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
        public async Task <IActionResult> Create([Bind("CategoryName")] DiagnosisCategory diagnosisCategory)
        {
            try
            {
                this.CheckFieldUniqueness(_context.DiagnosisCategories, "CategoryName", diagnosisCategory.CategoryName);
                if (ModelState.IsValid)
                {
                    _context.Add(diagnosisCategory);
                    await _context.SaveChangesAsync();

                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException)
            {
                return(null);
            }
        }
        public async Task <IActionResult> Create(PatientVisit patientVisit)
        {
            _patientVisitManager = new PatientVisitManager(_context, ViewBag, Request.Form);

            InitViewBags();

            var itemsToSave = _patientVisitManager.SavePatientExaminationsForVisit(patientVisit);

            this.CheckIfAtLeastOneIsSelected(itemsToSave.Count);

            if (ModelState.IsValid)
            {
                _context.Add(patientVisit);
                _context.PatientExaminations.AddRange(itemsToSave);
                await _context.SaveChangesAsync();
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }
            return(Json(new { result = "ok" }));
        }
        public IActionResult EditCategoryItem(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }
            var foundItem = _context.CaseReportFormCategories
                                  .Where(crfc => crfc.ID == id)
                                  .FirstOrDefault();

            if (foundItem == null)
            {
                return NotFound();
            }
            foundItem.Name = Request.Form["Name"];
            if (TryValidateModel(foundItem))
            {
                try
                {
                    _context.Update(foundItem);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                        "Try again, and if the problem persists, " +
                        "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return Json(new { success = false, errors });
            }

            return Json(new { result = "ok" });
        }
Пример #25
0
        public IActionResult Create([Bind("LastName,FirstName,DOB,Gender, RM2Number, PatientStatusId, DateOfDeath, PostCode, GenericNote")]
                                    Patient patient,
                                    PatientDiagnosis[] diagnoses,
                                    PatientDrug[] drugs,
                                    PatientSTGQuestionnaire[] sTGQuestionnaires,
                                    PatientImmunoglobulin[] patientImmunoglobulin,
                                    PatientRadiologyFinding[] patientRadiologyFinding,
                                    PatientMedicalTrial[] patientMedicalTrial,
                                    PatientDrugLevel[] drugLevels,
                                    PatientSurgery[] surgeries,
                                    PatientAllergicIntoleranceItem[] allergies,
                                    PatientPulmonaryFunctionTest[] patientPulmonaryFunctionTest,
                                    PatientNACDates patientNACDates,
                                    PatientMeasurement[] patientMeasurement,
                                    PatientMRCScore[] patientMRCScore,
                                    CaseReportFormResult[] caseReportFormResult,
                                    PatientSmokingDrinkingStatus patientSmokingDrinkingStatus)
        {
            var existingPatient = _context.Patients.FirstOrDefault(x => x.RM2Number == patient.RM2Number);

            patient.CaseReportFormResults = new List <CaseReportFormResult>();
            _patientManager.Request       = Request;
            CheckIsUnique(existingPatient);
            if (caseReportFormResult != null && caseReportFormResult.Length > 0 && caseReportFormResult[0].Results != null)
            {
                var results = caseReportFormResult[0].Results.ToArray();
                _caseReportFormManager.CreateCaseReportFormForResults(patient, results);
                patient.CaseReportFormResults.Add(caseReportFormResult[0]);
                _caseReportFormManager.LockForm(caseReportFormResult[0].CaseReportFormId);
            }

            _patientManager.AddCollectionsFromFormToPatients(patient,
                                                             ref diagnoses,
                                                             ref drugs,
                                                             ref sTGQuestionnaires,
                                                             patientImmunoglobulin,
                                                             ref patientRadiologyFinding);
            _patientManager.AddMedicalTrials(patient, patientMedicalTrial);
            _patientManager.AddDrugLevels(patient, drugLevels);
            _patientManager.AddPatientSurgeries(patient, surgeries);
            _patientManager.AddPatientAllergiesIntolerances(patient, allergies);
            _patientManager.AddPatientPFTs(patient, patientPulmonaryFunctionTest);
            _patientManager.AddPatientMeasurements(patient, patientMeasurement);
            _patientManager.AddMRCScores(patient, patientMRCScore);
            _patientManager.AddPatientNACDates(patient, patientNACDates);
            AddOrSkipSmokingStatus(patient, patientSmokingDrinkingStatus);
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(patient);
                    _context.SaveChanges();
                    _externalImport.Add(ExternalPatient.BuildFromPatient(patient));
                    var externalPatient = new ExternalPatient();
                    _externalImport.SaveChanges();
                    return(Json(new { result = "ok" }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
            catch (DbUpdateException ex)
            {
                return(null);
            }
        }
        public IActionResult EditOptionGroupItem(int?id, CaseReportFormOptionGroupViewModel optionGroup)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var foundItem = _context.CaseReportFormOptionGroups
                            .Include(crfog => crfog.Choices)
                            .Where(crfc => crfc.ID == id)
                            .FirstOrDefault();

            if (foundItem == null)
            {
                return(NotFound());
            }
            var optionsNames     = optionGroup.Options;
            var dbOptionsChoices = foundItem.Choices.Select(c => c.Name).ToList();
            var dbOptionsItems   = foundItem.Choices.ToList();
            var toDeleteOptions  = dbOptionsChoices.Except(optionsNames);
            var toInsertOptions  = optionsNames.Except(dbOptionsChoices);

            if (toDeleteOptions.Count() > 0)
            {
                var dbDeleteList = _context.CaseReportFormOptionChoices
                                   .Where(crfoc => toDeleteOptions.Contains(crfoc.Name) && crfoc.CaseReportFormOptionGroupId == id);
                _context.CaseReportFormOptionChoices.RemoveRange(dbDeleteList);
            }
            if (toInsertOptions.Count() > 0)
            {
                foreach (var optionName in toInsertOptions)
                {
                    var option = new CaseReportFormOptionChoice()
                    {
                        CaseReportFormOptionGroupId = id.Value,
                        Name = optionName
                    };
                    _context.CaseReportFormOptionChoices.Add(option);
                }
            }
            foundItem.Name = optionGroup.Name;
            if (TryValidateModel(foundItem))
            {
                try
                {
                    _context.Update(foundItem);
                    _context.SaveChanges();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }
Пример #27
0
        public IActionResult Create([Bind("ID, StartDate, EndDate, PatientIds")] Report report)
        {
            if (Request.Form.Files.Count > 0)
            {
                IFormFile file = Request.Form.Files[0];

                string webRootPath = _hostingEnvironment.WebRootPath;
                Action <FileStream, IFormFile, string> readFileAction = (stream, formFile, extension) => {
                    var    reportBuilder = new CPAMortalityAuditReportBuilder(_context, stream, _logger, formFile);
                    string newPath       = Path.Combine(webRootPath, "Upload");
                    string fileExtension = Path.GetExtension(file.FileName).ToLower();
                    string fullPath      = Path.Combine(newPath, file.FileName);
                    report.InputFilePath = fullPath;
                    reportBuilder.Build();
                };
                FileImporter.Import(file, webRootPath, readFileAction);
                var reportType = _context.ReportTypes
                                 .FirstOrDefault(rt => rt.Discriminator == "CPAMortalityAudit");
                report.ReportTypeId = reportType.ID;

                _context.Reports.Update(report);
                _context.SaveChanges();
                return(Json(new { success = true, id = report.ID }));
            }
            else
            {
                var reportType = _context.ReportTypes
                                 .FirstOrDefault(rt => rt.Discriminator == Request.Form["ReportTypeID"]);
                StringValues patientIds;
                if (reportType == null)
                {
                    return(Json(new { success = false }));
                }
                var reportItems = new List <PatientReportItem>();
                if (!string.IsNullOrEmpty(Request.Form["PatientIds"]))
                {
                    patientIds = Request.Form["PatientIds"];
                }
                if (patientIds.ToList()[0] == "null")
                {
                    ModelState.AddModelError("Base", "You need to add at least one patient to this report");
                }
                if (patientIds.ToList()[0] != "null" && !string.IsNullOrEmpty(patientIds))
                {
                    var idsToFind = patientIds.ToString()
                                    .Split(",")
                                    .Select(id => Int32.Parse(id))
                                    .ToList();

                    var patients = _context.Patients.Where(p => idsToFind.Contains(p.ID));
                    foreach (var patient in patients)
                    {
                        var patientReportItem = new PatientReportItem()
                        {
                            PatientId = patient.ID
                        };
                        reportItems.Add(patientReportItem);
                    }
                }
                report.ReportTypeId       = reportType.ID;
                report.PatientReportItems = reportItems;

                if (ModelState.IsValid)
                {
                    _context.Reports.Update(report);
                    _context.SaveChanges();
                    return(Json(new { success = true, id = report.ID }));
                }
                else
                {
                    Hashtable errors = ModelStateHelper.Errors(ModelState);
                    return(Json(new { success = false, errors }));
                }
            }
        }
Пример #28
0
        public async Task <IActionResult> EditPatient(int?id, [Bind("ID,DiagnosisCategoryId,DiagnosisTypeId,Description")] PatientDiagnosis[] diagnoses,
                                                      [Bind("ID,DrugId,StartDate,EndDate")] PatientDrug[] drugs,
                                                      [Bind("ID, ActivityScore, SymptomScore, ImpactScore, TotalScore")] PatientSTGQuestionnaire[] sTGQuestionnaires,
                                                      [Bind("ID, DateTaken, Value, ImmunoglobulinTypeId")] PatientImmunoglobulin[] patientImmunoglobulines,
                                                      [Bind("ID, DateTaken, FindingId, RadiologyTypeId, ChestLocationId, ChestDistributionId, GradeId, TreatmentResponseId, Note")] PatientRadiologyFinding[] radiololgyFindings,
                                                      [Bind("ID, PatientId, MedicalTrialId, PatientMedicalTrialStatusId, IdentifiedDate, ConsentedDate, RecruitedDate, Consented")] PatientMedicalTrial[] patientMedicalTrial,
                                                      [Bind("ID, PatientId, DrugId, UnitOfMeasurementId, DateTaken, DateReceived, ResultValue, ComparisionCharacter")] PatientDrugLevel[] drugLevels,
                                                      [Bind("ID, SurgeryId, PatientId, SurgeryDate, Note")] PatientSurgery[] surgeries,
                                                      [Bind("ID, AllergyIntoleranceItemType, AllergyIntoleranceItemId, IntoleranceType, Severity, Note")] PatientAllergicIntoleranceItem[] allergies,
                                                      [Bind("ID, PulmonaryFunctionTestId, Value, ResultValue, PatientId")] PatientPulmonaryFunctionTest[] pulmonaryFunctionTest,
                                                      [Bind("ID, FirstSeenAtNAC, CPABand, ReferralDate, LastObservationPoint, InitialDrug, FollowUp3MonthsDrug, PatientId")] PatientNACDates patientNACDates,
                                                      [Bind("ID, DateTaken, Weight, Height")] PatientMeasurement[] patientMeasurements,
                                                      [Bind("ID, DateTaken, Score")] PatientMRCScore[] patientMRCScores,
                                                      [Bind("ID, SmokingStatusId, PatientId, StartAge, StopAge, CigarettesPerDay, PacksPerYear, AlcolholUnits")] PatientSmokingDrinkingStatus patientSmokingDrinkingStatus,
                                                      CaseReportFormResult[] caseReportFormResult)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Patient patientToUpdate = await _patientManager
                                      .FindPatientWithFirstLevelRelationsByIdAsync(id);

            _patientManager.UpdateDiagnoses(diagnoses, patientToUpdate);
            _patientManager.UpdateDrugs(drugs, patientToUpdate, Request);
            _patientManager.UpdateSGRQ(sTGQuestionnaires, patientToUpdate);
            _patientManager.UpdateImmunoglobines(patientImmunoglobulines, patientToUpdate);
            _patientManager.UpdatePatientRadiology(radiololgyFindings, patientToUpdate);
            _patientManager.UpdatePatientMedicalTrials(patientMedicalTrial, patientToUpdate);
            _patientManager.UpdatePatientDrugLevels(drugLevels, patientToUpdate);
            _patientManager.UpdatePatientSurgeries(surgeries, patientToUpdate);
            _patientManager.UpdatePatientAllergiesIntolerances(allergies, patientToUpdate, Request);
            _patientManager.UpdatePatientsPFTs(pulmonaryFunctionTest, patientToUpdate);
            _patientManager.UpdateNacDates(patientNACDates, patientToUpdate);
            _patientManager.UpdateWeightHeight(patientMeasurements, patientToUpdate);
            _patientManager.UpdateMRCScore(patientMRCScores, patientToUpdate);
            AddOrSkipSmokingStatus(patientToUpdate, patientSmokingDrinkingStatus);
            _caseReportFormManager.UpdateCaseReportFormsForPatient(caseReportFormResult, patientToUpdate);



            _context.Entry(patientToUpdate).State = EntityState.Modified;
            ModelState.Remove("FirstSeenAtNAC"); //TODO - FIX THIS HACK..
            if (await TryUpdateModelAsync <Patient>(patientToUpdate,
                                                    "",
                                                    p => p.FirstName, p => p.LastName, p => p.DOB, p => p.RM2Number, p => p.PostCode,
                                                    p => p.Gender, p => p.PatientStatusId, p => p.DateOfDeath, p => p.GenericNote))
            {
                try
                {
                    _context.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    var message = ex.Message;
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            else
            {
                Hashtable errors = ModelStateHelper.Errors(ModelState);
                return(Json(new { success = false, errors }));
            }

            return(Json(new { result = "ok" }));
        }