Skip to content

Commit

Permalink
add HL7 eport
Browse files Browse the repository at this point in the history
Signed-off-by: Neil South <neil.south@answerdigital.com>
  • Loading branch information
neildsouth committed Dec 4, 2023
1 parent c9c16c2 commit 84c807b
Show file tree
Hide file tree
Showing 48 changed files with 1,394 additions and 958 deletions.
26 changes: 25 additions & 1 deletion src/Api/Hl7ApplicationConfigEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using FellowOakDicom;
using Monai.Deploy.InformaticsGateway.Api.Storage;
Expand All @@ -28,6 +28,13 @@ namespace Monai.Deploy.InformaticsGateway.Api
{
public class Hl7ApplicationConfigEntity : MongoDBEntityBase
{
/// <summary>
/// Gets or sets the name of a Hl7 application entity.
/// This value must be unique.
/// </summary>
[Key, Column(Order = 0)]
public string Name { get; set; } = default!;

/// <summary>
/// Gets or sets the sending identifier.
/// </summary>
Expand All @@ -48,6 +55,11 @@ public class Hl7ApplicationConfigEntity : MongoDBEntityBase
[JsonProperty("data_mapping")]
public List<StringKeyValuePair> DataMapping { get; set; } = new();

/// <summary>
/// Optional list of data input plug-in type names to be executed by the <see cref="IInputHL7DataPlugInEngine"/>.
/// </summary>
public List<string> PlugInAssemblies { get; set; } = default!;

public IEnumerable<string> Validate()
{
var errors = new List<string>();
Expand Down Expand Up @@ -116,6 +128,12 @@ public static implicit operator StringKeyValuePair(KeyValuePair<string, string>
public static List<StringKeyValuePair> FromDictionary(Dictionary<string, string> dictionary) =>
dictionary.Select(kvp => new StringKeyValuePair { Key = kvp.Key, Value = kvp.Value }).ToList();

public override bool Equals(object? obj) => Equals(obj as StringKeyValuePair);

public bool Equals(StringKeyValuePair? other) => other != null && Key == other.Key && Value == other.Value;

public override int GetHashCode() => HashCode.Combine(Key, Value);

}

public class DataKeyValuePair : IKeyValuePair<string, DataLinkType>

Check warning on line 139 in src/Api/Hl7ApplicationConfigEntity.cs

View workflow job for this annotation

GitHub Actions / unit-test

Implement 'IEquatable<DataKeyValuePair>'.

Check warning on line 139 in src/Api/Hl7ApplicationConfigEntity.cs

View workflow job for this annotation

GitHub Actions / unit-test

Seal class 'DataKeyValuePair' or implement 'IEqualityComparer<T>' instead.

Check warning on line 139 in src/Api/Hl7ApplicationConfigEntity.cs

View workflow job for this annotation

GitHub Actions / unit-test

Implement 'IEquatable<DataKeyValuePair>'.

Check warning on line 139 in src/Api/Hl7ApplicationConfigEntity.cs

View workflow job for this annotation

GitHub Actions / unit-test

Seal class 'DataKeyValuePair' or implement 'IEqualityComparer<T>' instead.
Expand All @@ -128,6 +146,12 @@ public static implicit operator DataKeyValuePair(KeyValuePair<string, DataLinkTy
{
return new DataKeyValuePair { Key = kvp.Key, Value = kvp.Value };
}

public override bool Equals(object? obj) => Equals(obj as DataKeyValuePair);

public bool Equals(DataKeyValuePair? other) => other != null && Key == other.Key && Value == other.Value;

public override int GetHashCode() => HashCode.Combine(Key, Value);
}

public interface IKeyValuePair<TKey, TValue>
Expand Down
5 changes: 5 additions & 0 deletions src/Client/IInformaticsGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public interface IInformaticsGatewayClient
/// </summary>
IAeTitleService<VirtualApplicationEntity> VirtualAeTitle { get; }

/// <summary>
/// Provides APIs to list, create, delete Virtual AE Titles.
/// </summary>
IAeTitleService<HL7DestinationEntity> HL7Destinations { get; }

/// <summary>
/// Configures the service URI of the DICOMweb service.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Client/InformaticsGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class InformaticsGatewayClient : IInformaticsGatewayClient
/// <inheritdoc/>
public IAeTitleService<VirtualApplicationEntity> VirtualAeTitle { get; }

/// <inheritdoc/>
public IAeTitleService<HL7DestinationEntity> HL7Destinations { get; }

/// <summary>
/// Initializes a new instance of the InformaticsGatewayClient class that connects to the specified URI using the credentials provided.
/// </summary>
Expand All @@ -67,6 +70,7 @@ public InformaticsGatewayClient(HttpClient httpClient, ILogger<InformaticsGatewa
DicomSources = new AeTitleService<SourceApplicationEntity>("config/source", _httpClient, _logger);
DicomDestinations = new AeTitleService<DestinationApplicationEntity>("config/destination", _httpClient, _logger);
VirtualAeTitle = new AeTitleService<VirtualApplicationEntity>("config/vae", _httpClient, _logger);
HL7Destinations = new AeTitleService<HL7DestinationEntity>("config/hl7-destination", _httpClient, _logger);
}

/// <inheritdoc/>
Expand Down
14 changes: 14 additions & 0 deletions src/Configuration/MessageBrokerConfigurationKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,19 @@ public class MessageBrokerConfigurationKeys
/// </summary>
[ConfigurationKeyName("externalAppRequest")]
public string ExternalAppRequest { get; set; } = "md.externalapp.request";

/// <summary>
/// Gets or sets the topic for publishing workflow requests.
/// Defaults to `md.export.request`.
/// </summary>
[ConfigurationKeyName("exportHl7")]
public string ExportHL7 { get; set; } = "md.export.hl7";

/// <summary>
/// Gets or sets the topic for publishing export complete requests.
/// Defaults to `md_export_complete`.
/// </summary>
[ConfigurationKeyName("exportHl7Complete")]
public string ExportHl7Complete { get; set; } = "md.export.hl7complete";
}
}
58 changes: 57 additions & 1 deletion src/Database/EntityFramework/Configuration/Hl7ApplicationConfigConfiguration.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* limitations under the License.
*/

using System.Text.Json.Serialization;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Monai.Deploy.InformaticsGateway.Api;

Expand All @@ -24,7 +27,60 @@ internal class Hl7ApplicationConfigConfiguration : IEntityTypeConfiguration<Hl7A
{
public void Configure(EntityTypeBuilder<Hl7ApplicationConfigEntity> builder)
{
builder.HasKey(j => j.Id);
var valueComparer = new ValueComparer<List<string>>(
(c1, c2) => c1!.SequenceEqual(c2!),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => c.ToList());

var jsonSerializerSettings = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};

builder.HasKey(j => j.Name);
builder.Property(j => j.SendingId).HasConversion(
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
v => JsonSerializer.Deserialize<StringKeyValuePair>(v, jsonSerializerSettings)!)
.IsRequired()
.Metadata
.SetValueComparer(
new ValueComparer<StringKeyValuePair>(
(c1, c2) => c1 == c2,
c => c.GetHashCode(),
c => c));

builder.Property(j => j.DataLink).HasConversion(
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
v => JsonSerializer.Deserialize<DataKeyValuePair>(v, jsonSerializerSettings)!)
.IsRequired()
.Metadata
.SetValueComparer(
new ValueComparer<DataKeyValuePair>(
(c1, c2) => c1 == c2,
c => c.GetHashCode(),
c => c));

builder.Property(j => j.DateTimeCreated).IsRequired();
builder.Property(j => j.PlugInAssemblies)
.HasConversion(
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
v => JsonSerializer.Deserialize<List<string>>(v, jsonSerializerSettings)!)
.Metadata.SetValueComparer(valueComparer);

builder.Property(j => j.DataMapping)
.HasConversion(
v => JsonSerializer.Serialize(v, jsonSerializerSettings),
v => JsonSerializer.Deserialize<List<StringKeyValuePair>>(v, jsonSerializerSettings)!)
.Metadata
.SetValueComparer(
new ValueComparer<List<StringKeyValuePair>>(
(c1, c2) => c1!.SequenceEqual(c2!),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => c.ToList()));

builder.HasIndex(p => p.Name, "idx_hl7_name").IsUnique();

builder.Ignore(p => p.Id);
}
}
}
1 change: 1 addition & 0 deletions src/Database/EntityFramework/InformaticsGatewayContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.ApplyConfiguration(new StorageMetadataWrapperEntityConfiguration());
modelBuilder.ApplyConfiguration(new DicomAssociationInfoConfiguration());
modelBuilder.ApplyConfiguration(new VirtualApplicationEntityConfiguration());
modelBuilder.ApplyConfiguration(new Hl7ApplicationConfigConfiguration());
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Expand Down
106 changes: 0 additions & 106 deletions src/Database/EntityFramework/Migrations/20231123141944_addHl7Config.cs

This file was deleted.

Loading

0 comments on commit 84c807b

Please sign in to comment.