コード例 #1
0
ファイル: ModelTests.cs プロジェクト: jamesagnew/fhir-net-api
        public void ExtensionManagement()
        {
            Patient p = new Patient();
            Uri u1 = new Uri("http://fhir.org/ext/ext-test");
            Assert.IsNull(p.GetExtension(u1));

            Extension newEx = p.SetExtension(u1, new FhirBoolean(true));
            Assert.AreSame(newEx, p.GetExtension(u1));

            p.AddExtension(new Uri("http://fhir.org/ext/ext-test2"), new FhirString("Ewout"));
            Assert.AreSame(newEx, p.GetExtension(u1));

            p.RemoveExtension(u1);
            Assert.IsNull(p.GetExtension(u1));

            p.SetExtension(new Uri("http://fhir.org/ext/ext-test2"), new FhirString("Ewout Kramer"));
            var ew = p.GetExtensions(new Uri("http://fhir.org/ext/ext-test2"));
            Assert.AreEqual(1, ew.Count());

            p.AddExtension(new Uri("http://fhir.org/ext/ext-test2"), new FhirString("Wouter Kramer"));

            ew = p.GetExtensions(new Uri("http://fhir.org/ext/ext-test2"));
            Assert.AreEqual(2, ew.Count());

        }
コード例 #2
0
ファイル: ModelTests.cs プロジェクト: tiloc/fhir-net-api
        public void ExtensionManagement()
        {
            Patient p = new Patient();
            var u1 = "http://fhir.org/ext/ext-test";
            Assert.IsNull(p.GetExtension("http://fhir.org/ext/ext-test"));

            Extension newEx = p.SetExtension(u1, new FhirBoolean(true));
            Assert.AreSame(newEx, p.GetExtension(u1));

            p.AddExtension("http://fhir.org/ext/ext-test2", new FhirString("Ewout"));
            Assert.AreSame(newEx, p.GetExtension(u1));

            p.RemoveExtension(u1);
            Assert.IsNull(p.GetExtension(u1));

            p.SetExtension("http://fhir.org/ext/ext-test2", new FhirString("Ewout Kramer"));
            var ew = p.GetExtensions("http://fhir.org/ext/ext-test2");
            Assert.AreEqual(1, ew.Count());

            p.AddExtension("http://fhir.org/ext/ext-test2", new FhirString("Wouter Kramer"));

            ew = p.GetExtensions("http://fhir.org/ext/ext-test2");
            Assert.AreEqual(2, ew.Count());

            Assert.AreEqual(0, p.ModifierExtension.Count());
            var me = p.AddExtension("http://fhir.org/ext/ext-test3", new FhirString("bla"), isModifier:true);
            Assert.AreEqual(1, p.ModifierExtension.Count());
            Assert.AreEqual(me, p.GetExtension("http://fhir.org/ext/ext-test3"));
            Assert.AreEqual(me, p.GetExtensions("http://fhir.org/ext/ext-test3").Single());
            Assert.AreEqual(3, p.AllExtensions().Count());

            var code = new Code("test");
            p.AddExtension("http://fhir.org/ext/code", code);            
            Assert.AreEqual(code, p.GetExtensionValue<Code>("http://fhir.org/ext/code"));

            var text = new FhirString("test");
            p.AddExtension("http://fhir.org/ext/string", text);
            Assert.AreEqual(text, p.GetExtensionValue<FhirString>("http://fhir.org/ext/string"));

            var fhirbool = new FhirBoolean(true);
            p.AddExtension("http://fhir.org/ext/bool", fhirbool);
            Assert.AreEqual(fhirbool, p.GetExtensionValue<FhirBoolean>("http://fhir.org/ext/bool"));
            
        }
コード例 #3
0
        public void ParseJsonNativeValues()
        {
            Patient p = new Patient();

            p.SetExtension(new Uri("http://blabla.nl/number"),new FhirDecimal(new Decimal(3.14)));
            p.SetExtension(new Uri("http://blabla.nl/int"), new Integer(150));
            p.SetExtension(new Uri("http://blabla.nl/bool"), new FhirBoolean(true));

            var json = FhirSerializer.SerializeResourceToJson(p);

            Assert.IsTrue(json.Contains("\"value\":3.14"));
            Assert.IsTrue(json.Contains("\"value\":150"));
            Assert.IsTrue(json.Contains("\"value\":true"));

            var err = new ErrorList();
            p = (Patient)FhirParser.ParseResourceFromJson(json, err);
            Assert.IsTrue(err.Count == 0);

            var ex = p.GetExtension(new Uri("http://blabla.nl/number"));
            Assert.AreEqual(new Decimal(3.14), ((FhirDecimal)ex.Value).Value.Value);
            ex = p.GetExtension(new Uri("http://blabla.nl/int"));
            Assert.AreEqual(150, ((Integer)ex.Value).Value.Value);
            ex = p.GetExtension(new Uri("http://blabla.nl/bool"));
            Assert.AreEqual(true, ((FhirBoolean)ex.Value).Value.Value);
        }
コード例 #4
0
        public void TestDeepCopy()
        {
            var p = new Patient();

            p.Name = new List<HumanName>();
            p.Name.Add(HumanName.ForFamily("Kramer").WithGiven("Ewout"));
            p.Name.Add(HumanName.ForFamily("Kramer").WithGiven("Wouter"));
            p.SetExtension("http://test.nl/test", new FhirString("Hello, world"));

            var p2 = (Patient)p.DeepCopy();

            Assert.IsTrue(p2 is Patient);
            Assert.AreNotEqual(p,p2);
            Assert.IsNotNull(p2.Name);
            Assert.AreNotEqual(p.Name, p2.Name);
            Assert.AreEqual(p.Name[0].Family.First(), p2.Name[0].Family.First());
            Assert.AreEqual(p.Name[0].Given.First(), p2.Name[0].Given.First());
            Assert.AreEqual(p.Name[1].Family.First(), p2.Name[1].Family.First());
            Assert.AreEqual(p.Name[1].Given.First(), p2.Name[1].Given.First());

            var ext = p.GetExtension("http://test.nl/test");
            var ext2 = p2.GetExtension("http://test.nl/test");
            Assert.AreNotEqual(ext, ext2);
            Assert.AreNotEqual(ext.Value, ext2.Value);
            Assert.AreEqual(((FhirString)ext.Value).Value, ((FhirString)ext2.Value).Value);
        }