Skip to content
Open
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
16 changes: 9 additions & 7 deletions DICOMStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ static class DICOMStore
{
/// <summary>
/// The method will read all files in a directory/sub-directories and send a DICOMweb Store request (STOW-RS)
/// Each 5 DICOM files will be grouped as a multi-part content and sent in a single request.
/// DICOM files will be grouped as defined in <paramref name="batch"/> as a multi-part content and sent in a single request.
/// </summary>
/// <param name="directory"></param>
/// <param name="storeUrl"></param>
public static void StoreDicomInDirectory(string directory, string storeUrl)
/// <param name="pattern"></param>
/// <param name="batch"></param>
public static void StoreDicomInDirectory(string directory, string storeUrl, string pattern, int batch)
{
var mimeType = "application/dicom";
MultipartContent multiContent = GetMultipartContent(mimeType);
int count = 0;

//Enumerate all files in a directory/sub-directories
foreach (var path in Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories))
//Enumerate files in a directory/sub-directories
foreach (var path in Directory.EnumerateFiles(directory, pattern, SearchOption.AllDirectories))
{
count++;

Expand All @@ -32,7 +34,7 @@ public static void StoreDicomInDirectory(string directory, string storeUrl)

multiContent.Add(sContent);

if (count % 5 == 0)
if (count % batch == 0)
{
count = 0;

Expand All @@ -42,7 +44,7 @@ public static void StoreDicomInDirectory(string directory, string storeUrl)
}
}

//Flush any remaining images (should be less than 5)
//Flush any remaining images (should be less than BATCH)
if (multiContent.Count() > 0)
{
StoreToServer(multiContent, storeUrl);
Expand Down Expand Up @@ -83,7 +85,7 @@ private static void StoreToServer(MultipartContent multiContent, string storeUrl

HttpResponseMessage response = result.Result;

Console.WriteLine(response.StatusCode);
Console.WriteLine($"[{(uint)response.StatusCode}]{response.StatusCode}: {response.ReasonPhrase}");

var result2 = response.Content.ReadAsStringAsync();

Expand Down
17 changes: 15 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ namespace DICOMcloudUploader
{
class Program
{
static void Main(string dir = null, string url = null)
static void Main(int batch = 5, string dir = null, string url = null, string pattern = null)
{
string uploadFolder = "";
url ??= "http://localhost:44301/stowrs/";
pattern ??= "*.*";

if (string.IsNullOrWhiteSpace(dir))
{
Expand All @@ -32,6 +33,8 @@ static void Main(string dir = null, string url = null)

sb.AppendLine($"1. DICOM Directory: {uploadFolder}");
sb.AppendLine($"2. DICOMweb Store Endpoint: {url}");
sb.AppendLine($"3. DICOM Directory File Pattern: {pattern}");
sb.AppendLine($"4. DICOMweb Store Send Batch: {batch}");
sb.AppendLine($"Press \"Enter\" to accept, \"1\" to change DICOM directory, \"2\" to change store endpoint or any key to exit");
Console.WriteLine(sb);

Expand All @@ -47,6 +50,16 @@ static void Main(string dir = null, string url = null)
Console.WriteLine("Enter URL for DICOMweb Store endpoint:");
url = Console.ReadLine();
}
else if (input == "3")
{
Console.WriteLine("Enter File Pattern DICOM directory to upload:");
pattern = Console.ReadLine();
}
else if (input == "4")
{
Console.WriteLine("Enter integer for DICOMweb Store send batch:");
int.TryParse( Console.ReadLine(), out batch);
}
else if (input != "")
{
return;
Expand All @@ -62,7 +75,7 @@ static void Main(string dir = null, string url = null)

DateTime startTime = DateTime.Now;
Console.WriteLine($"Upload start time: {startTime}");
DICOMStore.StoreDicomInDirectory(uploadFolder, url);
DICOMStore.StoreDicomInDirectory(uploadFolder, url, pattern, batch);
DateTime endTime = DateTime.Now;
Console.WriteLine($"Upload end time: {endTime}");

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ If arguments not provided in the command line, you will get the chance to specif
|arg| Description |
|--|--|
| --dir | Optional - Path to DICOM directory |
| -url | URL to a DICOMweb Store (aka STOW-RS) endpoint
| --url | URL to a DICOMweb Store (aka STOW-RS) endpoint |
| --pattern | File Pattern for DICOM directory to upload. Default is "\*.\*" |
| --batch | Optional - Integer for DICOMweb Store send batch. Default is 5 |

## Examples:
`DICOMcloudUploader.exe --dir "d:\dicomimages" --url "http://dicomcloud.azurewebsites.net/api/studies"`
```DICOMcloudUploader.exe --dir "d:\dicomimages" --url "http://dicomcloud.azurewebsites.net/api/studies"```

```DICOMcloudUploader.exe --dir "d:\dicomimages" --url "http://dicomcloud.azurewebsites.net/api/studies" --pattern "*.dcm" --batch 12```