Skip to content

Commit

Permalink
getLanguageCode() functonality added
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbarba19 committed Jun 11, 2024
1 parent 4483246 commit 8dd1601
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 132 deletions.
6 changes: 3 additions & 3 deletions app/femr/common/ItemModelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ public PatientEncounterItem createPatientEncounterItem(IPatientEncounter patient
patientEncounterItem.setPharmacistFullName(patientEncounter.getPharmacist().getFirstName() + " " + patientEncounter.getPharmacist().getLastName()); // Andrew Change
}
patientEncounterItem.setTurnAroundTime(dateUtils.getTurnAroundTime(patientEncounterItem));
if (patientEncounter.getLanguageCode() != null ) {
patientEncounterItem.setLanguageCode(patientEncounter.getLanguageCode());
}
// if (patientEncounter.getLanguageCode() != null ) {
patientEncounterItem.setLanguageCode("en");
//}
return patientEncounterItem;


Expand Down
8 changes: 7 additions & 1 deletion app/femr/common/dtos/CurrentUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,11 @@ public long getTimeout2() {
return SessionTimeOut;
}

public String getLanguageCode() { return langCode;}
public String getLanguageCode() {
return this.langCode;
}

public void setLanguageCode(String languageCode) {
this.langCode = languageCode;
}
}
19 changes: 2 additions & 17 deletions app/femr/ui/controllers/SettingsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,19 @@ public Result index() {
return ok(femr.ui.views.html.settings.index.render(currentUser, assetsFinder));
}

public Result update() {
public Result update(String languageCode) {
CurrentUser currentUser = sessionService.retrieveCurrentUserSession();
if (currentUser == null) {
return unauthorized();
}

IndexViewModelGet viewModelGet = new IndexViewModelGet();
Form<EditViewModel> editViewModelForm = formFactory.form(EditViewModel.class).bindFromRequest();
if (editViewModelForm.hasErrors()) {
return badRequest(index.render(currentUser, assetsFinder));
}

EditViewModel viewModel = editViewModelForm.get();
ServiceResponse<UserItem> userServiceResponse = userService.retrieveUser(currentUser.getId());
if (userServiceResponse.hasErrors()) {
return internalServerError();
}

UserItem userItem = userServiceResponse.getResponseObject();
userItem.setFirstName(viewModel.getFirstName());
userItem.setLastName(viewModel.getLastName());
userItem.setLanguageCode(viewModel.getLanguageCode());

if (StringUtils.isNotNullOrWhiteSpace(viewModel.getPasswordReset()) && viewModel.getPasswordReset().equals("on")) {
userItem.setPasswordReset(true);
} else {
userItem.setPasswordReset(false);
}
userItem.setLanguageCode(languageCode);


ServiceResponse<UserItem> updateResponse = userService.updateUser(userItem, null);
Expand Down
4 changes: 1 addition & 3 deletions app/femr/ui/views/admin/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = @currentUser.getLanguageCode();
updateLanguage(initialLanguage);
updateLanguage("@{currentUser.getLanguageCode()}");
document.getElementById('languageSelect').value = initialLanguage;
});

Expand Down
14 changes: 7 additions & 7 deletions app/femr/ui/views/feedback/feedback.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
.then(response => response.json())
.then(data => {
languageData = data;
const storedLanguage = localStorage.getItem('languageCode') || 'en';
updateLanguage(storedLanguage);
document.getElementById('languageSelect').value = storedLanguage;
try {
let languageCode = "@{currentUser.getLanguageCode()}";
updateLanguage(languageCode);
} catch (error) {
const languageCode = "en";
updateLanguage(languageCode);
}
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down
38 changes: 22 additions & 16 deletions app/femr/ui/views/home/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,46 @@
<script>
document.addEventListener('DOMContentLoaded', function(event) {
let languageData;

// Fetch language data
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
});
updateLanguage("@{currentUser.getLanguageCode()}");

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});
})
.catch(error => console.error('Error fetching language data:', error));

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
} else {
console.error(`Element with ID '${elementId}' not found.`);
}
}

