Skip to content

feat(mwl): Implement MWL-RS proposal #27

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::AppState;
use axum::Router;

mod aets;
pub mod mwl;
pub mod qido;
pub mod stow;
pub mod wado;
Expand All @@ -12,6 +13,7 @@ pub fn routes() -> Router<AppState> {
Router::new()
.merge(qido::routes())
.merge(wado::routes())
.merge(stow::routes()),
.merge(stow::routes())
.merge(mwl::routes()),
)
}
34 changes: 34 additions & 0 deletions src/api/mwl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
mod routes;
mod service;

pub use routes::routes;
pub use service::*;

use dicom::core::Tag;
use dicom::dictionary_std::tags;

/// <https://dicom.nema.org/medical/dicom/current/output/chtml/part04/sect_K.6.html#table_K.6-1>
pub const WORKITEM_SEARCH_TAGS: &[Tag] = &[
// Scheduled Procedure Step
tags::SCHEDULED_PROCEDURE_STEP_SEQUENCE,
tags::SCHEDULED_STATION_AE_TITLE,
tags::SCHEDULED_PROCEDURE_STEP_START_DATE,
tags::SCHEDULED_PROCEDURE_STEP_START_TIME,
tags::MODALITY,
tags::SCHEDULED_PERFORMING_PHYSICIAN_NAME,
tags::SCHEDULED_PROCEDURE_STEP_DESCRIPTION,
tags::SCHEDULED_STATION_NAME,
tags::SCHEDULED_PROCEDURE_STEP_LOCATION,
tags::REFERENCED_DEFINED_PROTOCOL_SEQUENCE,
tags::REFERENCED_SOP_CLASS_UID,
tags::REFERENCED_SOP_INSTANCE_UID,
// Requested Procedure

// Patient Identification
tags::PATIENT_NAME,
tags::PATIENT_ID,
tags::ISSUER_OF_PATIENT_ID,
// Patient Demographics
tags::PATIENT_BIRTH_DATE,
tags::PATIENT_SEX,
];
70 changes: 70 additions & 0 deletions src/api/mwl/routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use crate::backend::ServiceProvider;
use crate::AppState;
use axum::http::header;
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::routing::get;
use axum::Router;
use axum_extra::extract::Query;
use axum_streams::StreamBodyAs;
use dicom::object::InMemDicomObject;
use dicom_json::DicomJson;
use futures::TryStreamExt;
use tracing::instrument;

use super::{MwlQueryParameters, MwlRequestHeaderFields, MwlSearchError, MwlSearchRequest};

/// HTTP Router for the Modality Worklist.
///
/// <https://www.dicomstandard.org/news-dir/current/docs/sups/sup246.pdf>
#[rustfmt::skip]
pub fn routes() -> Router<AppState> {
Router::new()
.route("/modality-worklist", get(all_workitems))
}

// MWL-RS implementation
async fn mwl_handler(provider: ServiceProvider, request: MwlSearchRequest) -> impl IntoResponse {
if let Some(mwl) = provider.mwl {
let response = mwl.search(request).await;
let matches: Result<Vec<InMemDicomObject>, MwlSearchError> =
response.stream.try_collect().await;

match matches {
Ok(matches) => {
if matches.is_empty() {
StatusCode::NO_CONTENT.into_response()
} else {
let json: Vec<DicomJson<InMemDicomObject>> =
matches.into_iter().map(DicomJson::from).collect();

axum::response::Response::builder()
.status(StatusCode::OK)
.header(header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.body(StreamBodyAs::json_array(futures::stream::iter(json)))
.unwrap()
.into_response()
}
}
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
}
} else {
(
StatusCode::SERVICE_UNAVAILABLE,
"MWL-RS endpoint is disabled",
)
.into_response()
}
}

#[instrument(skip_all)]
async fn all_workitems(
provider: ServiceProvider,
Query(parameters): Query<MwlQueryParameters>,
) -> impl IntoResponse {
let request = MwlSearchRequest {
parameters,
headers: MwlRequestHeaderFields::default(),
};
mwl_handler(provider, request).await
}
Loading
Loading