Пример #1
0
 /// <summary>
 /// Handle an HL7 Transation from the given Actor Name.
 /// </summary>
 /// <param name="actorName">Source Actor Name.</param>
 /// <param name="hl7Transaction">HL7 Transaction.</param>
 protected override void HandleTransactionFrom(ActorName actorName, Hl7Transaction hl7Transaction)
 {
     switch (actorName.Type)
     {
         case ActorTypeEnum.AdtPatientRegistration:
             // received Patient Registration [RAD-1] or
             // received Patient Update [RAD-12]
             break;
         case ActorTypeEnum.DssOrderFiller:
             // received Filler Order Management [RAD-3] or
             // received Appointment Notification [RAD-48]
             break;
         default:
             break;
     }
 }
Пример #2
0
        private void ProcessTrigger(Hl7Trigger trigger)
        {
            _hl7Mllp = new Hl7Mllp();

            // get the next transaction number - needed to sort the
            // transactions correctly
            int transactionNumber = TransactionNumber.GetNextTransactionNumber();

            System.String message = System.String.Format("HL7 Client thread - connecting to \"{0}\" on port {1}...", _config.ToActorIpAddress, _config.PortNumber);
            _hl7ThreadForHl7Client.LogInformation(message);

            if (_hl7Mllp.Connect(_config.ToActorIpAddress, _config.PortNumber))
            {
                Hl7Message hl7RequestMessage = trigger.Trigger;

                // Set the sending and receiving applications
                hl7RequestMessage.SendingApplication = _config.FromActorAeTitle;
                hl7RequestMessage.ReceivingApplication = _config.ToActorAeTitle;

                // Add the control id and date/time of message
                hl7RequestMessage.MessageControlId = _messageControlId.ToString();
                _messageControlId++;
                hl7RequestMessage.DateTimeOfMessage = System.DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.CultureInfo.InvariantCulture);

                // get initial HL7 message delimiters from the config
                Hl7MessageDelimiters messageDelimiters = _config.MessageDelimiters;

                System.String messageType = hl7RequestMessage.Value(Hl7SegmentEnum.MSH, 9);
                _hl7ThreadForHl7Client.LogInformation(System.String.Format("HL7 Client thread - send message \"{0}\".", messageType));
                _hl7ThreadForHl7Client.LogInformation(hl7RequestMessage.ToString(messageDelimiters));

                if (_hl7Mllp.SendMessage(hl7RequestMessage, messageDelimiters) == true)
                {
                    Hl7Message hl7ResponseMessage = _hl7Mllp.ReceiveMessage(out messageDelimiters);

                    if (hl7ResponseMessage != null)
                    {
                        messageType = hl7ResponseMessage.Value(Hl7SegmentEnum.MSH, 9);
                        _hl7ThreadForHl7Client.LogInformation(System.String.Format("HL7 Client thread - received message \"{0}\".", messageType));
                        _hl7ThreadForHl7Client.LogInformation(hl7ResponseMessage.ToString(messageDelimiters));

                        // Validate the message
                        if (_config.AutoValidate == true)
                        {
                            ValidateMessage(hl7ResponseMessage, messageDelimiters);
                        }

                        // save the transaction
                        Hl7Transaction transaction = new Hl7Transaction(TransactionNameEnum.RAD_1, TransactionDirectionEnum.TransactionSent);
                        transaction.Request = hl7RequestMessage;
                        transaction.Response = hl7ResponseMessage;

                        ActorsTransaction actorsTransaction = new ActorsTransaction(transactionNumber,
                            ActorName, // from actor
                            ParentActor.ActorName,  // to actor
                            transaction,
                            _hl7ThreadForHl7Client.Options.ResultsFileNameOnly,
                            _hl7ThreadForHl7Client.Options.ResultsFullFileName,
                            (uint)_hl7ThreadForHl7Client.NrErrors,
                            (uint)_hl7ThreadForHl7Client.NrWarnings);

                        // save the transaction in the Actor log
                        ParentActor.ActorsTransactionLog.Add(actorsTransaction);

                        // publish the transaction event to any interested parties
                        PublishTransactionAvailableEvent(ActorName, actorsTransaction);
                    }
                }

                _hl7Mllp.Stop();

                _hl7ThreadForHl7Client.StopResultsGathering();
                _hl7ThreadForHl7Client.StartResultsGathering();
            }

            if (_awaitCompletion == true)
            {
                _semaphore.Signal();
            }
        }
