/// <summary> /// Parse Demographics /// </summary> public static Hl7.Fhir.Model.Demographics ParseDemographics(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Demographics existingInstance = null) { Hl7.Fhir.Model.Demographics result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Demographics(); try { 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.LocalId = Id.Parse(reader.ReadPrimitiveContents(typeof(Id))); } // Parse element identifier else if (atName == "identifier") { result.Identifier = new List <Hl7.Fhir.Model.Identifier>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "identifier")) { result.Identifier.Add(IdentifierParser.ParseIdentifier(reader, errors)); } reader.LeaveArray(); } // Parse element name else if (atName == "name") { result.Name = new List <Hl7.Fhir.Model.HumanName>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "name")) { result.Name.Add(HumanNameParser.ParseHumanName(reader, errors)); } reader.LeaveArray(); } // Parse element telecom else if (atName == "telecom") { result.Telecom = new List <Hl7.Fhir.Model.Contact>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "telecom")) { result.Telecom.Add(ContactParser.ParseContact(reader, errors)); } reader.LeaveArray(); } // Parse element gender else if (atName == "gender") { result.Gender = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element birthDate else if (atName == "birthDate") { result.BirthDate = FhirDateTimeParser.ParseFhirDateTime(reader, errors); } // Parse element deceased else if (atName == "deceased") { result.Deceased = FhirBooleanParser.ParseFhirBoolean(reader, errors); } // Parse element address else if (atName == "address") { result.Address = new List <Hl7.Fhir.Model.Address>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "address")) { result.Address.Add(AddressParser.ParseAddress(reader, errors)); } reader.LeaveArray(); } // Parse element photo else if (atName == "photo") { result.Photo = new List <Hl7.Fhir.Model.Attachment>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "photo")) { result.Photo.Add(AttachmentParser.ParseAttachment(reader, errors)); } reader.LeaveArray(); } // Parse element maritalStatus else if (atName == "maritalStatus") { result.MaritalStatus = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element language else if (atName == "language") { result.Language = new List <Hl7.Fhir.Model.Demographics.DemographicsLanguageComponent>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "language")) { result.Language.Add(DemographicsParser.ParseDemographicsLanguageComponent(reader, errors)); } reader.LeaveArray(); } else { errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader); reader.SkipSubElementsFor(currentElementName); result = null; } } reader.LeaveElement(); } catch (Exception ex) { errors.Add(ex.Message, reader); } return(result); }
public static void SerializeDemographics(Hl7.Fhir.Model.Demographics value, IFhirWriter writer) { writer.WriteStartComplexContent(); // Serialize element _id if (value.LocalId != null) { writer.WritePrimitiveContents("_id", value.LocalId, XmlSerializationHint.Attribute); } // Serialize element extension if (value.Extension != null && value.Extension.Count > 0) { writer.WriteStartArrayElement("extension"); foreach (var item in value.Extension) { writer.WriteStartArrayMember("extension"); ExtensionSerializer.SerializeExtension(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element identifier if (value.Identifier != null && value.Identifier.Count > 0) { writer.WriteStartArrayElement("identifier"); foreach (var item in value.Identifier) { writer.WriteStartArrayMember("identifier"); IdentifierSerializer.SerializeIdentifier(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element name if (value.Name != null && value.Name.Count > 0) { writer.WriteStartArrayElement("name"); foreach (var item in value.Name) { writer.WriteStartArrayMember("name"); HumanNameSerializer.SerializeHumanName(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element telecom if (value.Telecom != null && value.Telecom.Count > 0) { writer.WriteStartArrayElement("telecom"); foreach (var item in value.Telecom) { writer.WriteStartArrayMember("telecom"); ContactSerializer.SerializeContact(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element gender if (value.Gender != null) { writer.WriteStartElement("gender"); CodeableConceptSerializer.SerializeCodeableConcept(value.Gender, writer); writer.WriteEndElement(); } // Serialize element birthDate if (value.BirthDate != null) { writer.WriteStartElement("birthDate"); FhirDateTimeSerializer.SerializeFhirDateTime(value.BirthDate, writer); writer.WriteEndElement(); } // Serialize element deceased if (value.Deceased != null) { writer.WriteStartElement("deceased"); FhirBooleanSerializer.SerializeFhirBoolean(value.Deceased, writer); writer.WriteEndElement(); } // Serialize element address if (value.Address != null && value.Address.Count > 0) { writer.WriteStartArrayElement("address"); foreach (var item in value.Address) { writer.WriteStartArrayMember("address"); AddressSerializer.SerializeAddress(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element photo if (value.Photo != null && value.Photo.Count > 0) { writer.WriteStartArrayElement("photo"); foreach (var item in value.Photo) { writer.WriteStartArrayMember("photo"); AttachmentSerializer.SerializeAttachment(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element maritalStatus if (value.MaritalStatus != null) { writer.WriteStartElement("maritalStatus"); CodeableConceptSerializer.SerializeCodeableConcept(value.MaritalStatus, writer); writer.WriteEndElement(); } // Serialize element language if (value.Language != null && value.Language.Count > 0) { writer.WriteStartArrayElement("language"); foreach (var item in value.Language) { writer.WriteStartArrayMember("language"); DemographicsSerializer.SerializeDemographicsLanguageComponent(item, writer); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } writer.WriteEndComplexContent(); }