Skip to content

Commit a4bdda6

Browse files
Merge pull request #5 from RyanSept/ft-add-doctors-to-api
Missing commits in master (currently deployed in prod)
2 parents 6ed325f + 10363c5 commit a4bdda6

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Specification for the API is shown below. It is an open api and requires no auth
1212

1313
| EndPoint | Allowed Methods | Functionality | Parameters |
1414
|-------------------------------------|------------------|----------------------------------------------------------|------------|
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> |
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] |
1818

1919

2020
### Installation

healthtools_ke_api/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def index():
3434
"authentication": [],
3535
"endpoints": {
3636
"/": {"methods": ["GET"]},
37-
"/nurses": {"methods": ["GET"]}
37+
"/nurses": {"methods": ["GET"]},
38+
"/doctors": {"methods": ["GET"]},
39+
"/clinical-officers": {"methods": ["GET"]}
3840
}
3941
}
4042
return jsonify(msg)

healthtools_ke_api/views/sms_handler.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from healthtools_ke_api.analytics import track_event
44
from healthtools_ke_api.views.nurses import get_nurses_from_nc_registry
5+
from healthtools_ke_api.views.doctors import get_doctors_from_cloudsearch
6+
from healthtools_ke_api.views.clinical_officers import get_clinical_officers_from_cloudsearch
57

68
import requests
79
import re
@@ -68,26 +70,25 @@ def build_query_response(query):
6870
if find_keyword_in_query(query, DOC_KEYWORDS):
6971
search_terms = find_keyword_in_query(query, DOC_KEYWORDS)
7072
query = query[:search_terms.start()] + query[search_terms.end():]
71-
r = requests.get(current_app.config.get('DOCTORS_SEARCH_URL'), params={'q': query})
72-
msg = construct_docs_response(parse_cloud_search_results(r))
73-
print msg
74-
return [msg, r.json()]
73+
print query
74+
doctors = get_doctors_from_cloudsearch(query)
75+
msg = construct_docs_response(doctors[:SMS_RESULT_COUNT])
76+
return [msg]
7577
# Looking for Nurses keywords
7678
elif find_keyword_in_query(query, NO_KEYWORDS):
7779
search_terms = find_keyword_in_query(query, NO_KEYWORDS)
7880
query = query[:search_terms.start()] + query[search_terms.end():]
7981
nurses = get_nurses_from_nc_registry(query)
8082
msg = construct_nurse_response(nurses[:SMS_RESULT_COUNT])
81-
print msg
8283
return [msg]
8384
# Looking for clinical officers Keywords
8485
elif find_keyword_in_query(query, CO_KEYWORDS):
8586
search_terms = find_keyword_in_query(query, CO_KEYWORDS)
8687
query = query[:search_terms.start()] + query[search_terms.end():]
87-
r = requests.get(current_app.config.get('CO_SEARCH_URL'), params={'q': query})
88-
msg = construct_co_response(parse_cloud_search_results(r))
89-
print msg
90-
return [msg, r.json()]
88+
print query
89+
clinical_officers = get_clinical_officers_from_cloudsearch(query)
90+
msg = construct_co_response(clinical_officers[:SMS_RESULT_COUNT])
91+
return [msg]
9192
# Looking for nhif hospitals
9293
elif find_keyword_in_query(query, NHIF_KEYWORDS):
9394
search_terms = find_keyword_in_query(query, NHIF_KEYWORDS)
@@ -125,8 +126,9 @@ def construct_co_response(co_list):
125126
count = 1
126127
msg_items = []
127128
for co in co_list:
129+
co = co["fields"]
128130
status = " ".join(
129-
[str(count) + ".", co['name'], "-", co['qualification']])
131+
[str(count) + ".", "".join(co['name']), "-", "".join(co['qualifications'])])
130132
msg_items.append(status)
131133
count = count + 1
132134
if len(co_list) > 1:
@@ -193,13 +195,14 @@ def construct_docs_response(docs_list):
193195
msg_items = []
194196

195197
for doc in docs_list:
198+
doc = doc["fields"]
196199
# Ignore speciality if not there, dont display none
197-
if doc['specialty'] == "None":
198-
status = " ".join([str(count) + ".", doc['name'], "-",
199-
doc['registration_number'], "-", doc['qualification']])
200+
if doc['speciality'] == "None":
201+
status = " ".join([str(count) + ".", "".join(doc['name']), "-",
202+
"".join(doc['reg_no']), "-", "".join(doc['qualifications'])])
200203
else:
201-
status = " ".join([str(count) + ".", doc['name'], "-", doc[
202-
'registration_number'], "-", doc['qualification'], doc['specialty']])
204+
status = " ".join([str(count) + ".", "".join(doc['name']), "-", "".join(doc[
205+
'reg_no']), "-", "".join(doc['qualifications']), "".join(doc['speciality'])])
203206
msg_items.append(status)
204207
count = count + 1
205208
if len(docs_list) > 1:

0 commit comments

Comments
 (0)