public string GetCustomAttributeValue(CustomAttributeConfiguration config, IExtendable extended) { DateTime dttemp; if (extended.GetAttributeValue(config.AttributeKey) == null) { return(""); } ; var val = extended.GetAttributeValue(config.AttributeKey).ToString(); switch (config.CustomAttributeType) { case CustomAttributeType.FirstClassProperty: case CustomAttributeType.None: return(string.Empty); case CustomAttributeType.Numeric: case CustomAttributeType.String: return(val); case CustomAttributeType.Selection: var selection = _unitOfWork.Repository <SelectionDataItem>().Queryable().SingleOrDefault(s => s.AttributeKey == config.AttributeKey && s.SelectionKey == val); return(selection.Value); case CustomAttributeType.DateTime: return(DateTime.TryParse(val, out dttemp) ? Convert.ToDateTime(val).ToString("yyyy-MM-dd") : val); default: return(string.Empty); } }
private object GetAttributeValue(IExtendable extendable, CustomAttributeConfiguration config) { switch (config.CustomAttributeType) { case CustomAttributeType.Numeric: return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null) ? default(decimal) : extendable.GetAttributeValue(config.AttributeKey)); case CustomAttributeType.String: return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null) ? " "// Not a big fan of this but Razor does not recognise empty strings and ends up not rendering a control for the attribute. : extendable.GetAttributeValue(config.AttributeKey)); case CustomAttributeType.Selection: return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null) ? default(int) : extendable.GetAttributeValue(config.AttributeKey)); case CustomAttributeType.DateTime: return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null) ? default(DateTime) : extendable.GetAttributeValue(config.AttributeKey)); default: throw new CustomAttributeException("Unknown AttributeType for AttributeKey: {0}", config.AttributeKey); } }
private string GetCustomAttributeVale(IExtendable extendable, PVIMS.Core.Entities.CustomAttributeConfiguration customAttribute) { var attributeValue = extendable.GetAttributeValue(customAttribute.AttributeKey); if (attributeValue == null) { return(string.Empty); } if (customAttribute.CustomAttributeType == CustomAttributeType.DateTime) { DateTime datetimeValue = DateTime.MinValue; if (DateTime.TryParse(attributeValue.ToString(), out datetimeValue)) { return(datetimeValue.ToString("yyyy-MM-dd")); } else { return(string.Empty); } } else { return(attributeValue.ToString()); } }
private async Task CustomMapAsync(PatientList patientListFromRepo, PatientDetailDto mappedPatient) { if (patientListFromRepo == null) { throw new ArgumentNullException(nameof(patientListFromRepo)); } if (mappedPatient == null) { throw new ArgumentNullException(nameof(mappedPatient)); } var patientFromRepo = await _patientRepository.GetAsync(p => p.Id == mappedPatient.Id); if (patientFromRepo == null) { return; } IExtendable patientExtended = patientFromRepo; // Map all custom attributes mappedPatient.PatientAttributes = _modelExtensionBuilder.BuildModelExtension(patientExtended) .Select(h => new AttributeValueDto() { Key = h.AttributeKey, Value = h.Value.ToString(), Category = h.Category, SelectionValue = GetSelectionValue(h.Type, h.AttributeKey, h.Value.ToString()) }).Where(s => (s.Value != "0" && !String.IsNullOrWhiteSpace(s.Value)) || !String.IsNullOrWhiteSpace(s.SelectionValue)).ToList(); var attribute = patientExtended.GetAttributeValue("Medical Record Number"); mappedPatient.MedicalRecordNumber = attribute != null?attribute.ToString() : ""; }
private string GetCustomAttributeValue(CustomAttributeConfiguration config, IExtendable extended) { if (extended.GetAttributeValue(config.AttributeKey) == null) { return(""); } ; var val = extended.GetAttributeValue(config.AttributeKey).ToString(); if (config.CustomAttributeType == CustomAttributeType.Selection) { var selection = unitOfWork.Repository <SelectionDataItem>().Queryable().SingleOrDefault(s => s.AttributeKey == config.AttributeKey && s.SelectionKey == val); return(selection.Value); } else { return(val); } }
public void UpdateExtendable_SetsNumericCustomAttribute() { // Arrange var attributeDetails = new List <CustomAttributeDetail> { new CustomAttributeDetail { AttributeKey = "NumericAttribute", Type = CustomAttributeType.Numeric, Value = "1.0" } }; // Act handlerUnderTest.UpdateExtendable(emptyExtendable, attributeDetails, "UserName"); // Assert Assert.AreEqual(1, emptyExtendable.CustomAttributes.CustomNumericAttributes.Count, "Numeric Attribute Count"); Assert.AreEqual(typeof(decimal), emptyExtendable.GetAttributeValue("NumericAttribute").GetType(), "NumericAttribute type"); Assert.AreEqual(1.0, Convert.ToDecimal(emptyExtendable.GetAttributeValue("NumericAttribute")), "NumericAttribute value"); }
private void CustomAttributeMap(Patient patientFromRepo, PatientExpandedDto mappedPatient) { IExtendable patientExtended = patientFromRepo; mappedPatient.PatientAttributes = _modelExtensionBuilder.BuildModelExtension(patientExtended) .Select(h => new AttributeValueDto() { Key = h.AttributeKey, Value = h.Value.ToString(), Category = h.Category, SelectionValue = GetSelectionValue(h.Type, h.AttributeKey, h.Value.ToString()) }).Where(s => (s.Value != "0" && !String.IsNullOrWhiteSpace(s.Value)) || !String.IsNullOrWhiteSpace(s.SelectionValue)).ToList(); // Map additional attributes to main dto var attribute = patientExtended.GetAttributeValue("Medical Record Number"); mappedPatient.MedicalRecordNumber = attribute != null?attribute.ToString() : ""; }
public async Task <string> GetCustomAttributeValueAsync(string extendableTypeName, string attributeKey, IExtendable extended) { var configuration = await _customAttributeConfigRepository.GetAsync(c => c.ExtendableTypeName == extendableTypeName && c.AttributeKey == attributeKey); if (configuration == null) { return(""); } DateTime dttemp; var val = extended.GetAttributeValue(configuration.AttributeKey); if (val == null) { return(""); } ; switch (configuration.CustomAttributeType) { case CustomAttributeType.FirstClassProperty: case CustomAttributeType.None: return(string.Empty); case CustomAttributeType.Numeric: case CustomAttributeType.String: return(val.ToString()); case CustomAttributeType.Selection: var selection = _selectionDataItemRepository.Get(s => s.AttributeKey == configuration.AttributeKey && s.SelectionKey == val.ToString()); return(selection?.Value); case CustomAttributeType.DateTime: return(DateTime.TryParse(val.ToString(), out dttemp) ? Convert.ToDateTime(val) > DateTime.MinValue ? Convert.ToDateTime(val).ToString("yyyy-MM-dd") : string.Empty : string.Empty); default: return(string.Empty); } }
private async Task CustomMapAsync(Encounter encounterFromRepo, EncounterDetailDto mappedEncounter) { if (encounterFromRepo == null) { throw new ArgumentNullException(nameof(encounterFromRepo)); } mappedEncounter.Patient = _mapper.Map <PatientDetailDto>(encounterFromRepo.Patient); var datasetInstanceFromRepo = await _datasetInstanceRepository.GetAsync(di => di.Dataset.ContextType.Id == (int)ContextTypes.Encounter && di.ContextId == mappedEncounter.Id && di.EncounterTypeWorkPlan.EncounterType.Id == encounterFromRepo.EncounterType.Id , new string[] { "Dataset.ContextType" , "EncounterTypeWorkPlan.EncounterType" , "Dataset.DatasetCategories.DatasetCategoryElements" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.Field.FieldValues" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.DatasetElementSubs" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategoryElementConditions" , "DatasetInstanceValues" }); if (datasetInstanceFromRepo != null) { var groupedDatasetCategories = datasetInstanceFromRepo.Dataset.DatasetCategories .SelectMany(dc => dc.DatasetCategoryElements).OrderBy(dc => dc.FieldOrder) .GroupBy(dce => dce.DatasetCategory) .ToList(); mappedEncounter.DatasetCategories = groupedDatasetCategories .Select(dsc => new DatasetCategoryViewDto { DatasetCategoryId = dsc.Key.Id, DatasetCategoryName = dsc.Key.DatasetCategoryName, DatasetCategoryDisplayed = ShouldCategoryBeDisplayed(encounterFromRepo, dsc.Key), DatasetElements = dsc.Select(element => new DatasetElementViewDto { DatasetElementId = element.DatasetElement.Id, DatasetElementName = element.DatasetElement.ElementName, DatasetElementDisplayName = element.FriendlyName ?? element.DatasetElement.ElementName, DatasetElementHelp = element.Help, DatasetElementDisplayed = ShouldElementBeDisplayed(encounterFromRepo, element), DatasetElementChronic = IsElementChronic(encounterFromRepo, element), DatasetElementSystem = element.DatasetElement.System, DatasetElementType = element.DatasetElement.Field.FieldType.Description, DatasetElementValue = datasetInstanceFromRepo.GetInstanceValue(element.DatasetElement.ElementName), StringMaxLength = element.DatasetElement.Field.MaxLength, NumericMinValue = element.DatasetElement.Field.MinSize, NumericMaxValue = element.DatasetElement.Field.MaxSize, Required = element.DatasetElement.Field.Mandatory, SelectionDataItems = element.DatasetElement.Field.FieldValues.Select(fv => new SelectionDataItemDto() { SelectionKey = fv.Value, Value = fv.Value }).ToList(), DatasetElementSubs = element.DatasetElement.DatasetElementSubs.Select(elementSub => new DatasetElementSubViewDto { DatasetElementSubId = elementSub.Id, DatasetElementSubName = elementSub.ElementName, DatasetElementSubType = elementSub.Field.FieldType.Description }).ToArray() }) .ToArray() }) .ToArray(); } // patient custom mapping IExtendable patientExtended = encounterFromRepo.Patient; var attribute = patientExtended.GetAttributeValue("Medical Record Number"); mappedEncounter.Patient.MedicalRecordNumber = attribute != null?attribute.ToString() : ""; }
private void MapValuesUsingEvent(DatasetCategoryElement dce, string tag, PatientClinicalEvent clinicalEvent) { IExtendable ptExtended = clinicalEvent.Patient; IExtendable ceExtended = clinicalEvent; if (dce.DestinationMappings.Where(dm => dm.Tag == tag).Count() > 0) { // Get the value to be translated var mapping = dce.DestinationMappings.Single(dm => dm.Tag == tag); string sourceValue = string.Empty; object objectValue; if (mapping.MappingType == MappingType.AttributeToElement || mapping.MappingType == MappingType.AttributeToValue) { if (!String.IsNullOrWhiteSpace(mapping.PropertyPath) && !String.IsNullOrWhiteSpace(mapping.Property)) { switch (mapping.PropertyPath) { case "Patient": objectValue = ptExtended.GetAttributeValue(mapping.Property); sourceValue = objectValue != null?objectValue.ToString() : ""; break; case "PatientClinicalEvent": objectValue = ceExtended.GetAttributeValue(mapping.Property); sourceValue = objectValue != null?objectValue.ToString() : ""; break; default: break; } } else { if (!String.IsNullOrWhiteSpace(mapping.Property)) { objectValue = ceExtended.GetAttributeValue(mapping.Property); sourceValue = objectValue != null?objectValue.ToString() : ""; } } } else { Object src = clinicalEvent; if (mapping.MappingType == MappingType.FirstClassToElement || mapping.MappingType == MappingType.FirstClassToValue) { if (!String.IsNullOrWhiteSpace(mapping.PropertyPath)) { switch (mapping.PropertyPath) { case "Patient": src = clinicalEvent.Patient; break; default: break; } } objectValue = src.GetType().GetProperty(mapping.Property).GetValue(src, null); sourceValue = objectValue != null?objectValue.ToString() : ""; } } // Translate the value if (!String.IsNullOrWhiteSpace(sourceValue)) { var formattedValue = TranslateSourceValueForElement(mapping, sourceValue); if (!String.IsNullOrWhiteSpace(formattedValue)) { SetInstanceValue(dce.DatasetElement, formattedValue); } } } }
protected void btnSubmit_Click(object sender, EventArgs e) { TableRow row; TableCell cell; string action; //string facility = Request.QueryString["facility"]; //string uid = Request.QueryString["uid"]; //string fname = Request.QueryString["fname"]; //string sname = Request.QueryString["sname"]; string facility = ddlFacility.Text; int facilityId; int.TryParse(ddlFacility.SelectedValue, out facilityId); string uid = txtUniqueID.Value; string fname = txtFirstName.Value.Trim(); string sname = txtSurname.Value.Trim(); string dob = txtDateBirth.Value.Trim(); // Get custom attribute search value string custom = ""; string path = ""; var id = Convert.ToInt32(ddlCustomAttribute.SelectedValue); if (id > 0) { DropDownList ddl; TextBox txt; var con = UnitOfWork.Repository <CustomAttributeConfiguration>().Queryable().SingleOrDefault(c => c.Id == id); switch (con.CustomAttributeType) { case CustomAttributeType.String: txt = (TextBox)spnCustomValue.Controls[0].Controls[0]; custom = txt.Text; path = @"CustomStringAttribute"; break; case CustomAttributeType.DateTime: txt = (TextBox)spnCustomValue.Controls[0].Controls[0]; custom = txt.Text; path = @"CustomStringAttribute"; break; case CustomAttributeType.Numeric: txt = (TextBox)spnCustomValue.Controls[0].Controls[0]; custom = txt.Text; path = @"CustomStringAttribute"; break; case CustomAttributeType.Selection: ddl = (DropDownList)spnCustomValue.Controls[0].Controls[0]; custom = ddl.SelectedValue; path = @"CustomSelectionAttribute"; break; } } ; bool err = false; DateTime dttemp; divError.Visible = false; spnNoRows.Visible = false; spnRows.Visible = false; lblUniqueID.Attributes.Remove("class"); lblUniqueID.Attributes.Add("class", "input"); lblFirstName.Attributes.Remove("class"); lblFirstName.Attributes.Add("class", "input"); lblSurname.Attributes.Remove("class"); lblSurname.Attributes.Add("class", "input"); lblFacility.Attributes.Remove("class"); lblFacility.Attributes.Add("class", "input"); lblDOB.Attributes.Remove("class"); lblDOB.Attributes.Add("class", "input"); // Validation int temp; if (uid != "" && !int.TryParse(uid, out temp)) { lblUniqueID.Attributes.Remove("class"); lblUniqueID.Attributes.Add("class", "input state-error"); var errorMessageDiv = new HtmlGenericControl("div"); errorMessageDiv.Attributes.Add("class", "note note-error"); errorMessageDiv.InnerText = "Unique ID must be numeric"; lblUniqueID.Controls.Add(errorMessageDiv); err = true; } if (!String.IsNullOrWhiteSpace(fname)) { if (Regex.Matches(fname, @"[a-zA-Z']").Count < fname.Length) { lblFirstName.Attributes.Remove("class"); lblFirstName.Attributes.Add("class", "input state-error"); var errorMessageDiv = new HtmlGenericControl("div"); errorMessageDiv.Attributes.Add("class", "note note-error"); errorMessageDiv.InnerText = "First Name contains invalid characters (Enter A-Z, a-z)"; lblFirstName.Controls.Add(errorMessageDiv); err = true; } } if (!String.IsNullOrWhiteSpace(sname)) { if (Regex.Matches(sname, @"[a-zA-Z]").Count < sname.Length) { lblSurname.Attributes.Remove("class"); lblSurname.Attributes.Add("class", "input state-error"); var errorMessageDiv = new HtmlGenericControl("div"); errorMessageDiv.Attributes.Add("class", "note note-error"); errorMessageDiv.InnerText = "Last Name contains invalid characters (Enter A-Z, a-z)"; lblSurname.Controls.Add(errorMessageDiv); err = true; } } if (!String.IsNullOrWhiteSpace(dob)) { if (DateTime.TryParse(dob, out dttemp)) { dttemp = Convert.ToDateTime(dob); if (dttemp > DateTime.Today) { lblDOB.Attributes.Remove("class"); lblDOB.Attributes.Add("class", "input state-error"); var errorMessageDiv = new HtmlGenericControl("div"); errorMessageDiv.Attributes.Add("class", "note note-error"); errorMessageDiv.InnerText = "Date of Birth should be before current date"; lblDOB.Controls.Add(errorMessageDiv); err = true; } if (dttemp < DateTime.Today.AddYears(-120)) { lblDOB.Attributes.Remove("class"); lblDOB.Attributes.Add("class", "input state-error"); var errorMessageDiv = new HtmlGenericControl("div"); errorMessageDiv.Attributes.Add("class", "note note-error"); errorMessageDiv.InnerText = "Date of Birth cannot be so far in the past"; lblDOB.Controls.Add(errorMessageDiv); err = true; } } else { lblDOB.Attributes.Remove("class"); lblDOB.Attributes.Add("class", "input state-error"); var errorMessageDiv = new HtmlGenericControl("div"); errorMessageDiv.Attributes.Add("class", "note note-error"); errorMessageDiv.InnerText = "Date of Birth has an invalid date format"; lblDOB.Controls.Add(errorMessageDiv); err = true; } } if (err) { divError.Visible = true; return; } ; var patientQuery = UnitOfWork.Repository <Patient>().Queryable().Where(x => !x.Archived); if (!String.IsNullOrWhiteSpace(facility)) { if (facility != "All Facilities") { patientQuery = patientQuery.Where(pf => pf.PatientFacilities.OrderByDescending(pf1 => pf1.EnrolledDate).Take(1).Any(f => f.Facility.Id == facilityId)); } } if (!String.IsNullOrWhiteSpace(uid)) { var tid = Convert.ToInt32(uid); patientQuery = patientQuery.Where(p => p.Id == tid); } if (!String.IsNullOrWhiteSpace(fname)) { if (fname.Length < 3) { patientQuery = patientQuery.Where(p => p.FirstName.StartsWith(fname.Trim())); } else { patientQuery = patientQuery.Where(p => p.FirstName.Contains(fname.Trim())); } } if (!String.IsNullOrWhiteSpace(sname)) { if (sname.Length < 3) { patientQuery = patientQuery.Where(p => p.Surname.StartsWith(sname.Trim())); } else { patientQuery = patientQuery.Where(p => p.Surname.Contains(sname.Trim())); } } if (!String.IsNullOrWhiteSpace(dob)) { dttemp = Convert.ToDateTime(dob); patientQuery = patientQuery.Where(p => p.DateOfBirth == dttemp); } IEnumerable <Patient> patients = patientQuery.ToList(); // XML query on the custom attribute if (!String.IsNullOrWhiteSpace(custom)) { patients = patients.Where(p => XElement.Parse(p.CustomAttributesXmlSerialised).Descendants(path).Descendants("Value").First().Value == custom); } // Loop through and render table DateTime?lastEncounter = null; var rowCount = 0; foreach (var p in patients) { var href = "PatientView.aspx?pid=" + p.Id.ToString(); row = new TableRow(); cell = new TableCell(); cell.Text = p.Id.ToString(); row.Cells.Add(cell); cell = new TableCell(); cell.Text = p.FirstName; row.Cells.Add(cell); cell = new TableCell(); cell.Text = p.Surname; row.Cells.Add(cell); cell = new TableCell(); var patientFacility = p.GetCurrentFacility(); cell.Text = patientFacility != null ? patientFacility.Facility.FacilityName : ""; row.Cells.Add(cell); IExtendable pExtended = null; pExtended = p; var attribute = pExtended.GetAttributeValue("Medical Record Number"); cell = new TableCell(); cell.Text = attribute != null?attribute.ToString() : ""; row.Cells.Add(cell); cell = new TableCell(); if (p.Age < 19) { cell.Text = String.Format(@"{0} <span class=""badge bg-color-blueLight"">{1}</span>", p.DateOfBirth != null ? Convert.ToDateTime(p.DateOfBirth).ToString("yyyy-MM-dd") : "", p.Age.ToString()); } else { cell.Text = String.Format(@"{0} <span class=""badge bg-color-blueDark"">{1}</span>", Convert.ToDateTime(p.DateOfBirth).ToString("yyyy-MM-dd"), p.Age.ToString()); } row.Cells.Add(cell); lastEncounter = p.LastEncounterDate(); cell = new TableCell(); if (lastEncounter != null) { cell.Text = Convert.ToDateTime(lastEncounter).ToString("yyyy-MM-dd"); } else { cell.Text = @"<span class=""label label-warning"">No Encounters</span>"; } row.Cells.Add(cell); action = @"<div class=""btn-group""><a class=""btn btn-default"" href=""" + href + @""">View Patient</a></div><!-- /btn-group -->"; cell = new TableCell(); cell.Text = action; row.Cells.Add(cell); dt_basic.Rows.Add(row); rowCount += 1; } if (rowCount == 0) { spnNoRows.InnerText = "No matching records found..."; spnNoRows.Visible = true; spnRows.Visible = false; } else { spnRows.InnerText = rowCount.ToString() + " row(s) matching criteria found..."; spnRows.Visible = true; spnNoRows.Visible = false; } // Add button HyperLink hyp = new HyperLink() { ID = "btnAdd", NavigateUrl = "PatientView.aspx?pid=0", CssClass = "btn btn-default", Text = "Add Patient" }; spnButtons.Controls.Add(hyp); }
private async Task CustomMapAsync(Encounter encounterFromRepo, EncounterExpandedDto mappedEncounter) { if (encounterFromRepo == null) { throw new ArgumentNullException(nameof(encounterFromRepo)); } mappedEncounter.Patient = _mapper.Map <PatientDetailDto>(encounterFromRepo.Patient); var datasetInstanceFromRepo = await _datasetInstanceRepository.GetAsync(di => di.Dataset.ContextType.Id == (int)ContextTypes.Encounter && di.ContextId == mappedEncounter.Id && di.EncounterTypeWorkPlan.EncounterType.Id == encounterFromRepo.EncounterType.Id , new string[] { "Dataset.ContextType" , "EncounterTypeWorkPlan.EncounterType" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategory" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategory" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.Field.FieldType" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.Field.FieldValues" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.DatasetElementSubs" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategoryElementConditions" , "DatasetInstanceValues" }); if (datasetInstanceFromRepo != null) { var groupedDatasetCategories = datasetInstanceFromRepo.Dataset.DatasetCategories .SelectMany(dc => dc.DatasetCategoryElements).OrderBy(dc => dc.FieldOrder) .GroupBy(dce => dce.DatasetCategory) .ToList(); mappedEncounter.DatasetCategories = groupedDatasetCategories .Select(dsc => new DatasetCategoryViewDto { DatasetCategoryId = dsc.Key.Id, DatasetCategoryName = dsc.Key.DatasetCategoryName, DatasetCategoryDisplayed = ShouldCategoryBeDisplayed(encounterFromRepo, dsc.Key), DatasetElements = dsc.Select(element => new DatasetElementViewDto { DatasetElementId = element.DatasetElement.Id, DatasetElementName = element.DatasetElement.ElementName, DatasetElementDisplayName = element.FriendlyName ?? element.DatasetElement.ElementName, DatasetElementHelp = element.Help, DatasetElementDisplayed = ShouldElementBeDisplayed(encounterFromRepo, element), DatasetElementChronic = IsElementChronic(encounterFromRepo, element), DatasetElementSystem = element.DatasetElement.System, DatasetElementType = element.DatasetElement.Field.FieldType.Description, DatasetElementValue = datasetInstanceFromRepo.GetInstanceValue(element.DatasetElement.ElementName), StringMaxLength = element.DatasetElement.Field.MaxLength, NumericMinValue = element.DatasetElement.Field.MinSize, NumericMaxValue = element.DatasetElement.Field.MaxSize, Required = element.DatasetElement.Field.Mandatory, SelectionDataItems = element.DatasetElement.Field.FieldValues.Select(fv => new SelectionDataItemDto() { SelectionKey = fv.Value, Value = fv.Value }).ToList(), DatasetElementSubs = element.DatasetElement.DatasetElementSubs.Select(elementSub => new DatasetElementSubViewDto { DatasetElementSubId = elementSub.Id, DatasetElementSubName = elementSub.ElementName, DatasetElementSubType = elementSub.Field.FieldType.Description }).ToArray() }) .ToArray() }) .ToArray(); } // Condition groups int[] terms = _patientConditionRepository.List(pc => pc.Patient.Id == encounterFromRepo.Patient.Id && !pc.Archived && !pc.Patient.Archived, null, new string[] { "TerminologyMedDra" }) .Select(p => p.TerminologyMedDra.Id) .ToArray(); List <PatientConditionGroupDto> groupArray = new List <PatientConditionGroupDto>(); foreach (var conditionMeddra in _conditionMeddraRepository.List(cm => terms.Contains(cm.TerminologyMedDra.Id), null, new string[] { "Condition" }) .ToList()) { var tempCondition = conditionMeddra.GetConditionForPatient(encounterFromRepo.Patient); if (tempCondition != null) { var group = new PatientConditionGroupDto() { ConditionGroup = conditionMeddra.Condition.Description, Status = tempCondition.OutcomeDate != null ? "Case Closed" : "Case Open", PatientConditionId = tempCondition.Id, StartDate = tempCondition.OnsetDate.ToString("yyyy-MM-dd"), Detail = $"{tempCondition.TerminologyMedDra.DisplayName} started on {tempCondition.OnsetDate.ToString("yyyy-MM-dd")}" }; groupArray.Add(group); } } mappedEncounter.ConditionGroups = groupArray; // Weight history mappedEncounter.WeightSeries = _patientService.GetElementValues(encounterFromRepo.Patient.Id, "Weight (kg)", 5); // patient custom mapping IExtendable patientExtended = encounterFromRepo.Patient; var attribute = patientExtended.GetAttributeValue("Medical Record Number"); mappedEncounter.Patient.MedicalRecordNumber = attribute != null?attribute.ToString() : ""; }
private void MapPatientRelatedFields(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, out DateTime?onset, out DateTime?recovery) { IExtendable activeReportExtended = activeReport; IExtendable patientExtended = activeReport.Patient; var init = String.Format("{0}{1}", activeReport.Patient.FirstName.Substring(0, 1), activeReport.Patient.Surname.Substring(0, 1)); if (!String.IsNullOrWhiteSpace(init)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "A0BEAB3A-0B0A-457E-B190-1B66FE60CA73"), init); } ; //Patient Initial var dob = activeReport.Patient.DateOfBirth; onset = activeReport.OnsetDate; recovery = activeReport.ResolutionDate; if (dob.HasValue) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "4F71B7F4-4317-4680-B3A3-9C1C1F72AD6A"), dob.Value.ToString("yyyyMMdd")); //Patient Birthdate if (onset.HasValue) { var age = onset.Value.Year - dob.Value.Year; if (dob.Value > onset.Value.AddYears(-age)) { age--; } e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "E10C259B-DD2C-4F19-9D41-16FDDF9C5807"), age.ToString()); //Patient Onset Age e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "CA9B94C2-E1EF-407B-87C3-181224AF637A"), "801=Year"); //Patient Onset Age Unit } } var encounter = _unitOfWork.Repository <Encounter>().Queryable().OrderByDescending(e => e.EncounterDate).FirstOrDefault(e => e.Patient.Id == activeReport.Patient.Id && e.Archived == false & e.EncounterDate <= activeReport.OnsetDate); if (encounter != null) { var encounterInstance = _unitOfWork.Repository <DatasetInstance>().Queryable().SingleOrDefault(ds => ds.Dataset.DatasetName == "Chronic Treatment" && ds.ContextId == encounter.Id); if (encounterInstance != null) { var weight = encounterInstance.GetInstanceValue("Weight (kg)"); if (!String.IsNullOrWhiteSpace(weight)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "89A6E687-A220-4319-AAC1-AFBB55C81873"), weight); } ; //Patient Weight var height = encounterInstance.GetInstanceValue("Height (cm)"); if (!String.IsNullOrWhiteSpace(height)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "40DAD435-8282-4B3E-B65E-3478FF55D028"), height); } ; //Patient Height var lmp = encounterInstance.GetInstanceValue("Date of last menstrual period"); if (!String.IsNullOrWhiteSpace(lmp)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "93253F91-60D1-4161-AF1A-F3ABDD140CB9"), Convert.ToDateTime(lmp).ToString("yyyyMMdd")); } ; //Patient Last Menstrual Date var gest = encounterInstance.GetInstanceValue("Estimated gestation (weeks)"); if (!String.IsNullOrWhiteSpace(gest)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "B6BE9689-B6B2-4FCF-8918-664AFC91A4E0"), gest); //Gestation Period e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1F174413-2A1E-45BD-B5C4-0C8F5DFFBFF4"), "803=Week"); //Gestation Period Unit } ; } } var objectValue = activeReportExtended.GetAttributeValue("Weight (kg)"); var weightKg = objectValue != null?objectValue.ToString() : ""; if (!String.IsNullOrWhiteSpace(weightKg)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "89A6E687-A220-4319-AAC1-AFBB55C81873"), weightKg); } ; objectValue = activeReportExtended.GetAttributeValue("Height (cm)"); var heightCm = objectValue != null?objectValue.ToString() : ""; if (!String.IsNullOrWhiteSpace(heightCm)) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "40DAD435-8282-4B3E-B65E-3478FF55D028"), heightCm); } ; objectValue = patientExtended.GetAttributeValue("Gender"); var patientSex = objectValue != null?objectValue.ToString() : ""; if (!String.IsNullOrWhiteSpace(patientSex)) { if (patientSex == "1") { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "59498520-172C-42BC-B30C-E249F94E412A"), "1=Male"); } if (patientSex == "2") { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "59498520-172C-42BC-B30C-E249F94E412A"), "2=Female"); } } ; }
private async Task MapDrugRelatedFieldsAsync(DatasetInstance e2bInstance, PatientClinicalEvent activeReport, ReportInstance reportInstance) { string[] validNaranjoCriteria = { "Possible", "Probable", "Definite" }; string[] validWHOCriteria = { "Possible", "Probable", "Certain" }; var destinationProductElement = await _datasetElementRepository.GetAsync(de => de.DatasetElementGuid.ToString() == "E033BDE8-EDC8-43FF-A6B0-DEA6D6FA581C", new string[] { "DatasetElementSubs" }); // Medicinal Products foreach (ReportInstanceMedication med in reportInstance.Medications) { var newContext = Guid.NewGuid(); var patientMedication = await _patientMedicationRepository.GetAsync(pm => pm.PatientMedicationGuid == med.ReportInstanceMedicationGuid, new string[] { "Concept.MedicationForm" }); IExtendable mcExtended = patientMedication; var character = ""; character = (validNaranjoCriteria.Contains(med.NaranjoCausality) || validWHOCriteria.Contains(med.WhoCausality)) ? "1=Suspect" : "2=Concomitant"; e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Characterization"), character, (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Medicinal Product"), patientMedication.Concept.ConceptName, (Guid)newContext); var objectValue = mcExtended.GetAttributeValue("Batch Number"); var batchNumber = objectValue != null?objectValue.ToString() : ""; e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Batch Number"), batchNumber, (Guid)newContext); objectValue = mcExtended.GetAttributeValue("Comments"); var comments = objectValue != null?objectValue.ToString() : ""; e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Additional Information"), comments, (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Dosage Text"), patientMedication.DoseFrequency, (Guid)newContext); var form = patientMedication?.Concept?.MedicationForm?.Description; e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Dosage Form"), form, (Guid)newContext); var startdate = patientMedication.StartDate; e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Start Date"), startdate.ToString("yyyyMMdd"), (Guid)newContext); var enddate = patientMedication.EndDate; if (enddate.HasValue) { e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug End Date"), Convert.ToDateTime(enddate).ToString("yyyyMMdd"), (Guid)newContext); var rduration = (Convert.ToDateTime(enddate) - Convert.ToDateTime(startdate)).Days; e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Treatment Duration"), rduration.ToString(), (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Treatment Duration Unit"), "804=Day", (Guid)newContext); } if (int.TryParse(patientMedication.Dose, out int n)) { e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Structured Dosage"), patientMedication.Dose, (Guid)newContext); } ; var doseUnit = MapDoseUnitForActive(patientMedication.DoseUnit); if (!string.IsNullOrWhiteSpace(doseUnit)) { e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Structured Dosage Unit"), doseUnit, (Guid)newContext); } ; objectValue = mcExtended.GetAttributeValue("Clinician action taken with regard to medicine if related to AE"); var drugAction = objectValue != null?objectValue.ToString() : ""; if (!string.IsNullOrWhiteSpace(drugAction)) { drugAction = MapDrugActionForActive(drugAction); } ; if (!string.IsNullOrWhiteSpace(drugAction)) { e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Action"), drugAction, (Guid)newContext); } ; // Causality if (med.WhoCausality != null) { e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Reaction Assessment"), med.ReportInstance.TerminologyMedDra.DisplayName, (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Method of Assessment"), "WHO Causality Scale", (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Assessment Result"), med.WhoCausality.ToLowerInvariant() == "ignored" ? "" : med.WhoCausality, (Guid)newContext); } else { if (med.NaranjoCausality != null) { e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Drug Reaction Assessment"), med.ReportInstance.TerminologyMedDra.DisplayName, (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Method of Assessment"), "Naranjo Causality Scale", (Guid)newContext); e2bInstance.SetInstanceSubValue(destinationProductElement.DatasetElementSubs.Single(des => des.ElementName == "Assessment Result"), med.NaranjoCausality.ToLowerInvariant() == "ignored" ? "" : med.NaranjoCausality, (Guid)newContext); } } } // foreach (ReportInstanceMedication med in reportInstance.Medications) }
private object MapPrimarySourceRelatedFields(DatasetInstance e2bInstance, PatientClinicalEvent activeReport) { IExtendable activeReportExtended = activeReport; object objectValue = activeReportExtended.GetAttributeValue("Name of reporter"); var fullName = objectValue != null?objectValue.ToString() : ""; if (!String.IsNullOrWhiteSpace(fullName)) { if (fullName.Contains(" ")) { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "C35D5F5A-D539-4EEE-B080-FF384D5FBE08"), fullName.Substring(0, fullName.IndexOf(" "))); //Reporter Given Name e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "F214C619-EE0E-433E-8F52-83469778E418"), fullName.Substring(fullName.IndexOf(" ") + 1, fullName.Length - (fullName.IndexOf(" ") + 1))); //Reporter Family Name } else { e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "C35D5F5A-D539-4EEE-B080-FF384D5FBE08"), fullName); //Reporter Given Name } } objectValue = activeReportExtended.GetAttributeValue("Profession"); var profession = objectValue != null?objectValue.ToString() : ""; if (!String.IsNullOrWhiteSpace(profession)) { var selectionValue = _unitOfWork.Repository <SelectionDataItem>().Queryable().Single(sdi => sdi.AttributeKey == "Profession" && sdi.SelectionKey == profession).Value; switch (selectionValue.Trim()) { case "Dentist": case "RN": case "Other health professional": e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "3=Other Health Professional"); //Qualification break; case "Medical Doctor": case "Physician": e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "1=Physician"); break; case "Patient": case "Consumer or other non health professional": e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "5=Consumer or other non health professional"); break; case "RPh": case "Pharmacist": e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "2=Pharmacist"); break; case "Lawyer": e2bInstance.SetInstanceValue(_unitOfWork.Repository <DatasetElement>().Queryable().Single(dse => dse.DatasetElementGuid.ToString() == "1D59E85E-66AF-4E70-B779-6AB873DE1E84"), "4=Lawyer"); break; default: break; } } return(objectValue); }