|
|
|
|
@ -10,6 +10,7 @@ import 'package:hmg_qline/repositories/signalR_repo.dart';
|
|
|
|
|
import 'package:hmg_qline/services/audio_service.dart';
|
|
|
|
|
import 'package:hmg_qline/services/cache_service.dart';
|
|
|
|
|
import 'package:hmg_qline/services/text_to_speech_service.dart';
|
|
|
|
|
import 'package:hmg_qline/utilities/enums.dart';
|
|
|
|
|
import 'package:hmg_qline/view_models/screen_config_view_model.dart';
|
|
|
|
|
|
|
|
|
|
class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
@ -46,7 +47,7 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initializeAudioPlayer() {
|
|
|
|
|
audioService.listenAudioPlayerEvents(onAudioCompleted: onToneCompleted);
|
|
|
|
|
audioService.listenAudioPlayerEvents(onToneCompleted: onToneCompleted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initializeTextToSpeech() {
|
|
|
|
|
@ -54,10 +55,16 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onHubConfigCall(var response) async {
|
|
|
|
|
log("onHubConfigCall: $response");
|
|
|
|
|
if (response != null && response.isNotEmpty) {
|
|
|
|
|
var data = response.first['data'];
|
|
|
|
|
GlobalConfigurationsModel globalConfigurationsModel = GlobalConfigurationsModel.fromJson(data as Map<String, dynamic>);
|
|
|
|
|
GlobalConfigurationsModel globalConfigurationsModel = GlobalConfigurationsModel.fromJson(
|
|
|
|
|
json: data,
|
|
|
|
|
qType: response.first['qType'] ?? 1,
|
|
|
|
|
screenType: response.first['screenType'] ?? 1,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
log("onHubConfigCall: ${globalConfigurationsModel.toString()}");
|
|
|
|
|
|
|
|
|
|
ScreenConfigViewModel screenConfigViewModel = getIt.get<ScreenConfigViewModel>();
|
|
|
|
|
screenConfigViewModel.updateGlobalConfigurationsModel(value: globalConfigurationsModel, needNotify: true, shouldUpdateNextPrayer: true);
|
|
|
|
|
}
|
|
|
|
|
@ -81,11 +88,8 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
Future<void> onToneCompleted() async {
|
|
|
|
|
GlobalConfigurationsModel globalConfigurationsModel = getIt.get<ScreenConfigViewModel>().globalConfigurationsModel;
|
|
|
|
|
if (globalConfigurationsModel.isVoiceReq) {
|
|
|
|
|
textToSpeechService.speechText(
|
|
|
|
|
globalConfigurationsModel: globalConfigurationsModel,
|
|
|
|
|
ticket: currentTickets.first,
|
|
|
|
|
);
|
|
|
|
|
if (true) {
|
|
|
|
|
await textToSpeechService.speechText(globalConfigurationsModel: globalConfigurationsModel, ticket: currentTickets.first, isMute: !(globalConfigurationsModel.isVoiceReq));
|
|
|
|
|
} else {
|
|
|
|
|
waitAndCallNextTicketIfAvailable();
|
|
|
|
|
}
|
|
|
|
|
@ -102,7 +106,12 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
GlobalConfigurationsModel globalConfigurationsModel = getIt.get<ScreenConfigViewModel>().globalConfigurationsModel;
|
|
|
|
|
Timer(Duration(seconds: globalConfigurationsModel.concurrentCallDelaySec), () async {
|
|
|
|
|
if (queueTickets.isNotEmpty) {
|
|
|
|
|
int index = itemAlreadyAvailableAtIndex(ticketToSearch: queueTickets.first, listToSearchIn: currentTickets);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
currentTickets.removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
currentTickets.insert(0, queueTickets.first);
|
|
|
|
|
|
|
|
|
|
if (currentTickets.length > globalConfigurationsModel.screenMaxDisplayPatients) {
|
|
|
|
|
currentTickets.removeLast();
|
|
|
|
|
}
|
|
|
|
|
@ -117,12 +126,29 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
Future<void> onHubTicketCall(List<Object?>? response) async {
|
|
|
|
|
logger.i("onHubTicketCall: $response");
|
|
|
|
|
log("isCallingInProgress: $isCallingInProgress");
|
|
|
|
|
if (response != null && response.isNotEmpty) {
|
|
|
|
|
TicketDetailsModel ticketDetailsModel = TicketDetailsModel.fromJson(response.first as Map<String, dynamic>);
|
|
|
|
|
addNewTicket(ticketDetailsModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int itemAlreadyAvailableAtIndex({required TicketDetailsModel ticketToSearch, required List<TicketDetailsModel> listToSearchIn}) {
|
|
|
|
|
int isFoundAt = -1;
|
|
|
|
|
try {
|
|
|
|
|
isFoundAt = listToSearchIn.indexWhere((ticket) {
|
|
|
|
|
log("ticket.ticketModel!.queueNo: ${ticket.ticketModel!.queueNo}");
|
|
|
|
|
log("ticketToSearch.ticketModel!.queueNo: ${ticketToSearch.ticketModel!.queueNo}");
|
|
|
|
|
return ticket.ticketModel!.queueNo == ticketToSearch.ticketModel!.queueNo;
|
|
|
|
|
});
|
|
|
|
|
log("itemAlreadyAvailableAtIndex: $isFoundAt");
|
|
|
|
|
return isFoundAt;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log("Error isItemAlreadyAvailableInList: ${e.toString()}");
|
|
|
|
|
return isFoundAt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isCallingInProgress = false;
|
|
|
|
|
|
|
|
|
|
// Tickets Management
|
|
|
|
|
@ -131,13 +157,22 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
void addNewTicket(TicketDetailsModel ticket) {
|
|
|
|
|
if (!isCallingInProgress) {
|
|
|
|
|
int index = itemAlreadyAvailableAtIndex(ticketToSearch: ticket, listToSearchIn: currentTickets);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
currentTickets.removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
currentTickets.insert(0, ticket);
|
|
|
|
|
|
|
|
|
|
GlobalConfigurationsModel globalConfigurationsModel = getIt.get<ScreenConfigViewModel>().globalConfigurationsModel;
|
|
|
|
|
if (currentTickets.length > globalConfigurationsModel.screenMaxDisplayPatients) {
|
|
|
|
|
currentTickets.removeLast();
|
|
|
|
|
}
|
|
|
|
|
callTicketOnScreen(ticketData: currentTickets.first.ticketModel);
|
|
|
|
|
} else {
|
|
|
|
|
int index = itemAlreadyAvailableAtIndex(ticketToSearch: ticket, listToSearchIn: queueTickets);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
queueTickets.removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
queueTickets.add(ticket);
|
|
|
|
|
log("inQueue Length: ${queueTickets.length}");
|
|
|
|
|
}
|
|
|
|
|
@ -152,19 +187,49 @@ class QueuingViewModel extends ChangeNotifier {
|
|
|
|
|
if (ticketData == null) return;
|
|
|
|
|
ScreenConfigViewModel screenConfigViewModel = getIt.get<ScreenConfigViewModel>();
|
|
|
|
|
GlobalConfigurationsModel globalConfigurationsModel = screenConfigViewModel.globalConfigurationsModel;
|
|
|
|
|
screenConfigViewModel.acknowledgeTicket(ticketQueueID: ticketData.id!.toString());
|
|
|
|
|
if (globalConfigurationsModel.isToneReq) {
|
|
|
|
|
if (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment) {
|
|
|
|
|
screenConfigViewModel.acknowledgeTicketForAppointmentOnly(
|
|
|
|
|
ticketQueueID: ticketData.id ?? 0,
|
|
|
|
|
ipAddress: screenConfigViewModel.currentScreenIP,
|
|
|
|
|
callTypeEnum: ticketData.callTypeEnum,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
screenConfigViewModel.acknowledgeTicket(ticketQueueID: ticketData.id ?? 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log("globalConfigurationsModel: ${globalConfigurationsModel.toString()}");
|
|
|
|
|
if (true) {
|
|
|
|
|
isCallingInProgress = true;
|
|
|
|
|
await audioService.playTone(path: AppAssets.callTone, isMute: false );
|
|
|
|
|
await audioService.playTone(path: AppAssets.callTone, isMute: !(globalConfigurationsModel.isToneReq));
|
|
|
|
|
} else if (globalConfigurationsModel.isVoiceReq) {
|
|
|
|
|
isCallingInProgress = true;
|
|
|
|
|
await textToSpeechService.speechText(
|
|
|
|
|
globalConfigurationsModel: globalConfigurationsModel,
|
|
|
|
|
ticket: currentTickets.first,
|
|
|
|
|
isMute: false
|
|
|
|
|
);
|
|
|
|
|
await textToSpeechService.speechText(globalConfigurationsModel: globalConfigurationsModel, ticket: currentTickets.first, isMute: !(globalConfigurationsModel.isVoiceReq));
|
|
|
|
|
} else {
|
|
|
|
|
waitAndCallNextTicketIfAvailable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Future<void> callTicketOnScreen({required TicketData? ticketData}) async {
|
|
|
|
|
// if (ticketData == null) return;
|
|
|
|
|
// ScreenConfigViewModel screenConfigViewModel = getIt.get<ScreenConfigViewModel>();
|
|
|
|
|
// GlobalConfigurationsModel globalConfigurationsModel = screenConfigViewModel.globalConfigurationsModel;
|
|
|
|
|
// if (globalConfigurationsModel.qTypeEnum == QTypeEnum.appointment) {
|
|
|
|
|
// screenConfigViewModel.acknowledgeTicketForAppointmentOnly(
|
|
|
|
|
// ticketQueueID: ticketData.id ?? 0,
|
|
|
|
|
// ipAddress: screenConfigViewModel.currentScreenIP,
|
|
|
|
|
// callTypeEnum: ticketData.callTypeEnum,
|
|
|
|
|
// );
|
|
|
|
|
// } else {
|
|
|
|
|
// screenConfigViewModel.acknowledgeTicket(ticketQueueID: ticketData.id ?? 0);
|
|
|
|
|
// }
|
|
|
|
|
// if (globalConfigurationsModel.isToneReq) {
|
|
|
|
|
// isCallingInProgress = true;
|
|
|
|
|
// await audioService.playTone(path: AppAssets.callTone, isMute: !(globalConfigurationsModel.isToneReq));
|
|
|
|
|
// } else if (globalConfigurationsModel.isVoiceReq) {
|
|
|
|
|
// isCallingInProgress = true;
|
|
|
|
|
// await textToSpeechService.speechText(globalConfigurationsModel: globalConfigurationsModel, ticket: currentTickets.first, isMute: !(globalConfigurationsModel.isVoiceReq));
|
|
|
|
|
// } else {
|
|
|
|
|
// waitAndCallNextTicketIfAvailable();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|