Saltar a contenido

Generar CUIR

Genera un CUIR (Clave Única de Identificación de Receta) conforme al formato oficial a partir de los datos de la receta.

Endpoint POST /v1/cuir/generar

Use este endpoint antes de registrar la receta en registrarreceta. Devuelve la cadena CUIR lista para usar.

Parámetros (body JSON)

Campo Tipo Obligatorio Ejemplo Descripción
groupId string "00001234567890123456789" Identificador de grupo (25 caracteres).
itemId string "01" Identificador de ítem (2 caracteres).
state string "02" Código de jurisdicción (2 caracteres).
prescriptionType string "01" Tipo (2 dígitos) — p. ej. medicamento 01.
medicationType string "01" Subtipo (2 dígitos) — condición de expendio (01, 02, etc.).

groupId debe cumplir longitud y formato; la API validará.

Ejemplo - curl

curl -X POST "https://api.asystir.com/v1/cuir/generar" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: TU_API_KEY" \
  -H "X-API-Secret: TU_API_SECRET" \
  -d '{
    "groupId":"00001234567890123456789",
    "itemId":"01",
    "state":"02",
    "prescriptionType":"01",
    "medicationType":"01"
  }'

Ejemplo - JavaScript (fetch)

const resp = await fetch("https://api.asystir.com/v1/cuir/generar", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key": "TU_API_KEY",
    "X-API-Secret": "TU_API_SECRET"
  },
  body: JSON.stringify({
    groupId: "00001234567890123456789",
    itemId: "01",
    state: "02",
    prescriptionType: "01",
    medicationType: "01"
  })
});
console.log(await resp.json());

Ejemplo - Visual Basic .NET

Dim client As New HttpClient()
client.DefaultRequestHeaders.Add("X-API-Key", "TU_API_KEY")
client.DefaultRequestHeaders.Add("X-API-Secret", "TU_API_SECRET")

Dim bodyJson = "{
  ""groupId"":""00001234567890123456789"",
  ""itemId"":""01"",
  ""state"":""02"",
  ""prescriptionType"":""01"",
  ""medicationType"":""01""
}"
Dim content = New StringContent(bodyJson, Encoding.UTF8, "application/json")
Dim resp = Await client.PostAsync("https://api.asystir.com/v1/cuir/generar", content)
Dim txt = Await resp.Content.ReadAsStringAsync()
Console.WriteLine(txt)

Respuesta de éxito (201)

{
  "success": true,
  "data": {
    "cuir": "102500420201010000123456789012345678901",
    "components": {
      "platform": "1025",
      "repository": "0042",
      "jurisdiction": "02",
      "type_subtype": "0101",
      "groupId": "00001234567890123456789",
      "itemId": "01"
    }
  }
}

Errores comunes

  • 400 Bad Request — Campos obligatorios faltan o groupId no cumple largo.
  • 409 Conflict — El groupId + itemId ya fue usado (si aplica política de unicidad del cliente).
  • 401/403 — Problemas de autenticación.

Notas

  • El CUIR generado es válido para uso inmediato en registrarreceta.
  • Soportamos validación opcional contra reglas locales (p. ej. subtipos incompatibles); active según convenio.