-
Notifications
You must be signed in to change notification settings - Fork 2
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
pegahtah
wants to merge
23
commits into
develop
Choose a base branch
from
DDP-6034-SMIDS
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
DDP-6034-SMIDS #320
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 5ec1978
Merge remote-tracking branch 'origin/develop' into DDP-6034-SMIDS
pegahtah 613b600
added the backend side of sm ids for Tissue
pegahtah 9bcef0d
added the backend side of sm ids for Tissue to be saved in different …
pegahtah fb0b8fa
added changes for DDP-7163
pegahtah 9771739
changed the liquibase
pegahtah 24d830c
added the Dao
pegahtah 18bbbf3
added ability to receive a ffpe sm_id
pegahtah 1a533d0
changed how smid is received
pegahtah b3030f7
addressed PR comments
pegahtah de271e5
debugging
pegahtah b00cf84
fixed the part where a sm id is assigned to invalid participant
pegahtah 48197f7
added `ClinicalKitWrapper` to make json for PE-CGS
pegahtah 19c470b
changes for filtering
pegahtah 590fb89
added
pegahtah a192f32
added changes to fix how we get the sm ids
pegahtah 4047aab
throwing errors for null accession number and added checks wheen crea…
pegahtah 3f83726
Changed the way of making onc history to be better readable
pegahtah b63b4b1
added unique constraint
pegahtah 5c90966
Merge remote-tracking branch 'origin/develop' into DDP-6034-SMIDS
pegahtah e8e46bd
Merge remote-tracking branch 'origin/develop' into DDP-6034-SMIDS
pegahtah 0d3c589
fixes from prod changes after QA
pegahtah 212bba9
fixed the clinical kit bug and added more conditions for creating the…
pegahtah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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 = ?"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) " + | ||
|
@@ -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; | ||
|
@@ -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), | ||
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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<>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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