Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ aws-credential-types = { version = "1.2.13", optional = true }
testcontainers = "0.27.3"
dicom-test-files = "0.4.0"
dicom-web = "0.6.0"
reqwest = { version = "0.13.2", default-features = false, features = ["json"] }

[lints.rust]
unsafe_code = "forbid"
Expand Down
4 changes: 3 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod aets;
mod home;
pub mod mwl;
pub mod qido;
pub mod stgcmt;
pub mod stow;
pub mod wado;

Expand All @@ -27,7 +28,8 @@ pub fn routes(base_path: &str) -> Router<AppState> {
.merge(qido::routes())
.merge(wado::routes())
.merge(stow::routes())
.merge(mwl::routes()),
.merge(mwl::routes())
.merge(stgcmt::routes()),
);

// axum no longer supports nesting at the root
Expand Down
5 changes: 5 additions & 0 deletions src/api/stgcmt/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod routes;
mod service;

pub use routes::routes;
pub use service::*;
84 changes: 84 additions & 0 deletions src/api/stgcmt/routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::api::stgcmt::{CommitRequest, CommitmentState};
use crate::backend::ServiceProvider;
use crate::utils::dicom_json::DicomJsonBody;
use crate::AppState;
use axum::body::Body;
use axum::extract::Path;
use axum::http::header::CONTENT_TYPE;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::routing::post;
use axum::Router;
use dicom::object::InMemDicomObject;
use dicom_json::DicomJson;
use tracing::instrument;

/// HTTP Router for the Storage Commitment Service.
/// <https://dicom.nema.org/medical/dicom/current/output/chtml/part18/chapter_13.html>
pub fn routes() -> Router<AppState> {
Router::new().route(
"/commitment-requests/{transaction_uid}",
post(commit).get(check_result),
)
}

/// Commit Transaction.
/// <https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_13.4.html>
#[instrument(skip_all)]
async fn commit(
provider: ServiceProvider,
Path((_aet, transaction_uid)): Path<(String, String)>,
DicomJsonBody(object): DicomJsonBody,
) -> Response {
let Some(stgcmt) = provider.stgcmt else {
return (
StatusCode::SERVICE_UNAVAILABLE,
"Storage Commitment endpoint is disabled",
)
.into_response();
};

let request = match CommitRequest::from_object(transaction_uid, &object) {
Ok(request) => request,
Err(err) => return err.into_response(),
};

match stgcmt.commit(request).await {
Ok(()) => StatusCode::ACCEPTED.into_response(),
Err(err) => err.into_response(),
}
}

/// Check Commit Result Transaction.
/// <https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_13.5.html>
#[instrument(skip_all)]
async fn check_result(
provider: ServiceProvider,
Path((_aet, transaction_uid)): Path<(String, String)>,
) -> Response {
let Some(stgcmt) = provider.stgcmt else {
return (
StatusCode::SERVICE_UNAVAILABLE,
"Storage Commitment endpoint is disabled",
)
.into_response();
};

match stgcmt.check_result(&transaction_uid).await {
None => (
StatusCode::NOT_FOUND,
format!("Unknown Transaction UID {transaction_uid}"),
)
.into_response(),
Some(CommitmentState::Pending) => StatusCode::ACCEPTED.into_response(),
Some(CommitmentState::Completed(result)) => {
let json = DicomJson::from(InMemDicomObject::from(result));

Response::builder()
.status(StatusCode::OK)
.header(CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.body(Body::from(serde_json::to_string(&json).unwrap()))
.unwrap()
}
}
}
Loading
Loading