empathy-framework 4.6.6__py3-none-any.whl → 4.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/METADATA +7 -6
- empathy_framework-4.7.0.dist-info/RECORD +354 -0
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/top_level.txt +0 -2
- empathy_healthcare_plugin/monitors/monitoring/__init__.py +9 -9
- empathy_llm_toolkit/agent_factory/__init__.py +6 -6
- empathy_llm_toolkit/agent_factory/adapters/wizard_adapter.py +7 -10
- empathy_llm_toolkit/agents_md/__init__.py +22 -0
- empathy_llm_toolkit/agents_md/loader.py +218 -0
- empathy_llm_toolkit/agents_md/parser.py +271 -0
- empathy_llm_toolkit/agents_md/registry.py +307 -0
- empathy_llm_toolkit/commands/__init__.py +51 -0
- empathy_llm_toolkit/commands/context.py +375 -0
- empathy_llm_toolkit/commands/loader.py +301 -0
- empathy_llm_toolkit/commands/models.py +231 -0
- empathy_llm_toolkit/commands/parser.py +371 -0
- empathy_llm_toolkit/commands/registry.py +429 -0
- empathy_llm_toolkit/config/__init__.py +8 -8
- empathy_llm_toolkit/config/unified.py +3 -7
- empathy_llm_toolkit/context/__init__.py +22 -0
- empathy_llm_toolkit/context/compaction.py +455 -0
- empathy_llm_toolkit/context/manager.py +434 -0
- empathy_llm_toolkit/hooks/__init__.py +24 -0
- empathy_llm_toolkit/hooks/config.py +306 -0
- empathy_llm_toolkit/hooks/executor.py +289 -0
- empathy_llm_toolkit/hooks/registry.py +302 -0
- empathy_llm_toolkit/hooks/scripts/__init__.py +39 -0
- empathy_llm_toolkit/hooks/scripts/evaluate_session.py +201 -0
- empathy_llm_toolkit/hooks/scripts/first_time_init.py +285 -0
- empathy_llm_toolkit/hooks/scripts/pre_compact.py +207 -0
- empathy_llm_toolkit/hooks/scripts/session_end.py +183 -0
- empathy_llm_toolkit/hooks/scripts/session_start.py +163 -0
- empathy_llm_toolkit/hooks/scripts/suggest_compact.py +225 -0
- empathy_llm_toolkit/learning/__init__.py +30 -0
- empathy_llm_toolkit/learning/evaluator.py +438 -0
- empathy_llm_toolkit/learning/extractor.py +514 -0
- empathy_llm_toolkit/learning/storage.py +560 -0
- empathy_llm_toolkit/providers.py +4 -11
- empathy_llm_toolkit/security/__init__.py +17 -17
- empathy_llm_toolkit/utils/tokens.py +2 -5
- empathy_os/__init__.py +202 -70
- empathy_os/cache_monitor.py +5 -3
- empathy_os/cli/__init__.py +11 -55
- empathy_os/cli/__main__.py +29 -15
- empathy_os/cli/commands/inspection.py +21 -12
- empathy_os/cli/commands/memory.py +4 -12
- empathy_os/cli/commands/profiling.py +198 -0
- empathy_os/cli/commands/utilities.py +27 -7
- empathy_os/cli.py +28 -57
- empathy_os/cli_unified.py +525 -1164
- empathy_os/cost_tracker.py +9 -3
- empathy_os/dashboard/server.py +200 -2
- empathy_os/hot_reload/__init__.py +7 -7
- empathy_os/hot_reload/config.py +6 -7
- empathy_os/hot_reload/integration.py +35 -35
- empathy_os/hot_reload/reloader.py +57 -57
- empathy_os/hot_reload/watcher.py +28 -28
- empathy_os/hot_reload/websocket.py +2 -2
- empathy_os/memory/__init__.py +11 -4
- empathy_os/memory/claude_memory.py +1 -1
- empathy_os/memory/cross_session.py +8 -12
- empathy_os/memory/edges.py +6 -6
- empathy_os/memory/file_session.py +770 -0
- empathy_os/memory/graph.py +30 -30
- empathy_os/memory/nodes.py +6 -6
- empathy_os/memory/short_term.py +15 -9
- empathy_os/memory/unified.py +606 -140
- empathy_os/meta_workflows/agent_creator.py +3 -9
- empathy_os/meta_workflows/cli_meta_workflows.py +113 -53
- empathy_os/meta_workflows/form_engine.py +6 -18
- empathy_os/meta_workflows/intent_detector.py +64 -24
- empathy_os/meta_workflows/models.py +3 -1
- empathy_os/meta_workflows/pattern_learner.py +13 -31
- empathy_os/meta_workflows/plan_generator.py +55 -47
- empathy_os/meta_workflows/session_context.py +2 -3
- empathy_os/meta_workflows/workflow.py +20 -51
- empathy_os/models/cli.py +2 -2
- empathy_os/models/tasks.py +1 -2
- empathy_os/models/telemetry.py +4 -1
- empathy_os/models/token_estimator.py +3 -1
- empathy_os/monitoring/alerts.py +938 -9
- empathy_os/monitoring/alerts_cli.py +346 -183
- empathy_os/orchestration/execution_strategies.py +12 -29
- empathy_os/orchestration/pattern_learner.py +20 -26
- empathy_os/orchestration/real_tools.py +6 -15
- empathy_os/platform_utils.py +2 -1
- empathy_os/plugins/__init__.py +2 -2
- empathy_os/plugins/base.py +64 -64
- empathy_os/plugins/registry.py +32 -32
- empathy_os/project_index/index.py +49 -15
- empathy_os/project_index/models.py +1 -2
- empathy_os/project_index/reports.py +1 -1
- empathy_os/project_index/scanner.py +1 -0
- empathy_os/redis_memory.py +10 -7
- empathy_os/resilience/__init__.py +1 -1
- empathy_os/resilience/health.py +10 -10
- empathy_os/routing/__init__.py +7 -7
- empathy_os/routing/chain_executor.py +37 -37
- empathy_os/routing/classifier.py +36 -36
- empathy_os/routing/smart_router.py +40 -40
- empathy_os/routing/{wizard_registry.py → workflow_registry.py} +47 -47
- empathy_os/scaffolding/__init__.py +8 -8
- empathy_os/scaffolding/__main__.py +1 -1
- empathy_os/scaffolding/cli.py +28 -28
- empathy_os/socratic/__init__.py +3 -19
- empathy_os/socratic/ab_testing.py +25 -36
- empathy_os/socratic/blueprint.py +38 -38
- empathy_os/socratic/cli.py +34 -20
- empathy_os/socratic/collaboration.py +30 -28
- empathy_os/socratic/domain_templates.py +9 -1
- empathy_os/socratic/embeddings.py +17 -13
- empathy_os/socratic/engine.py +135 -70
- empathy_os/socratic/explainer.py +70 -60
- empathy_os/socratic/feedback.py +24 -19
- empathy_os/socratic/forms.py +15 -10
- empathy_os/socratic/generator.py +51 -35
- empathy_os/socratic/llm_analyzer.py +25 -23
- empathy_os/socratic/mcp_server.py +99 -159
- empathy_os/socratic/session.py +19 -13
- empathy_os/socratic/storage.py +98 -67
- empathy_os/socratic/success.py +38 -27
- empathy_os/socratic/visual_editor.py +51 -39
- empathy_os/socratic/web_ui.py +99 -66
- empathy_os/telemetry/cli.py +3 -1
- empathy_os/telemetry/usage_tracker.py +1 -3
- empathy_os/test_generator/__init__.py +3 -3
- empathy_os/test_generator/cli.py +28 -28
- empathy_os/test_generator/generator.py +64 -66
- empathy_os/test_generator/risk_analyzer.py +11 -11
- empathy_os/vscode_bridge.py +173 -0
- empathy_os/workflows/__init__.py +212 -120
- empathy_os/workflows/batch_processing.py +8 -24
- empathy_os/workflows/bug_predict.py +1 -1
- empathy_os/workflows/code_review.py +20 -5
- empathy_os/workflows/code_review_pipeline.py +13 -8
- empathy_os/workflows/keyboard_shortcuts/workflow.py +6 -2
- empathy_os/workflows/manage_documentation.py +1 -0
- empathy_os/workflows/orchestrated_health_check.py +6 -11
- empathy_os/workflows/orchestrated_release_prep.py +3 -3
- empathy_os/workflows/pr_review.py +18 -10
- empathy_os/workflows/progressive/__init__.py +2 -12
- empathy_os/workflows/progressive/cli.py +14 -37
- empathy_os/workflows/progressive/core.py +12 -12
- empathy_os/workflows/progressive/orchestrator.py +166 -144
- empathy_os/workflows/progressive/reports.py +22 -31
- empathy_os/workflows/progressive/telemetry.py +8 -14
- empathy_os/workflows/progressive/test_gen.py +29 -48
- empathy_os/workflows/progressive/workflow.py +31 -70
- empathy_os/workflows/release_prep.py +21 -6
- empathy_os/workflows/release_prep_crew.py +1 -0
- empathy_os/workflows/secure_release.py +13 -6
- empathy_os/workflows/security_audit.py +8 -3
- empathy_os/workflows/test_coverage_boost_crew.py +3 -2
- empathy_os/workflows/test_maintenance_crew.py +1 -0
- empathy_os/workflows/test_runner.py +16 -12
- empathy_software_plugin/SOFTWARE_PLUGIN_README.md +25 -703
- empathy_software_plugin/cli.py +0 -122
- coach_wizards/__init__.py +0 -45
- coach_wizards/accessibility_wizard.py +0 -91
- coach_wizards/api_wizard.py +0 -91
- coach_wizards/base_wizard.py +0 -209
- coach_wizards/cicd_wizard.py +0 -91
- coach_wizards/code_reviewer_README.md +0 -60
- coach_wizards/code_reviewer_wizard.py +0 -180
- coach_wizards/compliance_wizard.py +0 -91
- coach_wizards/database_wizard.py +0 -91
- coach_wizards/debugging_wizard.py +0 -91
- coach_wizards/documentation_wizard.py +0 -91
- coach_wizards/generate_wizards.py +0 -347
- coach_wizards/localization_wizard.py +0 -173
- coach_wizards/migration_wizard.py +0 -91
- coach_wizards/monitoring_wizard.py +0 -91
- coach_wizards/observability_wizard.py +0 -91
- coach_wizards/performance_wizard.py +0 -91
- coach_wizards/prompt_engineering_wizard.py +0 -661
- coach_wizards/refactoring_wizard.py +0 -91
- coach_wizards/scaling_wizard.py +0 -90
- coach_wizards/security_wizard.py +0 -92
- coach_wizards/testing_wizard.py +0 -91
- empathy_framework-4.6.6.dist-info/RECORD +0 -410
- empathy_llm_toolkit/wizards/__init__.py +0 -43
- empathy_llm_toolkit/wizards/base_wizard.py +0 -364
- empathy_llm_toolkit/wizards/customer_support_wizard.py +0 -190
- empathy_llm_toolkit/wizards/healthcare_wizard.py +0 -378
- empathy_llm_toolkit/wizards/patient_assessment_README.md +0 -64
- empathy_llm_toolkit/wizards/patient_assessment_wizard.py +0 -193
- empathy_llm_toolkit/wizards/technology_wizard.py +0 -209
- empathy_os/wizard_factory_cli.py +0 -170
- empathy_software_plugin/wizards/__init__.py +0 -42
- empathy_software_plugin/wizards/advanced_debugging_wizard.py +0 -395
- empathy_software_plugin/wizards/agent_orchestration_wizard.py +0 -511
- empathy_software_plugin/wizards/ai_collaboration_wizard.py +0 -503
- empathy_software_plugin/wizards/ai_context_wizard.py +0 -441
- empathy_software_plugin/wizards/ai_documentation_wizard.py +0 -503
- empathy_software_plugin/wizards/base_wizard.py +0 -288
- empathy_software_plugin/wizards/book_chapter_wizard.py +0 -519
- empathy_software_plugin/wizards/code_review_wizard.py +0 -604
- empathy_software_plugin/wizards/debugging/__init__.py +0 -50
- empathy_software_plugin/wizards/debugging/bug_risk_analyzer.py +0 -414
- empathy_software_plugin/wizards/debugging/config_loaders.py +0 -446
- empathy_software_plugin/wizards/debugging/fix_applier.py +0 -469
- empathy_software_plugin/wizards/debugging/language_patterns.py +0 -385
- empathy_software_plugin/wizards/debugging/linter_parsers.py +0 -470
- empathy_software_plugin/wizards/debugging/verification.py +0 -369
- empathy_software_plugin/wizards/enhanced_testing_wizard.py +0 -537
- empathy_software_plugin/wizards/memory_enhanced_debugging_wizard.py +0 -816
- empathy_software_plugin/wizards/multi_model_wizard.py +0 -501
- empathy_software_plugin/wizards/pattern_extraction_wizard.py +0 -422
- empathy_software_plugin/wizards/pattern_retriever_wizard.py +0 -400
- empathy_software_plugin/wizards/performance/__init__.py +0 -9
- empathy_software_plugin/wizards/performance/bottleneck_detector.py +0 -221
- empathy_software_plugin/wizards/performance/profiler_parsers.py +0 -278
- empathy_software_plugin/wizards/performance/trajectory_analyzer.py +0 -429
- empathy_software_plugin/wizards/performance_profiling_wizard.py +0 -305
- empathy_software_plugin/wizards/prompt_engineering_wizard.py +0 -425
- empathy_software_plugin/wizards/rag_pattern_wizard.py +0 -461
- empathy_software_plugin/wizards/security/__init__.py +0 -32
- empathy_software_plugin/wizards/security/exploit_analyzer.py +0 -290
- empathy_software_plugin/wizards/security/owasp_patterns.py +0 -241
- empathy_software_plugin/wizards/security/vulnerability_scanner.py +0 -604
- empathy_software_plugin/wizards/security_analysis_wizard.py +0 -322
- empathy_software_plugin/wizards/security_learning_wizard.py +0 -740
- empathy_software_plugin/wizards/tech_debt_wizard.py +0 -726
- empathy_software_plugin/wizards/testing/__init__.py +0 -27
- empathy_software_plugin/wizards/testing/coverage_analyzer.py +0 -459
- empathy_software_plugin/wizards/testing/quality_analyzer.py +0 -525
- empathy_software_plugin/wizards/testing/test_suggester.py +0 -533
- empathy_software_plugin/wizards/testing_wizard.py +0 -274
- wizards/__init__.py +0 -82
- wizards/admission_assessment_wizard.py +0 -644
- wizards/care_plan.py +0 -321
- wizards/clinical_assessment.py +0 -769
- wizards/discharge_planning.py +0 -77
- wizards/discharge_summary_wizard.py +0 -468
- wizards/dosage_calculation.py +0 -497
- wizards/incident_report_wizard.py +0 -454
- wizards/medication_reconciliation.py +0 -85
- wizards/nursing_assessment.py +0 -171
- wizards/patient_education.py +0 -654
- wizards/quality_improvement.py +0 -705
- wizards/sbar_report.py +0 -324
- wizards/sbar_wizard.py +0 -608
- wizards/shift_handoff_wizard.py +0 -535
- wizards/soap_note_wizard.py +0 -679
- wizards/treatment_plan.py +0 -15
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/WHEEL +0 -0
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/entry_points.txt +0 -0
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/licenses/LICENSE +0 -0
wizards/patient_education.py
DELETED
|
@@ -1,654 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Patient Education Wizard - AI Nurse Florence
|
|
3
|
-
Following Wizard Pattern Implementation from coding instructions
|
|
4
|
-
Educational content delivery system with AI-powered content generation and reading level adjustment
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import logging
|
|
8
|
-
from datetime import datetime
|
|
9
|
-
from typing import Any
|
|
10
|
-
from uuid import uuid4
|
|
11
|
-
|
|
12
|
-
from fastapi import APIRouter, HTTPException
|
|
13
|
-
from pydantic import BaseModel
|
|
14
|
-
|
|
15
|
-
from ...services.openai_client import create_openai_service
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger(__name__)
|
|
18
|
-
|
|
19
|
-
router = APIRouter(
|
|
20
|
-
prefix="/wizard/patient-education",
|
|
21
|
-
tags=["wizards", "patient-education"],
|
|
22
|
-
responses={
|
|
23
|
-
404: {"description": "Wizard session not found"},
|
|
24
|
-
422: {"description": "Invalid step data"},
|
|
25
|
-
},
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
# Wizard session storage (Redis in production)
|
|
29
|
-
_wizard_sessions: dict[str, dict[str, Any]] = {}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class EducationStepData(BaseModel):
|
|
33
|
-
"""Data model for education step submission."""
|
|
34
|
-
|
|
35
|
-
step_data: dict[str, Any]
|
|
36
|
-
comprehension_score: int | None = None
|
|
37
|
-
questions: list[str] | None = None
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@router.post("/start")
|
|
41
|
-
async def start_patient_education(topic: str = "general", patient_literacy_level: str = "standard"):
|
|
42
|
-
"""Start patient education wizard following Wizard Pattern Implementation."""
|
|
43
|
-
wizard_id = str(uuid4())
|
|
44
|
-
|
|
45
|
-
session_data = {
|
|
46
|
-
"wizard_id": wizard_id,
|
|
47
|
-
"wizard_type": "patient_education",
|
|
48
|
-
"created_at": datetime.now().isoformat(),
|
|
49
|
-
"current_step": 1,
|
|
50
|
-
"total_steps": 4,
|
|
51
|
-
"completed_steps": [],
|
|
52
|
-
"data": {
|
|
53
|
-
"topic": topic,
|
|
54
|
-
"literacy_level": patient_literacy_level,
|
|
55
|
-
"learning_objectives": [],
|
|
56
|
-
"content_delivered": [],
|
|
57
|
-
"comprehension_checks": [],
|
|
58
|
-
"follow_up_materials": [],
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
_wizard_sessions[wizard_id] = session_data
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
"wizard_id": wizard_id,
|
|
66
|
-
"wizard_type": "patient_education",
|
|
67
|
-
"current_step": 1,
|
|
68
|
-
"total_steps": 4,
|
|
69
|
-
"step_title": "Learning Assessment",
|
|
70
|
-
"step_description": "Assess patient's current knowledge and learning preferences",
|
|
71
|
-
"fields": [
|
|
72
|
-
{
|
|
73
|
-
"name": "current_knowledge_level",
|
|
74
|
-
"type": "select",
|
|
75
|
-
"options": [
|
|
76
|
-
"No knowledge",
|
|
77
|
-
"Some knowledge",
|
|
78
|
-
"Moderate knowledge",
|
|
79
|
-
"Good knowledge",
|
|
80
|
-
],
|
|
81
|
-
"required": True,
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"name": "preferred_learning_style",
|
|
85
|
-
"type": "select",
|
|
86
|
-
"options": ["Visual", "Auditory", "Reading/Writing", "Kinesthetic", "Mixed"],
|
|
87
|
-
"required": True,
|
|
88
|
-
},
|
|
89
|
-
{"name": "language_preference", "type": "text", "required": True},
|
|
90
|
-
{"name": "barriers_to_learning", "type": "textarea", "required": False},
|
|
91
|
-
{
|
|
92
|
-
"name": "support_system",
|
|
93
|
-
"type": "textarea",
|
|
94
|
-
"label": "Family/caregiver involvement",
|
|
95
|
-
"required": False,
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
"educational_note": "Tailor education to patient's literacy level, learning style, and cultural background.",
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
@router.get("/{wizard_id}/status")
|
|
103
|
-
async def get_patient_education_status(wizard_id: str):
|
|
104
|
-
"""Get patient education wizard status following Wizard Pattern Implementation."""
|
|
105
|
-
|
|
106
|
-
if wizard_id not in _wizard_sessions:
|
|
107
|
-
raise HTTPException(status_code=404, detail="Wizard session not found")
|
|
108
|
-
|
|
109
|
-
session = _wizard_sessions[wizard_id]
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
"wizard_id": wizard_id,
|
|
113
|
-
"wizard_type": session["wizard_type"],
|
|
114
|
-
"current_step": session["current_step"],
|
|
115
|
-
"total_steps": session["total_steps"],
|
|
116
|
-
"completed_steps": session["completed_steps"],
|
|
117
|
-
"progress": len(session["completed_steps"]) / session["total_steps"] * 100,
|
|
118
|
-
"status": (
|
|
119
|
-
"completed"
|
|
120
|
-
if len(session["completed_steps"]) == session["total_steps"]
|
|
121
|
-
else "in_progress"
|
|
122
|
-
),
|
|
123
|
-
"data": session["data"],
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
@router.post("/{wizard_id}/step/{step_number}")
|
|
128
|
-
async def submit_patient_education_step(
|
|
129
|
-
wizard_id: str, step_number: int, step_data: EducationStepData
|
|
130
|
-
):
|
|
131
|
-
"""Submit patient education step data following Wizard Pattern Implementation."""
|
|
132
|
-
|
|
133
|
-
if wizard_id not in _wizard_sessions:
|
|
134
|
-
raise HTTPException(status_code=404, detail="Wizard session not found")
|
|
135
|
-
|
|
136
|
-
session = _wizard_sessions[wizard_id]
|
|
137
|
-
|
|
138
|
-
if step_number != session["current_step"]:
|
|
139
|
-
raise HTTPException(
|
|
140
|
-
status_code=422,
|
|
141
|
-
detail=f"Invalid step. Expected step {session['current_step']}, got step {step_number}",
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
# Store step data based on step number
|
|
145
|
-
step_mapping = {
|
|
146
|
-
1: "learning_assessment",
|
|
147
|
-
2: "content_delivery",
|
|
148
|
-
3: "comprehension_check",
|
|
149
|
-
4: "follow_up_plan",
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if step_number in step_mapping:
|
|
153
|
-
session["data"][step_mapping[step_number]] = step_data.step_data
|
|
154
|
-
|
|
155
|
-
# Track comprehension scores if provided
|
|
156
|
-
if step_data.comprehension_score is not None:
|
|
157
|
-
session["data"]["comprehension_checks"].append(
|
|
158
|
-
{
|
|
159
|
-
"step": step_number,
|
|
160
|
-
"score": step_data.comprehension_score,
|
|
161
|
-
"timestamp": datetime.now().isoformat(),
|
|
162
|
-
}
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
# Track questions if provided
|
|
166
|
-
if step_data.questions:
|
|
167
|
-
if "patient_questions" not in session["data"]:
|
|
168
|
-
session["data"]["patient_questions"] = []
|
|
169
|
-
session["data"]["patient_questions"].extend(step_data.questions)
|
|
170
|
-
|
|
171
|
-
# Mark step as completed
|
|
172
|
-
if step_number not in session["completed_steps"]:
|
|
173
|
-
session["completed_steps"].append(step_number)
|
|
174
|
-
|
|
175
|
-
# Generate AI-powered educational content after step 1 (learning assessment)
|
|
176
|
-
ai_content = None
|
|
177
|
-
if step_number == 1:
|
|
178
|
-
ai_content = await _generate_personalized_content(
|
|
179
|
-
topic=session["data"]["topic"],
|
|
180
|
-
literacy_level=session["data"]["literacy_level"],
|
|
181
|
-
learning_style=step_data.step_data.get("preferred_learning_style", "Mixed"),
|
|
182
|
-
current_knowledge=step_data.step_data.get("current_knowledge_level", "No knowledge"),
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
# Generate comprehension quiz after step 2 (content delivery)
|
|
186
|
-
ai_quiz = None
|
|
187
|
-
if step_number == 2:
|
|
188
|
-
ai_quiz = await _generate_comprehension_quiz(
|
|
189
|
-
topic=session["data"]["topic"],
|
|
190
|
-
literacy_level=session["data"]["literacy_level"],
|
|
191
|
-
content_covered=step_data.step_data.get("key_concepts_covered", ""),
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
# Move to next step
|
|
195
|
-
if step_number < session["total_steps"]:
|
|
196
|
-
session["current_step"] = step_number + 1
|
|
197
|
-
next_step_info = _get_step_info(step_number + 1, session["data"]["topic"])
|
|
198
|
-
else:
|
|
199
|
-
next_step_info = None
|
|
200
|
-
|
|
201
|
-
response = {
|
|
202
|
-
"wizard_id": wizard_id,
|
|
203
|
-
"step_completed": step_number,
|
|
204
|
-
"current_step": session["current_step"],
|
|
205
|
-
"total_steps": session["total_steps"],
|
|
206
|
-
"progress": len(session["completed_steps"]) / session["total_steps"] * 100,
|
|
207
|
-
"status": (
|
|
208
|
-
"completed"
|
|
209
|
-
if len(session["completed_steps"]) == session["total_steps"]
|
|
210
|
-
else "in_progress"
|
|
211
|
-
),
|
|
212
|
-
"next_step": next_step_info,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
# Add AI-generated content to response if available
|
|
216
|
-
if ai_content:
|
|
217
|
-
response["ai_generated_content"] = ai_content
|
|
218
|
-
if ai_quiz:
|
|
219
|
-
response["ai_generated_quiz"] = ai_quiz
|
|
220
|
-
|
|
221
|
-
return response
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
@router.get("/{wizard_id}/step/{step_number}")
|
|
225
|
-
async def get_patient_education_step(wizard_id: str, step_number: int):
|
|
226
|
-
"""Get patient education step information."""
|
|
227
|
-
|
|
228
|
-
if wizard_id not in _wizard_sessions:
|
|
229
|
-
raise HTTPException(status_code=404, detail="Wizard session not found")
|
|
230
|
-
|
|
231
|
-
session = _wizard_sessions[wizard_id]
|
|
232
|
-
|
|
233
|
-
if step_number < 1 or step_number > session["total_steps"]:
|
|
234
|
-
raise HTTPException(status_code=422, detail="Invalid step number")
|
|
235
|
-
|
|
236
|
-
step_info = _get_step_info(step_number, session["data"]["topic"])
|
|
237
|
-
|
|
238
|
-
# Get previously entered data if exists
|
|
239
|
-
step_mapping = {
|
|
240
|
-
1: "learning_assessment",
|
|
241
|
-
2: "content_delivery",
|
|
242
|
-
3: "comprehension_check",
|
|
243
|
-
4: "follow_up_plan",
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
existing_data = session["data"].get(step_mapping.get(step_number, ""), {})
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
"wizard_id": wizard_id,
|
|
250
|
-
"step_number": step_number,
|
|
251
|
-
"existing_data": existing_data,
|
|
252
|
-
**step_info,
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
@router.get("/{wizard_id}/materials")
|
|
257
|
-
async def get_education_materials(wizard_id: str):
|
|
258
|
-
"""Get recommended educational materials based on topic and learning style."""
|
|
259
|
-
|
|
260
|
-
if wizard_id not in _wizard_sessions:
|
|
261
|
-
raise HTTPException(status_code=404, detail="Wizard session not found")
|
|
262
|
-
|
|
263
|
-
session = _wizard_sessions[wizard_id]
|
|
264
|
-
topic = session["data"].get("topic", "general")
|
|
265
|
-
learning_style = (
|
|
266
|
-
session["data"].get("learning_assessment", {}).get("preferred_learning_style", "Mixed")
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
# Generate material recommendations based on topic and learning style
|
|
270
|
-
materials = _generate_educational_materials(topic, learning_style)
|
|
271
|
-
|
|
272
|
-
return {
|
|
273
|
-
"wizard_id": wizard_id,
|
|
274
|
-
"topic": topic,
|
|
275
|
-
"learning_style": learning_style,
|
|
276
|
-
"materials": materials,
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
@router.delete("/{wizard_id}")
|
|
281
|
-
async def cancel_patient_education(wizard_id: str):
|
|
282
|
-
"""Cancel and delete patient education wizard session."""
|
|
283
|
-
|
|
284
|
-
if wizard_id not in _wizard_sessions:
|
|
285
|
-
raise HTTPException(status_code=404, detail="Wizard session not found")
|
|
286
|
-
|
|
287
|
-
del _wizard_sessions[wizard_id]
|
|
288
|
-
|
|
289
|
-
return {"message": "Patient education wizard session cancelled", "wizard_id": wizard_id}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
def _get_step_info(step_number: int, topic: str = "general") -> dict[str, Any]:
|
|
293
|
-
"""Get step configuration information."""
|
|
294
|
-
|
|
295
|
-
steps = {
|
|
296
|
-
1: {
|
|
297
|
-
"step_title": "Learning Assessment",
|
|
298
|
-
"step_description": "Assess patient's current knowledge and learning preferences",
|
|
299
|
-
"fields": [
|
|
300
|
-
{
|
|
301
|
-
"name": "current_knowledge_level",
|
|
302
|
-
"type": "select",
|
|
303
|
-
"options": [
|
|
304
|
-
"No knowledge",
|
|
305
|
-
"Some knowledge",
|
|
306
|
-
"Moderate knowledge",
|
|
307
|
-
"Good knowledge",
|
|
308
|
-
],
|
|
309
|
-
"required": True,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
"name": "preferred_learning_style",
|
|
313
|
-
"type": "select",
|
|
314
|
-
"options": ["Visual", "Auditory", "Reading/Writing", "Kinesthetic", "Mixed"],
|
|
315
|
-
"required": True,
|
|
316
|
-
},
|
|
317
|
-
{"name": "language_preference", "type": "text", "required": True},
|
|
318
|
-
{"name": "barriers_to_learning", "type": "textarea", "required": False},
|
|
319
|
-
{
|
|
320
|
-
"name": "support_system",
|
|
321
|
-
"type": "textarea",
|
|
322
|
-
"label": "Family/caregiver involvement",
|
|
323
|
-
"required": False,
|
|
324
|
-
},
|
|
325
|
-
],
|
|
326
|
-
"educational_note": "Tailor education to patient's literacy level, learning style, and cultural background.",
|
|
327
|
-
},
|
|
328
|
-
2: {
|
|
329
|
-
"step_title": "Content Delivery",
|
|
330
|
-
"step_description": f"Deliver educational content about {topic}",
|
|
331
|
-
"fields": [
|
|
332
|
-
{"name": "key_concepts_covered", "type": "textarea", "required": True},
|
|
333
|
-
{"name": "demonstrations_provided", "type": "textarea", "required": False},
|
|
334
|
-
{
|
|
335
|
-
"name": "materials_given",
|
|
336
|
-
"type": "textarea",
|
|
337
|
-
"label": "Written materials provided",
|
|
338
|
-
"required": True,
|
|
339
|
-
},
|
|
340
|
-
{"name": "visual_aids_used", "type": "textarea", "required": False},
|
|
341
|
-
{
|
|
342
|
-
"name": "patient_engagement",
|
|
343
|
-
"type": "select",
|
|
344
|
-
"options": ["Excellent", "Good", "Fair", "Poor"],
|
|
345
|
-
"required": True,
|
|
346
|
-
},
|
|
347
|
-
{"name": "time_spent", "type": "number", "unit": "minutes", "required": True},
|
|
348
|
-
],
|
|
349
|
-
"educational_note": "Use teach-back method to ensure comprehension. Provide materials at appropriate literacy level.",
|
|
350
|
-
},
|
|
351
|
-
3: {
|
|
352
|
-
"step_title": "Comprehension Check",
|
|
353
|
-
"step_description": "Verify patient understanding using teach-back method",
|
|
354
|
-
"fields": [
|
|
355
|
-
{
|
|
356
|
-
"name": "teach_back_response",
|
|
357
|
-
"type": "textarea",
|
|
358
|
-
"label": "Patient's explanation in own words",
|
|
359
|
-
"required": True,
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
"name": "comprehension_score",
|
|
363
|
-
"type": "number",
|
|
364
|
-
"min": 0,
|
|
365
|
-
"max": 100,
|
|
366
|
-
"unit": "%",
|
|
367
|
-
"required": True,
|
|
368
|
-
},
|
|
369
|
-
{"name": "areas_of_confusion", "type": "textarea", "required": False},
|
|
370
|
-
{"name": "additional_questions", "type": "textarea", "required": False},
|
|
371
|
-
{
|
|
372
|
-
"name": "demonstration_accuracy",
|
|
373
|
-
"type": "select",
|
|
374
|
-
"label": "Return demonstration accuracy",
|
|
375
|
-
"options": [
|
|
376
|
-
"Accurate",
|
|
377
|
-
"Mostly accurate",
|
|
378
|
-
"Needs improvement",
|
|
379
|
-
"Unable to demonstrate",
|
|
380
|
-
],
|
|
381
|
-
"required": False,
|
|
382
|
-
},
|
|
383
|
-
],
|
|
384
|
-
"educational_note": "Use teach-back method: 'To make sure I explained clearly, can you tell me in your own words...'",
|
|
385
|
-
},
|
|
386
|
-
4: {
|
|
387
|
-
"step_title": "Follow-up Plan",
|
|
388
|
-
"step_description": "Establish follow-up education and support plan",
|
|
389
|
-
"fields": [
|
|
390
|
-
{
|
|
391
|
-
"name": "reinforcement_needed",
|
|
392
|
-
"type": "select",
|
|
393
|
-
"options": ["None", "Minimal", "Moderate", "Extensive"],
|
|
394
|
-
"required": True,
|
|
395
|
-
},
|
|
396
|
-
{"name": "follow_up_date", "type": "date", "required": True},
|
|
397
|
-
{"name": "topics_to_review", "type": "textarea", "required": False},
|
|
398
|
-
{
|
|
399
|
-
"name": "support_resources",
|
|
400
|
-
"type": "textarea",
|
|
401
|
-
"label": "Community resources provided",
|
|
402
|
-
"required": True,
|
|
403
|
-
},
|
|
404
|
-
{
|
|
405
|
-
"name": "contact_information",
|
|
406
|
-
"type": "textarea",
|
|
407
|
-
"label": "Contact info for questions",
|
|
408
|
-
"required": True,
|
|
409
|
-
},
|
|
410
|
-
{"name": "documentation_completed", "type": "boolean", "required": True},
|
|
411
|
-
],
|
|
412
|
-
"educational_note": "Provide written discharge instructions and emergency contact information.",
|
|
413
|
-
},
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return steps.get(step_number, {})
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
def _generate_educational_materials(topic: str, learning_style: str) -> list[dict[str, Any]]:
|
|
420
|
-
"""Generate recommended educational materials based on topic and learning style."""
|
|
421
|
-
|
|
422
|
-
# Base materials available for all topics
|
|
423
|
-
materials = []
|
|
424
|
-
|
|
425
|
-
if learning_style in ["Visual", "Mixed"]:
|
|
426
|
-
materials.append(
|
|
427
|
-
{
|
|
428
|
-
"type": "video",
|
|
429
|
-
"title": f"Understanding {topic.title()}",
|
|
430
|
-
"description": "Visual guide with animations and graphics",
|
|
431
|
-
"duration": "5-10 minutes",
|
|
432
|
-
"language": "English with subtitles available",
|
|
433
|
-
}
|
|
434
|
-
)
|
|
435
|
-
materials.append(
|
|
436
|
-
{
|
|
437
|
-
"type": "infographic",
|
|
438
|
-
"title": f"{topic.title()} Quick Reference",
|
|
439
|
-
"description": "One-page visual summary with key information",
|
|
440
|
-
"format": "PDF, printable",
|
|
441
|
-
}
|
|
442
|
-
)
|
|
443
|
-
|
|
444
|
-
if learning_style in ["Reading/Writing", "Mixed"]:
|
|
445
|
-
materials.append(
|
|
446
|
-
{
|
|
447
|
-
"type": "handout",
|
|
448
|
-
"title": f"Patient Guide to {topic.title()}",
|
|
449
|
-
"description": "Comprehensive written guide at 6th grade reading level",
|
|
450
|
-
"format": "PDF, available in multiple languages",
|
|
451
|
-
}
|
|
452
|
-
)
|
|
453
|
-
materials.append(
|
|
454
|
-
{
|
|
455
|
-
"type": "worksheet",
|
|
456
|
-
"title": f"My {topic.title()} Action Plan",
|
|
457
|
-
"description": "Fill-in worksheet for personal care planning",
|
|
458
|
-
"format": "Printable PDF",
|
|
459
|
-
}
|
|
460
|
-
)
|
|
461
|
-
|
|
462
|
-
if learning_style in ["Auditory", "Mixed"]:
|
|
463
|
-
materials.append(
|
|
464
|
-
{
|
|
465
|
-
"type": "audio",
|
|
466
|
-
"title": f"{topic.title()} Audio Guide",
|
|
467
|
-
"description": "Narrated guide covering key concepts",
|
|
468
|
-
"duration": "10-15 minutes",
|
|
469
|
-
"format": "MP3, downloadable",
|
|
470
|
-
}
|
|
471
|
-
)
|
|
472
|
-
|
|
473
|
-
if learning_style in ["Kinesthetic", "Mixed"]:
|
|
474
|
-
materials.append(
|
|
475
|
-
{
|
|
476
|
-
"type": "demonstration",
|
|
477
|
-
"title": f"{topic.title()} Skills Practice",
|
|
478
|
-
"description": "Hands-on practice session with return demonstration",
|
|
479
|
-
"duration": "15-20 minutes",
|
|
480
|
-
"supplies_needed": "Provided by nursing staff",
|
|
481
|
-
}
|
|
482
|
-
)
|
|
483
|
-
|
|
484
|
-
# Add web resources for all
|
|
485
|
-
materials.append(
|
|
486
|
-
{
|
|
487
|
-
"type": "website",
|
|
488
|
-
"title": "MedlinePlus Patient Education",
|
|
489
|
-
"url": "https://medlineplus.gov",
|
|
490
|
-
"description": "Reliable health information from NIH",
|
|
491
|
-
"note": "Search for your specific condition",
|
|
492
|
-
}
|
|
493
|
-
)
|
|
494
|
-
|
|
495
|
-
return materials
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
async def _generate_personalized_content(
|
|
499
|
-
topic: str, literacy_level: str, learning_style: str, current_knowledge: str
|
|
500
|
-
) -> dict[str, Any]:
|
|
501
|
-
"""
|
|
502
|
-
Generate AI-powered personalized educational content with reading level adjustment.
|
|
503
|
-
|
|
504
|
-
This is the key feature for patient education - AI generates content at the appropriate
|
|
505
|
-
reading level (5th grade, 8th grade, high school, college) based on patient literacy.
|
|
506
|
-
"""
|
|
507
|
-
|
|
508
|
-
# Map literacy levels to reading grades
|
|
509
|
-
literacy_map = {
|
|
510
|
-
"low": "5th grade",
|
|
511
|
-
"standard": "8th grade",
|
|
512
|
-
"high": "high school",
|
|
513
|
-
"advanced": "college",
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
reading_level = literacy_map.get(literacy_level, "8th grade")
|
|
517
|
-
|
|
518
|
-
try:
|
|
519
|
-
service = create_openai_service()
|
|
520
|
-
|
|
521
|
-
if not service:
|
|
522
|
-
return _fallback_educational_content(topic, reading_level)
|
|
523
|
-
|
|
524
|
-
# Create personalized educational content prompt with reading level specification
|
|
525
|
-
prompt = f"""Generate patient education content about {topic} with the following requirements:
|
|
526
|
-
|
|
527
|
-
CRITICAL: Write at a {reading_level} reading level. Use simple words, short sentences, and clear explanations appropriate for {reading_level} literacy.
|
|
528
|
-
|
|
529
|
-
Patient Profile:
|
|
530
|
-
- Current Knowledge: {current_knowledge}
|
|
531
|
-
- Learning Style: {learning_style}
|
|
532
|
-
- Reading Level: {reading_level}
|
|
533
|
-
|
|
534
|
-
Please provide:
|
|
535
|
-
1. Introduction (2-3 simple sentences explaining what {topic} is)
|
|
536
|
-
2. Key Facts (5-7 important points at {reading_level} level)
|
|
537
|
-
3. What to Expect (daily life impacts, explained simply)
|
|
538
|
-
4. Warning Signs (when to call the doctor, in clear language)
|
|
539
|
-
5. Self-Care Tips (practical actions the patient can take)
|
|
540
|
-
|
|
541
|
-
Remember:
|
|
542
|
-
- Use {reading_level} vocabulary and sentence structure
|
|
543
|
-
- Avoid medical jargon or explain it in simple terms
|
|
544
|
-
- Use active voice and direct language
|
|
545
|
-
- Break complex ideas into simple steps
|
|
546
|
-
- Include encouraging, supportive tone
|
|
547
|
-
|
|
548
|
-
Format with clear headings and short paragraphs for easy reading."""
|
|
549
|
-
|
|
550
|
-
ai_response = await service.generate_response(
|
|
551
|
-
prompt=prompt,
|
|
552
|
-
context=f"Patient education at {reading_level} reading level for {learning_style} learner",
|
|
553
|
-
)
|
|
554
|
-
|
|
555
|
-
return {
|
|
556
|
-
"content_available": True,
|
|
557
|
-
"reading_level": reading_level,
|
|
558
|
-
"educational_content": ai_response.get("response", ""),
|
|
559
|
-
"learning_style_adapted": learning_style,
|
|
560
|
-
"ai_model": ai_response.get("model", "gpt-4"),
|
|
561
|
-
"service_status": ai_response.get("service_status", "available"),
|
|
562
|
-
"customization_note": f"Content adapted to {reading_level} reading level and {learning_style} learning style",
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
except Exception as e:
|
|
566
|
-
logger.error(f"AI content generation failed: {e}")
|
|
567
|
-
return _fallback_educational_content(topic, reading_level)
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
async def _generate_comprehension_quiz(
|
|
571
|
-
topic: str, literacy_level: str, content_covered: str
|
|
572
|
-
) -> dict[str, Any]:
|
|
573
|
-
"""
|
|
574
|
-
Generate AI-powered comprehension quiz questions based on content delivered.
|
|
575
|
-
Questions are adjusted to patient's literacy level for accurate assessment.
|
|
576
|
-
"""
|
|
577
|
-
|
|
578
|
-
literacy_map = {
|
|
579
|
-
"low": "5th grade",
|
|
580
|
-
"standard": "8th grade",
|
|
581
|
-
"high": "high school",
|
|
582
|
-
"advanced": "college",
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
reading_level = literacy_map.get(literacy_level, "8th grade")
|
|
586
|
-
|
|
587
|
-
try:
|
|
588
|
-
service = create_openai_service()
|
|
589
|
-
|
|
590
|
-
if not service:
|
|
591
|
-
return _fallback_quiz(topic, reading_level)
|
|
592
|
-
|
|
593
|
-
prompt = f"""Create a comprehension quiz about {topic} to verify patient understanding.
|
|
594
|
-
|
|
595
|
-
Content that was taught:
|
|
596
|
-
{content_covered}
|
|
597
|
-
|
|
598
|
-
Requirements:
|
|
599
|
-
- Write questions at {reading_level} reading level
|
|
600
|
-
- Use simple, clear language
|
|
601
|
-
- Create 5 multiple-choice questions
|
|
602
|
-
- Include 1 scenario-based question asking "What would you do if..."
|
|
603
|
-
- Provide correct answers with brief explanations
|
|
604
|
-
|
|
605
|
-
Format as:
|
|
606
|
-
Question 1: [question text]
|
|
607
|
-
A) [option]
|
|
608
|
-
B) [option]
|
|
609
|
-
C) [option]
|
|
610
|
-
D) [option]
|
|
611
|
-
Correct Answer: [letter] - [brief explanation]
|
|
612
|
-
|
|
613
|
-
Make questions practical and relevant to daily life."""
|
|
614
|
-
|
|
615
|
-
ai_response = await service.generate_response(
|
|
616
|
-
prompt=prompt, context=f"Comprehension quiz at {reading_level} level"
|
|
617
|
-
)
|
|
618
|
-
|
|
619
|
-
return {
|
|
620
|
-
"quiz_available": True,
|
|
621
|
-
"reading_level": reading_level,
|
|
622
|
-
"quiz_questions": ai_response.get("response", ""),
|
|
623
|
-
"question_count": 5,
|
|
624
|
-
"ai_model": ai_response.get("model", "gpt-4"),
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
except Exception as e:
|
|
628
|
-
logger.error(f"AI quiz generation failed: {e}")
|
|
629
|
-
return _fallback_quiz(topic, reading_level)
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
def _fallback_educational_content(topic: str, reading_level: str) -> dict[str, Any]:
|
|
633
|
-
"""Fallback educational content when AI is unavailable."""
|
|
634
|
-
return {
|
|
635
|
-
"content_available": False,
|
|
636
|
-
"reading_level": reading_level,
|
|
637
|
-
"message": "AI content generation temporarily unavailable",
|
|
638
|
-
"fallback_note": f"Use standard {topic} patient education materials at {reading_level} level from approved resources",
|
|
639
|
-
"recommended_resources": [
|
|
640
|
-
"MedlinePlus patient education materials (medlineplus.gov)",
|
|
641
|
-
"CDC patient fact sheets (cdc.gov)",
|
|
642
|
-
"Hospital-approved patient education library",
|
|
643
|
-
],
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
def _fallback_quiz(topic: str, reading_level: str) -> dict[str, Any]:
|
|
648
|
-
"""Fallback quiz when AI is unavailable."""
|
|
649
|
-
return {
|
|
650
|
-
"quiz_available": False,
|
|
651
|
-
"reading_level": reading_level,
|
|
652
|
-
"message": "AI quiz generation temporarily unavailable",
|
|
653
|
-
"fallback_note": "Use teach-back method to assess comprehension: 'Can you tell me in your own words what we discussed about {topic}?'",
|
|
654
|
-
}
|