Esempio n. 1
0
        public async Task O_HL7InterfaceSelfConnectShouldFail()
        {
            HL7InterfaceBase hl7InterfaceA = new HL7InterfaceBase();

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

            HL7Server serverA = new HL7Server();

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

            Assert.IsTrue(hl7InterfaceA.Initialize(serverA, protocolA));

            Assert.That(hl7InterfaceA.Start());

            hl7InterfaceA.NewSessionConnected += (e) =>
            {
            };

            Assert.IsFalse(await hl7InterfaceA.ConnectAsync(endPointA));

            hl7InterfaceA.Stop();
        }
Esempio n. 2
0
        public virtual bool Initialize(IProtocolConfig protocolConfig, IServerConfig serverConfig, HL7ProtocolBase hL7Protocol = null)
        {
            if (!m_HL7Server.Setup(serverConfig))
            {
                return(false);
            }

            if (hL7Protocol != null)
            {
                m_HL7Protocol = hL7Protocol;
            }

            m_HL7Protocol.Config = protocolConfig;

            m_LocalEndpoint = new IPEndPoint(IPAddress.Parse(m_HL7Server.Config.Ip), m_HL7Server.Config.Port);

            m_EasyClient.Initialize(new ReceiverFilter(m_HL7Protocol), (request) =>
            {
                if (request.Request.IsAcknowledge)
                {
                    m_HL7Server.Logger.Info($"CALLBACK: Ack captured {request.Request.GetValue("MSA-2")}");
                    ProcessIncomingAck(request.Request);
                }
                else
                {
                    ProcessIncomingRequest(request);
                }
            });

            NewRequestReceived += OnNewRequestReceived;

            return(true);
        }
Esempio n. 3
0
        public async Task I_HL7InterfaceSendsMessageToHL7ServerWaitAckAndResponseTest()
        {
            HL7InterfaceBase hl7Interface    = new HL7InterfaceBase();
            HL7Server        server          = new HL7Server();
            AutoResetEvent   requestReceived = new AutoResetEvent(false);

            HL7ProtocolBase protocol = new HL7ProtocolBase(new HL7ProtocolConfig()
            {
                IsAckRequired      = true,
                IsResponseRequired = true,
                AckTimeout         = 10000,
                ResponseTimeout    = 50000
            });

            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();
                Thread.Sleep(500);
                byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage((new PrepareForSpecimenResponse()).Encode()));
                e.Send(bytesToSend, 0, bytesToSend.Length);
            };

            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(req.Acknowledgment.IsAckForRequest(req.Request));

            Assert.That(req.Acknowledgment.GetValue("MSA-1") == "AA");

            Assert.IsNotNull(req.Response);

            Assert.That(req.Response.IsResponseForRequest(req.Request));

            requestReceived.WaitOne();

            server.Stop();

            hl7Interface.Stop();
        }
Esempio n. 4
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();
        }
Esempio n. 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();
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public async Task G_HL7InterfaceSendsMessageToHL7ServerNoAckNoResponse()
        {
            HL7InterfaceBase hl7Interface = new HL7InterfaceBase();

            HL7Server server = new HL7Server();

            AutoResetEvent requestReceived = new AutoResetEvent(false);

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

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

            HL7Server serverSide = new HL7Server();

            serverSide.Setup("127.0.0.1", 50060);

            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"), 50050));

            Assert.That(connected);

            await hl7Interface.SendHL7MessageAsync(new PrepareForSpecimenRequest());

            requestReceived.WaitOne();

            server.Stop();

            hl7Interface.Stop();
        }
Esempio n. 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();
        }
Esempio n. 9
0
        public async Task B_ConnectHL7InterfaceToAppServer()
        {
            HL7InterfaceBase hl7Interface = new HL7InterfaceBase();

            HL7Server server = new HL7Server();

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

            Assert.That(hl7Interface.Initialize());

            Assert.That(hl7Interface.Start());

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

            Assert.That(connected);

            server.Stop();

            hl7Interface.Stop();
        }
Esempio n. 10
0
        public void Init()
        {
            State        = new Ready();
            HL7Interface = new HL7Interface.HL7InterfaceBase();

            HL7Server server = new HL7Server();

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

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

            HL7Server serverSide = new HL7Server();

            serverSide.Setup("127.0.0.1", 50060);

            HL7Interface.Initialize(serverSide, protocol);

            HL7Interface.Start();
        }