import 'dart:developer'; import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:queuing_system/core/base/base_app_client.dart'; import 'package:queuing_system/core/config/config.dart'; import 'package:queuing_system/core/response_model/patient_call.dart'; import 'package:queuing_system/home/home_screen.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; } } class API { static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List, List) 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(); onSuccess(callPatients.reversed.toList(), isQueuePatients.reversed.toList()); return; } BaseAppClient.post(_getCallRequestInfoByClinicInfo, body: body, onSuccess: (apiResp, status) { if (status == 200) { final response = apiResp["data"]; 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()); } else { onFailure(apiResp); } }, onFailure: (error, status) => onFailure(error)); } static callUpdateNotIsQueueRecordByIDAsync(String deviceIp, {@required Tickets ticket, @required Function(List) onSuccess, @required Function(dynamic) onFailure}) async { if (ticket.id == null) { return; } List _ticketsUpdated = []; // for (var ticket in tickets) { final body = {"id": ticket.id, "apiKey": apiKey, "ipAddress": deviceIp}; 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); } } }