Exemple #1
0
        /// <summary>
        /// Serialize a FHIR Location#Position into JSON
        /// </summary>
        public static void SerializeJson(this Location.PositionComponent current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            // Component: Location#Position, Export: PositionComponent, Base: BackboneElement (BackboneElement)
            ((Hl7.Fhir.Model.BackboneElement)current).SerializeJson(writer, options, false);

            writer.WriteNumber("longitude", (decimal)current.LongitudeElement.Value);

            writer.WriteNumber("latitude", (decimal)current.LatitudeElement.Value);

            if (current.AltitudeElement != null)
            {
                if (current.AltitudeElement.Value != null)
                {
                    writer.WriteNumber("altitude", (decimal)current.AltitudeElement.Value);
                }
                if (current.AltitudeElement.HasExtensions() || (!string.IsNullOrEmpty(current.AltitudeElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_altitude", false, current.AltitudeElement.Extension, current.AltitudeElement.ElementId);
                }
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemple #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR Location#Position
        /// </summary>
        public static void DeserializeJson(this Location.PositionComponent 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($"Location.PositionComponent >>> Location#Position.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"Location.PositionComponent: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
Exemple #3
0
        private static List <Expression> ToExpressions(Location.PositionComponent element)
        {
            if (element == null || element.Latitude == null && element.Longitude == null)
            {
                return(null);
            }

            var position = new List <IndexValue>
            {
                new("latitude", new NumberValue(element.Latitude.Value)),
                new("longitude", new NumberValue(element.Longitude.Value))
            };

            return(ListOf(new CompositeValue(position)));
        }
        /// <summary>Root location for organization.</summary>
        /// <param name="org">The organization.</param>
        /// <returns>A Location.</returns>
        public static Location RootLocationForOrg(
            Organization org)
        {
            if (org == null)
            {
                throw new ArgumentNullException(nameof(org));
            }

            if ((org.Address == null) || (org.Address.Count == 0))
            {
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                throw new ArgumentException("Organization Address is required!");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
            }

            Location.PositionComponent position = null;

            if (HospitalManager.IsHospitalKnown(org.Id))
            {
                position = HospitalManager.PositionForHospital(org.Id);
            }
            else if (GeoManager.IsPostalCodeKnown(org.Address[0].PostalCode))
            {
                position = GeoManager.PositionForPostalCode(org.Address[0].PostalCode);
            }

            return(new Location()
            {
                Meta = new Hl7.Fhir.Model.Meta()
                {
                    Security = FhirTriplet.SecurityTest.GetCodingList(),
                },
                Id = IdForOrgRootLocation(org.Id),
                Address = org.Address[0],
                Status = GetLocationStatus(AvailabilityStatusActive),
                Mode = Location.LocationMode.Instance,
                PhysicalType = FhirTriplet.PhysicalTypeSite.GetConcept(),
                Position = position,
                ManagingOrganization = new ResourceReference($"{org.ResourceType}/{org.Id}"),
                Type = FhirGenerator.ConceptListForServiceLocationType(),
                Name = $"{org.Name} Building",
            });
        }
Exemple #5
0
        /// <summary>
        /// Deserialize JSON into a FHIR Location#Position
        /// </summary>
        public static void DeserializeJsonProperty(this Location.PositionComponent current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "longitude":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.LongitudeElement = new FhirDecimal();
                    reader.Skip();
                }
                else
                {
                    current.LongitudeElement = new FhirDecimal(reader.GetDecimal());
                }
                break;

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

            case "latitude":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.LatitudeElement = new FhirDecimal();
                    reader.Skip();
                }
                else
                {
                    current.LatitudeElement = new FhirDecimal(reader.GetDecimal());
                }
                break;

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

            case "altitude":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.AltitudeElement = new FhirDecimal();
                    reader.Skip();
                }
                else
                {
                    current.AltitudeElement = new FhirDecimal(reader.GetDecimal());
                }
                break;

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

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