import sys import os import datetime import io # Force UTF-8 for stdout sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') # Add src to path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'services/ai-service/src'))) from ai_med_extract.agents.patient_summary_agent import PatientSummarizerAgent # Mock Data patient_data = { "result": { "patientname": "John Doe", "patientnumber": "MRN-12345", "agey": "65", "gender": "Male", "allergies": ["Penicillin", "Peanuts"], "social_history": "Smokes 1 pack/day. Lives alone.", "past_medical_history": ["Hypertension", "Type 2 Diabetes"], "encounters": [ { "visit_date": "2023-10-01", "chief_complaint": "Chest pain", "diagnosis": ["Angina Pectoris", "Hypertension"], "vitals": {"BP": "140/90", "HR": "88"}, "medications": ["Aspirin", "Metoprolol"], "dr_notes": "Patient reports chest pain on exertion." }, { "visit_date": "2023-10-15", "chief_complaint": "Shortness of breath", "diagnosis": ["Acute Kidney Injury", "Heart Failure"], "vitals": {"BP": "130/85", "HR": "92"}, "medications": ["Lisinopril", "Furosemide"], "dr_notes": "Creatinine elevated. Holding Lisinopril." } ] } } # Mock LLM Output (simulating the new dashboard prompt) mock_llm_output = """ ## šŸ‘¤ Clinical Snapshot - **Patient Status**: Deteriorating - **Primary Issue**: Acute Kidney Injury overlaid on Heart Failure - **Critical Alerts**: > āš ļø **Acute Kidney Injury** - Creatinine rising, Lisinopril held. ## šŸ“‰ Longitudinal Trends & Key Findings | Date | Encounter | Key Vitals/Labs | Net Trend | |------|-----------|-----------------|-----------| | 2023-10-15 | Follow-up | BP 130/85, Cr Elevated | šŸ”“ Worsening Renal Function | | 2023-10-01 | Initial | BP 140/90 | 🟔 Uncontrolled HTN | ## šŸ’Š Active Medications & Treatments | Medication | Dosage | Indication | Status | |------------|--------|------------|--------| | Furosemide | 40mg | Heart Failure | āœ… Active | | Lisinopril | 10mg | Hypertension | šŸ›‘ HELD (AKI) | ## 🧠 Assessment & Plan - **Assessment**: 65M with Hx HTN/DM2 presenting with decompensated HF and new AKI. - **Recommended Next Steps**: - [ ] Monitor renal function daily - [ ] cardiology consult """ # Test Formatting agent = PatientSummarizerAgent() formatted_output = agent.format_clinical_output(mock_llm_output, patient_data) evaluation = agent.evaluate_summary_against_guidelines(mock_llm_output, patient_data) final_output = ( f"{formatted_output}\n\n" f"---\n" f"## šŸ“Š SIMULATED EVALUATION REPORT\n" f"{evaluation}" ) print(final_output) # Verify no ASCII art separators which were removed assert "===========" not in final_output assert "--- PATIENT OVERVIEW ---" not in final_output assert "# šŸ„ CLINICAL SUMMARY REPORT" in final_output assert "> āš ļø **Critical New Diagnoses:** Acute Kidney Injury" in final_output print("\nāœ… Verification Successful: Output is in Dashboard Markdown format.")