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

OpenMRS Add pagination #741

Merged
merged 13 commits into from
Sep 11, 2024
Merged

OpenMRS Add pagination #741

merged 13 commits into from
Sep 11, 2024

Conversation

mtuchi
Copy link
Collaborator

@mtuchi mtuchi commented Sep 6, 2024

Description
Add pagination support in openmrs adaptor.

Implementation

  • Add a new helper in openmrs utils autoFetchRequest. For pagination support
  • Add couple of unit test for pagination and other operations
  • Update devDependecies and remove unused decencies

Ref #744

@mtuchi mtuchi changed the title Add cursor, dateFns and pagination openMRS Add cursor, dateFns and pagination Sep 6, 2024
@mtuchi mtuchi changed the title openMRS Add cursor, dateFns and pagination OpenMRS Add cursor, dateFns and pagination Sep 6, 2024
Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

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

There's one code quality issue which I'm going to insist on changing.

But I'm generally not happy that this adaptor has zero tests, and that this PR introduces a lot of code duplication. It's not great.

If you think you can find the time, I would like to see the following changes:

  • pagination logic pushed down to the request helper. It'll paginate any request by default, based on body.links, unless offset is passed in.
  • A set of unit tests on request and paginated requests. Maybe 4-6 tests in total?

If I was doing this, I'd probably ask for half a day. It is not worth spending more than a day on.

packages/openmrs/src/Adaptor.js Outdated Show resolved Hide resolved
packages/openmrs/src/Adaptor.js Outdated Show resolved Hide resolved
@mtuchi mtuchi changed the title OpenMRS Add cursor, dateFns and pagination OpenMRS Add pagination Sep 6, 2024
@mtuchi mtuchi changed the base branch from main to release/openmrs September 9, 2024 06:10
@mtuchi
Copy link
Collaborator Author

mtuchi commented Sep 9, 2024

I have added couple of unit test and move the pagination implementation into util @josephjclark

Copy link
Collaborator

@josephjclark josephjclark left a comment

Choose a reason for hiding this comment

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

I much prefer this approach 👍 And thanks for the extra test coverage. Just a few little comments to address.

packages/openmrs/src/Utils.js Outdated Show resolved Hide resolved
});
logResponse(response);

allResponses
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still needs to be made into an if-else statement.

A ternary expression should always be on the right-hand-side of some expression. It shouldn't be a statement by itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made some improvements for the requestOptions

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah maybe I wasn't clear - I'm talking about this:

if (allResponses) {
  allResponses.body.results.push(...response.body.results)
} else {
  allResponses = response
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks i have update the code accordingly

packages/openmrs/test/index.js Outdated Show resolved Hide resolved
'GET',
'/ws/rest/v1/patient',
{},
{ q: 'Sarah', limit: 1, startIndex: 1 }
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you remove startIndex from this test,, does it still pass?

I'll bet it does - but it shouldn't!

You need to set up the interceptor to return a next page. That way you are properly testing that your adaptor code will ignore the next page IF the startIndex is set

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added the interceptor for the next page

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, ok, but now we still need to assert that only one page was actually fetched. You need to check that body.results.length === 1

Copy link
Collaborator Author

@mtuchi mtuchi Sep 11, 2024

Choose a reason for hiding this comment

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

@josephjclark Done, i have added the assertion for results to be equal to 1

packages/openmrs/test/index.js Show resolved Hide resolved
packages/openmrs/test/index.js Outdated Show resolved Hide resolved
@josephjclark josephjclark merged commit 57d8b55 into release/openmrs Sep 11, 2024
2 checks passed
@josephjclark josephjclark deleted the openmrs-improvements branch September 11, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants