Exemple #1
0
 /// <summary>
 /// Create an experiment
 /// </summary>
 /// <param name="experiment">Experiment to create</param>
 public void CreateExperiment(Experiment experiment)
 {
     if (experiment != null)
     {
         _experimentRepository.Add(experiment);
     }
 }
        /// <summary>
        /// Gets the patients matched with an experiment
        /// </summary>
        /// <param name="experiment">Experiment to match the patients with</param>
        /// <returns></returns>
        private List<Patient> GetPatientsForExperiment(Experiment experiment)
        {
            List<Patient> patientList = new List<Patient>();

            ExperimentViewModel model = JsonConvert.DeserializeObject<ExperimentViewModel>(experiment.QueryString);
            ExperimentCriteria criteria = CopyModelToCriteria(model);

            IEnumerable<Patient> patients = _experimentService.GetPatientsForExperiment(criteria);
            if (patients != null)
            {
                patientList.AddRange(patients);
            }

            return patientList;
        }
        public ActionResult CreateExperiment(ExperimentViewModel model,
            string[] selectedGenders, string[] selectedRaces, string[] selectedEthnicities,
            string[] selectedLocations)
        {
            ExperimentViewModel serializedModel = new ExperimentViewModel();

            serializedModel.ageRangeStart = model.ageRangeStart;
            serializedModel.ageRangeEnd = model.ageRangeEnd;
            serializedModel.weightRangeBegin = model.weightRangeBegin;
            serializedModel.weightRangeEnd = model.weightRangeEnd;
            serializedModel.heightRangeBegin = model.heightRangeBegin;
            serializedModel.heightRangeEnd = model.heightRangeEnd;

            // Generate Gender string
            if (selectedGenders != null)
            {
                model.selectedGenders = selectedGenders;
                serializedModel.selectedGenders = selectedGenders;
            }
            else
            {
                // No genders were selected, so get all genders
                string[] allGenders = Enum.GetNames(typeof(PatientGender));
                serializedModel.selectedGenders = allGenders;
            }

            // Generate Races string
            if (selectedRaces != null)
            {
                model.selectedRaces = selectedRaces;
                serializedModel.selectedRaces = selectedRaces;
            }
            else
            {
                string[] allRaces = Enum.GetNames(typeof(PatientRace));
                serializedModel.selectedRaces = allRaces;
            }

            // Generate Ethnicity string
            if (selectedEthnicities != null)
            {
                model.selectedEthnicities = selectedEthnicities;
                serializedModel.selectedEthnicities = selectedEthnicities;
            }
            else
            {
                string[] allEthnicities = Enum.GetNames(typeof(PatientEthnicity));
                serializedModel.selectedEthnicities = allEthnicities;
            }

            // Generate Locations string
            if (selectedLocations != null)
            {
                model.selectedLocations = selectedLocations;
                serializedModel.selectedLocations = selectedLocations;
            }
            else
            {
                string[] allLocations = Enum.GetNames(typeof(Location));
                serializedModel.selectedLocations = allLocations;
            }

            // These need to be down here to ensure the model is repopulated if the user enters bad criteria.
            // Check to make sure ranges are correct.
            if (model.ageRangeStart > model.ageRangeEnd)
            {
                ModelState.AddModelError("", "ERROR: The starting age in the age range is less than the ending age.");
            }
            if (model.weightRangeBegin > model.weightRangeEnd)
            {
                ModelState.AddModelError("", "ERROR: The beginning of weight range is less than the end.");
            }
            if (model.heightRangeBegin > model.heightRangeEnd)
            {
                ModelState.AddModelError("", "ERROR: The beginning of height range is less than the end.");
            }
            // Check if experiment name already exists.
            if (ExperimentNameIsUsed(model.ExperimentName))
            {
                ModelState.AddModelError("", "ERROR: That experiment name is already in use.");
            }
            // Check model state
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string queryString = JsonConvert.SerializeObject(serializedModel);

            ApplicationUserManager manager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>();

            Experiment experiment = new Experiment();
            experiment.QueryString = queryString;
            experiment.Name = model.ExperimentName;
            experiment.ExperimentAdministrator = _experimentAdminService.GetExperimentAdministrator(manager.FindByName(User.Identity.Name).ExperimentAdministratorId); // current user exp admin id
            experiment.LastModified = DateTime.Now;

            _experimentService.CreateExperiment(experiment);
            _experimentService.SaveChanges();

            return Redirect("/Experiment/CreateExperimentConfirmation");
        }