-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrxcheck.py
More file actions
101 lines (74 loc) · 2.82 KB
/
rxcheck.py
File metadata and controls
101 lines (74 loc) · 2.82 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
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
from flask import Flask, render_template, Response, request
from pymongo import MongoClient
from bson.json_util import dumps
app = Flask(__name__)
c_handler = CommsHandler.CommsHandler()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get/names/<search>')
def names(search):
client = MongoClient("mongodb://localhost:27017")
def getName(doc):
return doc.brand_name
cursor = client.rxcheck.medInfo.find({'brand_name': {
'$regex': '.*' + search
}}, {'brand_name': 1}).distinct('brand_name')
return Response(response=dumps(cursor),
status=200,
mimetype="application/json")
@app.route('/post/email/', methods=['POST'])
def uploadEmail():
userInfo = {'phone': request.form['phone'],
'email': request.form['email']}
drugs = request.form['drugs'].split(',')
#Connect to mongodb client
client = MongoClient('localhost', 27017)
#Get the database
db = client.rxcheck
#Get the collection
collection = db.emailInfo
for drug in drugs:
# collection.find_one_and_update(
# {'drug_name': drug},
# {'$push': {'users': userInfo}})
collection.insert({'drug_name': drug,
'users': userInfo})
e_handler = c_handler.get_email_sender()
e_handler.add_recipients(request.form['email'])
return Response(response='',
status=200,
mimetype="application/json")
@app.route('/email/<name>')
def setEmail(name):
client = MongoClient("mongodb://localhost:27017")
e_handler = c_handler.get_email_sender()
for data in client.rxcheck.emailInfo.find_all({'drug_name': name}):
e_handler.add_recipients(data.userInfo.email)
cursor = client.rxcheck.medInfo.find_one({'brand_name': {
'$regex': '^' + name
}}, {'brand_name': 1,
'generic_name': 1,
'warnings_and_precautions': 1,
'warnings': 1,
'active_ingredient': 1,
'inactive_ingredient': 1})
return Response(response=dumps(cursor),
status=200,
mimetype="application/json")
@app.route('/get/warnings/<name>')
def warnings(name):
client = MongoClient("mongodb://localhost:27017")
cursor = client.rxcheck.medInfo.find_one({'brand_name': {
'$regex': '^' + name
}}, {'brand_name': 1,
'generic_name': 1,
'warnings_and_precautions': 1,
'warnings': 1,
'active_ingredient': 1,
'inactive_ingredient': 1})
return Response(response=dumps(cursor),
status=200,
mimetype="application/json")
if __name__ == '__main__':
app.run(debug=True, port=5000)