Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nds add accession #1006

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified src/WorkflowManager/Common/Interfaces/IPayloadService.cs
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion src/WorkflowManager/Common/Services/PayloadService.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public PayloadService(
PatientDetails = patientDetails,
PayloadDeleted = PayloadDeleted.No,
Expires = await GetExpiry(DateTime.UtcNow, eventPayload.WorkflowInstanceId),
SeriesInstanceUid = _dicomService.GetSeriesInstanceUID(dict)
SeriesInstanceUid = _dicomService.GetSeriesInstanceUID(dict),
AccessionId = _dicomService.GetAccessionID(dict) ?? string.Empty
};

if (await _payloadRepository.CreateAsync(payload))
Expand Down
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion src/WorkflowManager/Contracts/Migrations/M002_WorkflowRevision_addVerion.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

namespace Monai.Deploy.WorkflowManager.Common.Contracts.Migrations
{
public class M002_WorkflowRevision_addVerion : DocumentMigration<WorkflowRevision>

Check warning on line 22 in src/WorkflowManager/Contracts/Migrations/M002_WorkflowRevision_addVerion.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Rename class 'M002_WorkflowRevision_addVerion' to match pascal case naming rules, consider using 'M002WorkflowRevisionaddVerion'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public M002_WorkflowRevision_addVerion() : base("1.0.0") { }
public M002_WorkflowRevision_addVerion() : base("1.0.2") { }

public override void Up(BsonDocument document)
{
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/WorkflowManager/Contracts/Migrations/M003_WorkflowRevision_addDataRetension.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

namespace Monai.Deploy.WorkflowManager.Common.Contracts.Migrations
{
public class M003_WorkflowRevision_addDataRetension : DocumentMigration<WorkflowRevision>

Check warning on line 23 in src/WorkflowManager/Contracts/Migrations/M003_WorkflowRevision_addDataRetension.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Rename class 'M003_WorkflowRevision_addDataRetension' to match pascal case naming rules, consider using 'M003WorkflowRevisionaddDataRetension'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public M003_WorkflowRevision_addDataRetension() : base("1.0.1") { }
public M003_WorkflowRevision_addDataRetension() : base("1.0.3") { }

public override void Up(BsonDocument document)
{
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/WorkflowManager/Contracts/Migrations/M004_WorkflowRevision_addConditions.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

namespace Monai.Deploy.WorkflowManager.Common.Contracts.Migrations
{
public class M004_WorkflowRevision_addConditions : DocumentMigration<WorkflowRevision>

Check warning on line 23 in src/WorkflowManager/Contracts/Migrations/M004_WorkflowRevision_addConditions.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Rename class 'M004_WorkflowRevision_addConditions' to match pascal case naming rules, consider using 'M004WorkflowRevisionaddConditions'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public M004_WorkflowRevision_addConditions() : base("1.0.2") { }
public M004_WorkflowRevision_addConditions() : base("1.0.4") { }

public override void Up(BsonDocument document)
{
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@

namespace Monai.Deploy.WorkflowManager.Common.Contracts.Migrations
{
public class M001_WorkflowRevision_addVerion : DocumentMigration<WorkflowRevision>
public class M007_Payload_addAccessionId : DocumentMigration<Payload>

Check warning on line 22 in src/WorkflowManager/Contracts/Migrations/M007_Payload_addAccessionId.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Rename class 'M007_Payload_addAccessionId' to match pascal case naming rules, consider using 'M007PayloadaddAccessionId'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
public M001_WorkflowRevision_addVerion() : base("1.0.0") { }
public M007_Payload_addAccessionId() : base("1.0.7") { }

public override void Up(BsonDocument document)
{
// empty, but this will make all objects re-saved with a version
document.Add("AccessionId", new BsonString(""), true);
}

public override void Down(BsonDocument document)
{
try
{
document.Remove("Version");
document.Remove("AccessionId");
}
catch
{ // can ignore we dont want failures stopping startup !
Expand Down
7 changes: 5 additions & 2 deletions src/WorkflowManager/Contracts/Models/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@

namespace Monai.Deploy.WorkflowManager.Common.Contracts.Models
{
[CollectionLocation("Payloads"), RuntimeVersion("1.0.6")]
[CollectionLocation("Payloads"), RuntimeVersion("1.0.7")]
public class Payload : IDocument
{
[JsonConverter(typeof(DocumentVersionConvert)), BsonSerializer(typeof(DocumentVersionConverBson))]
public DocumentVersion Version { get; set; } = new DocumentVersion(1, 0, 5);
public DocumentVersion Version { get; set; } = new DocumentVersion(1, 0, 7);

[JsonProperty(PropertyName = "id")]
public string Id { get; set; } = string.Empty;

[JsonProperty(PropertyName = "payload_id")]
public string PayloadId { get; set; } = string.Empty;

[JsonProperty(PropertyName = "accession_id")]
public string AccessionId { get; set; } = string.Empty;

[JsonProperty(PropertyName = "workflows")]
public IEnumerable<string> Workflows { get; set; } = [];

Expand Down
2 changes: 1 addition & 1 deletion src/WorkflowManager/Contracts/Models/WorkflowRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Monai.Deploy.WorkflowManager.Common.Contracts.Models
{
[CollectionLocation("Workflows"), RuntimeVersion("1.0.2")]
[CollectionLocation("Workflows"), RuntimeVersion("1.0.4")]
public class WorkflowRevision : ISoftDeleteable, IDocument
{
[BsonId]
Expand Down
2 changes: 2 additions & 0 deletions src/WorkflowManager/Storage/Constants/DicomTagConstants.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ public static class DicomTagConstants
public const string PatientHospitalIdTag = "00100021";

public const string SeriesInstanceUIDTag = "0020000E";

public const string AccessionNumberTag = "00080050";
}
}
24 changes: 19 additions & 5 deletions src/WorkflowManager/Storage/Services/DicomService.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@

public async Task<PatientDetails> GetPayloadPatientDetailsAsync(string payloadId, string bucketName)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(bucketName, nameof(bucketName));
ArgumentNullException.ThrowIfNullOrWhiteSpace(payloadId, nameof(payloadId));
ArgumentNullException.ThrowIfNullOrWhiteSpace(bucketName);
ArgumentNullException.ThrowIfNullOrWhiteSpace(payloadId);

var dict = await GetMetaData(payloadId, bucketName);

Expand All @@ -91,7 +91,7 @@

private string? GetFirstValueAsync(Dictionary<string, DicomValue>? dict, string keyId)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(keyId, nameof(keyId));
ArgumentNullException.ThrowIfNullOrWhiteSpace(keyId);
if (dict is null)
{
return null;
Expand All @@ -117,20 +117,20 @@

public async Task<Dictionary<string, DicomValue>?> GetMetaData(string payloadId, string bucketId)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(bucketId, nameof(bucketId));
ArgumentNullException.ThrowIfNullOrWhiteSpace(payloadId, nameof(payloadId));
ArgumentNullException.ThrowIfNullOrWhiteSpace(bucketId);
ArgumentNullException.ThrowIfNullOrWhiteSpace(payloadId);
var items = await _storageService.ListObjectsAsync(bucketId, $"{payloadId}/dcm", true);
var dict = new Dictionary<string, DicomValue>(StringComparer.OrdinalIgnoreCase);
try
{
if (items is null || items.Any() is false)

Check warning on line 126 in src/WorkflowManager/Storage/Services/DicomService.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
{
return null;
}

foreach (var filePath in items.Select(item => item.FilePath))
{
if (filePath.EndsWith(".dcm.json") is false)

Check warning on line 133 in src/WorkflowManager/Storage/Services/DicomService.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove the unnecessary Boolean literal(s). (https://rules.sonarsource.com/csharp/RSPEC-1125)
{
continue;
}
Expand Down Expand Up @@ -160,8 +160,8 @@

public async Task<IEnumerable<string>> GetDicomPathsForTaskAsync(string outputDirectory, string bucketName)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(outputDirectory, nameof(outputDirectory));

Check warning on line 163 in src/WorkflowManager/Storage/Services/DicomService.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove this argument from the method call; it hides the caller information. (https://rules.sonarsource.com/csharp/RSPEC-3236)
ArgumentNullException.ThrowIfNullOrWhiteSpace(bucketName, nameof(bucketName));

Check warning on line 164 in src/WorkflowManager/Storage/Services/DicomService.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove this argument from the method call; it hides the caller information. (https://rules.sonarsource.com/csharp/RSPEC-3236)

var files = await _storageService.ListObjectsAsync(bucketName, outputDirectory, true);

Expand All @@ -172,8 +172,8 @@

public async Task<string> GetAnyValueAsync(string keyId, string payloadId, string bucketId)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(keyId, nameof(keyId));

Check warning on line 175 in src/WorkflowManager/Storage/Services/DicomService.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove this argument from the method call; it hides the caller information. (https://rules.sonarsource.com/csharp/RSPEC-3236)
ArgumentNullException.ThrowIfNullOrWhiteSpace(payloadId, nameof(payloadId));

Check warning on line 176 in src/WorkflowManager/Storage/Services/DicomService.cs

View workflow job for this annotation

GitHub Actions / sonarscanner

Remove this argument from the method call; it hides the caller information. (https://rules.sonarsource.com/csharp/RSPEC-3236)
ArgumentNullException.ThrowIfNullOrWhiteSpace(bucketId, nameof(bucketId));

var path = $"{payloadId}/dcm";
Expand Down Expand Up @@ -296,6 +296,20 @@
return null;
}

public string? GetAccessionID(Dictionary<string, DicomValue>? dict)
{
if (dict is null)
{
return null;
}

if (dict.TryGetValue(DicomTagConstants.AccessionNumberTag, out var value))
{
return JsonConvert.SerializeObject(value.Value);
}
return null;
}

private string TryGetValueAndLogSupported(string vrFullString, DicomValue value, string jsonString)
{
var result = TryGetValue(value);
Expand Down
9 changes: 8 additions & 1 deletion src/WorkflowManager/Storage/Services/IDicomService.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ public interface IDicomService
/// Get the seriers instance UID from the metadata.
/// </summary>
/// <param name="dict"></param>
/// <returns>a string containing the seriers instanceUid</returns>
/// <returns>a string containing the series instanceUid</returns>
string? GetSeriesInstanceUID(Dictionary<string, DicomValue>? dict);

/// <summary>
/// Gets the Accession number from the metadata.
/// </summary>
/// <param name="dict">the metadata from the file</param>
/// <returns>a string containing the accession number</returns>
string? GetAccessionID(Dictionary<string, DicomValue>? dict);
}
}
Loading