Skip to content

Commit

Permalink
Added support for mrn to cmo/dmp patient id mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
n1zea144 committed Aug 16, 2023
1 parent e082832 commit 42460e1
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.mskcc.smile.model.web;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.io.Serializable;
import java.util.ArrayList;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class CrdbCrosswalkTriplet implements Serializable {
static String CMO_PATIENT_ID_PREFIX = "C-";

@Id
private String dmpId;
private String cmoId;
private String ptMrn;

public CrdbCrosswalkTriplet() {}

/**
* CrdbCrosswalkTriplet constructor
* @param crdbValues
* @throws JsonProcessingException
*/
public CrdbCrosswalkTriplet(ArrayList<Object> crdbValues) throws Exception {
// the crosswalk table may contain records that are missing fields (at least dmp)
// we need to handle cases where null is passed into this constructor
// Jackson null values to empty string "" does not work, so lets
// set null values to "" here in constructor
if (crdbValues.get(1) == null) {
this.dmpId = "";
} else {
this.dmpId = crdbValues.get(1).toString();
}
if (crdbValues.get(0) == null) {
this.cmoId = "";
} else {
this.cmoId = crdbValues.get(0).toString();
if (!this.cmoId.startsWith(CMO_PATIENT_ID_PREFIX)) {
this.cmoId = CMO_PATIENT_ID_PREFIX + this.cmoId;
}
}
if (crdbValues.get(2) == null) {
this.ptMrn = "";
} else {
this.ptMrn = crdbValues.get(2).toString();
}
}

public String getDmpId() {
return dmpId;
}

public void setDmpId(String dmpId) {
this.dmpId = dmpId;
}

public String getCmoId() {
return cmoId;
}

public void setCmoId(String cmoId) {
this.cmoId = cmoId;
}

public String getPtMrn() {
return ptMrn;
}

public void setPtMrn(String ptMrn) {
this.ptMrn = ptMrn;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mskcc.smile.persistence.jpa;

import org.mskcc.smile.model.internal.CrdbMappingModel;
import org.mskcc.smile.model.web.CrdbCrosswalkTriplet;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
Expand All @@ -16,4 +17,8 @@ public interface CrdbRepository extends CrudRepository<CrdbMappingModel, Long> {
nativeQuery = true)
Object getCmoPatientIdByInputId(@Param("inputId") String inputId);
// another query option
@Query(value = "SELECT CMO_ID, DMP_ID, PT_MRN "
+ "FROM CRDB_CMO_LOJ_DMP_MAP WHERE :inputId IN (DMP_ID, PT_MRN, CMO_ID)",
nativeQuery = true)
Object getCrdbCrosswalkTripletByInputId(@Param("inputId") String inputId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.mskcc.smile.service;

import org.mskcc.smile.model.internal.CrdbMappingModel;
import org.mskcc.smile.model.web.CrdbCrosswalkTriplet;

public interface CrdbMappingService {
String getCmoPatientIdbyDmpId(String dmpId);
String getCmoPatientIdByInputId(String inputId);
CrdbMappingModel getCrdbMappingModelByInputId(String inputId) throws Exception;
CrdbCrosswalkTriplet getCrdbCrosswalkTripletByInputId(String inputId) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.mskcc.smile.model.internal.CrdbMappingModel;
import org.mskcc.smile.model.web.CrdbCrosswalkTriplet;
import org.mskcc.smile.persistence.jpa.CrdbRepository;
import org.mskcc.smile.service.CrdbMappingService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -80,6 +81,22 @@ public Object call() {
return null;
}

@Override
public CrdbCrosswalkTriplet getCrdbCrosswalkTripletByInputId(String inputId) throws Exception {
Callable<Object> task = new Callable<Object>() {
@Override
public Object call() {
return crdbRepository.getCrdbCrosswalkTripletByInputId(inputId);
}
};
Object result = runQueryWithForcedTimeout(task);
if (result != null) {
ArrayList<Object> crdbValues = mapper.convertValue(result, ArrayList.class);
return new CrdbCrosswalkTriplet(crdbValues);
}
return null;
}

private Object runQueryWithForcedTimeout(Callable<Object> task) {
Future<Object> future = executor.submit(task);
try {
Expand Down
76 changes: 76 additions & 0 deletions web/src/main/java/org/mskcc/smile/web/CrosswalkController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.mskcc.smile.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mskcc.smile.model.web.CrdbCrosswalkTriplet;
import org.mskcc.smile.service.CrdbMappingService;
import org.mskcc.smile.service.exception.SmileWebServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping(value = "/")
@Api(tags = "crosswalk-controller", description = "Crosswalk Controller")
@PropertySource("classpath:/maven.properties")
public class CrosswalkController {

@Value("${smile.schema_version}")
private String smileSchemaVersion;

@Autowired
private CrdbMappingService crdbMappingService;

@Autowired
public CrosswalkController(CrdbMappingService crdbMappingService) {
this.crdbMappingService = crdbMappingService;
}

/**
* Returns a list of mrn-dmp-cmo patient id triplets given a list of MRNs.
* Only triplets that exist in the crdb crosswalk table are returned.
* @param mrns
* @return ResponseEntity
* @throws Exception
*/
@ApiOperation(value = "Returns a list of mrn-dmp-cmo patient id triplets given a list of MRNs.",
nickname = "fetchIDTripletListPOST")
@RequestMapping(value = "/crosswalk",
method = RequestMethod.POST,
produces = "application/json")
public ResponseEntity<List<CrdbCrosswalkTriplet>> fetchIDTripletListPOST(@ApiParam(value =
"List of MRNs", required = true, allowMultiple = true)
@RequestBody List<String> mrns) throws Exception {
List<CrdbCrosswalkTriplet> tripletList = new ArrayList<>();
for (String mrn: mrns) {
CrdbCrosswalkTriplet triplet = crdbMappingService.getCrdbCrosswalkTripletByInputId(mrn);
if (triplet != null) {
tripletList.add(triplet);
}
}
return ResponseEntity.ok()
.headers(responseHeaders())
.body(tripletList);
}

private HttpHeaders responseHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.set("smile-schema-version", smileSchemaVersion);
return headers;
}
}

0 comments on commit 42460e1

Please sign in to comment.