Merge branch 'prescription_changes' into 'development'

adding validation and voice speach to prescription form

See merge request Cloud_Solution/doctor_app_flutter!684
merge-requests/685/merge
Mohammad Aljammal 5 years ago
commit 2de29f0b83

@ -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/post_prescrition_req_model.dart';
import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_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/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/medicine_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription_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/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/SOAP/GetAssessmentReqModel.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.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/buttons/app_buttons_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/dailog-list-select.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/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-textfield-custom.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.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, addPrescriptionForm(context, PrescriptionViewModel model,
PatiantInformtion patient, prescription) { PatiantInformtion patient, prescription) {
@ -102,6 +108,13 @@ class PrescriptionFormWidget extends StatefulWidget {
} }
class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> { class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
String routeError;
String frequencyError;
String doseTimeError;
String durationError;
String unitError;
String strengthError;
int selectedType; int selectedType;
TextEditingController durationController = TextEditingController(); TextEditingController durationController = TextEditingController();
TextEditingController strengthController = TextEditingController(); TextEditingController strengthController = TextEditingController();
@ -124,6 +137,9 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
TextEditingController drugIdController = TextEditingController(); TextEditingController drugIdController = TextEditingController();
TextEditingController doseController = TextEditingController(); TextEditingController doseController = TextEditingController();
final searchController = TextEditingController(); final searchController = TextEditingController();
stt.SpeechToText speech = stt.SpeechToText();
var event = RobotProvider();
var reconizedWord;
var notesList; var notesList;
var filteredNotesList; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ListSelectDialog drugDialog; ListSelectDialog drugDialog;
@ -244,7 +314,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
(BuildContext context, ScrollController scrollController) { (BuildContext context, ScrollController scrollController) {
return SingleChildScrollView( return SingleChildScrollView(
child: Container( child: Container(
height: MediaQuery.of(context).size.height * 1.45, height: MediaQuery.of(context).size.height * 1.65,
color: Color(0xffF8F8F8), color: Color(0xffF8F8F8),
child: Padding( child: Padding(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
@ -437,11 +507,6 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox( SizedBox(
height: spaceBetweenTextFileds), height: spaceBetweenTextFileds),
Container( Container(
//height: screenSize.height * 0.062,
height: MediaQuery.of(context)
.size
.height *
0.0749,
width: double.infinity, width: double.infinity,
child: Row( child: Row(
children: [ children: [
@ -451,18 +516,16 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
.size .size
.width * .width *
0.35, 0.35,
child: TextField( child: AppTextFieldCustom(
decoration: height: 40,
textFieldSelectorDecorationStreangrh( validationError:
strengthController strengthError,
.text, hintText: 'Strength',
'Strength', //strengthController.text, isTextFieldHasSuffix: false,
false),
enabled: true, enabled: true,
controller: controller:
strengthController, strengthController,
onChanged: onChanged: (String value) {
(String value) {
setState(() { setState(() {
strengthChar = strengthChar =
value.length; value.length;
@ -476,19 +539,20 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
); );
} }
}, },
keyboardType: TextInputType inputType: TextInputType
.numberWithOptions( .numberWithOptions(
decimal: true, decimal: true,
)), ),
// keyboardType: TextInputType
// .numberWithOptions(
// decimal: true,
// ),
),
), ),
SizedBox( SizedBox(
width: 5.0, width: 5.0,
), ),
Container( Container(
// height: MediaQuery.of(context)
// .size
// .height *
// 0.06,
color: Colors.white, color: Colors.white,
width: MediaQuery.of(context) width: MediaQuery.of(context)
.size .size
@ -538,23 +602,23 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
); );
} }
: null, : null,
child: TextField( child: AppTextFieldCustom(
decoration: hintText: 'Select',
textFieldSelectorDecoration( isTextFieldHasSuffix:
'Select', true,
model.itemMedicineListUnit dropDownText: model
.itemMedicineListUnit
.length == .length ==
1 1
? units = model ? units = model
.itemMedicineListUnit[0] .itemMedicineListUnit[0]
[ ['description']
'description'] : units != null
: units !=
null
? units['description'] ? units['description']
.toString() .toString()
: null, : null,
true), validationError:
unitError,
enabled: false), enabled: false),
), ),
), ),
@ -564,7 +628,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox( SizedBox(
height: spaceBetweenTextFileds), height: spaceBetweenTextFileds),
Container( Container(
height: screenSize.height * 0.070, //height: screenSize.height * 0.070,
color: Colors.white, color: Colors.white,
child: InkWell( child: InkWell(
onTap: onTap:
@ -613,23 +677,44 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
); );
} }
: null, : null,
child: TextField( child: AppTextFieldCustom(
decoration: // decoration:
textFieldSelectorDecoration( // textFieldSelectorDecoration(
TranslationBase.of( // TranslationBase.of(
context) // context)
// .route,
// model.itemMedicineListRoute
// .length ==
// 1
// ? model.itemMedicineListRoute[
// 0]
// ['description']
// : route != null
// ? route[
// 'description']
// : null,
// true),
hintText:
TranslationBase.of(context)
.route, .route,
model.itemMedicineListRoute dropDownText: model
.itemMedicineListRoute
.length == .length ==
1 1
? model.itemMedicineListRoute[ ? model.itemMedicineListRoute[
0] 0]['description']
['description']
: route != null : route != null
? route[ ? route['description']
'description']
: null, : null,
true), isTextFieldHasSuffix: true,
//height: 45,
validationError:
model.itemMedicineListRoute
.length !=
1
? routeError
: null,
enabled: false, enabled: false,
), ),
), ),
@ -637,7 +722,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox( SizedBox(
height: spaceBetweenTextFileds), height: spaceBetweenTextFileds),
Container( Container(
height: screenSize.height * 0.070, //height: screenSize.height * 0.070,
color: Colors.white, color: Colors.white,
child: InkWell( child: InkWell(
onTap: onTap:
@ -704,23 +789,22 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
); );
} }
: null, : null,
child: TextField( child: AppTextFieldCustom(
decoration: isTextFieldHasSuffix: true,
textFieldSelectorDecoration( hintText:
TranslationBase.of( TranslationBase.of(context)
context)
.frequency, .frequency,
model.itemMedicineList dropDownText: model
.itemMedicineList
.length == .length ==
1 1
? model.itemMedicineList[ ? model.itemMedicineList[0]
0]
['description'] ['description']
: frequency != null : frequency != null
? frequency[ ? frequency[
'description'] 'description']
: null, : null,
true), validationError: frequencyError,
enabled: false, enabled: false,
), ),
), ),
@ -728,7 +812,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox( SizedBox(
height: spaceBetweenTextFileds), height: spaceBetweenTextFileds),
Container( Container(
height: screenSize.height * 0.070, //height: screenSize.height * 0.070,
color: Colors.white, color: Colors.white,
child: InkWell( child: InkWell(
onTap: onTap:
@ -770,17 +854,18 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
); );
} }
: null, : null,
child: TextField( child: AppTextFieldCustom(
decoration: hintText:
textFieldSelectorDecoration( TranslationBase.of(context)
TranslationBase.of(
context)
.doseTime, .doseTime,
doseTime != null isTextFieldHasSuffix: true,
dropDownText: doseTime != null
? doseTime['nameEn'] ? doseTime['nameEn']
: null, : null,
true), //height: 45,
enabled: false, enabled: false,
validationError: doseTimeError,
), ),
), ),
), ),
@ -894,7 +979,7 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
SizedBox( SizedBox(
height: spaceBetweenTextFileds), height: spaceBetweenTextFileds),
Container( Container(
height: screenSize.height * 0.070, //height: screenSize.height * 0.070,
color: Colors.white, color: Colors.white,
child: InkWell( child: InkWell(
onTap: onTap:
@ -963,16 +1048,15 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
); );
} }
: null, : null,
child: TextField( child: AppTextFieldCustom(
decoration: validationError: durationError,
textFieldSelectorDecoration( isTextFieldHasSuffix: true,
TranslationBase.of( dropDownText: duration != null
context)
.duration,
duration != null
? duration['nameEn'] ? duration['nameEn']
: null, : null,
true), hintText:
TranslationBase.of(context)
.duration,
enabled: false, enabled: false,
), ),
), ),
@ -1101,15 +1185,37 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
width: 1.0, width: 1.0,
color: color:
HexColor("#CCCCCC"))), HexColor("#CCCCCC"))),
child: TextFields( child: Stack(
children: [
TextFields(
maxLines: 6, maxLines: 6,
minLines: 4, minLines: 4,
hintText: hintText: TranslationBase.of(
TranslationBase.of(context) context)
.instruction, .instruction,
controller: instructionController, controller:
instructionController,
//keyboardType: TextInputType.number, //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( SizedBox(
height: spaceBetweenTextFileds), height: spaceBetweenTextFileds),
@ -1125,23 +1231,16 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
context) context)
.addMedication, .addMedication,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
onPressed: () { onPressed: () async {
formKey.currentState.save(); if (route != null &&
// Navigator.pop(context); duration != null &&
// openDrugToDrug(); doseTime != null &&
if (frequency == null || frequency != null &&
units != null &&
selectedDate != null &&
strengthController strengthController
.text == .text !=
"" || "") {
doseTime == null ||
duration == null ||
selectedDate == null) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(
context)
.pleaseFillAllFields);
return;
}
if (_selectedMedication if (_selectedMedication
.isNarcotic == .isNarcotic ==
true) { true) {
@ -1157,7 +1256,8 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
strengthController strengthController
.text) > .text) >
1000.0) { 1000.0) {
DrAppToastMsg.showErrorToast( DrAppToastMsg
.showErrorToast(
"1000 is the MAX for the strength"); "1000 is the MAX for the strength");
return; return;
} }
@ -1165,7 +1265,8 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
strengthController strengthController
.text) < .text) <
0.0) { 0.0) {
DrAppToastMsg.showErrorToast( DrAppToastMsg
.showErrorToast(
"strength can't be zero"); "strength can't be zero");
return; return;
} }
@ -1257,6 +1358,77 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
// ); // );
} }
} }
} 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( // Navigator.push(
@ -1430,17 +1602,20 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
// .join(' '), // .join(' '),
dose: strengthController.text, dose: strengthController.text,
doseUnit: model.itemMedicineListUnit.length == 1 doseUnit: model.itemMedicineListUnit.length == 1
? model.itemMedicineListUnit[0]['parameterCode'].toString() ? model.itemMedicineListUnit[0]['parameterCode']
.toString()
: units['parameterCode'].toString(), : units['parameterCode'].toString(),
patient: widget.patient, patient: widget.patient,
doseTimeIn: doseTime['id'].toString(), doseTimeIn: doseTime['id'].toString(),
model: widget.model, model: widget.model,
duration: duration['id'].toString(), duration: duration['id'].toString(),
frequency: model.itemMedicineList.length == 1 frequency: model.itemMedicineList.length == 1
? model.itemMedicineList[0]['parameterCode'].toString() ? model.itemMedicineList[0]['parameterCode']
.toString()
: frequency['parameterCode'].toString(), : frequency['parameterCode'].toString(),
route: model.itemMedicineListRoute.length == 1 route: model.itemMedicineListRoute.length == 1
? model.itemMedicineListRoute[0]['parameterCode'].toString() ? model.itemMedicineListRoute[0]['parameterCode']
.toString()
: route['parameterCode'].toString(), : route['parameterCode'].toString(),
drugId: _selectedMedication.itemId.toString(), drugId: _selectedMedication.itemId.toString(),
strength: strengthController.text, strength: strengthController.text,

Loading…
Cancel
Save