diff --git a/lib/core/api.dart b/lib/core/api.dart index dbab356..43a9d99 100644 --- a/lib/core/api.dart +++ b/lib/core/api.dart @@ -23,17 +23,7 @@ class API { if (isDevMode) { var callPatients = Tickets.testCallPatients; - // 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 = 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)); - - // callPatients.addAll(isQueuePatients.toList()); - + var isQueuePatients = callPatients.where((element) => (element.callType == 1 && element.isQueue == false) || (element.callType == 2 && element.isQueue == false)).toList(); onSuccess(callPatients.reversed.toList(), isQueuePatients.reversed.toList()); return; } @@ -48,7 +38,7 @@ class API { // log("callPatients: ${callPatients.toString()} "); // log("patients: ${patients.toString()} "); - var isQueuePatients = callPatients.where((element) => (element.callType == 1 && element.isQueueNurse == false) || (element.callType == 2 && element.isQueueDr == false)).toList(); + var isQueuePatients = callPatients.where((element) => (element.callType == 1 && element.isQueue == false) || (element.callType == 2 && element.isQueue == 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)); diff --git a/lib/core/response_model/call_config.dart b/lib/core/response_model/call_config.dart index 77ecf61..9bfc3c8 100644 --- a/lib/core/response_model/call_config.dart +++ b/lib/core/response_model/call_config.dart @@ -1,25 +1,15 @@ -// public int ConcurrentCallDelaySec { get; set; } -// public int VoiceType { get; set; } -// public int ScreenLanguage { get; set; } -// public int VoiceLanguage { get; set; } -// public int ScreenMaxDisplayPatients { get; set; } -// public string VitalSignText { get; set; } -// public string VitalSignTextN { get; set; } -// public string DoctorText { get; set; } -// public string DoctorTextN { get; set; } -// public string ProcedureText { get; set; } -// public string ProcedureTextN { get; set; } -// public string VaccinationText { get; set; } -// public string VaccinationTextN { get; set; } -// public string NebulizationText { get; set; } -// public string NebulizationTextN { get; set; } - class CallConfig { + int id; + bool globalClinicPrefixReq; + bool clinicPrefixReq; int concurrentCallDelaySec; int voiceType; int screenLanguage; int voiceLanguage; int screenMaxDisplayPatients; + int prioritySMS; + int priorityWhatsApp; + int priorityEmail; String vitalSignText; String vitalSignTextN; String doctorText; @@ -30,31 +20,50 @@ class CallConfig { String vaccinationTextN; String nebulizationText; String nebulizationTextN; + int createdBy; + String createdOn; + int editedBy; + String editedOn; - CallConfig({ - this.concurrentCallDelaySec, - this.voiceType, - this.screenLanguage, - this.voiceLanguage, - this.screenMaxDisplayPatients, - this.vitalSignText, - this.vitalSignTextN, - this.doctorText, - this.doctorTextN, - this.procedureText, - this.procedureTextN, - this.vaccinationText, - this.vaccinationTextN, - this.nebulizationText, - this.nebulizationTextN, - }); + CallConfig( + {this.id, + this.globalClinicPrefixReq, + this.clinicPrefixReq, + this.concurrentCallDelaySec, + this.voiceType, + this.screenLanguage, + this.voiceLanguage, + this.screenMaxDisplayPatients, + this.prioritySMS, + this.priorityWhatsApp, + this.priorityEmail, + this.vitalSignText, + this.vitalSignTextN, + this.doctorText, + this.doctorTextN, + this.procedureText, + this.procedureTextN, + this.vaccinationText, + this.vaccinationTextN, + this.nebulizationText, + this.nebulizationTextN, + this.createdBy, + this.createdOn, + this.editedBy, + this.editedOn}); CallConfig.fromJson(Map json) { + id = json['id']; + globalClinicPrefixReq = json['globalClinicPrefixReq']; + clinicPrefixReq = json['clinicPrefixReq']; concurrentCallDelaySec = json['concurrentCallDelaySec']; voiceType = json['voiceType']; screenLanguage = json['screenLanguage']; voiceLanguage = json['voiceLanguage']; screenMaxDisplayPatients = json['screenMaxDisplayPatients']; + prioritySMS = json['prioritySMS']; + priorityWhatsApp = json['priorityWhatsApp']; + priorityEmail = json['priorityEmail']; vitalSignText = json['vitalSignText']; vitalSignTextN = json['vitalSignTextN']; doctorText = json['doctorText']; @@ -65,5 +74,39 @@ class CallConfig { vaccinationTextN = json['vaccinationTextN']; nebulizationText = json['nebulizationText']; nebulizationTextN = json['nebulizationTextN']; + createdBy = json['createdBy']; + createdOn = json['createdOn']; + editedBy = json['editedBy']; + editedOn = json['editedOn']; + } + + Map toJson() { + final Map data = {}; + data['id'] = id; + data['globalClinicPrefixReq'] = globalClinicPrefixReq; + data['clinicPrefixReq'] = clinicPrefixReq; + data['concurrentCallDelaySec'] = concurrentCallDelaySec; + data['voiceType'] = voiceType; + data['screenLanguage'] = screenLanguage; + data['voiceLanguage'] = voiceLanguage; + data['screenMaxDisplayPatients'] = screenMaxDisplayPatients; + data['prioritySMS'] = prioritySMS; + data['priorityWhatsApp'] = priorityWhatsApp; + data['priorityEmail'] = priorityEmail; + data['vitalSignText'] = vitalSignText; + data['vitalSignTextN'] = vitalSignTextN; + data['doctorText'] = doctorText; + data['doctorTextN'] = doctorTextN; + data['procedureText'] = procedureText; + data['procedureTextN'] = procedureTextN; + data['vaccinationText'] = vaccinationText; + data['vaccinationTextN'] = vaccinationTextN; + data['nebulizationText'] = nebulizationText; + data['nebulizationTextN'] = nebulizationTextN; + data['createdBy'] = createdBy; + data['createdOn'] = createdOn; + data['editedBy'] = editedBy; + data['editedOn'] = editedOn; + return data; } } diff --git a/lib/core/response_model/patient_call.dart b/lib/core/response_model/patient_call.dart index 69ff7bd..a72d061 100644 --- a/lib/core/response_model/patient_call.dart +++ b/lib/core/response_model/patient_call.dart @@ -11,16 +11,15 @@ class Tickets { int patientGender; int callType; int editedOnTimeStamp; + int concurrentCallDelaySec; String roomNo; String createdOn; String editedOn; String queueNo; String callNoStr; - bool isQueueNurse; - bool isQueueDr; + bool isQueue; bool isToneReq; bool isVoiceReq; - String queueDuration; bool callUpdated = false; Tickets( @@ -37,11 +36,10 @@ class Tickets { this.editedOn, this.queueNo, this.callNoStr, - this.isQueueNurse, - this.isQueueDr, + this.isQueue, this.isToneReq, this.isVoiceReq, - this.queueDuration}); + this.concurrentCallDelaySec}); int getRandomNum() { return Random().nextInt(9); @@ -61,11 +59,10 @@ class Tickets { editedOn = json['editedOn']; queueNo = json['queueNo']; callNoStr = json['callNoStr']; - isQueueNurse = json['isQueueNurse']; - isQueueDr = json['isQueueDr']; + isQueue = json['isQueue']; isToneReq = json['isToneReq']; isVoiceReq = json['isVoiceReq']; - queueDuration = json['queueDuration']; + concurrentCallDelaySec = json['concurrentCallDelaySec']; } Map toJson() { @@ -82,11 +79,10 @@ class Tickets { data['editedOn'] = editedOn; data['queueNo'] = queueNo; data['callNoStr'] = callNoStr; - data['isQueueNurse'] = isQueueNurse; - data['isQueueDr'] = isQueueDr; + data['isQueue'] = isQueue; data['isToneReq'] = isToneReq; data['isVoiceReq'] = isVoiceReq; - data['queueDuration'] = queueDuration; + data['concurrentCallDelaySec'] = concurrentCallDelaySec; return data; } @@ -96,10 +92,24 @@ class Tickets { } CallType getCallType() { - if (callType == 3) return CallType.RECEPTION; - if (callType == 1) return CallType.NURSE; - if (callType == 2) return CallType.DOCTOR; - return CallType.NONE; + // { + // [EnumMember] + // VitalSign = 1, + // [EnumMember] + // Doctor = 2, + // [EnumMember] + // Procedure = 3, + // [EnumMember] + // Vaccination = 4, + // [EnumMember] + // Nebulization = 5 + + if (callType == 1) return CallType.nebulization; + if (callType == 2) return CallType.doctor; + if (callType == 3) return CallType.procedure; + if (callType == 4) return CallType.vaccination; + if (callType == 5) return CallType.nebulization; + return CallType.vitalSign; } static List testCallPatients = [ @@ -117,11 +127,10 @@ class Tickets { editedOnTimeStamp: DateTime.now().millisecondsSinceEpoch, queueNo: "B-89", callNoStr: "B-89", - isQueueNurse: true, - isQueueDr: false, + isQueue: true, isToneReq: true, isVoiceReq: true, - queueDuration: "5000", + concurrentCallDelaySec: 8, ), Tickets( id: 1, @@ -136,11 +145,10 @@ class Tickets { editedOn: DateTime.now().millisecondsSinceEpoch.toString(), queueNo: "B-89", callNoStr: "B-89", - isQueueNurse: true, - isQueueDr: false, + isQueue: true, isToneReq: true, isVoiceReq: true, - queueDuration: "5000", + concurrentCallDelaySec: 8, ), Tickets( id: 1, @@ -155,11 +163,10 @@ class Tickets { editedOn: DateTime.now().millisecondsSinceEpoch.toString(), queueNo: "B-89", callNoStr: "B-89", - isQueueNurse: true, - isQueueDr: false, + isQueue: true, isToneReq: true, isVoiceReq: true, - queueDuration: "5000", + concurrentCallDelaySec: 8, ), Tickets( id: 1, @@ -174,11 +181,10 @@ class Tickets { editedOn: DateTime.now().millisecondsSinceEpoch.toString(), queueNo: "B-89", callNoStr: "B-89", - isQueueNurse: true, - isQueueDr: false, + isQueue: true, isToneReq: true, isVoiceReq: true, - queueDuration: "5000", + concurrentCallDelaySec: 8, ), ]; } diff --git a/lib/home/home_screen.dart b/lib/home/home_screen.dart index 9679c41..cce01ef 100644 --- a/lib/home/home_screen.dart +++ b/lib/home/home_screen.dart @@ -51,7 +51,9 @@ class _MyHomePageState extends State { Future getCurrentIP() async { for (var interface in await NetworkInterface.list(type: InternetAddressType.IPv4)) { log("interfaces: ${interface.name}"); - if (interface.name == "eth0") { + //TODO: WE WILL UPDATE THIS WHEN TESTING ON SCREEN + if (interface.name == "wlan0") { + // if (interface.name == "eth0") { for (var address in interface.addresses) { deviceIPGlobal = address.address; return deviceIPGlobal; @@ -83,7 +85,6 @@ class _MyHomePageState extends State { audioPlayer.playerStateStream.listen((playerState) { if (playerState.processingState == ProcessingState.completed) { isCallingInProgress = false; - print("UpdatedInProgresslisten: $isCallingInProgress"); } }); return AppScaffold( @@ -165,17 +166,16 @@ class _MyHomePageState extends State { String getCallTypeText(Tickets ticket) { final callType = ticket.getCallType(); switch (callType) { - case CallType.RECEPTION: - return "Please Visit Doctor"; - break; - case CallType.NURSE: + case CallType.vitalSign: return "Please Visit Nurse"; - break; - case CallType.DOCTOR: + case CallType.doctor: return "Please Visit Doctor"; - break; - case CallType.NONE: - return ""; + case CallType.procedure: + return "Please Visit Procedure"; + case CallType.vaccination: + return "Please Visit Vaccination"; + case CallType.nebulization: + return "Please Visit Nebulization"; break; default: return ""; @@ -186,40 +186,28 @@ class _MyHomePageState extends State { int callFlag = 0; - bool isRequiredVoice({CallType callType, bool isQueueNurse, bool isQueueDr}) { - if (callType == CallType.DOCTOR && !isQueueDr) { - return true; - } - if (callType == CallType.NURSE && !isQueueNurse) { - return true; - } - return false; - } + // bool isRequiredVoice({CallType callType, bool isQueue}) { + // if (callType == CallType.DOCTOR && !isQueue) { + // return true; + // } + // if (callType == CallType.NURSE && !isQueue) { + // return true; + // } + // return false; + // } 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) { - if (waitings.first.isToneReq && - isRequiredVoice( - callType: waitings.first.getCallType(), - isQueueDr: waitings.first.isQueueDr, - isQueueNurse: waitings.first.isQueueNurse, - )) { + if (waitings.first.isToneReq && waitings.first.isQueue) { audioPlayer.setAsset("assets/tones/call_tone.mp3"); await audioPlayer.play(); await Future.delayed(const Duration(seconds: 2)); } - if (waitings.first.isVoiceReq && - voiceCaller == null && - isRequiredVoice( - callType: waitings.first.getCallType(), - isQueueDr: waitings.first.isQueueDr, - isQueueNurse: waitings.first.isQueueNurse, - )) { + if (waitings.first.isVoiceReq && voiceCaller == null && waitings.first.isQueue) { final postVoice = getCallTypeText(waitings.first); voiceCaller = CallByVoice(waitings.first.queueNo.trim().toString(), preVoice: "Ticket Number", postVoice: postVoice, lang: 'en'); await voiceCaller.startCalling(waitings.first.queueNo.trim().toString() != waitings.first.callNoStr.trim().toString()); @@ -227,7 +215,7 @@ class _MyHomePageState extends State { } } if (isQueuePatients.isNotEmpty) { - await Future.delayed(Duration(milliseconds: int.parse(isQueuePatients.first.queueDuration) * 10)).whenComplete(() async { + await Future.delayed(Duration(seconds: isQueuePatients.first.concurrentCallDelaySec)).whenComplete(() async { if (isQueuePatients.isNotEmpty) { isQueuePatients.removeAt(0); } @@ -289,8 +277,7 @@ class _MyHomePageState extends State { if (waitings.isNotEmpty) { if ((waitings.first.isToneReq && isCallingInProgress) || (waitings.first.isVoiceReq && voiceCaller != null)) { // if (true) { - print("I will wait with $isCallingInProgress "); - Timer(Duration(milliseconds: int.parse(waitings.first.queueDuration)), () async { + Timer(Duration(seconds: isQueuePatients.first.concurrentCallDelaySec), () async { await callPatientsAPI(); }); } else { @@ -304,8 +291,8 @@ class _MyHomePageState extends State { updateTickets() { if (waitings != null && waitings.isNotEmpty) { List _ticketsToUpdate = waitings.where((t) => t.callUpdated == false).toList(); - API.callUpdateNotIsQueueRecordByIDAsync(deviceIPGlobal, ticket: _ticketsToUpdate.first, onSuccess: (tickets_updated) { - log("[${tickets_updated.length}] Tickets Updated: $tickets_updated"); + API.callUpdateNotIsQueueRecordByIDAsync(deviceIPGlobal, ticket: _ticketsToUpdate.first, onSuccess: (ticketsUpdated) { + log("[${ticketsUpdated.length}] Tickets Updated: $ticketsUpdated"); }, onFailure: (e) { log("API UPDate Tickets Failed with : ${e.toString()}"); }); diff --git a/lib/utils/call_type.dart b/lib/utils/call_type.dart index 7749253..e476ce4 100644 --- a/lib/utils/call_type.dart +++ b/lib/utils/call_type.dart @@ -2,57 +2,68 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:queuing_system/core/config/config.dart'; -enum CallType { - RECEPTION, - NURSE, - DOCTOR, - NONE, -} +enum CallType { vitalSign, doctor, procedure, vaccination, nebulization, none } -extension xCallType on CallType { +extension XCallType on CallType { Color color() { - if (this == CallType.RECEPTION) { - return AppGlobal.appRedColor; - } else if (this == CallType.NURSE) { + if (this == CallType.vitalSign) { return AppGlobal.appGreenColor; - } else if (this == CallType.DOCTOR) { + } else if (this == CallType.doctor) { return AppGlobal.appRedColor; + } else if (this == CallType.procedure) { + return AppGlobal.appGreenColor; + } else if (this == CallType.vaccination) { + return AppGlobal.appGreenColor; + } else if (this == CallType.nebulization) { + return AppGlobal.appGreenColor; } else { return Colors.black54; } } + String message(String lang) { + if (this == CallType.vitalSign) { + return "Please visit VitalSign"; + } else if (this == CallType.doctor) { + return "Please visit Doctor"; + } else if (this == CallType.procedure) { + return "Please visit Procedure"; + } else if (this == CallType.vaccination) { + return "Please visit Vaccination"; + } + if (this == CallType.nebulization) { + return "Please visit Nebulization"; + } + return "Please wait . . ."; + } + SvgPicture icon( double height, ) { - if (this == CallType.RECEPTION) { - return SvgPicture.asset("assets/images/doctoricon.svg", height: height, color: color()); - } else if (this == CallType.NURSE) { + if (this == CallType.vitalSign) { return SvgPicture.asset("assets/images/nurseicon.svg", height: height, color: color()); - } else if (this == CallType.DOCTOR) { + } else if (this == CallType.doctor) { return SvgPicture.asset("assets/images/doctoricon.svg", height: height, color: color()); + } else if (this == CallType.procedure) { + return SvgPicture.asset("assets/images/doctoricon.svg", height: height, color: color()); + } else if (this == CallType.vaccination) { + return SvgPicture.asset("assets/images/doctoricon.svg", height: height, color: color()); + } else if (this == CallType.nebulization) { + return SvgPicture.asset("assets/images/nurseicon.svg", height: height, color: color()); } return SvgPicture.asset("assets/images/wait.svg", height: height, color: color()); - ; - } - - String message(String lang) { - if (this == CallType.RECEPTION) { - return "Please wait . . ."; - } else if (this == CallType.NURSE) { - return "Please visit nurse"; - } else if (this == CallType.DOCTOR) { - return "Please visit doctor"; - } - return "Please wait . . ."; } String audio(String lang) { - if (this == CallType.RECEPTION) { - return "visit_doctor.mp3"; - } else if (this == CallType.NURSE) { + if (this == CallType.vitalSign) { return "visit_nurse.mp3"; - } else if (this == CallType.DOCTOR) { + } else if (this == CallType.doctor) { + return "visit_doctor.mp3"; + } else if (this == CallType.procedure) { + return "visit_doctor.mp3"; + } else if (this == CallType.vaccination) { + return "visit_doctor.mp3"; + } else if (this == CallType.nebulization) { return "visit_doctor.mp3"; } return "";