Example #1
0
        public void TestGetFieldOBR_POC()
        {
            int           nIdx  = 2;
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "OBR"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }
            Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx));

            _processHL7 = ProcessHL7Message.Instance;
            var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1);

            Assert.AreNotSame(nIdx, data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 2);
            Assert.AreNotSame("EA194979A", data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4);
            Assert.AreNotSame("POC^POC Testing", data);
            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.1);
            Assert.AreNotSame("POC", data);
            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.2);
            Assert.AreNotSame("POC Testing", data);
        }
Example #2
0
        public void TestGetFieldDG1()
        {
            // "DG1|1||779.34^^I9|||W"
            int           nIdx  = 1;
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "DG1"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }
            Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx));

            _processHL7 = ProcessHL7Message.Instance;
            var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1);

            Assert.AreNotSame(nIdx, data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 3.1);
            Assert.AreNotSame(notExpected: "779.34", actual: data);
        }
Example #3
0
        public void TestGetFieldPID()
        {
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "PID"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }
            Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, 1));

            _processHL7 = ProcessHL7Message.Instance;
            var fName = _processHL7.GetField(_encoding, lStr[0], 5.1);

            //char enCodeChar = (parse.GetField(_encoding, lMsg[0], 1).Substring(0, 1))[0];
            // not using the enCodeChar to parse subfields
            // get the first name of the patient
            // PID 5.2
            fName = parse.GetField(_encoding, lStr[0], 5.1);
            Assert.AreNotSame("TIMOTHY", fName);

            var name1 = parse.GetField(_encoding, lStr[0], 5.0);

            Assert.AreNotSame("TEST^TIMOTHY^", fName);

            var name2 = parse.GetField(_encoding, lStr[0], 5);

            Assert.AreNotSame("TEST^TIMOTHY^", fName);
        }
Example #4
0
        public void TestGetFieldMSH()
        {
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "MSH"));

            if (lStr == null || lStr.Count <= 0 || lStr.Count > 1)
            {
                Assert.IsNull(lStr);
            }

            _processHL7 = ProcessHL7Message.Instance;
            var data = _processHL7.GetField(_encoding, lStr[0], 2);

            Assert.AreNotSame("CareLogic^2.16.840.1.113883.3.1452.100.4", data);
            data = _processHL7.GetField(_encoding, lStr[0], 2.1);
            Assert.AreNotSame("CareLogic", data);

            data = _processHL7.GetField(_encoding, lStr[0], 3);
            Assert.AreNotSame("TVFFC1", data);

            data = _processHL7.GetField(_encoding, lStr[0], 8);
            Assert.AreNotSame("ORM^O01", data);

            data = _processHL7.GetField(_encoding, lStr[0], 8.2);
            Assert.AreNotSame("O01", data);

            data = _processHL7.GetField(_encoding, lStr[0], 11);
            Assert.AreNotSame("2.3", data);
        }
Example #5
0
 /// <summary>
 /// Create a new instance of HL7Message
 /// </summary>
 /// <param name="message"></param>
 public HL7Message(IMessage message)
 {
     this.m_Message   = message;
     this.m_HL7Parser = new HL7Parser();
     this.m_Terser    = new Terser(m_Message);
     this.m_MSH       = m_Terser.getSegment("MSH");
 }
Example #6
0
        public void TestGetFieldNTE3()
        {
            // NTE|1||POC Barbiturates Result:Negative|
            int           nIdx  = 3;
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "NTE"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }
            Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx));

            _processHL7 = ProcessHL7Message.Instance;
            var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1);

            Assert.AreNotSame(nIdx, data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 3);
            Assert.AreNotSame(notExpected: "POC Buprenorphine Result:Positive", actual: data);
        }
Example #7
0
        public async Task M_EasyCLientSendsCommandToHL7InterfaceWaitAckAndResponse()
        {
            HL7InterfaceBase hl7Interface            = new HL7InterfaceBase();
            AutoResetEvent   ackReceived             = new AutoResetEvent(false);
            AutoResetEvent   commandResponseReceived = new AutoResetEvent(false);

            HL7Server serverSide = new HL7Server();

            Assert.IsTrue(serverSide.Setup("127.0.0.1", 50060));

            Assert.IsTrue(hl7Interface.Initialize(serverSide, new HL7ProtocolBase(new HL7ProtocolConfig())));

            Assert.That(hl7Interface.Start());

            hl7Interface.NewRequestReceived += (s, e) =>
            {
                string response = MLLP.CreateMLLPMessage((new PrepareForSpecimenResponse()).Encode());

                byte[] dataToSend = Encoding.ASCII.GetBytes(response);

                s.Send(dataToSend, 0, dataToSend.Length);
            };

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            EasyClient client = new EasyClient();

            client.Initialize(new ReceiverFilter(new HL7ProtocolBase()), (packageInfo) =>
            {
                if (packageInfo.Request.IsAcknowledge)
                {
                    Assert.That(packageInfo.Request is GeneralAcknowledgment);
                    Assert.That(HL7Parser.IsAckForRequest(request, packageInfo.Request));
                    ackReceived.Set();
                }
                else
                {
                    Assert.IsTrue(packageInfo.Request is PrepareForSpecimenResponse);
                    commandResponseReceived.Set();
                }
            });

            Assert.That(client.ConnectAsync(endPointA).Result);

            byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage(request.Encode()));

            client.Send(bytesToSend);

            Assert.That(ackReceived.WaitOne());

            Assert.That(commandResponseReceived.WaitOne());

            await client.Close();

            serverSide.Stop();

            hl7Interface.Stop();
        }
Example #8
0
        public virtual bool IsAckForRequest(IHL7Message request)
        {
            if (!this.IsAcknowledge)
            {
                return(false);
            }

            return(HL7Parser.IsAckForRequest(request, this));
        }
        public virtual ParserResult Parse(byte[] raw)
        {
            string message = Encoding.ASCII.GetString(raw);

            HL7api.Util.MLLP.StripMLLPContainer(ref message);
            HL7Parser p = new HL7Parser();

            return(p.Parse(message));
        }
        public void ParsePrepareForSpecimenResponse()
        {
            HL7Parser p = new HL7Parser();

            ParserResult pResult = null;

            string m = @"MSH|^~\&|||||20190322144038||EAR^U08^EAR_U08|89900867-5efc-4393-8dc2-c11baa88683f||2.5.1|||||||||PrepareForSpecimenResponse
            EQU||20190322144144
            ECD||LO^Prepare^ASTM|Y
            SAC|||123
            ECR|OK^Command completed successfully^HL70387";

            Assert.DoesNotThrow(() => { pResult = p.Parse(m); });

            Assert.That(pResult.MessageAccepted);

            EquipmentCommandResponse request = pResult.ParsedMessage as EquipmentCommandResponse;

            Assert.IsFalse(request.IsAcknowledge);

            Assert.IsNotNull(request);

            Assert.AreEqual(nameof(GeneralAcknowledgment), request.ExpectedAckID);

            Assert.AreEqual(string.Empty, request.ExpectedResponseID);

            Assert.AreEqual(request.GetValue("MSH-9-1"), "EAR");

            Assert.AreEqual(request.GetValue("MSH-9-2"), "U08");

            Assert.AreEqual(nameof(PrepareForSpecimenResponse), request.GetValue("MSH-21-1"));

            Assert.AreEqual("89900867-5efc-4393-8dc2-c11baa88683f", request.GetValue("MSH-10"));

            Assert.AreEqual(request.GetValue("COMMAND/ECD-2-1"), "LO");

            Assert.That(pResult.IsAcknowledge.HasValue && !pResult.IsAcknowledge.Value);

            GeneralAcknowledgment ack = pResult.Acknowledge as GeneralAcknowledgment;

            Assert.IsNotNull(ack);

            Assert.That(string.IsNullOrEmpty(ack.ExpectedResponseID));

            Assert.That(string.IsNullOrEmpty(ack.ExpectedAckID));

            Assert.AreEqual(ack.GetValue("MSA-1"), "AA");

            Assert.AreEqual(ack.GetValue("MSA-2"), "89900867-5efc-4393-8dc2-c11baa88683f");

            Assert.AreEqual(ack.GetValue("MSH-9-1"), "ACK");

            Assert.AreEqual(ack.GetValue("MSH-9-2"), "U08");

            Assert.AreEqual(nameof(GeneralAcknowledgment), ack.GetValue("MSH-21-1"));
        }
Example #11
0
        public void TestPositiveAckPrepareForSpecimenResponse()
        {
            PrepareForSpecimenResponse prepare = new PrepareForSpecimenResponse();

            HL7Parser p = new HL7Parser();

            ParserResult result = p.Parse(prepare.Encode());

            Assert.IsTrue(result.MessageAccepted);

            Assert.IsTrue(result.Acknowledge.IsAckForRequest(prepare));
        }
Example #12
0
        /// <summary>
        /// IsSegmentFound - in the list check if the list contains the entry based on the nIdx value
        /// This can be simpler by just checking if the nIdx value is less than or equal to the list count
        /// </summary>
        /// <param name="parse"></param>
        /// <param name="_encoding"></param>
        /// <param name="lStr"></param>
        /// <param name="nIdx"></param>
        /// <returns></returns>
        private static bool IsSegmentFound(HL7Parser parse, HL7Encoding _encoding, List <string> lStr, int nIdx)
        {
            Boolean bFound       = false;
            int     nSequenceFld = 1;

            foreach (var line in lStr)
            {
                if (parse.GetField(_encoding, line, nSequenceFld).Equals(nIdx.ToString()))   // get the sequence field value
                {
                    bFound = true;
                }
            }
            return(bFound);
        }
Example #13
0
        public async Task L_EasyClientSendsCommandToHL7InterfaceAndWaitAck()
        {
            HL7InterfaceBase hl7Interface            = new HL7InterfaceBase();
            AutoResetEvent   ackReceived             = new AutoResetEvent(false);
            AutoResetEvent   commandResponseReceived = new AutoResetEvent(false);

            HL7ProtocolBase protocol = new HL7ProtocolBase(new HL7ProtocolConfig()
            {
                IsAckRequired      = true,
                IsResponseRequired = true
            });

            HL7Server serverSide = new HL7Server();

            Assert.IsTrue(serverSide.Setup("127.0.0.1", 50060));

            Assert.IsTrue(hl7Interface.Initialize(serverSide, protocol));

            Assert.That(hl7Interface.Start());

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            EasyClient client = new EasyClient();

            client.Initialize(new ReceiverFilter(new HL7ProtocolBase()), (packageInfo) =>
            {
                if (packageInfo.Request.IsAcknowledge)
                {
                    Assert.That(packageInfo.Request is GeneralAcknowledgment);
                    Assert.That(HL7Parser.IsAckForRequest(request, packageInfo.Request));
                    ackReceived.Set();
                }
                else
                {
                    Assert.Fail();
                }
            });

            Assert.That(client.ConnectAsync(endPointA).Result);

            byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage(request.Encode()));
            client.Send(bytesToSend);

            Assert.That(ackReceived.WaitOne(timeout));

            await client.Close();

            hl7Interface.Stop();
        }
Example #14
0
        public void CanParseLLP()
        {
            const string packet = @"MSH|^~\&|ADT|EPIC-PRD|QDXI|CHB|20120103161618||ADT^A03|12586919|P|2.3-CH|||NS
EVN|A03|201201031616|||148266
PID|1||1157644^^^^MRN|E925019^^^^EPI~1157644^^^^MRN~77274^^^^MEHC|MASWALI^HAWA||19951126|F^FEMALE||B^Black or African American|7 NORTH FRANKLIN STREET^APT  2^LYNN^MA^01904-0000^USA^^^ESSEX||(781)598-6334||EN^ENGLISH|S^SINGLE|MUS^MUSLIM/MOSLEM|6110810355|013-80-8049|||R3.01||||||||N
ROL|1||1|00081109^SIGMAN^ELLEN^S^^^^^^^^^BADGE~01003873^SIGMAN^ELLEN^S^^^^^^^^^EPDS|19990205||||||1493 CAMBRIDGE STREET^^CAMBRIDGE^MA^02139^USA^O~1493 CAMBRIDGE STREET^^CAMBRIDGE^MA^02139^USA^S^^^^^^^^^^^^^01003873-2^^^CAMBRIDGE PEDIATRICS|(617)665-1264^^WP^^^617^6651264~(617)665-1835^^OF^^^617^6651835
PV1|1|I^INPATIENT|6E^^^^01|1^Emergency^N|||00080417^TRENOR^CAMERON^C^III^^^^^^^^BADGE~01094867^TRENOR^CAMERON^C^III^^^^^^^^EPDS|00081109^SIGMAN^ELLEN^S^^^^^^^^^BADGE~01003873^SIGMAN^ELLEN^S^^^^^^^^^EPDS||HEM^Hematology||||01^Physician Referral|||00126191^HENNELLY^KARA^E^^^^^^^^^BADGE~2012093^HENNELLY^KARA^E^^^^^^^^^EPDS|I|58825197|UHC^UNITED HEALTHCARE||||||||||||||||01^HOME|HOME^Home||||PB|||201201020159|201201031615||4000.14
PV2||S^Semi-Private|BODY ACHES|||||201201020000||||||||||||||N||||||||||||||||4^Walk-In
DG1|1|I9||BODY ACHES|201201020159|A|||||||||1|1094867^00080417
ZMD|SIGMAN^ELLEN^S|1493 CAMBRIDGE STREET^^CAMBRIDGE^MA^02139|(617)665-1264|(617)665-1835||01003873|010038732|SIGMAN^ELLEN^S|1493 CAMBRIDGE STREET^^CAMBRIDGE^MA^02139|(617)665-1264|(617)665-1835||01003873|010038732|SIGMAN^ELLEN^S|SIGMAN^ELLEN^S
ZPV|||||||||01003873|4^TRIAGE LEVEL 4|93^OTHER||201^201716^636^A||ED ADMIT||||||||||201201020656"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ;
            var          result = HL7Parser.LoadPackage(packet);

            Assert.IsNotNull(result);
        }