Пример #3
0
        /// <summary>
        /// Process Hl7 requests and responses.
        /// </summary>
        public void ProcessMessages()
        {
            _hl7Mllp = new Hl7Mllp();

            for(;;)
            {
                System.String message = System.String.Format("Listening for incoming HL7 connection on port {0}...", _config.PortNumber);
                _hl7ThreadForHl7Server.LogInformation(message);

                try
                {
                    // listen for a connection
                    _hl7Mllp.Listen(_config.PortNumber);

                    for(;;)
                    {
                        // accept the connection - only one at a time
                        _hl7Mllp.Accept();

                        // the message delimiters will be filled in by the ReceiveMessage method
                        Hl7MessageDelimiters messageDelimiters = null;

                        // receive an HL7 message
                        Hl7Message hl7RequestMessage = _hl7Mllp.ReceiveMessage(out messageDelimiters);
                        if (hl7RequestMessage != null)
                        {
                            System.String messageType = hl7RequestMessage.Value(Hl7SegmentEnum.MSH, 9);
                            message = System.String.Format("HL7 Server thread - received message \"{0}\".", messageType);
                            _hl7ThreadForHl7Server.LogInformation(message);
                            _hl7ThreadForHl7Server.LogInformation(hl7RequestMessage.ToString(messageDelimiters));

                            // Validate the message
                            if (_config.AutoValidate == true)
                            {
                                ValidateMessage(hl7RequestMessage, messageDelimiters);
                            }

                            // call the message handler to get a response
                            Hl7Message hl7ResponseMessage = MessageHandler(hl7RequestMessage);

                            // copy some fields from the request
                            hl7ResponseMessage.SendingApplication = hl7RequestMessage.ReceivingApplication;
                            hl7ResponseMessage.SendingFacility = hl7RequestMessage.ReceivingFacility;
                            hl7ResponseMessage.ReceivingApplication = hl7RequestMessage.SendingApplication;
                            hl7ResponseMessage.ReceivingFacility = hl7RequestMessage.SendingFacility;
                            hl7ResponseMessage.MessageControlId = hl7RequestMessage.MessageControlId;

                            // set the date/time of message
                            hl7ResponseMessage.DateTimeOfMessage = System.DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.CultureInfo.InvariantCulture);

                            // send the response
                            _hl7Mllp.SendMessage(hl7ResponseMessage, messageDelimiters);

                            messageType = hl7ResponseMessage.Value(Hl7SegmentEnum.MSH, 9);
                            message = System.String.Format("HL7 Server thread - sent message \"{0}\".", messageType);
                            _hl7ThreadForHl7Server.LogInformation(message);
                            _hl7ThreadForHl7Server.LogInformation(hl7ResponseMessage.ToString(messageDelimiters));

                            // get the next transaction number - needed to sort the
                            // transactions correctly
                            int transactionNumber = TransactionNumber.GetNextTransactionNumber();

                            // save the transaction
                            Hl7Transaction transaction = new Hl7Transaction(TransactionNameEnum.RAD_1, TransactionDirectionEnum.TransactionReceived);
                            transaction.Request = hl7RequestMessage;
                            transaction.Response = hl7ResponseMessage;

                            _hl7ThreadForHl7Server.LogInformation(String.Format("{0} - received Hl7 event from {1}", ParentActor.ActorName, ActorName));

                            ActorsTransaction actorsTransaction = new ActorsTransaction(transactionNumber,
                                ActorName,  // from actor
                                ParentActor.ActorName,  // to actor
                                transaction,
                                _hl7ThreadForHl7Server.Options.ResultsFileNameOnly,
                                _hl7ThreadForHl7Server.Options.ResultsFullFileName,
                                (uint)_hl7ThreadForHl7Server.NrErrors,
                                (uint)_hl7ThreadForHl7Server.NrWarnings);

                            // save the transaction in the Actor log
                            ParentActor.ActorsTransactionLog.Add(actorsTransaction);

                            // publish the transaction event to any interested parties
                            PublishTransactionAvailableEvent(ActorName, actorsTransaction);
                        }

                        _hl7Mllp.Close();

                        _hl7ThreadForHl7Server.StopResultsGathering();
                        _hl7ThreadForHl7Server.StartResultsGathering();
                    }
                }
                catch
                {
                    // System.Net.Sockets.Socket.Accept() exception thrown when the server is stopped by closing the listen socket.
                    break;
                }
            }
        }
