Exemplo n.º 1
0
        /// <summary>
        /// Convert address to XAD
        /// </summary>
        public static XAD FromModel(this XAD me, EntityAddress addr)
        {
            var refTerm = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptReferenceTerm(addr.AddressUseKey.GetValueOrDefault(), AddressUseCodeSystem);

            if (refTerm != null)
            {
                me.AddressType.Value = refTerm.Mnemonic;
            }

            var mappedFields = new Dictionary <Guid, String>()
            {
                { AddressComponentKeys.CensusTract, nameof(XAD.CensusTract) },
                { AddressComponentKeys.City, nameof(XAD.City) },
                { AddressComponentKeys.Country, nameof(XAD.Country) },
                { AddressComponentKeys.County, nameof(XAD.CountyParishCode) },
                { AddressComponentKeys.AdditionalLocator, nameof(XAD.OtherDesignation) },
                { AddressComponentKeys.State, nameof(XAD.StateOrProvince) },
                { AddressComponentKeys.StreetAddressLine, nameof(XAD.StreetAddress) },
                { AddressComponentKeys.AddressLine, nameof(XAD.StreetAddress) },
                { AddressComponentKeys.Precinct, nameof(XAD.OtherGeographicDesignation) },
                { AddressComponentKeys.StreetName, nameof(XAD.StreetAddress) },
                { AddressComponentKeys.PostalCode, nameof(XAD.ZipOrPostalCode) },
                { AddressComponentKeys.UnitIdentifier, nameof(XAD.StreetAddress) }
            };

            foreach (var itm in addr.LoadCollection <EntityAddressComponent>("Component"))
            {
                String propertyName = null;
                if (itm.ComponentTypeKey.HasValue && mappedFields.TryGetValue(itm.ComponentTypeKey.Value, out propertyName))
                {
                    var valueItem = typeof(XAD).GetRuntimeProperty(propertyName).GetValue(me);
                    if (valueItem is SAD) // Street address {
                    {
                        var sadItem = valueItem as SAD;
                        if (itm.ComponentTypeKey == AddressComponentKeys.UnitIdentifier)
                        {
                            sadItem.DwellingNumber.Value = itm.Value;
                        }
                        else if (itm.ComponentTypeKey == AddressComponentKeys.StreetName)
                        {
                            sadItem.StreetName.Value = itm.Value;
                        }
                        else if (itm.ComponentTypeKey == AddressComponentKeys.StreetAddressLine || itm.ComponentTypeKey == AddressComponentKeys.AddressLine)
                        {
                            sadItem.StreetOrMailingAddress.Value = itm.Value;
                        }
                    }
                    else if (valueItem is AbstractPrimitive)
                    {
                        (valueItem as AbstractPrimitive).Value = itm.Value;
                    }
                }
            }

            return(me);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get postal code
 /// </summary>
 public static String Value(this EntityAddress me, Guid addressType)
 {
     return(me.LoadCollection <EntityAddressComponent>("Component").FirstOrDefault(o => o.ComponentTypeKey == addressType)?.Value);
 }