Skip to content

Commit

Permalink
Database changed
Browse files Browse the repository at this point in the history
  • Loading branch information
bhardwajaditya committed May 10, 2019
1 parent 31aa5d2 commit b01a188
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 24 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import csv
import io

client = MongoClient()
db = client['medisyst']
client = pymongo.MongoClient("mongodb://Aditya:[email protected]:27017,cluster0-shard-00-01-kulfh.mongodb.net:27017,cluster0-shard-00-02-kulfh.mongodb.net:27017/medisyst?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true")
db = client.medisyst
users = db.users
doctors=db.doctors
addrequests=db.addrequests
Expand All @@ -23,7 +23,7 @@
# "permission": "Yes",
# "used": "No",
# "name": "Aditya Bhardwaj",
# "key": "w1",
# "key": "w123",
# "email":"[email protected]"

# })
Expand All @@ -33,9 +33,9 @@
# doctors.delete_many({})
# addrequests.delete_many({})

x=doctors.find()
for i in x:
print(i)
# x=doctors.find()
# for i in x:
# print(i)

username = "[email protected]"
password = "Wd85RaFy76Xrw3QBx"
Expand Down Expand Up @@ -162,14 +162,17 @@ def home(ID):
@app.route('/home/<ID>/addkey',methods = ['POST', 'GET'])
def addkey(ID):
if(request.method=="POST"):
doc=doctors.find_one({'_id':ObjectId(ID)})
name=request.form['Name']
email=request.form['email']
used="No"
permission="No"
x = name+str(datetime.datetime.now())
rawHashString = hmac.new(bytes(x, encoding='utf-8'), x.encode('utf-8')).digest()
key = base64.b64encode(rawHashString).decode()
key=key[:5]
req={
'docEmail':doc['email'],
'name':name,
'email':email,
'used':used,
Expand All @@ -192,14 +195,18 @@ def add(ID):
url="/home/"+ID
key=request.form['key']
result = addrequests.find_one({'key':key})
if(result==None):
error="key not valid"
addkey=url+"/addkey"
return render_template('add.html',url=url,error=error,addkey=addkey)
print(result['email'])
if(result['used']=="Yes" or result['permission']=="No"):
error="Key not valid"

return render_template('add.html',error=error,url=url)
else:
x=addrequests.update_one({'key':key},{'$set':{'used':"Yes"}})
print(x)
doc=doctors.find_one({'_id':ObjectId(ID)})
patient=users.find_one({'email':result['email']})
doc=doctors.find_one({'_id':ObjectId(ID)})
print(doc)
Expand All @@ -211,7 +218,8 @@ def add(ID):
if(patient not in A):
A.append(patient)
doc1=doctors.update_one({'_id':ObjectId(ID)},{'$set':{'patients':A}})
return render_template('addrecord.html',patient=patient,url=url,ID=ID,email=patient['email'])
x=addrequests.delete_one({'key':key})
return render_template('addrecord.html',patient=patient,url=url,ID=ID,email=patient['email'],doc=doc)

@app.route('/history',methods = ['POST', 'GET'])
def history():
Expand Down Expand Up @@ -345,6 +353,14 @@ def gsearch():
A.append(j)
return json_response(A)

@app.route('/getkey')
def keys():
key = addrequests.find()
A=[]
for i in key:
A.append({'name':i['name'],'key':i['key'],'permission':i['permission'],'used':i['used'],'docEmail':i['docEmail'],'email':i['email']})
return json_response(A)

@app.route('/csv')
def getcsv():
email=request.args.get('email')
Expand Down
4 changes: 2 additions & 2 deletions templates/addrecord.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1>{{patient['name']}}</h1>
<h1><p align="center">No History</p></h1>
<p align="center">Well done Doctor! Your patient has no past medical record</p>
<p align="center">
<a class="btn btn1 btn-lg" href={{addurl}} role="button">Add Patients</a>
<a class="btn btn1 btn-lg" href={{url}} role="button">Add Patients</a>
</p>
</div></div>
<div class="col-md-6">
Expand Down Expand Up @@ -92,7 +92,7 @@ <h4> <p align="center" >Add History</p></h4>
<form action="/history" method="post">
<div class="form-group" >
<label for="exampleInputEmail1">Doctor Name</label>
<input type="text" class="form-control" name="docname" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter Your Name">
<input type="text" class="form-control" name="docname" id="exampleInputEmail1" aria-describedby="emailHelp" value={{doc["fname"]}} placeholder="Enter Your Name">
</div>
<div class="form-group" >
<label for="exampleInputEmail1">Disease Name</label>
Expand Down

0 comments on commit b01a188

Please sign in to comment.