示例#1
0
        /// <summary>
        /// Parses the HL7 Message and transforms it to an object model
        /// </summary>
        /// <param name="hl7Message"></param>
        /// <returns></returns>
        public Patient Parse(String hl7Message)
        {
            Patient objPatient = new Patient();

            PipeParser parser = new PipeParser();

            var parsedMessage = new ADT_A01();

            parsedMessage = (ADT_A01)parser.Parse(hl7Message);

            // Patient Name Details
            objPatient.PersonName            = new Name();
            objPatient.PersonName.GivenName  = parsedMessage.PID.GetPatientName(0).GivenName.Value;
            objPatient.PersonName.FamilyName = parsedMessage.PID.GetPatientName(0).FamilyName.Value;
            objPatient.PersonName.Suffix     = parsedMessage.PID.GetPatientName(0).SuffixEgJRorIII.Value;


            objPatient.PersonSex = (Sex)Enum.Parse(typeof(Sex), parsedMessage.PID.Sex.Value);

            // Phone Number
            objPatient.PersonNumber            = new PhoneNumber();
            objPatient.PersonNumber.HomeNumber = parsedMessage.PID.GetPhoneNumberHome(0).PhoneNumber.Value;

            objPatient.PersonAddress = new Address();

            objPatient.PersonAddress.StreetAddress = parsedMessage.PID.GetPatientAddress(0).StreetAddress.Value;
            objPatient.PersonAddress.City          = parsedMessage.PID.GetPatientAddress(0).City.Value;
            objPatient.PersonAddress.State         = parsedMessage.PID.GetPatientAddress(0).StateOrProvince.Value;
            objPatient.PersonAddress.ZipCode       = parsedMessage.PID.GetPatientAddress(0).ZipOrPostalCode.Value;


            // Kin Details

            objPatient.NextOfKin = new List <Person>();
            Person objKin = new Person();

            objKin.PersonName            = new Name();
            objKin.PersonName.GivenName  = parsedMessage.GetNK1(0).GetName(0).GivenName.Value;
            objKin.PersonName.FamilyName = parsedMessage.GetNK1(0).GetName(0).FamilyName.Value;

            objKin.Relationship = parsedMessage.GetNK1(0).Relationship.Identifier.Value;

            objKin.PersonAddress = new Address();
            objKin.PersonAddress.StreetAddress = parsedMessage.GetNK1(0).GetAddress(0).StreetAddress.Value;
            objKin.PersonAddress.City          = parsedMessage.GetNK1(0).GetAddress(0).City.Value;
            objKin.PersonAddress.State         = parsedMessage.GetNK1(0).GetAddress(0).StateOrProvince.Value;
            objKin.PersonAddress.ZipCode       = parsedMessage.GetNK1(0).GetAddress(0).ZipOrPostalCode.Value;

            objKin.PersonNumber              = new PhoneNumber();
            objKin.PersonNumber.HomeNumber   = parsedMessage.GetNK1(0).GetPhoneNumber(0).PhoneNumber.Value;
            objKin.PersonNumber.OfficeNumber = parsedMessage.GetNK1(0).GetBusinessPhoneNumber(0).PhoneNumber.Value;

            objPatient.NextOfKin.Add(objKin);

            return(objPatient);
        }
示例#2
0
        public void TestCurrent()
        {
            var message = new ADT_A01();
            var sut     = new MessageIterator(message.GetROL(), "ROL", false);

            Assert.AreEqual(message.GetROL(1), sut.Current, "next rep if dir matches repeating segment");
            sut.Direction = "PDA";

            Assert.AreEqual(message.GetNK1(), sut.Current, "next sibling if dir doesn't match repeating segment");
            Console.WriteLine(sut.Current);

            sut.Direction = "PV1";
            Assert.AreEqual(message.PV2, sut.Current, "next sibling if dir matches non-repeating segment");

            sut = new MessageIterator(message.GetPROCEDURE(), "PDA", false);
            Assert.AreEqual(message.GetPROCEDURE().PR1, sut.Current, "group to child");
            sut.Direction = "PR1";

            Console.WriteLine(sut.Current);

            Assert.AreEqual(message.GetPROCEDURE(1), sut.Current, "next rep of group if 1st child matches dir");

            sut = new MessageIterator(message.GetPROCEDURE().GetROL(), "PDA", false);
            Assert.AreEqual(message.GetGT1(), sut.Current, "next sibling of parent if group doesn't contain direction");

            sut = new MessageIterator(message.GetINSURANCE().GetROL(), "IN3", false);
            Assert.AreEqual(message.ACC, sut.Current, "next sib of parent if contains dir after required child");

            sut = new MessageIterator(message.PDA, "FOO", false);
            try
            {
                var unused = sut.Current;
                Assert.Fail("should have thrown no such element exception on attempt to iterate past end of message");
            }
            catch (ArgumentOutOfRangeException)
            {
                /* OK */
            }

            sut = new MessageIterator(message.PDA, "FOO", true);
            var segment = (ISegment)sut.Current;

            Assert.AreEqual("FOO", segment.GetStructureName());

            sut     = new MessageIterator(message.GetINSURANCE().GetROL(), "BAR", true);
            segment = (ISegment)sut.Current;
            Assert.AreEqual("BAR", segment.GetStructureName());
            Assert.AreEqual(5, message.GetINSURANCE().Names.Length, "BAR added as a child of IN1 group");
        }