public static void SerializeInstant(Hl7.Fhir.Model.Instant 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();
        }
Esempio n. 2
0
        private List <Expression> ToExpressions(FhirModel.Instant element)
        {
            if (element == null || !element.Value.HasValue)
            {
                return(null);
            }

            var fdt = new FhirModel.FhirDateTime(element.Value.Value);

            return(ToExpressions(fdt));
        }
        /// <summary>
        /// Parse instant
        /// </summary>
        public static Hl7.Fhir.Model.Instant ParseInstant(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Instant existingInstance = null)
        {
            Hl7.Fhir.Model.Instant result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Instant();
            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 = Instant.Parse(reader.ReadPrimitiveContents(typeof(Instant))).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);
        }
Esempio n. 4
0
        public static bool TryParse(string value, out Instant result)
        {
            DateTimeOffset dt;

            if (value == null)
            {
                result = new Instant(null);
                return true;
            }
            else if( Util.TryParseIsoDateTime(value, out dt) )
            {
                result = new Instant(dt);
                return true;
            }
            else
            {
                result = null;
                return false;
            }
        }
        public void MilisecondsOnInstant()
        {
            Instant i = new Instant(new DateTimeOffset(2013, 4, 19, 16, 27, 23, 233, TimeSpan.Zero));

            Assert.IsTrue(i.Value.Value.Millisecond > 0);

            string xml = FhirSerializer.SerializeElementAsXml(i, "someInstant");

            ErrorList dummy = new ErrorList();
            Instant j = (Instant)FhirParser.ParseElementFromXml(xml, dummy);

            Assert.AreEqual(0, dummy.Count);
            Assert.AreEqual(233, j.Value.Value.Millisecond);

            Instant result;
            bool succ = Instant.TryParse("2013-04-19T16:17:23Z", out result);
            Assert.IsTrue(succ);

            xml = FhirSerializer.SerializeElementAsXml(result, "someInstant");
            Assert.IsFalse(xml.Contains("16:27:23.0"));
        }