public static void SerializeFhirDecimal(Hl7.Fhir.Model.FhirDecimal value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartComplexContent();

            // Serialize element value
            if (value.Value != null)
            {
                writer.WritePrimitiveContents("value", value, XmlSerializationHint.Attribute);
            }

            // 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();
            }


            writer.WriteEndComplexContent();
        }
Exemplo n.º 2
0
 public void FhirDecimalMapTest()
 {
     var input = new FhirDecimal(1081.54M);
     var result = sut.Map(input);
     Assert.AreEqual(1, result.Count);
     Assert.IsInstanceOfType(result.First(), typeof(NumberValue));
     Assert.AreEqual(1081.54M, ((NumberValue)result.First()).Value);
 }
Exemplo n.º 3
0
        private List <Expression> ToExpressions(FhirModel.FhirDecimal element)
        {
            if (element == null || !element.Value.HasValue)
            {
                return(null);
            }

            return(ListOf(new NumberValue(element.Value.Value)));
        }
Exemplo n.º 4
0
        public static FhirDecimal Parse(string value)
        {
            FhirDecimal result = null;

            if (TryParse(value, out result))
            {
                return(result);
            }
            else
            {
                throw new FhirFormatException("Not a decimal value");
            }
        }
        /// <summary>
        /// Parse decimal
        /// </summary>
        public static Hl7.Fhir.Model.FhirDecimal ParseFhirDecimal(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FhirDecimal existingInstance = null)
        {
            Hl7.Fhir.Model.FhirDecimal result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FhirDecimal();
            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.Value = FhirDecimal.Parse(reader.ReadPrimitiveContents(typeof(FhirDecimal))).Value;
                }

                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);
        }
Exemplo n.º 6
0
        public static bool TryParse(string value, out FhirDecimal result)
        {
            if (value == null)
            {
                result = new FhirDecimal(null);
                return(true);
            }

            decimal decimalValue;

            try
            {
                decimalValue = XmlConvert.ToDecimal(value);
                result       = new FhirDecimal(decimalValue);
                return(true);
            }
            catch
            {
            }

            result = null;
            return(false);

            //NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign |
            //                    NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingWhite;

            //if (value == null)
            //{
            //    result = new FhirDecimal(null);
            //    return true;
            //}
            //else if (Decimal.TryParse(value, style, NumberFormatInfo.InvariantInfo, out decimalValue))
            //{
            //    result = new FhirDecimal(decimalValue);
            //    return true;
            //}
            //else
            //{
            //    result = null;
            //    return false;
            //}
        }
Exemplo n.º 7
0
        public static bool TryParse(string value, out FhirDecimal result)
        {
            if (value == null)
            {
                result = new FhirDecimal(null);
                return true;
            }

            decimal decimalValue;

            try
            {
                decimalValue = XmlConvert.ToDecimal(value);
                result = new FhirDecimal(decimalValue);
                return true;
            }
            catch
            {
            }

            result = null;
            return false;

            //NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign |
            //                    NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingWhite;

            //if (value == null)
            //{
            //    result = new FhirDecimal(null);
            //    return true;
            //}
            //else if (Decimal.TryParse(value, style, NumberFormatInfo.InvariantInfo, out decimalValue))
            //{
            //    result = new FhirDecimal(decimalValue);
            //    return true;
            //}
            //else
            //{
            //    result = null;
            //    return false;
            //}
        }