3 July 2024

This commit is contained in:
2024-07-03 15:13:02 +02:00
parent 6f10fd8572
commit 8f0134a98f
62 changed files with 1101 additions and 343 deletions

View File

@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:patient_manager/components/homeTileGrid.dart';
import 'package:patient_manager/components/myAppBar.dart';
import 'package:patient_manager/components/myAppDrawer.dart';
import 'package:patient_manager/components/homeAppDrawer.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/main.dart';
class Home extends StatefulWidget {
@@ -22,7 +23,7 @@ class _HomeState extends State<Home> {
if (res.user!.email != null) {
//print("emai not null");
useremail = res.user!.email!;
//print(useremail);
//print("Home Page: $useremail");
}
}
@@ -38,8 +39,30 @@ class _HomeState extends State<Home> {
if (snapshot.connectionState == ConnectionState.done) {
return Scaffold(
appBar: const MyAppBar(barTitle: "Mzansi Innovation Hub"),
drawer: MyAppDrawer(
drawerTitle: useremail,
drawer: HomeAppDrawer(userEmail: useremail),
floatingActionButton: FloatingActionButton.extended(
label: const Text(
"Test Allert",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
backgroundColor: Colors.blueAccent,
onPressed: () {
// Navigator.of(context)
// .pushNamed('/patient-manager/add', arguments: widget.userEmail);
showDialog(
context: context,
builder: (context) => const MyErrorMessage(
errorType: "Internet Connection",
),
);
},
icon: const Icon(
Icons.warning_amber_rounded,
color: Colors.white,
),
),
body: HomeTileGrid(
userEmail: useremail,

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/components/myTextInput.dart';
import 'package:patient_manager/components/mybutton.dart';
import 'package:patient_manager/objects/appUser.dart';
@@ -29,7 +30,7 @@ class _AddPatientState extends State<AddPatient> {
final medNameController = TextEditingController();
final medSchemeController = TextEditingController();
final addressController = TextEditingController();
final docOfficeIdApiUrl = "http://localhost:80/docOffices/user/";
final docOfficeIdApiUrl = "http://localhost:80/users/profile/";
final apiUrl = "http://localhost:80/patients/insert/";
late int futureDocOfficeId;
@@ -44,10 +45,27 @@ class _AddPatientState extends State<AddPatient> {
//print(futureDocOfficeId);
});
} else {
internetConnectionPopUp();
throw Exception('failed to load patients');
}
}
bool isFieldsFilled() {
if (idController.text.isEmpty ||
fnameController.text.isEmpty ||
lnameController.text.isEmpty ||
cellController.text.isEmpty ||
emailController.text.isEmpty ||
medNoController.text.isEmpty ||
medNameController.text.isEmpty ||
medSchemeController.text.isEmpty ||
addressController.text.isEmpty) {
return false;
} else {
return true;
}
}
Future<void> addPatientAPICall() async {
await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail);
print(futureDocOfficeId.toString());
@@ -76,10 +94,19 @@ class _AddPatientState extends State<AddPatient> {
"${fnameController.text} ${lnameController.text} Successfully added";
messagePopUp(message);
} else {
messagePopUp("error");
internetConnectionPopUp();
}
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Internet Connection");
},
);
}
void messagePopUp(error) {
showDialog(
context: context,
@@ -129,7 +156,7 @@ class _AddPatientState extends State<AddPatient> {
controller: fnameController,
hintText: "First Name",
editable: true,
required: false,
required: true,
),
),
],
@@ -243,7 +270,19 @@ class _AddPatientState extends State<AddPatient> {
width: 500.0,
height: 100.0,
child: MyButton(
onTap: addPatientAPICall,
onTap: () {
if (isFieldsFilled()) {
addPatientAPICall();
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(
errorType: "Input Error");
},
);
}
},
buttonText: "Add",
),
),

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/components/myTextInput.dart';
import 'package:patient_manager/components/mybutton.dart';
import 'package:patient_manager/objects/appUser.dart';
@@ -31,7 +32,7 @@ class _EditPatientState extends State<EditPatient> {
final medNameController = TextEditingController();
final medSchemeController = TextEditingController();
final addressController = TextEditingController();
final docOfficeIdApiUrl = "http://localhost:80/docOffices/user/";
final docOfficeIdApiUrl = "http://localhost:80/users/profile/";
final apiUrlEdit = "http://localhost:80/patients/update/";
final apiUrlDelete = "http://localhost:80/patients/delete/";
late int futureDocOfficeId;
@@ -48,18 +49,19 @@ class _EditPatientState extends State<EditPatient> {
//print(futureDocOfficeId);
});
} else {
internetConnectionPopUp();
throw Exception('failed to load patients');
}
}
Future<void> updatePatientApiCall() async {
print("Here1");
//print("Here1");
//userEmail = getLoginUserEmail() as String;
print(userEmail);
print("Here2");
//print(userEmail);
//print("Here2");
await getOfficeIdByUser(docOfficeIdApiUrl + userEmail);
print(futureDocOfficeId.toString());
print("Here3");
//print(futureDocOfficeId.toString());
//print("Here3");
var response = await http.put(
Uri.parse(apiUrlEdit),
headers: <String, String>{
@@ -78,27 +80,27 @@ class _EditPatientState extends State<EditPatient> {
"doc_office_id": futureDocOfficeId,
}),
);
print("Here4");
print(response.statusCode);
//print("Here4");
//print(response.statusCode);
if (response.statusCode == 200) {
Navigator.of(context).pushNamed('/patient-manager', arguments: userEmail);
String message =
"${fnameController.text} ${lnameController.text} Successfully Updated";
messagePopUp(message);
} else {
messagePopUp("error ${response.statusCode}");
internetConnectionPopUp();
}
}
Future<void> deletePatientApiCall() async {
print("Here1");
//print("Here1");
//userEmail = getLoginUserEmail() as String;
print(userEmail);
print("Here2");
//print(userEmail);
//print("Here2");
await getOfficeIdByUser(docOfficeIdApiUrl + userEmail);
print("Office ID: ${futureDocOfficeId.toString()}");
print("OPatient ID No: ${idController.text}");
print("Here3");
//print("Office ID: ${futureDocOfficeId.toString()}");
//print("OPatient ID No: ${idController.text}");
//print("Here3");
var response = await http.delete(
Uri.parse(apiUrlDelete),
headers: <String, String>{
@@ -109,15 +111,15 @@ class _EditPatientState extends State<EditPatient> {
"doc_office_id": futureDocOfficeId,
}),
);
print("Here4");
print(response.statusCode);
//print("Here4");
//print(response.statusCode);
if (response.statusCode == 200) {
Navigator.of(context).pushNamed('/patient-manager', arguments: userEmail);
String message =
"${fnameController.text} ${lnameController.text} Successfully Deleted";
messagePopUp(message);
} else {
messagePopUp("error ${response.statusCode}");
internetConnectionPopUp();
}
}
@@ -138,6 +140,131 @@ class _EditPatientState extends State<EditPatient> {
);
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Internet Connection");
},
);
}
Widget deletePatientPopUp() {
return Dialog(
child: Stack(
children: [
Container(
padding: const EdgeInsets.all(10.0),
width: 500.0,
height: 475.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
border: Border.all(color: Colors.blueAccent, width: 5.0),
),
child: Column(
//mainAxisSize: MainAxisSize.max,
children: [
const Icon(
Icons.warning_amber_rounded,
size: 100,
color: Colors.blueAccent,
),
const SizedBox(height: 15),
const Text(
"Are you sure you want to delete this?",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.blueAccent,
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Text(
"This action is permanent! Deleting ${fnameController.text} ${lnameController.text} will remove him\\her from your account. You won't be able to recover it once it's gone.",
style: const TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 15),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 25.0),
child: Text(
"Here's what you'll be deleting:",
style: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 25.0),
child: SizedBox(
width: 450,
child: Text(
"1) Patient Profile Information.\n2) Patient Notes\n3) Patient Files.",
textAlign: TextAlign.left,
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(
width: 300,
height: 100,
child: MyButton(
onTap: deletePatientApiCall, buttonText: "Delete"))
],
),
),
Positioned(
top: 5,
right: 5,
width: 50,
height: 50,
child: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(
Icons.close,
color: Colors.red,
size: 35,
),
),
),
],
),
);
}
bool isFieldsFilled() {
if (idController.text.isEmpty ||
fnameController.text.isEmpty ||
lnameController.text.isEmpty ||
cellController.text.isEmpty ||
emailController.text.isEmpty ||
medNoController.text.isEmpty ||
medNameController.text.isEmpty ||
medSchemeController.text.isEmpty ||
addressController.text.isEmpty) {
return false;
} else {
return true;
}
}
@override
void initState() {
getLoginUserEmail();
@@ -190,38 +317,7 @@ class _EditPatientState extends State<EditPatient> {
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.warning),
Text("Warning"),
],
),
content: Text(
"You are trying to delete the patient ${fnameController.text} ${lnameController.text}.\n\n" +
"Please note that this patient will be deleted permenantly and can not be retored\n\n" +
"Would you like to delete patient?"),
actions: [
TextButton(
onPressed: () {
deletePatientApiCall();
},
child: const Text(
"Yes",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("No"),
)
],
),
builder: (context) => deletePatientPopUp(),
);
},
)
@@ -362,7 +458,17 @@ class _EditPatientState extends State<EditPatient> {
height: 100.0,
child: MyButton(
onTap: () {
updatePatientApiCall();
if (isFieldsFilled()) {
updatePatientApiCall();
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(
errorType: "Input Error");
},
);
}
},
buttonText: "Update",
),

