From 524daa5dfeaf72e75c3b9a64bbae6fa9eae5be74 Mon Sep 17 00:00:00 2001 From: AshishkurianTw <119398030+ashishkuriantw@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:06:27 +0530 Subject: [PATCH] [Ashish | Abinaya]Fix. Search results for prefilled patients | 1205365242337347 (#300) * [Ashish | Abinaya]Fix. Search results for prefilled patients * [Abinaya | Ashish ] Fix.Failing tests --- .../list/appointmentsListViewController.js | 32 +++++++++++-------- .../appointmentsListViewController.spec.js | 8 +++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/controllers/manage/list/appointmentsListViewController.js b/src/controllers/manage/list/appointmentsListViewController.js index a1044802d..cf233f500 100644 --- a/src/controllers/manage/list/appointmentsListViewController.js +++ b/src/controllers/manage/list/appointmentsListViewController.js @@ -2,9 +2,9 @@ angular.module('bahmni.appointments') .controller('AppointmentsListViewController', ['$scope', '$state', '$rootScope', '$translate', '$stateParams', 'spinner', - 'appointmentsService', 'appService', 'appointmentsFilter', 'printer', 'checkinPopUp', 'confirmBox', 'ngDialog', 'messagingService', 'appointmentCommonService', '$interval', + 'appointmentsService', 'appService', 'appointmentsFilter', 'printer', 'checkinPopUp', 'confirmBox', 'ngDialog', 'messagingService', 'appointmentCommonService', '$interval','$window','$location', function ($scope, $state, $rootScope, $translate, $stateParams, spinner, appointmentsService, appService, - appointmentsFilter, printer, checkinPopUp, confirmBox, ngDialog, messagingService, appointmentCommonService, $interval) { + appointmentsFilter, printer, checkinPopUp, confirmBox, ngDialog, messagingService, appointmentCommonService, $interval, $window, $location,) { $scope.enableSpecialities = appService.getAppDescriptor().getConfigValue('enableSpecialities'); $scope.enableServiceTypes = appService.getAppDescriptor().getConfigValue('enableServiceTypes'); $scope.priorityOptionsList = appService.getAppDescriptor().getConfigValue('priorityOptionsList') || []; @@ -73,12 +73,12 @@ angular.module('bahmni.appointments') var setAppointments = function (params) { autoRefreshStatus = false; - if($scope.getCurrentTabName() === APPOINTMENTS_TAB_NAME) + if($scope.getCurrentTabName() === APPOINTMENTS_TAB_NAME && $state.params.patient != null) return appointmentsService.getAllAppointments(params) - .then((response) => updateAppointments(response)); - else - return appointmentsService.search(APPOINTMENT_STATUS_WAITLIST) - .then((response) => updateAppointments(response)); + .then((response) => updateAppointments(response)); + else + return appointmentsService.search( $location.search()['patient'] ? { patientUuid: $location.search()['patient'] } : APPOINTMENT_STATUS_WAITLIST) + .then((response) => updateAppointments(response)); }; var updateAppointments = function (response){ @@ -206,8 +206,12 @@ angular.module('bahmni.appointments') $scope.selectedAppointment = undefined; }; - $scope.hasNoAppointments = function () { + $scope.hasNoAppointments = function () {if ($state.params.patient && $state.params.patient.label === 'undefined (undefined)') { + $window.location.reload(); + return false; + } else { return _.isEmpty($scope.filteredAppointments); + } }; $scope.goBackToPreviousView = function () { @@ -234,7 +238,7 @@ angular.module('bahmni.appointments') return appointmentType === 'WalkIn' ? 'Yes' : 'No'; }; - $scope.editAppointment = function () { + $scope.editAppointment = function () { var params = $stateParams; params.uuid = $scope.selectedAppointment.uuid; params.isRecurring = $scope.selectedAppointment.recurring; @@ -242,14 +246,14 @@ angular.module('bahmni.appointments') }; $scope.openTeleConsultation = function () { - window.open("https://" + - window.location.hostname + - Bahmni.Common.Constants.patientsURL + + window.open("https://" + + window.location.hostname + + Bahmni.Common.Constants.patientsURL + $scope.selectedAppointment.patient.uuid + Bahmni.Common.Constants.patientsURLGeneralInformationTab , '_self') - }; - + }; + $scope.copyTeleConsultationMeetingURL = function () { var jitsiMeetingUrl = $scope.selectedAppointment.teleconsultationLink; const el = document.createElement('textarea'); diff --git a/test/controllers/manage/list/appointmentsListViewController.spec.js b/test/controllers/manage/list/appointmentsListViewController.spec.js index 74d8695ee..0d64b00f0 100644 --- a/test/controllers/manage/list/appointmentsListViewController.spec.js +++ b/test/controllers/manage/list/appointmentsListViewController.spec.js @@ -14,8 +14,9 @@ describe('AppointmentsListViewController', function () { controller = $controller; stateparams = $stateParams; _appointmentsFilter = jasmine.createSpy('appointmentsFilter'); - appointmentsService = jasmine.createSpyObj('appointmentsService', ['getAllAppointments', 'changeStatus', 'undoCheckIn', 'changeProviderResponse']); + appointmentsService = jasmine.createSpyObj('appointmentsService', ['getAllAppointments', 'changeStatus', 'undoCheckIn', 'changeProviderResponse' , 'search']); appointmentsService.getAllAppointments.and.returnValue(specUtil.simplePromise({})); + appointmentsService.search.and.returnValue(specUtil.simplePromise({})); appService = jasmine.createSpyObj('appService', ['getAppDescriptor']); appDescriptor = jasmine.createSpyObj('appDescriptor', ['getConfigValue']); printer = jasmine.createSpyObj('printer', ['print']); @@ -114,6 +115,7 @@ describe('AppointmentsListViewController', function () { createController(); var viewDate = new Date('1970-01-01T11:30:00.000Z'); $state.params = {doFetchAppointmentsData: true}; + $state.params.patient = '123'; scope.getAppointmentsForDate(viewDate); expect(stateparams.viewDate).toEqual(viewDate); expect(appointmentsService.getAllAppointments).toHaveBeenCalledWith({forDate: viewDate}); @@ -242,7 +244,7 @@ describe('AppointmentsListViewController', function () { stateparams.filterParams = {serviceUuids: ["02666cc6-5f3e-4920-856d-ab7e28d3dbdb"]}; createController(); var viewDate = new Date('2017-08-28T11:30:00.000Z'); - $state.params = {doFetchAppointmentsData: true}; + $state.params = {doFetchAppointmentsData: true , patient: "123"}; scope.getAppointmentsForDate(viewDate); expect(scope.appointments).toBe(appointments); expect(scope.filteredAppointments.length).toEqual(1); @@ -346,7 +348,7 @@ describe('AppointmentsListViewController', function () { }; createController(); var viewDate = new Date('2017-08-28T11:30:00.000Z'); - $state.params = {doFetchAppointmentsData: true}; + $state.params = {doFetchAppointmentsData: true , patient:"123"}; scope.getAppointmentsForDate(viewDate); expect(scope.appointments).toBe(appointments); expect(scope.searchedPatient).toBeFalsy();