/// <summary> /// Deserialize JSON into a FHIR MedicationDispense#Substitution /// </summary> public static void DeserializeJson(this MedicationDispense.SubstitutionComponent 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($"MedicationDispense.SubstitutionComponent >>> MedicationDispense#Substitution.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"MedicationDispense.SubstitutionComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Serialize a FHIR MedicationDispense#Substitution into JSON /// </summary> public static void SerializeJson(this MedicationDispense.SubstitutionComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } // Component: MedicationDispense#Substitution, Export: SubstitutionComponent, Base: BackboneElement (BackboneElement) ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false); writer.WriteBoolean("wasSubstituted", (bool)current.WasSubstitutedElement.Value); if (current.Type != null) { writer.WritePropertyName("type"); current.Type.SerializeJson(writer, options); } if ((current.Reason != null) && (current.Reason.Count != 0)) { writer.WritePropertyName("reason"); writer.WriteStartArray(); foreach (CodeableConcept val in current.Reason) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.ResponsibleParty != null) && (current.ResponsibleParty.Count != 0)) { writer.WritePropertyName("responsibleParty"); writer.WriteStartArray(); foreach (ResourceReference val in current.ResponsibleParty) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR MedicationDispense#Substitution /// </summary> public static void DeserializeJsonProperty(this MedicationDispense.SubstitutionComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "wasSubstituted": if (reader.TokenType == JsonTokenType.Null) { current.WasSubstitutedElement = new FhirBoolean(); reader.Skip(); } else { current.WasSubstitutedElement = new FhirBoolean(reader.GetBoolean()); } break; case "_wasSubstituted": if (current.WasSubstitutedElement == null) { current.WasSubstitutedElement = new FhirBoolean(); } ((Hl7.Fhir.Model.Element)current.WasSubstitutedElement).DeserializeJson(ref reader, options); break; case "type": current.Type = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options); break; case "reason": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"SubstitutionComponent error reading 'reason' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Reason = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_Reason = new Hl7.Fhir.Model.CodeableConcept(); v_Reason.DeserializeJson(ref reader, options); current.Reason.Add(v_Reason); if (!reader.Read()) { throw new JsonException($"SubstitutionComponent error reading 'reason' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Reason.Count == 0) { current.Reason = null; } break; case "responsibleParty": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"SubstitutionComponent error reading 'responsibleParty' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ResponsibleParty = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_ResponsibleParty = new Hl7.Fhir.Model.ResourceReference(); v_ResponsibleParty.DeserializeJson(ref reader, options); current.ResponsibleParty.Add(v_ResponsibleParty); if (!reader.Read()) { throw new JsonException($"SubstitutionComponent error reading 'responsibleParty' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ResponsibleParty.Count == 0) { current.ResponsibleParty = null; } break; // Complex: substitution, Export: SubstitutionComponent, Base: BackboneElement default: ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }