diff --git a/lib/features/prescriptions/prescriptions_repo.dart b/lib/features/prescriptions/prescriptions_repo.dart index f35c705..e7a4f07 100644 --- a/lib/features/prescriptions/prescriptions_repo.dart +++ b/lib/features/prescriptions/prescriptions_repo.dart @@ -5,6 +5,7 @@ import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart'; import 'package:dartz/dartz.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/patient_prescriptions_response_model.dart'; +import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/prescription_delivery_response_model.dart'; import 'package:hmg_patient_app_new/features/prescriptions/models/resp_models/prescription_detail_response_model.dart'; import 'package:hmg_patient_app_new/services/logger_service.dart'; @@ -272,11 +273,14 @@ class PrescriptionsRepoImp implements PrescriptionsRepo { }, onSuccess: (response, statusCode, {messageStatus, errorMessage}) { try { + + final prescriptionOrders = response['response'].map((item) => PrescriptionDeliveryResponseModel.fromJson(item as Map)).toList().cast(); + apiResponse = GenericApiModel( messageStatus: messageStatus, statusCode: statusCode, errorMessage: null, - data: response, + data: prescriptionOrders, ); } catch (e) { failure = DataParsingFailure(e.toString()); diff --git a/lib/features/prescriptions/prescriptions_view_model.dart b/lib/features/prescriptions/prescriptions_view_model.dart index 186ecc8..693b727 100644 --- a/lib/features/prescriptions/prescriptions_view_model.dart +++ b/lib/features/prescriptions/prescriptions_view_model.dart @@ -252,6 +252,7 @@ class PrescriptionsViewModel extends ChangeNotifier { } Future getPrescriptionOrdersList({Function(dynamic)? onSuccess, Function(String)? onError}) async { + isPrescriptionsDeliveryOrdersLoading = true; prescriptionsOrderList.clear(); notifyListeners(); @@ -270,6 +271,7 @@ class PrescriptionsViewModel extends ChangeNotifier { onError!(apiResponse.errorMessage!); } else if (apiResponse.messageStatus == 1) { isPrescriptionsDeliveryOrdersLoading = false; + prescriptionsOrderList = apiResponse.data!; notifyListeners(); if (onSuccess != null) { onSuccess(apiResponse); diff --git a/lib/presentation/prescriptions/prescription_delivery_orders_list_page.dart b/lib/presentation/prescriptions/prescription_delivery_orders_list_page.dart index a2bfa8e..9f2b2a2 100644 --- a/lib/presentation/prescriptions/prescription_delivery_orders_list_page.dart +++ b/lib/presentation/prescriptions/prescription_delivery_orders_list_page.dart @@ -1,15 +1,19 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; +import 'package:hmg_patient_app_new/core/app_assets.dart'; +import 'package:hmg_patient_app_new/core/utils/date_util.dart'; import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/prescriptions/prescriptions_view_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; +import 'package:hmg_patient_app_new/presentation/emergency_services/history/widget/RequestStatus.dart'; import 'package:hmg_patient_app_new/presentation/lab/lab_result_item_view.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; +import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart'; import 'package:provider/provider.dart'; class PrescriptionDeliveryOrdersListPage extends StatelessWidget { @@ -26,10 +30,10 @@ class PrescriptionDeliveryOrdersListPage extends StatelessWidget { return Column( children: [ ListView.builder( - itemCount: model.isPrescriptionsOrdersLoading + itemCount: model.isPrescriptionsDeliveryOrdersLoading ? 4 - : model.patientPrescriptionOrders.isNotEmpty - ? model.patientPrescriptionOrdersViewList.length + : model.prescriptionsOrderList.isNotEmpty + ? model.prescriptionsOrderList.length : 1, physics: NeverScrollableScrollPhysics(), shrinkWrap: true, @@ -56,9 +60,6 @@ class PrescriptionDeliveryOrdersListPage extends StatelessWidget { decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 20.h, hasShadow: true), child: InkWell( onTap: () { - // setState(() { - // expandedIndex = isExpanded ? null : index; - // }); }, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -67,177 +68,20 @@ class PrescriptionDeliveryOrdersListPage extends StatelessWidget { padding: EdgeInsets.all(16.h), child: Column( crossAxisAlignment: CrossAxisAlignment.start, + spacing: 8.h, children: [ + RequestStatus(status: model.prescriptionsOrderList[index].statusId ?? 0), + "Req ID: ${model.prescriptionsOrderList[index].iD}".toText16(color: AppColors.textColor, weight: FontWeight.w600), Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + spacing: 4.w, children: [ - // CustomButton( - // text: "${model.patientPrescriptionOrdersViewList[index].prescriptionsList!.length} Prescriptions Available", - // onPressed: () {}, - // backgroundColor: AppColors.greyColor, - // borderColor: AppColors.greyColor, - // textColor: AppColors.blackColor, - // fontSize: 10, - // fontWeight: FontWeight.w500, - // borderRadius: 8, - // padding: EdgeInsets.fromLTRB(10, 0, 10, 0), - // height: 30.h, - // ), - // Icon(isExpanded ? Icons.expand_less : Icons.expand_more), + chip(Utils.getDayMonthYearDateFormatted(DateTime.tryParse(model.prescriptionsOrderList[index].created!)), AppAssets.calendar, + AppColors.blackBgColor), ], ), - SizedBox(height: 8.h), - // model.patientPrescriptionOrdersViewList[index].filterName!.toText16(isBold: true) ], ), ), - // AnimatedSwitcher( - // duration: Duration(milliseconds: 500), - // switchInCurve: Curves.easeIn, - // switchOutCurve: Curves.easeOut, - // transitionBuilder: (Widget child, Animation animation) { - // return FadeTransition( - // opacity: animation, - // child: SizeTransition( - // sizeFactor: animation, - // axisAlignment: 0.0, - // child: child, - // ), - // ); - // }, - // child: isExpanded - // ? Container( - // key: ValueKey(index), - // padding: EdgeInsets.symmetric(horizontal: 16.h, vertical: 8.h), - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ...model.patientPrescriptionOrdersViewList[index].prescriptionsList!.map((prescription) { - // return Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Row( - // mainAxisSize: MainAxisSize.min, - // children: [ - // Image.network( - // prescription.doctorImageURL!, - // width: 24.h, - // height: 24.h, - // fit: BoxFit.fill, - // ).circle(100), - // SizedBox(width: 8.h), - // Expanded(child: prescription.doctorName!.toText14(weight: FontWeight.w500)), - // ], - // ), - // SizedBox(height: 8.h), - // Row( - // children: [ - // CustomButton( - // text: DateUtil.formatDateToDate(DateUtil.convertStringToDate(prescription.appointmentDate), false), - // onPressed: () {}, - // backgroundColor: AppColors.greyColor, - // borderColor: AppColors.greyColor, - // textColor: AppColors.blackColor, - // fontSize: 10, - // fontWeight: FontWeight.w500, - // borderRadius: 8, - // padding: EdgeInsets.fromLTRB(10, 0, 10, 0), - // height: 24.h, - // ), - // SizedBox(width: 8.h), - // CustomButton( - // text: model.isSortByClinic ? prescription.name! : prescription.clinicDescription!, - // onPressed: () {}, - // backgroundColor: AppColors.greyColor, - // borderColor: AppColors.greyColor, - // textColor: AppColors.blackColor, - // fontSize: 10, - // fontWeight: FontWeight.w500, - // borderRadius: 8, - // padding: EdgeInsets.fromLTRB(10, 0, 10, 0), - // height: 24.h, - // ), - // ], - // ), - // SizedBox(height: 8.h), - // Row( - // children: [ - // Expanded( - // flex: 6, - // child: CustomButton( - // text: prescription.isHomeMedicineDeliverySupported! - // ? LocaleKeys.resendOrder.tr(context: context) - // : LocaleKeys.prescriptionDeliveryError.tr(context: context), - // onPressed: () async { - // if (prescription.isHomeMedicineDeliverySupported!) { - // LoaderBottomSheet.showLoader(loadingText: "Fetching prescription details...".needTranslation); - // await prescriptionsViewModel.getPrescriptionDetails(prescriptionsViewModel.patientPrescriptionOrders[index], - // onSuccess: (val) { - // LoaderBottomSheet.hideLoader(); - // prescriptionsViewModel.initiatePrescriptionDelivery(); - // }); - // } - // }, - // backgroundColor: - // prescription.isHomeMedicineDeliverySupported! ? AppColors.successColor.withOpacity(0.15) : AppColors.greyF7Color, - // borderColor: AppColors.successColor.withOpacity(0.01), - // textColor: prescription.isHomeMedicineDeliverySupported! ? AppColors.successColor : AppColors.textColor.withOpacity(0.35), - // fontSize: prescription.isHomeMedicineDeliverySupported! ? 14 : 12, - // fontWeight: FontWeight.w500, - // borderRadius: 12, - // padding: EdgeInsets.fromLTRB(10, 0, 10, 0), - // height: 40.h, - // icon: AppAssets.prescription_refill_icon, - // iconColor: prescription.isHomeMedicineDeliverySupported! ? AppColors.successColor : AppColors.textColor.withOpacity(0.35), - // iconSize: 14.h, - // ), - // ), - // SizedBox(width: 8.h), - // Expanded( - // flex: 1, - // child: Container( - // height: 40.h, - // width: 40.w, - // decoration: RoundedRectangleBorder().toSmoothCornerDecoration( - // color: AppColors.textColor, - // borderRadius: 12, - // ), - // child: Padding( - // padding: EdgeInsets.all(12.h), - // child: Transform.flip( - // flipX: appState.isArabic(), - // child: Utils.buildSvgWithAssets( - // icon: AppAssets.forward_arrow_icon_small, - // iconColor: AppColors.whiteColor, - // fit: BoxFit.contain, - // ), - // ), - // ), - // ).onPress(() { - // model.setPrescriptionsDetailsLoading(); - // Navigator.of(context).push( - // CustomPageRoute( - // page: PrescriptionDetailPage( - // prescriptionsResponseModel: prescription, - // isFromAppointments: false, - // ), - // ), - // ); - // }), - // ), - // ], - // ), - // SizedBox(height: 12.h), - // Divider(color: AppColors.borderOnlyColor.withValues(alpha: 0.05), height: 1.h), - // SizedBox(height: 12.h), - // ], - // ); - // }).toList(), - // ], - // ), - // ) - // : SizedBox.shrink(), - // ), ], ), ), @@ -255,4 +99,13 @@ class PrescriptionDeliveryOrdersListPage extends StatelessWidget { ), ); } + + chip(String title, String iconString, Color iconColor) { + return AppCustomChipWidget( + labelText: title, + icon: iconString, + iconColor: iconColor, + iconSize: 12.h, + ); + } }