forked from mattstibbs/nhshd-service-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
129 lines (90 loc) · 3.24 KB
/
app.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from flask import Flask, jsonify, render_template, request
import os
import requests
import untangle
from flask_cors import CORS
import re
import default_config as config
app = Flask(__name__)
# Allow Cross Origin Resource Sharing for routes under the API path so that other services can use the API
regEx = re.compile("/*")
CORS(app, resources={regEx: {"origins": "*"}})
api_key = config.api_key
google_key = config.google_maps_api_key
def get_choices_service(service_id):
url = 'http://v1.syndication.nhschoices.nhs.uk/organisations/hospitals/' \
f'odscode/{service_id}.xml?apikey={api_key}'
print(url)
print("Querying Choices DoS")
r = requests.get(url)
print("Getting Choices DoS Overview")
document = untangle.parse(r.text)
url2 = document.Organisation.ProfileLinks.d2p1_Link[0].d2p1_Uri.cdata
url2 = url2.replace("overview", "overview.xml")
r2 = requests.get(url2)
document2 = untangle.parse(r2.text)
overview = document2.feed.entry.content.s_overview
name = overview.s_name.cdata
ods_code = overview.s_odsCode.cdata
lat = overview.s_geographicCoordinates.s_latitude.cdata
lon = overview.s_geographicCoordinates.s_longitude.cdata
address = overview.s_address
telephone = overview.s_contact.s_telephone.cdata
website = overview.s_website.cdata
data = {
'name': name,
'id': ods_code,
'lat': lat,
'lon': lon,
'telephone': telephone,
'address': {
'postcode': address.s_postcode.cdata,
},
'website': website
}
return data
@app.route('/map/<service_id>')
def show_map(service_id):
response = get_choices_service(service_id)
return render_template('main2.html',
lon=response['lon'],
lat=response['lat'],
google_key=google_key)
@app.route('/service/<service_id>')
def get_service_by_id(service_id):
# Make a call to the NHS Choices API to retrieve the information for the specified service ID
response = get_choices_service(service_id)
return jsonify(response)
@app.route('/pages/display')
def display_page():
return render_template('display.html')
@app.route('/pages/text1')
def display_text1():
return render_template('text1.html')
@app.route('/pages/text2')
def display_text2():
return render_template('text2.html')
@app.route('/pages/thankyou')
def display_thankyou():
return render_template('thankyou.html')
@app.route('/pages/onlinereg')
def display_onlinereg():
return render_template('onlinereg.html')
@app.route('/feedback/<service_id>')
def show_feedback(service_id):
response = get_choices_service(service_id)
return render_template('ratings.html',
name=response['name'])
@app.route('/')
def display_links():
return render_template('links.html')
@app.route('/post', methods=['POST'])
def post_feedback():
data = request.json
r = requests.post('http://ec2-13-58-211-169.us-east-2.compute.amazonaws.com/api/feedback',
json=data)
print(r.status_code)
print(r.text)
return 'OK', 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.getenv('PORT', 5000)), debug=True)