Explorar documentación

Actualizar y eliminar pacientes

Guardá cambios sin pisar los de otros, consultá versiones anteriores y eliminá registros de prueba.

Ya sabés crear y leer un Patient. Ahora vamos a cambiarlo, ver su historial y eliminarlo. Usá solo datos ficticios en estos ejemplos.

Configurá el cliente de servidor del SDK para usar los ejemplos con esus. Usá el ID del paciente ficticio como patientId.

Actualizar (PUT)

PUT combina los campos que enviás con el recurso guardado: los campos que omitas no se borran. Podés enviar el recurso completo o solo lo que cambia.

REST
curl -X PUT https://api.esus.health/fhir/Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -H 'If-Match: W/"1"' \
  -d '{
    "resourceType": "Patient",
    "name": [
      { "use": "official", "family": "Pérez", "given": ["Juan", "Miguel"] }
    ],
    "birthDate": "1990-01-16"
  }'
SDK
const { etag } = await esus.fhir.read("Patient", patientId);
if (!etag) throw new Error("Missing Patient ETag");

await esus.fhir.update("Patient", patientId, {
  "name": [
    { "use": "official", "family": "Pérez", "given": ["Juan", "Miguel"] }
  ],
  "birthDate": "1990-01-16"
}, etag);

Las lecturas, PUT y PATCH devuelven el header ETag con la versión (W/"2"). Si mandás If-Match y alguien guardó otra versión antes, la API responde 412 Precondition Failed en lugar de pisar su cambio. El header es opcional, pero conviene usarlo cuando varias personas editan el mismo paciente.

Cambios puntuales (PATCH)

PATCH acepta tres formatos, según el Content-Type:

Content-TypeCuerpo
application/fhir+json o application/jsonUn Patient parcial con los campos a cambiar
application/json-patch+jsonOperaciones JSON Patch (RFC 6902)
application/merge-patch+jsonUn JSON Merge Patch (RFC 7386)
REST
curl -X PATCH https://api.esus.health/fhir/Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json-patch+json" \
  -d '[
    { "op": "replace", "path": "/gender", "value": "other" }
  ]'
SDK
const { etag } = await esus.fhir.read("Patient", patientId);
if (!etag) throw new Error("Missing Patient ETag");

await esus.fhir.patchJson("Patient", patientId, [
  { op: "replace", path: "/gender", value: "other" },
], etag);

PATCH también respeta If-Match y devuelve el recurso actualizado.

Consultar versiones anteriores

Cada cambio crea una versión nueva:

REST
# Todas las versiones
GET /fhir/Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6/_history

# Una versión específica
GET /fhir/Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6/_history/2
SDK
const history = await esus.fhir.history("Patient", patientId);
const version = await esus.fhir.readVersion("Patient", patientId, "2");

Eliminar (DELETE)

REST
curl -X DELETE https://api.esus.health/fhir/Patient/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer YOUR_TOKEN"
SDK
await esus.fhir.delete("Patient", patientId);

La API responde 204 No Content y el paciente se elimina de forma definitiva: después, tanto la lectura como _history devuelven 404 Not Found.

Entender una respuesta de error

CódigoSignificado
200 OKLectura o actualización exitosa
201 CreatedCreación exitosa
204 No ContentEliminación exitosa
400 Bad RequestParámetros inválidos
401 UnauthorizedFalta la credencial o no es válida
403 ForbiddenLa credencial no tiene permiso para esa acción
404 Not FoundEl recurso no existe
412 Precondition FailedIf-Match no coincide con la versión actual
422 Unprocessable EntityEl cuerpo no respeta el esquema del recurso

Los errores llegan como OperationOutcome. Por ejemplo, un If-Match desactualizado:

{
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "error",
      "code": "conflict",
      "diagnostics": "Version mismatch — re-read the resource and retry with the current versionId"
    }
  ]
}

Validar sin guardar

$validate revisa un recurso de cualquier tipo y no lo guarda:

REST
curl -X POST https://api.esus.health/fhir/\$validate \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/fhir+json" \
  -d '{ "resourceType": "Patient", "gender": "masculino" }'
SDK
const { body: outcome } = await esus.fhir.operation("POST /fhir/$validate", {
  body: { "resourceType": "Patient", "gender": "masculino" },
});

La respuesta es un OperationOutcome con los problemas encontrados.

Seguir practicando

Ya recorriste los primeros pasos. Si querés repasar lo aprendido, seguí con las preguntas de práctica. Tu avance se guarda en este navegador cuando elegís el modo Curso.