import requests
import concurrent.futures
API_URL = "https://{your-endpoint}/v1/codify"
API_TOKEN = "YOUR_TOKEN"
headers = {
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
}
def codify_note(note_data):
"""Process a single medical note"""
payload = {
"medical_note": note_data['text'],
"model": "balanced"
}
# Add optional tracking headers
request_headers = headers.copy()
if 'doctor_id' in note_data:
request_headers['x-doctor'] = note_data['doctor_id']
if 'patient_id' in note_data:
request_headers['x-patient'] = note_data['patient_id']
response = requests.post(API_URL, json=payload, headers=request_headers)
return {
'note_id': note_data['id'],
'result': response.json()
}
# Sample notes to process
notes = [
{
'id': 'note_001',
'text': 'Patient with Type 2 Diabetes, controlled with Metformin.',
'doctor_id': 'dr_123',
'patient_id': 'pt_456'
},
{
'id': 'note_002',
'text': 'Hypertension, essential, well controlled on Lisinopril 10mg daily.',
'doctor_id': 'dr_124',
'patient_id': 'pt_457'
},
{
'id': 'note_003',
'text': 'Acute bronchitis with productive cough. Started on azithromycin.',
'doctor_id': 'dr_125',
'patient_id': 'pt_458'
}
]
# Process in parallel (max 10 concurrent requests)
def process_batch(notes, max_workers=10):
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = [executor.submit(codify_note, note) for note in notes]
results = []
for future in concurrent.futures.as_completed(futures):
try:
results.append(future.result())
except Exception as e:
print(f"Error processing note: {e}")
return results
# Execute batch processing
results = process_batch(notes)
# Display results
for result in results:
print(f"\nNote ID: {result['note_id']}")
print(f"Codes found: {len(result['result']['final_code_assessments'])}")
for assessment in result['result']['final_code_assessments']:
print(f" - {assessment['code']}: {assessment['description']} ({assessment['confidence_percent']}%)")