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.
mohemm-flutter-app/lib/core/api.dart

58 lines
2.1 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_UpdateNotIsQueueRecordByID";
class API {
static GetCallRequestInfoByClinincInfo(String deviceIp, {@required Function(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["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList();
final patients = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
calledByNurse.addAll(patients);
calledByNurse.sort((a, b) => a.callNo.compareTo(b.callNo));
// final clinicCurrentPatient = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
onSuccess(calledByNurse);
} 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) {
print("response: $response");
if (status == 200) {
ticket.call_updated = true;
_ticketsUpdated.add(ticket);
}
},
onFailure: (error, status) => onFailure(error));
}
if (_ticketsUpdated.isNotEmpty) {
onSuccess(_ticketsUpdated);
} else {
onFailure(false);
}
}
}