From 14f1268f669b5f69b79d17488102203ed25a2b9f Mon Sep 17 00:00:00 2001 From: FaizHashmiCS22 Date: Tue, 15 Aug 2023 19:35:46 +0300 Subject: [PATCH] Final testing done --- lib/core/api.dart | 20 +++--- lib/core/response_model/patient_call.dart | 3 + lib/home/home_screen.dart | 79 ++++++++++++++++------- lib/utils/signalR_utils.dart | 7 +- 4 files changed, 71 insertions(+), 38 deletions(-) diff --git a/lib/core/api.dart b/lib/core/api.dart index 869f0e9..2a62101 100644 --- a/lib/core/api.dart +++ b/lib/core/api.dart @@ -24,19 +24,19 @@ class API { onSuccess: (apiResp, status) { if (status == 200) { final response = apiResp["data"]; - var calledByNurse = (response["nurseCallPatients"] as List).map((j) => Tickets.fromJson(j)).toList(); - final patients = (response["drCallPatients"] as List).map((j) => Tickets.fromJson(j)).toList(); - calledByNurse.addAll(patients); - log("NurseCallPatients: ${calledByNurse.toString()} "); - log("patients: ${patients.toString()} "); + 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 = calledByNurse.where((element) => element.isQueueNurse == false || element.isQueueDr == false).toList(); - calledByNurse.removeWhere((element) => element.isQueueNurse == false || element.isQueueDr == false); - // calledByNurse.sort((a, b) => a.callNo.compareTo(b.callNo)); + var isQueuePatients = callPatients.where((element) => (element.callType == 1 && element.isQueueNurse == false) || (element.callType == 2 && element.isQueueDr == 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)); - calledByNurse.addAll(isQueuePatients.toList()); + // callPatients.addAll(isQueuePatients.toList()); - onSuccess(calledByNurse.reversed.toList(), isQueuePatients.reversed.toList()); + onSuccess(callPatients.reversed.toList(), isQueuePatients.reversed.toList()); } else { onFailure(apiResp); } diff --git a/lib/core/response_model/patient_call.dart b/lib/core/response_model/patient_call.dart index ce518ac..abdc159 100644 --- a/lib/core/response_model/patient_call.dart +++ b/lib/core/response_model/patient_call.dart @@ -10,6 +10,7 @@ class Tickets { String doctorNameN; int patientGender; int callType; + int editedOnTimeStamp; String roomNo; String createdOn; String editedOn; @@ -30,6 +31,7 @@ class Tickets { this.doctorNameN, this.patientGender, this.callType, + this.editedOnTimeStamp, this.roomNo, this.createdOn, this.editedOn, @@ -53,6 +55,7 @@ class Tickets { doctorNameN = json['doctorNameN']; patientGender = json['patientGender']; callType = json['callType']; + editedOnTimeStamp = DateTime.parse(json['editedOn']).millisecondsSinceEpoch; roomNo = json['roomNo']; createdOn = json['createdOn']; editedOn = json['editedOn']; diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 0b12ad5..607e902 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -76,9 +76,16 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { + final AudioPlayer audioPlayer = AudioPlayer(); + audioPlayer.playerStateStream.listen((playerState) { + if (playerState.processingState == ProcessingState.completed) { + isCallingInProgress = false; + print("UpdatedInProgresslisten: $isCallingInProgress"); + } + }); return AppScaffold( appBar: AppHeader(), - body: dataContent(), + body: dataContent(audioPlayer), bottomNavigationBar: Container( color: Colors.grey.withOpacity(0.1), height: Utils.getHeight(), @@ -132,10 +139,8 @@ class _MyHomePageState extends State { // } } - Widget dataContent() { - // waitings.removeAt(0); - // waitings = waitings.sublist(0,3); - voiceCall(); + Widget dataContent(AudioPlayer audioPlayer) { + voiceCall(audioPlayer); if (waitings.isEmpty) { // No Patient in Queue @@ -170,7 +175,7 @@ class _MyHomePageState extends State { } CallByVoice voiceCaller; - final AudioPlayer audioPlayer = AudioPlayer(); + int callFlag = 0; bool isRequiredVoice({CallType callType, bool isQueueNurse, bool isQueueDr}) { @@ -183,7 +188,10 @@ class _MyHomePageState extends State { return false; } - voiceCall() async { + bool isCallingInProgress = false; + + voiceCall(AudioPlayer audioPlayer) async { + isCallingInProgress = true; //DONE: 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 print("I am here"); if (waitings.isNotEmpty) { @@ -195,7 +203,7 @@ class _MyHomePageState extends State { )) { audioPlayer.setAsset("assets/tones/call_tone.mp3"); await audioPlayer.play(); - // await Future.delayed(const Duration(seconds: 2)); + await Future.delayed(const Duration(seconds: 2)); } if (waitings.first.isVoiceReq && voiceCaller == null && @@ -247,26 +255,47 @@ class _MyHomePageState extends State { } } - onUpdateAvailable(data) async { - if (isQueuePatients.isNotEmpty && callFlag == 0) { - callFlag = 1; - return; - } - waitings.clear(); - API.getCallRequestInfoByClinicInfo(deviceIPGlobal, onSuccess: (waitingCalls, isQueuePatientsCalls) { - setState(() { - waitings = waitingCalls; - isQueuePatients = isQueuePatientsCalls; - // currents = currentInClinic; + onUpdateAvailable(data, audioPlayer) async { + // if (isQueuePatients.isNotEmpty && callFlag == 0) { + // callFlag = 1; + // return; + // } + print("hereValues: ${isCallingInProgress || voiceCaller != null}"); + if ((isCallingInProgress || voiceCaller != null) && waitings.isNotEmpty) { + Timer(Duration(milliseconds: int.parse(waitings.first.queueDuration)), () { + waitings.clear(); + API.getCallRequestInfoByClinicInfo(deviceIPGlobal, onSuccess: (waitingCalls, isQueuePatientsCalls) { + setState(() { + waitings = waitingCalls; + isQueuePatients = isQueuePatientsCalls; + // currents = currentInClinic; + }); + + log("--------------------"); + log("waiting: $waitings"); + log("isQueuePatients: $isQueuePatients"); + log("--------------------"); + + updateTickets(); + }, onFailure: (error) {}); }); + } else { + waitings.clear(); + API.getCallRequestInfoByClinicInfo(deviceIPGlobal, onSuccess: (waitingCalls, isQueuePatientsCalls) { + setState(() { + waitings = waitingCalls; + isQueuePatients = isQueuePatientsCalls; + // currents = currentInClinic; + }); - log("--------------------"); - log("waiting: $waitings"); - log("isQueuePatients: $isQueuePatients"); - log("--------------------"); + log("--------------------"); + log("waiting: $waitings"); + log("isQueuePatients: $isQueuePatients"); + log("--------------------"); - updateTickets(); - }, onFailure: (error) {}); + updateTickets(); + }, onFailure: (error) {}); + } } updateTickets() { diff --git a/lib/utils/signalR_utils.dart b/lib/utils/signalR_utils.dart index b926d9e..69cc1a0 100644 --- a/lib/utils/signalR_utils.dart +++ b/lib/utils/signalR_utils.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:http/io_client.dart'; +import 'package:just_audio/just_audio.dart'; import 'package:signalr_core/signalr_core.dart'; /* @@ -26,12 +27,12 @@ class SignalRHelper { HubConnection connection; startSignalRConnection(String deviceIp, - {@required Function(dynamic) onUpdateAvailable, @required VoidCallback onConnect, @required Function(dynamic) onDisconnect, @required VoidCallback onConnecting}) async { + {@required Function(dynamic, dynamic) onUpdateAvailable, @required VoidCallback onConnect, @required Function(dynamic) onDisconnect, @required VoidCallback onConnecting}) async { // Hardcoded IP For Testing // deviceIp = "10.10.14.11"; print("Connecting Signal R with: $deviceIp"); - final url = hubBaseURL+"?IPAddress=$deviceIp"; + final url = hubBaseURL + "?IPAddress=$deviceIp"; // final url = hubBaseURL; connection = HubConnectionBuilder() .withUrl( @@ -50,7 +51,7 @@ class SignalRHelper { connection.onreconnected((connectionId) => onConnect()); connection.on('addChatMessage', (message) { - onUpdateAvailable(message); + onUpdateAvailable(message, AudioPlayer()); }); // try {