From 77ab9373f895e3f55e4dbd7c369fe96682375a32 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 11 Jul 2023 14:09:00 +0300 Subject: [PATCH] Meal Plan APIs implementation continued --- lib/config/config.dart | 2 + .../get_meals_schedule_response_model.dart | 42 +++++++++++++++ lib/pages/InPatientServices/meal_plan.dart | 53 +++++++++++++++++-- .../clinic_services/get_clinic_service.dart | 37 ++++++++++++- 4 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 lib/models/InPatientServices/get_meals_schedule_response_model.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index 57376060..f3ededbd 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -608,6 +608,8 @@ var SAVE_BIRTH_NOTIFICATION = 'Services/INPs.svc/REST/SaveBirthNotification'; //Meal Plan APIs var GET_ADMITTED_PATIENTS = 'Services/MOP.svc/REST/GetAdmittedPatients'; +var GET_CURRENT_WEEKID_WEEKDAY = 'Services/MOP.svc/REST/GetCurrentWeekAndDayHMGMP'; +var GET_MEALS_OF_SCHEDULE_ID = 'Services/MOP.svc/REST/GetMealsOfScheduleID'; class AppGlobal { static var context; diff --git a/lib/models/InPatientServices/get_meals_schedule_response_model.dart b/lib/models/InPatientServices/get_meals_schedule_response_model.dart new file mode 100644 index 00000000..599534a4 --- /dev/null +++ b/lib/models/InPatientServices/get_meals_schedule_response_model.dart @@ -0,0 +1,42 @@ +class GetMealsScheduleResponseModel { + int scheduleID; + int mealID; + String description; + String descriptionN; + int weekID; + String weekDescription; + String weekDescriptionN; + String tAT; + int dietTypeID; + int dayID; + + GetMealsScheduleResponseModel({this.scheduleID, this.mealID, this.description, this.descriptionN, this.weekID, this.weekDescription, this.weekDescriptionN, this.tAT, this.dietTypeID, this.dayID}); + + GetMealsScheduleResponseModel.fromJson(Map json) { + scheduleID = json['ScheduleID']; + mealID = json['MealID']; + description = json['Description']; + descriptionN = json['DescriptionN']; + weekID = json['WeekID']; + weekDescription = json['WeekDescription']; + weekDescriptionN = json['WeekDescriptionN']; + tAT = json['TAT']; + dietTypeID = json['DietTypeID']; + dayID = json['DayID']; + } + + Map toJson() { + final Map data = new Map(); + data['ScheduleID'] = this.scheduleID; + data['MealID'] = this.mealID; + data['Description'] = this.description; + data['DescriptionN'] = this.descriptionN; + data['WeekID'] = this.weekID; + data['WeekDescription'] = this.weekDescription; + data['WeekDescriptionN'] = this.weekDescriptionN; + data['TAT'] = this.tAT; + data['DietTypeID'] = this.dietTypeID; + data['DayID'] = this.dayID; + return data; + } +} diff --git a/lib/pages/InPatientServices/meal_plan.dart b/lib/pages/InPatientServices/meal_plan.dart index 2a2c3565..4411b660 100644 --- a/lib/pages/InPatientServices/meal_plan.dart +++ b/lib/pages/InPatientServices/meal_plan.dart @@ -1,6 +1,8 @@ import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/models/InPatientServices/get_admitted_patient_response_model.dart'; +import 'package:diplomaticquarterapp/models/InPatientServices/get_meals_schedule_response_model.dart'; import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart'; +import 'package:diplomaticquarterapp/uitl/app_toast.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'; @@ -19,6 +21,10 @@ class MealPlanPage extends StatefulWidget { class _MealPlanPageState extends State { ProjectViewModel projectViewModel; GetAdmittedPatientsResponseModel getAdmittedPatientsResponseModel; + List getMealsScheduleResponseModelList = []; + + int currentDay = 0; + int currentWeek = 0; @override void initState() { @@ -115,12 +121,49 @@ class _MealPlanPageState extends State { GifLoaderDialogUtils.showMyDialog(context); service.getAdmittedPatientDetails(projectViewModel.user.patientID, projectViewModel.inPatientProjectID, projectViewModel.getAdmissionInfoResponseModel.admissionNo, 0, 0, 0, context).then((res) { GifLoaderDialogUtils.hideDialog(context); - print(res["List_MOP_AdmittedPatients"]); - getAdmittedPatientsResponseModel = new GetAdmittedPatientsResponseModel.fromJson(res["List_MOP_AdmittedPatients"][0]); - print(getAdmittedPatientsResponseModel.admissionNo); - // AppToast.showSuccessToast(message: TranslationBase.of(context).processDoneSuccessfully); - // Navigator.of(context).pop(); + if (res["List_MOP_AdmittedPatients"] != null && res["List_MOP_AdmittedPatients"].length != 0) { + print(res["List_MOP_AdmittedPatients"]); + getAdmittedPatientsResponseModel = new GetAdmittedPatientsResponseModel.fromJson(res["List_MOP_AdmittedPatients"][0]); + print(getAdmittedPatientsResponseModel.dietType); + getCurrentWeekIDAndDay(getAdmittedPatientsResponseModel.dietType); + } else { + AppToast.showErrorToast(message: "No data found for admitted patient"); + } + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); + print(err); + }); + } + + void getCurrentWeekIDAndDay(int dietType) { + ClinicListService service = new ClinicListService(); + GifLoaderDialogUtils.showMyDialog(context); + service.getCurrentWeekIDAndDay(context).then((res) { + GifLoaderDialogUtils.hideDialog(context); + currentDay = res["CurrentDay"]; + currentWeek = res["CurrentWeek"]; + getMealsOfScheduleID(dietType); }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); + print(err); + }); + } + + void getMealsOfScheduleID(int dietType) { + ClinicListService service = new ClinicListService(); + GifLoaderDialogUtils.showMyDialog(context); + service.getMealsOfScheduleID(projectViewModel.inPatientProjectID, projectViewModel.getAdmissionInfoResponseModel.admissionNo, dietType, currentWeek, currentDay, context).then((res) { + GifLoaderDialogUtils.hideDialog(context); + if (res["List_MOP_MealsOfScheduleID"] != null && res["List_MOP_MealsOfScheduleID"].length != 0) { + res['List_MOP_MealsOfScheduleID'].forEach((cOC) { + getMealsScheduleResponseModelList.add(GetMealsScheduleResponseModel.fromJson(res["List_MOP_MealsOfScheduleID"])); + }); + print(getMealsScheduleResponseModelList.length); + } else { + AppToast.showErrorToast(message: "No meal schedule found for admitted patient"); + } + }).catchError((err) { + GifLoaderDialogUtils.hideDialog(context); print(err); }); } diff --git a/lib/services/clinic_services/get_clinic_service.dart b/lib/services/clinic_services/get_clinic_service.dart index d08ecfd1..2ae7bbcf 100644 --- a/lib/services/clinic_services/get_clinic_service.dart +++ b/lib/services/clinic_services/get_clinic_service.dart @@ -279,8 +279,8 @@ class ClinicListService extends BaseService { Map request; request = { "ProjectID": projectID, - "PatientID" : 3649733, - "AdmissionNo": 2023000035, + "PatientID" : 3649746, + "AdmissionNo": 2023000036, "BuildingID" : buildingID, "FloorID" : floorID, "NursingStationID": nursingStationID @@ -296,4 +296,37 @@ class ClinicListService extends BaseService { return Future.value(localRes); } + Future getCurrentWeekIDAndDay(BuildContext context) async { + dynamic localRes; + await baseAppClient.get(GET_CURRENT_WEEKID_WEEKDAY, isExternal: true, onSuccess: (response, statusCode) async { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }); + return localRes; + } + + Future getMealsOfScheduleID(int projectID, int admissionNo, int dietType, int weekID, int weekDay, context) async { + Map request; + request = { + "ProjectID": projectID, + "AdmissionNo": admissionNo, + "BuildingID" : 0, + "FloorID" : 0, + "NursingStationID": 0, + "DietType": dietType, + "WeekID": weekID, + "WeekDay": weekDay, + }; + + dynamic localRes; + + await baseAppClient.post(GET_MEALS_OF_SCHEDULE_ID, onSuccess: (response, statusCode) async { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: request, isAllowAny: true); + return Future.value(localRes); + } + }