Skip to content

Commit

Permalink
Extend database and domain for 'analysis performed' and 'comment' (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-such-code authored Jul 13, 2023
1 parent 0f79b44 commit 400e866
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class SamplePreview {
private String bioReplicateLabel;
@Column(name = "label")
private String sampleLabel;
private String comment;
@Column(name = "analysis_type")
private String analysisType;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "experimentalGroupId")
private ExperimentalGroup experimentalGroup;
Expand All @@ -58,7 +61,7 @@ protected SamplePreview() {
private SamplePreview(ExperimentId experimentId, SampleId sampleId, String sampleCode,
String batchLabel, String bioReplicateLabel,
String sampleLabel, ExperimentalGroup experimentalGroup, String species, String specimen,
String analyte) {
String analyte, String analysisType, String comment) {
Objects.requireNonNull(experimentId);
Objects.requireNonNull(sampleId);
Objects.requireNonNull(sampleCode);
Expand All @@ -79,6 +82,9 @@ private SamplePreview(ExperimentId experimentId, SampleId sampleId, String sampl
this.species = species;
this.specimen = specimen;
this.analyte = analyte;
// optional columns
this.comment = comment;
this.analysisType = analysisType;
}

/**
Expand All @@ -100,15 +106,17 @@ private SamplePreview(ExperimentId experimentId, SampleId sampleId, String sampl
* preview
* @param analyte the {@link Analyte} for the {@link Sample} associated with this
* preview
* @param analysisType the type of analysis to be performed for this {@link Sample}
* @param comment an optional comment pertaining to the associated {@link Sample}
* @return the sample preview
*/
public static SamplePreview create(ExperimentId experimentId, SampleId sampleId,
String sampleCode,
String batchLabel, String bioReplicateLabel,
String sampleLabel, ExperimentalGroup experimentalGroup, String species, String specimen,
String analyte) {
String analyte, String analysisType, String comment) {
return new SamplePreview(experimentId, sampleId, sampleCode, batchLabel, bioReplicateLabel,
sampleLabel, experimentalGroup, species, specimen, analyte);
sampleLabel, experimentalGroup, species, specimen, analyte, analysisType, comment);
}

public ExperimentId experimentId() {
Expand Down Expand Up @@ -146,6 +154,12 @@ public String specimen() {
public String analyte() {
return analyte;
}
public String analysisType() {
return analysisType;
}
public String comment() {
return comment;
}

public ExperimentalGroup experimentalGroup() {
return experimentalGroup;
Expand All @@ -167,14 +181,15 @@ public boolean equals(Object o) {
that.sampleLabel)
&& Objects.equals(species, that.species) && Objects.equals(specimen,
that.specimen) && Objects.equals(analyte, that.analyte) && Objects.equals(
experimentalGroup, that.experimentalGroup);
experimentalGroup, that.experimentalGroup) && Objects.equals(analysisType,
that.analysisType) && Objects.equals(comment, that.comment);
}

@Override
public int hashCode() {
return Objects.hash(experimentId, sampleCode, sampleId, batchLabel, bioReplicateLabel,
sampleLabel,
species, specimen, analyte, experimentalGroup);
species, specimen, analyte, experimentalGroup, analysisType, comment);
}

@Override
Expand All @@ -189,6 +204,8 @@ public String toString() {
", species='" + species + '\'' +
", specimen='" + specimen + '\'' +
", analyte='" + analyte + '\'' +
", analysisType='" + analysisType + '\'' +
", comment='" + comment + '\'' +
", conditions=" + experimentalGroup +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import java.util.Objects;
import java.util.Optional;
import life.qbic.projectmanagement.domain.project.experiment.BiologicalReplicateId;
import life.qbic.projectmanagement.domain.project.experiment.ExperimentId;

Expand Down Expand Up @@ -37,14 +38,17 @@ public class Sample {
@AttributeOverride(name = "uuid", column = @Column(name = "sample_id"))
private SampleId id;
private String label;
private String comment;
@Column(name = "analysis_type")
private String analysisType;
@Embedded
private SampleCode sampleCode;
@Embedded
private SampleOrigin sampleOrigin;

private Sample(SampleId id, SampleCode sampleCode, BatchId assignedBatch, String label,
ExperimentId experimentId, Long experimentalGroupId, SampleOrigin sampleOrigin,
BiologicalReplicateId replicateReference
BiologicalReplicateId replicateReference, String analysisType, String comment
) {
this.id = id;
this.sampleCode = Objects.requireNonNull(sampleCode);
Expand All @@ -54,6 +58,8 @@ private Sample(SampleId id, SampleCode sampleCode, BatchId assignedBatch, String
this.sampleOrigin = sampleOrigin;
this.biologicalReplicateId = replicateReference;
this.assignedBatch = assignedBatch;
this.analysisType = analysisType;
this.comment = comment;
}

protected Sample() {
Expand All @@ -75,7 +81,8 @@ public static Sample create(
sampleRegistrationRequest.assignedBatch(),
sampleRegistrationRequest.label(), sampleRegistrationRequest.experimentId(),
sampleRegistrationRequest.experimentalGroupId(),
sampleRegistrationRequest.sampleOrigin(), sampleRegistrationRequest.replicateReference());
sampleRegistrationRequest.sampleOrigin(), sampleRegistrationRequest.replicateReference(),
sampleRegistrationRequest.analysisType(), sampleRegistrationRequest.comment());
}

public BatchId assignedBatch() {
Expand All @@ -98,6 +105,14 @@ public String label() {
return this.label;
}

public Optional<String> analysisType() {
return Optional.ofNullable(analysisType);
}

public Optional<String> comment() {
return Optional.ofNullable(comment);
}

public Long experimentalGroupId() {
return this.experimentalGroupId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package life.qbic.projectmanagement.domain.project.sample;

import java.util.Objects;
import java.util.Optional;
import life.qbic.projectmanagement.domain.project.experiment.BiologicalReplicateId;
import life.qbic.projectmanagement.domain.project.experiment.ExperimentId;

Expand All @@ -15,21 +16,26 @@
* @param experimentalGroupId the experimental group id the sample is part of
* @param replicateReference the biological replicated reference the sample has been taken from
* @param sampleOrigin information about the sample origin.
* @param analysisType analysis to be performed
* @param comment comment relating to the sample
* @since 1.0.0
*/
public record SampleRegistrationRequest(String label, BatchId assignedBatch,
ExperimentId experimentId, Long experimentalGroupId,
BiologicalReplicateId replicateReference,
SampleOrigin sampleOrigin) {
SampleOrigin sampleOrigin, String analysisType, String comment) {

public SampleRegistrationRequest(String label, BatchId assignedBatch, ExperimentId experimentId,
Long experimentalGroupId, BiologicalReplicateId replicateReference,
SampleOrigin sampleOrigin) {
SampleOrigin sampleOrigin, String analysisType, String comment) {
this.label = Objects.requireNonNull(label);
this.assignedBatch = Objects.requireNonNull(assignedBatch);
this.experimentId = Objects.requireNonNull(experimentId);
this.experimentalGroupId = Objects.requireNonNull(experimentalGroupId);
this.replicateReference = Objects.requireNonNull(replicateReference);
this.sampleOrigin = Objects.requireNonNull(sampleOrigin);
this.comment = comment;
this.analysisType = analysisType;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SampleRegistrationServiceSpec extends Specification {
def "Invalid SampleRegistrationRequests returns a Result containing a SAMPLE_REGISTRATION_FAILED response code"() {
given:
SampleOrigin sampleOrigin = SampleOrigin.create(new Species("species"), new Specimen("specimen"), new Analyte("analyte"))
SampleRegistrationRequest sampleRegistrationRequest = new SampleRegistrationRequest("my_label", BatchId.create(), ExperimentId.create(), 5, BiologicalReplicateId.create(), sampleOrigin)
SampleRegistrationRequest sampleRegistrationRequest = new SampleRegistrationRequest("my_label", BatchId.create(), ExperimentId.create(), 5, BiologicalReplicateId.create(), sampleOrigin, "mytype", "no comment")
SampleCode sampleCode = SampleCode.create("QABCDE")
sampleCodeService.generateFor(projectId) >> Result.fromValue(sampleCode)
Map<SampleCode, SampleRegistrationRequest> sampleCodesToRegistrationRequests = new HashMap<>()
Expand All @@ -53,7 +53,7 @@ class SampleRegistrationServiceSpec extends Specification {
def "Valid SampleRegistrationRequests returns a Result with the list of registered Samples"() {
given:
SampleOrigin sampleOrigin = SampleOrigin.create(new Species("species"), new Specimen("specimen"), new Analyte("analyte"))
SampleRegistrationRequest sampleRegistrationRequest = new SampleRegistrationRequest("my_label", BatchId.create(), ExperimentId.create(), 4, BiologicalReplicateId.create(), sampleOrigin)
SampleRegistrationRequest sampleRegistrationRequest = new SampleRegistrationRequest("my_label", BatchId.create(), ExperimentId.create(), 4, BiologicalReplicateId.create(), sampleOrigin, "this analysis type", "a comment")
SampleCode sampleCode = SampleCode.create("QABCDE")
Sample sample = Sample.create(sampleCode, sampleRegistrationRequest)
sampleCodeService.generateFor(projectId) >> Result.fromValue(sampleCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SampleDomainServiceSpec extends Specification {

def "When a sample has been successfully registered, a sample registered event is dispatched"() {
given:
Sample testSample = Sample.create(SampleCode.create("test"), new SampleRegistrationRequest("test sample", BatchId.create(), ExperimentId.create(), 1L, BiologicalReplicateId.create(), new SampleOrigin(new Species("test"), new Specimen("test"), new Analyte("test"))))
Sample testSample = Sample.create(SampleCode.create("test"), new SampleRegistrationRequest("test sample", BatchId.create(), ExperimentId.create(), 1L, BiologicalReplicateId.create(), new SampleOrigin(new Species("test"), new Specimen("test"), new Analyte("test")), "DNA analysis", ""))

and:
SampleRepository testRepo = Mock(SampleRepository)
Expand Down Expand Up @@ -54,7 +54,7 @@ class SampleDomainServiceSpec extends Specification {

when:
Result<Sample, SampleDomainService.ResponseCode> result = sampleDomainService.registerSample(SampleCode.create("test"),
new SampleRegistrationRequest("test sample", BatchId.create(), ExperimentId.create(), 1L, BiologicalReplicateId.create(), new SampleOrigin(new Species("test"), new Specimen("test"), new Analyte("test"))))
new SampleRegistrationRequest("test sample", BatchId.create(), ExperimentId.create(), 1L, BiologicalReplicateId.create(), new SampleOrigin(new Species("test"), new Specimen("test"), new Analyte("test")), "DNA analysis", ""))

then:
sampleRegistered.batchIdOfEvent.equals(result.getValue().assignedBatch())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* Sample Overview Component
* <p>
* Component embedded within the {@link SampleInformationPage} in the {@link ProjectViewPage}. It
* allows the user to see the information associated for all {@link Batch} and {@link Sample} of
* allows the user to see the information associated for each {@link Batch} and {@link Sample} of
* each
* {@link Experiment within a {@link life.qbic.projectmanagement.domain.project.Project}
* Additionally it enables the user to register new {@link Batch} and {@link Sample} via the
Expand Down Expand Up @@ -289,6 +289,8 @@ private Grid<SamplePreview> createSampleGrid() {
sampleGrid.addColumn(SamplePreview::species).setHeader("Species");
sampleGrid.addColumn(SamplePreview::specimen).setHeader("Specimen");
sampleGrid.addColumn(SamplePreview::analyte).setHeader("Analyte");
sampleGrid.addColumn(SamplePreview::analysisType).setHeader("Analysis to Perform");
sampleGrid.addColumn(SamplePreview::comment).setHeader("Comment");
return sampleGrid;
}

Expand Down Expand Up @@ -377,7 +379,8 @@ private List<SampleRegistrationRequest> createSampleRegistrationRequests(BatchId
return new SampleRegistrationRequest(sampleRegistrationContent.label(), batchId,
experimentId,
sampleRegistrationContent.experimentalGroupId(),
sampleRegistrationContent.biologicalReplicateId(), sampleOrigin);
sampleRegistrationContent.biologicalReplicateId(), sampleOrigin,
sampleRegistrationContent.analysisType(), sampleRegistrationContent.comment());
}).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* @param species String representation of the {@link Species}
* @param specimen String representation of the {@link Specimen}
* @param analyte String representation of the {@link Analyte}
* @param analysisType The analysis to be performed
* @param comment Sample specific comments
*/

public record SampleRegistrationContent(String label, BiologicalReplicateId biologicalReplicateId,
Long experimentalGroupId,
String species, String specimen, String analyte,
String species, String specimen, String analyte, String analysisType,
String comment) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private List<SampleRegistrationContent> getContent() {
SampleRegistrationContent sampleRegistrationContent = new SampleRegistrationContent(
row.sampleLabel(), row.bioReplicateID(), row.experimentalGroupId(), row.species(),
row.specimen(),
row.analyte(), row.customerComment());
row.analyte(), row.analysisType(), row.customerComment());
samplesToRegister.add(sampleRegistrationContent);
});
return samplesToRegister;
Expand Down

0 comments on commit 400e866

Please sign in to comment.