From 39052c178d1ad8ed68f861b02daa9b21659359d0 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Wed, 4 Jun 2025 15:31:09 +0200 Subject: [PATCH] Add new mih text form field to Pat Prof: Consultations --- .../list_builders/build_notes_list.dart | 62 +++-- .../package_tools/patient_consultation.dart | 213 ++++++++++-------- 2 files changed, 161 insertions(+), 114 deletions(-) diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart index 77c15290..94dc7368 100644 --- a/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/list_builders/build_notes_list.dart @@ -2,9 +2,8 @@ import 'dart:convert'; 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_multiline_text_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_package_components/mih_package_window.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_delete_message.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'; @@ -148,7 +147,7 @@ class _BuildNotesListState extends State { color: MzanziInnovationHub.of(context)!.theme.primaryColor(), ), - label: "Delete Document", + label: "Delete Note", labelBackgroundColor: MzanziInnovationHub.of(context)!.theme.successColor(), labelStyle: TextStyle( @@ -170,43 +169,62 @@ class _BuildNotesListState extends State { windowBody: Column( children: [ const SizedBox(height: 10.0), - MIHTextField( + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), controller: businessNameController, + multiLineInput: false, + requiredText: true, + readOnly: true, hintText: "Office", - editable: false, - required: false, ), const SizedBox(height: 10.0), - MIHTextField( + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), controller: userNameController, + multiLineInput: false, + requiredText: true, + readOnly: true, hintText: "Created By", - editable: false, - required: false, ), const SizedBox(height: 10.0), - MIHTextField( + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), controller: dateController, + multiLineInput: false, + requiredText: true, + readOnly: true, hintText: "Created Date", - editable: false, - required: false, ), const SizedBox(height: 10.0), - MIHTextField( + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), controller: noteTitleController, + multiLineInput: false, + requiredText: true, + readOnly: true, hintText: "Note Title", - editable: false, - required: false, ), const SizedBox(height: 10.0), - SizedBox( + MihTextFormField( height: 250, - child: MIHMLTextField( - controller: noteTextController, - hintText: "Note Details", - editable: false, - required: false, - ), + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: noteTextController, + multiLineInput: true, + requiredText: true, + readOnly: true, + hintText: "Note Details", ), + const SizedBox(height: 10.0), ], ), ), diff --git a/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_consultation.dart b/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_consultation.dart index f07237e6..1e4f0368 100644 --- a/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_consultation.dart +++ b/Frontend/lib/mih_packages/patient_profile/pat_profile/package_tools/patient_consultation.dart @@ -1,13 +1,14 @@ import 'dart:convert'; 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_multiline_text_input.dart'; -import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart'; +import 'package:mzansi_innovation_hub/mih_apis/mih_validation_services.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_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_package_window.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_loading_circle.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart'; @@ -51,6 +52,7 @@ class _PatientConsultationState extends State { final doctorController = TextEditingController(); final ValueNotifier _counter = ValueNotifier(0); String endpoint = "${AppEnviroment.baseApiUrl}/notes/patients/"; + final _formKey = GlobalKey(); Future> fetchNotes(String endpoint) async { final response = await http.get(Uri.parse( @@ -94,97 +96,124 @@ class _PatientConsultationState extends State { }, windowBody: Column( children: [ - MIHTextField( - controller: officeController, - hintText: "Office", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: doctorController, - hintText: "Created By", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: dateController, - hintText: "Created Date", - editable: false, - required: true, - ), - const SizedBox(height: 10.0), - MIHTextField( - controller: titleController, - hintText: "Note Title", - editable: true, - required: true, - ), - const SizedBox(height: 10.0), - SizedBox( - //width: 700, - height: 250, - child: MIHMLTextField( - controller: noteTextController, - hintText: "Note Details", - editable: true, - required: true, - ), - ), - SizedBox( - height: 15, - child: ValueListenableBuilder( - builder: (BuildContext context, int value, Widget? child) { - return Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text( - "$value", - style: TextStyle( - color: getNoteDetailLimitColor(), - ), - ), - const SizedBox(width: 5), - Text( - "/512", - style: TextStyle( - color: getNoteDetailLimitColor(), - ), - ), - ], - ); - }, - valueListenable: _counter, - ), - ), - const SizedBox(height: 15.0), - MihButton( - onPressed: () { - if (isFieldsFilled()) { - addPatientNoteAPICall(); - Navigator.pop(context); - } else { - showDialog( - context: context, - builder: (context) { - return const MIHErrorMessage(errorType: "Input Error"); - }, - ); - } - }, - buttonColor: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 300, - child: Text( - "Add Note", - style: TextStyle( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - fontSize: 20, - fontWeight: FontWeight.bold, + MihForm( + formKey: _formKey, + formFields: [ + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: officeController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Office", ), - ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: doctorController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Created By", + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: dateController, + multiLineInput: false, + requiredText: true, + readOnly: true, + hintText: "Created Date", + ), + const SizedBox(height: 10.0), + MihTextFormField( + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: titleController, + multiLineInput: false, + requiredText: true, + hintText: "Note Title", + validator: (value) { + return MihValidationServices().isEmpty(value); + }, + ), + const SizedBox(height: 10.0), + MihTextFormField( + height: 250, + fillColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + inputColor: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + controller: noteTextController, + multiLineInput: true, + requiredText: true, + hintText: "Note Details", + validator: (value) { + return MihValidationServices().validateLength(value, 512); + }, + ), + SizedBox( + height: 15, + child: ValueListenableBuilder( + builder: (BuildContext context, int value, Widget? child) { + return Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + "$value", + style: TextStyle( + color: getNoteDetailLimitColor(), + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(width: 5), + Text( + "/512", + style: TextStyle( + color: getNoteDetailLimitColor(), + fontWeight: FontWeight.bold, + ), + ), + ], + ); + }, + valueListenable: _counter, + ), + ), + const SizedBox(height: 15.0), + MihButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + addPatientNoteAPICall(); + Navigator.pop(context); + } + }, + buttonColor: + MzanziInnovationHub.of(context)!.theme.secondaryColor(), + width: 300, + child: Text( + "Add Note", + style: TextStyle( + color: + MzanziInnovationHub.of(context)!.theme.primaryColor(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ), + ], ), ], ),