Skip to content

Consultation Lifecycle

Consultation Lifecycle

A consultation in DELPHOS follows a well-defined lifecycle. This guide walks through every stage — from opening a session to receiving the completed SOAP note.

Consultation Phases

The consultation phase tracks the clinical encounter flow.

ABERTO → ATENDIMENTO → GRAVACAO → FINALIZADO
│ │ ↑ │
│ │ └────────┘ (stop/start recording)
│ │
│ └─────────────→ FINALIZADO
└────────────────────────→ (timeout)
PhaseDescription
ABERTOSession created, waiting for physician to begin
ATENDIMENTOPhysician has started the clinical encounter
GRAVACAOAudio recording is active
FINALIZADOConsultation complete — SOAP note generated

Starting a Consultation

There are two ways to begin: streaming (with real-time audio) or text (with a pre-existing transcript).

Streaming Consultation

Terminal window
curl -X POST "https://your-instance.delphos.app/v1/consultation/start" \
-H "x-api-key: $DELPHOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"external_consultation_id": "ATD-2024-001234",
"external_patient_id": "PAT-5678",
"language": "pt",
"diarize": true,
"metadata": {
"doctor_id": "DOC-123",
"specialty": "cardiology",
"location": "clinic-a",
"encounter_type": "follow-up"
}
}'

Response (201 Created):

{
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"external_consultation_id": "ATD-2024-001234",
"state": "ACTIVE",
"created_at": "2026-04-14T10:30:00Z",
"message": "Session created successfully. Ready to receive audio chunks."
}

Request Parameters

FieldTypeRequiredDescription
external_consultation_idstringYesYour system’s consultation ID (1-255 chars)
external_patient_idstringYesYour system’s patient ID
languagestringNoTranscription language (default: pt)
diarizebooleanNoEnable speaker diarization (default: true)
metadata.doctor_idstringYesDoctor’s external ID — must exist in DELPHOS
metadata.specialtystringNoMedical specialty for context

Text Consultation

If you already have a transcript (e.g., from typed notes), skip audio and send the text directly:

Terminal window
curl -X POST "https://your-instance.delphos.app/v1/consultation/text" \
-H "x-api-key: $DELPHOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"external_consultation_id": "ATD-2024-001235",
"external_patient_id": "PAT-5678",
"transcript": "Doctor: Good morning. How are you feeling today?\nPatient: The headaches are less frequent now...",
"metadata": {
"doctor_id": "DOC-123",
"specialty": "neurology"
},
"include_soap": true,
"wait_for_soap": true
}'

When wait_for_soap is true, the response waits for SOAP generation and returns 200 OK with the complete result. Set it to false to receive 202 Accepted and poll for the result.


Lifecycle Transitions

After creating a session, move it through phases to track the consultation progress:

  1. Start Attendance

    Signal that the physician has begun the encounter:

    Terminal window
    curl -X POST "https://your-instance.delphos.app/v1/consultation/{session_id}/start-attendance" \
    -H "x-api-key: $DELPHOS_API_KEY"

    Transitions: ABERTOATENDIMENTO

  2. Start Recording (optional)

    Activate audio recording:

    Terminal window
    curl -X POST "https://your-instance.delphos.app/v1/consultation/{session_id}/start-recording" \
    -H "x-api-key: $DELPHOS_API_KEY"

    Transitions: ATENDIMENTOGRAVACAO

  3. Stop Recording (optional)

    Pause audio capture without ending the consultation:

    Terminal window
    curl -X POST "https://your-instance.delphos.app/v1/consultation/{session_id}/stop-recording" \
    -H "x-api-key: $DELPHOS_API_KEY"

    Transitions: GRAVACAOATENDIMENTO

  4. Finalize

    End the consultation and trigger SOAP generation:

    Terminal window
    curl -X POST "https://your-instance.delphos.app/v1/consultation/{session_id}/finalize" \
    -H "x-api-key: $DELPHOS_API_KEY"

    Transitions: ATENDIMENTO or GRAVACAOFINALIZADO

Phase History

Retrieve the full audit trail of phase transitions:

Terminal window
curl -X GET "https://your-instance.delphos.app/v1/consultation/{session_id}/history" \
-H "x-api-key: $DELPHOS_API_KEY"
{
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"current_phase": "FINALIZADO",
"transitions": [
{
"from_phase": "ABERTO",
"to_phase": "ATENDIMENTO",
"triggered_at": "2026-04-14T10:30:00Z",
"triggered_by": "api-key-id"
},
{
"from_phase": "ATENDIMENTO",
"to_phase": "GRAVACAO",
"triggered_at": "2026-04-14T10:31:00Z",
"triggered_by": "api-key-id"
},
{
"from_phase": "GRAVACAO",
"to_phase": "FINALIZADO",
"triggered_at": "2026-04-14T10:45:00Z",
"triggered_by": "api-key-id"
}
]
}

Ending a Consultation

There are two endpoint forms for ending a consultation — both return the same response:

  • POST /v1/consultation/end — session_id provided in the request body
  • POST /v1/consultation/end/{session_id} — session_id in the URL path (shown below); also accepts accumulated_text for injecting physician notes

When ending a streaming consultation, you can include the physician’s accumulated notes and control SOAP generation:

Terminal window
curl -X POST "https://your-instance.delphos.app/v1/consultation/end/{session_id}" \
-H "x-api-key: $DELPHOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"accumulated_text": "Paciente com cefaleia tensional há 3 dias. Prescrever analgesico.",
"include_soap": true,
"wait_for_soap": true
}'

The accumulated_text field contains the physician’s typed notes, which are injected into the transcript before SOAP generation to enrich the clinical context.


Checking Session Status

Poll the status endpoint to track SOAP generation progress:

Terminal window
curl -X GET "https://your-instance.delphos.app/v1/consultation/{session_id}/status" \
-H "x-api-key: $DELPHOS_API_KEY"

The response includes the session state, full transcript, statistics, and the SOAP note once generation completes.

Session States

The session state tracks audio streaming and SOAP generation progress — independent of the consultation phase above.

StateDescription
ACTIVEReceiving audio chunks
PROCESSING_SOAPAudio complete, generating SOAP note
COMPLETEDSOAP generated successfully
ERRORProcessing error occurred
TIMEOUTSession timed out (24h TTL)

Error Handling

Response Codes

StatusMeaning
200 OKRequest completed successfully
201 CreatedSession created (streaming consultation)
202 AcceptedRequest accepted, poll status endpoint for result (when wait_for_soap=false)

Error Details

StatusCause
409 ConflictActive session already exists for this consultation, or session not in valid state for the requested action
422 Unprocessable EntityMissing required fields, or patient/doctor not found
503 Service UnavailableTranscription or SOAP generation service temporarily unavailable

Next Steps