Skip to main content
Glama

FastMCP Server Template

by rdwj
analyze_patient_50.py8.59 kB
#!/usr/bin/env python3 """ Analyze Patient 50's DeviceRequests with FDA Verification Agent """ import asyncio import json import sys from pathlib import Path # Add parent directory to path sys.path.append(str(Path(__file__).parent)) from agents.fda_verification_agent import FDAVerificationAgent # Patient 50's DeviceRequest resources from HAPI FHIR DEVICE_REQUESTS = [ { "name": "DeviceRequest 1: Digital Hearing Aid (Generic)", "resource": { "resourceType": "DeviceRequest", "id": "device-request-de00881a-69db-45fe-bc5e-26d3b8e7b54b", "status": "active", "intent": "order", "codeCodeableConcept": { "coding": [{ "system": "http://snomed.info/sct", "code": "43252007", "display": "Hearing aid" }], "text": "Digital Hearing Aid" }, "subject": { "reference": "Patient/aud-patient-00050" }, "encounter": { "reference": "Encounter/aud-encounter-00050" }, "occurrenceDateTime": "2025-09-17T12:56:14.690966", "requester": { "reference": "Practitioner/aud-practitioner-00050" }, "reasonCode": [{ "coding": [{ "system": "http://hl7.org/fhir/sid/icd-10-cm", "code": "H90.3", "display": "Sensorineural hearing loss, bilateral" }] }], "supportingInfo": [{ "reference": "Encounter/aud-encounter-00050" }], "note": [{ "text": "Bilateral hearing aid fitting recommended for existing user patient. Features should include noise reduction, directional microphones, and wireless connectivity." }] } }, { "name": "DeviceRequest 2: Hearing Aid with FDA 510(k) K181965", "resource": { "resourceType": "DeviceRequest", "id": "device-request-hearing-aid-00050", "status": "active", "intent": "order", "codeCodeableConcept": { "coding": [{ "system": "http://snomed.info/sct", "code": "467138008", "display": "Hearing aid" }], "text": "Bilateral digital hearing aids with FDA approval" }, "parameter": [{ "code": { "coding": [{ "system": "http://hl7.org/fhir/device-parameter", "code": "fda-510k", "display": "FDA 510(k) Number" }] }, "valueCodeableConcept": { "coding": [{ "system": "http://fda.gov/510k", "code": "K181965", "display": "FDA 510(k) Cleared Device" }], "text": "K181965" } }], "subject": { "reference": "Patient/aud-patient-00050" }, "authoredOn": "2025-09-21T21:23:50.399644", "requester": { "reference": "Practitioner/aud-practitioner-00050" }, "note": [{ "text": "FDA 510(k) Number: K181965 - Advanced digital hearing aid system with noise reduction" }] } } ] async def analyze_patient_50(): """Analyze Patient 50's DeviceRequests.""" print("=" * 80) print("Patient 50 - FDA Device Verification Analysis") print("=" * 80) print("Patient ID: aud-patient-00050") print("Found 2 DeviceRequest resources") print("=" * 80) # Get credentials import os api_key = os.getenv("LLAMA_API_KEY", "af78aa99d7ae5bb58f19380ee007277c") base_url = os.getenv("LLAMA_BASE_URL", "https://llama-4-scout-17b-16e-w4a16-maas-apicast-production.apps.prod.rhoai.rh-aiservices-bu.com:443/v1") mcp_url = os.getenv("FDA_MCP_URL", "http://localhost:8090/mcp/") # Initialize agent print(f"\nInitializing FDA Verification Agent...") print(f"MCP Server: {mcp_url}") print(f"LLM Model: llama-4-scout-17b-16e-w4a16") print("-" * 80) agent = FDAVerificationAgent( mcp_url=mcp_url, api_key=api_key, base_url=base_url ) # Analyze each DeviceRequest for i, dr in enumerate(DEVICE_REQUESTS, 1): print(f"\n🔍 Analyzing {dr['name']}") print("=" * 60) # Display key fields resource = dr['resource'] print("\n📋 DeviceRequest Details:") print(f" Device: {resource['codeCodeableConcept']['text']}") print(f" SNOMED Code: {resource['codeCodeableConcept']['coding'][0]['code']}") # Check for FDA info in parameters or notes has_fda_info = False if 'parameter' in resource: for param in resource['parameter']: if 'fda' in str(param).lower(): print(f" FDA Info in parameters: {param.get('valueCodeableConcept', {}).get('text', 'N/A')}") has_fda_info = True if 'note' in resource: for note in resource['note']: if 'FDA' in note['text'] or 'K' in note['text']: print(f" Note: {note['text']}") if 'K' in note['text']: has_fda_info = True if not has_fda_info: print(" No explicit FDA information found in request") print("\n🤖 Running FDA Verification Agent...") print("-" * 40) try: # Analyze with agent result = await agent.analyze_device_request(resource) # Display results print(f"\n📊 PA Decision: {result.decision.value.upper()}") print(f"💭 Reasoning: {result.reasoning}") if result.fda_verification: fda = result.fda_verification print(f"\n🔍 FDA Verification Results:") print(f" Device Name: {fda.device_name}") print(f" FDA Status: {fda.fda_status}") print(f" FDA Approved/Cleared: {'✅ Yes' if fda.is_fda_approved else '❌ No'}") if fda.fda_number: print(f" FDA Number: {fda.fda_number}") if fda.manufacturer: print(f" Manufacturer: {fda.manufacturer}") if fda.device_class: print(f" Device Class: {fda.device_class}") if fda.is_otc: print(f" OTC Status: ✅ Over-the-counter") print(f" Confidence: {fda.confidence:.0%}") print(f" Verification Method: {fda.verification_method}") if fda.notes: print(f" Notes:") for note in fda.notes: print(f" • {note}") if result.requirements_met: print(f"\n✓ Policy Requirements:") for req, met in result.requirements_met.items(): status = "✅" if met else "❌" print(f" {status} {req}") if result.missing_information: print(f"\n⚠️ Missing Information:") for info in result.missing_information: print(f" • {info}") if result.recommendations: print(f"\n💡 Recommendations:") for rec in result.recommendations: print(f" • {rec}") print(f"\n🎯 Overall Confidence: {result.confidence:.0%}") except Exception as e: print(f"\n❌ Error analyzing DeviceRequest: {e}") import traceback traceback.print_exc() print("\n" + "=" * 80) print("✅ Analysis Complete for Patient 50") print("=" * 80) # Summary print("\n📝 Summary for Patient aud-patient-00050:") print(" • 2 DeviceRequest resources found") print(" • DeviceRequest 1: Generic digital hearing aid (no FDA number)") print(" • DeviceRequest 2: Hearing aid with FDA 510(k) K181965") print("\nThe second DeviceRequest includes explicit FDA clearance information,") print("making it more likely to be approved for prior authorization.") if __name__ == "__main__": asyncio.run(analyze_patient_50())

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rdwj/fda-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server