Skip to content

Commit

Permalink
Merge pull request #508 from Project-MONAI/AI-382
Browse files Browse the repository at this point in the history
Ai 382
  • Loading branch information
neildsouth authored Jan 19, 2024
2 parents eb841e4 + 959816b commit 79eeb1b
Show file tree
Hide file tree
Showing 39 changed files with 757 additions and 182 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get clean \
&& apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& apt-get install -y libc-dev # this is a workaround for Mongo encryption library
&& apt-get install -y libc6-dev=2.35-0ubuntu3.6 # this is a workaround for Mongo encryption library
RUN rm -rf /var/lib/apt/lists


Expand Down
2 changes: 1 addition & 1 deletion doc/dependency_decisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
- Microsoft.NET.ILLink.Tasks
- :versions:
- 8.0.0
- 8.0.1
- 8.0.1
:when: 2022-10-14T23:37:16.793Z
:who: mocsharp
:why: MIT (https://github.com/dotnet/runtime/raw/main/LICENSE.TXT)
Expand Down
6 changes: 5 additions & 1 deletion src/Api/HL7DestinationEntity.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Monai.Deploy.InformaticsGateway.Api.Models
/// {
/// "name": "MYPACS",
/// "hostIp": "10.20.100.200",
/// "aeTitle": "MONAIPACS",
/// "port": 1104
/// }
/// </code>
Expand All @@ -36,5 +35,10 @@ public class HL7DestinationEntity : BaseApplicationEntity
/// Gets or sets the port to connect to.
/// </summary>
public int Port { get; set; }

public override string ToString()
{
return $"Name: {Name}/Host: {HostIp}/Port: {Port}";
}
}
}
11 changes: 2 additions & 9 deletions src/Api/Models/BaseApplicationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public class BaseApplicationEntity : MongoDBEntityBase
/// </summary>
public string Name { get; set; } = default!;

/// <summary>
/// Gets or sets the AE Title (AET) used to identify itself in a DICOM association.
/// </summary>
public string AeTitle { get; set; } = default!;

/// <summary>
/// Gets or set the host name or IP address of the AE Title.
Expand All @@ -62,13 +58,10 @@ public class BaseApplicationEntity : MongoDBEntityBase

public BaseApplicationEntity()
{
SetDefaultValues();
}

public void SetDefaultValues()
public virtual void SetDefaultValues()
{
if (string.IsNullOrWhiteSpace(Name))
Name = AeTitle;
}

public void SetAuthor(ClaimsPrincipal user, EditMode editMode)
Expand All @@ -90,7 +83,7 @@ public void SetAuthor(ClaimsPrincipal user, EditMode editMode)

public override string ToString()
{
return $"Name: {Name}/AET: {AeTitle}/Host: {HostIp}";
return $"Name: {Name} /Host: {HostIp}";
}
}
}
21 changes: 21 additions & 0 deletions src/Api/Models/DestinationApplicationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,30 @@ namespace Monai.Deploy.InformaticsGateway.Api.Models
/// </example>
public class DestinationApplicationEntity : BaseApplicationEntity
{
public DestinationApplicationEntity() : base()
{
SetDefaultValues();
}

/// <summary>
/// Gets or sets the port to connect to.
/// </summary>
public int Port { get; set; }

/// <summary>
/// Gets or sets the AE Title (AET) used to identify itself in a DICOM association.
/// </summary>
public string AeTitle { get; set; } = default!;

public override void SetDefaultValues()
{
if (string.IsNullOrWhiteSpace(Name))
Name = AeTitle;
}

public override string ToString()
{
return $"Name: {Name}/AET: {AeTitle}/Host: {HostIp}/Port: {Port}";
}
}
}
20 changes: 20 additions & 0 deletions src/Api/SourceApplicationEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,25 @@ namespace Monai.Deploy.InformaticsGateway.Api
/// </example>
public class SourceApplicationEntity : BaseApplicationEntity
{
public SourceApplicationEntity() : base()
{
SetDefaultValues();
}

/// <summary>
/// Gets or sets the AE Title (AET) used to identify itself in a DICOM association.
/// </summary>
public string AeTitle { get; set; } = default!;

public override void SetDefaultValues()
{
if (string.IsNullOrWhiteSpace(Name))
Name = AeTitle;
}

public override string ToString()
{
return $"Name: {Name}/AET: {AeTitle}/Host: {HostIp}";
}
}
}
5 changes: 1 addition & 4 deletions src/Api/Storage/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public TimeSpan Elapsed

