feat(ai-onboarding): enhance conversation flow, prompt rules & update Postman environment port to 8001
This commit is contained in:
@@ -20,37 +20,40 @@ class ResultExtractionService:
|
||||
)
|
||||
|
||||
prompt = f"""
|
||||
You are a hospital patient onboarding data extraction assistant.
|
||||
You are a senior clinical data extraction engine at a healthcare facility.
|
||||
|
||||
Your task is to convert the completed onboarding information
|
||||
into structured patient intake data.
|
||||
Your task is to convert the collected patient onboarding conversation and structured state
|
||||
into a clean, comprehensive, structured patient intake record for the attending doctor.
|
||||
|
||||
You are NOT a doctor.
|
||||
Do not diagnose the patient.
|
||||
Do not add information that was not provided.
|
||||
CLINICAL RULES:
|
||||
1. You are NOT a doctor. Do NOT diagnose or add medical interpretations.
|
||||
2. Capture ALL patient-reported symptoms, onset/duration, severity, location, frequency.
|
||||
3. Capture ALL reported medical history, medications (with dosage/frequency), allergies (with reaction), surgical history, and previous episodes.
|
||||
4. Capture any functional impact (sleep disruption, appetite changes, weakness) in additional_information.
|
||||
5. Do NOT invent information. If something was not provided, leave it null or an empty list.
|
||||
|
||||
PATIENT:
|
||||
PATIENT CONTEXT:
|
||||
{json.dumps({
|
||||
"id": session.patient_id,
|
||||
"name": session.patient_name,
|
||||
"age": session.age,
|
||||
"gender": session.gender,
|
||||
}, indent=2)}
|
||||
}, indent=2, ensure_ascii=False)}
|
||||
|
||||
CATEGORY:
|
||||
CATEGORY / SPECIALTY:
|
||||
{json.dumps({
|
||||
"type": session.category_type,
|
||||
"code": session.category_code,
|
||||
"name": session.category_name,
|
||||
}, indent=2)}
|
||||
}, indent=2, ensure_ascii=False)}
|
||||
|
||||
CURRENT STATE:
|
||||
{json.dumps(current_state, indent=2)}
|
||||
CURRENT INTAKE STATE:
|
||||
{json.dumps(current_state, indent=2, ensure_ascii=False)}
|
||||
|
||||
CONVERSATION:
|
||||
{json.dumps(conversation_history, indent=2)}
|
||||
FULL CONVERSATION:
|
||||
{json.dumps(conversation_history, indent=2, ensure_ascii=False)}
|
||||
|
||||
Return ONLY JSON conforming to this exact structure:
|
||||
Return ONLY a valid JSON object matching this structure:
|
||||
{{
|
||||
"patient_id": "{session.patient_id}",
|
||||
"category": {{
|
||||
@@ -58,19 +61,43 @@ Return ONLY JSON conforming to this exact structure:
|
||||
"code": "{session.category_code}",
|
||||
"name": "{session.category_name}"
|
||||
}},
|
||||
"chief_complaint": "string or null",
|
||||
"chief_complaint": "primary reason for visit or main symptom",
|
||||
"symptoms": [
|
||||
{{
|
||||
"name": "string",
|
||||
"duration": "string or null",
|
||||
"severity": "string or null",
|
||||
"description": "string or null"
|
||||
"name": "symptom name",
|
||||
"duration": "duration or null",
|
||||
"severity": "severity or null",
|
||||
"location": "location or null",
|
||||
"description": "brief details or null"
|
||||
}}
|
||||
],
|
||||
"medical_history": [],
|
||||
"medications": [],
|
||||
"allergies": [],
|
||||
"additional_information": "string or null",
|
||||
"medical_history": [
|
||||
{{
|
||||
"condition": "condition name",
|
||||
"duration": "duration or null",
|
||||
"status": "active/past or null"
|
||||
}}
|
||||
],
|
||||
"medications": [
|
||||
{{
|
||||
"name": "medication name",
|
||||
"dosage": "dosage or null",
|
||||
"frequency": "frequency or null",
|
||||
"duration": "duration or null"
|
||||
}}
|
||||
],
|
||||
"allergies": [
|
||||
{{
|
||||
"name": "allergen name",
|
||||
"type": "drug/food/etc or null",
|
||||
"reaction": "reaction or null"
|
||||
}}
|
||||
],
|
||||
"surgical_history": [],
|
||||
"previous_episodes": [],
|
||||
"family_history": [],
|
||||
"dietary_habits": null,
|
||||
"additional_information": "any functional impact, previous episodes, or additional notes",
|
||||
"language": "{session.language}",
|
||||
"onboarding_completed": true
|
||||
}}
|
||||
@@ -78,7 +105,7 @@ Return ONLY JSON conforming to this exact structure:
|
||||
|
||||
from app.config import GEMINI_API_KEY, GEMINI_MODEL, ANTHROPIC_API_KEY, ANTHROPIC_MODEL
|
||||
|
||||
# Primary: Google Gemini extraction (Ultra-fast ~1s)
|
||||
# Primary: Google Gemini extraction
|
||||
if GEMINI_API_KEY and GEMINI_API_KEY.strip() not in ["your_gemini_key", "your_gemini_api_key", ""]:
|
||||
try:
|
||||
import asyncio
|
||||
@@ -136,7 +163,7 @@ Return ONLY JSON conforming to this exact structure:
|
||||
except Exception as e:
|
||||
print(f"[Claude Result Extraction Error]: {e}")
|
||||
|
||||
# Fallback simulator from state (strictly without fake dummy strings)
|
||||
# Fallback structured builder from state
|
||||
chief_complaint = current_state.get("reason_for_visit")
|
||||
if isinstance(chief_complaint, dict):
|
||||
chief_complaint = chief_complaint.get("value")
|
||||
@@ -157,6 +184,11 @@ Return ONLY JSON conforming to this exact structure:
|
||||
history_raw = current_state.get("medical_history")
|
||||
history_list = history_raw.get("items", []) if isinstance(history_raw, dict) else (history_raw or [])
|
||||
|
||||
surgical_history = current_state.get("surgical_history", [])
|
||||
previous_episodes = current_state.get("previous_episodes", [])
|
||||
family_history = current_state.get("family_history", [])
|
||||
add_info = current_state.get("additional_information")
|
||||
|
||||
fallback_result = {
|
||||
"patient_id": session.patient_id,
|
||||
"category": {
|
||||
@@ -169,7 +201,10 @@ Return ONLY JSON conforming to this exact structure:
|
||||
"medical_history": history_list,
|
||||
"medications": meds_list,
|
||||
"allergies": allergies_list,
|
||||
"additional_information": None,
|
||||
"surgical_history": surgical_history if isinstance(surgical_history, list) else [],
|
||||
"previous_episodes": previous_episodes if isinstance(previous_episodes, list) else [],
|
||||
"family_history": family_history if isinstance(family_history, list) else [],
|
||||
"additional_information": add_info,
|
||||
"language": session.language,
|
||||
"onboarding_completed": True,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user