> ## Documentation Index
> Fetch the complete documentation index at: https://docs.linahealthcareplatform.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Programar envío de formularios

> Aprende a programar el envío de formularios clínicos a tus pacientes por email, SMS, WhatsApp o notificación push.

## Descripción general

LINA permite enviar formularios clínicos a pacientes a través de múltiples canales. Puedes programar envíos inmediatos o diferidos, y recibir los resultados automáticamente vía webhooks o consultando la API.

### Canales disponibles

| Canal      | Coste (créditos) | Descripción                                 |
| ---------- | ---------------- | ------------------------------------------- |
| `email`    | 1                | Correo electrónico con enlace al formulario |
| `sms`      | 2                | SMS con enlace corto                        |
| `whatsapp` | 3                | Mensaje de WhatsApp con botón interactivo   |
| `app`      | 0                | Notificación push en la app del paciente    |

## Flujo de trabajo

<Steps>
  <Step title="Obtener el ID del formulario">
    Primero, lista los formularios disponibles en tu cuenta para identificar cuál quieres enviar.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X GET https://api.linahealthcareplatform.com/api/v1/forms \
        -H "Authorization: Bearer YOUR_TOKEN"
      ```

      ```javascript Node.js theme={null}
      const response = await fetch('https://api.linahealthcareplatform.com/api/v1/forms', {
        headers: { 'Authorization': 'Bearer YOUR_TOKEN' }
      });
      const { data } = await response.json();
      console.log(data); // Lista de formularios disponibles
      ```

      ```python Python theme={null}
      import requests

      response = requests.get(
          "https://api.linahealthcareplatform.com/api/v1/forms",
          headers={"Authorization": "Bearer YOUR_TOKEN"}
      )
      forms = response.json()["data"]
      ```
    </CodeGroup>
  </Step>

  <Step title="Identificar al paciente">
    Necesitas el `id` del paciente. Puedes buscarlo por nombre o email.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X GET "https://api.linahealthcareplatform.com/api/v1/patients?search=maria.garcia@email.com" \
        -H "Authorization: Bearer YOUR_TOKEN"
      ```

      ```javascript Node.js theme={null}
      const response = await fetch(
        'https://api.linahealthcareplatform.com/api/v1/patients?search=maria.garcia@email.com',
        { headers: { 'Authorization': 'Bearer YOUR_TOKEN' } }
      );
      const { data } = await response.json();
      const patientId = data[0].id;
      ```

      ```python Python theme={null}
      response = requests.get(
          "https://api.linahealthcareplatform.com/api/v1/patients",
          params={"search": "maria.garcia@email.com"},
          headers={"Authorization": "Bearer YOUR_TOKEN"}
      )
      patient_id = response.json()["data"][0]["id"]
      ```
    </CodeGroup>
  </Step>

  <Step title="Crear la programación">
    Programa el envío del formulario al paciente indicando el canal y la fecha/hora deseada.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X POST https://api.linahealthcareplatform.com/api/v1/form-schedules \
        -H "Authorization: Bearer YOUR_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "formId": "form_abc123",
          "patientId": "pat_xyz789",
          "channel": "whatsapp",
          "scheduledAt": "2026-05-15T09:00:00Z",
          "message": "Hola María, te enviamos tu cuestionario de seguimiento semanal."
        }'
      ```

      ```javascript Node.js theme={null}
      const response = await fetch('https://api.linahealthcareplatform.com/api/v1/form-schedules', {
        method: 'POST',
        headers: {
          'Authorization': 'Bearer YOUR_TOKEN',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          formId: 'form_abc123',
          patientId: 'pat_xyz789',
          channel: 'whatsapp',
          scheduledAt: '2026-05-15T09:00:00Z',
          message: 'Hola María, te enviamos tu cuestionario de seguimiento semanal.'
        })
      });
      const schedule = await response.json();
      console.log(schedule.id); // sch_def456
      ```

      ```python Python theme={null}
      response = requests.post(
          "https://api.linahealthcareplatform.com/api/v1/form-schedules",
          headers={
              "Authorization": "Bearer YOUR_TOKEN",
              "Content-Type": "application/json"
          },
          json={
              "formId": "form_abc123",
              "patientId": "pat_xyz789",
              "channel": "whatsapp",
              "scheduledAt": "2026-05-15T09:00:00Z",
              "message": "Hola María, te enviamos tu cuestionario de seguimiento semanal."
          }
      )
      schedule = response.json()
      print(schedule["id"])  # sch_def456
      ```
    </CodeGroup>
  </Step>

  <Step title="Verificar el estado">
    Consulta el estado de la programación para confirmar que se ha enviado correctamente.

    <CodeGroup>
      ```bash cURL theme={null}
      curl -X GET https://api.linahealthcareplatform.com/api/v1/form-schedules?patientId=pat_xyz789&status=pending \
        -H "Authorization: Bearer YOUR_TOKEN"
      ```

      ```javascript Node.js theme={null}
      const response = await fetch(
        'https://api.linahealthcareplatform.com/api/v1/form-schedules?patientId=pat_xyz789&status=pending',
        { headers: { 'Authorization': 'Bearer YOUR_TOKEN' } }
      );
      const { data } = await response.json();
      ```

      ```python Python theme={null}
      response = requests.get(
          "https://api.linahealthcareplatform.com/api/v1/form-schedules",
          params={"patientId": "pat_xyz789", "status": "pending"},
          headers={"Authorization": "Bearer YOUR_TOKEN"}
      )
      schedules = response.json()["data"]
      ```
    </CodeGroup>
  </Step>
</Steps>

## Envío inmediato

Si omites el campo `scheduledAt`, el formulario se enviará inmediatamente:

```bash theme={null}
curl -X POST https://api.linahealthcareplatform.com/api/v1/form-schedules \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "formId": "form_abc123",
    "patientId": "pat_xyz789",
    "channel": "email"
  }'
```

## Cancelar un envío programado

Solo puedes cancelar envíos con estado `pending`. Los créditos se reembolsan automáticamente.

```bash theme={null}
curl -X POST https://api.linahealthcareplatform.com/api/v1/form-schedules/sch_def456/cancel \
  -H "Authorization: Bearer YOUR_TOKEN"
```

<Info>
  Los envíos cancelados devuelven los créditos consumidos a tu balance de forma inmediata.
</Info>

## Recibir respuestas

Configura un [webhook](/guides/webhooks) para el evento `form.completed` y recibirás las respuestas del paciente en tiempo real:

```json theme={null}
{
  "event": "form.completed",
  "data": {
    "formId": "form_abc123",
    "patientId": "pat_xyz789",
    "scheduleId": "sch_def456",
    "responses": [
      { "fieldId": "pain_level", "value": 3 },
      { "fieldId": "mood", "value": "bien" },
      { "fieldId": "notes", "value": "Me siento mejor esta semana" }
    ],
    "completedAt": "2026-05-15T09:12:34Z"
  }
}
```

<Warning>
  Los formularios enviados por SMS o WhatsApp expiran a las 72 horas. Los enviados por email o app no tienen caducidad.
</Warning>
