public void TestCreatePatient() { var message = new ADT_A01(); message.MSH.DateTimeOfMessage.TimeOfAnEvent.Value = DateTime.Now.ToString("yyyyMMddHHmmss"); message.PID.GetPatientName(0).FamilyLastName.FamilyName.Value = "Khanna"; message.PID.GetPatientName(0).GivenName.Value = "Nityan"; message.PID.GetMotherSMaidenName(0).GivenName.Value = "Mom"; message.PID.GetMotherSMaidenName(0).FamilyLastName.FamilyName.Value = "Khanna"; var details = new List <IResultDetail>(); var actual = MessageUtil.CreatePatient(message.MSH, message.EVN, message.PID, message.PD1, details); var name = actual.Names.FirstOrDefault(); Assert.IsNotNull(name); var firstName = name.Component.FirstOrDefault(n => n.ComponentTypeKey == NameComponentKeys.Given); Assert.IsNotNull(firstName); Assert.AreEqual("Nityan", firstName.Value); var lastName = name.Component.FirstOrDefault(n => n.ComponentTypeKey == NameComponentKeys.Family); Assert.IsNotNull(lastName); Assert.AreEqual("Khanna", lastName.Value); Assert.AreEqual(1, actual.Relationships.Count); var entityRelationship = actual.Relationships.FirstOrDefault(); Assert.IsNotNull(entityRelationship); var mothersFirstname = entityRelationship.TargetEntity.Names.FirstOrDefault()?.Component.FirstOrDefault(n => n.ComponentTypeKey == NameComponentKeys.Given); Assert.IsNotNull(mothersFirstname); Assert.AreEqual("Mom", mothersFirstname.Value); var mothersLastName = entityRelationship.TargetEntity.Names.FirstOrDefault()?.Component.FirstOrDefault(n => n.ComponentTypeKey == NameComponentKeys.Family); Assert.IsNotNull(mothersLastName); Assert.AreEqual("Khanna", mothersLastName.Value); }