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.
64 lines
2.4 KiB
Dart
64 lines
2.4 KiB
Dart
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 = "/GetCallRequestInfoByIP";
|
|
const _call_UpdateNotIsQueueRecordByIDAsync = "/UpdateCallRequestQueue";
|
|
|
|
class API {
|
|
static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List<Tickets>, List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async {
|
|
final body = {"IPAdress": deviceIp};
|
|
BaseAppClient.post(_getCallRequestInfoByClinicInfo,
|
|
body: body,
|
|
onSuccess: (response, status) {
|
|
if (status == 200) {
|
|
var calledByNurse = (response["NurseCallPatients"] as List).map((j) => Tickets.fromJson(j)).toList();
|
|
final patients = (response["DrCallPatients"] as List).map((j) => Tickets.fromJson(j)).toList();
|
|
calledByNurse.addAll(patients);
|
|
log("NurseCallPatients: ${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<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async {
|
|
if (ticket.id == null) {
|
|
return;
|
|
}
|
|
|
|
List<Tickets> _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);
|
|
}
|
|
}
|
|
}
|