From 5cbd43d369867e612b0663cb2bd02fa7a40742f0 Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Sun, 14 Jul 2024 10:37:22 +0200 Subject: [PATCH] fix: allow "OMIM:" and "MIM:" prefixes in omim_id param (#178) (#179) --- src/server/run/hpo_omims.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/server/run/hpo_omims.rs b/src/server/run/hpo_omims.rs index ea4fbaa..9d50b59 100644 --- a/src/server/run/hpo_omims.rs +++ b/src/server/run/hpo_omims.rs @@ -52,6 +52,25 @@ pub struct Query { pub hpo_terms: bool, } +impl Query { + /// Strip "OMIM:" prefix from `omim_id`, if any. + fn with_stripped_prefix(self) -> Self { + Self { + omim_id: self.omim_id.map(|omim_id| { + let lower_omim_id = omim_id.to_lowercase(); + if lower_omim_id.starts_with("omim:") { + omim_id[5..].to_string() + } else if lower_omim_id.starts_with("mim:") { + omim_id[4..].to_string() + } else { + omim_id + } + }), + ..self + } + } +} + /// Return default of `Request::max_results`. fn _default_max_results() -> usize { 100 @@ -164,6 +183,9 @@ async fn handle( let match_ = query.match_.unwrap_or_default(); let mut result: Vec = Vec::new(); + // Strip "OMIM:" and "MIM:" prefix from `query.omim_id` if given. + let query = query.into_inner().with_stripped_prefix(); + if match_ == Match::Exact { let omim_disease = if let Some(omim_id) = &query.omim_id { let omim_id = OmimDiseaseId::try_from(omim_id.as_ref()) @@ -238,7 +260,7 @@ async fn handle( let result = Result { version: Version::new(&data.ontology.hpo_version()), - query: query.into_inner(), + query, result, };