-
Notifications
You must be signed in to change notification settings - Fork 20
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
Added Wit.ai document type determiner #63
Conversation
healthtools/search/wit_ai.py
Outdated
This checks the doc type against the doc list an determines whether it should be elastic search or nurses search. | ||
If the doc type is empty,search type is None | ||
""" | ||
doc = ['nhif-outpatient', 'nhif-inpatient', 'nhif-outpatient-cs', 'doctors', 'health-facilities', 'clinical-officers'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a nitpick but lines 30-33 aren't pep8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick is so important in these uncertain times.. 💯
healthtools/views/search_api.py
Outdated
'result': {'hits': [], 'total': 0}, | ||
'doc_type': doc_type, | ||
'status': 'FAILED', | ||
'msg': '' # TODO: Pass run_query message here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have this TODO here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's me. We should pass an actual message if this fails. Currently we don't have any message being returned so we only know it's failed but not why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, @Awinja-Andela why are these changes reflecting here? I thought I had already written this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DavidLemayian i am reusing this code for wit.ai. I am using it just so that we can have two options for searching for the document name.
using wit.ai
or using document.py
It is either i do this, or i remove document.py
completely.
healthtools/views/search_api.py
Outdated
'msg': '' # TODO: Pass run_query message here. | ||
}) | ||
|
||
# TODO: Log event here (send to Google Analytics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is me again. Notes in code to get back to. Showing where we should do stuff.
healthtools/views/search_api.py
Outdated
|
||
|
||
blueprint = Blueprint('search_api', __name__) | ||
|
||
|
||
@blueprint.route('/search', methods=['GET'], strict_slashes=False) | ||
def search_index(doc_type=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Awinja-Andela Why are we creating a separate function for what's already below as "index"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DavidLemayian notice that i have introduced :
from healthtools.search.wit_ai import wit_run_query
while still retaining:
from healthtools.search import run_query
@blueprint.route('/wit_search', methods=['GET'], strict_slashes=False)
that uses:
result, doc_type = wit_run_query(query, doc_type)
and
@blueprint.route('/search', methods=['GET'], strict_slashes=False) @blueprint.route('/search/<doc_type>', methods=['GET'], strict_slashes=False)
that still uses:
result, doc_type = run_query(query, doc_type)
healthtools/settings.py
Outdated
|
||
#wit.ai access token | ||
|
||
access_token = os.getenv("access_token") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formating and naming on these changes do not follow the rest of the project..
healthtools/search/wit_ai.py
Outdated
resp = client.message(message_text) | ||
query = ''.join(nested_lookup('value', resp['entities']['query'])) | ||
doc_type = ''.join([var for var in (resp['entities'].keys()) if var != 'query']) | ||
#wit returns the entity with an underscore,this changes it to hyphen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you see it.
healthtools/search/wit_ai.py
Outdated
search_type = 'nurses' | ||
else: | ||
search_type = 'elastic' | ||
return search_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already defined in the DOCUMENTS
. Why an entire function for it? https://github.com/CodeForAfricaLabs/HealthTools.API/blob/develop/healthtools/documents.py
healthtools/settings.py
Outdated
|
||
################################################################################ | ||
|
||
#Wit.ai Access Token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you see it.
@Awinja-Andela I can kind of see what's happening here now. So as to avoid replication, let's approach this as a doc-type. When you search using |
@DavidLemayian yes. i see. let me try it out. |
@DavidLemayian check it out!!! |
This is shaping up nicely @Awinja-Andela. Now what I'd like is for |
@DavidLemayian Makes Sense. I have changed it to return |
@DavidLemayian you will see a lot has changed now. |
We are currently using keywords to determine which document type the application should query from, which limits to the application to some words. Wit.ai will identify key words in queries and determine which document type it should query.
This PR therefore introduces:
This task involved:
doctors
,nurses
,clinical-officers
,health-facilities
,nhif-inpatient
,nhif-outpatient
,nhif-outpatient-cs
andquery
wit.ai is suitable for the
/search
endpoint and furtherSMS
functionIt will enable users do searches like:
http://127.0.0.1:5000/search?q=is Doctor Jane Wairimu registered?
or send texts like:
where are civil servants outpatient services offered in kerugoya?
Relevant pivotal tracker stories
#51