Update API to update patient. Update mytextfield to table is editable paramiter. add edit page to edit user information.

This commit is contained in:
2024-06-20 10:07:52 +02:00
parent deda00c955
commit 5a3f62c1ff
19 changed files with 375 additions and 26 deletions
@@ -4,6 +4,7 @@ import 'package:patient_manager/objects/patients.dart';
class BuildPatientsList extends StatefulWidget { class BuildPatientsList extends StatefulWidget {
final List<Patient> patients; final List<Patient> patients;
final searchString; final searchString;
const BuildPatientsList({ const BuildPatientsList({
super.key, super.key,
required this.patients, required this.patients,
@@ -3,19 +3,30 @@ import 'package:flutter/material.dart';
class MyTextField extends StatelessWidget { class MyTextField extends StatelessWidget {
final controller; final controller;
final String hintText; final String hintText;
final bool editable;
const MyTextField({ const MyTextField({
super.key, super.key,
required this.controller, required this.controller,
required this.hintText, required this.hintText,
required this.editable,
}); });
bool makeEditable() {
if (editable) {
return false;
} else {
return true;
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0), padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: TextField( child: TextField(
controller: controller, controller: controller,
readOnly: makeEditable(),
obscureText: false, obscureText: false,
decoration: InputDecoration( decoration: InputDecoration(
fillColor: Colors.white, fillColor: Colors.white,
@@ -30,13 +30,27 @@ class _PatientDetailsState extends State<PatientDetails> {
child: SelectionArea( child: SelectionArea(
child: Column( child: Column(
children: [ children: [
const Text( Row(
"Patient Details", mainAxisAlignment: MainAxisAlignment.center,
textAlign: TextAlign.center, children: [
style: TextStyle( const Text(
fontSize: 35, "Patient Details",
fontWeight: FontWeight.bold, 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 Divider(),
const SizedBox(height: 10), 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; late int futureDocOfficeId;
Future getOfficeIdByUser(String endpoint) async { Future getOfficeIdByUser(String endpoint) async {
print("here1.1");
final response = await http.get(Uri.parse(endpoint)); final response = await http.get(Uri.parse(endpoint));
print("here1.2");
if (response.statusCode == 200) { if (response.statusCode == 200) {
print("here1.3");
String body = response.body; String body = response.body;
print(body);
print("here1.4");
var decodedData = jsonDecode(body); var decodedData = jsonDecode(body);
print("here1.5");
AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>); AppUser u = AppUser.fromJson(decodedData as Map<String, dynamic>);
print("here1.6");
setState(() { setState(() {
futureDocOfficeId = u.docOffice_id; futureDocOfficeId = u.docOffice_id;
//print(futureDocOfficeId); //print(futureDocOfficeId);
@@ -56,10 +49,8 @@ class _AddPatientState extends State<AddPatient> {
} }
Future<void> addPatientAPICall() async { Future<void> addPatientAPICall() async {
print("here1");
await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail); await getOfficeIdByUser(docOfficeIdApiUrl + widget.userEmail);
print(futureDocOfficeId.toString()); print(futureDocOfficeId.toString());
print("here2");
var response = await http.post( var response = await http.post(
Uri.parse(apiUrl), Uri.parse(apiUrl),
headers: <String, String>{ headers: <String, String>{
@@ -78,14 +69,12 @@ class _AddPatientState extends State<AddPatient> {
"doc_office_id": futureDocOfficeId, "doc_office_id": futureDocOfficeId,
}), }),
); );
print("here3");
if (response.statusCode == 201) { if (response.statusCode == 201) {
Navigator.of(context) Navigator.of(context)
.pushNamed('/patient-manager', arguments: widget.userEmail); .pushNamed('/patient-manager', arguments: widget.userEmail);
messagePopUp(fnameController.text + String message =
" " + "${fnameController.text} ${lnameController.text} Successfully added";
lnameController.text + messagePopUp(message);
" Successfully added");
} else { } else {
messagePopUp("error"); messagePopUp("error");
} }
@@ -124,8 +113,10 @@ class _AddPatientState extends State<AddPatient> {
children: [ children: [
Expanded( Expanded(
child: MyTextField( child: MyTextField(
controller: idController, controller: idController,
hintText: "13 digit ID Number or Passport"), hintText: "13 digit ID Number or Passport",
editable: true,
),
), ),
], ],
), ),
@@ -136,6 +127,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: fnameController, controller: fnameController,
hintText: "First Name", hintText: "First Name",
editable: true,
), ),
), ),
], ],
@@ -147,6 +139,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: lnameController, controller: lnameController,
hintText: "Last Name", hintText: "Last Name",
editable: true,
), ),
), ),
], ],
@@ -158,6 +151,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: cellController, controller: cellController,
hintText: "Cell Number", hintText: "Cell Number",
editable: true,
), ),
), ),
], ],
@@ -169,6 +163,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: emailController, controller: emailController,
hintText: "Email", hintText: "Email",
editable: true,
), ),
), ),
], ],
@@ -180,6 +175,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: addressController, controller: addressController,
hintText: "Address", hintText: "Address",
editable: true,
), ),
), ),
], ],
@@ -201,6 +197,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: medNoController, controller: medNoController,
hintText: "Medical Aid No.", hintText: "Medical Aid No.",
editable: true,
), ),
), ),
], ],
@@ -212,6 +209,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: medNameController, controller: medNameController,
hintText: "Medical Aid Name", hintText: "Medical Aid Name",
editable: true,
), ),
), ),
], ],
@@ -223,6 +221,7 @@ class _AddPatientState extends State<AddPatient> {
child: MyTextField( child: MyTextField(
controller: medSchemeController, controller: medSchemeController,
hintText: "Medical Aid Scheme", hintText: "Medical Aid Scheme",
editable: true,
), ),
), ),
], ],
@@ -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( child: MyTextField(
controller: officeID, controller: officeID,
hintText: 'OfficeID', hintText: 'OfficeID',
editable: true,
), ),
), ),
//spacer //spacer
@@ -105,6 +106,7 @@ class _RegisterState extends State<Register> {
child: MyTextField( child: MyTextField(
controller: emailController, controller: emailController,
hintText: 'Email', hintText: 'Email',
editable: true,
), ),
), ),
//spacer //spacer
@@ -82,6 +82,7 @@ class _SignInState extends State<SignIn> {
child: MyTextField( child: MyTextField(
controller: emailController, controller: emailController,
hintText: 'Email', hintText: 'Email',
editable: true,
), ),
), ),
//spacer //spacer
@@ -8,6 +8,7 @@ import 'package:patient_manager/objects/patients.dart';
import 'package:patient_manager/pages/home.dart'; import 'package:patient_manager/pages/home.dart';
import 'package:patient_manager/pages/patientManager.dart'; import 'package:patient_manager/pages/patientManager.dart';
import 'package:patient_manager/pages/patientView.dart'; import 'package:patient_manager/pages/patientView.dart';
import '../pages/patientEdit.dart';
class RouteGenerator { class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) { static Route<dynamic> generateRoute(RouteSettings settings) {
@@ -45,6 +46,15 @@ class RouteGenerator {
); );
} }
return _errorRoute(); return _errorRoute();
case '/patient-manager/patient/edit':
if (args is Patient) {
return MaterialPageRoute(
builder: (_) => EditPatient(
selectedPatient: args,
),
);
}
return _errorRoute();
case '/signin': case '/signin':
return MaterialPageRoute(builder: (_) => const SignInOrRegister()); return MaterialPageRoute(builder: (_) => const SignInOrRegister());
// //case '/signIn': // //case '/signIn':
Binary file not shown.
+3 -3
View File
@@ -18,7 +18,6 @@ class patientInsertRequest(BaseModel):
doc_office_id: int doc_office_id: int
class patientUpdateRequest(BaseModel): class patientUpdateRequest(BaseModel):
idpatients: int
id_no: str id_no: str
first_name: str first_name: str
last_name: str last_name: str
@@ -205,7 +204,7 @@ async def UpdatePatient(itemRequest : patientUpdateRequest):
query = "update patients " query = "update patients "
query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid_name=%s, " 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 += "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, patientData = (itemRequest.id_no,
itemRequest.first_name, itemRequest.first_name,
itemRequest.last_name, itemRequest.last_name,
@@ -216,7 +215,8 @@ async def UpdatePatient(itemRequest : patientUpdateRequest):
itemRequest.medical_aid_scheme, itemRequest.medical_aid_scheme,
itemRequest.address, itemRequest.address,
itemRequest.doc_office_id, itemRequest.doc_office_id,
itemRequest.idpatients) itemRequest.id_no,
itemRequest.doc_office_id)
try: try:
cursor.execute(query, patientData) cursor.execute(query, patientData)
except Exception as error: except Exception as error:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.