Skip to content

Commit

Permalink
integrando tela de cadastro de paciente #85
Browse files Browse the repository at this point in the history
  • Loading branch information
iuryFilho committed Jan 20, 2025
1 parent 57ad7c0 commit b035759
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 91 deletions.
9 changes: 5 additions & 4 deletions backend/controllers/pacienteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const pacienteController = {
// Criar um paciente
async create(req, res) {
try {
const paciente = new Paciente(req.body);
await db.collection('paciente').add(paciente.toFirestore());
res.status(201).json({ message: 'Paciente criado com sucesso!' });
const paciente = new Paciente();
paciente.fromJson(req.body);
await db.collection('paciente').add(paciente.toFirestore());
res.status(201).json({ message: 'Paciente criado com sucesso!' });
} catch (error) {
res.status(500).json({ error: error.message });
res.status(500).json({ error: error.message });
}
},

Expand Down
5 changes: 1 addition & 4 deletions backend/model/Paciente.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class Paciente {
constructor(alergias, altura, cpf, data_nascimento, email, foto_perfil = '', nome, peso, sexo,
constructor(alergias, altura, cpf, data_nascimento, email, nome, peso, sexo,
circunferencia_abdominal, gordura_corporal, massa_muscular, preferencias, senha) {
this.alergias = alergias;
this.altura = altura;
this.cpf = cpf;
this.dt_nascimento = data_nascimento;
this.email = email;
this.foto_perfil = foto_perfil;
this.nome = nome;
this.peso = peso;
this.sexo = sexo;
Expand All @@ -25,7 +24,6 @@ class Paciente {
cpf: this.cpf,
dt_nascimento: this.dt_nascimento,
email: this.email,
foto_perfil: this.foto_perfil,
nome: this.nome,
peso: this.peso,
sexo: this.sexo,
Expand All @@ -43,7 +41,6 @@ class Paciente {
this.cpf = json.cpf || '';
this.dt_nascimento = json.dt_nascimento || '';
this.email = json.email || '';
this.foto_perfil = json.foto_perfil || '';
this.nome = json.nome || '';
this.peso = parseFloat(json.peso) || 0;
this.sexo = json.sexo || '';
Expand Down
215 changes: 148 additions & 67 deletions healthway_app/lib/screens_patient/signup_patient_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
final _circunferenciaAbdominalController = TextEditingController();
final _gorduraCorporalController = TextEditingController();
final _massaMuscularController = TextEditingController();
final _alergiasController = TextEditingController();
final _preferenciasController = TextEditingController();
final List<TextEditingController> _alergiasController = [];
final List<TextEditingController> _preferenciasController = [];
final _senhaController = TextEditingController();
final _confirmarSenhaController = TextEditingController();

Expand Down Expand Up @@ -77,14 +77,15 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
_buildTextField(_cpfController, 'CPF', Icons.badge,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
]),
],
maxLength: 11),
_buildDateField(),
_buildDropdownField(),
_buildMeasurementFields(),
_buildTextField(
_buildListField(
_alergiasController, 'Alergias', Icons.warning),
_buildTextField(_preferenciasController,
'Preferências Alimentares', Icons.restaurant),
_buildListField(_preferenciasController, 'Preferências',
Icons.restaurant),
_buildPasswordFields(),
SizedBox(height: 30),
ElevatedButton(
Expand Down Expand Up @@ -113,10 +114,75 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
);
}

Widget _buildListField(
List<TextEditingController> controllerList, String label, IconData icon) {
return Column(
children: [
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: controllerList.length,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.only(bottom: 10.0),
child: Row(
children: [
Expanded(
child: TextFormField(
controller: controllerList[index],
decoration: InputDecoration(
labelText: '$label ${index + 1}',
prefixIcon: Icon(icon, color: kPrimaryColor),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide.none,
),
filled: true,
fillColor: Colors.white,
labelStyle: TextStyle(color: kPrimaryColor),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
style: TextStyle(fontSize: 16),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor, preencha este campo';
}
return null;
},
),
),
IconButton(
icon: Icon(Icons.remove_circle, color: Colors.red),
onPressed: () {
setState(() {
controllerList.removeAt(index);
});
},
),
],
),
);
},
),
TextButton.icon(
onPressed: () {
setState(() {
controllerList.add(TextEditingController());
});
},
icon: Icon(Icons.add, color: kPrimaryColor),
label:
Text('Adicionar $label', style: TextStyle(color: kPrimaryColor)),
),
],
);
}

