import 'package:autocomplete_textfield/autocomplete_textfield.dart'; import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; import 'package:doctor_app_flutter/models/SOAP/my_selected_assement.dart'; import 'package:doctor_app_flutter/models/SOAP/post_assessment_request_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/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/Text.dart'; import 'package:doctor_app_flutter/widgets/shared/TextFields.dart'; import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/dialogs/master_key_dailog.dart'; import 'package:doctor_app_flutter/widgets/shared/divider_with_spaces_around.dart'; import 'package:doctor_app_flutter/widgets/shared/expandable-widget-header-body.dart'; import 'package:eva_icons_flutter/eva_icons_flutter.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; class AssessmentPage extends StatefulWidget { final Function changePageViewIndex; final MySelectedAssessment mySelectedAssessment; final PatiantInformtion patientInfo; AssessmentPage( {Key key, this.changePageViewIndex, this.mySelectedAssessment, this.patientInfo}); @override _AssessmentPageState createState() => _AssessmentPageState(); } class _AssessmentPageState extends State { bool isAssessmentExpand = false; List assessmentList; dynamic _referTo; TextEditingController remarksController = TextEditingController(); Helpers helpers = Helpers(); @override Widget build(BuildContext context) { final screenSize = MediaQuery.of(context).size; return BaseView( builder: (_, model, w) => AppScaffold( isShowAppBar: false, body: SingleChildScrollView( physics: ScrollPhysics(), child: Center( child: FractionallySizedBox( widthFactor: 0.9, child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox( height: 30, ), HeaderBodyExpandableNotifier( headerWidget: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Texts('ASSESSMENT', variant: isAssessmentExpand ? "bodyText" : '', bold: isAssessmentExpand ? true : false, color: Colors.black), Icon( FontAwesomeIcons.asterisk, color: AppGlobal.appPrimaryColor, size: 12, ) ], ), InkWell( onTap: () { setState(() { isAssessmentExpand = !isAssessmentExpand; }); }, child: Icon(isAssessmentExpand ? EvaIcons.minus : EvaIcons.plus)) ], ), bodyWidget: Column(children: [ SizedBox( height: 20, ), Column( children: [ Container( margin: EdgeInsets.only(left: 5, right: 5, top: 15), child: TextFields( hintText: "Add ASSESSMENT", fontSize: 13.5, onTapTextFields: () { openAssessmentDialog(context); }, readOnly: true, // hintColor: Colors.black, suffixIcon: EvaIcons.plusCircleOutline, suffixIconColor: AppGlobal.appPrimaryColor, fontWeight: FontWeight.w600, // controller: messageController, validator: (value) { if (value == null) return TranslationBase .of(context) .emptyMessage; else return null; }), ), SizedBox( height: 20, ), if(widget.mySelectedAssessment != null && widget.mySelectedAssessment .appointmentId != null && widget.mySelectedAssessment .selectedDiagnosisType != null && widget.mySelectedAssessment .selectedDiagnosisCondition != null) Container( margin: EdgeInsets.only( left: 5, right: 5, top: 15), child: Row( mainAxisAlignment: MainAxisAlignment .spaceBetween, crossAxisAlignment: CrossAxisAlignment .start, children: [ Column( mainAxisAlignment: MainAxisAlignment .start, children: [ Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ AppText( "12".toUpperCase(), fontWeight: FontWeight.bold, fontSize: 16, ), AppText( "DEC".toUpperCase(), fontSize: 10, color: Colors.grey, ), ], ) ], ), Column( crossAxisAlignment: CrossAxisAlignment .start, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ AppText( "Appointment #: ", fontWeight: FontWeight.bold, fontSize: 16, ), AppText( widget.mySelectedAssessment .appointmentId .toString(), fontSize: 10, color: Colors.grey, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ AppText( widget.mySelectedAssessment .selectedDiagnosisCondition .nameEn, fontWeight: FontWeight.bold, fontSize: 16, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ AppText( "Type : ", fontWeight: FontWeight.bold, fontSize: 16, ), AppText( widget.mySelectedAssessment .selectedDiagnosisType .nameEn, fontSize: 10, color: Colors.grey, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ AppText( "Doc : ", fontWeight: FontWeight.bold, fontSize: 16, ), AppText( "Anas Abdullah", fontSize: 10, color: Colors.grey, ), ], ), SizedBox( height: 6, ), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox( height: 6, ), AppText( widget.mySelectedAssessment.remark, fontSize: 10, color: Colors.grey, ), ], ), ], ), Column( crossAxisAlignment: CrossAxisAlignment .start, children: [ Row( children: [ AppText( "ICD: ".toUpperCase(), fontWeight: FontWeight.bold, fontSize: 16, ), AppText( "R07.1".toUpperCase(), fontSize: 10, color: Colors.grey, ), ], ) ], ), Column( children: [ InkWell( onTap: () { openAssessmentDialog(context); }, child: Icon(EvaIcons .edit2Outline), ) ], ), ], ), ) ], ) ]), isExpand: isAssessmentExpand, ), DividerWithSpacesAround( height: 30, ), AppButton( title: TranslationBase.of(context).next, loading: model.state == ViewState.BusyLocal, onPressed: () async { await submitAssessment(model); }, ), SizedBox( height: 30, ), ], ), ), ), ))); } submitAssessment(SOAPViewModel model) async { if (widget.mySelectedAssessment.selectedDiagnosisCondition != null && widget.mySelectedAssessment.selectedDiagnosisType != null) { PostAssessmentRequestModel postAssessmentRequestModel = new PostAssessmentRequestModel( patientMRN: widget.patientInfo.patientMRN, episodeId: widget.patientInfo.episodeNo, appointmentNo: widget.patientInfo.appointmentNo, icdCodeDetails: [ new IcdCodeDetails( remarks: widget.mySelectedAssessment.remark, complexDiagnosis: true, conditionId: widget.mySelectedAssessment.selectedDiagnosisCondition.id, diagnosisTypeId: widget.mySelectedAssessment.selectedDiagnosisType.id, icdcode10Id: "1") ]); await model.postAssessment(postAssessmentRequestModel); if (model.state == ViewState.ErrorLocal) { helpers.showErrorToast(model.error); } else { widget.changePageViewIndex(3); } } else { helpers.showErrorToast('Please add required field correctly'); } widget.changePageViewIndex(3); } openAssessmentDialog(BuildContext context) { showModalBottomSheet( backgroundColor: Colors.white, isScrollControlled: true, context: context, builder: (context) { return AddAssessmentDetails( mySelectedAssessment: widget.mySelectedAssessment, addSelectedAssessment: () { setState(() { Navigator.of(context).pop(); }); }); }); } } class AddAssessmentDetails extends StatefulWidget { final MySelectedAssessment mySelectedAssessment; final Function() addSelectedAssessment; const AddAssessmentDetails( {Key key, this.mySelectedAssessment, this.addSelectedAssessment}) : super(key: key); @override _AddAssessmentDetailsState createState() => _AddAssessmentDetailsState(); } class _AddAssessmentDetailsState extends State { // MasterKeyModel _selectedDiagnosisCondition; // MasterKeyModel _selectedDiagnosisType; TextEditingController remarkController = TextEditingController(); TextEditingController appointmentIdController = TextEditingController( text: "234567"); GlobalKey key = new GlobalKey>(); @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); remarkController.text = widget.mySelectedAssessment.remark??""; final screenSize = MediaQuery .of(context) .size; InputDecoration textFieldSelectorDecoration(String hintText, String selectedText, bool isDropDown,{IconData icon}) { //TODO: make one Input InputDecoration for all return InputDecoration( focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0), borderRadius: BorderRadius.circular(8), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0), borderRadius: BorderRadius.circular(8), ), disabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Color(0xFFCCCCCC), width: 2.0), borderRadius: BorderRadius.circular(8), ), hintText: selectedText != null ? selectedText : hintText, suffixIcon: isDropDown ? Icon(icon??Icons.arrow_drop_down) : null, hintStyle: TextStyle( fontSize: 14, color: Colors.grey.shade600, ), ); } return FractionallySizedBox( heightFactor: 0.75, child: BaseView( onModelReady: (model) async { if (model.listOfDiagnosisCondition.length == 0) { await model.getMasterLookup(MasterKeysService.DiagnosisCondition); } if (model.listOfDiagnosisType.length == 0) { await model.getMasterLookup(MasterKeysService.DiagnosisType); } // if (model.listOfICD10.length == 0) { // await model.getMasterLookup(MasterKeysService.ICD10); // } }, builder: (_, model, w) => AppScaffold( baseViewModel: model, isShowAppBar: false, body: SingleChildScrollView( child: Center( child: FractionallySizedBox( widthFactor: 0.9, child: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 16, ), AppText( "Add Assessment Details".toUpperCase(), fontWeight: FontWeight.bold, fontSize: 16, ), SizedBox( height: 16, ), Container( margin: EdgeInsets.only( left: 0, right: 0, top: 15), child: TextFields( hintText: "Appointment Number", fontSize: 13.5, // hintColor: Colors.black, fontWeight: FontWeight.w600, readOnly: true, controller: appointmentIdController, validator: (value) { if (value == null) return TranslationBase .of(context) .emptyMessage; else return null; }), ), SizedBox( height: 10, ), Container( height: screenSize.height * 0.070, child: InkWell( onTap: model.listOfICD10 != null ? () { setState(() { widget.mySelectedAssessment.selectedICD = null; }); } : null, child:widget.mySelectedAssessment.selectedICD == null ? AutoCompleteTextField( decoration: textFieldSelectorDecoration("Name or ICD", widget.mySelectedAssessment.selectedICD != null ? widget.mySelectedAssessment.selectedICD.nameEn : null, true,icon: EvaIcons.search), itemSubmitted: (item) => setState(() => widget.mySelectedAssessment.selectedICD = item), key: key, suggestions: model.listOfICD10, itemBuilder: (context, suggestion) => new Padding( child:Texts( suggestion.description +" / "+ suggestion.code.toString()), padding: EdgeInsets.all(8.0)), itemSorter: (a, b) => 1, itemFilter: (suggestion, input) => suggestion.description.toLowerCase().startsWith(input.toLowerCase()) ||suggestion.description.toLowerCase().startsWith(input.toLowerCase()) ||suggestion.code.toLowerCase().startsWith(input.toLowerCase()) , ): TextField( decoration: textFieldSelectorDecoration( widget.mySelectedAssessment.selectedICD != null ? widget.mySelectedAssessment.selectedICD.code :"Name or ICD", widget.mySelectedAssessment.selectedICD != null ? widget.mySelectedAssessment.selectedICD.nameEn : null, true,icon: EvaIcons.search), enabled: false, ), ), ), SizedBox( height: 10, ), Container( height: screenSize.height * 0.070, child: InkWell( onTap: model.listOfDiagnosisCondition != null ? () { MasterKeyDailog dialog = MasterKeyDailog( list: model.listOfDiagnosisCondition, okText: TranslationBase .of(context) .ok, okFunction: ( MasterKeyModel selectedValue) { setState(() { widget.mySelectedAssessment .selectedDiagnosisCondition = selectedValue; }); }, ); showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { return dialog; }, ); } : null, child: TextField( decoration: textFieldSelectorDecoration( "Condition", widget.mySelectedAssessment .selectedDiagnosisCondition != null ? widget.mySelectedAssessment .selectedDiagnosisCondition .nameEn : null, true), enabled: false, ), ), ), SizedBox( height: 10, ), Container( height: screenSize.height * 0.070, child: InkWell( onTap: model.listOfDiagnosisType != null ? () { MasterKeyDailog dialog = MasterKeyDailog( list: model.listOfDiagnosisType, okText: TranslationBase .of(context) .ok, okFunction: ( MasterKeyModel selectedValue) { setState(() { // _selectedDiagnosisType = // selectedValue; widget.mySelectedAssessment .selectedDiagnosisType = selectedValue; }); }, ); showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { return dialog; }, ); } : null, child: TextField( decoration: textFieldSelectorDecoration( "Type", widget.mySelectedAssessment .selectedDiagnosisType != null ? widget.mySelectedAssessment .selectedDiagnosisType.nameEn : null, true), enabled: false, ), ), ), SizedBox( height: 10, ), Container( margin: EdgeInsets.only( left: 0, right: 0, top: 15), child: TextFields( hintText: "Remarks", fontSize: 13.5, // hintColor: Colors.black, fontWeight: FontWeight.w600, maxLines: 18, minLines: 5, controller: remarkController, validator: (value) { if (value == null) return TranslationBase .of(context) .emptyMessage; else return null; }), ), SizedBox( height: 10, ), AppButton( title: "Add".toUpperCase(), onPressed: () { setState(() { widget.mySelectedAssessment.remark = remarkController.text; widget.mySelectedAssessment .appointmentId = int.parse( appointmentIdController.text); widget.addSelectedAssessment(); }); }, ), ])), ), ), ))), ); } }