Skip to content

Commit 4bd0a08

Browse files
committed
Slight changes.
1 parent 4fe3f3d commit 4bd0a08

File tree

9 files changed

+50
-65
lines changed

9 files changed

+50
-65
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ Install Memcached
3030

3131
You can set the required environment variables like so
3232
```<>
33+
$ export APP_DEBUG=<False> # True or False
3334
$ export MEMCACHED_URL=<memcache_url:port> # defaults to 127.0.0.1:8000
3435
$ export GA_TRACKING_ID=<google-analytics-tracking-id>
3536
$ export SMS_USER=<sms-provider-user-id>
3637
$ export SMS_PASS=<sms-provider-passcode>
3738
$ export SMS_SHORTCODE=<sms-provider-shortcode>
3839
$ export SMS_SEND_URL=<url-for-sms-provider>
39-
$ export CONFIG=<config-mode> # eg. "healthtools_ke_api.settings.DevConfig"
40-
$ export AWS_ACCESS_KEY_ID=<aws-access-key-id>
40+
$ export AWS_ACCESS_KEY=<aws-access-key-id>
4141
$ export AWS_SECRET_KEY=<aws-secret-key>
42-
$ export AWS_REGION=<aws-region>
4342
$ export ES_HOST=<elasticsearch_host_endpoint> (DO NOT SET THIS IF YOU WOULD LIKE TO USE ELASTIC SEARCH LOCALLY ON YOUR MACHINE)
43+
$export ES_PORT=<elasticsearch_port>
4444
```
4545
**If you want to use elasticsearch locally on your machine use the following instructions to set it up**
4646

