public static void SerializeFhirString(Hl7.Fhir.Model.FhirString 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();
        }
 public string Cast(FhirString s)
 {
     if (s != null)
         return s.Value;
     else
         return null;
 }
Пример #3
0
        public void TestIsNullOrEmpty_Extension()
        {
            var e = new Extension();

            Assert.IsTrue(e.IsNullOrEmpty());

            var value = new FhirString("test");

            Assert.IsFalse(value.IsNullOrEmpty());

            e.Value = value;
            Assert.IsFalse(e.IsNullOrEmpty());

            e.Value = null;
            Assert.IsTrue(e.IsNullOrEmpty());
        }
        /// <summary>
        /// Parse string
        /// </summary>
        public static Hl7.Fhir.Model.FhirString ParseFhirString(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FhirString existingInstance = null)
        {
            Hl7.Fhir.Model.FhirString result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FhirString();
            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 = FhirString.Parse(reader.ReadPrimitiveContents(typeof(FhirString))).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);
        }
Пример #5
0
        void testIsNullOrEmpty_StringPrimitive <T>(string exampleValue = "test") where T : Primitive <string>, IStringValue, new()
        {
            var elem = new T();

            Assert.IsTrue(elem.IsNullOrEmpty());

            elem.Value = string.Empty;
            Assert.IsTrue(elem.IsNullOrEmpty());
            Assert.IsTrue((elem as Base).IsNullOrEmpty());

            Assert.IsFalse(string.IsNullOrEmpty(exampleValue));
            elem.Value = exampleValue;
            Assert.IsFalse(elem.IsNullOrEmpty());
            Assert.IsFalse((elem as Base).IsNullOrEmpty());

            elem.Value = null;
            Assert.IsTrue(elem.IsNullOrEmpty());
            Assert.IsTrue((elem as Base).IsNullOrEmpty());

            var extension = new Extension();

            Assert.IsTrue(extension.IsNullOrEmpty());
            elem.Extension.Add(extension);
            Assert.IsTrue(elem.IsNullOrEmpty());

            var extensionValue = new FhirString(exampleValue);

            Assert.IsFalse(extensionValue.IsNullOrEmpty());
            extension.Value = extensionValue;
            Assert.IsFalse(extension.IsNullOrEmpty());
            Assert.IsFalse(elem.IsNullOrEmpty());
            Assert.IsFalse((elem as Base).IsNullOrEmpty());

            extensionValue.Value = null;
            Assert.IsTrue(extensionValue.IsNullOrEmpty());
            Assert.IsTrue(extension.IsNullOrEmpty());
            Assert.IsTrue(elem.IsNullOrEmpty());

            elem.Extension.Clear();
            Assert.IsTrue(elem.IsNullOrEmpty());
        }
Пример #6
0
        void testIsNullOrEmpty_Primitive <T, V>(V testValue, V emptyValue) where T : Primitive <V>, IValue <V>, new()
        {
            var elem = new T();

            Assert.IsTrue(elem.IsNullOrEmpty());

            elem.Value = emptyValue;
            Assert.IsFalse(elem.IsNullOrEmpty());
            Assert.IsFalse((elem as Base).IsNullOrEmpty());

            elem.Value = testValue;
            Assert.IsFalse(elem.IsNullOrEmpty());
            Assert.IsFalse((elem as Base).IsNullOrEmpty());

            elem.Value = default(V);
            Assert.IsTrue(elem.IsNullOrEmpty());
            Assert.IsTrue((elem as Base).IsNullOrEmpty());

            var extension = new Extension();

            Assert.IsTrue(extension.IsNullOrEmpty());
            elem.Extension.Add(extension);
            Assert.IsTrue(elem.IsNullOrEmpty());

            var extensionValue = new FhirString("test");

            Assert.IsFalse(extensionValue.IsNullOrEmpty());
            extension.Value = extensionValue;
            Assert.IsFalse(extension.IsNullOrEmpty());
            Assert.IsFalse(elem.IsNullOrEmpty());
            Assert.IsFalse((elem as Base).IsNullOrEmpty());

            extensionValue.Value = null;
            Assert.IsTrue(extensionValue.IsNullOrEmpty());
            Assert.IsTrue(extension.IsNullOrEmpty());
            Assert.IsTrue(elem.IsNullOrEmpty());

            elem.Extension.Clear();
            Assert.IsTrue(elem.IsNullOrEmpty());
        }
Пример #7
0
 public static bool IsValidValue(string value)
 {
     return(FhirString.IsValidValue(value));
 }
Пример #8
0
 public static bool IsValidValue(string value) => FhirString.IsValidValue(value);
Пример #9
0
        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"));
            
        }
Пример #10
0
        public void FhirStringMapTest()
        {
            var input = new FhirString("bla");

            var result = sut.Map(input);

            Assert.AreEqual(1, result.Count());
            Assert.IsInstanceOfType(result[0], typeof(StringValue));

            Assert.AreEqual("bla", (result[0] as StringValue).Value);
        }
Пример #11
0
 private List <Expression> ToExpressions(FhirModel.FhirString element)
 {
     return(element != null?ListOf(new StringValue(element.Value)) : null);
 }