AppUser object created. Add patient page with API call added nd completed
This commit is contained in:
@@ -8,26 +8,25 @@ class MyButton extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return Padding(
|
||||||
onTap: onTap,
|
padding: const EdgeInsets.all(25.0),
|
||||||
child: Container(
|
child: ElevatedButton(
|
||||||
padding: const EdgeInsets.all(25),
|
onPressed: onTap,
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 25),
|
style: ElevatedButton.styleFrom(
|
||||||
decoration: BoxDecoration(
|
backgroundColor: Colors.blueAccent,
|
||||||
color: Colors.blueAccent,
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(12.0),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
|
||||||
child: Text(
|
child: Text(
|
||||||
buttonText,
|
buttonText,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
//fontWeight: FontWeight.bold,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class MzanziInnovationHub extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const MaterialApp(
|
return const MaterialApp(
|
||||||
title: 'Mzanzi Innovation Hub',
|
title: 'Mzansi Innovation Hub',
|
||||||
themeMode: ThemeMode.system,
|
themeMode: ThemeMode.system,
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
initialRoute: '/',
|
initialRoute: '/',
|
||||||
|
|||||||
15
Frontend/patient_manager/lib/objects/AppUser.dart
Normal file
15
Frontend/patient_manager/lib/objects/AppUser.dart
Normal file
@@ -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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ class _HomeState extends State<Home> {
|
|||||||
builder: (contexts, snapshot) {
|
builder: (contexts, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const MyAppBar(barTitle: "Mzanzi Innovation Hub"),
|
appBar: const MyAppBar(barTitle: "Mzansi Innovation Hub"),
|
||||||
drawer: MyAppDrawer(
|
drawer: MyAppDrawer(
|
||||||
drawerTitle: useremail,
|
drawerTitle: useremail,
|
||||||
),
|
),
|
||||||
|
|||||||
250
Frontend/patient_manager/lib/pages/patientAdd.dart
Normal file
250
Frontend/patient_manager/lib/pages/patientAdd.dart
Normal file
@@ -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<AddPatient> createState() => _AddPatientState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AddPatientState extends State<AddPatient> {
|
||||||
|
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<String, dynamic>);
|
||||||
|
print("here1.6");
|
||||||
|
setState(() {
|
||||||
|
futureDocOfficeId = u.docOffice_id;
|
||||||
|
//print(futureDocOfficeId);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw Exception('failed to load patients');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> addPatientAPICall() async {
|
||||||
|
print("here1");
|
||||||
|
await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail);
|
||||||
|
print(futureDocOfficeId.toString());
|
||||||
|
print("here2");
|
||||||
|
var response = await http.post(
|
||||||
|
Uri.parse(apiUrl),
|
||||||
|
headers: <String, String>{
|
||||||
|
"Content-Type": "application/json; charset=UTF-8"
|
||||||
|
},
|
||||||
|
body: jsonEncode(<String, dynamic>{
|
||||||
|
"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",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,14 +53,21 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
//floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
|
//floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
label: const Text(
|
label: const Text(
|
||||||
"Create",
|
"Add Patient",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.blueAccent,
|
backgroundColor: Colors.blueAccent,
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
icon: const Icon(Icons.add),
|
Navigator.of(context)
|
||||||
|
.pushNamed('/patient-manager/add', arguments: widget.userEmail);
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.add,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
body: FutureBuilder(
|
body: FutureBuilder(
|
||||||
future: futurePatients,
|
future: futurePatients,
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ class _PatientViewState extends State<PatientView> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const MyAppBar(barTitle: "Patient View"),
|
appBar: const MyAppBar(barTitle: "Patient View"),
|
||||||
body: Padding(
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0),
|
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -38,6 +39,7 @@ class _PatientViewState extends State<PatientView> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,26 +96,10 @@ class _SignInState extends State<SignIn> {
|
|||||||
),
|
),
|
||||||
//spacer
|
//spacer
|
||||||
const SizedBox(height: 10),
|
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
|
// sign in button
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 500.0,
|
width: 500.0,
|
||||||
|
height: 100.0,
|
||||||
child: MyButton(
|
child: MyButton(
|
||||||
onTap: signUserIn,
|
onTap: signUserIn,
|
||||||
buttonText: "Sign In",
|
buttonText: "Sign In",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/Authentication/authCheck.dart';
|
import 'package:patient_manager/Authentication/authCheck.dart';
|
||||||
import 'package:patient_manager/components/myAppBar.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/components/signInOrRegister.dart';
|
||||||
import 'package:patient_manager/objects/patients.dart';
|
import 'package:patient_manager/objects/patients.dart';
|
||||||
import 'package:patient_manager/pages/home.dart';
|
import 'package:patient_manager/pages/home.dart';
|
||||||
@@ -26,6 +27,15 @@ class RouteGenerator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return _errorRoute();
|
return _errorRoute();
|
||||||
|
case '/patient-manager/add':
|
||||||
|
if (args is String) {
|
||||||
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => AddPatient(
|
||||||
|
userEmail: args,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _errorRoute();
|
||||||
case '/patient-manager/patient':
|
case '/patient-manager/patient':
|
||||||
if (args is Patient) {
|
if (args is Patient) {
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
database/ibdata1
BIN
database/ibdata1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user