Skip to content

Commit

Permalink
Add more tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kalletlak committed Jul 12, 2023
1 parent fcac80a commit dc487c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,19 @@ public void getShallowSamplesByPatientId() {

@Test
public void hasTreatmentData() {
Boolean actual = treatmentRepository.hasTreatmentData(Collections.singletonList("study_tcga_pub"), ClinicalEventKeyCode.Agent);

Assert.assertEquals(actual, true);

Assert.assertEquals(true, treatmentRepository.hasTreatmentData(Collections.singletonList("study_tcga_pub"), ClinicalEventKeyCode.Agent));

Assert.assertEquals(false, treatmentRepository.hasTreatmentData(Collections.singletonList("acc_tcga"), ClinicalEventKeyCode.Agent));

}

@Test
public void getSampleCount() {
Boolean actual = treatmentRepository.hasSampleTimelineData(Collections.singletonList("study_tcga_pub"));

Assert.assertEquals(actual, true);
public void hasSampleTimelineData() {

Assert.assertEquals(true, treatmentRepository.hasSampleTimelineData(Collections.singletonList("study_tcga_pub")));

Assert.assertEquals(false, treatmentRepository.hasSampleTimelineData(Collections.singletonList("acc_tcga")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.*;

@Service
public class TreatmentServiceImpl implements TreatmentService {
@Autowired
Expand Down Expand Up @@ -163,20 +161,26 @@ public List<PatientTreatmentRow> getAllPatientTreatmentRows(

Map<String, List<Treatment>> treatmentSet = treatmentRepository.getTreatments(sampleIds, studyIds, key)
.stream()
.collect(groupingBy(Treatment::getTreatment));
.collect(Collectors.groupingBy(Treatment::getTreatment));

/*
This logic transforms treatmentSet to list of PatientTreatmentRow. transformation steps:
- key in treatmentSet is going to be treatment
- get all unique patient ids -> this is going to give count
- get all clinicalEventSamples using above unique patient ids
*/
return treatmentSet.entrySet()
.stream()
.map(entry -> {
String treatment = entry.getKey();
Set<String> patientIds = entry.getValue().stream().map(Treatment::getPatientId).collect(toSet());
Set<String> patientIds = entry.getValue().stream().map(Treatment::getPatientId).collect(Collectors.toSet());
Set<ClinicalEventSample> clinicalEventSamples = patientIds
.stream()
.flatMap(patientId -> samplesByPatient.getOrDefault(patientId, new ArrayList<>()).stream())
.collect(toSet());
.collect(Collectors.toSet());
return new PatientTreatmentRow(treatment, patientIds.size(), clinicalEventSamples);
})
.collect(toList());
.collect(Collectors.toList());
}

@Override
Expand Down

0 comments on commit dc487c2

Please sign in to comment.