From d073eb9d5f9cef037672058aed190cf5a524fb27 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 11 Jul 2023 14:46:43 +0300 Subject: [PATCH] MealPlan implementation continued --- lib/config/config.dart | 1 + ...et_meal_items_schedule_response_model.dart | 60 +++++++++++++++++++ lib/pages/InPatientServices/meal_plan.dart | 45 +++++++++++++- .../clinic_services/get_clinic_service.dart | 19 +++++- 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 lib/models/InPatientServices/get_meal_items_schedule_response_model.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index f3ededbd..85e57b6c 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -610,6 +610,7 @@ var SAVE_BIRTH_NOTIFICATION = 'Services/INPs.svc/REST/SaveBirthNotification'; 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'; +var GET_MEAL_ITEMS_OF_SCHEDULE_ID = 'Services/MOP.svc/REST/GetDefaultItemsOfScheduleID'; class AppGlobal { static var context; diff --git a/lib/models/InPatientServices/get_meal_items_schedule_response_model.dart b/lib/models/InPatientServices/get_meal_items_schedule_response_model.dart new file mode 100644 index 00000000..3d8cfc30 --- /dev/null +++ b/lib/models/InPatientServices/get_meal_items_schedule_response_model.dart @@ -0,0 +1,60 @@ +class GetMealItemsScheduleResponseModel { + int itemID; + String description; + String descriptionN; + dynamic comment; + dynamic commentN; + String imageURL; + bool isDefault; + int categoryID; + String categoryDescription; + String categoryDescriptionN; + int scheduleID; + int cal; + + GetMealItemsScheduleResponseModel( + {this.itemID, + this.description, + this.descriptionN, + this.comment, + this.commentN, + this.imageURL, + this.isDefault, + this.categoryID, + this.categoryDescription, + this.categoryDescriptionN, + this.scheduleID, + this.cal}); + + GetMealItemsScheduleResponseModel.fromJson(Map json) { + itemID = json['ItemID']; + description = json['Description']; + descriptionN = json['DescriptionN']; + comment = json['Comment']; + commentN = json['CommentN']; + imageURL = json['ImageURL']; + isDefault = json['IsDefault']; + categoryID = json['CategoryID']; + categoryDescription = json['CategoryDescription']; + categoryDescriptionN = json['CategoryDescriptionN']; + scheduleID = json['ScheduleID']; + cal = json['cal']; + } + + Map toJson() { + final Map data = new Map(); + data['ItemID'] = this.itemID; + data['Description'] = this.description; + data['DescriptionN'] = this.descriptionN; + data['Comment'] = this.comment; + data['CommentN'] = this.commentN; + data['ImageURL'] = this.imageURL; + data['IsDefault'] = this.isDefault; + data['CategoryID'] = this.categoryID; + data['CategoryDescription'] = this.categoryDescription; + data['CategoryDescriptionN'] = this.categoryDescriptionN; + data['ScheduleID'] = this.scheduleID; + data['cal'] = this.cal; + return data; + } +} diff --git a/lib/pages/InPatientServices/meal_plan.dart b/lib/pages/InPatientServices/meal_plan.dart index 4411b660..0c16ad88 100644 --- a/lib/pages/InPatientServices/meal_plan.dart +++ b/lib/pages/InPatientServices/meal_plan.dart @@ -1,5 +1,6 @@ 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_meal_items_schedule_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'; @@ -23,6 +24,10 @@ class _MealPlanPageState extends State { GetAdmittedPatientsResponseModel getAdmittedPatientsResponseModel; List getMealsScheduleResponseModelList = []; + List getMealItemsScheduleResponseModelBreakfast = []; + List getMealItemsScheduleResponseModelLunch = []; + List getMealItemsScheduleResponseModelDinner = []; + int currentDay = 0; int currentWeek = 0; @@ -128,6 +133,8 @@ class _MealPlanPageState extends State { getCurrentWeekIDAndDay(getAdmittedPatientsResponseModel.dietType); } else { AppToast.showErrorToast(message: "No data found for admitted patient"); + + getCurrentWeekIDAndDay(1); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); @@ -155,10 +162,12 @@ class _MealPlanPageState extends State { 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"])); + res['List_MOP_MealsOfScheduleID'].forEach((scheduleItem) { + getMealsScheduleResponseModelList.add(GetMealsScheduleResponseModel.fromJson(scheduleItem)); }); - print(getMealsScheduleResponseModelList.length); + getDefaultItemsOfScheduleID(getMealsScheduleResponseModelList[0].scheduleID, 1); + getDefaultItemsOfScheduleID(getMealsScheduleResponseModelList[1].scheduleID, 2); + getDefaultItemsOfScheduleID(getMealsScheduleResponseModelList[2].scheduleID, 3); } else { AppToast.showErrorToast(message: "No meal schedule found for admitted patient"); } @@ -167,4 +176,34 @@ class _MealPlanPageState extends State { print(err); }); } + + void getDefaultItemsOfScheduleID(int scheduleID, int mealType) { + ClinicListService service = new ClinicListService(); + GifLoaderDialogUtils.showMyDialog(context); + service.getDefaultItemsOfScheduleID(projectViewModel.inPatientProjectID, scheduleID, context).then((res) { + GifLoaderDialogUtils.hideDialog(context); + if (res["List_MOP_DefaultItemsOfMealModel"] != null && res["List_MOP_DefaultItemsOfMealModel"].length != 0) { + if (mealType == 1) { + res['List_MOP_DefaultItemsOfMealModel'].forEach((scheduleItem) { + getMealItemsScheduleResponseModelBreakfast.add(GetMealItemsScheduleResponseModel.fromJson(scheduleItem)); + }); + } + if (mealType == 2) { + res['List_MOP_DefaultItemsOfMealModel'].forEach((scheduleItem) { + getMealItemsScheduleResponseModelLunch.add(GetMealItemsScheduleResponseModel.fromJson(scheduleItem)); + }); + } + if (mealType == 3) { + res['List_MOP_DefaultItemsOfMealModel'].forEach((scheduleItem) { + getMealItemsScheduleResponseModelDinner.add(GetMealItemsScheduleResponseModel.fromJson(scheduleItem)); + }); + } + } else { + AppToast.showErrorToast(message: "No meal items 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 2ae7bbcf..be556ea2 100644 --- a/lib/services/clinic_services/get_clinic_service.dart +++ b/lib/services/clinic_services/get_clinic_service.dart @@ -298,7 +298,7 @@ class ClinicListService extends BaseService { Future getCurrentWeekIDAndDay(BuildContext context) async { dynamic localRes; - await baseAppClient.get(GET_CURRENT_WEEKID_WEEKDAY, isExternal: true, onSuccess: (response, statusCode) async { + await baseAppClient.get(GET_CURRENT_WEEKID_WEEKDAY, isExternal: false, isRCService: false, onSuccess: (response, statusCode) async { localRes = response; }, onFailure: (String error, int statusCode) { throw error; @@ -329,4 +329,21 @@ class ClinicListService extends BaseService { return Future.value(localRes); } + Future getDefaultItemsOfScheduleID(int projectID, int scheduleID, context) async { + Map request; + request = { + "ProjectID": projectID, + "MealScheduleID": scheduleID, + }; + + dynamic localRes; + + await baseAppClient.post(GET_MEAL_ITEMS_OF_SCHEDULE_ID, onSuccess: (response, statusCode) async { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: request, isAllowAny: true); + return Future.value(localRes); + } + }