use of uk.ac.bbsrc.tgac.miso.core.data.SampleSlide in project miso-lims by miso-lims.
the class LimsUtilsTest method testInstanceOfSampleTissueProcessing.
@Test
public void testInstanceOfSampleTissueProcessing() throws Exception {
SampleSlide slide = new SampleSlideImpl();
assertTrue("Slide is a type of Tissue Processing", LimsUtils.isTissueProcessingSample(slide));
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleSlide in project miso-lims by miso-lims.
the class DefaultSampleService method validateReferenceSlide.
private void validateReferenceSlide(DetailedSample sample, List<ValidationError> errors) {
SampleSlide reference = null;
if (isTissuePieceSample(sample)) {
reference = ((SampleTissuePiece) sample).getReferenceSlide();
} else if (isStockSample(sample)) {
reference = ((SampleStock) sample).getReferenceSlide();
} else {
return;
}
if (reference != null) {
Sample tissue = getParent(SampleTissue.class, sample);
Sample referenceTissue = getParent(SampleTissue.class, reference);
if (tissue.getId() != referenceTissue.getId()) {
errors.add(new ValidationError("referenceSlideId", "Reference slide must be derived from the same tissue"));
}
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleSlide in project miso-lims by miso-lims.
the class DefaultSampleService method loadChildEntities.
/**
* Loads persisted objects into sample fields. Should be called before saving new samples. Loads all member objects <b>except</b>
* <ul>
* <li>parent sample for detailed samples</li>
* <li>creator/lastModifier User objects</li>
* </ul>
*
* @param sample the Sample to load entities into. Must contain at least the IDs of objects to load (e.g. to load the persisted Project
* into sample.project, sample.project.id must be set)
* @throws IOException
*/
private void loadChildEntities(Sample sample) throws IOException {
if (sample.getProject() != null) {
sample.setProject(projectStore.get(sample.getProject().getId()));
}
loadChildEntity(sample::setScientificName, sample.getScientificName(), scientificNameService, "scientificNameId");
loadChildEntity(sample::setSequencingControlType, sample.getSequencingControlType(), sequencingControlTypeService, "sequencingControlTypeId");
loadChildEntity(sample::setSop, sample.getSop(), sopService, "sopId");
loadChildEntity(sample::setDetailedQcStatus, sample.getDetailedQcStatus(), detailedQcStatusService, "detailedQcStatusId");
loadChildEntity(sample::setRequisition, sample.getRequisition(), requisitionService, "requisitionId");
if (isDetailedSample(sample)) {
DetailedSample detailed = (DetailedSample) sample;
if (detailed.getSampleClass() != null && detailed.getSampleClass().isSaved()) {
detailed.setSampleClass(sampleClassService.get(detailed.getSampleClass().getId()));
}
if (detailed.getSubproject() != null && detailed.getSubproject().isSaved()) {
detailed.setSubproject(subprojectService.get(detailed.getSubproject().getId()));
}
if (isTissueProcessingSample(detailed)) {
if (detailed instanceof SampleSlide) {
Stain originalStain = ((SampleSlide) detailed).getStain();
Stain stain;
if (originalStain == null) {
stain = null;
} else {
stain = stainService.get(originalStain.getId());
}
((SampleSlide) detailed).setStain(stain);
} else if (detailed instanceof SampleTissuePiece) {
SampleTissuePiece tissuePiece = (SampleTissuePiece) detailed;
tissuePiece.setTissuePieceType(tissuePieceTypeDao.get(tissuePiece.getTissuePieceType().getId()));
if (tissuePiece.getReferenceSlide() != null) {
Sample ref = deproxify(get(tissuePiece.getReferenceSlide().getId()));
tissuePiece.setReferenceSlide((SampleSlide) ref);
}
}
}
if (isAliquotSample(detailed)) {
SampleAliquot sa = (SampleAliquot) detailed;
if (sa.getSamplePurpose() != null && sa.getSamplePurpose().isSaved()) {
sa.setSamplePurpose(samplePurposeDao.get(sa.getSamplePurpose().getId()));
}
}
if (isStockSample(detailed)) {
SampleStock stock = (SampleStock) detailed;
if (stock.getReferenceSlide() != null) {
Sample ref = deproxify(get(stock.getReferenceSlide().getId()));
stock.setReferenceSlide((SampleSlide) ref);
}
}
if (isTissueSample(detailed)) {
SampleTissue st = (SampleTissue) detailed;
if (st.getTissueMaterial() != null && st.getTissueMaterial().isSaved()) {
st.setTissueMaterial(tissueMaterialDao.get(st.getTissueMaterial().getId()));
}
if (st.getTissueOrigin() != null && st.getTissueOrigin().isSaved()) {
st.setTissueOrigin(tissueOriginDao.get(st.getTissueOrigin().getId()));
}
if (st.getTissueType() != null && st.getTissueType().isSaved()) {
st.setTissueType(tissueTypeDao.get(st.getTissueType().getId()));
}
if (st.getLab() != null && st.getLab().isSaved()) {
st.setLab(labService.get(st.getLab().getId()));
}
}
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleSlide in project miso-lims by miso-lims.
the class DefaultSampleService method create.
@Override
public long create(Sample sample) throws IOException {
findOrCreateRequisition(sample);
loadChildEntities(sample);
boxService.throwIfBoxPositionIsFilled(sample);
User changeUser = authorizationManager.getCurrentUser();
sample.setChangeDetails(changeUser);
if (isDetailedSample(sample)) {
DetailedSample detailed = (DetailedSample) sample;
if (!isIdentitySample(sample)) {
// Create a copy of the incoming sample's identity
SampleIdentity identityCopy = getIdentity(detailed);
if (detailed.getParent() == null) {
throw new IllegalArgumentException(ERR_MISSING_PARENT_ID);
}
if (detailed.getParent().isSaved()) {
detailed.setParent((DetailedSample) get(detailed.getParent().getId()));
} else {
try {
setIdentity(detailed);
if (!isIdentitySample(detailed.getParent())) {
detailed.setParent(findOrCreateParent(detailed));
}
} catch (MisoNamingException e) {
throw new ValidationException(e.getMessage());
}
}
addExternalNames(detailed, identityCopy);
validateHierarchy(detailed);
} else {
if (isUniqueExternalNameWithinProjectRequired() && isExternalNameDuplicatedInProject(sample)) {
throw makeDuplicateExternalNameError(((SampleIdentity) sample).getExternalName());
}
}
}
// pre-save field generation
sample.setName(generateTemporaryName());
if (isStringEmptyOrNull(sample.getAlias()) && getNamingScheme(sample).hasSampleAliasGenerator()) {
sample.setAlias(generateTemporaryName());
}
if (sample.getConcentration() == null) {
sample.setConcentrationUnits(null);
}
if (sample.getVolume() == null) {
sample.setVolumeUnits(null);
} else {
sample.setInitialVolume(sample.getVolume());
}
if (isSampleSlide(sample)) {
((SampleSlide) sample).setInitialSlides(((SampleSlide) sample).getSlides());
}
LimsUtils.updateParentVolume(sample, null, changeUser);
updateParentSlides(sample, null, changeUser);
validateChange(sample, null);
long savedId = save(sample, true).getId();
if (sample.getParent() != null) {
sampleStore.update(sample.getParent());
}
boxService.updateBoxableLocation(sample);
if (sample.getCreationReceiptInfo() != null) {
TransferSample transferSample = sample.getCreationReceiptInfo();
Transfer transfer = transferSample.getTransfer();
Transfer existingTransfer = transferService.listByProperties(transfer.getSenderLab(), transfer.getRecipientGroup(), sample.getProject(), transfer.getTransferTime()).stream().max(Comparator.comparing(Transfer::getCreationTime)).orElse(null);
if (existingTransfer != null) {
existingTransfer.getSampleTransfers().add(transferSample);
transferSample.setTransfer(existingTransfer);
transferService.addTransferSample(transferSample);
} else {
transferService.create(transfer);
}
}
// Don't log initial additions to requisition, as that's part of the requisition creation
if (sample.getRequisition() != null && sample.getRequisition().getCreationTime().toInstant().isBefore(Instant.now().minus(1, ChronoUnit.HOURS))) {
addRequisitionSampleChange(sample.getRequisition(), sample, true);
}
return savedId;
}
use of uk.ac.bbsrc.tgac.miso.core.data.SampleSlide in project miso-lims by miso-lims.
the class BulkSampleCreateIT method testCreateOneSlideWithProject.
@Test
public void testCreateOneSlideWithProject() throws Exception {
// Goal: ensure one slide with predefined project can be saved
BulkSamplePage page = getCreatePage(1, projectId, SampleTissueProcessing.CATEGORY_NAME);
HandsOnTable table = page.getTable();
Map<String, String> slide = new LinkedHashMap<>();
slide.put(SamColumns.DESCRIPTION, "Description");
slide.put(SamColumns.RECEIVE_DATE, "2017-07-17");
slide.put(SamColumns.RECEIVED_FROM, "University Health Network - BioBank");
slide.put(SamColumns.RECEIVED_BY, "TestGroupOne");
slide.put(SamColumns.RECEIPT_CONFIRMED, "True");
slide.put(SamColumns.RECEIPT_QC_PASSED, "True");
slide.put(SamColumns.RECEIPT_QC_NOTE, "");
// increment
slide.put(SamColumns.ID_BARCODE, "104");
slide.put(SamColumns.SAMPLE_CLASS, "Slide");
slide.put(SamColumns.SAMPLE_TYPE, "GENOMIC");
slide.put(SamColumns.SCIENTIFIC_NAME, "Homo sapiens");
slide.put(SamColumns.GROUP_ID, "1");
slide.put(SamColumns.GROUP_DESCRIPTION, "Test one");
slide.put(SamColumns.TISSUE_ORIGIN, "Bn (Brain)");
slide.put(SamColumns.TISSUE_TYPE, "P (Primary tumour)");
slide.put(SamColumns.PASSAGE_NUMBER, "");
slide.put(SamColumns.TIMES_RECEIVED, "1");
slide.put(SamColumns.TUBE_NUMBER, "1");
slide.put(SamColumns.SECONDARY_ID, "tube id 1");
slide.put(SamColumns.TISSUE_MATERIAL, "FFPE");
slide.put(SamColumns.REGION, "Medulla oblongata");
slide.put(SamColumns.SLIDES, "7");
slide.put(SamColumns.THICKNESS, "5");
slide.put(SamColumns.STAIN, "Hematoxylin+Eosin");
slide.put(SamColumns.QC_STATUS, "Ready");
slide.forEach((k, v) -> table.enterText(k, 0, v));
// need to enter this here, after project is entered otherwise identity lookup fails
// increment
slide.put(SamColumns.EXTERNAL_NAME, "ext4");
table.enterText(SamColumns.EXTERNAL_NAME, 0, slide.get(SamColumns.EXTERNAL_NAME));
assertIdentityLookupWasSuccessful(table, 0);
assertTrue(page.save(false));
HandsOnTable savedTable = page.getTable();
Long newId = getIdForRow(savedTable, 0);
// verify attributes against what got saved to the database
Project predefined = (Project) getSession().get(ProjectImpl.class, projectId);
SampleSlide created = (SampleSlide) getSession().get(SampleSlideImpl.class, newId);
assertEquals("confirm project", predefined.getShortName(), created.getProject().getShortName());
// everything else should be the same as in testCreateOneSlideNoProject()
}
Aggregations