/// <summary> /// Trigger the Client. /// </summary> /// <param name="actorName">Destination Actor Name.</param> /// <param name="trigger">Trigger message.</param> /// <param name="awaitCompletion">Boolean indicating whether this a synchronous call or not.</param> /// <returns>Boolean indicating success or failure.</returns> public bool TriggerClient(ActorName actorName, BaseTrigger trigger, bool awaitCompletion) { _awaitCompletion = awaitCompletion; Hl7Trigger hl7Trigger = (Hl7Trigger)trigger; _triggerQueue.Enqueue(hl7Trigger); // Check if this is a synchronous call or not if (_awaitCompletion == true) { // Timeout of 0 means "no timeout". _semaphore.Wait(0); } return(true); }
private AdrMessage GetMatchingResponse(System.String patientId) { AdrMessage hl7ResponseMessage = null; foreach (BaseTrigger baseTrigger in _responseList) { if (baseTrigger is Hl7Trigger) { Hl7Trigger hl7Trigger = (Hl7Trigger)baseTrigger; AdrMessage lHl7ResponseMessage = (AdrMessage)hl7Trigger.Trigger; if (lHl7ResponseMessage.PID[3] == patientId) { hl7ResponseMessage = lHl7ResponseMessage; break; } } } return(hl7ResponseMessage); }
/// <summary> /// Process Hl7 requests and responses. /// </summary> public void ProcessMessages() { _looping = true; while (_looping == true) { // Check if anything has been queued while (_triggerQueue.Count != 0) { // Get the trigger Hl7Trigger trigger = (Hl7Trigger)_triggerQueue.Dequeue(); if (trigger != null) { // Process the trigger ProcessTrigger(trigger); // Wait awhile before processing new Trigger System.Threading.Thread.Sleep(1000); } } System.Threading.Thread.Sleep(_loopDelay); } }
/// <summary> /// Add response trigger to server. /// </summary> /// <param name="actorName">Destination Actor Name.</param> /// <param name="trigger">Trigger message.</param> public void AddResponseTrigger(ActorName actorName, BaseTrigger trigger) { Hl7Trigger hl7Trigger = (Hl7Trigger)trigger; _responseList.Add(hl7Trigger); }
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(); } }