Example #15
0
        public async Task E_EasyClientSendsHL7MessageToHL7InterfaceAndReceivesAck()
        {
            HL7InterfaceBase hl7Interface = new HL7InterfaceBase();

            AutoResetEvent newRequestReceived = new AutoResetEvent(false);

            Assert.IsTrue(hl7Interface.Initialize());

            Assert.IsTrue(hl7Interface.Start());

            PrepareForSpecimenRequest equipmentCommandRequest = new PrepareForSpecimenRequest();

            hl7Interface.HL7Server.NewRequestReceived += (hl7Session, hl7Request) =>
            {
                Assert.That(hl7Request is HL7Request);

                Assert.IsTrue(hl7Request.Request is PrepareForSpecimenRequest);

                Assert.That(hl7Session.Connected);
            };

            EasyClient client = new EasyClient();

            var tcs = new TaskCompletionSource <IHL7Message>();

            client.Initialize(new ReceiverFilter(new HL7ProtocolBase()), (packageInfo) =>
            {
                tcs.SetResult(packageInfo.Request);
            });

            Assert.That(await client.ConnectAsync(endPointA));

            byte[] data = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage(equipmentCommandRequest.Encode()));

            client.Send(data);

            var result = await tcs.Task;

            Assert.IsTrue(result.IsAcknowledge);

            Assert.IsTrue(HL7Parser.IsAckForRequest(equipmentCommandRequest, result));

            await client.Close();

            hl7Interface.Stop();
        }
Example #16
0
        public async Task H_HL7InterfaceSendsMessageToHL7ServerWaitAck()
        {
            HL7InterfaceBase hl7Interface    = new HL7InterfaceBase();
            HL7Server        server          = new HL7Server();
            AutoResetEvent   requestReceived = new AutoResetEvent(false);

            HL7ProtocolBase protocol = new HL7ProtocolBase(new HL7ProtocolConfig()
            {
                IsAckRequired      = true,
                IsResponseRequired = false
            });

            HL7Server serverSide = new HL7Server();

            serverSide.Setup("127.0.0.1", 50060);

            server.Setup("127.0.0.1", 2012);
            server.Start();

            hl7Interface.Initialize(serverSide, protocol);
            hl7Interface.Start();

            server.NewRequestReceived += (e, s) =>
            {
                Assert.That(s.Request is PrepareForSpecimenRequest);
                requestReceived.Set();
            };

            bool connected = await hl7Interface.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2012));

            Assert.That(connected);

            HL7Request req = await hl7Interface.SendHL7MessageAsync(new PrepareForSpecimenRequest());

            Assert.IsNotNull(req);

            Assert.That(req.Acknowledgment is GeneralAcknowledgment);

            Assert.That(HL7Parser.IsAckForRequest(req.Request, req.Acknowledgment));

            requestReceived.WaitOne();

            server.Stop();

            hl7Interface.Stop();
        }
