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

            throw new JsonException($"Goal.TargetComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Exemple #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR Goal#Target
        /// </summary>
        public static void DeserializeJsonProperty(this Goal.TargetComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "measure":
                current.Measure = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Measure).DeserializeJson(ref reader, options);
                break;

            case "detailQuantity":
                current.Detail = new Hl7.Fhir.Model.Quantity();
                ((Hl7.Fhir.Model.Quantity)current.Detail).DeserializeJson(ref reader, options);
                break;

            case "detailRange":
                current.Detail = new Hl7.Fhir.Model.Range();
                ((Hl7.Fhir.Model.Range)current.Detail).DeserializeJson(ref reader, options);
                break;

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

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

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

            case "detailBoolean":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.Detail = new FhirBoolean();
                    reader.Skip();
                }
                else
                {
                    current.Detail = new FhirBoolean(reader.GetBoolean());
                }
                break;

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

            case "detailInteger":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.Detail = new Integer();
                    reader.Skip();
                }
                else
                {
                    current.Detail = new Integer(reader.GetInt32());
                }
                break;

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

            case "detailRatio":
                current.Detail = new Hl7.Fhir.Model.Ratio();
                ((Hl7.Fhir.Model.Ratio)current.Detail).DeserializeJson(ref reader, options);
                break;

            case "dueDate":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.Due = new Date();
                    reader.Skip();
                }
                else
                {
                    current.Due = new Date(reader.GetString());
                }
                break;

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

            case "dueDuration":
                current.Due = new Hl7.Fhir.Model.Duration();
                ((Hl7.Fhir.Model.Duration)current.Due).DeserializeJson(ref reader, options);
                break;

            // Complex: target, Export: TargetComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
Exemple #3
0
        /// <summary>
        /// Serialize a FHIR Goal#Target into JSON
        /// </summary>
        public static void SerializeJson(this Goal.TargetComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: Goal#Target, Export: TargetComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

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

            if (current.Detail != null)
            {
                switch (current.Detail)
                {
                case Quantity v_Quantity:
                    writer.WritePropertyName("detailQuantity");
                    v_Quantity.SerializeJson(writer, options);
                    break;

                case Range v_Range:
                    writer.WritePropertyName("detailRange");
                    v_Range.SerializeJson(writer, options);
                    break;

                case CodeableConcept v_CodeableConcept:
                    writer.WritePropertyName("detailCodeableConcept");
                    v_CodeableConcept.SerializeJson(writer, options);
                    break;

                case FhirString v_FhirString:
                    if (v_FhirString != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirString.Value))
                        {
                            writer.WriteString("detailString", v_FhirString.Value);
                        }
                        if (v_FhirString.HasExtensions() || (!string.IsNullOrEmpty(v_FhirString.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_detailString", false, v_FhirString.Extension, v_FhirString.ElementId);
                        }
                    }
                    break;

                case FhirBoolean v_FhirBoolean:
                    if (v_FhirBoolean != null)
                    {
                        if (v_FhirBoolean.Value != null)
                        {
                            writer.WriteBoolean("detailBoolean", (bool)v_FhirBoolean.Value);
                        }
                        if (v_FhirBoolean.HasExtensions() || (!string.IsNullOrEmpty(v_FhirBoolean.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_detailBoolean", false, v_FhirBoolean.Extension, v_FhirBoolean.ElementId);
                        }
                    }
                    break;

                case Integer v_Integer:
                    if (v_Integer != null)
                    {
                        if (v_Integer.Value != null)
                        {
                            writer.WriteNumber("detailInteger", (int)v_Integer.Value);
                        }
                        if (v_Integer.HasExtensions() || (!string.IsNullOrEmpty(v_Integer.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_detailInteger", false, v_Integer.Extension, v_Integer.ElementId);
                        }
                    }
                    break;

                case Ratio v_Ratio:
                    writer.WritePropertyName("detailRatio");
                    v_Ratio.SerializeJson(writer, options);
                    break;
                }
            }
            if (current.Due != null)
            {
                switch (current.Due)
                {
                case Date v_Date:
                    if (v_Date != null)
                    {
                        if (!string.IsNullOrEmpty(v_Date.Value))
                        {
                            writer.WriteString("dueDate", v_Date.Value);
                        }
                        if (v_Date.HasExtensions() || (!string.IsNullOrEmpty(v_Date.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_dueDate", false, v_Date.Extension, v_Date.ElementId);
                        }
                    }
                    break;

                case Duration v_Duration:
                    writer.WritePropertyName("dueDuration");
                    v_Duration.SerializeJson(writer, options);
                    break;
                }
            }
            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }