Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/reports/screens/report-detail-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function fmtSupportLevel(
if (raw === "nivel_1") return t("reports.supportLevel1");
if (raw === "nivel_2") return t("reports.supportLevel2");
if (raw === "nivel_3") return t("reports.supportLevel3");
if (raw === "indefinido") return t("reports.supportLevelUndefined");
return raw;
}

Expand Down
1 change: 1 addition & 0 deletions features/reports/utils/export-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function fmtSupportLevel(raw: string | null, t: T): string {
if (raw === "nivel_1") return t("reports.supportLevel1");
if (raw === "nivel_2") return t("reports.supportLevel2");
if (raw === "nivel_3") return t("reports.supportLevel3");
if (raw === "indefinido") return t("reports.supportLevelUndefined");
return raw;
}

Expand Down
1 change: 1 addition & 0 deletions features/sessions/hooks/use-student-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function formatSupportLevel(level: string | null): string | null {
if (level === "nivel_1") return "Nível 1";
if (level === "nivel_2") return "Nível 2";
if (level === "nivel_3") return "Nível 3";
if (level === "indefinido") return "Indefinido";
return level;
}

Expand Down
1 change: 1 addition & 0 deletions features/sessions/hooks/use-student-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function useStudentSessions(studentId?: string, options?: UseStudentSessi
if (level === "nivel_1") return "Nível 1";
if (level === "nivel_2") return "Nível 2";
if (level === "nivel_3") return "Nível 3";
if (level === "indefinido") return "Indefinido";
return level;
};

Expand Down
9 changes: 9 additions & 0 deletions features/settings/constants/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ export type TranslationKey =
| "students.support.n1"
| "students.support.n2"
| "students.support.n3"
| "students.support.undefined"
| "students.deleteTitle"
| "students.form.createTitle"
| "students.form.editTitle"
Expand All @@ -615,6 +616,7 @@ export type TranslationKey =
| "students.form.supportOption1"
| "students.form.supportOption2"
| "students.form.supportOption3"
| "students.form.supportOptionUndefined"
| "students.form.healthConditions"
| "students.form.healthConditionsPlaceholder"
| "students.form.observations"
Expand Down Expand Up @@ -801,6 +803,7 @@ export type TranslationKey =
| "reports.supportLevel1"
| "reports.supportLevel2"
| "reports.supportLevel3"
| "reports.supportLevelUndefined"
| "export.selectFormat"
| "export.pdfWithCharts"
| "export.csvTabular"
Expand Down Expand Up @@ -1700,6 +1703,7 @@ export const translations: Record<Locale, Record<TranslationKey, string>> = {
"students.support.n1": "TEA nível 1",
"students.support.n2": "TEA nível 2",
"students.support.n3": "TEA nível 3",
"students.support.undefined": "TEA nível indefinido",
"students.deleteTitle": "Excluir aluno?",
"students.form.createTitle": "Novo aluno",
"students.form.editTitle": "Editar aluno",
Expand All @@ -1719,6 +1723,7 @@ export const translations: Record<Locale, Record<TranslationKey, string>> = {
"students.form.supportOption1": "Transtorno do Espectro Autista Nível 1",
"students.form.supportOption2": "Transtorno do Espectro Autista Nível 2",
"students.form.supportOption3": "Transtorno do Espectro Autista Nível 3",
"students.form.supportOptionUndefined": "Indefinido",
"students.form.healthConditions": "Outras condições de saúde",
"students.form.healthConditionsPlaceholder": "Outras condições de saúde (opcional)",
"students.form.observations": "Observações",
Expand Down Expand Up @@ -1916,6 +1921,7 @@ export const translations: Record<Locale, Record<TranslationKey, string>> = {
"reports.supportLevel1": "Nível 1",
"reports.supportLevel2": "Nível 2",
"reports.supportLevel3": "Nível 3",
"reports.supportLevelUndefined": "Indefinido",
"export.selectFormat": "Selecionar formato",
"export.pdfWithCharts": "PDF (com gráficos)",
"export.csvTabular": "CSV (dados tabulares)",
Expand Down Expand Up @@ -2812,6 +2818,7 @@ export const translations: Record<Locale, Record<TranslationKey, string>> = {
"students.support.n1": "ASD level 1",
"students.support.n2": "ASD level 2",
"students.support.n3": "ASD level 3",
"students.support.undefined": "ASD level undefined",
"students.deleteTitle": "Delete student?",
"students.form.createTitle": "New student",
"students.form.editTitle": "Edit student",
Expand All @@ -2831,6 +2838,7 @@ export const translations: Record<Locale, Record<TranslationKey, string>> = {
"students.form.supportOption1": "Autism Spectrum Disorder Level 1",
"students.form.supportOption2": "Autism Spectrum Disorder Level 2",
"students.form.supportOption3": "Autism Spectrum Disorder Level 3",
"students.form.supportOptionUndefined": "Undefined",
"students.form.healthConditions": "Other health conditions",
"students.form.healthConditionsPlaceholder": "Other health conditions (optional)",
"students.form.observations": "Notes",
Expand Down Expand Up @@ -3027,6 +3035,7 @@ export const translations: Record<Locale, Record<TranslationKey, string>> = {
"reports.supportLevel1": "Level 1",
"reports.supportLevel2": "Level 2",
"reports.supportLevel3": "Level 3",
"reports.supportLevelUndefined": "Undefined",
"export.selectFormat": "Select format",
"export.pdfWithCharts": "PDF (with charts)",
"export.csvTabular": "CSV (tabular data)",
Expand Down
1 change: 1 addition & 0 deletions features/students/components/new-student.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function NewStudent({
t("students.form.supportOption1"),
t("students.form.supportOption2"),
t("students.form.supportOption3"),
t("students.form.supportOptionUndefined"),
];

useEffect(() => {
Expand Down
18 changes: 7 additions & 11 deletions features/students/hooks/use-students.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { supabase } from "@/lib/supabase";
import { calculateAge } from "@/lib/date-utils";
import { toSupportLevelCode } from "@/features/students/utils/support-level";
import { useI18n } from "@/features/settings/contexts/i18n-context";
import { resolveEquipeId } from "@/lib/resolve-equipe-id";
import { uploadImage } from "@/lib/upload-image";
Expand Down Expand Up @@ -125,11 +126,13 @@ const loadStudents = useCallback(async (showLoader = true) => {
weight: Number(aluno.peso) || 0,
height: Number(aluno.altura) || 0,
waist: Number(aluno.cintura) || 0,
supportLevel:
supportLevel:
aluno.nivel_suporte === "nivel_1" ? "Nível 1"
: aluno.nivel_suporte === "nivel_2"
? "Nível 2"
: "Nível 3",
: aluno.nivel_suporte === "nivel_3"
? "Nível 3"
: "Indefinido",
healthConditions: aluno.diagnostico_detalhado || "",
observations: aluno.observacoes_clinicas || "",
avatarUrl: aluno.avatar_url,
Expand Down Expand Up @@ -188,10 +191,7 @@ const loadStudents = useCallback(async (showLoader = true) => {
: (await uploadImage("avatares", photoUri, "alunos")) ?? null;
}

let nivelSuporteDb = "nivel_1";
const supportLower = data.supportLevel.toLowerCase();
if (supportLower.includes("2")) nivelSuporteDb = "nivel_2";
if (supportLower.includes("3")) nivelSuporteDb = "nivel_3";
const nivelSuporteDb = toSupportLevelCode(data.supportLevel);

let formattedDate = data.birthDate;
if (formattedDate.includes("/")) {
Expand Down Expand Up @@ -271,11 +271,7 @@ const loadStudents = useCallback(async (showLoader = true) => {
}

if (data.supportLevel !== undefined) {
let nivelSuporteDb = "nivel_1";
const supportLower = data.supportLevel.toLowerCase();
if (supportLower.includes("2")) nivelSuporteDb = "nivel_2";
if (supportLower.includes("3")) nivelSuporteDb = "nivel_3";
payload.nivel_suporte = nivelSuporteDb;
payload.nivel_suporte = toSupportLevelCode(data.supportLevel);
}

if (data.birthDate !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion features/students/screens/students-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function StudentsScreen({ tutorial = false }: StudentsScreenProps) {
if (level.includes("1")) return t("students.support.n1");
if (level.includes("2")) return t("students.support.n2");
if (level.includes("3")) return t("students.support.n3");
return level;
return t("students.support.undefined");
};

const content = (
Expand Down
24 changes: 24 additions & 0 deletions features/students/utils/support-level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** A TEA support level as stored in `alunos.nivel_suporte`. */
export type SupportLevelCode = "nivel_1" | "nivel_2" | "nivel_3" | "indefinido";

/**
* Maps the support level shown in the UI back to the code the database stores.
*
* @param label - Any support level wording the app produces: a picked option
* ("Transtorno do Espectro Autista Nível 2"), a short display label
* ("Nível 2", "Indefinido") or the stored code itself ("nivel_2").
* @returns The matching code, or "indefinido" when no level can be identified.
*
* @remarks
* The level is identified by its digit — the only part every wording shares,
* in both locales and in the stored code. No wording of "Indefinido" carries a
* digit, so it doubles as the fallback: an unknown or empty support level is
* exactly an undefined one, and is now storable as such.
*/
export function toSupportLevelCode(label: string | null | undefined): SupportLevelCode {
const text = label ?? "";
if (text.includes("1")) return "nivel_1";
if (text.includes("2")) return "nivel_2";
if (text.includes("3")) return "nivel_3";
return "indefinido";
}
24 changes: 2 additions & 22 deletions features/teams/hooks/use-team-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { resolveEquipeId } from "@/lib/resolve-equipe-id";
import { supabase } from "@/lib/supabase";
import { calculateAge } from "@/lib/date-utils";
import { uploadImage } from "@/lib/upload-image";
import { toSupportLevelCode } from "@/features/students/utils/support-level";
import { useI18n } from "@/features/settings/contexts/i18n-context";
import { useEffect, useState } from "react";
import { Alert } from "react-native";
Expand Down Expand Up @@ -224,28 +225,7 @@ export function useTeamData() {
formattedDate = `${year}-${month}-${day}`;
}

let nivelSuporteDb = "nivel_1";
const suporteText = data.supportLevel?.toLowerCase() || "";

if (
suporteText.includes("nível 1") ||
suporteText.includes("nivel 1") ||
suporteText === "nivel_1"
) {
nivelSuporteDb = "nivel_1";
} else if (
suporteText.includes("nível 2") ||
suporteText.includes("nivel 2") ||
suporteText === "nivel_2"
) {
nivelSuporteDb = "nivel_2";
} else if (
suporteText.includes("nível 3") ||
suporteText.includes("nivel 3") ||
suporteText === "nivel_3"
) {
nivelSuporteDb = "nivel_3";
}
const nivelSuporteDb = toSupportLevelCode(data.supportLevel);

const basePayload = {
nome_completo: data.name,
Expand Down
18 changes: 18 additions & 0 deletions supabase/migrations/20260805120000_nivel_suporte_indefinido.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- =======================================================================
-- Migration: nível de suporte TEA passa a aceitar "Indefinido"
-- =======================================================================
-- Nem toda criança chega ao programa com o nível de suporte já definido em
-- laudo. Até aqui o cadastro obrigava a escolher entre os níveis 1, 2 e 3,
-- o que forçava o avaliador a chutar um nível — e o chute vira histórico
-- clínico. O ENUM ganha um valor explícito para esse caso.
--
-- A coluna alunos.nivel_suporte é NOT NULL, então "não sei ainda" não pode
-- ser representado por NULL: precisa ser um valor do próprio tipo.
--
-- Mudança puramente aditiva: nenhum registro existente é alterado e os três
-- níveis continuam válidos.

ALTER TYPE nivel_suporte_tea ADD VALUE IF NOT EXISTS 'indefinido';

COMMENT ON TYPE nivel_suporte_tea IS
'Nível de suporte TEA do aluno. "indefinido" cobre quem ainda não tem o nível determinado.';