{
  "name": "HealthPower — Patient appointment booking with authorization + consent check",
  "description": "Complete patient flow: verify consent → check authorization rules → create appointment → notify patient. Demonstrates HealthPower's Validation Gateway (auto-approve/manual-review/copay) and consent verification before booking. For health insurers and providers in LATAM.",
  "tags": [
    "mediavox",
    "healthpower",
    "health",
    "appointments",
    "consent",
    "authorization",
    "latam",
    "insurance"
  ],
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "book-appointment",
        "responseMode": "responseNode"
      },
      "name": "Webhook (Booking Request)",
      "type": "n8n-nodes-base.webhook",
      "position": [
        240,
        300
      ],
      "notes": "Receives: { paciente_tipo_id, paciente_id, especialista_id, fecha, categoria, motivo }",
      "id": "505d014a-edbf-49df-a230-2cb0a139a4ec"
    },
    {
      "parameters": {
        "method": "health.consent.status",
        "params": "={{ JSON.stringify({ paciente_tipo_id: $json.body.paciente_tipo_id, paciente_id: $json.body.paciente_id }) }}",
        "product": "healthpower"
      },
      "name": "Check Consent",
      "type": "n8n-nodes-mediavox.mediavox",
      "position": [
        460,
        300
      ],
      "credentials": {
        "mediavoxApi": {
          "name": "Mediavox HP"
        }
      },
      "notes": "Verifies if patient has active data-sharing consent. Required before any clinical operation.",
      "typeVersion": 2,
      "id": "defef116-b05f-405f-b7c4-655cf9e84843"
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.has_consent }}",
              "value2": true
            }
          ]
        }
      },
      "name": "Has Consent?",
      "type": "n8n-nodes-base.if",
      "position": [
        660,
        300
      ],
      "notes": "Routes to booking if consent exists, or to rejection if not.",
      "id": "fe0937e6-8664-41df-9ba6-3bfa41c8a0ec"
    },
    {
      "parameters": {
        "method": "health.appointments.create",
        "params": "={{ JSON.stringify({ id_especialista: $('Webhook (Booking Request)').first().json.body.especialista_id, fecha: $('Webhook (Booking Request)').first().json.body.fecha, paciente_tipo_id: $('Webhook (Booking Request)').first().json.body.paciente_tipo_id, paciente_id: $('Webhook (Booking Request)').first().json.body.paciente_id, categoria: $('Webhook (Booking Request)').first().json.body.categoria, motivo: $('Webhook (Booking Request)').first().json.body.motivo }) }}",
        "product": "healthpower"
      },
      "name": "Create Appointment",
      "type": "n8n-nodes-mediavox.mediavox",
      "position": [
        880,
        250
      ],
      "credentials": {
        "mediavoxApi": {
          "name": "Mediavox HP"
        }
      },
      "notes": "Creates appointment. If $.healthpower.authorization.mode='local', validates against rules automatically. Returns estado: confirmada | pendiente_autorizacion + copago amount.",
      "typeVersion": 2,
      "id": "526a0863-14d0-4813-9b29-c47b7706149a"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, appointment_id: $json.id, estado: $json.estado, copago: $json.copago, message: $json.estado === 'confirmada' ? 'Cita confirmada' : 'Cita pendiente de autorización' }) }}"
      },
      "name": "Respond OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1100,
        250
      ],
      "id": "3760e6a5-4c52-42af-a0c6-c6502ebdc83c"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: false, error: 'Patient has not granted data consent. Request consent first via /health/consent/grant.' }) }}",
        "options": {
          "responseCode": 403
        }
      },
      "name": "Respond No Consent",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        880,
        400
      ],
      "id": "a066ad0e-0e83-4c5e-b740-6c6e6bc04af7"
    }
  ],
  "connections": {
    "Webhook (Booking Request)": {
      "main": [
        [
          {
            "node": "Check Consent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Consent": {
      "main": [
        [
          {
            "node": "Has Consent?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Consent?": {
      "main": [
        [
          {
            "node": "Create Appointment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond No Consent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Appointment": {
      "main": [
        [
          {
            "node": "Respond OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "active": false,
  "versionId": "f98f3f15-ee78-481a-93ec-53ae2e1655f3",
  "meta": {
    "templateCredsSetupCompleted": true
  }
}