Skip to content

Commit

Permalink
Handle sample metadata updates with patient swap (#706)
Browse files Browse the repository at this point in the history
Now handles scenario where sample metadata updates can include a patient swap
Added unit tests specific for this scenario
Confirmed that the REST service works as expected

Signed-off-by: Angelica Ochoa <[email protected]>
  • Loading branch information
ao508 authored Jun 1, 2022
1 parent f2c36c3 commit 10ff4cd
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 68 deletions.
5 changes: 5 additions & 0 deletions model/src/main/java/org/mskcc/smile/model/SmilePatient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class SmilePatient implements Serializable {

public SmilePatient() {}

public SmilePatient(String aliasValue, String aliasNamespace) {
this.patientAliases = new ArrayList<>();
patientAliases.add(new PatientAlias(aliasValue, aliasNamespace));
}

public UUID getSmilePatientId() {
return smilePatientId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ void updateSamplePatientRelationship(@Param("smileSampleId") UUID smileSampleId,
+ "OR sm.cmoSampleName = $inputId "
+ "RETURN s;")
SmileSample findSampleByInputId(@Param("inputId") String inputId);

@Query("MATCH (s: Sample {smileSampleId: $smileSampleId}) "
+ "MATCH (s)<-[r:HAS_SAMPLE]-(p: Patient {smilePatientId: $smilePatientId}) "
+ "DELETE r")
void removeSamplePatientRelationship(@Param("smileSampleId") UUID smileSampleId,
@Param("smilePatientId") UUID smilePatientId);
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<testcontainers.version>1.16.0</testcontainers.version>
<!-- smile messaging and shared entities dependency versions -->
<smile_messaging_java.group>com.github.mskcc</smile_messaging_java.group>
<smile_messaging_java.version>1.3.3.RELEASE</smile_messaging_java.version>
<smile_messaging_java.version>1.3.4.RELEASE</smile_messaging_java.version>
<!-- smile commons centralized config properties -->
<smile_commons.group>com.github.mskcc</smile_commons.group>
<smile_commons.version>1.3.3.RELEASE</smile_commons.version>
<smile_commons.version>1.3.4.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 @@ -10,7 +10,7 @@

public interface SmileSampleService {
SmileSample saveSmileSample(SmileSample smileSample) throws Exception;
SmileSample fetchAndLoadSampleDetails(SmileSample smileSample) throws Exception;
SmileSample fetchAndLoadPatientDetails(SmileSample smileSample) throws Exception;
Boolean updateSampleMetadata(SampleMetadata sampleMetadata) throws Exception;
List<SmileSample> getMatchedNormalsBySample(SmileSample smileSample)
throws Exception;
Expand All @@ -19,7 +19,8 @@ List<SmileSample> getMatchedNormalsBySample(SmileSample smileSample)
SmileSample getResearchSampleByRequestAndIgoId(String requestId, String igoId) throws Exception;
List<SmileSample> getResearchSamplesByRequestId(String requestId) throws Exception;
List<SampleMetadata> getResearchSampleMetadataHistoryByIgoId(String igoId) throws Exception;
Boolean sampleHasMetadataUpdates(SampleMetadata existingSampleMetadata, SampleMetadata sampleMetadata)
Boolean sampleHasMetadataUpdates(SampleMetadata existingSampleMetadata,
SampleMetadata sampleMetadata, Boolean isResearchSample)
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())) {
smileSample.getLatestSampleMetadata(), 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())) {
smileSample.getLatestSampleMetadata(), Boolean.FALSE)) {
LOG.info("Found updates for sample - persisting to database: "
+ smileSample.getPrimarySampleAlias());
existingSample.updateSampleMetadata(smileSample.getLatestSampleMetadata());
Expand Down Expand Up @@ -244,6 +244,11 @@ public void onMessage(Message msg, Object message) {
DmpSampleMetadata.class);
String cmoPatientId = crdbMappingService.getCmoPatientIdbyDmpId(
dmpSample.getDmpPatientId());
if (cmoPatientId == null) {
LOG.error("Could not resolve cmoPatientId from dmpId: "
+ dmpSample.getDmpPatientId());
return;
}
SmileSample sample = SampleDataFactory.buildNewClinicalSampleFromMetadata(
cmoPatientId, dmpSample);
clinicalMessageHandlingService.newClinicalSampleHandler(sample);
Expand All @@ -268,6 +273,11 @@ public void onMessage(Message msg, Object message) {
DmpSampleMetadata.class);
String cmoPatientId = crdbMappingService.getCmoPatientIdbyDmpId(
dmpSample.getDmpPatientId());
if (cmoPatientId == null) {
LOG.error("Could not resolve cmoPatientId from dmpId: "
+ dmpSample.getDmpPatientId());
return;
}
SmileSample sample = SampleDataFactory.buildNewClinicalSampleFromMetadata(
cmoPatientId, dmpSample);
clinicalMessageHandlingService.clinicalSampleUpdateHandler(sample);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,15 @@ private Boolean timestampWithin24Hours(Date referenceTimestamp, Date newTimestam

@Override
public Boolean requestHasUpdates(SmileRequest existingRequest, SmileRequest request) throws Exception {
try {
jsonComparator.isConsistent(mapper.writeValueAsString(existingRequest),
mapper.writeValueAsString(request));
} catch (AssertionError e) {
LOG.warn("Found discrepancies between JSONs:\n" + e.getLocalizedMessage());
return Boolean.TRUE;
}
return Boolean.FALSE;
return !(jsonComparator.isConsistent(mapper.writeValueAsString(existingRequest),
mapper.writeValueAsString(request)));
}

@Override
public Boolean requestHasMetadataUpdates(RequestMetadata existingRequestMetadata,
RequestMetadata requestMetadata) throws Exception {
try {
jsonComparator.isConsistent(existingRequestMetadata.getRequestMetadataJson(),
requestMetadata.getRequestMetadataJson());
} catch (AssertionError e) {
LOG.warn("Found discrepancies between JSONs:\n" + e.getLocalizedMessage());
return Boolean.TRUE;
}
return Boolean.FALSE;
return !(jsonComparator.isConsistent(existingRequestMetadata.getRequestMetadataJson(),
requestMetadata.getRequestMetadataJson()));
}

@Override
Expand All @@ -240,14 +228,10 @@ public List<SmileSample> getRequestSamplesWithUpdates(SmileRequest request) thro
if (existingSample == null) {
continue;
}
// compare sample metadata from current request and the saved request
String latestMetadata = mapper.writeValueAsString(existingSample.getLatestSampleMetadata());
String currentMetadata = mapper.writeValueAsString(sample.getLatestSampleMetadata());

try {
jsonComparator.isConsistent(latestMetadata, currentMetadata);
} catch (AssertionError e) {
LOG.warn("Found discrepancies between JSONs:\n" + e.getLocalizedMessage());
Boolean sampleHasUpdates =
sampleService.sampleHasMetadataUpdates(existingSample.getLatestSampleMetadata(),
sample.getLatestSampleMetadata(), Boolean.TRUE);
if (sampleHasUpdates) {
existingSample.updateSampleMetadata(sample.getLatestSampleMetadata());
updatedSamples.add(existingSample);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class ResearchMessageHandlingServiceImpl implements ResearchMessageHandli
@Value("${smile.cmo_sample_update_topic}")
private String CMO_SAMPLE_UPDATE_TOPIC;

@Value("${request_reply.cmo_label_generator_topic}")
private String CMO_LABEL_GENERATOR_REQREPLY_TOPIC;

@Value("${num.new_request_handler_threads}")
private int NUM_NEW_REQUEST_HANDLERS;

Expand Down Expand Up @@ -123,10 +126,10 @@ public void run() {
requestService.saveRequest(request);
} else {
// request-service and sample-service methods will check for updates and persist
// them if applicable
// them if applicable (including patient swapping)
requestService.updateRequestMetadata(request.getLatestRequestMetadata());
for (SmileSample sample : request.getSmileSampleList()) {
sampleService.updateSampleMetadata(sample.getLatestSampleMetadata());
sampleService.saveSmileSample(sample);
}
}
// publish updated/saved request to consistency checker or promoted request topic
Expand Down
Loading

0 comments on commit 10ff4cd

Please sign in to comment.