Skip to content

Commit

Permalink
edit app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
k-arthik-r committed Feb 18, 2024
1 parent 125efa4 commit 64bbc66
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from email.mime.multipart import MIMEMultipart
from docx import Document
from datetime import datetime
import os

config = ConfigParser()
config.read('config.ini')
Expand Down Expand Up @@ -311,7 +312,6 @@ def fetchpatientdetails():

@app.route('/generatereport', methods=["GET"])
def generatereport():

name = request.args.get('name')
pid = request.args.get('pid')
age = request.args.get('age')
Expand All @@ -320,9 +320,7 @@ def generatereport():
docid = request.args.get('docid')
docname = request.args.get('docname')



data = {'name': name, 'pid':pid, 'age':age, 'sfeel':sfeel, 'stest':stest, 'docid': docid, 'docname': docname}
data = {'name': name, 'pid': pid, 'age': age, 'sfeel': sfeel, 'stest': stest, 'doctor_id': docid, 'doctor_name': docname}

now = datetime.now()
current_month = str(now.month)
Expand All @@ -340,12 +338,17 @@ def generatereport():
for key, value in data.items():
if key in paragraph.text:
paragraph.text = paragraph.text.replace('{{' + key + '}}', str(value))

# Ensure the directory exists
documentsgen_dir = os.path.join(app.root_path, 'static', 'documentsgen')
os.makedirs(documentsgen_dir, exist_ok=True)

# Construct the absolute path for the temporary Word document
fname = data["pid"]
temp_docx_path = f'static/documentsgen/{fname}.docx'
temp_docx_path = os.path.join(documentsgen_dir, f'{fname}.docx')
doc.save(temp_docx_path)

return send_file(temp_docx_path, as_attachment=True)

return send_file(temp_docx_path, as_attachment=True)

if __name__ == '__main__':
app.run(debug = True)
Expand Down

0 comments on commit 64bbc66

Please sign in to comment.