Widget _buildTextField(
TextEditingController controller, String label, IconData icon,
{TextInputType? keyboardType,
List<TextInputFormatter>? inputFormatters}) {
List<TextInputFormatter>? inputFormatters,
int? maxLength}) {
return Padding(
padding: EdgeInsets.only(bottom: 20.0),
child: TextFormField(
Expand All @@ -133,9 +199,14 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
labelStyle: TextStyle(color: kPrimaryColor),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
style: TextStyle(fontSize: 16),
style: TextStyle(
fontSize: 16, color: kTextColor, fontWeight: FontWeight.w500),
keyboardType: keyboardType,
inputFormatters: inputFormatters,
maxLength: maxLength,
buildCounter: (context,
{required currentLength, required isFocused, maxLength}) =>
null,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor, preencha este campo';
Expand Down Expand Up @@ -163,7 +234,8 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
labelStyle: TextStyle(color: kPrimaryColor),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
style: TextStyle(fontSize: 16),
style: TextStyle(
fontSize: 16, color: kTextColor, fontWeight: FontWeight.w500),
readOnly: true,
onTap: () async {
final pickedDate = await showDatePicker(
Expand Down Expand Up @@ -218,7 +290,8 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
labelStyle: TextStyle(color: kPrimaryColor),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
style: TextStyle(fontSize: 16, color: Colors.black),
style: TextStyle(
fontSize: 16, color: kTextColor, fontWeight: FontWeight.w500),
items: ['Masculino', 'Feminino', 'Outro']
.map((label) => DropdownMenuItem(
value: label,
Expand All @@ -241,53 +314,50 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
}

Widget _buildMeasurementFields() {
return Card(
elevation: 4,
color: Color(0xFFF0FAFB),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Medidas Corporais',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: kPrimaryColor),
),
SizedBox(height: 16),
Row(
children: [
Expanded(
child: _buildMeasurementField(
_alturaController, 'Altura (cm)', Icons.height)),
SizedBox(width: 16),
Expanded(
child: _buildMeasurementField(
_pesoController, 'Peso (kg)', Icons.fitness_center)),
],
),
SizedBox(height: 16),
_buildMeasurementField(_circunferenciaAbdominalController,
'Circunferência Abdominal (cm)', Icons.straighten),
SizedBox(height: 16),
Row(
return Padding(
padding: EdgeInsets.only(bottom: 20.0),
child: Card(
elevation: 4,
color: Color(0xFFF0FAFB),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: _buildMeasurementField(_gorduraCorporalController,
'Gordura Corporal (%)', Icons.percent)),
SizedBox(width: 16),
Expanded(
child: _buildMeasurementField(_massaMuscularController,
'Massa Muscular (kg)', Icons.fitness_center)),
Text(
'Medidas Corporais',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: kPrimaryColor),
),
SizedBox(height: 16),
Row(
children: [
Expanded(
child: _buildMeasurementField(
_alturaController, 'Altura (cm)', Icons.height)),
SizedBox(width: 16),
Expanded(
child: _buildMeasurementField(_pesoController,
'Peso (kg)', Icons.fitness_center)),
],
),
SizedBox(height: 16),
_buildMeasurementField(_circunferenciaAbdominalController,
'Circunferência Abdominal (cm)', Icons.straighten),
SizedBox(height: 16),
_buildMeasurementField(_gorduraCorporalController,
'Gordura Corporal (%)', Icons.percent),
SizedBox(height: 16),
_buildMeasurementField(_massaMuscularController,
'Massa Muscular (kg)', Icons.fitness_center),
],
),
],
),
),
);
),
));
}

Widget _buildMeasurementField(
Expand All @@ -307,8 +377,12 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
),
labelStyle: TextStyle(color: kPrimaryColor),
),
keyboardType: TextInputType.number,
style: TextStyle(fontSize: 16),
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'^\d*(\,|\.)?\d*')),
],
style: TextStyle(
fontSize: 16, color: kTextColor, fontWeight: FontWeight.w500),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Preencha este campo';
Expand Down Expand Up @@ -379,7 +453,8 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
labelStyle: TextStyle(color: kPrimaryColor),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
style: TextStyle(fontSize: 16),
style: TextStyle(
fontSize: 16, color: kTextColor, fontWeight: FontWeight.w500),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor, insira uma senha';
Expand Down Expand Up @@ -411,14 +486,16 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
cpf: _cpfController.text,
dataNascimento: DateFormat('dd/MM/yyyy').format(dataNascimento),
sexo: _sexo!,
altura: double.parse(_alturaController.text),
peso: double.parse(_pesoController.text),
circunferenciaAbdominal:
double.parse(_circunferenciaAbdominalController.text),
gorduraCorporal: double.parse(_gorduraCorporalController.text),
massaMuscular: double.parse(_massaMuscularController.text),
alergias: [],
preferencias: [],
altura: double.parse(_alturaController.text.replaceFirst(',', '.')),
peso: double.parse(_pesoController.text.replaceFirst(',', '.')),
circunferenciaAbdominal: double.parse(
_circunferenciaAbdominalController.text.replaceFirst(',', '.')),
gorduraCorporal: double.parse(
_gorduraCorporalController.text.replaceFirst(',', '.')),
massaMuscular: double.parse(
_massaMuscularController.text.replaceFirst(',', '.')),
alergias: _alergiasController.map((e) => e.text).toList(),
preferencias: _preferenciasController.map((e) => e.text).toList(),
senha: _senhaController.text,
));

Expand Down Expand Up @@ -451,8 +528,12 @@ class _CadastroPacienteScreenState extends State<CadastroPacienteScreen> {
_circunferenciaAbdominalController.dispose();
_gorduraCorporalController.dispose();
_massaMuscularController.dispose();
_alergiasController.dispose();
_preferenciasController.dispose();
for (var controller in _alergiasController) {
controller.dispose();
}
for (var controller in _preferenciasController) {
controller.dispose();
}
_senhaController.dispose();
_confirmarSenhaController.dispose();
super.dispose();
Expand Down
Loading

0 comments on commit b035759

Please sign in to comment.