mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-13 16:38:56 +03:30
beta commit
This commit is contained in:
+310
-265
@@ -1,265 +1,310 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../config/urls.dart';
|
||||
import '../config/user.dart';
|
||||
import '../models/cycles_models.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CyclesProvider extends ChangeNotifier {
|
||||
List<String> labelVals = [];
|
||||
List<TextEditingController> labelValues = [];
|
||||
String initialLabelValue = '';
|
||||
int curLabelVal = 1;
|
||||
|
||||
resetLabelVals() {
|
||||
labelVals = [];
|
||||
labelValues = [];
|
||||
initialLabelValue = '';
|
||||
curLabelVal = 1;
|
||||
// notifyListeners();
|
||||
}
|
||||
|
||||
addLabelVal() {
|
||||
curLabelVal += 1;
|
||||
TextEditingController lbl = new TextEditingController();
|
||||
lbl.text = initialLabelValue;
|
||||
labelValues.add(lbl);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
changeLabelVal(String value, int index) {
|
||||
labelValues[index].text = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String searchBoxValue = '';
|
||||
bool filterOn = false;
|
||||
List<CycleResultObject> items;
|
||||
List<CycleResultObject> originalItems; //before do search on results
|
||||
|
||||
CycleDetailObject result;
|
||||
CycleFilterObject filters = CycleFilterObject(
|
||||
id: '',
|
||||
cycleNumber: '',
|
||||
sterilizerId: '',
|
||||
hospital: '',
|
||||
date: '',
|
||||
);
|
||||
int pageNumber = 1;
|
||||
void resetPageNumber() => pageNumber = 1;
|
||||
bool isloading = false;
|
||||
void resetLoading() {
|
||||
isloading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setLoading() {
|
||||
isloading = true;
|
||||
// notifyListeners();
|
||||
}
|
||||
|
||||
Future<List<Map<String, String>>> getHospitalsFilters() async {
|
||||
var response = await http.get(
|
||||
Uri.parse(Url.filterItems),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
List<Map<String, String>> result = [];
|
||||
var filterDatas = json.decode(response.body);
|
||||
for (var hospital in filterDatas['data']['MedicalCenters']) {
|
||||
result.add({
|
||||
'name': hospital['name'].toString(),
|
||||
'id': hospital['id'].toString()
|
||||
});
|
||||
// print(hospital['name']);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<String>> getLabelFilters() async {
|
||||
var response = await http.get(
|
||||
Uri.parse(Url.labelItems),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
List<String> result = [];
|
||||
var filterDatas = json.decode(response.body);
|
||||
for (var label in filterDatas['data']) {
|
||||
result.add(label['id'].toString());
|
||||
// print(hospital['name']);
|
||||
}
|
||||
labelVals = result;
|
||||
initialLabelValue = labelVals[0];
|
||||
TextEditingController newLbl = new TextEditingController();
|
||||
newLbl.text = initialLabelValue;
|
||||
labelValues.add(newLbl);
|
||||
notifyListeners();
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> createCycleResult(
|
||||
cycleNumber, date, labels, note, sterilizerId) async {
|
||||
List<Map<String, Object>> labs = [];
|
||||
for (var label in labels) {
|
||||
labs.add({'name': '', 'id': label});
|
||||
}
|
||||
// print(labs);
|
||||
var response = await http.post(Uri.parse(Url.createCycleResult),
|
||||
body: json.encode(
|
||||
{
|
||||
'note': note,
|
||||
'labels': labs,
|
||||
'cycle_number': cycleNumber,
|
||||
'date': date,
|
||||
'sterilizer_id': sterilizerId,
|
||||
},
|
||||
),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
});
|
||||
|
||||
print(response.body);
|
||||
}
|
||||
|
||||
void setFilters(id, cycleNumber, sterilizerId, hospital, date) {
|
||||
pageNumber = 1;
|
||||
filters = CycleFilterObject(
|
||||
id: id,
|
||||
cycleNumber: cycleNumber,
|
||||
sterilizerId: sterilizerId,
|
||||
hospital: hospital,
|
||||
date: date,
|
||||
);
|
||||
if (filters.id == '' &&
|
||||
filters.cycleNumber == '' &&
|
||||
filters.sterilizerId == '' &&
|
||||
filters.hospital == '' &&
|
||||
filters.date == '') {
|
||||
filterOn = false;
|
||||
} else {
|
||||
filterOn = true;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void search(String value) {
|
||||
items = [];
|
||||
searchBoxValue = value;
|
||||
originalItems.forEach((result) {
|
||||
if (result.id.toString().contains(searchBoxValue)) {
|
||||
items.add(result);
|
||||
}
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getCycleResults() async {
|
||||
String url = Url.cycleResults(pageNumber);
|
||||
if (filterOn) {
|
||||
items = [];
|
||||
if (filters.id != '') {
|
||||
url += '&cycle_id=${filters.id}';
|
||||
}
|
||||
if (filters.cycleNumber != '') {
|
||||
url += '&cycle_number=${filters.cycleNumber}';
|
||||
}
|
||||
if (filters.sterilizerId != '') {
|
||||
url += '&sterilizer_id=${filters.sterilizerId}';
|
||||
}
|
||||
if (filters.hospital != '') {
|
||||
url += '&medical_center_id=${filters.hospital}';
|
||||
}
|
||||
if (filters.date != '') {
|
||||
url += '&date=${filters.date}';
|
||||
}
|
||||
}
|
||||
// print(url);
|
||||
var response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
|
||||
var testResultData = json.decode(response.body);
|
||||
List<String> labels = [];
|
||||
if (pageNumber == 1) {
|
||||
originalItems = [];
|
||||
items = [];
|
||||
}
|
||||
|
||||
for (var item in testResultData['data']['data']) {
|
||||
// print(item);
|
||||
labels = [];
|
||||
for (var label in item['labels']) {
|
||||
// print(label['id']);
|
||||
labels.add(label['id'].toString());
|
||||
}
|
||||
originalItems.add(
|
||||
CycleResultObject(
|
||||
createdAt: item['date'],
|
||||
id: item['id'].toString(),
|
||||
label: labels,
|
||||
),
|
||||
);
|
||||
}
|
||||
pageNumber += 1;
|
||||
search('');
|
||||
}
|
||||
|
||||
Future<CycleDetailObject> showCycleResult(String id) async {
|
||||
var response = await http.get(Uri.parse(Url.getCycleResult(id)), headers: {
|
||||
'Authorization': User.token,
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
return CycleDetailObject(
|
||||
id: 'null',
|
||||
description: 'null',
|
||||
createDate: 'null',
|
||||
hospitalName: 'null',
|
||||
date: '2020-01-01',
|
||||
sterileId: 'null',
|
||||
cycleNumber: 'null',
|
||||
labels: [],
|
||||
);
|
||||
}
|
||||
var data = json.decode(response.body)['data'];
|
||||
List<String> lablesList = [];
|
||||
for (var label in data['labels']) {
|
||||
lablesList.add(label['id'].toString());
|
||||
}
|
||||
print(data);
|
||||
result = CycleDetailObject(
|
||||
id: data['id'].toString(),
|
||||
description: data['note'] != null ? data['note'] : '',
|
||||
createDate: data['created_at'] != null ? data['created_at'] : '',
|
||||
hospitalName: data['user']['medical_center']['name'],
|
||||
date: data['date'] != null ? data['date'] : '',
|
||||
sterileId: data['sterilizer_id'] != null ? data['sterilizer_id'] : '',
|
||||
cycleNumber: data['cycle_number'] != null ? data['cycle_number'] : '',
|
||||
labels: lablesList,
|
||||
);
|
||||
// result = {
|
||||
// 'id': data['id'],
|
||||
// 'auto_cleave_id': data['inputs']['Autoclave ID'],
|
||||
// 'test_code': data['test_type_id'],
|
||||
// 'date': data['created_at'],
|
||||
// 'verified': data['verified'],
|
||||
// 'description': data['inputs']['Note'],
|
||||
// 'test_type_name': data['test_type']['name'],
|
||||
|
||||
// // 'device_label': data['device_label'],
|
||||
// // 'device_id': data['device_id'],
|
||||
// // 'result': data['result'],
|
||||
// // 'user_name': data['user']['name'],
|
||||
// // 'medical_center': data['user']['medical_center']['name'],
|
||||
// };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
import 'dart:convert';
|
||||
|
||||
import '../config/urls.dart';
|
||||
import '../config/user.dart';
|
||||
import '../models/cycles_models.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class CyclesProvider extends ChangeNotifier {
|
||||
List<String> labelVals = [];
|
||||
List<TextEditingController> labelValues = [];
|
||||
String initialLabelValue = '';
|
||||
int curLabelVal = 1;
|
||||
|
||||
resetLabelVals() {
|
||||
labelVals = [];
|
||||
labelValues = [];
|
||||
initialLabelValue = '';
|
||||
curLabelVal = 1;
|
||||
// notifyListeners();
|
||||
}
|
||||
|
||||
addLabelVal() {
|
||||
curLabelVal += 1;
|
||||
TextEditingController lbl = new TextEditingController();
|
||||
lbl.text = initialLabelValue;
|
||||
labelValues.add(lbl);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
changeLabelVal(String value, int index) {
|
||||
labelValues[index].text = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String searchBoxValue = '';
|
||||
bool filterOn = false;
|
||||
List<CycleResultObject>? items;
|
||||
List<CycleResultObject>? originalItems;
|
||||
|
||||
CycleDetailObject? result;
|
||||
CycleFilterObject? filters = CycleFilterObject(
|
||||
id: '',
|
||||
cycleNumber: '',
|
||||
sterilizerId: '',
|
||||
hospital: '',
|
||||
date: '',
|
||||
);
|
||||
int pageNumber = 1;
|
||||
void resetPageNumber() => pageNumber = 1;
|
||||
bool isloading = false;
|
||||
void resetLoading() {
|
||||
isloading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setLoading() {
|
||||
isloading = true;
|
||||
// notifyListeners();
|
||||
}
|
||||
|
||||
Future<List<Map<String, String>>> getHospitalsFilters() async {
|
||||
var response = await http.get(
|
||||
Uri.parse(Url.filterItems),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
List<Map<String, String>> result = [];
|
||||
var filterDatas = json.decode(response.body);
|
||||
for (var hospital in filterDatas['data']['MedicalCenters']) {
|
||||
result.add({
|
||||
'name': hospital['name'].toString(),
|
||||
'id': hospital['id'].toString()
|
||||
});
|
||||
// print(hospital['name']);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<String>> getLabelFilters() async {
|
||||
var response = await http.get(
|
||||
Uri.parse(Url.labelItems),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
List<String> result = [];
|
||||
var filterDatas = json.decode(response.body);
|
||||
for (var label in filterDatas['data']) {
|
||||
result.add(label['id'].toString());
|
||||
// print(hospital['name']);
|
||||
}
|
||||
labelVals = result;
|
||||
initialLabelValue = labelVals[0];
|
||||
TextEditingController newLbl = new TextEditingController();
|
||||
newLbl.text = initialLabelValue;
|
||||
labelValues.add(newLbl);
|
||||
notifyListeners();
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> createCycleResult(
|
||||
cycleNumber, date, labels, note, sterilizerId) async {
|
||||
List<Map<String, Object>> labs = [];
|
||||
for (var label in labels) {
|
||||
labs.add({'name': '', 'id': label});
|
||||
}
|
||||
// print(labs);
|
||||
var response = await http.post(Uri.parse(Url.createCycleResult),
|
||||
body: json.encode(
|
||||
{
|
||||
'note': note,
|
||||
'labels': labs,
|
||||
'cycle_number': cycleNumber,
|
||||
'date': date,
|
||||
'sterilizer_id': sterilizerId,
|
||||
},
|
||||
),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
});
|
||||
|
||||
print(response.body);
|
||||
}
|
||||
|
||||
Future<void> updateCycleResult(
|
||||
id,
|
||||
sterilizerId,
|
||||
cycleNumber,
|
||||
// label,
|
||||
date,
|
||||
description,
|
||||
) async {
|
||||
var response = await http.put(Uri.parse(Url.updateCycleResult(id)),
|
||||
body: json.encode(
|
||||
{
|
||||
'sterilizer_id': sterilizerId,
|
||||
'cycle_number': cycleNumber,
|
||||
'note': description,
|
||||
// 'label_id': label['id'].toString(),
|
||||
'date': date,
|
||||
},
|
||||
),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
});
|
||||
|
||||
print(response.body);
|
||||
}
|
||||
|
||||
Future<bool> removeCycles(String id) async {
|
||||
var response = await http.post(Uri.parse(Url.removeCycles(id)), body: {
|
||||
'_method': 'delete'
|
||||
}, headers: {
|
||||
'Authorization': User.token,
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
items!.removeWhere((item) {
|
||||
return item.id.toString() == id;
|
||||
});
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
return true;
|
||||
}
|
||||
|
||||
void setFilters(id, cycleNumber, sterilizerId, hospital, date) {
|
||||
pageNumber = 1;
|
||||
filters = CycleFilterObject(
|
||||
id: id,
|
||||
cycleNumber: cycleNumber,
|
||||
sterilizerId: sterilizerId,
|
||||
hospital: hospital,
|
||||
date: date,
|
||||
);
|
||||
if (filters!.id == '' &&
|
||||
filters!.cycleNumber == '' &&
|
||||
filters!.sterilizerId == '' &&
|
||||
filters!.hospital == '' &&
|
||||
filters!.date == '') {
|
||||
filterOn = false;
|
||||
} else {
|
||||
filterOn = true;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void search(String value) {
|
||||
items = [];
|
||||
searchBoxValue = value;
|
||||
originalItems!.forEach((result) {
|
||||
if (result.id.toString().contains(searchBoxValue)) {
|
||||
items!.add(result);
|
||||
}
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getCycleResults() async {
|
||||
String url = Url.cycleResults(pageNumber);
|
||||
if (filterOn) {
|
||||
items = [];
|
||||
if (filters!.id != '') {
|
||||
url += '&cycle_id=${filters!.id}';
|
||||
}
|
||||
if (filters!.cycleNumber != '') {
|
||||
url += '&cycle_number=${filters!.cycleNumber}';
|
||||
}
|
||||
if (filters!.sterilizerId != '') {
|
||||
url += '&sterilizer_id=${filters!.sterilizerId}';
|
||||
}
|
||||
if (filters!.hospital != '') {
|
||||
url += '&medical_center_id=${filters!.hospital}';
|
||||
}
|
||||
if (filters!.date != '') {
|
||||
url += '&date=${filters!.date}';
|
||||
}
|
||||
}
|
||||
// print(url);
|
||||
var response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
|
||||
var testResultData = json.decode(response.body);
|
||||
List<String> labels = [];
|
||||
if (pageNumber == 1) {
|
||||
originalItems = [];
|
||||
items = [];
|
||||
}
|
||||
|
||||
for (var item in testResultData['data']['data']) {
|
||||
// print(item);
|
||||
labels = [];
|
||||
for (var label in item['labels']) {
|
||||
// print(label['id']);
|
||||
labels.add(label['id'].toString());
|
||||
}
|
||||
originalItems!.add(
|
||||
CycleResultObject(
|
||||
createdAt: item['date'],
|
||||
id: item['id'].toString(),
|
||||
label: labels,
|
||||
),
|
||||
);
|
||||
}
|
||||
pageNumber += 1;
|
||||
search('');
|
||||
}
|
||||
|
||||
Future<CycleDetailObject> showCycleResult(String id) async {
|
||||
var response = await http.get(Uri.parse(Url.getCycleResult(id)), headers: {
|
||||
'Authorization': User.token,
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
return CycleDetailObject(
|
||||
id: 'null',
|
||||
description: 'null',
|
||||
createDate: 'null',
|
||||
hospitalName: 'null',
|
||||
date: '2020-01-01',
|
||||
sterileId: 'null',
|
||||
cycleNumber: 'null',
|
||||
labels: [],
|
||||
);
|
||||
}
|
||||
var data = json.decode(response.body)['data'];
|
||||
List<String> lablesList = [];
|
||||
for (var label in data['labels']) {
|
||||
lablesList.add(label['id'].toString());
|
||||
}
|
||||
print(data);
|
||||
result = CycleDetailObject(
|
||||
id: data['id'].toString(),
|
||||
description: data['note'] != null ? data['note'] : '',
|
||||
createDate: data['created_at'] != null ? data['created_at'] : '',
|
||||
hospitalName: data['user']['medical_center']['name'],
|
||||
date: data['date'] != null ? data['date'] : '',
|
||||
sterileId: data['sterilizer_id'] != null ? data['sterilizer_id'] : '',
|
||||
cycleNumber: data['cycle_number'] != null ? data['cycle_number'] : '',
|
||||
labels: lablesList,
|
||||
);
|
||||
// result = {
|
||||
// 'id': data['id'],
|
||||
// 'auto_cleave_id': data['inputs']['Autoclave ID'],
|
||||
// 'test_code': data['test_type_id'],
|
||||
// 'date': data['created_at'],
|
||||
// 'verified': data['verified'],
|
||||
// 'description': data['inputs']['Note'],
|
||||
// 'test_type_name': data['test_type']['name'],
|
||||
|
||||
// // 'device_label': data['device_label'],
|
||||
// // 'device_id': data['device_id'],
|
||||
// // 'result': data['result'],
|
||||
// // 'user_name': data['user']['name'],
|
||||
// // 'medical_center': data['user']['medical_center']['name'],
|
||||
// };
|
||||
return result!;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user