Пример #1
0
        /// <summary>
        /// Do this before processing the Client Trigger.
        /// </summary>
        /// <param name="trigger">Trigger message.</param>
        public override void BeforeProcessTrigger(Object trigger)
        {
            // call the base implementation
            base.BeforeProcessTrigger(trigger);

            // get the next transaction number - needed to sort the
            // transactions correctly
            _transactionNumber = TransactionNumber.GetNextTransactionNumber();
        }
Пример #2
0
        private void LogTransaction()
        {
            DicomThread dicomThread = (DicomThread)DvtkHighLevelInterface.Common.Threads.Thread.CurrentThread;

            if (dicomThread == null)
            {
                return;
            }

            if (_currentDicomTransaction == null)
            {
                return;
            }

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

            // save the transaction
            ActorsTransaction actorsTransaction = new ActorsTransaction(transactionNumber,
                                                                        ActorName,             // from actor
                                                                        ParentActor.ActorName, // to actor
                                                                        _currentDicomTransaction,
                                                                        dicomThread.Options.ResultsFileNameOnly,
                                                                        dicomThread.Options.ResultsFullFileName,
                                                                        (uint)dicomThread.NrOfErrors,
                                                                        (uint)dicomThread.NrOfWarnings);

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

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

            // remove any messages from the dicom thread
            dicomThread.ClearMessages();

            _currentDicomTransaction = null;
        }
Пример #3
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();
            }
        }
Пример #4
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;
                }
            }
        }