Added ISQueue and QueueDuration

dev_faiz
Faiz Hashmi 3 years ago
parent 16f3bfc221
commit 482f83c35d

@ -8,23 +8,26 @@ const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfoByClinincInfo";
const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByID";
class API {
static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List<Tickets>) onSuccess, @required Function(dynamic) onFailure}) async {
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["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList();
log("calledByNurse Length: ${calledByNurse.length}");
final patients = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
log("patients Length: ${patients.length}");
calledByNurse.addAll(patients);
log("calledByNurse: ${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));
onSuccess(calledByNurse.reversed.toList());
calledByNurse.addAll(isQueuePatients.toList());
onSuccess(calledByNurse.reversed.toList(), isQueuePatients.reversed.toList());
} else {
onFailure(response);
}

@ -16,10 +16,11 @@ class Tickets {
this.patientID,
this.callNoStr,
this.queueNo,
this.queueDuration,
});
int getRandomNum() {
return Random().nextInt(1);
return Random().nextInt(2);
}
Tickets.fromJson(dynamic json) {
@ -35,8 +36,10 @@ class Tickets {
patientGender = json['PatientGender'];
patientID = json['PatientID'];
queueNo = json['QueueNo'];
queueDuration = json['QueueDuration'];
callNoStr = json['CallNoStr'] ?? json['CallNo'].toString();
isAcknowledged = getRandomNum();
isQueue = json["ISQueue"] ?? false;
// isQueue = getRandomNum();
}
int id;
@ -51,9 +54,10 @@ class Tickets {
int patientGender;
int patientID;
String queueNo;
String queueDuration;
String callNoStr;
bool callUpdated = false;
int isAcknowledged;
bool isQueue;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
@ -70,6 +74,8 @@ class Tickets {
map['PatientID'] = patientID;
map['CallNoStr'] = callNoStr;
map['QueueNo'] = queueNo;
map['QueueDuration'] = queueDuration;
map['ISQueue'] = isQueue;
return map;
}

@ -32,7 +32,7 @@ class _MyHomePageState extends State<MyHomePage> {
SignalRHelper signalRHelper = SignalRHelper();
List<Tickets> waitings = [];
List<Tickets> currents = [];
List<Tickets> isQueuePatients = [];
bool isLoading = false;
@ -113,31 +113,32 @@ class _MyHomePageState extends State<MyHomePage> {
}
onUpdateIPPressed() async {
if (controller.text.isNotEmpty) {
isLoading = true;
setState(() {});
DEVICE_IP = controller.text;
await signalRHelper.connection.stop();
if (!signalRHelper.getConnectionState()) {
await signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect);
}
controller.clear();
waitings.clear();
isLoading = false;
setState(() {});
}
// if (controller.text.isNotEmpty) {
// isLoading = true;
// setState(() {});
// DEVICE_IP = controller.text;
//
// await signalRHelper.connection.stop();
// if (!signalRHelper.getConnectionState()) {
// await signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect);
// }
//
// controller.clear();
// waitings.clear();
// isLoading = false;
// setState(() {});
// }
}
Widget content() {
// waitings.removeAt(0);
// waitings = waitings.sublist(0,3);
voiceCall();
if (waitings.isEmpty) {
// No Patient in Queue
return noPatientInQueue();
} else if (waitings.length > 4) {
} else if (waitings.length > 3) {
// Return Content With Side List
return priorityTicketsWithSideList(waitings);
} else {
@ -167,31 +168,53 @@ class _MyHomePageState extends State<MyHomePage> {
}
CallByVoice voiceCaller;
int callFlag = 0;
voiceCall() async {
//TODO: After calling this voice call, we should delay for milliseconds that is given by API. After that we will check if there are more patients in isQueuePatients we will remove the patient from waiting list and then update the state
if (waitings.isNotEmpty && voiceCaller == null) {
final postVoice = getCallTypeText(waitings.first);
voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en');
await voiceCaller.startCalling();
voiceCaller = null;
log("isQueuePatients : ${isQueuePatients.length}");
}
if (isQueuePatients.isNotEmpty) {
await Future.delayed(Duration(milliseconds: int.parse(isQueuePatients.first.queueDuration) * 10)).whenComplete(() async {
isQueuePatients.removeAt(0);
Tickets ticket = waitings.elementAt(0);
waitings.removeAt(0);
waitings.add(ticket);
if (isQueuePatients.isNotEmpty) {
setState(() {});
}
if (isQueuePatients.isEmpty && callFlag == 1) {
callFlag == 0;
log("Done : ${isQueuePatients.length}");
await Future.delayed(const Duration(seconds: 3));
}
});
}
}
onUpdateAvailable(data) async {
if (isQueuePatients.isNotEmpty && callFlag == 0) {
callFlag = 1;
return;
}
waitings.clear();
API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls) {
API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls, isQueuePatientsCalls) {
setState(() {
waitings = waitingCalls;
isQueuePatients = isQueuePatientsCalls;
// currents = currentInClinic;
});
log("\n\n");
log("--------------------");
log("waiting: $waitings");
log("isQueuePatients: $isQueuePatients");
log("--------------------");
log("\n\n");
updateTickets();
}, onFailure: (error) {});

@ -20,8 +20,6 @@ class CallByVoice {
Future<dynamic> _getLanguages() async => await textToSpeech.getLanguages;
startCalling() async {
log("languages: ${await _getLanguages()}");
log("no: $ticketNo");
textToSpeech.setLanguage("en-US");
var splitText = ticketNo.split("-");
// Create Pre Voice Players

Loading…
Cancel
Save