"""Handle clinical notes queries."""
import json
from typing import Optional
from ..data import PatientDataLoader
def handle_list_clinical_notes(
patient_id: str,
loader: PatientDataLoader,
note_type: Optional[str] = None
) -> str:
"""List clinical notes (summary with IDs, types, and dates only)."""
if not loader.patient_exists(patient_id):
return json.dumps({"error": f"Patient {patient_id} not found"})
notes = loader.get_clinical_notes(patient_id, note_type=note_type)
summary = [
{
"id": note.id,
"date": str(note.date),
"type": note.type,
"provider": note.provider,
"summary": note.summary
}
for note in notes
]
return json.dumps(summary, indent=2)
def handle_get_clinical_note_details(patient_id: str, note_id: str, loader: PatientDataLoader) -> str:
"""Get detailed information for a specific clinical note."""
if not loader.patient_exists(patient_id):
return json.dumps({"error": f"Patient {patient_id} not found"})
notes = loader.get_clinical_notes(patient_id)
for note in notes:
if note.id == note_id:
return json.dumps(note.model_dump(mode='json'), indent=2, default=str)
return json.dumps({"error": f"Clinical note {note_id} not found for patient {patient_id}"})