Refactor add_prescription_form
parent
113fb42d68
commit
2b38293d61
@ -0,0 +1,739 @@
|
|||||||
|
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||||
|
import 'package:doctor_app_flutter/config/config.dart';
|
||||||
|
import 'package:doctor_app_flutter/config/size_config.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/service/AnalyticsService.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/icons_app/doctor_app_icons.dart';
|
||||||
|
import 'package:doctor_app_flutter/locator.dart';
|
||||||
|
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
|
||||||
|
import 'package:doctor_app_flutter/screens/prescription/prescription_text_filed.dart';
|
||||||
|
import 'package:doctor_app_flutter/util/date-utils.dart';
|
||||||
|
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
|
||||||
|
import 'package:doctor_app_flutter/util/helpers.dart';
|
||||||
|
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||||
|
import 'package:doctor_app_flutter/widgets/shared/TextFields.dart';
|
||||||
|
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/speech-text-popup.dart';
|
||||||
|
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:hexcolor/hexcolor.dart';
|
||||||
|
import 'package:speech_to_text/speech_recognition_error.dart';
|
||||||
|
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
||||||
|
import 'add_drug_widget.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PrescriptionFormWidget extends StatefulWidget {
|
||||||
|
final PatiantInformtion patient;
|
||||||
|
final List<PrescriptionModel> prescriptionList;
|
||||||
|
final PrescriptionViewModel prescriptionViewModel;
|
||||||
|
final MedicineViewModel medicineViewModel;
|
||||||
|
|
||||||
|
|
||||||
|
const PrescriptionFormWidget({Key key, this.patient, this.prescriptionList,
|
||||||
|
this.prescriptionViewModel, this.medicineViewModel,});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_PrescriptionFormWidgetState createState() => _PrescriptionFormWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PrescriptionFormWidgetState extends State<PrescriptionFormWidget> {
|
||||||
|
String routeError;
|
||||||
|
String frequencyError;
|
||||||
|
String doseTimeError;
|
||||||
|
String durationError;
|
||||||
|
String unitError;
|
||||||
|
String strengthError;
|
||||||
|
|
||||||
|
int selectedType;
|
||||||
|
|
||||||
|
TextEditingController strengthController = TextEditingController();
|
||||||
|
TextEditingController unitController = TextEditingController();
|
||||||
|
TextEditingController indicationController = TextEditingController();
|
||||||
|
TextEditingController instructionController = TextEditingController();
|
||||||
|
|
||||||
|
bool visibilityPrescriptionForm = false;
|
||||||
|
bool visibilitySearch = true;
|
||||||
|
|
||||||
|
final myController = TextEditingController();
|
||||||
|
DateTime selectedDate;
|
||||||
|
int strengthChar;
|
||||||
|
GetMedicationResponseModel _selectedMedication;
|
||||||
|
PrescriptionViewModel prescriptionViewModel;
|
||||||
|
|
||||||
|
GlobalKey key =
|
||||||
|
new GlobalKey<AutoCompleteTextFieldState<GetMedicationResponseModel>>();
|
||||||
|
|
||||||
|
TextEditingController drugIdController = TextEditingController();
|
||||||
|
TextEditingController doseController = TextEditingController();
|
||||||
|
final searchController = TextEditingController();
|
||||||
|
stt.SpeechToText speech = stt.SpeechToText();
|
||||||
|
var event = RobotProvider();
|
||||||
|
var recognizedWord;
|
||||||
|
|
||||||
|
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||||
|
final double spaceBetweenTextFields = 12;
|
||||||
|
dynamic route;
|
||||||
|
dynamic frequency;
|
||||||
|
dynamic duration;
|
||||||
|
dynamic doseTime;
|
||||||
|
dynamic indication;
|
||||||
|
dynamic units;
|
||||||
|
dynamic uom;
|
||||||
|
dynamic box;
|
||||||
|
dynamic x;
|
||||||
|
|
||||||
|
|
||||||
|
setSelectedType(int val) {
|
||||||
|
setState(() {
|
||||||
|
selectedType = val;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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'});
|
||||||
|
print(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void statusListener(String status) {
|
||||||
|
recognizedWord = status == 'listening' ? 'Listening...' : 'Sorry....';
|
||||||
|
}
|
||||||
|
|
||||||
|
// void requestPermissions() async {
|
||||||
|
// void requestPermissions() async {
|
||||||
|
// Map<Permission, PermissionStatus> statuses = await [
|
||||||
|
// Permission.microphone,
|
||||||
|
// ].request();
|
||||||
|
// }
|
||||||
|
|
||||||
|
void resultListener(result) {
|
||||||
|
recognizedWord = result.recognizedWords;
|
||||||
|
event.setValue({"searchText": recognizedWord});
|
||||||
|
|
||||||
|
if (result.finalResult == true) {
|
||||||
|
setState(() {
|
||||||
|
SpeechToText.closeAlertDialog(context);
|
||||||
|
speech.stop();
|
||||||
|
instructionController.text += recognizedWord + '\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) {
|
||||||
|
final screenSize = MediaQuery.of(context).size;
|
||||||
|
return Visibility(
|
||||||
|
visible: visibilitySearch,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
AppText(
|
||||||
|
_selectedMedication?.description ??
|
||||||
|
"",
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 15.0,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SizedBox(width: 6,),
|
||||||
|
AppText(
|
||||||
|
TranslationBase.of(context)
|
||||||
|
.orderType,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
SizedBox(width: 18,),
|
||||||
|
Radio(
|
||||||
|
activeColor:
|
||||||
|
AppGlobal.appRedColor,
|
||||||
|
value: 1,
|
||||||
|
groupValue: selectedType,
|
||||||
|
onChanged: (value) {
|
||||||
|
setSelectedType(value);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Text(TranslationBase.of(context)
|
||||||
|
.regular),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: MediaQuery.of(context)
|
||||||
|
.size
|
||||||
|
.width *
|
||||||
|
0.35,
|
||||||
|
child: AppTextFieldCustom(
|
||||||
|
height: 38,
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 5.0,
|
||||||
|
),
|
||||||
|
// Container(
|
||||||
|
// width: MediaQuery.of(context)
|
||||||
|
// .size
|
||||||
|
// .width *
|
||||||
|
// 0.35,
|
||||||
|
// child: AppTextFieldCustom(
|
||||||
|
// height: 38,
|
||||||
|
// validationError:
|
||||||
|
// unitError,
|
||||||
|
// hintText: 'Unit',
|
||||||
|
// isTextFieldHasSuffix: false,
|
||||||
|
// enabled: true,
|
||||||
|
// controller:
|
||||||
|
// unitController,
|
||||||
|
// onChanged: (selectedValue) {
|
||||||
|
// setState(() {
|
||||||
|
// units = selectedValue;
|
||||||
|
// units['isDefault'] = true;
|
||||||
|
// });
|
||||||
|
// if (strengthChar >= 5) {
|
||||||
|
// DrAppToastMsg
|
||||||
|
// .showErrorToast(
|
||||||
|
// TranslationBase.of(
|
||||||
|
// context)
|
||||||
|
// .only5DigitsAllowedForStrength,
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// inputType: TextInputType
|
||||||
|
// .numberWithOptions(
|
||||||
|
// decimal: true,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
PrescriptionTextFiled(
|
||||||
|
width: MediaQuery.of(context)
|
||||||
|
.size
|
||||||
|
.width *
|
||||||
|
0.510,
|
||||||
|
element: widget.medicineViewModel
|
||||||
|
.itemMedicineListUnit
|
||||||
|
.length ==
|
||||||
|
1
|
||||||
|
? widget.medicineViewModel
|
||||||
|
.itemMedicineListUnit[0]
|
||||||
|
: units,
|
||||||
|
elementError: unitError,
|
||||||
|
keyName: 'description',
|
||||||
|
keyId: 'parameterCode',
|
||||||
|
hintText: 'Unit',
|
||||||
|
elementList: widget.medicineViewModel
|
||||||
|
.itemMedicineListUnit,
|
||||||
|
okFunction: (selectedValue) {
|
||||||
|
setState(() {
|
||||||
|
units = selectedValue;
|
||||||
|
units['isDefault'] = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
PrescriptionTextFiled(
|
||||||
|
elementList:
|
||||||
|
widget.medicineViewModel.itemMedicineListRoute,
|
||||||
|
element: widget.medicineViewModel.itemMedicineListRoute
|
||||||
|
.length ==
|
||||||
|
1
|
||||||
|
? route = widget.medicineViewModel.itemMedicineListRoute[0]
|
||||||
|
: route,
|
||||||
|
elementError: routeError,
|
||||||
|
keyId: 'parameterCode',
|
||||||
|
keyName: 'description',
|
||||||
|
okFunction: (selectedValue) {
|
||||||
|
setState(() {
|
||||||
|
route = selectedValue;
|
||||||
|
route['isDefault'] = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
hintText:
|
||||||
|
TranslationBase.of(context)
|
||||||
|
.route,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
PrescriptionTextFiled(
|
||||||
|
hintText: TranslationBase.of(context).frequency,
|
||||||
|
elementError: frequencyError,
|
||||||
|
// element: frequency,
|
||||||
|
element: widget.medicineViewModel.itemMedicineListRoute
|
||||||
|
.length ==
|
||||||
|
1
|
||||||
|
? frequency = widget.medicineViewModel.itemMedicineListRoute[0]
|
||||||
|
: frequency,
|
||||||
|
elementList: widget.medicineViewModel.itemMedicineList,
|
||||||
|
keyId: 'parameterCode',
|
||||||
|
keyName: 'description',
|
||||||
|
okFunction: (selectedValue) {
|
||||||
|
setState(() {
|
||||||
|
frequency = selectedValue;
|
||||||
|
frequency['isDefault'] = true;
|
||||||
|
if (_selectedMedication != null && duration != null && frequency != null && strengthController.text != null) {
|
||||||
|
widget.medicineViewModel.getBoxQuantity(
|
||||||
|
freq: frequency['parameterCode'],
|
||||||
|
duration: duration['id'],
|
||||||
|
itemCode: _selectedMedication.itemId,
|
||||||
|
strength: double.parse(strengthController.text)
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
PrescriptionTextFiled(
|
||||||
|
hintText:
|
||||||
|
TranslationBase.of(context)
|
||||||
|
.doseTime,
|
||||||
|
elementError: doseTimeError,
|
||||||
|
element: doseTime,
|
||||||
|
elementList:
|
||||||
|
widget.medicineViewModel.medicationDoseTimeList,
|
||||||
|
keyId: 'id',
|
||||||
|
keyName: 'nameEn',
|
||||||
|
okFunction: (selectedValue) {
|
||||||
|
setState(() {
|
||||||
|
doseTime = selectedValue;
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
if (widget.medicineViewModel
|
||||||
|
.patientAssessmentList.isNotEmpty)
|
||||||
|
Container(
|
||||||
|
height: screenSize.height * 0.070,
|
||||||
|
width: double.infinity,
|
||||||
|
color: Colors.white,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width:
|
||||||
|
MediaQuery.of(context)
|
||||||
|
.size
|
||||||
|
.width *
|
||||||
|
0.29,
|
||||||
|
child: AppTextFieldCustom(
|
||||||
|
hintText:
|
||||||
|
widget.medicineViewModel
|
||||||
|
.patientAssessmentList[
|
||||||
|
0]
|
||||||
|
.icdCode10ID
|
||||||
|
.toString(),
|
||||||
|
// indication != null
|
||||||
|
// ? indication[
|
||||||
|
// 'name']
|
||||||
|
// : null,
|
||||||
|
|
||||||
|
enabled: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width:
|
||||||
|
MediaQuery.of(context)
|
||||||
|
.size
|
||||||
|
.width *
|
||||||
|
0.57,
|
||||||
|
color: Colors.white,
|
||||||
|
child: AppTextFieldCustom(
|
||||||
|
maxLines: 5,
|
||||||
|
hintText:
|
||||||
|
widget.medicineViewModel
|
||||||
|
.patientAssessmentList[
|
||||||
|
0]
|
||||||
|
.asciiDesc
|
||||||
|
.toString(),
|
||||||
|
// indication != null
|
||||||
|
// ? indication[
|
||||||
|
// 'name']
|
||||||
|
// : null,
|
||||||
|
enabled: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
Container(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => selectDate(
|
||||||
|
context, widget.prescriptionViewModel),
|
||||||
|
child: AppTextFieldCustom(
|
||||||
|
validationError:
|
||||||
|
strengthError,
|
||||||
|
hintText: 'Date',
|
||||||
|
isTextFieldHasSuffix: true,
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
Icons.calendar_today,
|
||||||
|
color: Colors.black,),
|
||||||
|
),
|
||||||
|
dropDownText: selectedDate != null
|
||||||
|
? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}"
|
||||||
|
: null,
|
||||||
|
enabled: false,
|
||||||
|
controller: strengthController,
|
||||||
|
),
|
||||||
|
|
||||||
|
// TextField(
|
||||||
|
// decoration:
|
||||||
|
// textFieldSelectorDecoration(
|
||||||
|
// TranslationBase.of(
|
||||||
|
// context)
|
||||||
|
// .date,
|
||||||
|
// selectedDate != null
|
||||||
|
// ? "${AppDateUtils.convertStringToDateFormat(selectedDate.toString(), "yyyy-MM-dd")}"
|
||||||
|
// : null,
|
||||||
|
// true,
|
||||||
|
// suffixIcon: Icon(
|
||||||
|
// Icons.calendar_today,
|
||||||
|
// color: Colors.black,
|
||||||
|
// )),
|
||||||
|
// enabled: false,
|
||||||
|
// ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
PrescriptionTextFiled(
|
||||||
|
element: duration,
|
||||||
|
elementError: durationError,
|
||||||
|
hintText:
|
||||||
|
TranslationBase.of(context)
|
||||||
|
.duration,
|
||||||
|
elementList:
|
||||||
|
widget.medicineViewModel.medicationDurationList,
|
||||||
|
keyName: 'nameEn',
|
||||||
|
keyId: 'id',
|
||||||
|
okFunction: (selectedValue) {
|
||||||
|
setState(() {
|
||||||
|
duration = selectedValue;
|
||||||
|
if (_selectedMedication !=
|
||||||
|
null &&
|
||||||
|
duration != null &&
|
||||||
|
frequency != null &&
|
||||||
|
strengthController.text !=
|
||||||
|
null) {
|
||||||
|
widget.medicineViewModel.getBoxQuantity(
|
||||||
|
freq: frequency[
|
||||||
|
'parameterCode'],
|
||||||
|
duration: duration['id'],
|
||||||
|
itemCode:
|
||||||
|
_selectedMedication
|
||||||
|
.itemId,
|
||||||
|
strength: double.parse(
|
||||||
|
strengthController
|
||||||
|
.text),
|
||||||
|
);
|
||||||
|
box = widget.medicineViewModel.boxQuintity;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
Container(
|
||||||
|
color: Colors.white,
|
||||||
|
child: AppTextFieldCustom(
|
||||||
|
hintText: "UOM",
|
||||||
|
isTextFieldHasSuffix: false,
|
||||||
|
dropDownText:
|
||||||
|
uom != null ? uom : null,
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
Container(
|
||||||
|
color: Colors.white,
|
||||||
|
child: AppTextFieldCustom(
|
||||||
|
hintText:
|
||||||
|
TranslationBase.of(context)
|
||||||
|
.boxQuantity,
|
||||||
|
isTextFieldHasSuffix: false,
|
||||||
|
dropDownText: box != null
|
||||||
|
? widget.medicineViewModel.boxQuintity.toString()
|
||||||
|
: null,
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(6.0)),
|
||||||
|
border: Border.all(
|
||||||
|
width: 1.0,
|
||||||
|
color:
|
||||||
|
HexColor("#CCCCCC"))),
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
TextFields(
|
||||||
|
maxLines: 6,
|
||||||
|
minLines: 4,
|
||||||
|
hintText: TranslationBase.of(
|
||||||
|
context)
|
||||||
|
.instruction,
|
||||||
|
controller:
|
||||||
|
instructionController,
|
||||||
|
//keyboardType: TextInputType.number,
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
top: 0,
|
||||||
|
right: 15,
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
DoctorApp.speechtotext,
|
||||||
|
color: Colors.black,
|
||||||
|
size: 35,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
initSpeechState().then(
|
||||||
|
(value) =>
|
||||||
|
{onVoiceText()});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields),
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.all(
|
||||||
|
SizeConfig.widthMultiplier * 5),
|
||||||
|
child: Wrap(
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
AppButton(
|
||||||
|
color: Color(0xff359846),
|
||||||
|
title: TranslationBase.of(
|
||||||
|
context)
|
||||||
|
.addMedication,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
onPressed: () async {
|
||||||
|
addMedicationButton( widget.medicineViewModel);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectDate(BuildContext context, PrescriptionViewModel model) async {
|
||||||
|
Helpers.hideKeyboard(context);
|
||||||
|
DateTime selectedDate;
|
||||||
|
selectedDate = DateTime.now();
|
||||||
|
final DateTime picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: selectedDate,
|
||||||
|
firstDate: DateTime.now(),
|
||||||
|
lastDate: DateTime(2040),
|
||||||
|
initialEntryMode: DatePickerEntryMode.calendar,
|
||||||
|
);
|
||||||
|
if (picked != null && picked != selectedDate) {
|
||||||
|
setState(() {
|
||||||
|
this.selectedDate = picked;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
openDrugToDrug(MedicineViewModel model, PrescriptionViewModel modelPrescription) {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AddDrugWidget(
|
||||||
|
patient: widget.patient,
|
||||||
|
medicineModel: model,
|
||||||
|
modelPrescription: modelPrescription,
|
||||||
|
prescriptionList: widget.prescriptionList,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
addMedicationButton(MedicineViewModel model) async {
|
||||||
|
await locator<
|
||||||
|
AnalyticsService>()
|
||||||
|
.logEvent(
|
||||||
|
eventCategory:
|
||||||
|
"Add Prescription Form",
|
||||||
|
eventAction:
|
||||||
|
"Add Prescription",
|
||||||
|
);
|
||||||
|
if (duration != null &&
|
||||||
|
doseTime != null &&
|
||||||
|
frequency != null &&
|
||||||
|
selectedDate != null &&
|
||||||
|
strengthController
|
||||||
|
.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 (formKey.currentState
|
||||||
|
.validate()) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
openDrugToDrug(model, widget.prescriptionViewModel);
|
||||||
|
}
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hexcolor/hexcolor.dart';
|
||||||
|
import '../../../config/config.dart';
|
||||||
|
import '../../../core/model/search_drug/get_medication_response_model.dart';
|
||||||
|
import '../../../core/viewModel/medicine_view_model.dart';
|
||||||
|
import '../../../core/viewModel/prescription_view_model.dart';
|
||||||
|
import '../../../util/helpers.dart';
|
||||||
|
import '../../../util/translations_delegate_base.dart';
|
||||||
|
import '../../../widgets/medicine/medicine_item_widget.dart';
|
||||||
|
import '../../../widgets/shared/buttons/app_buttons_widget.dart';
|
||||||
|
import '../../../widgets/shared/loader/gif_loader_dialog_utils.dart';
|
||||||
|
import '../../../widgets/shared/network_base_view.dart';
|
||||||
|
import '../../../widgets/shared/text_fields/app_text_form_field.dart';
|
||||||
|
import '../../base/base_view.dart';
|
||||||
|
|
||||||
|
final myController = TextEditingController();
|
||||||
|
class SearchPrescriptionWidget extends StatelessWidget {
|
||||||
|
final double spaceBetweenTextFields;
|
||||||
|
final MedicineViewModel medicineViewModel;
|
||||||
|
final PrescriptionViewModel prescriptionViewModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const SearchPrescriptionWidget({Key key, this.spaceBetweenTextFields, this.medicineViewModel,
|
||||||
|
this.prescriptionViewModel}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
bool visibilityPrescriptionForm = false;
|
||||||
|
bool visibilitySearch = true;
|
||||||
|
GetMedicationResponseModel _selectedMedication;
|
||||||
|
|
||||||
|
return BaseView<MedicineViewModel>(
|
||||||
|
onModelReady: (model) async {},
|
||||||
|
builder: (
|
||||||
|
BuildContext context,
|
||||||
|
MedicineViewModel model,
|
||||||
|
Widget child,) =>
|
||||||
|
NetworkBaseView(
|
||||||
|
baseViewModel: model,
|
||||||
|
child: Visibility(
|
||||||
|
visible: visibilityPrescriptionForm,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
FractionallySizedBox(
|
||||||
|
widthFactor: 0.9,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(6.0)),
|
||||||
|
border: Border.all(width: 1.0, color: HexColor("#CCCCCC"))),
|
||||||
|
padding: EdgeInsets.all(10),
|
||||||
|
child: AppTextFormField(
|
||||||
|
onTap: () {
|
||||||
|
visibilityPrescriptionForm = false;
|
||||||
|
visibilitySearch = true;
|
||||||
|
},
|
||||||
|
borderColor: Colors.white,
|
||||||
|
hintText: TranslationBase.of(context).searchMedicineNameHere,
|
||||||
|
controller: myController,
|
||||||
|
onSaved: (value) {},
|
||||||
|
onFieldSubmitted: (value) {
|
||||||
|
searchMedicine(context, model);
|
||||||
|
},
|
||||||
|
inputFormatter: ONLY_LETTERS,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 15.0,
|
||||||
|
),
|
||||||
|
Visibility(
|
||||||
|
visible: visibilitySearch,
|
||||||
|
child: Container(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
FractionallySizedBox(
|
||||||
|
widthFactor: 0.8,
|
||||||
|
child: Container(
|
||||||
|
child: Wrap(
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
AppButton(
|
||||||
|
title: TranslationBase.of(context).search,
|
||||||
|
onPressed: () async {
|
||||||
|
await searchMedicine(
|
||||||
|
context,
|
||||||
|
model,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (myController.text != '')
|
||||||
|
Container(
|
||||||
|
height: MediaQuery.of(context).size.height * 0.5,
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(top: 20),
|
||||||
|
scrollDirection: Axis.vertical,
|
||||||
|
itemCount: model.allMedicationList == null
|
||||||
|
? 0
|
||||||
|
: model.allMedicationList.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return InkWell(
|
||||||
|
child: MedicineItemWidget(
|
||||||
|
label:
|
||||||
|
model.allMedicationList[index].description),
|
||||||
|
onTap: () {
|
||||||
|
model.getItem(
|
||||||
|
itemID: model.allMedicationList[index].itemId);
|
||||||
|
visibilityPrescriptionForm = true;
|
||||||
|
visibilitySearch = false;
|
||||||
|
|
||||||
|
_selectedMedication =
|
||||||
|
model.allMedicationList[index];
|
||||||
|
// uom = _selectedMedication.uom;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: spaceBetweenTextFields,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
);}
|
||||||
|
|
||||||
|
searchMedicine(context, MedicineViewModel model) async {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
if (myController.text.length < 3) {
|
||||||
|
Helpers.showErrorToast(TranslationBase.of(context).moreThan3Letter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GifLoaderDialogUtils.showMyDialog(context);
|
||||||
|
await model.getMedicationList(drug: myController.text,isLocalBusy: true);
|
||||||
|
GifLoaderDialogUtils.hideDialog(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue