public DatasetInstance CreateInstance(int contextId, string tag, EncounterTypeWorkPlan encounterTypeWorkPlan, DatasetInstance spontaneousReport, PatientClinicalEvent activeReport) { var instance = new DatasetInstance(this, contextId, tag, encounterTypeWorkPlan); foreach (DatasetCategory category in DatasetCategories) { foreach (DatasetCategoryElement element in category.DatasetCategoryElements) { if (element.DatasetElement.Field.FieldType.Description == "Table") { instance.AddInstanceValue(element.DatasetElement, "<<Table>>"); } } } if (spontaneousReport != null) { instance.InitialiseValuesForSpontaneousDataset(tag, spontaneousReport); } if (activeReport != null) { instance.InitialiseValuesForActiveDataset(tag, activeReport); } return(instance); }
public DatasetInstance(Dataset dataset, int contextId, string tag, EncounterTypeWorkPlan encounterTypeWorkPlan) { _datasetInstanceValues = new List <DatasetInstanceValue>(); DatasetInstanceGuid = Guid.NewGuid(); Status = DatasetInstanceStatus.INCOMPLETE; Dataset = dataset; DatasetId = dataset.Id; ContextId = contextId; Tag = tag; EncounterTypeWorkPlanId = encounterTypeWorkPlan?.Id; EncounterTypeWorkPlan = encounterTypeWorkPlan; }
public async Task <IActionResult> CreateEncounterType( [FromBody] EncounterTypeForUpdateDto encounterTypeForUpdate) { if (encounterTypeForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); } if (Regex.Matches(encounterTypeForUpdate.EncounterTypeName, @"[a-zA-Z ']").Count < encounterTypeForUpdate.EncounterTypeName.Length) { ModelState.AddModelError("Message", "Description contains invalid characters (Enter A-Z, a-z)"); } if (!String.IsNullOrWhiteSpace(encounterTypeForUpdate.Help)) { if (Regex.Matches(encounterTypeForUpdate.Help, @"[a-zA-Z0-9. ']").Count < encounterTypeForUpdate.Help.Length) { ModelState.AddModelError("Message", "Help contains invalid characters (Enter A-Z, a-z, 0-9, period)"); } } if (_unitOfWork.Repository <EncounterType>().Queryable(). Where(l => l.Description == encounterTypeForUpdate.EncounterTypeName) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); } var workPlan = _workPlanRepository.Get(wp => wp.Description == encounterTypeForUpdate.WorkPlanName); if (workPlan == null) { ModelState.AddModelError("Message", "Unable to locate work plan"); } long id = 0; if (ModelState.IsValid) { var newEncounterType = new EncounterType() { Description = encounterTypeForUpdate.EncounterTypeName, Help = encounterTypeForUpdate.Help }; var newEncounterTypeWorkPlan = new EncounterTypeWorkPlan() { CohortGroup = null, EncounterType = newEncounterType, WorkPlan = workPlan }; _encounterTypeRepository.Save(newEncounterType); _encounterTypeWorkPlanRepository.Save(newEncounterTypeWorkPlan); id = newEncounterType.Id; var mappedEncounterType = await GetEncounterTypeAsync <EncounterTypeIdentifierDto>(id); if (mappedEncounterType == null) { return(StatusCode(500, "Unable to locate newly added item")); } return(CreatedAtAction("GetEncounterTypeByIdentifier", new { id = mappedEncounterType.Id }, CreateLinksForEncounterType <EncounterTypeIdentifierDto>(mappedEncounterType))); } return(BadRequest(ModelState)); }
public ActionResult AddEncounterType(EncounterTypeAddModel model) { ViewBag.MenuItem = CurrentMenuItem; if (unitOfWork.Repository <EncounterType>().Queryable().Any(et => et.Description == model.Description)) { ModelState.AddModelError("Description", "An encounter type with the specified description already exists."); } if (Regex.Matches(model.Description, @"[a-zA-Z ']").Count < model.Description.Length) { ModelState.AddModelError("Description", "Description contains invalid characters (Enter A-Z, a-z)"); } if (!String.IsNullOrWhiteSpace(model.Help)) { if (Regex.Matches(model.Help, @"[a-zA-Z ']").Count < model.Help.Length) { ModelState.AddModelError("Help", "Help contains invalid characters (Enter A-Z, a-z)"); } } if (ModelState.IsValid) { var encodedDescription = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.Description, false); var encodedHelp = !String.IsNullOrWhiteSpace(model.Help) ? System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.Help, false) : ""; var newEncounterType = new EncounterType { Description = encodedDescription, Help = encodedHelp }; var workPlan = unitOfWork.Repository <WorkPlan>().Queryable().SingleOrDefault(wp => wp.Id == model.WorkPlanId); var newEncounterTypeWorkPlan = new EncounterTypeWorkPlan { CohortGroup = null, EncounterType = newEncounterType, WorkPlan = workPlan }; try { unitOfWork.Repository <EncounterType>().Save(newEncounterType); unitOfWork.Repository <EncounterTypeWorkPlan>().Save(newEncounterTypeWorkPlan); return(Redirect("/Admin/ManageEncounterType.aspx")); } catch (Exception ex) { ModelState.AddModelError("", string.Format("Unable to add the encounter type: {0}", ex.Message)); } } var workPlans = unitOfWork.Repository <WorkPlan>() .Queryable() .ToList(); var wpList = new List <SelectListItem> { { new SelectListItem { Value = "", Text = "" } } }; wpList.AddRange(workPlans.Select(wp => new SelectListItem { Value = wp.Id.ToString(), Text = wp.Description })); ViewBag.WorkPlans = wpList; return(View(model)); }