diff --git a/openapi.yaml b/openapi.yaml index a7aa3e8..f3964eb 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -81,12 +81,19 @@ paths: nullable: true - name: match_ in: query - description: The match mode. + description: The match mode, default is `Match::Exact`. required: false schema: allOf: - $ref: '#/components/schemas/Match' nullable: true + - name: ignore_case + in: query + description: Whether case is insentivie, default is `false`. + required: false + schema: + type: boolean + nullable: true - name: max_results in: query description: Maximal number of results to return. diff --git a/src/server/run/hpo_omims.rs b/src/server/run/hpo_omims.rs index 6efc642..ea4fbaa 100644 --- a/src/server/run/hpo_omims.rs +++ b/src/server/run/hpo_omims.rs @@ -39,9 +39,11 @@ pub struct Query { pub omim_id: Option, /// The disease name to search for. pub name: Option, - /// The match mode. + /// The match mode, default is `Match::Exact`. #[serde(alias = "match")] pub match_: Option, + /// Whether case is insentivie, default is `false`. + pub ignore_case: Option, /// Maximal number of results to return. #[serde(default = "_default_max_results")] pub max_results: usize, @@ -144,6 +146,7 @@ pub struct Result { /// Query for OMIM diseases in the HPO database. #[allow(clippy::unused_async)] +#[allow(clippy::too_many_lines)] #[utoipa::path( operation_id = "hpo_omims", params(Query), @@ -167,11 +170,22 @@ async fn handle( .map_err(|e| CustomError::new(anyhow::anyhow!(e)))?; ontology.omim_disease(&omim_id) } else if let Some(name) = &query.name { + let name = if query.ignore_case.unwrap_or_default() { + name.to_lowercase() + } else { + name.clone() + }; let mut omim_disease = None; let mut it = ontology.omim_diseases(); let mut tmp = it.next(); while tmp.is_some() && omim_disease.is_none() { - if tmp.expect("checked above").name() == name { + let tmp_name = tmp.expect("checked above").name(); + let tmp_name = if query.ignore_case.unwrap_or_default() { + tmp_name.to_lowercase() + } else { + tmp_name.to_string() + }; + if tmp_name == name { omim_disease = tmp; } tmp = it.next(); @@ -191,11 +205,21 @@ async fn handle( let mut it = ontology.omim_diseases(); let mut omim_disease = it.next(); while omim_disease.is_some() && result.len() < query.max_results { + let name = if query.ignore_case.unwrap_or_default() { + name.to_lowercase() + } else { + name.clone() + }; let omim_name = omim_disease.as_ref().expect("checked above").name(); + let omim_name = if query.ignore_case.unwrap_or_default() { + omim_name.to_lowercase() + } else { + omim_name.to_string() + }; let is_match = match query.match_.unwrap_or_default() { - Match::Prefix => omim_name.starts_with(name), - Match::Suffix => omim_name.ends_with(name), - Match::Contains => omim_name.contains(name), + Match::Prefix => omim_name.starts_with(&name), + Match::Suffix => omim_name.ends_with(&name), + Match::Contains => omim_name.contains(&name), Match::Exact => panic!("cannot happen here"), }; if is_match { diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_no_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_no_hpo_terms.snap index bf6fad2..cfe4f6c 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_no_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_no_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: tel-Manzke syndro match_: contains + ignore_case: ~ max_results: 100 hpo_terms: false result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_with_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_with_hpo_terms.snap index a99d788..48ecb3d 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_with_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_contains_with_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: tel-Manzke syndro match_: contains + ignore_case: ~ max_results: 100 hpo_terms: true result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_no_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_no_hpo_terms.snap index 33a14ad..21e40b4 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_no_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_no_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: Catel-Manzke syndrome match_: ~ + ignore_case: ~ max_results: 100 hpo_terms: false result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_with_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_with_hpo_terms.snap index f78af79..c06ceb6 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_with_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_exact_with_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: Catel-Manzke syndrome match_: ~ + ignore_case: ~ max_results: 100 hpo_terms: true result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_no_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_no_hpo_terms.snap index 42dae91..7abe192 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_no_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_no_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: Catel-Manzke syndro match_: prefix + ignore_case: ~ max_results: 100 hpo_terms: false result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_with_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_with_hpo_terms.snap index 9022e08..d06e83a 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_with_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_prefix_with_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: Catel-Manzke syndro match_: prefix + ignore_case: ~ max_results: 100 hpo_terms: true result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_no_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_no_hpo_terms.snap index 223d861..2d4f4df 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_no_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_no_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: tel-Manzke syndrome match_: suffix + ignore_case: ~ max_results: 100 hpo_terms: false result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_with_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_with_hpo_terms.snap index d2564bb..41196eb 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_with_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_name_suffix_with_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: ~ name: tel-Manzke syndrome match_: suffix + ignore_case: ~ max_results: 100 hpo_terms: true result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_no_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_no_hpo_terms.snap index e4852d9..484b0b3 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_no_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_no_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: "616145" name: ~ match_: ~ + ignore_case: ~ max_results: 100 hpo_terms: false result: diff --git a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_with_hpo_terms.snap b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_with_hpo_terms.snap index e57a71f..83a2d7f 100644 --- a/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_with_hpo_terms.snap +++ b/src/server/run/snapshots/viguno__server__run__hpo_omims__test__hpo_omims_omim_id_exact_with_hpo_terms.snap @@ -9,6 +9,7 @@ query: omim_id: "616145" name: ~ match_: ~ + ignore_case: ~ max_results: 100 hpo_terms: true result: