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

# Encaminhamentos

> Contratos de solicitacao, paciente, exames, relatorio e notificacoes.

## Encaminhamentos

## Criar encaminhamento

```http theme={"system"}
POST /attendance-service/referrals
```

Headers adicionais:

```http theme={"system"}
request-id: {referralRequestId}
```

Body:

```ts theme={"system"}
type NewReferralInput = {
  patient: {
    document: string;
    anamnesis: string;
    birthDate: string;
    gender: string;
    complaint: string;
    name: string;
  };
  specialist: {
    id: string;
    profile: {
      specialty: {
        description: string;
      };
    };
  };
  institution: {
    id: string;
    unity: {
      id: string;
    };
  };
  type: InstitutionAllowedReferralTypes;
  anamnesisHistoryList: AnamnesisHistoryType[];
  referralRequestId?: string;
  inhssScore?: number;
  protocol?: unknown;
};
```

Resposta esperada:

```json theme={"system"}
{
  "id": "referral-id"
}
```

Observacao: arquivos de exames nao sao enviados junto nesse body. Apos criar o encaminhamento, o frontend envia cada arquivo sequencialmente para o endpoint de upload.

## Upload de exames

```http theme={"system"}
POST /attendance-service/referrals/{referralId}/exams/upload
```

Content-Type:

```http theme={"system"}
multipart/form-data
```

Campo:

```text theme={"system"}
exams: File
```

Limite por arquivo:

* `NEXT_PUBLIC_REFERRAL_EXAM_MAX_FILE_BYTES`, quando definido.
* senao `NEXT_PUBLIC_REFERRAL_EXAM_MAX_FILE_MB`.
* default: `20 MB`.

## Atualizar paciente

```http theme={"system"}
PUT /attendance-service/referrals/{referralId}
```

Body:

```ts theme={"system"}
type UpdatePatientInput = {
  name: string;
  document: string;
  birthDate: string;
  gender: string;
  complaint: string;
  anamnesis: string;
};
```

## Buscar encaminhamentos

```http theme={"system"}
GET /attendance-service/referrals{filters}
```

O parametro `filters` e montado pelo chamador e anexado diretamente na URL.

## Detalhe por referral

```http theme={"system"}
GET /institution-service/referrals/{referralId}
```

O retorno e tratado como `FirebaseReferral`, usado para dados do paciente, solicitante, especialista, especialidade, chat e atendimento.

## Criar avaliacao/relatorio medico

```http theme={"system"}
POST /attendance-service/referrals/{referralId}/medical-report
```

Body:

```ts theme={"system"}
type CreateReferralEvaluationInput = {
  conduct: string;
  hypothesis: string;
  notes?: string | null;
  medicalReportHistory?: Array<{
    hypothesis: string;
    conduct: string;
    notes: string;
    enhancedByAi: boolean;
    createdAt: Date;
  }>;
};
```

Apos concluir, a aplicacao tambem cria uma notificacao:

```http theme={"system"}
POST /notification-service/notification
```

Body resumido:

```json theme={"system"}
{
  "userId": "requester-id",
  "title": "Avaliacao Concluida",
  "description": "HTML com nome do especialista",
  "type": "FINISHED_REPORT",
  "app_name": "nextmed-web",
  "metadata": "{\"referralId\":\"...\"}"
}
```

## Marcar relatorio como visualizado

```http theme={"system"}
POST /attendance-service/referrals/{referralId}/report/update-viewing-status
```

## Instituicoes e unidades

```http theme={"system"}
POST /institution-service/health-unity/assign/{institutionId}/{userProfileId}
GET /institution-service/health-unity/{institutionId}
GET /institution-service/institutions/specialties/{institutionId}
```

Body de solicitacao de vinculo:

```json theme={"system"}
{
  "unitiesIds": ["unity-id"]
}
```
