Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
Fix RXNorm spelling suggestions loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hrickards committed Sep 21, 2015
1 parent 5e5caf5 commit 1042e1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/controllers/rxnorm.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ router.post("/spelling", function (req, res, next) {
// rxnorm lib returns JSON for queryRxNormSpelling
var result = JSON.parse(rawResult);
// if no results are found, we should return an object rather than null
if (result.suggestionGroup.suggestionList === null) {
if (typeof result.suggestionGroup.suggestionList === "undefined" || result.suggestionGroup.suggestionList === null) {
result.suggestionGroup.suggestionList = {
suggestion: []
};
}

// remove results identical to the query
// (prevents looping suggestions in the UI)
result.suggestionGroup.suggestionList.suggestion = result.suggestionGroup.suggestionList.suggestion.filter(function (suggestion) {
return suggestion.toLowerCase().trim() !== medname.toLowerCase().trim();
});

// basic object response
// just return data as it's provided to us
res.send({
Expand Down
13 changes: 13 additions & 0 deletions test/rxnorm/query_spelling_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,18 @@ describe("RXNorm", function () {
expect(response.body.result.suggestionGroup.suggestionList.suggestion.length).to.be.above(0);
});
});

it("ignores suggestions with the name equal to the queried name", function () {
return query({
medname: "multivitamins"
}).then(function (response) {
expect(response).to.be.an.rxnorm.spellingSuccess;
console.log(response.body.result.suggestionGroup.suggestionList);
expect(response.body.result.suggestionGroup.suggestionList.suggestion.length).to.be.above(0);
expect(response.body.result.suggestionGroup.suggestionList.suggestion).to.not.include("multivitamins");
expect(response.body.result.suggestionGroup.suggestionList.suggestion).to.not.include("Multivitamins");
expect(response.body.result.suggestionGroup.suggestionList.suggestion).to.not.include("MULTIVITAMINS");
});
});
});
});

0 comments on commit 1042e1c

Please sign in to comment.