Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic dashboard statistics #156

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ config/dev-gcloud-creds-sql.json
config/test-gcloud-creds.json
config/staging-gcloud-creds.json
config/prod-gcloud-creds.json
config/ellkay.conf
liquibase.properties

src/test/resources/output
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/broadinstitute/dsm/DSMServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.broadinstitute.dsm.log.SlackAppender;
import org.broadinstitute.dsm.pubsub.PubSubResultMessageSubscription;
import org.broadinstitute.dsm.route.*;
import org.broadinstitute.dsm.route.dynamicdashboard.StatisticDataRoute;
import org.broadinstitute.dsm.route.familymember.AddFamilyMemberRoute;
import org.broadinstitute.dsm.route.participant.GetParticipantDataRoute;
import org.broadinstitute.dsm.security.JWTConverter;
Expand Down Expand Up @@ -529,6 +530,9 @@ private void setupMiscellaneousRoutes() {

GetParticipantDataRoute getParticipantDataRoute = new GetParticipantDataRoute();
get(UI_ROOT + RoutePath.GET_PARTICIPANT_DATA, getParticipantDataRoute, new JsonTransformer());

StatisticDataRoute statisticDataRoute = new StatisticDataRoute();
get(UI_ROOT + RoutePath.GET_STATISTICS, statisticDataRoute, new JsonTransformer());
}

private void setupSharedRoutes(@NonNull KitUtil kitUtil, @NonNull NotificationUtil notificationUtil,
Expand Down
28 changes: 1 addition & 27 deletions src/main/java/org/broadinstitute/dsm/db/DDPInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,6 @@ public DDPInstance(String ddpInstanceId, String name, String baseUrl, String col
this.usersIndexES = usersIndexES;
}

public static DDPInstance getDDPInstance(@NonNull String realm) {
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(SQL_SELECT_ALL_ACTIVE_REALMS + QueryExtension.BY_INSTANCE_NAME)) {
stmt.setString(1, realm);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
dbVals.resultValue = getDDPInstanceFormResultSet(rs);
}
}
catch (SQLException e) {
throw new RuntimeException("Error getting information for " + realm, e);
}
}
catch (SQLException ex) {
dbVals.resultException = ex;
}
return dbVals;
});

if (results.resultException != null) {
throw new RuntimeException("Couldn't get realm information for " + realm, results.resultException);
}
return (DDPInstance) results.resultValue;
}

public static DDPInstance getDDPInstanceById(@NonNull Integer ddpInstanceId) {
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
Expand Down Expand Up @@ -256,7 +230,7 @@ private static DDPInstance getDDPInstanceWithRoleFormResultSet(@NonNull ResultSe
rs.getString(DBConstants.ES_USERS_INDEX));
}

