Exemplo n.º 1
0
        public void DateTimeHandling()
        {
            FhirDateTime dt = FhirDateTime.Parse("2010-01-01");

            Assert.AreEqual("2010-01-01", dt.ToString());

            FhirDateTime dt2 = new FhirDateTime(1972, 11, 30, 15, 10);

            Assert.IsTrue(dt2.ToString().StartsWith("1972-11-30T15:10"));
        }
        /// <summary>
        /// Parse dateTime
        /// </summary>
        public static Hl7.Fhir.Model.FhirDateTime ParseFhirDateTime(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FhirDateTime existingInstance = null)
        {
            Hl7.Fhir.Model.FhirDateTime result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FhirDateTime();
            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 = FhirDateTime.Parse(reader.ReadPrimitiveContents(typeof(FhirDateTime))).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);
        }