Coder Social home page Coder Social logo

codeforafrica / healthtools.api Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 20.0 1.67 MB

HealthTools API to retrieve, structure and return data being used by the health tools. Accessible at https://api.healthtools.codeforafrica.org/

Home Page: https://api.healthtools.codeforafrica.org/

License: MIT License

Python 99.20% Dockerfile 0.80%
memcached doctor health healthtools-kenya-api healthtools healthtools-api kenya africa dodgy-doctors

healthtools.api's Introduction

Build Status

HealthTools.API

Providing actionable health information.

The HealthTools API is a free to access, open, and structured service for newsrooms, civic organizations, and governments to access health information.

This API provides a simple wrapper around Elasticsearch data being made available through the HealthTools Scraper and as a cached proxy for websites unable to be reliably scraped such as Kenya's nursing council website.

Through the API you can access data that we've scraped from:

  1. Doctors: http://medicalboard.co.ke/online-services/retention/
  2. Foreign Doctors: http://medicalboard.co.ke/online-services/foreign-doctors-license-register
  3. Clinical Officers: http://clinicalofficerscouncil.org/online-services/retention/
  4. Health Facilities: http://kmhfl.health.go.ke
  5. NHIF accredited outpatient facilities for civil servants: http://www.nhif.or.ke/healthinsurance/medicalFacilities
  6. NHIF accredited inpatient facilities: http://www.nhif.or.ke/healthinsurance/inpatientServices
  7. NHIF accredited outpatient facilities: http://www.nhif.or.ke/healthinsurance/outpatientServices

Usage

Specification for the API are:

URL Endpoint HTTP Methods Functionality Parameters
/search/doctors GET Search a doctor by the name q=[name]
/search/nurses GET Search a nurse by the name q=[name]
/search/clinical-officers GET Search a clinical officer by the name q=[name]
/search/health-facilities GET Search a health facility by the name q=[name]
/search/nhif-outpatient GET Search a NHIF accredited outpatient facility by the name q=[name]
/search/nhif-outpatient-cs GET Search a NHIF accredited outpatient facility for civil servants q=[name]
/search/nhif-inpatient GET Search a NHIF accredited inpatient facility by the name q=[name]
/search GET Search a query that contains a keyword Eg. HF Kitale q=[query]
/sms GET Search a query received from sms Eg. Dr Jane q=[phoneNumber, message]
/sms/[adapter] GET Search a query received from sms using the specified adapter Eg. mtech q=[query]

Requirments


Development

To get started with developing on HealthTools.API, do the following:

git clone https://github.com/CodeForAfricaLabs/HealthTools.API.git`
cd HealthTools.API
touch .env
docker-compose build web
docker-compose up web

# Load latest data
docker-compose exec web flask htools loaddata

Reset Index

To reset the elasticsearch index, run:

docker-compose exec web flask htools resetindex

Tests

Use nosetests to run tests (with stdout) like so:

$ nosetests --nocapture
$ nosetests healthtools/tests
$ nosetests healthtools/tests/doctor.py
$ nosetests healthtools/tests/nurse.py
$ nosetests healthtools/tests/clinical_officer.py
$ nosetests healthtools/tests/health_facilities.py
$ nosetests healthtools/tests/nhif_inpatient.py
$ nosetests healthtools/tests/nhif_outpatient.py
$ nosetests healthtools/tests/nhif_outpatient_cs.py

Wit.ai

Wit.ai is a simple natural language processing API that helps developers turn speech and text into actionable data. In healthtools.API, we use it to distinguish the doc_type and the query param from the parameters being sent to the API. For example: dr mary

{
    "msg_id": "0csXmLxhRzgowQFJI",
    "_text": "dr mary",
    "entities": {
        "doctors": [
            {
                "confidence": 0.96676127393653,
                "value": "dr",
                "type": "value"
            }
        ],
        "query": [
            {
                "suggested": true,
                "confidence": 0.99538476989175,
                "value": "mary",
                "type": "value"
            }
        ]
    }
}

The doc_type has been identified as doctors and mary has been identified as query param. To configure wit.ai:

  • Sign up on wit.ai website with either your github or facebook account
  • Create an app with the name you prefer to use.
  • Detect your first entities:

Alt text

Improve the detection

This will be done by continuously training your app to identify keyword or sentences. Input a message and check its prediction, if wrong, correct it if right validate it.

Alt text

Configure Server Access Token in the ENV.

The token can be found from the settings tab, API details segment. Alt text

To set it in the ENV, run export WIT_ACCESS_TOKEN='Token'

