@@ -3,7 +3,8 @@ use std::fmt::Formatter;
33
44use crate :: AppState ;
55use axum:: Router ;
6- use dicom:: core:: dictionary:: { DataDictionaryEntry , DataDictionaryEntryRef } ;
6+ use dicom:: core:: dictionary:: DataDictionaryEntry ;
7+ use dicom:: core:: ops:: AttributeSelector ;
78use dicom:: core:: { DataDictionary , PrimitiveValue , Tag , VR } ;
89use dicom:: object:: StandardDataDictionary ;
910use serde:: de:: { Error , SeqAccess , Visitor } ;
@@ -39,10 +40,10 @@ pub fn routes(base_path: &str) -> Router<AppState> {
3940/// Match Query Parameters for QIDO and MWL requests.
4041#[ derive( Debug , Deserialize , PartialEq ) ]
4142#[ serde( try_from = "HashMap<String, String>" ) ]
42- pub struct MatchCriteria ( Vec < ( Tag , PrimitiveValue ) > ) ;
43+ pub struct MatchCriteria ( Vec < ( AttributeSelector , PrimitiveValue ) > ) ;
4344
4445impl MatchCriteria {
45- pub fn into_inner ( self ) -> Vec < ( Tag , PrimitiveValue ) > {
46+ pub fn into_inner ( self ) -> Vec < ( AttributeSelector , PrimitiveValue ) > {
4647 self . 0
4748 }
4849}
@@ -51,15 +52,15 @@ impl TryFrom<HashMap<String, String>> for MatchCriteria {
5152 type Error = String ;
5253
5354 fn try_from ( value : HashMap < String , String > ) -> Result < Self , Self :: Error > {
54- let criteria: Vec < ( Tag , PrimitiveValue ) > = value
55+ let criteria: Vec < ( AttributeSelector , PrimitiveValue ) > = value
5556 . into_iter ( )
5657 . map ( |( key, value) | {
5758 StandardDataDictionary
58- . by_expr ( & key)
59- . ok_or ( format ! ( "Cannot use unknown attribute {key} for matching. " ) )
60- . and_then ( |entry | {
61- to_primitive_value ( entry , & value)
62- . map ( |primitive| ( entry . tag . inner ( ) , primitive) )
59+ . parse_selector ( & key)
60+ . map_err ( |err| format ! ( "invalid attribute selector {key}: {err} " ) )
61+ . and_then ( |selector | {
62+ to_primitive_value ( selector . last_tag ( ) , & value)
63+ . map ( |primitive| ( selector , primitive) )
6364 } )
6465 } )
6566 . collect :: < Result < _ , Self :: Error > > ( ) ?;
@@ -68,14 +69,15 @@ impl TryFrom<HashMap<String, String>> for MatchCriteria {
6869}
6970
7071/// helper function to convert a query parameter value to a PrimitiveValue
71- fn to_primitive_value (
72- entry : & DataDictionaryEntryRef ,
73- raw_value : & str ,
74- ) -> Result < PrimitiveValue , String > {
72+ fn to_primitive_value ( tag : Tag , raw_value : & str ) -> Result < PrimitiveValue , String > {
7573 if raw_value. is_empty ( ) {
7674 return Ok ( PrimitiveValue :: Empty ) ;
7775 }
78- match entry. vr . relaxed ( ) {
76+ let vr = StandardDataDictionary
77+ . by_tag ( tag)
78+ . ok_or_else ( || format ! ( "unknown tag {tag}" ) ) ?
79+ . vr ( ) ;
80+ match vr. relaxed ( ) {
7981 // String-like VRs, no parsing required
8082 VR :: AE
8183 | VR :: AS
@@ -133,9 +135,8 @@ fn to_primitive_value(
133135 Ok ( PrimitiveValue :: from ( value) )
134136 }
135137 _ => Err ( format ! (
136- "Attribute {} cannot be used for matching due to unsupported VR {}" ,
137- entry. tag( ) ,
138- entry. vr. relaxed( )
138+ "Attribute {} cannot be used for matching due to unsupported VR {:?}" ,
139+ tag, vr
139140 ) ) ,
140141 }
141142}
0 commit comments