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

DDP-6034-SMIDS #320

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6fe84f7
added the columns to liquibase and to queries
pegahtah Aug 12, 2021
5ec1978
Merge remote-tracking branch 'origin/develop' into DDP-6034-SMIDS
pegahtah Nov 15, 2021
613b600
added the backend side of sm ids for Tissue
pegahtah Nov 18, 2021
9bcef0d
added the backend side of sm ids for Tissue to be saved in different …
pegahtah Nov 22, 2021
fb0b8fa
added changes for DDP-7163
pegahtah Nov 22, 2021
9771739
changed the liquibase
pegahtah Nov 22, 2021
24d830c
added the Dao
pegahtah Nov 22, 2021
18bbbf3
added ability to receive a ffpe sm_id
pegahtah Nov 23, 2021
1a533d0
changed how smid is received
pegahtah Nov 23, 2021
b3030f7
addressed PR comments
pegahtah Nov 23, 2021
de271e5
debugging
pegahtah Nov 23, 2021
b00cf84
fixed the part where a sm id is assigned to invalid participant
pegahtah Nov 23, 2021
48197f7
added `ClinicalKitWrapper` to make json for PE-CGS
pegahtah Nov 24, 2021
19c470b
changes for filtering
pegahtah Nov 29, 2021
590fb89
added
pegahtah Nov 29, 2021
a192f32
added changes to fix how we get the sm ids
pegahtah Dec 1, 2021
4047aab
throwing errors for null accession number and added checks wheen crea…
pegahtah Dec 1, 2021
3f83726
Changed the way of making onc history to be better readable
pegahtah Dec 9, 2021
b63b4b1
added unique constraint
pegahtah Dec 10, 2021
5c90966
Merge remote-tracking branch 'origin/develop' into DDP-6034-SMIDS
pegahtah Dec 15, 2021
e8e46bd
Merge remote-tracking branch 'origin/develop' into DDP-6034-SMIDS
pegahtah Dec 20, 2021
0d3c589
fixes from prod changes after QA
pegahtah Dec 29, 2021
212bba9
fixed the clinical kit bug and added more conditions for creating the…
pegahtah Jan 3, 2022
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
17 changes: 11 additions & 6 deletions src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@
import com.google.gson.Gson;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.*;
import java.util.*;
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 static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction;

Expand Down
148 changes: 117 additions & 31 deletions src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java

Large diffs are not rendered by default.

