Skip to content

Commit

Permalink
Modified igo updates handling and new smile-commons version (#796)
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Madala <[email protected]>

Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
divyamadala30 authored Oct 14, 2022
1 parent 328676c commit 060b9d9
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 79 deletions.
19 changes: 19 additions & 0 deletions model/src/main/java/org/mskcc/smile/model/SmileRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,25 @@ public void updateRequestMetadataByMetadata(RequestMetadata requestMetadata)
addRequestMetadata(requestMetadata);
}

/**
* Updates by LIMS
* Update Metadata to only include accepted updates for a list of fields
* @param requestMetadata
* @throws JsonProcessingException
*/
public void applyIgoRequestMetadataUpdates(RequestMetadata requestMetadata)
throws JsonProcessingException {
Map<String, Object> metadataMap =
mapper.readValue(requestMetadata.getRequestMetadataJson(), Map.class);

this.genePanel = resolveGenePanel(metadataMap);
this.strand = String.valueOf(metadataMap.get("strand"));
this.libraryType = String.valueOf(metadataMap.get("libraryType"));
this.isCmoRequest = Boolean.parseBoolean(String.valueOf(metadataMap.get("isCmoRequest")));
this.pooledNormals = mapper.convertValue(metadataMap.get("pooledNormals"), List.class);
addRequestMetadata(requestMetadata);
}

/**
* Resolves gene panel from recipe or genePanel sample json field.
* @param metadataMap
Expand Down
31 changes: 31 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 @@ -154,6 +154,37 @@ public SampleMetadata getLatestSampleMetadata() throws ParseException {
return null;
}

/**
* Applies IGO LIMS updates for the following fields
* @param sampleMetadata
* @return
*/
public void applyIgoLimsUpdates(SampleMetadata sampleMetadata) throws ParseException {
SampleMetadata latestSampleMetadata = getLatestSampleMetadata();

sampleMetadata.setId(null);
sampleMetadata.setCmoPatientId(latestSampleMetadata.getCmoPatientId());
sampleMetadata.setInvestigatorSampleId(latestSampleMetadata.getInvestigatorSampleId());
sampleMetadata.setInvestigatorSampleId(latestSampleMetadata.getInvestigatorSampleId());
sampleMetadata.setSampleName(latestSampleMetadata.getSampleName());
sampleMetadata.setCmoInfoIgoId(latestSampleMetadata.getCmoInfoIgoId());
sampleMetadata.setOncotreeCode(latestSampleMetadata.getOncotreeCode());
sampleMetadata.setCollectionYear(latestSampleMetadata.getCollectionYear());
sampleMetadata.setTubeId(latestSampleMetadata.getTubeId());
sampleMetadata.setSpecies(latestSampleMetadata.getSpecies());
sampleMetadata.setSex(latestSampleMetadata.getSex());
sampleMetadata.setTumorOrNormal(latestSampleMetadata.getTumorOrNormal());
sampleMetadata.setSampleType(latestSampleMetadata.getSampleType());
sampleMetadata.setPreservation(latestSampleMetadata.getPreservation());
sampleMetadata.setSampleClass(latestSampleMetadata.getSampleClass());
sampleMetadata.setSampleOrigin(latestSampleMetadata.getSampleOrigin());
sampleMetadata.setTissueLocation(latestSampleMetadata.getTissueLocation());
sampleMetadata.setGenePanel(latestSampleMetadata.getGenePanel());
sampleMetadata.setIgoComplete(latestSampleMetadata.getIgoComplete());

addSampleMetadata(sampleMetadata);
}