Пример #4
0
        private void ProcessTrigger(Hl7Trigger trigger)
        {
            _hl7Mllp = new Hl7Mllp();

            // get the next transaction number - needed to sort the
            // transactions correctly
            int transactionNumber = TransactionNumber.GetNextTransactionNumber();

            System.String message = System.String.Format("HL7 Client thread - connecting to \"{0}\" on port {1}...", _config.ToActorIpAddress, _config.PortNumber);
            _hl7ThreadForHl7Client.LogInformation(message);

            if (_hl7Mllp.Connect(_config.ToActorIpAddress, _config.PortNumber))
            {
                Hl7Message hl7RequestMessage = trigger.Trigger;

                // Set the sending and receiving applications
                hl7RequestMessage.SendingApplication   = _config.FromActorAeTitle;
                hl7RequestMessage.ReceivingApplication = _config.ToActorAeTitle;

                // Add the control id and date/time of message
                hl7RequestMessage.MessageControlId = _messageControlId.ToString();
                _messageControlId++;
                hl7RequestMessage.DateTimeOfMessage = System.DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.CultureInfo.InvariantCulture);

                // get initial HL7 message delimiters from the config
                Hl7MessageDelimiters messageDelimiters = _config.MessageDelimiters;

                System.String messageType = hl7RequestMessage.Value(Hl7SegmentEnum.MSH, 9);
                _hl7ThreadForHl7Client.LogInformation(System.String.Format("HL7 Client thread - send message \"{0}\".", messageType));
                _hl7ThreadForHl7Client.LogInformation(hl7RequestMessage.ToString(messageDelimiters));

                if (_hl7Mllp.SendMessage(hl7RequestMessage, messageDelimiters) == true)
                {
                    Hl7Message hl7ResponseMessage = _hl7Mllp.ReceiveMessage(out messageDelimiters);

                    if (hl7ResponseMessage != null)
                    {
                        messageType = hl7ResponseMessage.Value(Hl7SegmentEnum.MSH, 9);
                        _hl7ThreadForHl7Client.LogInformation(System.String.Format("HL7 Client thread - received message \"{0}\".", messageType));
                        _hl7ThreadForHl7Client.LogInformation(hl7ResponseMessage.ToString(messageDelimiters));

                        // Validate the message
                        if (_config.AutoValidate == true)
                        {
                            ValidateMessage(hl7ResponseMessage, messageDelimiters);
                        }

                        // save the transaction
                        Hl7Transaction transaction = new Hl7Transaction(TransactionNameEnum.RAD_1, TransactionDirectionEnum.TransactionSent);
                        transaction.Request  = hl7RequestMessage;
                        transaction.Response = hl7ResponseMessage;

                        ActorsTransaction actorsTransaction = new ActorsTransaction(transactionNumber,
                                                                                    ActorName,             // from actor
                                                                                    ParentActor.ActorName, // to actor
                                                                                    transaction,
                                                                                    _hl7ThreadForHl7Client.Options.ResultsFileNameOnly,
                                                                                    _hl7ThreadForHl7Client.Options.ResultsFullFileName,
                                                                                    (uint)_hl7ThreadForHl7Client.NrErrors,
                                                                                    (uint)_hl7ThreadForHl7Client.NrWarnings);

                        // save the transaction in the Actor log
                        ParentActor.ActorsTransactionLog.Add(actorsTransaction);

                        // publish the transaction event to any interested parties
                        PublishTransactionAvailableEvent(ActorName, actorsTransaction);
                    }
                }

                _hl7Mllp.Stop();

                _hl7ThreadForHl7Client.StopResultsGathering();
                _hl7ThreadForHl7Client.StartResultsGathering();
            }

            if (_awaitCompletion == true)
            {
                _semaphore.Signal();
            }
        }
