Skip to content

Commit

Permalink
fix: allow "OMIM:" and "MIM:" prefixes in omim_id param (#178) (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jul 14, 2024
1 parent 692555d commit 5cbd43d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/server/run/hpo_omims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -164,6 +183,9 @@ async fn handle(
let match_ = query.match_.unwrap_or_default();
let mut result: Vec<ResultEntry> = 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())
Expand Down Expand Up @@ -238,7 +260,7 @@ async fn handle(

let result = Result {
version: Version::new(&data.ontology.hpo_version()),
query: query.into_inner(),
query,
result,
};

Expand Down

0 comments on commit 5cbd43d

Please sign in to comment.