Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.IntStream;
import java.util.stream.Stream;

Expand Down Expand Up @@ -38,6 +39,7 @@ public LabwareLabelData getLabelData(Labware labware) {
List<LabelContent> content = labware.getSlots().stream()
.sorted(slotOrder)
.flatMap(slot -> slot.getSamples().stream())
.distinct()
.map(this::getContent)
.collect(toList());
Set<String> mediums = labware.getSlots().stream()
Expand Down Expand Up @@ -425,12 +427,22 @@ public String prefix(LifeStage lifeStage) {

public List<LabelContent> getPlannedContent(List<PlanAction> planActions, Comparator<Slot> slotOrder) {
return planActions.stream()
.filter(distinctPlanSection())
.sorted(Comparator.comparing(PlanAction::getDestination, slotOrder)
.thenComparing(PlanAction::getId))
.map(this::getContent)
.collect(toList());
}

/**
* Creates a filter to dedupe new sections. Doesn't filter out non-sections.
* @return a predicate to filter out plan actions creating the same section
*/
static Predicate<PlanAction> distinctPlanSection() {
final Set<PlanActionKey> keys = new HashSet<>();
return pa -> (nullOrEmpty(pa.getNewSection()) || keys.add(new PlanActionKey(pa)));
}

public LabelContent getContent(PlanAction planAction) {
BioState bs = planAction.getNewBioState();
if (bs==null) {
Expand Down Expand Up @@ -468,4 +480,11 @@ public SimpleContent(Sample sample) {
this(sample.getTissue(), sample.getSection());
}
}

/** The characteristics to dedupe the new section that will be created from a plan action */
record PlanActionKey(Sample parentSample, String section) {
public PlanActionKey(PlanAction pa) {
this(pa.getSample(), pa.getNewSection());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,32 @@ static Stream<Arguments> getContentArgs() {
}).map(Arguments::of);
}

@Test
void testDistinctPlanSection() {
Sample[] samples = EntityFactory.makeSamples(2);
List<PlanAction> pas = List.of(
makePlanAction(1, samples[0], null),
makePlanAction(2, samples[0], null),
makePlanAction(3, samples[1], null),
makePlanAction(4, samples[0], "1a"),
makePlanAction(5, samples[0], "1a"), // this one gets filtered out
makePlanAction(6, samples[1], "1a"),
makePlanAction(7, samples[1], "2b")
);
assertThat(pas.stream()
.filter(LabwareLabelDataService.distinctPlanSection())
.map(PlanAction::getId)
).containsExactly(1, 2, 3, 4, 6, 7);
}

static PlanAction makePlanAction(int id, Sample sam, String newSection) {
PlanAction pa = new PlanAction();
pa.setId(id);
pa.setSample(sam);
pa.setNewSection(newSection);
return pa;
}

private String tissueString(Tissue tissue) {
String prefix = switch (tissue.getDonor().getLifeStage()) {
case paediatric -> "P";
Expand Down
Loading