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 7 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
7 changes: 5 additions & 2 deletions src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
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 All @@ -39,7 +42,7 @@ public class OncHistoryDetail {
"oD.fax_sent_3_by, oD.fax_confirmed_3, oD.tissue_received, oD.tissue_problem_option, oD.gender, oD.destruction_policy, oD.unable_obtain_tissue, " +
"tissue_id, t.notes, count_received, tissue_type, tissue_site, tumor_type, h_e, pathology_report, collaborator_sample_id, block_sent, scrolls_received, sk_id, sm_id, " +
"sent_gp, first_sm_id, additional_tissue_value_json, expected_return, return_date, return_fedex_id, shl_work_number, tumor_percentage, tissue_sequence, " +
" scrolls_count, uss_count, h_e_count, blocks_count " +
" scrolls_count, uss_count, h_e_count, blocks_count, t.uss_sm_ids, t.scrolls_sm_ids, t.he_sm_ids " +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is old version and should be removed

"FROM ddp_onc_history_detail oD " +
"LEFT JOIN ddp_medical_record m on (oD.medical_record_id = m.medical_record_id AND NOT oD.deleted <=> 1 AND NOT m.deleted <=> 1) " +
"LEFT JOIN ddp_institution inst on (inst.institution_id = m.institution_id) " +
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/org/broadinstitute/dsm/db/Tissue.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.broadinstitute.dsm.db;

import com.google.gson.Gson;
import lombok.Data;
import lombok.NonNull;
import org.broadinstitute.ddp.db.SimpleResult;
Expand Down Expand Up @@ -30,7 +31,7 @@ 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, uss_sm_ids, scrolls_sm_ids, he_sm_ids FROM ddp_tissue t WHERE NOT (deleted <=> 1) AND onc_history_detail_id = ?";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is old version and should be removed

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 @@ -123,14 +124,23 @@ public class Tissue {
@ColumnName (DBConstants.H_E_COUNT)
private Integer hECount;

@ColumnName(DBConstants.USS_SMIDS)
private TissueSmId[] ussSMID;

@ColumnName(DBConstants.SCROLL_SMIDS)
private TissueSmId[] scrollSMID;

@ColumnName(DBConstants.HE_SMIDS)
private 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, TissueSmId[] ussSMIDs, TissueSmId[] scrollSMIDs, TissueSmId[] heSMID) {
this.tissueId = tissueId;
this.oncHistoryDetailId = oncHistoryDetailId;
this.tNotes = tNotes;
Expand Down Expand Up @@ -158,9 +168,13 @@ 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 {
Gson gson = new Gson();
Tissue tissue = new Tissue(
rs.getString(DBConstants.TISSUE_ID),
rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID),
Expand Down Expand Up @@ -188,10 +202,35 @@ 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),
null,
null,
null);
tissue.setSMIds();
return tissue;
}

private void setSMIds() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get the sm ids in one call and not make 3 calls to the same table?

if (this.hECount>0){
this.heSMID = TissueSmId.getSMIdsForTissueId(this.tissueId, TissueSmId.HE);
} else{
this.heSMID = new TissueSmId[0];
}
if (this.ussCount>0){
this.ussSMID = TissueSmId.getSMIdsForTissueId(this.tissueId, TissueSmId.USS);
}
else{
this.ussSMID = new TissueSmId[0];
}
if (this.scrollsCount>0){
this.scrollSMID = TissueSmId.getSMIdsForTissueId(this.tissueId, TissueSmId.SCROLLS);
}
else{
this.scrollSMID = new TissueSmId[0];
}

}

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

List<Tissue> tissue = new ArrayList<>();
Expand Down
57 changes: 57 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,57 @@
package org.broadinstitute.dsm.db;

import lombok.Data;
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.statics.DBConstants;

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";
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(String tissueId, String type) {
TissueSMIDDao tissueSMIDDao = new TissueSMIDDao();
List<TissueSmId> list = tissueSMIDDao.getSMIdsForTissueId(tissueId, type);
return list.toArray(new TissueSmId[list.size()]);
}

public String createNewSmId(String tissueId, String userId, String smIdType){
String smIdId = new TissueSMIDDao().createNewSMIDForTissue(tissueId, userId, smIdType);
return smIdId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package org.broadinstitute.dsm.db.dao.ddp.tissue;

import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.TissueSmId;
import org.broadinstitute.dsm.statics.DBConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

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

public class TissueSMIDDao {
private static final Logger logger = LoggerFactory.getLogger(TissueSMIDDao.class);

public static final String SQL_GET_SM_ID_BASED_ON_TISSUE_ID=" SELECT * from sm_id where tissue_id= ? and sm_id_type_id = ? and NOT deleted <=> 1";
public static final String SQL_TYPE_ID_FOR_TYPE="SELECT sm_id_type_id from sm_id_type where `sm_id_type` = ?";
public static final String SQL_INSERT_SM_ID = "INSERT INTO sm_id SET tissue_id = ?, sm_id_type_id = ?, last_changed = ?, changed_by = ?";

public List<TissueSmId> getSMIdsForTissueId(String tissueId, String type) {
String typeId = getTypeForName(type);
List<TissueSmId> list = new ArrayList();
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(SQL_GET_SM_ID_BASED_ON_TISSUE_ID)) {
stmt.setString(1, tissueId);
stmt.setString(2, typeId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
TissueSmId tissueSmId = new TissueSmId(
rs.getString(DBConstants.SM_ID_PK),
rs.getString(DBConstants.SM_ID_TYPE_ID),
rs.getString(DBConstants.SM_ID_VALUE),
rs.getString(DBConstants.TISSUE_ID)
);
list.add(tissueSmId);
}
}
}
catch (SQLException ex) {
dbVals.resultException = ex;
}
return dbVals;
});

