diff --git a/src/controllers/manage/list/appointmentsListViewController.js b/src/controllers/manage/list/appointmentsListViewController.js index e850a03b6..5e72c1c81 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') || []; @@ -101,12 +101,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)); + return appointmentsService.search( $location.search()['patient'] ? { patientUuid: $location.search()['patient'] } : APPOINTMENT_STATUS_WAITLIST) + .then((response) => updateAppointments(response)); }; var updateAppointments = function (response){ @@ -234,8 +234,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 () { diff --git a/test/controllers/manage/list/appointmentsListViewController.spec.js b/test/controllers/manage/list/appointmentsListViewController.spec.js index 9e40f7935..39bbf993f 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();