Skip to content

Commit

Permalink
uses DestinationPath if given
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 Nov 13, 2023
1 parent 3890067 commit 0b29c02
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 18 deletions.
39 changes: 35 additions & 4 deletions src/Api/Storage/DicomFileStorageMetadata.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public DicomFileStorageMetadata(string associationId, string identifier, string
StudyInstanceUid = studyInstanceUid;
SeriesInstanceUid = seriesInstanceUid;
SopInstanceUid = sopInstanceUid;
SetupFilePaths(associationId);

DataOrigin.DataService = dataService;
DataOrigin.Source = callingAeTitle;
DataOrigin.Destination = calledAeTitle;
}

private void SetupFilePaths(string associationId)
{
File = new StorageObjectMetadata(FileExtension)
{
TemporaryPath = string.Join(PathSeparator, associationId, DataTypeDirectoryName, $"{Guid.NewGuid()}{FileExtension}"),
Expand All @@ -106,10 +115,32 @@ public DicomFileStorageMetadata(string associationId, string identifier, string
UploadPath = $"{File.UploadPath}{DicomJsonFileExtension}",
ContentType = DicomJsonContentType,
};
}

DataOrigin.DataService = dataService;
DataOrigin.Source = callingAeTitle;
DataOrigin.Destination = calledAeTitle;
public void SetupGivenFilePaths(string? DestinationFolder)
{
if (DestinationFolder is null)
{
return;
}

File = new StorageObjectMetadata(FileExtension)
{
TemporaryPath = string.Join(PathSeparator, DestinationFolder, $"Temp{PathSeparator}{Guid.NewGuid()}{FileExtension}"),
UploadPath = string.Join(PathSeparator, DestinationFolder, $"{SopInstanceUid}{FileExtension}"),
ContentType = DicomContentType,
DestinationFolderOverride = true,
};

JsonFile = new StorageObjectMetadata(DicomJsonFileExtension)
{
TemporaryPath = $"{File.TemporaryPath}{DicomJsonFileExtension}",
UploadPath = $"{File.UploadPath}{DicomJsonFileExtension}",
ContentType = DicomJsonContentType,
DestinationFolderOverride = true,
};

//DestinationFolderNeil = DestinationFolder;

Check warning on line 143 in src/Api/Storage/DicomFileStorageMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.

Check warning on line 143 in src/Api/Storage/DicomFileStorageMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.

Check warning on line 143 in src/Api/Storage/DicomFileStorageMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.
}

public override void SetFailed()
Expand All @@ -118,4 +149,4 @@ public override void SetFailed()
JsonFile.SetFailed();
}
}
}
}
5 changes: 4 additions & 1 deletion src/Api/Storage/FileStorageMetadata.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public abstract record FileStorageMetadata
[JsonPropertyName("payloadId")]
public string? PayloadId { get; set; }

// [JsonPropertyName("destinationFolder")]
//public string? DestinationFolderNeil { get; set; }

Check warning on line 108 in src/Api/Storage/FileStorageMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.

Check warning on line 108 in src/Api/Storage/FileStorageMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.

Check warning on line 108 in src/Api/Storage/FileStorageMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.

/// <summary>
/// DO NOT USE
/// This constructor is intended for JSON serializer.
Expand Down Expand Up @@ -162,4 +165,4 @@ public static string IpAddress()
return "127.0.0.1";
}
}
}
}
7 changes: 7 additions & 0 deletions src/Api/Storage/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ 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 Down Expand Up @@ -132,6 +134,11 @@ public void Add(FileStorageMetadata value)
DataOrigins.Add(value.DataOrigin);
}

//if (string.IsNullOrWhiteSpace(value.DestinationFolderNeil) is false)
//{

Check warning on line 138 in src/Api/Storage/Payload.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.

Check warning on line 138 in src/Api/Storage/Payload.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove this commented out code.
// DestinationFolder = value.DestinationFolderNeil;
//}

_lastReceived.Reset();
_lastReceived.Start();
}
Expand Down
9 changes: 8 additions & 1 deletion src/Api/Storage/StorageObjectMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class StorageObjectMetadata
[JsonPropertyName("isMoveCompleted"), JsonInclude]
public bool IsMoveCompleted { get; private set; } = default!;

[JsonPropertyName("destinationFolderOverride")]
public bool DestinationFolderOverride { get; set; } = false;