The following endpoint is used to run wit.ai on healthtools.API

URL Endpoint HTTP Method Functionality Parameter
/search/wit GET Search Query q=[query]

Contributing

If you'd like to contribute to HealthTools.API, check out the CONTRIBUTING.md file on how to get started.


License

MIT License

Copyright (c) 2017 Code for Africa

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

healthtools.api's People

Contributors

andela-mabdussalam avatar andela-mmakinde avatar andela-ookoro avatar chegejames avatar davidlemayian avatar dependabot-preview[bot] avatar gathondu avatar kilemensi avatar ryansept avatar tinamurimi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

healthtools.api's Issues

Provide user interaction feature

If we receive a story lead instead of a query, the API should allow journalists/newsrooms to follow up with the user via a dashboard.

The platform should provide for this functionality possibly allowing API calls using a securely generated token. Not necessarily providing the interface/dashboard. The dashboard can be separate to keep the API lean.

Use RabbitMQ for query processing

When a service we are depending on such as Elasticsearch fails, we will lose the queries (particularly via SMS that are costly) and will be unable to respond to the user.

Using RabbitMQ will allow storing the message in a queue and track the job until it is finished successfully on a number of retries or manually if intervention is needed.

Cache queries

On running run_query, we should cache the queries in Memcached.

Ref: #42

Improve Documentation

The documentation should be updated to improve ability for contribution and generally tool build.

This includes in-line documentation and the README.md.

Create base Bot processor

The base bot processor determine which "adapter" a request should be routed to and appropriate response.

Development - v0.2

Through development of the HealthTools.API, we've learnt a lot and want to make it more extensible. v0.2 seeks to do a couple of things:

1. Views
1.1. Search

  • Have a single search API view to receive requests and output results in JSON
  • Send requests to a single query function used by sms, bots, etc.

1.2. SMS

  • Have a single SMS view that receives requests and outputs results in JSON.
  • Send requests to a single sms process function (detailed below)

2. Search

2.1 Query

  • This would be the primary query module that determines the doc-type (e.g nurses, doctors, cos etc.)
  • This would determine the search "vector" i.e elastic search or proxy for nurses etc.
  • Return dictionary/list of results.

2.2. Nurses Search "Vector"

  • Proxy the nurses website because we are unable to scrape it.

2.3. Elastic search "vector"

  • Search from elastic search.

3. SMS

  • The base module would process SMS requests using the query function and structure for an SMS response.
  • This would then use "adapters" for the different providers e.g M-Tech, Twilio.

4. Other considerations:

  • Tests to be rewritten
  • Analytics to work as a Flask "Middleware" or have as part of an "events" module.
  • Slack integration with Python's logging module.
  • Cache queries using Memcached (all not just nurses as before)
  • RabbitMQ integration for SMS processing.
  • Wit.ai to replace determination from keywords what doc-type is being queried.
  • Bots architecture similar to SMS. Probably re-using a lot of SMS so might be combined into just "Chat" that both inherit.

Wrap external calls with try catch statements

Currently external calls aren't "sandboxed" to avoid complete failure. We should therefore have every method doing an external call in try statements and raise exceptions appropriately.

Ref: #52

Add Twilio SMS "adapter"

Twilio is a great service that allows easy deployment in more countries. We should therefore create a Twilio adapter that returns the same SMS we are currently returning via M-Tech (sms provider).

In this case, we would re-work SMS functionality to have providers as "adapters".

Update test scripts

Description

Currently, the test runner cannot run any test case, it reports that there is no test (which is false).
After including the test files in the init file of the test module, some tests are failing due to changes in the implementation of some features, such as the returned value when a document was not found.

Screenshots

Nosetests report that no test was found
notest

Some test failing
testfails

Files

The concerned files reside in the healthtools/tests folder

To Reproduce

Run the tests, some would fail

Create M-Tech SMS Adapter

The M-Tech SMS adapter is the default SMS adapter and would be added to allow using the M-Tech service.

Log significant info using Python logging module

We would like to log significant events using Python's logging module and eventually send specific notifications to Slack. For our purposes we want to log:

  1. When the doc_type isn't understood so that:
    • Dev team can add keyword if it is appropriate.
    • Could be a question instead or a tip-off for newsroom to follow up with.
  2. When an error occurs e.g ElasticSearch is down or the nurses website is down.

Add analytics as middleware or event

We should track the searches happening as either some sort of Flask middleware approach or as an event module. This would be sent to Google Analytics. We should track:

  • Query
  • Source (IP, SMS/Web, Bot etc)
  • Results total found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.