upload findings functionality done

dev
Sneha 1 year ago
parent 7dc0d0f426
commit 233a8bf7e5

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:healthcare_user/Reports/add_reports.dart';
import 'package:healthcare_user/Reports/finding_images.dart';
import 'package:healthcare_user/Reports/prescription_images.dart';
import 'package:healthcare_user/Reports/report_images.dart';
import 'package:healthcare_user/common/settings.dart';
import 'package:healthcare_user/common/zoom_image.dart';
@ -278,8 +279,15 @@ class _AllReportsState extends State<AllReports> {
Text(reportsList[index].hospitalName.toString().toUpperCase(),style: valuesTextStyle()),
Text(reportsList[index].date.toString().toUpperCase(),style: valuesTextStyle()),
Text(reportsList[index].patient_name.toString().toUpperCase(),style: valuesTextStyle()),
Row(
children: [
Text(reportsList[index].gender.toString().toUpperCase(),style: valuesTextStyle()),
Text(reportsList[index].age.toString().toUpperCase(),style: valuesTextStyle()),
SizedBox(width:MediaQuery.of(context).size.width * .05,),
Text(reportsList[index].age.toString().toUpperCase()+" Yrs",style: valuesTextStyle()),
],
),
],
),
@ -364,16 +372,12 @@ class _AllReportsState extends State<AllReports> {
onPrimary: Colors.white, // foreground
),
onPressed: () async {
/*Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const FindingImages()),
);*/
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new FindingImages(imageDetails:reportsList[index].findingsImages)));
builder: (__) => new FindingImages(imageDetails:reportsList[index].findingsImages,recordId: reportsList[index].recordId,))).then((value) {
gaetAllRecords();
});
},
child: Text('Findings: '+reportsList[index].findingsImages.length.toString()),
),
@ -403,6 +407,13 @@ class _AllReportsState extends State<AllReports> {
onPrimary: Colors.white, // foreground
),
onPressed: () async {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new PrescriptionImages(imageDetails:reportsList[index].prescriptionImages,recordId: reportsList[index].recordId,familyDetails:reportsList[index]))).then((value) {
gaetAllRecords();
});
},
child: Text('Prescriptions: '+reportsList[index].prescriptionImages.length.toString()),
),