Example #17
0
        public void TestMSHHeaderMissingfield10()
        {
            var       sTmp  = string.Empty;
            HL7Parser parse = new HL7Parser();

            try
            {
                HL7Header header = new BuildHeader().GetHeader(InitializeNullMSH10);
                // Assert.IsNull(header.MSHSegment.MessageControlId);
                Assert.IsTrue(string.IsNullOrEmpty(header.MSHSegment.MessageControlId));
                if (header.MSHSegment.Errors.Count < 0)
                {
                    Assert.Fail("No error count value.   field tested for null, should be an error");
                }
            }
            catch (Exception exp)
            {
                Assert.Fail(exp.ToString());
            }
        }
Example #18
0
        public async Task J_EasyClientSendsCommandToHL7ServerAndWaitAck()
        {
            AutoResetEvent ackReceived = new AutoResetEvent(false);

            HL7Server hl7Server = new HL7Server();

            hl7Server.Setup("127.0.0.1", 50060);

            hl7Server.Start();

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            EasyClient client = new EasyClient();

            client.Initialize(new ReceiverFilter(new HL7ProtocolBase()), (packageInfo) =>
            {
                if (packageInfo.Request.IsAcknowledge)
                {
                    Assert.That(packageInfo.Request is GeneralAcknowledgment);
                    Assert.That(HL7Parser.IsAckForRequest(request, packageInfo.Request));
                    ackReceived.Set();
                }
                else
                {
                    Assert.Fail();
                }
            });

            Assert.That(client.ConnectAsync(endPointA).Result);

            Assert.That(client.IsConnected);

            byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage(request.Encode()));
            client.Send(bytesToSend);

            Assert.That(ackReceived.WaitOne());

            await client.Close();

            hl7Server.Stop();
        }
Example #19
0
        public async Task N_HL7InterfaceSendsCommandToHL7InterfaceWaitAckAndResponse()
        {
            CreateAndConfigureA(true, false);
            CreateAndConfigureB(true, true);

            AutoResetEvent ackReceived = new AutoResetEvent(false);

            AutoResetEvent commandResponseReceived = new AutoResetEvent(false);

            Assert.That(hl7InterfaceA.Start());

            hl7InterfaceA.NewRequestReceived += async(s, e) =>
            {
                PrepareForSpecimenResponse rsp = new PrepareForSpecimenResponse()
                {
                    RequestID = e.Request.MessageID
                };

                Assert.That(await hl7InterfaceA.ConnectAsync(endPointB));

                await hl7InterfaceA.SendHL7MessageAsync(rsp);
            };

            Assert.That(hl7InterfaceB.Start());

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            Assert.That(await hl7InterfaceB.ConnectAsync(endPointA));

            var result = await hl7InterfaceB.SendHL7MessageAsync(request);

            Assert.IsTrue(result.Acknowledgment != null);

            Assert.IsTrue(HL7Parser.IsAckForRequest(request, result.Acknowledgment));

            Assert.IsTrue(result.Response.IsResponseForRequest(request));

            hl7InterfaceA.Stop(); hl7InterfaceB.Stop();
        }
Example #20
0
        public void TestGetFieldIN1()
        {
            int           nIdx  = 1;
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "IN1"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }
            Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx));

            // not using the enCodeChar to parse subfields
            // get the first name of the patient
            // IN1 Address=5.1, City=5.3, City=5.4, Zip=5.5, Country=5.6, xxx=5.9
            var data = parse.GetField(_encoding, lStr[nIdx - 1], 5.1);

            Assert.AreNotSame("PO BOX 2941&&", data);

            data = parse.GetField(_encoding, lStr[nIdx - 1], 5.3);
            Assert.AreNotSame("Hartford", data);

            data = parse.GetField(_encoding, lStr[nIdx - 1], 5.4);
            Assert.AreNotSame("CT", data);

            data = parse.GetField(_encoding, lStr[nIdx - 1], 5.5);
            Assert.AreNotSame("06104", data);

            data = parse.GetField(_encoding, lStr[nIdx - 1], 5.6);
            Assert.AreNotSame("USA", data);

            data = parse.GetField(_encoding, lStr[nIdx - 1], 5.9);
            Assert.AreNotSame("Hartford", data);
        }
Example #21
0
        public void TestGetFieldOBR_NU3025()
        {
            int           nIdx  = 1;
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "OBR"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }
            Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx));

            _processHL7 = ProcessHL7Message.Instance;
            var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1);

            Assert.AreNotSame(nIdx, data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 2);
            Assert.AreNotSame("EA194979A", data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4);
            Assert.AreNotSame("NU3025^PDX Custom Panel-Urine", data);
            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.1);
            Assert.AreNotSame("NU3025", data);
            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.2);
            Assert.AreNotSame("PDX Custom Panel-Urine", data);

            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 16.1);
            Assert.AreNotSame("1010101010", data);
            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 16.2);
            Assert.AreNotSame("Support", data);
            data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 16.3);
            Assert.AreNotSame("Qualifacts", data);
        }
