public ActionResult Index(int reportInstanceId) { var reportInstance = _unitOfWork.Repository <ReportInstance>().Queryable().Single(ri => ri.Id == reportInstanceId); ViewBag.MenuItem = string.Equals(reportInstance.WorkFlow.WorkFlowGuid.ToString(), "892F3305-7819-4F18-8A87-11CBA3AEE219", StringComparison.InvariantCultureIgnoreCase) ? "ActiveReporting" : "SpontaneousReporting"; ViewBag.PopUpMessage = PreparePopUpMessage(); var returnUrl = "/Analytical/ReportInstanceList.aspx?wuid=" + reportInstance.WorkFlow.WorkFlowGuid.ToString(); TempData["returnUrl"] = returnUrl; ViewBag.ReturnUrl = returnUrl; var activities = _unitOfWork.Repository <ActivityExecutionStatusEvent>().Queryable().Include(evt => evt.ExecutionStatus.Activity).Include(evt2 => evt2.EventCreatedBy).Where(evt => evt.ActivityInstance.ReportInstance.Id == reportInstanceId).OrderBy(evt => evt.EventDateTime).ToList().Select(a => new ActivityListItem { Activity = a.ExecutionStatus.Activity.QualifiedName, Comments = a.Comments, ExecutionBy = a.EventCreatedBy != null ? a.EventCreatedBy.FullName : string.Empty, ExecutionDate = a.EventDateTime.ToString("yyyy-MM-dd HH:mm"), ExecutionEvent = a.ExecutionStatus.Description, ReceiptDate = a.ContextDateTime != null ? Convert.ToDateTime(a.ContextDateTime).ToString("yyyy-MM-dd") : "", ReceiptCode = a.ContextCode, PatientSummaryFileId = a.Attachments.SingleOrDefault(att => att.Description == "PatientSummary") == null ? 0 : a.Attachments.SingleOrDefault(att => att.Description == "PatientSummary").Id, PatientExtractFileId = a.Attachments.SingleOrDefault(att => att.Description == "PatientExtract") == null ? 0 : a.Attachments.SingleOrDefault(att => att.Description == "PatientExtract").Id, E2bXmlFileId = a.Attachments.SingleOrDefault(att => att.Description == "E2b") == null ? 0 : a.Attachments.SingleOrDefault(att => att.Description == "E2b").Id }); ViewData.Model = activities; return(View()); }
public ActionResult ViewCustomAttribute(string entityName, string attributeName) { ViewBag.MenuItem = CurrentMenuItem; var config = _unitOfWork.Repository <CustomAttributeConfiguration>() .Queryable() .Single(ca => ca.ExtendableTypeName == entityName && ca.AttributeKey == attributeName); List <SelectListItem> listItems = new List <SelectListItem>(); SelectListItem listItem = new SelectListItem { Text = "Numeric", Value = "1" }; listItems.Add(listItem); listItem = new SelectListItem { Text = "String", Value = "2" }; listItems.Add(listItem); listItem = new SelectListItem { Text = "Selection", Value = "3" }; listItems.Add(listItem); listItem = new SelectListItem { Text = "DateTime", Value = "4" }; listItems.Add(listItem); ViewBag.CustomAttributeTypes = listItems; ViewData.Model = new CustomAttributeConfigDetail { EntityName = entityName, Category = config.Category, AttributeDetail = config.AttributeDetail, CustomAttributeType = config.CustomAttributeType, Required = config.IsRequired, Searchable = config.IsSearchable, NumericMaxValue = config.NumericMaxValue, NumericMinValue = config.NumericMinValue, FutureDateOnly = config.FutureDateOnly, PastDateOnly = config.PastDateOnly, StringMaxLength = config.StringMaxLength }; return(View()); }
public UserInfoStore(IUnitOfWorkInt unitOfWork) { this.unitOfWork = unitOfWork; this.userRoleRepository = unitOfWork.Repository <UserRole>(); this.roleRepository = unitOfWork.Repository <Role>(); this.userRepository = unitOfWork.Repository <User>(); }
public DatasetElement GetTerminologyMedDra() { var meddraElement = _unitOfWork.Repository <DatasetElement>().Queryable().SingleOrDefault(u => u.ElementName == "TerminologyMedDra"); if (meddraElement == null) { meddraElement = new DatasetElement() { // Prepare new element DatasetElementType = _unitOfWork.Repository <DatasetElementType>().Queryable().Single(x => x.Description == "Generic"), Field = new Field() { Anonymise = false, Mandatory = false, FieldType = _unitOfWork.Repository <FieldType>().Queryable().Single(x => x.Description == "AlphaNumericTextbox") }, ElementName = "TerminologyMedDra", DefaultValue = string.Empty, OID = string.Empty, System = true }; var rule = meddraElement.GetRule(DatasetRuleType.ElementCanoOnlyLinkToSingleDataset); rule.RuleActive = true; _unitOfWork.Repository <DatasetElement>().Save(meddraElement); } return(meddraElement); }
public CustomAttributeService(IUnitOfWorkInt unitOfWork) { Check.IsNotNull(unitOfWork, "unitOfWork may not be null"); customAttributeConfigRepository = unitOfWork.Repository <CustomAttributeConfiguration>(); selectionDataRepository = unitOfWork.Repository <SelectionDataItem>(); _unitOfWork = unitOfWork; }
public ActionResult EditContactDetail(int cId) { ViewBag.MenuItem = CurrentMenuItem; var contact = unitOfWork.Repository <SiteContactDetail>().Queryable().SingleOrDefault(c => c.Id == cId); return(View(new ContactDetailEditModel { ContactDetailId = contact.Id, City = contact.City, ContactEmail = contact.ContactEmail, ContactFirstName = contact.ContactFirstName, ContactNumber = contact.ContactNumber, ContactSurname = contact.ContactSurname, ContactType = contact.ContactType.ToString(), CountryCode = contact.CountryCode, OrganisationName = contact.OrganisationName, PostCode = contact.PostCode, State = contact.State, StreetAddress = contact.StreetAddress })); }
public ActionResult DownloadSingleAttachment(long attid) { var generatedDate = DateTime.Now; var documentDirectory = String.Format("{0}\\Temp\\", System.AppDomain.CurrentDomain.BaseDirectory); // Get attachment var attachment = _unitOfWork.Repository <Attachment>().Queryable().SingleOrDefault(a => a.Id == attid); if (attachment == null) { return(null); } // Write file FileStream fs = new System.IO.FileStream(string.Format("{0}{1}", documentDirectory, attachment.FileName), System.IO.FileMode.Create, FileAccess.Write); // Writes a block of bytes to this stream using data from // a byte array. fs.Write(attachment.Content, 0, attachment.Content.Length); // close file stream fs.Close(); switch (attachment.AttachmentType.Key) { case "docx": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", attachment.FileName)); case "doc": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "application/msword", attachment.FileName)); case "xlsx": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", attachment.FileName)); case "xls": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "application/vnd.ms-excel", attachment.FileName)); case "pdf": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "application/pdf", attachment.FileName)); case "png": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "image/png", attachment.FileName)); case "jpg": case "jpeg": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "image/jpeg", attachment.FileName)); case "bmp": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "image/bmp", attachment.FileName)); case "xml": return(File(string.Format("{0}{1}", documentDirectory, attachment.FileName), "application/xhtml+xml", attachment.FileName)); } return(null); }
public async Task <IActionResult> CreateLabTest( [FromBody] LabTestForUpdateDto labTestForUpdate) { if (labTestForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); } if (Regex.Matches(labTestForUpdate.LabTestName, @"[a-zA-Z0-9 ]").Count < labTestForUpdate.LabTestName.Length) { ModelState.AddModelError("Message", "Value contains invalid characters (Enter A-Z, a-z, 0-9, space)"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <LabTest>().Queryable(). Where(l => l.Description == labTestForUpdate.LabTestName) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); } long id = 0; if (ModelState.IsValid) { var newLabTest = new LabTest() { Description = labTestForUpdate.LabTestName, Active = true }; _labTestRepository.Save(newLabTest); id = newLabTest.Id; var mappedLabTest = await GetLabTestAsync <LabTestIdentifierDto>(id); if (mappedLabTest == null) { return(StatusCode(500, "Unable to locate newly added item")); } return(CreatedAtAction("GetLabTestByIdentifier", new { id = mappedLabTest.Id }, CreateLinksForLabTest <LabTestIdentifierDto>(mappedLabTest))); } return(BadRequest(ModelState)); }
public async Task <IActionResult> CreateCareEvent( [FromBody] CareEventForUpdateDto careEventForUpdate) { if (careEventForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (Regex.Matches(careEventForUpdate.CareEventName, @"[a-zA-Z ']").Count < careEventForUpdate.CareEventName.Length) { ModelState.AddModelError("Message", "Description contains invalid characters (Enter A-Z, a-z)"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <CareEvent>().Queryable(). Where(l => l.Description == careEventForUpdate.CareEventName) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); return(BadRequest(ModelState)); } long id = 0; if (ModelState.IsValid) { var newCareEvent = new CareEvent() { Description = careEventForUpdate.CareEventName }; _careEventRepository.Save(newCareEvent); id = newCareEvent.Id; } var mappedCareEvent = await GetCareEventAsync <CareEventIdentifierDto>(id); if (mappedCareEvent == null) { return(StatusCode(500, "Unable to locate newly added item")); } return(CreatedAtAction("GetCareEventByIdentifier", new { id = mappedCareEvent.Id }, CreateLinksForCareEvent <CareEventIdentifierDto>(mappedCareEvent))); }
public ActionResult Index() { ViewBag.MenuItem = CurrentMenuItem; ViewData.Model = unitOfWork.Repository <Role>().Queryable() .ToList() .Select(r => new RoleListItem { RoleId = r.Id, RoleName = r.Name, RoleKey = r.Key }); return(View()); }
// GET: odata/PatientOData public async Task <IHttpActionResult> Get(ODataQueryOptions <PatientDTO> queryOptions) { try { queryOptions.Validate(_validationSettings); var patients = await Task.Run(() => unitOfWork.Repository <Patient>() .Queryable() .ToList() .Select(p => new PatientDTO { PatientId = p.Id, PatientUniqueIdentifier = p.PatientGuid, PatientFirstName = p.FirstName, PatientLastName = p.Surname, PatientDateOfBirth = p.DateOfBirth.GetValueOrDefault(DateTime.MinValue), }).ToArray()); return(Ok(patients)); } catch (ODataException ex) { return(BadRequest(ex.Message)); } }
private async Task CreateE2BExtractAndLinkToExecutionEventAsync(ReportInstance reportInstance, ActivityExecutionStatusEvent executionEvent) { if (reportInstance is null) { throw new ArgumentNullException(nameof(reportInstance)); } if (executionEvent is null) { throw new ArgumentNullException(nameof(executionEvent)); } var e2bInstance = await GetDatasetInstance(reportInstance); if (e2bInstance == null) { throw new KeyNotFoundException($"Unable to locate E2B dataset for report {reportInstance.Id} for XML generation"); } var artefactModel = await _xmlDocumentService.CreateE2BDocumentAsync(e2bInstance); using (var tempFile = File.OpenRead(artefactModel.FullPath)) { if (tempFile.Length > 0) { BinaryReader rdr = new BinaryReader(tempFile); executionEvent.AddAttachment(Path.GetFileName(artefactModel.FileName), _unitOfWork.Repository <AttachmentType>().Queryable().Single(at => at.Key == "xml"), tempFile.Length, rdr.ReadBytes((int)tempFile.Length), "E2b"); } } }
public InfrastructureService(IUnitOfWorkInt unitOfWork) { Check.IsNotNull(unitOfWork, "unitOfWork may not be null"); _unitOfWork = unitOfWork; _instanceValueRepository = unitOfWork.Repository <DatasetInstanceValue>(); }
public PatientService(IUnitOfWorkInt unitOfWork) { Check.IsNotNull(unitOfWork, "unitOfWork may not be null"); _unitOfWork = unitOfWork; _patientRepository = unitOfWork.Repository <Patient>(); }
public IHttpActionResult GetCohortGroups() { var cohortGroups = _unitOfWork.Repository <CohortGroup>() .Queryable() .OrderBy(cg => cg.CohortName) .Select(cg => new { Id = cg.Id, CohortName = cg.CohortName }); return(Ok(cohortGroups.ToArray())); }
public async Task <IActionResult> CreateLabResult( [FromBody] LabResultForUpdateDto labResultForUpdate) { if (labResultForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <LabResult>().Queryable(). Where(l => l.Description == labResultForUpdate.LabResultName) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); return(BadRequest(ModelState)); } long id = 0; if (ModelState.IsValid) { var newLabResult = new LabResult() { Description = labResultForUpdate.LabResultName, Active = true }; _labResultRepository.Save(newLabResult); id = newLabResult.Id; } var mappedLabResult = await GetLabResultAsync <LabResultIdentifierDto>(id); if (mappedLabResult == null) { return(StatusCode(500, "Unable to locate newly added item")); } return(CreatedAtAction("GetLabResultByIdentifier", new { id = mappedLabResult.Id }, CreateLinksForLabResult <LabResultIdentifierDto>(mappedLabResult))); }
public async Task <IActionResult> CreateHoliday( [FromBody] HolidayForUpdateDto holidayForUpdate) { if (holidayForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <Holiday>().Queryable(). Where(l => l.HolidayDate == holidayForUpdate.HolidayDate) .Count() > 0) { ModelState.AddModelError("Message", "A holiday has already been loaded for this date"); return(BadRequest(ModelState)); } long id = 0; if (ModelState.IsValid) { var newHoliday = new Holiday() { HolidayDate = holidayForUpdate.HolidayDate, Description = holidayForUpdate.Description }; _holidayRepository.Save(newHoliday); id = newHoliday.Id; } var mappedHoliday = await GetHolidayAsync <HolidayIdentifierDto>(id); if (mappedHoliday == null) { return(StatusCode(500, "Unable to locate newly added item")); } return(CreatedAtAction("GetHolidayByIdentifier", new { id = mappedHoliday.Id }, CreateLinksForHoliday <HolidayIdentifierDto>(mappedHoliday))); }
// GET: api/PatientLabTestApi public async Task <IEnumerable <PatientLabTestDTO> > Get() { return(await Task.Run(() => unitOfWork.Repository <PatientLabTest>() .Queryable() .Include(p => p.TestUnit) .ToList() .Select(p => new PatientLabTestDTO { PatientId = p.Patient.Id, PatientLabTestId = p.Id, PatientLabTestIdentifier = p.PatientLabTestGuid, TestName = p.LabTest != null ? p.LabTest.Description : "", TestDate = p.TestDate, TestResult = p.TestResult, LabValue = p.LabValue, TestUnit = p.TestUnit != null ? p.TestUnit.Id : 0, customAttributes = getCustomAttributes(p) }).ToArray())); }
public void UpdateCustomAttribute(CustomAttributeConfigDetail customAttribute) { var updateCustomAttribute = _unitOfWork.Repository <CustomAttributeConfiguration>().Queryable().Single(ca => ca.ExtendableTypeName == customAttribute.EntityName && ca.AttributeKey == customAttribute.AttributeName); updateCustomAttribute.Category = customAttribute.Category; updateCustomAttribute.AttributeDetail = customAttribute.AttributeDetail; updateCustomAttribute.IsRequired = customAttribute.Required; updateCustomAttribute.IsSearchable = customAttribute.Searchable; switch (updateCustomAttribute.CustomAttributeType) { case CustomAttributeType.Numeric: if (customAttribute.NumericMinValue.HasValue) { updateCustomAttribute.NumericMinValue = customAttribute.NumericMinValue.Value; } if (customAttribute.NumericMaxValue.HasValue) { updateCustomAttribute.NumericMaxValue = customAttribute.NumericMaxValue.Value; } break; case CustomAttributeType.String: if (customAttribute.StringMaxLength.HasValue) { updateCustomAttribute.StringMaxLength = customAttribute.StringMaxLength.Value; } break; case CustomAttributeType.DateTime: updateCustomAttribute.FutureDateOnly = customAttribute.FutureDateOnly; updateCustomAttribute.PastDateOnly = customAttribute.PastDateOnly; break; default: break; } customAttributeConfigRepository.Update(updateCustomAttribute); _unitOfWork.Complete(); }
public DatasetInstanceValueList GetElementValuesForPatient(Patient patient, DatasetElement element, int records) { var encounters = _unitOfWork.Repository <Encounter>().Queryable().Where(e => e.Patient.Id == patient.Id).OrderByDescending(e => e.EncounterDate).Take(records); var model = new DatasetInstanceValueList() { DatasetElement = element }; foreach (Encounter encounter in encounters) { var val = GetValueForElement(_unitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(di => di.ContextID == encounter.Id), element); var modelItem = new DatasetInstanceValueListItem() { Value = !String.IsNullOrWhiteSpace(val) ? val : "NO VALUE", ValueDate = encounter.EncounterDate }; model.Values.Add(modelItem); } return(model); }
public DatasetInstanceValueListDto GetElementValuesForPatient(long patientId, string datasetName, string elementName, int records) { var encounters = _unitOfWork.Repository <Encounter>().Queryable() .Where(e => e.Patient.Id == patientId) .OrderByDescending(e => e.EncounterDate).Take(records); var datasetElement = _unitOfWork.Repository <DatasetElement>().Queryable() .SingleOrDefault(de => de.ElementName == elementName && de.DatasetCategoryElements.Any(dce => dce.DatasetCategory.Dataset.DatasetName == datasetName)); var model = new DatasetInstanceValueListDto() { DatasetElement = datasetElement }; if (datasetElement != null) { foreach (Encounter encounter in encounters) { var val = GetValueForElement(_unitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(di => di.ContextID == encounter.Id), datasetElement); var modelItem = new DatasetInstanceValueListItem() { Value = !String.IsNullOrWhiteSpace(val) ? val : "NO VALUE", ValueDate = encounter.EncounterDate }; model.Values.Add(modelItem); } } return(model); }
public IHttpActionResult GetDatasetElementSubsForDatasetElementId(int id) { var datasetElement = unitOfWork.Repository <DatasetElement>() .Queryable() .Include(i => i.DatasetElementSubs.Select(i2 => i2.Field.FieldType)) .Include(i => i.DatasetElementSubs.Select(i2 => i2.Field.FieldValues)) .SingleOrDefault(de => de.Id == id); var items = datasetElement.DatasetElementSubs .Where(des => des.System == false) .OrderBy(o => o.FieldOrder) .Select(des => new { DatasetElementSubId = des.Id, DatasetElementSubName = des.ElementName, DatasetElementSubDisplayName = String.IsNullOrWhiteSpace(des.FriendlyName) ? des.ElementName : des.FriendlyName, DatasetElementSubHelp = des.Help, DatasetElementSubType = des.Field.FieldType.Description, DatasetElementSubRequired = des.Field.Mandatory, FieldValues = des.Field.FieldValues.OrderBy(fv => fv.Value).Select(fv => new { FieldValueId = fv.Id, FieldValueName = fv.Value }) .ToArray() }) .ToArray(); return(Ok(items)); }
// GET: api/PatientConditionApi public async Task <IEnumerable <PatientConditionDTO> > Get() { return(await Task.Run(() => unitOfWork.Repository <PatientCondition>() .Queryable() .ToList() .Select(p => new PatientConditionDTO { PatientConditionIdentifier = p.PatientConditionGuid, PatientConditionId = p.Id, PatientId = p.Patient.Id, MedDraId = p.TerminologyMedDra.Id, //ConditionId = p.Condition != null ? p.Condition.Id: default(int), StartDate = p.DateStart, EndDate = p.OutcomeDate, Comments = p.Comments, customAttributes = getCustomAttributes(p) }).ToArray())); }
public void ExecuteScripts() { var scriptsFolder = Server.MapPath("~/PostDeploymentScripts/"); var postDeploymentRepository = _unitOfWork.Repository <PostDeployment>(); var pendingPostDeploymentScripts = postDeploymentRepository.Queryable() .Where(x => !x.RunDate.HasValue) .OrderBy(u => u.RunRank) .ToList(); foreach (var pendingPostDeploymentScript in pendingPostDeploymentScripts) { try { var fullPath = Path.Combine(scriptsFolder, pendingPostDeploymentScript.ScriptFileName); if (!System.IO.File.Exists(fullPath)) { pendingPostDeploymentScript.StatusCode = 404; pendingPostDeploymentScript.StatusMessage = "File not found"; } else { postDeploymentRepository.ExecuteSqlCommand(System.IO.File.ReadAllText(fullPath)); pendingPostDeploymentScript.StatusCode = 200; } } catch (Exception exception) { pendingPostDeploymentScript.StatusCode = 501; pendingPostDeploymentScript.StatusMessage = exception.Message; } finally { pendingPostDeploymentScript.RunDate = DateTime.Now; postDeploymentRepository.Update(pendingPostDeploymentScript); _unitOfWork.Complete(); } } }
public async Task <ActionResult <List <GroupValueDto> > > GetGroupValues(long id) { var datasetElementFromRepo = await _datasetElementRepository.GetAsync(f => f.Id == id); if (datasetElementFromRepo == null) { return(NotFound()); } var instanceValues = _unitOfWork.Repository <DatasetInstanceValue>() .Queryable() .Where(div => div.DatasetElement.Id == datasetElementFromRepo.Id) .GroupBy(val => val.InstanceValue) .Select(group => new GroupValueDto() { GroupValue = group.Key, Count = group.Count() }) .OrderBy(x => x.GroupValue) .ToList(); return(Ok(instanceValues)); }
/// <summary> /// Prepare patient record with associated conditions /// </summary> private void AddConditions(Patient patient, List <ConditionDetail> conditions) { if (patient == null) { throw new ArgumentNullException(nameof(patient)); } if (conditions == null) { throw new ArgumentNullException(nameof(conditions)); } if (conditions.Count == 0) { return; } foreach (var condition in conditions) { var treatmentOutcome = !String.IsNullOrWhiteSpace(condition.TreatmentOutcome) ? _unitOfWork.Repository <TreatmentOutcome>().Get(to => to.Description == condition.TreatmentOutcome) : null; var terminologyMedDra = condition.MeddraTermId != null?_unitOfWork.Repository <TerminologyMedDra>().Get(tm => tm.Id == condition.MeddraTermId) : null; var patientCondition = new PatientCondition { Patient = patient, ConditionSource = condition.ConditionSource, TerminologyMedDra = terminologyMedDra, OnsetDate = Convert.ToDateTime(condition.OnsetDate), TreatmentOutcome = treatmentOutcome, CaseNumber = condition.CaseNumber, Comments = condition.Comments }; // Custom Property handling _typeExtensionHandler.UpdateExtendable(patientCondition, condition.CustomAttributes, "Admin"); patient.PatientConditions.Add(patientCondition); } }
public async Task <UserInfo> FindByEmailAsync(string email) { var user = await unitOfWork.Repository <User>() .Queryable() .FirstOrDefaultAsync(u => u.Email == email); if (user == null) { return(null); } return(new UserInfo { Id = user.Id, Email = user.Email, UserName = user.UserName }); }
public ActionResult AddCareEvent(CareEventAddModel model) { ViewBag.MenuItem = CurrentMenuItem; if (ModelState.IsValid) { if (unitOfWork.Repository <CareEvent>().Queryable().Any(ce => ce.Description == model.Description)) { ModelState.AddModelError("Description", "A care event with the specified description already exists."); return(View(model)); } if (Regex.Matches(model.Description, @"[a-zA-Z ']").Count < model.Description.Length) { ModelState.AddModelError("Description", "Description contains invalid characters (Enter A-Z, a-z)"); return(View(model)); } var encodedDescription = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.Description, false); var newCareEvent = new CareEvent { Description = encodedDescription }; try { unitOfWork.Repository <CareEvent>().Save(newCareEvent); return(Redirect("/Admin/ManageCareEvent.aspx")); } catch (Exception ex) { ModelState.AddModelError("", string.Format("Unable to add the care event: {0}", ex.Message)); } } return(View(model)); }
public async Task CreateWorkFlowInstanceAsync(string workFlowName, Guid contextGuid, string patientIdentifier, string sourceIdentifier, string facilityIdentifier) { if (string.IsNullOrWhiteSpace(workFlowName)) { throw new ArgumentException($"'{nameof(workFlowName)}' cannot be null or whitespace.", nameof(workFlowName)); } if (string.IsNullOrWhiteSpace(sourceIdentifier)) { throw new ArgumentException($"'{nameof(sourceIdentifier)}' cannot be null or whitespace.", nameof(sourceIdentifier)); } if (string.IsNullOrWhiteSpace(facilityIdentifier)) { throw new ArgumentException($"'{nameof(facilityIdentifier)}' cannot be null or whitespace.", nameof(facilityIdentifier)); } // Ensure instance does not exist for this context var workFlow = await _workFlowRepository.GetAsync(wf => wf.Description == workFlowName, new string[] { "Activities.ExecutionStatuses" }); if (workFlow == null) { throw new KeyNotFoundException($"{nameof(workFlowName)} Unable to locate work flow"); } var userName = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var currentUser = await _userRepository.GetAsync(u => u.UserName == userName); if (currentUser == null) { throw new KeyNotFoundException($"Unable to locate current user"); } var reportInstance = await _reportInstanceRepository.GetAsync(ri => ri.ContextGuid == contextGuid); if (reportInstance == null) { reportInstance = new ReportInstance(workFlow, currentUser, contextGuid, patientIdentifier, sourceIdentifier, facilityIdentifier); await _reportInstanceRepository.SaveAsync(reportInstance); reportInstance.SetSystemIdentifier(); _unitOfWork.Repository <ReportInstance>().Update(reportInstance); await _unitOfWork.CompleteAsync(); } }
// GET: api/PatientMedicationApi public async Task <IEnumerable <PatientMedicationDTO> > Get() { return(await Task.Run(() => unitOfWork.Repository <PatientMedication>() .Queryable() .ToList() .Select(p => new PatientMedicationDTO { PatientMedicationIdentifier = p.PatientMedicationGuid, PatientMedicationId = p.Id, PatientId = p.Patient.Id, MedicationId = p.Medication != null? p.Medication.Id: default(int), StartDate = p.DateStart, EndDate = p.DateEnd, Dose = p.Dose, DoseFrequency = p.DoseFrequency, DoseUnit = p.DoseUnit, CustomAttributes = getCustomAttributes(p) }).ToArray())); }