public void Cleanup() { this.entityTelecomAddress = null; this.xad = null; this.xpn = null; this.xtn = null; }
public void Initialize() { this.entityTelecomAddress = new EntityTelecomAddress { AddressUse = new Core.Model.DataTypes.Concept { Key = TelecomAddressUseKeys.Public }, Value = "9055751212" }; this.xad = new XAD(Activator.CreateInstance(typeof(ADT_A01)) as IMessage); this.xad.AddressType.Value = "L"; this.xad.City.Value = "Hamilton"; this.xad.Country.Value = "Canada"; this.xad.StateOrProvince.Value = "Ontario"; this.xad.StreetAddress.Value = "123 Main street west"; this.xad.ZipOrPostalCode.Value = "L8N3T2"; this.xpn = new XPN(Activator.CreateInstance(typeof(ADT_A01)) as IMessage); this.xpn.DegreeEgMD.Value = "MD"; this.xpn.FamilyLastName.FamilyName.Value = "Khanna"; this.xpn.GivenName.Value = "Nityan"; this.xpn.PrefixEgDR.Value = "Dr."; this.xpn.MiddleInitialOrName.Value = "Dave"; this.xtn = new XTN(Activator.CreateInstance(typeof(ADT_A01)) as IMessage); }
/// <summary> /// Convert a telecom address to an XTN v2 structure /// </summary> public static XTN FromModel(this XTN me, EntityTelecomAddress tel) { if (tel.AddressUseKey != NullReasonKeys.NoInformation) { var useTerm = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptReferenceTerm(tel.AddressUseKey.GetValueOrDefault(), TelecomUseCodeSystem); if (useTerm != null) { me.TelecommunicationUseCode.Value = useTerm.Mnemonic; } else { m_tracer.TraceWarning("Could not find {0} in {1}", tel.LoadProperty(o => o.AddressUse), TelecomUseCodeSystem); } } if (tel.TypeConceptKey.HasValue) { var typeTerm = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptReferenceTerm(tel.TypeConceptKey.GetValueOrDefault(), TelecomTypeCodeSystem); if (typeTerm != null) { me.TelecommunicationEquipmentType.Value = typeTerm.Mnemonic; } else { m_tracer.TraceWarning("Could not find {0} in {1}", tel.LoadProperty(o => o.TypeConcept), TelecomTypeCodeSystem); } } me.AnyText.Value = tel.Value; return(me); }
/// <summary> /// Converts an <see cref="EntityTelecomAddress"/> instance to <see cref="FhirTelecom"/> instance. /// </summary> /// <param name="telecomAddress">The telecom address.</param> /// <returns>Returns the mapped FHIR telecom.</returns> public static FhirTelecom ToFhirTelecom(EntityTelecomAddress telecomAddress) { traceSource.TraceEvent(TraceEventType.Verbose, 0, "Mapping entity telecom address"); return(new FhirTelecom() { Use = DataTypeConverter.ToFhirCodeableConcept(telecomAddress.AddressUse)?.GetPrimaryCode()?.Code, Value = telecomAddress.IETFValue }); }
/// <summary> /// Converts an <see cref="EntityTelecomAddress"/> instance to <see cref="FhirTelecom"/> instance. /// </summary> /// <param name="telecomAddress">The telecom address.</param> /// <returns>Returns the mapped FHIR telecom.</returns> public static FhirTelecom ToFhirTelecom(EntityTelecomAddress telecomAddress) { traceSource.TraceEvent(EventLevel.Verbose, "Mapping entity telecom address"); return(new FhirTelecom() { Use = telecomAddress.AddressUseKey == NullReasonKeys.NoInformation ? null : DataTypeConverter.ToFhirCodeableConcept(telecomAddress.AddressUse, "http://hl7.org/fhir/contact-point-use", true)?.GetPrimaryCode()?.Code, Value = telecomAddress.IETFValue }); }
/// <summary> /// Converts an <see cref="EntityTelecomAddress"/> instance to an <see cref="NHapi.Model.V231.Datatype.XTN"/> instance. /// </summary> /// <param name="tel">The entity telecom address instance to be converted.</param> /// <param name="instance">The converted XTN instance.</param> public static void XTNFromTel(EntityTelecomAddress tel, NHapi.Model.V231.Datatype.XTN instance) { var v25Instance = new NHapi.Model.V25.Datatype.XTN(instance.Message); XTNFromTel(tel, v25Instance); for (var i = 0; i < v25Instance.Components.Length; i++) { if (v25Instance.Components[i] is AbstractPrimitive && i < instance.Components.Length) { (instance.Components[i] as AbstractPrimitive).Value = (v25Instance.Components[i] as AbstractPrimitive).Value; } } }
/// <summary> /// Maps the contact point. /// </summary> /// <param name="addressUseKey">The address use key.</param> /// <param name="contactPoint">The contact point.</param> /// <returns>Returns an entity telecom address.</returns> private static EntityTelecomAddress MapContactPoint(Guid addressUseKey, contactPoint contactPoint) { var concept = MapCodedType(contactPoint.codedType.code, contactPoint.codedType.codingScheme); var entityTelecomAddress = new EntityTelecomAddress(addressUseKey, contactPoint.codedType.Value); if (concept == null) { ShowWarningOnNotFound($"Warning, unable to map telecommunications use, no related concept found for code: {contactPoint.codedType.code} using scheme: {contactPoint.codedType.codingScheme}", nameof(TelecomAddressUseKeys.Public), TelecomAddressUseKeys.Public); } else { entityTelecomAddress.AddressUseKey = concept.Key; } return(entityTelecomAddress); }
/// <summary> /// Convert a telecom address to an XTN v2 structure /// </summary> public static XTN FromModel(this XTN me, EntityTelecomAddress tel) { if (tel.AddressUseKey != NullReasonKeys.NoInformation) { var useTerm = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptReferenceTerm(tel.AddressUseKey.GetValueOrDefault(), TelecomUseCodeSystem); me.TelecommunicationUseCode.Value = useTerm.Mnemonic; } if (tel.TypeConceptKey.HasValue) { var typeTerm = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptReferenceTerm(tel.TypeConceptKey.GetValueOrDefault(), TelecomTypeCodeSystem); me.TelecommunicationEquipmentType.Value = typeTerm.Mnemonic; } me.AnyText.Value = tel.Value; return(me); }
/// <summary> /// Converts an <see cref="EntityTelecomAddress"/> instance to an <see cref="NHapi.Model.V25.Datatype.XTN"/> instance. /// </summary> /// <param name="tel">The entity telecom address instance to be converted.</param> /// <param name="instance">The converted XTN instance.</param> public static void XTNFromTel(EntityTelecomAddress tel, NHapi.Model.V25.Datatype.XTN instance) { Regex re = new Regex(@"^(?<s1>(?<s0>[^:/\?#]+):)?(?<a1>//(?<a0>[^/\;#]*))?(?<p0>[^\;#]*)(?<q1>\;(?<q0>[^#]*))?(?<f1>#(?<f0>.*))?"); // Match var match = re.Match(tel.Value); if (match.Groups[1].Value != "tel:") { instance.AnyText.Value = tel.Value; return; } // Telephone string[] comps = match.Groups[5].Value.Split('-'); StringBuilder sb = new StringBuilder(), phone = new StringBuilder(); for (int i = 0; i < comps.Length; i++) { if (i == 0 && comps[i].Contains("+")) { sb.Append(comps[i]); instance.CountryCode.Value = comps[i]; } else if (sb.Length == 0 && comps.Length == 3 || comps.Length == 4 && i == 1) // area code? { sb.AppendFormat("({0})", comps[i]); instance.AreaCityCode.Value = comps[i]; } else if (i != comps.Length - 1) { sb.AppendFormat("{0}-", comps[i]); phone.AppendFormat("{0}", comps[i]); } else { sb.Append(comps[i]); phone.Append(comps[i]); } } instance.LocalNumber.Value = phone.ToString().Replace("-", ""); // Extension? string[] parms = match.Groups[7].Value.Split(';'); foreach (var parm in parms) { string[] pData = parm.Split('='); if (pData[0] == "extension" || pData[0] == "ext" || pData[0] == "postd") { sb.AppendFormat("X{0}", pData[1]); instance.Extension.Value = pData[1]; } } instance.TelephoneNumber.Value = sb.ToString(); // Tel use if (tel.AddressUseKey != null) { var concept = GetConcept(instance.TelecommunicationUseCode.Value, "urn:oid:2.16.840.1.113883.5.1011"); // TODO: cleanup if (concept == null) { throw new ArgumentException("Code not known"); } instance.TelecommunicationUseCode.Value = concept.Mnemonic; } }
/// <summary> /// Converts a <see cref="XTN"/> instance to a <see cref="EntityTelecomAddress"/> instance. /// </summary> /// <param name="xtn">The v2 XTN instance to be converted.</param> /// <returns>Returns the converted entity telecom address instance.</returns> public static EntityTelecomAddress ConvertXTN(XTN xtn) { var re = new Regex(@"([+0-9A-Za-z]{1,4})?\((\d{3})\)?(\d{3})\-(\d{4})X?(\d{1,6})?"); var retVal = new EntityTelecomAddress(); if (xtn.AnyText.Value == null) { var sb = new StringBuilder("tel:"); try { if (xtn.CountryCode.Value != null) { sb.AppendFormat("{0}-", xtn.CountryCode); } if (xtn.PhoneNumber?.Value != null && !xtn.PhoneNumber.Value.Contains("-")) { xtn.PhoneNumber.Value = xtn.PhoneNumber.Value.Insert(3, "-"); } sb.AppendFormat("{0}-{1}", xtn.AreaCityCode, xtn.PhoneNumber); if (xtn.Extension.Value != null) { sb.AppendFormat(";ext={0}", xtn.Extension); } } catch { // ignored } if (sb.ToString().EndsWith("tel:") || sb.ToString() == "tel:-") { retVal.Value = "tel:" + xtn.AnyText.Value; } else { retVal.Value = sb.ToString(); } } else { var match = re.Match(xtn.AnyText.Value); var sb = new StringBuilder("tel:"); for (var i = 1; i < 5; i++) { if (!string.IsNullOrEmpty(match.Groups[i].Value)) { sb.AppendFormat("{0}{1}", match.Groups[i].Value, i == 4 ? "" : "-"); } } if (!string.IsNullOrEmpty(match.Groups[5].Value)) { sb.AppendFormat(";ext={0}", match.Groups[5].Value); } retVal.Value = sb.ToString(); } // Use code conversion var use = Guid.Empty; if (!string.IsNullOrEmpty(xtn.TelecommunicationUseCode.Value)) { var concept = GetConcept(xtn.TelecommunicationUseCode.Value, "urn:oid:2.16.840.1.113883.5.1011"); // TODO: cleanup if (concept == null) { throw new ArgumentException("Code not known"); } use = concept.Key.Value; } retVal.AddressUseKey = use; return(retVal); }
/// <summary> /// Converts a <see cref="XTN"/> instance to a <see cref="EntityTelecomAddress"/> instance. /// </summary> /// <param name="xtn">The v2 XTN instance to be converted.</param> /// <returns>Returns the converted entity telecom address instance.</returns> public static EntityTelecomAddress ToModel(this XTN xtn) { var re = new Regex(@"([+0-9A-Za-z]{1,4})?\((\d{3})\)?(\d{3})\-(\d{4})X?(\d{1,6})?"); var retVal = new EntityTelecomAddress(); if (!String.IsNullOrEmpty(xtn.EmailAddress?.Value)) { retVal.IETFValue = $"mailto:{xtn.EmailAddress.Value}"; } else if (xtn.AnyText.Value == null) { var sb = new StringBuilder("tel:"); try { if (xtn.CountryCode.Value != null) { sb.AppendFormat("{0}{1}-", xtn.CountryCode.Value.Contains("+") ? "" : "+", xtn.CountryCode); } if (!String.IsNullOrEmpty(xtn.TelephoneNumber?.Value)) { if (xtn.TelephoneNumber?.Value != null && !xtn.TelephoneNumber.Value.Contains("-")) { xtn.TelephoneNumber.Value = xtn.TelephoneNumber.Value.Insert(3, "-"); } sb.AppendFormat("{0}-{1}", xtn.AreaCityCode, xtn.TelephoneNumber.Value); } else { sb.AppendFormat("{0}-{1}", xtn.AreaCityCode, xtn.LocalNumber.Value.Contains("-") ? xtn.LocalNumber.Value : xtn.LocalNumber.Value.Replace(" ", "-").Insert(3, "-")); } if (xtn.Extension.Value != null) { sb.AppendFormat(";ext={0}", xtn.Extension); } } catch { // ignored } if (sb.ToString().EndsWith("tel:") || sb.ToString() == "tel:-") { retVal.IETFValue = "tel:" + xtn.AnyText.Value; } else { retVal.IETFValue = sb.ToString(); } } else { var match = re.Match(xtn.UnformattedTelephoneNumber.Value); var sb = new StringBuilder("tel:"); for (var i = 1; i < 5; i++) { if (!string.IsNullOrEmpty(match.Groups[i].Value)) { sb.AppendFormat("{0}{1}", match.Groups[i].Value, i == 4 ? "" : "-"); } } if (!string.IsNullOrEmpty(match.Groups[5].Value)) { sb.AppendFormat(";ext={0}", match.Groups[5].Value); } retVal.IETFValue = sb.ToString(); } // Use code conversion Guid use = NullReasonKeys.NoInformation; if (!string.IsNullOrEmpty(xtn.TelecommunicationUseCode.Value)) { var concept = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptByReferenceTerm(xtn.TelecommunicationUseCode.Value, TelecomUseCodeSystem); if (concept == null) { throw new HL7DatatypeProcessingException("Error processing XTN", 1, new KeyNotFoundException($"Telecom use code {xtn.TelecommunicationUseCode.Value} not known")); } use = concept.Key.Value; } retVal.AddressUseKey = use; // Type code conversion Guid?type = null; if (!string.IsNullOrEmpty(xtn.TelecommunicationEquipmentType.Value)) { var concept = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>().GetConceptByReferenceTerm(xtn.TelecommunicationEquipmentType.Value, TelecomTypeCodeSystem); if (concept == null) { throw new HL7DatatypeProcessingException("Error processing XTN", 2, new KeyNotFoundException($"Telecom equipment type {xtn.TelecommunicationEquipmentType.Value} not known")); } type = concept.Key.Value; } retVal.TypeConceptKey = type; return(retVal); }