From f86e3ecd579eb91b2ab44615e6a1a27deccbb8f4 Mon Sep 17 00:00:00 2001
From: muoimeo <bvnminh6a01@gmail.com>
Date: Thu, 10 Apr 2025 14:18:19 +0700
Subject: [PATCH] add csv + gen report

---
 app/routes/patients.py |  2 +-
 app/routes/report.py   | 24 ++++++++++++++----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/app/routes/patients.py b/app/routes/patients.py
index a9aa611..21ee034 100644
--- a/app/routes/patients.py
+++ b/app/routes/patients.py
@@ -228,7 +228,7 @@ def new_referral(patient_id):
             reason=request.form.get('reason'),
             referral_status='new',
             priority=int(request.form.get('priority', 3)),
-            ml_prediction=False,
+            is_ml_recommended=False,
             notes=request.form.get('notes')
         )
         
diff --git a/app/routes/report.py b/app/routes/report.py
index 8456789..600b7cf 100644
--- a/app/routes/report.py
+++ b/app/routes/report.py
@@ -283,7 +283,7 @@ def generate():
         ).count(),
         'ml_prediction': Referral.query.filter(
             Referral.referralRequestedDateTime.between(start_date, end_date),
-            Referral.ml_prediction == True
+            Referral.is_ml_recommended == True
         ).count()
     }
     
@@ -292,11 +292,11 @@ def generate():
         'total': Procedure.query.filter(Procedure.procedureDateTime.between(start_date, end_date)).count(),
         'enteral_feeding': Procedure.query.filter(
             Procedure.procedureDateTime.between(start_date, end_date),
-            Procedure.procedure_type == 'enteral_feeding'
+            Procedure.procedureType == 'enteral_feeding'
         ).count(),
         'parenteral_nutrition': Procedure.query.filter(
             Procedure.procedureDateTime.between(start_date, end_date),
-            Procedure.procedure_type == 'parenteral_nutrition'
+            Procedure.procedureType == 'parenteral_nutrition'
         ).count()
     }
     
@@ -365,7 +365,8 @@ def generate():
         
         # Create temporary file
         temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
-        excel_file.save(temp_file.name)
+        temp_file.write(excel_file.getvalue())
+        temp_file.close()
         
         # Send the file
         return send_file(
@@ -392,7 +393,8 @@ def generate():
         
         # Create temporary file
         temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
-        excel_file.save(temp_file.name)
+        temp_file.write(excel_file.getvalue())
+        temp_file.close()
         
         # Send the file
         return send_file(
@@ -461,7 +463,7 @@ def create_stats_report(report_type):
         ).count(),
         'ml_prediction': Referral.query.filter(
             Referral.referralRequestedDateTime.between(start_date, end_date),
-            Referral.ml_prediction == True
+            Referral.is_ml_recommended == True
         ).count()
     }
     
@@ -470,11 +472,11 @@ def create_stats_report(report_type):
         'total': Procedure.query.filter(Procedure.procedureDateTime.between(start_date, end_date)).count(),
         'enteral_feeding': Procedure.query.filter(
             Procedure.procedureDateTime.between(start_date, end_date),
-            Procedure.procedure_type == 'enteral_feeding'
+            Procedure.procedureType == 'enteral_feeding'
         ).count(),
         'parenteral_nutrition': Procedure.query.filter(
             Procedure.procedureDateTime.between(start_date, end_date),
-            Procedure.procedure_type == 'parenteral_nutrition'
+            Procedure.procedureType == 'parenteral_nutrition'
         ).count()
     }
     
@@ -543,7 +545,8 @@ def create_stats_report(report_type):
         
         # Create temporary file
         temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
-        excel_file.save(temp_file.name)
+        temp_file.write(excel_file.getvalue())
+        temp_file.close()
         
         # Send the file
         return send_file(
@@ -570,7 +573,8 @@ def create_stats_report(report_type):
         
         # Create temporary file
         temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.xlsx')
-        excel_file.save(temp_file.name)
+        temp_file.write(excel_file.getvalue())
+        temp_file.close()
         
         # Send the file
         return send_file(
-- 
GitLab