Пример #5
0
 /// <summary>
 /// Handle an HL7 Transation from the given Actor Name.
 /// </summary>
 /// <param name="actorName">Source Actor Name.</param>
 /// <param name="hl7Transaction">HL7 Transaction.</param>
 protected virtual void HandleTransactionFrom(ActorName actorName, Hl7Transaction hl7Transaction)
 {
 }
Пример #6
0
        /// <summary>
        /// Handle an HL7 Transation from the given Actor Name.
        /// </summary>
        /// <param name="actorName">Source Actor Name.</param>
        /// <param name="hl7Transaction">HL7 Transaction.</param>
        protected override void HandleTransactionFrom(ActorName actorName, Hl7Transaction hl7Transaction)
        {
            Hl7Message request = hl7Transaction.Request;

            switch (actorName.Type)
            {
                case ActorTypeEnum.AdtPatientRegistration:
                    // received Patient Registration [RAD-1] or
                    // received Patient Update [RAD-12]
                    if (request.MessageType == "ADT")
                    {
                        switch(request.MessageSubType)
                        {
                            case "A01" :
                                {
            //									HandlePatientRegistration(request);
                                }
                                break;

                            case "A08" :
                                {
                                    HandlePatientUpdate(request);

                                    // Generate trigger
                                    Hl7Trigger trigger = new Hl7Trigger(TransactionNameEnum.RAD_12);
                                    trigger.Trigger = request;

                                    // RAD-12 - trigger the ImageManager
                                    bool triggerResult = TriggerActorInstances(ActorTypeEnum.ImageManager, trigger, false);
                                }
                                break;

                            case "A40" :
                                {
                                    HandlePatientMerge(request);

                                    // Generate trigger
                                    Hl7Trigger trigger = new Hl7Trigger(TransactionNameEnum.RAD_12);
                                    trigger.Trigger = request;

                                    // RAD-12 - trigger the ImageManager
                                    bool triggerResult = TriggerActorInstances(ActorTypeEnum.ImageManager, trigger, false);
                                }
                                break;
                        }
                    }
                    break;
                case ActorTypeEnum.OrderPlacer:
                    // received Placer Order Management [RAD-2]
                    if (request.MessageType == "ORM")
                    {
                        switch(request.MessageSubType)
                        {
                            case "O01" :
                                HandlePlacerOrderManagement(request);
                                break;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
Пример #7
0
        /// <summary>
        /// Handle an HL7 Transation from the given Actor Name.
        /// </summary>
        /// <param name="actorName">Source Actor Name.</param>
        /// <param name="hl7Transaction">HL7 Transaction.</param>
        protected override void HandleTransactionFrom(ActorName actorName, Hl7Transaction hl7Transaction)
        {
            Hl7Message request = hl7Transaction.Request;

            switch (actorName.Type)
            {
                case ActorTypeEnum.DssOrderFiller:
                    // received Procedure Scheduled [RAD-4] or
                    // received Patient Update [Rad-12] or
                    // received Procedure Updated [RAD-13]
                    UpdateImageArchiveActor(request);
                    break;
                default:
                    break;
            }
        }
Пример #8
0
        /// <summary>
        /// Process Hl7 requests and responses.
        /// </summary>
        public void ProcessMessages()
        {
            _hl7Mllp = new Hl7Mllp();

            for (;;)
            {
                System.String message = System.String.Format("Listening for incoming HL7 connection on port {0}...", _config.PortNumber);
                _hl7ThreadForHl7Server.LogInformation(message);

                try
                {
                    // listen for a connection
                    _hl7Mllp.Listen(_config.PortNumber);

                    for (;;)
                    {
                        // accept the connection - only one at a time
                        _hl7Mllp.Accept();

                        // the message delimiters will be filled in by the ReceiveMessage method
                        Hl7MessageDelimiters messageDelimiters = null;

                        // receive an HL7 message
                        Hl7Message hl7RequestMessage = _hl7Mllp.ReceiveMessage(out messageDelimiters);
                        if (hl7RequestMessage != null)
                        {
                            System.String messageType = hl7RequestMessage.Value(Hl7SegmentEnum.MSH, 9);
                            message = System.String.Format("HL7 Server thread - received message \"{0}\".", messageType);
                            _hl7ThreadForHl7Server.LogInformation(message);
                            _hl7ThreadForHl7Server.LogInformation(hl7RequestMessage.ToString(messageDelimiters));

                            // Validate the message
                            if (_config.AutoValidate == true)
                            {
                                ValidateMessage(hl7RequestMessage, messageDelimiters);
                            }

                            // call the message handler to get a response
                            Hl7Message hl7ResponseMessage = MessageHandler(hl7RequestMessage);

                            // copy some fields from the request
                            hl7ResponseMessage.SendingApplication   = hl7RequestMessage.ReceivingApplication;
                            hl7ResponseMessage.SendingFacility      = hl7RequestMessage.ReceivingFacility;
                            hl7ResponseMessage.ReceivingApplication = hl7RequestMessage.SendingApplication;
                            hl7ResponseMessage.ReceivingFacility    = hl7RequestMessage.SendingFacility;
                            hl7ResponseMessage.MessageControlId     = hl7RequestMessage.MessageControlId;

                            // set the date/time of message
                            hl7ResponseMessage.DateTimeOfMessage = System.DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.CultureInfo.InvariantCulture);

                            // send the response
                            _hl7Mllp.SendMessage(hl7ResponseMessage, messageDelimiters);

                            messageType = hl7ResponseMessage.Value(Hl7SegmentEnum.MSH, 9);
                            message     = System.String.Format("HL7 Server thread - sent message \"{0}\".", messageType);
                            _hl7ThreadForHl7Server.LogInformation(message);
                            _hl7ThreadForHl7Server.LogInformation(hl7ResponseMessage.ToString(messageDelimiters));

                            // get the next transaction number - needed to sort the
                            // transactions correctly
                            int transactionNumber = TransactionNumber.GetNextTransactionNumber();

                            // save the transaction
                            Hl7Transaction transaction = new Hl7Transaction(TransactionNameEnum.RAD_1, TransactionDirectionEnum.TransactionReceived);
                            transaction.Request  = hl7RequestMessage;
                            transaction.Response = hl7ResponseMessage;

                            _hl7ThreadForHl7Server.LogInformation(String.Format("{0} - received Hl7 event from {1}", ParentActor.ActorName, ActorName));

                            ActorsTransaction actorsTransaction = new ActorsTransaction(transactionNumber,
                                                                                        ActorName,             // from actor
                                                                                        ParentActor.ActorName, // to actor
                                                                                        transaction,
                                                                                        _hl7ThreadForHl7Server.Options.ResultsFileNameOnly,
                                                                                        _hl7ThreadForHl7Server.Options.ResultsFullFileName,
                                                                                        (uint)_hl7ThreadForHl7Server.NrErrors,
                                                                                        (uint)_hl7ThreadForHl7Server.NrWarnings);

                            // save the transaction in the Actor log
                            ParentActor.ActorsTransactionLog.Add(actorsTransaction);

                            // publish the transaction event to any interested parties
                            PublishTransactionAvailableEvent(ActorName, actorsTransaction);
                        }

                        _hl7Mllp.Close();

                        _hl7ThreadForHl7Server.StopResultsGathering();
                        _hl7ThreadForHl7Server.StartResultsGathering();
                    }
                }
                catch
                {
                    // System.Net.Sockets.Socket.Accept() exception thrown when the server is stopped by closing the listen socket.
                    break;
                }
            }
        }