Ejemplo n.º 1
0
        /// <summary>
        /// Converts a <see cref="FhirHumanName" /> instance to an <see cref="EntityName" /> instance.
        /// </summary>
        /// <param name="fhirHumanName">The name of the human.</param>
        /// <returns>Returns an entity name instance.</returns>
        /// <exception cref="System.InvalidOperationException">Unable to locate service</exception>
        public static EntityName ToEntityName(FhirHumanName fhirHumanName)
        {
            traceSource.TraceEvent(EventLevel.Verbose, "Mapping FHIR human name");

            var name = new EntityName
            {
                NameUseKey = ToConcept(fhirHumanName.Use ?? "official", "http://hl7.org/fhir/name-use")?.Key
            };

            name.Component.AddRange(fhirHumanName.Family.Select(f => new EntityNameComponent(NameComponentKeys.Family, f.Value)));
            name.Component.AddRange(fhirHumanName.Given.Select(g => new EntityNameComponent(NameComponentKeys.Given, g.Value)));
            name.Component.AddRange(fhirHumanName.Prefix.Select(p => new EntityNameComponent(NameComponentKeys.Prefix, p.Value)));
            name.Component.AddRange(fhirHumanName.Suffix.Select(s => new EntityNameComponent(NameComponentKeys.Suffix, s.Value)));

            return(name);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts an <see cref="EntityName"/> instance to a <see cref="FhirHumanName"/> instance.
        /// </summary>
        /// <param name="entityName">Name of the entity.</param>
        /// <returns>Returns the mapped FHIR human name.</returns>
        public static FhirHumanName ToFhirHumanName(EntityName entityName)
        {
            traceSource.TraceEvent(EventLevel.Verbose, "Mapping entity name");

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

            // Return value
            var retVal = new FhirHumanName
            {
                Use = DataTypeConverter.ToFhirCodeableConcept(entityName.NameUse, "http://hl7.org/fhir/name-use")?.GetPrimaryCode()?.Code
            };

            // Process components
            foreach (var com in entityName.LoadCollection <EntityNameComponent>(nameof(EntityName.Component)))
            {
                if (string.IsNullOrEmpty(com.Value))
                {
                    continue;
                }

                if (com.ComponentTypeKey == NameComponentKeys.Given)
                {
                    retVal.Given.Add(com.Value);
                }
                else if (com.ComponentTypeKey == NameComponentKeys.Family)
                {
                    retVal.Family.Add(com.Value);
                }
                else if (com.ComponentTypeKey == NameComponentKeys.Prefix)
                {
                    retVal.Prefix.Add(com.Value);
                }
                else if (com.ComponentTypeKey == NameComponentKeys.Suffix)
                {
                    retVal.Suffix.Add(com.Value);
                }
            }

            return(retVal);
        }