Skip to content

Commit 438faee

Browse files
authored
Record associations to the database (#263)
* Record associations to the database Signed-off-by: Victor Chang <[email protected]>
1 parent 0749690 commit 438faee

20 files changed

+997
-11
lines changed

src/Api/DicomAssociationInfo.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
19+
namespace Monai.Deploy.InformaticsGateway.Api
20+
{
21+
public class DicomAssociationInfo : MongoDBEntityBase
22+
{
23+
public DateTime DateTimeDisconnected { get; set; }
24+
public string CorrelationId { get; set; }
25+
public int FileCount { get; private set; }
26+
public string CallingAeTitle { get; set; }
27+
public string CalledAeTitle { get; set; }
28+
public string RemoteHost { get; set; }
29+
public int RemotePort { get; set; }
30+
public string Errors { get; set; }
31+
public TimeSpan Duration { get; private set; }
32+
33+
public DicomAssociationInfo()
34+
{
35+
FileCount = 0;
36+
}
37+
38+
public void FileReceived()
39+
{
40+
FileCount++;
41+
}
42+
43+
public void Disconnect()
44+
{
45+
DateTimeDisconnected = DateTime.UtcNow;
46+
Duration = DateTimeDisconnected.Subtract(DateTimeCreated);
47+
}
48+
}
49+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Monai.Deploy.InformaticsGateway.Api;
18+
19+
namespace Monai.Deploy.InformaticsGateway.Database.Api.Repositories
20+
{
21+
public interface IDicomAssociationInfoRepository
22+
{
23+
Task<List<DicomAssociationInfo>> ToListAsync(CancellationToken cancellationToken = default);
24+
25+
Task<DicomAssociationInfo> AddAsync(DicomAssociationInfo item, CancellationToken cancellationToken = default);
26+
27+
}
28+
}

src/Database/DatabaseManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static IServiceCollection ConfigureDatabase(this IServiceCollection servi
5454
services.AddScoped(typeof(ISourceApplicationEntityRepository), typeof(EntityFramework.Repositories.SourceApplicationEntityRepository));
5555
services.AddScoped(typeof(IStorageMetadataRepository), typeof(EntityFramework.Repositories.StorageMetadataWrapperRepository));
5656
services.AddScoped(typeof(IPayloadRepository), typeof(EntityFramework.Repositories.PayloadRepository));
57+
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(EntityFramework.Repositories.DicomAssociationInfoRepository));
5758
return services;
5859
case DbType_MongoDb:
5960
services.AddSingleton<IMongoClient, MongoClient>(s => new MongoClient(connectionStringConfigurationSection[SR.DatabaseConnectionStringKey]));
@@ -65,6 +66,7 @@ public static IServiceCollection ConfigureDatabase(this IServiceCollection servi
6566
services.AddScoped(typeof(ISourceApplicationEntityRepository), typeof(MongoDB.Repositories.SourceApplicationEntityRepository));
6667
services.AddScoped(typeof(IStorageMetadataRepository), typeof(MongoDB.Repositories.StorageMetadataWrapperRepository));
6768
services.AddScoped(typeof(IPayloadRepository), typeof(MongoDB.Repositories.PayloadRepository));
69+
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(MongoDB.Repositories.DicomAssociationInfoRepository));
6870

6971
return services;
7072
default:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2021-2022 MONAI Consortium
3+
* Copyright 2021 NVIDIA Corporation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
using Microsoft.EntityFrameworkCore;
19+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
20+
using Monai.Deploy.InformaticsGateway.Api;
21+
22+
namespace Monai.Deploy.InformaticsGateway.Database.EntityFramework.Configuration
23+
{
24+
internal class DicomAssociationInfoConfiguration : IEntityTypeConfiguration<DicomAssociationInfo>
25+
{
26+
public void Configure(EntityTypeBuilder<DicomAssociationInfo> builder)
27+
{
28+
builder.HasKey(j => j.Id);
29+
builder.Property(j => j.CalledAeTitle).IsRequired();
30+
builder.Property(j => j.CalledAeTitle).IsRequired();
31+
builder.Property(j => j.DateTimeCreated).IsRequired();
32+
builder.Property(j => j.DateTimeDisconnected).IsRequired();
33+
builder.Property(j => j.CorrelationId).IsRequired();
34+
builder.Property(j => j.FileCount).IsRequired();
35+
builder.Property(j => j.RemoteHost).IsRequired();
36+
builder.Property(j => j.RemotePort).IsRequired();
37+
}
38+
}
39+
}

src/Database/EntityFramework/InformaticsGatewayContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public InformaticsGatewayContext(DbContextOptions<InformaticsGatewayContext> opt
4040
public virtual DbSet<InferenceRequest> InferenceRequests { get; set; }
4141
public virtual DbSet<Payload> Payloads { get; set; }
4242
public virtual DbSet<StorageMetadataWrapper> StorageMetadataWrapperEntities { get; set; }
43+
public virtual DbSet<DicomAssociationInfo> DicomAssociationHistories { get; set; }
4344

4445
protected override void OnModelCreating(ModelBuilder modelBuilder)
4546
{
@@ -51,6 +52,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
5152
modelBuilder.ApplyConfiguration(new InferenceRequestConfiguration());
5253
modelBuilder.ApplyConfiguration(new PayloadConfiguration());
5354
modelBuilder.ApplyConfiguration(new StorageMetadataWrapperEntityConfiguration());
55+
modelBuilder.ApplyConfiguration(new DicomAssociationInfoConfiguration());
5456
}
5557

5658
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

0 commit comments

Comments
 (0)