RRT Services implementation contd.
							parent
							
								
									5505f549fc
								
							
						
					
					
						commit
						1f7a941aa0
					
				
											
												
													File diff suppressed because one or more lines are too long
												
											
										
									
								
											
												
													File diff suppressed because one or more lines are too long
												
											
										
									
								
											
												
													File diff suppressed because one or more lines are too long
												
											
										
									
								| @ -0,0 +1,55 @@ | ||||
| import 'package:dartz/dartz.dart'; | ||||
| import 'package:hmg_patient_app_new/core/api/api_client.dart'; | ||||
| import 'package:hmg_patient_app_new/core/api_consts.dart'; | ||||
| import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart'; | ||||
| import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart'; | ||||
| import 'package:hmg_patient_app_new/features/emergency_services/models/resp_models/rrt_procedures_response_model.dart'; | ||||
| import 'package:hmg_patient_app_new/services/logger_service.dart'; | ||||
| 
 | ||||
| abstract class EmergencyServicesRepo { | ||||
|   Future<Either<Failure, GenericApiModel<List<RRTProceduresResponseModel>>>> getRRTProcedures(); | ||||
| } | ||||
| 
 | ||||
| class EmergencyServicesRepoImp implements EmergencyServicesRepo { | ||||
|   final ApiClient apiClient; | ||||
|   final LoggerService loggerService; | ||||
| 
 | ||||
|   EmergencyServicesRepoImp({required this.loggerService, required this.apiClient}); | ||||
| 
 | ||||
|   @override | ||||
|   Future<Either<Failure, GenericApiModel<List<RRTProceduresResponseModel>>>> getRRTProcedures() async { | ||||
|     Map<String, dynamic> mapDevice = {}; | ||||
| 
 | ||||
|     try { | ||||
|       GenericApiModel<List<RRTProceduresResponseModel>>? apiResponse; | ||||
|       Failure? failure; | ||||
|       await apiClient.post( | ||||
|         GET_RRT_PROCEDURE_LIST, | ||||
|         body: mapDevice, | ||||
|         onFailure: (error, statusCode, {messageStatus, failureType}) { | ||||
|           failure = failureType; | ||||
|         }, | ||||
|         onSuccess: (response, statusCode, {messageStatus, errorMessage}) { | ||||
|           try { | ||||
|             final list = response['Vida_ProcedureList']; | ||||
|             final proceduresList = list.map((item) => RRTProceduresResponseModel.fromJson(item as Map<String, dynamic>)).toList().cast<RRTProceduresResponseModel>(); | ||||
| 
 | ||||
|             apiResponse = GenericApiModel<List<RRTProceduresResponseModel>>( | ||||
|               messageStatus: messageStatus, | ||||
|               statusCode: statusCode, | ||||
|               errorMessage: null, | ||||
|               data: proceduresList, | ||||
|             ); | ||||
|           } catch (e) { | ||||
|             failure = DataParsingFailure(e.toString()); | ||||
|           } | ||||
|         }, | ||||
|       ); | ||||
|       if (failure != null) return Left(failure!); | ||||
|       if (apiResponse == null) return Left(ServerFailure("Unknown error")); | ||||
|       return Right(apiResponse!); | ||||
|     } catch (e) { | ||||
|       return Left(UnknownFailure(e.toString())); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,43 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:hmg_patient_app_new/features/emergency_services/emergency_services_repo.dart'; | ||||
| import 'package:hmg_patient_app_new/features/emergency_services/models/resp_models/rrt_procedures_response_model.dart'; | ||||
| import 'package:hmg_patient_app_new/services/error_handler_service.dart'; | ||||
| 
 | ||||
| class EmergencyServicesViewModel extends ChangeNotifier { | ||||
|   EmergencyServicesRepo emergencyServicesRepo; | ||||
|   ErrorHandlerService errorHandlerService; | ||||
| 
 | ||||
|   List<RRTProceduresResponseModel> RRTProceduresList = []; | ||||
| 
 | ||||
|   late RRTProceduresResponseModel selectedRRTProcedure; | ||||
| 
 | ||||
|   setSelectedRRTProcedure(RRTProceduresResponseModel procedure) { | ||||
|     selectedRRTProcedure = procedure; | ||||
|     notifyListeners(); | ||||
|   } | ||||
| 
 | ||||
|   EmergencyServicesViewModel({required this.emergencyServicesRepo, required this.errorHandlerService}); | ||||
| 
 | ||||
|   Future<void> getRRTProcedures({Function(dynamic)? onSuccess, Function(String)? onError}) async { | ||||
|     RRTProceduresList.clear(); | ||||
|     notifyListeners(); | ||||
| 
 | ||||
|     final result = await emergencyServicesRepo.getRRTProcedures(); | ||||
| 
 | ||||
|     result.fold( | ||||
|       (failure) async => await errorHandlerService.handleError(failure: failure), | ||||
|       (apiResponse) { | ||||
|         if (apiResponse.messageStatus == 2) { | ||||
|           // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); | ||||
|         } else if (apiResponse.messageStatus == 1) { | ||||
|           RRTProceduresList = apiResponse.data!; | ||||
|           selectedRRTProcedure = RRTProceduresList.first; | ||||
|           notifyListeners(); | ||||
|           if (onSuccess != null) { | ||||
|             onSuccess(apiResponse); | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| class RRTProceduresResponseModel { | ||||
|   num? patientShare; | ||||
|   num? patientShareWithTax; | ||||
|   num? patientTaxAmount; | ||||
|   String? procedureID; | ||||
|   String? procedureName; | ||||
| 
 | ||||
|   RRTProceduresResponseModel({this.patientShare, this.patientShareWithTax, this.patientTaxAmount, this.procedureID, this.procedureName}); | ||||
| 
 | ||||
|   RRTProceduresResponseModel.fromJson(Map<String, dynamic> json) { | ||||
|     patientShare = json['PatientShare']; | ||||
|     patientShareWithTax = json['PatientShareWithTax']; | ||||
|     patientTaxAmount = json['PatientTaxAmount']; | ||||
|     procedureID = json['ProcedureID']; | ||||
|     procedureName = json['ProcedureName']; | ||||
|   } | ||||
| 
 | ||||
|   Map<String, dynamic> toJson() { | ||||
|     final Map<String, dynamic> data = new Map<String, dynamic>(); | ||||
|     data['PatientShare'] = this.patientShare; | ||||
|     data['PatientShareWithTax'] = this.patientShareWithTax; | ||||
|     data['PatientTaxAmount'] = this.patientTaxAmount; | ||||
|     data['ProcedureID'] = this.procedureID; | ||||
|     data['ProcedureName'] = this.procedureName; | ||||
|     return data; | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,46 @@ | ||||
| import 'package:flutter/cupertino.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:hmg_patient_app_new/core/app_export.dart'; | ||||
| import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; | ||||
| import 'package:hmg_patient_app_new/features/emergency_services/emergency_services_view_model.dart'; | ||||
| import 'package:hmg_patient_app_new/theme/colors.dart'; | ||||
| import 'package:hmg_patient_app_new/widgets/radio/custom_radio_button.dart'; | ||||
| import 'package:provider/provider.dart'; | ||||
| 
 | ||||
| class RrtRequestTypeSelect extends StatelessWidget { | ||||
|   const RrtRequestTypeSelect({super.key}); | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     // return Consumer<EmergencyServicesViewModel>(builder: (context, emergencyServicesVM, child) { | ||||
|     return Column( | ||||
|       children: [ | ||||
|         Container( | ||||
|           padding: EdgeInsets.all(16.h), | ||||
|           height: 200.h, | ||||
|           decoration: RoundedRectangleBorder().toSmoothCornerDecoration( | ||||
|             color: AppColors.whiteColor, | ||||
|             borderRadius: 24.h, | ||||
|           ), | ||||
|           child: Column( | ||||
|             crossAxisAlignment: CrossAxisAlignment.start, | ||||
|             children: [ | ||||
|               Row( | ||||
|                 children: [ | ||||
|                   CustomRadioOption( | ||||
|                     value: "", | ||||
|                     groupValue: "", | ||||
|                     onChanged: (value) {}, | ||||
|                     text: "Home Visit Emergency", | ||||
|                   ) | ||||
|                 ], | ||||
|               ), | ||||
|             ], | ||||
|           ), | ||||
|         ), | ||||
|         SizedBox(height: 32.h), | ||||
|       ], | ||||
|     ); | ||||
|     // }); | ||||
|   } | ||||
| } | ||||
| @ -0,0 +1,49 @@ | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; | ||||
| import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; | ||||
| import 'package:hmg_patient_app_new/theme/colors.dart'; | ||||
| 
 | ||||
| class CustomRadioOption<T> extends StatelessWidget { | ||||
|   final T value; | ||||
|   final T? groupValue; | ||||
|   final ValueChanged<T?> onChanged; | ||||
|   final String text; | ||||
| 
 | ||||
|   // final Widget child; // The content of your radio option (e.g., Text, Image) | ||||
| 
 | ||||
|   const CustomRadioOption({ | ||||
|     super.key, | ||||
|     required this.value, | ||||
|     required this.groupValue, | ||||
|     required this.onChanged, | ||||
|     // required this.child, | ||||
|     required this.text, | ||||
|   }); | ||||
| 
 | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     // bool isSelected = value == groupValue; | ||||
|     bool isSelected = false; | ||||
|     return InkWell( | ||||
|       onTap: () => onChanged(value), | ||||
|       child: Container( | ||||
|         padding: EdgeInsets.all(8.h), | ||||
|         child: Row( | ||||
|           children: [ | ||||
|             Container( | ||||
|               width: 20.h, | ||||
|               height: 20.h, | ||||
|               decoration: BoxDecoration( | ||||
|                 shape: BoxShape.circle, | ||||
|                 color: isSelected ? AppColors.primaryRedColor : AppColors.whiteColor, | ||||
|                 border: Border.all(color: isSelected ? AppColors.primaryRedColor : AppColors.bottomNAVBorder, width: 2.h), | ||||
|               ), | ||||
|             ), | ||||
|             SizedBox(width: 8.h), | ||||
|             text.toText16(weight: FontWeight.w500), // The provided content | ||||
|           ], | ||||
|         ), | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in New Issue