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

[Phani] | BAH-3711 | Refactor appointment patient search component #322

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion i18n/appointments/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"SELECT_APPOINTMENT_PROVIDER": "Select Provider",
"INVITED_PROVIDERS": "Invitees",
"APPOINTMENT_PROVIDER_REMOVE_ACTION": "Remove",
"DROPDOWN_NO_OPTIONS_MESSAGE" : "Type to search",
"DROPDOWN_NO_OPTIONS_MESSAGE" : "No patients found",
"DROPDOWN_LOADING_MESSAGE" : "Loading...",
"RECURRENCE_THIS_APPOINTMENT": "Cancel Occurrence",
"RECURRENCE_ALL_APPOINTMENTS" : "Cancel All",
Expand Down
62 changes: 26 additions & 36 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"carbon-components-react": "7.55.1",
"carbon-components": "^10.19.0",
"carbon-icons": "^7.0.7",
"axios": "^0.19.0",
"axios": "^1.6.7",
"babel-polyfill": "^6.26.0",
"classnames": "^2.2.6",
"js-cookie": "^2.2.1",
Expand Down
19 changes: 15 additions & 4 deletions ui/react-components/api/patientApi.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import axios from 'axios';
import {patientUrl, searchPatientUrl, personUrl} from '../config';

export const getPatientsByLocation = async (locationUuid, searchQuery, startIndex = 0) => {
export const getPatientsByLocation = async (locationUuid, searchQuery, cancelToken, startIndex = 0) => {
try {
const response = await axios.get(`${searchPatientUrl}?loginLocationUuid=${locationUuid}&filterOnAllIdentifiers=true&identifier=${searchQuery}&q=${searchQuery}&startIndex=${startIndex}`);
const response = await axios.get(searchPatientUrl, {
params: {
loginLocationUuid: locationUuid,
filterOnAllIdentifiers: true,
identifier: searchQuery,
q: searchQuery,
startIndex: startIndex
},
cancelToken: cancelToken
});
return response.data.pageOfResults;
} catch (error) {
console.error(error);
if (!axios.isCancel(error)) {
console.error(error);
}
return error.response;
}
};
Expand All @@ -25,7 +36,7 @@ export const getPersonAttribute = async (uuid, attribute) => {
try {
const response = await axios.get(`${personUrl}/${uuid}/attribute`);
for (let i = 0; i < response.data.results.length; i++) {
if(response.data.results[i].attributeType.display == attribute)
if (response.data.results[i].attributeType.display == attribute)
return response.data.results[i].value;
}
return null;
Expand Down
34 changes: 27 additions & 7 deletions ui/react-components/api/patientApi.spec.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Phanindra-tw could we add a test to ensure calls are cancelled when a new character is entered?. The rest of the changes looks great. If we have the test ready, we're good to merge the changes. Please prioritize adding the test.

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ afterEach(() => {
});

describe('Patient Api', () => {
it('should take location uuid and search query to return list of patients', async () =>{
it('should take location uuid and search query and cancel Token to return list of patients', async () =>{
let locationUuid = "locationUuid";
let searchQuery = "searchquery";
let cancelToken = "CancelToken";
let expectedParams = {
cancelToken: cancelToken,
params: {
filterOnAllIdentifiers: true,
identifier: searchQuery,
loginLocationUuid: locationUuid,
q: searchQuery,
startIndex: 0
}
}
let mockResponse = {
"totalCount": null,
"pageOfResults": [
Expand Down Expand Up @@ -41,18 +52,28 @@ describe('Patient Api', () => {
})
);

let patientsByLocation = await getPatientsByLocation(locationUuid, searchQuery);
let patientsByLocation = await getPatientsByLocation(locationUuid, searchQuery, cancelToken);

expect(mockAxios.get)
.toHaveBeenCalledWith(
`${searchPatientUrl}?loginLocationUuid=${locationUuid}&filterOnAllIdentifiers=true&identifier=${searchQuery}&q=${searchQuery}&startIndex=0`);
.toHaveBeenCalledWith(searchPatientUrl, expectedParams);
expect(patientsByLocation).toEqual(mockResponse.pageOfResults);
});

it('should take location uuid and search query and start index to return list of patients', async () => {
let locationUuid = "locationUuid";
let searchQuery = "searchquery";
let startIndex = 6;
let cancelToken = "CancelToken";
let expectedParams = {
cancelToken: cancelToken,
params: {
filterOnAllIdentifiers: true,
identifier: searchQuery,
loginLocationUuid: locationUuid,
q: searchQuery,
startIndex: startIndex
}
}
let mockResponse = {
"totalCount": null,
"pageOfResults": [
Expand Down Expand Up @@ -82,11 +103,10 @@ describe('Patient Api', () => {
})
);

await getPatientsByLocation(locationUuid, searchQuery, startIndex);
await getPatientsByLocation(locationUuid, searchQuery, cancelToken, startIndex);

expect(mockAxios.get)
.toHaveBeenCalledWith(
`${searchPatientUrl}?loginLocationUuid=${locationUuid}&filterOnAllIdentifiers=true&identifier=${searchQuery}&q=${searchQuery}&startIndex=${startIndex}`);
.toHaveBeenCalledWith(searchPatientUrl, expectedParams);
});

it('should fetch patient by given uuid', async () =>{
Expand Down
4 changes: 2 additions & 2 deletions ui/react-components/carbon-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ $css--body: false;
.bx--radio-button:checked+.bx--radio-button__label .bx--radio-button__appearance::before {
background-color: #0a74ff;
}
.bx--list-box__wrapper{
max-width: 250px;
.bx--list-box__menu-item[disabled] .bx--list-box__menu-item__option {
color: #363463;
}
.bx--number__control-btn{
border: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe('Add Appointment', () => {
"enableServiceTypes": true
};
const {container, getByTestId} = renderWithReactIntl(<AddAppointment appConfig={config}/>);
expect(container.querySelector('.bx--search-input')).not.toBeNull();
expect(container.querySelector('.bx--text-input')).not.toBeNull();
expect(container.querySelector('.bx--list-box')).not.toBeNull();
expect(container.querySelectorAll('.bx--list-box').length).toEqual(4);
expect(container.querySelectorAll('.bx--list-box').length).toEqual(5);
expect(getByTestId('search-patient')).not.toBeNull();
expect(getByTestId('service-search')).not.toBeNull();
expect(() => getByTestId('speciality-search')).toThrow();
Expand All @@ -93,9 +93,9 @@ describe('Add Appointment', () => {
"enableServiceTypes": true
};
const {container, getByTestId} = renderWithReactIntl(<AddAppointment appConfig={config}/>);
expect(container.querySelector('.bx--search-input')).not.toBeNull();
expect(container.querySelector('.bx--text-input')).not.toBeNull();
expect(container.querySelector('.bx--list-box')).not.toBeNull();
expect(container.querySelectorAll('.bx--list-box').length).toEqual(5);
expect(container.querySelectorAll('.bx--list-box').length).toEqual(6);
expect(getByTestId('patient-search')).not.toBeNull();
expect(getByTestId('service-search')).not.toBeNull();
expect(getByTestId('speciality-search')).not.toBeNull();
Expand Down Expand Up @@ -136,18 +136,17 @@ describe('Add Appointment', () => {

//select patient
const targetPatient = '9DEC74AB 9DEC74B7 (IQ1110)';
const inputBox = container.querySelector('.bx--search-input');
fireEvent.blur(inputBox);
const inputBox = container.querySelector('.bx--text-input');
fireEvent.change(inputBox, { target: { value: "abc" } });
await waitForElement(
() => (container.querySelector('.bx--tile--clickable'))
() => (container.querySelector('.bx--list-box__menu-item'))
);
fireEvent.click(container.querySelector('.bx--tile--clickable'))
fireEvent.click(container.querySelector('.bx--list-box__menu-item'))


//select service
const targetService = 'Physiotherapy OPD';
const inputBoxService = container.querySelector('.bx--text-input');
const inputBoxService = container.querySelectorAll('.bx--text-input')[1];
fireEvent.change(inputBoxService, { target: { value: "Phy" } });
await waitForElement(() => (container.querySelector('.bx--list-box__menu')));
const option = getByText(targetService);
Expand Down Expand Up @@ -494,9 +493,9 @@ describe('Add Appointment', () => {

expect(queryByText("Provider One")).not.toBeNull();
getByText("Please select maximum of 1 provider(s)");
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 200);
jest.runAllTimers();
expect(queryByText("Please select maximum of 1 provider(s)")).toBeNull();
setTimeout(() => {
expect(queryByText("Please select maximum of 1 provider(s)")).toBeNull();
}, 3000);
});

it('should hide service appointment type if enableServiceTypes is undefined', () => {
Expand Down Expand Up @@ -554,10 +553,6 @@ describe('Add Appointment', () => {
expect(dateInputField.value).toBe(selectedDate.format('MM/DD/YYYY'));

});
it('should fetch patient details on load if patient is present in url params', () => {
const {findByText} = renderWithReactIntl(<AddAppointment urlParams={{patient:"6bb24e7e-5c04-4561-9e7a-2d2bbf8074ad"}}/>);
expect(findByText('Test Patient')).not.toBeNull();
});
});

describe('Add appointment with appointment request enabled', () => {
Expand All @@ -566,12 +561,11 @@ describe('Add appointment with appointment request enabled', () => {

const selectPatient = async (container, getByText) => {
const targetPatient = '9DEC74AB 9DEC74B7 (IQ1110)';
const inputBox = container.querySelector('.bx--search-input');
fireEvent.blur(inputBox);
const inputBox = container.querySelector('.bx--text-input');
fireEvent.change(inputBox, { target: { value: "abc" } });
let searchedPatient;
await waitForElement(
() => (searchedPatient = container.querySelector('.bx--tile--clickable'))
() => (searchedPatient = container.querySelector('.bx--list-box__menu-item'))
);
expect(getByText(targetPatient)).toBeTruthy();
fireEvent.click(searchedPatient);
Expand Down Expand Up @@ -627,13 +621,13 @@ describe('Add appointment with appointment request enabled', () => {
});

it('should update the appointment status and provider responses if the AppointmentRequest is Enabled', async () => {
const {container, getByText, getByTestId, queryByText} = renderWithReactIntl(
const {container, queryAllByText, getByText, getByTestId, queryByText} = renderWithReactIntl(
<AppContext.Provider value={{setViewDate: jest.fn()}}>
<AddAppointment appConfig={config} appointmentParams={appointmentTime} currentProvider={currentProvider}/>
</AppContext.Provider>

);
await selectPatient(container, getByText);
await selectPatient(container, queryAllByText);
await selectService(getByTestId, getByText);
await selectProvider(getByTestId, getByText, "Two", "Provider Two");
await selectProvider(getByTestId, getByText, "Three", "Provider Three");
Expand Down Expand Up @@ -678,6 +672,10 @@ describe('Add appointment with appointment request enabled', () => {
expect(appointmentRequestData.providers[0].response).toEqual("ACCEPTED");
expect(appointmentRequestData.providers[1].name).toEqual("Provider Two");
expect(appointmentRequestData.providers[1].response).toEqual("AWAITING");
})
});
});

it('should fetch patient details on load if patient is present in url params', () => {
const {findByText} = renderWithReactIntl(<AddAppointment urlParams={{patient:"6bb24e7e-5c04-4561-9e7a-2d2bbf8074ad"}}/>);
expect(findByText('Test Patient')).not.toBeNull();
});
});
Loading
Loading