public HL7Header(IMessage msgIn) { if (msgIn.Version.Equals("2.3.1")) { _msh231 = (NHapi.Model.V231.Segment.MSH)msgIn.GetStructure("MSH"); this.SendingApplicaiton = new Identifier( _msh231.SendingApplication.NamespaceID.Value, _msh231.SendingApplication.UniversalID.Value, _msh231.SendingApplication.UniversalIDType.Value); this.SendingFacility = new Identifier( _msh231.SendingFacility.NamespaceID.Value, _msh231.SendingFacility.UniversalID.Value, _msh231.SendingFacility.UniversalIDType.Value); this.ReceivingApplication = new Identifier( _msh231.ReceivingApplication.NamespaceID.Value, _msh231.ReceivingApplication.UniversalID.Value, _msh231.ReceivingApplication.UniversalIDType.Value); this.ReceivingFacility = new Identifier( _msh231.ReceivingFacility.NamespaceID.Value, _msh231.ReceivingFacility.UniversalID.Value, _msh231.ReceivingFacility.UniversalIDType.Value); this.MessageControlId = _msh231.MessageControlID.Value; this.MessageCode = _msh231.MessageType.MessageType.Value; this.TriggerEvent = _msh231.MessageType.TriggerEvent.Value; this.MessageStructure = _msh231.MessageType.MessageStructure.Value; this.MessageDate = _msh231.DateTimeOfMessage.TimeOfAnEvent.Value; } else { _msh25 = (NHapi.Model.V25.Segment.MSH)msgIn.GetStructure("MSH"); this.SendingApplicaiton = new Identifier( _msh25.SendingApplication.NamespaceID.Value, _msh25.SendingApplication.UniversalID.Value, _msh25.SendingApplication.UniversalIDType.Value); this.SendingFacility = new Identifier( _msh25.SendingFacility.NamespaceID.Value, _msh25.SendingFacility.UniversalID.Value, _msh25.SendingFacility.UniversalIDType.Value); this.ReceivingApplication = new Identifier( _msh25.ReceivingApplication.NamespaceID.Value, _msh25.ReceivingApplication.UniversalID.Value, _msh25.ReceivingApplication.UniversalIDType.Value); this.ReceivingFacility = new Identifier( _msh25.ReceivingFacility.NamespaceID.Value, _msh25.ReceivingFacility.UniversalID.Value, _msh25.ReceivingFacility.UniversalIDType.Value); this.MessageControlId = _msh25.MessageControlID.Value; this.MessageCode = _msh25.MessageType.MessageCode.Value; this.TriggerEvent = _msh25.MessageType.TriggerEvent.Value; this.MessageStructure = _msh25.MessageType.MessageStructure.Value; this.MessageDate = _msh25.DateTimeOfMessage.Time.Value; } }
/// <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); }