upload prescriptions done

dev
Sneha 1 year ago
parent 233a8bf7e5
commit 895626d5b5

@ -45,7 +45,7 @@ class _AddReportsState extends State<AddReports> {
imageFileList.addAll(selectedImages); imageFileList.addAll(selectedImages);
} }
var res = await AppSettings.uploadImageForFindings(imageFileList); var res = await AppSettings.uploadFindingsGallery(imageFileList);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
@ -59,7 +59,7 @@ class _AddReportsState extends State<AddReports> {
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageForFindingsCamera(image); var res = await AppSettings.uploadFindingsCamera(image);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
@ -69,7 +69,38 @@ class _AddReportsState extends State<AddReports> {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
} }
} }
/*Future pickImageFromGalleryForUpdate() 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.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
}
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.updateFindingsCamera(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');
}
}*/
Future takeImageFromCameraForReports() async { Future takeImageFromCameraForReports() async {
try { try {
@ -104,18 +135,17 @@ class _AddReportsState extends State<AddReports> {
}); });
} }
Future takeImageFromCameraForPrescriptions() async { Future takeImageFromCameraForPrescriptions() async {
try { try {
final image = await _picker.pickImage(source: ImageSource.camera); final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageForFindingsCamera(image); var res = await AppSettings.uploadPrescriptionsCamera(image);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
uiFindingsImages = jsonDecode(res)['findings']; uiPrescriptionImages = jsonDecode(res)['precription'];
}); });
} on PlatformException catch (e) { } on PlatformException catch (e) {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
@ -123,14 +153,15 @@ class _AddReportsState extends State<AddReports> {
} }
Future pickImageFromGalleryForPrescriptions() async { Future pickImageFromGalleryForPrescriptions() async {
imageFileListPrescriptions = []; // imageFileListPrescriptions = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage(); final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
if (selectedImages!.isNotEmpty) { if (selectedImages!.isNotEmpty) {
imageFileListPrescriptions.addAll(selectedImages); imageFileListPrescriptions.addAll(selectedImages);
} }
var res = await AppSettings.uploadImageForPrescriptions(imageFileListPrescriptions); var res = await AppSettings.uploadPrescriptionsGallery(
imageFileListPrescriptions);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
@ -138,8 +169,6 @@ class _AddReportsState extends State<AddReports> {
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -233,143 +262,167 @@ class _AddReportsState extends State<AddReports> {
), ),
Row( Row(
children: [ children: [
Expanded(
Expanded(child: RadioListTile( child: RadioListTile(
title: Text("For Yourself"), title: Text("For Yourself"),
value: "self", value: "self",
groupValue: prescriptionFor, groupValue: prescriptionFor,
activeColor: primaryColor, activeColor: primaryColor,
onChanged: (value){ onChanged: (value) {
setState(() { setState(() {
prescriptionFor = value.toString(); prescriptionFor = value.toString();
}); });
}, },
),), ),
Expanded(child: RadioListTile( ),
title: Text("For Family"), Expanded(
value: "others", child: RadioListTile(
groupValue: prescriptionFor, title: Text("For Family"),
activeColor: primaryColor, value: "others",
onChanged: (value){ groupValue: prescriptionFor,
setState(() { activeColor: primaryColor,
prescriptionFor = value.toString(); onChanged: (value) {
}); setState(() {
}, prescriptionFor = value.toString();
),), });
},
),
),
], ],
), ),
Visibility( Visibility(
visible:prescriptionFor.toString().toLowerCase()=='others' , visible:
prescriptionFor.toString().toLowerCase() == 'others',
child: Container( child: Container(
child: TextFormField( child: TextFormField(
cursorColor: greyColor, cursorColor: greyColor,
controller: patientNameController, controller: patientNameController,
decoration: textFormFieldDecoration(Icons.person,'Enter patient name'), decoration: textFormFieldDecoration(
Icons.person, 'Enter patient name'),
), ),
),), ),
SizedBox(height:MediaQuery.of(context).size.height * .02,), ),
SizedBox(
height: MediaQuery.of(context).size.height * .02,
),
Visibility( Visibility(
visible:prescriptionFor.toString().toLowerCase()=='others' , visible:
prescriptionFor.toString().toLowerCase() == 'others',
child: Container( child: Container(
child: TextFormField( child: TextFormField(
cursorColor: greyColor, cursorColor: greyColor,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
controller: patientAgeController, controller: patientAgeController,
decoration: textFormFieldDecoration(Icons.person,'Enter patient age'), decoration: textFormFieldDecoration(
Icons.person, 'Enter patient age'),
), ),
),), ),
),
Visibility( Visibility(
visible:prescriptionFor.toString().toLowerCase()=='others' , visible:
prescriptionFor.toString().toLowerCase() == 'others',
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded(
Expanded(child: RadioListTile( child: RadioListTile(
title: Text("Male",style: TextStyle(fontSize: 10)), title: Text("Male", style: TextStyle(fontSize: 10)),
value: "male", value: "male",
groupValue: gender, groupValue: gender,
activeColor: primaryColor, activeColor: primaryColor,
onChanged: (value){ onChanged: (value) {
setState(() { setState(() {
gender = value.toString(); gender = value.toString();
}); });
}, },
),), ),
Expanded(child: RadioListTile( ),
title: Text("Female",style: TextStyle(fontSize: 10),), Expanded(
value: "female", child: RadioListTile(
groupValue: gender, title: Text(
activeColor: primaryColor, "Female",
onChanged: (value){ style: TextStyle(fontSize: 10),
setState(() { ),
gender = value.toString(); value: "female",
}); groupValue: gender,
}, activeColor: primaryColor,
),), onChanged: (value) {
Expanded(child: RadioListTile( setState(() {
title: Text("Others",style: TextStyle(fontSize: 10)), gender = value.toString();
value: "other", });
groupValue: gender, },
activeColor: primaryColor, ),
onChanged: (value){ ),
setState(() { Expanded(
gender = value.toString(); child: RadioListTile(
}); title:
}, Text("Others", style: TextStyle(fontSize: 10)),
),), value: "other",
groupValue: gender,
activeColor: primaryColor,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
),
),
], ],
),),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
onPrimary: Colors.white, // foreground
), ),
onPressed: () async { ),
showModalBottomSheet<void>( Visibility(
context: context, visible: uiFindingsImages.length == 0,
builder: (BuildContext context) { child: ElevatedButton(
return SizedBox( style: ElevatedButton.styleFrom(
height: 200, primary: primaryColor, // background
child: Center( onPrimary: Colors.white, // foreground
child: Row( ),
mainAxisAlignment: MainAxisAlignment.center, onPressed: () async {
children: <Widget>[ showModalBottomSheet<void>(
GestureDetector( context: context,
child: Icon( builder: (BuildContext context) {
Icons.camera_alt_outlined, return SizedBox(
size: 100, height: 200,
color: primaryColor, 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);
},
), ),
onTap: () async { SizedBox(
await takeImageFromCamera(); width:
Navigator.pop(context); MediaQuery.of(context).size.width *
}, .20,
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
), ),
onTap: () async { GestureDetector(
await pickImageFromGallery(); child: Icon(
Navigator.pop(context); Icons.photo,
}, size: 100,
), color: primaryColor,
], ),
onTap: () async {
await pickImageFromGallery();
Navigator.pop(context);
},
),
],
),
), ),
), );
); });
}); },
}, child: const Text('Select Findings'),
child: const Text('Select Findings'), ),
), ),
Visibility( Visibility(
visible: uiFindingsImages.length > 0, visible: uiFindingsImages.length > 0,
@ -384,8 +437,11 @@ class _AddReportsState extends State<AddReports> {
children: [ children: [
Card( Card(
child: Container( child: Container(
width: MediaQuery.of(context).size.width * .30, width: MediaQuery.of(context).size.width *
height: MediaQuery.of(context).size.height * .15, .30,
height:
MediaQuery.of(context).size.height *
.15,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.rectangle, shape: BoxShape.rectangle,
image: DecorationImage( image: DecorationImage(
@ -407,54 +463,111 @@ class _AddReportsState extends State<AddReports> {
); );
}), }),
)), )),
ElevatedButton( Visibility(
style: ElevatedButton.styleFrom( visible: uiFindingsImages.length != 0,
primary: primaryColor, // background child: ElevatedButton(
onPrimary: Colors.white, // foreground style: ElevatedButton.styleFrom(
primary: Colors.red, // background
onPrimary: Colors.white, // foreground
),
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);
},
),
],
),
),
);
});
},
child: const Text('Add Findings'),
), ),
onPressed: () async { ),
showModalBottomSheet<void>( Visibility(
context: context, visible: uiReportsImages.length == 0,
builder: (BuildContext context) { child: ElevatedButton(
return SizedBox( style: ElevatedButton.styleFrom(
height: 200, primary: primaryColor, // background
child: Center( onPrimary: Colors.white, // foreground
child: Row( ),
mainAxisAlignment: MainAxisAlignment.center, onPressed: () async {
children: <Widget>[ showModalBottomSheet<void>(
GestureDetector( context: context,
child: Icon( builder: (BuildContext context) {
Icons.camera_alt_outlined, return SizedBox(
size: 100, height: 200,
color: primaryColor, child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForReports();
Navigator.pop(context);
},
), ),
onTap: () async { SizedBox(
await takeImageFromCameraForReports(); width:
Navigator.pop(context); MediaQuery.of(context).size.width *
}, .20,
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
), ),
onTap: () async { GestureDetector(
await pickImageFromGalleryForReports(); child: Icon(
Navigator.pop(context); Icons.photo,
}, size: 100,
), color: primaryColor,
], ),
onTap: () async {
await pickImageFromGalleryForReports();
Navigator.pop(context);
},
),
],
),
), ),
), );
); });
}); },
}, child: const Text('Select Reports'),
child: const Text('Select Reports'), ),
), ),
Visibility( Visibility(
visible: uiReportsImages.length > 0, visible: uiReportsImages.length > 0,
@ -469,15 +582,18 @@ class _AddReportsState extends State<AddReports> {
children: [ children: [
Card( Card(
child: Container( child: Container(
width: MediaQuery.of(context).size.width * .30, width: MediaQuery.of(context).size.width *
height: MediaQuery.of(context).size.height * .15, .30,
height:
MediaQuery.of(context).size.height *
.15,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.rectangle, shape: BoxShape.rectangle,
image: DecorationImage( image: DecorationImage(
image: NetworkImage( image: NetworkImage(
uiReportsImages[index] uiReportsImages[index]
['url']) ['url'])
as ImageProvider, // picked file as ImageProvider, // picked file
fit: BoxFit.fill)), fit: BoxFit.fill)),
), ),
), ),
@ -492,56 +608,112 @@ class _AddReportsState extends State<AddReports> {
); );
}), }),
)), )),
ElevatedButton( Visibility(
style: ElevatedButton.styleFrom( visible: uiReportsImages.length != 0,
primary: primaryColor, // background child: ElevatedButton(
onPrimary: Colors.white, // foreground style: ElevatedButton.styleFrom(
primary: Colors.red, // background
onPrimary: Colors.white, // foreground
),
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 takeImageFromCameraForReports();
Navigator.pop(context);
},
),
SizedBox(
width:
MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForReports();
Navigator.pop(context);
},
),
],
),
),
);
});
},
child: const Text('Add Reports'),
), ),
onPressed: () async { ),
showModalBottomSheet<void>( Visibility(
context: context, visible: uiPrescriptionImages.length == 0,
builder: (BuildContext context) { child: ElevatedButton(
return SizedBox( style: ElevatedButton.styleFrom(
height: 200, primary: primaryColor, // background
child: Center( onPrimary: Colors.white, // foreground
child: Row( ),
mainAxisAlignment: MainAxisAlignment.center, onPressed: () async {
children: <Widget>[ showModalBottomSheet<void>(
GestureDetector( context: context,
child: Icon( builder: (BuildContext context) {
Icons.camera_alt_outlined, return SizedBox(
size: 100, height: 200,
color: primaryColor, child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
child: Icon(
Icons.camera_alt_outlined,
size: 100,
color: primaryColor,
),
onTap: () async {
await takeImageFromCameraForPrescriptions();
Navigator.pop(context);
},
), ),
onTap: () async { SizedBox(
await takeImageFromCameraForPrescriptions(); width:
Navigator.pop(context); MediaQuery.of(context).size.width *
}, .20,
),
SizedBox(
width: MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
), ),
onTap: () async { GestureDetector(
await pickImageFromGalleryForPrescriptions(); child: Icon(
Navigator.pop(context); Icons.photo,
}, size: 100,
), color: primaryColor,
], ),
onTap: () async {
await pickImageFromGalleryForPrescriptions();
Navigator.pop(context);
},
),
],
),
), ),
), );
); });
}); },
}, child: const Text('Select Prescriptions'),
child: const Text('Select Prescriptions'), ),
), ),
Visibility( Visibility(
visible: uiPrescriptionImages.length > 0, visible: uiPrescriptionImages.length > 0,
child: Container( child: Container(
@ -555,16 +727,44 @@ class _AddReportsState extends State<AddReports> {
children: [ children: [
Card( Card(
child: Container( child: Container(
width: MediaQuery.of(context).size.width * .30, width: MediaQuery.of(context).size.width *
height: MediaQuery.of(context).size.height * .15, .30,
height:
MediaQuery.of(context).size.height *
.15,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.rectangle, shape: BoxShape.rectangle,
image: DecorationImage( image: DecorationImage(
image: NetworkImage( image: NetworkImage(
uiPrescriptionImages[index] uiPrescriptionImages[index]['url'])
['url']) as ImageProvider, // picked file
as ImageProvider, // picked file
fit: BoxFit.fill)), 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 = uiPrescriptionImages[index]['url'].split('/').last;
var response = await AppSettings.deletePrescriptions(fileName);
print(jsonDecode(response));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
uiPrescriptionImages = jsonDecode(response)['precription'];
});
},
),
),
)
]),
), ),
), ),
/*Expanded(child:IconButton( /*Expanded(child:IconButton(
@ -578,89 +778,149 @@ class _AddReportsState extends State<AddReports> {
); );
}), }),
)), )),
Visibility(
visible: uiPrescriptionImages.length != 0,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red, // background
onPrimary: Colors.white, // foreground
),
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 takeImageFromCameraForPrescriptions();
Navigator.pop(context);
},
),
SizedBox(
width:
MediaQuery.of(context).size.width *
.20,
),
GestureDetector(
child: Icon(
Icons.photo,
size: 100,
color: primaryColor,
),
onTap: () async {
await pickImageFromGalleryForPrescriptions();
Navigator.pop(context);
},
),
],
),
),
);
});
},
child: const Text('Add Prescriptions'),
),
),
Container( Container(
width:double.infinity, width: double.infinity,
height: MediaQuery.of(context).size.height * .06, height: MediaQuery.of(context).size.height * .06,
child: ElevatedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
primary: buttonColors, // background primary: buttonColors, // background
onPrimary: Colors.black, // foreground onPrimary: Colors.black, // foreground
), ),
onPressed: () async{ onPressed: () async {
if (doctorNameController.text != '' &&
if(doctorNameController.text!=''&& problemController.text!=''&& dateInput.text!=''&&prescriptionFor!=''){ problemController.text != '' &&
dateInput.text != '' &&
String _name=''; prescriptionFor != '') {
String _age=''; String _name = '';
String? _gender=''; String _age = '';
String? _gender = '';
if(prescriptionFor.toString().toLowerCase()=='others'){
if(patientNameController!=''&& patientAgeController.text!=''&&gender!=''){ if (prescriptionFor.toString().toLowerCase() ==
_name=patientNameController.text; 'others') {
_age=patientAgeController.text; if (patientNameController != '' &&
_gender=gender; patientAgeController.text != '' &&
gender != '') {
_name = patientNameController.text;
_age = patientAgeController.text;
_gender = gender;
} else {
AppSettings.longFailedToast(
'Please enter details');
} }
else{ } else {
AppSettings.longFailedToast('Please enter details'); _name = AppSettings.userName;
} _age = AppSettings.age;
} _gender = AppSettings.gender;
else{
_name=AppSettings.userName;
_age=AppSettings.age;
_gender=AppSettings.gender;
} }
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
bool isOnline = await AppSettings.internetConnectivity(); bool isOnline =
if(isOnline){ await AppSettings.internetConnectivity();
if (isOnline) {
var payload = new Map<String, dynamic>(); var payload = new Map<String, dynamic>();
payload["problem"] = problemController.text.toString(); payload["problem"] =
payload["doctorName"] = doctorNameController.text.toString(); problemController.text.toString();
payload["hospitalName"] = hospitalNameController.text.toString(); payload["doctorName"] =
payload["date"] = dateInput.text.toString(); doctorNameController.text.toString();
payload["findings_date"] = ''; payload["hospitalName"] =
payload["reports_date"] = ''; hospitalNameController.text.toString();
payload["prescription_date"] = ''; payload["date"] = dateInput.text.toString();
payload["patientType"] = prescriptionFor.toString(); payload["findings_date"] = '';
payload["others"] ={ payload["reports_date"] = '';
"name": _name, payload["prescription_date"] = '';
"age": int.parse(_age), payload["patientType"] =
"gender": _gender.toString().toLowerCase() prescriptionFor.toString();
}; payload["others"] = {
payload["findings"] =uiFindingsImages; "name": _name,
payload["reports"] =uiReportsImages; "age": int.parse(_age),
payload["prescription"] =uiPrescriptionImages; "gender": _gender.toString().toLowerCase()
};
bool uploadStatus = await AppSettings.addRecords(payload); payload["findings"] = uiFindingsImages;
payload["reports"] = uiReportsImages;
try{ payload["prescription"] = uiPrescriptionImages;
if(uploadStatus){
Navigator.of(context,rootNavigator: true).pop(); bool uploadStatus =
AppSettings.longSuccessToast('Record added successfully'); await AppSettings.addRecords(payload);
Navigator.pop(context);
} try {
else{ if (uploadStatus) {
Navigator.of(context,rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true)
AppSettings.longFailedToast('Fail to add record details'); .pop();
} AppSettings.longSuccessToast(
'Record added successfully');
Navigator.pop(context);
} else {
Navigator.of(context, rootNavigator: true)
.pop();
AppSettings.longFailedToast(
'Fail to add record details');
} }
catch(e){ } catch (e) {
print(e); print(e);
Navigator.of(context,rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true)
AppSettings.longFailedToast('Fail to add record details'); .pop();
} AppSettings.longFailedToast(
'Fail to add record details');
}
else{
AppSettings.longFailedToast('Please check internet');
} }
} else {
AppSettings.longFailedToast(
'Please check internet');
} }
else{ } else {
AppSettings.longFailedToast('Please enter valid details'); AppSettings.longFailedToast(
'Please enter valid details');
} }
}, },
child: const Text('Submit'), child: const Text('Submit'),

@ -24,8 +24,63 @@ class _AllReportsState extends State<AllReports> {
List<ReportsModel> reportsListOriginal = []; List<ReportsModel> reportsListOriginal = [];
bool isReportsDataLoading = false; bool isReportsDataLoading = false;
bool isSereverIssue = false; bool isSereverIssue = false;
TextEditingController searchController = TextEditingController();
String dropdownSearchType = 'Problem';
var typeOfSearchItems = [
'Problem',
'Doctor',
'Date',
];
Future<void> getAllRecords() async {
isReportsDataLoading=true;
try {
var response = await AppSettings.getAllRecords();
setState(() {
reportsListOriginal = ((jsonDecode(response)) as List)
.map((dynamic model) {
return ReportsModel.fromJson(model);
}).toList();
reportsList=reportsListOriginal.reversed.toList();
isReportsDataLoading = false;
});
} catch (e) {
setState(() {
isReportsDataLoading = false;
isSereverIssue = true;
});
}
}
Future<void> getRecordsByProblemName(var problem) async {
isReportsDataLoading=true;
try {
var response = await AppSettings.getAllRecords();
setState(() {
reportsListOriginal = ((jsonDecode(response)) as List)
.map((dynamic model) {
return ReportsModel.fromJson(model);
}).toList();
reportsList=reportsListOriginal.reversed.toList();
reportsList= reportsListOriginal.where(
(x) => x.problem.toString().toLowerCase().contains(problem.toString().toLowerCase())
).toList();
isReportsDataLoading = false;
});
} catch (e) {
setState(() {
isReportsDataLoading = false;
isSereverIssue = true;
});
}
}
Future<void> getRecordsByDoctorName(var doctor) async {
Future<void> gaetAllRecords() async {
isReportsDataLoading=true; isReportsDataLoading=true;
try { try {
var response = await AppSettings.getAllRecords(); var response = await AppSettings.getAllRecords();
@ -36,6 +91,9 @@ class _AllReportsState extends State<AllReports> {
return ReportsModel.fromJson(model); return ReportsModel.fromJson(model);
}).toList(); }).toList();
reportsList=reportsListOriginal.reversed.toList(); reportsList=reportsListOriginal.reversed.toList();
reportsList= reportsListOriginal.where(
(x) => x.doctorName.toString().toLowerCase().contains(doctor.toString().toLowerCase())
).toList();
isReportsDataLoading = false; isReportsDataLoading = false;
}); });
} catch (e) { } catch (e) {
@ -48,7 +106,7 @@ class _AllReportsState extends State<AllReports> {
@override @override
void initState() { void initState() {
gaetAllRecords(); getAllRecords();
super.initState(); super.initState();
} }
@ -244,207 +302,397 @@ class _AllReportsState extends State<AllReports> {
} }
Widget _filtereddata(){
if(reportsList.length!=0){
return ListView.builder(
padding: EdgeInsets.all(0),
itemCount: reportsList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
//color: prescriptionsList[index].cardColor,
child: Padding(
padding:EdgeInsets.all(8) ,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width * .55,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Problem: '+reportsList[index].problem.toString().toUpperCase(),style: problemTextStyle()),
Text(reportsList[index].doctorName.toString().toUpperCase(),style: valuesTextStyle()),
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()),
SizedBox(width:MediaQuery.of(context).size.width * .05,),
Text(reportsList[index].age.toString().toUpperCase()+" Yrs",style: valuesTextStyle()),
],
),
],
),
),
Expanded(child:IconButton(
icon: const Icon(Icons.edit,color: primaryColor,),
onPressed: () {
},
),),
Expanded(child:IconButton(
icon: const Icon(Icons.delete,color: primaryColor,),
onPressed: () async{
showDialog(
//if set to true allow to close popup by tapping out of the popup
//barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Do you want to delete Record?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: ()async {
bool deleteTankStatus = await AppSettings.deleteRecord(reportsList[index].recordId);
if(deleteTankStatus){
getAllRecords();
AppSettings.longSuccessToast('Record deleted successfully');
Navigator.of(context).pop(true);
}
else{
AppSettings.longFailedToast('Record deletion failed');
Navigator.of(context).pop(true);
}
},
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,
)),
),
],
),
);
},
),)
],
),
Row(
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
onPrimary: Colors.white, // foreground
),
onPressed: () async {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new FindingImages(imageDetails:reportsList[index].findingsImages,recordId: reportsList[index].recordId,))).then((value) {
getAllRecords();
});
},
child: Text('Findings: '+reportsList[index].findingsImages.length.toString()),
),
SizedBox(
width:MediaQuery.of(context).size.width * .05,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
onPrimary: Colors.white, // foreground
),
onPressed: () async {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new ReportImages(imageDetails:reportsList[index].reportImages,recordId:reportsList[index].recordId ,))).then((value) {
getAllRecords();
});
},
child: Text('Reports: '+reportsList[index].reportImages.length.toString()),
),
SizedBox(
width:MediaQuery.of(context).size.width * .05,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
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) {
getAllRecords();
});
},
child: Text('Prescriptions: '+reportsList[index].prescriptionImages.length.toString()),
),
],
),
Visibility(
visible: false,
child: Text('Findings',style: headingsTextStyle()),),
Visibility(
visible: false,
child: findings(reportsList[index])),
Visibility(
visible: false,
child: Text('Reports',style: headingsTextStyle()),),
Visibility(
visible: false,
child:reports(reportsList[index]) ),
Visibility(
visible: false,
child: Text('Prescriptions',style: headingsTextStyle()),),
Visibility(
visible:false,
child:prescriptions(reportsList[index]) ),
],
),
),
);
});
}
else{
return Padding(padding: EdgeInsets.fromLTRB(60,10,60,10),
child: Column(
children: [
Text('No records found related to your search'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: Colors.red,
radius: 30,
child: const Icon(
Icons.info,
color: Colors.white,
),
)
],
),);
}
}
Widget _allreports(){ Widget _allreports(){
if(reportsList.length!=0){ if(reportsListOriginal.length!=0){
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Expanded(child:ListView.builder( Container(
padding: EdgeInsets.all(0), padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
itemCount: reportsList.length, child: DropdownButtonFormField(
itemBuilder: (BuildContext context, int index) { // Initial Value
return Card( value: dropdownSearchType,
isExpanded: true,
//color: prescriptionsList[index].cardColor, decoration: const InputDecoration(
child: Padding( prefixIcon: Icon(
padding:EdgeInsets.all(8) , Icons.search,
child: Column( color: greyColor,
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ border: OutlineInputBorder(
Row( borderSide: BorderSide(color: greyColor)),
mainAxisAlignment: MainAxisAlignment.spaceBetween, focusedBorder: OutlineInputBorder(
crossAxisAlignment: CrossAxisAlignment.center, borderSide: BorderSide(color: greyColor),
children: [ ),
enabledBorder: OutlineInputBorder(
Container( borderSide: BorderSide(color: greyColor),
width: MediaQuery.of(context).size.width * .55, ),
child: Column( labelText: 'Search By',
mainAxisAlignment: MainAxisAlignment.start, labelStyle: TextStyle(
crossAxisAlignment: CrossAxisAlignment.start, color: greyColor, //<-- SEE HERE
children: [ ),
Text('Problem: '+reportsList[index].problem.toString().toUpperCase(),style: problemTextStyle()), ),
Text(reportsList[index].doctorName.toString().toUpperCase(),style: valuesTextStyle()),
Text(reportsList[index].hospitalName.toString().toUpperCase(),style: valuesTextStyle()), hint: Text('Select Search Type'),
Text(reportsList[index].date.toString().toUpperCase(),style: valuesTextStyle()), // Down Arrow Icon
Text(reportsList[index].patient_name.toString().toUpperCase(),style: valuesTextStyle()), icon: const Icon(Icons.keyboard_arrow_down),
Row(
children: [ // Array list of items
Text(reportsList[index].gender.toString().toUpperCase(),style: valuesTextStyle()), items: typeOfSearchItems.map((String items) {
SizedBox(width:MediaQuery.of(context).size.width * .05,), return DropdownMenuItem(
Text(reportsList[index].age.toString().toUpperCase()+" Yrs",style: valuesTextStyle()), value: items,
], child: Text(items),
), );
}).toList(),
// After selecting the desired option,it will
], // change button value to selected value
), onChanged: (String? newValue) {
setState(() {
dropdownSearchType = newValue!;
), });
},
),
Expanded(child:IconButton( ),
icon: const Icon(Icons.edit,color: primaryColor,), Visibility(
onPressed: () { visible:dropdownSearchType.toString().toLowerCase()=='problem' ,
child: Container(
height: MediaQuery.of(context).size.height * .07,
}, padding: EdgeInsets.all(5),
),), child: Center(child: TextField(
Expanded(child:IconButton(
icon: const Icon(Icons.delete,color: primaryColor,), cursorColor: primaryColor,
controller: searchController,
onPressed: () async{ onChanged: (string) {
showDialog( if(string.length>=1){
//if set to true allow to close popup by tapping out of the popup getRecordsByProblemName(string);
//barrierDismissible: false, }
context: context, else{
builder: (BuildContext context) => AlertDialog( getAllRecords();
title: const Text('Do you want to delete Record?', }
style: TextStyle( },
color: primaryColor, decoration: InputDecoration(
fontSize: 20, prefixIcon: Icon(
)), Icons.search,
actionsAlignment: MainAxisAlignment.spaceBetween, color: primaryColor,
actions: [ ),
TextButton( /*suffixIcon: Icon(
onPressed: ()async { Icons.clear,
color: greyColor,
bool deleteTankStatus = await AppSettings.deleteRecord(reportsList[index].recordId); ),*/
suffixIcon: IconButton(
icon: Icon(
if(deleteTankStatus){ Icons.clear,
gaetAllRecords(); color: Colors.red,
AppSettings.longSuccessToast('Record deleted successfully');
Navigator.of(context).pop(true);
}
else{
AppSettings.longFailedToast('Record deletion failed');
Navigator.of(context).pop(true);
}
},
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,
)),
),
],
),
);
},
),)
],
),
Row(
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
onPrimary: Colors.white, // foreground
),
onPressed: () async {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new FindingImages(imageDetails:reportsList[index].findingsImages,recordId: reportsList[index].recordId,))).then((value) {
gaetAllRecords();
});
},
child: Text('Findings: '+reportsList[index].findingsImages.length.toString()),
),
SizedBox(
width:MediaQuery.of(context).size.width * .05,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
onPrimary: Colors.white, // foreground
),
onPressed: () async {
Navigator.push(
context,
new MaterialPageRoute(
builder: (__) => new ReportImages(imageDetails:reportsList[index].reportImages)));
},
child: Text('Reports: '+reportsList[index].reportImages.length.toString()),
),
SizedBox(
width:MediaQuery.of(context).size.width * .05,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: primaryColor, // background
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()),
),
],
),
Visibility(
visible: false,
child: Text('Findings',style: headingsTextStyle()),),
Visibility(
visible: false,
child: findings(reportsList[index])),
Visibility(
visible: false,
child: Text('Reports',style: headingsTextStyle()),),
Visibility(
visible: false,
child:reports(reportsList[index]) ),
Visibility(
visible: false,
child: Text('Prescriptions',style: headingsTextStyle()),),
Visibility(
visible:false,
child:prescriptions(reportsList[index]) ),
],
), ),
onPressed: () {
setState(() {
searchController.text='';
});
getAllRecords();
},
), ),
); border: OutlineInputBorder(
}) ), borderSide: BorderSide(color: primaryColor),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
borderRadius: BorderRadius.circular(30),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
borderRadius: BorderRadius.circular(30),
),
//labelText: 'Search by phone number',
hintText: 'Search by problem',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
),)
),),
Visibility(
visible:dropdownSearchType.toString().toLowerCase()=='doctor' ,
child: Container(
height: MediaQuery.of(context).size.height * .07,
padding: EdgeInsets.all(5),
child: Center(child: TextField(
cursorColor: primaryColor,
controller: searchController,
onChanged: (string) {
if(string.length>=1){
getRecordsByDoctorName(string);
}
else{
getAllRecords();
}
},
decoration: InputDecoration(
prefixIcon: Icon(
Icons.search,
color: primaryColor,
),
/*suffixIcon: Icon(
Icons.clear,
color: greyColor,
),*/
suffixIcon: IconButton(
icon: Icon(
Icons.clear,
color: Colors.red,
),
onPressed: () {
setState(() {
searchController.text='';
});
getAllRecords();
},
),
border: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
borderRadius: BorderRadius.circular(30),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
borderRadius: BorderRadius.circular(30),
),
//labelText: 'Search by phone number',
hintText: 'Search by doctor',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
),)
),),
Expanded(child: _filtereddata()),
Padding( Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8), padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar( child: CircleAvatar(
@ -466,7 +714,7 @@ class _AllReportsState extends State<AllReports> {
builder: (context) => AddPrescription()), builder: (context) => AddPrescription()),
);*/ );*/
Navigator.push(context, MaterialPageRoute(builder: (context) => AddReports())).then((value) { Navigator.push(context, MaterialPageRoute(builder: (context) => AddReports())).then((value) {
gaetAllRecords(); getAllRecords();
}); });
//showBoreAddingDialog(); //showBoreAddingDialog();
}, },
@ -483,6 +731,8 @@ class _AllReportsState extends State<AllReports> {
), ),
), ),
]); ]);
} }
else{ else{
return Center( return Center(
@ -507,7 +757,7 @@ class _AllReportsState extends State<AllReports> {
), ),
onPressed: () async { onPressed: () async {
Navigator.push(context, MaterialPageRoute(builder: (context) => AddReports())).then((value) { Navigator.push(context, MaterialPageRoute(builder: (context) => AddReports())).then((value) {
gaetAllRecords(); getAllRecords();
}); });
}, },
), ),

@ -27,7 +27,7 @@ class _FindingImagesState extends State<FindingImages> {
List uiFindingsImages = []; List uiFindingsImages = [];
final ImagePicker _picker = ImagePicker(); final ImagePicker _picker = ImagePicker();
Future pickImageFromGallery() async { /* Future pickImageFromGallery() async {
imageFileList = []; imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage(); final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
@ -35,23 +35,7 @@ class _FindingImagesState extends State<FindingImages> {
imageFileList.addAll(selectedImages); imageFileList.addAll(selectedImages);
} }
var res = await AppSettings.uploadImageForFindings(imageFileList); var res = await AppSettings.updateFindingsGallery(imageFileList,widget.recordId);
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)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
@ -65,7 +49,7 @@ class _FindingImagesState extends State<FindingImages> {
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageForFindingsFromCamera(image); var res = await AppSettings.updateFindingsCamera(image,widget.recordId);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
@ -74,6 +58,22 @@ class _FindingImagesState extends State<FindingImages> {
} on PlatformException catch (e) { } on PlatformException catch (e) {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
} }
}*/
Future pickImageFromGalleryForUpdate() 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.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['findings'];
});
} }
Future takeImageFromCameraForUpdate() async { Future takeImageFromCameraForUpdate() async {
@ -82,7 +82,7 @@ class _FindingImagesState extends State<FindingImages> {
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageForFindingsUpdateFromCamera(image,widget.recordId); var res = await AppSettings.updateFindingsCamera(image,widget.recordId);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
@ -148,22 +148,21 @@ class _FindingImagesState extends State<FindingImages> {
payload["urlType"] = 'findings'; payload["urlType"] = 'findings';
payload["url"] = widget.imageDetails[index]['url']; payload["url"] = widget.imageDetails[index]['url'];
bool deleteStatus = await AppSettings.deleteRecords(payload,widget.recordId); // bool deleteStatus = await AppSettings.deleteRecordsNew(payload,widget.recordId);
try{
if(deleteStatus){ var res = await AppSettings.deleteRecordsNew(payload,widget.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
AppSettings.longSuccessToast("Image deleted Successfully"); AppSettings.longSuccessToast("Image deleted Successfully");
//AllReportsState().getAllRecords(); setState(() {
Navigator.pop(context); widget.imageDetails = jsonDecode(res)['remainingUrls'];
});
} }
else{ catch(e){
print(e);
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast("Image deletion failed"); AppSettings.longFailedToast("Image deletion failed");
} }
}, },
), ),
/* color: Colors.pinkAccent, /* color: Colors.pinkAccent,
@ -186,7 +185,7 @@ class _FindingImagesState extends State<FindingImages> {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
SizedBox(height: MediaQuery.of(context).size.height * .25,), SizedBox(height: MediaQuery.of(context).size.height * .25,),
Text('Click below icon to add new Report'), Text('Click below icon to add new findings'),
SizedBox( SizedBox(
height: 20, height: 20,
), ),
@ -216,7 +215,7 @@ class _FindingImagesState extends State<FindingImages> {
color: primaryColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
await takeImageFromCamera(); await takeImageFromCameraForUpdate();
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
@ -231,7 +230,7 @@ class _FindingImagesState extends State<FindingImages> {
color: primaryColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
await pickImageFromGallery(); await pickImageFromGalleryForUpdate();
Navigator.pop(context); Navigator.pop(context);
}, },
), ),

@ -1,6 +1,8 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:healthcare_user/Reports/allreports.dart'; import 'package:healthcare_user/Reports/allreports.dart';
import 'package:healthcare_user/Reports/order_medicines_new.dart'; import 'package:healthcare_user/Reports/order_medicines_new.dart';
import 'package:healthcare_user/common/settings.dart'; import 'package:healthcare_user/common/settings.dart';
@ -24,8 +26,9 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
final ImagePicker imagePicker = ImagePicker(); final ImagePicker imagePicker = ImagePicker();
List imageFileList = []; List imageFileList = [];
List uiPrescriptionImages = []; List uiPrescriptionImages = [];
final ImagePicker _picker = ImagePicker();
Future pickImageFromGallery() async { /*Future pickImageFromGallery() async {
imageFileList = []; imageFileList = [];
final List<XFile>? selectedImages = await imagePicker.pickMultiImage(); final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
AppSettings.preLoaderDialog(context); AppSettings.preLoaderDialog(context);
@ -33,14 +36,65 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
imageFileList.addAll(selectedImages); imageFileList.addAll(selectedImages);
} }
var res = await AppSettings.uploadImageForPrescriptions(imageFileList); var res = await AppSettings.uploadPrescriptionsGallery(imageFileList);
print(jsonDecode(res)); print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
widget.imageDetails = jsonDecode(res)['findings']; widget.imageDetails = jsonDecode(res)['precription'];
}); });
} }
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.uploadPrescriptionsCamera(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['precription'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}*/
Future pickImageFromGalleryForUpdate() 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.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['prescription'];
});
}
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.updatePrescriptionsCamera(image,widget.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['prescription'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Widget renderUi() { Widget renderUi() {
if (widget.imageDetails.length != 0) { if (widget.imageDetails.length != 0) {
return Column( return Column(
@ -94,26 +148,22 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
.last; .last;
var payload = new Map<String, dynamic>(); var payload = new Map<String, dynamic>();
payload["urlType"] = 'prescriptions'; payload["urlType"] = 'prescription';
payload["url"] = payload["url"] = widget.imageDetails[index]['url'];
widget.imageDetails[index]['url'];
bool deleteStatus =
await AppSettings.deleteRecords(
payload, widget.recordId);
if (deleteStatus) { try{
Navigator.of(context, rootNavigator: true) var res = await AppSettings.deleteRecordsNew(payload,widget.recordId);
.pop(); print(jsonDecode(res));
AppSettings.longSuccessToast( Navigator.of(context, rootNavigator: true).pop();
"Image deleted Successfully"); AppSettings.longSuccessToast("Image deleted Successfully");
//AllReportsState().getAllRecords(); setState(() {
Navigator.pop(context); widget.imageDetails = jsonDecode(res)['remainingUrls'];
} else { });
Navigator.of(context, rootNavigator: true) }
.pop(); catch(e){
AppSettings.longFailedToast( print(e);
"Image deletion failed"); Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast("Image deletion failed");
} }
}, },
), ),
@ -184,7 +234,7 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
color: primaryColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
//await takeImageFromCamera(); await takeImageFromCameraForUpdate();
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
@ -199,7 +249,7 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
color: primaryColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
await pickImageFromGallery(); await pickImageFromGalleryForUpdate();
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
@ -249,12 +299,13 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
color: primaryColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
//await takeImageFromCamera(); await takeImageFromCameraForUpdate();
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
SizedBox( SizedBox(
width: MediaQuery.of(context).size.width * .20, width: MediaQuery.of(context).size.width *
.20,
), ),
GestureDetector( GestureDetector(
child: Icon( child: Icon(
@ -263,7 +314,7 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
color: primaryColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
await pickImageFromGallery(); await pickImageFromGalleryForUpdate();
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
@ -272,6 +323,9 @@ class _PrescriptionImagesState extends State<PrescriptionImages> {
), ),
); );
}); });
}, },
), ),
) )

