コード例 #1
0
        /// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductInteraction
        /// </summary>
        public static void DeserializeJson(this MedicinalProductInteraction 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($"MedicinalProductInteraction >>> MedicinalProductInteraction.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"MedicinalProductInteraction: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
コード例 #2
0
        /// <summary>
        /// Serialize a FHIR MedicinalProductInteraction into JSON
        /// </summary>
        public static void SerializeJson(this MedicinalProductInteraction current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "MedicinalProductInteraction");
            // Complex: MedicinalProductInteraction, Export: MedicinalProductInteraction, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

            if ((current.Subject != null) && (current.Subject.Count != 0))
            {
                writer.WritePropertyName("subject");
                writer.WriteStartArray();
                foreach (ResourceReference val in current.Subject)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (current.DescriptionElement != null)
            {
                if (!string.IsNullOrEmpty(current.DescriptionElement.Value))
                {
                    writer.WriteString("description", current.DescriptionElement.Value);
                }
                if (current.DescriptionElement.HasExtensions() || (!string.IsNullOrEmpty(current.DescriptionElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_description", false, current.DescriptionElement.Extension, current.DescriptionElement.ElementId);
                }
            }

            if ((current.Interactant != null) && (current.Interactant.Count != 0))
            {
                writer.WritePropertyName("interactant");
                writer.WriteStartArray();
                foreach (MedicinalProductInteraction.InteractantComponent val in current.Interactant)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (current.Type != null)
            {
                writer.WritePropertyName("type");
                current.Type.SerializeJson(writer, options);
            }

            if (current.Effect != null)
            {
                writer.WritePropertyName("effect");
                current.Effect.SerializeJson(writer, options);
            }

            if (current.Incidence != null)
            {
                writer.WritePropertyName("incidence");
                current.Incidence.SerializeJson(writer, options);
            }

            if (current.Management != null)
            {
                writer.WritePropertyName("management");
                current.Management.SerializeJson(writer, options);
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
コード例 #3
0
        /// <summary>
        /// Deserialize JSON into a FHIR MedicinalProductInteraction
        /// </summary>
        public static void DeserializeJsonProperty(this MedicinalProductInteraction current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "subject":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductInteraction error reading 'subject' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Subject = new List <ResourceReference>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ResourceReference v_Subject = new Hl7.Fhir.Model.ResourceReference();
                    v_Subject.DeserializeJson(ref reader, options);
                    current.Subject.Add(v_Subject);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductInteraction error reading 'subject' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Subject.Count == 0)
                {
                    current.Subject = null;
                }
                break;

            case "description":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DescriptionElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.DescriptionElement = new FhirString(reader.GetString());
                }
                break;

            case "_description":
                if (current.DescriptionElement == null)
                {
                    current.DescriptionElement = new FhirString();
                }
                ((Hl7.Fhir.Model.Element)current.DescriptionElement).DeserializeJson(ref reader, options);
                break;

            case "interactant":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"MedicinalProductInteraction error reading 'interactant' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Interactant = new List <MedicinalProductInteraction.InteractantComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.MedicinalProductInteraction.InteractantComponent v_Interactant = new Hl7.Fhir.Model.MedicinalProductInteraction.InteractantComponent();
                    v_Interactant.DeserializeJson(ref reader, options);
                    current.Interactant.Add(v_Interactant);

                    if (!reader.Read())
                    {
                        throw new JsonException($"MedicinalProductInteraction error reading 'interactant' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Interactant.Count == 0)
                {
                    current.Interactant = null;
                }
                break;

            case "type":
                current.Type = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options);
                break;

            case "effect":
                current.Effect = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Effect).DeserializeJson(ref reader, options);
                break;

            case "incidence":
                current.Incidence = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Incidence).DeserializeJson(ref reader, options);
                break;

            case "management":
                current.Management = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Management).DeserializeJson(ref reader, options);
                break;

            // Complex: MedicinalProductInteraction, Export: MedicinalProductInteraction, Base: DomainResource
            default:
                ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }