diff --git a/Frontend/patient_manager/lib/components/mybutton.dart b/Frontend/patient_manager/lib/components/mybutton.dart index 5d20039f..e7753b24 100644 --- a/Frontend/patient_manager/lib/components/mybutton.dart +++ b/Frontend/patient_manager/lib/components/mybutton.dart @@ -8,23 +8,22 @@ class MyButton extends StatelessWidget { @override Widget build(BuildContext context) { - return GestureDetector( - onTap: onTap, - child: Container( - padding: const EdgeInsets.all(25), - margin: const EdgeInsets.symmetric(horizontal: 25), - decoration: BoxDecoration( - color: Colors.blueAccent, - borderRadius: BorderRadius.circular(10), + return Padding( + padding: const EdgeInsets.all(25.0), + child: ElevatedButton( + onPressed: onTap, + style: ElevatedButton.styleFrom( + backgroundColor: Colors.blueAccent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0), + ), ), - child: Center( - child: Text( - buttonText, - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - color: Colors.white, - ), + child: Text( + buttonText, + style: const TextStyle( + //fontWeight: FontWeight.bold, + fontSize: 20, + color: Colors.white, ), ), ), diff --git a/Frontend/patient_manager/lib/main.dart b/Frontend/patient_manager/lib/main.dart index 655e95f5..fde87ca6 100644 --- a/Frontend/patient_manager/lib/main.dart +++ b/Frontend/patient_manager/lib/main.dart @@ -20,7 +20,7 @@ class MzanziInnovationHub extends StatelessWidget { @override Widget build(BuildContext context) { return const MaterialApp( - title: 'Mzanzi Innovation Hub', + title: 'Mzansi Innovation Hub', themeMode: ThemeMode.system, debugShowCheckedModeBanner: false, initialRoute: '/', diff --git a/Frontend/patient_manager/lib/objects/AppUser.dart b/Frontend/patient_manager/lib/objects/AppUser.dart new file mode 100644 index 00000000..e48058b0 --- /dev/null +++ b/Frontend/patient_manager/lib/objects/AppUser.dart @@ -0,0 +1,15 @@ +class AppUser { + final int idusers; + final String email; + final int docOffice_id; + + const AppUser( + this.idusers, + this.email, + this.docOffice_id, + ); + + factory AppUser.fromJson(dynamic json) { + return AppUser(json['idusers'], json['email'], json['docOffice_id']); + } +} diff --git a/Frontend/patient_manager/lib/pages/home.dart b/Frontend/patient_manager/lib/pages/home.dart index a5dcd873..a1b5f2cf 100644 --- a/Frontend/patient_manager/lib/pages/home.dart +++ b/Frontend/patient_manager/lib/pages/home.dart @@ -37,7 +37,7 @@ class _HomeState extends State { builder: (contexts, snapshot) { if (snapshot.connectionState == ConnectionState.done) { return Scaffold( - appBar: const MyAppBar(barTitle: "Mzanzi Innovation Hub"), + appBar: const MyAppBar(barTitle: "Mzansi Innovation Hub"), drawer: MyAppDrawer( drawerTitle: useremail, ), diff --git a/Frontend/patient_manager/lib/pages/patientAdd.dart b/Frontend/patient_manager/lib/pages/patientAdd.dart new file mode 100644 index 00000000..2c4a78f3 --- /dev/null +++ b/Frontend/patient_manager/lib/pages/patientAdd.dart @@ -0,0 +1,250 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:patient_manager/components/myTextInput.dart'; +import 'package:patient_manager/components/mybutton.dart'; +import '../components/myAppBar.dart'; +import 'package:http/http.dart' as http; +import '../objects/AppUser.dart'; + +class AddPatient extends StatefulWidget { + final String userEmail; + + const AddPatient({ + super.key, + required this.userEmail, + }); + + @override + State createState() => _AddPatientState(); +} + +class _AddPatientState extends State { + final idController = TextEditingController(); + final fnameController = TextEditingController(); + final lnameController = TextEditingController(); + final cellController = TextEditingController(); + final emailController = TextEditingController(); + final medNoController = TextEditingController(); + final medNameController = TextEditingController(); + final medSchemeController = TextEditingController(); + final addressController = TextEditingController(); + final docOfficeIdApiUrl = "http://localhost:80/docOffices/user/"; + final apiUrl = "http://localhost:80/patients/insert/"; + late int futureDocOfficeId; + + Future getOfficeIdByUser(String endpoint) async { + print("here1.1"); + final response = await http.get(Uri.parse(endpoint)); + print("here1.2"); + if (response.statusCode == 200) { + print("here1.3"); + String body = response.body; + print(body); + print("here1.4"); + var decodedData = jsonDecode(body); + print("here1.5"); + AppUser u = AppUser.fromJson(decodedData as Map); + print("here1.6"); + setState(() { + futureDocOfficeId = u.docOffice_id; + //print(futureDocOfficeId); + }); + } else { + throw Exception('failed to load patients'); + } + } + + Future addPatientAPICall() async { + print("here1"); + await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail); + print(futureDocOfficeId.toString()); + print("here2"); + var response = await http.post( + Uri.parse(apiUrl), + headers: { + "Content-Type": "application/json; charset=UTF-8" + }, + body: jsonEncode({ + "id_no": idController.text, + "first_name": fnameController.text, + "last_name": lnameController.text, + "email": emailController.text, + "cell_no": cellController.text, + "medical_aid_name": medNameController.text, + "medical_aid_no": medNoController.text, + "medical_aid_scheme": medSchemeController.text, + "address": addressController.text, + "doc_office_id": futureDocOfficeId, + }), + ); + print("here3"); + if (response.statusCode == 201) { + Navigator.of(context) + .pushNamed('/patient-manager', arguments: widget.userEmail); + messagePopUp(fnameController.text + + " " + + lnameController.text + + " Successfully added"); + } else { + messagePopUp("error"); + } + } + + void messagePopUp(error) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text(error), + ); + }, + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: const MyAppBar(barTitle: "Add Patient"), + body: Padding( + padding: const EdgeInsets.all(15.0), + child: SingleChildScrollView( + child: Column( + children: [ + const Text( + "Personal Details", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + //color: Colors.blueAccent, + ), + ), + Row( + children: [ + Expanded( + child: MyTextField( + controller: idController, + hintText: "13 digit ID Number or Passport"), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: fnameController, + hintText: "First Name", + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: lnameController, + hintText: "Last Name", + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: cellController, + hintText: "Cell Number", + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: emailController, + hintText: "Email", + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: addressController, + hintText: "Address", + ), + ), + ], + ), + const SizedBox(height: 15.0), + const Text( + "Medical Aid Details", + textAlign: TextAlign.center, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 25.0, + //color: Colors.blueAccent, + ), + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: medNoController, + hintText: "Medical Aid No.", + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: medNameController, + hintText: "Medical Aid Name", + ), + ), + ], + ), + const SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: MyTextField( + controller: medSchemeController, + hintText: "Medical Aid Scheme", + ), + ), + ], + ), + //const SizedBox(height: 10.0), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: 500.0, + height: 100.0, + child: MyButton( + onTap: addPatientAPICall, + buttonText: "Add", + ), + ), + ], + ), + ], + ), + ), + ), + ); + } +} diff --git a/Frontend/patient_manager/lib/pages/patientManager.dart b/Frontend/patient_manager/lib/pages/patientManager.dart index 2dd7c99a..707c19d6 100644 --- a/Frontend/patient_manager/lib/pages/patientManager.dart +++ b/Frontend/patient_manager/lib/pages/patientManager.dart @@ -53,14 +53,21 @@ class _PatientManagerState extends State { //floatingActionButtonLocation: FloatingActionButtonLocation.endTop, floatingActionButton: FloatingActionButton.extended( label: const Text( - "Create", + "Add Patient", style: TextStyle( fontWeight: FontWeight.bold, + color: Colors.white, ), ), backgroundColor: Colors.blueAccent, - onPressed: () {}, - icon: const Icon(Icons.add), + onPressed: () { + Navigator.of(context) + .pushNamed('/patient-manager/add', arguments: widget.userEmail); + }, + icon: const Icon( + Icons.add, + color: Colors.white, + ), ), body: FutureBuilder( future: futurePatients, diff --git a/Frontend/patient_manager/lib/pages/patientView.dart b/Frontend/patient_manager/lib/pages/patientView.dart index 55d0f760..bff96338 100644 --- a/Frontend/patient_manager/lib/pages/patientView.dart +++ b/Frontend/patient_manager/lib/pages/patientView.dart @@ -17,25 +17,27 @@ class _PatientViewState extends State { Widget build(BuildContext context) { return Scaffold( appBar: const MyAppBar(barTitle: "Patient View"), - body: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), - child: Column( - children: [ - PatientDetails(selectedPatient: widget.selectedPatient), - const SizedBox( - height: 10.0, - ), - Row( - children: [ - PatientNotes( - patientIndex: widget.selectedPatient.idpatients, - ), - PatientNotes( - patientIndex: widget.selectedPatient.idpatients, - ) - ], - ) - ], + body: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), + child: Column( + children: [ + PatientDetails(selectedPatient: widget.selectedPatient), + const SizedBox( + height: 10.0, + ), + Row( + children: [ + PatientNotes( + patientIndex: widget.selectedPatient.idpatients, + ), + PatientNotes( + patientIndex: widget.selectedPatient.idpatients, + ) + ], + ) + ], + ), ), ), ); diff --git a/Frontend/patient_manager/lib/pages/signin.dart b/Frontend/patient_manager/lib/pages/signin.dart index 8b092011..289d7c51 100644 --- a/Frontend/patient_manager/lib/pages/signin.dart +++ b/Frontend/patient_manager/lib/pages/signin.dart @@ -96,26 +96,10 @@ class _SignInState extends State { ), //spacer const SizedBox(height: 10), - // forgot password - const Padding( - padding: EdgeInsets.symmetric(horizontal: 25.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text( - 'Forgot Password?', - style: TextStyle( - color: Colors.white, - ), - ), - ], - ), - ), - //spacer - const SizedBox(height: 50), // sign in button SizedBox( width: 500.0, + height: 100.0, child: MyButton( onTap: signUserIn, buttonText: "Sign In", diff --git a/Frontend/patient_manager/lib/router/routeGenerator.dart b/Frontend/patient_manager/lib/router/routeGenerator.dart index facb67e8..3cafda8e 100644 --- a/Frontend/patient_manager/lib/router/routeGenerator.dart +++ b/Frontend/patient_manager/lib/router/routeGenerator.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:patient_manager/Authentication/authCheck.dart'; import 'package:patient_manager/components/myAppBar.dart'; +import 'package:patient_manager/pages/patientAdd.dart'; import 'package:patient_manager/components/signInOrRegister.dart'; import 'package:patient_manager/objects/patients.dart'; import 'package:patient_manager/pages/home.dart'; @@ -26,6 +27,15 @@ class RouteGenerator { ); } return _errorRoute(); + case '/patient-manager/add': + if (args is String) { + return MaterialPageRoute( + builder: (_) => AddPatient( + userEmail: args, + ), + ); + } + return _errorRoute(); case '/patient-manager/patient': if (args is Patient) { return MaterialPageRoute( diff --git a/database/#ib_16384_0.dblwr b/database/#ib_16384_0.dblwr index b579d058..ea04f780 100644 Binary files a/database/#ib_16384_0.dblwr and b/database/#ib_16384_0.dblwr differ diff --git a/database/#innodb_redo/#ib_redo10 b/database/#innodb_redo/#ib_redo10 index f253b739..59d1780f 100644 Binary files a/database/#innodb_redo/#ib_redo10 and b/database/#innodb_redo/#ib_redo10 differ diff --git a/database/binlog.000014 b/database/binlog.000014 index 6e051dd1..4892af23 100644 Binary files a/database/binlog.000014 and b/database/binlog.000014 differ diff --git a/database/ibdata1 b/database/ibdata1 index 04d37903..20f9dada 100644 Binary files a/database/ibdata1 and b/database/ibdata1 differ diff --git a/database/mysql.ibd b/database/mysql.ibd index cfedbf92..495bccd9 100644 Binary files a/database/mysql.ibd and b/database/mysql.ibd differ diff --git a/database/patient_manager/patients.ibd b/database/patient_manager/patients.ibd index 4e1a61a0..95e174c7 100644 Binary files a/database/patient_manager/patients.ibd and b/database/patient_manager/patients.ibd differ diff --git a/database/undo_001 b/database/undo_001 index 92e309e1..8fd87f11 100644 Binary files a/database/undo_001 and b/database/undo_001 differ diff --git a/database/undo_002 b/database/undo_002 index 15f44b34..6c421e29 100644 Binary files a/database/undo_002 and b/database/undo_002 differ