From fecb72fc208ade4d2d0c4500841c08daf0b0264f Mon Sep 17 00:00:00 2001 From: Neil South Date: Tue, 9 Jan 2024 17:28:01 +0000 Subject: [PATCH] fixing around message ack Signed-off-by: Neil South --- src/InformaticsGateway/Logging/Log.800.Hl7Service.cs | 3 +++ src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs | 7 ++++++- .../Services/HealthLevel7/MllpExtract.cs | 4 ++-- .../Services/HealthLevel7/MllpService.cs | 2 +- .../Test/Services/Common/InputHL7DataPlugInEngineTest.cs | 4 ++-- .../Test/Services/HealthLevel7/MllpClientTest.cs | 2 +- .../Integration.Test/StepDefinitions/Hl7StepDefinitions.cs | 2 +- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs b/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs index 79c4737d..b207d5f8 100755 --- a/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs +++ b/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs @@ -111,5 +111,8 @@ public static partial class Log [LoggerMessage(EventId = 829, Level = LogLevel.Trace, Message = "HL7 config Not matching message Id {senderId} configId {configID}")] public static partial void Hl7NotMatchingConfig(this ILogger logger, string senderId, string configID); + [LoggerMessage(EventId = 830, Level = LogLevel.Error, Message = "Error generating HL7 acknowledgment. for message {message}")] + public static partial void ErrorGeneratingHl7Acknowledgment(this ILogger logger, Exception ex, string message); + } } diff --git a/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs b/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs index 2f1b329d..fdf27504 100755 --- a/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs +++ b/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs @@ -159,7 +159,12 @@ private async Task SendAcknowledgment(INetworkStream clientStream, Message messa if (ShouldSendAcknowledgment(message)) { - var ackMessage = message.GetACK(); + var ackMessage = message.GetACK(true); + if (ackMessage is null) + { + _logger.ErrorGeneratingHl7Acknowledgment(new Exception(), message.HL7Message); + return; + } var ackData = new ReadOnlyMemory(ackMessage.GetMLLP()); try { diff --git a/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs b/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs index d60acf40..ccc57185 100755 --- a/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs +++ b/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs @@ -150,7 +150,7 @@ private Message RepopulateMessage(Hl7ApplicationConfigEntity config, ExternalApp { var newMess = message.HL7Message.Replace(oldvalue, details.PatientId); message = new Message(newMess); - message.ParseMessage(false); + message.ParseMessage(true); } } else if (tag == DicomTag.StudyInstanceUID) @@ -162,7 +162,7 @@ private Message RepopulateMessage(Hl7ApplicationConfigEntity config, ExternalApp { var newMess = message.HL7Message.Replace(oldvalue, details.StudyInstanceUid); message = new Message(newMess); - message.ParseMessage(false); + message.ParseMessage(true); } } } diff --git a/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs b/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs index 1ee3d0a9..0004d063 100755 --- a/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs +++ b/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs @@ -340,7 +340,7 @@ private async Task EnsureAck(NetworkStream networkStream) foreach (var message in _rawHl7Messages) { var hl7Message = new Message(message); - hl7Message.ParseMessage(false); + hl7Message.ParseMessage(true); if (hl7Message.MessageStructure == "ACK") { return; diff --git a/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs b/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs index 8dd77674..917cf5cf 100755 --- a/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs +++ b/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs @@ -115,7 +115,7 @@ public async Task GivenAnInputHL7DataPlugInEngine_WhenExecutePlugInsIsCalledWith "called"); var message = new HL7.Dotnetcore.Message(SampleMessage); - message.ParseMessage(false); + message.ParseMessage(true); await Assert.ThrowsAsync(async () => await pluginEngine.ExecutePlugInsAsync(message, dicomInfo, config)); } @@ -152,7 +152,7 @@ public async Task GivenAnInputHL7DataPlugInEngine_WhenExecutePlugInsIsCalled_Exp "called"); var message = new HL7.Dotnetcore.Message(SampleMessage); - message.ParseMessage(false); + message.ParseMessage(true); var (Hl7Message, resultDicomInfo) = await pluginEngine.ExecutePlugInsAsync(message, dicomInfo, config); diff --git a/src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs b/src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs index de8b363c..6eb27206 100755 --- a/src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs +++ b/src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs @@ -33,7 +33,7 @@ namespace Monai.Deploy.InformaticsGateway.Test.Services.HealthLevel7 { public class MllpClientTest { - private const string SampleMessage = "MSH|^~\\&|MD|MD HOSPITAL|MD Test|MONAI Deploy|202207130000|SECURITY|MD^A01^ADT_A01|MSG00001|P|2.8||||\r\n"; + private const string SampleMessage = "MSH|^~\\&|MD|MD HOSPITAL|MD Test|MONAI Deploy|202207130000|SECURITY|MD^A01^ADT_A01|MSG00001|P|2.8||||\r"; private readonly Mock _tcpClient; private readonly Hl7Configuration _config; diff --git a/tests/Integration.Test/StepDefinitions/Hl7StepDefinitions.cs b/tests/Integration.Test/StepDefinitions/Hl7StepDefinitions.cs index be93a8bc..69887eff 100755 --- a/tests/Integration.Test/StepDefinitions/Hl7StepDefinitions.cs +++ b/tests/Integration.Test/StepDefinitions/Hl7StepDefinitions.cs @@ -219,7 +219,7 @@ public async Task ThenEnsureThatExportcompleteMessagesAreSentWithSuscess(string private async Task SendAcknowledgment(NetworkStream networkStream, HL7.Dotnetcore.Message message, CancellationToken cancellationToken) { if (message == null) { return; } - var ackMessage = message.GetACK(); + var ackMessage = message.GetACK(true); var ackData = new ReadOnlyMemory(ackMessage.GetMLLP()); { try