Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d65a2a3

Browse files
committedMay 26, 2023
Enforce there's exactly one Alphabetic
1 parent fd09915 commit d65a2a3

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed
 

‎src/dicom_json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub enum DicomValue {
1717
Integer(Vec<i64>),
1818
Float(Vec<f64>),
1919
String(Vec<String>),
20-
Alphabetic(Vec<Alphabetic>),
20+
Alphabetic([Alphabetic; 1]),
2121
SeqField(Vec<DicomJsonData>),
2222
}
2323

‎src/dimble_to_ir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn headerfield_and_bytes_to_dicom_fields(
5252
}
5353
b"PN" => {
5454
let name = rmp_serde::decode::from_slice(field_bytes).unwrap();
55-
let a = DicomValue::Alphabetic(vec![Alphabetic { alphabetic: name }]);
55+
let a = DicomValue::Alphabetic([Alphabetic { alphabetic: name }]);
5656
DicomField {
5757
value: Some(a),
5858
vr: *vr,

‎src/ir_to_dimble.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn get_file_bytes(safetensors_path: &str) -> Vec<u8> {
3131
fs::read(safetensors_path).unwrap()
3232
}
3333

34-
fn dicom_values_to_vec(tag: &str, dicom_values: &DicomValue) -> Option<Vec<u8>> {
34+
fn dicom_values_to_vec(dicom_values: &DicomValue) -> Option<Vec<u8>> {
3535
let field_bytes = match dicom_values {
3636
DicomValue::String(v) => match &**v {
3737
[s] => to_vec(&s),
@@ -45,10 +45,7 @@ fn dicom_values_to_vec(tag: &str, dicom_values: &DicomValue) -> Option<Vec<u8>>
4545
[u] => to_vec(&u),
4646
o => to_vec(o),
4747
},
48-
DicomValue::Alphabetic(v) => match &**v {
49-
[u] => to_vec(&u.alphabetic),
50-
_ => panic!("{tag} can't have more than one Alphabetic"),
51-
},
48+
DicomValue::Alphabetic([u]) => to_vec(&u.alphabetic),
5249
DicomValue::SeqField(_) => {
5350
// TODO: handle sequences of sequences properly
5451
return None;
@@ -106,7 +103,7 @@ fn prepare_dimble_field(
106103
}
107104
dicom_values => {
108105
// call a function to handle this
109-
match dicom_values_to_vec(tag, dicom_values) {
106+
match dicom_values_to_vec(dicom_values) {
110107
Some(field_bytes) => {
111108
Ok(extend_and_make_field(data_bytes, &field_bytes, *vr))
112109
}

0 commit comments

Comments
 (0)
Please sign in to comment.