public static void SerializeFhirBoolean(Hl7.Fhir.Model.FhirBoolean 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 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); }
public static FhirBoolean Parse(string value) { FhirBoolean result = null; if (TryParse(value, out result)) { return(result); } else { throw new FhirFormatException("Booleans can be either 0, 1, true of false"); } }
/// <summary> /// { code : true/false }, system is absent /// </summary> /// <param name="element"></param> /// <returns></returns> private List <Expression> ToExpressions(FhirModel.FhirBoolean element) { if (element == null || !element.Value.HasValue) { return(null); } var values = new List <IndexValue>(); values.Add(new IndexValue("code", element.Value.Value ? new StringValue(Boolean.TrueString) : new StringValue(Boolean.FalseString))); return(ListOf(new CompositeValue(values))); //TODO: Include implied system: http://hl7.org/fhir/special-values ? }
/// <summary> /// Parse boolean /// </summary> public static Hl7.Fhir.Model.FhirBoolean ParseFhirBoolean(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.FhirBoolean existingInstance = null) { Hl7.Fhir.Model.FhirBoolean result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.FhirBoolean(); 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 = FhirBoolean.Parse(reader.ReadPrimitiveContents(typeof(FhirBoolean))).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); }
public static bool TryParse(string value, out FhirBoolean result) { if (value == null) { result = new FhirBoolean(null); return true; } bool b; try { b = XmlConvert.ToBoolean(value); result = new FhirBoolean(b); return true; } catch { } result = null; return false; //if(value == "1" || value == "true") //{ // result = new FhirBoolean(true); // return true; //} //else if(value == "0" || value == "false") //{ // result = new FhirBoolean(false); // return true; //} //else if (value == null) //{ // result = new FhirBoolean(null); // return true; //} //else //{ // result = null; // return false; //} }
public static bool TryParse(string value, out FhirBoolean result) { if (value == null) { result = new FhirBoolean(null); return(true); } bool b; try { b = XmlConvert.ToBoolean(value); result = new FhirBoolean(b); return(true); } catch { } result = null; return(false); //if(value == "1" || value == "true") //{ // result = new FhirBoolean(true); // return true; //} //else if(value == "0" || value == "false") //{ // result = new FhirBoolean(false); // return true; //} //else if (value == null) //{ // result = new FhirBoolean(null); // return true; //} //else //{ // result = null; // return false; //} }
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")); }
public void FhirBooleanMapTest() { var input = new FhirBoolean(false); var result = sut.Map(input); Assert.AreEqual(1, result.Count()); Assert.IsInstanceOfType(result[0], typeof(CompositeValue)); var comp = (CompositeValue)result[0]; CheckCoding(comp, code: "False", system: null, text: null); }
public void TestGetValueAsString() { var x = new FhirBoolean(true); Assert.AreEqual("true", x.GetValueAsString()); }