Skip to content

Commit

Permalink
Merge branch 'temr-dev' into temr-dev-michael
Browse files Browse the repository at this point in the history
  • Loading branch information
mhayes2772 authored May 23, 2024
2 parents 7e5b0cf + f354bbc commit 960e767
Show file tree
Hide file tree
Showing 16 changed files with 1,020 additions and 89 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/license_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check for LICENSE File in femr Directory

on:
push:

jobs:
check-license-file:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Check if file exists
run: |
if [ ! -f "./LICENSE" ]; then
echo "File does not exist. Exiting with failure."
exit 1
fi
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ RUN mkdir -p $PROJECT_HOME/activator $PROJECT_HOME/app
WORKDIR $PROJECT_WORKPLACE/activator

# Install Play Framework
RUN curl -O http://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip
RUN curl -O https://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip

RUN unzip typesafe-activator-1.3.6.zip -d / && rm typesafe-activator-1.3.6.zip && ls && sudo chmod a+x /activator-dist-1.3.6/activator
ENV PATH $PATH:/activator-1.3.6

Expand All @@ -35,11 +36,16 @@ RUN \

# Install sbt
RUN \
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
mkdir /working/ && \
cd /working/ && \
curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get install sbt
apt-get install sbt && \
cd && \
rm -r /working/ && \
sbt sbtVersion

# Setup path variables and copy fEMR into container
ENV PATH $PROJECT_HOME/activator/activator-dist-1.3.10/bin:$PATH
Expand Down
636 changes: 636 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/femr/ui/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import play.mvc.Controller;
import play.mvc.Result;

import java.util.ArrayList;

public class HomeController extends Controller {

private final AssetsFinder assetsFinder;
Expand All @@ -28,7 +30,7 @@ public Result index() {
return ok(index.render(currentUser, assetsFinder));
}

return ok(create.render(null, 0, assetsFinder));
return ok(create.render(null, 0, null, assetsFinder, new ArrayList<String>()));
}


Expand Down
21 changes: 7 additions & 14 deletions app/femr/ui/controllers/MedicalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import femr.util.stringhelpers.StringUtils;
import femr.util.translation.TranslationJson;
import femr.util.translation.TranslationServer;
import femr.util.translation.TranslationResponseMap;
import play.data.Form;
import play.data.FormFactory;
import play.libs.Json;
Expand Down Expand Up @@ -269,30 +270,21 @@ public Result translateGet() {
String toLanguage = sessionService.retrieveCurrentUserSession().getLanguageCode();

// retrieve current patient encounter encounter

int patientId = Integer.parseInt(request().getQueryString("patientId"));
ServiceResponse<PatientEncounterItem> currentEncounterByPatientId = searchService.retrieveRecentPatientEncounterItemByPatientId(patientId);
if (currentEncounterByPatientId.hasErrors()) {
throw new RuntimeException();
}
PatientEncounterItem patientEncounter = currentEncounterByPatientId.getResponseObject();
String fromLanguage = patientEncounter.getLanguageCode();

// add whether the language is rtl to response
List<String> rtlLanguages = Arrays.asList("he", "ar");
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("toLanguageIsRtl", rtlLanguages.contains(toLanguage));
responseMap.put("fromLanguageIsRtl", rtlLanguages.contains(fromLanguage));
// Harrison Shu: Handles the creation of the response map and figures out whether or not to translate
TranslationResponseMap responseMapObject = new TranslationResponseMap(fromLanguage, toLanguage, text);

// if same to same (like en to en) don't translate
if (Objects.equals(toLanguage, fromLanguage)) {
responseMap.put("translation", "SameToSame");
} else {
responseMap.put("translation", translate(jsonText, fromLanguage,toLanguage));
}

return ok(Json.toJson(responseMap));
return ok(responseMapObject.getResponseJson());
}