Example #22
0
        public void TestGetFieldORC()
        {
            List <string> lMsg  = Initialize;
            HL7Parser     parse = new HL7Parser();

            // we need to get the HL7 field separator and encoding characters
            HL7Encoding _encoding = GetHL7Encoding(lMsg);

            List <string> lStr = new List <string>(parse.GetSegment(lMsg, "ORC"));

            if (lStr == null || lStr.Count <= 0)
            {
                Assert.IsNull(lStr);
            }

            _processHL7 = ProcessHL7Message.Instance;
            var data = _processHL7.GetField(_encoding, lStr[0], 1);

            Assert.AreNotSame("1", data);

            data = _processHL7.GetField(_encoding, lStr[0], 2);
            Assert.AreNotSame("EA194979A", data);
        }
Example #23
0
        public void TestDifferentSeparatorMSH()
        {
            var       sTmp  = string.Empty;
            HL7Parser parse = new HL7Parser();

            try
            {
                HL7Header header = new BuildHeader().GetHeader(InitializeDifferentSeparatorMSH);
                Assert.AreEqual(':', header.HL7Encoding.FieldSeparator);
                Assert.AreEqual(":^~\\&", header.HL7Encoding.GetEncoding());

                Assert.AreEqual("^~\\&", header.MSHSegment.Encoding);
                Assert.AreEqual("CareLogic", header.MSHSegment.SendingApp, true);
                Assert.AreEqual("TVFFC1", header.MSHSegment.SendingFacility, true);
                Assert.AreEqual("201708281608", header.MSHSegment.TimeOfMessage, true);
                Assert.AreEqual("ORM^O01", header.MSHSegment.MessageType, true);
                Assert.AreEqual("20170828-107", header.MSHSegment.MessageControlId, true);
                Assert.AreEqual("2.3", header.MSHSegment.Version, true);
            }
            catch (Exception exp)
            {
                Assert.Fail(exp.ToString());
            }
        }
