import 'dart:developer'; import 'package:flutter/cupertino.dart'; import 'package:queuing_system/core/base/base_app_client.dart'; import 'package:queuing_system/core/response_model/patient_call.dart'; const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfoByClinincInfoNew"; const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByIDNew"; class API { static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List, List) onSuccess, @required Function(dynamic) onFailure}) async { final body = {"IPAdress": deviceIp}; BaseAppClient.post(_getCallRequestInfoByClinicInfo, body: body, onSuccess: (response, status) { if (status == 200) { var calledByNurse = (response["CalledByNurseNew"] as List).map((j) => Tickets.fromJson(j)).toList(); final patients = (response["ClinicCurrentPatientNew"] as List).map((j) => Tickets.fromJson(j)).toList(); calledByNurse.addAll(patients); log("CalledByNurseNew: ${calledByNurse.toString()} "); log("patients: ${patients.toString()} "); var isQueuePatients = calledByNurse.where((element) => element.isQueue == false).toList(); calledByNurse.removeWhere((element) => element.isQueue == false); // calledByNurse.sort((a, b) => a.callNo.compareTo(b.callNo)); calledByNurse.addAll(isQueuePatients.toList()); onSuccess(calledByNurse.reversed.toList(), isQueuePatients.reversed.toList()); } else { onFailure(response); } }, 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 = {"CallID": ticket.id}; await BaseAppClient.post(_call_UpdateNotIsQueueRecordByIDAsync, body: body, onSuccess: (response, status) { if (status == 200) { ticket.callUpdated = true; _ticketsUpdated.add(ticket); } }, onFailure: (error, status) => onFailure(error)); // } if (_ticketsUpdated.isNotEmpty) { onSuccess(_ticketsUpdated); } else { onFailure(false); } } }