public int FilesFailedToUpload { get => Files.Count(p => p.IsUploadFailed); }

public string DestinationFolder { get; set; } = string.Empty;

public Payload(string key, string correlationId, string? workflowInstanceId, string? taskId, DataOrigin dataTrigger, uint timeout)
{
Guard.Against.NullOrWhiteSpace(key, nameof(key));
Expand All @@ -108,7 +106,7 @@ public Payload(string key, string correlationId, string? workflowInstanceId, str
DataTrigger = dataTrigger;
}

public Payload(string key, string correlationId, string? workflowInstanceId, string? taskId, DataOrigin dataTrigger, uint timeout, string? payloadId = null, string? DestinationFolder = null) :
public Payload(string key, string correlationId, string? workflowInstanceId, string? taskId, DataOrigin dataTrigger, uint timeout, string? payloadId) :
this(key, correlationId, workflowInstanceId, taskId, dataTrigger, timeout)
{
Guard.Against.NullOrWhiteSpace(key, nameof(key));
Expand All @@ -121,7 +119,6 @@ public Payload(string key, string correlationId, string? workflowInstanceId, str
{
PayloadId = Guid.Parse(payloadId);
}
DestinationFolder ??= string.Empty;
}

public void Add(FileStorageMetadata value)
Expand Down
15 changes: 2 additions & 13 deletions src/Api/Test/HL7DestinationEntityTest.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,23 @@ namespace Monai.Deploy.InformaticsGateway.Api.Test
{
public class HL7DestinationEntityTest
{
[Fact]
public void GivenAMonaiApplicationEntity_WhenNameIsNotSet_ExepectSetDefaultValuesToBeUsed()
{
var entity = new HL7DestinationEntity
{
AeTitle = "AET",
};

entity.SetDefaultValues();

Assert.Equal(entity.AeTitle, entity.Name);
}

[Fact]
public void GivenAMonaiApplicationEntity_WhenNameIsSet_ExepectSetDefaultValuesToNotOverwrite()
{
var entity = new HL7DestinationEntity
{
AeTitle = "AET",
Port = 1104,
HostIp = "IP",
Name = "Name"
};

entity.SetDefaultValues();

Assert.Equal("AET", entity.AeTitle);
Assert.Equal("IP", entity.HostIp);
Assert.Equal("Name", entity.Name);
Assert.Equal(1104, entity.Port);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
* limitations under the License.
*/

using Monai.Deploy.InformaticsGateway.Api.Models;
using Xunit;

namespace Monai.Deploy.InformaticsGateway.Api.Test
{
public class BaseApplicationEntityTest
public class SourceBaseApplicationEntityTest
{
[Fact]
public void GivenABaseApplicationEntity_WhenNameIsNotSet_ExpectSetDefaultValuesToSetName()
{
var entity = new BaseApplicationEntity
var entity = new SourceApplicationEntity
{
AeTitle = "AET",
HostIp = "IP"
Expand All @@ -38,7 +37,7 @@ public void GivenABaseApplicationEntity_WhenNameIsNotSet_ExpectSetDefaultValuesT
[Fact]
public void GivenABaseApplicationEntity_WhenNameIsSet_ExpectSetDefaultValuesToNotSetName()
{
var entity = new BaseApplicationEntity
var entity = new SourceApplicationEntity
{
AeTitle = "AET",
HostIp = "IP",
Expand Down
3 changes: 1 addition & 2 deletions src/Configuration/ValidationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public static bool IsValid(this HL7DestinationEntity hl7destinationEntity, out I

var valid = true;
valid &= !string.IsNullOrWhiteSpace(hl7destinationEntity.Name);
valid &= IsAeTitleValid(hl7destinationEntity.GetType().Name, hl7destinationEntity.AeTitle, validationErrors);
valid &= IsValidHostNameIp(hl7destinationEntity.AeTitle, hl7destinationEntity.HostIp, validationErrors);
valid &= IsValidHostNameIp(hl7destinationEntity.Name, hl7destinationEntity.HostIp, validationErrors);
valid &= IsPortValid(hl7destinationEntity.GetType().Name, hl7destinationEntity.Port, validationErrors);

return valid;
Expand Down
2 changes: 1 addition & 1 deletion src/Database/DatabaseMigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static Type[] FindMatchingTypesFromAssemblies(Assembly[] assemblies)
}
}

return matchingTypes.ToArray();
return [.. matchingTypes];
}
}
}
3 changes: 1 addition & 2 deletions src/Database/EntityFramework/Configuration/HL7DestinationEntityConfiguration.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class HL7DestinationEntityConfiguration : IEntityTypeConfiguration<HL7D
public void Configure(EntityTypeBuilder<HL7DestinationEntity> builder)
{
builder.HasKey(j => j.Name);
builder.Property(j => j.AeTitle).IsRequired();
builder.Property(j => j.Port).IsRequired();
builder.Property(j => j.HostIp).IsRequired();
builder.Property(j => j.CreatedBy).IsRequired(false);
Expand All @@ -35,7 +34,7 @@ public void Configure(EntityTypeBuilder<HL7DestinationEntity> builder)
builder.Property(j => j.DateTimeUpdated).IsRequired(false);

builder.HasIndex(p => p.Name, "idx_destination_name").IsUnique();
builder.HasIndex(p => new { p.Name, p.AeTitle, p.HostIp, p.Port }, "idx_source_all").IsUnique();
builder.HasIndex(p => new { p.Name, p.HostIp, p.Port }, "idx_source_all").IsUnique();

builder.Ignore(p => p.Id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/EntityFramework/EfDatabaseMigrationManager.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IHost Migrate(IHost host)
catch (Exception ex)
{
var logger = scope.ServiceProvider.GetService<ILogger>();
logger?.Log(LogLevel.Critical, "Failed to migrate database", ex);
logger?.Log(LogLevel.Critical, message: "Failed to migrate database", exception: ex);
throw;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/Database/EntityFramework/Migrations/20221116172042_R3_0.3.4.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Monai.Deploy.InformaticsGateway.Database.Migrations
{
public partial class R3_034 : Migration
{
private static readonly string[] StorageMetadataWrapperEntitiesColumns = ["CorrelationId", "Identity"];
private static readonly string[] StorageMetadataWrapperColumns = ["CorrelationId", "Identity"];

protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
Expand Down Expand Up @@ -87,7 +90,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
migrationBuilder.CreateIndex(
name: "idx_storagemetadata_ids",
table: "StorageMetadataWrapperEntities",
columns: new[] { "CorrelationId", "Identity" });
columns: StorageMetadataWrapperEntitiesColumns);

migrationBuilder.CreateIndex(
name: "idx_storagemetadata_uploaded",
Expand Down Expand Up @@ -166,7 +169,7 @@ protected override void Down(MigrationBuilder migrationBuilder)
migrationBuilder.CreateIndex(
name: "idx_storagemetadata_ids",
table: "StorageMetadataWrapper",
columns: new[] { "CorrelationId", "Identity" });
columns: StorageMetadataWrapperColumns);

migrationBuilder.CreateIndex(
name: "idx_storagemetadata_uploaded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Monai.Deploy.InformaticsGateway.Database.Migrations
{
public partial class Hl7DEstinationAndConfig : Migration
{
private static readonly string[] HL7DestinationEntitiesColumns = ["Name", "AeTitle", "HostIp", "Port"];

protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
Expand Down Expand Up @@ -58,7 +60,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
migrationBuilder.CreateIndex(
name: "idx_source_all_HL7Destination",
table: "HL7DestinationEntities",
columns: new[] { "Name", "AeTitle", "HostIp", "Port" },
columns: HL7DestinationEntitiesColumns,
unique: true);
}

Expand Down
Loading

0 comments on commit 79eeb1b

Please sign in to comment.