From 60302c3ceee863c38b3710e41d74b2bc578ac247 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 4 Jun 2025 15:23:58 +0200 Subject: [PATCH] Add new mih text form field to Pat Prof: Details --- .../package_tools/patient_info.dart | 248 ++++++---- .../pat_profile/patient_add.dart | 422 +++++++++++------ .../pat_profile/patient_edit.dart | 444 +++++++++++------- 3 files changed, 674 insertions(+), 440 deletions(-) diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_info.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_info.dart index 310c4769..8bab62df 100644 --- a/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_info.dart +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_info.dart @@ -1,9 +1,10 @@ import 'package:flutter_speed_dial/flutter_speed_dial.dart'; import 'package:mzansi_innovation_hub/main.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_floating_menu.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart'; import 'package:mzansi_innovation_hub/mih_objects/app_user.dart'; import 'package:mzansi_innovation_hub/mih_objects/arguments.dart'; import 'package:mzansi_innovation_hub/mih_objects/patients.dart'; @@ -37,6 +38,7 @@ class _PatientInfoState extends State { final medAidController = TextEditingController(); final medMainMemController = TextEditingController(); final medAidCodeController = TextEditingController(); + final _formKey = GlobalKey(); double textFieldWidth = 400.0; late String medAid; @@ -45,53 +47,69 @@ class _PatientInfoState extends State { spacing: 15, runSpacing: 10, children: [ - SizedBox( + MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: idController, - hintText: "ID No.", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: idController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "ID No.", + // validator: (value) { + // return MihValidationServices().isEmpty(value); + // }, ), - SizedBox( + MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: fnameController, - hintText: "Name", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: fnameController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "First Name", ), - SizedBox( + MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: lnameController, - hintText: "Surname", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: lnameController, + multiLineInput: false, + requiredText: true, + hintText: "Surname", + readOnly: true, ), - SizedBox( + MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: cellController, - hintText: "Cell No.", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: cellController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Cell No.", ), - SizedBox( + MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: emailController, - hintText: "Email", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: emailController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Email", ), - SizedBox( + MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: addressController, - hintText: "Address", - editable: false, - required: false), + height: 100, + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: addressController, + multiLineInput: true, + requiredText: true, + readOnly: true, + hintText: "Address", ), ], ); @@ -99,14 +117,18 @@ class _PatientInfoState extends State { Widget getMedAidDetailsFields() { List medAidDet = []; - medAidDet.add(SizedBox( - width: textFieldWidth, - child: MIHTextField( - controller: medAidController, - hintText: "Medical Aid", - editable: false, - required: false), - )); + medAidDet.add( + MihTextFormField( + width: textFieldWidth, + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: medAidController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Medical Aid", + ), + ); bool req; if (medAid == "Yes") { req = true; @@ -116,64 +138,69 @@ class _PatientInfoState extends State { medAidDet.addAll([ Visibility( visible: req, - child: SizedBox( + child: MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: medMainMemController, - hintText: "Main Member", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: medMainMemController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Main Member", ), ), - //const SizedBox(height: 10.0), Visibility( visible: req, - child: SizedBox( + child: MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: medNoController, - hintText: "No.", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: medNoController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "No.", ), ), - //const SizedBox(height: 10.0), Visibility( visible: req, - child: SizedBox( + child: MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: medAidCodeController, - hintText: "Code", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: medAidCodeController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Code", ), ), - //const SizedBox(height: 10.0), Visibility( visible: req, - child: SizedBox( + child: MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: medNameController, - hintText: "Name", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: medNameController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Name", ), ), - //const SizedBox(height: 10.0), Visibility( visible: req, - child: SizedBox( + child: MihTextFormField( width: textFieldWidth, - child: MIHTextField( - controller: medSchemeController, - hintText: "Plan", - editable: false, - required: false), + fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: medSchemeController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Plan", ), ), - //), ]); return Wrap( spacing: 10, @@ -245,12 +272,35 @@ class _PatientInfoState extends State { MihSingleChildScroll( child: Column( children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - //crossAxisAlignment: , - children: [ - Text( - "Personal Details", + MihForm( + formKey: _formKey, + formFields: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + //crossAxisAlignment: , + children: [ + Text( + "Personal", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 25, + fontWeight: FontWeight.bold, + color: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + ), + ), + ]), + Divider( + color: MzanziInnovationHub.of(context)! + .theme + .secondaryColor()), + const SizedBox(height: 10), + getPatientDetailsField(), + const SizedBox(height: 10), + Center( + child: Text( + "Medical Aid", textAlign: TextAlign.center, style: TextStyle( fontSize: 25, @@ -260,25 +310,15 @@ class _PatientInfoState extends State { .secondaryColor(), ), ), - ]), - const SizedBox(height: 10), - getPatientDetailsField(), - const SizedBox(height: 10), - Text( - "Medical Aid Details", - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 25, - fontWeight: FontWeight.bold, - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), + ), + Divider( + color: MzanziInnovationHub.of(context)! + .theme + .secondaryColor()), + const SizedBox(height: 10), + getMedAidDetailsFields(), + ], ), - Divider( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10), - getMedAidDetailsFields(), ], ), ), diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_add.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_add.dart index 4b9fdc32..6887d697 100644 --- a/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_add.dart +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_add.dart @@ -1,14 +1,15 @@ import 'dart:convert'; import 'package:mzansi_innovation_hub/main.dart'; +import 'package:mzansi_innovation_hub/mih_apis/mih_validation_services.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_action.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_body.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_header.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_layout_builder.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; import 'package:mzansi_innovation_hub/mih_env/env.dart'; @@ -49,6 +50,7 @@ class _AddPatientState extends State { //late bool medRequired; final ValueNotifier medRequired = ValueNotifier(false); final FocusNode _focusNode = FocusNode(); + final _formKey = GlobalKey(); bool isFieldsFilled() { if (medRequired.value) { @@ -159,151 +161,268 @@ class _AddPatientState extends State { } Widget displayForm() { - return MihSingleChildScroll( + return SingleChildScrollView( child: Column( children: [ - Text( - "Personal Details", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 22.0, - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - Divider( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10.0), - MIHTextField( - controller: idController, - hintText: "13 digit ID Number or Passport", - editable: true, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: fnameController, - hintText: "First Name", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: lnameController, - hintText: "Last Name", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: cellController, - hintText: "Cell Number", - editable: true, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: emailController, - hintText: "Email", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: addressController, - hintText: "Address", - editable: true, - required: true, - ), - const SizedBox(height: 15.0), - Text( - "Medical Aid Details", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 22.0, - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - Divider( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10.0), - MIHDropdownField( - controller: medAidController, - hintText: "Medical Aid", - editable: true, - enableSearch: false, - // onSelect: (_) { - // isRequired(); - // }, - required: true, - dropdownOptions: const ["Yes", "No"], - ), - ValueListenableBuilder( - valueListenable: medRequired, - builder: (BuildContext context, bool value, Widget? child) { - return Visibility( - visible: value, - child: Column( - children: [ - const SizedBox(height: 10.0), - MIHDropdownField( - controller: medMainMemController, - hintText: "Main Member", - editable: value, - required: value, - enableSearch: false, - dropdownOptions: const ["Yes", "No"], + MihForm( + formKey: _formKey, + formFields: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Personal", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + color: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medNoController, - hintText: "Medical Aid No.", - editable: value, - required: value, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medAidCodeController, - hintText: "Medical Aid Code", - editable: value, - required: value, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medNameController, - hintText: "Medical Aid Name", - editable: value, - required: value, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medSchemeController, - hintText: "Medical Aid Plan", - editable: value, - required: value, - ), - ], - ), - ); - }, - ), - const SizedBox(height: 30.0), - MihButton( - onPressed: () { - submitForm(); - }, - buttonColor: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 300, - child: Text( - "Add", - style: TextStyle( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontSize: 20, - fontWeight: FontWeight.bold, + ), + ], ), - ), + Divider( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: idController, + multiLineInput: false, + requiredText: true, + hintText: "ID No.", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: fnameController, + multiLineInput: false, + requiredText: true, + hintText: "First Name", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: lnameController, + multiLineInput: false, + requiredText: true, + hintText: "Surname", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: cellController, + multiLineInput: false, + requiredText: true, + hintText: "Cell No.", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: emailController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Email", + validator: (value) { + return MihValidationServices().validateEmail(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + height: 100, + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: addressController, + multiLineInput: true, + requiredText: true, + hintText: "Address", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 15.0), + Center( + child: Text( + "Medical Aid Details", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + ), + Divider( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10.0), + MIHDropdownField( + controller: medAidController, + hintText: "Medical Aid", + editable: true, + required: true, + enableSearch: false, + dropdownOptions: const ["Yes", "No"], + ), + ValueListenableBuilder( + valueListenable: medRequired, + builder: (BuildContext context, bool value, Widget? child) { + return Visibility( + visible: value, + child: Column( + children: [ + const SizedBox(height: 10.0), + MIHDropdownField( + controller: medMainMemController, + hintText: "Main Member", + editable: value, + required: value, + enableSearch: false, + dropdownOptions: const ["Yes", "No"], + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medNoController, + multiLineInput: false, + requiredText: true, + hintText: "No.", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medAidCodeController, + multiLineInput: false, + requiredText: true, + hintText: "Code", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medNameController, + multiLineInput: false, + requiredText: true, + hintText: "Name", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medSchemeController, + multiLineInput: false, + requiredText: true, + hintText: "Plan", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + ], + ), + ); + }, + ), + const SizedBox(height: 20.0), + Center( + child: MihButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + submitForm(); + } + }, + buttonColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + width: 300, + child: Text( + "Add", + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + const SizedBox(height: 20.0), + ], ), ], ), @@ -311,16 +430,7 @@ class _AddPatientState extends State { } void submitForm() { - if (isFieldsFilled()) { - addPatientAPICall(); - } else { - showDialog( - context: context, - builder: (context) { - return const MIHErrorMessage(errorType: "Input Error"); - }, - ); - } + addPatientAPICall(); } MIHAction getActionButton() { @@ -350,7 +460,7 @@ class _AddPatientState extends State { MIHBody getBody() { return MIHBody( - borderOn: true, + borderOn: false, bodyItems: [ KeyboardListener( focusNode: _focusNode, @@ -358,7 +468,9 @@ class _AddPatientState extends State { onKeyEvent: (event) async { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) { - submitForm(); + if (_formKey.currentState!.validate()) { + submitForm(); + } } }, child: displayForm(), diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_edit.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_edit.dart index 81ad520a..540fb055 100644 --- a/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_edit.dart +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/patient_edit.dart @@ -1,13 +1,15 @@ import 'dart:convert'; import 'package:mzansi_innovation_hub/main.dart'; +import 'package:mzansi_innovation_hub/mih_apis/mih_validation_services.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_action.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_body.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_header.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_layout_builder.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart'; +import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; import 'package:mzansi_innovation_hub/mih_env/env.dart'; @@ -49,6 +51,7 @@ class _EditPatientState extends State { final docOfficeIdApiUrl = "${AppEnviroment.baseApiUrl}/users/profile/"; final apiUrlEdit = "${AppEnviroment.baseApiUrl}/patients/update/"; final apiUrlDelete = "${AppEnviroment.baseApiUrl}/patients/delete/"; + final _formKey = GlobalKey(); late int futureDocOfficeId; late String userEmail; @@ -375,196 +378,273 @@ class _EditPatientState extends State { return SingleChildScrollView( child: Column( children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Personal Details", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 22.0, + MihForm( + formKey: _formKey, + formFields: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Personal", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + color: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + ), + ), + ], + ), + Divider( color: + MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: idController, + multiLineInput: false, + requiredText: true, + hintText: "ID No.", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: fnameController, + multiLineInput: false, + requiredText: true, + hintText: "First Name", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: lnameController, + multiLineInput: false, + requiredText: true, + hintText: "Surname", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: cellController, + multiLineInput: false, + requiredText: true, + hintText: "Cell No.", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: emailController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Email", + validator: (value) { + return MihValidationServices().validateEmail(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + height: 100, + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: addressController, + multiLineInput: true, + requiredText: true, + hintText: "Address", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 15.0), + Center( + child: Text( + "Medical Aid Details", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + ), + Divider( + color: + MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10.0), + MIHDropdownField( + controller: medAidController, + hintText: "Medical Aid", + editable: true, + required: true, + enableSearch: false, + dropdownOptions: const ["Yes", "No"], + ), + ValueListenableBuilder( + valueListenable: medRequired, + builder: (BuildContext context, bool value, Widget? child) { + return Visibility( + visible: value, + child: Column( + children: [ + const SizedBox(height: 10.0), + MIHDropdownField( + controller: medMainMemController, + hintText: "Main Member", + editable: value, + required: value, + enableSearch: false, + dropdownOptions: const ["Yes", "No"], + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medNoController, + multiLineInput: false, + requiredText: true, + hintText: "No.", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medAidCodeController, + multiLineInput: false, + requiredText: true, + hintText: "Code", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medNameController, + multiLineInput: false, + requiredText: true, + hintText: "Name", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: MzanziInnovationHub.of(context)! + .theme + .secondaryColor(), + inputColor: MzanziInnovationHub.of(context)! + .theme + .primaryColor(), + controller: medSchemeController, + multiLineInput: false, + requiredText: true, + hintText: "Plan", + validator: (validationValue) { + if (value) { + return MihValidationServices() + .isEmpty(validationValue); + } + return null; + }, + ), + const SizedBox(height: 10.0), + ], + ), + ); + }, + ), + const SizedBox(height: 20.0), + Center( + child: MihButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + submitForm(); + } + }, + buttonColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + width: 300, + child: Text( + "Update", + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), ), ), - // IconButton( - // icon: const Icon(Icons.delete), - // color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - // //alignment: Alignment.topRight, - // onPressed: () { - // deletePatientPopUp(); - // }, - // ), + const SizedBox(height: 20.0), ], ), - Divider( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10.0), - MIHTextField( - controller: idController, - hintText: "13 digit ID Number or Passport", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: fnameController, - hintText: "First Name", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: lnameController, - hintText: "Last Name", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: cellController, - hintText: "Cell Number", - editable: true, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: emailController, - hintText: "Email", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: addressController, - hintText: "Address", - editable: true, - required: true, - ), - const SizedBox(height: 15.0), - Text( - "Medical Aid Details", - textAlign: TextAlign.center, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 22.0, - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - Divider( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10.0), - MIHDropdownField( - controller: medAidController, - hintText: "Medical Aid", - // onSelect: (selected) { - // if (selected == "Yes") { - // setState(() { - // medRequired = true; - // }); - // } else { - // setState(() { - // medRequired = false; - // }); - // } - // }, - editable: true, - required: true, - enableSearch: false, - dropdownOptions: const ["Yes", "No"], - ), - ValueListenableBuilder( - valueListenable: medRequired, - builder: (BuildContext context, bool value, Widget? child) { - return Visibility( - visible: value, - child: Column( - children: [ - const SizedBox(height: 10.0), - MIHDropdownField( - controller: medMainMemController, - hintText: "Main Member.", - editable: value, - required: value, - enableSearch: false, - dropdownOptions: const ["Yes", "No"], - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medNoController, - hintText: "Medical Aid No.", - editable: value, - required: value, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medAidCodeController, - hintText: "Medical Aid Code", - editable: value, - required: value, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medNameController, - hintText: "Medical Aid Name", - editable: value, - required: value, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: medSchemeController, - hintText: "Medical Aid Plan", - editable: value, - required: value, - ), - ], - ), - ); - }, - ), - const SizedBox(height: 30.0), - MihButton( - onPressed: () { - submitForm(); - }, - buttonColor: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 300, - child: Text( - "Update", - style: TextStyle( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ), ], ), ); } void submitForm() { - if (isFieldsFilled()) { - if (!medRequired.value) { - setState(() { - medMainMemController.text = ""; - medNoController.text = ""; - medAidCodeController.text = ""; - medNameController.text = ""; - medSchemeController.text = ""; - }); - } - updatePatientApiCall(); - } else { - showDialog( - context: context, - builder: (context) { - return const MIHErrorMessage(errorType: "Input Error"); - }, - ); - } + updatePatientApiCall(); } MIHAction getActionButton() { @@ -594,7 +674,7 @@ class _EditPatientState extends State { MIHBody getBody() { return MIHBody( - borderOn: true, + borderOn: false, bodyItems: [ KeyboardListener( focusNode: _focusNode, @@ -602,7 +682,9 @@ class _EditPatientState extends State { onKeyEvent: (event) async { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) { - submitForm(); + if (_formKey.currentState!.validate()) { + submitForm(); + } } }, child: displayForm(),