import requests
BASE_URL = "https://{your_api_url}"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
"x-doctor": "dr_123", # REQUIRED
"x-patient": "pt_456" # OPTIONAL
}
# Step 1: Create transcription
transcription_data = {
"duration_seconds": 180,
"original_transcript": "The patient is a 45-year-old male presenting with chest pain...",
"language_used": "en"
}
transcription_response = requests.post(
f"{BASE_URL}/v1/transcriptions/create",
json=transcription_data,
headers=headers
)
transcription = transcription_response.json()
transcription_id = transcription['transcription']['id']
print(f"✅ Step 1: Transcription created: {transcription_id}")
# Step 2: Create thread
thread_response = requests.post(
f"{BASE_URL}/v1/lang-graph/threads",
json={},
headers=headers
)
thread = thread_response.json()
thread_id = thread['thread_id']
print(f"✅ Step 2: Thread created: {thread_id}")
# Step 3: Execute run for clinical extraction
run_headers = {
**headers,
"x-is-chat": "false" # Clinical extraction mode
}
run_data = {
"input": {
"messages": [
{
"role": "user",
"content": f"Extract clinical information: {transcription_data['original_transcript']}"
}
]
},
"config": {
"configurable": {
"thread_id": thread_id
}
}
}
run_response = requests.post(
f"{BASE_URL}/v1/lang-graph/threads/{thread_id}/runs",
json=run_data,
headers=run_headers
)
run = run_response.json()
run_id = run['run_id']
print(f"✅ Step 3: Run executed: {run_id}")
# Step 4: Update clinical note (assuming note_id exists)
note_id = "note_def456ghi" # This would be created elsewhere
note_data = {
"template": "SOAP",
"ai_generated_content": {
"subjective": "Patient reports chest pain radiating to left arm",
"objective": "BP 140/90, HR 88, RR 18, O2 sat 98% on RA",
"assessment": "R/O myocardial infarction",
"plan": "Admit to CCU, serial troponins, cardiology consult"
},
"report_thread_id": thread_id,
"report_run_id": [run_id]
}
note_response = requests.patch(
f"{BASE_URL}/v1/clinical-notes/{note_id}",
json=note_data,
headers=headers
)
note = note_response.json()
print(f"✅ Step 4: Clinical note updated: {note['id']}")
print(f"\n🎉 Workflow complete!")