@ -1,10 +1,19 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:healthcare_user/Reports/allreports.dart';
import 'package:healthcare_user/common/settings.dart';
import 'package:healthcare_user/common/zoom_image.dart';
import 'package:image_picker/image_picker.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
class FindingImages extends StatefulWidget {
var imageDetails;
FindingImages({this.imageDetails});
var recordId;
FindingImages({this.imageDetails,this.recordId});
@override
@ -12,13 +21,86 @@ class FindingImages extends StatefulWidget {
}
class _FindingImagesState extends State<FindingImages> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppSettings.appBar('Finding Images'),
body:Container(
padding: EdgeInsets.all(12.0),
child: GridView.builder(
final ImagePicker imagePicker = ImagePicker();
List imageFileList = [];
List uiFindingsImages = [];
final ImagePicker _picker = ImagePicker();
Future pickImageFromGallery() async {
imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);
}
var res = await AppSettings.uploadImageForFindings(imageFileList);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
}
Future pickImageFromGalleryForUpdate() async {
imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);
}
var res = await AppSettings.uploadImageForFindingsUpdate(imageFileList,widget.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
}
Future takeImageFromCamera() 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.uploadImageForFindingsFromCamera(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Future takeImageFromCameraForUpdate() 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.uploadImageForFindingsUpdateFromCamera(image,widget.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Widget renderUi() {
if(widget.imageDetails.length!=0){
return GridView.builder(
itemCount:widget.imageDetails.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
@ -58,6 +140,27 @@ class _FindingImagesState extends State<FindingImages> {
),
onPressed: () async {
AppSettings.preLoaderDialog(context);
String fileName = widget.imageDetails[index]['url'].split('/').last;
var payload = new Map<String, dynamic>();
payload["urlType"] = 'findings';
payload["url"] = widget.imageDetails[index]['url'];
bool deleteStatus = await AppSettings.deleteRecords(payload,widget.recordId);
if(deleteStatus){
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longSuccessToast("Image deleted Successfully");
//AllReportsState().getAllRecords();
Navigator.pop(context);
}
else{
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast("Image deletion failed");
}
@ -73,7 +176,149 @@ class _FindingImagesState extends State<FindingImages> {
//Image.network(widget.imageDetails[index]['url']),
);
},
)),
);
}
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 takeImageFromCamera();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGallery();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
)
],
),
)
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text("Finding Images"),
actions: [
Visibility(
visible: widget.imageDetails.length>0,
child: IconButton(
iconSize: 30,
icon: Icon(
Icons.add_task,
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 takeImageFromCameraForUpdate();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForUpdate();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),)
],
),
body:Container(
padding: EdgeInsets.all(12.0),
child: renderUi()),
);
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,283 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:healthcare_user/Reports/allreports.dart';
import 'package:healthcare_user/Reports/order_medicines_new.dart';
import 'package:healthcare_user/common/settings.dart';
import 'package:healthcare_user/common/zoom_image.dart';
import 'package:healthcare_user/prescriptions/oreder_medicines.dart';
import 'package:image_picker/image_picker.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
class PrescriptionImages extends StatefulWidget {
var imageDetails;
var recordId;
var familyDetails;
PrescriptionImages({this.imageDetails, this.recordId,this.familyDetails});
@override
State<PrescriptionImages> createState() => _PrescriptionImagesState();
}
class _PrescriptionImagesState extends State<PrescriptionImages> {
final ImagePicker imagePicker = ImagePicker();
List imageFileList = [];
List uiPrescriptionImages = [];
Future pickImageFromGallery() async {
imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);
}
var res = await AppSettings.uploadImageForPrescriptions(imageFileList);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
}
Widget renderUi() {
if (widget.imageDetails.length != 0) {
return Column(
children: [
Expanded(
child: GridView.builder(
itemCount: widget.imageDetails.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.imageDetails[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.imageDetails[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.cancel,
color: Colors.red,
),
onPressed: () async {
AppSettings.preLoaderDialog(context);
String fileName = widget.imageDetails[index]
['url']
.split('/')
.last;
var payload = new Map<String, dynamic>();
payload["urlType"] = 'prescriptions';
payload["url"] =
widget.imageDetails[index]['url'];
bool deleteStatus =
await AppSettings.deleteRecords(
payload, widget.recordId);
if (deleteStatus) {
Navigator.of(context, rootNavigator: true)
.pop();
AppSettings.longSuccessToast(
"Image deleted Successfully");
//AllReportsState().getAllRecords();
Navigator.pop(context);
} else {
Navigator.of(context, rootNavigator: true)
.pop();
AppSettings.longFailedToast(
"Image deletion failed");
}
},
),
),
)
]),
),
//Image.network(widget.imageDetails[index]['url']),
);
},
),
),
TextButton(
child: const Text(
'Order Medicines',
style: TextStyle(color: primaryColor),
),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new OrderMedicinesPrescriptions(prescriptionDetails:widget.imageDetails,familyDetails: widget.familyDetails,)));
//signup screen
},
)
],
);
} 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 takeImageFromCamera();
Navigator.pop(context);
},
),
SizedBox(
width:
MediaQuery.of(context).size.width * .20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGallery();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
)
],
),
));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text("Prescriptions"),
actions: [
Visibility(
visible: widget.imageDetails.length > 0,
child: IconButton(
iconSize: 30,
icon: Icon(
Icons.add_task,
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 takeImageFromCamera();
Navigator.pop(context);
},
),
SizedBox(
width: MediaQuery.of(context).size.width * .20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGallery();
Navigator.pop(context);
},
),
],
),
),
);
});
},
),
)
],
),
body: Container(padding: EdgeInsets.all(12.0), child: renderUi()),
);
}
}

