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

# Clínica nas Nuvens as a data source

> Bring data from Clínica nas Nuvens to Nekt.

Clínica nas Nuvens is a Brazilian cloud-based clinic management software designed for healthcare professionals. It provides tools for managing appointments, patients, procedures, and billing, helping clinics streamline their operations and improve patient care.

<img height="50" src="https://mintcdn.com/nekt/mv9aOh-5_CnX_z0c/assets/logo/logo-clinica-nas-nuvens.png?fit=max&auto=format&n=mv9aOh-5_CnX_z0c&q=85&s=0a3f9b3a3490c82ae8a78b540c910f2c" data-path="assets/logo/logo-clinica-nas-nuvens.png" />

## Configuring Clínica nas Nuvens as a Source

In the [Sources](https://app.nekt.ai/sources) tab, click on the "Add source" button located on the top right of your screen. Then, select the Clínica nas Nuvens option from the list of connectors.

Click **Next** and you'll be prompted to add your access.

### 1. Add account access

You'll need to provide your API credentials to access your Clínica nas Nuvens data. These credentials can be found in your Clínica nas Nuvens account under **Menu > Integrações > API**.

The following configurations are available:

* **Client ID**: The client ID to authenticate against the Clínica nas Nuvens API.

* **Client Secret**: The client secret to authenticate against the Clínica nas Nuvens API.

* **Token**: The token to authenticate against the Clínica nas Nuvens API.

* **Start Date**: The earliest date from which records will be synced. This is used for date-based streams like Agenda (appointments).

Once you're done, click **Next**.

### 2. Select streams

Choose which data streams you want to sync. For faster extractions, select only the streams that are relevant to your analysis. You can select entire groups of streams or pick specific ones.

> Tip: The stream can be found more easily by typing its name.

Select the streams and click **Next**.

### 3. Configure data streams

Customize how you want your data to appear in your catalog. Select the desired layer where the data will be placed, a folder to organize it inside the layer, a name for each table (which will effectively contain the fetched data) and the type of sync.

* **Layer**: choose between the existing layers on your catalog. This is where you will find your new extracted tables as the extraction runs successfully.
* **Folder**: a folder can be created inside the selected layer to group all tables being created from this new data source.
* **Table name**: we suggest a name, but feel free to customize it. You have the option to add a **prefix** to all tables at once and make this process faster!
* **Sync Type**: FULL\_TABLE sync is used for all streams.

<Note>
  **Incremental sync is not supported.** The Clínica nas Nuvens API does not provide reliable filters by modification date, so all streams use full table sync. Each extraction will fetch the complete current state of the data.
</Note>

Once you are done configuring, click **Next**.

### 4. Configure data source

Describe your data source for easy identification within your organization, not exceeding 140 characters.

To define your [Trigger](https://docs.nekt.com/get-started/core-concepts/triggers), consider how often you want data to be extracted from this source. This decision usually depends on how frequently you need the new table data updated (every day, once a week, or only at specific times).

Optionally, you can define some additional settings:

* Configure Delta Log Retention and determine for how long we should store old states of this table as it gets updated. Read more about this resource [here](https://docs.nekt.com/get-started/core-concepts/resource-control).
* Determine when to execute an **Additional [Full Sync](https://docs.nekt.com/get-started/core-concepts/types-of-sync#additional-full-sync)**. This will complement the incremental data extractions, ensuring that your data is completely synchronized with your source every once in a while.

Once you are ready, click **Next** to finalize the setup.

### 5. Check your new source

You can view your new source on the [Sources](https://app.nekt.ai/sources) page. If needed, manually trigger the source extraction by clicking on the arrow button. Once executed, your data will appear in your Catalog.

<Warning>For you to be able to see it on your [Catalog](https://app.nekt.ai/catalog), you need at least one successful source run.</Warning>

# Streams and Fields

Below you'll find all available data streams from Clínica nas Nuvens and their corresponding fields:

<AccordionGroup>
  <Accordion title="Agenda (Appointments)">
    Stream containing scheduled appointments and their details.

    **Key Fields:**

    * `id` - Unique identifier for the appointment
    * `data` - Date of the scheduled appointment
    * `horaInicio` - Start time of the appointment
    * `horaFim` - End time of the appointment
    * `status` - Appointment status

    **Patient Information:**

    * `idPaciente` - ID of the patient
    * `emailPaciente` - Patient's email address
    * `telefoneCelularPaciente` - Patient's mobile phone number
    * `idOrigemPaciente` - ID of the patient's origin/source

    **Appointment Details:**

    * `idLocalAgenda` - ID of the schedule location
    * `idPessoaExecutor` - ID of the person performing the appointment
    * `idTipoConsulta` - ID of the consultation type
    * `idTipoConvenio` - ID of the agreement/insurance type
    * `idRotulo` - ID of the label
    * `encaminhamento` - Referral information
    * `observacoes` - Observations about the appointment
    * `urlSalaEspera` - URL of the virtual waiting room

    **Procedures:**

    * `procedimentos[]` - Array of procedures for the appointment:
      * `procedimentos[].id` - Procedure ID
      * `procedimentos[].nome` - Procedure name
      * `procedimentos[].idEspecialidade` - Specialty ID
      * `procedimentos[].idTipoProcedimento` - Procedure type ID
      * `procedimentos[].idPromocao` - Promotion ID
      * `procedimentos[].quantidade` - Quantity
  </Accordion>

  <Accordion title="Pacientes (Patients)">
    Stream containing patient records and their personal information.

    **Key Fields:**

    * `id` - Unique identifier for the patient
    * `nome` - Patient's full name
    * `nomeSocial` - Patient's social name
    * `ativo` - Indicates whether the patient is active

    **Personal Information:**

    * `cpfcnpj` - Patient's CPF or CNPJ document number
    * `dataNascimento` - Patient's date of birth
    * `sexo` - Patient's biological sex
    * `genero` - Patient's gender
    * `idNacionalidade` - ID of the patient's nationality
    * `estrangeiro` - Indicates if the patient is a foreigner
    * `numeroControle` - Patient's control number
    * `numeroIdentificacao` - Patient's identification number
    * `idOrigem` - Origin/source identifier

    **Contact Information (`contato`):**

    * `contato.email` - Patient's email address
    * `contato.telefoneCelular` - Mobile phone number
    * `contato.telefoneResidencial` - Residential phone number
    * `contato.telefoneComercial` - Commercial phone number
    * `contato.telefoneRecados` - Message phone number
    * `contato.skype` - Skype username
    * `contato.ramalTelefoneResidencial` - Residential phone extension
    * `contato.ramalTelefoneComercial` - Commercial phone extension
    * `contato.ramalTelefoneRecados` - Message phone extension

    **Address Information (`endereco`):**

    * `endereco.rua` - Street name
    * `endereco.numero` - Address number
    * `endereco.complemento` - Address complement
    * `endereco.bairro` - Neighborhood
    * `endereco.cep` - ZIP/postal code
    * `endereco.idCidade` - City ID (joins with Cidades stream)
  </Accordion>

  <Accordion title="Cidades (Cities)">
    Lookup table containing city information with state details.

    **Key Fields:**

    * `id` - Unique identifier for the city
    * `nome` - City name
    * `codIbge` - IBGE code (Brazilian official city code)

    **State Information (`estado`):**

    * `estado.id` - State identifier
    * `estado.nome` - State name
    * `estado.sigla` - State abbreviation (e.g., SP, RJ, MG)
  </Accordion>

  <Accordion title="Especialidades (Specialties)">
    Lookup table containing medical specialties.

    **Key Fields:**

    * `id` - Unique identifier for the specialty
    * `nome` - Specialty name (e.g., Cardiologia, Dermatologia)
  </Accordion>

  <Accordion title="Nacionalidades (Nationalities)">
    Lookup table containing nationalities.

    **Key Fields:**

    * `id` - Unique identifier for the nationality
    * `nacionalidade` - Nationality name (e.g., Brasileira, Portuguesa)
  </Accordion>

  <Accordion title="Origem (Patient Sources)">
    Lookup table containing patient origin/source information. Tracks how patients discovered or were referred to the clinic.

    **Key Fields:**

    * `id` - Unique identifier for the origin
    * `nome` - Origin name (e.g., "Indicação", "Google", "Convênio")
    * `ativo` - Indicates if the origin is active
  </Accordion>

  <Accordion title="Agenda Origem (Schedule Origins)">
    Lookup table containing schedule/appointment origin information.

    **Key Fields:**

    * `id` - Unique identifier for the schedule origin
    * `nome` - Schedule origin name
    * `ativo` - Indicates if the record is active
  </Accordion>

  <Accordion title="Tipo Convênio (Agreement Types)">
    Lookup table containing agreement/insurance types (convênios).

    **Key Fields:**

    * `id` - Unique identifier for the agreement type
    * `nome` - Agreement type name
    * `ativo` - Indicates if the agreement type is active
    * `particular` - Indicates if it's a private/self-pay option
    * `beneficio` - Indicates benefit status
  </Accordion>

  <Accordion title="Tipo Procedimento (Procedure Types)">
    Lookup table containing procedure types with associated specialties.

    **Key Fields:**

    * `id` - Unique identifier for the procedure type
    * `nome` - Procedure type name
    * `ativo` - Indicates if the procedure type is active

    **Associated Specialties:**

    * `especialidades[]` - Array of specialties that can perform this procedure:
      * `especialidades[].id` - Specialty ID
      * `especialidades[].nome` - Specialty name
  </Accordion>
</AccordionGroup>

# Data Model

The following diagram illustrates the relationships between the core data streams in Clínica nas Nuvens. The arrows indicate the join keys that link the different entities, providing a clear overview of the data structure.

```mermaid theme={null}
erDiagram
    Agenda }o--|| Pacientes : "idPaciente"
    Agenda }o--|| TipoConvenio : "idTipoConvenio"
    Agenda }o--|| Origem : "idOrigemPaciente"
    Agenda }o--|| Especialidades : "procedimentos.idEspecialidade"
    Agenda }o--|| TipoProcedimento : "procedimentos.idTipoProcedimento"
    
    Pacientes }o--|| Cidades : "endereco.idCidade"
    Pacientes }o--|| Nacionalidades : "idNacionalidade"
    Pacientes }o--|| Origem : "idOrigem"
    
    TipoProcedimento }o--|| Especialidades : "especialidades.id"

    Agenda {
        int id PK
        string data
        string horaInicio
        string horaFim
        string status
        int idPaciente FK
        int idTipoConvenio FK
        int idOrigemPaciente FK
        int idLocalAgenda
        int idPessoaExecutor
        int idTipoConsulta
        int idRotulo
        string emailPaciente
        string telefoneCelularPaciente
        string observacoes
        string encaminhamento
        string urlSalaEspera
        array procedimentos
    }
    
    Pacientes {
        int id PK
        string nome
        string nomeSocial
        string cpfcnpj
        string dataNascimento
        string sexo
        string genero
        boolean ativo
        boolean estrangeiro
        int idNacionalidade FK
        int idOrigem FK
        object contato
        object endereco
    }
    
    Cidades {
        int id PK
        string nome
        string codIbge
        object estado
    }
    
    Especialidades {
        int id PK
        string nome
    }
    
    Nacionalidades {
        int id PK
        string nacionalidade
    }
    
    Origem {
        int id PK
        string nome
        boolean ativo
    }
    
    TipoConvenio {
        int id PK
        string nome
        boolean ativo
        boolean particular
        boolean beneficio
    }
    
    TipoProcedimento {
        int id PK
        string nome
        boolean ativo
        array especialidades
    }
```

# Use Cases for Data Analysis

This guide outlines valuable business intelligence use cases when consolidating Clínica nas Nuvens data, along with ready-to-use SQL queries that you can run on [Explorer](https://app.nekt.ai/explorer).

### 1. Appointment Volume Analysis

Track appointment volumes over time to understand clinic capacity and identify trends.

**Business Value:**

* Understand daily and weekly appointment patterns
* Identify peak hours and days for resource planning
* Monitor appointment status distribution

<Accordion title="SQL query">
  <Tabs>
    <Tab title="AWS">
      ```sql theme={null}
      WITH appointment_metrics AS (
          SELECT
              DATE(a.data) AS appointment_date,
              DATE_FORMAT(DATE(a.data), '%W') AS day_of_week,
              a.status,
              COUNT(*) AS total_appointments,
              COUNT(DISTINCT a.idPaciente) AS unique_patients
          FROM
              nekt_raw.clinica_nas_nuvens_agenda a
          WHERE
              DATE(a.data) >= CURRENT_DATE - INTERVAL '30' DAY
          GROUP BY
              DATE(a.data),
              DATE_FORMAT(DATE(a.data), '%W'),
              a.status
      )
      SELECT
          appointment_date,
          day_of_week,
          status,
          total_appointments,
          unique_patients
      FROM
          appointment_metrics
      ORDER BY
          appointment_date DESC,
          total_appointments DESC
      ```
    </Tab>

    <Tab title="GCP">
      ```sql theme={null}
      WITH appointment_metrics AS (
          SELECT
              DATE(a.data) AS appointment_date,
              FORMAT_DATE('%A', DATE(a.data)) AS day_of_week,
              a.status,
              COUNT(*) AS total_appointments,
              COUNT(DISTINCT a.idPaciente) AS unique_patients
          FROM
              `nekt_raw.clinica_nas_nuvens_agenda` a
          WHERE
              DATE(a.data) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
          GROUP BY
              1, 2, 3
      )
      SELECT
          appointment_date,
          day_of_week,
          status,
          total_appointments,
          unique_patients
      FROM
          appointment_metrics
      ORDER BY
          appointment_date DESC,
          total_appointments DESC
      ```
    </Tab>
  </Tabs>
</Accordion>

<Accordion title="Sample Result">
  | appointment\_date | day\_of\_week | status     | total\_appointments | unique\_patients |
  | ----------------- | ------------- | ---------- | ------------------- | ---------------- |
  | 2024-11-27        | Wednesday     | Confirmado | 45                  | 42               |
  | 2024-11-27        | Wednesday     | Aguardando | 12                  | 12               |
  | 2024-11-27        | Wednesday     | Cancelado  | 3                   | 3                |
  | 2024-11-26        | Tuesday       | Confirmado | 52                  | 48               |
  | 2024-11-26        | Tuesday       | Aguardando | 8                   | 8                |
</Accordion>

### 2. Patient Origin Analysis

Understand where your patients are coming from to optimize marketing efforts.

**Business Value:**

* Identify most effective patient acquisition channels
* Measure ROI of marketing initiatives
* Optimize patient acquisition strategy

<Accordion title="SQL query">
  <Tabs>
    <Tab title="AWS">
      ```sql theme={null}
      SELECT
          o.nome AS origem,
          COUNT(DISTINCT p.id) AS total_patients,
          COUNT(DISTINCT CASE WHEN p.ativo = true THEN p.id END) AS active_patients,
          ROUND(
              COUNT(DISTINCT CASE WHEN p.ativo = true THEN p.id END) * 100.0 / 
              NULLIF(COUNT(DISTINCT p.id), 0), 
              1
          ) AS active_rate_pct
      FROM
          nekt_raw.clinica_nas_nuvens_pacientes p
          LEFT JOIN nekt_raw.clinica_nas_nuvens_origem o ON p.idOrigem = o.id
      GROUP BY
          o.nome
      ORDER BY
          total_patients DESC
      ```
    </Tab>

    <Tab title="GCP">
      ```sql theme={null}
      SELECT
          o.nome AS origem,
          COUNT(DISTINCT p.id) AS total_patients,
          COUNT(DISTINCT CASE WHEN p.ativo = true THEN p.id END) AS active_patients,
          ROUND(
              SAFE_DIVIDE(
                  COUNT(DISTINCT CASE WHEN p.ativo = true THEN p.id END) * 100.0,
                  COUNT(DISTINCT p.id)
              ), 
              1
          ) AS active_rate_pct
      FROM
          `nekt_raw.clinica_nas_nuvens_pacientes` p
          LEFT JOIN `nekt_raw.clinica_nas_nuvens_origem` o ON p.idOrigem = o.id
      GROUP BY
          o.nome
      ORDER BY
          total_patients DESC
      ```
    </Tab>
  </Tabs>
</Accordion>

<Accordion title="Sample Result">
  | origem    | total\_patients | active\_patients | active\_rate\_pct |
  | --------- | --------------- | ---------------- | ----------------- |
  | Indicação | 1,245           | 1,102            | 88.5              |
  | Google    | 856             | 723              | 84.5              |
  | Convênio  | 634             | 589              | 92.9              |
  | Instagram | 423             | 367              | 86.8              |
  | Site      | 312             | 256              | 82.1              |
</Accordion>

### 3. Procedure and Specialty Analysis

Analyze which procedures and specialties are most in demand.

**Business Value:**

* Identify most popular procedures
* Understand specialty distribution
* Plan resource allocation based on demand

<Accordion title="SQL query">
  <Tabs>
    <Tab title="AWS">
      ```sql theme={null}
      WITH procedure_data AS (
          SELECT
              p.id AS procedure_id,
              p.nome AS procedure_name,
              p.idEspecialidade AS specialty_id,
              p.quantidade AS quantity,
              a.id AS appointment_id,
              a.data AS appointment_date
          FROM
              nekt_raw.clinica_nas_nuvens_agenda a
              CROSS JOIN UNNEST(a.procedimentos) AS t(p)
          WHERE
              DATE(a.data) >= CURRENT_DATE - INTERVAL '30' DAY
      )
      SELECT
          e.nome AS specialty,
          tp.nome AS procedure_type,
          COUNT(DISTINCT pd.appointment_id) AS total_appointments,
          SUM(pd.quantity) AS total_procedures
      FROM
          procedure_data pd
          LEFT JOIN nekt_raw.clinica_nas_nuvens_especialidades e ON pd.specialty_id = e.id
          LEFT JOIN nekt_raw.clinica_nas_nuvens_tipo_procedimento tp ON pd.procedure_id = tp.id
      GROUP BY
          e.nome,
          tp.nome
      ORDER BY
          total_appointments DESC
      ```
    </Tab>

    <Tab title="GCP">
      ```sql theme={null}
      WITH procedure_data AS (
          SELECT
              p.id AS procedure_id,
              p.nome AS procedure_name,
              p.idEspecialidade AS specialty_id,
              p.quantidade AS quantity,
              a.id AS appointment_id,
              a.data AS appointment_date
          FROM
              `nekt_raw.clinica_nas_nuvens_agenda` a,
              UNNEST(a.procedimentos) AS p
          WHERE
              DATE(a.data) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
      )
      SELECT
          e.nome AS specialty,
          tp.nome AS procedure_type,
          COUNT(DISTINCT pd.appointment_id) AS total_appointments,
          SUM(pd.quantity) AS total_procedures
      FROM
          procedure_data pd
          LEFT JOIN `nekt_raw.clinica_nas_nuvens_especialidades` e ON pd.specialty_id = e.id
          LEFT JOIN `nekt_raw.clinica_nas_nuvens_tipo_procedimento` tp ON pd.procedure_id = tp.id
      GROUP BY
          e.nome,
          tp.nome
      ORDER BY
          total_appointments DESC
      ```
    </Tab>
  </Tabs>
</Accordion>

<Accordion title="Sample Result">
  | specialty    | procedure\_type       | total\_appointments | total\_procedures |
  | ------------ | --------------------- | ------------------- | ----------------- |
  | Dermatologia | Consulta              | 234                 | 234               |
  | Cardiologia  | Consulta              | 189                 | 189               |
  | Dermatologia | Procedimento Estético | 156                 | 312               |
  | Oftalmologia | Consulta              | 145                 | 145               |
  | Pediatria    | Consulta              | 123                 | 123               |
</Accordion>

## Implementation Notes

### Data Quality Considerations

* The `Agenda` stream uses the `start_date` configuration to filter appointments by date
* Patient records may have null values for optional contact and address fields
* Use the lookup tables (Cidades, Especialidades, etc.) to enrich your analyses with descriptive names

### Best Practices

* Always join with lookup tables to get descriptive names instead of just IDs
* Consider patient privacy when analyzing personal data

## Skills for agents

<Snippet file="agent-skills-intro.mdx" />

<Card title="Download Clínica nas Nuvens skills file" icon="wand-magic-sparkles" href="/sources/clinica-nas-nuvens.md">
  Clínica nas Nuvens connector documentation as plain markdown, for use in AI agent contexts.
</Card>
