diff --git a/app/femr/business/services/core/IUpdatesService.java b/app/femr/business/services/core/IUpdatesService.java new file mode 100644 index 000000000..03803fd53 --- /dev/null +++ b/app/femr/business/services/core/IUpdatesService.java @@ -0,0 +1,71 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.business.services.core; + +import femr.common.dtos.ServiceResponse; +import femr.data.models.core.IKitStatus; +import femr.data.models.core.INetworkStatus; +import femr.data.models.core.IDatabaseStatus; + +import java.util.List; + +public interface IUpdatesService { + + /** + * Retrieve network statuses. + * + * @return a list of current network statues. + */ + ServiceResponse> retrieveNetworkStatuses(); + + /** + * Update network statuses. + * + * @return a list of network statues after the update (update by running a script). + */ + ServiceResponse> updateNetworkStatuses(); + + /** + * Retrieve network statuses. + * + * @return a list of current network statues. + */ + ServiceResponse> retrieveKitStatuses(); + + /** + * Update kit statuses. + * + * @return a list of kit statuses after the update (update by running a script?). + */ + ServiceResponse> updateKitStatuses(); + + /** + * Retrieve database last update. + * + * @return a list of current database status. + */ + ServiceResponse> retrieveDatabaseStatuses(); + + /** + * Update database last update and do the backup via script. + * + * @return a list of kit database status. + */ + ServiceResponse> updateDatabaseStatuses(); +} diff --git a/app/femr/business/services/system/UpdatesService.java b/app/femr/business/services/system/UpdatesService.java new file mode 100644 index 000000000..4855c4a41 --- /dev/null +++ b/app/femr/business/services/system/UpdatesService.java @@ -0,0 +1,136 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.business.services.system; + +import com.google.inject.Inject; +import femr.business.services.core.IUpdatesService; +import femr.common.dtos.ServiceResponse; +import femr.data.daos.IRepository; +import femr.data.models.core.IKitStatus; +import femr.data.models.core.INetworkStatus; +import femr.data.models.core.IDatabaseStatus; +import femr.data.models.mysql.KitStatus; +import femr.data.models.mysql.NetworkStatus; +import femr.data.models.mysql.DatabaseStatus; + +import java.util.List; + +public class UpdatesService implements IUpdatesService { + + private final IRepository networkStatusRepository; + private final IRepository kitStatusRepository; + private final IRepository databaseStatusRepository; + + @Inject + public UpdatesService(IRepository networkStatusRepository, + IRepository kitStatusRepository, + IRepository databaseStatusRepository) { + this.networkStatusRepository = networkStatusRepository; + this.kitStatusRepository = kitStatusRepository; + this.databaseStatusRepository = databaseStatusRepository; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> retrieveNetworkStatuses() { + ServiceResponse> response = new ServiceResponse<>(); + try { + List networkStatuses = networkStatusRepository.findAll(NetworkStatus.class); + response.setResponseObject(networkStatuses); + + } catch (Exception ex) { + response.addError("", ex.getMessage()); + } + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> updateNetworkStatuses() { + ServiceResponse> response = new ServiceResponse<>(); + //TODO: Lemur Team update the database with the right values + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> retrieveKitStatuses() { + ServiceResponse> response = new ServiceResponse<>(); + try { + List kitStatuses = kitStatusRepository.findAll(KitStatus.class); + response.setResponseObject(kitStatuses); + + } catch (Exception ex) { + response.addError("", ex.getMessage()); + } + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> updateKitStatuses() { + ServiceResponse> response = new ServiceResponse<>(); + //TODO: Lemur Team update the database with the right values + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> retrieveDatabaseStatuses() { + ServiceResponse> response = new ServiceResponse<>(); + try { + List databaseStatuses = databaseStatusRepository.findAll(DatabaseStatus.class); + response.setResponseObject(databaseStatuses); + + } catch (Exception ex) { + response.addError("", ex.getMessage()); + } + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> updateDatabaseStatuses() { + ServiceResponse> response = new ServiceResponse<>(); + //TODO: Feather Team backup database ---> run script to see if it successsfully return if it succeeds or not + + String updated_date = java.time.LocalDate.now().toString().replace("-", "."); + DatabaseStatus databaseStatus = new DatabaseStatus(); + databaseStatus.setName("Last Backup"); + databaseStatus.setValue(updated_date); + databaseStatusRepository.update(databaseStatus); + + return response; + } + + +} + diff --git a/app/femr/data/models/core/IDatabaseStatus.java b/app/femr/data/models/core/IDatabaseStatus.java new file mode 100644 index 000000000..0c6bad488 --- /dev/null +++ b/app/femr/data/models/core/IDatabaseStatus.java @@ -0,0 +1,33 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.core; + +public interface IDatabaseStatus { + int getId(); + + void setId(int id); + + String getName(); + + void setName(String name); + + String getValue(); + + void setValue(String value); +} diff --git a/app/femr/data/models/core/IKitStatus.java b/app/femr/data/models/core/IKitStatus.java new file mode 100644 index 000000000..33ea65637 --- /dev/null +++ b/app/femr/data/models/core/IKitStatus.java @@ -0,0 +1,34 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.core; + + +public interface IKitStatus { + int getId(); + + void setId(int id); + + String getName(); + + void setName(String name); + + String getValue(); + + void setValue(String value); +} diff --git a/app/femr/data/models/core/IKitUpdate.java b/app/femr/data/models/core/IKitUpdate.java new file mode 100644 index 000000000..23f4e4c31 --- /dev/null +++ b/app/femr/data/models/core/IKitUpdate.java @@ -0,0 +1,33 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.core; + +public interface IKitUpdate { + int getId(); + + void setId(int id); + + String getName(); + + void setName(String name); + + String getValue(); + + void setValue(String value); +} diff --git a/app/femr/data/models/core/INetworkStatus.java b/app/femr/data/models/core/INetworkStatus.java new file mode 100644 index 000000000..ff4d3b1d2 --- /dev/null +++ b/app/femr/data/models/core/INetworkStatus.java @@ -0,0 +1,33 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.core; + +public interface INetworkStatus { + int getId(); + + void setId(int id); + + String getName(); + + void setName(String name); + + String getValue(); + + void setValue(String value); +} diff --git a/app/femr/data/models/mysql/DatabaseStatus.java b/app/femr/data/models/mysql/DatabaseStatus.java new file mode 100644 index 000000000..a9d46ffde --- /dev/null +++ b/app/femr/data/models/mysql/DatabaseStatus.java @@ -0,0 +1,68 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.mysql; + +import femr.data.models.core.IDatabaseStatus; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "database_status") +public class DatabaseStatus implements IDatabaseStatus { + @Id + @Column(name = "id", unique = true, nullable = false) + private int id; + @Column(name = "name") + private String name; + @Column(name = "val") + private String value; + + @Override + public int getId() { + return id; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } +} diff --git a/app/femr/data/models/mysql/KitStatus.java b/app/femr/data/models/mysql/KitStatus.java new file mode 100644 index 000000000..aa09c3189 --- /dev/null +++ b/app/femr/data/models/mysql/KitStatus.java @@ -0,0 +1,68 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.mysql; + +import femr.data.models.core.IKitStatus; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "kit_status") +public class KitStatus implements IKitStatus { + @Id + @Column(name = "id", unique = true, nullable = false) + private int id; + @Column(name = "name") + private String name; + @Column(name = "val") + private String value; + + @Override + public int getId() { + return id; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } +} diff --git a/app/femr/data/models/mysql/KitUpdate.java b/app/femr/data/models/mysql/KitUpdate.java new file mode 100644 index 000000000..6f444e442 --- /dev/null +++ b/app/femr/data/models/mysql/KitUpdate.java @@ -0,0 +1,68 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.mysql; + +import femr.data.models.core.IDatabaseStatus; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "kit_update") +public class KitUpdate implements IDatabaseStatus { + @Id + @Column(name = "id", unique = true, nullable = false) + private int id; + @Column(name = "name") + private String name; + @Column(name = "val") + private String value; + + @Override + public int getId() { + return id; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } +} diff --git a/app/femr/data/models/mysql/NetworkStatus.java b/app/femr/data/models/mysql/NetworkStatus.java new file mode 100644 index 000000000..aeed1b792 --- /dev/null +++ b/app/femr/data/models/mysql/NetworkStatus.java @@ -0,0 +1,68 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.data.models.mysql; + +import femr.data.models.core.INetworkStatus; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "network_status") +public class NetworkStatus implements INetworkStatus { + @Id + @Column(name = "id", unique = true, nullable = false) + private int id; + @Column(name = "name") + private String name; + @Column(name = "val") + private String value; + + @Override + public int getId() { + return id; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } +} diff --git a/app/femr/ui/controllers/admin/UpdatesController.java b/app/femr/ui/controllers/admin/UpdatesController.java new file mode 100644 index 000000000..f1b97fda7 --- /dev/null +++ b/app/femr/ui/controllers/admin/UpdatesController.java @@ -0,0 +1,131 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.ui.controllers.admin; + +import com.google.inject.Inject; +import controllers.AssetsFinder; +import femr.business.services.core.IUpdatesService; +import femr.business.services.core.ISessionService; +import femr.common.dtos.CurrentUser; +import femr.common.dtos.ServiceResponse; +import femr.data.models.core.IKitStatus; +import femr.data.models.core.INetworkStatus; +import femr.data.models.core.IDatabaseStatus; +import femr.data.models.mysql.Roles; +import femr.ui.helpers.security.AllowedRoles; +import femr.ui.helpers.security.FEMRAuthenticated; +import femr.ui.models.admin.updates.IndexViewModelGet; +import femr.ui.views.html.admin.updates.manage; +import play.Logger; +import play.data.FormFactory; +import play.mvc.Controller; +import play.mvc.Result; +import play.mvc.Security; + +import java.util.ArrayList; +import java.util.List; + +@Security.Authenticated(FEMRAuthenticated.class) +@AllowedRoles({Roles.ADMINISTRATOR, Roles.SUPERUSER}) +public class UpdatesController extends Controller { + + private final AssetsFinder assetsFinder; + private final FormFactory formFactory; + private ISessionService sessionService; + private IUpdatesService updatesService; + private List messages; + + @Inject + public UpdatesController(AssetsFinder assetsFinder, + FormFactory formFactory, + ISessionService sessionService, + IUpdatesService updatesService) { + + this.assetsFinder = assetsFinder; + this.formFactory = formFactory; + this.sessionService = sessionService; + this.updatesService = updatesService; + this.messages = new ArrayList<>(); + } + + public Result manageGet() { + CurrentUser currentUser = sessionService.retrieveCurrentUserSession(); + IndexViewModelGet indexViewModel = new IndexViewModelGet(); + + ServiceResponse> networkStatusesResponse = updatesService.retrieveNetworkStatuses(); + if (networkStatusesResponse.hasErrors()) { + Logger.error("UpdatesController-manageGet()","Failed to get network statuses"); + throw new RuntimeException(); + } + for (INetworkStatus ns : networkStatusesResponse.getResponseObject()) { + indexViewModel.setNetworkStatus(ns.getName(), ns.getValue()); + } + + ServiceResponse> kitStatusesResponse = updatesService.retrieveKitStatuses(); + if (kitStatusesResponse.hasErrors()) { + Logger.error("UpdatesController-manageGet()","Failed to get kit statuses"); + throw new RuntimeException(); + } + for (IKitStatus ks : kitStatusesResponse.getResponseObject()) { + indexViewModel.setKitStatus(ks.getName(), ks.getValue()); + } + + ServiceResponse> databaseStatusResponse = updatesService.retrieveDatabaseStatuses(); + if (databaseStatusResponse.hasErrors()) { + Logger.error("UpdatesController-manageGet()","Failed to get database backup statuses"); + throw new RuntimeException(); + } + for (IDatabaseStatus ds : databaseStatusResponse.getResponseObject()) { + indexViewModel.setDatabaseStatus(ds.getName(), ds.getValue()); + } + + //TODO setIsUpdateAvailable according to something --- Team Lemur + + return ok(manage.render(currentUser, indexViewModel, assetsFinder, messages)); + } + + //databasePost + public Result databasePost() { + ServiceResponse> databaseStatusesResponse = updatesService.updateDatabaseStatuses(); + this.messages = new ArrayList<>(); + + if (databaseStatusesResponse.hasErrors()) { + Logger.error("UpdatesController-databasePost()","Failed to get database backup statuses"); + throw new RuntimeException(); + } + else + { + messages.add("The database was successfully backed up."); + } + + return manageGet(); + } + + public Result kitUpdatePost() { + this.messages = new ArrayList<>(); + + // TODO just run the script here + // TODO need to check errors + + messages.add("The kit was successfully updated."); + + return manageGet(); + } + +} diff --git a/app/femr/ui/models/admin/updates/IndexViewModelGet.java b/app/femr/ui/models/admin/updates/IndexViewModelGet.java new file mode 100644 index 000000000..9940f61b4 --- /dev/null +++ b/app/femr/ui/models/admin/updates/IndexViewModelGet.java @@ -0,0 +1,54 @@ +package femr.ui.models.admin.updates; + +import java.util.HashMap; +import java.util.Map; + +public class IndexViewModelGet { + private Map networkStatus; + private Map databaseStatus; + private Map kitStatus; + private boolean isUpdateAvailable; + + public IndexViewModelGet(){ + this.networkStatus = new HashMap<>(); + this.databaseStatus = new HashMap<>(); + this.kitStatus = new HashMap<>(); + this.isUpdateAvailable = true; + } + + public Map getNetworkStatus() { return networkStatus; } + public Map getDatabaseStatus() { + return databaseStatus; + } + public Map getKitStatus() { + return kitStatus; + } + public boolean isUpdateAvailable(){ + return this.isUpdateAvailable; + } + + public void setNetworkStatus(String name, String value){ + networkStatus.put(name, value); + } + public void setDatabaseStatus(String name, String value){ + databaseStatus.put(name, value); + } + public void setKitStatus(String name, String value){ + kitStatus.put(name, value); + } + + public void setNetworkStatuses(Map networkStatus) { + this.networkStatus = networkStatus; + } + public void setDatabaseStatuses(Map databaseStatus) { + this.databaseStatus = databaseStatus; + } + public void setKitStatuses(Map kitStatus) { + this.kitStatus = kitStatus; + } + + public void setIsUpdateAvailable(boolean bool){ + this.isUpdateAvailable = bool; + } + +} diff --git a/app/femr/ui/views/admin/updates/manage.scala.html b/app/femr/ui/views/admin/updates/manage.scala.html new file mode 100644 index 000000000..d347e5d08 --- /dev/null +++ b/app/femr/ui/views/admin/updates/manage.scala.html @@ -0,0 +1,84 @@ +@(currentUser: femr.common.dtos.CurrentUser, + viewModel: femr.ui.models.admin.updates.IndexViewModelGet, + assets: AssetsFinder, + messages: java.util.List[_ <: java.lang.String]) + +@import femr.ui.controllers.admin.routes.UpdatesController +@import femr.ui.views.html.layouts.admin + + @additionalStyles = { + + } + @additionalMessages = { + @for(message <- messages) { +

@message

+ } + } + +@admin("Updates", currentUser, styles = additionalStyles, assets = assets, message = additionalMessages) { +
+

Database Status

+ + + @for((key,valyew) <- viewModel.getDatabaseStatus) { + + + + + } + @helper.form(action = UpdatesController.databasePost()) { + + + + + } +
@key:@valyew
Create Backup: + +
+
+ + +
+

Network Status

+ + + @for((key,valyew) <- viewModel.getNetworkStatus) { + + + + + } +
@key:@valyew
+
+ +
+

Available Updates

+ + + @if(viewModel.isUpdateAvailable) { + @helper.form(action = UpdatesController.kitUpdatePost()) { + + } + } else {} + + +
Kit Update: Available + Kit Update: Already up to date
+ +
+ + +
+

fEMR Kit Status

+ + + @for((key2,valyew2) <- viewModel.getKitStatus) { + + + + + } +
@key2:@valyew2
+
+ +} diff --git a/app/femr/ui/views/layouts/admin.scala.html b/app/femr/ui/views/layouts/admin.scala.html index bb7d9a6c1..e32fa0455 100644 --- a/app/femr/ui/views/layouts/admin.scala.html +++ b/app/femr/ui/views/layouts/admin.scala.html @@ -9,6 +9,7 @@ @import femr.ui.views.html.layouts.main @import femr.ui.controllers.admin.routes.UsersController @import femr.ui.controllers.admin.routes.ConfigureController + @import femr.ui.controllers.admin.routes.UpdatesController @import femr.ui.controllers.admin.routes.InventoryController @import femr.ui.controllers.superuser.routes.SuperuserController @import femr.ui.controllers.superuser.routes.TabController @@ -42,6 +43,9 @@ } Users + + + Updates
diff --git a/app/femr/util/dependencyinjection/modules/BusinessLayerModule.java b/app/femr/util/dependencyinjection/modules/BusinessLayerModule.java index 1b8b8be42..96ab4f5b9 100644 --- a/app/femr/util/dependencyinjection/modules/BusinessLayerModule.java +++ b/app/femr/util/dependencyinjection/modules/BusinessLayerModule.java @@ -31,6 +31,7 @@ protected void configure() { //Business Service Injection bind(IConceptService.class).to(ConceptService.class); bind(IConfigureService.class).to(ConfigureService.class); + bind(IUpdatesService.class).to(UpdatesService.class); bind(ITabService.class).to(TabService.class); bind(IEncounterService.class).to(EncounterService.class); bind(IInventoryService.class).to(InventoryService.class); diff --git a/app/femr/util/dependencyinjection/modules/DataLayerModule.java b/app/femr/util/dependencyinjection/modules/DataLayerModule.java index 5315f7ed9..7ab5d18b0 100644 --- a/app/femr/util/dependencyinjection/modules/DataLayerModule.java +++ b/app/femr/util/dependencyinjection/modules/DataLayerModule.java @@ -60,6 +60,9 @@ protected void configure() { bind(IPhoto.class).toProvider(PhotoProvider.class); bind(IRole.class).toProvider(RoleProvider.class); bind(ISystemSetting.class).toProvider(SystemSettingProvider.class); + bind(INetworkStatus.class).toProvider(NetworkStatusProvider.class); + bind(IKitStatus.class).toProvider(KitStatusProvider.class); + bind(IDatabaseStatus.class).toProvider(DatabaseStatusProvider.class); bind(ITab.class).toProvider(TabProvider.class); bind(ITabField.class).toProvider(TabFieldProvider.class); bind(ITabFieldType.class).toProvider(TabFieldTypeProvider.class); @@ -89,6 +92,9 @@ protected void configure() { bind(new TypeLiteral>(){}).to(new TypeLiteral>(){}); bind(new TypeLiteral>() {}).to(new TypeLiteral>() {}); bind(new TypeLiteral>() {}).to(new TypeLiteral>(){}); + bind(new TypeLiteral>() {}).to(new TypeLiteral>(){}); + bind(new TypeLiteral>() {}).to(new TypeLiteral>(){}); + bind(new TypeLiteral>() {}).to(new TypeLiteral>(){}); bind(new TypeLiteral>(){}).to(new TypeLiteral>(){}); bind(new TypeLiteral>(){}).to(new TypeLiteral>(){}); bind(new TypeLiteral>(){}).to(new TypeLiteral>(){}); diff --git a/app/femr/util/dependencyinjection/providers/DatabaseStatusProvider.java b/app/femr/util/dependencyinjection/providers/DatabaseStatusProvider.java new file mode 100644 index 000000000..0edb9472a --- /dev/null +++ b/app/femr/util/dependencyinjection/providers/DatabaseStatusProvider.java @@ -0,0 +1,30 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.util.dependencyinjection.providers; + +import com.google.inject.Provider; +import femr.data.models.core.IDatabaseStatus; +import femr.data.models.mysql.DatabaseStatus; + +public class DatabaseStatusProvider implements Provider { + @Override + public IDatabaseStatus get() { + return new DatabaseStatus(); + } +} \ No newline at end of file diff --git a/app/femr/util/dependencyinjection/providers/KitStatusProvider.java b/app/femr/util/dependencyinjection/providers/KitStatusProvider.java new file mode 100644 index 000000000..bea0ac7e0 --- /dev/null +++ b/app/femr/util/dependencyinjection/providers/KitStatusProvider.java @@ -0,0 +1,30 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.util.dependencyinjection.providers; + +import com.google.inject.Provider; +import femr.data.models.core.IKitStatus; +import femr.data.models.mysql.KitStatus; + +public class KitStatusProvider implements Provider { + @Override + public IKitStatus get() { + return new KitStatus(); + } +} \ No newline at end of file diff --git a/app/femr/util/dependencyinjection/providers/NetworkStatusProvider.java b/app/femr/util/dependencyinjection/providers/NetworkStatusProvider.java new file mode 100644 index 000000000..1d761a2ce --- /dev/null +++ b/app/femr/util/dependencyinjection/providers/NetworkStatusProvider.java @@ -0,0 +1,30 @@ +/* + fEMR - fast Electronic Medical Records + Copyright (C) 2014 Team fEMR + + fEMR is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + fEMR is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with fEMR. If not, see . If + you have any questions, contact . +*/ +package femr.util.dependencyinjection.providers; + +import com.google.inject.Provider; +import femr.data.models.core.INetworkStatus; +import femr.data.models.mysql.NetworkStatus; + +public class NetworkStatusProvider implements Provider { + @Override + public INetworkStatus get() { + return new NetworkStatus(); + } +} \ No newline at end of file diff --git a/app/femr/util/startup/DatabaseSeeder.java b/app/femr/util/startup/DatabaseSeeder.java index 227e6e97d..ef582f823 100644 --- a/app/femr/util/startup/DatabaseSeeder.java +++ b/app/femr/util/startup/DatabaseSeeder.java @@ -47,6 +47,9 @@ public class DatabaseSeeder { private final IRepository missionCityRepository; private final IRepository missionTeamRepository; private final IRepository systemSettingRepository; + private final IRepository networkStatusRepository; + private final IRepository kitStatusRepository; + private final IRepository databaseStatusRepository; private final IRepository tabFieldRepository; private final IRepository tabFieldSizeRepository; private final IRepository tabFieldTypeRepository; @@ -64,6 +67,9 @@ public DatabaseSeeder(IPatientRepository patientRepository, IRepository missionCityRepository, IRepository missionTeamRepository, IRepository systemSettingRepository, + IRepository networkStatusRepository, + IRepository kitStatusRepository, + IRepository databaseStatusRepository, IRepository tabFieldRepository, IRepository tabFieldSizeRepository, IRepository tabFieldTypeRepository, @@ -79,6 +85,9 @@ public DatabaseSeeder(IPatientRepository patientRepository, this.passwordEncryptor = passwordEncryptor; this.diagnosisRepository = diagnosisRepository; this.systemSettingRepository = systemSettingRepository; + this.networkStatusRepository = networkStatusRepository; + this.kitStatusRepository = kitStatusRepository; + this.databaseStatusRepository = databaseStatusRepository; this.tabFieldRepository = tabFieldRepository; this.tabFieldSizeRepository = tabFieldSizeRepository; this.tabFieldTypeRepository = tabFieldTypeRepository; @@ -94,6 +103,9 @@ public DatabaseSeeder(IPatientRepository patientRepository, private void seed() { seedMissionTripInformation(); + seedNetworkStatus(); + seedKitStatus(); + seedDatabaseStatus(); seedSystemSettings(); seedSystemSettingsDescriptions(); seedAdminUser(); @@ -107,6 +119,85 @@ private void seed() { seedVitals(); } + private void seedDatabaseStatus() { + //TODO Feather to set initial values + List databaseStatuses = databaseStatusRepository.findAll(DatabaseStatus.class); + DatabaseStatus databaseStatus; + if (databaseStatuses != null && !containDatabaseStatus(databaseStatuses, "Last Backup")) { + databaseStatus = new DatabaseStatus(); + databaseStatus.setName("Last Backup"); + databaseStatus.setValue("2021.02.17"); + databaseStatusRepository.create(databaseStatus); + } + } + + private void seedKitStatus() { + //TODO Lemur to set initial values + List kitStatuses = kitStatusRepository.findAll(KitStatus.class); + KitStatus kitStatus; + if (kitStatuses != null && !containKitStatus(kitStatuses, "Status")) { + kitStatus = new KitStatus(); + kitStatus.setName("Status"); + kitStatus.setValue("Currently Online"); + kitStatusRepository.create(kitStatus); + } + if (kitStatuses != null && !containKitStatus(kitStatuses, "Version")) { + kitStatus = new KitStatus(); + kitStatus.setName("Version"); + kitStatus.setValue("1.0.0"); + kitStatusRepository.create(kitStatus); + } + if (kitStatuses != null && !containKitStatus(kitStatuses, "Last Update")) { + kitStatus = new KitStatus(); + kitStatus.setName("Last Update"); + kitStatus.setValue("2021.02.17"); + kitStatusRepository.create(kitStatus); + } + if (kitStatuses != null && !containKitStatus(kitStatuses, "Type")) { + kitStatus = new KitStatus(); + kitStatus.setName("Type"); + kitStatus.setValue("Docker Container"); + kitStatusRepository.create(kitStatus); + } + } + + private void seedNetworkStatus() { + //TODO Lemur to set initial values + List networkStatuses = networkStatusRepository.findAll(NetworkStatus.class); + NetworkStatus networkStatus; + if (networkStatuses != null && !containNetworkStatus(networkStatuses, "Status")) { + networkStatus = new NetworkStatus(); + networkStatus.setName("Status"); + networkStatus.setValue("Connection Stable"); + networkStatusRepository.create(networkStatus); + } + if (networkStatuses != null && !containNetworkStatus(networkStatuses, "Download")) { + networkStatus = new NetworkStatus(); + networkStatus.setName("Download"); + networkStatus.setValue("10 Mbps"); + networkStatusRepository.create(networkStatus); + } + if (networkStatuses != null && !containNetworkStatus(networkStatuses, "Upload")) { + networkStatus = new NetworkStatus(); + networkStatus.setName("Upload"); + networkStatus.setValue("1 Mbps"); + networkStatusRepository.create(networkStatus); + } + if (networkStatuses != null && !containNetworkStatus(networkStatuses, "Ping")) { + networkStatus = new NetworkStatus(); + networkStatus.setName("Ping"); + networkStatus.setValue("76 ms"); + networkStatusRepository.create(networkStatus); + } + if (networkStatuses != null && !containNetworkStatus(networkStatuses, "Last Available")) { + networkStatus = new NetworkStatus(); + networkStatus.setName("Last Available"); + networkStatus.setValue("2021.02.17"); + networkStatusRepository.create(networkStatus); + } + } + + private void seedVitals() { List vitals = vitalRepository.findAll(Vital.class); @@ -1073,6 +1164,33 @@ private static boolean containSetting(List systemSetti return false; } + private static boolean containNetworkStatus(List networkStatuses, String name) { + for (INetworkStatus ns : networkStatuses) { + if (ns.getName().equals(name)) { + return true; + } + } + return false; + } + + private static boolean containKitStatus(List kitStatuses, String name) { + for (IKitStatus ks : kitStatuses) { + if (ks.getName().equals(name)) { + return true; + } + } + return false; + } + + private static boolean containDatabaseStatus(List databaseStatuses, String name) { + for (IDatabaseStatus ds : databaseStatuses) { + if (ds.getName().equals(name)) { + return true; + } + } + return false; + } + private static boolean containTabField(List tabFields, String tabField) { for (ITabField tf : tabFields) { if (tf.getName().equals(tabField)) { diff --git a/conf/evolutions/default/110.sql b/conf/evolutions/default/110.sql new file mode 100644 index 000000000..f031b00a4 --- /dev/null +++ b/conf/evolutions/default/110.sql @@ -0,0 +1,12 @@ +# --- !Ups + +CREATE TABLE `network_status` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `val` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `id_UNIQUE` (`id` ASC)); + +# --- !Downs + +DROP TABLE `network_status`; \ No newline at end of file diff --git a/conf/evolutions/default/111.sql b/conf/evolutions/default/111.sql new file mode 100644 index 000000000..8ba69d2ed --- /dev/null +++ b/conf/evolutions/default/111.sql @@ -0,0 +1,12 @@ +# --- !Ups + +CREATE TABLE `kit_status` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `val` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `id_UNIQUE` (`id` ASC)); + +# --- !Downs + +DROP TABLE `kit_status`; \ No newline at end of file diff --git a/conf/evolutions/default/112.sql b/conf/evolutions/default/112.sql new file mode 100644 index 000000000..0218fb75c --- /dev/null +++ b/conf/evolutions/default/112.sql @@ -0,0 +1,12 @@ +# --- !Ups + +CREATE TABLE `database_status` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `val` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `id_UNIQUE` (`id` ASC)); + +# --- !Downs + +DROP TABLE `database_status`; \ No newline at end of file diff --git a/conf/routes b/conf/routes index d7fbb5d63..389e00b75 100644 --- a/conf/routes +++ b/conf/routes @@ -28,6 +28,9 @@ POST /admin/inventory/editCurrent/:id/:tripId @femr.ui.controll POST /admin/inventory/editTotal/:id/:tripId @femr.ui.controllers.admin.InventoryController.ajaxEditTotal(id: Integer, tripId: Integer) GET /admin/configure @femr.ui.controllers.admin.ConfigureController.manageGet() POST /admin/configure @femr.ui.controllers.admin.ConfigureController.managePost() +GET /admin/updates @femr.ui.controllers.admin.UpdatesController.manageGet() +POST /admin/updates/database @femr.ui.controllers.admin.UpdatesController.databasePost() +POST /admin/updates/kit @femr.ui.controllers.admin.UpdatesController.kitUpdatePost() GET /admin/trips @femr.ui.controllers.admin.TripController.manageGet() POST /admin/trips @femr.ui.controllers.admin.TripController.managePost() GET /admin/trips/edit/:id @femr.ui.controllers.admin.TripController.editGet(id: Integer) diff --git a/test/unit/app/femr/data/models/mysql/DatabaseStatusTest.java b/test/unit/app/femr/data/models/mysql/DatabaseStatusTest.java new file mode 100644 index 000000000..aa50bc03a --- /dev/null +++ b/test/unit/app/femr/data/models/mysql/DatabaseStatusTest.java @@ -0,0 +1,33 @@ +package unit.app.femr.data.models.mysql; + +import femr.data.models.mysql.DatabaseStatus; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class DatabaseStatusTest { + DatabaseStatus ds; + + @Before + public void setUp() { + ds = new DatabaseStatus(); + } + + @Test + public void checkId(){ + ds.setId(123); + assertEquals(123, ds.getId()); + } + + @Test + public void checkName(){ + ds.setName("very cool database"); + assertEquals("very cool database", ds.getName()); + } + + @Test + public void checkValue(){ + ds.setValue("connected"); + assertEquals("connected", ds.getValue()); + } +} diff --git a/test/unit/app/femr/data/models/mysql/KitStatusTest.java b/test/unit/app/femr/data/models/mysql/KitStatusTest.java new file mode 100644 index 000000000..803105d64 --- /dev/null +++ b/test/unit/app/femr/data/models/mysql/KitStatusTest.java @@ -0,0 +1,33 @@ +package unit.app.femr.data.models.mysql; + +import femr.data.models.mysql.KitStatus; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class KitStatusTest { + KitStatus ks; + + @Before + public void setUp() { + ks = new KitStatus(); + } + + @Test + public void checkId(){ + ks.setId(123); + assertEquals(123, ks.getId()); + } + + @Test + public void checkName(){ + ks.setName("KitA"); + assertEquals("KitA", ks.getName()); + } + + @Test + public void checkValue(){ + ks.setValue("deployed"); + assertEquals("deployed", ks.getValue()); + } +} diff --git a/test/unit/app/femr/data/models/mysql/KitUpdateTest.java b/test/unit/app/femr/data/models/mysql/KitUpdateTest.java new file mode 100644 index 000000000..1ad8f2814 --- /dev/null +++ b/test/unit/app/femr/data/models/mysql/KitUpdateTest.java @@ -0,0 +1,33 @@ +package unit.app.femr.data.models.mysql; + +import femr.data.models.mysql.KitUpdate; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class KitUpdateTest { + KitUpdate ku; + + @Before + public void setUp() { + ku = new KitUpdate(); + } + + @Test + public void checkId(){ + ku.setId(123); + assertEquals(123, ku.getId()); + } + + @Test + public void checkName(){ + ku.setName("new schema update"); + assertEquals("new schema update", ku.getName()); + } + + @Test + public void checkValue(){ + ku.setValue("completed"); + assertEquals("completed", ku.getValue()); + } +} diff --git a/test/unit/app/femr/data/models/mysql/NetworkStatusTest.java b/test/unit/app/femr/data/models/mysql/NetworkStatusTest.java new file mode 100644 index 000000000..cec399f43 --- /dev/null +++ b/test/unit/app/femr/data/models/mysql/NetworkStatusTest.java @@ -0,0 +1,34 @@ +package unit.app.femr.data.models.mysql; + +import femr.data.models.mysql.NetworkStatus; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class NetworkStatusTest { + NetworkStatus nt; + + @Before + public void setUp() { + nt = new NetworkStatus(); + } + + @Test + public void checkId(){ + nt.setId(123); + assertEquals(123, nt.getId()); + } + + @Test + public void checkName(){ + nt.setName("NetworkA"); + assertEquals("NetworkA", nt.getName()); + } + + @Test + public void checkValue(){ + nt.setValue("connected"); + assertEquals("connected", nt.getValue()); + } + +}