Skip to content

Commit

Permalink
add calls for decryption test
Browse files Browse the repository at this point in the history
  • Loading branch information
Avery Wang committed Sep 17, 2024
1 parent f043915 commit 4e5e710
Showing 1 changed file with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
Expand Down Expand Up @@ -81,6 +88,12 @@ public class MskEntityTranslationController {
@Value("${patient_view.url}")
public void setPatientViewURL(String property) { this.patientViewURL = property; }

@Value("${mpath.decryption_url:}")
private String mpathDecryptionUrl;

@Value("${mpath.token:}")
private String mpathToken;

private static final String ARCHER = "mskarcher";
private static final String RAINDANCE = "mskraindance";
private static final String IMPACT = "mskimpact";
Expand All @@ -90,6 +103,24 @@ private static Pattern initDMPSampleIDPattern() {
return Pattern.compile("(P-[0-9]{7,})-T[0-9]{2,}-(\\w{3,})");
}

@RequestMapping(
value={"/api-legacy/epic/sample/{sampleID}"},
method=RequestMethod.GET
)
public ModelAndView redirectIMPACTSampleForEpic(@PathVariable String sampleID, ModelMap model) {
String decryptedId = getDecryptedId(sampleID);
return new ModelAndView(getRedirectURL(decryptedId), model);
}

@RequestMapping(
value={"/api-legacy/epic/patient/{patientID}"},
method=RequestMethod.GET
)
public ModelAndView redirectIMPACTPatientForEpic(@PathVariable String patientID, ModelMap model) {
String decryptedId = getDecryptedId(patientID);
return new ModelAndView(getPatientRedirectURL(decryptedId), model);
}

@RequestMapping(
value={"/api-legacy/cis/{sampleID}", "/api-legacy/darwin/{sampleID}"},
method=RequestMethod.GET
Expand All @@ -106,17 +137,33 @@ public ModelAndView redirectCRDB(@PathVariable String sampleID, ModelMap model)
return new ModelAndView(getRedirectURL(sampleID), model);
}

// Accepts both encrypted patient/sample ids
// Ids not found will not be decrypted -- will propagate down and result in 400 Error Request
// Should be avoided upstream in Epic by using /exists endpoint to check firstd
private String getDecryptedId(String id) {
String requestUrl = mpathDecryptionUrl + id;
RestTemplate restTemplate = new RestTemplate();
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("x-api-key", mpathToken);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
ResponseEntity<Object> responseEntity = restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, Object.class);
String decryptedId = id;
if (responseEntity.getStatusCode().value() == 200) {
decryptedId = responseEntity.getBody().toString();
}
return decryptedId;
}

private String getRedirectURL(String sampleID) {
String redirectURL = "redirect:" + sampleViewURL;
String studyID = getCancerStudy(sampleID);
if (!checkIfSampleExistsInStudy(studyID, sampleID)) {
if (studyID.equals(ARCHER)) {
String patientID = getPatientID(sampleID);
if (patientID != null) {
redirectURL = "redirect:" + patientViewURL;
redirectURL = redirectURL.replace("STUDY_ID", IMPACT);
redirectURL = redirectURL.replace("CASE_ID", patientID);
return redirectURL;
return getPatientRedirectURL(patientID);
}
// else patientID is null
}
Expand All @@ -131,6 +178,13 @@ private String getRedirectURL(String sampleID) {
return redirectURL;
}

private String getPatientRedirectURL(String patientID) {
String redirectURL = "redirect:" + patientViewURL;
redirectURL = redirectURL.replace("STUDY_ID", IMPACT);
redirectURL = redirectURL.replace("CASE_ID", patientID);
return redirectURL;
}

@RequestMapping(
value={"/api-legacy/cis/{sampleID}/exists", "/api-legacy/darwin/{sampleID}/exists", "/api-legacy/crdb/{sampleID}/exists"},
method=RequestMethod.GET
Expand All @@ -141,6 +195,17 @@ private String getRedirectURL(String sampleID) {
return result;
}

@RequestMapping(
value={"/api-legacy/epic/{sampleID}/exists"},
method=RequestMethod.GET
)
public @ResponseBody HashMap<String, Boolean> existsForEpic(@PathVariable String sampleID, ModelMap model) {
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
String decryptedId = getDecryptedId(sampleID);
result.put("exists", new Boolean(checkIfSampleExists(decryptedId)));
return result;
}

private boolean checkIfPatientExists(String studyID, String sampleID) {
try {
String patientID = getPatientID(sampleID);
Expand Down

0 comments on commit 4e5e710

Please sign in to comment.