Example #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));
        }
Example #2
0
        public void NativelySerializedElements()
        {
            Integer i    = new Integer(3141);
            var     json = FhirSerializer.SerializeElementAsJson(i);

            Assert.AreEqual("{\"value\":3141}", json);

            FhirBoolean b = new FhirBoolean(false);

            json = FhirSerializer.SerializeElementAsJson(b);
            Assert.AreEqual("{\"value\":false}", json);
        }
Example #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));
        }