Skip to content

Commit 47d071b

Browse files
authored
Add isCmoSample to CMO label parts class (#133)
Allows label generator to check differences in field 'isCmoSample' to determine if a label update is needed or not. Signed-off-by: Angelica Ochoa <15623749+ao508@users.noreply.github.com>
1 parent cbe6659 commit 47d071b

File tree

5 files changed

+115
-48
lines changed

5 files changed

+115
-48
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,17 @@ public void run() {
201201
String requestId = getRequestIdFromRequestJson(requestJson);
202202
LOG.info("Extracting samples from request received: " + requestId);
203203
List<Map<String, Object>> samples = getSamplesFromRequestJson(requestJson);
204+
// get is cmo request for label generator
205+
Object isCmoRequest = getIsCmoRequestFromRequestJson(requestJson);
204206

205-
// get existing samples for all patients in the request
207+
// get existing samples for all patients and alt ids in the request
206208
Map<String, List<CmoLabelParts>> patientSamplesMap = getPatientSamplesMap(samples);
207209
Map<String, List<CmoLabelParts>> altIdSamplesMap = getAltIdSamplesMap(samples);
208210

209211
// udpated samples list will store samples which had a label generated successfully
210212
for (int i = 0; i < samples.size(); i++) {
211213
Map<String, Object> sampleMap = samples.get(i);
212-
CmoLabelParts labelParts = new CmoLabelParts(sampleMap, requestId);
214+
CmoLabelParts labelParts = new CmoLabelParts(sampleMap, requestId, isCmoRequest);
213215

214216
Map<String, Object> statusMap = mapper.convertValue(
215217
sampleMap.get("status"), Map.class);
@@ -351,7 +353,7 @@ public void run() {
351353
Map<String, String> origSampleJsonMap = new HashMap<>();
352354
for (int i = 0; i < samples.size(); i++) {
353355
Map<String, Object> sampleMap = samples.get(i);
354-
CmoLabelParts labelParts = new CmoLabelParts(sampleMap, null);
356+
CmoLabelParts labelParts = new CmoLabelParts(sampleMap, null, null);
355357
origSampleJsonMap.put(labelParts.getPrimaryId(),
356358
labelParts.getOrigSampleJsonStr());
357359

@@ -497,7 +499,7 @@ private Map<String, List<CmoLabelParts>> getPatientSamplesMap(List<Map<String, O
497499
Map<String, List<CmoLabelParts>> patientSamplesMap = new HashMap<>();
498500
for (Map<String, Object> sm : samples) {
499501
// get or request existing patient samples and update patient sample mapping
500-
CmoLabelParts sample = new CmoLabelParts(sm, null);
502+
CmoLabelParts sample = new CmoLabelParts(sm, null, null);
501503
if (StringUtils.isBlank(sample.getCmoPatientId())
502504
|| patientSamplesMap.containsKey(sample.getCmoPatientId())) {
503505
continue;
@@ -518,7 +520,7 @@ private List<CmoLabelParts> getExistingPatientSamples(String cmoPatientId) throw
518520
List<CmoLabelParts> samples = new ArrayList<>();
519521
for (Object s : sampleObjList) {
520522
Map<String, Object> sm = mapper.convertValue(s, Map.class);
521-
samples.add(new CmoLabelParts(sm, null));
523+
samples.add(new CmoLabelParts(sm, null, null));
522524
}
523525
return samples;
524526
}
@@ -537,7 +539,7 @@ private List<CmoLabelParts> getSamplesByCmoLabel(String cmoLabel) throws Excepti
537539
List<CmoLabelParts> samples = new ArrayList<>();
538540
for (Object s : sampleObjList) {
539541
Map<String, Object> sm = mapper.convertValue(s, Map.class);
540-
samples.add(new CmoLabelParts(sm, null));
542+
samples.add(new CmoLabelParts(sm, null, null));
541543
}
542544
return samples;
543545
}
@@ -547,7 +549,7 @@ private Map<String, List<CmoLabelParts>> getAltIdSamplesMap(List<Map<String, Obj
547549
Map<String, List<CmoLabelParts>> altIdSamplesMap = new HashMap<>();
548550
for (Map<String, Object> sm : samples) {
549551
// get or request existing patient samples and update patient sample mapping
550-
CmoLabelParts sample = new CmoLabelParts(sm, null);
552+
CmoLabelParts sample = new CmoLabelParts(sm, null, null);
551553
if (StringUtils.isBlank(sample.getAltId())
552554
|| altIdSamplesMap.containsKey(sample.getAltId())) {
553555
continue;
@@ -573,7 +575,7 @@ private List<CmoLabelParts> getSamplesByAltId(String altId) throws Exception {
573575
List<CmoLabelParts> samples = new ArrayList<>();
574576
for (Object s : sampleObjList) {
575577
Map<String, Object> sm = mapper.convertValue(s, Map.class);
576-
samples.add(new CmoLabelParts(sm, null));
578+
samples.add(new CmoLabelParts(sm, null, null));
577579
}
578580
return samples;
579581
}
@@ -596,6 +598,11 @@ private String getRequestIdFromRequestJson(String requestJson) throws JsonProces
596598
return requestJsonMap.get("requestId").toString();
597599
}
598600

601+
private Object getIsCmoRequestFromRequestJson(String requestJson) throws JsonProcessingException {
602+
Map<String, Object> requestJsonMap = mapper.readValue(requestJson, Map.class);
603+
return requestJsonMap.get("isCmoRequest");
604+
}
605+
599606
private List<Map<String, Object>> getSamplesFromRequestJson(String requestJson)
600607
throws JsonProcessingException {
601608
Map<String, Object> requestJsonMap = mapper.readValue(requestJson, Map.class);
@@ -775,7 +782,7 @@ public void onMessage(Message msg, Object message) {
775782
for (Object s : sampleObjList) {
776783
Map<String, Object> sm = mapper.convertValue(s, Map.class);
777784
if (!sm.containsKey("igoRequestId")) {
778-
CmoLabelParts labelParts = new CmoLabelParts(sm, null);
785+
CmoLabelParts labelParts = new CmoLabelParts(sm, null, null);
779786
sm.put("igoRequestId", labelParts.getIgoRequestId());
780787
}
781788
sampleMetadataList.add(sm);
@@ -798,7 +805,7 @@ private String findNextAvailableCmoLabel(String primaryId, String cmoLabel,
798805
// in smile and is associated with a different sample
799806
// if diff alt ids then increment by sample counter otherwise increment nuc acid counter
800807
Map<String, Object> sm = mapper.convertValue(s, Map.class);
801-
CmoLabelParts sample = new CmoLabelParts(sm, null);
808+
CmoLabelParts sample = new CmoLabelParts(sm, null, null);
802809
if (!sample.getPrimaryId().equals(primaryId)) {
803810
String otherAltId = sample.getAltId();
804811
if (!StringUtils.isBlank(altId) && !StringUtils.isBlank(otherAltId)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void run() {
9595
if (replyInfo != null) {
9696
Map<String, Object> sample = mapper.readValue(replyInfo.getRequestMessage(),
9797
Map.class);
98-
CmoLabelParts sampleLabelParts = new CmoLabelParts(sample, null);
98+
CmoLabelParts sampleLabelParts = new CmoLabelParts(sample, null, null);
9999
List<CmoLabelParts> existingPatientSamples
100100
= getExistingPatientSamples(sampleLabelParts.getCmoPatientId());
101101
List<CmoLabelParts> samplesByAltId
@@ -130,7 +130,7 @@ private List<CmoLabelParts> getExistingPatientSamples(String cmoPatientId) throw
130130
List<CmoLabelParts> ptSamples = new ArrayList<>();
131131
for (Object s : sampleObjectList) {
132132
Map<String, Object> sm = mapper.convertValue(s, Map.class);
133-
ptSamples.add(new CmoLabelParts(sm, null));
133+
ptSamples.add(new CmoLabelParts(sm, null, null));
134134
}
135135
return ptSamples;
136136
}
@@ -144,7 +144,7 @@ private List<CmoLabelParts> getSamplesByAltId(String altId) throws Exception {
144144
List<CmoLabelParts> samplesByAltId = new ArrayList<>();
145145
for (Object s : sampleObjectList) {
146146
Map<String, Object> sm = mapper.convertValue(s, Map.class);
147-
samplesByAltId.add(new CmoLabelParts(sm, null));
147+
samplesByAltId.add(new CmoLabelParts(sm, null, null));
148148
}
149149
return samplesByAltId;
150150
}

src/main/java/org/mskcc/smile/service/util/CmoLabelParts.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ public class CmoLabelParts implements Serializable, Cloneable {
3232
private String origSampleJsonStr;
3333
private String cmoSampleName; // igo/smile => cmoSampleName
3434
private String tumorOrNormal; // igo/smile => tumorOrNormal
35+
private Object isCmoSample; // igo => request:isCmoRequest, smile => additionalProperties:isCmoSample
3536

3637
public CmoLabelParts() {}
3738

3839
/**
3940
* Constructor for CmoLabelParts.
4041
* @param sampleMap
4142
* @param requestId
43+
* @param isCmoSample
4244
* @throws JsonProcessingException
4345
*/
44-
public CmoLabelParts(Map<String, Object> sampleMap, String requestId) throws JsonProcessingException {
46+
public CmoLabelParts(Map<String, Object> sampleMap, String requestId, Object isCmoSample)
47+
throws JsonProcessingException {
4548
this.origSampleJsonStr = mapper.writeValueAsString(sampleMap);
4649

4750
// fields common to both smile and igo sample data
@@ -74,6 +77,11 @@ public CmoLabelParts(Map<String, Object> sampleMap, String requestId) throws Jso
7477
getString(additionalProperties, "requestId"));
7578
this.altId = sampleMap.containsKey("altid")
7679
? getString(sampleMap, "altid") : getString(additionalProperties, "altId");
80+
if (isCmoSample != null) {
81+
this.isCmoSample = isCmoSample;
82+
} else if (additionalProperties != null) {
83+
this.isCmoSample = additionalProperties.get("isCmoSample");
84+
}
7785
}
7886

7987
/**
@@ -300,6 +308,20 @@ public void setTumorOrNormal(String tumorOrNormal) {
300308
this.tumorOrNormal = tumorOrNormal;
301309
}
302310

311+
/**
312+
* @return the isCmoSample
313+
*/
314+
public Object getIsCmoSample() {
315+
return isCmoSample;
316+
}
317+
318+
/**
319+
* @param isCmoSample the isCmoSample to set
320+
*/
321+
public void setIsCmoSample(Object isCmoSample) {
322+
this.isCmoSample = isCmoSample;
323+
}
324+
303325
private String getString(Map<String, Object> map, String key) {
304326
return (map == null || !map.containsKey(key) || map.get(key) == null)
305327
? null : map.get(key).toString();

0 commit comments

Comments
 (0)