View File

@@ -4,23 +4,11 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:patient_manager/components/buildPatientList.dart';
import 'package:patient_manager/components/myAppBar.dart';
import 'package:patient_manager/components/myAppDrawer.dart';
import 'package:http/http.dart' as http;
import 'package:patient_manager/components/mySearchInput.dart';
import 'package:patient_manager/components/patManAppDrawer.dart';
import 'package:patient_manager/objects/patients.dart';
Future<List<Patient>> fetchPatients(String endpoint) async {
final response = await http.get(Uri.parse(endpoint));
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
List<Patient> patients =
List<Patient>.from(l.map((model) => Patient.fromJson(model)));
return patients;
} else {
throw Exception('failed to load patients');
}
}
class PatientManager extends StatefulWidget {
final String userEmail;
@@ -39,6 +27,20 @@ class _PatientManagerState extends State<PatientManager> {
late Future<List<Patient>> futurePatients;
String searchString = "";
Future<List<Patient>> fetchPatients(String endpoint) async {
//print("Patien manager page: $endpoint");
final response = await http.get(Uri.parse(endpoint));
//print(response.statusCode);
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
List<Patient> patients =
List<Patient>.from(l.map((model) => Patient.fromJson(model)));
return patients;
} else {
throw Exception('failed to load patients');
}
}
@override
void initState() {
futurePatients = fetchPatients(endpoint + widget.userEmail);
@@ -49,7 +51,7 @@ class _PatientManagerState extends State<PatientManager> {
Widget build(BuildContext context) {
return Scaffold(
appBar: const MyAppBar(barTitle: "Patient Manager"),
drawer: MyAppDrawer(drawerTitle: widget.userEmail),
drawer: PatManAppDrawer(userEmail: widget.userEmail),
//floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
floatingActionButton: FloatingActionButton.extended(
label: const Text(
@@ -105,7 +107,7 @@ class _PatientManagerState extends State<PatientManager> {
],
);
} else {
return const MyAppDrawer(drawerTitle: "Error pulling email");
return const PatManAppDrawer(userEmail: "Error pulling email");
}
},
),

View File

@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:patient_manager/components/myAppBar.dart';
import 'package:patient_manager/components/profileOfficeUpdate.dart';
import 'package:patient_manager/components/profileUserUpdate.dart';
import 'package:patient_manager/objects/appUser.dart';
class ProfileUpdate extends StatefulWidget {
final AppUser signedInUser;
//final String userEmail;
const ProfileUpdate({
super.key,
//required this.userEmail,
required this.signedInUser,
});
@override
State<ProfileUpdate> createState() => _ProfileUpdateState();
}
class _ProfileUpdateState extends State<ProfileUpdate> {
int _selectedIndex = 0;
late List<Widget> _widgetOptions;
@override
void initState() {
_widgetOptions = <Widget>[
//Center(child: Text("User profile")),
ProfileUserUpdate(
signedInUser: widget.signedInUser,
),
ProfileOfficeUpdate(
signedInUser: widget.signedInUser,
),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const MyAppBar(barTitle: "Update Profile"),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: Padding(
padding: const EdgeInsets.symmetric(horizontal: 150.0, vertical: 5.0),
child: GNav(
//hoverColor: Colors.lightBlueAccent,
iconSize: 35.0,
activeColor: Colors.white,
tabBackgroundColor: Colors.blueAccent,
gap: 20,
//padding: EdgeInsets.all(15),
tabs: const [
GButton(
icon: Icons.perm_identity,
text: "User Profile",
),
GButton(
icon: Icons.business,
text: "Office Profile",
),
],
selectedIndex: _selectedIndex,
onTabChange: (index) {
setState(() {
_selectedIndex = index;
});
},
),
),
);
}
}

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/components/myPassInput.dart';
import 'package:patient_manager/components/myTextInput.dart';
import 'package:patient_manager/components/mybutton.dart';
@@ -32,20 +33,18 @@ class _SignInState extends State<SignIn> {
});
//Navigator.of(context).pushNamed('/homme');
}
} on AuthException catch (error) {
loginError(error.message);
} on AuthException {
loginError();
//emailController.clear();
passwordController.clear();
}
}
void loginError(error) {
void loginError() {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(error),
);
return const MyErrorMessage(errorType: "Invalid Credentials");
},
);
}
@@ -109,7 +108,19 @@ class _SignInState extends State<SignIn> {
height: 100.0,
child: MyButton(
onTap: () {
signUserIn();
if (emailController.text.isEmpty ||
passwordController.text.isEmpty) {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(
errorType: "Input Error");
},
);
} else {
signUserIn();
}
if (successfulSignIn) {
Navigator.of(context).pushNamed('/homme');
}