示例#1
0
        /// <summary>
        /// Converts an <see cref="EntityAddress"/> instance to a <see cref="FhirAddress"/> instance.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns>Returns a FHIR address.</returns>
        public static FhirAddress ToFhirAddress(EntityAddress address)
        {
            traceSource.TraceEvent(EventLevel.Verbose, "Mapping entity address");

            if (address == null)
            {
                return(null);
            }

            // Return value
            var retVal = new FhirAddress()
            {
                Use  = DataTypeConverter.ToFhirCodeableConcept(address.AddressUse, "http://hl7.org/fhir/address-use")?.GetPrimaryCode()?.Code,
                Line = new List <FhirString>()
            };

            // Process components
            foreach (var com in address.LoadCollection <EntityAddressComponent>(nameof(EntityAddress.Component)))
            {
                if (com.ComponentTypeKey == AddressComponentKeys.City)
                {
                    retVal.City = com.Value;
                }
                else if (com.ComponentTypeKey == AddressComponentKeys.Country)
                {
                    retVal.Country = com.Value;
                }
                else if (com.ComponentTypeKey == AddressComponentKeys.AddressLine ||
                         com.ComponentTypeKey == AddressComponentKeys.StreetAddressLine)
                {
                    retVal.Line.Add(com.Value);
                }
                else if (com.ComponentTypeKey == AddressComponentKeys.State)
                {
                    retVal.State = com.Value;
                }
                else if (com.ComponentTypeKey == AddressComponentKeys.PostalCode)
                {
                    retVal.Zip = com.Value;
                }
                else
                {
                    retVal.Extension.Add(new Extension()
                    {
                        Url   = FhirConstants.SanteDBProfile + "#address-" + com.LoadProperty <Concept>(nameof(EntityAddressComponent.ComponentType)).Mnemonic,
                        Value = new FhirString(com.Value)
                    });
                }
            }

            return(retVal);
        }
示例#2
0
        /// <summary>
        /// Converts an <see cref="FhirAddress"/> instance to an <see cref="EntityAddress"/> instance.
        /// </summary>
        /// <param name="fhirAddress">The FHIR address.</param>
        /// <returns>Returns an entity address instance.</returns>
        public static EntityAddress ToEntityAddress(FhirAddress fhirAddress)
        {
            traceSource.TraceEvent(EventLevel.Verbose, "Mapping FHIR address");

            var address = new EntityAddress
            {
                AddressUseKey = ToConcept(fhirAddress.Use ?? "home", "http://hl7.org/fhir/address-use")?.Key
            };

            if (fhirAddress.City?.Value != null)
            {
                address.Component.Add(new EntityAddressComponent(AddressComponentKeys.City, fhirAddress.City.Value));
            }

            if (fhirAddress.Country?.Value != null)
            {
                address.Component.Add(new EntityAddressComponent(AddressComponentKeys.Country, fhirAddress.Country.Value));
            }

            if (fhirAddress.Line?.Any() == true)
            {
                address.Component.AddRange(fhirAddress.Line.Select(a => new EntityAddressComponent(AddressComponentKeys.AddressLine, a.Value)));
            }

            if (fhirAddress.State?.Value != null)
            {
                address.Component.Add(new EntityAddressComponent(AddressComponentKeys.State, fhirAddress.State.Value));
            }

            if (fhirAddress.Zip?.Value != null)
            {
                address.Component.Add(new EntityAddressComponent(AddressComponentKeys.PostalCode, fhirAddress.Zip.Value));
            }

            return(address);
        }