function updateLanguage(languageCode, currUser = " Admin!") {
const language = languageCode;
updateTextContent("home_index_h2_Welcome", languageData[language].home_index_h2_Welcome + currUser);
updateTextContent("home_index_div_Your", languageData[language].home_index_div_Your);
updateTextContent("home_index_p_Please", languageData[language].home_index_p_Please);
updateTextContent("home_index_p_Or", languageData[language].home_index_p_Or);
updateTextContent("home_index_p_Search", languageData[language].home_index_p_Search);
const patientSearch = document.getElementById("patientSearch");
if (patientSearch) {
patientSearch.placeholder = languageData[language].home_index_div_ID;
if (languageData && languageData[language]) {
updateTextContent("home_index_h2_Welcome", languageData[language].home_index_h2_Welcome + currUser);
updateTextContent("home_index_div_Your", languageData[language].home_index_div_Your);
updateTextContent("home_index_p_Please", languageData[language].home_index_p_Please);
updateTextContent("home_index_p_Or", languageData[language].home_index_p_Or);
updateTextContent("home_index_p_Search", languageData[language].home_index_p_Search);
const patientSearch = document.getElementById("patientSearch");
if (patientSearch) {
patientSearch.placeholder = languageData[language].home_index_div_ID;
} else {
console.error("Element with ID 'patientSearch' not found.");
}
} else {
console.error(`Language data for code '${language}' not found.`);
}
}
});

</script>
}

Expand Down
15 changes: 7 additions & 8 deletions app/femr/ui/views/layouts/admin.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = @currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
try {
let languageCode = "@{currentUser.getLanguageCode()}";
updateLanguage(languageCode);
} catch (error) {
const languageCode = "en";
updateLanguage(languageCode);
}
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down
11 changes: 2 additions & 9 deletions app/femr/ui/views/layouts/settings.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down Expand Up @@ -71,7 +64,7 @@
<h2 id="settings_title">Settings Panel</h2>
</div>
<div id="info">
<h3 id="settings_language">Language Preference.</h3>
<h3 id="settings_language">Language Preference</h3>
</div>

@message
Expand Down
9 changes: 1 addition & 8 deletions app/femr/ui/views/manager/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = @currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down
9 changes: 1 addition & 8 deletions app/femr/ui/views/medical/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = @currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down
11 changes: 2 additions & 9 deletions app/femr/ui/views/partials/authenticated.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = value;
}
}

function updateLanguage(languageCode = "en") {
function updateLanguage(languageCode) {
localStorage.setItem('languageCode', languageCode);
updateTextContent("langCode_triage", languageData[languageCode].langCode_triage);
updateTextContent("langCode_medical", languageData[languageCode].langCode_medical);
Expand Down
9 changes: 4 additions & 5 deletions app/femr/ui/views/partials/footer.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
<script>
document.addEventListener('DOMContentLoaded', function(event) {
let languageData;
let languageCode;
fetch('@routes.Assets.versioned("json/languages.json")')
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//currentUser.getLanguageCode();
//const initialLanguage = currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
languageCode = "en";
updateLanguage(languageCode);
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down
10 changes: 2 additions & 8 deletions app/femr/ui/views/partials/shared/searchBox.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = @currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
});
updateLanguage("@{currentUser.getLanguageCode()}");

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
Expand Down
10 changes: 2 additions & 8 deletions app/femr/ui/views/pharmacies/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = @currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
});
updateLanguage("@{currentUser.getLanguageCode()}");

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
Expand Down
8 changes: 1 addition & 7 deletions app/femr/ui/views/research/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
.then(response => response.json())
.then(data => {
languageData = data;
const storedLanguage = localStorage.getItem('languageCode') || 'en';
updateLanguage(storedLanguage);
document.getElementById('languageSelect').value = storedLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
});

/*function updateTextContent(elementId, value) {
Expand Down Expand Up @@ -120,10 +118,6 @@
updateButtonValue("export-button", languageData[languageCode].export_data_button);
updateTextContent("select_trip_option", languageData[language].select_trip);
}

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});
});
</script>

Expand Down
12 changes: 5 additions & 7 deletions app/femr/ui/views/settings/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
.then(response => response.json())
.then(data => {
languageData = data;
const initialLanguage = localStorage.getItem('languageCode') || 'en';
//const initialLanguage = currentUser.getLanguageCode();
updateLanguage(initialLanguage);
document.getElementById('languageSelect').value = initialLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
//document.getElementById('languageSelect').value = initialLanguage;
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});
//document.getElementById('languageSelect').addEventListener('change', function() {
//updateLanguage(this.value);
//});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
Expand Down
8 changes: 1 addition & 7 deletions app/femr/ui/views/triage/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@
.then(response => response.json())
.then(data => {
languageData = data;
const storedLanguage = localStorage.getItem('languageCode') || 'en';
updateLanguage(storedLanguage);
document.getElementById('languageSelect').value = storedLanguage;
updateLanguage("@{currentUser.getLanguageCode()}");
});

document.getElementById('languageSelect').addEventListener('change', function() {
updateLanguage(this.value);
});

function updateTextContent(elementId, value) {
const element = document.getElementById(elementId);
if (element) {
Expand Down
Loading

0 comments on commit 8dd1601

Please sign in to comment.