Пример #1
0
        public void  R_Ack_Not_Received_Scenario()
        {
            CreateAndConfigureA(true, false, 5000);

            FakeHL7Server fakeHL7Server = new FakeHL7Server();

            IServerConfig fakeHL7ServerConfig = new ServerConfig()
            {
                Ip   = "127.0.0.1",
                Port = 50050
            };

            Assert.That(hl7InterfaceA.Start());

            Assert.IsTrue(fakeHL7Server.Setup(fakeHL7ServerConfig));

            Assert.That(fakeHL7Server.Start());

            var connectionTask = hl7InterfaceA.ConnectAsync(endPointB);

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            Assert.ThrowsAsync(Is.TypeOf <HL7InterfaceException>()

                               .And.Message.EqualTo($"The message was not acknowledged after a total number of 0 retries"),

                               async() => await hl7InterfaceA.SendHL7MessageAsync(request));

            fakeHL7Server.Stop(); hl7InterfaceA.Stop();
        }
Пример #2
0
        public async Task P_Stopping_Interface_Should_Cancel_Incompleted_SenderTask()
        {
            CreateAndConfigureA(true, true, 5000);
            CreateAndConfigureB(true, false);

            AutoResetEvent ackReceived = new AutoResetEvent(false);

            AutoResetEvent commandResponseReceived = new AutoResetEvent(false);

            Assert.That(hl7InterfaceA.Start());

            Assert.That(hl7InterfaceB.Start());

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

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

            var senderTask = hl7InterfaceA.SendHL7MessageAsync(request);

            await Task.Delay(10);

            hl7InterfaceA.Stop();

            Assert.IsTrue(senderTask.IsCompleted);

            hl7InterfaceB.Stop();
        }
Пример #3
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();
        }
Пример #4
0
        public void TestPositiveAckConstruction()
        {
            PrepareForSpecimenRequest prepare = new PrepareForSpecimenRequest();

            HL7Parser p = new HL7Parser();

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

            Assert.IsTrue(result.MessageAccepted);

            Assert.IsTrue(result.Acknowledge.IsAckForRequest(prepare));
        }
Пример #5
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();
        }
Пример #6
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();
        }
Пример #7
0
        public async Task F_HL7InterfaceReceivesHL7MessageSendsAResponseToEasyClient()
        {
            HL7InterfaceBase hl7Interface = new HL7InterfaceBase();

            AutoResetEvent newRequestReceived = new AutoResetEvent(false);

            Assert.IsTrue(hl7Interface.Initialize());

            Assert.IsTrue(hl7Interface.Start());

            PrepareForSpecimenRequest equipmentCommandRequest = new PrepareForSpecimenRequest();

            hl7Interface.HL7Server.NewSessionConnected += (hl7Session) =>
            {
                Assert.That(hl7Session.Connected);

                string response = MLLP.CreateMLLPMessage((new PrepareForSpecimenResponse()).Encode());

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

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

            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));

            var result = await tcs.Task;

            Assert.IsTrue(result is PrepareForSpecimenResponse);

            await client.Close();

            hl7Interface.Stop();
        }
Пример #8
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();
        }
Пример #9
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();
        }
        public void A_CreateAndParsePrepareForSpecimenAcquisition()
        {
            PrepareForSpecimenRequest prepare = new PrepareForSpecimenRequest();

            Assert.AreEqual(nameof(PrepareForSpecimenRequest), prepare.MessageID);

            Assert.AreEqual("2.5.1", prepare.HL7Version);

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

            Assert.AreEqual(nameof(PrepareForSpecimenResponse), prepare.ExpectedResponseID);

            Assert.AreEqual("U07", prepare.TriggerEvent);

            Assert.AreEqual("EAC", prepare.MessageCode);

            Assert.AreEqual("EAR_U08", prepare.ExpectedResponseType);

            Assert.AreEqual("ACK_U07", prepare.ExpectedAckType);

            Assert.IsFalse(prepare.IsAcknowledge);

            Assert.IsTrue(Regex.Match(prepare.ControlID, pattern, RegexOptions.IgnoreCase).Success);

            string prepareRcv = @"MSH|^~\&|||||20190322123829||EAC^U07^EAC_U07|728d2456-339c-4d34-b7ad-c41b1e4cff34||2.5.1|||||||||PrepareForSpecimenRequest|
            EQU||20190322123829
            ECD||LO^Prepare^ASTM|Y
            SAC|||123";

            ParserResult result = parser.Parse(prepareRcv);

            Assert.IsNotNull(result);

            Assert.IsTrue(result.MessageAccepted);

            Assert.IsTrue(result.IsAcknowledge.HasValue && !result.IsAcknowledge.Value);

            Assert.IsNotNull(result.ParsedMessage);

            Assert.IsTrue(result.ParsedMessage is PrepareForSpecimenRequest);

            PrepareForSpecimenRequest prepareForSpecimen = (PrepareForSpecimenRequest)result.ParsedMessage;

            Assert.IsTrue(prepareForSpecimen.GetValue("/COMMAND(0)/SPECIMEN_CONTAINER/SAC-3") == "123");

            Assert.IsTrue(prepareForSpecimen.MessageID == "PrepareForSpecimenRequest");

            Assert.IsTrue(prepareForSpecimen.MessageID == typeof(PrepareForSpecimenRequest).Name);

            Assert.IsTrue(prepareForSpecimen.HL7Version == "2.5.1");

            //Assert.IsTrue(prepare.ProcessingID == "P");

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

            Assert.AreEqual(nameof(PrepareForSpecimenResponse), prepareForSpecimen.ExpectedResponseID);

            Assert.IsFalse(prepareForSpecimen.IsAcknowledge);

            Assert.AreEqual("728d2456-339c-4d34-b7ad-c41b1e4cff34", prepareForSpecimen.ControlID);

            //Assert.AreEqual("20190322123829", prepareForSpecimen.MessageDateTime.ToString("yyyyMMddHHmmss"));

            //ARANGE & ACT
            GeneralAcknowledgment ack = result.Acknowledge as GeneralAcknowledgment;

            //ASSERTS
            Assert.IsNotNull(ack);

            //Assert.IsTrue(ack.AckType == AckTypes.AA);

            Assert.IsTrue(ack.MessageID == "GeneralAcknowledgment");

            Assert.IsTrue(ack.TriggerEvent == "U07");

            Assert.IsTrue(ack.MessageCode == "ACK");

            Assert.IsTrue(prepare.HL7Version == "2.5.1");

            Assert.IsTrue(ack.ExpectedAckID == "");

            Assert.AreEqual(string.Empty, ack.ExpectedAckID);

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

            Assert.AreEqual(string.Empty, ack.ExpectedResponseType);

            Assert.AreEqual(string.Empty, ack.ExpectedAckType);

            Assert.IsTrue(ack.IsAcknowledge);

            var regex1 = new Regex(@"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$");

            //StringAssert.Matches(ack.MessageID, regex1, "The MSH-10 shoul be a guid");

            Assert.IsTrue(ack.IsAckForRequest(prepareForSpecimen));
        }