Skip to content

Commit

Permalink
Merge pull request #167 from esmero/alliomeria-patch-1
Browse files Browse the repository at this point in the history
Update for MeSH Autocomplete
  • Loading branch information
DiegoPino authored Nov 29, 2023
2 parents e1f5b5b + dcbd1db commit 1ccf67b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Controller/AuthAutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ protected function mesh($input, $vocab, $rdftype) {
return $results;
}

$input = rawurlencode($input);
$urlindex = "/mesh/lookup/{$vocab}?label=" . $input .'&limit=10&match=' . $rdftype;
$input_encoded = rawurlencode($input);
$urlindex = "/mesh/lookup/{$vocab}?label=" . $input_encoded .'&limit=10&match=' . $rdftype;
$baseurl = 'https://id.nlm.nih.gov';
$remoteUrl = $baseurl . $urlindex;
$options['headers'] = ['Accept' => 'application/json'];
Expand All @@ -926,12 +926,20 @@ protected function mesh($input, $vocab, $rdftype) {
$jsondata = json_decode($body, TRUE);
$json_error = json_last_error();
if ($json_error == JSON_ERROR_NONE) {
if (count($jsondata) > 1) {
if (count($jsondata) > 0) {
foreach ($jsondata as $entry) {
$results[] = [
'value' => $entry['resource'],
'label' => $entry['label'],
];
if (strtolower(trim($entry['label'] ?? '')) == strtolower($input)) {
array_unshift($results, [
'value' => $entry['resource'],
'label' => $entry['label'],
]);
}
else {
$results[] = [
'value' => $entry['resource'],
'label' => $entry['label'],
];
}
}
}
else {
Expand Down

0 comments on commit 1ccf67b

Please sign in to comment.