AOSSIE-Org / AOSSIE-Org/NeuroTrack

BUG: Child mode onboarding saves wrong data to Supabase for phone, country, and guardian relation fields

Abierto
#215 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Dart
Estrellas
29
Forks
50
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

## 📌 Issue Overview

In the Patient App's Personal Details screen, selecting "For my child" mode causes three fields to be incorrectly mapped in the `getPersonalInfo` getter, silently corrupting every child-mode registration saved to Supabase.

- `guardianRelation` is assigned `guardianPhoneController.text` instead of `selectedRelation`. The dropdown value is captured but never read.
- `phoneNo` is hardcoded to `phoneController.text` (the adult controller), which is always empty in child mode.
- `country` always reads `selectedCountry` (adult picker). `selectedChildCountry` is set correctly by the child form but ignored in the getter.

Additionally, the Relation and Patient Gender dropdowns are plain `DropdownMenu` widgets, so `_formKey.currentState?.validate()` skips them entirely. A user can submit with no relation or gender selected and it passes silently.

## 🔍 Steps to Reproduce
1. Open the Patient App and sign in
2. On the Personal Details screen, select **For my child** from the "Assessment is for?" dropdown
3. Fill in child name, child age, select relation "Guardian", select gender "Male", enter guardian phone `+911234567890`, and pick a country e.g. India
4. Tap **Continue**
5. Check the `patient` table row in Supabase

## 🎯 Expected Behavior

| Field | Expected |
|---|---|
| `guardian_relation` | `"Guardian"` |
| `phone` | `"+911234567890"` |
| `country` | `"India"` |
| `gender` | `"Male"` |

## 🚨 Actual Behavior

| Field | Actual |
|---|---|
| `guardian_relation` | `"+911234567890"` (phone stored as relation) |
| `phone` | `""` (always empty in child mode) |
| `country` | `""` (always empty, child picker ignored) |
| `gender` | `""` (dropdown bypasses form validation) |

Root cause in `patient/lib/presentation/auth/personal_details_screen.dart`:
```dart
// guardianRelation gets the phone number, selectedRelation is never read
guardianRelation: isAssessmentForChild ? guardianPhoneController.text : phoneController.text,

// phoneNo always reads the adult controller, empty in child mode
phoneNo: phoneController.text,

// always reads adult country picker, selectedChildCountry is ignored
country: selectedCountry?.displayName ?? '',
```

## 📷 Screenshot

Not applicable. The corruption is in the data written to Supabase, not visible in the UI.

## 💡 Suggested Improvements

Fix the `getPersonalInfo` getter to branch correctly on `isAssessmentForChild`:
```dart
phoneNo: isAssessmentForChild ? guardianPhoneController.text : phoneController.text,
guardianRelation: isAssessmentForChild ? selectedRelation : '',
country: isAssessmentForChild
? selectedChildCountry?.displayName ?? ''
: selectedCountry?.displayName ?? '',
```

Add pre-submission checks for `selectedRelation` and `selectedChildGender` in the `onPressed` handler since they are `DropdownMenu` widgets and are skipped by `_formKey.currentState?.validate()`.

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.