You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
healthcare-frontend/lib/Reports/all_records_tab.dart

1113 lines
46 KiB

import 'dart:convert';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:healthcare_user/prescriptions/oreder_medicines.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter/material.dart';
import 'package:healthcare_user/common/settings.dart';
import 'package:healthcare_user/common/zoom_image.dart';
class AllReportsTab extends StatefulWidget {
var recordDetails;
var initialIndex;
AllReportsTab({this.recordDetails,this.initialIndex});
@override
State<AllReportsTab> createState() => _AllReportsTabState();
}
class _AllReportsTabState extends State<AllReportsTab>
with TickerProviderStateMixin {
late TabController _controller;
final List<Tab> topTabs = <Tab>[
Tab(
child: Text(
'Findings',
style: TextStyle(fontSize: 12),
)),
Tab(
child: Text(
'Reports',
style: TextStyle(fontSize: 12),
)),
Tab(
child: Text(
'Prescriptions',
style: TextStyle(fontSize: 12),
)),
];
final ImagePicker imagePicker = ImagePicker();
List imageFileList = [];
final ImagePicker _picker = ImagePicker();
@override
void initState() {
_controller =
TabController(vsync: this, initialIndex: widget.initialIndex, length: topTabs.length);
super.initState();
}
Future pickImageFromGalleryForUpdateFindings() async {
imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);
}
var res = await AppSettings.updateFindingsGallery(
imageFileList, widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.recordDetails.findingsImages = jsonDecode(res)['findings'];
});
}
Future takeImageFromCameraForUpdateFindings() async {
try {
final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return;
final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.updateFindingsCamera(
image, widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.recordDetails.findingsImages = jsonDecode(res)['findings'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Future pickImageFromGalleryForUpdateReports() async {
imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);
}
var res = await AppSettings.updateReportsGallery(
imageFileList, widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.recordDetails.reportImages = jsonDecode(res)['reports'];
});
}
Future takeImageFromCameraForUpdateReports() async {
try {
final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return;
final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.updateReportsCamera(
image, widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.recordDetails.reportImages = jsonDecode(res)['reports'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Future pickImageFromGalleryForUpdatePrescriptions() async {
imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);
}
var res = await AppSettings.updatePrescriptionsGallery(
imageFileList, widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.recordDetails.prescriptionImages = jsonDecode(res)['prescription'];
});
}
Future takeImageFromCameraForUpdatePrescriptions() async {
try {
final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return;
final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.updatePrescriptionsCamera(
image, widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.recordDetails.prescriptionImages =
jsonDecode(res)['prescription'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Widget renderUiForFindings() {
if (widget.recordDetails.findingsImages.length != 0) {
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child: GridView.builder(
itemCount: widget.recordDetails.findingsImages.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 2.0,
mainAxisSpacing: 2.0,
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new ImageZoomPage(
imageName: 'Findings',
imageDetails: widget.recordDetails
.findingsImages[index]['url'])));
/*gridOntap(index);*/
},
child: Container(
width: MediaQuery.of(context).size.width * .30,
height: MediaQuery.of(context).size.height * .15,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
image: DecorationImage(
image: NetworkImage(
widget.recordDetails.findingsImages[index]
['url']) as ImageProvider, // picked file
fit: BoxFit.fill)),
child: Stack(children: [
Positioned(
right: 0,
child: Container(
child: IconButton(
iconSize: 30,
icon: const Icon(
Icons.delete,
color: Colors.red,
),
onPressed: () async {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title:
const Text('Do you want to delete image?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment:
MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: () async {
AppSettings.preLoaderDialog(context);
String fileName = widget.recordDetails
.findingsImages[index]['url']
.split('/')
.last;
var payload = new Map<String, dynamic>();
payload["urlType"] = 'findings';
payload["url"] = widget.recordDetails
.findingsImages[index]['url'];
// bool deleteStatus = await AppSettings.deleteRecordsNew(payload,widget.recordId);
try {
var res =
await AppSettings.deleteRecordsNew(
payload,
widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context,
rootNavigator: true)
.pop();
Navigator.of(context).pop(true);
AppSettings.longSuccessToast(
"Image deleted Successfully");
setState(() {
widget.recordDetails.findingsImages =
jsonDecode(res)['remainingUrls'];
});
} catch (e) {
print(e);
Navigator.of(context,
rootNavigator: true)
.pop();
Navigator.of(context).pop(true);
AppSettings.longFailedToast(
"Image deletion failed");
}
},
child: const Text('Yes',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('No',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
],
),
);
},
),
/* color: Colors.pinkAccent,
width: 35,
height: 35,*/
),
)
]),
),
//Image.network(widget.imageDetails[index]['url']),
);
},
)),
Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForUpdateFindings();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdateFindings();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
],
),
),
),
],
);
} else {
return Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * .25,
),
Text('Click below icon to add new findings'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForUpdateFindings();
Navigator.pop(context);
},
),
SizedBox(
width:
MediaQuery.of(context).size.width * .20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdateFindings();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
)
],
),
));
}
}
Widget renderUiForReports() {
if (widget.recordDetails.reportImages.length != 0) {
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: GridView.builder(
itemCount: widget.recordDetails.reportImages.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 2.0,
mainAxisSpacing: 2.0,
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new ImageZoomPage(
imageName: 'Findings',
imageDetails: widget
.recordDetails.reportImages[index]['url'])));
/*gridOntap(index);*/
},
child: Container(
width: MediaQuery.of(context).size.width * .30,
height: MediaQuery.of(context).size.height * .15,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
image: DecorationImage(
image: NetworkImage(
widget.recordDetails.reportImages[index]
['url']) as ImageProvider, // picked file
fit: BoxFit.fill)),
child: Stack(children: [
Positioned(
right: 0,
child: Container(
child: IconButton(
iconSize: 30,
icon: const Icon(
Icons.delete,
color: Colors.red,
),
onPressed: () async {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title:
const Text('Do you want to delete image?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment:
MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: () async {
AppSettings.preLoaderDialog(context);
String fileName = widget.recordDetails
.reportImages[index]['url']
.split('/')
.last;
var payload = new Map<String, dynamic>();
payload["urlType"] = 'reports';
payload["url"] = widget.recordDetails
.reportImages[index]['url'];
try {
var res =
await AppSettings.deleteRecordsNew(
payload,
widget.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context,
rootNavigator: true)
.pop();
Navigator.of(context).pop(true);
AppSettings.longSuccessToast(
"Image deleted Successfully");
setState(() {
widget.recordDetails.reportImages =
jsonDecode(res)['remainingUrls'];
});
} catch (e) {
print(e);
Navigator.of(context,
rootNavigator: true)
.pop();
Navigator.of(context).pop(true);
AppSettings.longFailedToast(
"Image deletion failed");
}
},
child: const Text('Yes',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('No',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
],
),
);
},
),
/* color: Colors.pinkAccent,
width: 35,
height: 35,*/
),
)
]),
),
//Image.network(widget.imageDetails[index]['url']),
);
},
)),
Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForUpdateReports();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdateReports();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
],
),
),
),
],
);
} else {
return Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * .25,
),
Text('Click below icon to add new Report'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForUpdateReports();
Navigator.pop(context);
},
),
SizedBox(
width:
MediaQuery.of(context).size.width * .20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdateReports();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
)
],
),
));
}
}
Widget renderUiForPrescriptions() {
if (widget.recordDetails.prescriptionImages.length != 0) {
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: GridView.builder(
itemCount: widget.recordDetails.prescriptionImages.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 2.0,
mainAxisSpacing: 2.0,
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new ImageZoomPage(
imageName: 'Prescripitons',
imageDetails: widget.recordDetails
.prescriptionImages[index]['url'])));
/*gridOntap(index);*/
},
child: Container(
width: MediaQuery.of(context).size.width * .30,
height: MediaQuery.of(context).size.height * .15,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
image: DecorationImage(
image: NetworkImage(
widget.recordDetails.prescriptionImages[index]
['url']) as ImageProvider, // picked file
fit: BoxFit.fill)),
child: Stack(children: [
Positioned(
right: 0,
child: Container(
child: IconButton(
iconSize: 30,
icon: const Icon(
Icons.delete,
color: Colors.red,
),
onPressed: () async {
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title:
const Text('Do you want to delete image?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment:
MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: () async {
AppSettings.preLoaderDialog(context);
String fileName = widget.recordDetails
.prescriptionImages[index]['url']
.split('/')
.last;
var payload =
new Map<String, dynamic>();
payload["urlType"] = 'prescription';
payload["url"] = widget.recordDetails
.prescriptionImages[index]['url'];
try {
var res = await AppSettings
.deleteRecordsNew(
payload,
widget
.recordDetails.recordId);
print(jsonDecode(res));
Navigator.of(context,
rootNavigator: true)
.pop();
Navigator.of(context).pop(true);
AppSettings.longSuccessToast(
"Image deleted Successfully");
setState(() {
widget.recordDetails
.prescriptionImages =
jsonDecode(
res)['remainingUrls'];
});
} catch (e) {
print(e);
Navigator.of(context,
rootNavigator: true)
.pop();
Navigator.of(context).pop(true);
AppSettings.longFailedToast(
"Image deletion failed");
}
},
child: const Text('Yes',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('No',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
],
),
);
},
),
),
)
]),
),
//Image.network(widget.imageDetails[index]['url']),
);
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.shopping_cart,
color: Colors.white,
),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new OrderMedicines(
prescriptionDetails: widget.recordDetails)));
//signup screen
},
),
],
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForUpdatePrescriptions();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdatePrescriptions();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
],
),
),
),
],
)
],
);
} else {
return Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * .25,
),
Text('Click below icon to add new Prescriptions'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return SizedBox(
height: 200,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForUpdatePrescriptions();
Navigator.pop(context);
},
),
SizedBox(
width:
MediaQuery.of(context).size.width * .20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdatePrescriptions();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
)
],
),
));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Reports'),
backgroundColor: primaryColor,
bottom: TabBar(
isScrollable: true,
controller: _controller,
tabs: topTabs,
indicatorColor: buttonColors,
unselectedLabelColor: Colors.white60,
indicatorWeight: 2,
),
),
body: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * .15,
width: double.infinity,
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Problem: ' +
widget.recordDetails.problem.toString().toUpperCase(),
style: problemTextStyle()),
Text(widget.recordDetails.doctorName.toString().toUpperCase(),
style: valuesTextStyle()),
Text(
widget.recordDetails.hospitalName
.toString()
.toUpperCase(),
style: valuesTextStyle()),
Text(widget.recordDetails.date.toString().toUpperCase(),
style: valuesTextStyle()),
Text('Patient details: ', style: problemTextStyle()),
Text(
widget.recordDetails.patient_name
.toString()
.toUpperCase(),
style: valuesTextStyle()),
Row(
children: [
Text(widget.recordDetails.gender.toString().toUpperCase(),
style: valuesTextStyle()),
SizedBox(
width: MediaQuery.of(context).size.width * .05,
),
Text(
widget.recordDetails.age.toString().toUpperCase() +
" Yrs",
style: valuesTextStyle()),
],
),
],
),
),
),
Expanded(
child: TabBarView(controller: _controller, children: [
Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Findings', style: recordDetailsHeading()),
SizedBox(
height: MediaQuery.of(context).size.height * .02,
),
Expanded(
child: Container(
//color: Colors.lightBlueAccent,
child: renderUiForFindings()),
)
],
)),
Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Reports', style: recordDetailsHeading()),
SizedBox(
height: MediaQuery.of(context).size.height * .02,
),
Expanded(
child: Container(
//color: Colors.lightBlueAccent,
child: renderUiForReports()),
)
],
)),
Padding(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Prescriptions', style: recordDetailsHeading()),
SizedBox(
height: MediaQuery.of(context).size.height * .02,
),
Expanded(
child: Container(
//color: Colors.lightBlueAccent,
child: renderUiForPrescriptions()),
)
],
)),
]),
)
],
),
);
}
}