mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-13 12:18:56 +03:30
commit
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
// import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart' as di;
|
||||
|
||||
import 'package:cssd/config/urls.dart';
|
||||
import 'package:cssd/config/user.dart';
|
||||
@@ -6,8 +10,47 @@ import 'package:cssd/models/test_result_models.dart';
|
||||
// import 'package:cssd/providers/test_result.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:random_string/random_string.dart';
|
||||
// import 'package:multi_image_picker/multi_image_picker.dart';
|
||||
|
||||
class TestResultsProvider with ChangeNotifier {
|
||||
List<File> catchImages = [];
|
||||
List<Uint8List> images = [];
|
||||
|
||||
setImages() async {
|
||||
images = [];
|
||||
for (var image in catchImages) {
|
||||
var result = image.readAsBytesSync();
|
||||
// final batchId = randomString(10);
|
||||
// addImage(batchId, result, image.path);
|
||||
images.add(result.buffer
|
||||
.asUint8List(result.offsetInBytes, result.lengthInBytes));
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
setCatchImages(List<File> images) {
|
||||
catchImages = images;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
removeImage(int index) {
|
||||
catchImages.removeAt(index);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Future<String> addImage() async {
|
||||
// Map<dynamic, dynamic> imgs = {};
|
||||
// var counter = 0;
|
||||
// for (var image in images) {
|
||||
// imgs[counter.toString()] =
|
||||
// di.MultipartFile.fromBytes(image, filename: 'test$counter.jpg');
|
||||
// counter += 1;
|
||||
// }
|
||||
|
||||
// return 'True';
|
||||
// }
|
||||
|
||||
String searchBoxValue = '';
|
||||
bool filterOn = false;
|
||||
List<TestResultObject> items;
|
||||
@@ -157,14 +200,16 @@ class TestResultsProvider with ChangeNotifier {
|
||||
items = [];
|
||||
}
|
||||
for (var item in testResultData['data']['data']) {
|
||||
// print(item);
|
||||
originalItems.add(
|
||||
TestResultObject(
|
||||
id: item['id'].toString(),
|
||||
name: item['test_type']['name'],
|
||||
deviceId: item['device_id'].toString(),
|
||||
result: item['verified'] == 'Verified' ? 'Verified' : 'Not Verified',
|
||||
date: item['date'],
|
||||
result: item['result'] == 'Accept' ? 'Accepted' : 'Not Accepted',
|
||||
date: item['created_at'].toString().substring(0, 10),
|
||||
hospital: item['user']['medical_center']['name'],
|
||||
verified: item['verified'].toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -187,16 +232,75 @@ class TestResultsProvider with ChangeNotifier {
|
||||
print(response.body);
|
||||
}
|
||||
|
||||
static Future<void> createTestResult(values) async {
|
||||
var response = await http
|
||||
.post(Url.createTestResult, body: json.encode(values), headers: {
|
||||
Future<String> addImage(String batchId, dynamic file, String fileName) async {
|
||||
var imageListInt = file.cast<int>();
|
||||
var dio = new di.Dio();
|
||||
dio.options.headers = {
|
||||
'Authorization': User.token,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
di.FormData formData = new di.FormData.fromMap({
|
||||
"batch_id": batchId,
|
||||
'model_type': 'TestResult',
|
||||
"file": di.MultipartFile.fromBytes(imageListInt, filename: fileName)
|
||||
});
|
||||
|
||||
print(response.body);
|
||||
var response = await dio.post(
|
||||
Url.addImage,
|
||||
data: formData,
|
||||
);
|
||||
// print(response.statusCode);
|
||||
// print(response.statusMessage);
|
||||
// print(response.data);
|
||||
|
||||
return 'Added';
|
||||
}
|
||||
|
||||
Future<String> createTestResult(values, batchId) async {
|
||||
final batchId = randomString(10);
|
||||
|
||||
for (var image in catchImages) {
|
||||
await addImage(batchId, image.readAsBytesSync(), image.path);
|
||||
}
|
||||
dynamic vals = values;
|
||||
vals['file_batch_id'] = batchId;
|
||||
|
||||
// int counter = 0;
|
||||
// if (images.length != 0) {
|
||||
// for (var image in images) {
|
||||
// vals['imgs'][counter.toString()] = base64Encode(
|
||||
// image,
|
||||
// );
|
||||
// counter += 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
var dio = new di.Dio();
|
||||
dio.options.headers = {
|
||||
'Authorization': User.token,
|
||||
// 'X-Requested-With': 'XMLHttpRequest'
|
||||
};
|
||||
var response = await dio.post(
|
||||
Url.createTestResult,
|
||||
data: vals,
|
||||
);
|
||||
print(response.data);
|
||||
if (response.data['status'] == 'Success') {
|
||||
catchImages = [];
|
||||
return 'done';
|
||||
} else {
|
||||
return 'error';
|
||||
}
|
||||
// var response = await http
|
||||
// .post(Url.createTestResult, body: json.encode(values), headers: {
|
||||
// 'Authorization': User.token,
|
||||
// 'X-Requested-With': 'XMLHttpRequest',
|
||||
// "Content-Type": "application/json",
|
||||
// "Accept": "application/json"
|
||||
// });
|
||||
|
||||
// print(response.body);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> showTestResult(String id) async {
|
||||
@@ -213,11 +317,16 @@ class TestResultsProvider with ChangeNotifier {
|
||||
: '',
|
||||
'test_code': data['test_type_id'] != null ? data['test_type_id'] : '',
|
||||
'date': data['created_at'] != null ? data['created_at'] : '',
|
||||
'verified': data['verified'] != null ? data['verified'] : '',
|
||||
'accepted': originalItems
|
||||
.firstWhere((element) => element.id == data['id'].toString())
|
||||
.result, //az api safheye asli estefade mishavad
|
||||
'description':
|
||||
data['inputs']['Note'] != null ? data['inputs']['Note'] : '',
|
||||
'test_type_name':
|
||||
data['test_type']['name'] != null ? data['test_type']['name'] : '',
|
||||
'hospital': originalItems
|
||||
.firstWhere((element) => element.id == data['id'].toString())
|
||||
.hospital // az api safheye asli estefade mi shavad
|
||||
};
|
||||
return result;
|
||||
}
|
||||
@@ -238,4 +347,28 @@ class TestResultsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> changeVerification(String id, String value) async {
|
||||
print(id);
|
||||
print(value);
|
||||
var response = await http.post(
|
||||
Url.testResultVerification(id, value),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
},
|
||||
);
|
||||
var testResultData = json.decode(response.body);
|
||||
// print(response.body);
|
||||
try {
|
||||
if (testResultData['status'] == 'Success') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user