-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
65 lines (55 loc) · 1.67 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
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
import api
app = Flask(__name__)
CORS(app)
"""
To ensure our server is working
"""
@app.route('/')
def index():
return "Hello World!"
"""
GET: Takes the name of the patient and returns the number of drugs being taken,
what drugs are being taken, and the lexographical codes of those drugs
"""
@app.route('/taken/firstName=<firstName>&lastName=<lastName>', methods=['GET'])
def get_drugs_taken(firstName, lastName):
drug = api.get_drug(firstName, lastName)
names = api.get_drug_name(drug)
code = []
# gets codes for all drugs
for n in names:
c = api.numbers(n)
code.append(c)
return jsonify({'num_drugs': len(drug),'drug': drug, 'code': code})
"""
GET: Takes all the currently prescribed drugs and the drug that the doctor wants
to prescribe and returns descriptions of their reactions
"""
@app.route('/combine/drug=<drug>&check_drug=<check_drug>', methods=['GET'])
def combined_drugs(drug, check_drug):
# parses any drug entered and gets a list out of them. The drugs can only
# have 0s in between and nothing else
meds = parse(drug)
meds.append(check_drug)
description = api.get_danger(meds)
return jsonify({'description': description})
"""
Parses when multiple drugs are put in with 0s in between each drug
"""
def parse(s):
split = s.split('0')
list = []
for p in split:
n = ''
if ',' in p:
n = p[0:p.index(',')]
else:
n = p
if ' ' in n:
n = n[0: n.index(' ')]
list.append(n.lower())
return list
if __name__ == "__main__":
app.run(debug=True)