add pagination on in patient

replay_status
Elham Rababh 4 years ago
parent a014e0140d
commit 1fd192e4bc

@ -14,26 +14,37 @@ import 'base_view_model.dart';
class PatientSearchViewModel extends BaseViewModel {
OutPatientService _outPatientService = locator<OutPatientService>();
SpecialClinicsService _specialClinicsService = locator<SpecialClinicsService>();
SpecialClinicsService _specialClinicsService =
locator<SpecialClinicsService>();
List<PatiantInformtion> get patientList => _outPatientService.patientList;
List<GetSpecialClinicalCareMappingListResponseModel> get specialClinicalCareMappingList =>
_specialClinicsService.specialClinicalCareMappingList;
List<GetSpecialClinicalCareMappingListResponseModel>
get specialClinicalCareMappingList =>
_specialClinicsService.specialClinicalCareMappingList;
List<PatiantInformtion> filterData = [];
DateTime selectedFromDate;
DateTime selectedToDate;
int firstSubsetIndex = 0;
int inPatientPageSize = 20;
int lastSubsetIndex = 19;
searchData(String str) {
var strExist = str.length > 0 ? true : false;
if (strExist) {
filterData = [];
for (var i = 0; i < _outPatientService.patientList.length; i++) {
String firstName = _outPatientService.patientList[i].firstName.toUpperCase();
String lastName = _outPatientService.patientList[i].lastName.toUpperCase();
String mobile = _outPatientService.patientList[i].mobileNumber.toUpperCase();
String patientID = _outPatientService.patientList[i].patientId.toString();
String firstName =
_outPatientService.patientList[i].firstName.toUpperCase();
String lastName =
_outPatientService.patientList[i].lastName.toUpperCase();
String mobile =
_outPatientService.patientList[i].mobileNumber.toUpperCase();
String patientID =
_outPatientService.patientList[i].patientId.toString();
if (firstName.contains(str.toUpperCase()) ||
lastName.contains(str.toUpperCase()) ||
@ -49,7 +60,8 @@ class PatientSearchViewModel extends BaseViewModel {
}
}
getOutPatient(PatientSearchRequestModel patientSearchRequestModel, {bool isLocalBusy = false}) async {
getOutPatient(PatientSearchRequestModel patientSearchRequestModel,
{bool isLocalBusy = false}) async {
if (isLocalBusy) {
setState(ViewState.BusyLocal);
} else {
@ -81,9 +93,11 @@ class PatientSearchViewModel extends BaseViewModel {
setState(ViewState.Idle);
}
getPatientFileInformation(PatientSearchRequestModel patientSearchRequestModel, {bool isLocalBusy = false}) async {
getPatientFileInformation(PatientSearchRequestModel patientSearchRequestModel,
{bool isLocalBusy = false}) async {
setState(ViewState.Busy);
await _outPatientService.getPatientFileInformation(patientSearchRequestModel);
await _outPatientService
.getPatientFileInformation(patientSearchRequestModel);
if (_outPatientService.hasError) {
error = _outPatientService.error;
setState(ViewState.Error);
@ -102,21 +116,32 @@ class PatientSearchViewModel extends BaseViewModel {
String dateTo;
String dateFrom;
if (OutPatientFilterType.Previous == outPatientFilterType) {
selectedFromDate = DateTime(DateTime.now().year, DateTime.now().month - 1, DateTime.now().day);
selectedToDate = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day - 1);
selectedFromDate = DateTime(
DateTime.now().year, DateTime.now().month - 1, DateTime.now().day);
selectedToDate = DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day - 1);
dateTo = AppDateUtils.convertDateToFormat(selectedToDate, 'yyyy-MM-dd');
dateFrom = AppDateUtils.convertDateToFormat(selectedFromDate, 'yyyy-MM-dd');
dateFrom =
AppDateUtils.convertDateToFormat(selectedFromDate, 'yyyy-MM-dd');
} else if (OutPatientFilterType.NextWeek == outPatientFilterType) {
dateTo = AppDateUtils.convertDateToFormat(
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 6), 'yyyy-MM-dd');
DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day + 6),
'yyyy-MM-dd');
dateFrom = AppDateUtils.convertDateToFormat(
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day + 1), 'yyyy-MM-dd');
DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day + 1),
'yyyy-MM-dd');
} else {
dateFrom = AppDateUtils.convertDateToFormat(
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day), 'yyyy-MM-dd');
DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day),
'yyyy-MM-dd');
dateTo = AppDateUtils.convertDateToFormat(
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day), 'yyyy-MM-dd');
DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day),
'yyyy-MM-dd');
}
PatientSearchRequestModel currentModel = PatientSearchRequestModel();
currentModel.patientID = patientSearchRequestModel.patientID;
@ -130,11 +155,13 @@ class PatientSearchViewModel extends BaseViewModel {
filterData = _outPatientService.patientList;
}
PatientInPatientService _inPatientService = locator<PatientInPatientService>();
PatientInPatientService _inPatientService =
locator<PatientInPatientService>();
List<PatiantInformtion> get inPatientList => _inPatientService.inPatientList;
List<PatiantInformtion> get myIinPatientList => _inPatientService.myInPatientList;
List<PatiantInformtion> get myIinPatientList =>
_inPatientService.myInPatientList;
List<PatiantInformtion> filteredInPatientItems = List();
@ -146,7 +173,8 @@ class PatientSearchViewModel extends BaseViewModel {
} else {
setState(ViewState.Busy);
}
if (inPatientList.length == 0) await _inPatientService.getInPatientList(requestModel, false);
if (inPatientList.length == 0)
await _inPatientService.getInPatientList(requestModel, false);
if (_inPatientService.hasError) {
error = _inPatientService.error;
if (isLocalBusy) {
@ -163,10 +191,12 @@ class PatientSearchViewModel extends BaseViewModel {
sortInPatient({bool isDes = false}) {
if (isDes)
filteredInPatientItems.sort((PatiantInformtion a, PatiantInformtion b) =>
b.admissionDateWithDateTimeForm.compareTo(a.admissionDateWithDateTimeForm));
b.admissionDateWithDateTimeForm
.compareTo(a.admissionDateWithDateTimeForm));
else
filteredInPatientItems.sort((PatiantInformtion a, PatiantInformtion b) =>
a.admissionDateWithDateTimeForm.compareTo(b.admissionDateWithDateTimeForm));
a.admissionDateWithDateTimeForm
.compareTo(b.admissionDateWithDateTimeForm));
setState(ViewState.Idle);
}
@ -174,10 +204,30 @@ class PatientSearchViewModel extends BaseViewModel {
setState(ViewState.BusyLocal);
await getDoctorProfile();
filteredInPatientItems.clear();
if (inPatientList.length > 0) filteredInPatientItems.addAll(inPatientList);
firstSubsetIndex = 0;
lastSubsetIndex = inPatientPageSize - 1;
if (inPatientList.length > 0)
filteredInPatientItems
.addAll(inPatientList.sublist(firstSubsetIndex, lastSubsetIndex));
setState(ViewState.Idle);
}
addOnFilteredList() {
if (lastSubsetIndex < inPatientList.length) {
firstSubsetIndex = firstSubsetIndex +
(inPatientList.length - lastSubsetIndex < inPatientPageSize - 1
? inPatientList.length - lastSubsetIndex
: inPatientPageSize - 1);
lastSubsetIndex = lastSubsetIndex +
(inPatientList.length - lastSubsetIndex < inPatientPageSize - 1
? inPatientList.length - lastSubsetIndex
: inPatientPageSize - 1);
filteredInPatientItems
.addAll(inPatientList.sublist(firstSubsetIndex, lastSubsetIndex));
setState(ViewState.Idle);
}
}
void clearPatientList() {
_inPatientService.inPatientList = [];
_inPatientService.myInPatientList = [];
@ -208,7 +258,8 @@ class PatientSearchViewModel extends BaseViewModel {
}
}
getSpecialClinicalCareMappingList(clinicId, {bool isLocalBusy = false}) async {
getSpecialClinicalCareMappingList(clinicId,
{bool isLocalBusy = false}) async {
if (isLocalBusy) {
setState(ViewState.BusyLocal);
} else {

@ -12,7 +12,7 @@ import 'package:doctor_app_flutter/screens/home/dashboard_swipe_widget.dart';
import 'package:doctor_app_flutter/screens/home/home_patient_card.dart';
import 'package:doctor_app_flutter/screens/live_care/live_care_patient_screen.dart';
import 'package:doctor_app_flutter/screens/medicine/medicine_search_screen.dart';
import 'package:doctor_app_flutter/screens/patients/PatientsInPatientScreen.dart';
import 'package:doctor_app_flutter/screens/patients/In_patient/in_patient_screen.dart';
import 'package:doctor_app_flutter/screens/patients/out_patient/out_patient_screen.dart';
import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_screen.dart';
import 'package:doctor_app_flutter/screens/patients/profile/referral/patient_referral_screen.dart';
@ -371,7 +371,7 @@ class _HomeScreenState extends State<HomeScreen> {
Navigator.push(
context,
FadePage(
page: PatientInPatientScreen(
page: InPatientScreen(
specialClinic: model.getSpecialClinic(
clinicId ?? projectsProvider.doctorClinicsList[0].clinicID),
),

@ -1,252 +0,0 @@
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/patient_card/PatientCard.dart';
import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/errors/error_message.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_container.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../routes.dart';
class InPatientPage extends StatefulWidget {
final bool isMyInPatient;
final PatientSearchViewModel patientSearchViewModel;
InPatientPage(this.isMyInPatient, this.patientSearchViewModel);
@override
_InPatientPageState createState() => _InPatientPageState();
}
class _InPatientPageState extends State<InPatientPage> {
TextEditingController _searchController = TextEditingController();
bool isSortDes = false;
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AppScaffold(
baseViewModel: widget.patientSearchViewModel,
isShowAppBar: false,
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.070,
),
Container(
margin: EdgeInsets.all(16.0),
child: Stack(
children: [
AppTextFieldCustom(
hintText: TranslationBase.of(context).searchPatientName,
isTextFieldHasSuffix: true,
suffixIcon: IconButton(
icon: Icon(
Icons.search,
color: Colors.black,
),
onPressed: () {},
),
controller: _searchController,
onChanged: (value) {
widget.patientSearchViewModel.filterSearchResults(value);
}),
Positioned(
right: 35,
top: 5,
child: IconButton(
icon: Icon(
isSortDes
? FontAwesomeIcons.sortAmountDown
: FontAwesomeIcons.sortAmountUp,
color: Colors.black,
),
iconSize: 20,
// padding: EdgeInsets.only(bottom: 30),
onPressed: () {
GifLoaderDialogUtils.showMyDialog(context);
widget.patientSearchViewModel
.sortInPatient(isDes: isSortDes);
isSortDes = !isSortDes;
GifLoaderDialogUtils.hideDialog(context);
},
),
)
],
),
),
widget.patientSearchViewModel.state == ViewState.Idle
? widget.patientSearchViewModel.filteredInPatientItems.length > 0
? (widget.isMyInPatient &&
widget.patientSearchViewModel.myIinPatientList
.length ==
0)
? NoData()
: Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListView.builder(
itemCount: widget.patientSearchViewModel
.filteredInPatientItems.length,
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, index) {
if (!widget.isMyInPatient)
return PatientCard(
patientInfo: widget
.patientSearchViewModel
.filteredInPatientItems[index],
patientType: "1",
arrivalType: "1",
isInpatient: true,
isMyPatient: widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget.patientSearchViewModel
.doctorProfile.doctorID,
onTap: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus
.hasPrimaryFocus) {
currentFocus.unfocus();
}
Navigator.of(context).pushNamed(
PATIENTS_PROFILE,
arguments: {
"patient": widget
.patientSearchViewModel
.filteredInPatientItems[index],
"patientType": "1",
"from": "0",
"to": "0",
"isSearch": false,
"isInpatient": true,
"arrivalType": "1",
"isMyPatient": widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget
.patientSearchViewModel
.doctorProfile
.doctorID,
});
},
);
else if (widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget.patientSearchViewModel
.doctorProfile.doctorID &&
widget.isMyInPatient)
return PatientCard(
patientInfo: widget
.patientSearchViewModel
.filteredInPatientItems[index],
patientType: "1",
arrivalType: "1",
isInpatient: true,
isMyPatient: widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget.patientSearchViewModel
.doctorProfile.doctorID,
onTap: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus
.hasPrimaryFocus) {
currentFocus.unfocus();
}
Navigator.of(context).pushNamed(
PATIENTS_PROFILE,
arguments: {
"patient": widget
.patientSearchViewModel
.filteredInPatientItems[index],
"patientType": "1",
"from": "0",
"to": "0",
"isSearch": false,
"isInpatient": true,
"arrivalType": "1",
"isMyPatient": widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget
.patientSearchViewModel
.doctorProfile
.doctorID,
});
},
);
else
return SizedBox();
}),
SizedBox(
height: 15,
)
],
),
),
),
)
: NoData()
: Center(
child: Container(
height: 300,
width: 300,
),
),
],
),
);
}
}
class NoData extends StatelessWidget {
const NoData({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Expanded(
child: SingleChildScrollView(
child: Container(
child: ErrorMessage(
error: TranslationBase.of(context).noDataAvailable)),
),
);
}
}

@ -0,0 +1,250 @@
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/patient_card/PatientCard.dart';
import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/errors/error_message.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_container.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../../routes.dart';
class InPatientListPage extends StatefulWidget {
final bool isMyInPatient;
final PatientSearchViewModel patientSearchViewModel;
InPatientListPage(this.isMyInPatient, this.patientSearchViewModel);
@override
_InPatientListPageState createState() => _InPatientListPageState();
}
class _InPatientListPageState extends State<InPatientListPage> {
TextEditingController _searchController = TextEditingController();
bool isSortDes = false;
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AppScaffold(
baseViewModel: widget.patientSearchViewModel,
isShowAppBar: false,
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.070,
),
Container(
margin: EdgeInsets.all(16.0),
child: Stack(
children: [
AppTextFieldCustom(
hintText: TranslationBase.of(context).searchPatientName,
isTextFieldHasSuffix: true,
suffixIcon: IconButton(
icon: Icon(
Icons.search,
color: Colors.black,
),
onPressed: () {},
),
controller: _searchController,
onChanged: (value) {
widget.patientSearchViewModel.filterSearchResults(value);
}),
Positioned(
right: 35,
top: 5,
child: IconButton(
icon: Icon(
isSortDes
? FontAwesomeIcons.sortAmountDown
: FontAwesomeIcons.sortAmountUp,
color: Colors.black,
),
iconSize: 20,
// padding: EdgeInsets.only(bottom: 30),
onPressed: () {
GifLoaderDialogUtils.showMyDialog(context);
widget.patientSearchViewModel
.sortInPatient(isDes: isSortDes);
isSortDes = !isSortDes;
GifLoaderDialogUtils.hideDialog(context);
},
),
)
],
),
),
widget.patientSearchViewModel.state == ViewState.Idle
? widget.patientSearchViewModel.filteredInPatientItems.length > 0
? (widget.isMyInPatient &&
widget.patientSearchViewModel.myIinPatientList
.length ==
0)
? NoData()
: Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 16.0),
child: NotificationListener(
child: ListView.builder(
itemCount: widget.patientSearchViewModel
.filteredInPatientItems.length,
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, index) {
if (!widget.isMyInPatient)
return PatientCard(
patientInfo: widget
.patientSearchViewModel
.filteredInPatientItems[index],
patientType: "1",
arrivalType: "1",
isInpatient: true,
isMyPatient: widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget.patientSearchViewModel
.doctorProfile.doctorID,
onTap: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus
.hasPrimaryFocus) {
currentFocus.unfocus();
}
Navigator.of(context).pushNamed(
PATIENTS_PROFILE,
arguments: {
"patient": widget
.patientSearchViewModel
.filteredInPatientItems[index],
"patientType": "1",
"from": "0",
"to": "0",
"isSearch": false,
"isInpatient": true,
"arrivalType": "1",
"isMyPatient": widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget
.patientSearchViewModel
.doctorProfile
.doctorID,
});
},
);
else if (widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget.patientSearchViewModel
.doctorProfile.doctorID &&
widget.isMyInPatient)
return PatientCard(
patientInfo: widget
.patientSearchViewModel
.filteredInPatientItems[index],
patientType: "1",
arrivalType: "1",
isInpatient: true,
isMyPatient: widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget.patientSearchViewModel
.doctorProfile.doctorID,
onTap: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus
.hasPrimaryFocus) {
currentFocus.unfocus();
}
Navigator.of(context).pushNamed(
PATIENTS_PROFILE,
arguments: {
"patient": widget
.patientSearchViewModel
.filteredInPatientItems[index],
"patientType": "1",
"from": "0",
"to": "0",
"isSearch": false,
"isInpatient": true,
"arrivalType": "1",
"isMyPatient": widget
.patientSearchViewModel
.filteredInPatientItems[
index]
.doctorId ==
widget
.patientSearchViewModel
.doctorProfile
.doctorID,
});
},
);
else
return SizedBox();
}),
onNotification: (t) {
if (t is ScrollUpdateNotification && t.metrics.pixels >= t.metrics.maxScrollExtent - 50 ) {
widget.patientSearchViewModel.addOnFilteredList();
}
return;
},
),
),
)
: NoData()
: Center(
child: Container(
height: 300,
width: 300,
),
),
],
),
);
}
}
class NoData extends StatelessWidget {
const NoData({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Expanded(
child: SingleChildScrollView(
child: Container(
child: ErrorMessage(
error: TranslationBase.of(context).noDataAvailable)),
),
);
}
}

@ -14,19 +14,19 @@ import 'package:doctor_app_flutter/widgets/shared/text_fields/text_fields_utils.
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'DischargedPatientPage.dart';
import 'InPatientPage.dart';
import '../DischargedPatientPage.dart';
import 'in_patient_list_page.dart';
class PatientInPatientScreen extends StatefulWidget {
class InPatientScreen extends StatefulWidget {
GetSpecialClinicalCareListResponseModel specialClinic;
PatientInPatientScreen({Key key, this.specialClinic});
InPatientScreen({Key key, this.specialClinic});
@override
_PatientInPatientScreenState createState() => _PatientInPatientScreenState();
_InPatientScreenState createState() => _InPatientScreenState();
}
class _PatientInPatientScreenState extends State<PatientInPatientScreen>
class _InPatientScreenState extends State<InPatientScreen>
with SingleTickerProviderStateMixin {
TabController _tabController;
int _activeTab = 0;
@ -266,8 +266,8 @@ class _PatientInPatientScreenState extends State<PatientInPatientScreen>
physics: BouncingScrollPhysics(),
controller: _tabController,
children: [
InPatientPage(false, model),
InPatientPage(true,model),
InPatientListPage(false, model),
InPatientListPage(true,model),
DischargedPatient(),
],
),
Loading…
Cancel
Save