Skip to content

Commit 5a26ec6

Browse files
committed
Support new Workflow Request event data structure.
Signed-off-by: Victor Chang <[email protected]>
1 parent 2eacbce commit 5a26ec6

File tree

96 files changed

+929
-1108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+929
-1108
lines changed

.editorconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 MONAI Consortium
1+
# Copyright 2022-2023 MONAI Consortium
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818
root = true
1919

2020
# Copyright File Header
21-
file_header_template = SPDX-FileCopyrightText: © [year file created] - [last year file modified], MONAI Consortium\nSPDX-License-Identifier: Apache License 2.0
21+
file_header_template = SPDX-FileCopyrightText: © [year file created] - [last year file modified], MONAI Consortium\nSPDX-License-Identifier: Apache License 2.0
2222
dotnet_diagnostic.IDE0073.severity = error
2323

2424
# Default settings:
@@ -309,3 +309,7 @@ max_line_length = 88
309309
[*.json]
310310
indent_size = 2
311311
insert_final_newline = ignore
312+
313+
314+
# Spelling
315+
spelling_error_severity = information

src/Api/Monai.Deploy.InformaticsGateway.Api.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
~ Copyright 2021-2022 MONAI Consortium
2+
~ Copyright 2021-2023 MONAI Consortium
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
55
~ you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
3131
<PackageReference Include="fo-dicom" Version="5.1.1" />
3232
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
3333
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.21" />
34-
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.25" />
34+
<PackageReference Include="Monai.Deploy.Messaging" Version="1.0.0" />
3535
<PackageReference Include="Monai.Deploy.Storage" Version="0.2.18" />
3636
</ItemGroup>
3737

src/Api/Storage/DicomFileStorageMetadata.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Text.Json.Serialization;
1919
using Ardalis.GuardClauses;
20+
using Monai.Deploy.Messaging.Events;
2021

2122
namespace Monai.Deploy.InformaticsGateway.Api.Storage
2223
{
@@ -31,21 +32,6 @@ public sealed record DicomFileStorageMetadata : FileStorageMetadata
3132
public static readonly string DicomContentType = "application/dicom";
3233
public static readonly string DicomJsonContentType = System.Net.Mime.MediaTypeNames.Application.Json;
3334

34-
/// <summary>
35-
/// The calling AE title of the DICOM instance.
36-
/// For ACR, this is the Transaction ID of the original request.
37-
/// Note: this value is same as <see cref="FileStorageMetadata.Source"/>
38-
/// </summary>
39-
[JsonIgnore]
40-
public string CallingAeTitle { get => Source; }
41-
42-
/// <summary>
43-
/// The MONAI AE Title that received the DICOM instance.
44-
/// For ACR request, this field is empty.
45-
/// </summary>
46-
[JsonPropertyName("calledAeTitle")]
47-
public string CalledAeTitle { get; set; } = default!;
48-
4935
/// <summary>
5036
/// Gets or set the Study Instance UID of the DICOM instance.
5137
/// </summary>
@@ -95,7 +81,7 @@ public sealed record DicomFileStorageMetadata : FileStorageMetadata
9581
[JsonConstructor]
9682
public DicomFileStorageMetadata() { }
9783

98-
public DicomFileStorageMetadata(string associationId, string identifier, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid)
84+
public DicomFileStorageMetadata(string associationId, string identifier, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid, DataService dataService, string callingAeTitle, string calledAeTitle)
9985
: base(associationId.ToString(), identifier)
10086
{
10187
Guard.Against.NullOrWhiteSpace(associationId, nameof(associationId));
@@ -120,6 +106,10 @@ public DicomFileStorageMetadata(string associationId, string identifier, string
120106
UploadPath = $"{File.UploadPath}{DicomJsonFileExtension}",
121107
ContentType = DicomJsonContentType,
122108
};
109+
110+
DataOrigin.DataService = dataService;
111+
DataOrigin.Source = callingAeTitle;
112+
DataOrigin.Destination = calledAeTitle;
123113
}
124114

125115
public override void SetFailed()
@@ -128,4 +118,4 @@ public override void SetFailed()
128118
JsonFile.SetFailed();
129119
}
130120
}
131-
}
121+
}

src/Api/Storage/FhirFileStorageMetadata.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Text.Json.Serialization;
1919
using Ardalis.GuardClauses;
2020
using Monai.Deploy.InformaticsGateway.Api.Rest;
21+
using Monai.Deploy.Messaging.Events;
2122

