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.
queuing_system/lib/core/api.dart

48 lines
1.8 KiB
Dart

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 = "/GetCallRequestInfoByClinincInfo";
const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByIDAsync";
class API{
static GetCallRequestInfoByClinincInfo(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){
final calledByNurse = (response["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList();
final clinicCurrentPatient = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
onSuccess(calledByNurse, clinicCurrentPatient);
}else{
onFailure(response);
}
}, onFailure: (error, status) => onFailure(error));
}
static Call_UpdateNotIsQueueRecordByIDAsync(String deviceIp, {@required List<Tickets> tickets, @required Function(List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async{
if(tickets.isEmpty) {
return;
}
List<Tickets> _ticketsUpdated = [];
for (var ticket in tickets) {
final body = { "CallID" : ticket.callNo};
await BaseAppClient.post(_call_UpdateNotIsQueueRecordByIDAsync, body: body, onSuccess: (response, status){
if(status == 200){
ticket.call_updated = true;
_ticketsUpdated.add(ticket);
}
}, onFailure: (error, status) => onFailure(error));
}
if(_ticketsUpdated.isNotEmpty) {
onSuccess(_ticketsUpdated);
}else{
onFailure(false);
}
}
}