public void updateSampleMetadata(SampleMetadata sampleMetadata) throws ParseException {
sampleMetadata.setId(null);
addSampleMetadata(sampleMetadata);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<smile_messaging_java.version>1.3.6.RELEASE</smile_messaging_java.version>
<!-- smile commons centralized config properties -->
<smile_commons.group>com.github.mskcc</smile_commons.group>
<smile_commons.version>1.3.6.RELEASE</smile_commons.version>
<smile_commons.version>1.3.8.RELEASE</smile_commons.version>
<!-- smile expected schema version -->
<smile.schema_version>v2.2</smile.schema_version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public interface SmileRequestService {
Boolean saveRequestMetadata(SmileRequest request);
SmileRequest getSmileRequestById(String requestId) throws Exception;
PublishedSmileRequest getPublishedSmileRequestById(String requestId) throws Exception;
Boolean updateRequestMetadata(RequestMetadata requestMetadata) throws Exception;
Boolean requestHasUpdates(SmileRequest existingRequest, SmileRequest request) throws Exception;
Boolean updateRequestMetadata(RequestMetadata requestMetadata, Boolean fromLims) throws Exception;
Boolean requestHasUpdates(SmileRequest existingRequest, SmileRequest request, Boolean fromLims)
throws Exception;
Boolean requestHasMetadataUpdates(RequestMetadata existingRequestMetadata,
RequestMetadata requestMetadata) throws Exception;
RequestMetadata requestMetadata, Boolean fromLims) throws Exception;
List<SmileSample> getRequestSamplesWithUpdates(SmileRequest request) throws Exception;
List<RequestSummary> getRequestsByDate(String startDate, String endDate) throws Exception;
List<RequestMetadata> getRequestMetadataHistory(String reqId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public interface SmileSampleService {
SmileSample saveSmileSample(SmileSample smileSample) throws Exception;
SmileSample fetchAndLoadPatientDetails(SmileSample smileSample) throws Exception;
Boolean updateSampleMetadata(SampleMetadata sampleMetadata) throws Exception;
Boolean updateSampleMetadata(SampleMetadata sampleMetadata, Boolean fromLims) throws Exception;
List<SmileSample> getMatchedNormalsBySample(SmileSample smileSample)
throws Exception;
List<String> getPooledNormalsBySample(SmileSample smileSample) throws Exception;
Expand All @@ -20,7 +20,7 @@ List<SmileSample> getMatchedNormalsBySample(SmileSample smileSample)
List<SmileSample> getResearchSamplesByRequestId(String requestId) throws Exception;
List<SampleMetadata> getResearchSampleMetadataHistoryByIgoId(String igoId) throws Exception;
Boolean sampleHasMetadataUpdates(SampleMetadata existingSampleMetadata,
SampleMetadata sampleMetadata, Boolean isResearchSample)
SampleMetadata sampleMetadata, Boolean isResearchSample, Boolean fromLims)
throws Exception;
PublishedSmileSample getPublishedSmileSample(UUID smileSampleId) throws Exception;
List<PublishedSmileSample> getPublishedSmileSamplesByCmoPatientId(String cmoPatientId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void run() {
mapper.writeValueAsString(smileSample));
} else if (sampleService.sampleHasMetadataUpdates(
existingSample.getLatestSampleMetadata(),
smileSample.getLatestSampleMetadata(), Boolean.FALSE)) {
smileSample.getLatestSampleMetadata(), Boolean.FALSE, Boolean.FALSE)) {
LOG.info("Found updates for sample - persisting to database: "
+ smileSample.getPrimarySampleAlias());
existingSample.updateSampleMetadata(smileSample.getLatestSampleMetadata());
Expand Down Expand Up @@ -180,7 +180,7 @@ public void run() {
mapper.writeValueAsString(smileSample));
} else if (sampleService.sampleHasMetadataUpdates(
existingSample.getLatestSampleMetadata(),
smileSample.getLatestSampleMetadata(), Boolean.FALSE)) {
smileSample.getLatestSampleMetadata(), Boolean.FALSE, Boolean.FALSE)) {
LOG.info("Found updates for sample - persisting to database: "
+ smileSample.getPrimarySampleAlias());
existingSample.updateSampleMetadata(smileSample.getLatestSampleMetadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,22 @@ public PublishedSmileRequest getPublishedSmileRequestById(String requestId) thro
}

@Override
public Boolean updateRequestMetadata(RequestMetadata requestMetadata) throws Exception {
public Boolean updateRequestMetadata(RequestMetadata requestMetadata, Boolean fromLims) throws Exception {
SmileRequest existingRequest = getSmileRequestById(requestMetadata.getIgoRequestId());
if (existingRequest == null) {
LOG.error("Cannot persist updates to a request that does not already exist: "
+ requestMetadata.getIgoRequestId());
return Boolean.FALSE;
}
// persist updates for request metadata if applicable
if (requestHasMetadataUpdates(existingRequest.getLatestRequestMetadata(), requestMetadata)) {
LOG.info("Persisting updates for request: " + existingRequest.getIgoRequestId());
existingRequest.updateRequestMetadataByMetadata(requestMetadata);
if (requestHasMetadataUpdates(existingRequest.getLatestRequestMetadata(),
requestMetadata, fromLims)) {
if (fromLims) {
LOG.info("Persisting igo property updates for request: " + existingRequest.getIgoRequestId());
existingRequest.applyIgoRequestMetadataUpdates(requestMetadata);
} else {
LOG.info("Persisting updates for request: " + existingRequest.getIgoRequestId());
existingRequest.updateRequestMetadataByMetadata(requestMetadata);
}
saveRequestMetadata(existingRequest);
return Boolean.TRUE;
}
Expand All @@ -205,16 +210,28 @@ private Boolean timestampWithin24Hours(Date referenceTimestamp, Date newTimestam
}

@Override
public Boolean requestHasUpdates(SmileRequest existingRequest, SmileRequest request) throws Exception {
return !(jsonComparator.isConsistent(mapper.writeValueAsString(existingRequest),
mapper.writeValueAsString(request)));
public Boolean requestHasUpdates(SmileRequest existingRequest, SmileRequest request,
Boolean fromLims) throws Exception {
if (fromLims) {
return !jsonComparator.isConsistentByIgoProperties(mapper.writeValueAsString(existingRequest),
mapper.writeValueAsString(request));
}
return !jsonComparator.isConsistent(mapper.writeValueAsString(existingRequest),
mapper.writeValueAsString(request));
}

@Override
public Boolean requestHasMetadataUpdates(RequestMetadata existingRequestMetadata,
RequestMetadata requestMetadata) throws Exception {
return !(jsonComparator.isConsistent(existingRequestMetadata.getRequestMetadataJson(),
requestMetadata.getRequestMetadataJson()));
RequestMetadata requestMetadata, Boolean fromLims) throws Exception {
// if request is from LIMS, look for updates by igo properties
if (fromLims) {
return !jsonComparator.isConsistentByIgoProperties(
existingRequestMetadata.getRequestMetadataJson(),
requestMetadata.getRequestMetadataJson());
}
// if request is not from LIMS, look for updates by all properties
return !jsonComparator.isConsistent(existingRequestMetadata.getRequestMetadataJson(),
requestMetadata.getRequestMetadataJson());
}

@Override
Expand All @@ -230,7 +247,7 @@ public List<SmileSample> getRequestSamplesWithUpdates(SmileRequest request) thro
}
Boolean sampleHasUpdates =
sampleService.sampleHasMetadataUpdates(existingSample.getLatestSampleMetadata(),
sample.getLatestSampleMetadata(), Boolean.TRUE);
sample.getLatestSampleMetadata(), Boolean.TRUE, Boolean.FALSE);
if (sampleHasUpdates) {
existingSample.updateSampleMetadata(sample.getLatestSampleMetadata());
updatedSamples.add(existingSample);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ public void run() {
} else {
// request-service and sample-service methods will check for updates and persist
// them if applicable (including patient swapping)
requestService.updateRequestMetadata(request.getLatestRequestMetadata());
// Boolean arg in updateRequestMetadata refers to fromLims
requestService.updateRequestMetadata(request.getLatestRequestMetadata(),
Boolean.TRUE);
for (SmileSample sample : request.getSmileSampleList()) {
sampleService.saveSmileSample(sample);
// Boolean arg in updateSampleMetadata refers to fromLims
sampleService.updateSampleMetadata(sample.getLatestSampleMetadata(),
Boolean.TRUE);
sampleService.createSampleRequestRelationship(sample.getSmileSampleId(),
existingRequest.getSmileRequestId());
}
Expand Down Expand Up @@ -180,7 +184,8 @@ public void run() {
try {
RequestMetadata requestMetadata = requestUpdateQueue.poll(100, TimeUnit.MILLISECONDS);
if (requestMetadata != null) {
if (requestService.updateRequestMetadata(requestMetadata)) {
// Boolean arg in updateRequestMetadata refers to fromLims
if (requestService.updateRequestMetadata(requestMetadata, Boolean.FALSE)) {
LOG.info("Publishing Request-level Metadata updates "
+ "to " + CMO_REQUEST_UPDATE_TOPIC);
SmileRequest existingRequest =
Expand Down Expand Up @@ -222,7 +227,8 @@ public void run() {
SampleMetadata sampleMetadata = researchSampleUpdateQueue.poll(
100, TimeUnit.MILLISECONDS);
if (sampleMetadata != null) {
if (sampleService.updateSampleMetadata(sampleMetadata)) {
// Boolean arg in updateSampleMetadata refers to fromLims
if (sampleService.updateSampleMetadata(sampleMetadata, Boolean.FALSE)) {
SmileSample existingSample = sampleService.getResearchSampleByRequestAndIgoId(
sampleMetadata.getIgoRequestId(), sampleMetadata.getPrimaryId());
LOG.info("Publishing sample-level metadata history for research sample: "
Expand Down
Loading

0 comments on commit 060b9d9

Please sign in to comment.