pat man used signedinUser as paremeter and required user to search for patient by id or medaid no
This commit is contained in:
@@ -2,8 +2,10 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:patient_manager/components/buildPatientList.dart';
|
import 'package:patient_manager/components/buildPatientList.dart';
|
||||||
import 'package:patient_manager/components/mihAppBar.dart';
|
import 'package:patient_manager/components/mihAppBar.dart';
|
||||||
|
import 'package:patient_manager/objects/appUser.dart';
|
||||||
import 'package:supertokens_flutter/http.dart' as http;
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
import 'package:patient_manager/components/mySearchInput.dart';
|
import 'package:patient_manager/components/mySearchInput.dart';
|
||||||
import 'package:patient_manager/env/env.dart';
|
import 'package:patient_manager/env/env.dart';
|
||||||
@@ -11,11 +13,11 @@ import 'package:patient_manager/main.dart';
|
|||||||
import 'package:patient_manager/objects/patients.dart';
|
import 'package:patient_manager/objects/patients.dart';
|
||||||
|
|
||||||
class PatientManager extends StatefulWidget {
|
class PatientManager extends StatefulWidget {
|
||||||
final String userEmail;
|
final AppUser signedInUser;
|
||||||
|
|
||||||
const PatientManager({
|
const PatientManager({
|
||||||
super.key,
|
super.key,
|
||||||
required this.userEmail,
|
required this.signedInUser,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -25,16 +27,20 @@ class PatientManager extends StatefulWidget {
|
|||||||
//
|
//
|
||||||
class _PatientManagerState extends State<PatientManager> {
|
class _PatientManagerState extends State<PatientManager> {
|
||||||
TextEditingController searchController = TextEditingController();
|
TextEditingController searchController = TextEditingController();
|
||||||
String endpoint = "${AppEnviroment.baseApiUrl}/patients/user/";
|
String baseUrl = AppEnviroment.baseApiUrl;
|
||||||
late Future<List<Patient>> futurePatients;
|
|
||||||
|
final FocusNode _focusNode = FocusNode();
|
||||||
String errorCode = "";
|
String errorCode = "";
|
||||||
String errorBody = "";
|
String errorBody = "";
|
||||||
|
|
||||||
String searchString = "";
|
String searchString = "";
|
||||||
|
|
||||||
Future<List<Patient>> fetchPatients(String endpoint) async {
|
late Future<List<Patient>> patientSearchResults;
|
||||||
|
|
||||||
|
Future<List<Patient>> fetchPatients(String search) async {
|
||||||
//print("Patien manager page: $endpoint");
|
//print("Patien manager page: $endpoint");
|
||||||
final response = await http.get(Uri.parse(endpoint));
|
final response =
|
||||||
|
await http.get(Uri.parse("$baseUrl/patients/search/$search"));
|
||||||
// print("Here");
|
// print("Here");
|
||||||
// print("Body: ${response.body}");
|
// print("Body: ${response.body}");
|
||||||
// print("Code: ${response.statusCode}");
|
// print("Code: ${response.statusCode}");
|
||||||
@@ -68,158 +74,151 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
return templist;
|
return templist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void submitForm() {
|
||||||
|
setState(() {
|
||||||
|
searchString = searchController.text;
|
||||||
|
patientSearchResults = fetchPatients(searchString);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Widget displayList(List<Patient> patientsList, String searchString) {
|
Widget displayList(List<Patient> patientsList, String searchString) {
|
||||||
if (searchString.isNotEmpty && searchString != "") {
|
if (searchString.isNotEmpty && searchString != "") {
|
||||||
return Padding(
|
return Container(
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 25,
|
|
||||||
right: 25,
|
|
||||||
bottom: 25,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
height: 500,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
borderRadius: BorderRadius.circular(25.0),
|
|
||||||
border: Border.all(
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
width: 3.0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: BuildPatientsList(
|
|
||||||
patients: patientsList,
|
|
||||||
//searchString: searchString,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 25,
|
|
||||||
right: 25,
|
|
||||||
bottom: 25,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
height: 500,
|
height: 500,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
borderRadius: BorderRadius.circular(25.0),
|
borderRadius: BorderRadius.circular(25.0),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
width: 3.0),
|
width: 3.0,
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
"Enter ID or Medical Aid No. of Patient",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
color:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.messageTextColor()),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
child: BuildPatientsList(
|
||||||
|
patients: patientsList,
|
||||||
|
signedInUser: widget.signedInUser,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Container(
|
||||||
|
height: 500,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
borderRadius: BorderRadius.circular(25.0),
|
||||||
|
border: Border.all(
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
width: 3.0),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
"Enter ID or Medical Aid No. of Patient",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.messageTextColor()),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget patientSearch(double w, double h) {
|
Widget patientSearch(double w, double h) {
|
||||||
return SizedBox(
|
return KeyboardListener(
|
||||||
width: w,
|
focusNode: _focusNode,
|
||||||
height: h,
|
autofocus: true,
|
||||||
child: Column(mainAxisSize: MainAxisSize.max, children: [
|
onKeyEvent: (event) async {
|
||||||
//spacer
|
if (event is KeyDownEvent &&
|
||||||
const SizedBox(height: 10),
|
event.logicalKey == LogicalKeyboardKey.enter) {
|
||||||
MySearchField(
|
submitForm();
|
||||||
controller: searchController,
|
}
|
||||||
hintText: "ID or Medical Aid No. Search",
|
},
|
||||||
required: false,
|
child: Padding(
|
||||||
editable: true,
|
padding: const EdgeInsets.only(
|
||||||
onTap: () {},
|
left: 25,
|
||||||
onChanged: (value) {
|
right: 25,
|
||||||
setState(() {
|
bottom: 25,
|
||||||
searchString = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
//spacer
|
child: SizedBox(
|
||||||
const SizedBox(height: 10),
|
width: w,
|
||||||
FutureBuilder(
|
height: h,
|
||||||
future: futurePatients,
|
child: Column(mainAxisSize: MainAxisSize.max, children: [
|
||||||
builder: (context, snapshot) {
|
//spacer
|
||||||
//print("patient Liust ${snapshot.data}");
|
const SizedBox(height: 10),
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
MySearchField(
|
||||||
return Padding(
|
controller: searchController,
|
||||||
padding: const EdgeInsets.only(
|
hintText: "ID or Medical Aid No. Search",
|
||||||
left: 25,
|
required: false,
|
||||||
right: 25,
|
editable: true,
|
||||||
bottom: 25,
|
onTap: () {
|
||||||
),
|
submitForm();
|
||||||
child: Container(
|
},
|
||||||
height: 500,
|
onChanged: (value) {},
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color:
|
//spacer
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
const SizedBox(height: 10),
|
||||||
borderRadius: BorderRadius.circular(25.0),
|
FutureBuilder(
|
||||||
border: Border.all(
|
future: patientSearchResults,
|
||||||
color: MzanziInnovationHub.of(context)!
|
builder: (context, snapshot) {
|
||||||
.theme
|
//print("patient Liust ${snapshot.data}");
|
||||||
.secondaryColor(),
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
width: 3.0),
|
return Container(
|
||||||
),
|
height: 500,
|
||||||
child: const Center(
|
decoration: BoxDecoration(
|
||||||
child: CircularProgressIndicator(),
|
color:
|
||||||
),
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
),
|
borderRadius: BorderRadius.circular(25.0),
|
||||||
);
|
border: Border.all(
|
||||||
} else if (snapshot.hasData) {
|
|
||||||
List<Patient> patientsList;
|
|
||||||
if (searchString == "") {
|
|
||||||
patientsList = [];
|
|
||||||
} else {
|
|
||||||
patientsList =
|
|
||||||
filterSearchResults(snapshot.data!, searchString);
|
|
||||||
//print(patientsList);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Expanded(
|
|
||||||
child: displayList(patientsList, searchString),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 25,
|
|
||||||
right: 25,
|
|
||||||
bottom: 25,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
height: 500,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
borderRadius: BorderRadius.circular(25.0),
|
|
||||||
border: Border.all(
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
width: 3.0),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
"$errorCode: Error pulling Patients Data\n$endpoint${widget.userEmail}\n$errorBody",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
color: MzanziInnovationHub.of(context)!
|
color: MzanziInnovationHub.of(context)!
|
||||||
.theme
|
.theme
|
||||||
.errorColor()),
|
.secondaryColor(),
|
||||||
textAlign: TextAlign.center,
|
width: 3.0),
|
||||||
),
|
),
|
||||||
),
|
child: const Center(
|
||||||
),
|
child: CircularProgressIndicator(),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
},
|
} else if (snapshot.hasData) {
|
||||||
|
List<Patient> patientsList;
|
||||||
|
if (searchString == "") {
|
||||||
|
patientsList = [];
|
||||||
|
} else {
|
||||||
|
patientsList =
|
||||||
|
filterSearchResults(snapshot.data!, searchString);
|
||||||
|
//print(patientsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Expanded(
|
||||||
|
child: displayList(patientsList, searchString),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Container(
|
||||||
|
height: 500,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
borderRadius: BorderRadius.circular(25.0),
|
||||||
|
border: Border.all(
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
width: 3.0),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
"$errorCode: Error pulling Patients Data\n$baseUrl${widget.signedInUser.email}\n$errorBody",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.errorColor()),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]),
|
||||||
),
|
),
|
||||||
]),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +227,7 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
// errorCode = "";
|
// errorCode = "";
|
||||||
// errorBody = "";
|
// errorBody = "";
|
||||||
//print("patient manager page: ${widget.userEmail}");
|
//print("patient manager page: ${widget.userEmail}");
|
||||||
futurePatients = fetchPatients(endpoint + widget.userEmail);
|
patientSearchResults = fetchPatients("abc");
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,24 +242,24 @@ class _PatientManagerState extends State<PatientManager> {
|
|||||||
// logo: MzanziInnovationHub.of(context)!.theme.logoImage(),
|
// logo: MzanziInnovationHub.of(context)!.theme.logoImage(),
|
||||||
// ),
|
// ),
|
||||||
//floatingActionButtonLocation: FloatingActionButtonLocation.,
|
//floatingActionButtonLocation: FloatingActionButtonLocation.,
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
// floatingActionButton: FloatingActionButton.extended(
|
||||||
label: Text(
|
// label: Text(
|
||||||
"Add Patient",
|
// "Add Patient",
|
||||||
style: TextStyle(
|
// style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
// fontWeight: FontWeight.bold,
|
||||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
//backgroundColor: Colors.blueAccent,
|
// //backgroundColor: Colors.blueAccent,
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
Navigator.of(context)
|
// Navigator.of(context).pushNamed('/patient-manager/add',
|
||||||
.pushNamed('/patient-manager/add', arguments: widget.userEmail);
|
// arguments: widget.signedInUser.email);
|
||||||
},
|
// },
|
||||||
icon: Icon(
|
// icon: Icon(
|
||||||
Icons.add,
|
// Icons.add,
|
||||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
body: patientSearch(screenWidth, screenHeight),
|
body: patientSearch(screenWidth, screenHeight),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user