You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.6 KiB
Dart
88 lines
3.6 KiB
Dart
import 'dart:developer';
|
|
import 'dart:io';
|
|
|
|
import 'package:queuing_system/core/base/base_app_client.dart';
|
|
import 'package:queuing_system/core/config/config.dart';
|
|
import 'package:queuing_system/core/response_models/call_config.dart';
|
|
import 'package:queuing_system/core/response_models/patient_call.dart';
|
|
|
|
const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfo_ByIP";
|
|
const _callUpdateNotIsQueueRecordByIDAsync = "/CallRequest_QueueUpdate";
|
|
|
|
class MyHttpOverrides extends HttpOverrides {
|
|
@override
|
|
HttpClient createHttpClient(SecurityContext? context) {
|
|
return super.createHttpClient(context)..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
|
|
}
|
|
}
|
|
|
|
bool isDevMode = true;
|
|
|
|
class API {
|
|
static getCallRequestInfoByClinicInfo(String deviceIp, {required Function(List<Tickets>, List<Tickets>, CallConfig callConfig) onSuccess, required Function(dynamic) onFailure}) async {
|
|
final body = {"ipAdress": deviceIp, "apiKey": apiKey};
|
|
|
|
if (isDevMode) {
|
|
var callPatients = Tickets.testCallPatients;
|
|
var isQueuePatients = callPatients.where((element) => (element.callType == 1 && element.isQueue == false) || (element.callType == 2 && element.isQueue == false)).toList();
|
|
CallConfig callConfig = CallConfig();
|
|
onSuccess(callPatients.reversed.toList(), isQueuePatients.reversed.toList(), callConfig);
|
|
return;
|
|
}
|
|
BaseAppClient.post(_getCallRequestInfoByClinicInfo,
|
|
body: body,
|
|
onSuccess: (apiResp, status) {
|
|
if (status == 200) {
|
|
final response = apiResp["data"];
|
|
|
|
CallConfig callConfig = CallConfig.fromJson(response["callConfig"]);
|
|
var callPatients = (response["callPatients"] as List).map((j) => Tickets.fromJson(j)).toList();
|
|
// final patients = (response["drCallPatients"] as List).map((j) => Tickets.fromJson(j)).toList();
|
|
// callPatients.addAll(patients);
|
|
// log("callPatients: ${callPatients.toString()} ");
|
|
// log("patients: ${patients.toString()} ");
|
|
|
|
var isQueuePatients = callPatients.where((element) => (element.callType == 1 && element.isQueue == false) || (element.callType == 2 && element.isQueue == false)).toList();
|
|
// callPatients.removeWhere((element) => (element.callType == 1 && element.isQueueNurse == false) || (element.callType == 2 && element.isQueueDr == false));
|
|
callPatients.sort((a, b) => a.editedOnTimeStamp!.compareTo(b.editedOnTimeStamp!));
|
|
|
|
// callPatients.addAll(isQueuePatients.toList());
|
|
|
|
onSuccess(callPatients.reversed.toList(), isQueuePatients.reversed.toList(), callConfig);
|
|
} else {
|
|
onFailure(apiResp);
|
|
}
|
|
},
|
|
onFailure: (error, status) => onFailure(error));
|
|
}
|
|
|
|
static callUpdateNotIsQueueRecordByIDAsync(
|
|
String deviceIp, {
|
|
required Tickets ticket,
|
|
required Function(List<Tickets>) onSuccess,
|
|
required Function(dynamic) onFailure,
|
|
}) async {
|
|
List<Tickets> _ticketsUpdated = [];
|
|
|
|
// for (var ticket in tickets) {
|
|
final body = {"id": ticket.id, "apiKey": apiKey, "ipAddress": deviceIp, "callType": ticket.callType};
|
|
await BaseAppClient.post(_callUpdateNotIsQueueRecordByIDAsync,
|
|
body: body,
|
|
onSuccess: (response, status) {
|
|
if (status == 200) {
|
|
ticket.callUpdated = true;
|
|
_ticketsUpdated.add(ticket);
|
|
}
|
|
log("here response: $response");
|
|
},
|
|
onFailure: (error, status) => onFailure(error));
|
|
// }
|
|
|
|
if (_ticketsUpdated.isNotEmpty) {
|
|
onSuccess(_ticketsUpdated);
|
|
} else {
|
|
onFailure(false);
|
|
}
|
|
}
|
|
}
|