Skip to content

Commit

Permalink
fix restrict lookup to also restrict concepts that are searched for b…
Browse files Browse the repository at this point in the history
…y ID.
  • Loading branch information
tomolopolis committed May 5, 2020
1 parent f42bad7 commit c28b575
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions webapp/frontend/src/components/common/ConceptPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,32 @@ export default {
const searchByTerm = function () {
let searchConceptsQueryParams = `search=${term}&cdb__in=${conceptDbs}`
that.$http.get(`/api/search-concepts/?${searchConceptsQueryParams}`).then(resp => {
that.searchResults = resp.data.results.map(res => mapResult(res, resp.data.results))
if (that.project.restrict_concept_lookup) {
if (that.project.tuis) {
let tuis = that.project.tuis.split(',').map(t => t.trim())
that.searchResults = that.searchResults.filter(r => tuis.indexOf(r.tui) !== -1)
}
if (that.project.cuis) {
let cuis = that.project.cuis.split(',').map(c => c.trim())
that.searchResults = that.searchResults.filter(r => cuis.indexOf(r.cui) !== -1)
}
}
that.searchResults = filterResults(that.project,
resp.data.results.map(res => mapResult(res, resp.data.results)))
loading(false)
})
}
const filterResults = function (project, results) {
if (project.restrict_concept_lookup) {
if (project.tuis) {
let tuis = project.tuis.split(',').map(t => t.trim())
results = results.filter(r => tuis.indexOf(r.tui) !== -1)
}
if (project.cuis) {
let cuis = project.cuis.split(',').map(c => c.trim())
results = results.filter(r => cuis.indexOf(r.cui) !== -1)
}
}
return results
}
if (term.match(/^(?:c)\d{7}|s-\d*/gmi)) {
this.$http.get(`/api/concepts/?cui=${term}`).then(resp => {
if (resp.data.results.length > 0) {
loading(false)
this.searchResults = resp.data.results.map(res => mapResult(res, resp.data.results))
this.searchResults = filterResults(that.project,
resp.data.results.map(res => mapResult(res, resp.data.results)))
}
})
} else if (term.match(/^\w\d\d.*/i)) {
Expand Down

0 comments on commit c28b575

Please sign in to comment.