Esempio n. 1
0
        /// <summary>
        /// Convert a telecom address
        /// </summary>
        internal TelecommunicationsAddress ConvertTelecom(Telecom tel, List <IResultDetail> dtls)
        {
            var retVal = new TelecommunicationsAddress();

            if (tel.Use != null)
            {
                retVal.Use = MARC.Everest.Connectors.Util.ToWireFormat(HackishCodeMapping.Lookup(HackishCodeMapping.TELECOM_USE, tel.Use));
                // Extensions
                retVal.Use += ExtensionUtil.ParseTELUseExtension(tel.Extension, dtls);
            }
            if (String.IsNullOrEmpty(tel.Value))
            {
                dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, "Telecommunications address must carry a value", "telecom"));
            }
            else
            {
                retVal.Value = tel.Value;
                if (tel.System.Value == "phone" && !retVal.Value.StartsWith("tel:"))
                {
                    dtls.Add(new ValidationResultDetail(ResultDetailType.Error, "Telecommunications address must start with tel: when system is phone", null, null));
                }
                else if (tel.System.Value == "email" && !retVal.Value.StartsWith("mailto:"))
                {
                    dtls.Add(new ValidationResultDetail(ResultDetailType.Error, "Telecommunications address must start with mailto: when system is email", null, null));
                }
            }
            if (tel.Period != null)
            {
                dtls.Add(new UnsupportedFhirDatatypePropertyResultDetail(ResultDetailType.Warning, "Period", "Name"));
                tel.Period = null;
            }

            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Convert a name
        /// </summary>
        internal NameSet ConvertName(HumanName name, List <IResultDetail> dtls)
        {
            NameSet retVal = new NameSet();

            if (name.Use != null)
            {
                retVal.Use  = HackishCodeMapping.Lookup(HackishCodeMapping.NAME_USE, name.Use);
                retVal.Use |= ExtensionUtil.ParsePNUseExtension(name.Use.Extension, dtls);
            }

            // Name text
            if (name.Text != null)
            {
                dtls.Add(new UnsupportedFhirDatatypePropertyResultDetail(ResultDetailType.Warning, "Text", "Name"));
                name.Text = null;
            }

            foreach (var fn in name.Family)
            {
                retVal.Parts.Add(new NamePart()
                {
                    Type = NamePart.NamePartType.Family, Value = fn
                });
            }
            foreach (var sfx in name.Suffix)
            {
                retVal.Parts.Add(new NamePart()
                {
                    Type = NamePart.NamePartType.Suffix, Value = sfx
                });
            }
            foreach (var gn in name.Given)
            {
                retVal.Parts.Add(new NamePart()
                {
                    Type = NamePart.NamePartType.Given, Value = gn
                });
            }
            foreach (var pfx in name.Prefix)
            {
                retVal.Parts.Add(new NamePart()
                {
                    Type = NamePart.NamePartType.Prefix, Value = pfx
                });
            }

            retVal.Parts.RemoveAll(o => String.IsNullOrEmpty(o.Value));
            // Use period
            if (name.Period != null)
            {
                dtls.Add(new UnsupportedFhirDatatypePropertyResultDetail(ResultDetailType.Warning, "Period", "Name"));
                name.Period = null;
            }

            return(retVal);
        }
Esempio n. 3
0
        /// <summary>
        /// Convert address set
        /// </summary>
        internal List <Address> ConvertAddressSet(AddressSet addr)
        {
            List <Address> retVal = new List <Address>();

            foreach (var use in Enum.GetValues(typeof(AddressSet.AddressSetUse)))
            {
                if (((int)use == 0 && addr.Use == 0) ^ ((int)use != 0 && addr.Use.HasFlag((AddressSet.AddressSetUse)use)))
                {
                    Address adEntry = new Address();
                    // An address can have multiple uses
                    if ((AddressSet.AddressSetUse)use != AddressSet.AddressSetUse.Search)
                    {
                        adEntry.Use = new PrimitiveCode <string>(HackishCodeMapping.ReverseLookup(HackishCodeMapping.ADDRESS_USE, (AddressSet.AddressSetUse)use));
                        if (adEntry.Use == null || adEntry.Use.Value == null)
                        {
                            adEntry.Use = new PrimitiveCode <string>();
                            adEntry.Use.Extension.Add(ExtensionUtil.CreateADUseExtension((AddressSet.AddressSetUse)use));
                        }
                    }

                    foreach (var pt in addr.Parts)
                    {
                        switch (pt.PartType)
                        {
                        case AddressPart.AddressPartType.AddressLine:
                        case AddressPart.AddressPartType.StreetAddressLine:
                            adEntry.Line.Add(pt.AddressValue);
                            break;

                        case AddressPart.AddressPartType.City:
                            adEntry.City = pt.AddressValue;
                            break;

                        case AddressPart.AddressPartType.Country:
                            adEntry.Country = pt.AddressValue;
                            break;

                        case AddressPart.AddressPartType.PostalCode:
                            adEntry.Zip = pt.AddressValue;
                            break;

                        case AddressPart.AddressPartType.State:
                            adEntry.State = pt.AddressValue;
                            break;

                        default:     // Can't find a place to put it and don't want to lose data ... so stuff it into an extension
                            adEntry.Extension.Add(ExtensionUtil.CreateADExtension(pt));
                            break;
                        }
                    }
                    retVal.Add(adEntry);
                }
            }
            return(retVal);
        }
Esempio n. 4
0
        /// <summary>
        /// Convert telecom
        /// </summary>
        internal List <Telecom> ConvertTelecom(TelecommunicationsAddress tel)
        {
            var retVal = new List <Telecom>();
            var use    = MARC.Everest.Connectors.Util.Convert <SET <CS <TelecommunicationAddressUse> > >(tel.Use);

            foreach (var instance in use)
            {
                // Add telecom
                Telecom telInstance = new Telecom();
                // Convert use adding additional data if needed
                telInstance.Use = new PrimitiveCode <string>(HackishCodeMapping.ReverseLookup(HackishCodeMapping.TELECOM_USE, instance.Code));
                if (telInstance.Use == null || telInstance.Use.Value == null)
                {
                    telInstance.Use = new PrimitiveCode <string>();
                    telInstance.Use.Extension.Add(ExtensionUtil.CreateTELUseExtension((TelecommunicationAddressUse)instance.Code));
                }

                // Set values, etc
                try
                {
                    telInstance.Value = tel.Value;
                    switch (new Uri(telInstance.Value).Scheme)
                    {
                    case "mailto":
                        telInstance.System = new PrimitiveCode <string>("email");
                        break;

                    case "fax":
                        telInstance.System = new PrimitiveCode <string>("fax");
                        break;

                    case "tel":
                        telInstance.System = new PrimitiveCode <string>("phone");
                        break;

                    default:
                        telInstance.System = new PrimitiveCode <string>("url");
                        break;
                    }
                }
                catch { }
                retVal.Add(telInstance);
            }
            return(retVal);
        }
Esempio n. 5
0
        /// <summary>
        /// Process a name set
        /// </summary>
        protected HumanName ConvertNameSet(NameSet name)
        {
            HumanName retVal = new HumanName();

            if (name.Use != NameSet.NameSetUse.Search)
            {
                retVal.Use = new PrimitiveCode <string>(HackishCodeMapping.ReverseLookup(HackishCodeMapping.NAME_USE, name.Use));
                if (String.IsNullOrEmpty(retVal.Use.Value))
                {
                    retVal.Use.Extension.Add(ExtensionUtil.CreatePNUseExtension(name.Use));
                }
            }

            foreach (var pt in name.Parts)
            {
                switch (pt.Type)
                {
                case NamePart.NamePartType.Family:
                    retVal.Family.Add(pt.Value);
                    break;

                case NamePart.NamePartType.Given:
                    retVal.Given.Add(pt.Value);
                    break;

                case NamePart.NamePartType.Prefix:
                    retVal.Prefix.Add(pt.Value);
                    break;

                case NamePart.NamePartType.Suffix:
                    retVal.Suffix.Add(pt.Value);
                    break;

                case NamePart.NamePartType.None:
                    retVal.Text = pt.Value;
                    break;
                }
            }
            return(retVal);
        }
Esempio n. 6
0
        /// <summary>
        /// Convert an address to a address set
        /// </summary>
        internal AddressSet ConvertAddress(Address address, List <IResultDetail> dtls)
        {
            if (address == null)
            {
                return(null);
            }

            AddressSet retVal = new AddressSet();

            if (address.Use != null) // convert use
            {
                retVal.Use  = HackishCodeMapping.Lookup(HackishCodeMapping.ADDRESS_USE, address.Use);
                retVal.Use |= ExtensionUtil.ParseADUseExtension(address.Use.Extension, dtls);
            }

            if (address.Text != null) // Convert text? this is discarded
            {
                dtls.Add(new UnsupportedFhirDatatypePropertyResultDetail(ResultDetailType.Warning, "Text", "Address"));
                address.Text = null;
            }

            foreach (var itm in address.Line)
            {
                retVal.Parts.Add(new AddressPart()
                {
                    AddressValue = itm.Value, PartType = AddressPart.AddressPartType.StreetAddressLine
                });
            }
            if (address.City != null)
            {
                retVal.Parts.Add(new AddressPart()
                {
                    AddressValue = address.City, PartType = AddressPart.AddressPartType.City
                });
            }
            if (address.State != null)
            {
                retVal.Parts.Add(new AddressPart()
                {
                    AddressValue = address.State, PartType = AddressPart.AddressPartType.State
                });
            }
            if (address.Zip != null)
            {
                retVal.Parts.Add(new AddressPart()
                {
                    AddressValue = address.Zip, PartType = AddressPart.AddressPartType.PostalCode
                });
            }
            if (address.Country != null)
            {
                retVal.Parts.Add(new AddressPart()
                {
                    AddressValue = address.Country, PartType = AddressPart.AddressPartType.Country
                });
            }

            retVal.Parts.AddRange(ExtensionUtil.ParseADExtension(address.Extension, dtls));

            // Period of operation
            if (address.Period != null)
            {
                dtls.Add(new UnsupportedFhirDatatypePropertyResultDetail(ResultDetailType.Warning, "Period", "Address"));
                address.Period = null;
            }

            retVal.Parts.RemoveAll(o => String.IsNullOrEmpty(o.AddressValue));


            return(retVal);
        }