/// <summary>
        /// Maps the outbound resource to FHIR.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns>Returns the mapped FHIR resource.</returns>
        protected override ImmunizationRecommendation MapToFhir(SubstanceAdministration model)
        {
            ImmunizationRecommendation retVal = new ImmunizationRecommendation();

            retVal.Id          = model.Key.ToString();
            retVal.DateElement = new FhirDateTime(DateTimeOffset.Now);
            retVal.Identifier  = model.Identifiers.Select(o => DataTypeConverter.ToFhirIdentifier(o)).ToList();

            var rct = model.LoadCollection <ActParticipation>(nameof(Act.Participations)).FirstOrDefault(o => o.ParticipationRoleKey == ActParticipationKey.RecordTarget)?.LoadProperty <Entity>(nameof(ActParticipation.PlayerEntity));

            if (rct != null)
            {
                retVal.Patient = DataTypeConverter.CreateNonVersionedReference <Patient>(rct);
            }

            var mat = model.Participations.FirstOrDefault(o => o.ParticipationRoleKey == ActParticipationKey.Product).PlayerEntity;

            // Recommend
            string status         = (model.StopTime ?? model.ActTime) < DateTimeOffset.Now ? "overdue" : "due";
            var    recommendation = new ImmunizationRecommendation.RecommendationComponent()
            {
                DoseNumber  = new PositiveInt(model.SequenceId),
                VaccineCode = new List <CodeableConcept>()
                {
                    DataTypeConverter.ToFhirCodeableConcept(mat?.TypeConceptKey)
                },
                ForecastStatus = new CodeableConcept("http://hl7.org/fhir/conceptset/immunization-recommendation-status", status),
                DateCriterion  = new List <ImmunizationRecommendation.DateCriterionComponent>()
                {
                    new ImmunizationRecommendation.DateCriterionComponent()
                    {
                        Code         = new CodeableConcept("http://hl7.org/fhir/conceptset/immunization-recommendation-date-criterion", "recommended"),
                        ValueElement = new FhirDateTime(model.ActTime)
                    }
                }
            };

            if (model.StartTime.HasValue)
            {
                recommendation.DateCriterion.Add(new ImmunizationRecommendation.DateCriterionComponent()
                {
                    Code         = new CodeableConcept("http://hl7.org/fhir/conceptset/immunization-recommendation-date-criterion", "earliest"),
                    ValueElement = new FhirDateTime(model.StartTime.Value)
                });
            }
            if (model.StopTime.HasValue)
            {
                recommendation.DateCriterion.Add(new ImmunizationRecommendation.DateCriterionComponent()
                {
                    Code         = new CodeableConcept("http://hl7.org/fhir/conceptset/immunization-recommendation-date-criterion", "overdue"),
                    ValueElement = new FhirDateTime(model.StopTime.Value)
                });
            }

            retVal.Recommendation = new List <ImmunizationRecommendation.RecommendationComponent>()
            {
                recommendation
            };
            return(retVal);
        }
Exemple #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR ImmunizationRecommendation#Recommendation
        /// </summary>
        public static void DeserializeJson(this ImmunizationRecommendation.RecommendationComponent 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($"ImmunizationRecommendation.RecommendationComponent >>> ImmunizationRecommendation#Recommendation.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"ImmunizationRecommendation.RecommendationComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Exemple #3
0
        /// <summary>
        /// Deserialize JSON into a FHIR ImmunizationRecommendation#Recommendation
        /// </summary>
        public static void DeserializeJsonProperty(this ImmunizationRecommendation.RecommendationComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "vaccineCode":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"RecommendationComponent error reading 'vaccineCode' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.VaccineCode = new List <CodeableConcept>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.CodeableConcept v_VaccineCode = new Hl7.Fhir.Model.CodeableConcept();
                    v_VaccineCode.DeserializeJson(ref reader, options);
                    current.VaccineCode.Add(v_VaccineCode);

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

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

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

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

                current.ContraindicatedVaccineCode = new List <CodeableConcept>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.CodeableConcept v_ContraindicatedVaccineCode = new Hl7.Fhir.Model.CodeableConcept();
                    v_ContraindicatedVaccineCode.DeserializeJson(ref reader, options);
                    current.ContraindicatedVaccineCode.Add(v_ContraindicatedVaccineCode);

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

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

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

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

                current.ForecastReason = new List <CodeableConcept>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.CodeableConcept v_ForecastReason = new Hl7.Fhir.Model.CodeableConcept();
                    v_ForecastReason.DeserializeJson(ref reader, options);
                    current.ForecastReason.Add(v_ForecastReason);

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

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

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

                current.DateCriterion = new List <ImmunizationRecommendation.DateCriterionComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ImmunizationRecommendation.DateCriterionComponent v_DateCriterion = new Hl7.Fhir.Model.ImmunizationRecommendation.DateCriterionComponent();
                    v_DateCriterion.DeserializeJson(ref reader, options);
                    current.DateCriterion.Add(v_DateCriterion);

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

                if (current.DateCriterion.Count == 0)
                {
                    current.DateCriterion = 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 "series":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.SeriesElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.SeriesElement = new FhirString(reader.GetString());
                }
                break;

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

            case "doseNumberPositiveInt":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DoseNumber = new PositiveInt();
                    reader.Skip();
                }
                else
                {
                    current.DoseNumber = new PositiveInt(reader.GetInt32());
                }
                break;

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

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

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

            case "seriesDosesPositiveInt":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.SeriesDoses = new PositiveInt();
                    reader.Skip();
                }
                else
                {
                    current.SeriesDoses = new PositiveInt(reader.GetInt32());
                }
                break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            writer.WritePropertyName("forecastStatus");
            current.ForecastStatus.SerializeJson(writer, options);

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

            if ((current.DateCriterion != null) && (current.DateCriterion.Count != 0))
            {
                writer.WritePropertyName("dateCriterion");
                writer.WriteStartArray();
                foreach (ImmunizationRecommendation.DateCriterionComponent val in current.DateCriterion)
                {
                    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.SeriesElement != null)
            {
                if (!string.IsNullOrEmpty(current.SeriesElement.Value))
                {
                    writer.WriteString("series", current.SeriesElement.Value);
                }
                if (current.SeriesElement.HasExtensions() || (!string.IsNullOrEmpty(current.SeriesElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_series", false, current.SeriesElement.Extension, current.SeriesElement.ElementId);
                }
            }

            if (current.DoseNumber != null)
            {
                switch (current.DoseNumber)
                {
                case PositiveInt v_PositiveInt:
                    if (v_PositiveInt != null)
                    {
                        if (v_PositiveInt.Value != null)
                        {
                            writer.WriteNumber("doseNumberPositiveInt", (int)v_PositiveInt.Value);
                        }
                        if (v_PositiveInt.HasExtensions() || (!string.IsNullOrEmpty(v_PositiveInt.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_doseNumberPositiveInt", false, v_PositiveInt.Extension, v_PositiveInt.ElementId);
                        }
                    }
                    break;

                case FhirString v_FhirString:
                    if (v_FhirString != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirString.Value))
                        {
                            writer.WriteString("doseNumberString", v_FhirString.Value);
                        }
                        if (v_FhirString.HasExtensions() || (!string.IsNullOrEmpty(v_FhirString.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_doseNumberString", false, v_FhirString.Extension, v_FhirString.ElementId);
                        }
                    }
                    break;
                }
            }
            if (current.SeriesDoses != null)
            {
                switch (current.SeriesDoses)
                {
                case PositiveInt v_PositiveInt:
                    if (v_PositiveInt != null)
                    {
                        if (v_PositiveInt.Value != null)
                        {
                            writer.WriteNumber("seriesDosesPositiveInt", (int)v_PositiveInt.Value);
                        }
                        if (v_PositiveInt.HasExtensions() || (!string.IsNullOrEmpty(v_PositiveInt.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_seriesDosesPositiveInt", false, v_PositiveInt.Extension, v_PositiveInt.ElementId);
                        }
                    }
                    break;

                case FhirString v_FhirString:
                    if (v_FhirString != null)
                    {
                        if (!string.IsNullOrEmpty(v_FhirString.Value))
                        {
                            writer.WriteString("seriesDosesString", v_FhirString.Value);
                        }
                        if (v_FhirString.HasExtensions() || (!string.IsNullOrEmpty(v_FhirString.ElementId)))
                        {
                            JsonStreamUtilities.SerializeExtensionList(writer, options, "_seriesDosesString", false, v_FhirString.Extension, v_FhirString.ElementId);
                        }
                    }
                    break;
                }
            }
            if ((current.SupportingImmunization != null) && (current.SupportingImmunization.Count != 0))
            {
                writer.WritePropertyName("supportingImmunization");
                writer.WriteStartArray();
                foreach (ResourceReference val in current.SupportingImmunization)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

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

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }