diff --git a/app/femr/ui/controllers/MedicalController.java b/app/femr/ui/controllers/MedicalController.java index 948836214..6a415dc71 100644 --- a/app/femr/ui/controllers/MedicalController.java +++ b/app/femr/ui/controllers/MedicalController.java @@ -266,27 +266,25 @@ public Result translateGet() { String jsonText = request().getQueryString("text"); int patientId = Integer.parseInt(request().getQueryString("patientId")); - //Harrison Shu - String toLanguage = sessionService.retrieveCurrentUserSession().getLanguageCode(); - // retrieve current patient encounter encounter - int patientId = Integer.parseInt(request().getQueryString("patientId")); ServiceResponse currentEncounterByPatientId = searchService.retrieveRecentPatientEncounterItemByPatientId(patientId); if (currentEncounterByPatientId.hasErrors()) { throw new RuntimeException(); } - PatientEncounterItem patientEncounter = currentEncounterByPatientId.getResponseObject(); - String fromLanguage = patientEncounter.getLanguageCode(); + //Harrison Shu + String toLanguage = sessionService.retrieveCurrentUserSession().getLanguageCode(); + String fromLanguage = currentEncounterByPatientId.getResponseObject().getLanguageCode(); + // Harrison Shu: Handles the creation of the response map and figures out whether or not to translate - TranslationResponseMap responseMapObject = new TranslationResponseMap(fromLanguage, toLanguage, text); + TranslationResponseMap responseMapObject = new TranslationResponseMap(fromLanguage, toLanguage, jsonText); return ok(responseMapObject.getResponseJson()); } // Calls Python Script to translate - private String translate(String jsonText, String fromLanguage, String toLanguage) { + public static String translate(String jsonText, String fromLanguage, String toLanguage) { String data = ""; try { data = TranslationServer.makeServerRequest(jsonText, fromLanguage, toLanguage); @@ -297,8 +295,7 @@ private String translate(String jsonText, String fromLanguage, String toLanguage return data; } - - public String parseJsonResponse(String jsonResponse){ + public static String parseJsonResponse(String jsonResponse){ try{ ObjectMapper mapper = new ObjectMapper(); TranslationJson api = mapper.readValue(jsonResponse, TranslationJson.class); diff --git a/app/femr/util/translation/TranslationResponseMap.java b/app/femr/util/translation/TranslationResponseMap.java index d67ada956..b8fd4fc8f 100644 --- a/app/femr/util/translation/TranslationResponseMap.java +++ b/app/femr/util/translation/TranslationResponseMap.java @@ -1,5 +1,5 @@ package femr.util.translation; -import femr.ui.controllers.BackEndControllerHelper; +import femr.ui.controllers.MedicalController; import java.util.*; import play.libs.Json; @@ -37,7 +37,7 @@ private void populateTranslation() { } else { String data = ""; try { - data = BackEndControllerHelper.translate(text, fromLanguage, toLanguage); + data = MedicalController.translate(text, fromLanguage, toLanguage); } catch (Exception e) { e.printStackTrace(); }