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

(rebased) Refactor sort/search/pagination for ClinicalData table endpoint #10766

Closed
wants to merge 1 commit into from

Conversation

dippindots
Copy link
Member

Fix # (see https://help.github.com/en/articles/closing-issues-using-keywords)

Describe changes proposed in this pull request:

  • a
  • b

Checks

Any screenshots or GIFs?

If this is a new visual feature please add a before/after screenshot or gif
here with e.g. Giphy CAPTURE or Peek

Notify reviewers

Read our Pull request merging
policy
. It can help to figure out who worked on the
file before you. Please use git blame <filename> to determine that
and notify them either through slack or by assigning them as a reviewer on the PR

@dippindots dippindots force-pushed the demo-fix-clinical-table-sorting-rebase branch from 0efc4e7 to 5d3077f Compare April 22, 2024 20:27
Copy link

sonarcloud bot commented Apr 22, 2024

Copy link
Collaborator

@haynescd haynescd left a comment

Choose a reason for hiding this comment

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

Also some sonarCloud issues to relove

import org.springframework.stereotype.Component;

@Component
public class PaginationCalculator {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a util class. Should not be injected. Use Static methods


@Override
public List<CancerStudy> getAllStudies(String keyword, String projection, Integer pageSize, Integer pageNumber,
String sortBy, String direction) {

return studyMapper.getStudies(null, keyword, projection, pageSize, offsetCalculator.calculate(pageSize, pageNumber),
return studyMapper.getStudies(null, keyword, projection, pageSize, paginationCalculator.offset(pageSize, pageNumber),
Copy link
Collaborator

Choose a reason for hiding this comment

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

PaginationCalculator::offset(pageSize, pageNumber)

Comment on lines +256 to +272
// Apply pagination to the sampleId list.
Integer toIndex = paginationCalculator.lastIndex(offset, pageSize, allSampleInternalIds.size());
List<Integer> visibleSampleInternalIds = allSampleInternalIds.subList(offset, toIndex);

List<ClinicalData> sampleClinicalData = clinicalDataRepository.getSampleClinicalDataBySampleInternalIds(
visibleSampleInternalIds
);
List<ClinicalData> patientClinicalData = clinicalDataRepository.getPatientClinicalDataBySampleInternalIds(
visibleSampleInternalIds
);

// Merge sample and patient level clinical data and key by unique sample-key.
sampleClinicalDataCollection.setByUniqueSampleKey(
Stream.concat(sampleClinicalData.stream(), patientClinicalData.stream())
.collect(Collectors.groupingBy(clinicalDatum ->
calculateBase64(clinicalDatum.getSampleId(), clinicalDatum.getStudyId())
)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just from observation. Our functions are usually bigger than they need to be. We should start focusing on keeping them small. With that, I would extract this out into a fn maybe buildSampleClinicalDataCollection


import java.util.Base64;

public class Encoding {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Encoder would be a better name

import java.util.List;
import java.util.Map;

public class SampleClinicalDataCollection {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably should start making Models not returned by MyBatis (Java Objs created by query results... Persistence layer) Immutable.

I would suggest making the class immutable (using a Builder Pattern to build the object)

@JREastonMarks
Copy link
Contributor

Weren't most, if not all, of these fixed with @fuzhaoyuan PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

These should not be added

@inodb
Copy link
Member

inodb commented May 2, 2024

Correct @JREastonMarks - I think this is superseded by: #10407

@inodb inodb closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants