Skip to content

Commit 3ab84ec

Browse files
authored
Merge pull request #53 from UMEssen/push-srqtrsztvrkp
Fix clippy warnings and clean up unused code
2 parents a52eda4 + f737ec6 commit 3ab84ec

31 files changed

Lines changed: 137 additions & 394 deletions

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ target/
2121
# VSCode
2222
.vscode/
2323

24-
# Fleet
25-
.fleet/
24+
# Zed editor
25+
.zed/
2626

2727
# Avoid adding config files that overwrite the default config
28-
config.toml
28+
config.toml

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ nursery = "warn"
6868
cargo = "warn"
6969
module_name_repetitions = "allow"
7070
must_use_candidate = "allow"
71+
lint_groups_priority = "allow"
7172

7273
[profile.release]
7374
codegen-units = 1

src/api/aets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ async fn all_aets(state: State<AppState>) -> impl IntoResponse {
1515
let aets = &state.config.aets;
1616

1717
Json(serde_json::Value::Array(
18-
aets.into_iter()
19-
.map(|ae| serde_json::Value::String(ae.aet.to_owned()))
18+
aets.iter()
19+
.map(|ae| serde_json::Value::String(ae.aet.clone()))
2020
.collect::<Vec<serde_json::Value>>(),
2121
))
2222
}

src/api/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl TryFrom<HashMap<String, String>> for MatchCriteria {
6868
}
6969
}
7070

71-
/// helper function to convert a query parameter value to a PrimitiveValue
71+
/// helper function to convert a query parameter value to a `PrimitiveValue`
7272
fn to_primitive_value(tag: Tag, raw_value: &str) -> Result<PrimitiveValue, String> {
7373
if raw_value.is_empty() {
7474
return Ok(PrimitiveValue::Empty);
@@ -135,8 +135,7 @@ fn to_primitive_value(tag: Tag, raw_value: &str) -> Result<PrimitiveValue, Strin
135135
Ok(PrimitiveValue::from(value))
136136
}
137137
_ => Err(format!(
138-
"Attribute {} cannot be used for matching due to unsupported VR {:?}",
139-
tag, vr
138+
"Attribute {tag} cannot be used for matching due to unsupported VR {vr:?}",
140139
)),
141140
}
142141
}

src/api/mwl/routes.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use dicom_json::DicomJson;
1212
use futures::TryStreamExt;
1313
use tracing::instrument;
1414

15-
use super::{MwlQueryParameters, MwlRequestHeaderFields, MwlSearchError, MwlSearchRequest};
15+
use super::{MwlQueryParameters, MwlSearchError, MwlSearchRequest};
1616

1717
/// HTTP Router for the Modality Worklist.
1818
///
@@ -58,9 +58,6 @@ async fn all_workitems(
5858
provider: ServiceProvider,
5959
Query(parameters): Query<MwlQueryParameters>,
6060
) -> impl IntoResponse {
61-
let request = MwlSearchRequest {
62-
parameters,
63-
headers: MwlRequestHeaderFields::default(),
64-
};
61+
let request = MwlSearchRequest { parameters };
6562
mwl_handler(provider, request).await
6663
}

src/api/mwl/service.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub trait MwlService: Send + Sync {
1616

1717
pub struct MwlSearchRequest {
1818
pub parameters: MwlQueryParameters,
19-
pub headers: MwlRequestHeaderFields,
2019
}
2120

2221
/// Query parameters for a MWL-RS request.
@@ -48,25 +47,6 @@ impl Default for MwlQueryParameters {
4847
}
4948
}
5049

51-
#[derive(Debug, Default)]
52-
pub struct MwlRequestHeaderFields {
53-
pub accept: Option<String>,
54-
pub accept_charset: Option<String>,
55-
}
56-
57-
/// <https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_10.6.3.2.html#table_10.6.3-2>
58-
#[derive(Debug, Default)]
59-
pub struct ResponseHeaderFields {
60-
/// The DICOM Media Type of the response payload.
61-
/// Shall be present if the response has a payload.
62-
pub content_type: Option<String>,
63-
/// Shall be present if no transfer coding has been applied to the payload.
64-
pub content_length: Option<usize>,
65-
/// Shall be present if a transfer encoding has been applied to the payload.
66-
pub transfer_encoding: Option<String>,
67-
pub warning: Vec<String>,
68-
}
69-
7050
pub struct MwlSearchResponse<'a> {
7151
pub stream: BoxStream<'a, Result<InMemDicomObject, MwlSearchError>>,
7252
}

src/api/qido/routes.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::api::qido::{
2-
QueryParameters, RequestHeaderFields, ResourceQuery, SearchError, SearchRequest,
3-
};
1+
use crate::api::qido::{QueryParameters, ResourceQuery, SearchError, SearchRequest};
42
use crate::backend::ServiceProvider;
53
use crate::types::QueryRetrieveLevel;
64
use crate::AppState;
@@ -15,7 +13,6 @@ use axum_streams::StreamBodyAs;
1513
use dicom::object::InMemDicomObject;
1614
use dicom_json::DicomJson;
1715
use futures::TryStreamExt;
18-
use std::default::Default;
1916
use tracing::instrument;
2017

2118
/// HTTP Router for the Search Transaction.
@@ -74,7 +71,6 @@ async fn all_studies(
7471
series_instance_uid: None,
7572
},
7673
parameters,
77-
headers: RequestHeaderFields::default(),
7874
};
7975
qido_handler(provider, request).await
8076
}
@@ -92,7 +88,6 @@ async fn studys_series(
9288
series_instance_uid: None,
9389
},
9490
parameters,
95-
headers: RequestHeaderFields::default(),
9691
};
9792
qido_handler(provider, request).await
9893
}
@@ -110,7 +105,6 @@ async fn studys_series_instances(
110105
series_instance_uid: Some(series),
111106
},
112107
parameters,
113-
headers: RequestHeaderFields::default(),
114108
};
115109
qido_handler(provider, request).await
116110
}
@@ -128,7 +122,6 @@ async fn studys_instances(
128122
series_instance_uid: None,
129123
},
130124
parameters,
131-
headers: RequestHeaderFields::default(),
132125
};
133126
qido_handler(provider, request).await
134127
}
@@ -145,7 +138,6 @@ async fn all_series(
145138
series_instance_uid: None,
146139
},
147140
parameters,
148-
headers: RequestHeaderFields::default(),
149141
};
150142
qido_handler(provider, request).await
151143
}
@@ -162,7 +154,6 @@ async fn all_instances(
162154
series_instance_uid: None,
163155
},
164156
parameters,
165-
headers: RequestHeaderFields::default(),
166157
};
167158
qido_handler(provider, request).await
168159
}

src/api/qido/service.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub trait QidoService: Send + Sync {
1919
pub struct SearchRequest {
2020
pub query: ResourceQuery,
2121
pub parameters: QueryParameters,
22-
pub headers: RequestHeaderFields,
2322
}
2423

2524
/// Query parameters for a QIDO-RS request.
@@ -51,25 +50,6 @@ impl Default for QueryParameters {
5150
}
5251
}
5352

54-
#[derive(Debug, Default)]
55-
pub struct RequestHeaderFields {
56-
pub accept: Option<String>,
57-
pub accept_charset: Option<String>,
58-
}
59-
60-
/// <https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_10.6.3.2.html#table_10.6.3-2>
61-
#[derive(Debug, Default)]
62-
pub struct ResponseHeaderFields {
63-
/// The DICOM Media Type of the response payload.
64-
/// Shall be present if the response has a payload.
65-
pub content_type: Option<String>,
66-
/// Shall be present if no transfer coding has been applied to the payload.
67-
pub content_length: Option<usize>,
68-
/// Shall be present if a transfer encoding has been applied to the payload.
69-
pub transfer_encoding: Option<String>,
70-
pub warning: Vec<String>,
71-
}
72-
7353
pub struct SearchResponse<'a> {
7454
pub stream: BoxStream<'a, Result<InMemDicomObject, SearchError>>,
7555
}

src/api/stow/routes.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use multer::Error;
1616
use tracing::{error, instrument, warn};
1717

1818
/// HTTP Router for the Store Transaction
19-
/// https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_10.5
19+
/// <https://dicom.nema.org/medical/dicom/current/output/html/part18.html#sect_10.5>
2020
pub fn routes() -> Router<AppState> {
2121
Router::new()
2222
.route("/studies", post(studies))
@@ -37,38 +37,33 @@ async fn studies(
3737
instances.push(file);
3838
}
3939
Err(err) => {
40-
let err = match &err {
41-
Error::StreamReadFailed(stream_error) => {
42-
let is_limit_exceeded = stream_error
43-
.downcast_ref::<axum::Error>()
44-
.and_then(std::error::Error::source)
45-
.and_then(|err| err.downcast_ref::<LengthLimitError>())
46-
.is_some();
40+
let err = if let Error::StreamReadFailed(stream_error) = &err {
41+
let is_limit_exceeded = stream_error
42+
.downcast_ref::<axum::Error>()
43+
.and_then(std::error::Error::source)
44+
.and_then(|err| err.downcast_ref::<LengthLimitError>())
45+
.is_some();
4746

48-
if is_limit_exceeded {
49-
warn!("Upload limit exceeded.");
50-
StoreError::UploadLimitExceeded
51-
} else {
52-
error!("Failed to read multipart stream: {err:?}");
53-
StoreError::Stream(err)
54-
}
55-
}
56-
_ => {
57-
error!("Failed to read multipart stream: {:?}", err);
47+
if is_limit_exceeded {
48+
warn!("Upload limit exceeded.");
49+
StoreError::UploadLimitExceeded
50+
} else {
51+
error!("Failed to read multipart stream: {err:?}");
5852
StoreError::Stream(err)
5953
}
54+
} else {
55+
error!("Failed to read multipart stream: {:?}", err);
56+
StoreError::Stream(err)
6057
};
6158
return (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response();
6259
}
6360
};
6461
}
6562

66-
let request = StoreRequest {
67-
instances,
68-
study_instance_uid: None, // TODO
69-
};
63+
let request = StoreRequest { instances };
7064

7165
if let Some(stow) = provider.stow {
66+
#[allow(clippy::option_if_let_else)]
7267
if let Ok(response) = stow.store(request).await {
7368
let json = DicomJson::from(InMemDicomObject::from(response));
7469

src/api/stow/service.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use thiserror::Error;
1010

1111
pub struct StoreRequest {
1212
pub instances: Vec<FileDicomObject<InMemDicomObject>>,
13-
pub study_instance_uid: Option<UI>,
1413
}
1514

1615
/// <https://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_10-11>
@@ -89,10 +88,6 @@ pub trait StowService: Sync + Send {
8988

9089
#[derive(Debug, Error)]
9190
pub enum StoreError {
92-
#[error("Instance does not match the provided Study Instance UID")]
93-
StudyInstanceUidMismatch { study_instance_uid: String },
94-
#[error("The media type {media_type} is not supported")]
95-
UnsupportedMediaType { media_type: String },
9691
#[error("The file exceeds the configured upload size limit")]
9792
UploadLimitExceeded,
9893
#[error(transparent)]

0 commit comments

Comments
 (0)