Skip to content

Commit 959816b

Browse files
committed
merge in develop
Signed-off-by: Neil South <[email protected]>
2 parents ff173a0 + eb841e4 commit 959816b

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

src/InformaticsGateway/Logging/Log.5000.DataPlugins.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ public static partial class Log
4848
[LoggerMessage(EventId = 5008, Level = LogLevel.Trace, Message = "InputDataPlugInEngine: {pluginName} executed. fileMetadata now: {fileMetadata}")]
4949
public static partial void ExecutedInputDataPlugIn(this ILogger logger, string pluginName, string fileMetadata);
5050

51+
[LoggerMessage(EventId = 5009, Level = LogLevel.Trace, Message = "Import plugin executed: {pluginName}. now: {fileMetadata}")]
52+
public static partial void InputDataPlugInEngineexecuted(this ILogger logger, string pluginName, string fileMetadata);
5153
}
5254
}

src/InformaticsGateway/Services/Common/InputDataPluginEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<Tuple<DicomFile, FileStorageMetadata>> ExecutePlugInsAsync(Dic
5050
_logger.ExecutingInputDataPlugIn(plugin.Name);
5151
(dicomFile, fileMetadata) = await plugin.ExecuteAsync(dicomFile, fileMetadata).ConfigureAwait(false);
5252

53-
_logger.ExecutedInputDataPlugIn(plugin.Name, JsonSerializer.Serialize(fileMetadata));
53+
_logger.InputDataPlugInEngineexecuted(plugin.Name, JsonSerializer.Serialize(fileMetadata));
5454
}
5555

5656
return new Tuple<DicomFile, FileStorageMetadata>(dicomFile, fileMetadata);

src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
using System;
1818
using System.Collections.Generic;
19-
using System.Linq;
2019
using System.Text;
2120
using System.Threading;
2221
using System.Threading.Tasks;
@@ -54,8 +53,8 @@ public MllpClient(ITcpClientAdapter client, Hl7Configuration configurations, ILo
5453
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
5554

5655
ClientId = Guid.NewGuid();
57-
_exceptions = new List<Exception>();
58-
_messages = new List<Message>();
56+
_exceptions = [];
57+
_messages = [];
5958

6059
_loggerScope = _logger.BeginScope(new LoggingDataDictionary<string, object> { { "Endpoint", _client.RemoteEndPoint }, { "CorrelationId", ClientId } })!;
6160
}
@@ -159,10 +158,23 @@ private async Task SendAcknowledgment(INetworkStream clientStream, Message messa
159158

160159
if (ShouldSendAcknowledgment(message))
161160
{
162-
var ackMessage = message.GetACK(true);
161+
Message ackMessage;
162+
try
163+
{
164+
ackMessage = message.GetACK(true);
165+
}
166+
catch (Exception ex)
167+
{
168+
_logger.ErrorGeneratingHl7Acknowledgment(ex, message.HL7Message);
169+
_exceptions.Add(ex);
170+
return;
171+
}
172+
163173
if (ackMessage is null)
164174
{
165-
_logger.ErrorGeneratingHl7Acknowledgment(new Exception(), message.HL7Message);
175+
var ex = new Exception("Error generating HL7 acknowledgment.");
176+
_logger.ErrorGeneratingHl7Acknowledgment(ex, message.HL7Message);
177+
_exceptions.Add(ex);
166178
return;
167179
}
168180
var ackData = new ReadOnlyMemory<byte>(ackMessage.GetMLLP());
@@ -196,8 +208,8 @@ private bool ShouldSendAcknowledgment(Message message)
196208
return value.Value switch
197209
{
198210
Resources.AcknowledgmentTypeNever => false,
199-
Resources.AcknowledgmentTypeError => _exceptions.Any(),
200-
Resources.AcknowledgmentTypeSuccessful => !_exceptions.Any(),
211+
Resources.AcknowledgmentTypeError => _exceptions.Count is not 0,
212+
Resources.AcknowledgmentTypeSuccessful => _exceptions.Count is 0,
201213
_ => true,
202214
};
203215
}

src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,11 @@
3030

3131
namespace Monai.Deploy.InformaticsGateway.Api.Mllp
3232
{
33-
public sealed class MllpExtract : IMllpExtract
33+
public sealed class MllpExtract(IHl7ApplicationConfigRepository hl7ApplicationConfigRepository, IExternalAppDetailsRepository externalAppDetailsRepository, ILogger<MllpExtract> logger) : IMllpExtract
3434
{
35-
private readonly ILogger<MllpExtract> _logger;
36-
private readonly IHl7ApplicationConfigRepository _hl7ApplicationConfigRepository;
37-
private readonly IExternalAppDetailsRepository _externalAppDetailsRepository;
38-
39-
public MllpExtract(IHl7ApplicationConfigRepository hl7ApplicationConfigRepository, IExternalAppDetailsRepository externalAppDetailsRepository, ILogger<MllpExtract> logger)
40-
{
41-
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
42-
_hl7ApplicationConfigRepository = hl7ApplicationConfigRepository ?? throw new ArgumentNullException(nameof(hl7ApplicationConfigRepository));
43-
_externalAppDetailsRepository = externalAppDetailsRepository ?? throw new ArgumentNullException(nameof(externalAppDetailsRepository));
44-
}
45-
35+
private readonly ILogger<MllpExtract> _logger = logger ?? throw new ArgumentNullException(nameof(logger));
36+
private readonly IHl7ApplicationConfigRepository _hl7ApplicationConfigRepository = hl7ApplicationConfigRepository ?? throw new ArgumentNullException(nameof(hl7ApplicationConfigRepository));
37+
private readonly IExternalAppDetailsRepository _externalAppDetailsRepository = externalAppDetailsRepository ?? throw new ArgumentNullException(nameof(externalAppDetailsRepository));
4638

4739
public async Task<Message> ExtractInfo(Hl7FileStorageMetadata meta, Message message, Hl7ApplicationConfigEntity configItem)
4840
{

src/InformaticsGateway/Services/HealthLevel7/MllpService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public int ActiveConnections
7676

7777
public string ServiceName => "HL7 Service";
7878

79-
public MllpService(IServiceScopeFactory serviceScopeFactory,
80-
IOptions<InformaticsGatewayConfiguration> configuration)
79+
public MllpService(IServiceScopeFactory serviceScopeFactory, IOptions<InformaticsGatewayConfiguration> configuration)
8180
{
8281
ArgumentNullException.ThrowIfNull(serviceScopeFactory, nameof(serviceScopeFactory));
8382

@@ -281,7 +280,7 @@ public async Task SendMllp(IPAddress address, int port, string hl7Message, Cance
281280
catch (Exception ex)
282281
{
283282
_logger.Hl7SendException(ex);
284-
throw new Hl7SendException("Send exception");
283+
throw new Hl7SendException($"Send exception: {ex.Message}");
285284
}
286285
}
287286

src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ public async Task ReceiveData_InvalidMessage()
134134
{
135135
await Task.Run(() =>
136136
{
137-
Assert.Empty(results.Messages);
138137
Assert.NotNull(results.AggregateException);
139-
Assert.Single(results.AggregateException.InnerExceptions);
140-
Assert.Contains("Failed to validate the message with error", results.AggregateException.InnerExceptions.First().Message);
138+
Assert.Equal(1, results.AggregateException.InnerExceptions.Count);
141139
});
142140
});
143141
await client.Start(action, _cancellationTokenSource.Token);

0 commit comments

Comments
 (0)