feat(ai-onboarding): enhance conversation flow, prompt rules & update Postman environment port to 8001

This commit is contained in:
2026-09-01 15:22:40 +05:30
parent 1d794ca425
commit c23d979338
31 changed files with 4686 additions and 749 deletions
@@ -1,4 +1,5 @@
import json
from app.ai.orchestrator import check_required_missing
class CompletionService:
@@ -8,45 +9,25 @@ class CompletionService:
session,
state,
) -> bool:
data = json.loads(
state.state_json
)
"""
Clinical intake completion validation using the single source of truth:
check_required_missing().
reason = data.get("reason_for_visit")
symptoms = data.get("symptoms")
history = data.get("medical_history")
medications = data.get("medications")
allergies = data.get("allergies")
Returns True only when:
- Session status is already 'completed' or stage is 'confirmation', OR
- All required categories (reason_for_visit, symptoms+duration,
medical_history, medications, allergies) are either reported or confirmed_none.
"""
if getattr(session, "status", None) == "completed" or getattr(session, "stage", None) == "confirmation":
return True
# Check structured status dictionary format
if isinstance(reason, dict):
if reason.get("status") == "not_collected" or not reason.get("value"):
return False
elif not reason:
if not state or not getattr(state, "state_json", None):
return False
if isinstance(symptoms, dict):
if symptoms.get("status") == "not_collected" or len(symptoms.get("items", [])) == 0:
return False
elif not symptoms:
try:
data = json.loads(state.state_json)
except Exception:
return False
if isinstance(history, dict):
if history.get("status") == "not_collected":
return False
elif history is None:
return False
if isinstance(medications, dict):
if medications.get("status") == "not_collected":
return False
elif medications is None:
return False
if isinstance(allergies, dict):
if allergies.get("status") == "not_collected":
return False
elif allergies is None:
return False
return True
missing = check_required_missing(data)
return len(missing) == 0