You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/AlHabibMedicalService/E-Referral/search_for_referrals_page.dart

356 lines
17 KiB
Dart

import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/search_criteria_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/search_e_referral_request_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/all_habib_medical_services/e_referral_view_model.dart';
3 years ago
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/E-Referral/referral_details.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/medical/balance/new_text_Field.dart';
3 years ago
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
3 years ago
import 'package:diplomaticquarterapp/widgets/data_display/medical/doctor_card.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/errors/app_embedded_error.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
3 years ago
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
3 years ago
import 'package:provider/provider.dart';
import 'New_E_Referral/new_e_referral_step_one_page.dart';
import 'dialogs/select_country_ingo_Dialog.dart';
import 'dialogs/select_search_criteria_dialog.dart';
class SearchForReferralsPage extends StatefulWidget {
SearchForReferralsPage({Key key});
@override
_SearchForReferralsPageState createState() => _SearchForReferralsPageState();
}
class _SearchForReferralsPageState extends State<SearchForReferralsPage> {
TextEditingController _searchTextController = TextEditingController();
TextEditingController _mobileTextController = TextEditingController();
bool _isSubmitted = false;
dynamic _selectedCountry = {
"name": "Saudi Arabia",
"name_ar": "المملكة العربية السعودية",
"code": "+966",
"countryCode": "SA",
"pattern": "5xxxxxxxx",
"maxLength": 9
};
SearchCriteriaModel selectedCriteria = SearchCriteriaModel(
name: "Identification Number", nameAr: "رقم المحول", value: 1);
@override
Widget build(BuildContext context) {
3 years ago
ProjectViewModel projectViewModel = Provider.of(context);
return BaseView<EReferralViewModel>(
3 years ago
onModelReady: (model) async {
if (projectViewModel.isLogin) {
SearchEReferralRequestModel searchEReferralRequestModel =
new SearchEReferralRequestModel(
patientMobileNumber: (projectViewModel.user.outSA == 0
? "966"
: "971") +
projectViewModel.user.mobileNumber
.substring(1, projectViewModel.user.mobileNumber.length),
);
if (selectedCriteria.value == 1) {
searchEReferralRequestModel.identificationNo =
_searchTextController.text;
searchEReferralRequestModel.referralNumber = 0;
} else {
searchEReferralRequestModel.referralNumber =
int.parse(_searchTextController.text);
searchEReferralRequestModel.identificationNo =
projectViewModel.user.patientIdentificationNo;
}
await model.getEReferrals(searchEReferralRequestModel);
}
},
builder: (_, model, widget) => AppScaffold(
isShowAppBar: false,
3 years ago
baseViewModel: model,
body: SingleChildScrollView(
physics: ScrollPhysics(),
child: Container(
margin: EdgeInsets.all(12),
child: Center(
3 years ago
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 10,
),
InkWell(
onTap: () => selectSearchCriteriaDialog(),
child: Container(
padding: EdgeInsets.all(12),
width: double.infinity,
height: 65,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Texts(getSearchCriteriaName()),
Icon(Icons.arrow_drop_down)
],
),
),
3 years ago
),
SizedBox(
height: 12,
),
NewTextFields(
hintText: selectedCriteria.value == 1
? "Enter Patient Identification No"
: "Enter Referral Number",
controller: _searchTextController,
onChanged: (_) {
setState(() {});
},
),
SizedBox(
height: 12,
),
InkWell(
onTap: () => confirmSelectCountryTypeDialog(),
child: Container(
padding: EdgeInsets.all(12),
width: double.infinity,
height: 65,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Texts(getCountryName()),
Icon(Icons.arrow_drop_down)
],
),
),
3 years ago
),
SizedBox(
height: 12,
),
MobileNumberTextFiled(
controller: _mobileTextController,
onChange: (_) {
setState(() {});
},
code: _selectedCountry == null
? "11"
: _selectedCountry["code"],
),
SizedBox(
height: 12,
),
if ((model.state == ViewState.Idle &&
model.allReferral.length == 0))
Center(
child: Text(
TranslationBase.of(context).noSearchResult)),
if ((model.state == ViewState.ErrorLocal))
AppEmbeddedError(error: model.error),
model.allReferral.length > 0
? NetworkBaseView(
baseViewModel: model,
child: ListView.separated(
separatorBuilder: (context, index) =>
SizedBox(height: 0),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: model.allReferral == null
? 0
: model.allReferral.length,
itemBuilder: (BuildContext context, int index) {
return Container(
width: double.infinity,
child: InkWell(
onTap: () {
Navigator.push(
context,
FadePage(
page: ReferralDetails(
referral:
model.allReferral[index]),
),
);
},
child: Card(
shape: cardRadius(12),
margin: EdgeInsets.all(10),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
projectViewModel.isArabic
? model
.allReferral[
index]
.statusAr
: model
.allReferral[
index]
.status,
style: TextStyle(
fontSize: 14.0,
letterSpacing: -0.56,
fontWeight:
FontWeight.bold)),
Container(
margin: EdgeInsets.only(
top: 5.0),
child: myRichText(
TranslationBase.of(
context)
.patientName +
": ",
model
.allReferral[
index]
.patientName,
projectViewModel
.isArabic)),
myRichText(
TranslationBase.of(
context)
.hospital +
": ",
model.allReferral[index]
.preferredBranchName,
projectViewModel
.isArabic),
myRichText(
TranslationBase.of(
context)
.referralDate +
": ",
DateUtil.getMonthDayYearDateFormatted(
DateUtil.convertStringToDateNoTimeZone(
model
.allReferral[
index]
.referralDate)),
projectViewModel
.isArabic),
],
),
Icon(projectViewModel.isArabic
? Icons
.arrow_back_ios_outlined
: Icons
.arrow_forward_ios_outlined),
],
),
),
),
),
);
},
),
)
: Container(),
SizedBox(
height: 80.0,
)
],
),
),
),
),
bottomSheet: Container(
3 years ago
color: Theme.of(context).scaffoldBackgroundColor,
width: double.infinity,
3 years ago
padding: EdgeInsets.all(14),
child: DefaultButton(
TranslationBase.of(context).search,
(_searchTextController.text.isEmpty ||
_mobileTextController.text.isEmpty)
? null
: () async {
SearchEReferralRequestModel
searchEReferralRequestModel =
new SearchEReferralRequestModel(
patientMobileNumber: _selectedCountry['code'] +
_mobileTextController.text,
);
if (selectedCriteria.value == 1) {
searchEReferralRequestModel.identificationNo =
_searchTextController.text;
searchEReferralRequestModel.referralNumber = 0;
} else {
searchEReferralRequestModel.referralNumber =
int.parse(_searchTextController.text);
searchEReferralRequestModel.identificationNo = '';
}
await model.getEReferrals(searchEReferralRequestModel);
setState(() {
_isSubmitted = true;
});
},
disabledColor: Colors.grey,
),
)));
}
void confirmSelectCountryTypeDialog() {
showDialog(
context: context,
child: SelectCountryDialog(
selectedCountry: _selectedCountry,
onValueSelected: (value) {
setState(() {
_selectedCountry = value;
});
},
),
);
}
String getCountryName() {
if (_selectedCountry != null)
return _selectedCountry["name"];
else
return "Country";
}
void selectSearchCriteriaDialog() {
showDialog(
context: context,
child: SelectSearchCriteriaDialog(
selectedCriteria: selectedCriteria,
onValueSelected: (value) {
setState(() {
selectedCriteria = value;
});
},
),
);
}
String getSearchCriteriaName() {
return selectedCriteria.name;
}
}