From 7252bdc4f24d43b1ad850ecd61dd4a337b727f3c Mon Sep 17 00:00:00 2001 From: grapigeau Date: Thu, 14 Nov 2024 09:31:27 -0500 Subject: [PATCH] add qcFailed field to shesmu detailed cases add changelog --- .../on/oicr/gsi/cardea/data/ShesmuSample.java | 16 +++- .../cardea/server/service/CaseService.java | 76 +++++++++++-------- changes/add_qc_failed_field.md | 1 + 3 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 changes/add_qc_failed_field.md diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/ShesmuSample.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/ShesmuSample.java index 274bade..df08ee0 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/ShesmuSample.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/ShesmuSample.java @@ -3,9 +3,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import java.util.Set; - -import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; /** @@ -16,11 +13,13 @@ public class ShesmuSample { private final String id; private final boolean supplemental; + private final boolean qcFailed; private ShesmuSample(Builder builder) { this.id = requireNonNull(builder.id); this.supplemental = requireNonNull(builder.supplemental); + this.qcFailed = requireNonNull(builder.qcFailed); } @@ -32,6 +31,10 @@ public Boolean isSupplemental() { return supplemental; } + public Boolean qcFailed() { + return qcFailed; + } + @JsonPOJOBuilder(withPrefix = "") @@ -39,6 +42,7 @@ public static class Builder { private String id; private boolean supplemental; + private boolean qcFailed; public ShesmuSample build() { return new ShesmuSample(this); @@ -55,5 +59,11 @@ public Builder supplemental(boolean supplemental) { return this; } + public Builder qcFailed(boolean qcFailed) { + this.qcFailed = qcFailed; + return this; + } + + } } diff --git a/cardea-server/src/main/java/ca/on/oicr/gsi/cardea/server/service/CaseService.java b/cardea-server/src/main/java/ca/on/oicr/gsi/cardea/server/service/CaseService.java index d7868ac..9e94f26 100644 --- a/cardea-server/src/main/java/ca/on/oicr/gsi/cardea/server/service/CaseService.java +++ b/cardea-server/src/main/java/ca/on/oicr/gsi/cardea/server/service/CaseService.java @@ -127,44 +127,47 @@ public Set getShesmuCases() { public Set getShesmuDetailedCases() { return caseData.getCases().stream() - .filter(kase -> kase.getTests().stream() - .anyMatch(test -> !test.getFullDepthSequencings().isEmpty() - || test.getLibraryQualifications().stream() - .anyMatch(sample -> sample.getRun() != null))) - .map(kase -> convertCaseToShesmuDetailedCase(kase)) - .collect(Collectors.toSet()); + .filter(kase -> kase.getTests().stream() + .anyMatch(test -> !test.getFullDepthSequencings().isEmpty() + || test.getLibraryQualifications().stream() + .anyMatch(sample -> sample.getRun() != null))) + .map(kase -> convertCaseToShesmuDetailedCase(kase)) + .collect(Collectors.toSet()); } - private Set getSequencingForShesmuCase(Case kase){ + private Set getSequencingForShesmuCase(Case kase) { Set sequencings = new HashSet<>(); final long reqId = kase.getRequisition().getId(); for (Test test : kase.getTests()) { - ShesmuSequencing fullDepthSeq = makeShesmuSequencing(test.getFullDepthSequencings(), MetricCategory.FULL_DEPTH_SEQUENCING, reqId, test.getName()); + ShesmuSequencing fullDepthSeq = makeShesmuSequencing(test.getFullDepthSequencings(), + MetricCategory.FULL_DEPTH_SEQUENCING, reqId, test.getName()); if (fullDepthSeq != null) { sequencings.add(fullDepthSeq); } - ShesmuSequencing libraryQual = makeShesmuSequencing(test.getLibraryQualifications(), MetricCategory.LIBRARY_QUALIFICATION, reqId, test.getName()); + ShesmuSequencing libraryQual = makeShesmuSequencing(test.getLibraryQualifications(), + MetricCategory.LIBRARY_QUALIFICATION, reqId, test.getName()); if (libraryQual != null) { sequencings.add(libraryQual); } - }; + } ; return sequencings; } - private ShesmuSequencing makeShesmuSequencing(List samples, MetricCategory type, long reqId, String name){ + private ShesmuSequencing makeShesmuSequencing(List samples, MetricCategory type, + long reqId, String name) { Set shesmuSamples = new HashSet<>(); boolean hasPassed = false; boolean hasWaiting = false; - for (Sample sample : samples){ + for (Sample sample : samples) { - if (sample.getDataReviewPassed() == null || sample.getQcPassed() == null){ + if (sample.getDataReviewPassed() == null || sample.getQcPassed() == null) { hasWaiting = true; } else if (sample.getDataReviewPassed() && sample.getQcPassed()) { hasPassed = true; @@ -172,9 +175,10 @@ private ShesmuSequencing makeShesmuSequencing(List samples, MetricCatego if (!(sample.getRun() == null && type.equals(MetricCategory.LIBRARY_QUALIFICATION))) { shesmuSamples.add(new ShesmuSample.Builder() - .id(sample.getId()) - .supplemental(!Objects.equals(sample.getRequisitionId(), reqId)) - .build()); + .id(sample.getId()) + .supplemental(!Objects.equals(sample.getRequisitionId(), reqId)) + .qcFailed(getQcFailed(sample)) + .build()); } } @@ -182,11 +186,19 @@ private ShesmuSequencing makeShesmuSequencing(List samples, MetricCatego return null; } return new ShesmuSequencing.Builder() - .test(name) - .limsIds(shesmuSamples) - .complete((hasPassed && !hasWaiting)) - .type(type) - .build(); + .test(name) + .limsIds(shesmuSamples) + .complete((hasPassed && !hasWaiting)) + .type(type) + .build(); + } + + private boolean getQcFailed(Sample sample) { + Run run = sample.getRun(); + return (!(sample.getDataReviewPassed() == null || sample.getDataReviewPassed()) + && !(sample.getQcPassed() == null || sample.getQcPassed()) + && !(run.getDataReviewPassed() == null || run.getDataReviewPassed()) + && !(run.getQcPassed() == null || run.getQcPassed())); } private Set getLimsIusIdsForShesmu(Case kase) { @@ -242,17 +254,17 @@ private ShesmuCase convertCaseToShesmuCase(Case kase) { private ShesmuDetailedCase convertCaseToShesmuDetailedCase(Case kase) { return new ShesmuDetailedCase.Builder() - .assayName(caseData.getAssaysById().get(kase.getAssayId()).getName()) - .assayVersion(caseData.getAssaysById().get(kase.getAssayId()).getVersion()) - .caseIdentifier(kase.getId()) - .caseStatus(getCaseStatus(kase)) - .paused(kase.getRequisition().isPaused()) - .stopped(kase.getRequisition().isStopped()) - .completedDateLocal(getCompletedDate(kase)) - .requisitionId(kase.getRequisition().getId()) - .requisitionName(kase.getRequisition().getName()) - .sequencing(getSequencingForShesmuCase(kase)) - .build(); + .assayName(caseData.getAssaysById().get(kase.getAssayId()).getName()) + .assayVersion(caseData.getAssaysById().get(kase.getAssayId()).getVersion()) + .caseIdentifier(kase.getId()) + .caseStatus(getCaseStatus(kase)) + .paused(kase.getRequisition().isPaused()) + .stopped(kase.getRequisition().isStopped()) + .completedDateLocal(getCompletedDate(kase)) + .requisitionId(kase.getRequisition().getId()) + .requisitionName(kase.getRequisition().getName()) + .sequencing(getSequencingForShesmuCase(kase)) + .build(); } @Scheduled(fixedDelay = 1L, timeUnit = TimeUnit.MINUTES) diff --git a/changes/add_qc_failed_field.md b/changes/add_qc_failed_field.md new file mode 100644 index 0000000..ba89108 --- /dev/null +++ b/changes/add_qc_failed_field.md @@ -0,0 +1 @@ +Field qcFailed on shesmu detailed cases \ No newline at end of file