Skip to content

Commit

Permalink
Updates to facilitate support for updating sample label topic in labe…
Browse files Browse the repository at this point in the history
…l-generator (#588)

Signed-off-by: Angelica Ochoa <[email protected]>
  • Loading branch information
ao508 authored Feb 3, 2022
1 parent f8ceafc commit e8259b3
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ MetadbSample findResearchSampleByRequestAndIgoId(@Param("reqId") String reqId,
List<MetadbSample> findAllSamplesByCmoPatientId(
@Param("cmoPatientId") String cmoPatientId);

@Query("MATCH (pa: PatientAlias {namespace: 'cmoId', value: $cmoPatientId})-[:IS_ALIAS]->"
+ "(p: Patient)-[:HAS_SAMPLE]->(s: Sample {sampleCategory: $sampleCategory}) "
+ "RETURN s")
List<MetadbSample> findAllSamplesByCategoryAndCmoPatientId(
@Param("cmoPatientId") String cmoPatientId, @Param("sampleCategory") String sampleCategory);

@Query("MATCH (sa :SampleAlias {value:$value, namespace: $namespace})"
+ "-[:IS_ALIAS]->(s: Sample)"
+ "-[:HAS_METADATA]->(sm: SampleMetadata)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ List<MetadbSample> getMatchedNormalsBySample(MetadbSample metaDbSample)
List<String> getPooledNormalsBySample(MetadbSample metaDbSample) throws Exception;
MetadbSample getMetadbSample(UUID metaDbSampleId) throws Exception;
MetadbSample getResearchSampleByRequestAndIgoId(String requestId, String igoId) throws Exception;
List<SampleMetadata> getSampleMetadataListByCmoPatientId(String cmoPatientId) throws Exception;
List<MetadbSample> getResearchSamplesByRequestId(String requestId) throws Exception;
List<SampleMetadata> getResearchSampleMetadataHistoryByIgoId(String igoId) throws Exception;
Boolean sampleHasMetadataUpdates(SampleMetadata existingSampleMetadata, SampleMetadata sampleMetadata)
throws Exception;
PublishedMetadbSample getPublishedMetadbSample(UUID metadbSampleId) throws Exception;
List<PublishedMetadbSample> getPublishedMetadbSampleListByCmoPatientId(String cmoPatientId)
List<PublishedMetadbSample> getPublishedMetadbSamplesByCmoPatientId(String cmoPatientId)
throws Exception;
List<MetadbSample> getMetadbSampleListByCmoPatientId(String cmoPatientId) throws Exception;
List<MetadbSample> getSamplesByCmoPatientId(String cmoPatientId) throws Exception;
MetadbSample getDetailedMetadbSample(MetadbSample sample) throws ParseException;
MetadbSample getClinicalSampleByDmpId(String dmpId) throws Exception;

List<MetadbSample> getSamplesByCategoryAndCmoPatientId(String cmoPatientId,
String sampleCategory) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void run() {
// get samples by old cmo patient id before updating the
// cmo patient id for the given patient alias/patient node
List<MetadbSample> samples =
sampleService.getMetadbSampleListByCmoPatientId(oldCmoPatientId);
sampleService.getSamplesByCmoPatientId(oldCmoPatientId);
MetadbPatient updatedPatient = patientService.updateCmoPatientId(
oldCmoPatientId, newCmoPatientId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.nats.client.Message;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
Expand All @@ -14,6 +15,7 @@
import org.apache.commons.logging.LogFactory;
import org.mskcc.cmo.messaging.Gateway;
import org.mskcc.cmo.messaging.MessageConsumer;
import org.mskcc.cmo.metadb.model.MetadbSample;
import org.mskcc.cmo.metadb.model.SampleMetadata;
import org.mskcc.cmo.metadb.service.CrdbMappingService;
import org.mskcc.cmo.metadb.service.MetadbSampleService;
Expand Down Expand Up @@ -86,13 +88,18 @@ public void run() {
phaser.arrive();
while (true) {
try {
// reply info request message contains cmo patient id
ReplyInfo replyInfo = patientSamplesReqReplyQueue.poll(100, TimeUnit.MILLISECONDS);
if (replyInfo != null) {
List<SampleMetadata> sampleList =
sampleService.getSampleMetadataListByCmoPatientId(
replyInfo.getRequestMessage());
List<MetadbSample> researchSamples =
sampleService.getSamplesByCategoryAndCmoPatientId(
replyInfo.getRequestMessage(), "research");
List<SampleMetadata> sampleMetadataList = new ArrayList<>();
for (MetadbSample sample : researchSamples) {
sampleMetadataList.add(sample.getLatestSampleMetadata());
}
messagingGateway.replyPublish(replyInfo.getReplyTo(),
mapper.writeValueAsString(sampleList));
mapper.writeValueAsString(sampleMetadataList));
}
if (interrupted && patientSamplesReqReplyQueue.isEmpty()) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ public MetadbSample getResearchSampleByRequestAndIgoId(String requestId, String
return getDetailedMetadbSample(sample);
}

@Override
public List<SampleMetadata> getSampleMetadataListByCmoPatientId(String cmoPatientId) throws Exception {
List<SampleMetadata> sampleMetadataList = new ArrayList<>();
for (MetadbSample sample: sampleRepository.findAllSamplesByCmoPatientId(cmoPatientId)) {
getDetailedMetadbSample(sample);
sampleMetadataList.add(sample.getLatestSampleMetadata());
}
return sampleMetadataList;
}

@Override
public List<MetadbSample> getResearchSamplesByRequestId(String requestId) throws Exception {
List<MetadbSample> requestSamples = new ArrayList<>();
Expand Down Expand Up @@ -147,7 +137,7 @@ public PublishedMetadbSample getPublishedMetadbSample(UUID metadbSampleId) throw
}

@Override
public List<PublishedMetadbSample> getPublishedMetadbSampleListByCmoPatientId(
public List<PublishedMetadbSample> getPublishedMetadbSamplesByCmoPatientId(
String cmoPatientId) throws Exception {
List<MetadbSample> sampleList = sampleRepository
.findAllSamplesByCmoPatientId(cmoPatientId);
Expand All @@ -161,7 +151,7 @@ public List<PublishedMetadbSample> getPublishedMetadbSampleListByCmoPatientId(
}

@Override
public List<MetadbSample> getMetadbSampleListByCmoPatientId(String cmoPatientId) throws Exception {
public List<MetadbSample> getSamplesByCmoPatientId(String cmoPatientId) throws Exception {
List<MetadbSample> samples = new ArrayList<>();
for (MetadbSample sample: sampleRepository.findAllSamplesByCmoPatientId(cmoPatientId)) {
samples.add(getDetailedMetadbSample(sample));
Expand Down Expand Up @@ -189,4 +179,14 @@ public MetadbSample getClinicalSampleByDmpId(String dmpId) throws Exception {
return metadbSample;
}

@Override
public List<MetadbSample> getSamplesByCategoryAndCmoPatientId(String cmoPatientId, String sampleCategory)
throws Exception {
List<MetadbSample> samples = new ArrayList<>();
for (MetadbSample sample: sampleRepository.findAllSamplesByCategoryAndCmoPatientId(cmoPatientId,
sampleCategory)) {
samples.add(getDetailedMetadbSample(sample));
}
return samples;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public void testUpdateCmoPatientId() throws Exception {
String oldCmoPatientId = "C-1MP6YY";
String newCmoPatientId = "NewCmoPatientId";

int numOfSampleBeforeUpdate = sampleService.getSampleMetadataListByCmoPatientId(
int numOfSampleBeforeUpdate = sampleService.getSamplesByCmoPatientId(
oldCmoPatientId).size();
patientService.updateCmoPatientId(oldCmoPatientId, newCmoPatientId);
int numOfSampleAfterUpdate = sampleService.getSampleMetadataListByCmoPatientId(
int numOfSampleAfterUpdate = sampleService.getSamplesByCmoPatientId(
newCmoPatientId).size();

Assertions.assertThat(numOfSampleBeforeUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public void testFindPooledNormalSample() throws Exception {
@Test
public void testGetSampleMetadataListByCmoPatientId() throws Exception {
String cmoPatientId = "C-PXXXD9";
List<SampleMetadata> savedSampleMetadataList = sampleService
.getSampleMetadataListByCmoPatientId(cmoPatientId);
Assertions.assertThat(savedSampleMetadataList.size()).isEqualTo(2);
List<MetadbSample> savedSampleList =
sampleService.getSamplesByCmoPatientId(cmoPatientId);
Assertions.assertThat(savedSampleList.size()).isEqualTo(2);
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testPersistClinicalSample() throws Exception {
String dmpPatientId = "P-0000001";
String cmoPatientId = mockDataUtils.getCmoPatientIdForDmpPatient(dmpPatientId);
List<MetadbSample> sampleList = sampleService
.getMetadbSampleListByCmoPatientId(cmoPatientId);
.getSamplesByCmoPatientId(cmoPatientId);
Assertions.assertThat(sampleList.size()).isEqualTo(2);
}

Expand All @@ -279,7 +279,7 @@ public void testPatientSamplesCountMatchExpectedValues() throws Exception {
for (Map.Entry<String, Integer> entry : mockDataUtils.EXPECTED_PATIENT_SAMPLES_COUNT.entrySet()) {
String cmoPatientId = entry.getKey();
Integer expectedSampleCount = entry.getValue();
List<MetadbSample> sampleList = sampleService.getMetadbSampleListByCmoPatientId(cmoPatientId);
List<MetadbSample> sampleList = sampleService.getSamplesByCmoPatientId(cmoPatientId);
if (expectedSampleCount != sampleList.size()) {
StringBuilder builder = new StringBuilder();
builder.append("CMO patient id: ").append(cmoPatientId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResponseEntity<List<PublishedMetadbSample>> fetchSampleMetadataListByCmoP
@ApiParam(value = "CMO Patient ID", required = true)
@PathVariable String cmoPatientId) throws Exception {
List<PublishedMetadbSample> samples = sampleService
.getPublishedMetadbSampleListByCmoPatientId(cmoPatientId);
.getPublishedMetadbSamplesByCmoPatientId(cmoPatientId);
if (samples == null) {
return requestNotFoundHandler("Samples not found by CMO patient ID: " + cmoPatientId);
}
Expand Down

0 comments on commit e8259b3

Please sign in to comment.