34 lines
1010 B
Python
34 lines
1010 B
Python
import json
|
|
from app.ai.orchestrator import check_required_missing
|
|
|
|
|
|
class CompletionService:
|
|
|
|
def is_complete(
|
|
self,
|
|
session,
|
|
state,
|
|
) -> bool:
|
|
"""
|
|
Clinical intake completion validation using the single source of truth:
|
|
check_required_missing().
|
|
|
|
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
|
|
|
|
if not state or not getattr(state, "state_json", None):
|
|
return False
|
|
|
|
try:
|
|
data = json.loads(state.state_json)
|
|
except Exception:
|
|
return False
|
|
|
|
missing = check_required_missing(data)
|
|
return len(missing) == 0
|