- #11: Add validation to prevent simultaneous scheduling of routines and medications - Added _check_schedule_conflicts() in routines.py - Added _check_med_schedule_conflicts() in medications.py - Returns HTTP 409 with descriptive error on conflict - #10: Fix medication reminders not being sent - Added call to check_adaptive_medication_reminders() in daemon poll loop - #9: Fix can't enable adaptive timing - Added proper error handling and logging in update_adaptive_settings() - Returns meaningful error message on database failures - #8: Fix nagging not working - Added debug logging for missing settings - Auto-create medication schedules if they don't exist - Improved error logging (warning -> error)
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
api/routes/adaptive_meds.py - API endpoints for adaptive medication settings
|
||||
"""
|
||||
|
||||
import logging
|
||||
import flask
|
||||
import jwt
|
||||
import os
|
||||
import core.postgres as postgres
|
||||
import core.adaptive_meds as adaptive_meds
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
JWT_SECRET = os.getenv("JWT_SECRET")
|
||||
|
||||
|
||||
@@ -99,18 +102,25 @@ def register(app):
|
||||
"quiet_hours_end": data.get("quiet_hours_end"),
|
||||
}
|
||||
|
||||
# Check if settings exist
|
||||
existing = adaptive_meds.get_adaptive_settings(user_uuid)
|
||||
try:
|
||||
# Check if settings exist
|
||||
existing = adaptive_meds.get_adaptive_settings(user_uuid)
|
||||
|
||||
if existing:
|
||||
postgres.update(
|
||||
"adaptive_med_settings", update_data, {"user_uuid": user_uuid}
|
||||
)
|
||||
else:
|
||||
update_data["user_uuid"] = user_uuid
|
||||
postgres.insert("adaptive_med_settings", update_data)
|
||||
if existing:
|
||||
postgres.update(
|
||||
"adaptive_med_settings", update_data, {"user_uuid": user_uuid}
|
||||
)
|
||||
else:
|
||||
update_data["user_uuid"] = user_uuid
|
||||
postgres.insert("adaptive_med_settings", update_data)
|
||||
|
||||
return flask.jsonify({"success": True}), 200
|
||||
return flask.jsonify({"success": True}), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save adaptive settings: {e}")
|
||||
return flask.jsonify({
|
||||
"error": "Failed to save settings",
|
||||
"details": str(e)
|
||||
}), 500
|
||||
|
||||
@app.route("/api/adaptive-meds/presence", methods=["GET"])
|
||||
def get_presence_status():
|
||||
|
||||
Reference in New Issue
Block a user