forked from priyanshugandhi/Med-Help
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnearestDoctor.py
More file actions
executable file
·43 lines (39 loc) · 2.24 KB
/
nearestDoctor.py
File metadata and controls
executable file
·43 lines (39 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import urllib.request
import json
import config
# lat = "39.0289"
# long = "-116.5950"
def nearestDoctors(lat, long):
# getting maximum 33(random number) doctors in the ascending order of their distance from the user
url = "https://api.betterdoctor.com/2016-03-01/practices?location=" + lat + "%2C" + long + "%2C100&user_location=" + lat + "%2C" + long + "&sort=distance-asc&skip=0&limit=33&user_key=" + config.BetterDoctoruserKey
resultString = urllib.request.urlopen(url).read().decode("utf-8")
resultJson = json.loads(resultString)
index = 1
doctorProfiles = {}
# getting the main data from the result
for doctors in resultJson['data']:
try: # if any of the keys don't occur we skip that doctor
doctorProfile = {} # this dictionary stores the data of each doctor to be displayed at the front end.
# getting info about each doctor
for doctor in doctors['doctors']:
# storing the name
try:
doctorProfile["Name"] = doctor['profile']['first_name'] + " " + doctor['profile'][
'middle_name'] + " " + \
doctor['profile'][
'last_name']
except KeyError: # if middle name doesn't exist
doctorProfile["Name"] = doctor['profile']['first_name'] + " " + doctor['profile']['last_name']
# the doctors specialisations to be stored as a list
doctorSpecialities = []
for specialties in doctor['specialties']:
doctorSpecialities.append(specialties['actor'])
doctorProfile["specialities"] = doctorSpecialities
# storing the address with comma-separated string
doctorProfile["address"] = doctors['visit_address']['street'] + ", " + doctors['visit_address'][
'city'] + ", " + doctors['visit_address']['state_long'] + ", " + doctors['visit_address']['zip']
doctorProfiles[index] = doctorProfile
index = index + 1
except KeyError:
continue # just in case some key doesn't exist
return doctorProfiles