@ -1,16 +1,93 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:healthcare_user/common/settings.dart'; import 'package:healthcare_user/common/settings.dart';
import 'package:healthcare_user/common/zoom_image.dart'; import 'package:healthcare_user/common/zoom_image.dart';
import 'package:image_picker/image_picker.dart';
class ReportImages extends StatefulWidget { class ReportImages extends StatefulWidget {
var imageDetails; var imageDetails;
ReportImages({this.imageDetails}); var recordId;
ReportImages({this.imageDetails,this.recordId});
@override @override
State<ReportImages> createState() => _ReportImagesState(); State<ReportImages> createState() => _ReportImagesState();
} }
class _ReportImagesState extends State<ReportImages> { class _ReportImagesState extends State<ReportImages> {
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.uploadReportsGallery(imageFileList);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['reports'];
});
}
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.uploadReportsCamera(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['reports'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}*/
Future pickImageFromGalleryForUpdate() 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.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['reports'];
});
}
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.updateReportsCamera(image,widget.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() {
widget.imageDetails = jsonDecode(res)['reports'];
});
} on PlatformException catch (e) {
print('Failed to pick image: $e');
}
}
Widget renderUi() { Widget renderUi() {
@ -55,9 +132,28 @@ class _ReportImagesState extends State<ReportImages> {
), ),
onPressed: () async { onPressed: () async {
AppSettings.preLoaderDialog(context);
String fileName = widget.imageDetails[index]['url'].split('/').last;
var payload = new Map<String, dynamic>();
payload["urlType"] = 'reports';
payload["url"] = widget.imageDetails[index]['url'];
try{
var res = await AppSettings.deleteRecordsNew(payload,widget.recordId);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longSuccessToast("Image deleted Successfully");
setState(() {
widget.imageDetails = jsonDecode(res)['remainingUrls'];
});
}
catch(e){
print(e);
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedToast("Image deletion failed");
}
}, },
), ),
/* color: Colors.pinkAccent, /* color: Colors.pinkAccent,
@ -95,11 +191,46 @@ class _ReportImagesState extends State<ReportImages> {
color: Colors.white, color: Colors.white,
), ),
onPressed: () async { onPressed: () async {
/*Navigator.push( showModalBottomSheet<void>(
context, context: context,
MaterialPageRoute( builder: (BuildContext context) {
builder: (context) => const Login()), 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);
},
),
],
),
),
);
});
}, },
), ),
) )
@ -127,6 +258,48 @@ class _ReportImagesState extends State<ReportImages> {
color: Colors.white, color: Colors.white,
), ),
onPressed: () async { 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);
},
),
],
),
),
);
});
}, },
),) ),)

@ -236,10 +236,12 @@ class AppSettings {
static String getSugarHistoryUrl = host + 'userssugar'; static String getSugarHistoryUrl = host + 'userssugar';
static String addMedicineTimingsUrl = host + 'medicine-timing'; static String addMedicineTimingsUrl = host + 'medicine-timing';
static String getMedicineTimingsUrl = host + 'getmedicineztiming'; static String getMedicineTimingsUrl = host + 'getmedicineztiming';
static String prescriptionUploadPicUrl = host + 'uploads-precription';
static String findingsUploadPicUrl = host + 'uploads-findings-prescription'; static String findingsUploadPicUrl = host + 'uploads-findings-prescription';
static String updateFindingsUploadPicUrl = host + 'update-uploads-findings-prescription'; static String updateFindingsUploadPicUrl = host + 'update-uploads-findings-prescription';
static String updateReportsUploadPicUrl = host + 'update-uploads-reports-prescription';
static String reportsUploadPicUrl = host + 'uploads-reports-prescription'; static String reportsUploadPicUrl = host + 'uploads-reports-prescription';
static String prescriptionUploadPicUrl = host + 'uploads-prescription-prescription';
static String updatePrescriptionPicUrl = host + 'update-uploads-prescription-prescription';
static String recordPrescriptionsUploadPicUrl = host + 'uploads-prescription-prescription'; static String recordPrescriptionsUploadPicUrl = host + 'uploads-prescription-prescription';
static String getAllpharmaciesDataUrl = host + 'getAllPharmacylist'; static String getAllpharmaciesDataUrl = host + 'getAllPharmacylist';
static String getAllQuotationRequestsUrl = host + 'userprecription'; static String getAllQuotationRequestsUrl = host + 'userprecription';
@ -252,6 +254,7 @@ class AppSettings {
static String getRecordsDataUrl = host + 'getAllRecords'; static String getRecordsDataUrl = host + 'getAllRecords';
static String deleteRecordUrl = host + 'deleteRecord'; static String deleteRecordUrl = host + 'deleteRecord';
static String deleteFindingsUrl = host + 'uploads-findings-prescription'; static String deleteFindingsUrl = host + 'uploads-findings-prescription';
static String deletePrescriptionsUrl = host + 'uploads-prescription-prescription';
static String deleteRecordsUrl = host + 'delete-url'; static String deleteRecordsUrl = host + 'delete-url';
@ -720,7 +723,9 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadImageForFindings(file) async { /*upload and update findings*/
static Future<String> uploadFindingsGallery(file) async {
var request = http.MultipartRequest( var request = http.MultipartRequest(
'POST', Uri.parse(findingsUploadPicUrl + '/' + customerId)); 'POST', Uri.parse(findingsUploadPicUrl + '/' + customerId));
@ -734,8 +739,7 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadFindingsCamera(file) async {
static Future<String> uploadImageForFindingsFromCamera(file) async {
var request = http.MultipartRequest('POST', Uri.parse(findingsUploadPicUrl + '/' + customerId)); var request = http.MultipartRequest('POST', Uri.parse(findingsUploadPicUrl + '/' + customerId));
request.files.add(await http.MultipartFile.fromPath('picture', file.path)); request.files.add(await http.MultipartFile.fromPath('picture', file.path));
var res = await request.send(); var res = await request.send();
@ -743,7 +747,7 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadImageForFindingsUpdate(file,var recordId) async { static Future<String> updateFindingsGallery(file,var recordId) async {
var request = http.MultipartRequest( var request = http.MultipartRequest(
'POST', Uri.parse(updateFindingsUploadPicUrl + '/' + customerId+'/'+recordId)); 'POST', Uri.parse(updateFindingsUploadPicUrl + '/' + customerId+'/'+recordId));
@ -757,7 +761,7 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadImageForFindingsUpdateFromCamera(file,var recordId) async { static Future<String> updateFindingsCamera(file,var recordId) async {
var request = http.MultipartRequest('POST', Uri.parse(updateFindingsUploadPicUrl + '/' + customerId+'/'+recordId)); var request = http.MultipartRequest('POST', Uri.parse(updateFindingsUploadPicUrl + '/' + customerId+'/'+recordId));
request.files.add(await http.MultipartFile.fromPath('picture', file.path)); request.files.add(await http.MultipartFile.fromPath('picture', file.path));
var res = await request.send(); var res = await request.send();
@ -765,7 +769,12 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadImageForReports(file) async { /*End*/
/*upload and update Reports*/
static Future<String> uploadReportsGallery(file) async {
var request = http.MultipartRequest( var request = http.MultipartRequest(
'POST', Uri.parse(reportsUploadPicUrl + '/' + customerId)); 'POST', Uri.parse(reportsUploadPicUrl + '/' + customerId));
@ -779,11 +788,45 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadReportsCamera(file) async {
var request = http.MultipartRequest('POST', Uri.parse(reportsUploadPicUrl + '/' + 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> updateReportsGallery(file,var recordId) async {
var request = http.MultipartRequest(
'POST', Uri.parse(updateReportsUploadPicUrl + '/' + 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> updateReportsCamera(file,var recordId) async {
var request = http.MultipartRequest('POST', Uri.parse(updateReportsUploadPicUrl + '/' + 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;
}
/*End*/
static Future<String> uploadImageForPrescriptions(file) async {
/*upload and update Prescriptions*/
static Future<String> uploadPrescriptionsGallery(file) async {
var request = http.MultipartRequest( var request = http.MultipartRequest(
'POST', Uri.parse(recordPrescriptionsUploadPicUrl + '/' + customerId)); 'POST', Uri.parse(prescriptionUploadPicUrl + '/' + customerId));
if (file.length > 0) { if (file.length > 0) {
for (var i = 0; i < file.length; i++) { 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', file[i].path));
@ -794,6 +837,60 @@ class AppSettings {
return response.body; return response.body;
} }
static Future<String> uploadPrescriptionsCamera(file) async {
var request = http.MultipartRequest('POST', Uri.parse(prescriptionUploadPicUrl + '/' + 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> updatePrescriptionsGallery(file,var recordId) async {
var request = http.MultipartRequest(
'POST', Uri.parse(updatePrescriptionPicUrl + '/' + 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> updatePrescriptionsCamera(file,var recordId) async {
var request = http.MultipartRequest('POST', Uri.parse(updatePrescriptionPicUrl + '/' + 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;
}
/*End*/
static Future<String> uploadImageForReports(file) async {
var request = http.MultipartRequest(
'POST', Uri.parse(reportsUploadPicUrl + '/' + customerId));
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> uploadImageForFindingsCamera(file) async { static Future<String> uploadImageForFindingsCamera(file) async {
var request = http.MultipartRequest( var request = http.MultipartRequest(
@ -805,6 +902,8 @@ class AppSettings {
} }
static Future<String> uploadVideoInReportMySelf(file) async { static Future<String> uploadVideoInReportMySelf(file) async {
var request = http.MultipartRequest( var request = http.MultipartRequest(
'POST', Uri.parse(reportMySelfVideoUploadUrl + '/' + customerId)); 'POST', Uri.parse(reportMySelfVideoUploadUrl + '/' + customerId));
@ -1116,6 +1215,35 @@ class AppSettings {
} }
} }
static Future<String> deletePrescriptions(fileName) async {
var uri = Uri.parse(deletePrescriptionsUrl + '/' + customerId+'/'+fileName);
try {
var response = await http.delete(uri, headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return response.body;
} 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 response.body;
} else {
return '';
}
} else {
return '';
}
} else {
return '';
}
} catch (e) {
print(e);
return '';
}
}
static Future<bool> deleteRecords(payload, recordId) async { static Future<bool> deleteRecords(payload, recordId) async {
var uri = Uri.parse(deleteRecordsUrl + '/' + customerId+'/'+recordId); var uri = Uri.parse(deleteRecordsUrl + '/' + customerId+'/'+recordId);
@ -1148,6 +1276,37 @@ class AppSettings {
static Future<String> deleteRecordsNew(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 response.body;
} 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 response.body;
} else {
return '';
}
} else {
return '';
}
} else {
return '';
}
} catch (e) {
print(e);
return '';
}
}

Loading…
Cancel
Save