@ -11,6 +11,8 @@ class ReportImages extends StatefulWidget {
}
class _ReportImagesState extends State<ReportImages> {
Widget renderUi() {
if(widget.imageDetails.length!=0){
@ -51,7 +53,12 @@ class _ReportImagesState extends State<ReportImages> {
Icons.cancel,
color: Colors.red,
),
onPressed: () async {},
onPressed: () async {
},
),
/* color: Colors.pinkAccent,
width: 35,
@ -107,7 +114,24 @@ class _ReportImagesState extends State<ReportImages> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppSettings.appBar('Report Images'),
appBar:AppBar(
backgroundColor: primaryColor,
title: Text("Report Images"),
actions: [
Visibility(
visible: widget.imageDetails.length>0,
child: IconButton(
iconSize: 30,
icon: Icon(
Icons.add_task,
color: Colors.white,
),
onPressed: () async {
},
),)
],
),
body: Container(padding: EdgeInsets.all(12.0), child: renderUi()),
);
}

@ -491,7 +491,7 @@ class _DashboardState extends State<Dashboard> {
TextButton(
child: Text('Yes', style: textButtonStyle()),
onPressed: () async {
await AppSettings.clearSharedPreferences();
await AppSettings.clearSharedPrefeences();
await Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => Login()),

@ -238,6 +238,7 @@ class AppSettings {
static String getMedicineTimingsUrl = host + 'getmedicineztiming';
static String prescriptionUploadPicUrl = host + 'uploads-precription';
static String findingsUploadPicUrl = host + 'uploads-findings-prescription';
static String updateFindingsUploadPicUrl = host + 'update-uploads-findings-prescription';
static String reportsUploadPicUrl = host + 'uploads-reports-prescription';
static String recordPrescriptionsUploadPicUrl = host + 'uploads-prescription-prescription';
static String getAllpharmaciesDataUrl = host + 'getAllPharmacylist';
@ -248,9 +249,11 @@ class AppSettings {
static String reportMySelfVideoUploadUrl = host + 'reportProblemVideo';
//static String getAllPrescriptionsDataUrl = host + 'usersinglerprecription';
static String getAllPrescriptionsDataUrl = host + 'getAllPrescriptionDetails';
static String getRecordsDataUrl = host + 'getAllRecords';
static String deleteRecordUrl = host + 'deleteRecord';
static String deleteFindingsUrl = host + 'uploads-findings-prescription';
static String deleteRecordsUrl = host + 'delete-url';
@ -334,7 +337,7 @@ class AppSettings {
}
}
static clearSharedPreferences() async {
static clearSharedPrefeences() async {
sharedPreferences = await SharedPreferences.getInstance();
await sharedPreferences.clear();
}
@ -731,6 +734,37 @@ class AppSettings {
return response.body;
}
static Future<String> uploadImageForFindingsFromCamera(file) async {
var request = http.MultipartRequest('POST', Uri.parse(findingsUploadPicUrl + '/' + customerId));
request.files.add(await http.MultipartFile.fromPath('picture', file.path));
var res = await request.send();
var response = await http.Response.fromStream(res);
return response.body;
}
static Future<String> uploadImageForFindingsUpdate(file,var recordId) async {
var request = http.MultipartRequest(
'POST', Uri.parse(updateFindingsUploadPicUrl + '/' + customerId+'/'+recordId));
if (file.length > 0) {
for (var i = 0; i < file.length; i++) {
request.files.add(await http.MultipartFile.fromPath('picture', file[i].path));
}}
// request.files.add(await http.MultipartFile.fromPath('picture', images.toString().replaceAll('[', '').replaceAll(']','')));
var res = await request.send();
var response = await http.Response.fromStream(res);
return response.body;
}
static Future<String> uploadImageForFindingsUpdateFromCamera(file,var recordId) async {
var request = http.MultipartRequest('POST', Uri.parse(updateFindingsUploadPicUrl + '/' + customerId+'/'+recordId));
request.files.add(await http.MultipartFile.fromPath('picture', file.path));
var res = await request.send();
var response = await http.Response.fromStream(res);
return response.body;
}
static Future<String> uploadImageForReports(file) async {
var request = http.MultipartRequest(
@ -1052,6 +1086,71 @@ class AppSettings {
}
}
static Future<bool> deleteFindings(fileName) async {
var uri = Uri.parse(deleteFindingsUrl + '/' + customerId+'/'+fileName);
try {
var response = await http.delete(uri, headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.delete(uri, headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} catch (e) {
print(e);
return false;
}
}
static Future<bool> deleteRecords(payload, recordId) async {
var uri = Uri.parse(deleteRecordsUrl + '/' + customerId+'/'+recordId);
try {
var response = await http.post(uri, body: json.encode(payload),headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.delete(uri, headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} catch (e) {
print(e);
return false;
}
}
/*Apis ends here*/
//save data local

Loading…
Cancel
Save