public static Quantity ToUnitsOfMeasureQuantity(this FM.Quantity input) { Metric metric = (input.Code != null) ? System.Metric(input.Code) : new Metric(new List <Metric.Axis>()); Exponential value = input.Value ?? 1; //todo: is this assumption correct? return(new Quantity(value, metric)); }
public static Expression NonUcumIndexedExpression(this FM.Quantity quantity) { var values = new List <ValueExpression>(); if (quantity.System != null) { values.Add(new IndexValue("system", new StringValue(quantity.System))); } if (quantity.Unit != null) { values.Add(new IndexValue("unit", new StringValue(quantity.Unit))); } if (quantity.Value.HasValue) { values.Add(new IndexValue("value", new NumberValue(quantity.Value.Value))); } if (values.Any()) { return(new CompositeValue(values)); } return(null); }
public void RenderRatio() { var n = new Quantity() { Value = 5.0m, Units = "$" }; var d = new Quantity() { Value = 1m, Units = "wk" }; var r = new Ratio() { Numerator = n, Denominator = d }; Assert.AreEqual("5.0$ : 1wk",r.ForDisplay()); }
// This code might have a better place somewhere else: //mh public static FM.Quantity ToModelQuantity(this ValueExpression expression) { var q = QuantityValue.Parse(expression.ToString()); var quantity = new FM.Quantity { Value = q.Number, System = q.Namespace, Unit = q.Unit, Code = q.Unit }; return(quantity); }
public static FM.Quantity ToFhirModelQuantity(this Quantity input) { FM.Quantity output = new FM.Quantity(); output.Value = (decimal)input.Value; output.Code = input.Metric.ToString(); output.Unit = output.Code; output.System = UCUM.Uri.ToString(); return(output); }
public static bool IsUcum(this FM.Quantity quantity) { if (quantity.System == null) { return(false); } return(UcumUri.IsBaseOf(new Uri(quantity.System))); }
public static FM.Quantity ToFhirModelQuantity(this Quantity input) { FM.Quantity output = new FM.Quantity(); output.Value = (decimal)input.Value; output.Code = input.Metric.ToString(); output.Unit = output.Code; output.System = UCUM.Uri.ToString(); return output; }
public static BsonDocument ToBson(this FM.Quantity quantity) { if (quantity.IsUcum()) { var q = quantity.ToUnitsOfMeasureQuantity(); return(ToBson(q)); } return(quantity.NonUcumIndexed()); }
public static Expression ToExpression(this FM.Quantity quantity) { if (quantity.IsUcum()) { var q = quantity.ToUnitsOfMeasureQuantity(); return(q.ToExpression()); } return(quantity.NonUcumIndexedExpression()); }
/// <summary> /// Height Observation Generation /// </summary> /// <returns></returns> private HL7.Quantity GenerateHeightValues() { HL7.Quantity valueQuantity = new HL7.Quantity(); valueQuantity.Value = (decimal)(70.0 * rand.NextDouble() + 110.0); valueQuantity.Unit = "cm"; valueQuantity.System = "http://unitsofmeasure.org"; valueQuantity.Code = "cm"; return(valueQuantity); }
/// <summary> /// Hemoglobin Observation Generation /// </summary> /// <returns></returns> private HL7.Quantity GenerateHemoValues() { HL7.Quantity valueQuantity = new HL7.Quantity(); valueQuantity.Value = (decimal)(10 * rand.NextDouble() + 6); valueQuantity.Unit = "mg/dL"; valueQuantity.System = "http://unitsofmeasure.org"; valueQuantity.Code = "mg/dL"; return(valueQuantity); }
public static void setValue(this Model.Quantity me, double?value) { if (value.HasValue) { me.Value = (decimal)value.Value; } else { me.Value = null; } }
private List <Expression> ToExpressions(FhirModel.Quantity element) { try { return(element != null?ListOf(element.ToExpression()) : null); } catch (ArgumentException ex) { _log.InvalidElement("unknown", String.Format("Quantity: {0} {1} {2}", element.Code, element.Unit, element.Value), ex.Message); } return(null); }
// This code might have a better place somewhere else: //mh public static FM.Quantity ToModelQuantity(this ValueExpression expression) { QuantityValue q = QuantityValue.Parse(expression.ToString()); FM.Quantity quantity = new FM.Quantity { Value = q.Number, System = q.Namespace, Unit = q.Unit, Code = q.Unit }; return quantity; }
public static BsonDocument Indexed(this Model.Quantity quantity) { if (quantity.IsUcum()) { Quantity q = quantity.ToSystemQuantity(); return(q.Indexed()); } else { return(quantity.NonUcumIndexed()); } }
public static BsonDocument ToBson(this Model.Quantity quantity) { if (quantity.IsUcum()) { Quantity q = quantity.ToUnitsOfMeasureQuantity(); return(q.ToBson()); } else { return(quantity.NonUcumIndexed()); } }
public static BsonDocument NonUcumIndexed(this Model.Quantity quantity) { string system = (quantity.System != null) ? quantity.System.ToString() : null; BsonDocument block = new BsonDocument { { "system", system }, { "value", quantity.GetValueAsBson() }, { "unit", quantity.Code } }; return(block); }
public void SliceSize(ElementTreeSlice slice, ValueSet units) { // Fix component code ElementTreeNode valueXNode = this.SliceValueXByType(slice, new string[] { "Quantity", "Range" }); { Hl7.Fhir.Model.Quantity q = new Hl7.Fhir.Model.Quantity { System = units.Url }; ElementDefinition valueX = new ElementDefinition { Path = $"{slice.ElementDefinition.Path}.value[x]", ElementId = $"{slice.ElementDefinition.ElementId}.value[x]:valueQuantity", SliceName = $"valueQuantity", Min = 0, Max = "1" } .Pattern(q) .Type("Quantity") ; valueXNode.CreateSlice($"valueQuantity", valueX); } { Hl7.Fhir.Model.Range r = new Hl7.Fhir.Model.Range { Low = new SimpleQuantity { System = units.Url, }, High = new SimpleQuantity { System = units.Url, } }; ElementDefinition valueX = new ElementDefinition { Path = $"{slice.ElementDefinition.Path}.value[x]", ElementId = $"{slice.ElementDefinition.ElementId}.value[x]:valueRange", SliceName = $"valueRange", Min = 0, Max = "1" } .Pattern(r) .Type("Range") ; valueXNode.CreateSlice($"valueRange", valueX); } }
public static Model.Quantity Canonical(this Model.Quantity input) { if (IsUcum(input)) { Quantity quantity = input.ToSystemQuantity(); quantity = system.Canonical(quantity); return(quantity.ToModelQuantity()); } else { return(input); } }
public static FM.Quantity Canonical(this FM.Quantity input) { if (IsUcum(input)) { Quantity quantity = input.ToUnitsOfMeasureQuantity(); quantity = System.Canonical(quantity); return(quantity.ToFhirModelQuantity()); } else { return(input); } }
public static BsonDocument NonUcumIndexed(this FM.Quantity quantity) { var system = quantity.System != null ? (BsonValue)quantity.System : BsonNull.Value; var code = quantity.Code != null ? (BsonValue)quantity.Code : BsonNull.Value; var block = new BsonDocument { { "system", system }, { "value", quantity.GetValueAsBson() }, { "unit", (BsonValue)quantity.Code ?? BsonNull.Value } }; return(block); }
public void RenderQuantity() { var q = new Quantity(); q.Value = 4.5m; q.Code = "kg"; q.System = "http://unitsofmeasure.org"; Assert.AreEqual("4.5kg", q.ForDisplay()); q.Units = "kilo"; Assert.AreEqual("4.5 kilo", q.ForDisplay()); q.Comparator = Quantity.QuantityCompararator.LessOrEqual; Assert.AreEqual("<=4.5 kilo", q.ForDisplay()); }
public static Quantity Standardize(this Quantity quantity) { Quantity result = new Quantity(); // Example code if (quantity.Units == "mg") { result.Units = "g"; result.System = quantity.System; result.Value = quantity.Value / 1000; } else { result.Units = quantity.Units; result.System = quantity.System; result.Value = quantity.Value; } return result; }
public static void setUnit(this Model.Quantity me, string value) { me.Unit = value; }
public static void setCode(this Model.Quantity me, string value) { me.Code = value; }
// DSTU2: tags //public void Collect(Tag tag) //{ // string scheme = Assigned(tag.Scheme) ? tag.Scheme.ToString() : null; // string term = tag.Term; // string label = tag.Label; // //string tagstring = glue("/", scheme, term); // BsonDocument value = new BsonDocument() // { // { "scheme", scheme }, // { "term", term }, // { "label", label } // }; // Write(InternalField.TAG, value); //} public void Write(Definition definition, Quantity quantity) { switch (definition.ParamType) { case Conformance.SearchParamType.Quantity: { BsonDocument block = quantity.ToBson(); document.Write(definition.ParamName, block); break; } case Conformance.SearchParamType.Date: { break; } default: return; } }
public void RenderRange() { var n = new Quantity() { Value = 5.0m, Units = "cm" }; var r = new Range { Low = n }; Assert.AreEqual("[5.0cm,∞]", r.ForDisplay()); }
// This code might have a better place somewhere else: //mh private static Quantity ToQuantity(this ValueExpression expression) { QuantityValue q = QuantityValue.Parse(expression.ToString()); Quantity quantity = new Quantity { Value = q.Number, System = (q.Namespace != null) ? new Uri(q.Namespace) : null, Units = q.Unit }; return quantity; }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as SupplyRequest; if (dest == null) { throw new ArgumentException("Can only copy to an object of the same type", "other"); } base.CopyTo(dest); if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.SupplyRequest.SupplyRequestStatus>)StatusElement.DeepCopy(); } if (Category != null) { dest.Category = (Hl7.Fhir.Model.CodeableConcept)Category.DeepCopy(); } if (PriorityElement != null) { dest.PriorityElement = (Code <Hl7.Fhir.Model.RequestPriority>)PriorityElement.DeepCopy(); } if (Item != null) { dest.Item = (Hl7.Fhir.Model.CodeableReference)Item.DeepCopy(); } if (Quantity != null) { dest.Quantity = (Hl7.Fhir.Model.Quantity)Quantity.DeepCopy(); } if (Parameter != null) { dest.Parameter = new List <Hl7.Fhir.Model.SupplyRequest.ParameterComponent>(Parameter.DeepCopy()); } if (Occurrence != null) { dest.Occurrence = (Hl7.Fhir.Model.DataType)Occurrence.DeepCopy(); } if (AuthoredOnElement != null) { dest.AuthoredOnElement = (Hl7.Fhir.Model.FhirDateTime)AuthoredOnElement.DeepCopy(); } if (Requester != null) { dest.Requester = (Hl7.Fhir.Model.ResourceReference)Requester.DeepCopy(); } if (Supplier != null) { dest.Supplier = new List <Hl7.Fhir.Model.ResourceReference>(Supplier.DeepCopy()); } if (Reason != null) { dest.Reason = new List <Hl7.Fhir.Model.CodeableReference>(Reason.DeepCopy()); } if (DeliverFrom != null) { dest.DeliverFrom = (Hl7.Fhir.Model.ResourceReference)DeliverFrom.DeepCopy(); } if (DeliverTo != null) { dest.DeliverTo = (Hl7.Fhir.Model.ResourceReference)DeliverTo.DeepCopy(); } return(dest); }
public void QuantityValueSystemCodeMapTest() { var input = new Quantity(); input.Value = 10; input.System = "http://unitsofmeasure.org/"; input.Code = "kg"; var result = sut.Map(input); CheckQuantity(result, value: 10000, unit: "g", system: "http://unitsofmeasure.org/", decimals: "gE4x1.0"); }
public static void SerializeQuantity(Hl7.Fhir.Model.Quantity value, IFhirWriter writer, bool summary) { writer.WriteStartComplexContent(); // Serialize element _id if (value.LocalIdElement != null) { writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute); } // Serialize element extension if (value.Extension != null && !summary && value.Extension.Count > 0) { writer.WriteStartArrayElement("extension"); foreach (var item in value.Extension) { writer.WriteStartArrayMember("extension"); ExtensionSerializer.SerializeExtension(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element value if (value.ValueElement != null) { writer.WriteStartElement("value"); FhirDecimalSerializer.SerializeFhirDecimal(value.ValueElement, writer, summary); writer.WriteEndElement(); } // Serialize element comparator if (value.ComparatorElement != null) { writer.WriteStartElement("comparator"); CodeSerializer.SerializeCode <Hl7.Fhir.Model.Quantity.QuantityCompararator>(value.ComparatorElement, writer, summary); writer.WriteEndElement(); } // Serialize element units if (value.UnitsElement != null) { writer.WriteStartElement("units"); FhirStringSerializer.SerializeFhirString(value.UnitsElement, writer, summary); writer.WriteEndElement(); } // Serialize element system if (value.SystemElement != null) { writer.WriteStartElement("system"); FhirUriSerializer.SerializeFhirUri(value.SystemElement, writer, summary); writer.WriteEndElement(); } // Serialize element code if (value.CodeElement != null) { writer.WriteStartElement("code"); CodeSerializer.SerializeCode(value.CodeElement, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); }
public static string ValueAsSearchableString(this Model.Quantity quantity) { Quantity q = quantity.ToSystemQuantity(); return(q.LeftSearchableString()); }
public void QuantityValueUnitMapTest() { var input = new Quantity(); input.Value = 10; input.Unit = "km"; var result = sut.Map(input); CheckQuantity(result, value: 10, unit: "km", system:null, decimals: null); }
public static BsonDouble GetValueAsBson(this FM.Quantity quantity) { var value = (double)quantity.Value; return(new BsonDouble(value)); }
public void Collect(Definition definition, Quantity quantity) { if (definition.ParamType != Conformance.SearchParamType.Quantity) return; Quantity q = quantity.Standardize(); string system = (quantity.System != null) ? quantity.System.ToString() : null; BsonDocument block = new BsonDocument() { { "system", system }, { "value", q.GetValueAsBson() }, { "decimals", q.GetDecimalSearchableValue() }, { "unit", q.Units } }; Write(definition.ParamName, block); }
public static string ValueAsSearchableString(this FM.Quantity quantity) { Quantity q = quantity.ToUnitsOfMeasureQuantity(); return(q.LeftSearchableString()); }
public static void setSystem(this Model.Quantity me, string value) { me.System = value; }
public static bool IsUcum(this FM.Quantity quantity) => quantity.System != null && new Uri(UcumUriString).IsBaseOf(new Uri(quantity.System));
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as MedicationDispense; if (dest != null) { base.CopyTo(dest); if (Identifier != null) { dest.Identifier = (Hl7.Fhir.Model.Identifier)Identifier.DeepCopy(); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.MedicationDispense.MedicationDispenseStatus>)StatusElement.DeepCopy(); } if (Patient != null) { dest.Patient = (Hl7.Fhir.Model.ResourceReference)Patient.DeepCopy(); } if (Dispenser != null) { dest.Dispenser = (Hl7.Fhir.Model.ResourceReference)Dispenser.DeepCopy(); } if (AuthorizingPrescription != null) { dest.AuthorizingPrescription = new List <Hl7.Fhir.Model.ResourceReference>(AuthorizingPrescription.DeepCopy()); } if (Type != null) { dest.Type = (Hl7.Fhir.Model.CodeableConcept)Type.DeepCopy(); } if (Quantity != null) { dest.Quantity = (Hl7.Fhir.Model.Quantity)Quantity.DeepCopy(); } if (DaysSupply != null) { dest.DaysSupply = (Hl7.Fhir.Model.Quantity)DaysSupply.DeepCopy(); } if (Medication != null) { dest.Medication = (Hl7.Fhir.Model.ResourceReference)Medication.DeepCopy(); } if (WhenPreparedElement != null) { dest.WhenPreparedElement = (Hl7.Fhir.Model.FhirDateTime)WhenPreparedElement.DeepCopy(); } if (WhenHandedOverElement != null) { dest.WhenHandedOverElement = (Hl7.Fhir.Model.FhirDateTime)WhenHandedOverElement.DeepCopy(); } if (Destination != null) { dest.Destination = (Hl7.Fhir.Model.ResourceReference)Destination.DeepCopy(); } if (Receiver != null) { dest.Receiver = new List <Hl7.Fhir.Model.ResourceReference>(Receiver.DeepCopy()); } if (NoteElement != null) { dest.NoteElement = (Hl7.Fhir.Model.FhirString)NoteElement.DeepCopy(); } if (DosageInstruction != null) { dest.DosageInstruction = new List <Hl7.Fhir.Model.MedicationDispense.MedicationDispenseDosageInstructionComponent>(DosageInstruction.DeepCopy()); } if (Substitution != null) { dest.Substitution = (Hl7.Fhir.Model.MedicationDispense.MedicationDispenseSubstitutionComponent)Substitution.DeepCopy(); } return(dest); } else { throw new ArgumentException("Can only copy to an object of the same type", "other"); } }
/// <summary> /// Parse Quantity /// </summary> public static Hl7.Fhir.Model.Quantity ParseQuantity(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Quantity existingInstance = null) { Hl7.Fhir.Model.Quantity result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Quantity(); string currentElementName = reader.CurrentElementName; reader.EnterElement(); while (reader.HasMoreElements()) { var atName = reader.CurrentElementName; // Parse element extension if (atName == "extension") { result.Extension = new List <Hl7.Fhir.Model.Extension>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "extension")) { result.Extension.Add(ExtensionParser.ParseExtension(reader, errors)); } reader.LeaveArray(); } // Parse element _id else if (atName == "_id") { result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id))); } // Parse element value else if (atName == "value") { result.ValueElement = FhirDecimalParser.ParseFhirDecimal(reader, errors); } // Parse element comparator else if (atName == "comparator") { result.ComparatorElement = CodeParser.ParseCode <Hl7.Fhir.Model.Quantity.QuantityCompararator>(reader, errors); } // Parse element units else if (atName == "units") { result.UnitsElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element system else if (atName == "system") { result.SystemElement = FhirUriParser.ParseFhirUri(reader, errors); } // Parse element code else if (atName == "code") { result.CodeElement = CodeParser.ParseCode(reader, errors); } else { errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader); reader.SkipSubElementsFor(currentElementName); result = null; } } reader.LeaveElement(); return(result); }