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

83 lines
3.4 KiB
Dart

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<Tickets>, List<Tickets>) 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<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async {
if (ticket.id == null) {
return;
}
List<Tickets> _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);
}
}
}