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"; const _call_UpdateNotIsQueueRecordByIDAsync = "/Call_UpdateNotIsQueueRecordByID";
class API { 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}; final body = {"IPAdress": deviceIp};
BaseAppClient.post(_getCallRequestInfoByClinicInfo, BaseAppClient.post(_getCallRequestInfoByClinicInfo,
body: body, body: body,
onSuccess: (response, status) { onSuccess: (response, status) {
if (status == 200) { if (status == 200) {
var calledByNurse = (response["CalledByNurse"] as List).map((j) => Tickets.fromJson(j)).toList(); 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(); final patients = (response["ClinicCurrentPatient"] as List).map((j) => Tickets.fromJson(j)).toList();
log("patients Length: ${patients.length}");
calledByNurse.addAll(patients); 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)); // 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 { } else {
onFailure(response); onFailure(response);
} }
@ -40,16 +43,16 @@ class API {
List<Tickets> _ticketsUpdated = []; List<Tickets> _ticketsUpdated = [];
// for (var ticket in tickets) { // for (var ticket in tickets) {
final body = {"CallID": ticket.id}; final body = {"CallID": ticket.id};
await BaseAppClient.post(_call_UpdateNotIsQueueRecordByIDAsync, await BaseAppClient.post(_call_UpdateNotIsQueueRecordByIDAsync,
body: body, body: body,
onSuccess: (response, status) { onSuccess: (response, status) {
if (status == 200) { if (status == 200) {
ticket.callUpdated = true; ticket.callUpdated = true;
_ticketsUpdated.add(ticket); _ticketsUpdated.add(ticket);
} }
}, },
onFailure: (error, status) => onFailure(error)); onFailure: (error, status) => onFailure(error));
// } // }
if (_ticketsUpdated.isNotEmpty) { if (_ticketsUpdated.isNotEmpty) {

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

@ -32,7 +32,7 @@ class _MyHomePageState extends State<MyHomePage> {
SignalRHelper signalRHelper = SignalRHelper(); SignalRHelper signalRHelper = SignalRHelper();
List<Tickets> waitings = []; List<Tickets> waitings = [];
List<Tickets> currents = []; List<Tickets> isQueuePatients = [];
bool isLoading = false; bool isLoading = false;
@ -113,31 +113,32 @@ class _MyHomePageState extends State<MyHomePage> {
} }
onUpdateIPPressed() async { onUpdateIPPressed() async {
if (controller.text.isNotEmpty) { // if (controller.text.isNotEmpty) {
isLoading = true; // isLoading = true;
setState(() {}); // setState(() {});
DEVICE_IP = controller.text; // DEVICE_IP = controller.text;
//
await signalRHelper.connection.stop(); // await signalRHelper.connection.stop();
if (!signalRHelper.getConnectionState()) { // if (!signalRHelper.getConnectionState()) {
await signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect); // await signalRHelper.startSignalRConnection(DEVICE_IP, onUpdateAvailable: onUpdateAvailable, onConnect: onConnect, onConnecting: onConnecting, onDisconnect: onDisconnect);
} // }
//
controller.clear(); // controller.clear();
waitings.clear(); // waitings.clear();
isLoading = false; // isLoading = false;
setState(() {}); // setState(() {});
} // }
} }
Widget content() { Widget content() {
// waitings.removeAt(0);
// waitings = waitings.sublist(0,3); // waitings = waitings.sublist(0,3);
voiceCall(); voiceCall();
if (waitings.isEmpty) { if (waitings.isEmpty) {
// No Patient in Queue // No Patient in Queue
return noPatientInQueue(); return noPatientInQueue();
} else if (waitings.length > 4) { } else if (waitings.length > 3) {
// Return Content With Side List // Return Content With Side List
return priorityTicketsWithSideList(waitings); return priorityTicketsWithSideList(waitings);
} else { } else {
@ -167,31 +168,53 @@ class _MyHomePageState extends State<MyHomePage> {
} }
CallByVoice voiceCaller; CallByVoice voiceCaller;
int callFlag = 0;
voiceCall() async { 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) { if (waitings.isNotEmpty && voiceCaller == null) {
final postVoice = getCallTypeText(waitings.first); final postVoice = getCallTypeText(waitings.first);
voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en'); voiceCaller = CallByVoice(waitings.first.callNoStr.toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en');
await voiceCaller.startCalling(); await voiceCaller.startCalling();
voiceCaller = null; 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 { onUpdateAvailable(data) async {
if (isQueuePatients.isNotEmpty && callFlag == 0) {
callFlag = 1;
return;
}
waitings.clear(); waitings.clear();
API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls) { API.getCallRequestInfoByClinicInfo(DEVICE_IP, onSuccess: (waitingCalls, isQueuePatientsCalls) {
setState(() { setState(() {
waitings = waitingCalls; waitings = waitingCalls;
isQueuePatients = isQueuePatientsCalls;
// currents = currentInClinic; // currents = currentInClinic;
}); });
log("\n\n");
log("--------------------"); log("--------------------");
log("waiting: $waitings"); log("waiting: $waitings");
log("isQueuePatients: $isQueuePatients");
log("--------------------"); log("--------------------");
log("\n\n");
updateTickets(); updateTickets();
}, onFailure: (error) {}); }, onFailure: (error) {});

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

Loading…
Cancel
Save