Ejemplo n.º 1
0
        /// <summary>
        /// Method to map a Fhir Model Patient element to an Patient object
        /// </summary>
        /// <param name="element"> Patient element from Fhir model </param>
        /// <returns> A Patient object with values from Fhir model element </returns>
        public override Models.Patient Map(Hl7.Fhir.Model.Patient element)
        {
            /// create a new Patient object and map values from Fhir model to it
            var patient = new Models.Patient
            {
                Id   = element.Id,
                Name = element.Name[0].ToString()
            };

            if (element.BirthDateElement != null)
            {
                patient.BirthDate = ((DateTimeOffset)element.BirthDateElement.ToDateTimeOffset()).DateTime;
            }
            else
            {
                patient.BirthDate = null;
            }

            if (Enum.TryParse(element.GenderElement.TypeName, out Gender gender))
            {
                patient.Gender = gender;
            }

            /// use Address mapper to map Patient's Address
            if (element.Address.Count > 0)
            {
                Hl7.Fhir.Model.Address address = element.Address[0];
                AddressMapper          mapper  = new AddressMapper();
                patient.Address = mapper.Map(address);
            }

            return(patient);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to map a Fhir Model Practitioner element to an Practitioner object
        /// </summary>
        /// <param name="element"> Practitioner element from Fhir model </param>
        /// <returns> A Practitioner object with values from Fhir model element </returns>
        public override Models.Practitioner Map(Hl7.Fhir.Model.Practitioner element)
        {
            var practitioner = new Models.Practitioner();

            /// get valid identifier
            foreach (var identifier in element.Identifier)
            {
                if (identifier.System.Equals(ID_SYSTEM))
                {
                    practitioner.Id = identifier.Value;
                    break;
                }
            }

            practitioner.Name = element.Name[0].ToString();

            if (element.BirthDateElement != null)
            {
                practitioner.BirthDate = ((DateTimeOffset)element.BirthDateElement.ToDateTimeOffset()).DateTime;
            }
            else
            {
                practitioner.BirthDate = null;
            }

            if (Enum.TryParse(element.GenderElement.TypeName, out Gender gender))
            {
                practitioner.Gender = gender;
            }

            /// map practitioner's address with AddressMapper
            if (element.Address.Count > 0)
            {
                Hl7.Fhir.Model.Address address = element.Address[0];
                AddressMapper          mapper  = new AddressMapper();
                practitioner.Address = mapper.Map(address);
            }

            return(practitioner);
        }