active medication
parent
cb56503622
commit
de8c7bc605
@ -0,0 +1,99 @@
|
||||
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:hmg_patient_app_new/features/active_prescriptions/models/active_prescriptions_response_model.dart';
|
||||
|
||||
import '../../core/api/api_client.dart';
|
||||
import '../../core/api_consts.dart';
|
||||
import '../../core/common_models/generic_api_model.dart';
|
||||
import '../../core/exceptions/api_failure.dart';
|
||||
import '../../services/logger_service.dart';
|
||||
|
||||
abstract class ActivePrescriptionsRepo {
|
||||
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> getActivePrescriptionsDetails();
|
||||
|
||||
}
|
||||
|
||||
class ActivePrescriptionsRepoImp implements ActivePrescriptionsRepo {
|
||||
final ApiClient apiClient;
|
||||
final LoggerService loggerService;
|
||||
|
||||
ActivePrescriptionsRepoImp({required this.loggerService, required this.apiClient});
|
||||
|
||||
@override
|
||||
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> getActivePrescriptionsDetails() async
|
||||
{
|
||||
try {
|
||||
GenericApiModel<dynamic>? apiResponse;
|
||||
Failure? failure;
|
||||
await apiClient.post(
|
||||
ApiConsts.getActivePrescriptionsDetails,
|
||||
body: {},
|
||||
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
},
|
||||
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
// final list = response['GetActivePrescriptionReportByPatientIDList'];
|
||||
|
||||
// final prescriptionLists = list.map((item) => ActivePrescriptionsResponseModel.fromJson(item as Map<String, dynamic>)).toList().cast<ActivePrescriptionsResponseModel>();
|
||||
|
||||
apiResponse = GenericApiModel<dynamic>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: null,
|
||||
data: response,
|
||||
);
|
||||
return ['List_ActiveGetPrescriptionReportByPatientID'];
|
||||
//apiResponse;
|
||||
} 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Future<Either<Failure, GenericApiModel>> getActiveMedications() {
|
||||
// try {
|
||||
// GenericApiModel<dynamic>? apiResponse;
|
||||
// Failure? failure;
|
||||
// return apiClient.post(
|
||||
// ApiConsts.getActivePrescriptionsDetails,
|
||||
// body: patientDeviceDataRequest,
|
||||
// onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
// failure = failureType;
|
||||
// },
|
||||
// onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
// try {
|
||||
// apiResponse = GenericApiModel<dynamic>(
|
||||
// messageStatus: messageStatus,
|
||||
// statusCode: statusCode,
|
||||
// errorMessage: errorMessage,
|
||||
// data: response,
|
||||
// );
|
||||
// } catch (e) {
|
||||
// failure = DataParsingFailure(e.toString());
|
||||
// }
|
||||
// },
|
||||
// ).then((_) {
|
||||
// if (failure != null) return Left(failure!);
|
||||
// if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
// return Right(apiResponse!);
|
||||
// });
|
||||
// } catch (e) {
|
||||
// return Future.value(Left(UnknownFailure(e.toString())));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hmg_patient_app_new/features/active_prescriptions/models/active_prescriptions_response_model.dart';
|
||||
import 'package:hmg_patient_app_new/features/active_prescriptions/active_prescriptions_repo.dart';
|
||||
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
|
||||
|
||||
class ActivePrescriptionsViewModel extends ChangeNotifier {
|
||||
bool isActivePrescriptionsDetailsLoading = false;
|
||||
|
||||
late ActivePrescriptionsRepo activePrescriptionsRepo;
|
||||
late ErrorHandlerService errorHandlerService;
|
||||
|
||||
// Prescription Orders Lists
|
||||
List<ActivePrescriptionsResponseModel> activePrescriptionsDetailsList = [];
|
||||
|
||||
initActivePrescriptionsViewModel() {
|
||||
getActiveMedications();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
setPrescriptionsDetailsLoading() {
|
||||
isActivePrescriptionsDetailsLoading = true;
|
||||
// activePrescriptionsDetailsList.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getActiveMedications( {Function(dynamic)? onSuccess, Function(String)? onError})
|
||||
async {
|
||||
final result = await activePrescriptionsRepo.getActivePrescriptionsDetails();
|
||||
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) {
|
||||
activePrescriptionsDetailsList = apiResponse.data!;
|
||||
isActivePrescriptionsDetailsLoading = false;
|
||||
notifyListeners();
|
||||
if (onSuccess != null) {
|
||||
onSuccess(apiResponse);
|
||||
print(activePrescriptionsDetailsList.length);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class ActivePrescriptionsResponseModel {
|
||||
dynamic address;
|
||||
int? appointmentNo;
|
||||
dynamic clinic;
|
||||
dynamic companyName;
|
||||
int? days;
|
||||
dynamic doctorName;
|
||||
int? doseDailyQuantity;
|
||||
String? frequency;
|
||||
int? frequencyNumber;
|
||||
dynamic image;
|
||||
dynamic imageExtension;
|
||||
dynamic imageSrcUrl;
|
||||
String? imageString;
|
||||
dynamic imageThumbUrl;
|
||||
dynamic isCovered;
|
||||
String? itemDescription;
|
||||
int? itemId;
|
||||
String? orderDate;
|
||||
int? patientId;
|
||||
dynamic patientName;
|
||||
dynamic phoneOffice1;
|
||||
dynamic prescriptionQr;
|
||||
int? prescriptionTimes;
|
||||
dynamic productImage;
|
||||
String? productImageBase64;
|
||||
String? productImageString;
|
||||
int? projectId;
|
||||
dynamic projectName;
|
||||
dynamic remarks;
|
||||
String? route;
|
||||
String? sku;
|
||||
int? scaleOffset;
|
||||
String? startDate;
|
||||
|
||||
ActivePrescriptionsResponseModel({
|
||||
this.address,
|
||||
this.appointmentNo,
|
||||
this.clinic,
|
||||
this.companyName,
|
||||
this.days,
|
||||
this.doctorName,
|
||||
this.doseDailyQuantity,
|
||||
this.frequency,
|
||||
this.frequencyNumber,
|
||||
this.image,
|
||||
this.imageExtension,
|
||||
this.imageSrcUrl,
|
||||
this.imageString,
|
||||
this.imageThumbUrl,
|
||||
this.isCovered,
|
||||
this.itemDescription,
|
||||
this.itemId,
|
||||
this.orderDate,
|
||||
this.patientId,
|
||||
this.patientName,
|
||||
this.phoneOffice1,
|
||||
this.prescriptionQr,
|
||||
this.prescriptionTimes,
|
||||
this.productImage,
|
||||
this.productImageBase64,
|
||||
this.productImageString,
|
||||
this.projectId,
|
||||
this.projectName,
|
||||
this.remarks,
|
||||
this.route,
|
||||
this.sku,
|
||||
this.scaleOffset,
|
||||
this.startDate,
|
||||
});
|
||||
|
||||
factory ActivePrescriptionsResponseModel.fromRawJson(String str) => ActivePrescriptionsResponseModel.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory ActivePrescriptionsResponseModel.fromJson(Map<String, dynamic> json) => ActivePrescriptionsResponseModel(
|
||||
address: json["Address"],
|
||||
appointmentNo: json["AppointmentNo"],
|
||||
clinic: json["Clinic"],
|
||||
companyName: json["CompanyName"],
|
||||
days: json["Days"],
|
||||
doctorName: json["DoctorName"],
|
||||
doseDailyQuantity: json["DoseDailyQuantity"],
|
||||
frequency: json["Frequency"],
|
||||
frequencyNumber: json["FrequencyNumber"],
|
||||
image: json["Image"],
|
||||
imageExtension: json["ImageExtension"],
|
||||
imageSrcUrl: json["ImageSRCUrl"],
|
||||
imageString: json["ImageString"],
|
||||
imageThumbUrl: json["ImageThumbUrl"],
|
||||
isCovered: json["IsCovered"],
|
||||
itemDescription: json["ItemDescription"],
|
||||
itemId: json["ItemID"],
|
||||
orderDate: json["OrderDate"],
|
||||
patientId: json["PatientID"],
|
||||
patientName: json["PatientName"],
|
||||
phoneOffice1: json["PhoneOffice1"],
|
||||
prescriptionQr: json["PrescriptionQR"],
|
||||
prescriptionTimes: json["PrescriptionTimes"],
|
||||
productImage: json["ProductImage"],
|
||||
productImageBase64: json["ProductImageBase64"],
|
||||
productImageString: json["ProductImageString"],
|
||||
projectId: json["ProjectID"],
|
||||
projectName: json["ProjectName"],
|
||||
remarks: json["Remarks"],
|
||||
route: json["Route"],
|
||||
sku: json["SKU"],
|
||||
scaleOffset: json["ScaleOffset"],
|
||||
startDate: json["StartDate"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"Address": address,
|
||||
"AppointmentNo": appointmentNo,
|
||||
"Clinic": clinic,
|
||||
"CompanyName": companyName,
|
||||
"Days": days,
|
||||
"DoctorName": doctorName,
|
||||
"DoseDailyQuantity": doseDailyQuantity,
|
||||
"Frequency": frequency,
|
||||
"FrequencyNumber": frequencyNumber,
|
||||
"Image": image,
|
||||
"ImageExtension": imageExtension,
|
||||
"ImageSRCUrl": imageSrcUrl,
|
||||
"ImageString": imageString,
|
||||
"ImageThumbUrl": imageThumbUrl,
|
||||
"IsCovered": isCovered,
|
||||
"ItemDescription": itemDescription,
|
||||
"ItemID": itemId,
|
||||
"OrderDate": orderDate,
|
||||
"PatientID": patientId,
|
||||
"PatientName": patientName,
|
||||
"PhoneOffice1": phoneOffice1,
|
||||
"PrescriptionQR": prescriptionQr,
|
||||
"PrescriptionTimes": prescriptionTimes,
|
||||
"ProductImage": productImage,
|
||||
"ProductImageBase64": productImageBase64,
|
||||
"ProductImageString": productImageString,
|
||||
"ProjectID": projectId,
|
||||
"ProjectName": projectName,
|
||||
"Remarks": remarks,
|
||||
"Route": route,
|
||||
"SKU": sku,
|
||||
"ScaleOffset": scaleOffset,
|
||||
"StartDate": startDate,
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,155 @@
|
||||
// import 'package:easy_localization/easy_localization.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
|
||||
//
|
||||
// import '../../generated/locale_keys.g.dart';
|
||||
// import '../../theme/colors.dart';
|
||||
//
|
||||
// class ReminderTimerDialog extends StatefulWidget {
|
||||
// final Function()? onSetReminderPress;
|
||||
// final String message;
|
||||
//
|
||||
// const ReminderTimerDialog(this.onSetReminderPress, this.message, {super.key});
|
||||
//
|
||||
//
|
||||
// @override
|
||||
// State<ReminderTimerDialog> createState() => _ReminderTimerDialogState();
|
||||
// }
|
||||
//
|
||||
// class _ReminderTimerDialogState extends State<ReminderTimerDialog> {
|
||||
// final List<String> options = ["Morning", "Afternoon", "Evening", "Midnight"];
|
||||
// final List<String> selectedTimes = ["Morning"]; // Default selection
|
||||
//
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return //
|
||||
// Column(
|
||||
// children: [
|
||||
// Container(
|
||||
// decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24,
|
||||
// hasShadow: true,),
|
||||
// child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// // Checkboxes list
|
||||
// children: options.map((time) => buildCircleCheckbox(time)).toList(),
|
||||
// ).paddingAll(16),
|
||||
// ),
|
||||
// const SizedBox(height: 25),
|
||||
// // Buttons Row
|
||||
// Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// child: ElevatedButton.icon(
|
||||
// onPressed: () => Navigator.pop(context),
|
||||
// icon: const Icon(Icons.close, color: AppColors.errorColor),
|
||||
// label: Text(
|
||||
// LocaleKeys.cancel.tr(),
|
||||
// style: TextStyle(
|
||||
// color: AppColors.errorColor,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontSize: 14
|
||||
// ),
|
||||
// ),
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// backgroundColor: AppColors.secondaryLightRedColor,
|
||||
// elevation: 0,
|
||||
// padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(12),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(width: 12),
|
||||
// Expanded(
|
||||
// child: ElevatedButton.icon(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context, selectedTimes);
|
||||
// },
|
||||
// icon: const Icon(Icons.notifications_rounded),
|
||||
// label: Text(
|
||||
// LocaleKeys.setReminder.tr(),
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontSize: 14
|
||||
// ),
|
||||
// ),
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// backgroundColor: AppColors.successColor,
|
||||
// foregroundColor: AppColors.whiteColor,
|
||||
// elevation: 0,
|
||||
// padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(12),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// const SizedBox(height: 30),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// Widget buildCircleCheckbox(String label) {
|
||||
// final bool isSelected = selectedTimes.contains(label);
|
||||
// return InkWell(
|
||||
// onTap: () {
|
||||
// setState(() {
|
||||
// if (isSelected) {
|
||||
// selectedTimes.remove(label);
|
||||
// } else {
|
||||
// selectedTimes.add(label);
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
// borderRadius: BorderRadius.circular(25),
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// // Custom circle checkbox
|
||||
// Container(
|
||||
// width: 15,
|
||||
// height: 15,
|
||||
// decoration: BoxDecoration(
|
||||
// shape: BoxShape.circle,
|
||||
// border: Border.all(
|
||||
// color: isSelected ? AppColors.spacerLineColor: AppColors.spacerLineColor,
|
||||
// width: 1,
|
||||
// ),
|
||||
// color: isSelected ? AppColors.errorColor: AppColors.transparent,
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(width: 12),
|
||||
// // Label text
|
||||
// Text(
|
||||
// label,
|
||||
// style: const TextStyle(fontSize: 16, color: Colors.black87),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void showCircleCheckboxDialog(BuildContext context) async {
|
||||
// final selected = await showDialog<List<String>>(
|
||||
// context: context,
|
||||
// builder: (context) => const ReminderTimerDialog(),
|
||||
// );
|
||||
//
|
||||
// if (selected != null && selected.isNotEmpty) {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(content: Text('Reminders set for: ${selected.join(', ')}')),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
Loading…
Reference in New Issue