Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow "OMIM:" and "MIM:" prefixes in omim_id param (#178) #179

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading