Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        /// <summary>
        /// Parse Ratio
        /// </summary>
        public static Hl7.Fhir.Model.Ratio ParseRatio(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Ratio existingInstance = null)
        {
            Hl7.Fhir.Model.Ratio result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Ratio();
            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 numerator
                else if (atName == "numerator")
                {
                    result.Numerator = QuantityParser.ParseQuantity(reader, errors);
                }

                // Parse element denominator
                else if (atName == "denominator")
                {
                    result.Denominator = QuantityParser.ParseQuantity(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);
        }
Esempio n. 3
0
        public static void SerializeRatio(Hl7.Fhir.Model.Ratio 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 numerator
            if (value.Numerator != null)
            {
                writer.WriteStartElement("numerator");
                QuantitySerializer.SerializeQuantity(value.Numerator, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element denominator
            if (value.Denominator != null)
            {
                writer.WriteStartElement("denominator");
                QuantitySerializer.SerializeQuantity(value.Denominator, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
        }