private void AddLanguageCommunication(Patient patient, XElement element) { var communication = new Patient.CommunicationComponent(); foreach (var child in element.Elements()) { switch (child.Name.LocalName) { case "languageCode": var code = FromXml(new CodeParser(), child); if (code != null) { communication.Language = new CodeableConcept("urn:ietf:bcp:47", code.Value); } break; case "preferenceInd": communication.PreferredElement = new FhirBooleanParser().FromXml(child, Errors); break; } } if (communication.Language != null) { patient.Communication.Add(communication); } }
/// <summary> /// Deserialize JSON into a FHIR Patient#Communication /// </summary> public static void DeserializeJsonProperty(this Patient.CommunicationComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "language": current.Language = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Language).DeserializeJson(ref reader, options); break; case "preferred": if (reader.TokenType == JsonTokenType.Null) { current.PreferredElement = new FhirBoolean(); reader.Skip(); } else { current.PreferredElement = new FhirBoolean(reader.GetBoolean()); } break; case "_preferred": if (current.PreferredElement == null) { current.PreferredElement = new FhirBoolean(); } ((Hl7.Fhir.Model.Element)current.PreferredElement).DeserializeJson(ref reader, options); break; // Complex: communication, Export: CommunicationComponent, Base: BackboneElement default: ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }
/// <summary> /// Serialize a FHIR Patient#Communication into JSON /// </summary> public static void SerializeJson(this Patient.CommunicationComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } // Component: Patient#Communication, Export: CommunicationComponent, Base: BackboneElement (BackboneElement) ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false); writer.WritePropertyName("language"); current.Language.SerializeJson(writer, options); if (current.PreferredElement != null) { if (current.PreferredElement.Value != null) { writer.WriteBoolean("preferred", (bool)current.PreferredElement.Value); } if (current.PreferredElement.HasExtensions() || (!string.IsNullOrEmpty(current.PreferredElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_preferred", false, current.PreferredElement.Extension, current.PreferredElement.ElementId); } } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR Patient#Communication /// </summary> public static void DeserializeJson(this Patient.CommunicationComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options) { string propertyName; while (reader.Read()) { if (reader.TokenType == JsonTokenType.EndObject) { return; } if (reader.TokenType == JsonTokenType.PropertyName) { propertyName = reader.GetString(); if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug) { Console.WriteLine($"Patient.CommunicationComponent >>> Patient#Communication.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"Patient.CommunicationComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
public void AddACommunicationElementToStoredPatient() { var com = new Patient.CommunicationComponent { Language = new CodeableConcept("https://tools.ietf.org/html/bcp47", "en") }; _fhirResourceRepository.Patient.Communication.Add(com); }