Search in sources :

Example 6 with SampleSlide

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));
}
Also used : SampleSlideImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleSlideImpl) SampleSlide(uk.ac.bbsrc.tgac.miso.core.data.SampleSlide) Test(org.junit.Test)

Example 7 with SampleSlide

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"));
        }
    }
}
Also used : DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) SampleSlide(uk.ac.bbsrc.tgac.miso.core.data.SampleSlide) ValidationError(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationError) SampleStock(uk.ac.bbsrc.tgac.miso.core.data.SampleStock)

Example 8 with SampleSlide

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()));
            }
        }
    }
}
Also used : SampleTissue(uk.ac.bbsrc.tgac.miso.core.data.SampleTissue) Stain(uk.ac.bbsrc.tgac.miso.core.data.Stain) SampleAliquot(uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) SampleSlide(uk.ac.bbsrc.tgac.miso.core.data.SampleSlide) SampleTissuePiece(uk.ac.bbsrc.tgac.miso.core.data.SampleTissuePiece) SampleStock(uk.ac.bbsrc.tgac.miso.core.data.SampleStock)

Example 9 with SampleSlide

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;
}
Also used : User(com.eaglegenomics.simlims.core.User) ValidationException(uk.ac.bbsrc.tgac.miso.core.service.exception.ValidationException) SampleIdentity(uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity) DetailedSample(uk.ac.bbsrc.tgac.miso.core.data.DetailedSample) SampleSlide(uk.ac.bbsrc.tgac.miso.core.data.SampleSlide) Transfer(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.Transfer) TransferSample(uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample) MisoNamingException(uk.ac.bbsrc.tgac.miso.core.exception.MisoNamingException)

Example 10 with SampleSlide

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()
}
Also used : SampleSlideImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.SampleSlideImpl) Project(uk.ac.bbsrc.tgac.miso.core.data.Project) HandsOnTable(uk.ac.bbsrc.tgac.miso.webapp.integrationtest.page.element.HandsOnTable) ProjectImpl(uk.ac.bbsrc.tgac.miso.core.data.impl.ProjectImpl) SampleSlide(uk.ac.bbsrc.tgac.miso.core.data.SampleSlide) BulkSamplePage(uk.ac.bbsrc.tgac.miso.webapp.integrationtest.page.BulkSamplePage) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

SampleSlide (uk.ac.bbsrc.tgac.miso.core.data.SampleSlide)10 SampleSlideImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.SampleSlideImpl)5 DetailedSample (uk.ac.bbsrc.tgac.miso.core.data.DetailedSample)4 SampleStock (uk.ac.bbsrc.tgac.miso.core.data.SampleStock)3 TransferSample (uk.ac.bbsrc.tgac.miso.core.data.impl.transfer.TransferSample)3 Test (org.junit.Test)2 Sample (uk.ac.bbsrc.tgac.miso.core.data.Sample)2 SampleTissue (uk.ac.bbsrc.tgac.miso.core.data.SampleTissue)2 Stain (uk.ac.bbsrc.tgac.miso.core.data.Stain)2 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)1 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)1 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)1 User (com.eaglegenomics.simlims.core.User)1 LinkedHashMap (java.util.LinkedHashMap)1 Project (uk.ac.bbsrc.tgac.miso.core.data.Project)1 SampleAliquot (uk.ac.bbsrc.tgac.miso.core.data.SampleAliquot)1 SampleIdentity (uk.ac.bbsrc.tgac.miso.core.data.SampleIdentity)1 SampleTissuePiece (uk.ac.bbsrc.tgac.miso.core.data.SampleTissuePiece)1 DetailedSampleImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.DetailedSampleImpl)1 ProjectImpl (uk.ac.bbsrc.tgac.miso.core.data.impl.ProjectImpl)1