-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi1.py
More file actions
173 lines (141 loc) · 5.34 KB
/
api1.py
File metadata and controls
173 lines (141 loc) · 5.34 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from flask import Flask, redirect, url_for, request, jsonify
from firebase_admin import credentials, firestore, initialize_app
import json
app = Flask(__name__)
cred = credentials.Certificate('key.json')
default_app = initialize_app(cred)
db = firestore.client()
patient_details = db.collection('patient_details')
medicines_diagonized = db.collection('medicines_diagonized')
diagnosis_keywords = db.collection('diagnosis_keywords')
# API SUMMARY
# API1: patient_details_api [POST and GET]
# API2: diagonized_medicines_api [POST GET and PUT]
# API3: diagnosis_keywords_api [POST GET and PUT]
@app.route('/prediction', methods=['POST'])
def prediction():
s = ['skin_rash', 'continuous_sneezing', 'acidity', 'fatigue', 'nausea', 'loss_of_appetite',
'chest_pain', 'fast_heart_rate', 'bladder_discomfort', 'muscle_pain', 'prognosis']
requestData = request.json
print(requestData)
data = requestData['val']
symptom = []
for i in range(0, 10):
if data[i] == 1:
symptom.append(s[i])
if request.method == 'POST':
dummyData = {
"message": "Reply aaya be",
"symptoms": symptom,
"Alergy": [
0, {
"Hydroxyzine": [1, 0, 1, 600],
"Levocetirizine": [2, 0, 1, 400],
"Xyzal": [3, 0, 1, 500],
"Vistaril": [4, 0, 1, 650],
"Doxylamine": [5, 0, 1, 500]
}
]
}
return dummyData
#working
@app.route('/patient_details',methods=['POST','GET'])
def patient_details_api():
requestData = request.json
pid = requestData['pid']
if request.method == 'POST':
res = patient_details.document(pid).set(request.json)
data = {
"message":"patient_added",
"pid": pid
}
return data
elif request.method == 'GET':
data = patient_details.document(pid).get()
return jsonify(data.to_dict())
else:
return "Invalid request"
#Modify the PUT one.
@app.route('/diagonized_medicines', methods=['POST', 'GET', 'PUT'])
def diagonized_medicines():
requestData = request.json
pid = requestData['pid']
if(request.method == 'POST'):
timestamp = requestData['timestamp']
medicines_diagonized.document(pid).set(request.json)
data = {
"message": "Medicines stored for first time",
"pid": pid,
"timestamp": timestamp
}
return data
elif request.method == 'PUT':
'''
#Now this is interesting, please note carefully.
When the doctor is gonna update it when the user visits second time,
Here, the previous json object will be called using get and then the current one will be appended,
so that it becomes an array of objects according to timestamp.
#Thats just json, manipulation, in the api, we will just update the value, whenever a put request is received.
'''
# The requestData will obviously change as is sent in the request.
data = medicines_diagonized.document(pid).get()
data = data.to_dict()
json_data = {}
json_data.append(data)
json_data.append(requestData)
print(json_data)
json_data = json.dumps(json_data)
print(type(json_data))
medicines_diagonized.document(pid).update(json.loads(json_data))
data = {
"message": "Medicines updated",
"pid": pid,
}
return data
# This will be used while generating the prescription.
elif(request.method == 'GET'):
data = medicines_diagonized.document(pid).get()
return jsonify(data.to_dict())
else:
return "Invalid request"
#Have to check PUT method.
@app.route('/keywords',methods=['GET','PUT','POST'])
def keywords():
requestData = request.json
pid = requestData['pid']
if(request.method == 'POST'):
timestamp = requestData['timestamp']
diagnosis_keywords.document(pid).set(request.json)
data = {
"message":"Keywords stored!!!",
"pid": pid,
"timestamp":timestamp
}
return data
elif request.method == 'PUT':
'''
#This is exactly same as the previous API.
#Now this is interesting, please note carefully.
When the doctor is gonna update it when the user visits second time,
Here, the previous json object will be called using get and then the current one will be appended,
so that it becomes an array of objects according to timestamp.
#Thats just json, manipulation, in the api, we will just update the value, whenever a put request is received.
'''
#The requestData will obviously change as is sent in the request.
diagnosis_keywords.document(pid).update(requestData)
data = {
"message":"Keywords updated",
"pid":pid,
}
return data
#This will be used while generating the prescription.
elif(request.method == 'GET'):
data = diagnosis_keywords.document(pid).get()
return jsonify(data.to_dict())
else:
return "Invalid request"
@app.route('/')
def index():
return "Welcome to DocAid-API"
if __name__ == '__main__':
app.run(debug=True)