/// <summary> /// Deserialize JSON into a FHIR MedicationAdministration /// </summary> public static void DeserializeJson(this MedicationAdministration 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($"MedicationAdministration >>> MedicationAdministration.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"MedicationAdministration: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
/// <summary> /// Serialize a FHIR MedicationAdministration into JSON /// </summary> public static void SerializeJson(this MedicationAdministration current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "MedicationAdministration"); // Complex: MedicationAdministration, Export: MedicationAdministration, Base: DomainResource (DomainResource) ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false); if ((current.Identifier != null) && (current.Identifier.Count != 0)) { writer.WritePropertyName("identifier"); writer.WriteStartArray(); foreach (Identifier val in current.Identifier) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.InstantiatesElement != null) && (current.InstantiatesElement.Count != 0)) { int valueCount = 0; int extensionCount = 0; foreach (FhirUri val in current.InstantiatesElement) { if (!string.IsNullOrEmpty(val.Value)) { valueCount++; } if (val.HasExtensions()) { extensionCount++; } } if (valueCount > 0) { writer.WritePropertyName("instantiates"); writer.WriteStartArray(); foreach (FhirUri val in current.InstantiatesElement) { if (string.IsNullOrEmpty(val.Value)) { writer.WriteNullValue(); } else { writer.WriteStringValue(val.Value); } } writer.WriteEndArray(); } if (extensionCount > 0) { writer.WritePropertyName("_instantiates"); writer.WriteStartArray(); foreach (FhirUri val in current.InstantiatesElement) { if (val.HasExtensions() || (!string.IsNullOrEmpty(val.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, string.Empty, true, val.Extension, val.ElementId); } else { writer.WriteNullValue(); } } writer.WriteEndArray(); } } if ((current.PartOf != null) && (current.PartOf.Count != 0)) { writer.WritePropertyName("partOf"); writer.WriteStartArray(); foreach (ResourceReference val in current.PartOf) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } writer.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value)); if ((current.StatusReason != null) && (current.StatusReason.Count != 0)) { writer.WritePropertyName("statusReason"); writer.WriteStartArray(); foreach (CodeableConcept val in current.StatusReason) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Category != null) { writer.WritePropertyName("category"); current.Category.SerializeJson(writer, options); } if (current.Medication != null) { switch (current.Medication) { case CodeableConcept v_CodeableConcept: writer.WritePropertyName("medicationCodeableConcept"); v_CodeableConcept.SerializeJson(writer, options); break; case ResourceReference v_ResourceReference: writer.WritePropertyName("medicationReference"); v_ResourceReference.SerializeJson(writer, options); break; } } writer.WritePropertyName("subject"); current.Subject.SerializeJson(writer, options); if (current.Context != null) { writer.WritePropertyName("context"); current.Context.SerializeJson(writer, options); } if ((current.SupportingInformation != null) && (current.SupportingInformation.Count != 0)) { writer.WritePropertyName("supportingInformation"); writer.WriteStartArray(); foreach (ResourceReference val in current.SupportingInformation) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Effective != null) { switch (current.Effective) { case FhirDateTime v_FhirDateTime: writer.WriteString("effectiveDateTime", v_FhirDateTime.Value); break; case Period v_Period: writer.WritePropertyName("effectivePeriod"); v_Period.SerializeJson(writer, options); break; } } if ((current.Performer != null) && (current.Performer.Count != 0)) { writer.WritePropertyName("performer"); writer.WriteStartArray(); foreach (MedicationAdministration.PerformerComponent val in current.Performer) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.ReasonCode != null) && (current.ReasonCode.Count != 0)) { writer.WritePropertyName("reasonCode"); writer.WriteStartArray(); foreach (CodeableConcept val in current.ReasonCode) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.ReasonReference != null) && (current.ReasonReference.Count != 0)) { writer.WritePropertyName("reasonReference"); writer.WriteStartArray(); foreach (ResourceReference val in current.ReasonReference) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Request != null) { writer.WritePropertyName("request"); current.Request.SerializeJson(writer, options); } if ((current.Device != null) && (current.Device.Count != 0)) { writer.WritePropertyName("device"); writer.WriteStartArray(); foreach (ResourceReference val in current.Device) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((current.Note != null) && (current.Note.Count != 0)) { writer.WritePropertyName("note"); writer.WriteStartArray(); foreach (Annotation val in current.Note) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (current.Dosage != null) { writer.WritePropertyName("dosage"); current.Dosage.SerializeJson(writer, options); } if ((current.EventHistory != null) && (current.EventHistory.Count != 0)) { writer.WritePropertyName("eventHistory"); writer.WriteStartArray(); foreach (ResourceReference val in current.EventHistory) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR MedicationAdministration /// </summary> public static void DeserializeJsonProperty(this MedicationAdministration current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Identifier = new List <Identifier>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.Identifier v_Identifier = new Hl7.Fhir.Model.Identifier(); v_Identifier.DeserializeJson(ref reader, options); current.Identifier.Add(v_Identifier); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'identifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Identifier.Count == 0) { current.Identifier = null; } break; case "instantiates": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'instantiates' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.InstantiatesElement = new List <FhirUri>(); while (reader.TokenType != JsonTokenType.EndArray) { if (reader.TokenType == JsonTokenType.Null) { current.InstantiatesElement.Add(new FhirUri()); reader.Skip(); } else { current.InstantiatesElement.Add(new FhirUri(reader.GetString())); } if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'instantiates' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.InstantiatesElement.Count == 0) { current.InstantiatesElement = null; } break; case "_instantiates": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'instantiates' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } int i_instantiates = 0; while (reader.TokenType != JsonTokenType.EndArray) { if (i_instantiates >= current.InstantiatesElement.Count) { current.InstantiatesElement.Add(new FhirUri()); } if (reader.TokenType == JsonTokenType.Null) { reader.Skip(); } else { ((Hl7.Fhir.Model.Element)current.InstantiatesElement[i_instantiates++]).DeserializeJson(ref reader, options); } if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'instantiates' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } break; case "partOf": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'partOf' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.PartOf = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_PartOf = new Hl7.Fhir.Model.ResourceReference(); v_PartOf.DeserializeJson(ref reader, options); current.PartOf.Add(v_PartOf); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'partOf' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.PartOf.Count == 0) { current.PartOf = null; } break; case "status": if (reader.TokenType == JsonTokenType.Null) { current.StatusElement = new Code <Hl7.Fhir.Model.MedicationAdministration.MedicationAdministrationStatusCodes>(); reader.Skip(); } else { current.StatusElement = new Code <Hl7.Fhir.Model.MedicationAdministration.MedicationAdministrationStatusCodes>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.MedicationAdministration.MedicationAdministrationStatusCodes>(reader.GetString())); } break; case "_status": if (current.StatusElement == null) { current.StatusElement = new Code <Hl7.Fhir.Model.MedicationAdministration.MedicationAdministrationStatusCodes>(); } ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options); break; case "statusReason": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'statusReason' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.StatusReason = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_StatusReason = new Hl7.Fhir.Model.CodeableConcept(); v_StatusReason.DeserializeJson(ref reader, options); current.StatusReason.Add(v_StatusReason); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'statusReason' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.StatusReason.Count == 0) { current.StatusReason = null; } break; case "category": current.Category = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Category).DeserializeJson(ref reader, options); break; case "medicationCodeableConcept": current.Medication = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.Medication).DeserializeJson(ref reader, options); break; case "medicationReference": current.Medication = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Medication).DeserializeJson(ref reader, options); break; case "subject": current.Subject = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Subject).DeserializeJson(ref reader, options); break; case "context": current.Context = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Context).DeserializeJson(ref reader, options); break; case "supportingInformation": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'supportingInformation' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.SupportingInformation = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_SupportingInformation = new Hl7.Fhir.Model.ResourceReference(); v_SupportingInformation.DeserializeJson(ref reader, options); current.SupportingInformation.Add(v_SupportingInformation); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'supportingInformation' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.SupportingInformation.Count == 0) { current.SupportingInformation = null; } break; case "effectiveDateTime": if (reader.TokenType == JsonTokenType.Null) { current.Effective = new FhirDateTime(); reader.Skip(); } else { current.Effective = new FhirDateTime(reader.GetString()); } break; case "_effectiveDateTime": if (current.Effective == null) { current.Effective = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.Effective).DeserializeJson(ref reader, options); break; case "effectivePeriod": current.Effective = new Hl7.Fhir.Model.Period(); ((Hl7.Fhir.Model.Period)current.Effective).DeserializeJson(ref reader, options); break; case "performer": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'performer' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Performer = new List <MedicationAdministration.PerformerComponent>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.MedicationAdministration.PerformerComponent v_Performer = new Hl7.Fhir.Model.MedicationAdministration.PerformerComponent(); v_Performer.DeserializeJson(ref reader, options); current.Performer.Add(v_Performer); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'performer' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Performer.Count == 0) { current.Performer = null; } break; case "reasonCode": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'reasonCode' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ReasonCode = new List <CodeableConcept>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.CodeableConcept v_ReasonCode = new Hl7.Fhir.Model.CodeableConcept(); v_ReasonCode.DeserializeJson(ref reader, options); current.ReasonCode.Add(v_ReasonCode); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'reasonCode' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ReasonCode.Count == 0) { current.ReasonCode = null; } break; case "reasonReference": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'reasonReference' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.ReasonReference = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_ReasonReference = new Hl7.Fhir.Model.ResourceReference(); v_ReasonReference.DeserializeJson(ref reader, options); current.ReasonReference.Add(v_ReasonReference); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'reasonReference' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.ReasonReference.Count == 0) { current.ReasonReference = null; } break; case "request": current.Request = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Request).DeserializeJson(ref reader, options); break; case "device": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'device' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Device = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_Device = new Hl7.Fhir.Model.ResourceReference(); v_Device.DeserializeJson(ref reader, options); current.Device.Add(v_Device); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'device' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Device.Count == 0) { current.Device = null; } break; case "note": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'note' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Note = new List <Annotation>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.Annotation v_Note = new Hl7.Fhir.Model.Annotation(); v_Note.DeserializeJson(ref reader, options); current.Note.Add(v_Note); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'note' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Note.Count == 0) { current.Note = null; } break; case "dosage": current.Dosage = new Hl7.Fhir.Model.MedicationAdministration.DosageComponent(); ((Hl7.Fhir.Model.MedicationAdministration.DosageComponent)current.Dosage).DeserializeJson(ref reader, options); break; case "eventHistory": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"MedicationAdministration error reading 'eventHistory' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.EventHistory = new List <ResourceReference>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.ResourceReference v_EventHistory = new Hl7.Fhir.Model.ResourceReference(); v_EventHistory.DeserializeJson(ref reader, options); current.EventHistory.Add(v_EventHistory); if (!reader.Read()) { throw new JsonException($"MedicationAdministration error reading 'eventHistory' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.EventHistory.Count == 0) { current.EventHistory = null; } break; // Complex: MedicationAdministration, Export: MedicationAdministration, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }