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

            throw new JsonException($"Composition.RelatesToComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serialize a FHIR Composition#RelatesTo into JSON
        /// </summary>
        public static void SerializeJson(this Composition.RelatesToComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: Composition#RelatesTo, Export: RelatesToComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            writer.WriteString("code", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.CodeElement.Value));

            if (current.Target != null)
            {
                switch (current.Target)
                {
                case Identifier v_Identifier:
                    writer.WritePropertyName("targetIdentifier");
                    v_Identifier.SerializeJson(writer, options);
                    break;

                case ResourceReference v_ResourceReference:
                    writer.WritePropertyName("targetReference");
                    v_ResourceReference.SerializeJson(writer, options);
                    break;
                }
            }
            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserialize JSON into a FHIR Composition#RelatesTo
        /// </summary>
        public static void DeserializeJsonProperty(this Composition.RelatesToComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "code":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.CodeElement = new Code <Hl7.Fhir.Model.DocumentRelationshipType>();
                    reader.Skip();
                }
                else
                {
                    current.CodeElement = new Code <Hl7.Fhir.Model.DocumentRelationshipType>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.DocumentRelationshipType>(reader.GetString()));
                }
                break;

            case "_code":
                if (current.CodeElement == null)
                {
                    current.CodeElement = new Code <Hl7.Fhir.Model.DocumentRelationshipType>();
                }
                ((Hl7.Fhir.Model.Element)current.CodeElement).DeserializeJson(ref reader, options);
                break;

            case "targetIdentifier":
                current.Target = new Hl7.Fhir.Model.Identifier();
                ((Hl7.Fhir.Model.Identifier)current.Target).DeserializeJson(ref reader, options);
                break;

            case "targetReference":
                current.Target = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Target).DeserializeJson(ref reader, options);
                break;

            // Complex: relatesTo, Export: RelatesToComponent, Base: BackboneElement
            default:
                ((Hl7.Fhir.Model.BackboneElement)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
Exemplo n.º 4
0
        Composition CreateComposition(ResourceReference subject, ResourceReference author, DateTime date)
        {
            var comp = new Composition();

            comp.Meta = new Meta()
            {
                Profile = new string[] { RndsStructureDefinition.BRResultadoExameLaboratorial }
            };
            comp.Status = CompositionStatus.Final;
            comp.Type   = new CodeableConcept(RndsCodeSystem.BRTipoDocumento, $"{DocumentType}");

            comp.Author.Add(author);

            comp.Subject = subject;

            comp.Title = Title;
            comp.Date  = date.ToString("yyyy-MM-ddThh:mm:ss.fffzzz");

            if (!string.IsNullOrEmpty(RelatesTo))
            {
                var rt = new Composition.RelatesToComponent();
                rt.Code   = DocumentRelationshipType.Replaces;
                rt.Target = new ResourceReference($"Composition/{RelatesTo}");

                comp.RelatesTo.Add(rt);
            }

            var section = new Composition.SectionComponent();

            section.Entry = new List <ResourceReference>();
            section.Entry.Add(new ResourceReference(RndsUrls.ObservationUrl));

            comp.Section.Add(section);

            return(comp);
        }