Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -774,9 +774,6 @@ PHYSICAL ACTIVITY/EXERCISE:
|
|
| 774 |
- [Recommended physical activities, duration, frequency, limitations, and progression]
|
| 775 |
SYMPTOM MANAGEMENT:
|
| 776 |
- [Detailed instructions for managing specific symptoms (e.g., pain, nausea, shortness of breath), non-pharmacological interventions]
|
| 777 |
-
RED FLAGS / WHEN TO SEEK HELP:
|
| 778 |
-
- [Clear, actionable instructions on symptoms requiring immediate medical attention (Emergency - call 911/local emergency, go to ER)]
|
| 779 |
-
- [Instructions on symptoms requiring contact with doctor/clinic (Urgent but not Emergency - call office, visit clinic)]
|
| 780 |
ADDITIONAL RECOMMENDATIONS:
|
| 781 |
- [Other relevant advice, e.g., rest, monitoring specific vital signs, wound care instructions, mental health support, caregiver tips]
|
| 782 |
FOLLOW-UP:
|
|
@@ -800,7 +797,6 @@ Instructions:
|
|
| 800 |
3. Prioritize addressing the issues raised in the patient feedback.
|
| 801 |
4. Be specific, actionable, and realistic in your recommendations (e.g., specify *what* activities, *when* to take medications and *what" medications and diet to follow).
|
| 802 |
5. Ensure the language is clear, empathetic, and easy for a patient or caregiver to understand. Avoid overly technical jargon where possible.
|
| 803 |
-
6. Include clear instructions in the "RED FLAGS / WHEN TO SEEK HELP" section, distinguishing between immediate emergency (e.g., call 911/local emergency) and urgent but non-emergency situations (e.g., call doctor's office).
|
| 804 |
7. Do NOT include any introductory phrases (like "Here is the updated plan:", "Based on your feedback...") or concluding sentences outside the plan structure. Provide ONLY the structured content that fits within the template.
|
| 805 |
8. If the previous care plan was unavailable or unreadable, create the plan based solely on the patient information and feedback, still following the template.
|
| 806 |
9. Ensure the plan is medically sound and reflects standard care principles. If feedback indicates a significant change or potential issue, the ASSESSMENT and subsequent sections should clearly address this and recommend appropriate actions (like contacting their doctor for a re-evaluation, even if it's not an immediate emergency).
|
|
@@ -1006,7 +1002,6 @@ def send_whatsapp_doctor(patient_id):
|
|
| 1006 |
|
| 1007 |
|
| 1008 |
# --- Existing routes remain below ---
|
| 1009 |
-
|
| 1010 |
@app.route('/download_pdf/<patient_id>')
|
| 1011 |
def download_pdf(patient_id):
|
| 1012 |
logger.info(f"Download requested for patient ID: {patient_id}")
|
|
@@ -1026,20 +1021,29 @@ def download_pdf(patient_id):
|
|
| 1026 |
)
|
| 1027 |
|
| 1028 |
# Check if the buffer contains the error message text (simple check)
|
| 1029 |
-
|
|
|
|
| 1030 |
if "Error Generating Care Plan PDF" in buffer_content:
|
| 1031 |
logger.error(f"PDF generation failed for ID {patient_id}, returning error PDF.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1032 |
# Send the error PDF, but indicate it's an error
|
| 1033 |
return send_file(
|
| 1034 |
io.BytesIO(pdf_buffer.getvalue()), # Need to create a new buffer from the value
|
| 1035 |
as_attachment=True,
|
| 1036 |
-
download_name=
|
| 1037 |
mimetype='application/pdf'
|
| 1038 |
)
|
| 1039 |
|
| 1040 |
|
| 1041 |
pdf_buffer.seek(0) # Reset buffer position after checking content
|
| 1042 |
|
|
|
|
| 1043 |
safe_name = re.sub(r'[^a-zA-Z0-9_\-]', '', patient.name or 'patient').lower()
|
| 1044 |
download_name = f"care_plan_{safe_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf"
|
| 1045 |
|
|
@@ -1054,6 +1058,7 @@ def download_pdf(patient_id):
|
|
| 1054 |
logger.error(f"PDF Download Error for ID {patient_id}: {str(e)}", exc_info=True)
|
| 1055 |
# Fallback error response if even generating the basic error PDF fails
|
| 1056 |
return f"Error generating PDF for download: {str(e)}", 500
|
|
|
|
| 1057 |
|
| 1058 |
|
| 1059 |
@app.route('/get_emergency_notifications')
|
|
|
|
| 774 |
- [Recommended physical activities, duration, frequency, limitations, and progression]
|
| 775 |
SYMPTOM MANAGEMENT:
|
| 776 |
- [Detailed instructions for managing specific symptoms (e.g., pain, nausea, shortness of breath), non-pharmacological interventions]
|
|
|
|
|
|
|
|
|
|
| 777 |
ADDITIONAL RECOMMENDATIONS:
|
| 778 |
- [Other relevant advice, e.g., rest, monitoring specific vital signs, wound care instructions, mental health support, caregiver tips]
|
| 779 |
FOLLOW-UP:
|
|
|
|
| 797 |
3. Prioritize addressing the issues raised in the patient feedback.
|
| 798 |
4. Be specific, actionable, and realistic in your recommendations (e.g., specify *what* activities, *when* to take medications and *what" medications and diet to follow).
|
| 799 |
5. Ensure the language is clear, empathetic, and easy for a patient or caregiver to understand. Avoid overly technical jargon where possible.
|
|
|
|
| 800 |
7. Do NOT include any introductory phrases (like "Here is the updated plan:", "Based on your feedback...") or concluding sentences outside the plan structure. Provide ONLY the structured content that fits within the template.
|
| 801 |
8. If the previous care plan was unavailable or unreadable, create the plan based solely on the patient information and feedback, still following the template.
|
| 802 |
9. Ensure the plan is medically sound and reflects standard care principles. If feedback indicates a significant change or potential issue, the ASSESSMENT and subsequent sections should clearly address this and recommend appropriate actions (like contacting their doctor for a re-evaluation, even if it's not an immediate emergency).
|
|
|
|
| 1002 |
|
| 1003 |
|
| 1004 |
# --- Existing routes remain below ---
|
|
|
|
| 1005 |
@app.route('/download_pdf/<patient_id>')
|
| 1006 |
def download_pdf(patient_id):
|
| 1007 |
logger.info(f"Download requested for patient ID: {patient_id}")
|
|
|
|
| 1021 |
)
|
| 1022 |
|
| 1023 |
# Check if the buffer contains the error message text (simple check)
|
| 1024 |
+
# Using latin-1 and ignore for decoding potentially non-UTF8 PDF content
|
| 1025 |
+
buffer_content = pdf_buffer.getvalue().decode('latin-1', errors='ignore')
|
| 1026 |
if "Error Generating Care Plan PDF" in buffer_content:
|
| 1027 |
logger.error(f"PDF generation failed for ID {patient_id}, returning error PDF.")
|
| 1028 |
+
# --- FIX START ---
|
| 1029 |
+
# Extract the re.sub call out of the f-string expression
|
| 1030 |
+
safe_name_error = re.sub(r'[^a-zA-Z0-9_\-]', '', patient.name or 'patient').lower()
|
| 1031 |
+
# Use the variable in the f-string
|
| 1032 |
+
download_name_error = f"care_plan_{safe_name_error}_error.pdf"
|
| 1033 |
+
# --- FIX END ---
|
| 1034 |
+
|
| 1035 |
# Send the error PDF, but indicate it's an error
|
| 1036 |
return send_file(
|
| 1037 |
io.BytesIO(pdf_buffer.getvalue()), # Need to create a new buffer from the value
|
| 1038 |
as_attachment=True,
|
| 1039 |
+
download_name=download_name_error, # Use the corrected variable here
|
| 1040 |
mimetype='application/pdf'
|
| 1041 |
)
|
| 1042 |
|
| 1043 |
|
| 1044 |
pdf_buffer.seek(0) # Reset buffer position after checking content
|
| 1045 |
|
| 1046 |
+
# This part was already correct
|
| 1047 |
safe_name = re.sub(r'[^a-zA-Z0-9_\-]', '', patient.name or 'patient').lower()
|
| 1048 |
download_name = f"care_plan_{safe_name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf"
|
| 1049 |
|
|
|
|
| 1058 |
logger.error(f"PDF Download Error for ID {patient_id}: {str(e)}", exc_info=True)
|
| 1059 |
# Fallback error response if even generating the basic error PDF fails
|
| 1060 |
return f"Error generating PDF for download: {str(e)}", 500
|
| 1061 |
+
|
| 1062 |
|
| 1063 |
|
| 1064 |
@app.route('/get_emergency_notifications')
|