Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A-1207131329891848 | Filtering on Awaiting Appointments should query the backend #330

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/appointments/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
"RECURRENCE_WEEKDAYS_ERROR_MESSAGE": "Please select the day(s)",
"NO_CONTENT_ERROR_MESSAGE": "Selected days do not fall under the end date selected",
"UNEXPECTED_SERVICE_ERROR": "There was an unexpected issue on the server. Please try again",
"APPOINTMENT_SEARCH_TIME_ERROR": "Connection timed out. The request took too long to complete.",
"PRIORITY_ERROR_MESSAGE": "Please select appointment category",
"STATUS_ERROR_MESSAGE": "Please select appointment status",
"PUBLIC_HOLIDAY_WARNING": "Date selected is a Public Holiday",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/manage/appointmentsCreateController.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ angular.module('bahmni.appointments')

$scope.onSelectPatient = function (data) {
$scope.appointment.patient = data;
return spinner.forPromise(appointmentsService.search({patientUuid: data.uuid}).then(function (oldAppointments) {
return spinner.forPromise(appointmentsService.search({patientUuids: [data.uuid]}).then(function (oldAppointments) {
$scope.patientAppointments = oldAppointments.data;
}));
};
Expand Down
12 changes: 10 additions & 2 deletions src/controllers/manage/appointmentsFilterController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('bahmni.appointments')
.controller('AppointmentsFilterController', ['$scope', '$state', '$rootScope', '$q', '$translate', 'appointmentsServiceService', 'spinner', 'ivhTreeviewMgr', 'providerService', 'appService', 'locationService',
function ($scope, $state, $rootScope, $q, $translate, appointmentsServiceService, spinner, ivhTreeviewMgr, providerService, appService, locationService) {
.controller('AppointmentsFilterController', ['$scope', '$state', '$rootScope', '$q', '$translate', 'appointmentsServiceService', 'spinner', 'ivhTreeviewMgr', 'providerService', 'appService', 'locationService', 'appointmentsService',
function ($scope, $state, $rootScope, $q, $translate, appointmentsServiceService, spinner, ivhTreeviewMgr, providerService, appService, locationService, appointmentsService) {
var init = function () {
$scope.isSpecialityEnabled = appService.getAppDescriptor().getConfigValue('enableSpecialities');
$scope.isServiceTypeEnabled = appService.getAppDescriptor().getConfigValue('enableServiceTypes');
Expand Down Expand Up @@ -254,6 +254,14 @@ angular.module('bahmni.appointments')
$state.params.filterParams.statusList = _.map($scope.selectedStatusList, function (status) {
return status.value;
});
const AWAITING_APPOINTMENTS_TAB_NAME = "awaitingappointments";
if($state.current.tabName === AWAITING_APPOINTMENTS_TAB_NAME) {
let payload = $state.params.filterParams;
payload.withoutDates = true;
spinner.forPromise(appointmentsService.search(payload).then(function (response) {
$rootScope.appointmentsData = response.data;
}));
}
};

$scope.isFilterApplied = function () {
Expand Down
9 changes: 5 additions & 4 deletions src/controllers/manage/list/appointmentsListViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ angular.module('bahmni.appointments')
var enableAutoRefresh = !isNaN(autoRefreshIntervalInSeconds);
var autoRefreshStatus = true;
const APPOINTMENT_STATUS_WAITLIST = {
"isDatelessAppointments": true
"withoutDates": true
}
const APPOINTMENTS_TAB_NAME = "appointments";
const AWAITING_APPOINTMENTS_TAB_NAME = "awaitingappointments";
Expand Down Expand Up @@ -107,8 +107,9 @@ angular.module('bahmni.appointments')
.then((response) => updateAppointments(response));
}
else
return appointmentsService.search( prefilledPatient ? { patientUuid: prefilledPatient } : APPOINTMENT_STATUS_WAITLIST)
.then((response) => updateAppointments(response));
return appointmentsService.search( prefilledPatient ? { patientUuids: [prefilledPatient] } : APPOINTMENT_STATUS_WAITLIST)
.then((response) => updateAppointments(response))
.catch((error) => messagingService.showMessage('error', 'APPOINTMENT_SEARCH_TIME_ERROR'));
};

var updateAppointments = function (response){
Expand Down Expand Up @@ -150,7 +151,7 @@ angular.module('bahmni.appointments')
}

var setAppointmentsInPatientSearch = function (patientUuid) {
appointmentsService.search({patientUuid: patientUuid}).then(function (response) {
appointmentsService.search({patientUuids: [patientUuid]}).then(function (response) {
var appointmentsInDESCOrderBasedOnStartDateTime = _.sortBy(response.data, "startDateTime").reverse();
setFilteredAppointmentsInPatientSearch(appointmentsInDESCOrderBasedOnStartDateTime);
});
Expand Down
2 changes: 1 addition & 1 deletion src/directives/patientSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ angular.module('bahmni.appointments')

$scope.onSelectPatient = function (data) {
$state.params.patient = data;
spinner.forPromise(appointmentsService.search({patientUuid: data.uuid}).then(function (oldAppointments) {
spinner.forPromise(appointmentsService.search({patientUuids: [data.uuid]}).then(function (oldAppointments) {
var appointmentInDESCOrderBasedOnStartDateTime = _.sortBy(oldAppointments.data, "startDateTime").reverse();
$scope.onSearch(appointmentInDESCOrderBasedOnStartDateTime);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ describe("AppointmentsCreateController", function () {
$scope.patientAppointments = undefined;
var patientUuid = 'uuid';
appointmentContext = {appointment: {patient:{uuid: patientUuid}}};
var appointmentSearchParams = {patientUuid: patientUuid};
var appointmentSearchParams = {patientUuids: [patientUuid]};
createController();

expect(appointmentsService.search).toHaveBeenCalledWith(appointmentSearchParams);
Expand Down
20 changes: 19 additions & 1 deletion test/controllers/manage/appointmentsFilterController.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

describe('AppointmentsFilterController', function () {
var controller, scope, state, appService, appDescriptor, appointmentsServiceService, ivhTreeviewMgr, q, translate;
var controller, scope, state, appService, appDescriptor, appointmentsServiceService, ivhTreeviewMgr, q, translate, appointmentsService;
var locationService = jasmine.createSpyObj('locationService', ['getAllByTag']);
var providerService = jasmine.createSpyObj('providerService', ['list']);
var appService = jasmine.createSpyObj('appService', ['getAppDescriptor']);
Expand Down Expand Up @@ -93,6 +93,7 @@ describe('AppointmentsFilterController', function () {
appService = jasmine.createSpyObj('appService', ['getAppDescriptor']);
appDescriptor = jasmine.createSpyObj('appDescriptor', ['getConfigValue']);
appointmentsServiceService = jasmine.createSpyObj('appointmentsServiceService', ['getAllServicesWithServiceTypes']);
appointmentsService = jasmine.createSpyObj('appointmentsService', ['search']);
ivhTreeviewMgr = jasmine.createSpyObj('ivhTreeviewMgr', ['deselectAll', 'selectEach', 'collapseRecursive']);
translate = jasmine.createSpyObj('$translate', ['instant']);
appService.getAppDescriptor.and.returnValue(appDescriptor);
Expand All @@ -115,6 +116,7 @@ describe('AppointmentsFilterController', function () {
$scope: scope,
appService: appService,
appointmentsServiceService: appointmentsServiceService,
appointmentsService: appointmentsService,
$state: state,
ivhTreeviewMgr: ivhTreeviewMgr,
$q: q,
Expand Down Expand Up @@ -800,4 +802,20 @@ describe('AppointmentsFilterController', function () {
createController();
expect(scope.providers.length).toBe(2)
});

it("should make appointments search call when in awaiting appointments tab when filters are clicked", function() {
q.all.and.returnValue(specUtil.simplePromise([servicesWithTypes, providers, locations]));
createController();
state.current.tabName = "awaitingappointments";
appointmentsService.search.and.returnValue(specUtil.simplePromise({data: []}));
scope.applyFilter();
expect(appointmentsService.search).toHaveBeenCalledWith({
serviceUuids: [],
serviceTypeUuids : [],
providerUuids: [],
locationUuids: [],
statusList: [],
withoutDates: true
});
});
});
4 changes: 2 additions & 2 deletions test/directives/patientSearch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("Patient Search", function () {
var patient = {uuid: 'patientUuid'};
compiledScope.onSelectPatient(patient);
expect(state.params.patient).toEqual(patient);
expect(appointmentsService.search).toHaveBeenCalledWith({patientUuid: patient.uuid});
expect(appointmentsService.search).toHaveBeenCalledWith({patientUuids: [patient.uuid]});
expect(scope.displaySearchedPatient).toHaveBeenCalled();
});

Expand All @@ -90,7 +90,7 @@ describe("Patient Search", function () {
var element = createElement();
var compiledScope = element.isolateScope();
expect(compiledScope.patient).toBe(patient.givenName + " " + patient.familyName + " " + "(" + patient.identifier + ")");
expect(appointmentsService.search).toHaveBeenCalledWith({patientUuid: patient.uuid});
expect(appointmentsService.search).toHaveBeenCalledWith({patientUuids: [patient.uuid]});
expect(scope.displaySearchedPatient).toHaveBeenCalled();
});

Expand Down
Loading