if (results.resultException != null) {
throw new RuntimeException("Error getting sm ids for tissue w/ id " + tissueId +" for type "+type, results.resultException);
}

return list;
}



private static String getTypeForName(String type) {
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(SQL_TYPE_ID_FOR_TYPE)) {
stmt.setString(1, type);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
dbVals.resultValue = rs.getString(DBConstants.SM_ID_TYPE_ID);
}
}
}
catch (SQLException ex) {
dbVals.resultException = ex;
}
return dbVals;
});

if (results.resultException != null) {
throw new RuntimeException("Error getting type ids for sm id " + type, results.resultException);
}

return (String) results.resultValue;
}

public String createNewSMIDForTissue(String tissueId, String userId, String smIdType) {
String smIdtypeId = getTypeForName(smIdType);
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(SQL_INSERT_SM_ID, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, tissueId);
stmt.setString(2, smIdtypeId);
stmt.setLong(3, System.currentTimeMillis());
stmt.setString(4, userId);
int result = stmt.executeUpdate();
if (result == 1) {
try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) {
logger.info("Created new sm id for tissue w/ id " + tissueId);
dbVals.resultValue = rs.getString(1);
}
}
catch (Exception e) {
throw new RuntimeException("Error getting id of new sm id ", e);
}
}
else {
throw new RuntimeException("Error adding new sm id for tissue w/ id " + tissueId + " it was updating " + result + " rows");
}
}
catch (SQLException ex) {
dbVals.resultException = ex;
}
return dbVals;
});

if (results.resultException != null) {
throw new RuntimeException("Error adding new sm id for tissue w/ id " + tissueId, results.resultException);
}
else {
return (String) results.resultValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.dsm.db.DDPInstance;
import org.broadinstitute.dsm.db.OncHistoryDetail;
import org.broadinstitute.dsm.db.dao.Dao;
import org.broadinstitute.dsm.db.dto.kit.ClinicalKitDto;
import org.broadinstitute.dsm.model.elasticsearch.ESProfile;
import org.broadinstitute.dsm.model.elasticsearch.ElasticSearchParticipantDto;
import org.broadinstitute.dsm.statics.DBConstants;
import org.broadinstitute.dsm.util.DBUtil;
import org.broadinstitute.dsm.util.ElasticSearchUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,6 +24,7 @@ public class BSPDummyKitDao implements Dao<ClinicalKitDto> {

private static final String SQL_UPDATE_DUMMY_KIT = "UPDATE ddp_kit SET kit_label = ? where dsm_kit_request_id = ?";
private static final String SQL_SELECT_RANDOM_PT = "SELECT ddp_participant_id FROM ddp_kit_request req, ddp_kit kit where req.dsm_kit_request_id = kit.dsm_kit_request_id and deactivated_date is null and ddp_instance_id = ? group by ddp_participant_id ORDER BY RAND() LIMIT 1";
private static final String SQL_SELECT_RANDOM_SUFFIX = " ORDER BY RAND() LIMIT 1";
private static final Logger logger = LoggerFactory.getLogger(BSPDummyKitDao.class);

public void updateKitLabel(String kitLabel, String dsmKitRequestId) {
Expand Down Expand Up @@ -83,6 +86,29 @@ public Optional<String> getRandomParticipantIdForStudy(String ddpInstanceId) {
return Optional.ofNullable((String) results.resultValue);
}

public Optional<String> getRandomOncHistoryForStudy(String ddpInstanceName) {
SimpleResult results = inTransaction((conn) -> {
SimpleResult dbVals = new SimpleResult();
try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(OncHistoryDetail.SQL_SELECT_ONC_HISTORY_DETAIL , SQL_SELECT_RANDOM_SUFFIX))) {
stmt.setString(1, ddpInstanceName);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
dbVals.resultValue = Optional.of(rs.getString(DBConstants.DDP_PARTICIPANT_ID));
}else{

}
}
catch (SQLException e) {
dbVals.resultException = e;
}
return dbVals;
});
if (results.resultException != null) {
throw new RuntimeException("Problem getting a random participant id for instance " + ddpInstanceName, results.resultException);
}
return (Optional<String>) results.resultValue;
}

@Override
public int create(ClinicalKitDto clinicalKitDto) {
return 0;
Expand All @@ -97,4 +123,6 @@ public int delete(int id) {
public Optional<ClinicalKitDto> get(long id) {
return Optional.empty();
}


}
1 change: 1 addition & 0 deletions src/main/java/org/broadinstitute/dsm/model/Patch.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Patch {
public static final String ONC_HISTORY_ID = "oncHistoryDetailId";
public static final String PARTICIPANT_DATA_ID = "participantDataId";
public static final String DDP_PARTICIPANT_ID = "ddpParticipantId";
public static final String TISSUEID = "tissueId";

private String id;
private String parent; //for new added rows at oncHistoryDetails/tissue
Expand Down
Loading