adding validation and voice speach to prescription form

merge-requests/684/head
hussam al-habibeh 5 years ago
parent d50740b9b9
commit b6cb6362f6

@ -5,10 +5,12 @@ import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/Prescriptions/post_prescrition_req_model.dart';
import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_model.dart';
import 'package:doctor_app_flutter/core/model/search_drug/get_medication_response_model.dart';
import 'package:doctor_app_flutter/core/provider/robot_provider.dart';
import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/models/SOAP/GetAssessmentReqModel.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
@ -23,12 +25,16 @@ import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.dart';
import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart';
import 'package:doctor_app_flutter/widgets/shared/speech-text-popup.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.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;
addPrescriptionForm(context, PrescriptionViewModel model,
PatiantInformtion patient, prescription) {
@ -102,6 +108,13 @@ class PrescriptionFormWidget extends StatefulWidget {
}
class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
String routeError;
String frequencyError;
String doseTimeError;
String durationError;
String unitError;
String strengthError;
int selectedType;
TextEditingController durationController = TextEditingController();
TextEditingController strengthController = TextEditingController();
@ -124,6 +137,9 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
TextEditingController drugIdController = TextEditingController();
TextEditingController doseController = TextEditingController();
final searchController = TextEditingController();
stt.SpeechToText speech = stt.SpeechToText();
var event = RobotProvider();
var reconizedWord;
var notesList;
var filteredNotesList;
@ -188,6 +204,60 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
});
}
onVoiceText() async {
new SpeechToText(context: context).showAlertDialog(context);
var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode;
bool available = await speech.initialize(
onStatus: statusListener, onError: errorListener);
if (available) {
speech.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.");
}
}
void errorListener(SpeechRecognitionError error) {
event.setValue({"searchText": 'null'});
//SpeechToText.closeAlertDialog(context);
print(error);
}
void statusListener(String status) {
reconizedWord = status == 'listening' ? 'Lisening...' : 'Sorry....';
}
void requestPermissions() async {
Map<Permission, PermissionStatus> statuses = await [
Permission.microphone,
].request();
}
void resultListener(result) {
reconizedWord = result.recognizedWords;
event.setValue({"searchText": reconizedWord});
if (result.finalResult == true) {
setState(() {
SpeechToText.closeAlertDialog(context);
speech.stop();
indicationController.text += reconizedWord + '\n';
});
} else {
print(result.finalResult);
}
}
Future<void> initSpeechState() async {
bool hasSpeech = await speech.initialize(
onError: errorListener, onStatus: statusListener);
print(hasSpeech);
if (!mounted) return;
}
@override
Widget build(BuildContext context) {
ListSelectDialog drugDialog;
@ -244,7 +314,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
(BuildContext context, ScrollController scrollController) {
return SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height * 1.45,
height: MediaQuery.of(context).size.height * 1.65,
color: Color(0xffF8F8F8),
child: Padding(
padding: EdgeInsets.symmetric(
@ -437,11 +507,6 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox(
height: spaceBetweenTextFileds),
Container(
//height: screenSize.height * 0.062,
height: MediaQuery.of(context)
.size
.height *
0.0749,
width: double.infinity,
child: Row(
children: [
@ -451,44 +516,43 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
.size
.width *
0.35,
child: TextField(
decoration:
textFieldSelectorDecorationStreangrh(
strengthController
.text,
'Strength', //strengthController.text,
false),
enabled: true,
controller:
strengthController,
onChanged:
(String value) {
setState(() {
strengthChar =
value.length;
});
if (strengthChar >= 5) {
DrAppToastMsg
.showErrorToast(
TranslationBase.of(
context)
.only5DigitsAllowedForStrength,
);
}
},
keyboardType: TextInputType
.numberWithOptions(
decimal: true,
)),
child: AppTextFieldCustom(
height: 40,
validationError:
strengthError,
hintText: 'Strength',
isTextFieldHasSuffix: false,
enabled: true,
controller:
strengthController,
onChanged: (String value) {
setState(() {
strengthChar =
value.length;
});
if (strengthChar >= 5) {
DrAppToastMsg
.showErrorToast(
TranslationBase.of(
context)
.only5DigitsAllowedForStrength,
);
}
},
inputType: TextInputType
.numberWithOptions(
decimal: true,
),
// keyboardType: TextInputType
// .numberWithOptions(
// decimal: true,
// ),
),
),
SizedBox(
width: 5.0,
),
Container(
// height: MediaQuery.of(context)
// .size
// .height *
// 0.06,
color: Colors.white,
width: MediaQuery.of(context)
.size
@ -538,23 +602,23 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
);
}
: null,
child: TextField(
decoration:
textFieldSelectorDecoration(
'Select',
model.itemMedicineListUnit
.length ==
1
? units = model
.itemMedicineListUnit[0]
[
'description']
: units !=
null
? units['description']
.toString()
: null,
true),
child: AppTextFieldCustom(
hintText: 'Select',
isTextFieldHasSuffix:
true,
dropDownText: model
.itemMedicineListUnit
.length ==
1
? units = model
.itemMedicineListUnit[0]
['description']
: units != null
? units['description']
.toString()
: null,
validationError:
unitError,
enabled: false),
),
),
@ -564,7 +628,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox(
height: spaceBetweenTextFileds),
Container(
height: screenSize.height * 0.070,
//height: screenSize.height * 0.070,
color: Colors.white,
child: InkWell(
onTap:
@ -613,23 +677,44 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
);
}
: null,
child: TextField(
decoration:
textFieldSelectorDecoration(
TranslationBase.of(
context)
.route,
model.itemMedicineListRoute
.length ==
1
? model.itemMedicineListRoute[
0]
['description']
: route != null
? route[
'description']
: null,
true),
child: AppTextFieldCustom(
// decoration:
// textFieldSelectorDecoration(
// TranslationBase.of(
// context)
// .route,
// model.itemMedicineListRoute
// .length ==
// 1
// ? model.itemMedicineListRoute[
// 0]
// ['description']
// : route != null
// ? route[
// 'description']
// : null,
// true),
hintText:
TranslationBase.of(context)
.route,
dropDownText: model
.itemMedicineListRoute
.length ==
1
? model.itemMedicineListRoute[
0]['description']
: route != null
? route['description']
: null,
isTextFieldHasSuffix: true,
//height: 45,
validationError:
model.itemMedicineListRoute
.length !=
1
? routeError
: null,
enabled: false,
),
),
@ -637,7 +722,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox(
height: spaceBetweenTextFileds),
Container(
height: screenSize.height * 0.070,
//height: screenSize.height * 0.070,
color: Colors.white,
child: InkWell(
onTap:
@ -704,23 +789,22 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
);
}
: null,
child: TextField(
decoration:
textFieldSelectorDecoration(
TranslationBase.of(
context)
.frequency,
model.itemMedicineList
.length ==
1
? model.itemMedicineList[
0]
['description']
: frequency != null
? frequency[
'description']
: null,
true),
child: AppTextFieldCustom(
isTextFieldHasSuffix: true,
hintText:
TranslationBase.of(context)
.frequency,
dropDownText: model
.itemMedicineList
.length ==
1
? model.itemMedicineList[0]
['description']
: frequency != null
? frequency[
'description']
: null,
validationError: frequencyError,
enabled: false,
),
),
@ -728,7 +812,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox(
height: spaceBetweenTextFileds),
Container(
height: screenSize.height * 0.070,
//height: screenSize.height * 0.070,
color: Colors.white,
child: InkWell(
onTap:
@ -770,17 +854,18 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
);
}
: null,
child: TextField(
decoration:
textFieldSelectorDecoration(
TranslationBase.of(
context)
.doseTime,
doseTime != null
? doseTime['nameEn']
: null,
true),
child: AppTextFieldCustom(
hintText:
TranslationBase.of(context)
.doseTime,
isTextFieldHasSuffix: true,
dropDownText: doseTime != null
? doseTime['nameEn']
: null,
//height: 45,
enabled: false,
validationError: doseTimeError,
),
),
),
@ -894,7 +979,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox(
height: spaceBetweenTextFileds),
Container(
height: screenSize.height * 0.070,
//height: screenSize.height * 0.070,
color: Colors.white,
child: InkWell(
onTap:
@ -963,16 +1048,15 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
);
}
: null,
child: TextField(
decoration:
textFieldSelectorDecoration(
TranslationBase.of(
context)
.duration,
duration != null
? duration['nameEn']
: null,
true),
child: AppTextFieldCustom(
validationError: durationError,
isTextFieldHasSuffix: true,
dropDownText: duration != null
? duration['nameEn']
: null,
hintText:
TranslationBase.of(context)
.duration,
enabled: false,
),
),
@ -1101,14 +1185,36 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
width: 1.0,
color:
HexColor("#CCCCCC"))),
child: TextFields(
maxLines: 6,
minLines: 4,
hintText:
TranslationBase.of(context)
child: Stack(
children: [
TextFields(
maxLines: 6,
minLines: 4,
hintText: TranslationBase.of(
context)
.instruction,
controller: instructionController,
//keyboardType: TextInputType.number,
controller:
instructionController,
//keyboardType: TextInputType.number,
),
Positioned(
top:
0, //MediaQuery.of(context).size.height * 0,
right: 15,
child: IconButton(
icon: Icon(
DoctorApp.speechtotext,
color: Colors.black,
size: 35,
),
onPressed: () {
initSpeechState().then(
(value) =>
{onVoiceText()});
},
),
),
],
),
),
SizedBox(
@ -1125,139 +1231,205 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
context)
.addMedication,
fontWeight: FontWeight.w600,
onPressed: () {
formKey.currentState.save();
// Navigator.pop(context);
// openDrugToDrug();
if (frequency == null ||
onPressed: () async {
if (route != null &&
duration != null &&
doseTime != null &&
frequency != null &&
units != null &&
selectedDate != null &&
strengthController
.text ==
"" ||
doseTime == null ||
duration == null ||
selectedDate == null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(
context)
.pleaseFillAllFields);
return;
}
if (_selectedMedication
.isNarcotic ==
true) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(
context)
.narcoticMedicineCanOnlyBePrescribedFromVida);
Navigator.pop(context);
return;
}
.text !=
"") {
if (_selectedMedication
.isNarcotic ==
true) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(
context)
.narcoticMedicineCanOnlyBePrescribedFromVida);
Navigator.pop(context);
return;
}
if (double.parse(
strengthController
.text) >
1000.0) {
DrAppToastMsg.showErrorToast(
"1000 is the MAX for the strength");
return;
}
if (double.parse(
strengthController
.text) <
0.0) {
DrAppToastMsg.showErrorToast(
"strength can't be zero");
return;
}
if (double.parse(
strengthController
.text) >
1000.0) {
DrAppToastMsg
.showErrorToast(
"1000 is the MAX for the strength");
return;
}
if (double.parse(
strengthController
.text) <
0.0) {
DrAppToastMsg
.showErrorToast(
"strength can't be zero");
return;
}
if (formKey.currentState
.validate()) {
Navigator.pop(context);
openDrugToDrug(model);
{
// postProcedure(
// icdCode: model
// .patientAssessmentList
// .isNotEmpty
// ? model
// .patientAssessmentList[
// 0]
// .icdCode10ID
// .isEmpty
// ? "test"
// : model
// .patientAssessmentList[
// 0]
// .icdCode10ID
// .toString()
// : "test",
// // icdCode: model
// // .patientAssessmentList
// // .map((value) => value
// // .icdCode10ID
// // .trim())
// // .toList()
// // .join(' '),
// dose: strengthController
// .text,
// doseUnit: model
// .itemMedicineListUnit
// .length ==
// 1
// ? model
// .itemMedicineListUnit[
// 0][
// 'parameterCode']
// .toString()
// : units['parameterCode']
// .toString(),
// patient: widget.patient,
// doseTimeIn:
// doseTime['id']
// .toString(),
// model: widget.model,
// duration: duration['id']
// .toString(),
// frequency: model
// .itemMedicineList
// .length ==
// 1
// ? model
// .itemMedicineList[
// 0][
// 'parameterCode']
// .toString()
// : frequency[
// 'parameterCode']
// .toString(),
// route: model.itemMedicineListRoute
// .length ==
// 1
// ? model
// .itemMedicineListRoute[
// 0][
// 'parameterCode']
// .toString()
// : route['parameterCode']
// .toString(),
// drugId:
// _selectedMedication
// .itemId
// .toString(),
// strength:
// strengthController
// .text,
// indication:
// indicationController
// .text,
// instruction:
// instructionController
// .text,
// doseTime: selectedDate,
// );
if (formKey.currentState
.validate()) {
Navigator.pop(context);
openDrugToDrug(model);
{
// postProcedure(
// icdCode: model
// .patientAssessmentList
// .isNotEmpty
// ? model
// .patientAssessmentList[
// 0]
// .icdCode10ID
// .isEmpty
// ? "test"
// : model
// .patientAssessmentList[
// 0]
// .icdCode10ID
// .toString()
// : "test",
// // icdCode: model
// // .patientAssessmentList
// // .map((value) => value
// // .icdCode10ID
// // .trim())
// // .toList()
// // .join(' '),
// dose: strengthController
// .text,
// doseUnit: model
// .itemMedicineListUnit
// .length ==
// 1
// ? model
// .itemMedicineListUnit[
// 0][
// 'parameterCode']
// .toString()
// : units['parameterCode']
// .toString(),
// patient: widget.patient,
// doseTimeIn:
// doseTime['id']
// .toString(),
// model: widget.model,
// duration: duration['id']
// .toString(),
// frequency: model
// .itemMedicineList
// .length ==
// 1
// ? model
// .itemMedicineList[
// 0][
// 'parameterCode']
// .toString()
// : frequency[
// 'parameterCode']
// .toString(),
// route: model.itemMedicineListRoute
// .length ==
// 1
// ? model
// .itemMedicineListRoute[
// 0][
// 'parameterCode']
// .toString()
// : route['parameterCode']
// .toString(),
// drugId:
// _selectedMedication
// .itemId
// .toString(),
// strength:
// strengthController
// .text,
// indication:
// indicationController
// .text,
// instruction:
// instructionController
// .text,
// doseTime: selectedDate,
// );
}
}
} else {
setState(() {
if (duration == null) {
durationError =
TranslationBase.of(
context)
.fieldRequired;
} else {
durationError = null;
}
if (doseTime == null) {
doseTimeError =
TranslationBase.of(
context)
.fieldRequired;
} else {
doseTimeError = null;
}
if (route == null) {
routeError =
TranslationBase.of(
context)
.fieldRequired;
} else {
routeError = null;
}
if (frequency == null) {
frequencyError =
TranslationBase.of(
context)
.fieldRequired;
} else {
frequencyError = null;
}
if (units == null) {
unitError =
TranslationBase.of(
context)
.fieldRequired;
} else {
unitError = null;
}
if (strengthController
.text ==
"") {
strengthError =
TranslationBase.of(
context)
.fieldRequired;
} else {
strengthError = null;
}
});
}
formKey.currentState.save();
// Navigator.pop(context);
// openDrugToDrug();
// if (frequency == null ||
// strengthController
// .text ==
// "" ||
// doseTime == null ||
// duration == null ||
// selectedDate == null) {
// DrAppToastMsg.showErrorToast(
// TranslationBase.of(
// context)
// .pleaseFillAllFields);
// return;
// }
{
// Navigator.push(
// context,
@ -1430,17 +1602,20 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
// .join(' '),
dose: strengthController.text,
doseUnit: model.itemMedicineListUnit.length == 1
? model.itemMedicineListUnit[0]['parameterCode'].toString()
? model.itemMedicineListUnit[0]['parameterCode']
.toString()
: units['parameterCode'].toString(),
patient: widget.patient,
doseTimeIn: doseTime['id'].toString(),
model: widget.model,
duration: duration['id'].toString(),
frequency: model.itemMedicineList.length == 1
? model.itemMedicineList[0]['parameterCode'].toString()
? model.itemMedicineList[0]['parameterCode']
.toString()
: frequency['parameterCode'].toString(),
route: model.itemMedicineListRoute.length == 1
? model.itemMedicineListRoute[0]['parameterCode'].toString()
? model.itemMedicineListRoute[0]['parameterCode']
.toString()
: route['parameterCode'].toString(),
drugId: _selectedMedication.itemId.toString(),
strength: strengthController.text,

Loading…
Cancel
Save