Esempio n. 1
0
        /// <summary>
        /// Converts components of a HL7v2 message to a <see cref="Patient"/> instance.
        /// </summary>
        /// <param name="msh">The message header segment.</param>
        /// <param name="evn">The event segment.</param>
        /// <param name="pid">The patient identification segment.</param>
        /// <param name="pd1">The patient pd1 segment.</param>
        /// <param name="details">The list of result details used for validation.</param>
        /// <returns>Returns the patient instance.</returns>
        public static Patient CreatePatient(MSH msh, EVN evn, PID pid, PD1 pd1, List <IResultDetail> details)
        {
            var patient = new Patient
            {
                Addresses        = ConvertAddresses(pid.GetPatientAddress()).ToList(),
                DateOfBirth      = ConvertTS(pid.DateTimeOfBirth),
                DeceasedDate     = ConvertTS(pid.PatientDeathDateAndTime),
                GenderConceptKey = GetConcept(pid.Sex.Value, "urn:oid:2.16.840.1.113883.5.1")?.Key,
                Names            = ConvertNames(pid.GetPatientName()).ToList(),
            };

            if (patient.GenderConceptKey == null || (patient.GenderConceptKey.HasValue && patient.GenderConceptKey.Value == Guid.Empty))
            {
                details.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, null, null));
                details.Add(new NotSupportedChoiceResultDetail(ResultDetailType.Error, null, null));
            }

            patient.Identifiers.AddRange(MessageUtil.ConvertIdentifiers(pid.GetPatientIdentifierList()));
            patient.Identifiers.AddRange(MessageUtil.ConvertIdentifiers(pid.GetAlternatePatientIDPID()));

            if (!string.IsNullOrEmpty(pid.PrimaryLanguage.Identifier.Value) && !string.IsNullOrWhiteSpace(pid.PrimaryLanguage.Identifier.Value))
            {
                patient.LanguageCommunication.Add(new PersonLanguageCommunication(pid.PrimaryLanguage.Identifier.Value, true));
            }

            if (!string.IsNullOrEmpty(pid.MultipleBirthIndicator.Value) && !string.IsNullOrWhiteSpace(pid.MultipleBirthIndicator.Value))
            {
                patient.MultipleBirthOrder = Convert.ToInt32(pid.MultipleBirthIndicator.Value);
            }

            patient.Telecoms.AddRange(pid.GetPhoneNumberHome().Select(ConvertXTN));
            patient.Telecoms.AddRange(pid.GetPhoneNumberBusiness().Select(ConvertXTN));

            if (pid.MotherSIdentifierRepetitionsUsed > 0 || pid.MotherSMaidenNameRepetitionsUsed > 0)
            {
                var person = new Person
                {
                    Identifiers = ConvertIdentifiers(pid.GetMotherSIdentifier()).ToList(),
                    Names       = ConvertNames(pid.GetMotherSMaidenName()).ToList(),
                };

                patient.Relationships.Add(new EntityRelationship(EntityRelationshipTypeKeys.Mother, person));
            }

            return(patient);
        }
Esempio n. 2
0
 /// <summary>
 /// Converts an <see cref="CX"/> instance to an <see cref="EntityIdentifier"/> instance.
 /// </summary>
 /// <param name="identifier">The identifier to be converted.</param>
 /// <returns>Returns the converted identifier.</returns>
 public static EntityIdentifier ConvertIdentifier(CX identifier)
 {
     return(MessageUtil.ConvertIdentifiers(new CX[] { identifier }).FirstOrDefault());
 }