public StorageObjectMetadata(string fileExtension)
{
Guard.Against.NullOrWhiteSpace(fileExtension, nameof(fileExtension));
Expand All @@ -111,7 +114,11 @@ public string GetPayloadPath(Guid payloadId)
{
Guard.Against.Null(payloadId, nameof(payloadId));

return $"{payloadId}{FileStorageMetadata.PathSeparator}{UploadPath}";
if (DestinationFolderOverride is false)

Check warning on line 117 in src/Api/Storage/StorageObjectMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove the unnecessary Boolean literal(s).

Check warning on line 117 in src/Api/Storage/StorageObjectMetadata.cs

View workflow job for this annotation

GitHub Actions / unit-test

Remove the unnecessary Boolean literal(s).
{
return $"{payloadId}{FileStorageMetadata.PathSeparator}{UploadPath}";
}
return $"{UploadPath}";
}

public void SetUploaded(string bucketName)
Expand Down
2 changes: 1 addition & 1 deletion src/InformaticsGateway/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal static IHostBuilder CreateHostBuilder(string[] args) =>
services.AddSingleton<ITcpListenerFactory, TcpListenerFactory>();
services.AddSingleton<IMllpClientFactory, MllpClientFactory>();
services.AddSingleton<IApplicationEntityManager, ApplicationEntityManager>();
services.AddSingleton<IObjectUploadQueue, ObjectUploadQueue>();
//services.AddSingleton<IObjectUploadQueue, ObjectUploadQueue>();
services.AddSingleton<IScuQueue, ScuQueue>();
//services.AddSingleton<ScpService>();
//services.AddSingleton<ScuService>();
Expand Down
28 changes: 20 additions & 8 deletions src/InformaticsGateway/Services/Scp/ApplicationEntityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,24 @@ public async Task<string> HandleInstanceAsync(DicomCStoreRequest request, string
return string.Empty;
}

ExternalAppDetails? storedDetails = null;

if (type == ScpInputTypeEnum.ExternalAppReturn)
{
storedDetails = await _externalAppDetailsRepository.GetAsync(uids.StudyInstanceUid, new System.Threading.CancellationToken()).ConfigureAwait(false);

if (storedDetails is null)
{
_logger.FailedToFindStoredExtAppDetails(uids.StudyInstanceUid);
}
}

var dicomInfo = new DicomFileStorageMetadata(associationId.ToString(), uids.Identifier, uids.StudyInstanceUid, uids.SeriesInstanceUid, uids.SopInstanceUid, DataService.DIMSE, callingAeTitle, calledAeTitle);
if (type == ScpInputTypeEnum.ExternalAppReturn)
{
RetrieveExternalAppDetails(storedDetails, dicomInfo);
dicomInfo.SetupGivenFilePaths(storedDetails?.DestinationFolder);
}

if (_configuration.Workflows.Any())
{
Expand All @@ -129,10 +146,7 @@ public async Task<string> HandleInstanceAsync(DicomCStoreRequest request, string
}
}

if (type == ScpInputTypeEnum.ExternalAppReturn)
{
await RetrieveExternalAppDetails(uids.StudyInstanceUid, dicomInfo);
}



var result = await _pluginEngine.ExecutePlugInsAsync(request.File, dicomInfo).ConfigureAwait(false);
Expand All @@ -154,18 +168,16 @@ public async Task<string> HandleInstanceAsync(DicomCStoreRequest request, string
return dicomInfo.PayloadId;
}

private async Task RetrieveExternalAppDetails(string studyInstanceUid, DicomFileStorageMetadata dicomInfo)
private void RetrieveExternalAppDetails(ExternalAppDetails? storedDetails, DicomFileStorageMetadata dicomInfo)
{
var storedDetails = await _externalAppDetailsRepository.GetAsync(studyInstanceUid, new System.Threading.CancellationToken()).ConfigureAwait(false);
if (storedDetails is null)
{
_logger.FailedToFindStoredExtAppDetails(studyInstanceUid);
return;
}
dicomInfo.ChangeCorrelationId(_logger, storedDetails.CorrelationId);
dicomInfo.WorkflowInstanceId = storedDetails.WorkflowInstanceId;
dicomInfo.TaskId = storedDetails.ExportTaskID;
dicomInfo.PayloadId = storedDetails.DestinationFolder;
//dicomInfo.DestinationFolderNeil = storedDetails.DestinationFolder!;
}

private bool AcceptsSopClass(string sopClassUid)
Expand Down
Empty file modified tests/Integration.Test/Common/MinioDataSink.cs
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task GivenAExternalAppStudyThatIsExportedToTheTestHost()
Files = _dataProvider.DicomSpecs.Files.Keys.ToList(),
MessageId = Guid.NewGuid().ToString(),
WorkflowInstanceId = _workflowInstanceId,
DestinationFolder = Guid.NewGuid().ToString(),
DestinationFolder = "ThisIs/My/Output/Folder",
};

//_exportRequestEvent.PluginAssemblies.Add(typeof(DicomDeidentifier).AssemblyQualifiedName);
Expand Down Expand Up @@ -198,7 +198,7 @@ await _informaticsGatewayClient.MonaiScpAeTitle.Create(new MonaiApplicationEntit
}
}

var timeoutPolicy = Policy.TimeoutAsync(240, TimeoutStrategy.Pessimistic);
var timeoutPolicy = Policy.TimeoutAsync(140, TimeoutStrategy.Pessimistic);
await timeoutPolicy
.ExecuteAsync(
async () => { await SendRequest(exportCount); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public async Task AStudyThatIsExportedToTheTestHostBadPlugin()
}
}

[When(@"the study is received and sent back to Informatics Gateway with (.*)")]
[When(@"the study is received and sent back to Informatics Gateway with (.*) messages")]
public async Task WhenTheStudyIsReceivedAndSentBackToInformaticsGatewayWith(int exportCount)
{

Expand Down

0 comments on commit 0b29c02

Please sign in to comment.