forked from yaso_meth/mih-project
Update API to update patient. Update mytextfield to table is editable paramiter. add edit page to edit user information.
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:patient_manager/objects/patients.dart';
|
||||
class BuildPatientsList extends StatefulWidget {
|
||||
final List<Patient> patients;
|
||||
final searchString;
|
||||
|
||||
const BuildPatientsList({
|
||||
super.key,
|
||||
required this.patients,
|
||||
|
||||
@@ -3,19 +3,30 @@ import 'package:flutter/material.dart';
|
||||
class MyTextField extends StatelessWidget {
|
||||
final controller;
|
||||
final String hintText;
|
||||
final bool editable;
|
||||
|
||||
const MyTextField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.hintText,
|
||||
required this.editable,
|
||||
});
|
||||
|
||||
bool makeEditable() {
|
||||
if (editable) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
readOnly: makeEditable(),
|
||||
obscureText: false,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Colors.white,
|
||||
|
||||
@@ -30,13 +30,27 @@ class _PatientDetailsState extends State<PatientDetails> {
|
||||
child: SelectionArea(
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
"Patient Details",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"Patient Details",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
alignment: Alignment.topRight,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
'/patient-manager/patient/edit',
|
||||
arguments: widget.selectedPatient);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const Divider(),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class EditScreenArguments {
|
||||
final String useremail;
|
||||
final String selectedPatient;
|
||||
|
||||
EditScreenArguments({required this.useremail, required this.selectedPatient});
|
||||
}
|
||||
@@ -34,18 +34,11 @@ class _AddPatientState extends State<AddPatient> {
|
||||
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);
|
||||
@@ -56,10 +49,8 @@ class _AddPatientState extends State<AddPatient> {
|
||||
}
|
||||
|
||||
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>{
|
||||
@@ -78,14 +69,12 @@ class _AddPatientState extends State<AddPatient> {
|
||||
"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");
|
||||
String message =
|
||||
"${fnameController.text} ${lnameController.text} Successfully added";
|
||||
messagePopUp(message);
|
||||
} else {
|
||||
messagePopUp("error");
|
||||
}
|
||||
@@ -124,8 +113,10 @@ class _AddPatientState extends State<AddPatient> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: idController,
|
||||
hintText: "13 digit ID Number or Passport"),
|
||||
controller: idController,
|
||||
hintText: "13 digit ID Number or Passport",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -136,6 +127,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: fnameController,
|
||||
hintText: "First Name",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -147,6 +139,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: lnameController,
|
||||
hintText: "Last Name",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -158,6 +151,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: cellController,
|
||||
hintText: "Cell Number",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -169,6 +163,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: emailController,
|
||||
hintText: "Email",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -180,6 +175,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: addressController,
|
||||
hintText: "Address",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -201,6 +197,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: medNoController,
|
||||
hintText: "Medical Aid No.",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -212,6 +209,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: medNameController,
|
||||
hintText: "Medical Aid Name",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -223,6 +221,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
child: MyTextField(
|
||||
controller: medSchemeController,
|
||||
hintText: "Medical Aid Scheme",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
305
Frontend/patient_manager/lib/pages/patientEdit.dart
Normal file
305
Frontend/patient_manager/lib/pages/patientEdit.dart
Normal file
@@ -0,0 +1,305 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/myTextInput.dart';
|
||||
import 'package:patient_manager/components/mybutton.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import '../components/myAppBar.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../objects/AppUser.dart';
|
||||
import '../objects/patients.dart';
|
||||
|
||||
class EditPatient extends StatefulWidget {
|
||||
final Patient selectedPatient;
|
||||
|
||||
const EditPatient({
|
||||
super.key,
|
||||
required this.selectedPatient,
|
||||
});
|
||||
|
||||
@override
|
||||
State<EditPatient> createState() => _EditPatientState();
|
||||
}
|
||||
|
||||
class _EditPatientState extends State<EditPatient> {
|
||||
var 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/update/";
|
||||
late int futureDocOfficeId;
|
||||
late String userEmail;
|
||||
|
||||
Future getOfficeIdByUser(String endpoint) async {
|
||||
final response = await http.get(Uri.parse(endpoint));
|
||||
if (response.statusCode == 200) {
|
||||
String body = response.body;
|
||||
var decodedData = jsonDecode(body);
|
||||
AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>);
|
||||
setState(() {
|
||||
futureDocOfficeId = u.docOffice_id;
|
||||
//print(futureDocOfficeId);
|
||||
});
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updatePatientApiCall() async {
|
||||
print("Here1");
|
||||
//userEmail = getLoginUserEmail() as String;
|
||||
print(userEmail);
|
||||
print("Here2");
|
||||
await getOfficeIdByUser(docOfficeIdApiUrl + userEmail);
|
||||
print(futureDocOfficeId.toString());
|
||||
print("Here3");
|
||||
var response = await http.put(
|
||||
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("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}");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getLoginUserEmail() async {
|
||||
userEmail =
|
||||
(await Supabase.instance.client.auth.currentUser?.email.toString())!;
|
||||
//print(userEmail);
|
||||
}
|
||||
|
||||
void messagePopUp(error) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(error),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
getLoginUserEmail();
|
||||
setState(() {
|
||||
idController.value = TextEditingValue(text: widget.selectedPatient.id_no);
|
||||
fnameController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.first_name);
|
||||
lnameController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.last_name);
|
||||
cellController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.cell_no);
|
||||
emailController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.email);
|
||||
medNameController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.medical_aid_name);
|
||||
medNoController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.medical_aid_no);
|
||||
medSchemeController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.medical_aid_scheme);
|
||||
addressController.value =
|
||||
TextEditingValue(text: widget.selectedPatient.address);
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: const MyAppBar(barTitle: "Edit Patient"),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"Personal Details",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 25.0,
|
||||
//color: Colors.blueAccent,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
alignment: Alignment.topRight,
|
||||
onPressed: () {
|
||||
// Navigator.of(context).pushNamed(
|
||||
// '/patient-manager/patient/edit',
|
||||
// arguments: widget.selectedPatient);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: idController,
|
||||
hintText: "13 digit ID Number or Passport",
|
||||
editable: false,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: fnameController,
|
||||
hintText: "First Name",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: lnameController,
|
||||
hintText: "Last Name",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: cellController,
|
||||
hintText: "Cell Number",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: emailController,
|
||||
hintText: "Email",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: addressController,
|
||||
hintText: "Address",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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.",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: medNameController,
|
||||
hintText: "Medical Aid Name",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextField(
|
||||
controller: medSchemeController,
|
||||
hintText: "Medical Aid Scheme",
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
//const SizedBox(height: 10.0),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 500.0,
|
||||
height: 100.0,
|
||||
child: MyButton(
|
||||
onTap: () {
|
||||
updatePatientApiCall();
|
||||
},
|
||||
buttonText: "Update",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,7 @@ class _RegisterState extends State<Register> {
|
||||
child: MyTextField(
|
||||
controller: officeID,
|
||||
hintText: 'OfficeID',
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
//spacer
|
||||
@@ -105,6 +106,7 @@ class _RegisterState extends State<Register> {
|
||||
child: MyTextField(
|
||||
controller: emailController,
|
||||
hintText: 'Email',
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
//spacer
|
||||
|
||||
@@ -82,6 +82,7 @@ class _SignInState extends State<SignIn> {
|
||||
child: MyTextField(
|
||||
controller: emailController,
|
||||
hintText: 'Email',
|
||||
editable: true,
|
||||
),
|
||||
),
|
||||
//spacer
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:patient_manager/objects/patients.dart';
|
||||
import 'package:patient_manager/pages/home.dart';
|
||||
import 'package:patient_manager/pages/patientManager.dart';
|
||||
import 'package:patient_manager/pages/patientView.dart';
|
||||
import '../pages/patientEdit.dart';
|
||||
|
||||
class RouteGenerator {
|
||||
static Route<dynamic> generateRoute(RouteSettings settings) {
|
||||
@@ -45,6 +46,15 @@ class RouteGenerator {
|
||||
);
|
||||
}
|
||||
return _errorRoute();
|
||||
case '/patient-manager/patient/edit':
|
||||
if (args is Patient) {
|
||||
return MaterialPageRoute(
|
||||
builder: (_) => EditPatient(
|
||||
selectedPatient: args,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _errorRoute();
|
||||
case '/signin':
|
||||
return MaterialPageRoute(builder: (_) => const SignInOrRegister());
|
||||
// //case '/signIn':
|
||||
|
||||
Binary file not shown.
@@ -18,7 +18,6 @@ class patientInsertRequest(BaseModel):
|
||||
doc_office_id: int
|
||||
|
||||
class patientUpdateRequest(BaseModel):
|
||||
idpatients: int
|
||||
id_no: str
|
||||
first_name: str
|
||||
last_name: str
|
||||
@@ -205,7 +204,7 @@ async def UpdatePatient(itemRequest : patientUpdateRequest):
|
||||
query = "update patients "
|
||||
query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid_name=%s, "
|
||||
query += "medical_aid_no=%s, medical_aid_scheme=%s, address=%s, doc_office_id=%s "
|
||||
query += "where idpatients=%s"
|
||||
query += "where id_no=%s and doc_office_id=%s"
|
||||
patientData = (itemRequest.id_no,
|
||||
itemRequest.first_name,
|
||||
itemRequest.last_name,
|
||||
@@ -216,7 +215,8 @@ async def UpdatePatient(itemRequest : patientUpdateRequest):
|
||||
itemRequest.medical_aid_scheme,
|
||||
itemRequest.address,
|
||||
itemRequest.doc_office_id,
|
||||
itemRequest.idpatients)
|
||||
itemRequest.id_no,
|
||||
itemRequest.doc_office_id)
|
||||
try:
|
||||
cursor.execute(query, patientData)
|
||||
except Exception as error:
|
||||
|
||||
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