private static DDPInstance getDDPInstanceFormResultSet(@NonNull ResultSet rs) throws SQLException {
public static DDPInstance getDDPInstanceFormResultSet(@NonNull ResultSet rs) throws SQLException {
String notificationRecipient = rs.getString(DBConstants.NOTIFICATION_RECIPIENT);
List<String> recipients = null;
if (StringUtils.isNotBlank(notificationRecipient)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.NonNull;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.ddp.db.TransactionWrapper;
import org.broadinstitute.dsm.db.dao.ddp.instance.DDPInstanceDao;
import org.broadinstitute.dsm.model.ddp.DDPParticipant;
import org.broadinstitute.dsm.statics.ApplicationConfigConstants;
import org.broadinstitute.dsm.statics.DBConstants;
Expand Down Expand Up @@ -63,7 +64,7 @@ public static Collection<ParticipantEvent> getSkippedParticipantEvents(@NonNull
logger.error("Couldn't get list of skipped participant events for " + realm, results.resultException);
}
else {
DDPInstance instance = DDPInstance.getDDPInstance(realm);
DDPInstance instance = DDPInstanceDao.getDDPInstanceByRealm(realm);
for (ParticipantEvent skippedParticipant : skippedParticipantEvents) {
String sendRequest = instance.getBaseUrl() + RoutePath.DDP_PARTICIPANTS_PATH + "/" + skippedParticipant.getParticipantId();
try {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broadinstitute/dsm/db/ParticipantExit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.dao.ddp.instance.DDPInstanceDao;
import org.broadinstitute.dsm.model.ddp.DDPParticipant;
import org.broadinstitute.dsm.statics.DBConstants;
import org.broadinstitute.dsm.util.ElasticSearchUtil;
Expand Down Expand Up @@ -82,7 +83,7 @@ public static Map<String, ParticipantExit> getExitedParticipants(@NonNull String
}

private static void addParticipantInformation(@NonNull String realm, @NonNull Collection<ParticipantExit> exitedParticipants) {
DDPInstance instance = DDPInstance.getDDPInstance(realm);
DDPInstance instance = DDPInstanceDao.getDDPInstanceByRealm(realm);
if (!instance.isHasRole()) {
if (StringUtils.isNotBlank(instance.getParticipantIndexES())) {
Map<String, Map<String, Object>> participantsESData = ElasticSearchUtil.getDDPParticipantsFromES(realm, instance.getParticipantIndexES());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.broadinstitute.dsm.db.dao.dashboardsettings;

import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.dao.Dao;
import org.broadinstitute.dsm.db.dto.dashboardsettings.DashboardSettingsDto;
import org.broadinstitute.dsm.db.dto.participant.data.ParticipantDataDto;

public class DashboardSettingsDao implements Dao<DashboardSettingsDto> {

private static String SQL_DASHBOARD_SETTINGS_BY_INSTANCE_ID = "SELECT " +
"dashboard_settings_id, " +
"ddp_instance_id, " +
"display_text, " +
"display_type, " +
"possible_values, " +
"filter_type, " +
"statistic_for, " +
"order_id " +
"FROM dashboard_settings WHERE ddp_instance_id = ?";

private static final String DASHBOARD_SETTINGS_ID = "dashboard_settings_id";
private static final String DDP_INSTANCE_ID = "ddp_instance_id";
private static final String DISPLAY_TEXT = "display_text";
private static final String POSSIBLE_VALUES = "possible_values";
private static final String FILTER_TYPE = "filter_type";
private static final String ORDER_ID = "order_id";
private static final String DISPLAY_TYPE = "display_type";
private static final String STATISTIC_FOR = "statistic_for";


@Override
public int create(DashboardSettingsDto dashboardSettingsDto) {
return 0;
}

@Override
public int delete(int id) {
return 0;
}

@Override
public Optional<DashboardSettingsDto> get(long id) {
return Optional.empty();
}

public List<DashboardSettingsDto> getDashboardSettingsByInstanceId(int instanceId) {
List<DashboardSettingsDto> dashboardSettingsDtos = new ArrayList<>();
SimpleResult results = inTransaction((conn) -> {
SimpleResult execResult = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(SQL_DASHBOARD_SETTINGS_BY_INSTANCE_ID)) {
stmt.setInt(1, instanceId);
try(ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
dashboardSettingsDtos.add(
new DashboardSettingsDto(
rs.getInt(DASHBOARD_SETTINGS_ID),
rs.getInt(DDP_INSTANCE_ID),
rs.getString(DISPLAY_TEXT),
rs.getString(DISPLAY_TYPE),
rs.getString(POSSIBLE_VALUES),
rs.getString(FILTER_TYPE),
rs.getString(STATISTIC_FOR),
rs.getInt(ORDER_ID)
)
);
}
}
}
catch (SQLException ex) {
execResult.resultException = ex;
}
return execResult;
});
if (results.resultException != null) {
throw new RuntimeException("Error getting dashboard data with instance id: "
+ instanceId, results.resultException);
}
return dashboardSettingsDtos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.NonNull;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.DDPInstance;
import org.broadinstitute.dsm.db.dao.Dao;
import org.broadinstitute.dsm.db.dto.ddp.instance.DDPInstanceDto;
import org.broadinstitute.dsm.statics.DBConstants;
Expand Down Expand Up @@ -75,6 +76,32 @@ public static boolean getRole(@NonNull String realm, @NonNull String role) {
return (boolean) results.resultValue;
}

public static DDPInstance getDDPInstanceByRealm(@NonNull String realm) {
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(DDPInstance.SQL_SELECT_ALL_ACTIVE_REALMS + QueryExtension.BY_INSTANCE_NAME)) {
stmt.setString(1, realm);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
dbVals.resultValue = DDPInstance.getDDPInstanceFormResultSet(rs);
}
}
catch (SQLException e) {
throw new RuntimeException("Error getting information for " + realm, e);
}
}
catch (SQLException ex) {
dbVals.resultException = ex;
}
return dbVals;
});

if (results.resultException != null) {
throw new RuntimeException("Couldn't get realm information for " + realm, results.resultException);
}
return (DDPInstance) results.resultValue;
}

@Override
public int create(DDPInstanceDto ddpInstanceDto) {
SimpleResult simpleResult = inTransaction(conn -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.broadinstitute.dsm.db.dto.dashboardsettings;


import lombok.Data;

@Data
public class DashboardSettingsDto {

private int dashboardSettingsId;
private int ddpInstanceId;
private String displayText;
private String displayType;
private String possibleValues;
private String filterType;
private String statisticFor;
private int orderId;

public DashboardSettingsDto(int dashboardSettingsId, int ddpInstanceId, String displayText, String displayType,
String possibleValues, String filterType, String statisticFor, int orderId) {
this.dashboardSettingsId = dashboardSettingsId;
this.ddpInstanceId = ddpInstanceId;
this.displayText = displayText;
this.displayType = displayType;
this.possibleValues = possibleValues;
this.filterType = filterType;
this.statisticFor = statisticFor;
this.orderId = orderId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.DDPInstance;
import org.broadinstitute.dsm.db.ParticipantData;
import org.broadinstitute.dsm.db.dao.ddp.instance.DDPInstanceDao;
import org.broadinstitute.dsm.util.NotificationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -43,7 +44,7 @@ public static boolean receiveATKitRequest(@NonNull NotificationUtil notification

String dataString = new Gson().toJson(data);
if (updateData(dataString, participantData.getDataId())) {
DDPInstance ddpInstance = DDPInstance.getDDPInstance("atcp");
DDPInstance ddpInstance = DDPInstanceDao.getDDPInstanceByRealm("atcp");
List<String> recipients = ddpInstance.getNotificationRecipient();
if (recipients != null && !recipients.isEmpty()) {
for (String recipient : recipients) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.broadinstitute.dsm.db.DDPInstance;
import org.broadinstitute.dsm.db.KitRequestShipping;
import org.broadinstitute.dsm.db.ParticipantData;
import org.broadinstitute.dsm.db.dao.ddp.instance.DDPInstanceDao;
import org.broadinstitute.dsm.statics.DBConstants;
import org.broadinstitute.dsm.util.ElasticSearchUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -104,7 +105,7 @@ else if (SHORT_ID.equals(field)) {

//add ES information
if (!kitRequests.isEmpty()) {
DDPInstance ddpInstance = DDPInstance.getDDPInstance("atcp");
DDPInstance ddpInstance = DDPInstanceDao.getDDPInstanceByRealm("atcp");
kitRequests.forEach((ddpParticipantId, kitRequestShipping) -> {
Map<String, Map<String, Object>> participantESData = ElasticSearchUtil.getFilteredDDPParticipantsFromES(ddpInstance,
ElasticSearchUtil.BY_GUID + ddpParticipantId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

public enum DisplayType {
COUNTER,
GRAPH_BAR;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

public enum FilterType {
REGISTERED,
ENROLLED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

public interface Statistic {

StatisticResult filter(StatisticPayload statisticPayload);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

public interface StatisticFactory {

Statistic makeStatistic(StatisticPayload statisticPayload);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

public enum StatisticFor {
PARTICIPANT,
MEDICAL_RECORD;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

import lombok.Data;

@Data
public class StatisticPayload {

private DisplayType displayType;
private StatisticFor statisticFor;
private FilterType filterType;

public StatisticPayload(DisplayType displayType, StatisticFor statisticFor, FilterType filterType) {
this.displayType = displayType;
this.statisticFor = statisticFor;
this.filterType = filterType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

public abstract class StatisticResult {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.broadinstitute.dsm.model.dynamicdashboard;

import org.broadinstitute.dsm.model.dynamicdashboard.counter.participant.ParticipantCounter;

public class StatisticsCreator implements StatisticFactory {

@Override
public Statistic makeStatistic(StatisticPayload statisticPayload) {
Statistic statistic = statisticPayload1 -> null;
switch (statisticPayload.getDisplayType()) {
case COUNTER:
switch (statisticPayload.getStatisticFor()) {
case PARTICIPANT:
statistic = new ParticipantCounter();
break;
case MEDICAL_RECORD:
break;
default:
break;
}
break;
case GRAPH_BAR:
break;
default:
break;
}
return statistic;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.broadinstitute.dsm.model.dynamicdashboard.counter;

import org.broadinstitute.dsm.model.dynamicdashboard.Statistic;

public abstract class Counter implements Statistic {

}
Loading