fixing snitch and adaptive medication timing persistance and logic

This commit is contained in:
2026-02-17 18:52:35 -06:00
parent cf2b4be033
commit f826e511d5
4 changed files with 47 additions and 46 deletions

View File

@@ -3,6 +3,7 @@ api/routes/adaptive_meds.py - API endpoints for adaptive medication settings
"""
import logging
import uuid
import flask
import jwt
import os
@@ -103,16 +104,11 @@ def register(app):
}
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)
update_data["user_uuid"] = user_uuid
update_data.setdefault("id", str(uuid.uuid4()))
postgres.upsert(
"adaptive_med_settings", update_data, conflict_columns=["user_uuid"]
)
return flask.jsonify({"success": True}), 200
except Exception as e:

View File

@@ -2,6 +2,7 @@
api/routes/snitch.py - API endpoints for snitch system
"""
import uuid
import flask
import jwt
import os
@@ -89,15 +90,10 @@ def register(app):
"updated_at": datetime.utcnow(),
}
# Check if settings exist
existing = snitch_core.get_snitch_settings(user_uuid)
if existing:
postgres.update("snitch_settings", update_data, {"user_uuid": user_uuid})
else:
update_data["user_uuid"] = user_uuid
update_data["created_at"] = datetime.utcnow()
postgres.insert("snitch_settings", update_data)
update_data["user_uuid"] = user_uuid
update_data.setdefault("id", str(uuid.uuid4()))
update_data.setdefault("created_at", datetime.utcnow())
postgres.upsert("snitch_settings", update_data, conflict_columns=["user_uuid"])
return flask.jsonify({"success": True}), 200
@@ -161,6 +157,7 @@ def register(app):
), 400
contact_data = {
"id": str(uuid.uuid4()),
"user_uuid": user_uuid,
"contact_name": data["contact_name"],
"contact_type": data["contact_type"],
@@ -277,6 +274,7 @@ def register(app):
# Insert into snitch_log so the bot will pick it up and send it
log_data = {
"id": str(uuid.uuid4()),
"user_uuid": user_uuid,
"contact_id": contact.get("id"),
"medication_id": None, # Test snitch, no actual medication