@@ -63,4 +63,4 @@ Run memcached on your terminal `$ memcached -p <port you set MEMCACHED_URL to ru
6363
_**make sure if you use elasticsearch locally, it's running**_
6464

6565
Use nosetests to run tests (with stdout) like this:
66-
```$ nosetests --nocapture```
66+
```$ nosetests --nocapture```

healthtools_ke_api/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313

1414
app = Flask(__name__)
1515

16-
try:
17-
app.config.from_object(os.getenv('CONFIG'))
18-
except KeyError:
19-
print "No config has been specified for use in the environment variables."
20-
sys.exit()
21-
2216
app.register_blueprint(doctors_api, url_prefix='/doctors')
2317
app.register_blueprint(nurses_api, url_prefix='/nurses')
2418
app.register_blueprint(clinical_officers_api, url_prefix='/clinical-officers')

healthtools_ke_api/analytics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def track_event(tracking_id, category, action, cid, label=None, value=0):
2424
'ea': action,
2525
'el': label,
2626
'ev': value,
27-
}
27+
}
2828
response = requests.post(
2929
'http://www.google-analytics.com/collect', data=data)
3030
response.raise_for_status()

healthtools_ke_api/settings.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,28 @@
11
import os
22

3+
DEBUG = os.getenv("APP_DEBUG", False)
4+
35
# Url of memcached server
4-
MEMCACHED_URL = os.getenv("MEMCACHED_URL", '127.0.0.1:8000')
6+
MEMCACHED_URL = os.getenv("MEMCACHED_URL", "127.0.0.1:11211")
57

68
# 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", 'eu-west-1'),
11-
}
9+
AWS = {
10+
"access_key": os.getenv("AWS_ACCESS_KEY"),
11+
"secret_key": os.getenv("AWS_SECRET_KEY"),
12+
"region": os.getenv("AWS_REGION", "eu-west-1"),
13+
}
1214

1315
# Elastic Search configs
1416
ES = {
1517
"host": os.getenv("ES_HOST", "127.0.0.1"),
1618
"port": os.getenv("ES_PORT", "9200"),
17-
"index": "healthtools"
18-
}
19-
20-
21-
class Config(object):
22-
# Google Analytics tracking id
23-
GA_TRACKING_ID = os.environ.get('GA_TRACKING_ID')
24-
25-
# SMS provider credentials
26-
SMS_USER = os.environ.get('SMS_USER')
27-
SMS_PASS = os.environ.get('SMS_PASS')
28-
SMS_SHORTCODE = os.environ.get('SMS_SHORTCODE')
29-
30-
DOCTORS_SEARCH_URL = "https://6ujyvhcwe6.execute-api.eu-west-1.amazonaws.com/prod"
31-
NURSE_SEARCH_URL = "https://api.healthtools.codeforafrica.org/nurses/search.json"
32-
CO_SEARCH_URL = "https://vfblk3b8eh.execute-api.eu-west-1.amazonaws.com/prod"
33-
NHIF_SEARCH_URL = "https://t875kgqahj.execute-api.eu-west-1.amazonaws.com/prod"
34-
HF_SEARCH_URL = "https://187mzjvmpd.execute-api.eu-west-1.amazonaws.com/prod"
19+
"index": "healthtools-ke"
20+
}
3521

22+
# Google Analytics tracking id
23+
GA_TRACKING_ID = os.environ.get('GA_TRACKING_ID')
3624

37-
# development config
38-
class DevConfig(Config):
39-
DEBUG = True
40-
SERVER_NAME = "127.0.0.1:8000"
25+
# SMS provider credentials
26+
SMS_USER = os.environ.get('SMS_USER')
27+
SMS_PASS = os.environ.get('SMS_PASS')
28+
SMS_SHORTCODE = os.environ.get('SMS_SHORTCODE')

healthtools_ke_api/views/clinical_officers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ def index():
1515
"name": "API to Kenyan Clinical Officers registry",
1616
"authentication": [],
1717
"endpoints": {
18-
"/": {"methods": ["GET"]},
18+
"/": {
19+
"methods": ["GET"]
20+
},
1921
"/clinical-officers/search.json": {
2022
"methods": ["GET"],
2123
"args": {
2224
"q": {"required": True}
23-
}
24-
},
25-
}
25+
}
26+
},
2627
}
28+
}
2729
return jsonify(msg)
2830

2931

@@ -36,7 +38,7 @@ def search():
3638
"error": "A query is required.",
3739
"results": "",
3840
"data": {"clinical_officers": []}
39-
})
41+
})
4042

4143
# get clinical_officers by that name from aws
4244
response = {}
@@ -59,4 +61,4 @@ def search():
5961
"status": "error",
6062
"message": str(err),
6163
"data": {"clinical_officers": []}
62-
})
64+
})

healthtools_ke_api/views/doctors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def index():
2020
"methods": ["GET"],
2121
"args": {
2222
"q": {"required": True}
23-
}
24-
},
25-
}
23+
}
24+
},
2625
}
26+
}
2727
return jsonify(msg)
2828

2929

@@ -36,7 +36,7 @@ def search():
3636
"error": "A query is required.",
3737
"results": "",
3838
"data": {"doctors": []}
39-
})
39+
})
4040

4141
# get doctors by that name from aws
4242
response = {}
@@ -58,4 +58,4 @@ def search():
5858
"status": "error",
5959
"message": str(err),
6060
"data": {"doctors": []}
61-
})
61+
})

healthtools_ke_api/views/elastic_search.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
from elasticsearch import Elasticsearch, RequestsHttpConnection
22
from requests_aws4auth import AWS4Auth
33

4-
from healthtools_ke_api.settings import AWS_CONFIGS as AWS, ES
4+
from healthtools_ke_api.settings import AWS, ES
55
from serializer import JSONSerializerPython2
66
import re
77

8+
89
class Elastic(object):
910
"""
1011
Common class for elastic search client and methods
1112
"""
1213
def __init__(self):
1314
# client host for aws elastic search service
14-
if 'aws' in ES['host']:
15+
if "aws" in ES["host"]:
1516
# set up authentication credentials
16-
awsauth = AWS4Auth(AWS["aws_access_key_id"], AWS["aws_secret_access_key"], AWS["region_name"], 'es')
17+
awsauth = AWS4Auth(AWS["access_key"], AWS["secret_key"], AWS["region"], 'es')
1718
self.es_client = Elasticsearch(
18-
hosts=ES['host'],
19-
port=ES['port'],
19+
hosts=ES["host"],
20+
port=int(ES["port"]),
2021
http_auth=awsauth,
2122
use_ssl=True,
2223
verify_certs=True,
2324
connection_class=RequestsHttpConnection,
2425
serializer=JSONSerializerPython2()
25-
)
26+
)
2627
else:
27-
self.es_client = Elasticsearch("{}:{}".format(ES['host'], ES['port']))
28+
self.es_client = Elasticsearch("{}:{}".format(ES["host"], ES["port"]))
2829

2930
@staticmethod
3031
def remove_keyword(query):
@@ -54,9 +55,9 @@ def get_from_elasticsearch(self, doc_type, query):
5455
"query": search_term,
5556
"fuzziness": "auto",
5657
"prefix_length": 1
57-
}
5858
}
5959
}
6060
}
61-
)
61+
}
62+
)
6263
return results["hits"]["hits"]

healthtools_ke_api/views/nurses.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def index():
2828
"methods": ["GET"],
2929
"args": {
3030
"q": {"required": True}
31-
}
32-
},
33-
}
31+
}
32+
},
3433
}
34+
}
3535
return jsonify(msg)
3636

3737

@@ -81,7 +81,7 @@ def search():
8181
"status": "error",
8282
"message": str(err),
8383
"data": {"nurses": []}
84-
})
84+
})
8585

8686

8787
def get_nurses_from_nc_registry(query):
@@ -97,7 +97,7 @@ def get_nurses_from_nc_registry(query):
9797

9898
# make soup for parsing out of response and get the table
9999
soup = BeautifulSoup(response.content, "html.parser")
100-
table = soup.find('table', {"class": "zebra"}).find("tbody")
100+
table = soup.find("table", {"class": "zebra"}).find("tbody")
101101
rows = table.find_all("tr")
102102

103103
# parse table for the nurses data

healthtools_ke_api/views/sms_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'hospitali', 'sanatorium', 'health centre']
2121
es = Elastic()
2222

23-
sms_handler = Blueprint('sms_handler', __name__)
23+
sms_handler = Blueprint("sms_handler", __name__)
2424

2525

2626
@sms_handler.route("/sms", methods=['GET'])

0 commit comments

Comments
 (0)