81 changes: 70 additions & 11 deletions src/main/java/org/broadinstitute/dsm/db/Tissue.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction;
Expand All @@ -30,7 +31,9 @@ public class Tissue {
private static final String SQL_SELECT_TISSUE = "SELECT tissue_id, onc_history_detail_id, notes, count_received, tissue_type, tissue_site, tumor_type, h_e, " +
"pathology_report, collaborator_sample_id, block_sent, expected_return, return_date, return_fedex_id, scrolls_received, sk_id, sm_id, " +
"scrolls_count, uss_count, blocks_count, h_e_count, first_sm_id, sent_gp, last_changed, changed_by, additional_tissue_value_json, shl_work_number, " +
"tumor_percentage, tissue_sequence FROM ddp_tissue t WHERE NOT (deleted <=> 1) AND onc_history_detail_id = ?";
"tumor_percentage, tissue_sequence, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted, sm.tissue_id FROM ddp_tissue t " +
"LEFT JOIN sm_id sm on (sm.tissue_id = t.tissue_id AND NOT sm.deleted <=> 1 AND NOT t.deleted <=> 1) " +
"WHERE NOT (t.deleted <=> 1) AND onc_history_detail_id = ?";
private static final String SQL_INSERT_TISSUE = "INSERT INTO ddp_tissue SET onc_history_detail_id = ?, last_changed = ?, changed_by = ?";
public static final String SQL_SELECT_TISSUE_LAST_CHANGED = "SELECT t.last_changed FROM ddp_institution inst " +
"LEFT JOIN ddp_participant as p on (p.participant_id = inst.participant_id) LEFT JOIN ddp_instance as ddp on (ddp.ddp_instance_id = p.ddp_instance_id) " +
Expand Down Expand Up @@ -71,7 +74,7 @@ public class Tissue {
private final String shlWorkNumber;

@ColumnName (DBConstants.SCROLLS_RECEIVED)
@DbDateConversion(SqlDateConverter.STRING_DAY)
@DbDateConversion (SqlDateConverter.STRING_DAY)
private final String scrollsReceived;

@ColumnName (DBConstants.SK_ID)
Expand All @@ -81,7 +84,7 @@ public class Tissue {
private final String smId;

@ColumnName (DBConstants.SENT_GP)
@DbDateConversion(SqlDateConverter.STRING_DAY)
@DbDateConversion (SqlDateConverter.STRING_DAY)
private final String sentGp;

private String changedBy;
Expand All @@ -96,7 +99,7 @@ public class Tissue {
private String additionalValues;

@ColumnName (DBConstants.TISSUE_RETURN_DATE)
@DbDateConversion(SqlDateConverter.STRING_DAY)
@DbDateConversion (SqlDateConverter.STRING_DAY)
private String tissueReturnDate;
//
@ColumnName (DBConstants.RETURN_FEDEX_ID)
Expand All @@ -123,14 +126,19 @@ public class Tissue {
@ColumnName (DBConstants.H_E_COUNT)
private Integer hECount;

private List<TissueSmId> ussSMID;

private List<TissueSmId> scrollSMID;

private List<TissueSmId> heSMID;


public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer countReceived, String tissueType,
String tissueSite, String tumorType, String hE, String pathologyReport, String collaboratorSampleId,
String blockSent, String scrollsReceived, String skId, String smId, String sentGp, String firstSmId,
String additionalValues, String expectedReturn, String tissueReturnDate,
String returnFedexId, String shlWorkNumber, String tumorPercentage, String sequenceResults, Integer scrollsCount,
Integer ussCount, Integer blocksCount, Integer hECount) {
Integer ussCount, Integer blocksCount, Integer hECount, List<TissueSmId> ussSMIDs, List<TissueSmId> scrollSMIDs, List<TissueSmId> heSMID) {
this.tissueId = tissueId;
this.oncHistoryDetailId = oncHistoryDetailId;
this.tNotes = tNotes;
Expand Down Expand Up @@ -158,11 +166,14 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer
this.hECount = hECount;
this.blocksCount = blocksCount;
this.ussCount = ussCount;
this.scrollSMID = scrollSMIDs;
this.ussSMID = ussSMIDs;
this.heSMID = heSMID;
}

public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException {
Tissue tissue = new Tissue(
rs.getString(DBConstants.TISSUE_ID),
rs.getString("t." + DBConstants.TISSUE_ID),
rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID),
rs.getString(DBConstants.DDP_TISSUE_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.NOTES),
rs.getInt(DBConstants.COUNT_RECEIVED),
Expand All @@ -188,19 +199,39 @@ public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException {
rs.getInt(DBConstants.SCROLLS_COUNT),
rs.getInt(DBConstants.USS_COUNT),
rs.getInt(DBConstants.BLOCKS_COUNT),
rs.getInt(DBConstants.H_E_COUNT));
rs.getInt(DBConstants.H_E_COUNT),
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>());
return tissue;
}


public static TissueSmId getSMIds(ResultSet rs) {
return TissueSmId.getSMIdsForTissueId(rs);
}

public static List<Tissue> getTissue(@NonNull Connection conn, @NonNull String oncHistoryDetailId) {

List<Tissue> tissue = new ArrayList<>();
List<Tissue> tissueList = new ArrayList<>();
SimpleResult dbVals = new SimpleResult();
HashMap<String, Tissue> tissues = new HashMap<>();
try (PreparedStatement stmt = conn.prepareStatement(SQL_SELECT_TISSUE)) {
stmt.setString(1, oncHistoryDetailId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
tissue.add(getTissue(rs));
TissueSmId tissueSmId = getSMIds(rs);
Tissue tissue;
if (tissueSmId != null && tissues.containsKey(tissueSmId.getTissueId())) {
tissue = tissues.get(tissueSmId.getTissueId());
}
else {
tissue = getTissue(rs);
}
if (tissueSmId != null) {
tissue.setSmIdBasedOnType(tissueSmId, rs);
}
tissues.put(tissue.tissueId, tissue);
}
}
}
Expand All @@ -211,9 +242,37 @@ public static List<Tissue> getTissue(@NonNull Connection conn, @NonNull String o
if (dbVals.resultException != null) {
throw new RuntimeException("Error getting tissue for oncHistoryDetails w/ id " + oncHistoryDetailId, dbVals.resultException);
}
tissueList.addAll(tissues.values());
logger.info("Found " + tissueList.size() + " tissue for oncHistoryDetails w/ id " + oncHistoryDetailId);
return tissueList;
}

public void setSmIdBasedOnType(TissueSmId tissueSmId, ResultSet rs) {
if (tissueSmId == null || tissueSmId.getSmIdType() == null) {
return;
}
try {
String type = rs.getString(DBConstants.SM_ID_TYPE_TABLE_ALIAS + "." + DBConstants.SM_ID_TYPE);
switch (type.toLowerCase()) {
case "he": {
this.heSMID.add(tissueSmId);
break;

}
case "uss": {
this.ussSMID.add(tissueSmId);
break;
}
case "scrolls": {
this.scrollSMID.add(tissueSmId);
break;
}
}
}
catch (SQLException throwables) {
throwables.printStackTrace();
}

logger.info("Found " + tissue.size() + " tissue for oncHistoryDetails w/ id " + oncHistoryDetailId);
return tissue;
}

public static String createNewTissue(@NonNull String oncHistoryId, @NonNull String user) {
Expand Down
107 changes: 107 additions & 0 deletions src/main/java/org/broadinstitute/dsm/db/TissueSmId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.broadinstitute.dsm.db;

import lombok.Data;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSMIDDao;
import org.broadinstitute.dsm.db.structure.ColumnName;
import org.broadinstitute.dsm.db.structure.TableName;
import org.broadinstitute.dsm.exception.DuplicateException;
import org.broadinstitute.dsm.model.NameValue;
import org.broadinstitute.dsm.statics.DBConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Data
@TableName (
name = DBConstants.SM_ID_TABLE,
alias = DBConstants.SM_ID_TABLE_ALIAS,
primaryKey = DBConstants.SM_ID_PK,
columnPrefix = "")
public class TissueSmId {

@ColumnName (DBConstants.SM_ID_VALUE)
private String smIdValue;

@ColumnName (DBConstants.SM_ID_TYPE_ID)
private String smIdType;

@ColumnName (DBConstants.SM_ID_TISSUE_ID)
private String tissueId;

@ColumnName (DBConstants.SM_ID_PK)
private String smIdPk;

@ColumnName (DBConstants.DELETED)
private Boolean deleted;

public static String HE = "he";
public static String USS = "uss";
public static String SCROLLS = "scrolls";
private static final Logger logger = LoggerFactory.getLogger(TissueSmId.class);

public TissueSmId() {
}

public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissueId) {
this.smIdPk = smIdPk;
this.smIdType = smIdType;
this.smIdValue = smIdValue;
this.tissueId = tissueId;
}


public static TissueSmId getSMIdsForTissueId(ResultSet rs) {
TissueSmId tissueSmId = null;

try {
if (rs.getString(DBConstants.SM_ID_PK) == null) {
return null;
}
tissueSmId = new TissueSmId(
rs.getString(DBConstants.SM_ID_PK),
rs.getString(DBConstants.SM_ID_TYPE_ID),
rs.getString(DBConstants.SM_ID_VALUE),
rs.getString("sm." + DBConstants.TISSUE_ID)
);
if (tissueSmId != null) {
tissueSmId.setDeleted(rs.getBoolean("sm." + DBConstants.DELETED));
}
}
catch (SQLException e) {
logger.error("problem getting tissue sm ids", e);
}
return tissueSmId;
}

public static boolean isUniqueSmId(String smIdValue, String id) {
return new TissueSMIDDao().isUnique(smIdValue, id);
}

public static boolean isUniqueSmId(String smIdValue) {
return new TissueSMIDDao().isUnique(smIdValue);
}

public String createNewSmId(@NonNull String tissueId, String userId, @NonNull List<NameValue> smIdDetails) {
String smIdType = null;
String smIdValue = null;
for (NameValue nameValue : smIdDetails) {
if (nameValue.getName().equals("smIdType")) {
smIdType = String.valueOf(nameValue.getValue());
}
else if (nameValue.getName().equals("smIdValue")) {
smIdValue = String.valueOf(nameValue.getValue());
}
}
if(StringUtils.isNotBlank(smIdValue) && this.isUniqueSmId(smIdValue)) {
String smIdId = new TissueSMIDDao().createNewSMIDForTissue(tissueId, userId, smIdType, smIdValue);
return smIdId;
} else{
throw new DuplicateException("Duplicate or blank value for sm id value "+smIdValue);
}
}
}
16 changes: 10 additions & 6 deletions src/main/java/org/broadinstitute/dsm/db/ViewFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ public static ViewFilter parseFilteringQuery(String str, ViewFilter viewFilter)
Boolean f1 = false;
NameValue filter2 = null;
NameValue filter1 = null;

String[] words = condition.trim().split("(\\s+)");
for (String word : words) {
if (StringUtils.isNotBlank(word)) {
Expand Down Expand Up @@ -581,8 +582,9 @@ else if (word.equals("->")) {
if (word.equals(Filter.TODAY) || word.matches("'\\d{4}-\\d{1,2}-\\d{1,2}'")) {
if (word.equals(Filter.TODAY)) {
value = getDate();
} else {
value = word.replace("'","");
}
else {
value = word.replace("'", "");
}
state = 22;
break;
Expand All @@ -591,7 +593,8 @@ else if (word.equals(Filter.TRUE) || word.equals(Filter.FALSE)) {
value = word;
type = Filter.BOOLEAN;
state = 40;
} else if (StringUtils.isNumeric(word)) {
}
else if (StringUtils.isNumeric(word)) {
value = word;
type = Filter.NUMBER;
state = 40;
Expand Down Expand Up @@ -633,7 +636,8 @@ else if (longWord) {
value = trimValue(word);
if (isValidDate(value, false)) {
type = Filter.DATE;
} else if (StringUtils.isNumeric(word)) {
}
else if (StringUtils.isNumeric(word)) {
type = Filter.NUMBER;
}
state = 11;
Expand Down Expand Up @@ -896,7 +900,6 @@ else if (word.equals(Filter.MINUS_SIGN)) {
break;
case 40:
break;

}
}
}
Expand Down Expand Up @@ -965,7 +968,8 @@ else if (Filter.TEXT.equals(filter.type) || Filter.BOOLEAN.equals(filter.type) |
if (Filter.NUMBER.equals(filter.type)
&& condition.contains(Filter.SMALLER_EQUALS_TRIMMED) && !arrayContains(conditions, Filter.LARGER_EQUALS_TRIMMED)) {
filter.setFilter2(new NameValue(columnName, value));
} else {
}
else {
filter.setFilter1(new NameValue(columnName, value));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.broadinstitute.dsm.db.dao.ddp.participant;

import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.dao.Dao;
import org.broadinstitute.dsm.db.dto.ddp.participant.ParticipantDto;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Optional;

import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.dao.Dao;
import org.broadinstitute.dsm.db.dto.ddp.participant.ParticipantDto;
import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction;

public class ParticipantDao implements Dao<ParticipantDto> {

Expand Down
Loading