forked from yaso_meth/mih-project
add access review page and list of access revquests
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/popUpMessages/mihWarningMessage.dart';
|
||||
import 'package:patient_manager/env/env.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/objects/accessRequest.dart';
|
||||
import 'package:patient_manager/objects/appUser.dart';
|
||||
|
||||
class BuildAccessRequestList extends StatefulWidget {
|
||||
final List<AccessRequest> accessRequests;
|
||||
final AppUser signedInUser;
|
||||
|
||||
const BuildAccessRequestList({
|
||||
super.key,
|
||||
required this.accessRequests,
|
||||
required this.signedInUser,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BuildAccessRequestList> createState() => _BuildPatientsListState();
|
||||
}
|
||||
|
||||
class _BuildPatientsListState extends State<BuildAccessRequestList> {
|
||||
String baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
Widget displayQueue(int index) {
|
||||
String title =
|
||||
"Appointment: ${widget.accessRequests[index].date_time.substring(0, 10)}";
|
||||
String subtitle = "";
|
||||
subtitle += "Requestor: ${widget.accessRequests[index].Name}\n";
|
||||
subtitle += "Business Type: ${widget.accessRequests[index].type}\n";
|
||||
subtitle += "Access: ${widget.accessRequests[index].access}";
|
||||
|
||||
return ListTile(
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
//popup to approve
|
||||
},
|
||||
trailing: Icon(
|
||||
Icons.arrow_forward,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void noAccessWarning() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const MIHWarningMessage(warningType: "No Access");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.separated(
|
||||
separatorBuilder: (BuildContext context, index) {
|
||||
return Divider(
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
);
|
||||
},
|
||||
itemCount: widget.accessRequests.length,
|
||||
itemBuilder: (context, index) {
|
||||
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
||||
//print(index);
|
||||
return displayQueue(index);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
47
Frontend/patient_manager/lib/objects/accessRequest.dart
Normal file
47
Frontend/patient_manager/lib/objects/accessRequest.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
class AccessRequest {
|
||||
final int idpatient_queue;
|
||||
final String business_id;
|
||||
final String app_id;
|
||||
final String date_time;
|
||||
final String access;
|
||||
final String Name;
|
||||
final String type;
|
||||
final String logo_path;
|
||||
|
||||
const AccessRequest({
|
||||
required this.idpatient_queue,
|
||||
required this.business_id,
|
||||
required this.app_id,
|
||||
required this.date_time,
|
||||
required this.access,
|
||||
required this.Name,
|
||||
required this.type,
|
||||
required this.logo_path,
|
||||
});
|
||||
|
||||
factory AccessRequest.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
"idpatient_queue": int idpatient_queue,
|
||||
'business_id': String business_id,
|
||||
'app_id': String app_id,
|
||||
'date_time': String date_time,
|
||||
'access': String access,
|
||||
'Name': String Name,
|
||||
'type': String type,
|
||||
'logo_path': String logo_path,
|
||||
} =>
|
||||
AccessRequest(
|
||||
idpatient_queue: idpatient_queue,
|
||||
business_id: business_id,
|
||||
app_id: app_id,
|
||||
date_time: date_time,
|
||||
access: access,
|
||||
Name: Name,
|
||||
type: type,
|
||||
logo_path: logo_path,
|
||||
),
|
||||
_ => throw const FormatException('Failed to load album.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
227
Frontend/patient_manager/lib/pages/patientAccessReview.dart
Normal file
227
Frontend/patient_manager/lib/pages/patientAccessReview.dart
Normal file
@@ -0,0 +1,227 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/builders/buildAccessRequestList.dart';
|
||||
import 'package:patient_manager/components/mihAppBar.dart';
|
||||
import 'package:patient_manager/components/mihLoadingCircle.dart';
|
||||
import 'package:patient_manager/env/env.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/objects/accessRequest.dart';
|
||||
import 'package:patient_manager/objects/appUser.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
class PatientAccessRequest extends StatefulWidget {
|
||||
final AppUser signedInUser;
|
||||
|
||||
const PatientAccessRequest({
|
||||
super.key,
|
||||
required this.signedInUser,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PatientAccessRequest> createState() => _PatientAccessRequestState();
|
||||
}
|
||||
|
||||
class _PatientAccessRequestState extends State<PatientAccessRequest> {
|
||||
String baseUrl = AppEnviroment.baseApiUrl;
|
||||
|
||||
String errorCode = "";
|
||||
String errorBody = "";
|
||||
String datefilter = "";
|
||||
String accessFilter = "";
|
||||
|
||||
late Future<List<AccessRequest>> accessRequestResults;
|
||||
|
||||
Future<List<AccessRequest>> fetchAccessRequests() async {
|
||||
//print("Patien manager page: $endpoint");
|
||||
final response = await http.get(
|
||||
Uri.parse("$baseUrl/access/requests/${widget.signedInUser.app_id}"));
|
||||
// print("Here");
|
||||
// print("Body: ${response.body}");
|
||||
// print("Code: ${response.statusCode}");
|
||||
errorCode = response.statusCode.toString();
|
||||
errorBody = response.body;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
//print("Here1");
|
||||
Iterable l = jsonDecode(response.body);
|
||||
//print("Here2");
|
||||
List<AccessRequest> patientQueue = List<AccessRequest>.from(
|
||||
l.map((model) => AccessRequest.fromJson(model)));
|
||||
//print("Here3");
|
||||
//print(patientQueue);
|
||||
return patientQueue;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
}
|
||||
}
|
||||
|
||||
List<AccessRequest> filterSearchResults(List<AccessRequest> accessList) {
|
||||
List<AccessRequest> templist = [];
|
||||
|
||||
for (var item in accessList) {
|
||||
if (item.date_time.contains(datefilter)) {
|
||||
templist.add(item);
|
||||
}
|
||||
}
|
||||
return templist;
|
||||
}
|
||||
|
||||
Widget displayAccessRequestList(List<AccessRequest> accessRequestList) {
|
||||
if (accessRequestList.isNotEmpty) {
|
||||
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: BuildAccessRequestList(
|
||||
signedInUser: widget.signedInUser,
|
||||
accessRequests: accessRequestList,
|
||||
),
|
||||
// BuildPatientQueueList(
|
||||
// patientQueue: patientQueueList,
|
||||
// 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(
|
||||
"No Request have been made.",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: MzanziInnovationHub.of(context)!.theme.messageTextColor()),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget viewAccessRequest(double w, double h) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: SizedBox(
|
||||
width: w,
|
||||
height: 600,
|
||||
child: Column(mainAxisSize: MainAxisSize.max, children: [
|
||||
//const SizedBox(height: 15),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
//const SizedBox(height: 25),
|
||||
const Text(
|
||||
"Access Request",
|
||||
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
refreshList();
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.refresh,
|
||||
))
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FutureBuilder(
|
||||
future: accessRequestResults,
|
||||
builder: (context, snapshot) {
|
||||
//print("patient Queue List ${snapshot.hasData}");
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
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: const Mihloadingcircle(),
|
||||
);
|
||||
} else if (snapshot.connectionState == ConnectionState.done) {
|
||||
List<AccessRequest> accessRequestList;
|
||||
// if (searchString == "") {
|
||||
// patientQueueList = [];
|
||||
// } else {
|
||||
accessRequestList = filterSearchResults(snapshot.requireData);
|
||||
// print(patientQueueList);
|
||||
// }
|
||||
|
||||
return Expanded(
|
||||
child: displayAccessRequestList(accessRequestList),
|
||||
);
|
||||
} 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/queue/patients/\n$errorBody",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.errorColor()),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void refreshList() {
|
||||
setState(() {
|
||||
accessRequestResults = fetchAccessRequests();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
setState(() {
|
||||
accessRequestResults = fetchAccessRequests();
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
return Scaffold(
|
||||
appBar: const MIHAppBar(barTitle: "Access Reviews"),
|
||||
body: viewAccessRequest(screenWidth, screenHeight),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user