2223
namespace Monai.Deploy.InformaticsGateway.Api.Storage
2324
{
@@ -30,13 +31,6 @@ public sealed record FhirFileStorageMetadata : FileStorageMetadata
3031
public const string JsonFilExtension = ".json";
3132
public const string XmlFileExtension = ".xml";
3233

33-
/// <summary>
34-
/// The transaction ID of the original ACR request.
35-
/// Note: this value is same as <see cref="FileStorageMetadata.Source"/>
36-
/// </summary>
37-
[JsonIgnore]
38-
public string TransactionId { get => Source; }
39-
4034
/// <summary>
4135
/// Gets or set the FHIR resource type.
4236
/// </summary>
@@ -66,17 +60,20 @@ public sealed record FhirFileStorageMetadata : FileStorageMetadata
6660
[JsonConstructor]
6761
public FhirFileStorageMetadata() { }
6862

69-
public FhirFileStorageMetadata(string transactionId, string resourceType, string resourceId, FhirStorageFormat fhirFileFormat)
63+
public FhirFileStorageMetadata(string transactionId, string resourceType, string resourceId, FhirStorageFormat fhirFileFormat, DataService dataType, string dataOrigin)
7064
: base(transactionId, $"{resourceType}{PathSeparator}{resourceId}")
7165
{
7266
Guard.Against.NullOrWhiteSpace(transactionId, nameof(transactionId));
7367
Guard.Against.NullOrWhiteSpace(resourceType, nameof(resourceType));
7468
Guard.Against.NullOrWhiteSpace(resourceId, nameof(resourceId));
7569

76-
Source = transactionId;
7770
ResourceType = resourceType;
7871
ResourceId = resourceId;
7972

73+
DataOrigin.DataService = dataType;
74+
DataOrigin.Source = dataOrigin;
75+
DataOrigin.Destination = IpAddress();
76+
8077
var fileExtension = fhirFileFormat == FhirStorageFormat.Json ? JsonFilExtension : XmlFileExtension;
8178
File = new StorageObjectMetadata(fileExtension)
8279
{
@@ -86,4 +83,4 @@ public FhirFileStorageMetadata(string transactionId, string resourceType, string
8683
};
8784
}
8885
}
89-
}
86+
}

src/Api/Storage/FileStorageMetadata.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
using System;
1818
using System.Collections.Generic;
19+
using System.Net;
1920
using System.Text.Json.Serialization;
2021
using Ardalis.GuardClauses;
2122
using Microsoft.Extensions.Logging;
23+
using Monai.Deploy.Messaging.Events;
2224

2325
namespace Monai.Deploy.InformaticsGateway.Api.Storage
2426
{
@@ -64,10 +66,10 @@ public abstract record FileStorageMetadata
6466
public string CorrelationId { get; set; } = default!;
6567

6668
/// <summary>
67-
/// Gets or sets the source of the file.
69+
/// Gets or sets the data origin of this file.
6870
/// </summary>
69-
[JsonPropertyName("source")]
70-
public string Source { get; set; } = default!;
71+
[JsonPropertyName("dataOrigin"), JsonInclude]
72+
public DataOrigin DataOrigin { get; private set; }
7173

7274
/// <summary>
7375
/// Gets a list of workflows designated for the file.
@@ -96,6 +98,12 @@ public abstract record FileStorageMetadata
9698
[JsonPropertyName("taskId")]
9799
public string? TaskId { get; set; }
98100

101+
/// <summary>
102+
/// Gets or sets the PayloadId associated with this file.
103+
/// </summary>
104+
[JsonPropertyName("payloadId")]
105+
public string? PayloadId { get; set; }
106+
99107
/// <summary>
100108
/// DO NOT USE
101109
/// This constructor is intended for JSON serializer.
@@ -114,6 +122,7 @@ protected FileStorageMetadata(string correlationId, string identifier)
114122
Id = identifier;
115123
DateReceived = DateTime.UtcNow;
116124
Workflows = new List<string>();
125+
DataOrigin = new DataOrigin();
117126
}
118127

119128
/// <summary>
@@ -138,6 +147,19 @@ public void ChangeCorrelationId(ILogger logger, string correlationId)
138147
CorrelationId = correlationId;
139148
}
140149

141-
public string? PayloadId { get; set; }
150+
public static string IpAddress()
151+
{
152+
var entry = Dns.GetHostEntry(Dns.GetHostName());
153+
154+
foreach (var ip in entry.AddressList)
155+
{
156+
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
157+
{
158+
return ip.ToString();
159+
}
160+
}
161+
162+
return "127.0.0.1";
163+
}
142164
}
143-
}
165+
}

src/Api/Storage/Hl7FileStorageMetadata.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2022 MONAI Consortium
2+
* Copyright 2021-2023 MONAI Consortium
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Text.Json.Serialization;
1919
using Ardalis.GuardClauses;
20+
using Monai.Deploy.Messaging.Events;
2021

