forked from yaso_meth/mih-project
AppUser object created. Add patient page with API call added nd completed
This commit is contained in:
@@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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: '/',
|
||||
|
||||
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) {
|
||||
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,
|
||||
),
|
||||
|
||||
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,
|
||||
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,
|
||||
|
||||
@@ -17,25 +17,27 @@ class _PatientViewState extends State<PatientView> {
|
||||
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,
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -96,26 +96,10 @@ class _SignInState extends State<SignIn> {
|
||||
),
|
||||
//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",
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user