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
7 changes: 7 additions & 0 deletions model/src/main/java/org/mskcc/smile/model/SmileSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public void applyIgoLimsUpdates(SampleMetadata sampleMetadata) throws ParseExcep
SampleMetadata latestSampleMetadata = getLatestSampleMetadata();

sampleMetadata.setId(null);
this.sampleClass = latestSampleMetadata.getTumorOrNormal();
sampleMetadata.setCmoPatientId(latestSampleMetadata.getCmoPatientId());
sampleMetadata.setInvestigatorSampleId(latestSampleMetadata.getInvestigatorSampleId());
sampleMetadata.setSampleName(latestSampleMetadata.getSampleName());
Expand All @@ -205,8 +206,14 @@ public void applyIgoLimsUpdates(SampleMetadata sampleMetadata) throws ParseExcep
addSampleMetadata(sampleMetadata);
}

/**
* Updates sample instance with given metadata.
* @param sampleMetadata
* @throws ParseException
*/
public void updateSampleMetadata(SampleMetadata sampleMetadata) throws ParseException {
sampleMetadata.setId(null);
this.sampleClass = sampleMetadata.getTumorOrNormal();
addSampleMetadata(sampleMetadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ List<SmileSample> getSamplesByCategoryAndCmoPatientId(String cmoPatientId,
List<String> getSamplePrimaryIdsBySmileTempoIds(List<UUID> smileTempoIds) throws Exception;
String getSamplePrimaryIdBySampleInputId(String inputId) throws Exception;
Map<String, Object> getMatchedAndUnmatchedInputSampleIds(List<String> inputIds) throws Exception;
void setSampleRevisableTrue(UUID smileSampleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void run() {
+ smileSample.getPrimarySampleAlias());

sampleService.saveSmileSample(smileSample);
sampleService.setSampleRevisableTrue(smileSample.getSmileSampleId());
LOG.info("Publishing metadata history for new sample: "
+ smileSample.getPrimarySampleAlias());
messagingGateway.publish(CONS_DMP_NEW_SAMPLE_TOPIC,
Expand All @@ -133,6 +134,7 @@ public void run() {
+ smileSample.getPrimarySampleAlias());
existingSample.updateSampleMetadata(smileSample.getLatestSampleMetadata());
sampleService.saveSmileSample(existingSample);
sampleService.setSampleRevisableTrue(existingSample.getSmileSampleId());
messagingGateway.publish(CONS_DMP_SAMPLE_UPDATE_TOPIC,
mapper.writeValueAsString(smileSample));
} else {
Expand Down Expand Up @@ -176,6 +178,7 @@ public void run() {
+ smileSample.getPrimarySampleAlias());

sampleService.saveSmileSample(smileSample);
sampleService.setSampleRevisableTrue(smileSample.getSmileSampleId());
LOG.info("Publishing metadata history for new sample: "
+ smileSample.getPrimarySampleAlias());
messagingGateway.publish(CONS_DMP_NEW_SAMPLE_TOPIC,
Expand All @@ -187,6 +190,7 @@ public void run() {
+ smileSample.getPrimarySampleAlias());
existingSample.updateSampleMetadata(smileSample.getLatestSampleMetadata());
sampleService.saveSmileSample(existingSample);
sampleService.setSampleRevisableTrue(existingSample.getSmileSampleId());
messagingGateway.publish(CONS_DMP_SAMPLE_UPDATE_TOPIC,
mapper.writeValueAsString(smileSample));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public void run() {
// the cmo patient id we are swapping to
sample.updateSampleMetadata(updatedMetadata);
sampleService.saveSmileSample(sample);
sampleService.setSampleRevisableTrue(sample.getSmileSampleId());
}

// sample service is handling patient swapping now so we can simply rely on deleting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void setupPatientSamplesHandler(Gateway gateway,
gateway.replySub(PATIENT_SAMPLES_REQREPLY_TOPIC, new MessageConsumer() {
@Override
public void onMessage(Message msg, Object message) {
LOG.info("Received message on topic: " + PATIENT_SAMPLES_REQREPLY_TOPIC);
LOG.debug("Received message on topic: " + PATIENT_SAMPLES_REQREPLY_TOPIC);
try {
if (StringUtils.isBlank(new String(msg.getData()))) {
LOG.error("Expected a patient ID but message received is empty: " + msg
Expand All @@ -353,7 +353,7 @@ private void setupSamplesByCmoLabelHandler(Gateway gateway,
gateway.replySub(SAMPLES_BY_CMO_LABEL_REQREPLY_TOPIC, new MessageConsumer() {
@Override
public void onMessage(Message msg, Object message) {
LOG.info("Received message on topic: " + SAMPLES_BY_CMO_LABEL_REQREPLY_TOPIC);
LOG.debug("Received message on topic: " + SAMPLES_BY_CMO_LABEL_REQREPLY_TOPIC);
try {
if (StringUtils.isBlank(new String(msg.getData()))) {
LOG.error("Expected a CMO label but message received is empty: " + msg
Expand All @@ -375,7 +375,7 @@ private void setupSamplesByAltIdHandler(Gateway gateway,
gateway.replySub(SAMPLES_BY_ALT_ID_REQREPLY_TOPIC, new MessageConsumer() {
@Override
public void onMessage(Message msg, Object message) {
LOG.info("Received message on topic: " + SAMPLES_BY_ALT_ID_REQREPLY_TOPIC);
LOG.debug("Received message on topic: " + SAMPLES_BY_ALT_ID_REQREPLY_TOPIC);
try {
if (StringUtils.isBlank(new String(msg.getData()))) {
LOG.error("Expected an alt ID but message received is empty: " + msg
Expand All @@ -397,7 +397,7 @@ private void setupPatientIdMappingHandler(Gateway gateway,
gateway.replySub(PATIENT_MAPPING_REQREPLY_TOPIC, new MessageConsumer() {
@Override
public void onMessage(Message msg, Object message) {
LOG.info("Received message on topic: " + PATIENT_MAPPING_REQREPLY_TOPIC);
LOG.debug("Received message on topic: " + PATIENT_MAPPING_REQREPLY_TOPIC);
try {
requestReplyHandlingServiceImpl.patientIdMappingHandler(
new String(msg.getData()), msg.getReplyTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public Boolean saveRequest(SmileRequest request) throws Exception {
for (SmileSample s: request.getSmileSampleList()) {
// considering adding the patientService.savePatient() stuff here
// and remove from the sample service.
updatedSamples.add(sampleService.saveSmileSample(s));
sampleService.saveSmileSample(s);
sampleService.setSampleRevisableTrue(s.getSmileSampleId());
updatedSamples.add(s);
}
request.setSmileSampleList(updatedSamples);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ public void run() {
100, TimeUnit.MILLISECONDS);
if (sampleMetadataEntry != null) {
// Boolean arg in updateSampleMetadata refers to fromLims
SmileSample existingSample = sampleService.getResearchSampleByRequestAndIgoId(
sampleMetadataEntry.getValue().getIgoRequestId(),
sampleMetadataEntry.getValue().getPrimaryId());
Boolean fromLims = sampleMetadataEntry.getKey();
if (sampleService.updateSampleMetadata(sampleMetadataEntry.getValue(),
sampleMetadataEntry.getKey())) {
SmileSample existingSample = sampleService.getResearchSampleByRequestAndIgoId(
sampleMetadataEntry.getValue().getIgoRequestId(),
sampleMetadataEntry.getValue().getPrimaryId());
fromLims)) {
// temp patch to avoid deep-nested circular writing of
// sample -> tempo - > sample etc.
// tempo isn't needed when publishing sample metadata history
Expand All @@ -265,6 +266,7 @@ public void run() {
Arrays.asList(sampleMetadataEntry.getValue().getPrimaryId()));
}
}
sampleService.setSampleRevisableTrue(existingSample.getSmileSampleId());
}
if (interrupted && researchSampleUpdateQueue.isEmpty()) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public SmileSample saveSmileSample(SmileSample

// If there is a TumorOrNormal update in SampleMetadata level,
// then sampleClass should also be updated in the SmileSample level
if (!existingSample.getSampleClass().equals(sampleMetadata.getTumorOrNormal())) {
if (StringUtils.isBlank(existingSample.getSampleClass())
|| !existingSample.getSampleClass().equals(sampleMetadata.getTumorOrNormal())) {
existingSample.setSampleClass(sampleMetadata.getTumorOrNormal());
}

Expand Down Expand Up @@ -128,8 +129,6 @@ public SmileSample saveSmileSample(SmileSample
sampleRepository.save(existingSample);
toReturn = existingSample;
}
// update revisable to true for sample
sampleRepository.updateRevisableBySampleId(toReturn.getSmileSampleId(), Boolean.TRUE);
return toReturn;
}

Expand Down Expand Up @@ -292,14 +291,6 @@ public Boolean updateSampleMetadata(SampleMetadata sampleMetadata, Boolean fromL
saveSmileSample(existingSample);
return Boolean.TRUE;
}
// if sample revisable is false then return true so that message handler
// publishes message downstream (allows dashboard to make changes to db directly
// without having to wait or poll for updates)
if (!existingSample.getRevisable()) {
sampleRepository.updateRevisableBySampleId(existingSample.getSmileSampleId(), Boolean.TRUE);
return Boolean.TRUE;
}

// no updates to persist to sample, log and return false
LOG.info("There are no updates to persist for sample: "
+ sampleMetadata.getPrimaryId());
Expand Down Expand Up @@ -359,32 +350,34 @@ public List<SampleMetadata> getResearchSampleMetadataHistoryByIgoId(String igoId
}

@Override
public Boolean sampleHasMetadataUpdates(SampleMetadata existingSampleMetadata,
SampleMetadata sampleMetadata, Boolean isResearchSample, Boolean fromLims) throws Exception {
String existingMetadata = mapper.writeValueAsString(existingSampleMetadata);
String currentMetadata = mapper.writeValueAsString(sampleMetadata);
public Boolean sampleHasMetadataUpdates(SampleMetadata existingMetadata,
SampleMetadata newMetadata, Boolean isResearchSample, Boolean fromLims) throws Exception {
String existingMetadataStr = mapper.writeValueAsString(existingMetadata);
String newMetadataStr = mapper.writeValueAsString(newMetadata);
// if sample is from LIMS, look for updates by igo properties
if (fromLims && !jsonComparator.isConsistentByIgoProperties(currentMetadata, existingMetadata)) {
if (fromLims && !jsonComparator.isConsistentByIgoProperties(newMetadataStr, existingMetadataStr)) {
return Boolean.TRUE;
}
// if sample is not from LIMS, look for updates by all properties
if (!fromLims && !jsonComparator.isConsistent(currentMetadata, existingMetadata)) {
if (!fromLims && !jsonComparator.isConsistent(newMetadataStr, existingMetadataStr)) {
return Boolean.TRUE;
}
// if there is a change to the cmo sample label..
if (isResearchSample) {
String currentLabel = existingSampleMetadata.getCmoSampleName();
String newLabel = sampleMetadata.getCmoSampleName();
String currentLabel = existingMetadata.getCmoSampleName();
String newLabel = newMetadata.getCmoSampleName();
if ((!StringUtils.isBlank(currentLabel) && !currentLabel.equals(newLabel))
|| (StringUtils.isBlank(currentLabel) && !StringUtils.isBlank(newLabel))) {
return Boolean.TRUE;
}
}

// if there needs to be a patient swap..
if (!existingSampleMetadata.getCmoPatientId()
.equals(sampleMetadata.getCmoPatientId())) {
if (StringUtils.isBlank(existingMetadata.getCmoPatientId())
|| !existingMetadata.getCmoPatientId().equals(newMetadata.getCmoPatientId())) {
return Boolean.TRUE;
}

return Boolean.FALSE;
}

Expand Down Expand Up @@ -556,4 +549,9 @@ public String getSamplePrimaryIdBySampleInputId(String inputId) throws Exception
public Map<String, Object> getMatchedAndUnmatchedInputSampleIds(List<String> inputIds) throws Exception {
return sampleRepository.findMatchedAndUnmatchedInputSampleIds(inputIds);
}

@Override
public void setSampleRevisableTrue(UUID smileSampleId) {
sampleRepository.updateRevisableBySampleId(smileSampleId, Boolean.TRUE);
}
}