2122
namespace Monai.Deploy.InformaticsGateway.Api.Storage
2223
{
@@ -45,12 +46,14 @@ public sealed record Hl7FileStorageMetadata : FileStorageMetadata
4546
[JsonConstructor]
4647
public Hl7FileStorageMetadata() { }
4748

48-
public Hl7FileStorageMetadata(string connectionId)
49+
public Hl7FileStorageMetadata(string connectionId, DataService dataType, string dataOrigin)
4950
: base(connectionId, Guid.NewGuid().ToString())
5051
{
5152
Guard.Against.NullOrWhiteSpace(connectionId, nameof(connectionId));
5253

53-
Source = connectionId;
54+
DataOrigin.DataService = dataType;
55+
DataOrigin.Source = dataOrigin;
56+
DataOrigin.Destination = IpAddress();
5457

5558
File = new StorageObjectMetadata(FileExtension)
5659
{
@@ -60,4 +63,4 @@ public Hl7FileStorageMetadata(string connectionId)
6063
};
6164
}
6265
}
63-
}
66+
}

src/Api/Storage/Payload.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Diagnostics;
2020
using System.Linq;
2121
using Ardalis.GuardClauses;
22+
using Monai.Deploy.Messaging.Events;
2223

2324
namespace Monai.Deploy.InformaticsGateway.Api.Storage
2425
{
@@ -68,31 +69,29 @@ public enum PayloadState
6869

6970
public string? TaskId { get; init; }
7071

72+
public DataOrigin DataTrigger { get; init; }
73+
74+
public HashSet<DataOrigin> DataOrigins { get; init; }
75+
7176
public int Count { get => Files.Count; }
7277

7378
public bool HasTimedOut { get => ElapsedTime().TotalSeconds >= Timeout; }
7479

7580
public TimeSpan Elapsed
76-
{ get { return DateTime.UtcNow.Subtract(DateTimeCreated); } }
77-
78-
public string? CallingAeTitle { get => Files.OfType<DicomFileStorageMetadata>().Select(p => p.CallingAeTitle).FirstOrDefault(); }
79-
80-
public string? CalledAeTitle { get => Files.OfType<DicomFileStorageMetadata>().Select(p => p.CalledAeTitle).FirstOrDefault(); }
81+
{
82+
get { return DateTime.UtcNow.Subtract(DateTimeCreated); }
83+
}
8184

8285
public int FilesUploaded { get => Files.Count(p => p.IsUploaded); }
8386

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

86-
public Payload(string key, string correlationId, uint timeout)
87-
: this(key, correlationId, null, null, timeout)
88-
{
89-
}
90-
91-
public Payload(string key, string correlationId, string? workflowInstanceId, string? taskId, uint timeout)
89+
public Payload(string key, string correlationId, string? workflowInstanceId, string? taskId, DataOrigin dataTrigger, uint timeout)
9290
{
9391
Guard.Against.NullOrWhiteSpace(key, nameof(key));
9492

9593
Files = new List<FileStorageMetadata>();
94+
DataOrigins = new HashSet<DataOrigin>();
9695
_lastReceived = new Stopwatch();
9796

9897
CorrelationId = correlationId;
@@ -105,13 +104,20 @@ public Payload(string key, string correlationId, string? workflowInstanceId, str
105104
State = PayloadState.Created;
106105
RetryCount = 0;
107106
Timeout = timeout;
107+
DataTrigger = dataTrigger;
108108
}
109109

110110
public void Add(FileStorageMetadata value)
111111
{
112112
Guard.Against.Null(value, nameof(value));
113113

114114
Files.Add(value);
115+
116+
if (!DataTrigger.Equals(value.DataOrigin))
117+
{
118+
DataOrigins.Add(value.DataOrigin);
119+
}
120+
115121
_lastReceived.Reset();
116122
_lastReceived.Start();
117123
}
@@ -152,4 +158,4 @@ public void Dispose()
152158
GC.SuppressFinalize(this);
153159
}
154160
}
155-
}
161+
}

src/Api/Test/Monai.Deploy.InformaticsGateway.Api.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
~ Copyright 2021-2022 MONAI Consortium
2+
~ Copyright 2021-2023 MONAI Consortium
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
55
~ you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
3333
<PrivateAssets>all</PrivateAssets>
3434
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3535
</PackageReference>
36-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
36+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
3737
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.2.3" />
3838
<PackageReference Include="xRetry" Version="1.9.0" />
3939
<PackageReference Include="xunit" Version="2.5.0" />

0 commit comments

Comments
 (0)