update_10_patients.py•6.5 kB
#!/usr/bin/env python3
"""
Update 10 patients' DeviceRequests with real FDA-approved hearing aids
"""
import requests
import json
from datetime import datetime
# FHIR server URL
FHIR_BASE = "https://hapi-fhir-davinci-data.apps.cluster-sdzgj.sdzgj.sandbox319.opentlc.com/fhir"
# Real FDA-approved hearing aids (all OTC, Class 2)
FDA_DEVICES = [
{
"patient_id": "aud-patient-00001",
"k_number": "K223137",
"device_name": "Lexie Lumen Self-Fitting OTC Hearing Aid",
"manufacturer": "hearX SA (Pty) Ltd.",
"otc": True
},
{
"patient_id": "aud-patient-00002",
"k_number": "K221064",
"device_name": "Nuheara IQbuds 2 PRO Hearing Aid",
"manufacturer": "Nuheara Limited",
"otc": True
},
{
"patient_id": "aud-patient-00003",
"k_number": "K233747",
"device_name": "Concha Sol Hearing Aid (CL-1001)",
"manufacturer": "Concha Labs",
"otc": True
},
{
"patient_id": "aud-patient-00004",
"k_number": "K230538",
"device_name": "All-Day Clear ADC1 Hearing Aid",
"manufacturer": "Sonova AG",
"otc": True
},
{
"patient_id": "aud-patient-00005",
"k_number": "K231550",
"device_name": "Sontro OTC Hearing Aid (AI)",
"manufacturer": "Soundwave Hearing, LLC",
"otc": True
},
{
"patient_id": "aud-patient-00006",
"k_number": "K213424",
"device_name": "Jabra Enhance Plus",
"manufacturer": "GN Hearing A/S",
"otc": True
},
{
"patient_id": "aud-patient-00007",
"k_number": "K230467",
"device_name": "Eargo 7",
"manufacturer": "Eargo, Inc.",
"otc": True
},
{
"patient_id": "aud-patient-00008",
"k_number": "K221338",
"device_name": "Sony CRE-C10 Self-Fitting OTC Hearing Aid",
"manufacturer": "Sony Electronics Inc.",
"otc": True
},
{
"patient_id": "aud-patient-00009",
"k_number": "K221349",
"device_name": "Sony CRE-E10 Self-Fitting OTC Hearing Aid",
"manufacturer": "Sony Electronics Inc.",
"otc": True
},
{
"patient_id": "aud-patient-00010",
"k_number": "K220892",
"device_name": "Audien ATOM PRO",
"manufacturer": "Audien Hearing",
"otc": True
}
]
def update_device_request(patient_id, device_info):
"""Update a patient's DeviceRequest with real FDA device info."""
# First, get the existing DeviceRequest
search_url = f"{FHIR_BASE}/DeviceRequest?subject=Patient/{patient_id}"
response = requests.get(search_url)
if response.status_code != 200:
print(f"❌ Failed to fetch DeviceRequest for {patient_id}")
return False
bundle = response.json()
if bundle.get("total", 0) == 0:
print(f"⚠️ No DeviceRequest found for {patient_id}")
return False
# Get the first DeviceRequest
device_request = bundle["entry"][0]["resource"]
device_request_id = device_request["id"]
# Update with real FDA device info
device_request["codeCodeableConcept"] = {
"coding": [{
"system": "http://snomed.info/sct",
"code": "469512007",
"display": "Digital hearing aid"
}],
"text": device_info["device_name"]
}
# Add FDA-specific parameters
device_request["parameter"] = [
{
"code": {
"coding": [{
"system": "http://hl7.org/fhir/ValueSet/device-safety",
"code": "fda-510k",
"display": "FDA 510(k) Number"
}]
},
"valueCodeableConcept": {
"text": device_info["k_number"]
}
},
{
"code": {
"coding": [{
"system": "http://hl7.org/fhir/ValueSet/device-safety",
"code": "manufacturer",
"display": "Manufacturer"
}]
},
"valueString": device_info["manufacturer"]
},
{
"code": {
"coding": [{
"system": "http://hl7.org/fhir/ValueSet/device-safety",
"code": "otc-status",
"display": "Over-The-Counter Status"
}]
},
"valueBoolean": device_info["otc"]
},
{
"code": {
"coding": [{
"system": "http://hl7.org/fhir/ValueSet/device-safety",
"code": "device-class",
"display": "FDA Device Class"
}]
},
"valueString": "2" # All OTC hearing aids are Class 2
}
]
# Add FDA clearance note
if "note" not in device_request:
device_request["note"] = []
device_request["note"].append({
"time": datetime.now().isoformat(),
"text": f"FDA 510(k) cleared device: {device_info['k_number']} - {device_info['device_name']} by {device_info['manufacturer']}. This is an OTC hearing aid, Class 2 medical device."
})
# Update the resource
update_url = f"{FHIR_BASE}/DeviceRequest/{device_request_id}"
update_response = requests.put(update_url, json=device_request, headers={"Content-Type": "application/fhir+json"})
if update_response.status_code in [200, 201]:
print(f"✅ Updated {patient_id}: {device_info['device_name']} ({device_info['k_number']})")
return True
else:
print(f"❌ Failed to update {patient_id}: {update_response.status_code}")
return False
def main():
print("=" * 80)
print("Updating 10 Patients with Real FDA-Approved Hearing Aids")
print("=" * 80)
success_count = 0
for device_info in FDA_DEVICES:
patient_id = device_info["patient_id"]
print(f"\nUpdating {patient_id}...")
if update_device_request(patient_id, device_info):
success_count += 1
print("\n" + "=" * 80)
print(f"✅ Successfully updated {success_count}/10 patients")
print("=" * 80)
if success_count == 10:
print("\n🎉 All patients now have real FDA-approved hearing aids!")
print(" These devices should be APPROVED by the FDA verification agent.")
return success_count == 10
if __name__ == "__main__":
success = main()
exit(0 if success else 1)