Skip to content

Commit 6ed325f

Browse files
Merge pull request #3 from RyanSept/ft-add-doctors-to-api
Add doctors and clinical officers to API
2 parents 67f54dc + d6884ab commit 6ed325f

File tree

15 files changed

+289
-9
lines changed

15 files changed

+289
-9
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM python:2.7.13
22
COPY . /healthtools-ke-api
33
WORKDIR /healthtools-ke-api
44
RUN pip install -r requirements.txt
5-
CMD ["gunicorn", "manage:app"]
5+
CMD ["gunicorn", "manage:app"]

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# HealthTools.KE-api
2-
HealthTools Kenya API to retrieve, structure and return data being used by the health tools.
2+
HealthTools Kenya API to retrieve, structure and return data being used by the health tools. It provides
3+
data on the following medical officer registries:
4+
5+
- Doctors: http://medicalboard.co.ke/online-services/retention/
6+
- Foreign doctors: http://medicalboard.co.ke/online-services/foreign-doctors-license-register
7+
- Clinical officers: http://clinicalofficerscouncil.org/online-services/retention/
8+
9+
### Specifications
10+
Specification for the API is shown below. It is an open api and requires no authentication to access.
11+
12+
13+
| EndPoint | Allowed Methods | Functionality | Parameters |
14+
|-------------------------------------|------------------|----------------------------------------------------------|------------|
15+
| `/doctors/search.json` | GET | Search a doctor by the name | q=<name> |
16+
| `/nurses/search.json` | GET | Search a nurse by the name | q=<name> |
17+
| `/clinical-officers/search.json` | GET | Search a clinical officer by the name | q=<name> |
18+
19+
20+
### Installation
21+
Clone the repo from github `$ git clone [email protected]:RyanSept/HealthTools.KE-api.git`
22+
23+
Change directory into package `$ cd HealthTools.KE-api`
24+
25+
Install the dependencies by running `$ pip install requirements.txt`
26+
27+
You can set the required environment variables like so
28+
```<>
29+
$ export GA_TRACKING_ID=<google-analytics-tracking-id>
30+
$ export SMS_USER=<sms-provider-user-id>
31+
$ export SMS_PASS=<sms-provider-passcode>
32+
$ export SMS_SHORTCODE=<sms-provider-shortcode>
33+
$ export SMS_SEND_URL=<url-for-sms-provider>
34+
$ export CONFIG=<config-mode> # eg. "healthtools_ke_api.settings.DevConfig"
35+
$ export AWS_ACCESS_KEY_ID=<aws-access-key-id>
36+
$ export AWS_SECRET_KEY=<aws-secret-key>
37+
$ export AWS_REGION="<aws-region>
38+
```
39+
40+
You can now run the server `$ python manage.py` or `gunicorn manage:app` for production.
41+
42+
43+
## Running the tests
44+
45+
Use nosetests to run tests (with stdout) like this:
46+
```$ nosetests --nocapture```

healthtools_ke_api/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from flask import Flask, jsonify
22
from werkzeug.exceptions import HTTPException, default_exceptions
33

4-
from healthtools_ke_api.nurses import nurses_api
5-
from healthtools_ke_api.sms_handler import sms_handler
4+
from healthtools_ke_api.views.doctors import doctors_api
5+
from healthtools_ke_api.views.nurses import nurses_api
6+
from healthtools_ke_api.views.clinical_officers import clinical_officers_api
7+
8+
from healthtools_ke_api.views.sms_handler import sms_handler
69

710
import os
811
import sys
@@ -15,7 +18,9 @@
1518
print "No config has been specified for use in the environment variables."
1619
sys.exit()
1720

21+
app.register_blueprint(doctors_api, url_prefix='/doctors')
1822
app.register_blueprint(nurses_api, url_prefix='/nurses')
23+
app.register_blueprint(clinical_officers_api, url_prefix='/clinical-officers')
1924
app.register_blueprint(sms_handler)
2025

2126

healthtools_ke_api/config.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

healthtools_ke_api/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# Url of memcached server
44
MEMCACHED_URL = os.getenv("MEMCACHED_URL")
55

6+
# Amazon Web Services configs
7+
AWS_CONFIGS = {
8+
"aws_access_key_id": os.getenv("AWS_ACCESS_KEY_ID"),
9+
"aws_secret_access_key": os.getenv("AWS_SECRET_KEY"),
10+
"region_name": os.getenv("AWS_REGION"),
11+
}
12+
613

714
class Config(object):
815
# Google Analytics tracking id
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from unittest import TestCase
2+
from healthtools_ke_api import app
3+
from healthtools_ke_api.views.clinical_officers import get_clinical_officers_from_cloudsearch
4+
5+
6+
class TestClinicalOfficersAPI(TestCase):
7+
def setUp(self):
8+
self.client = app.test_client()
9+
10+
def test_gets_cos_from_cloudsearch(self):
11+
clinical_officers = get_clinical_officers_from_cloudsearch("Marie")
12+
self.assertTrue(len(clinical_officers) > 0)
13+
14+
def test_cos_endpoint_with_bad_query(self):
15+
response = self.client.get("/clinical-officers/search.json?q=")
16+
self.assertIn("A query is required.", response.data)
17+
18+
def test_cos_endpoint_gets_doctors(self):
19+
response = self.client.get("/clinical-officers/search.json?q=Marie")
20+
self.assertIn("success", response.data)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from unittest import TestCase
2+
from healthtools_ke_api import app
3+
from healthtools_ke_api.views.doctors import get_doctors_from_cloudsearch
4+
5+
6+
class TestDoctorsAPI(TestCase):
7+
def setUp(self):
8+
self.client = app.test_client()
9+
10+
def test_gets_doctors_from_cloudsearch(self):
11+
doctors = get_doctors_from_cloudsearch("Marie")
12+
self.assertTrue(len(doctors) > 0)
13+
14+
def test_doctors_endpoint_with_bad_query(self):
15+
response = self.client.get("/doctors/search.json?q=")
16+
self.assertIn("A query is required.", response.data)
17+
18+
def test_doctors_endpoint_gets_doctors(self):
19+
response = self.client.get("/doctors/search.json?q=Marie")
20+
self.assertIn("success", response.data)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from unittest import TestCase
2+
from healthtools_ke_api import app
3+
from healthtools_ke_api.views.nurses import get_nurses_from_nc_registry
4+
5+
6+
class TestNursesAPI(TestCase):
7+
def setUp(self):
8+
self.client = app.test_client()
9+
10+
def test_gets_nurses_from_nc_registry(self):
11+
nurses = get_nurses_from_nc_registry("Marie")
12+
self.assertTrue(len(nurses) > 0)
13+
14+
def test_gets_nurses_from_nc_registry_handle_inexistent_nurse(self):
15+
nurses = get_nurses_from_nc_registry("ihoafiho39023u8")
16+
self.assertEqual(len(nurses), 0)
17+
18+
def test_nurses_endpoint_handles_bad_query(self):
19+
response = self.client.get("/nurses/search.json?q=")
20+
self.assertIn("A query is required.", response.data)
21+
22+
def test_nurses_endpoint_gets_nurses(self):
23+
response = self.client.get("/nurses/search.json?q=Marie")
24+
self.assertIn("success", response.data)
25+
26+
def test_nurses_endpoint_can_retrieve_cached_result(self):
27+
# call once
28+
self.client.get("/nurses/search.json?q=Marie")
29+
# second time should retrieve cached result
30+
response = self.client.get("/nurses/search.json?q=Marie")
31+
self.assertIn("X-Retrieved-From-Cache", response.headers.keys())

healthtools_ke_api/views/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)