Skip to content

Commit b3df67b

Browse files
authored
Refactor label generator (#130)
* Refactored Label Generator - Added CmoLabelParts that is agnostic of sample data from IGO vs. updates from dashboard - Removes dependency on `model` layer of `smile-server` repo - Simplifies logic for label generation of incoming samples as part of a request and incoming sample updates from the dashboard - Cleaned up redundancies in label generation logic Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> * Simplified logic for generating labels for IGO_NEW_REQUEST samples Main label generator method now also resolves which label to use if current sample being handled exists and has a label assigned. i.e., only labels with meaningful changes are kept Updated logic to bypass label generation step if there aren't any applicable updates to label-specific data fields. Added and updated unit tests for bypass check. Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> * Simplified logic for sample label updates topic Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com> --------- Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com>
1 parent 18de5f7 commit b3df67b

File tree

9 files changed

+1103
-789
lines changed

9 files changed

+1103
-789
lines changed

pom.xml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
<!-- smile commons centralized config properties -->
3434
<smile_commons.group>com.github.mskcc</smile_commons.group>
3535
<smile_commons.version>a661a7b9a81ae51cb761ae32a6444dd01fb1994d</smile_commons.version> <!-- this is 2.1.3.RELEASE -->
36-
<!-- smile server model module -->
37-
<smile_server.group>com.github.mskcc.smile-server</smile_server.group>
38-
<smile_server.version>2.1.37.RELEASE</smile_server.version>
3936
</properties>
4037

4138
<dependencies>
@@ -51,12 +48,6 @@
5148
<artifactId>smile-commons</artifactId>
5249
<version>${smile_commons.version}</version>
5350
</dependency>
54-
<!-- smile server model -->
55-
<dependency>
56-
<groupId>${smile_server.group}</groupId>
57-
<artifactId>model</artifactId>
58-
<version>${smile_server.version}</version>
59-
</dependency>
6051
<!-- spring -->
6152
<dependency>
6253
<groupId>org.springframework</groupId>
@@ -94,6 +85,12 @@
9485
<artifactId>jsonassert</artifactId>
9586
<version>1.5.3</version>
9687
</dependency>
88+
<dependency>
89+
<groupId>commons-lang</groupId>
90+
<artifactId>commons-lang</artifactId>
91+
<version>2.6</version>
92+
<type>jar</type>
93+
</dependency>
9794
</dependencies>
9895

9996
<build>

src/main/java/org/mskcc/smile/service/CmoLabelGeneratorService.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,25 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import java.util.List;
5-
import org.mskcc.smile.model.SampleMetadata;
6-
import org.mskcc.smile.model.Status;
7-
import org.mskcc.smile.model.igo.IgoSampleManifest;
5+
import java.util.Map;
6+
import org.mskcc.smile.service.util.CmoLabelParts;
87

98
/**
109
*
1110
* @author ochoaa
1211
*/
1312
public interface CmoLabelGeneratorService {
14-
String generateCmoSampleLabel(String requestId,
15-
IgoSampleManifest sampleManifest, List<SampleMetadata> existingPatientSamples,
16-
List<SampleMetadata> samplesByAltId);
17-
String generateCmoSampleLabel(SampleMetadata sample, List<SampleMetadata> existingPatientSamples,
18-
List<SampleMetadata> samplesByAltId);
19-
Status generateSampleStatus(String requestId, IgoSampleManifest sampleManifest,
20-
List<SampleMetadata> existingSamples, List<SampleMetadata> samplesByAltId)
21-
throws JsonProcessingException;
22-
Status generateSampleStatus(SampleMetadata sampleMetadata, List<SampleMetadata> existingSamples,
23-
List<SampleMetadata> samplesByAltId) throws JsonProcessingException;
13+
Boolean sampleHasLabelSpecificUpdates(CmoLabelParts sample,
14+
List<CmoLabelParts> existingPatientSamples) throws Exception;
15+
String generateCmoSampleLabel(CmoLabelParts sample, List<CmoLabelParts> existingPatientSamples,
16+
List<CmoLabelParts> samplesByAltId);
17+
Map<String, Object> generateSampleStatus(CmoLabelParts sample, List<CmoLabelParts> existingSamples,
18+
List<CmoLabelParts> samplesByAltId) throws JsonProcessingException;
2419
Boolean igoSampleRequiresLabelUpdate(String newCmoLabel, String existingCmoLabel);
25-
String resolveSampleTypeAbbreviation(String specimenTypeValue, String sampleOriginValue,
26-
String cmoSampleClassValue, String sampleTypeDetailedValue);
20+
String resolveSampleTypeAbbreviation(CmoLabelParts sample);
2721
String resolveSampleTypeAbbrevWithContext(String primaryId, String resolvedSampleTypeAbbrev,
28-
List<SampleMetadata> samplesByAltId);
29-
String generateValidationReport(String originalJson, String filteredJson, Boolean isSample)
22+
List<CmoLabelParts> samplesByAltId);
23+
String generateValidationReportLog(String originalJson, String filteredJson, Boolean isSample)
3024
throws JsonProcessingException;
3125
String incrementNucleicAcidCounter(String cmoLabel);
3226
String incrementSampleCounter(String cmoLabel);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.mskcc.smile.service;
22

33
import java.util.List;
4+
import java.util.Map;
45
import org.mskcc.cmo.messaging.Gateway;
5-
import org.mskcc.smile.model.SampleMetadata;
66

77
public interface MessageHandlingService {
88
void initialize(Gateway gateway) throws Exception;
99
void cmoLabelGeneratorHandler(String requestJson) throws Exception;
1010
void cmoPromotedLabelHandler(String requestJson) throws Exception;
11-
void cmoSampleLabelUpdateHandler(List<SampleMetadata> sampleMetadataList) throws Exception;
11+
void cmoSampleLabelUpdateHandler(List<Map<String, Object>> sampleMetadataList) throws Exception;
1212
void shutdown() throws Exception;
1313
}

src/main/java/org/mskcc/smile/service/impl/CmoLabelGeneratorServiceImpl.java

Lines changed: 165 additions & 186 deletions
Large diffs are not rendered by default.

src/main/java/org/mskcc/smile/service/impl/LabelGenMessageHandlingServiceImpl.java

Lines changed: 306 additions & 331 deletions
Large diffs are not rendered by default.

src/main/java/org/mskcc/smile/service/impl/RequestReplyHandlingServiceImpl.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import io.nats.client.Message;
55
import java.nio.charset.StandardCharsets;
66
import java.util.ArrayList;
7-
import java.util.Arrays;
87
import java.util.List;
8+
import java.util.Map;
99
import java.util.concurrent.BlockingQueue;
1010
import java.util.concurrent.CountDownLatch;
1111
import java.util.concurrent.ExecutorService;
@@ -17,9 +17,9 @@
1717
import org.apache.commons.logging.LogFactory;
1818
import org.mskcc.cmo.messaging.Gateway;
1919
import org.mskcc.cmo.messaging.MessageConsumer;
20-
import org.mskcc.smile.model.SampleMetadata;
2120
import org.mskcc.smile.service.CmoLabelGeneratorService;
2221
import org.mskcc.smile.service.RequestReplyHandlingService;
22+
import org.mskcc.smile.service.util.CmoLabelParts;
2323
import org.springframework.beans.factory.annotation.Autowired;
2424
import org.springframework.beans.factory.annotation.Value;
2525
import org.springframework.stereotype.Service;
@@ -93,14 +93,15 @@ public void run() {
9393
// reply info request message contains cmo patient id
9494
ReplyInfo replyInfo = cmoLabelGeneratorReqReplyQueue.poll(100, TimeUnit.MILLISECONDS);
9595
if (replyInfo != null) {
96-
SampleMetadata sample = mapper.readValue(replyInfo.getRequestMessage(),
97-
SampleMetadata.class);
98-
List<SampleMetadata> existingPatientSamples
99-
= getExistingPatientSamples(sample.getCmoPatientId());
100-
List<SampleMetadata> samplesByAltId
101-
= getSamplesByAltId(sample.getAdditionalProperty("altId"));
96+
Map<String, Object> sample = mapper.readValue(replyInfo.getRequestMessage(),
97+
Map.class);
98+
CmoLabelParts sampleLabelParts = new CmoLabelParts(sample, null);
99+
List<CmoLabelParts> existingPatientSamples
100+
= getExistingPatientSamples(sampleLabelParts.getCmoPatientId());
101+
List<CmoLabelParts> samplesByAltId
102+
= getSamplesByAltId(sampleLabelParts.getAltId());
102103
String updatedCmoSampleLabel =
103-
cmoLabelGeneratorService.generateCmoSampleLabel(sample,
104+
cmoLabelGeneratorService.generateCmoSampleLabel(sampleLabelParts,
104105
existingPatientSamples, samplesByAltId);
105106

106107
//log replied to the message
@@ -120,22 +121,32 @@ public void run() {
120121
}
121122
}
122123

123-
private List<SampleMetadata> getExistingPatientSamples(String cmoPatientId) throws Exception {
124+
private List<CmoLabelParts> getExistingPatientSamples(String cmoPatientId) throws Exception {
124125
Message reply = messagingGateway.request(PATIENT_SAMPLES_REQUEST_TOPIC,
125126
cmoPatientId);
126-
SampleMetadata[] ptSamples = mapper.readValue(
127+
List<Object> sampleObjectList = mapper.readValue(
127128
new String(reply.getData(), StandardCharsets.UTF_8),
128-
SampleMetadata[].class);
129-
return new ArrayList<>(Arrays.asList(ptSamples));
129+
List.class);
130+
List<CmoLabelParts> ptSamples = new ArrayList<>();
131+
for (Object s : sampleObjectList) {
132+
Map<String, Object> sm = mapper.convertValue(s, Map.class);
133+
ptSamples.add(new CmoLabelParts(sm, null));
134+
}
135+
return ptSamples;
130136
}
131137

132-
private List<SampleMetadata> getSamplesByAltId(String altId) throws Exception {
138+
private List<CmoLabelParts> getSamplesByAltId(String altId) throws Exception {
133139
Message reply = messagingGateway.request(SAMPLES_BY_ALT_ID_REQREPLY_TOPIC,
134140
altId);
135-
SampleMetadata[] samplesByAltId = mapper.readValue(
141+
List<Object> sampleObjectList = mapper.readValue(
136142
new String(reply.getData(), StandardCharsets.UTF_8),
137-
SampleMetadata[].class);
138-
return new ArrayList<>(Arrays.asList(samplesByAltId));
143+
List.class);
144+
List<CmoLabelParts> samplesByAltId = new ArrayList<>();
145+
for (Object s : sampleObjectList) {
146+
Map<String, Object> sm = mapper.convertValue(s, Map.class);
147+
samplesByAltId.add(new CmoLabelParts(sm, null));
148+
}
149+
return samplesByAltId;
139150
}
140151

141152
@Override

0 commit comments

Comments
 (0)