Skip to content

REST API to C-ECHO a DICOM Destination #185

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

Merged
merged 9 commits into from
Sep 30, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ jobs:

- name: Update docs version
run: |
sed -i -e "s,v0.0.0,v$SEMVER,g" ./docs/docfx.json
sed -i -e "s,v0.0.0,v$SEMVER,g" ./docs/index.md
sed -i -e "s,v0.0.0,v${{ env.SEMVER }},g" ./docs/docfx.json
sed -i -e "s,v0.0.0,v${{ env.SEMVER }},g" ./docs/index.md

- name: Build Docs
working-directory: docs
Expand Down
40 changes: 34 additions & 6 deletions docs/api/rest/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Response Content Type: JSON - [MonaiApplicationEntity](xref:Monai.Deploy.Informa
| Code | Description |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | Configuration retrieved successfully. |
| 404 | Configuration Titles not found. |
| 404 | Named AE not found. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down Expand Up @@ -185,7 +185,7 @@ Response Content Type: JSON - [MonaiApplicationEntity](xref:Monai.Deploy.Informa
| Code | Description |
| ---- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | AE Title deleted. |
| 404 | AE Title not found. |
| 404 | Named MONAI AE not found. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down Expand Up @@ -265,7 +265,7 @@ Response Content Type: JSON - [SourceApplicationEntity](xref:Monai.Deploy.Inform
| Code | Description |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | AE Titles retrieved successfully. |
| 404 | AE Titles not found. |
| 404 | Named source not found. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down Expand Up @@ -347,7 +347,7 @@ Response Content Type: JSON - [SourceApplicationEntity](xref:Monai.Deploy.Inform
| Code | Description |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | AE Title deleted. |
| 404 | AE Title not found. |
| 404 | Named source not found. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request
Expand Down Expand Up @@ -451,6 +451,34 @@ curl --location --request GET 'http://localhost:5000/config/destination/USEAST'

---

## GET /config/destination/cecho/{name}

Performs a DICOM C-Echo request to the named destination on behalf of `MONAISCU`.

### Parameters

| Name | Type | Description |
| ---- | ------ | ----------------------------------------- |
| name | string | The _name_ of the AE Title to be deleted. |

### Responses


| Code | Description |
| ---- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | C-ECHO performed successfully. |
| 404 | Named destination not found. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |
| 502 | C-ECHO failure. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request

```bash
curl --location --request DELETE 'http://localhost:5000/config/destination/cecho/USEAST'
```

---

## POST /config/destination

Adds a new DICOM destination AET for exporting results to.
Expand Down Expand Up @@ -513,13 +541,13 @@ Response Content Type: JSON - [DestinationApplicationEntity](xref:Monai.Deploy.I
| Code | Description |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | AE Title deleted. |
| 404 | AE Title not found. |
| 404 | Named destination not found. |
| 500 | Server error. The response will be a [Problem details](https://datatracker.ietf.org/doc/html/rfc7807) object with server error details. |

### Example Request

```bash
curl --location --request DELETE 'http://localhost:5000/config/ae/USEAST'
curl --location --request DELETE 'http://localhost:5000/config/destination/USEAST'
```

### Example Response
Expand Down
11 changes: 9 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@


# Changelog

## 0.3.1

[GitHub Milestone 0.3.2](https://github.com/Project-MONAI/monai-deploy-informatics-gateway/milestone/8)

- New [C-ECHO API](api/rest/config.md) to perform a DICOM C-ECHO to a configured DICOM destination.

## 0.3.1

[GitHub Milestone 0.3.0](https://github.com/Project-MONAI/monai-deploy-informatics-gateway/milestone/7)
[GitHub Milestone 0.3.1](https://github.com/Project-MONAI/monai-deploy-informatics-gateway/milestone/7)

- The SCU AE Title is now uppercase MONAISCU.
- Update fo-dicom to 5.0.3
Expand All @@ -28,7 +35,7 @@

[GitHub Milestone 0.3.0](https://github.com/Project-MONAI/monai-deploy-informatics-gateway/milestone/3)

- Adds a basic [FHIR service](api/rest/config.md) to accept any versions of FHIR.
- Adds a basic [FHIR service](api/rest/fhir.md) to accept any versions of FHIR.
- Updates [Health Check API](api/rest/health.md) to replace `/health/live` and `/health/ready` APIs with `/health` API.

## 0.2.0
Expand Down
1 change: 1 addition & 0 deletions docs/setup/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Options:

Commands:
add Add a new DICOM destination
cecho C-ECHO a DICOM destination
del, rm Remove a DICOM destination
list, ls List all DICOM destinations
```
1 change: 0 additions & 1 deletion src/Api/Monai.Deploy.InformaticsGateway.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.9" />
<PackageReference Include="Monai.Deploy.Messaging" Version="0.1.5" />
<PackageReference Include="Monai.Deploy.Storage" Version="0.2.7" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions src/CLI/Commands/DestinationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ public DestinationCommand() : base("dst", "Configure DICOM destinations")
SetupAddDestinationCommand();
SetupRemoveDestinationCommand();
SetupListDestinationCommand();
SetupCEchoCommand();
}

private void SetupCEchoCommand()
{
var cechoCommand = new Command("cecho", "C-ECHO a DICOM destination");
cechoCommand.AddAlias("cecho");
AddCommand(cechoCommand);

var nameOption = new Option<string>(new string[] { "-n", "--name" }, "Name of the DICOM destination") { IsRequired = true };
cechoCommand.AddOption(nameOption);

cechoCommand.Handler = CommandHandler.Create<string, IHost, bool, CancellationToken>(CEchoDestinationHandlerAsync);
}

private void SetupListDestinationCommand()
Expand Down Expand Up @@ -149,6 +162,42 @@ private async Task<int> ListDestinationHandlerAsync(DestinationApplicationEntity
return ExitCodes.Success;
}

private async Task<int> CEchoDestinationHandlerAsync(string name, IHost host, bool verbose, CancellationToken cancellationToken)
{
Guard.Against.NullOrWhiteSpace(name, nameof(name));
Guard.Against.Null(host, nameof(host));

LogVerbose(verbose, host, "Configuring services...");
var configService = host.Services.GetRequiredService<IConfigurationService>();
var client = host.Services.GetRequiredService<IInformaticsGatewayClient>();
var logger = CreateLogger<DestinationCommand>(host);

Guard.Against.Null(logger, nameof(logger), "Logger is unavailable.");
Guard.Against.Null(configService, nameof(configService), "Configuration service is unavailable.");
Guard.Against.Null(client, nameof(client), $"{Strings.ApplicationName} client is unavailable.");

try
{
CheckConfiguration(configService);
client.ConfigureServiceUris(configService.Configurations.InformaticsGatewayServerUri);
LogVerbose(verbose, host, $"Connecting to {Strings.ApplicationName} at {configService.Configurations.InformaticsGatewayServerEndpoint}...");
LogVerbose(verbose, host, $"Deleting DICOM destination {name}...");
await client.DicomDestinations.CEcho(name, cancellationToken).ConfigureAwait(false);
logger.DicomCEchoSuccessful(name);
}
catch (ConfigurationException ex)
{
logger.ConfigurationException(ex.Message);
return ExitCodes.Config_NotConfigured;
}
catch (Exception ex)
{
logger.ErrorCEchogDicomDestination(name, ex.Message);
return ExitCodes.DestinationAe_ErrorCEcho;
}
return ExitCodes.Success;
}

private async Task<int> RemoveDestinationHandlerAsync(string name, IHost host, bool verbose, CancellationToken cancellationToken)
{
Guard.Against.NullOrWhiteSpace(name, nameof(name));
Expand Down
1 change: 1 addition & 0 deletions src/CLI/ExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static class ExitCodes
public const int DestinationAe_ErrorList = 300;
public const int DestinationAe_ErrorDelete = 301;
public const int DestinationAe_ErrorCreate = 302;
public const int DestinationAe_ErrorCEcho = 303;

public const int SourceAe_ErrorList = 400;
public const int SourceAe_ErrorDelete = 401;
Expand Down
6 changes: 6 additions & 0 deletions src/CLI/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ public static partial class Log
[LoggerMessage(EventId = 30053, Level = LogLevel.Information, Message = "\n\nFound {count} items.")]
public static partial void ListedNItems(this ILogger logger, int count);

[LoggerMessage(EventId = 30054, Level = LogLevel.Information, Message = "C-ECHO to {name} completed successfully.")]
public static partial void DicomCEchoSuccessful(this ILogger logger, string name);

[LoggerMessage(EventId = 30055, Level = LogLevel.Critical, Message = "C-ECHO to {name} failed: {error}.")]
public static partial void ErrorCEchogDicomDestination(this ILogger logger, string name, string error);

// Docker Runner
[LoggerMessage(EventId = 31000, Level = LogLevel.Debug, Message = "Checking for existing {applicationName} ({version}) containers...")]
public static partial void CheckingExistingAppContainer(this ILogger logger, string applicationName, string version);
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/Monai.Deploy.InformaticsGateway.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<SelfContained>true</SelfContained>
<PublishTrimmed>false</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<AssemblyName>mig-cli</AssemblyName>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
Loading