Ejemplo n.º 1
0
        public void PolymorphAndArraySerialization()
        {
            Extension ext = new Extension()
            {
                Url       = new Uri("http://hl7.org/fhir/profiles/@3141#test"),
                Value     = new FhirBoolean(true),
                Extension = new List <Extension>()
                {
                    new Extension()
                    {
                        Value = new Coding()
                        {
                            Code = "R51", System = new Uri("http://hl7.org/fhir/sid/icd-10")
                        }
                    }
                }
            };

            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-16""?>" +
                            @"<element xmlns=""http://hl7.org/fhir"">" +
                            @"<extension><valueCoding><system value=""http://hl7.org/fhir/sid/icd-10"" /><code value=""R51"" /></valueCoding></extension>" +
                            @"<url value=""http://hl7.org/fhir/profiles/@3141#test"" />" +
                            @"<valueBoolean value=""true"" />" +
                            @"</element>", FhirSerializer.SerializeElementAsXml(ext));
            Assert.AreEqual(
                @"{" +
                @"""extension"":[{""valueCoding"":{""system"":{""value"":""http://hl7.org/fhir/sid/icd-10""},""code"":{""value"":""R51""}}}]," +
                @"""url"":{""value"":""http://hl7.org/fhir/profiles/@3141#test""}," +
                @"""valueBoolean"":{""value"":true}" +
                @"}", FhirSerializer.SerializeElementAsJson(ext));
        }
Ejemplo n.º 2
0
        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);

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

            Assert.IsTrue(succ);

            xml = FhirSerializer.SerializeElementAsXml(new Instant(result), "someInstant");
            Assert.IsFalse(xml.Contains("16:27:23.0"));
        }
Ejemplo n.º 3
0
        public void SerializeElement()
        {
            Identifier id = new Identifier
            {
                LocalId = "3141",
                Use     = Identifier.IdentifierUse.Official,
                Label   = "SSN",
                System  = new Uri("http://hl7.org/fhir/sid/us-ssn"),
                Key     = "000111111",
                Period  = new Period()
                {
                    StartElement = new FhirDateTime(2001, 1, 2),
                    EndElement   = new FhirDateTime(2010, 3, 4)
                },
                Assigner = new ResourceReference {
                    Type      = "Organization",
                    Reference = "organization/@123",
                    Display   = "HL7, Inc"
                }
            };


            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-16""?>" +
                            @"<element id=""3141"" xmlns=""http://hl7.org/fhir"">" +
                            @"<use value=""official"" />" +
                            @"<label value=""SSN"" />" +
                            @"<system value=""http://hl7.org/fhir/sid/us-ssn"" />" +
                            @"<key value=""000111111"" />" +
                            @"<period><start value=""2001-01-02"" /><end value=""2010-03-04"" /></period>" +
                            @"<assigner><type value=""Organization"" /><reference value=""organization/@123"" /><display value=""HL7, Inc"" /></assigner>" +
                            @"</element>", FhirSerializer.SerializeElementAsXml(id));

            Assert.AreEqual(
                @"{""_id"":""3141"",""use"":{""value"":""official""},""label"":{""value"":""SSN""}," +
                @"""system"":{""value"":""http://hl7.org/fhir/sid/us-ssn""},""key"":{""value"":""000111111""}," +
                @"""period"":{""start"":{""value"":""2001-01-02""},""end"":{""value"":""2010-03-04""}}," +
                @"""assigner"":{""type"":{""value"":""Organization""},""reference"":{""value"":""organization/@123""}," +
                @"""display"":{""value"":""HL7, Inc""}}}", FhirSerializer.SerializeElementAsJson(id));
        }
        public void JsonDivZonderNamespace()
        {
            string jsonString = "{ \"testNarrative\" : {" +
                                "\"status\" : { \"value\" : \"generated\" }, " +
                                "\"div\" : " +
                                "\"<div>Whatever</div>\" } }";

            var errors = new ErrorList();
            var result = (Narrative)FhirParser.ParseElementFromJson(jsonString, errors);
            var xml    = FhirSerializer.SerializeElementAsXml(result, "testNarrative");

            Assert.IsTrue(xml.Contains("w3.org/1999/xhtml"));

            jsonString = "{ \"testNarrative\" : {" +
                         "\"status\" : { \"value\" : \"generated\" }, " +
                         "\"div\" : " +
                         "\"<div xmlns='http://www.w3.org/1999/xhtml'>Whatever</div>\" } }";

            errors.Clear();
            result = (Narrative)FhirParser.ParseElementFromJson(jsonString, errors);
            xml    = FhirSerializer.SerializeElementAsXml(result, "testNarrative");
            Assert.IsTrue(xml.Contains("w3.org/1999/xhtml"));
        }