From 482f83c35dc6c04c19a3b575bfbfaac65298dd5b Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Wed, 8 Feb 2023 09:36:54 +0300 Subject: [PATCH] Added ISQueue and QueueDuration --- lib/core/api.dart | 33 ++++++------ lib/core/response_model/patient_call.dart | 12 +++-- lib/home/home_screen.dart | 65 +++++++++++++++-------- lib/utils/call_by_voice.dart | 2 - 4 files changed, 71 insertions(+), 41 deletions(-) diff --git a/lib/core/api.dart b/lib/core/api.dart index e64c53d..f5de6f1 100644 --- a/lib/core/api.dart +++ b/lib/core/api.dart @@ -8,23 +8,26 @@ const _getCallRequestInfoByClinicInfo = "/GetCallRequestInfoByClinincInfo"; const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByID"; class API { - static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List) onSuccess, @required Function(dynamic) onFailure}) async { + static getCallRequestInfoByClinicInfo(String deviceIp, {@required Function(List, List) 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); } @@ -40,16 +43,16 @@ class API { List _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)); + 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) { diff --git a/lib/core/response_model/patient_call.dart b/lib/core/response_model/patient_call.dart index dc1332b..ca93354 100644 --- a/lib/core/response_model/patient_call.dart +++ b/lib/core/response_model/patient_call.dart @@ -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 toJson() { final map = {}; @@ -70,6 +74,8 @@ class Tickets { map['PatientID'] = patientID; map['CallNoStr'] = callNoStr; map['QueueNo'] = queueNo; + map['QueueDuration'] = queueDuration; + map['ISQueue'] = isQueue; return map; } diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index beac166..cac83bf 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -32,7 +32,7 @@ class _MyHomePageState extends State { SignalRHelper signalRHelper = SignalRHelper(); List waitings = []; - List currents = []; + List isQueuePatients = []; bool isLoading = false; @@ -113,31 +113,32 @@ class _MyHomePageState extends State { } 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 { } 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) {}); diff --git a/lib/utils/call_by_voice.dart b/lib/utils/call_by_voice.dart index 910e82d..a23887c 100644 --- a/lib/utils/call_by_voice.dart +++ b/lib/utils/call_by_voice.dart @@ -20,8 +20,6 @@ class CallByVoice { Future _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