adriaanbd / yelpi-api

A Rails API to a healthcare app wherein a caretaker can register patients they care about along with their health data inputs.
https://mighty-ocean-68056.herokuapp.com/
4 stars 1 forks source link

Discuss Autocomplete feature for Medications #40

Open adriaanbd opened 4 years ago

adriaanbd commented 4 years ago

When a user is adding a medication name, autocomplete should suggest available options from general Medicine table.

Here are some resources I found:

Let's talk about how we will implement this feature. It looks simple from high-level. Just send the params on the searchbar to a database query and get back results with top x amount of results. It has to be fast though.

rvvergara commented 4 years ago

We can talk about this more when we get to the frontend part. High level idea of it is this:

  1. We have a text box (search box)
  2. Whenever a user types a certain set of characters we make a query to the server for a certain endpoint that returns to us a collection of words
  3. We then render those collection of words

This search box component we can build from scratch or even find a react component for it. For the backend it's just a matter of creating an "autocomplete" controller which have an action that might look like the ff:

def index
 query_str = params[:query_string]
 autocomplete_results = Medication.find_by_terms(query_str)
 # find_by_terms is a method we can define in the Medication model
render :autocomplete_results, locals: { results: autocomplete_results }, status: :ok
end

Of course there are gems that can help us with "find_by_terms" method above. So yeah this should not be a big problem for us later on :)

adriaanbd commented 4 years ago

https://github.com/Casecommons/pg_search