// Calls Python Script to translate
private String translate(String jsonText, String fromLanguage, String toLanguage) {
String data = "";
Expand All @@ -305,6 +297,7 @@ private String translate(String jsonText, String fromLanguage, String toLanguage
return data;
}


public String parseJsonResponse(String jsonResponse){
try{
ObjectMapper mapper = new ObjectMapper();
Expand Down
74 changes: 67 additions & 7 deletions app/femr/ui/controllers/SessionsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import com.google.inject.Inject;
import controllers.AssetsFinder;
import femr.business.services.core.IInternetStatusService;
import femr.business.services.core.ISessionService;
import femr.business.services.core.IUpdatesService;
import femr.business.services.core.IUserService;
import femr.business.services.core.*;
import femr.business.services.system.UpdatesService;
import femr.common.dtos.CurrentUser;
import femr.common.dtos.ServiceResponse;
import femr.common.models.InternetStatusItem;
import femr.common.models.UserItem;
import femr.data.models.core.INetworkStatus;
import femr.data.models.core.IUser;
import femr.data.models.mysql.NetworkStatus;
Expand Down Expand Up @@ -38,16 +36,18 @@ public class SessionsController extends Controller {
private final FormFactory formFactory;
private final ISessionService sessionsService;
private final IUserService userService;
private final IRoleService roleService;
private final IUpdatesService internetStatusService;

@Inject
public SessionsController(AssetsFinder assetsFinder, FormFactory formFactory, ISessionService sessionsService, IUserService userService,
IUpdatesService internetStatusService) {
IRoleService roleService, IUpdatesService internetStatusService) {

this.assetsFinder = assetsFinder;
this.formFactory = formFactory;
this.sessionsService = sessionsService;
this.userService = userService;
this.roleService = roleService;
this.internetStatusService = internetStatusService;
}

Expand All @@ -56,11 +56,12 @@ public Result createGet() {

final Form<CreateViewModel> createViewModelForm = formFactory.form(CreateViewModel.class);


if (currentUser != null) {
return redirect(routes.HomeController.index());
}

return ok(create.render(createViewModelForm, 0, assetsFinder));
return ok(create.render(createViewModelForm, 0,null, assetsFinder, new ArrayList<String>()));
}

public Result createPost() {
Expand All @@ -70,7 +71,7 @@ public Result createPost() {
ServiceResponse<CurrentUser> response = sessionsService.createSession(viewModel.getEmail(), viewModel.getPassword(), request().remoteAddress());

if (response.hasErrors()) {
return ok(create.render(createViewModelForm.bindFromRequest(), 1, assetsFinder));
return ok(create.render(createViewModelForm.bindFromRequest(), 1, null, assetsFinder, new ArrayList<String>()));
}else{
IUser user = userService.retrieveById(response.getResponseObject().getId());
user.setLastLogin(dateUtils.getCurrentDateTime());
Expand Down Expand Up @@ -100,6 +101,52 @@ public Result createPost() {

}

public Result createPostAccount() {
CurrentUser currentUser = sessionsService.retrieveCurrentUserSession();

final Form<CreateViewModel> createViewModelForm = formFactory.form(CreateViewModel.class);
Form<CreateViewModel> form = createViewModelForm.bindFromRequest();

ServiceResponse<List<String>> roleServiceResponse = roleService.retrieveAllRoles();
if (roleServiceResponse.hasErrors()){
throw new RuntimeException();
}
List<String> messages = new ArrayList<>();

if (!form.field("email").getValue().isPresent()) {
return badRequest(create.render(form, 2, messages, assetsFinder, roleServiceResponse.getResponseObject()));
}

if (form.field("email").getValue().isPresent() &&
!form.field("email").getValue().get().matches("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$")) {
messages.add("Invalid Email");
return badRequest(create.render(form, 2, messages, assetsFinder, roleServiceResponse.getResponseObject()));
}

if (form.hasErrors()) {
return badRequest(create.render(form, 2, messages, assetsFinder, roleServiceResponse.getResponseObject()));
} else {
CreateViewModel viewModel = form.bindFromRequest().get();
UserItem user = createUserItem(viewModel);

ServiceResponse<UserItem> response = userService.createUser(user, viewModel.getPassword(), 0);
if (response.hasErrors()) {
messages.add(response.getErrors().get(""));
return ok(create.render(form, 2, messages, assetsFinder, roleServiceResponse.getResponseObject()));
}
else
//added user's last name to be displayed[FEMR-161]
//Contributed by Harsha Peswani during the CEN5035 course at FSU
if (StringUtils.isNullOrWhiteSpace(viewModel.getLastName()))
messages.add("An account for " + user.getFirstName() + " was created successfully. You may begin creating a new user.");
else
messages.add("An account for " + user.getFirstName() + " "+ user.getLastName() +" was created successfully. You may begin creating a new user.");


return ok(create.render(form, 0, messages, assetsFinder, roleServiceResponse.getResponseObject()));
}
}

public Result editPasswordGet(IUser user){

final Form<CreateViewModel> createViewModelForm = formFactory.form(CreateViewModel.class);
Expand Down Expand Up @@ -165,4 +212,17 @@ public Result delete() {

return redirect(routes.HomeController.index());
}

private UserItem createUserItem(CreateViewModel viewModel) {
UserItem user = new UserItem();
user.setFirstName(viewModel.getFirstName());
user.setLastName(viewModel.getLastName());
user.setEmail(viewModel.getEmail());
user.setDeleted(true);
user.setPasswordReset(false);
user.setNotes(viewModel.getNotes());
user.setRoles(viewModel.getRoles());
user.setDateCreated(viewModel.getDateCreated());
return user;
}
}
48 changes: 48 additions & 0 deletions app/femr/ui/models/sessions/CreateViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
*/
package femr.ui.models.sessions;

import femr.util.stringhelpers.StringUtils;
import play.data.validation.ValidationError;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class CreateViewModel {
private String email;
private String password;
//used for password reset
private String newPassword;
private String newPasswordVerify;
private String firstName;
private String lastName;
private List<String> roles;
private String notes;
private String DateCreated; //Sam Zanni

public String getEmail() {
return email;
Expand Down Expand Up @@ -56,4 +68,40 @@ public String getNewPasswordVerify() {
public void setNewPasswordVerify(String newPasswordVerify) {
this.newPasswordVerify = newPasswordVerify;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getNotes() {
return notes;
}

public void setNotes(String notes) {
this.notes = notes;
}

public List<String> getRoles() {
return roles;
}

public void setRoles(List<String> roles) {
this.roles = roles;
}

public String getDateCreated() { return DateCreated; } //Sam Zanni

public void setDateCreated(String DateCreated) { this.DateCreated = DateCreated; } //Sam Zanni
}
Loading

0 comments on commit 960e767

Please sign in to comment.