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 async Task CustomMapAsync(PatientClinicalEvent patientClinicalEventFromRepo, PatientClinicalEventExpandedDto dto) { IExtendable patientClinicalEventExtended = patientClinicalEventFromRepo; // Map all custom attributes dto.ClinicalEventAttributes = _modelExtensionBuilder.BuildModelExtension(patientClinicalEventExtended) .Select(h => new AttributeValueDto() { Id = h.Id, Key = h.AttributeKey, Value = h.TransformValueToString(), 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(); dto.ReportDate = await _customAttributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Date of Report", patientClinicalEventExtended); dto.IsSerious = await _customAttributeService.GetCustomAttributeValueAsync("PatientClinicalEvent", "Is the adverse event serious?", patientClinicalEventExtended); var activity = await _reportInstanceQueries.GetExecutionStatusEventsForEventViewAsync(patientClinicalEventFromRepo.Id); dto.Activity = activity.ToList(); var reportInstanceFromRepo = await _reportInstanceRepository.GetAsync(ri => ri.ContextGuid == patientClinicalEventFromRepo.PatientClinicalEventGuid, new string[] { "TerminologyMedDra", "Medications", "Tasks.Comments" }); if (reportInstanceFromRepo == null) { return; } dto.SetMedDraTerm = reportInstanceFromRepo.TerminologyMedDra?.DisplayName; dto.SetClassification = ReportClassification.From(reportInstanceFromRepo.ReportClassificationId).Name; dto.Medications = _mapper.Map <ICollection <ReportInstanceMedicationDetailDto> >(reportInstanceFromRepo.Medications.Where(m => !String.IsNullOrWhiteSpace(m.WhoCausality) || (!String.IsNullOrWhiteSpace(m.NaranjoCausality)))); dto.Tasks = _mapper.Map <ICollection <TaskDto> >(reportInstanceFromRepo.Tasks.Where(t => t.TaskStatusId != Core.Aggregates.ReportInstanceAggregate.TaskStatus.Cancelled.Id)); }
private async Task CustomMedicationMapAsync(PatientMedicationDetailDto dto) { var medication = await _patientMedicationRepository.GetAsync(p => p.Id == dto.Id); if (medication == null) { return; } IExtendable medicationExtended = medication; // Map all custom attributes dto.MedicationAttributes = _modelExtensionBuilder.BuildModelExtension(medicationExtended) .Select(h => new AttributeValueDto() { Id = h.Id, Key = h.AttributeKey, Value = h.TransformValueToString(), 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(); dto.IndicationType = await _customAttributeService.GetCustomAttributeValueAsync("PatientMedication", "Type of Indication", medicationExtended); dto.ReasonForStopping = await _customAttributeService.GetCustomAttributeValueAsync("PatientMedication", "Reason For Stopping", medicationExtended); dto.ClinicianAction = await _customAttributeService.GetCustomAttributeValueAsync("PatientMedication", "Clinician action taken with regard to medicine if related to AE", medicationExtended); dto.ChallengeEffect = await _customAttributeService.GetCustomAttributeValueAsync("PatientMedication", "Effect OF Dechallenge (D) & Rechallenge (R)", medicationExtended); }
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); } }
/// <summary> /// 从特定的参数存储器中拷贝所有自定义参数 /// </summary> /// <param name="a"></param> /// <param name="target"></param> public static void CopyExtendedProperties(this IExtendable a, IExtendable target) { foreach (var kv in target.GetExtendedProperties()) { a[kv.Key] = kv.Value; } }
public Dialog_Rename(IExtendable iExtendable) { _iExtendable = iExtendable; _curName = iExtendable.Name; closeOnEscapeKey = true; absorbInputAroundWindow = true; }
public static T GetValue <T>(this IExtendable extendable, string name, JsonSerializer jsonSerializer) { if (extendable == null) { throw new ArgumentNullException(nameof(extendable)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Value cannot be null, empty, or consists only of white-space.", nameof(name)); } if (extendable.ExtensionData == null) { return(default(T)); } var json = JObject.Parse(extendable.ExtensionData); var prop = json[name]; if (prop == null) { return(default(T)); } if (TypeHelper.IsPrimitiveExtendedIncludingNullable(typeof(T))) { return(prop.Value <T>()); } else { return((T)prop.ToObject(typeof(T), jsonSerializer ?? JsonSerializer.CreateDefault())); } }
/// <summary> /// Updates the extendable object with values from the custom attribute collection. /// </summary> /// <param name="extendableToUpdate">The extendable to update.</param> /// <param name="customAttributeDetails">The custom attribute details.</param> /// <returns>The updated Extendable object</returns> /// <exception cref="CustomAttributeException">Unknown AttributeType for AttributeKey: {0}</exception> public IExtendable UpdateExtendable(IExtendable extendableToUpdate, IEnumerable <CustomAttributeDetail> customAttributeDetails, string updatedByUser) { if (customAttributeDetails == null || !customAttributeDetails.Any()) { return(extendableToUpdate); } foreach (var customAttribute in customAttributeDetails) { switch (customAttribute.Type) { case CustomAttributeType.Numeric: extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, (decimal)ExtractValue(customAttribute), updatedByUser); break; case CustomAttributeType.String: extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, ExtractValue(customAttribute).ToString(), updatedByUser); break; case CustomAttributeType.Selection: extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, (Int32)ExtractValue(customAttribute), updatedByUser); break; case CustomAttributeType.DateTime: extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, Convert.ToDateTime(ExtractValue(customAttribute)), updatedByUser); break; default: throw new CustomAttributeException("Unknown AttributeType for AttributeKey: {0}", customAttribute.AttributeKey); } } return(extendableToUpdate); }
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() : ""; }
/// <summary> /// Extension method to get fhir generic type extension /// </summary> /// <param name="resource"></param> public static IEnumerable <ElementDefinition> GetGenericTypes(this IExtendable resource) { foreach (Extension ext in resource.GetExtensions(GenericExtensionUri)) { yield return((ElementDefinition)ext.Value); } }
public static void AddGenericType(this IExtendable resource, String genericParamPath, String genericParamTypeUri) { if (resource is null) { throw new ArgumentNullException(nameof(resource)); } if (genericParamPath is null) { throw new ArgumentNullException(nameof(genericParamPath)); } if (genericParamTypeUri is null) { throw new ArgumentNullException(nameof(genericParamTypeUri)); } // Make sure that generic name is a.b.c:d String[] parts = genericParamPath.Split('.'); String[] subParts = parts[parts.Length - 1].Split(':'); Debug.Assert(subParts.Length == 2); ElementDefinition genericElement = new ElementDefinition() { ElementId = genericParamPath, Path = genericParamPath }; //$genericElement.Type.Add(new ElementDefinition.TypeRefComponent { Code = genericParamTypeUri }); resource.AddExtension(GenericExtensionUri, genericElement); }
public static void PopulateProperties(this IMessage message, IExtendable extendable) { if (extendable.MessageProperties == null || !extendable.MessageProperties.Any()) { return; } Guid correlationId; object correlationIdRaw; extendable.MessageProperties.TryGetValue(MessagePropertyKeys.CorrelationId, out correlationIdRaw); Guid.TryParse((string)correlationIdRaw, out correlationId); message.CorrelationId = correlationId; message.ExtendedProperties = message.ExtendedProperties ?? new Dictionary<string, object>(); foreach (var prop in extendable.MessageProperties) { if (prop.Key.Equals(MessagePropertyKeys.CorrelationId)) { continue; } if (!message.ExtendedProperties.ContainsKey(prop.Key)) { message.ExtendedProperties.Add(prop); } } }
/// <summary>Removes the <see cref="CHANGED_BY_DIFF_EXT"/> extension from the specified element.</summary> /// <param name="element">An <see cref="IExtendable"/> instance.</param> public static void RemoveChangedByDiff(this IExtendable element) { if (element == null) { throw Error.ArgumentNull(nameof(element)); } element.RemoveExtension(CHANGED_BY_DIFF_EXT); }
/// <summary> /// Decorate the specified snapshot element definition with a special extension /// to indicate that the element is constrained by the differential. /// </summary> /// <param name="element">An <see cref="IExtendable"/> instance.</param> /// <param name="value">An optional boolean value (default <c>true</c>).</param> /// <remarks>Sets the <see cref="CONSTRAINED_BY_DIFF_EXT"/> extension to store the boolean flag.</remarks> internal static void SetConstrainedByDiffExtension(this IExtendable element, bool value = true) { if (element == null) { throw Error.ArgumentNull(nameof(element)); } element.SetBoolExtension(CONSTRAINED_BY_DIFF_EXT, value); }
/// <summary>Removes the <see cref="CONSTRAINED_BY_DIFF_EXT"/> extension from the specified element definition.</summary> public static void RemoveConstrainedByDiffExtension(this IExtendable element) { if (element == null) { throw Error.ArgumentNull(nameof(element)); } element.RemoveExtension(CONSTRAINED_BY_DIFF_EXT); }
/// <summary>Mark the snapshot element as changed by the differential.</summary> /// <param name="element">An <see cref="IExtendable"/> instance.</param> /// <param name="value">An optional boolean value (default <c>true</c>).</param> /// <remarks>Sets the <see cref="CHANGED_BY_DIFF_EXT"/> extension to store the boolean flag.</remarks> public static void SetChangedByDiff(this IExtendable element, bool value = true) { if (element == null) { throw Error.ArgumentNull(nameof(element)); } element.SetBoolExtension(CHANGED_BY_DIFF_EXT, value); }
/// <summary> /// Return the first extension with the given uri /// </summary> /// <param name="extendable"></param> /// <param name="uri"></param> /// <returns>The first uri, or null if no extension with the given uri was found.</returns> public static Extension GetExtension(this IExtendable extendable, Uri uri) { if (extendable.Extension != null) { return(GetExtensions(extendable, uri).FirstOrDefault()); } return(null); }
/// <summary> /// Find all extensions with the given uri. /// </summary> /// <param name="extendable"></param> /// <param name="uri"></param> /// <returns>The list of extensions with a matching uri, or empty list if none were found.</returns> public static IEnumerable <Extension> GetExtensions(this IExtendable extendable, string uri) { if (extendable.Extension != null) { return(extendable.Extension.Where(ext => ext.Url == uri)); } return(null); }
/// <summary> /// Remove all extensions with the current uri, if any. /// </summary> /// <param name="extendable"></param> /// <param name="uri"></param> public static void RemoveExtension(this IExtendable extendable, Uri uri) { if (extendable.Extension == null) { return; } extendable.Extension.RemoveAll(ext => ext.Url != null && ext.Url.ToString() == uri.ToString()); }
/// <summary> /// Find all extensions with the given uri. /// </summary> /// <param name="extendable"></param> /// <param name="uri"></param> /// <returns>The list of extensions with a matching uri, or empty list if none were found.</returns> public static IEnumerable <Extension> GetExtensions(this IExtendable extendable, Uri uri) { if (extendable.Extension != null) { return(extendable.Extension .Where(ext => ext.Url != null && ext.Url.ToString() == uri.ToString())); } return(null); }
public void WhenHealthvaultThingIsTransformedtoFhirDomainResource_ThenStateIsStoredInExtension() { var activeState = ThingState.Active; ThingBase thing = new Height(34.5); //By default thingstate is active. Use xml deserializer to create deleted thing IExtendable extendable = thing.ToFhir() as IExtendable; Assert.IsTrue(extendable.HasExtensions()); Assert.AreEqual(activeState.ToString(), extendable.GetStringExtension(HealthVaultExtensions.StateFhirExtensionName)); }
static async Task <TransportOperation[]> InvokeMessageHandler(IExtendable context, Func <Task> next) { var pendingOperations = new PendingTransportOperations(); context.Extensions.Set(pendingOperations); await next(); return(pendingOperations.Operations); }
private async Task PrepareMedicationsForActiveReportAsync(ReportInstance reportInstance) { var i = 0; foreach (ReportInstanceMedication reportMedication in reportInstance.Medications) { var patientMedication = await _patientMedicationRepository.GetAsync(pm => pm.PatientMedicationGuid == reportMedication.ReportInstanceMedicationGuid); if (patientMedication != null) { i += 1; List <string[]> rows = new(); List <string> cells = new(); cells.Add("Drug"); cells.Add("Start Date (yyyy-mm-dd)"); cells.Add("End Date (yyyy-mm-dd)"); cells.Add("Dose"); cells.Add("Route"); cells.Add("Causality"); rows.Add(cells.ToArray()); cells = new(); IExtendable extendable = patientMedication; cells.Add(patientMedication.DisplayName); cells.Add(patientMedication.StartDate.ToString("yyyy-MM-dd")); cells.Add(patientMedication.EndDate.HasValue ? patientMedication.EndDate.Value.ToString("yyyy-MM-dd") : ""); cells.Add($"{patientMedication.Dose} {patientMedication.DoseUnit}"); cells.Add(await _attributeService.GetCustomAttributeValueAsync("PatientMedication", "Route", extendable)); cells.Add($"{reportMedication.WhoCausality} {reportMedication.NaranjoCausality}"); rows.Add(cells.ToArray()); _wordDocumentService.AddRowTable(rows, new int[] { 2500, 1250, 1250, 1250, 1250, 3852 }); _wordDocumentService.AddTableHeader("D.1 CLINICIAN ACTION TAKEN WITH REGARD TO MEDICINE"); _wordDocumentService.AddOneColumnTable(new List <string>() { "" }); _wordDocumentService.AddTableHeader("D.2 EFFECT OF DECHALLENGE/RECHALLENGE"); _wordDocumentService.AddOneColumnTable(new List <string>() { "" }); _wordDocumentService.AddTableHeader("D.3 NOTES"); _wordDocumentService.AddOneColumnTable(new List <string>() { "" }); } } }
public static void PrintInstanceWithRunSpecificIfPossible(this IExtendable context, string instance, TextWriter writer) { if (context.Extensions.TryGet(RunSpecificKey, out int runSpecific)) { writer.WriteLine($"{instance}: {runSpecific}"); } else { writer.WriteLine(instance); } }
/// <summary> /// Return the first extension with the given uri as a string, or null if none was found /// </summary> /// <param name="extendable"></param> /// <param name="uri"></param> /// <returns>The first uri, or null if no extension with the given uri was found.</returns> public static string GetStringExtension(this IExtendable extendable, string uri) { var ext = extendable.GetExtension(uri); if (ext != null && ext.Value != null && ext.Value is FhirString) { return(((FhirString)ext.Value).Value); } return(null); }
public static bool?GetBoolExtension(this IExtendable extendable, string uri) { var ext = extendable.GetExtension(uri); if (ext != null && ext.Value != null && ext.Value is FhirBoolean) { return(((FhirBoolean)ext.Value).Value); } return(null); }
public static T GetExtensionValue <T>(this IExtendable extendable, string uri) where T : Element { var ext = extendable.GetExtension(uri); if (ext != null && ext.Value != null && ext.Value is T) { return((T)ext.Value); } return(null); }
/// <summary> /// Add an extension with the given uri and value, removing any pre-existsing extensions /// with the same uri. /// </summary> /// <param name="extendable"></param> /// <param name="uri"></param> /// <param name="value"></param> /// <param name="isModifier"></param> /// <returns>The newly added extension</returns> public static Extension SetExtension(this IExtendable extendable, string uri, Element value, bool isModifier = false) { if (extendable.Extension == null) { extendable.Extension = new List <Extension>(); } RemoveExtension(extendable, uri); return(AddExtension(extendable, uri, value, isModifier)); }
public static IEnumerable <Extension> AllExtensions(this IExtendable extendable) { if (extendable is IModifierExtendable) { return(((IModifierExtendable)extendable).ModifierExtension.Concat(extendable.Extension)); } else { return(extendable.Extension); } }
public static T GetValue <T>(this IExtendable extendable, string name, bool handleType = false) { return(extendable.GetValue <T>( name, handleType ? new JsonSerializer { TypeNameHandling = TypeNameHandling.All } : JsonSerializer.CreateDefault() )); }