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,44 +516,43 @@ 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: (String value) {
onChanged: setState(() {
(String value) { strengthChar =
setState(() { value.length;
strengthChar = });
value.length; if (strengthChar >= 5) {
}); DrAppToastMsg
if (strengthChar >= 5) { .showErrorToast(
DrAppToastMsg TranslationBase.of(
.showErrorToast( context)
TranslationBase.of( .only5DigitsAllowedForStrength,
context) );
.only5DigitsAllowedForStrength, }
); },
} inputType: TextInputType
}, .numberWithOptions(
keyboardType: TextInputType decimal: true,
.numberWithOptions( ),
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
.length == .itemMedicineListUnit
1 .length ==
? units = model 1
.itemMedicineListUnit[0] ? units = model
[ .itemMedicineListUnit[0]
'description'] ['description']
: units != : units != null
null ? units['description']
? units['description'] .toString()
.toString() : null,
: null, validationError:
true), 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, // .route,
model.itemMedicineListRoute // 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), // 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, 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, dropDownText: model
model.itemMedicineList .itemMedicineList
.length == .length ==
1 1
? model.itemMedicineList[ ? model.itemMedicineList[0]
0] ['description']
['description'] : frequency != null
: frequency != null ? frequency[
? frequency[ 'description']
'description'] : null,
: null, validationError: frequencyError,
true),
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( .doseTime,
context) isTextFieldHasSuffix: true,
.doseTime, dropDownText: doseTime != null
doseTime != null ? doseTime['nameEn']
? doseTime['nameEn'] : null,
: null, //height: 45,
true),
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['nameEn']
.duration, : null,
duration != null hintText:
? duration['nameEn'] TranslationBase.of(context)
: null, .duration,
true),
enabled: false, enabled: false,
), ),
), ),
@ -1101,14 +1185,36 @@ class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
width: 1.0, width: 1.0,
color: color:
HexColor("#CCCCCC"))), HexColor("#CCCCCC"))),
child: TextFields( child: Stack(
maxLines: 6, children: [
minLines: 4, TextFields(
hintText: maxLines: 6,
TranslationBase.of(context) minLines: 4,
hintText: TranslationBase.of(
context)
.instruction, .instruction,
controller: instructionController, controller:
//keyboardType: TextInputType.number, 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( SizedBox(
@ -1125,139 +1231,205 @@ 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 || if (_selectedMedication
duration == null || .isNarcotic ==
selectedDate == null) { true) {
DrAppToastMsg.showErrorToast( DrAppToastMsg.showErrorToast(
TranslationBase.of( TranslationBase.of(
context) context)
.pleaseFillAllFields); .narcoticMedicineCanOnlyBePrescribedFromVida);
return; Navigator.pop(context);
} return;
if (_selectedMedication }
.isNarcotic ==
true) {
DrAppToastMsg.showErrorToast(
TranslationBase.of(
context)
.narcoticMedicineCanOnlyBePrescribedFromVida);
Navigator.pop(context);
return;
}
if (double.parse( if (double.parse(
strengthController strengthController
.text) > .text) >
1000.0) { 1000.0) {
DrAppToastMsg.showErrorToast( DrAppToastMsg
"1000 is the MAX for the strength"); .showErrorToast(
return; "1000 is the MAX for the strength");
} return;
if (double.parse( }
strengthController if (double.parse(
.text) < strengthController
0.0) { .text) <
DrAppToastMsg.showErrorToast( 0.0) {
"strength can't be zero"); DrAppToastMsg
return; .showErrorToast(
} "strength can't be zero");
return;
}
if (formKey.currentState if (formKey.currentState
.validate()) { .validate()) {
Navigator.pop(context); Navigator.pop(context);
openDrugToDrug(model); openDrugToDrug(model);
{ {
// postProcedure( // postProcedure(
// icdCode: model // icdCode: model
// .patientAssessmentList // .patientAssessmentList
// .isNotEmpty // .isNotEmpty
// ? model // ? model
// .patientAssessmentList[ // .patientAssessmentList[
// 0] // 0]
// .icdCode10ID // .icdCode10ID
// .isEmpty // .isEmpty
// ? "test" // ? "test"
// : model // : model
// .patientAssessmentList[ // .patientAssessmentList[
// 0] // 0]
// .icdCode10ID // .icdCode10ID
// .toString() // .toString()
// : "test", // : "test",
// // icdCode: model // // icdCode: model
// // .patientAssessmentList // // .patientAssessmentList
// // .map((value) => value // // .map((value) => value
// // .icdCode10ID // // .icdCode10ID
// // .trim()) // // .trim())
// // .toList() // // .toList()
// // .join(' '), // // .join(' '),
// dose: strengthController // dose: strengthController
// .text, // .text,
// doseUnit: model // doseUnit: model
// .itemMedicineListUnit // .itemMedicineListUnit
// .length == // .length ==
// 1 // 1
// ? model // ? model
// .itemMedicineListUnit[ // .itemMedicineListUnit[
// 0][ // 0][
// 'parameterCode'] // 'parameterCode']
// .toString() // .toString()
// : units['parameterCode'] // : units['parameterCode']
// .toString(), // .toString(),
// patient: widget.patient, // patient: widget.patient,
// doseTimeIn: // doseTimeIn:
// doseTime['id'] // doseTime['id']
// .toString(), // .toString(),
// model: widget.model, // model: widget.model,
// duration: duration['id'] // duration: duration['id']
// .toString(), // .toString(),
// frequency: model // frequency: model
// .itemMedicineList // .itemMedicineList
// .length == // .length ==
// 1 // 1
// ? model // ? model
// .itemMedicineList[ // .itemMedicineList[
// 0][ // 0][
// 'parameterCode'] // 'parameterCode']
// .toString() // .toString()
// : frequency[ // : frequency[
// 'parameterCode'] // 'parameterCode']
// .toString(), // .toString(),
// route: model.itemMedicineListRoute // route: model.itemMedicineListRoute
// .length == // .length ==
// 1 // 1
// ? model // ? model
// .itemMedicineListRoute[ // .itemMedicineListRoute[
// 0][ // 0][
// 'parameterCode'] // 'parameterCode']
// .toString() // .toString()
// : route['parameterCode'] // : route['parameterCode']
// .toString(), // .toString(),
// drugId: // drugId:
// _selectedMedication // _selectedMedication
// .itemId // .itemId
// .toString(), // .toString(),
// strength: // strength:
// strengthController // strengthController
// .text, // .text,
// indication: // indication:
// indicationController // indicationController
// .text, // .text,
// instruction: // instruction:
// instructionController // instructionController
// .text, // .text,
// doseTime: selectedDate, // 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( // Navigator.push(
// context, // context,
@ -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