|
|
|
|
@ -1,6 +1,4 @@
|
|
|
|
|
import 'package:doctor_app_flutter/config/config.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/provider/robot_provider.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/viewModel/PatientMedicalReportViewModel.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/models/patient/MedicalReport/MeidcalReportModel.dart';
|
|
|
|
|
@ -11,14 +9,11 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/speech-text-popup.dart';
|
|
|
|
|
import 'package:doctor_app_flutter/widgets/shared/text_fields/html_rich_editor.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:html_editor_enhanced/html_editor.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_recognition_error.dart';
|
|
|
|
|
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
|
|
|
|
|
|
|
|
|
class AddVerifyMedicalReport extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
@ -26,42 +21,6 @@ class AddVerifyMedicalReport extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AddVerifyMedicalReportState extends State<AddVerifyMedicalReport> {
|
|
|
|
|
stt.SpeechToText speechHistoryFinding = stt.SpeechToText();
|
|
|
|
|
stt.SpeechToText speechLaboratoryData = stt.SpeechToText();
|
|
|
|
|
stt.SpeechToText speechRecommendation = stt.SpeechToText();
|
|
|
|
|
var recognizedWord1;
|
|
|
|
|
var recognizedWord2;
|
|
|
|
|
var recognizedWord3;
|
|
|
|
|
var event = RobotProvider();
|
|
|
|
|
|
|
|
|
|
TextEditingController historyFindingController = TextEditingController();
|
|
|
|
|
TextEditingController laboratoryDataController = TextEditingController();
|
|
|
|
|
TextEditingController recommendationController = TextEditingController();
|
|
|
|
|
String commentsError;
|
|
|
|
|
String comments2Error;
|
|
|
|
|
String comments3Error;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
requestPermissions();
|
|
|
|
|
event.controller.stream.listen((p) {
|
|
|
|
|
if (p['startPopUp'] == 'true') {
|
|
|
|
|
if (this.mounted) {
|
|
|
|
|
initSpeechState().then((value) {
|
|
|
|
|
onVoiceText();
|
|
|
|
|
});
|
|
|
|
|
initSpeechState2().then((value) {
|
|
|
|
|
onVoiceText2();
|
|
|
|
|
});
|
|
|
|
|
initSpeechState3().then((value) {
|
|
|
|
|
onVoiceText3();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
ProjectViewModel projectViewModel = Provider.of<ProjectViewModel>(context);
|
|
|
|
|
@ -94,9 +53,15 @@ class _AddVerifyMedicalReportState extends State<AddVerifyMedicalReport> {
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
HtmlRichEditor(initialText: model
|
|
|
|
|
.medicalReportTemplate[0]
|
|
|
|
|
.templateTextHtml, height: MediaQuery.of(context).size.height * 0.75,),
|
|
|
|
|
if (model.medicalReportTemplate.length > 0)
|
|
|
|
|
HtmlRichEditor(
|
|
|
|
|
initialText: model
|
|
|
|
|
.medicalReportTemplate[0]
|
|
|
|
|
.templateTextHtml,
|
|
|
|
|
height:
|
|
|
|
|
MediaQuery.of(context).size.height *
|
|
|
|
|
0.75,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -121,13 +86,13 @@ class _AddVerifyMedicalReportState extends State<AddVerifyMedicalReport> {
|
|
|
|
|
// disabled: progressNoteController.text.isEmpty,
|
|
|
|
|
fontWeight: FontWeight.w700,
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
|
|
|
|
|
String txtOfMedicalReport = await HtmlEditor.getText();
|
|
|
|
|
String txtOfMedicalReport =
|
|
|
|
|
await HtmlEditor.getText();
|
|
|
|
|
|
|
|
|
|
if (txtOfMedicalReport.isNotEmpty) {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
model.insertMedicalReport(patient,txtOfMedicalReport
|
|
|
|
|
);
|
|
|
|
|
model.insertMedicalReport(
|
|
|
|
|
patient, txtOfMedicalReport);
|
|
|
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
|
|
|
if (model.state == ViewState.ErrorLocal) {
|
|
|
|
|
DrAppToastMsg.showErrorToast(model.error);
|
|
|
|
|
@ -166,137 +131,11 @@ class _AddVerifyMedicalReportState extends State<AddVerifyMedicalReport> {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onVoiceText() async {
|
|
|
|
|
new SpeechToText(context: context).showAlertDialog(context);
|
|
|
|
|
var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode;
|
|
|
|
|
bool available = await speechHistoryFinding.initialize(
|
|
|
|
|
onStatus: statusListener, onError: errorListener);
|
|
|
|
|
if (available) {
|
|
|
|
|
speechHistoryFinding.listen(
|
|
|
|
|
onResult: resultListener,
|
|
|
|
|
listenMode: stt.ListenMode.confirmation,
|
|
|
|
|
localeId: lang == 'en' ? 'en-US' : 'ar-SA',
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
print("The user has denied the use of speech recognition.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onVoiceText2() async {
|
|
|
|
|
new SpeechToText(context: context).showAlertDialog(context);
|
|
|
|
|
var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode;
|
|
|
|
|
bool available = await speechLaboratoryData.initialize(
|
|
|
|
|
onStatus: statusListener, onError: errorListener);
|
|
|
|
|
if (available) {
|
|
|
|
|
speechLaboratoryData.listen(
|
|
|
|
|
onResult: resultListener2,
|
|
|
|
|
listenMode: stt.ListenMode.confirmation,
|
|
|
|
|
localeId: lang == 'en' ? 'en-US' : 'ar-SA',
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
print("The user has denied the use of speech recognition.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onVoiceText3() async {
|
|
|
|
|
new SpeechToText(context: context).showAlertDialog(context);
|
|
|
|
|
var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode;
|
|
|
|
|
bool available = await speechRecommendation.initialize(
|
|
|
|
|
onStatus: statusListener, onError: errorListener);
|
|
|
|
|
if (available) {
|
|
|
|
|
speechRecommendation.listen(
|
|
|
|
|
onResult: resultListener3,
|
|
|
|
|
listenMode: stt.ListenMode.confirmation,
|
|
|
|
|
localeId: lang == 'en' ? 'en-US' : 'ar-SA',
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
print("The user has denied the use of speech recognition.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void errorListener(SpeechRecognitionError error) {
|
|
|
|
|
event.setValue({"searchText": 'null'});
|
|
|
|
|
//SpeechToText.closeAlertDialog(context);
|
|
|
|
|
print(error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void statusListener(String status) {
|
|
|
|
|
recognizedWord1 = status == 'listening' ? 'Lisening...' : 'Sorry....';
|
|
|
|
|
recognizedWord2 = status == 'listening' ? 'Lisening...' : 'Sorry....';
|
|
|
|
|
recognizedWord3 = status == 'listening' ? 'Lisening...' : 'Sorry....';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void requestPermissions() async {
|
|
|
|
|
Map<Permission, PermissionStatus> statuses = await [
|
|
|
|
|
Permission.microphone,
|
|
|
|
|
].request();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resultListener(result) {
|
|
|
|
|
recognizedWord1 = result.recognizedWords;
|
|
|
|
|
event.setValue({"searchText": recognizedWord1});
|
|
|
|
|
|
|
|
|
|
if (result.finalResult == true) {
|
|
|
|
|
setState(() {
|
|
|
|
|
SpeechToText.closeAlertDialog(context);
|
|
|
|
|
speechHistoryFinding.stop();
|
|
|
|
|
historyFindingController.text += recognizedWord1 + '\n';
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
print(result.finalResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resultListener2(result) {
|
|
|
|
|
recognizedWord2 = result.recognizedWords;
|
|
|
|
|
event.setValue({"searchText": recognizedWord2});
|
|
|
|
|
|
|
|
|
|
if (result.finalResult == true) {
|
|
|
|
|
setState(() {
|
|
|
|
|
SpeechToText.closeAlertDialog(context);
|
|
|
|
|
speechLaboratoryData.stop();
|
|
|
|
|
laboratoryDataController.text += recognizedWord2 + '\n';
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
print(result.finalResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resultListener3(result) {
|
|
|
|
|
recognizedWord3 = result.recognizedWords;
|
|
|
|
|
event.setValue({"searchText": recognizedWord3});
|
|
|
|
|
|
|
|
|
|
if (result.finalResult == true) {
|
|
|
|
|
setState(() {
|
|
|
|
|
SpeechToText.closeAlertDialog(context);
|
|
|
|
|
speechRecommendation.stop();
|
|
|
|
|
recommendationController.text += recognizedWord3 + '\n';
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
print(result.finalResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> initSpeechState() async {
|
|
|
|
|
bool hasSpeech = await speechHistoryFinding.initialize(
|
|
|
|
|
onError: errorListener, onStatus: statusListener);
|
|
|
|
|
print(hasSpeech);
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> initSpeechState2() async {
|
|
|
|
|
bool hasSpeech = await speechLaboratoryData.initialize(
|
|
|
|
|
onError: errorListener, onStatus: statusListener);
|
|
|
|
|
print(hasSpeech);
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> initSpeechState3() async {
|
|
|
|
|
bool hasSpeech = await speechRecommendation.initialize(
|
|
|
|
|
onError: errorListener, onStatus: statusListener);
|
|
|
|
|
print(hasSpeech);
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum MedicalReportStatus { ADD, VERIFY }
|
|
|
|
|
|