Skip to content

Commit

Permalink
Merge pull request #342 from broadinstitute/DDP-7121_participant_filter
Browse files Browse the repository at this point in the history
ElasticSearch feature | patchroute refactoring -> elastic export -> data migration -> refactoring participant list
  • Loading branch information
gmakharat authored Feb 11, 2022
2 parents eed78ad + a6b2db4 commit 4d6846d
Show file tree
Hide file tree
Showing 248 changed files with 9,154 additions and 2,400 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/broadinstitute/dsm/db/KitDiscard.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ else if (IMAGE_FILE.equals(pathName)) {
}
}

public static String addKitToDiscard(@NonNull String kitRequestId, @NonNull String action) {
public static String addKitToDiscard(@NonNull long kitRequestId, @NonNull String action) {
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(TransactionWrapper.getSqlFromConfig(ApplicationConfigConstants.INSERT_KIT_DISCARD), Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, action);
stmt.setString(2, kitRequestId);
stmt.setLong(2, kitRequestId);
int result = stmt.executeUpdate();
if (result == 1) {
try (ResultSet rs = stmt.getGeneratedKeys()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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.db.dto.ddp.instance.DDPInstanceDto;
import org.broadinstitute.dsm.model.KitRequestSettings;
import org.broadinstitute.dsm.model.KitType;
import org.broadinstitute.dsm.statics.DBConstants;
Expand Down Expand Up @@ -66,10 +68,10 @@ public KitRequestCreateLabel(@NonNull String dsmKitId, @NonNull String dsmKitReq
/**
* Set given kitRequests to need label
*/
public static void updateKitLabelRequested(KitRequestShipping[] kitRequests, @NonNull String userId) {
public static void updateKitLabelRequested(KitRequestShipping[] kitRequests, @NonNull String userId, DDPInstanceDto ddpInstanceDto) {
if (kitRequests.length > 0) {
for (KitRequestShipping kitRequest : kitRequests) {
KitRequestShipping.updateKit(kitRequest.getDsmKitId(), userId);
KitRequestShipping.updateKit(kitRequest.getDsmKitId(), userId, ddpInstanceDto);
}
logger.info("Done triggering label creation");
}
Expand All @@ -79,7 +81,8 @@ public static void updateKitLabelRequested(KitRequestShipping[] kitRequests, @No
* Select all sample requests without kit per realm
* optional per kit type
*/
public static void updateKitLabelRequested(String realm, String type, @NonNull String userId) {
public static void updateKitLabelRequested(String realm, String type, @NonNull String userId,
DDPInstanceDto ddpInstanceDto) {
List<KitRequestCreateLabel> kitsNoLabel = new ArrayList<>();
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
Expand Down Expand Up @@ -109,10 +112,9 @@ public static void updateKitLabelRequested(String realm, String type, @NonNull S
throw new RuntimeException("Error looking up the latestKitRequests ", results.resultException);
}
logger.info("Found " + kitsNoLabel.size() + " kit requests which need a label");

if (!kitsNoLabel.isEmpty()) {
for (KitRequestCreateLabel uploadedKit : kitsNoLabel) {
KitRequestShipping.updateKit(uploadedKit.getDsmKitId(), userId);
KitRequestShipping.updateKit(Long.parseLong(uploadedKit.getDsmKitId()), userId, ddpInstanceDto);
}
}
logger.info("Done triggering label creation");
Expand Down
334 changes: 232 additions & 102 deletions src/main/java/org/broadinstitute/dsm/db/KitRequestShipping.java

Large diffs are not rendered by default.

130 changes: 98 additions & 32 deletions src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
package org.broadinstitute.dsm.db;

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

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.ddp.handlers.util.InstitutionDetail;
import org.broadinstitute.ddp.handlers.util.MedicalInfo;
import org.broadinstitute.dsm.DSMServer;
import org.broadinstitute.dsm.db.structure.ColumnName;
import org.broadinstitute.dsm.db.structure.DbDateConversion;
import org.broadinstitute.dsm.db.structure.SqlDateConverter;
import org.broadinstitute.dsm.db.structure.TableName;
import org.broadinstitute.dsm.model.FollowUp;
import org.broadinstitute.dsm.statics.*;
import org.broadinstitute.dsm.statics.DBConstants;
import org.broadinstitute.dsm.statics.QueryExtension;
import org.broadinstitute.dsm.statics.RequestParameter;
import org.broadinstitute.dsm.statics.RoutePath;
import org.broadinstitute.dsm.util.DBUtil;
import org.broadinstitute.dsm.util.DDPRequestUtil;
import org.broadinstitute.dsm.util.proxy.jackson.ObjectMapperSingleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.*;
import java.util.*;

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

@TableName (
name = DBConstants.DDP_MEDICAL_RECORD,
alias = DBConstants.DDP_MEDICAL_RECORD_ALIAS,
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MedicalRecord {

private static final Logger logger = LoggerFactory.getLogger(MedicalRecord.class);
Expand All @@ -45,9 +63,36 @@ public class MedicalRecord {
"LEFT JOIN ddp_medical_record as m on (m.institution_id = inst.institution_id) WHERE p.participant_id = ?";
public static final String SQL_ORDER_BY = " ORDER BY p.ddp_participant_id, inst.ddp_institution_id ASC";

private final String medicalRecordId;
private String institutionId;
@TableName (
name = DBConstants.DDP_MEDICAL_RECORD,
alias = DBConstants.DDP_MEDICAL_RECORD_ALIAS,
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@ColumnName (DBConstants.MEDICAL_RECORD_ID)
private long medicalRecordId;

@TableName (
name = DBConstants.DDP_INSTITUTION,
alias = DBConstants.DDP_INSTITUTION_ALIAS,
primaryKey = DBConstants.INSTITUTION_ID,
columnPrefix = "")
@ColumnName (DBConstants.INSTITUTION_ID)
private long institutionId;

@TableName (
name = DBConstants.DDP_INSTITUTION,
alias = DBConstants.DDP_INSTITUTION_ALIAS,
primaryKey = DBConstants.DDP_INSTITUTION_ID,
columnPrefix = "")
@ColumnName (DBConstants.DDP_INSTITUTION_ID)
private String ddpInstitutionId;

@TableName (
name = DBConstants.DDP_PARTICIPANT,
alias = DBConstants.DDP_PARTICIPANT_ALIAS,
primaryKey = DBConstants.DDP_PARTICIPANT_ID,
columnPrefix = "")
@ColumnName (DBConstants.DDP_PARTICIPANT_ID)
private String ddpParticipantId;

@TableName (
Expand Down Expand Up @@ -223,23 +268,31 @@ public class MedicalRecord {
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@ColumnName (DBConstants.MR_UNABLE_OBTAIN_TEXT)
private String mrUnableToObtainText;
private String unableObtainText;

@TableName (
name = DBConstants.DDP_MEDICAL_RECORD,
alias = DBConstants.DDP_MEDICAL_RECORD_ALIAS,
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@ColumnName (DBConstants.FOLLOWUP_REQUIRED)
private boolean followUpRequired;
private boolean followupRequired;

@JsonProperty("followupRequired")
public boolean isFollowupRequired() {
return followupRequired;
}

@TableName (
name = DBConstants.DDP_MEDICAL_RECORD,
alias = DBConstants.DDP_MEDICAL_RECORD_ALIAS,
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@ColumnName (DBConstants.FOLLOWUP_REQUIRED_TEXT)
private String followUpRequiredText;
private String followupRequiredText;

@JsonProperty("followupRequiredText")
public String getFollowupRequiredText() { return followupRequiredText; }

@TableName (
name = DBConstants.DDP_MEDICAL_RECORD,
Expand Down Expand Up @@ -271,7 +324,7 @@ public class MedicalRecord {
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@ColumnName (DBConstants.NOTES)
private String mrNotes;
private String notes;

@TableName (
name = DBConstants.DDP_MEDICAL_RECORD,
Expand All @@ -286,8 +339,19 @@ public class MedicalRecord {
alias = DBConstants.DDP_MEDICAL_RECORD_ALIAS,
primaryKey = DBConstants.MEDICAL_RECORD_ID,
columnPrefix = "")
@ColumnName (DBConstants.ADDITIONAL_VALUES)
private String additionalValues;
@ColumnName (DBConstants.ADDITIONAL_VALUES_JSON)
@JsonProperty("dynamicFields")
@SerializedName("dynamicFields")
private String additionalValuesJson;

@JsonProperty("dynamicFields")
public Map<String, Object> getDynamicFields() {
try {
return ObjectMapperSingleton.instance().readValue(additionalValuesJson, new TypeReference<Map<String, Object>>() {});
} catch (IOException | NullPointerException e) {
return Map.of();
}
}

private boolean reviewMedicalRecord;

Expand All @@ -299,23 +363,25 @@ public class MedicalRecord {
@ColumnName (DBConstants.PATHOLOGY_PRESENT)
private String pathologyPresent;

public MedicalRecord(String medicalRecordId, String institutionId, String ddpInstitutionId, String type) {
public MedicalRecord(long medicalRecordId, long institutionId, String ddpInstitutionId, String type) {
this.medicalRecordId = medicalRecordId;
this.institutionId = institutionId;
this.ddpInstitutionId = ddpInstitutionId;
this.type = type;
}

public MedicalRecord(String medicalRecordId, String institutionId, String ddpInstitutionId, String type,
public MedicalRecord() {}

public MedicalRecord(long medicalRecordId, long institutionId, String ddpInstitutionId, String type,
String name, String contact, String phone, String fax,
String faxSent, String faxSentBy, String faxConfirmed,
String faxSent2, String faxSent2By, String faxConfirmed2,
String faxSent3, String faxSent3By, String faxConfirmed3,
String mrReceived, String mrDocument, String mrDocumentFileNames, boolean mrProblem,
String mrProblemText, boolean unableObtain, boolean duplicate, boolean international, boolean crRequired,
String pathologyPresent, String mrNotes, boolean reviewMedicalRecord,
FollowUp[] followUps, boolean followUpRequired, String followUpRequiredText, String additionalValues,
String mrUnableToObtainText, String ddpParticipantId) {
FollowUp[] followUps, boolean followUpRequired, String followupRequiredText, String additionalValuesJson,
String unableObtainText, String ddpParticipantId) {
this.medicalRecordId = medicalRecordId;
this.institutionId = institutionId;
this.ddpInstitutionId = ddpInstitutionId;
Expand Down Expand Up @@ -343,20 +409,20 @@ public MedicalRecord(String medicalRecordId, String institutionId, String ddpIns
this.international = international;
this.crRequired = crRequired;
this.pathologyPresent = pathologyPresent;
this.mrNotes = mrNotes;
this.notes = mrNotes;
this.reviewMedicalRecord = reviewMedicalRecord;
this.followUps = followUps;
this.followUpRequired = followUpRequired;
this.followUpRequiredText = followUpRequiredText;
this.additionalValues = additionalValues;
this.mrUnableToObtainText = mrUnableToObtainText;
this.followupRequired = followUpRequired;
this.followupRequiredText = followupRequiredText;
this.additionalValuesJson = additionalValuesJson;
this.unableObtainText = unableObtainText;
this.ddpParticipantId = ddpParticipantId;
}

public static MedicalRecord getMedicalRecord(@NonNull ResultSet rs) throws SQLException {
MedicalRecord medicalRecord = new MedicalRecord(
rs.getString(DBConstants.MEDICAL_RECORD_ID),
rs.getString(DBConstants.INSTITUTION_ID),
rs.getLong(DBConstants.MEDICAL_RECORD_ID),
rs.getLong(DBConstants.INSTITUTION_ID),
rs.getString(DBConstants.DDP_INSTITUTION_ID),
rs.getString(DBConstants.TYPE),
rs.getString(DBConstants.NAME),
Expand Down Expand Up @@ -387,7 +453,7 @@ public static MedicalRecord getMedicalRecord(@NonNull ResultSet rs) throws SQLEx
new Gson().fromJson(rs.getString(DBConstants.FOLLOW_UP_REQUESTS), FollowUp[].class),
rs.getBoolean(DBConstants.FOLLOWUP_REQUIRED),
rs.getString(DBConstants.FOLLOWUP_REQUIRED_TEXT),
rs.getString(DBConstants.ADDITIONAL_VALUES),
rs.getString(DBConstants.ADDITIONAL_VALUES_JSON),
rs.getString(DBConstants.MR_UNABLE_OBTAIN_TEXT),
rs.getString(DBConstants.DDP_PARTICIPANT_ID)
);
Expand Down Expand Up @@ -484,8 +550,8 @@ public static List<MedicalRecord> getInstitutions(@NonNull String realm, @NonNul
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
medicalRecords.add(new MedicalRecord(
rs.getString(DBConstants.MEDICAL_RECORD_ID),
rs.getString(DBConstants.INSTITUTION_ID),
rs.getLong(DBConstants.MEDICAL_RECORD_ID),
rs.getLong(DBConstants.INSTITUTION_ID),
rs.getString(DBConstants.DDP_INSTITUTION_ID),
rs.getString(DBConstants.TYPE)));
}
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/org/broadinstitute/dsm/db/OncHistory.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.broadinstitute.dsm.db;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.NonNull;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.structure.DbDateConversion;
import org.broadinstitute.dsm.db.structure.SqlDateConverter;
import org.broadinstitute.dsm.model.NameValue;
import org.broadinstitute.dsm.util.SystemUtil;
import org.slf4j.Logger;
Expand All @@ -12,25 +17,33 @@

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

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class OncHistory {

private static final Logger logger = LoggerFactory.getLogger(OncHistory.class);

private static final String SQL_UPDATE_ONC_HISTORY = "UPDATE ddp_onc_history SET created = ?, last_changed = ?, changed_by = ? WHERE participant_id = ? AND created IS NULL";

private final String participantId;
private final String created;
private final String reviewed;
private final String changedBy;
private long participantId;

public OncHistory (String participantId, String created, String reviewed, String changedBy) {
@DbDateConversion(SqlDateConverter.STRING_DAY)
private String created;

@DbDateConversion(SqlDateConverter.STRING_DAY)
private String reviewed;
private String changedBy;

public OncHistory() {}

public OncHistory (long participantId, String created, String reviewed, String changedBy) {
this.participantId = participantId;
this.created = created;
this.reviewed = reviewed;
this.changedBy = changedBy;
}

public String getParticipantId() {
public long getParticipantId() {
return participantId;
}

Expand Down
Loading

0 comments on commit 4d6846d

Please sign in to comment.