diff --git a/src/Api/Storage/Hl7FileStorageMetadata.cs b/src/Api/Storage/Hl7FileStorageMetadata.cs
index 576f88ae..b4e33aed 100755
--- a/src/Api/Storage/Hl7FileStorageMetadata.cs
+++ b/src/Api/Storage/Hl7FileStorageMetadata.cs
@@ -27,7 +27,7 @@ namespace Monai.Deploy.InformaticsGateway.Api.Storage
public sealed record Hl7FileStorageMetadata : FileStorageMetadata
{
public const string Hl7SubDirectoryName = "ehr";
- public const string FileExtension = ".txt";
+ public const string FileExtension = ".hl7";
///
[JsonIgnore]
diff --git a/src/InformaticsGateway/Logging/Log.5000.DataPlugins.cs b/src/InformaticsGateway/Logging/Log.5000.DataPlugins.cs
index 0dbfd93f..60b3271f 100755
--- a/src/InformaticsGateway/Logging/Log.5000.DataPlugins.cs
+++ b/src/InformaticsGateway/Logging/Log.5000.DataPlugins.cs
@@ -44,5 +44,8 @@ public static partial class Log
[LoggerMessage(EventId = 5007, Level = LogLevel.Error, Message = "Error executing plug-in: {plugin}.")]
public static partial void ErrorAddingOutputDataPlugIn(this ILogger logger, Exception d, string plugin);
+
+ [LoggerMessage(EventId = 5008, Level = LogLevel.Trace, Message = "Import plugin executed: {pluginName}. now: {fileMetadata}")]
+ public static partial void InputDataPlugInEngineexecuted(this ILogger logger, string pluginName, string fileMetadata);
}
}
diff --git a/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs b/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs
index 15694a8f..b207d5f8 100755
--- a/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs
+++ b/src/InformaticsGateway/Logging/Log.800.Hl7Service.cs
@@ -51,14 +51,14 @@ public static partial class Log
[LoggerMessage(EventId = 809, Level = LogLevel.Debug, Message = "Acknowledgment type={value}.")]
public static partial void AcknowledgmentType(this ILogger logger, string value);
- [LoggerMessage(EventId = 810, Level = LogLevel.Information, Message = "Acknowledgment sent: length={length}.")]
- public static partial void AcknowledgmentSent(this ILogger logger, int length);
+ [LoggerMessage(EventId = 810, Level = LogLevel.Information, Message = "Acknowledgment sent message:{message} length:{length}.")]
+ public static partial void AcknowledgmentSent(this ILogger logger, string message, int length);
[LoggerMessage(EventId = 811, Level = LogLevel.Debug, Message = "HL7 bytes received: {length}.")]
public static partial void Hl7MessageBytesRead(this ILogger logger, int length);
- [LoggerMessage(EventId = 812, Level = LogLevel.Debug, Message = "Parsing message with {length} bytes.")]
- public static partial void Hl7GenerateMessage(this ILogger logger, int length);
+ [LoggerMessage(EventId = 812, Level = LogLevel.Debug, Message = "Parsing message with {length} bytes. {message}")]
+ public static partial void Hl7GenerateMessage(this ILogger logger, int length, string message);
[LoggerMessage(EventId = 813, Level = LogLevel.Debug, Message = "Waiting for HL7 message.")]
public static partial void HL7ReadingMessage(this ILogger logger);
@@ -105,5 +105,14 @@ public static partial class Log
[LoggerMessage(EventId = 827, Level = LogLevel.Warning, Message = "HL7 plugin loading exceptions")]
public static partial void HL7PluginLoadingExceptions(this ILogger logger, Exception ex);
+ [LoggerMessage(EventId = 828, Level = LogLevel.Information, Message = "HL7 message recieved. {message}")]
+ public static partial void Hl7MessageReceieved(this ILogger logger, string message);
+
+ [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/Program.cs b/src/InformaticsGateway/Program.cs
index 9a3da68e..a3352862 100755
--- a/src/InformaticsGateway/Program.cs
+++ b/src/InformaticsGateway/Program.cs
@@ -182,6 +182,7 @@ private static NLog.Logger ConfigureNLog(string assemblyVersionNumber)
ext.RegisterLayoutRenderer("servicename", logEvent => typeof(Program).Namespace);
ext.RegisterLayoutRenderer("serviceversion", logEvent => assemblyVersionNumber);
ext.RegisterLayoutRenderer("machinename", logEvent => Environment.MachineName);
+ ext.RegisterLayoutRenderer("appname", logEvent => "MIG");
})
.LoadConfigurationFromAppSettings()
.GetCurrentClassLogger();
diff --git a/src/InformaticsGateway/Services/Common/InputDataPluginEngine.cs b/src/InformaticsGateway/Services/Common/InputDataPluginEngine.cs
old mode 100644
new mode 100755
index 3b0d177d..51d7b18b
--- a/src/InformaticsGateway/Services/Common/InputDataPluginEngine.cs
+++ b/src/InformaticsGateway/Services/Common/InputDataPluginEngine.cs
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json;
using System.Threading.Tasks;
using FellowOakDicom;
using Microsoft.Extensions.Logging;
@@ -31,7 +32,7 @@ internal class InputDataPlugInEngine : IInputDataPlugInEngine
{
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger;
- private IReadOnlyList? _plugsins;
+ private IReadOnlyList? _plugins;
public InputDataPlugInEngine(IServiceProvider serviceProvider, ILogger logger)
{
@@ -41,20 +42,22 @@ public InputDataPlugInEngine(IServiceProvider serviceProvider, ILogger pluginAssemblies)
{
- _plugsins = LoadPlugIns(_serviceProvider, pluginAssemblies);
+ _plugins = LoadPlugIns(_serviceProvider, pluginAssemblies);
}
public async Task> ExecutePlugInsAsync(DicomFile dicomFile, FileStorageMetadata fileMetadata)
{
- if (_plugsins == null)
+ if (_plugins == null)
{
throw new PlugInInitializationException("InputDataPlugInEngine not configured, please call Configure() first.");
}
- foreach (var plugin in _plugsins)
+ foreach (var plugin in _plugins)
{
_logger.ExecutingInputDataPlugIn(plugin.Name);
(dicomFile, fileMetadata) = await plugin.ExecuteAsync(dicomFile, fileMetadata).ConfigureAwait(false);
+
+ _logger.InputDataPlugInEngineexecuted(plugin.Name, JsonSerializer.Serialize(fileMetadata));
}
return new Tuple(dicomFile, fileMetadata);
diff --git a/src/InformaticsGateway/Services/Common/InputHL7DataPlugInEngine.cs b/src/InformaticsGateway/Services/Common/InputHL7DataPlugInEngine.cs
index a4abac3f..6f7f1d7b 100755
--- a/src/InformaticsGateway/Services/Common/InputHL7DataPlugInEngine.cs
+++ b/src/InformaticsGateway/Services/Common/InputHL7DataPlugInEngine.cs
@@ -47,20 +47,22 @@ public void Configure(IReadOnlyList pluginAssemblies)
public async Task> ExecutePlugInsAsync(Message hl7File, FileStorageMetadata fileMetadata, Hl7ApplicationConfigEntity? configItem)
{
- if (_plugsins == null)
+ if (configItem?.PlugInAssemblies is not null && configItem.PlugInAssemblies.Any())
{
- throw new PlugInInitializationException("InputHL7DataPlugInEngine not configured, please call Configure() first.");
- }
+ if (_plugsins == null)
+ {
+ throw new PlugInInitializationException("InputHL7DataPlugInEngine not configured, please call Configure() first.");
+ }
- foreach (var plugin in _plugsins)
- {
- if (configItem is not null && configItem.PlugInAssemblies.Exists(a => a.StartsWith(plugin.ToString()!)))
+ foreach (var plugin in _plugsins)
{
- _logger.ExecutingInputDataPlugIn(plugin.Name);
- (hl7File, fileMetadata) = await plugin.ExecuteAsync(hl7File, fileMetadata).ConfigureAwait(false);
+ if (configItem is not null && configItem.PlugInAssemblies.Exists(a => a.StartsWith(plugin.ToString()!)))
+ {
+ _logger.ExecutingInputDataPlugIn(plugin.Name);
+ (hl7File, fileMetadata) = await plugin.ExecuteAsync(hl7File, fileMetadata).ConfigureAwait(false);
+ }
}
}
-
return new Tuple(hl7File, fileMetadata);
}
diff --git a/src/InformaticsGateway/Services/Connectors/PayloadAssembler.cs b/src/InformaticsGateway/Services/Connectors/PayloadAssembler.cs
index bc784031..b89f4393 100755
--- a/src/InformaticsGateway/Services/Connectors/PayloadAssembler.cs
+++ b/src/InformaticsGateway/Services/Connectors/PayloadAssembler.cs
@@ -144,7 +144,7 @@ private async void OnTimedEvent(Object? source, System.Timers.ElapsedEventArgs e
}
foreach (var key in _payloads.Keys)
{
- var payload = await _payloads[key].WithCancellation(_tokenSource.Token);
+ var payload = await _payloads[key].WithCancellation(_tokenSource.Token).ConfigureAwait(false);
using var loggerScope = _logger.BeginScope(new LoggingDataDictionary { { "CorrelationId", payload.CorrelationId } });
_logger.BucketElapsedTime(key, payload.Timeout, payload.ElapsedTime().TotalSeconds, payload.Files.Count, payload.FilesUploaded, payload.FilesFailedToUpload);
diff --git a/src/InformaticsGateway/Services/Connectors/PayloadNotificationActionHandler.cs b/src/InformaticsGateway/Services/Connectors/PayloadNotificationActionHandler.cs
index 1aa2a848..cae010ec 100755
--- a/src/InformaticsGateway/Services/Connectors/PayloadNotificationActionHandler.cs
+++ b/src/InformaticsGateway/Services/Connectors/PayloadNotificationActionHandler.cs
@@ -16,6 +16,7 @@
using System;
using System.Linq;
+using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
@@ -169,6 +170,8 @@ private async Task SendArtifactRecievedEvent(Payload payload)
};
artifiactRecievedEvent.DataOrigins.AddRange(payload.DataOrigins);
+ _logger.LogTrace($"Adding files to ArtifactsReceivedEvent files {JsonSerializer.Serialize(payload)}");
+
artifiactRecievedEvent.Artifacts = payload.Files.Select(f => new Artifact { Type = f.DataOrigin.ArtifactType, Path = f.File.UploadPath }).ToList();
var message = new JsonMessage(
diff --git a/src/InformaticsGateway/Services/Export/Hl7ExportService.cs b/src/InformaticsGateway/Services/Export/Hl7ExportService.cs
index 0e39217d..1acf2f17 100755
--- a/src/InformaticsGateway/Services/Export/Hl7ExportService.cs
+++ b/src/InformaticsGateway/Services/Export/Hl7ExportService.cs
@@ -31,6 +31,7 @@
using Monai.Deploy.InformaticsGateway.Api.Mllp;
using Monai.Deploy.Messaging.Common;
using Polly;
+using System.Linq;
namespace Monai.Deploy.InformaticsGateway.Services.Export
{
@@ -119,7 +120,7 @@ private async Task ExecuteHl7Export(
.ExecuteAsync(async () =>
{
await _mllpService.SendMllp(
- IPAddress.Parse(destination.HostIp),
+ Dns.GetHostAddresses(destination.HostIp).First(),
destination.Port, Encoding.UTF8.GetString(exportRequestData.FileContent),
cancellationToken
).ConfigureAwait(false);
diff --git a/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs b/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs
index cc8a0c36..ae2fb4a8 100755
--- a/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs
+++ b/src/InformaticsGateway/Services/HealthLevel7/MllpClient.cs
@@ -159,13 +159,31 @@ private async Task SendAcknowledgment(INetworkStream clientStream, Message messa
if (ShouldSendAcknowledgment(message))
{
- var ackMessage = message.GetACK();
+ Message ackMessage = message;
+ try
+ {
+ ackMessage = message.GetACK(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorGeneratingHl7Acknowledgment(ex, message.HL7Message);
+ _exceptions.Add(ex);
+ return;
+ }
+
+ if (ackMessage is null)
+ {
+ var ex = new Exception("Error generating HL7 acknowledgment.");
+ _logger.ErrorGeneratingHl7Acknowledgment(ex, message.HL7Message);
+ _exceptions.Add(ex);
+ return;
+ }
var ackData = new ReadOnlyMemory(ackMessage.GetMLLP());
try
{
await clientStream.WriteAsync(ackData, cancellationToken).ConfigureAwait(false);
await clientStream.FlushAsync(cancellationToken).ConfigureAwait(false);
- _logger.AcknowledgmentSent(ackData.Length);
+ _logger.AcknowledgmentSent(ackMessage.HL7Message, ackData.Length);
}
catch (Exception ex)
{
@@ -181,7 +199,7 @@ private bool ShouldSendAcknowledgment(Message message)
try
{
var value = message.DefaultSegment(Resources.MessageHeaderSegment).Fields(Resources.AcceptAcknowledgementType);
- if (value is null)
+ if (value is null || string.IsNullOrWhiteSpace(value.Value))
{
return true;
}
@@ -211,9 +229,9 @@ private bool CreateMessage(int startIndex, int endIndex, ref string data, out Me
try
{
var text = data.Substring(messageStartIndex, endIndex - messageStartIndex);
- _logger.Hl7GenerateMessage(text.Length);
+ _logger.Hl7GenerateMessage(text.Length, text);
message = new Message(text);
- message.ParseMessage();
+ message.ParseMessage(false);
data = data.Length > endIndex ? data.Substring(messageEndIndex) : string.Empty;
return true;
}
diff --git a/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs b/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs
index e579db25..2daa02b5 100755
--- a/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs
+++ b/src/InformaticsGateway/Services/HealthLevel7/MllpExtract.cs
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
+using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using FellowOakDicom;
@@ -29,19 +30,11 @@
namespace Monai.Deploy.InformaticsGateway.Api.Mllp
{
- public sealed class MllpExtract : IMllpExtract
+ public sealed class MllpExtract(IHl7ApplicationConfigRepository hl7ApplicationConfigRepository, IExternalAppDetailsRepository externalAppDetailsRepository, ILogger logger) : IMllpExtract
{
- private readonly ILogger _logger;
- private readonly IHl7ApplicationConfigRepository _hl7ApplicationConfigRepository;
- private readonly IExternalAppDetailsRepository _externalAppDetailsRepository;
-
- public MllpExtract(IHl7ApplicationConfigRepository hl7ApplicationConfigRepository, IExternalAppDetailsRepository externalAppDetailsRepository, ILogger logger)
- {
- _logger = logger ?? throw new ArgumentNullException(nameof(logger));
- _hl7ApplicationConfigRepository = hl7ApplicationConfigRepository ?? throw new ArgumentNullException(nameof(hl7ApplicationConfigRepository));
- _externalAppDetailsRepository = externalAppDetailsRepository ?? throw new ArgumentNullException(nameof(externalAppDetailsRepository));
- }
-
+ private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));
+ private readonly IHl7ApplicationConfigRepository _hl7ApplicationConfigRepository = hl7ApplicationConfigRepository ?? throw new ArgumentNullException(nameof(hl7ApplicationConfigRepository));
+ private readonly IExternalAppDetailsRepository _externalAppDetailsRepository = externalAppDetailsRepository ?? throw new ArgumentNullException(nameof(externalAppDetailsRepository));
public async Task ExtractInfo(Hl7FileStorageMetadata meta, Message message, Hl7ApplicationConfigEntity configItem)
{
@@ -87,7 +80,7 @@ public async Task ExtractInfo(Hl7FileStorageMetadata meta, Message mess
_logger.Hl7NoConfig();
return null;
}
- _logger.Hl7ConfigLoaded($"Config: {config}");
+ _logger.Hl7ConfigLoaded($"Config: {JsonSerializer.Serialize(config)}");
// get config for vendorId
var configItem = GetConfig(config, message);
if (configItem == null)
@@ -115,15 +108,20 @@ public async Task ExtractInfo(Hl7FileStorageMetadata meta, Message mess
throw new Exception($"Invalid DataLinkType: {type}");
}
- internal static Hl7ApplicationConfigEntity? GetConfig(List config, Message message)
+ internal Hl7ApplicationConfigEntity? GetConfig(List config, Message message)
{
foreach (var item in config)
{
- var t = message.GetValue(item.SendingId.Key);
- if (item.SendingId.Value == message.GetValue(item.SendingId.Key))
+ var sendingId = message.GetValue(item.SendingId.Key);
+ if (item.SendingId.Value == sendingId)
{
+ _logger.Hl7FoundMatchingConfig(sendingId, JsonSerializer.Serialize(item));
return item;
}
+ else
+ {
+ _logger.Hl7NotMatchingConfig(sendingId, item.SendingId.Value);
+ }
}
return null;
}
@@ -143,7 +141,7 @@ private Message RepopulateMessage(Hl7ApplicationConfigEntity config, ExternalApp
{
var newMess = message.HL7Message.Replace(oldvalue, details.PatientId);
message = new Message(newMess);
- message.ParseMessage();
+ message.ParseMessage(true);
}
}
else if (tag == DicomTag.StudyInstanceUID)
@@ -155,7 +153,7 @@ private Message RepopulateMessage(Hl7ApplicationConfigEntity config, ExternalApp
{
var newMess = message.HL7Message.Replace(oldvalue, details.StudyInstanceUid);
message = new Message(newMess);
- message.ParseMessage();
+ message.ParseMessage(true);
}
}
}
diff --git a/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs b/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs
index b105b58e..0abeddc7 100755
--- a/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs
+++ b/src/InformaticsGateway/Services/HealthLevel7/MllpService.cs
@@ -76,13 +76,9 @@ public int ActiveConnections
public string ServiceName => "HL7 Service";
- public MllpService(IServiceScopeFactory serviceScopeFactory,
- IOptions configuration)
+ public MllpService(IServiceScopeFactory serviceScopeFactory, IOptions configuration)
{
- if (serviceScopeFactory is null)
- {
- throw new ArgumentNullException(nameof(serviceScopeFactory));
- }
+ ArgumentNullException.ThrowIfNull(nameof(serviceScopeFactory));
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
@@ -192,8 +188,10 @@ private async Task OnDisconnect(IMllpClient client, MllpClientResult result)
{
await _inputHL7DataPlugInEngine.ExecutePlugInsAsync(message, hl7Filemetadata, configItem).ConfigureAwait(false);
newMessage = await _mIIpExtract.ExtractInfo(hl7Filemetadata, message, configItem).ConfigureAwait(false);
- }
+ _logger.LogTrace(message: $"HL7 message after plug-in processing: {newMessage.HL7Message} correlationId: {hl7Filemetadata.CorrelationId}");
+ }
+ _logger.Hl7MessageReceieved(newMessage.HL7Message);
await hl7Filemetadata.SetDataStream(newMessage.HL7Message, _configuration.Value.Storage.TemporaryDataStorage, _fileSystem, _configuration.Value.Storage.LocalTemporaryStoragePath).ConfigureAwait(false);
var payloadId = await _payloadAssembler.Queue(client.ClientId.ToString(), hl7Filemetadata, new DataOrigin { DataService = DataService.HL7, Source = client.ClientIp, Destination = FileStorageMetadata.IpAddress() }).ConfigureAwait(false);
hl7Filemetadata.PayloadId ??= payloadId.ToString();
@@ -215,7 +213,7 @@ private async Task OnDisconnect(IMllpClient client, MllpClientResult result)
private async Task ConfigurePlugInEngine()
{
var configs = await _hl7ApplicationConfigRepository.GetAllAsync().ConfigureAwait(false);
- if (configs is not null && configs.Any() && configs.Max(c => c.LastModified) > _lastConfigRead)
+ if (configs is not null && configs.Count is not 0 && configs.Max(c => c.LastModified) > _lastConfigRead)
{
var pluginAssemblies = new List();
foreach (var config in configs.Where(p => p.PlugInAssemblies?.Count > 0))
@@ -229,7 +227,7 @@ private async Task ConfigurePlugInEngine()
_logger.HL7PluginLoadingExceptions(ex);
}
}
- if (pluginAssemblies.Any())
+ if (pluginAssemblies.Count is not 0)
{
_inputHL7DataPlugInEngine.Configure(pluginAssemblies);
}
@@ -282,7 +280,7 @@ public async Task SendMllp(IPAddress address, int port, string hl7Message, Cance
catch (Exception ex)
{
_logger.Hl7SendException(ex);
- throw new Hl7SendException("Send exception");
+ throw new Hl7SendException($"Send exception: {ex.Message}");
}
}
@@ -338,7 +336,7 @@ private async Task EnsureAck(NetworkStream networkStream)
foreach (var message in _rawHl7Messages)
{
var hl7Message = new Message(message);
- hl7Message.ParseMessage();
+ hl7Message.ParseMessage(false);
if (hl7Message.MessageStructure == "ACK")
{
return;
diff --git a/src/InformaticsGateway/Test/Plug-ins/TestInputHL7DataPlugs.cs b/src/InformaticsGateway/Test/Plug-ins/TestInputHL7DataPlugs.cs
index c24e9327..c3b45c8f 100755
--- a/src/InformaticsGateway/Test/Plug-ins/TestInputHL7DataPlugs.cs
+++ b/src/InformaticsGateway/Test/Plug-ins/TestInputHL7DataPlugs.cs
@@ -30,6 +30,8 @@ public class TestInputHL7DataPlugInAddWorkflow : IInputHL7DataPlugIn
public Task<(Message hl7Message, FileStorageMetadata fileMetadata)> ExecuteAsync(Message hl7File, FileStorageMetadata fileMetadata)
{
hl7File.SetValue("MSH.3", TestString);
+ hl7File = new Message(hl7File.SerializeMessage(false));
+ hl7File.ParseMessage();
fileMetadata.Workflows.Add(TestString);
return Task.FromResult((hl7File, fileMetadata));
}
diff --git a/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs b/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs
index 29532222..917cf5cf 100755
--- a/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs
+++ b/src/InformaticsGateway/Test/Services/Common/InputHL7DataPlugInEngineTest.cs
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2023 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+using HL7.Dotnetcore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Monai.Deploy.InformaticsGateway.Api;
@@ -94,6 +95,15 @@ public async Task GivenAnInputHL7DataPlugInEngine_WhenExecutePlugInsIsCalledWith
var pluginEngine = new InputHL7DataPlugInEngine(_serviceProvider, _logger.Object);
var assemblies = new List() { typeof(TestInputHL7DataPlugInAddWorkflow).AssemblyQualifiedName };
+ var config = new Hl7ApplicationConfigEntity()
+ {
+ PlugInAssemblies = assemblies,
+ DataMapping = new List()
+ {
+ new StringKeyValuePair() { Key = "MSH.3", Value = "MSH.3" },
+ },
+ };
+
var dicomInfo = new DicomFileStorageMetadata(
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
@@ -105,20 +115,30 @@ public async Task GivenAnInputHL7DataPlugInEngine_WhenExecutePlugInsIsCalledWith
"called");
var message = new HL7.Dotnetcore.Message(SampleMessage);
- message.ParseMessage();
+ message.ParseMessage(true);
- await Assert.ThrowsAsync(async () => await pluginEngine.ExecutePlugInsAsync(message, dicomInfo, null));
+ await Assert.ThrowsAsync(async () => await pluginEngine.ExecutePlugInsAsync(message, dicomInfo, config));
}
[Fact]
public async Task GivenAnInputHL7DataPlugInEngine_WhenExecutePlugInsIsCalled_ExpectDataIsProcessedByPlugInAsync()
{
+
var pluginEngine = new InputHL7DataPlugInEngine(_serviceProvider, _logger.Object);
var assemblies = new List()
{
typeof(TestInputHL7DataPlugInAddWorkflow).AssemblyQualifiedName,
};
+ var config = new Hl7ApplicationConfigEntity()
+ {
+ PlugInAssemblies = assemblies,
+ DataMapping = new List()
+ {
+ new StringKeyValuePair() { Key = "MSH.3", Value = "MSH.3" },
+ },
+ };
+
pluginEngine.Configure(assemblies);
var dicomInfo = new DicomFileStorageMetadata(
@@ -132,12 +152,11 @@ public async Task GivenAnInputHL7DataPlugInEngine_WhenExecutePlugInsIsCalled_Exp
"called");
var message = new HL7.Dotnetcore.Message(SampleMessage);
- message.ParseMessage();
- var configItem = new Hl7ApplicationConfigEntity { PlugInAssemblies = new List { { "Monai.Deploy.InformaticsGateway.Test.PlugIns.TestInputHL7DataPlugInAddWorkflow" } } };
+ message.ParseMessage(true);
- var (Hl7Message, resultDicomInfo) = await pluginEngine.ExecutePlugInsAsync(message, dicomInfo, configItem);
+ var (Hl7Message, resultDicomInfo) = await pluginEngine.ExecutePlugInsAsync(message, dicomInfo, config);
- Assert.Equal(Hl7Message, message);
+ Assert.NotEqual(Hl7Message, message);
Assert.Equal(resultDicomInfo, dicomInfo);
Assert.Equal(Hl7Message.GetValue("MSH.3"), TestInputHL7DataPlugInAddWorkflow.TestString);
}
diff --git a/src/InformaticsGateway/Test/Services/HealthLevel7/MllPExtractTests.cs b/src/InformaticsGateway/Test/Services/HealthLevel7/MllPExtractTests.cs
index 0d9aa254..c9fba7e6 100755
--- a/src/InformaticsGateway/Test/Services/HealthLevel7/MllPExtractTests.cs
+++ b/src/InformaticsGateway/Test/Services/HealthLevel7/MllPExtractTests.cs
@@ -75,13 +75,13 @@ public void ParseConfig_Should_Return_Correct_Item()
var message = new Message(SampleMessage);
var isParsed = message.ParseMessage();
- var config = MllpExtract.GetConfig(configs, message);
+ var config = _sut.GetConfig(configs, message);
Assert.Equal(correctid, config?.Id);
message = new Message(ABCDEMessage);
isParsed = message.ParseMessage();
- config = MllpExtract.GetConfig(configs, message);
+ config = _sut.GetConfig(configs, message);
Assert.Equal(azCorrectid, config?.Id);
}
@@ -191,13 +191,13 @@ public void ParseConfig_Should_Return_Correct_Item_For_Vendor()
var message = new Message(VendorMessage);
var isParsed = message.ParseMessage();
- var config = MllpExtract.GetConfig(configs, message);
+ var config = _sut.GetConfig(configs, message);
Assert.Equal(correctid, config?.Id);
message = new Message(ABCDEMessage);
isParsed = message.ParseMessage();
- config = MllpExtract.GetConfig(configs, message);
+ config = _sut.GetConfig(configs, message);
Assert.Equal(azCorrectid, config?.Id);
}
}
diff --git a/src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs b/src/InformaticsGateway/Test/Services/HealthLevel7/MllpClientTest.cs
index de8b363c..a0201768 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;
@@ -134,10 +134,8 @@ public async Task ReceiveData_InvalidMessage()
{
await Task.Run(() =>
{
- Assert.Empty(results.Messages);
Assert.NotNull(results.AggregateException);
- Assert.Single(results.AggregateException.InnerExceptions);
- Assert.Contains("Failed to validate the message with error", results.AggregateException.InnerExceptions.First().Message);
+ Assert.Equal(1, results.AggregateException.InnerExceptions.Count);
});
});
await client.Start(action, _cancellationTokenSource.Token);
diff --git a/src/InformaticsGateway/nlog.config b/src/InformaticsGateway/nlog.config
index 4b106748..8798fce0 100755
--- a/src/InformaticsGateway/nlog.config
+++ b/src/InformaticsGateway/nlog.config
@@ -51,6 +51,7 @@ limitations under the License.
+
diff --git a/tests/Integration.Test/Common/DataProvider.cs b/tests/Integration.Test/Common/DataProvider.cs
index cb609530..2748a16a 100755
--- a/tests/Integration.Test/Common/DataProvider.cs
+++ b/tests/Integration.Test/Common/DataProvider.cs
@@ -311,7 +311,8 @@ internal async Task GenerateHl7Messages(string version)
var message = new HL7.Dotnetcore.Message(text);
message.ParseMessage();
message.SetValue("MSH.10", file);
- HL7Specs.Files[file] = message;
+ HL7Specs.Files[file] = new HL7.Dotnetcore.Message(message.SerializeMessage(false));
+ HL7Specs.Files[file].ParseMessage();
}
}
}
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