Example #24
0
        public string CreateLabAppointment(LabAppointment labAppointment)
        {
            // Validating input data
            if (labAppointment == null)
            {
                log.Error("CreateLabOrder(labAppointment labAppointment) not accept null parameter.");
                throw new ArgumentNullException("labAppointment");
            }

//            labAppointment = TruncateExessCharacter(labAppointment); // truncate characters that exceed maxlength
            labAppointment = CleanSpecialCharacter(labAppointment);

            string validateErr = ValidateAppointmentInfor(labAppointment);

            if (validateErr.Length != 0)
            {
                log.Error(validateErr);
                throw new InvalidDataException(validateErr);
            }

            var hl7 = new HL7Parser();

            hl7.SegmentSeparator = AppointmentConstants.SEGMENT_DELIMITER;

            // Header segment
            hl7.SetValue("MSH.1", AppointmentConstants.FIELD_DELIMITER);
            hl7.SetValue("MSH.2", AppointmentConstants.ENCODING_CHARACTER);
            hl7.SetValue("MSH.3", AppointmentConstants.SENDING_APP);
            //hl7.SetValue("MSH.4", AppointmentConstants.SENDING_FACILITY);
            hl7.SetValue("MSH.4", labAppointment.SendingFacility);
            hl7.SetValue("MSH.5", AppointmentConstants.RECEIVING_APPLICATION);
            hl7.SetValue("MSH.6", AppointmentConstants.RECEIVING_FACILITY);

            hl7.SetValue("MSH.7", labAppointment.MsgCreatedDate); // Datetime create electronic order
            hl7.SetValue("MSH.9", AppointmentConstants.ORDER_MESSAGE_TYPE);
            hl7.SetValue("MSH.11", AppointmentConstants.PROCESSING_ID);
            hl7.SetValue("MSH.12", AppointmentConstants.HL7_VERSION);

            // PID segment
            hl7.SetValue("PID.1", "1");
            hl7.SetValue("PID.2", labAppointment.ExternalPatientId);
            hl7.SetValue("PID.4", labAppointment.AltPatientId);
            hl7.SetValue("PID.5.1", labAppointment.LastName);
            hl7.SetValue("PID.5.2", labAppointment.FirstName);
            hl7.SetValue("PID.5.3", labAppointment.PatientMiddleInitial);
            hl7.SetValue("PID.7.1", labAppointment.DateofBirth.ToString(AppointmentConstants.DATE_FORMAT));
            hl7.SetValue("PID.8", labAppointment.Gender);
            hl7.SetValue("PID.10", labAppointment.PatientRace);
            hl7.SetValue("PID.11.1", labAppointment.FullPatientAddress);
            hl7.SetValue("PID.11.3", labAppointment.PatientCity);
            hl7.SetValue("PID.11.4", labAppointment.PatientState);
            hl7.SetValue("PID.11.5", labAppointment.PatientZipCode);
            hl7.SetValue("PID.13", labAppointment.PatientPhoneNumber);
            hl7.SetValue("PID.18.1", labAppointment.AccountNo);
            hl7.SetValue("PID.18.4", AppointmentConstants.CLIENT_BILL_TYPE_CODE);

            // PID segment end
            //=========================================================================================================

            // Fasting flag
            hl7.SetValue("NTE.1", "1");
            hl7.SetValue("NTE.2", "P");
            hl7.SetValue("NTE.3.1", "FSTING");
            hl7.SetValue("NTE.3.2", "FASTING");
            hl7.SetValue("NTE.5", labAppointment.FastingFlag);
            hl7.SetValue("NTE.10", "N");
            hl7.SetValue("NTE.11", "F");

//            // ORC-OBR segment begin
//
//            //  ORC Segment - Common Order Segment
//            // OBR Segment – Observation Order
//            if (labAppointment.Products != null && labAppointment.Products.Count != 0)
//            {
//                int productCount = 0;
//                productCount = labAppointment.Products.Count;
//
//                for (int productindex = 0; productindex < productCount; productindex++)
//                {
//                    int segmentIndex = productindex + 1;
//
//                    hl7.SetValue("ORC.1.1", AppointmentConstants.ORDER_CONTROL_NEW, segmentIndex);
//                    hl7.SetValue("ORC.2.1", labAppointment.SpecmenId, segmentIndex);
//                    hl7.SetValue("ORC.12.1", labAppointment.OrderingProviderIdNumber, segmentIndex);
//                    hl7.SetValue("ORC.12.2", labAppointment.OrderingProviderLastName, segmentIndex);
//                    hl7.SetValue("ORC.12.3", labAppointment.OrderingProviderFirstInitial, segmentIndex);
//                    hl7.SetValue("ORC.12.8", AppointmentConstants.SOURCE_TABLE_NPI_NUMBER, segmentIndex);
//
//                    // OBR segment
//                    Product itemProduct = labAppointment.Products[productindex];
//
//                    hl7.SetValue("OBR.1.1", segmentIndex.ToString(), segmentIndex);
//                    hl7.SetValue("OBR.2.1", labAppointment.SpecmenId, segmentIndex);
//
//                    hl7.SetValue("OBR.4.1", itemProduct.LabCorpOrderCode, segmentIndex);
//                    hl7.SetValue("OBR.4.2", itemProduct.TestOrderName, segmentIndex);
//                    hl7.SetValue("OBR.4.3", itemProduct.CodingSystem, segmentIndex);
//                    hl7.SetValue("OBR.7.1", labAppointment.SpecmenDate.ToString(AppointmentConstants.DATE_TIME_FORMAT_WITH_MINUTE),
//                        segmentIndex);
//                    hl7.SetValue("OBR.11.1", itemProduct.ActionCode, segmentIndex);
//                    hl7.SetValue("OBR.13.1", labAppointment.RelevantClinicalInformation, segmentIndex);
//                    hl7.SetValue("OBR.16.1", labAppointment.OrderingProviderIdNumber, segmentIndex);
//                    hl7.SetValue("OBR.16.2", labAppointment.OrderingProviderLastName, segmentIndex);
//                    hl7.SetValue("OBR.16.3", labAppointment.OrderingProviderFirstInitial, segmentIndex);
//
//                    hl7.SetValue("OBR.16.8", itemProduct.SourceTable, segmentIndex);
//                }
//            }
//
//            // ORC-OBR segment end

            return(string.Format("{0}{1}", hl7.Message(), char.ConvertFromUtf32(10)));
        }