From 6fe84f7bfb1daf8b09c0de783d062272de948bf8 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Thu, 12 Aug 2021 12:30:34 -0400 Subject: [PATCH 01/20] added the columns to liquibase and to queries --- .../dsm/db/OncHistoryDetail.java | 7 ++++-- .../org/broadinstitute/dsm/db/Tissue.java | 22 ++++++++++++++++--- .../dsm/statics/DBConstants.java | 2 ++ .../resources/liquibase/DDP-6034_SMIDS.xml | 17 ++++++++++++++ src/main/resources/master-changelog.xml | 1 + 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/liquibase/DDP-6034_SMIDS.xml diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 305da0d04..09ad0296e 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -17,7 +17,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; @@ -37,7 +40,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_id " + "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) " + diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index de661e70f..121483f4c 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -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; @@ -11,6 +12,7 @@ import java.sql.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -28,7 +30,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 FROM ddp_tissue t WHERE NOT (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) " + @@ -118,6 +120,12 @@ public class Tissue { @ColumnName (DBConstants.H_E_COUNT) private Integer hECount; + @ColumnName(DBConstants.USS_SMIDS) + private List ussSMIDs; + + @ColumnName(DBConstants.SCROLL_SMIDS) + private List scrollSMIDs; + public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer countReceived, String tissueType, @@ -125,7 +133,7 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer 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 ussSMIDs, List scrollSMIDs) { this.tissueId = tissueId; this.oncHistoryDetailId = oncHistoryDetailId; this.tNotes = tNotes; @@ -153,10 +161,15 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer this.hECount = hECount; this.blocksCount = blocksCount; this.ussCount = ussCount; + this.scrollSMIDs = scrollSMIDs; + this.ussSMIDs = ussSMIDs; } public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { + Gson gson = new Gson(); + List ussSMIds = Arrays.asList(gson.fromJson(rs.getString(DBConstants.USS_SMIDS), String[].class)); Tissue tissue = new Tissue( + rs.getString(DBConstants.TISSUE_ID), rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID), rs.getString(DBConstants.DDP_TISSUE_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.NOTES), @@ -183,7 +196,10 @@ 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), + Arrays.asList(new Gson().fromJson(rs.getString(DBConstants.USS_SMIDS), String[].class)), + Arrays.asList(new Gson().fromJson(rs.getString(DBConstants.SCROLL_SMIDS), String[].class)) + ); return tissue; } diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index f704f3c10..158be993c 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -241,6 +241,8 @@ public class DBConstants { public static final String USS_COUNT = "uss_count"; public static final String SCROLLS_COUNT = "scrolls_count"; public static final String H_E_COUNT = "h_e_count"; + public static final String USS_SMIDS = "uss_sm_ids"; + public static final String SCROLL_SMIDS = "scrolls_sm_ids"; public static final String BLOCKS_COUNT = "blocks_count"; diff --git a/src/main/resources/liquibase/DDP-6034_SMIDS.xml b/src/main/resources/liquibase/DDP-6034_SMIDS.xml new file mode 100644 index 000000000..68f2bf88a --- /dev/null +++ b/src/main/resources/liquibase/DDP-6034_SMIDS.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/master-changelog.xml b/src/main/resources/master-changelog.xml index 2f1bef805..bd08c74a8 100644 --- a/src/main/resources/master-changelog.xml +++ b/src/main/resources/master-changelog.xml @@ -64,4 +64,5 @@ + From 613b600ae89f0cef832f822d4bf3e946f659a228 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Thu, 18 Nov 2021 17:09:54 -0500 Subject: [PATCH 02/20] added the backend side of sm ids for Tissue --- .../dsm/db/OncHistoryDetail.java | 2 +- .../org/broadinstitute/dsm/db/Tissue.java | 39 +++++++++++++------ .../dsm/statics/DBConstants.java | 4 +- .../liquibase/{ => CMI}/DDP-6034_SMIDS.xml | 3 ++ src/main/resources/master-changelog.xml | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) rename src/main/resources/liquibase/{ => CMI}/DDP-6034_SMIDS.xml (83%) diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 554c11bf3..4a83ef26f 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -42,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, t.uss_sm_ids, t.scrolls_sm_id " + + " scrolls_count, uss_count, h_e_count, blocks_count, t.uss_sm_ids, t.scrolls_sm_ids, t.he_sm_ids " + "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) " + diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index 336d80ce1..381f51d89 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -3,6 +3,7 @@ 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.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DbDateConversion; @@ -14,7 +15,6 @@ import java.sql.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -32,7 +32,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, uss_sm_ids, scrolls_sm_ids 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 = ?"; 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) " + @@ -126,10 +126,13 @@ public class Tissue { private Integer hECount; @ColumnName(DBConstants.USS_SMIDS) - private List ussSMIDs; + private String[] ussSMID; @ColumnName(DBConstants.SCROLL_SMIDS) - private List scrollSMIDs; + private String[] scrollSMID; + + @ColumnName(DBConstants.HE_SMIDS) + private String[] heSMID; @@ -138,7 +141,7 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer 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, List ussSMIDs, List scrollSMIDs) { + Integer ussCount, Integer blocksCount, Integer hECount, String[] ussSMIDs, String[] scrollSMIDs, String[] heSMID) { this.tissueId = tissueId; this.oncHistoryDetailId = oncHistoryDetailId; this.tNotes = tNotes; @@ -166,15 +169,27 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer this.hECount = hECount; this.blocksCount = blocksCount; this.ussCount = ussCount; - this.scrollSMIDs = scrollSMIDs; - this.ussSMIDs = ussSMIDs; + this.scrollSMID = scrollSMIDs; + this.ussSMID = ussSMIDs; + this.heSMID = heSMID; } public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { Gson gson = new Gson(); - List ussSMIds = Arrays.asList(gson.fromJson(rs.getString(DBConstants.USS_SMIDS), String[].class)); + String[] ussSMIds = new String[0]; + String[] scrollSMIds = new String[0]; + String[] heSMIds = new String[0]; + if(StringUtils.isNotBlank(rs.getString(DBConstants.USS_SMIDS))) { +// ussSMIds = gson.fromJson(rs.getString(DBConstants.USS_SMIDS), String[].class); + ussSMIds = rs.getString(DBConstants.USS_SMIDS).split(","); + } + if(StringUtils.isNotBlank(rs.getString(DBConstants.SCROLL_SMIDS))) { + scrollSMIds = gson.fromJson(rs.getString(DBConstants.SCROLL_SMIDS), String[].class); + } + if(StringUtils.isNotBlank(rs.getString(DBConstants.HE_SMIDS))) { + heSMIds = gson.fromJson(rs.getString(DBConstants.HE_SMIDS), String[].class); + } Tissue tissue = new Tissue( - rs.getString(DBConstants.TISSUE_ID), rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID), rs.getString(DBConstants.DDP_TISSUE_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.NOTES), @@ -202,9 +217,9 @@ public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { rs.getInt(DBConstants.USS_COUNT), rs.getInt(DBConstants.BLOCKS_COUNT), rs.getInt(DBConstants.H_E_COUNT), - Arrays.asList(new Gson().fromJson(rs.getString(DBConstants.USS_SMIDS), String[].class)), - Arrays.asList(new Gson().fromJson(rs.getString(DBConstants.SCROLL_SMIDS), String[].class)) - ); + ussSMIds, + scrollSMIds, + heSMIds); return tissue; } diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index 59bdc4a4a..935da20ff 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -242,9 +242,11 @@ public class DBConstants { public static final String USS_COUNT = "uss_count"; public static final String SCROLLS_COUNT = "scrolls_count"; public static final String H_E_COUNT = "h_e_count"; + public static final String BLOCKS_COUNT = "blocks_count"; public static final String USS_SMIDS = "uss_sm_ids"; public static final String SCROLL_SMIDS = "scrolls_sm_ids"; - public static final String BLOCKS_COUNT = "blocks_count"; + public static final String HE_SMIDS = "he_sm_ids"; + //field_settings diff --git a/src/main/resources/liquibase/DDP-6034_SMIDS.xml b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml similarity index 83% rename from src/main/resources/liquibase/DDP-6034_SMIDS.xml rename to src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml index 68f2bf88a..931f0be5e 100644 --- a/src/main/resources/liquibase/DDP-6034_SMIDS.xml +++ b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml @@ -12,6 +12,9 @@ + + + diff --git a/src/main/resources/master-changelog.xml b/src/main/resources/master-changelog.xml index 20befbfa4..651c27add 100644 --- a/src/main/resources/master-changelog.xml +++ b/src/main/resources/master-changelog.xml @@ -74,5 +74,5 @@ - + From 9bcef0d7ce36cbe52ad3848acb9fee92e31fd26e Mon Sep 17 00:00:00 2001 From: pegahtah Date: Mon, 22 Nov 2021 10:02:42 -0500 Subject: [PATCH 03/20] added the backend side of sm ids for Tissue to be saved in different table --- .../org/broadinstitute/dsm/db/Tissue.java | 50 +++++++++------- .../org/broadinstitute/dsm/db/TissueSmId.java | 57 +++++++++++++++++++ .../org/broadinstitute/dsm/model/Patch.java | 1 + .../broadinstitute/dsm/route/PatchRoute.java | 38 +++++++++---- .../dsm/statics/DBConstants.java | 12 +++- .../broadinstitute/dsm/util/PatchUtil.java | 8 ++- .../liquibase/CMI/DDP-6034_SMIDS.xml | 54 +++++++++++++++++- 7 files changed, 183 insertions(+), 37 deletions(-) create mode 100644 src/main/java/org/broadinstitute/dsm/db/TissueSmId.java diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index 381f51d89..dc48286bf 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -3,7 +3,6 @@ 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.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DbDateConversion; @@ -126,13 +125,13 @@ public class Tissue { private Integer hECount; @ColumnName(DBConstants.USS_SMIDS) - private String[] ussSMID; + private TissueSmId[] ussSMID; @ColumnName(DBConstants.SCROLL_SMIDS) - private String[] scrollSMID; + private TissueSmId[] scrollSMID; @ColumnName(DBConstants.HE_SMIDS) - private String[] heSMID; + private TissueSmId[] heSMID; @@ -141,7 +140,7 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer 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, String[] ussSMIDs, String[] scrollSMIDs, String[] heSMID) { + Integer ussCount, Integer blocksCount, Integer hECount, TissueSmId[] ussSMIDs, TissueSmId[] scrollSMIDs, TissueSmId[] heSMID) { this.tissueId = tissueId; this.oncHistoryDetailId = oncHistoryDetailId; this.tNotes = tNotes; @@ -176,19 +175,6 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { Gson gson = new Gson(); - String[] ussSMIds = new String[0]; - String[] scrollSMIds = new String[0]; - String[] heSMIds = new String[0]; - if(StringUtils.isNotBlank(rs.getString(DBConstants.USS_SMIDS))) { -// ussSMIds = gson.fromJson(rs.getString(DBConstants.USS_SMIDS), String[].class); - ussSMIds = rs.getString(DBConstants.USS_SMIDS).split(","); - } - if(StringUtils.isNotBlank(rs.getString(DBConstants.SCROLL_SMIDS))) { - scrollSMIds = gson.fromJson(rs.getString(DBConstants.SCROLL_SMIDS), String[].class); - } - if(StringUtils.isNotBlank(rs.getString(DBConstants.HE_SMIDS))) { - heSMIds = gson.fromJson(rs.getString(DBConstants.HE_SMIDS), String[].class); - } Tissue tissue = new Tissue( rs.getString(DBConstants.TISSUE_ID), rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID), @@ -217,12 +203,34 @@ public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { rs.getInt(DBConstants.USS_COUNT), rs.getInt(DBConstants.BLOCKS_COUNT), rs.getInt(DBConstants.H_E_COUNT), - ussSMIds, - scrollSMIds, - heSMIds); + null, + null, + null); + tissue.setSMIds(); return tissue; } + private void setSMIds() { + 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 getTissue(@NonNull Connection conn, @NonNull String oncHistoryDetailId) { List tissue = new ArrayList<>(); diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java new file mode 100644 index 000000000..9220d2afa --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -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_ID, + 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_ID) + private String smIdId; + + @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 smIdId, String smIdType, String smIdValue, String tissueId){ + this.smIdId = smIdId; + this.smIdType = smIdType; + this.smIdValue = smIdValue; + this.tissueId = tissueId; + } + + + public static TissueSmId[] getSMIdsForTissueId(String tissueId, String type) { + TissueSMIDDao tissueSMIDDao = new TissueSMIDDao(); + List 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; + } +} diff --git a/src/main/java/org/broadinstitute/dsm/model/Patch.java b/src/main/java/org/broadinstitute/dsm/model/Patch.java index e4e740a82..9197f3c16 100644 --- a/src/main/java/org/broadinstitute/dsm/model/Patch.java +++ b/src/main/java/org/broadinstitute/dsm/model/Patch.java @@ -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 diff --git a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java index dbd54fba0..47233ebc9 100644 --- a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java @@ -42,6 +42,7 @@ import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; + import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; //Class needs to be refactored as soon as possible!!! @@ -273,6 +274,12 @@ else if (Patch.ONC_HISTORY_ID.equals(patch.getParent())) { throw new RuntimeException("DBElement not found in ColumnNameMap: " + patch.getNameValue().getName()); } } + else if (Patch.TISSUEID.equals(patch.getParent())) { + String smIdId = new TissueSmId().createNewSmId(patch.getParentId(), patch.getUser(), (String) patch.getNameValue().getValue()); + Map map = new HashMap<>(); + map.put("smId", smIdId); + return new Result(200, gson.toJson(map)); + } else if (Patch.PARTICIPANT_DATA_ID.equals(patch.getParent())) { String participantDataId = null; Map map = new HashMap<>(); @@ -348,9 +355,13 @@ private void controlWorkflowByEmail(Patch patch, NameValue nameValue, DDPInstanc logger.info("Email in patch data matches participant profile email, will update workflows"); int ddpInstanceIdByGuid = Integer.parseInt(ddpInstance.getDdpInstanceId()); FieldSettings fieldSettings = new FieldSettings(); - pData.forEach((columnName,columnValue) -> { - if (!fieldSettings.isColumnExportable(ddpInstanceIdByGuid, columnName)) return; - if (!patch.getFieldId().contains(org.broadinstitute.dsm.model.participant.data.ParticipantData.FIELD_TYPE)) return; + pData.forEach((columnName, columnValue) -> { + if (!fieldSettings.isColumnExportable(ddpInstanceIdByGuid, columnName)) { + return; + } + if (!patch.getFieldId().contains(org.broadinstitute.dsm.model.participant.data.ParticipantData.FIELD_TYPE)) { + return; + } // Use participant guid here to avoid multiple ES lookups. ElasticSearchUtil.writeWorkflow(WorkflowForES.createInstanceWithStudySpecificData(ddpInstance, profile.getParticipantGuid(), columnName, columnValue, new WorkflowForES.StudySpecificData( @@ -358,18 +369,23 @@ private void controlWorkflowByEmail(Patch patch, NameValue nameValue, DDPInstanc pData.get(FamilyMemberConstants.FIRSTNAME), pData.get(FamilyMemberConstants.LASTNAME))), false); }); - } else { + } + else { logger.info("Email in patch data does not match participant profile email, will remove workflows"); Map esMap = ElasticSearchUtil .getObjectsMap(ddpInstance.getParticipantIndexES(), profile.getParticipantGuid(), ESObjectConstants.WORKFLOWS); - if (Objects.isNull(esMap) || esMap.isEmpty()) return; - CopyOnWriteArrayList> workflowsList = new CopyOnWriteArrayList<>((List>)esMap.get(ESObjectConstants.WORKFLOWS)); + if (Objects.isNull(esMap) || esMap.isEmpty()) { + return; + } + CopyOnWriteArrayList> workflowsList = new CopyOnWriteArrayList<>((List>) esMap.get(ESObjectConstants.WORKFLOWS)); int startingSize = workflowsList.size(); workflowsList.forEach(workflow -> { Map workflowDataMap = (Map) workflow.get(ESObjectConstants.DATA); String collaboratorParticipantId = workflowDataMap.get(ESObjectConstants.SUBJECT_ID); - if (Objects.isNull(collaboratorParticipantId)) return; + if (Objects.isNull(collaboratorParticipantId)) { + return; + } if (collaboratorParticipantId.equals(pData.get(FamilyMemberConstants.COLLABORATOR_PARTICIPANT_ID))) { workflowsList.remove(workflow); } @@ -380,8 +396,10 @@ private void controlWorkflowByEmail(Patch patch, NameValue nameValue, DDPInstanc ElasticSearchUtil.updateRequest(profile.getParticipantGuid(), ddpInstance.getParticipantIndexES(), esMap); } } - } catch (JsonSyntaxException ignored) { - } catch (Exception e) { + } + catch (JsonSyntaxException ignored) { + } + catch (Exception e) { throw new RuntimeException(e); } } @@ -550,7 +568,7 @@ private NameValue setAdditionalValue(String additionalValue, @NonNull Patch patc } } - private void triggerParticipantEvent(DDPInstance ddpInstance, Patch patch, Value action){ + private void triggerParticipantEvent(DDPInstance ddpInstance, Patch patch, Value action) { Optional eventType = eventTypeDao.getEventTypeByEventTypeAndInstanceId(action.getName(), ddpInstance.getDdpInstanceId()); eventType.ifPresent(eventTypeDto -> { boolean participantHasTriggeredEventByEventType = eventDao.hasTriggeredEventByEventTypeAndDdpParticipantId(action.getName(), patch.getParentId()).orElse(false); diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index 935da20ff..c5ca9366d 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -486,6 +486,16 @@ public class DBConstants { //access_user public static final String PHONE_NUMBER = "phone_number"; - + //sm_id table + public static final String SM_ID_TABLE = "sm_id"; + public static final String SM_ID_TABLE_ALIAS = "sm"; + public static final String SM_ID_ID = "sm_id_id"; + public static final String SM_ID_TYPE_ID = "sm_id_type_id"; + public static final String SM_ID_VALUE = "sm_id_value"; + public static final String SM_ID_TISSUE_ID = "tissue_id"; + + //sm_id_type table + public static final String SM_ID_TYPE_TABLE = "sm_id_type"; + public static final String SM_ID_TYPE = "sm_id_type"; } diff --git a/src/main/java/org/broadinstitute/dsm/util/PatchUtil.java b/src/main/java/org/broadinstitute/dsm/util/PatchUtil.java index 6ffd4f0fd..9efb26c75 100644 --- a/src/main/java/org/broadinstitute/dsm/util/PatchUtil.java +++ b/src/main/java/org/broadinstitute/dsm/util/PatchUtil.java @@ -5,9 +5,7 @@ import org.broadinstitute.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DBElement; 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.db.ViewFilter; import org.broadinstitute.dsm.model.KitRequest; import org.broadinstitute.dsm.statics.DBConstants; import org.slf4j.Logger; @@ -15,7 +13,10 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class PatchUtil { @@ -41,6 +42,7 @@ public PatchUtil() { getColumnNames(KitRequest.class); getColumnNames(Drug.class); getColumnNames(ParticipantData.class); + getColumnNames(TissueSmId.class); logger.info("Loaded patch utils"); } diff --git a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml index 931f0be5e..3568fcf9b 100644 --- a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml +++ b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml @@ -4,8 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - - + + @@ -16,5 +16,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From fb0b8fadb48ae51c60fdac93a3b58d230e934cf1 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Mon, 22 Nov 2021 11:26:12 -0500 Subject: [PATCH 04/20] added changes for DDP-7163 --- .../org/broadinstitute/dsm/db/TissueSmId.java | 10 +-- .../dsm/db/dao/kit/BSPDummyKitDao.java | 28 ++++++++ .../route/CreateClinicalDummyKitRoute.java | 69 +++++++++++++------ .../dsm/statics/DBConstants.java | 2 +- .../liquibase/CMI/DDP-6034_SMIDS.xml | 14 +--- 5 files changed, 84 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java index 9220d2afa..5bae329bc 100644 --- a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -12,7 +12,7 @@ @TableName ( name = DBConstants.SM_ID_TABLE, alias = DBConstants.SM_ID_TABLE_ALIAS, - primaryKey = DBConstants.SM_ID_ID, + primaryKey = DBConstants.SM_ID_PK, columnPrefix = "") public class TissueSmId { @@ -25,8 +25,8 @@ public class TissueSmId { @ColumnName(DBConstants.SM_ID_TISSUE_ID) private String tissueId; - @ColumnName(DBConstants.SM_ID_ID) - private String smIdId; + @ColumnName(DBConstants.SM_ID_PK) + private String smIdPk; @ColumnName(DBConstants.DELETED) private boolean deleted; @@ -36,8 +36,8 @@ public class TissueSmId { public static String SCROLLS = "scrolls"; public TissueSmId(){} - public TissueSmId(String smIdId, String smIdType, String smIdValue, String tissueId){ - this.smIdId = smIdId; + public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissueId){ + this.smIdPk = smIdPk; this.smIdType = smIdType; this.smIdValue = smIdValue; this.tissueId = tissueId; diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java index c9725ca4b..33ee1b651 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java @@ -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; @@ -22,6 +24,7 @@ public class BSPDummyKitDao implements Dao { 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) { @@ -83,6 +86,29 @@ public Optional getRandomParticipantIdForStudy(String ddpInstanceId) { return Optional.ofNullable((String) results.resultValue); } + public Optional 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) results.resultValue; + } + @Override public int create(ClinicalKitDto clinicalKitDto) { return 0; @@ -97,4 +123,6 @@ public int delete(int id) { public Optional get(long id) { return Optional.empty(); } + + } diff --git a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java index 003ddf8bf..1be924d71 100644 --- a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java @@ -1,10 +1,9 @@ package org.broadinstitute.dsm.route; import org.apache.commons.lang3.StringUtils; -import org.broadinstitute.dsm.db.DDPInstance; -import org.broadinstitute.dsm.db.KitRequestShipping; -import org.broadinstitute.dsm.db.KitType; +import org.broadinstitute.dsm.db.*; import org.broadinstitute.dsm.db.dao.bookmark.BookmarkDao; +import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSMIDDao; import org.broadinstitute.dsm.db.dao.kit.BSPDummyKitDao; import org.broadinstitute.dsm.model.elasticsearch.ESProfile; import org.broadinstitute.dsm.model.elasticsearch.ElasticSearchParticipantDto; @@ -18,6 +17,7 @@ import java.util.List; import java.util.Optional; +import java.util.Random; public class CreateClinicalDummyKitRoute implements Route { private static final Logger logger = LoggerFactory.getLogger(CreateClinicalDummyKitRoute.class); @@ -25,6 +25,10 @@ public class CreateClinicalDummyKitRoute implements Route { private static String CLINICAL_KIT_PREFIX = "CLINICALKIT_"; private int REALM; private static final String USER_ID = "MERCURY"; + private final String FFPE_USER = "ffpe-dummy-kit-creator"; + private final String FFPE = "ffpe"; + private final String FFPE_SCROLL = "ffpe-scroll"; + private final String FFPE_SSECTION = "ffpe-section"; @Override public Object handle(Request request, Response response) { @@ -35,34 +39,59 @@ public Object handle(Request request, Response response) { response.status(500); return "Please include a kit label as a path parameter"; } - logger.info("Got a new Clinical Kit request with kit label " + kitLabel+" and kit type "+kitTypeString); + logger.info("Got a new Clinical Kit request with kit label " + kitLabel + " and kit type " + kitTypeString); new BookmarkDao().getBookmarkByInstance(CLINICAL_KIT_REALM).ifPresentOrElse(book -> { REALM = (int) book.getValue(); }, () -> { throw new RuntimeException("Bookmark doesn't exist for " + CLINICAL_KIT_REALM); }); DDPInstance ddpInstance = DDPInstance.getDDPInstanceById(REALM); + BSPDummyKitDao bspDummyKitDao = new BSPDummyKitDao(); if (ddpInstance != null) { - String kitRequestId = CLINICAL_KIT_PREFIX + KitRequestShipping.createRandom(20); - String ddpParticipantId = new BSPDummyKitDao().getRandomParticipantForStudy(ddpInstance); - Optional maybeParticipantByParticipantId = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); List kitTypes = KitType.getKitTypes(ddpInstance.getName(), null); KitType desiredKitType = kitTypes.stream().filter(k -> kitTypeString.equalsIgnoreCase(k.getName())).findFirst().orElseThrow(); logger.info("Found kit type " + desiredKitType.getName()); - maybeParticipantByParticipantId.ifPresentOrElse(p -> { - String participantCollaboratorId = KitRequestShipping.getCollaboratorParticipantId(ddpInstance.getBaseUrl(), ddpInstance.getDdpInstanceId(), ddpInstance.isMigratedDDP(), - ddpInstance.getCollaboratorIdPrefix(), ddpParticipantId, p.getProfile().map(ESProfile::getHruid).orElseThrow(), null); - String collaboratorSampleId = KitRequestShipping.getCollaboratorSampleId(desiredKitType.getKitId(), participantCollaboratorId, desiredKitType.getName()); - logger.info("Found collaboratorSampleId " + collaboratorSampleId); - //if instance not null - String dsmKitRequestId = KitRequestShipping.writeRequest(ddpInstance.getDdpInstanceId(), kitRequestId, desiredKitType.getKitId(), - ddpParticipantId, participantCollaboratorId, collaboratorSampleId, - USER_ID, "", "", "", false, ""); - new BSPDummyKitDao().updateKitLabel(kitLabel, dsmKitRequestId); + if (kitTypeString.toLowerCase().indexOf(FFPE) == -1) { + String ddpParticipantId = bspDummyKitDao.getRandomParticipantForStudy(ddpInstance); + String kitRequestId = CLINICAL_KIT_PREFIX + KitRequestShipping.createRandom(20); + Optional maybeParticipantByParticipantId = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); + maybeParticipantByParticipantId.ifPresentOrElse(p -> { + String participantCollaboratorId = KitRequestShipping.getCollaboratorParticipantId(ddpInstance.getBaseUrl(), ddpInstance.getDdpInstanceId(), ddpInstance.isMigratedDDP(), + ddpInstance.getCollaboratorIdPrefix(), ddpParticipantId, p.getProfile().map(ESProfile::getHruid).orElseThrow(), null); + String collaboratorSampleId = KitRequestShipping.getCollaboratorSampleId(desiredKitType.getKitId(), participantCollaboratorId, desiredKitType.getName()); + logger.info("Found collaboratorSampleId " + collaboratorSampleId); + //if instance not null + String dsmKitRequestId = KitRequestShipping.writeRequest(ddpInstance.getDdpInstanceId(), kitRequestId, desiredKitType.getKitId(), + ddpParticipantId, participantCollaboratorId, collaboratorSampleId, + USER_ID, "", "", "", false, ""); + bspDummyKitDao.updateKitLabel(kitLabel, dsmKitRequestId); - }, () -> { - throw new RuntimeException(" Participant " + ddpParticipantId + " was not found!"); - }); + }, () -> { + throw new RuntimeException(" Participant " + ddpParticipantId + " was not found!"); + }); + }else{ + String smIdType; + if(kitTypeString.equalsIgnoreCase(FFPE_SCROLL)){ + smIdType = TissueSmId.SCROLLS; + }else if(kitTypeString.equalsIgnoreCase(FFPE_SSECTION)){ + smIdType = TissueSmId.USS; + }else{ + throw new RuntimeException("The FFPE kit type does not match any of the valid types "+kitTypeString); + } + Optional randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); + randomOncHistoryDetailId.ifPresentOrElse(oid -> { + List tissueIds = OncHistoryDetail.getOncHistoryDetail(oid, ddpInstance.getName()).getTissues(); + String tissueId; + + if (tissueIds.isEmpty()){ + tissueId = Tissue.createNewTissue(oid, FFPE_USER); + }else{ + tissueId = tissueIds.get( new Random().nextInt(tissueIds.size())).getTissueId(); + } + new TissueSMIDDao().createNewSMIDForTissue(tissueId, FFPE_USER, smIdType); + }, + ()-> {throw new RuntimeException("no onc history for study " + ddpInstance.getName() + " was found!");}); + } logger.info("Kit added successfully"); response.status(200); return null; diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index c5ca9366d..92778be9a 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -489,7 +489,7 @@ public class DBConstants { //sm_id table public static final String SM_ID_TABLE = "sm_id"; public static final String SM_ID_TABLE_ALIAS = "sm"; - public static final String SM_ID_ID = "sm_id_id"; + public static final String SM_ID_PK = "sm_id_pk"; public static final String SM_ID_TYPE_ID = "sm_id_type_id"; public static final String SM_ID_VALUE = "sm_id_value"; public static final String SM_ID_TISSUE_ID = "tissue_id"; diff --git a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml index 3568fcf9b..5f68c9ac9 100644 --- a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml +++ b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml @@ -4,18 +4,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - - - - - - - - - - - - @@ -26,7 +14,7 @@ - + From 977173952c725794700f34f1f6591fe205262e7a Mon Sep 17 00:00:00 2001 From: pegahtah Date: Mon, 22 Nov 2021 12:17:19 -0500 Subject: [PATCH 05/20] changed the liquibase --- .../resources/liquibase/CMI/DDP-6034_SMIDS.xml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml index 5f68c9ac9..6f203ae17 100644 --- a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml +++ b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml @@ -28,6 +28,9 @@ + + + @@ -41,18 +44,6 @@ - - - - - - - - - - - - - + From 24d830cdd02d9a26bf3e81bfa556ce06b4642d58 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Mon, 22 Nov 2021 14:17:06 -0500 Subject: [PATCH 06/20] added the Dao --- .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 122 ++++++++++++++++++ .../broadinstitute/dsm/route/PatchRoute.java | 4 +- 2 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java new file mode 100644 index 000000000..eeac2947f --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java @@ -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 getSMIdsForTissueId(String tissueId, String type) { + String typeId = getTypeForName(type); + List 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; + } + } +} diff --git a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java index 47233ebc9..013cef963 100644 --- a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java @@ -275,9 +275,9 @@ else if (Patch.ONC_HISTORY_ID.equals(patch.getParent())) { } } else if (Patch.TISSUEID.equals(patch.getParent())) { - String smIdId = new TissueSmId().createNewSmId(patch.getParentId(), patch.getUser(), (String) patch.getNameValue().getValue()); + String smIdPk = new TissueSmId().createNewSmId(patch.getParentId(), patch.getUser(), (String) patch.getNameValue().getValue()); Map map = new HashMap<>(); - map.put("smId", smIdId); + map.put("smId", smIdPk); return new Result(200, gson.toJson(map)); } else if (Patch.PARTICIPANT_DATA_ID.equals(patch.getParent())) { From 18bbbf3ab36f6783d39b930e9e8f2e5fe74968a1 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 23 Nov 2021 00:13:27 -0500 Subject: [PATCH 07/20] added ability to receive a ffpe sm_id --- .../broadinstitute/dsm/db/DDPInstance.java | 50 +++++++++++ .../dsm/db/OncHistoryDetail.java | 87 +++++++++++++++++-- .../dao/ddp/participant/ParticipantDao.java | 37 +++++++- .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 35 ++++++++ .../dsm/db/dto/kit/ClinicalKitDto.java | 55 +++++++++++- .../org/broadinstitute/dsm/model/KitType.java | 24 ++++- .../dsm/model/bsp/BSPKitInfo.java | 2 +- .../dsm/model/ddp/DDPParticipant.java | 1 + .../dsm/route/ClinicalKitsRoute.java | 31 ++++++- .../dsm/statics/DBConstants.java | 3 + 10 files changed, 304 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java b/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java index c9ea64c4a..0d061c659 100644 --- a/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java +++ b/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java @@ -47,6 +47,9 @@ public class DDPInstance { "(SELECT count(role.name) FROM ddp_instance realm, ddp_instance_role inRol, instance_role role WHERE realm.ddp_instance_id = inRol.ddp_instance_id AND inRol.instance_role_id = role.instance_role_id "+ "AND role.name = ? AND realm.ddp_instance_id = main.ddp_instance_id) as 'has_role', mr_attention_flag_d, tissue_attention_flag_d, auth0_token, notification_recipients "+ "FROM ddp_instance main, ddp_participant part WHERE main.ddp_instance_id = part.ddp_instance_id AND main.is_active = 1 AND part.ddp_participant_id = ? AND main.instance_name = ?"; + private static final String SQL_SELECT_INSTANCE_PARTICIPANT = "SELECT realm.* " + + "FROM ddp_participant p LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + + " WHERE p.ddp_participant_id = ? "; public static final String SQL_SELECT_GROUP = "SELECT ddp_group_id from ddp_instance_group g LEFT JOIN ddp_instance realm ON (g.ddp_instance_id = realm.ddp_instance_id) WHERE instance_name =?"; public static final String BY_BASE_URL = " and base_url like \"%dsm/studies/%1\""; private static final String SQL_SELECT_STUDY_GUID_BY_INSTANCE_NAME = @@ -71,6 +74,7 @@ public class DDPInstance { private final String participantIndexES; private final String activityDefinitionIndexES; private final String usersIndexES; + private String bspCollection; private InstanceSettings instanceSettings; @@ -94,6 +98,27 @@ public DDPInstance(String ddpInstanceId, String name, String baseUrl, String col this.usersIndexES = usersIndexES; } + public DDPInstance(String ddpInstanceId, String name, String baseUrl, String collaboratorIdPrefix, boolean hasRole, + int daysMrAttentionNeeded, int daysTissueAttentionNeeded, boolean hasAuth0Token, List notificationRecipient, + boolean migratedDDP, String billingReference, String participantIndexES, String activityDefinitionIndexES, + String usersIndexES, String bspCollection) { + this.ddpInstanceId = ddpInstanceId; + this.name = name; + this.baseUrl = baseUrl; + this.collaboratorIdPrefix = collaboratorIdPrefix; + this.hasRole = hasRole; + this.daysMrAttentionNeeded = daysMrAttentionNeeded; + this.daysTissueAttentionNeeded = daysTissueAttentionNeeded; + this.hasAuth0Token = hasAuth0Token; + this.notificationRecipient = notificationRecipient; + this.migratedDDP = migratedDDP; + this.billingReference = billingReference; + this.participantIndexES = participantIndexES; + this.activityDefinitionIndexES = activityDefinitionIndexES; + this.usersIndexES = usersIndexES; + this.bspCollection = bspCollection; + } + public int getDdpInstanceIdAsInt() { return Integer.parseInt(ddpInstanceId); } @@ -479,4 +504,29 @@ public static List getDDPInstanceListWithKitBehavior() { } return ddpInstances; } + + public static DDPInstance getDDPInstanceFromParticipantId(String participantId) { + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement statemnt = conn.prepareStatement(SQL_SELECT_INSTANCE_PARTICIPANT)) { + statemnt.setString(1, participantId); + try (ResultSet rs = statemnt.executeQuery()) { + if (rs.next()) { + DDPInstance ddpInstance = getDDPInstanceFormResultSet(rs); + ddpInstance.setBspCollection(rs.getString(DBConstants.BSP_COLLECTION)); + dbVals.resultValue = ddpInstance; + } + } + } + catch (SQLException ex) { + dbVals.resultException = ex; + } + return dbVals; + }); + + if (results.resultException != null) { + throw new RuntimeException("Error getting ddpInstances ", results.resultException); + } + return (DDPInstance) results.resultValue; + } } diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 4a83ef26f..78c79c5e8 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -113,40 +113,40 @@ public class OncHistoryDetail { private String request; @ColumnName (DBConstants.FAX_SENT) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tFaxSent; @ColumnName (DBConstants.FAX_SENT_BY) private String tFaxSentBy; @ColumnName (DBConstants.FAX_CONFIRMED) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tFaxConfirmed; @ColumnName (DBConstants.FAX_SENT_2) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tFaxSent2; @ColumnName (DBConstants.FAX_SENT_2_BY) private String tFaxSent2By; @ColumnName (DBConstants.FAX_CONFIRMED_2) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tFaxConfirmed2; @ColumnName (DBConstants.FAX_SENT_3) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tFaxSent3; @ColumnName (DBConstants.FAX_SENT_3_BY) private String tFaxSent3By; @ColumnName (DBConstants.FAX_CONFIRMED_3) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tFaxConfirmed3; @ColumnName (DBConstants.TISSUE_RECEIVED) - @DbDateConversion(SqlDateConverter.STRING_DAY) + @DbDateConversion (SqlDateConverter.STRING_DAY) private String tissueReceived; @ColumnName (DBConstants.TISSUE_PROBLEM_OPTION) @@ -285,6 +285,23 @@ public static OncHistoryDetail getOncHistoryDetail(@NonNull ResultSet rs) throws return oncHistoryDetail; } + public static OncHistoryDetail getOncHistoryDetailByTissueId(String tissueId, DDPInstance ddpInstance) { + List list = new ArrayList(); + list.add(tissueId); + Map> oncHistoryDetailMap = getOncHistoryDetails(ddpInstance.getName(), " and t.tissue_id = ? ", list); + if (oncHistoryDetailMap.size() == 0) { + throw new RuntimeException("Onc History for tissue id " + tissueId + " was not found"); + } + if (oncHistoryDetailMap.size() > 1) { + throw new RuntimeException("multiple participants for tissue id " + tissueId + " was found"); + } + String key = oncHistoryDetailMap.keySet().iterator().next(); + if(oncHistoryDetailMap.get(key).size() != 1) + throw new RuntimeException("wrong number of onc histories for " + tissueId + " was found "); + return oncHistoryDetailMap.get(key).get(0); + + } + public void addTissue(Tissue tissue) { if (tissues != null) { tissues.add(tissue); @@ -353,6 +370,62 @@ public static Map> getOncHistoryDetails(@NonNull return oncHistory; } + public static Map> getOncHistoryDetails(@NonNull String realm, String queryAddition, List values) { + logger.info("Collection oncHistoryDetail information"); + Map> oncHistory = new HashMap<>(); + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(SQL_SELECT_ONC_HISTORY_DETAIL, queryAddition) + SQL_ORDER_BY)) { + stmt.setString(1, realm); + for (int i = 0; i < values.size(); i++) { + stmt.setString(i + 2, values.get(i)); + } + try (ResultSet rs = stmt.executeQuery()) { + Map oncHistoryMap = new HashMap<>(); + while (rs.next()) { + String ddpParticipantId = rs.getString(DBConstants.DDP_PARTICIPANT_ID); + String oncHistoryDetailId = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); + + Tissue tissue = Tissue.getTissue(rs); + + //check if oncHistoryDetails is already in map + List oncHistoryDataList = new ArrayList<>(); + if (oncHistory.containsKey(ddpParticipantId)) { + oncHistoryDataList = oncHistory.get(ddpParticipantId); + } + else { + oncHistory.put(ddpParticipantId, oncHistoryDataList); + oncHistoryMap = new HashMap<>(); + } + + OncHistoryDetail oncHistoryDetail = null; + if (oncHistoryMap.containsKey(oncHistoryDetailId)) { + oncHistoryDetail = oncHistoryMap.get(oncHistoryDetailId); + oncHistoryDetail.addTissue(tissue); + } + else { + oncHistoryDetail = getOncHistoryDetail(rs); + oncHistoryDetail.addTissue(tissue); + oncHistoryDataList.add(oncHistoryDetail); + } + oncHistoryMap.put(oncHistoryDetailId, oncHistoryDetail); + } + } + } + catch (SQLException ex) { + dbVals.resultException = ex; + } + return dbVals; + }); + + if (results.resultException != null) { + throw new RuntimeException("Couldn't get list of oncHistories ", results.resultException); + } + + logger.info("Got " + oncHistory.size() + " participants oncHistories in DSM DB for " + realm); + return oncHistory; + } + public static OncHistoryDetail getOncHistoryDetail(@NonNull String oncHistoryDetailId, String realm) { SimpleResult results = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java index 83d272439..65f19540f 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java @@ -1,21 +1,29 @@ 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 org.broadinstitute.dsm.util.DBUtil; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +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.ddp.participant.ParticipantDto; +import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; public class ParticipantDao implements Dao { private static final String SQL_INSERT_PARTICIPANT = "INSERT INTO ddp_participant (ddp_participant_id, last_version, last_version_date, ddp_instance_id, release_completed, " + "assignee_id_mr, assignee_id_tissue, last_changed, changed_by) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE last_changed = ?, changed_by = ?"; + private final String SQL_SELECT_PARTICIPANT = "SELECT p.ddp_participant_id " + + "FROM ddp_participant p LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + + "LEFT JOIN ddp_participant_exit ex on (p.ddp_participant_id = ex.ddp_participant_id AND p.ddp_instance_id = ex.ddp_instance_id) " + + "LEFT JOIN ddp_institution inst on (p.participant_id = inst.participant_id) LEFT JOIN ddp_medical_record m on (m.institution_id = inst.institution_id AND NOT m.deleted <=> 1) " + + "LEFT JOIN ddp_onc_history_detail oD on (m.medical_record_id = oD.medical_record_id AND NOT oD.deleted <=> 1) " + + "LEFT JOIN ddp_tissue t on (t.onc_history_detail_id = oD.onc_history_detail_id AND NOT t.deleted <=> 1) " ; @Override public int create(ParticipantDto participantDto) { @@ -61,4 +69,25 @@ public Optional get(long id) { return Optional.empty(); } + public String getDDPParticipantId(String condition, List values){ + SimpleResult simpleResult = inTransaction(conn -> { + SimpleResult dbVals = new SimpleResult(-1); + try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(SQL_SELECT_PARTICIPANT, condition))) { + for (int i=0; i getTissueSMId(String smId) { + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement stmt = conn.prepareStatement(SQL_GET_SM_ID_BASED_ON_SM_ID_VALUE)) { + stmt.setString(1, smId); + stmt.executeQuery(); + try (ResultSet rs = stmt.getGeneratedKeys()) { + if (rs.next()) { + dbVals.resultValue = new TissueSmId( + rs.getString(DBConstants.SM_ID_PK), + rs.getString(DBConstants.SM_ID_TYPE), + rs.getString(DBConstants.SM_ID_VALUE), + rs.getString(DBConstants.TISSUE_ID)); + } + } + catch (Exception e) { + throw new RuntimeException("Error getting id of new sm id ", e); + } + } + catch (SQLException ex) { + dbVals.resultException = ex; + } + return dbVals; + }); + + if (results.resultException != null) { + throw new RuntimeException("Error getting tissueSmId based on smId " + smId, results.resultException); + } + else { + return Optional.ofNullable((TissueSmId)results.resultValue); + } + } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java index 3a44ca124..a4cad37f8 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java +++ b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java @@ -2,6 +2,17 @@ import com.google.gson.annotations.SerializedName; import lombok.Data; +import org.broadinstitute.dsm.db.DDPInstance; +import org.broadinstitute.dsm.db.KitRequestShipping; +import org.broadinstitute.dsm.db.OncHistoryDetail; +import org.broadinstitute.dsm.db.TissueSmId; +import org.broadinstitute.dsm.model.KitType; +import org.broadinstitute.dsm.model.elasticsearch.ESProfile; +import org.broadinstitute.dsm.model.elasticsearch.ElasticSearchParticipantDto; +import org.broadinstitute.dsm.util.ElasticSearchUtil; + +import java.util.HashMap; +import java.util.Optional; @Data public class ClinicalKitDto { @@ -39,12 +50,14 @@ public class ClinicalKitDto { @SerializedName("accession_number") String accessionNumber; - @SerializedName("collection_date") - String collectionDate; - @SerializedName("kit_label") String mfBarcode; + private final String FFPE_SECTION_KIT_TYPE = "FFPE-SECTION"; + private final String FFPE_SCROLLS_KIT_TYPE = "FFPE-SCROLL"; + private final String USS = "uss"; + private final String SCROLLS = "scrolls"; + public ClinicalKitDto(){} public void setSampleType(String kitType){ @@ -75,4 +88,40 @@ public void setGender(String genderString){ } } + public void setAllInfoBasedOnTissue(TissueSmId tissueSmId, String ddpParticipantId, DDPInstance ddpInstance) { + OncHistoryDetail oncHistoryDetail = OncHistoryDetail.getOncHistoryDetailByTissueId(tissueSmId.getTissueId(), ddpInstance); + Optional maybeParticipantByParticipantId = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); + maybeParticipantByParticipantId.ifPresent(participant -> { + String shortId = maybeParticipantByParticipantId.get().getProfile().map(ESProfile::getHruid).get(); + KitType kitType = getKitType(tissueSmId, ddpInstance); + String collaboratorParticipantId = KitRequestShipping.getCollaboratorParticipantId(ddpInstance.getBaseUrl(), ddpInstance.getDdpInstanceId(), ddpInstance.isMigratedDDP(), + ddpInstance.getCollaboratorIdPrefix(), ddpParticipantId, shortId, null); + this.setAccessionNumber(oncHistoryDetail.getAccessionNumber()); + this.setCollaboratorParticipantId(collaboratorParticipantId); + this.setSampleType(kitType.getKitTypeName()); + this.setMaterialType(kitType.getBspMaterialType()); + this.setVesselType(kitType.getBspReceptableType()); + this.setSampleCollection(ddpInstance.getBspCollection()); + this.setSampleId(ddpInstance.getBspCollection()); + }); + maybeParticipantByParticipantId.orElseThrow(() -> { + throw new RuntimeException("Participant Info in ES not found! Participant id : "+ddpParticipantId);}); + + } + + + private KitType getKitType(TissueSmId tissueSmId , DDPInstance ddpInstance) { + KitType kitType = null; + HashMap map = KitType.getKitLookup(); + switch (tissueSmId.getSmIdType()){ + case USS: + kitType = map.get(FFPE_SECTION_KIT_TYPE + "_" + ddpInstance.getDdpInstanceId()); + break; + case SCROLLS: + kitType = map.get(FFPE_SCROLLS_KIT_TYPE + "_" + ddpInstance.getDdpInstanceId()); + break; + + } + return kitType; + } } diff --git a/src/main/java/org/broadinstitute/dsm/model/KitType.java b/src/main/java/org/broadinstitute/dsm/model/KitType.java index beedfd0ce..f472721a4 100644 --- a/src/main/java/org/broadinstitute/dsm/model/KitType.java +++ b/src/main/java/org/broadinstitute/dsm/model/KitType.java @@ -20,7 +20,7 @@ public class KitType { private static final Logger logger = LoggerFactory.getLogger(KitType.class); - private static final String SQL_SELECT_KIT_TYPE = "SELECT ks.ddp_instance_id, type.kit_type_name, ks.kit_type_display_name, type.kit_type_id, type.bsp_receptacle_type, type.customs_json, ks.external_shipper " + + private static final String SQL_SELECT_KIT_TYPE = "SELECT ks.ddp_instance_id, type.kit_type_name, ks.kit_type_display_name, type.kit_type_id, type.bsp_receptacle_type, type.customs_json, ks.external_shipper, type.bsp_material_type " + "FROM ddp_kit_request_settings ks left join kit_type type on (ks.kit_type_id = type.kit_type_id) left join sub_kits_settings subK on (subK.ddp_kit_request_settings_id = ks.ddp_kit_request_settings_id)"; private static final String SQL_SELECT_CARRIER_SERVICE = "SELECT dkc.kit_type_id, kt.kit_type_name, kt.customs_json, ddp_instance_id, cs_to.carrier as carrierTo, cs_to.easypost_carrier_id as carrierToId, " + "cs_to.carrier_account_number as carrierToAccountNumber, cs_to.service as serviceTo, cs_return.carrier as carrierReturn, cs_return.easypost_carrier_id as carrierReturnId, " + @@ -40,6 +40,9 @@ public class KitType { private String externalShipper; private String customsJson; private String externalKitName; + private String bspMaterialType; + private String bspReceptableType; + public KitType (int kitTypeId, int instanceId, String kitTypeName, String kitDisplayName, String externalShipper, String customsJson) { this.kitTypeId = kitTypeId; @@ -50,6 +53,18 @@ public KitType (int kitTypeId, int instanceId, String kitTypeName, String kitDis this.customsJson = customsJson; } + public KitType (int kitTypeId, int instanceId, String kitTypeName, String kitDisplayName, String externalShipper, String customsJson, + String bspMaterialType, String bspReceptableType) { + this.kitTypeId = kitTypeId; + this.instanceId = instanceId; + this.kitTypeName = kitTypeName; + this.kitDisplayName = kitDisplayName; + this.externalShipper = externalShipper; + this.customsJson = customsJson; + this.bspMaterialType = bspMaterialType; + this.bspReceptableType = bspReceptableType; + } + public KitType(int kitTypeId, int instanceId, String kitTypeName, String kitDisplayName, String externalShipper, String customsJson, String externalKitName) { this.kitTypeId = kitTypeId; this.instanceId = instanceId; @@ -79,7 +94,10 @@ public static HashMap getKitLookup() { rs.getString(DBConstants.KIT_TYPE_NAME), rs.getString(DBConstants.KIT_TYPE_DISPLAY_NAME), rs.getString(DBConstants.EXTERNAL_SHIPPER), - rs.getString(DBConstants.CUSTOMS_JSON))); + rs.getString(DBConstants.CUSTOMS_JSON), + rs.getString(DBConstants.BSP_MATERIAL_TYPE), + rs.getString(DBConstants.BSP_RECEPTABLE_TYPE) + )); } } } @@ -128,4 +146,4 @@ public static List getKitTypesWithExternalShipper() { logger.info("Found " + kitTypes.size() + " kitTypes"); return kitTypes; } -} \ No newline at end of file +} diff --git a/src/main/java/org/broadinstitute/dsm/model/bsp/BSPKitInfo.java b/src/main/java/org/broadinstitute/dsm/model/bsp/BSPKitInfo.java index 7a11bd2ca..7d0931a21 100644 --- a/src/main/java/org/broadinstitute/dsm/model/bsp/BSPKitInfo.java +++ b/src/main/java/org/broadinstitute/dsm/model/bsp/BSPKitInfo.java @@ -10,7 +10,7 @@ public class BSPKitInfo { private static final Logger logger = LoggerFactory.getLogger(BSPKitInfo.class); private String collaboratorParticipantId, collaboratorSampleId, sampleCollectionBarcode, gender, materialInfo, receptacleName, - accessionNumber, realm, kitTypeName; + realm, kitTypeName; private final int organismClassificationId; public BSPKitInfo(String sampleCollectionBarcode, diff --git a/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java b/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java index dce709886..c9e85ceb3 100644 --- a/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java +++ b/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java @@ -56,6 +56,7 @@ public DDPParticipant(String participantId, String firstName, String lastName, S this.state = state; } + public String getShortId() { if (StringUtils.isNotBlank(shortId)) { return shortId; diff --git a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java index 676d97e96..31dfe88b9 100644 --- a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java @@ -4,6 +4,9 @@ import org.apache.commons.lang3.StringUtils; import org.broadinstitute.dsm.db.DDPInstance; import org.broadinstitute.dsm.db.OncHistoryDetail; +import org.broadinstitute.dsm.db.TissueSmId; +import org.broadinstitute.dsm.db.dao.ddp.participant.ParticipantDao; +import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSMIDDao; import org.broadinstitute.dsm.db.dao.kit.BSPKitDao; import org.broadinstitute.dsm.db.dto.kit.BSPKitDto; import org.broadinstitute.dsm.db.dto.kit.ClinicalKitDto; @@ -13,6 +16,7 @@ import org.broadinstitute.dsm.model.ddp.DDPActivityConstants; import org.broadinstitute.dsm.model.elasticsearch.*; import org.broadinstitute.dsm.statics.RequestParameter; +import org.broadinstitute.dsm.util.ElasticSearchUtil; import org.broadinstitute.dsm.util.NotificationUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +64,7 @@ private ClinicalKitDto getClinicalKit(String kitLabel) { BSPKit bspKit = new BSPKit(); ClinicalKitDto clinicalKit = new ClinicalKitDto(); Optional maybeKitInfo = bspKit.receiveBSPKit(kitLabel, notificationUtil); - maybeKitInfo.ifPresent(kitInfo -> { + maybeKitInfo.ifPresentOrElse(kitInfo -> { logger.info("Creating clinical kit to return to GP " + kitLabel); clinicalKit.setCollaboratorParticipantId(kitInfo.getCollaboratorParticipantId()); clinicalKit.setSampleId(kitInfo.getCollaboratorSampleId()); @@ -80,12 +84,33 @@ private ClinicalKitDto getClinicalKit(String kitLabel) { ElasticSearchParticipantDto participantByShortId = new ElasticSearch().getParticipantByShortId(ddpInstance.getParticipantIndexES(), hruid); setNecessaryParticipantDataToClinicalKit(clinicalKit, participantByShortId, kitInfo.getRealm()); - }); - maybeKitInfo.orElseThrow(); + }, + () -> getClinicalKitWithSMId(kitLabel, clinicalKit)); return clinicalKit; } + private void getClinicalKitWithSMId(String smId, ClinicalKitDto clinicalKit) { + TissueSMIDDao tissueSmIdDao = new TissueSMIDDao(); + Optional maybeTissueSmId = tissueSmIdDao.getTissueSMId(smId); + maybeTissueSmId.ifPresentOrElse( tissueSmId -> { + List list = new ArrayList(); + list.add(tissueSmId.getTissueId()); + String ddpParticipantId = new ParticipantDao().getDDPParticipantId( " where t.tissue_id = ? ", list); + DDPInstance ddpInstance = DDPInstance.getDDPInstanceFromParticipantId(ddpParticipantId); + clinicalKit.setAllInfoBasedOnTissue(tissueSmId, ddpParticipantId, ddpInstance); + ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId).ifPresentOrElse( + maybeParticipant -> { + String shortId = maybeParticipant.getProfile().map(ESProfile::getHruid).get(); + ElasticSearchParticipantDto participantByShortId = + new ElasticSearch().getParticipantByShortId(ddpInstance.getParticipantIndexES(), shortId); + setNecessaryParticipantDataToClinicalKit(clinicalKit, participantByShortId, ddpInstance.getName()); + }, () -> { + throw new RuntimeException("Participant ES Data is not found for "+ddpParticipantId); + }); + }, () -> { throw new RuntimeException("TissueeSMID for sm id was not found "+smId);}); + } + private void setNecessaryParticipantDataToClinicalKit(ClinicalKitDto clinicalKit, ElasticSearchParticipantDto participantByShortId, String instanceName) { try { diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index 92778be9a..f972e6584 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -46,6 +46,7 @@ public class DBConstants { public static final String CARRIER_USERNAME = "carrier_username"; public static final String CARRIER_PASSWORD= "carrier_password"; public static final String CARRIER_ACCESSKEY = "carrier_accesskey"; + public static final String BSP_COLLECTION = "bsp_collection"; //kit request public static final String DSM_KIT_ID = "dsm_kit_id"; @@ -83,6 +84,8 @@ public class DBConstants { public static final String KIT_TYPE_RETURN_ADDRESS_COUNTRY = "return_address_country"; public static final String KIT_TYPE_RETURN_ADDRESS_PHONE = "return_address_phone"; public static final String CUSTOMS_JSON = "customs_json"; + public static final String BSP_MATERIAL_TYPE = "bsp_material_type"; + public static final String BSP_RECEPTABLE_TYPE = "bsp_receptable_type"; public static final String KIT_DIMENSIONS_LENGTH = "kit_length"; public static final String KIT_DIMENSIONS_HEIGHT = "kit_height"; public static final String KIT_DIMENSIONS_WIDTH = "kit_width"; From 1a533d02ce58840475d6d3458712f34bd9420a19 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 23 Nov 2021 12:24:18 -0500 Subject: [PATCH 08/20] changed how smid is received --- .../broadinstitute/dsm/db/DDPInstance.java | 50 ------ .../dsm/db/OncHistoryDetail.java | 17 --- .../dao/ddp/participant/ParticipantDao.java | 29 ---- .../dsm/db/dao/kit/ClinicalKitDao.java | 74 +++++++++ .../dsm/db/dto/kit/ClinicalKitDto.java | 143 ++++++++++++------ .../org/broadinstitute/dsm/model/KitType.java | 22 +-- .../dsm/model/ddp/DDPParticipant.java | 1 - .../dsm/route/ClinicalKitsRoute.java | 87 +---------- .../dsm/statics/DBConstants.java | 5 +- .../liquibase/CMI/DDP-6034_SMIDS.xml | 8 + 10 files changed, 189 insertions(+), 247 deletions(-) create mode 100644 src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java diff --git a/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java b/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java index 0d061c659..c9ea64c4a 100644 --- a/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java +++ b/src/main/java/org/broadinstitute/dsm/db/DDPInstance.java @@ -47,9 +47,6 @@ public class DDPInstance { "(SELECT count(role.name) FROM ddp_instance realm, ddp_instance_role inRol, instance_role role WHERE realm.ddp_instance_id = inRol.ddp_instance_id AND inRol.instance_role_id = role.instance_role_id "+ "AND role.name = ? AND realm.ddp_instance_id = main.ddp_instance_id) as 'has_role', mr_attention_flag_d, tissue_attention_flag_d, auth0_token, notification_recipients "+ "FROM ddp_instance main, ddp_participant part WHERE main.ddp_instance_id = part.ddp_instance_id AND main.is_active = 1 AND part.ddp_participant_id = ? AND main.instance_name = ?"; - private static final String SQL_SELECT_INSTANCE_PARTICIPANT = "SELECT realm.* " + - "FROM ddp_participant p LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + - " WHERE p.ddp_participant_id = ? "; public static final String SQL_SELECT_GROUP = "SELECT ddp_group_id from ddp_instance_group g LEFT JOIN ddp_instance realm ON (g.ddp_instance_id = realm.ddp_instance_id) WHERE instance_name =?"; public static final String BY_BASE_URL = " and base_url like \"%dsm/studies/%1\""; private static final String SQL_SELECT_STUDY_GUID_BY_INSTANCE_NAME = @@ -74,7 +71,6 @@ public class DDPInstance { private final String participantIndexES; private final String activityDefinitionIndexES; private final String usersIndexES; - private String bspCollection; private InstanceSettings instanceSettings; @@ -98,27 +94,6 @@ public DDPInstance(String ddpInstanceId, String name, String baseUrl, String col this.usersIndexES = usersIndexES; } - public DDPInstance(String ddpInstanceId, String name, String baseUrl, String collaboratorIdPrefix, boolean hasRole, - int daysMrAttentionNeeded, int daysTissueAttentionNeeded, boolean hasAuth0Token, List notificationRecipient, - boolean migratedDDP, String billingReference, String participantIndexES, String activityDefinitionIndexES, - String usersIndexES, String bspCollection) { - this.ddpInstanceId = ddpInstanceId; - this.name = name; - this.baseUrl = baseUrl; - this.collaboratorIdPrefix = collaboratorIdPrefix; - this.hasRole = hasRole; - this.daysMrAttentionNeeded = daysMrAttentionNeeded; - this.daysTissueAttentionNeeded = daysTissueAttentionNeeded; - this.hasAuth0Token = hasAuth0Token; - this.notificationRecipient = notificationRecipient; - this.migratedDDP = migratedDDP; - this.billingReference = billingReference; - this.participantIndexES = participantIndexES; - this.activityDefinitionIndexES = activityDefinitionIndexES; - this.usersIndexES = usersIndexES; - this.bspCollection = bspCollection; - } - public int getDdpInstanceIdAsInt() { return Integer.parseInt(ddpInstanceId); } @@ -504,29 +479,4 @@ public static List getDDPInstanceListWithKitBehavior() { } return ddpInstances; } - - public static DDPInstance getDDPInstanceFromParticipantId(String participantId) { - SimpleResult results = inTransaction((conn) -> { - SimpleResult dbVals = new SimpleResult(); - try (PreparedStatement statemnt = conn.prepareStatement(SQL_SELECT_INSTANCE_PARTICIPANT)) { - statemnt.setString(1, participantId); - try (ResultSet rs = statemnt.executeQuery()) { - if (rs.next()) { - DDPInstance ddpInstance = getDDPInstanceFormResultSet(rs); - ddpInstance.setBspCollection(rs.getString(DBConstants.BSP_COLLECTION)); - dbVals.resultValue = ddpInstance; - } - } - } - catch (SQLException ex) { - dbVals.resultException = ex; - } - return dbVals; - }); - - if (results.resultException != null) { - throw new RuntimeException("Error getting ddpInstances ", results.resultException); - } - return (DDPInstance) results.resultValue; - } } diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 78c79c5e8..2f4a4589f 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -285,23 +285,6 @@ public static OncHistoryDetail getOncHistoryDetail(@NonNull ResultSet rs) throws return oncHistoryDetail; } - public static OncHistoryDetail getOncHistoryDetailByTissueId(String tissueId, DDPInstance ddpInstance) { - List list = new ArrayList(); - list.add(tissueId); - Map> oncHistoryDetailMap = getOncHistoryDetails(ddpInstance.getName(), " and t.tissue_id = ? ", list); - if (oncHistoryDetailMap.size() == 0) { - throw new RuntimeException("Onc History for tissue id " + tissueId + " was not found"); - } - if (oncHistoryDetailMap.size() > 1) { - throw new RuntimeException("multiple participants for tissue id " + tissueId + " was found"); - } - String key = oncHistoryDetailMap.keySet().iterator().next(); - if(oncHistoryDetailMap.get(key).size() != 1) - throw new RuntimeException("wrong number of onc histories for " + tissueId + " was found "); - return oncHistoryDetailMap.get(key).get(0); - - } - public void addTissue(Tissue tissue) { if (tissues != null) { tissues.add(tissue); diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java index 65f19540f..938479251 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/participant/ParticipantDao.java @@ -3,13 +3,11 @@ import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.dsm.db.dao.Dao; import org.broadinstitute.dsm.db.dto.ddp.participant.ParticipantDto; -import org.broadinstitute.dsm.util.DBUtil; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.List; import java.util.Optional; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -18,12 +16,6 @@ public class ParticipantDao implements Dao { private static final String SQL_INSERT_PARTICIPANT = "INSERT INTO ddp_participant (ddp_participant_id, last_version, last_version_date, ddp_instance_id, release_completed, " + "assignee_id_mr, assignee_id_tissue, last_changed, changed_by) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE last_changed = ?, changed_by = ?"; - private final String SQL_SELECT_PARTICIPANT = "SELECT p.ddp_participant_id " + - "FROM ddp_participant p LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + - "LEFT JOIN ddp_participant_exit ex on (p.ddp_participant_id = ex.ddp_participant_id AND p.ddp_instance_id = ex.ddp_instance_id) " + - "LEFT JOIN ddp_institution inst on (p.participant_id = inst.participant_id) LEFT JOIN ddp_medical_record m on (m.institution_id = inst.institution_id AND NOT m.deleted <=> 1) " + - "LEFT JOIN ddp_onc_history_detail oD on (m.medical_record_id = oD.medical_record_id AND NOT oD.deleted <=> 1) " + - "LEFT JOIN ddp_tissue t on (t.onc_history_detail_id = oD.onc_history_detail_id AND NOT t.deleted <=> 1) " ; @Override public int create(ParticipantDto participantDto) { @@ -69,25 +61,4 @@ public Optional get(long id) { return Optional.empty(); } - public String getDDPParticipantId(String condition, List values){ - SimpleResult simpleResult = inTransaction(conn -> { - SimpleResult dbVals = new SimpleResult(-1); - try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(SQL_SELECT_PARTICIPANT, condition))) { - for (int i=0; i 1) " + + "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) " + + "left join sm_id_type sit on (sit.sm_id_type_id = sm.sm_id_type_id) " + + "left join kit_type ktype on ( sit.kit_type_id = ktype.kit_type_id) " + + "where sm.sm_id_value = ? "; + + public Optional getClinicalKitFromSMId(String smIdValue){ + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement stmt = conn.prepareStatement(SQL_GET_CLINICAL_KIT_BASED_ON_SM_ID_VALUE)) { + stmt.setString(1, smIdValue); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + ClinicalKitDto clinicalKitDto = new ClinicalKitDto( + null, + rs.getString(DBConstants.BSP_COLLECTION), + rs.getString(DBConstants.BSP_ORGANISM), + rs.getString(DBConstants.BSP_MATERIAL_TYPE), + rs.getString(DBConstants.BSP_RECEPTABLE_TYPE), + null, + null, + null, + null, + null, + rs.getString(DBConstants.ACCESSION_NUMBER), + null + ); + clinicalKitDto.setSampleType(rs.getString(DBConstants.KIT_TYPE_NAME)); + clinicalKitDto.setDdpInstanceId(Integer.parseInt(rs.getString(DBConstants.DDP_INSTANCE_ID))); + clinicalKitDto.setDdpParticipantId(rs.getString(DBConstants.DDP_PARTICIPANT_ID)); + dbVals.resultValue = clinicalKitDto; + + } + } + catch (Exception e) { + throw new RuntimeException("Error getting id of new sm id ", e); + } + } + catch (SQLException ex) { + dbVals.resultException = ex; + } + + return dbVals; + }); + + if (results.resultException != null) { + throw new RuntimeException("Error getting clinicalKit based on smId " + smIdValue, results.resultException); + } + else { + return Optional.ofNullable((ClinicalKitDto) results.resultValue); + } + } +} diff --git a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java index a4cad37f8..8ba16c91b 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java +++ b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java @@ -2,17 +2,16 @@ import com.google.gson.annotations.SerializedName; import lombok.Data; +import org.apache.commons.lang3.StringUtils; import org.broadinstitute.dsm.db.DDPInstance; import org.broadinstitute.dsm.db.KitRequestShipping; import org.broadinstitute.dsm.db.OncHistoryDetail; -import org.broadinstitute.dsm.db.TissueSmId; -import org.broadinstitute.dsm.model.KitType; -import org.broadinstitute.dsm.model.elasticsearch.ESProfile; -import org.broadinstitute.dsm.model.elasticsearch.ElasticSearchParticipantDto; +import org.broadinstitute.dsm.db.dao.kit.ClinicalKitDao; +import org.broadinstitute.dsm.model.ddp.DDPActivityConstants; +import org.broadinstitute.dsm.model.elasticsearch.*; import org.broadinstitute.dsm.util.ElasticSearchUtil; -import java.util.HashMap; -import java.util.Optional; +import java.util.*; @Data public class ClinicalKitDto { @@ -41,27 +40,47 @@ public class ClinicalKitDto { @SerializedName ("date_of_birth") String dateOfBirth; - @SerializedName("sample_type") + @SerializedName ("sample_type") String sampleType; - @SerializedName("gender") + @SerializedName ("gender") String gender; - @SerializedName("accession_number") + @SerializedName ("accession_number") String accessionNumber; - @SerializedName("kit_label") + @SerializedName ("kit_label") String mfBarcode; + String ddpParticipantId; + Integer ddpInstanceId; + private final String FFPE_SECTION_KIT_TYPE = "FFPE-SECTION"; private final String FFPE_SCROLLS_KIT_TYPE = "FFPE-SCROLL"; private final String USS = "uss"; private final String SCROLLS = "scrolls"; - public ClinicalKitDto(){} + public ClinicalKitDto(String collaboratorParticipantId, String sampleId, String sampleCollection, String materialType, String vesselType, + String firstName, String lastName, String dateOfBirth, String sampleType, String gender, String accessionNumber, String mfBarcode) { + this.collaboratorParticipantId = collaboratorParticipantId; + this.sampleId = sampleId; + this.sampleCollection = sampleCollection; + this.materialType = materialType; + this.vesselType = vesselType; + this.firstName = firstName; + this.lastName = lastName; + this.dateOfBirth = dateOfBirth; + this.sampleType = sampleType; + this.gender = gender; + this.accessionNumber = accessionNumber; + this.mfBarcode = mfBarcode; + } + + public ClinicalKitDto() { + } - public void setSampleType(String kitType){ - switch (kitType.toLowerCase()){ + public void setSampleType(String kitType) { + switch (kitType.toLowerCase()) { case "saliva": this.sampleType = "Normal"; break; @@ -74,8 +93,8 @@ public void setSampleType(String kitType){ } } - public void setGender(String genderString){ - switch (genderString.toLowerCase()){ + public void setGender(String genderString) { + switch (genderString.toLowerCase()) { case "male": this.gender = "M"; break; @@ -88,40 +107,74 @@ public void setGender(String genderString){ } } - public void setAllInfoBasedOnTissue(TissueSmId tissueSmId, String ddpParticipantId, DDPInstance ddpInstance) { - OncHistoryDetail oncHistoryDetail = OncHistoryDetail.getOncHistoryDetailByTissueId(tissueSmId.getTissueId(), ddpInstance); - Optional maybeParticipantByParticipantId = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); - maybeParticipantByParticipantId.ifPresent(participant -> { - String shortId = maybeParticipantByParticipantId.get().getProfile().map(ESProfile::getHruid).get(); - KitType kitType = getKitType(tissueSmId, ddpInstance); - String collaboratorParticipantId = KitRequestShipping.getCollaboratorParticipantId(ddpInstance.getBaseUrl(), ddpInstance.getDdpInstanceId(), ddpInstance.isMigratedDDP(), - ddpInstance.getCollaboratorIdPrefix(), ddpParticipantId, shortId, null); - this.setAccessionNumber(oncHistoryDetail.getAccessionNumber()); - this.setCollaboratorParticipantId(collaboratorParticipantId); - this.setSampleType(kitType.getKitTypeName()); - this.setMaterialType(kitType.getBspMaterialType()); - this.setVesselType(kitType.getBspReceptableType()); - this.setSampleCollection(ddpInstance.getBspCollection()); - this.setSampleId(ddpInstance.getBspCollection()); - }); - maybeParticipantByParticipantId.orElseThrow(() -> { - throw new RuntimeException("Participant Info in ES not found! Participant id : "+ddpParticipantId);}); - } + public Optional getClinicalKitBasedONSmId(String smIdValue) { + ClinicalKitDao clinicalKitDao = new ClinicalKitDao(); + Optional maybeClinicalKit = clinicalKitDao.getClinicalKitFromSMId(smIdValue); + maybeClinicalKit.orElseThrow(); + ClinicalKitDto clinicalKitDto = maybeClinicalKit.get(); + DDPInstance ddpInstance = DDPInstance.getDDPInstanceById(clinicalKitDto.ddpInstanceId); + clinicalKitDto.setNecessaryParticipantDataToClinicalKit(clinicalKitDto.ddpParticipantId, ddpInstance); + return Optional.ofNullable(clinicalKitDto); + } - private KitType getKitType(TissueSmId tissueSmId , DDPInstance ddpInstance) { - KitType kitType = null; - HashMap map = KitType.getKitLookup(); - switch (tissueSmId.getSmIdType()){ - case USS: - kitType = map.get(FFPE_SECTION_KIT_TYPE + "_" + ddpInstance.getDdpInstanceId()); - break; - case SCROLLS: - kitType = map.get(FFPE_SCROLLS_KIT_TYPE + "_" + ddpInstance.getDdpInstanceId()); - break; + public void setNecessaryParticipantDataToClinicalKit(String ddpParticipantId, DDPInstance ddpInstance) { + ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId).ifPresentOrElse( + maybeParticipant -> { + String shortId = maybeParticipant.getProfile().map(ESProfile::getHruid).get(); + ElasticSearchParticipantDto participantByShortId = + new ElasticSearch().getParticipantByShortId(ddpInstance.getParticipantIndexES(), shortId); + try { + this.setDateOfBirth(Objects.requireNonNull(participantByShortId).getDsm().map(ESDsm::getDateOfBirth).orElse("")); + String firstName = participantByShortId.getProfile().map(ESProfile::getFirstName).orElse(""); + String lastName = participantByShortId.getProfile().map(ESProfile::getLastName).orElse(""); + String gender = getParticipantGender(participantByShortId, ddpInstance.getName()); + this.setFirstName(firstName); + this.setLastName(lastName); + this.setGender(gender); + String collaboratorParticipantId = KitRequestShipping.getCollaboratorParticipantId(ddpInstance.getBaseUrl(), ddpInstance.getDdpInstanceId(), ddpInstance.isMigratedDDP(), + ddpInstance.getCollaboratorIdPrefix(), ddpParticipantId, shortId, null); + this.setCollaboratorParticipantId(collaboratorParticipantId); + } + catch (Exception e) { + throw new RuntimeException("Participant doesn't exist / is not valid for kit "); + } + + }, () -> { + throw new RuntimeException("Participant ES Data is not found for " + ddpParticipantId); + }); + } + private String getParticipantGender(ElasticSearchParticipantDto participantByShortId, String realm) { + // if gender is set on tissue page use that + List list = new ArrayList(); + list.add(participantByShortId.getParticipantId()); + Map> oncHistoryDetails = OncHistoryDetail.getOncHistoryDetailsByParticipantIds(realm, list); + if (!oncHistoryDetails.isEmpty()) { + Optional oncHistoryWithGender = oncHistoryDetails.get(participantByShortId.getParticipantId()).stream().filter(o -> StringUtils.isNotBlank(o.getGender())).findFirst(); + if (oncHistoryWithGender.isPresent()) { + return oncHistoryWithGender.get().getGender(); + } } - return kitType; + //if gender is not set on tissue page get answer from "ABOUT_YOU.ASSIGNED_SEX" + return participantByShortId.getActivities() + .map(this::getGenderFromActivities) + .orElse("U"); + } + + private String getGenderFromActivities(List activities) { + Optional maybeAboutYouActivity = activities.stream() + .filter(activity -> DDPActivityConstants.ACTIVITY_ABOUT_YOU.equals(activity.getActivityCode())) + .findFirst(); + return (String) maybeAboutYouActivity.map(aboutYou -> { + List> questionsAnswers = aboutYou.getQuestionsAnswers(); + Optional> maybeGenderQuestionAnswer = questionsAnswers.stream() + .filter(q -> DDPActivityConstants.ABOUT_YOU_ACTIVITY_GENDER.equals(q.get(DDPActivityConstants.DDP_ACTIVITY_STABLE_ID))) + .findFirst(); + return maybeGenderQuestionAnswer + .map(answer -> answer.get(DDPActivityConstants.ACTIVITY_QUESTION_ANSWER)) + .orElse(""); + }).orElse(""); } } diff --git a/src/main/java/org/broadinstitute/dsm/model/KitType.java b/src/main/java/org/broadinstitute/dsm/model/KitType.java index f472721a4..46b77ceb5 100644 --- a/src/main/java/org/broadinstitute/dsm/model/KitType.java +++ b/src/main/java/org/broadinstitute/dsm/model/KitType.java @@ -20,7 +20,7 @@ public class KitType { private static final Logger logger = LoggerFactory.getLogger(KitType.class); - private static final String SQL_SELECT_KIT_TYPE = "SELECT ks.ddp_instance_id, type.kit_type_name, ks.kit_type_display_name, type.kit_type_id, type.bsp_receptacle_type, type.customs_json, ks.external_shipper, type.bsp_material_type " + + private static final String SQL_SELECT_KIT_TYPE = "SELECT ks.ddp_instance_id, type.kit_type_name, ks.kit_type_display_name, type.kit_type_id, type.bsp_receptacle_type, type.customs_json, ks.external_shipper " + "FROM ddp_kit_request_settings ks left join kit_type type on (ks.kit_type_id = type.kit_type_id) left join sub_kits_settings subK on (subK.ddp_kit_request_settings_id = ks.ddp_kit_request_settings_id)"; private static final String SQL_SELECT_CARRIER_SERVICE = "SELECT dkc.kit_type_id, kt.kit_type_name, kt.customs_json, ddp_instance_id, cs_to.carrier as carrierTo, cs_to.easypost_carrier_id as carrierToId, " + "cs_to.carrier_account_number as carrierToAccountNumber, cs_to.service as serviceTo, cs_return.carrier as carrierReturn, cs_return.easypost_carrier_id as carrierReturnId, " + @@ -40,9 +40,6 @@ public class KitType { private String externalShipper; private String customsJson; private String externalKitName; - private String bspMaterialType; - private String bspReceptableType; - public KitType (int kitTypeId, int instanceId, String kitTypeName, String kitDisplayName, String externalShipper, String customsJson) { this.kitTypeId = kitTypeId; @@ -53,18 +50,6 @@ public KitType (int kitTypeId, int instanceId, String kitTypeName, String kitDis this.customsJson = customsJson; } - public KitType (int kitTypeId, int instanceId, String kitTypeName, String kitDisplayName, String externalShipper, String customsJson, - String bspMaterialType, String bspReceptableType) { - this.kitTypeId = kitTypeId; - this.instanceId = instanceId; - this.kitTypeName = kitTypeName; - this.kitDisplayName = kitDisplayName; - this.externalShipper = externalShipper; - this.customsJson = customsJson; - this.bspMaterialType = bspMaterialType; - this.bspReceptableType = bspReceptableType; - } - public KitType(int kitTypeId, int instanceId, String kitTypeName, String kitDisplayName, String externalShipper, String customsJson, String externalKitName) { this.kitTypeId = kitTypeId; this.instanceId = instanceId; @@ -94,10 +79,7 @@ public static HashMap getKitLookup() { rs.getString(DBConstants.KIT_TYPE_NAME), rs.getString(DBConstants.KIT_TYPE_DISPLAY_NAME), rs.getString(DBConstants.EXTERNAL_SHIPPER), - rs.getString(DBConstants.CUSTOMS_JSON), - rs.getString(DBConstants.BSP_MATERIAL_TYPE), - rs.getString(DBConstants.BSP_RECEPTABLE_TYPE) - )); + rs.getString(DBConstants.CUSTOMS_JSON))); } } } diff --git a/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java b/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java index c9e85ceb3..dce709886 100644 --- a/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java +++ b/src/main/java/org/broadinstitute/dsm/model/ddp/DDPParticipant.java @@ -56,7 +56,6 @@ public DDPParticipant(String participantId, String firstName, String lastName, S this.state = state; } - public String getShortId() { if (StringUtils.isNotBlank(shortId)) { return shortId; diff --git a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java index 31dfe88b9..e44d44ed7 100644 --- a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java @@ -3,20 +3,13 @@ import lombok.NonNull; import org.apache.commons.lang3.StringUtils; import org.broadinstitute.dsm.db.DDPInstance; -import org.broadinstitute.dsm.db.OncHistoryDetail; -import org.broadinstitute.dsm.db.TissueSmId; -import org.broadinstitute.dsm.db.dao.ddp.participant.ParticipantDao; -import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSMIDDao; import org.broadinstitute.dsm.db.dao.kit.BSPKitDao; import org.broadinstitute.dsm.db.dto.kit.BSPKitDto; import org.broadinstitute.dsm.db.dto.kit.ClinicalKitDto; import org.broadinstitute.dsm.model.BSPKit; import org.broadinstitute.dsm.model.bsp.BSPKitInfo; import org.broadinstitute.dsm.model.bsp.BSPKitStatus; -import org.broadinstitute.dsm.model.ddp.DDPActivityConstants; -import org.broadinstitute.dsm.model.elasticsearch.*; import org.broadinstitute.dsm.statics.RequestParameter; -import org.broadinstitute.dsm.util.ElasticSearchUtil; import org.broadinstitute.dsm.util.NotificationUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +17,7 @@ import spark.Response; import spark.Route; -import java.util.*; +import java.util.Optional; public class ClinicalKitsRoute implements Route { private String FIRSTNAME = "firstName"; @@ -77,84 +70,12 @@ private ClinicalKitDto getClinicalKit(String kitLabel) { bspKitQueryResult.orElseThrow(() -> {throw new RuntimeException("kit label was not found "+kitLabel);}); BSPKitDto maybeBspKitQueryResult = bspKitQueryResult.get(); DDPInstance ddpInstance = DDPInstance.getDDPInstance(maybeBspKitQueryResult.getInstanceName()); - String hruid = maybeBspKitQueryResult.getBspParticipantId(); - if (hruid.indexOf('_') != -1) { - hruid = maybeBspKitQueryResult.getBspParticipantId().substring(maybeBspKitQueryResult.getBspParticipantId().lastIndexOf('_') + 1); - } - ElasticSearchParticipantDto participantByShortId = - new ElasticSearch().getParticipantByShortId(ddpInstance.getParticipantIndexES(), hruid); - setNecessaryParticipantDataToClinicalKit(clinicalKit, participantByShortId, kitInfo.getRealm()); + clinicalKit.setNecessaryParticipantDataToClinicalKit( maybeBspKitQueryResult.getDdpParticipantId(), ddpInstance); }, - () -> getClinicalKitWithSMId(kitLabel, clinicalKit)); - return clinicalKit; - - } - - private void getClinicalKitWithSMId(String smId, ClinicalKitDto clinicalKit) { - TissueSMIDDao tissueSmIdDao = new TissueSMIDDao(); - Optional maybeTissueSmId = tissueSmIdDao.getTissueSMId(smId); - maybeTissueSmId.ifPresentOrElse( tissueSmId -> { - List list = new ArrayList(); - list.add(tissueSmId.getTissueId()); - String ddpParticipantId = new ParticipantDao().getDDPParticipantId( " where t.tissue_id = ? ", list); - DDPInstance ddpInstance = DDPInstance.getDDPInstanceFromParticipantId(ddpParticipantId); - clinicalKit.setAllInfoBasedOnTissue(tissueSmId, ddpParticipantId, ddpInstance); - ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId).ifPresentOrElse( - maybeParticipant -> { - String shortId = maybeParticipant.getProfile().map(ESProfile::getHruid).get(); - ElasticSearchParticipantDto participantByShortId = - new ElasticSearch().getParticipantByShortId(ddpInstance.getParticipantIndexES(), shortId); - setNecessaryParticipantDataToClinicalKit(clinicalKit, participantByShortId, ddpInstance.getName()); - }, () -> { - throw new RuntimeException("Participant ES Data is not found for "+ddpParticipantId); - }); - }, () -> { throw new RuntimeException("TissueeSMID for sm id was not found "+smId);}); - } + () -> {clinicalKit.getClinicalKitBasedONSmId(kitLabel);}); - private void setNecessaryParticipantDataToClinicalKit(ClinicalKitDto clinicalKit, - ElasticSearchParticipantDto participantByShortId, String instanceName) { - try { - clinicalKit.setDateOfBirth(Objects.requireNonNull(participantByShortId).getDsm().map(ESDsm::getDateOfBirth).orElse("")); - String firstName = participantByShortId.getProfile().map(ESProfile::getFirstName).orElse(""); - String lastName = participantByShortId.getProfile().map(ESProfile::getLastName).orElse(""); - String gender = getParticipantGender(participantByShortId, instanceName); - clinicalKit.setFirstName(firstName); - clinicalKit.setLastName(lastName); - clinicalKit.setGender(gender); - } catch (Exception e) { - throw new RuntimeException("Participant doesn't exist / is not valid for kit "); - } - } + return clinicalKit; - private String getParticipantGender(ElasticSearchParticipantDto participantByShortId, String realm) { - // if gender is set on tissue page use that - List list = new ArrayList(); - list.add(participantByShortId.getParticipantId()); - Map> oncHistoryDetails = OncHistoryDetail.getOncHistoryDetailsByParticipantIds(realm, list); - if(!oncHistoryDetails.isEmpty()){ - Optional oncHistoryWithGender = oncHistoryDetails.get(participantByShortId.getParticipantId()).stream().filter(o -> StringUtils.isNotBlank(o.getGender())).findFirst(); - if(oncHistoryWithGender.isPresent()){ - return oncHistoryWithGender.get().getGender(); - } - } - //if gender is not set on tissue page get answer from "ABOUT_YOU.ASSIGNED_SEX" - return participantByShortId.getActivities() - .map(this::getGenderFromActivities) - .orElse("U"); } - private String getGenderFromActivities(List activities) { - Optional maybeAboutYouActivity = activities.stream() - .filter(activity -> DDPActivityConstants.ACTIVITY_ABOUT_YOU.equals(activity.getActivityCode())) - .findFirst(); - return (String) maybeAboutYouActivity.map(aboutYou -> { - List> questionsAnswers = aboutYou.getQuestionsAnswers(); - Optional> maybeGenderQuestionAnswer = questionsAnswers.stream() - .filter(q -> DDPActivityConstants.ABOUT_YOU_ACTIVITY_GENDER.equals(q.get(DDPActivityConstants.DDP_ACTIVITY_STABLE_ID))) - .findFirst(); - return maybeGenderQuestionAnswer - .map(answer -> answer.get(DDPActivityConstants.ACTIVITY_QUESTION_ANSWER)) - .orElse(""); - }).orElse(""); - } } diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index f972e6584..31e39cb61 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -47,6 +47,7 @@ public class DBConstants { public static final String CARRIER_PASSWORD= "carrier_password"; public static final String CARRIER_ACCESSKEY = "carrier_accesskey"; public static final String BSP_COLLECTION = "bsp_collection"; + public static final String BSP_ORGANISM = "bsp_organism"; //kit request public static final String DSM_KIT_ID = "dsm_kit_id"; @@ -62,6 +63,8 @@ public class DBConstants { public static final String UPS_RETURN_DATE = "ups_return_date"; public static final String SAMPLE_TYPE = "sample_type"; public static final String DDP_KIT_REQUEST_TABLE_ABBR = "req."; + public static final String BSP_MATERIAL_TYPE = "bsp_material_type"; + public static final String BSP_RECEPTABLE_TYPE = "bsp_receptable_type"; @@ -84,8 +87,6 @@ public class DBConstants { public static final String KIT_TYPE_RETURN_ADDRESS_COUNTRY = "return_address_country"; public static final String KIT_TYPE_RETURN_ADDRESS_PHONE = "return_address_phone"; public static final String CUSTOMS_JSON = "customs_json"; - public static final String BSP_MATERIAL_TYPE = "bsp_material_type"; - public static final String BSP_RECEPTABLE_TYPE = "bsp_receptable_type"; public static final String KIT_DIMENSIONS_LENGTH = "kit_length"; public static final String KIT_DIMENSIONS_HEIGHT = "kit_height"; public static final String KIT_DIMENSIONS_WIDTH = "kit_width"; diff --git a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml index 6f203ae17..929874c73 100644 --- a/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml +++ b/src/main/resources/liquibase/CMI/DDP-6034_SMIDS.xml @@ -44,6 +44,14 @@ + + + + + + + From b3030f7eb21403a54d4489692787dbf18d3f9f5a Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 23 Nov 2021 13:18:39 -0500 Subject: [PATCH 09/20] addressed PR comments --- .../dsm/db/OncHistoryDetail.java | 2 +- .../org/broadinstitute/dsm/db/Tissue.java | 33 +++++++------------ .../org/broadinstitute/dsm/db/TissueSmId.java | 7 ++-- .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 20 +++++------ .../route/CreateClinicalDummyKitRoute.java | 4 +-- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 2f4a4589f..eb71581e9 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -42,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, t.uss_sm_ids, t.scrolls_sm_ids, t.he_sm_ids " + + " scrolls_count, uss_count, h_e_count, blocks_count " + "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) " + diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index dc48286bf..74b398fed 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -4,6 +4,7 @@ import lombok.Data; import lombok.NonNull; import org.broadinstitute.ddp.db.SimpleResult; +import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSMIDDao; import org.broadinstitute.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DbDateConversion; import org.broadinstitute.dsm.db.structure.SqlDateConverter; @@ -15,6 +16,7 @@ import java.sql.*; import java.util.ArrayList; import java.util.List; +import java.util.Map; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -31,7 +33,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, uss_sm_ids, scrolls_sm_ids, he_sm_ids FROM ddp_tissue t WHERE NOT (deleted <=> 1) AND onc_history_detail_id = ?"; + "tumor_percentage, tissue_sequence FROM ddp_tissue t WHERE NOT (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) " + @@ -124,13 +126,10 @@ 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; @@ -211,24 +210,14 @@ public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { } private void setSMIds() { - 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]; - } - + Map> map= TissueSmId.getSMIdsForTissueId(this.getTissueId()); + TissueSMIDDao tissueSMIDDao = new TissueSMIDDao(); + String typeId = tissueSMIDDao.getTypeForName(TissueSmId.HE); + this.heSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); + typeId = tissueSMIDDao.getTypeForName(TissueSmId.USS); + this.ussSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); + typeId = tissueSMIDDao.getTypeForName(TissueSmId.SCROLLS); + this.scrollSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); } public static List getTissue(@NonNull Connection conn, @NonNull String oncHistoryDetailId) { diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java index 5bae329bc..ccf5a770b 100644 --- a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -7,6 +7,7 @@ import org.broadinstitute.dsm.statics.DBConstants; import java.util.List; +import java.util.Map; @Data @TableName ( @@ -44,10 +45,10 @@ public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissu } - public static TissueSmId[] getSMIdsForTissueId(String tissueId, String type) { + public static Map> getSMIdsForTissueId(String tissueId) { TissueSMIDDao tissueSMIDDao = new TissueSMIDDao(); - List list = tissueSMIDDao.getSMIdsForTissueId(tissueId, type); - return list.toArray(new TissueSmId[list.size()]); + Map> map = tissueSMIDDao.getSMIdsForTissueId(tissueId); + return map; } public String createNewSmId(String tissueId, String userId, String smIdType){ diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java index e45b00bdb..73a90da3a 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java @@ -10,28 +10,24 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; 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_GET_SM_ID_BASED_ON_TISSUE_ID=" SELECT * from sm_id sm where sm.tissue_id= ? and NOT sm.deleted <=> 1"; public static final String SQL_GET_SM_ID_BASED_ON_SM_ID_VALUE=" SELECT * from sm_id where sm_id_value= ? "; 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 getSMIdsForTissueId(String tissueId, String type) { - String typeId = getTypeForName(type); - List list = new ArrayList(); + public Map> getSMIdsForTissueId(String tissueId) { + Map> map = new HashMap<>(); 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( @@ -40,7 +36,9 @@ public List getSMIdsForTissueId(String tissueId, String type) { rs.getString(DBConstants.SM_ID_VALUE), rs.getString(DBConstants.TISSUE_ID) ); + List list = map.getOrDefault(tissueSmId.getSmIdType(), new ArrayList<>()); list.add(tissueSmId); + map.put(tissueSmId.getSmIdType(), list); } } } @@ -51,15 +49,15 @@ public List getSMIdsForTissueId(String tissueId, String type) { }); if (results.resultException != null) { - throw new RuntimeException("Error getting sm ids for tissue w/ id " + tissueId +" for type "+type, results.resultException); + throw new RuntimeException("Error getting sm ids for tissue w/ id " + tissueId , results.resultException); } - return list; + return map; } - private static String getTypeForName(String type) { + public String getTypeForName(String type) { SimpleResult results = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); try (PreparedStatement stmt = conn.prepareStatement(SQL_TYPE_ID_FOR_TYPE)) { diff --git a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java index 1be924d71..593edefd0 100644 --- a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java @@ -28,7 +28,7 @@ public class CreateClinicalDummyKitRoute implements Route { private final String FFPE_USER = "ffpe-dummy-kit-creator"; private final String FFPE = "ffpe"; private final String FFPE_SCROLL = "ffpe-scroll"; - private final String FFPE_SSECTION = "ffpe-section"; + private final String FFPE_SECTION = "ffpe-section"; @Override public Object handle(Request request, Response response) { @@ -73,7 +73,7 @@ public Object handle(Request request, Response response) { String smIdType; if(kitTypeString.equalsIgnoreCase(FFPE_SCROLL)){ smIdType = TissueSmId.SCROLLS; - }else if(kitTypeString.equalsIgnoreCase(FFPE_SSECTION)){ + }else if(kitTypeString.equalsIgnoreCase(FFPE_SECTION)){ smIdType = TissueSmId.USS; }else{ throw new RuntimeException("The FFPE kit type does not match any of the valid types "+kitTypeString); From de271e5dc64863c00ff6dc502c478ca24db960cd Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 23 Nov 2021 16:22:11 -0500 Subject: [PATCH 10/20] debugging --- .../broadinstitute/dsm/db/MedicalRecord.java | 17 ++++--- .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 45 +++++++++++++++++++ .../dsm/db/dao/kit/BSPDummyKitDao.java | 6 +-- .../dsm/db/dao/kit/ClinicalKitDao.java | 17 +++---- .../dsm/db/dto/kit/ClinicalKitDto.java | 13 +++--- .../dsm/route/ClinicalKitsRoute.java | 16 +++---- .../route/CreateClinicalDummyKitRoute.java | 29 +++++++----- .../dsm/statics/DBConstants.java | 2 +- 8 files changed, 101 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java b/src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java index a2a291187..77029f90a 100644 --- a/src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java +++ b/src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java @@ -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; diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java index 73a90da3a..73d91ff4e 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java @@ -21,6 +21,7 @@ public class TissueSMIDDao { public static final String SQL_GET_SM_ID_BASED_ON_SM_ID_VALUE=" SELECT * from sm_id where sm_id_value= ? "; 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 static final String SQL_INSERT_SM_ID_WITH_VALUE = "INSERT INTO sm_id SET tissue_id = ?, sm_id_type_id = ?, last_changed = ?, changed_by = ?, sm_id_value = ?"; public Map> getSMIdsForTissueId(String tissueId) { Map> map = new HashMap<>(); @@ -81,6 +82,48 @@ public String getTypeForName(String type) { return (String) results.resultValue; } + public String createNewSMIDForTissueWithValue(String tissueId, String userId, String smIdType, String smIdValue) { + String smIdtypeId = getTypeForName(smIdType); + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement stmt = conn.prepareStatement(SQL_INSERT_SM_ID_WITH_VALUE, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, tissueId); + stmt.setString(2, smIdtypeId); + stmt.setLong(3, System.currentTimeMillis()); + stmt.setString(4, userId); + stmt.setString(5, smIdValue); + 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; + } + } + public String createNewSMIDForTissue(String tissueId, String userId, String smIdType) { String smIdtypeId = getTypeForName(smIdType); SimpleResult results = inTransaction((conn) -> { @@ -112,6 +155,8 @@ public String createNewSMIDForTissue(String tissueId, String userId, String smId return dbVals; }); + + if (results.resultException != null) { throw new RuntimeException("Error adding new sm id for tissue w/ id " + tissueId, results.resultException); } diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java index 33ee1b651..b1869d7ee 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java @@ -86,14 +86,14 @@ public Optional getRandomParticipantIdForStudy(String ddpInstanceId) { return Optional.ofNullable((String) results.resultValue); } - public Optional getRandomOncHistoryForStudy(String ddpInstanceName) { + public 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)); + dbVals.resultValue = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); }else{ } @@ -106,7 +106,7 @@ public Optional getRandomOncHistoryForStudy(String ddpInstanceName) { if (results.resultException != null) { throw new RuntimeException("Problem getting a random participant id for instance " + ddpInstanceName, results.resultException); } - return (Optional) results.resultValue; + return (String)results.resultValue; } @Override diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java index 15094d6e6..d4e176e80 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java @@ -3,6 +3,8 @@ import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.dsm.db.dto.kit.ClinicalKitDto; import org.broadinstitute.dsm.statics.DBConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -12,15 +14,16 @@ import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; public class ClinicalKitDao { - private final static String SQL_GET_CLINICAL_KIT_BASED_ON_SM_ID_VALUE = "SELECT p.ddp_participant_id, oD.accession_number, ddp.instance_name, bsp_organism, bsp_collection," + - " kit_type_name, bsp_material_type, bsp_receptable_type, accession_number, " + + private static final Logger logger = LoggerFactory.getLogger(ClinicalKitDao.class); + private final static String SQL_GET_CLINICAL_KIT_BASED_ON_SM_ID_VALUE = "SELECT p.ddp_participant_id, accession_number, ddp.instance_name, bsp_organism, bsp_collection," + + " kit_type_name, bsp_material_type, bsp_receptacle_type, ddp.ddp_instance_id " + "from sm_id sm " + "left join ddp_tissue t on (t.tissue_id = sm.tissue_id) " + "left join ddp_onc_history_detail oD on (oD.onc_history_detail_id = t.onc_history_detail_id) " + "left join ddp_medical_record mr on (mr.medical_record_id = oD.medical_record_id) " + "left join ddp_institution inst on (mr.institution_id = inst.institution_id AND NOT mr.deleted <=> 1) " + - "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) " + + "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) " + "left join sm_id_type sit on (sit.sm_id_type_id = sm.sm_id_type_id) " + "left join kit_type ktype on ( sit.kit_type_id = ktype.kit_type_id) " + "where sm.sm_id_value = ? "; @@ -54,7 +57,7 @@ public Optional getClinicalKitFromSMId(String smIdValue){ } } catch (Exception e) { - throw new RuntimeException("Error getting id of new sm id ", e); + throw new RuntimeException("Error getting clinical kit", e); } } catch (SQLException ex) { @@ -67,8 +70,6 @@ public Optional getClinicalKitFromSMId(String smIdValue){ if (results.resultException != null) { throw new RuntimeException("Error getting clinicalKit based on smId " + smIdValue, results.resultException); } - else { - return Optional.ofNullable((ClinicalKitDto) results.resultValue); - } + return Optional.ofNullable((ClinicalKitDto) results.resultValue); } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java index 8ba16c91b..aa2034f61 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java +++ b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java @@ -10,6 +10,8 @@ import org.broadinstitute.dsm.model.ddp.DDPActivityConstants; import org.broadinstitute.dsm.model.elasticsearch.*; import org.broadinstitute.dsm.util.ElasticSearchUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; @@ -55,10 +57,8 @@ public class ClinicalKitDto { String ddpParticipantId; Integer ddpInstanceId; - private final String FFPE_SECTION_KIT_TYPE = "FFPE-SECTION"; - private final String FFPE_SCROLLS_KIT_TYPE = "FFPE-SCROLL"; - private final String USS = "uss"; - private final String SCROLLS = "scrolls"; + + private static final Logger logger = LoggerFactory.getLogger(ClinicalKitDto.class); public ClinicalKitDto(String collaboratorParticipantId, String sampleId, String sampleCollection, String materialType, String vesselType, String firstName, String lastName, String dateOfBirth, String sampleType, String gender, String accessionNumber, String mfBarcode) { @@ -109,14 +109,15 @@ public void setGender(String genderString) { - public Optional getClinicalKitBasedONSmId(String smIdValue) { + public ClinicalKitDto getClinicalKitBasedONSmId(String smIdValue) { + logger.info("Checking the kit for SM Id value"); ClinicalKitDao clinicalKitDao = new ClinicalKitDao(); Optional maybeClinicalKit = clinicalKitDao.getClinicalKitFromSMId(smIdValue); maybeClinicalKit.orElseThrow(); ClinicalKitDto clinicalKitDto = maybeClinicalKit.get(); DDPInstance ddpInstance = DDPInstance.getDDPInstanceById(clinicalKitDto.ddpInstanceId); clinicalKitDto.setNecessaryParticipantDataToClinicalKit(clinicalKitDto.ddpParticipantId, ddpInstance); - return Optional.ofNullable(clinicalKitDto); + return clinicalKitDto; } public void setNecessaryParticipantDataToClinicalKit(String ddpParticipantId, DDPInstance ddpInstance) { diff --git a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java index e44d44ed7..5c90f9018 100644 --- a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java @@ -41,11 +41,10 @@ public Object handle(Request request, Response response) { BSPKit bspKit = new BSPKit(); if (!bspKit.canReceiveKit(kitLabel)) { Optional result = bspKit.getKitStatus(kitLabel, notificationUtil); - if(result.isEmpty()){ - response.status(404); - return null; + if(!result.isEmpty()){ + return result.get(); } - return result.get(); + } return getClinicalKit(kitLabel); } @@ -57,7 +56,7 @@ private ClinicalKitDto getClinicalKit(String kitLabel) { BSPKit bspKit = new BSPKit(); ClinicalKitDto clinicalKit = new ClinicalKitDto(); Optional maybeKitInfo = bspKit.receiveBSPKit(kitLabel, notificationUtil); - maybeKitInfo.ifPresentOrElse(kitInfo -> { + maybeKitInfo.ifPresent(kitInfo -> { logger.info("Creating clinical kit to return to GP " + kitLabel); clinicalKit.setCollaboratorParticipantId(kitInfo.getCollaboratorParticipantId()); clinicalKit.setSampleId(kitInfo.getCollaboratorSampleId()); @@ -71,9 +70,10 @@ private ClinicalKitDto getClinicalKit(String kitLabel) { BSPKitDto maybeBspKitQueryResult = bspKitQueryResult.get(); DDPInstance ddpInstance = DDPInstance.getDDPInstance(maybeBspKitQueryResult.getInstanceName()); clinicalKit.setNecessaryParticipantDataToClinicalKit( maybeBspKitQueryResult.getDdpParticipantId(), ddpInstance); - }, - () -> {clinicalKit.getClinicalKitBasedONSmId(kitLabel);}); - + }); + if(maybeKitInfo.isEmpty()){ + return clinicalKit.getClinicalKitBasedONSmId(kitLabel); + } return clinicalKit; } diff --git a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java index 593edefd0..72affb7f5 100644 --- a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java @@ -78,19 +78,24 @@ public Object handle(Request request, Response response) { }else{ throw new RuntimeException("The FFPE kit type does not match any of the valid types "+kitTypeString); } - Optional randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); - randomOncHistoryDetailId.ifPresentOrElse(oid -> { - List tissueIds = OncHistoryDetail.getOncHistoryDetail(oid, ddpInstance.getName()).getTissues(); - String tissueId; + String randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); + OncHistoryDetail oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); + logger.info("found randomOncHistoryDetailId "+ randomOncHistoryDetailId); + while(oncHistoryDetail == null){ + randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); + oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); + logger.info("found randomOncHistoryDetailId "+ randomOncHistoryDetailId); - if (tissueIds.isEmpty()){ - tissueId = Tissue.createNewTissue(oid, FFPE_USER); - }else{ - tissueId = tissueIds.get( new Random().nextInt(tissueIds.size())).getTissueId(); - } - new TissueSMIDDao().createNewSMIDForTissue(tissueId, FFPE_USER, smIdType); - }, - ()-> {throw new RuntimeException("no onc history for study " + ddpInstance.getName() + " was found!");}); + } + List tissueIds = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()).getTissues(); + String tissueId; + + if (tissueIds.isEmpty()){ + tissueId = Tissue.createNewTissue(randomOncHistoryDetailId, FFPE_USER); + }else{ + tissueId = tissueIds.get( new Random().nextInt(tissueIds.size())).getTissueId(); + } + new TissueSMIDDao().createNewSMIDForTissueWithValue(tissueId, FFPE_USER, smIdType, kitLabel); } logger.info("Kit added successfully"); response.status(200); diff --git a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java index 31e39cb61..6bd2208a8 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java +++ b/src/main/java/org/broadinstitute/dsm/statics/DBConstants.java @@ -64,7 +64,7 @@ public class DBConstants { public static final String SAMPLE_TYPE = "sample_type"; public static final String DDP_KIT_REQUEST_TABLE_ABBR = "req."; public static final String BSP_MATERIAL_TYPE = "bsp_material_type"; - public static final String BSP_RECEPTABLE_TYPE = "bsp_receptable_type"; + public static final String BSP_RECEPTABLE_TYPE = "bsp_receptacle_type"; From b00cf84d4a57c3a4d6964aeaf629d1b09ead07b2 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 23 Nov 2021 17:09:55 -0500 Subject: [PATCH 11/20] fixed the part where a sm id is assigned to invalid participant --- .../dsm/db/OncHistoryDetail.java | 8 +++-- .../route/CreateClinicalDummyKitRoute.java | 31 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index eb71581e9..633ab17af 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -42,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, p.ddp_participant_id " + "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) " + @@ -281,7 +281,11 @@ public static OncHistoryDetail getOncHistoryDetail(@NonNull ResultSet rs) throws rs.getString(DBConstants.DESTRUCTION_POLICY), rs.getBoolean(DBConstants.UNABLE_OBTAIN_TISSUE) ); - + try { + oncHistoryDetail.setParticipantId(rs.getString(DBConstants.DDP_PARTICIPANT_ID)); + }catch (java.sql.SQLException e) { + oncHistoryDetail.setParticipantId(null); + } return oncHistoryDetail; } diff --git a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java index 72affb7f5..1566a26b7 100644 --- a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java @@ -69,31 +69,38 @@ public Object handle(Request request, Response response) { }, () -> { throw new RuntimeException(" Participant " + ddpParticipantId + " was not found!"); }); - }else{ + } + else { String smIdType; - if(kitTypeString.equalsIgnoreCase(FFPE_SCROLL)){ + if (kitTypeString.equalsIgnoreCase(FFPE_SCROLL)) { smIdType = TissueSmId.SCROLLS; - }else if(kitTypeString.equalsIgnoreCase(FFPE_SECTION)){ + } + else if (kitTypeString.equalsIgnoreCase(FFPE_SECTION)) { smIdType = TissueSmId.USS; - }else{ - throw new RuntimeException("The FFPE kit type does not match any of the valid types "+kitTypeString); + } + else { + throw new RuntimeException("The FFPE kit type does not match any of the valid types " + kitTypeString); } String randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); OncHistoryDetail oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); - logger.info("found randomOncHistoryDetailId "+ randomOncHistoryDetailId); - while(oncHistoryDetail == null){ + String ddpParticipantId = oncHistoryDetail.getParticipantId(); + Optional maybeParticipant = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); + logger.info("found randomOncHistoryDetailId " + randomOncHistoryDetailId); + while (oncHistoryDetail == null || maybeParticipant.isEmpty() || maybeParticipant.get().getProfile().map(ESProfile::getHruid).isEmpty()) { randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); - logger.info("found randomOncHistoryDetailId "+ randomOncHistoryDetailId); - + ddpParticipantId = oncHistoryDetail.getParticipantId(); + logger.info("found randomOncHistoryDetailId " + randomOncHistoryDetailId); + maybeParticipant = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); } List tissueIds = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()).getTissues(); String tissueId; - if (tissueIds.isEmpty()){ + if (tissueIds.isEmpty()) { tissueId = Tissue.createNewTissue(randomOncHistoryDetailId, FFPE_USER); - }else{ - tissueId = tissueIds.get( new Random().nextInt(tissueIds.size())).getTissueId(); + } + else { + tissueId = tissueIds.get(new Random().nextInt(tissueIds.size())).getTissueId(); } new TissueSMIDDao().createNewSMIDForTissueWithValue(tissueId, FFPE_USER, smIdType, kitLabel); } From 48197f7bd49b0998f753360a2c1f58c1427d7378 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Wed, 24 Nov 2021 00:16:23 -0500 Subject: [PATCH 12/20] added `ClinicalKitWrapper` to make json for PE-CGS --- .../dsm/db/dao/kit/ClinicalKitDao.java | 12 +++++++----- .../dsm/db/dto/kit/ClinicalKitDto.java | 15 +++++++-------- .../dsm/model/ClinicalKitWrapper.java | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/broadinstitute/dsm/model/ClinicalKitWrapper.java diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java index d4e176e80..acfcf5587 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java @@ -2,6 +2,7 @@ import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.dsm.db.dto.kit.ClinicalKitDto; +import org.broadinstitute.dsm.model.ClinicalKitWrapper; import org.broadinstitute.dsm.statics.DBConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +29,7 @@ public class ClinicalKitDao { "left join kit_type ktype on ( sit.kit_type_id = ktype.kit_type_id) " + "where sm.sm_id_value = ? "; - public Optional getClinicalKitFromSMId(String smIdValue){ + public Optional getClinicalKitFromSMId(String smIdValue){ SimpleResult results = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); try (PreparedStatement stmt = conn.prepareStatement(SQL_GET_CLINICAL_KIT_BASED_ON_SM_ID_VALUE)) { @@ -50,9 +51,10 @@ public Optional getClinicalKitFromSMId(String smIdValue){ null ); clinicalKitDto.setSampleType(rs.getString(DBConstants.KIT_TYPE_NAME)); - clinicalKitDto.setDdpInstanceId(Integer.parseInt(rs.getString(DBConstants.DDP_INSTANCE_ID))); - clinicalKitDto.setDdpParticipantId(rs.getString(DBConstants.DDP_PARTICIPANT_ID)); - dbVals.resultValue = clinicalKitDto; + ClinicalKitWrapper clinicalKitWrapper = new ClinicalKitWrapper(clinicalKitDto, + Integer.parseInt(rs.getString(DBConstants.DDP_INSTANCE_ID)), + rs.getString(DBConstants.DDP_PARTICIPANT_ID)); + dbVals.resultValue = clinicalKitWrapper; } } @@ -70,6 +72,6 @@ public Optional getClinicalKitFromSMId(String smIdValue){ if (results.resultException != null) { throw new RuntimeException("Error getting clinicalKit based on smId " + smIdValue, results.resultException); } - return Optional.ofNullable((ClinicalKitDto) results.resultValue); + return Optional.ofNullable((ClinicalKitWrapper) results.resultValue); } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java index aa2034f61..e3af8b6db 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java +++ b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java @@ -7,6 +7,7 @@ import org.broadinstitute.dsm.db.KitRequestShipping; import org.broadinstitute.dsm.db.OncHistoryDetail; import org.broadinstitute.dsm.db.dao.kit.ClinicalKitDao; +import org.broadinstitute.dsm.model.ClinicalKitWrapper; import org.broadinstitute.dsm.model.ddp.DDPActivityConstants; import org.broadinstitute.dsm.model.elasticsearch.*; import org.broadinstitute.dsm.util.ElasticSearchUtil; @@ -54,9 +55,6 @@ public class ClinicalKitDto { @SerializedName ("kit_label") String mfBarcode; - String ddpParticipantId; - Integer ddpInstanceId; - private static final Logger logger = LoggerFactory.getLogger(ClinicalKitDto.class); @@ -112,11 +110,12 @@ public void setGender(String genderString) { public ClinicalKitDto getClinicalKitBasedONSmId(String smIdValue) { logger.info("Checking the kit for SM Id value"); ClinicalKitDao clinicalKitDao = new ClinicalKitDao(); - Optional maybeClinicalKit = clinicalKitDao.getClinicalKitFromSMId(smIdValue); - maybeClinicalKit.orElseThrow(); - ClinicalKitDto clinicalKitDto = maybeClinicalKit.get(); - DDPInstance ddpInstance = DDPInstance.getDDPInstanceById(clinicalKitDto.ddpInstanceId); - clinicalKitDto.setNecessaryParticipantDataToClinicalKit(clinicalKitDto.ddpParticipantId, ddpInstance); + Optional maybeClinicalKitWrapper = clinicalKitDao.getClinicalKitFromSMId(smIdValue); + maybeClinicalKitWrapper.orElseThrow(); + ClinicalKitWrapper clinicalKitWrapper = maybeClinicalKitWrapper.get(); + ClinicalKitDto clinicalKitDto = clinicalKitWrapper.getClinicalKitDto(); + DDPInstance ddpInstance = DDPInstance.getDDPInstanceById(clinicalKitWrapper.getDdpInstanceId()); + clinicalKitDto.setNecessaryParticipantDataToClinicalKit(clinicalKitWrapper.getDdpParticipantId(), ddpInstance); return clinicalKitDto; } diff --git a/src/main/java/org/broadinstitute/dsm/model/ClinicalKitWrapper.java b/src/main/java/org/broadinstitute/dsm/model/ClinicalKitWrapper.java new file mode 100644 index 000000000..48fcdd9e7 --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/model/ClinicalKitWrapper.java @@ -0,0 +1,16 @@ +package org.broadinstitute.dsm.model; + +import lombok.Data; +import org.broadinstitute.dsm.db.dto.kit.ClinicalKitDto; +@Data +public class ClinicalKitWrapper { + ClinicalKitDto clinicalKitDto; + String ddpParticipantId; + Integer ddpInstanceId; + + public ClinicalKitWrapper(ClinicalKitDto clinicalKitDto, int ddpInstanceId, String ddpParticipantId) { + this.clinicalKitDto = clinicalKitDto; + this.ddpInstanceId = ddpInstanceId; + this.ddpParticipantId = ddpParticipantId; + } +} From 19c470b7849c9c940b66af11ec4f41ec79163716 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Mon, 29 Nov 2021 10:22:52 -0500 Subject: [PATCH 13/20] changes for filtering --- .../dsm/db/OncHistoryDetail.java | 6 +- .../org/broadinstitute/dsm/db/Tissue.java | 10 ++- .../org/broadinstitute/dsm/db/TissueSmId.java | 46 +++++++++--- .../org/broadinstitute/dsm/db/ViewFilter.java | 33 +++++++-- .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 73 ------------------- .../dsm/db/dao/ddp/tissue/TissueSmIdType.java | 45 ++++++++++++ .../dsm/db/structure/DBElement.java | 5 +- .../broadinstitute/dsm/model/TissueList.java | 6 +- .../BaseFilterParticipantList.java | 17 ++--- .../SavedFilterParticipantList.java | 5 -- .../dsm/statics/DBConstants.java | 3 + .../broadinstitute/dsm/util/PatchUtil.java | 2 + 12 files changed, 137 insertions(+), 114 deletions(-) create mode 100644 src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 633ab17af..e5ebe4b74 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -40,15 +40,17 @@ public class OncHistoryDetail { "oD.location_px, oD.histology, oD.accession_number, oD.facility, oD.phone, oD.fax, oD.notes, oD.additional_values_json, " + "oD.request, oD.fax_sent, oD.fax_sent_by, oD.fax_confirmed, oD.fax_sent_2, oD.fax_sent_2_by, oD.fax_confirmed_2, oD.fax_sent_3, " + "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, " + + "t.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, p.ddp_participant_id " + + " scrolls_count, uss_count, h_e_count, blocks_count, p.ddp_participant_id, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted, sm.tissue_id " + "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) " + "LEFT JOIN ddp_participant p on (p.participant_id = inst.participant_id) " + "LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + "LEFT JOIN ddp_tissue t on (oD.onc_history_detail_id = t.onc_history_detail_id AND NOT t.deleted <=> 1) " + + "LEFT JOIN sm_id sm on (sm.tissue_id = t.tissue_id AND NOT sm.deleted <=> 1 ) " + + "LEFT JOIN sm_id_type smt on (smt.sm_id_type_id = sm.sm_id_type_id ) " + "WHERE realm.instance_name = ? "; private static final String SQL_CREATE_ONC_HISTORY = "INSERT INTO ddp_onc_history_detail SET medical_record_id = ?, request = ?, last_changed = ?, changed_by = ?"; private static final String SQL_SELECT_ONC_HISTORY = "SELECT onc_history_detail_id, medical_record_id, date_px, type_px, location_px, histology, accession_number, facility," + diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index 74b398fed..98adfcf5d 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -33,7 +33,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 (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) " + @@ -205,12 +207,12 @@ public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { null, null, null); - tissue.setSMIds(); + tissue.setSMIds(rs); return tissue; } - private void setSMIds() { - Map> map= TissueSmId.getSMIdsForTissueId(this.getTissueId()); + private void setSMIds(ResultSet rs) { + Map> map= TissueSmId.getSMIdsForTissueId(rs); TissueSMIDDao tissueSMIDDao = new TissueSMIDDao(); String typeId = tissueSMIDDao.getTypeForName(TissueSmId.HE); this.heSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java index ccf5a770b..175e376ff 100644 --- a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -5,7 +5,13 @@ import org.broadinstitute.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.TableName; 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.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,27 +23,29 @@ columnPrefix = "") public class TissueSmId { - @ColumnName(DBConstants.SM_ID_VALUE) + @ColumnName (DBConstants.SM_ID_VALUE) private String smIdValue; - @ColumnName(DBConstants.SM_ID_TYPE_ID) + @ColumnName (DBConstants.SM_ID_TYPE_ID) private String smIdType; - @ColumnName(DBConstants.SM_ID_TISSUE_ID) + @ColumnName (DBConstants.SM_ID_TISSUE_ID) private String tissueId; - @ColumnName(DBConstants.SM_ID_PK) + @ColumnName (DBConstants.SM_ID_PK) private String smIdPk; - @ColumnName(DBConstants.DELETED) + @ColumnName (DBConstants.DELETED) private boolean deleted; public static String HE = "he"; public static String USS = "uss"; public static String SCROLLS = "scrolls"; - public TissueSmId(){} + private static final Logger logger = LoggerFactory.getLogger(TissueSmId.class); + public TissueSmId() { + } - public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissueId){ + public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissueId) { this.smIdPk = smIdPk; this.smIdType = smIdType; this.smIdValue = smIdValue; @@ -45,13 +53,29 @@ public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissu } - public static Map> getSMIdsForTissueId(String tissueId) { - TissueSMIDDao tissueSMIDDao = new TissueSMIDDao(); - Map> map = tissueSMIDDao.getSMIdsForTissueId(tissueId); + public static Map> getSMIdsForTissueId(ResultSet rs) { + Map> map = new HashMap<>(); + TissueSmId tissueSmId = null; + try { + 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) + ); + } + catch (SQLException e) { + logger.error("problem getting tissue sm ids", e); + } + + List list = map.getOrDefault(tissueSmId.getSmIdType(), new ArrayList<>()); + list.add(tissueSmId); + map.put(tissueSmId.getSmIdType(), list); + return map; } - public String createNewSmId(String tissueId, String userId, String smIdType){ + public String createNewSmId(String tissueId, String userId, String smIdType) { String smIdId = new TissueSMIDDao().createNewSMIDForTissue(tissueId, userId, smIdType); return smIdId; } diff --git a/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java b/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java index 2853b76d3..5c48eeb54 100644 --- a/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java +++ b/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.ddp.handlers.util.Result; +import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSmIdType; import org.broadinstitute.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DBElement; import org.broadinstitute.dsm.db.structure.TableName; @@ -258,6 +259,9 @@ public static void addQueryCondition(@NonNull Map queryCondition queryCondition = queryConditions.get(tmp); } queryConditions.put(tmp, queryCondition.concat(Filter.getQueryStringForFiltering(filter, dbElement))); + if (dbElement.tableAlias.equals(DBConstants.SM_ID_ALIAS) && filter.getFilter2() != null) { + new TissueSmIdType().createFilterForType(queryConditions, (String) filter.getFilter2().getValue(), tmp); + } } else { String queryCondition = ""; @@ -471,6 +475,8 @@ public static String getFilterQuery(@NonNull String filterName, @NonNull String public static ViewFilter parseFilteringQuery(String str, ViewFilter viewFilter) { String[] conditions = str.split("(and\\s)|(AND\\s)"); Map filters = new HashMap<>(conditions.length); + Filter lastSmIdFilter = null; + boolean isSmIDTypeFilter = false; for (String condition : conditions) { if (StringUtils.isBlank(condition)) { continue; @@ -492,6 +498,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)) { @@ -519,6 +526,9 @@ else if (word.equals(Filter.JSON_CONTAINS)) {// type is JSONARRAY else {// beginning of other types of query tableName = word.substring(0, word.indexOf(Filter.DB_NAME_DELIMITER)); columnName = word.substring(word.indexOf(Filter.DB_NAME_DELIMITER) + 1); + if (DBConstants.SM_ID_TYPE_TABLE_ALIAS.equals(tableName)) { + isSmIDTypeFilter = true; + } state = 1; } break; @@ -581,8 +591,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; @@ -591,7 +602,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; @@ -633,7 +645,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; @@ -903,6 +916,12 @@ else if (word.equals(Filter.MINUS_SIGN)) { if (state != 7 && state != 9 && state != 10 && state != 11 && state != 13 && state != 22 && state != 25 && state != 37 && state != 40) {// terminal states throw new RuntimeException("Query parsing ended in bad state: " + state); } + if (isSmIDTypeFilter && lastSmIdFilter != null) { + lastSmIdFilter.setFilter2(new NameValue(null, value)); + lastSmIdFilter = null; + isSmIDTypeFilter = false; + continue; + } String columnKey = columnName; if (StringUtils.isNotBlank(tableName)) { columnKey = tableName.concat(DBConstants.ALIAS_DELIMITER).concat(columnName); @@ -965,7 +984,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)); } } @@ -1001,6 +1021,9 @@ else if (filter2 != null || f2) { filter.setFilter2(filter2); } } + if (DBConstants.SM_ID_ALIAS.equals(tableName)) { + lastSmIdFilter = filter; + } filters.put(columnName, filter); } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java index 73d91ff4e..4e3080e7b 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java @@ -1,7 +1,6 @@ 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; @@ -10,7 +9,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.*; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -18,46 +16,10 @@ 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 sm where sm.tissue_id= ? and NOT sm.deleted <=> 1"; - public static final String SQL_GET_SM_ID_BASED_ON_SM_ID_VALUE=" SELECT * from sm_id where sm_id_value= ? "; 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 static final String SQL_INSERT_SM_ID_WITH_VALUE = "INSERT INTO sm_id SET tissue_id = ?, sm_id_type_id = ?, last_changed = ?, changed_by = ?, sm_id_value = ?"; - public Map> getSMIdsForTissueId(String tissueId) { - Map> map = new HashMap<>(); - 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); - 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 list = map.getOrDefault(tissueSmId.getSmIdType(), new ArrayList<>()); - list.add(tissueSmId); - map.put(tissueSmId.getSmIdType(), list); - } - } - } - catch (SQLException ex) { - dbVals.resultException = ex; - } - return dbVals; - }); - - if (results.resultException != null) { - throw new RuntimeException("Error getting sm ids for tissue w/ id " + tissueId , results.resultException); - } - - return map; - } - - - public String getTypeForName(String type) { SimpleResult results = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); @@ -155,8 +117,6 @@ public String createNewSMIDForTissue(String tissueId, String userId, String smId return dbVals; }); - - if (results.resultException != null) { throw new RuntimeException("Error adding new sm id for tissue w/ id " + tissueId, results.resultException); } @@ -164,37 +124,4 @@ public String createNewSMIDForTissue(String tissueId, String userId, String smId return (String) results.resultValue; } } - - public Optional getTissueSMId(String smId) { - SimpleResult results = inTransaction((conn) -> { - SimpleResult dbVals = new SimpleResult(); - try (PreparedStatement stmt = conn.prepareStatement(SQL_GET_SM_ID_BASED_ON_SM_ID_VALUE)) { - stmt.setString(1, smId); - stmt.executeQuery(); - try (ResultSet rs = stmt.getGeneratedKeys()) { - if (rs.next()) { - dbVals.resultValue = new TissueSmId( - rs.getString(DBConstants.SM_ID_PK), - rs.getString(DBConstants.SM_ID_TYPE), - rs.getString(DBConstants.SM_ID_VALUE), - rs.getString(DBConstants.TISSUE_ID)); - } - } - catch (Exception e) { - throw new RuntimeException("Error getting id of new sm id ", e); - } - } - catch (SQLException ex) { - dbVals.resultException = ex; - } - return dbVals; - }); - - if (results.resultException != null) { - throw new RuntimeException("Error getting tissueSmId based on smId " + smId, results.resultException); - } - else { - return Optional.ofNullable((TissueSmId)results.resultValue); - } - } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java new file mode 100644 index 000000000..45aa32978 --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java @@ -0,0 +1,45 @@ +package org.broadinstitute.dsm.db.dao.ddp.tissue; + +import lombok.Data; +import org.apache.commons.lang3.StringUtils; +import org.broadinstitute.dsm.db.structure.ColumnName; +import org.broadinstitute.dsm.db.structure.DBElement; +import org.broadinstitute.dsm.db.structure.TableName; +import org.broadinstitute.dsm.model.Filter; +import org.broadinstitute.dsm.model.NameValue; +import org.broadinstitute.dsm.statics.DBConstants; + +import java.lang.annotation.Annotation; +import java.util.Map; + +@Data +@TableName ( + name = DBConstants.SM_ID_TYPE_TABLE, + alias = DBConstants.SM_ID_TYPE_TABLE_ALIAS, + primaryKey = DBConstants.SM_ID_TYPE_ID, + columnPrefix = "") +public class TissueSmIdType { + + @ColumnName (DBConstants.SM_ID_TYPE_ID) + private String smIdTypeId; + + @ColumnName (DBConstants.SM_ID_TYPE) + private String smIdType; + + public void createFilterForType(Map queryConditions, String type, String tmp) { + if (StringUtils.isBlank(type)) { + return; + } + Annotation annotation = TissueSmIdType.class.getAnnotation(TableName.class); + TableName tableNameAnnotation = (TableName) annotation; + String tableName = tableNameAnnotation.name(); + String tableAlias = tableNameAnnotation.alias(); + String primaryKey = tableNameAnnotation.primaryKey(); + DBElement dbElementForType = new DBElement(tableName, tableAlias, primaryKey, DBConstants.SM_ID_TYPE); + Filter filterForType = new Filter(); + filterForType.setType(Filter.TEXT); + filterForType.setExactMatch(true); + filterForType.setFilter1(new NameValue("smIdType", type)); + queryConditions.put(tmp, queryConditions.get(tmp).concat(Filter.getQueryStringForFiltering(filterForType, dbElementForType))); + } +} diff --git a/src/main/java/org/broadinstitute/dsm/db/structure/DBElement.java b/src/main/java/org/broadinstitute/dsm/db/structure/DBElement.java index 058f79941..98858f3f3 100644 --- a/src/main/java/org/broadinstitute/dsm/db/structure/DBElement.java +++ b/src/main/java/org/broadinstitute/dsm/db/structure/DBElement.java @@ -1,12 +1,11 @@ package org.broadinstitute.dsm.db.structure; -import java.text.SimpleDateFormat; +import lombok.Data; + import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import lombok.Data; - @Data public class DBElement { diff --git a/src/main/java/org/broadinstitute/dsm/model/TissueList.java b/src/main/java/org/broadinstitute/dsm/model/TissueList.java index 2e9c676ef..5442e99c9 100644 --- a/src/main/java/org/broadinstitute/dsm/model/TissueList.java +++ b/src/main/java/org/broadinstitute/dsm/model/TissueList.java @@ -26,12 +26,14 @@ public class TissueList { "oD.fax_sent_3_by, oD.fax_confirmed_3, oD.tissue_received, oD.tissue_problem_option, oD.additional_values_json, oD.gender, oD.destruction_policy, oD.unable_obtain_tissue," + "tissue_id, t.notes, t.count_received, t.tissue_type, t.tissue_site, t.tumor_type, t.h_e, t.pathology_report, t.collaborator_sample_id, t.block_sent, t.scrolls_received, t.sk_id, t.sm_id, " + "t.sent_gp, t.first_sm_id, t.additional_tissue_value_json, t.expected_return, t.return_date, t.return_fedex_id, t.shl_work_number, t.tumor_percentage, t.tissue_sequence, t.onc_history_detail_id, " + - "t.scrolls_count, t.h_e_count, t.uss_count, t.blocks_count " + + "t.scrolls_count, t.h_e_count, t.uss_count, t.blocks_count, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted " + "FROM ddp_participant p LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + "LEFT JOIN ddp_participant_exit ex on (p.ddp_participant_id = ex.ddp_participant_id AND p.ddp_instance_id = ex.ddp_instance_id) " + "LEFT JOIN ddp_institution inst on (p.participant_id = inst.participant_id) LEFT JOIN ddp_medical_record m on (m.institution_id = inst.institution_id AND NOT m.deleted <=> 1) " + "LEFT JOIN ddp_onc_history_detail oD on (m.medical_record_id = oD.medical_record_id AND NOT oD.deleted <=> 1) " + - "LEFT JOIN ddp_tissue t on (oD.onc_history_detail_id = t.onc_history_detail_id AND NOT t.deleted <=> 1) WHERE realm.instance_name = ? AND ex.ddp_participant_exit_id IS NULL AND oD.onc_history_detail_id IS NOT NULL"; + "LEFT JOIN ddp_tissue t on (oD.onc_history_detail_id = t.onc_history_detail_id AND NOT t.deleted <=> 1) " + + "LEFT JOIN sm_id sm on (sm.tissue_id = t.tissue_id AND NOT sm.deleted <=> 1 AND NOT t.deleted <=> 1) "+ + "WHERE realm.instance_name = ? AND ex.ddp_participant_exit_id IS NULL AND oD.onc_history_detail_id IS NOT NULL"; public static final String SQL_ORDER_BY_ONC_HISTORY = " ORDER BY oD.onc_history_detail_id "; private OncHistoryDetail oncHistoryDetails; diff --git a/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java b/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java index ba5c6110d..3d719e916 100644 --- a/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java +++ b/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java @@ -1,11 +1,5 @@ package org.broadinstitute.dsm.model.filter.participant; -import java.time.LocalDate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - import com.google.gson.Gson; import lombok.NonNull; import org.apache.commons.lang3.StringUtils; @@ -19,10 +13,9 @@ import org.broadinstitute.dsm.db.structure.DBElement; import org.broadinstitute.dsm.model.Filter; import org.broadinstitute.dsm.model.elasticsearch.ElasticSearch; -import org.broadinstitute.dsm.model.participant.ParticipantWrapper; import org.broadinstitute.dsm.model.filter.BaseFilter; import org.broadinstitute.dsm.model.filter.Filterable; -import org.broadinstitute.dsm.model.participant.ParticipantWrapperDto; +import org.broadinstitute.dsm.model.participant.ParticipantWrapper; import org.broadinstitute.dsm.model.participant.ParticipantWrapperPayload; import org.broadinstitute.dsm.model.participant.ParticipantWrapperResult; import org.broadinstitute.dsm.statics.DBConstants; @@ -31,6 +24,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + public abstract class BaseFilterParticipantList extends BaseFilter implements Filterable { private static final Logger logger = LoggerFactory.getLogger(BaseFilterParticipantList.class); @@ -110,7 +109,7 @@ protected ParticipantWrapperResult filterParticipantList(Filter[] filters, Map Date: Mon, 29 Nov 2021 14:54:32 -0500 Subject: [PATCH 14/20] added --- .../org/broadinstitute/dsm/db/ViewFilter.java | 19 --------------- .../dsm/db/dao/ddp/tissue/TissueSmIdType.java | 23 ------------------- 2 files changed, 42 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java b/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java index 5c48eeb54..9caf56443 100644 --- a/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java +++ b/src/main/java/org/broadinstitute/dsm/db/ViewFilter.java @@ -6,7 +6,6 @@ import org.apache.commons.lang3.StringUtils; import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.ddp.handlers.util.Result; -import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSmIdType; import org.broadinstitute.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DBElement; import org.broadinstitute.dsm.db.structure.TableName; @@ -259,9 +258,6 @@ public static void addQueryCondition(@NonNull Map queryCondition queryCondition = queryConditions.get(tmp); } queryConditions.put(tmp, queryCondition.concat(Filter.getQueryStringForFiltering(filter, dbElement))); - if (dbElement.tableAlias.equals(DBConstants.SM_ID_ALIAS) && filter.getFilter2() != null) { - new TissueSmIdType().createFilterForType(queryConditions, (String) filter.getFilter2().getValue(), tmp); - } } else { String queryCondition = ""; @@ -475,8 +471,6 @@ public static String getFilterQuery(@NonNull String filterName, @NonNull String public static ViewFilter parseFilteringQuery(String str, ViewFilter viewFilter) { String[] conditions = str.split("(and\\s)|(AND\\s)"); Map filters = new HashMap<>(conditions.length); - Filter lastSmIdFilter = null; - boolean isSmIDTypeFilter = false; for (String condition : conditions) { if (StringUtils.isBlank(condition)) { continue; @@ -526,9 +520,6 @@ else if (word.equals(Filter.JSON_CONTAINS)) {// type is JSONARRAY else {// beginning of other types of query tableName = word.substring(0, word.indexOf(Filter.DB_NAME_DELIMITER)); columnName = word.substring(word.indexOf(Filter.DB_NAME_DELIMITER) + 1); - if (DBConstants.SM_ID_TYPE_TABLE_ALIAS.equals(tableName)) { - isSmIDTypeFilter = true; - } state = 1; } break; @@ -909,19 +900,12 @@ else if (word.equals(Filter.MINUS_SIGN)) { break; case 40: break; - } } } if (state != 7 && state != 9 && state != 10 && state != 11 && state != 13 && state != 22 && state != 25 && state != 37 && state != 40) {// terminal states throw new RuntimeException("Query parsing ended in bad state: " + state); } - if (isSmIDTypeFilter && lastSmIdFilter != null) { - lastSmIdFilter.setFilter2(new NameValue(null, value)); - lastSmIdFilter = null; - isSmIDTypeFilter = false; - continue; - } String columnKey = columnName; if (StringUtils.isNotBlank(tableName)) { columnKey = tableName.concat(DBConstants.ALIAS_DELIMITER).concat(columnName); @@ -1021,9 +1005,6 @@ else if (filter2 != null || f2) { filter.setFilter2(filter2); } } - if (DBConstants.SM_ID_ALIAS.equals(tableName)) { - lastSmIdFilter = filter; - } filters.put(columnName, filter); } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java index 45aa32978..f75b2632a 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSmIdType.java @@ -1,17 +1,10 @@ package org.broadinstitute.dsm.db.dao.ddp.tissue; import lombok.Data; -import org.apache.commons.lang3.StringUtils; import org.broadinstitute.dsm.db.structure.ColumnName; -import org.broadinstitute.dsm.db.structure.DBElement; import org.broadinstitute.dsm.db.structure.TableName; -import org.broadinstitute.dsm.model.Filter; -import org.broadinstitute.dsm.model.NameValue; import org.broadinstitute.dsm.statics.DBConstants; -import java.lang.annotation.Annotation; -import java.util.Map; - @Data @TableName ( name = DBConstants.SM_ID_TYPE_TABLE, @@ -26,20 +19,4 @@ public class TissueSmIdType { @ColumnName (DBConstants.SM_ID_TYPE) private String smIdType; - public void createFilterForType(Map queryConditions, String type, String tmp) { - if (StringUtils.isBlank(type)) { - return; - } - Annotation annotation = TissueSmIdType.class.getAnnotation(TableName.class); - TableName tableNameAnnotation = (TableName) annotation; - String tableName = tableNameAnnotation.name(); - String tableAlias = tableNameAnnotation.alias(); - String primaryKey = tableNameAnnotation.primaryKey(); - DBElement dbElementForType = new DBElement(tableName, tableAlias, primaryKey, DBConstants.SM_ID_TYPE); - Filter filterForType = new Filter(); - filterForType.setType(Filter.TEXT); - filterForType.setExactMatch(true); - filterForType.setFilter1(new NameValue("smIdType", type)); - queryConditions.put(tmp, queryConditions.get(tmp).concat(Filter.getQueryStringForFiltering(filterForType, dbElementForType))); - } } From a192f32e1c879b0057d86495d7f5b9a30f583c08 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Wed, 1 Dec 2021 12:09:23 -0500 Subject: [PATCH 15/20] added changes to fix how we get the sm ids --- .../dsm/db/OncHistoryDetail.java | 38 ++++++-- .../org/broadinstitute/dsm/db/Tissue.java | 92 ++++++++++++------- .../org/broadinstitute/dsm/db/TissueSmId.java | 26 +++--- .../broadinstitute/dsm/model/TissueList.java | 35 +++++-- 4 files changed, 132 insertions(+), 59 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index e5ebe4b74..47f133dab 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -42,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, " + "t.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, p.ddp_participant_id, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted, sm.tissue_id " + + " scrolls_count, uss_count, h_e_count, blocks_count, p.ddp_participant_id, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted, sm.tissue_id, smt.sm_id_type " + "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) " + @@ -58,7 +58,7 @@ public class OncHistoryDetail { " tissue_received, gender, tissue_problem_option, destruction_policy FROM ddp_onc_history_detail WHERE NOT (deleted <=> 1)"; private static final String SQL_SELECT_TISSUE_RECEIVED = "SELECT tissue_received FROM ddp_onc_history_detail WHERE onc_history_detail_id = ?"; private static final String SQL_INSERT_ONC_HISTORY_DETAIL = "INSERT INTO ddp_onc_history_detail SET medical_record_id = ?, request = ?, last_changed = ?, changed_by = ?"; - public static final String SQL_ORDER_BY = " ORDER BY p.ddp_participant_id, inst.ddp_institution_id, oD.onc_history_detail_id ASC"; + public static final String SQL_ORDER_BY = " ORDER BY p.ddp_participant_id, inst.ddp_institution_id, oD.onc_history_detail_id, t.tissue_id ASC"; public static final String SQL_SELECT_ONC_HISTORY_LAST_CHANGED = "SELECT oD.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) " + "LEFT JOIN ddp_medical_record as m on (m.institution_id = inst.institution_id AND NOT m.deleted <=> 1) LEFT JOIN ddp_onc_history_detail as oD on (m.medical_record_id = oD.medical_record_id) " + @@ -285,7 +285,8 @@ public static OncHistoryDetail getOncHistoryDetail(@NonNull ResultSet rs) throws ); try { oncHistoryDetail.setParticipantId(rs.getString(DBConstants.DDP_PARTICIPANT_ID)); - }catch (java.sql.SQLException e) { + } + catch (java.sql.SQLException e) { oncHistoryDetail.setParticipantId(null); } return oncHistoryDetail; @@ -309,6 +310,7 @@ public static Map> getOncHistoryDetailsByParticip public static Map> getOncHistoryDetails(@NonNull String realm, String queryAddition) { logger.info("Collection oncHistoryDetail information"); Map> oncHistory = new HashMap<>(); + HashMap tissues = new HashMap<>(); SimpleResult results = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(SQL_SELECT_ONC_HISTORY_DETAIL, queryAddition) + SQL_ORDER_BY)) { @@ -318,8 +320,18 @@ public static Map> getOncHistoryDetails(@NonNull while (rs.next()) { String ddpParticipantId = rs.getString(DBConstants.DDP_PARTICIPANT_ID); String oncHistoryDetailId = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); - - Tissue tissue = Tissue.getTissue(rs); + TissueSmId tissueSmId = Tissue.getSMIds(rs); + Tissue tissue; + if (tissueSmId != null && tissues.containsKey(tissueSmId.getTissueId())) { + tissue = tissues.get(tissueSmId.getTissueId()); + } + else { + tissue = Tissue.getTissue(rs); + } + if (tissueSmId != null) { + tissue.setSmIdBasedOnType(tissueSmId, rs); + } + tissues.put(tissue.getTissueId(), tissue); //check if oncHistoryDetails is already in map List oncHistoryDataList = new ArrayList<>(); @@ -334,6 +346,7 @@ public static Map> getOncHistoryDetails(@NonNull OncHistoryDetail oncHistoryDetail = null; if (oncHistoryMap.containsKey(oncHistoryDetailId)) { oncHistoryDetail = oncHistoryMap.get(oncHistoryDetailId); + oncHistoryDetail.getTissues().removeIf(tissue1 -> tissue1.getTissueId() == tissue.getTissueId()); oncHistoryDetail.addTissue(tissue); } else { @@ -362,6 +375,7 @@ public static Map> getOncHistoryDetails(@NonNull public static Map> getOncHistoryDetails(@NonNull String realm, String queryAddition, List values) { logger.info("Collection oncHistoryDetail information"); Map> oncHistory = new HashMap<>(); + HashMap tissues = new HashMap<>(); SimpleResult results = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(SQL_SELECT_ONC_HISTORY_DETAIL, queryAddition) + SQL_ORDER_BY)) { @@ -375,7 +389,18 @@ public static Map> getOncHistoryDetails(@NonNull String ddpParticipantId = rs.getString(DBConstants.DDP_PARTICIPANT_ID); String oncHistoryDetailId = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); - Tissue tissue = Tissue.getTissue(rs); + TissueSmId tissueSmId = Tissue.getSMIds(rs); + Tissue tissue; + if (tissueSmId != null && tissues.containsKey(tissueSmId.getTissueId())) { + tissue = tissues.get(tissueSmId.getTissueId()); + } + else { + tissue = Tissue.getTissue(rs); + } + if (tissueSmId != null) { + tissue.setSmIdBasedOnType(tissueSmId, rs); + } + tissues.put(tissue.getTissueId(), tissue); //check if oncHistoryDetails is already in map List oncHistoryDataList = new ArrayList<>(); @@ -390,6 +415,7 @@ public static Map> getOncHistoryDetails(@NonNull OncHistoryDetail oncHistoryDetail = null; if (oncHistoryMap.containsKey(oncHistoryDetailId)) { oncHistoryDetail = oncHistoryMap.get(oncHistoryDetailId); + oncHistoryDetail.getTissues().removeIf(tissue1 -> tissue.getTissueId() == tissue1.getTissueId()); oncHistoryDetail.addTissue(tissue); } else { diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index 98adfcf5d..befade866 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -1,10 +1,8 @@ package org.broadinstitute.dsm.db; -import com.google.gson.Gson; import lombok.Data; import lombok.NonNull; import org.broadinstitute.ddp.db.SimpleResult; -import org.broadinstitute.dsm.db.dao.ddp.tissue.TissueSMIDDao; import org.broadinstitute.dsm.db.structure.ColumnName; import org.broadinstitute.dsm.db.structure.DbDateConversion; import org.broadinstitute.dsm.db.structure.SqlDateConverter; @@ -15,8 +13,8 @@ import java.sql.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -import java.util.Map; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -34,7 +32,7 @@ public class Tissue { "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, 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) "+ + "LEFT JOIN sm_id sm on (sm.tissue_id = t.tissue_id AND NOT sm.deleted <=> 1 AND NOT t.deleted <=> 1) " + "WHERE NOT (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 " + @@ -76,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) @@ -86,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; @@ -101,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) @@ -128,12 +126,11 @@ public class Tissue { @ColumnName (DBConstants.H_E_COUNT) private Integer hECount; - private TissueSmId[] ussSMID; + private List ussSMID; - private TissueSmId[] scrollSMID; - - private TissueSmId[] heSMID; + private List scrollSMID; + private List heSMID; public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer countReceived, String tissueType, @@ -141,7 +138,7 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer 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, TissueSmId[] ussSMIDs, TissueSmId[] scrollSMIDs, TissueSmId[] heSMID) { + Integer ussCount, Integer blocksCount, Integer hECount, List ussSMIDs, List scrollSMIDs, List heSMID) { this.tissueId = tissueId; this.oncHistoryDetailId = oncHistoryDetailId; this.tNotes = tNotes; @@ -175,9 +172,9 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer } public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { - Gson gson = new Gson(); + 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), @@ -204,33 +201,38 @@ public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { rs.getInt(DBConstants.USS_COUNT), rs.getInt(DBConstants.BLOCKS_COUNT), rs.getInt(DBConstants.H_E_COUNT), - null, - null, - null); - tissue.setSMIds(rs); + new ArrayList<>(), + new ArrayList<>(), + new ArrayList<>()); return tissue; } - private void setSMIds(ResultSet rs) { - Map> map= TissueSmId.getSMIdsForTissueId(rs); - TissueSMIDDao tissueSMIDDao = new TissueSMIDDao(); - String typeId = tissueSMIDDao.getTypeForName(TissueSmId.HE); - this.heSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); - typeId = tissueSMIDDao.getTypeForName(TissueSmId.USS); - this.ussSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); - typeId = tissueSMIDDao.getTypeForName(TissueSmId.SCROLLS); - this.scrollSMID = map.getOrDefault(typeId, new ArrayList<>()).toArray(new TissueSmId[map.getOrDefault(typeId, new ArrayList<>()).size()]); + + public static TissueSmId getSMIds(ResultSet rs) { + return TissueSmId.getSMIdsForTissueId(rs); } public static List getTissue(@NonNull Connection conn, @NonNull String oncHistoryDetailId) { - List tissue = new ArrayList<>(); + List tissueList = new ArrayList<>(); SimpleResult dbVals = new SimpleResult(); + HashMap 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); } } } @@ -241,9 +243,37 @@ public static List 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) { diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java index 175e376ff..6079184ad 100644 --- a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -10,10 +10,6 @@ import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; @Data @TableName ( @@ -36,12 +32,13 @@ public class TissueSmId { private String smIdPk; @ColumnName (DBConstants.DELETED) - private boolean 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() { } @@ -53,26 +50,25 @@ public TissueSmId(String smIdPk, String smIdType, String smIdValue, String tissu } - public static Map> getSMIdsForTissueId(ResultSet rs) { - Map> map = new HashMap<>(); - TissueSmId tissueSmId = null; + 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(DBConstants.TISSUE_ID) + 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); } - - List list = map.getOrDefault(tissueSmId.getSmIdType(), new ArrayList<>()); - list.add(tissueSmId); - map.put(tissueSmId.getSmIdType(), list); - - return map; + return tissueSmId; } public String createNewSmId(String tissueId, String userId, String smIdType) { diff --git a/src/main/java/org/broadinstitute/dsm/model/TissueList.java b/src/main/java/org/broadinstitute/dsm/model/TissueList.java index 5442e99c9..3eec7eb4c 100644 --- a/src/main/java/org/broadinstitute/dsm/model/TissueList.java +++ b/src/main/java/org/broadinstitute/dsm/model/TissueList.java @@ -5,6 +5,7 @@ import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.dsm.db.OncHistoryDetail; import org.broadinstitute.dsm.db.Tissue; +import org.broadinstitute.dsm.db.TissueSmId; import org.broadinstitute.dsm.statics.DBConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,6 +13,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import static org.broadinstitute.ddp.db.TransactionWrapper.inTransaction; @@ -24,17 +26,18 @@ public class TissueList { "oD.location_px, oD.histology, oD.accession_number, oD.facility, oD.phone, oD.fax, oD.notes, oD.additional_values_json, " + "oD.request, oD.fax_sent, oD.fax_sent_by, oD.fax_confirmed, oD.fax_sent_2, oD.fax_sent_2_by, oD.fax_confirmed_2, oD.fax_sent_3, " + "oD.fax_sent_3_by, oD.fax_confirmed_3, oD.tissue_received, oD.tissue_problem_option, oD.additional_values_json, oD.gender, oD.destruction_policy, oD.unable_obtain_tissue," + - "tissue_id, t.notes, t.count_received, t.tissue_type, t.tissue_site, t.tumor_type, t.h_e, t.pathology_report, t.collaborator_sample_id, t.block_sent, t.scrolls_received, t.sk_id, t.sm_id, " + + "t.tissue_id, t.notes, t.count_received, t.tissue_type, t.tissue_site, t.tumor_type, t.h_e, t.pathology_report, t.collaborator_sample_id, t.block_sent, t.scrolls_received, t.sk_id, t.sm_id, " + "t.sent_gp, t.first_sm_id, t.additional_tissue_value_json, t.expected_return, t.return_date, t.return_fedex_id, t.shl_work_number, t.tumor_percentage, t.tissue_sequence, t.onc_history_detail_id, " + - "t.scrolls_count, t.h_e_count, t.uss_count, t.blocks_count, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted " + + "t.scrolls_count, t.h_e_count, t.uss_count, t.blocks_count, sm.tissue_id, sm.sm_id_value, sm.sm_id_type_id, sm.sm_id_pk, sm.deleted, smt.sm_id_type " + "FROM ddp_participant p LEFT JOIN ddp_instance realm on (p.ddp_instance_id = realm.ddp_instance_id) " + "LEFT JOIN ddp_participant_exit ex on (p.ddp_participant_id = ex.ddp_participant_id AND p.ddp_instance_id = ex.ddp_instance_id) " + "LEFT JOIN ddp_institution inst on (p.participant_id = inst.participant_id) LEFT JOIN ddp_medical_record m on (m.institution_id = inst.institution_id AND NOT m.deleted <=> 1) " + "LEFT JOIN ddp_onc_history_detail oD on (m.medical_record_id = oD.medical_record_id AND NOT oD.deleted <=> 1) " + "LEFT JOIN ddp_tissue t on (oD.onc_history_detail_id = t.onc_history_detail_id AND NOT t.deleted <=> 1) " + - "LEFT JOIN sm_id sm on (sm.tissue_id = t.tissue_id AND NOT sm.deleted <=> 1 AND NOT t.deleted <=> 1) "+ + "LEFT JOIN sm_id sm on (sm.tissue_id = t.tissue_id AND NOT sm.deleted <=> 1 AND NOT t.deleted <=> 1) " + + "LEFT JOIN sm_id_type smt on (smt.sm_id_type_id = sm.sm_id_type_id ) " + "WHERE realm.instance_name = ? AND ex.ddp_participant_exit_id IS NULL AND oD.onc_history_detail_id IS NOT NULL"; - public static final String SQL_ORDER_BY_ONC_HISTORY = " ORDER BY oD.onc_history_detail_id "; + public static final String SQL_ORDER_BY_ONC_HISTORY = " ORDER BY oD.onc_history_detail_id, t.tissue_id "; private OncHistoryDetail oncHistoryDetails; private Tissue tissue; @@ -53,6 +56,8 @@ public static List getAllTissueListsForRealmNoFilter(String realm) { public static List getAllTissueListsForRealm(String realm, String query) { List results = new ArrayList<>(); + HashMap tissues = new HashMap<>(); + HashMap oncHistoryDetailHashMap = new HashMap<>(); SimpleResult result = inTransaction((conn) -> { SimpleResult dbVals = new SimpleResult(); try (PreparedStatement stmt = conn.prepareStatement(query)) { @@ -61,10 +66,26 @@ public static List getAllTissueListsForRealm(String realm, String qu OncHistoryDetail oncHistory = null; String ptId = null; while (rs.next()) { - oncHistory = OncHistoryDetail.getOncHistoryDetail(rs); ptId = rs.getString(DBConstants.DDP_PARTICIPANT_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.DDP_PARTICIPANT_ID); - Tissue tissue = Tissue.getTissue(rs); - TissueList tissueList = new TissueList(oncHistory, null, ptId); + TissueSmId tissueSmId = Tissue.getSMIds(rs); + Tissue tissue; + if (tissueSmId != null && tissues.containsKey(tissueSmId.getTissueId())) { + tissue = tissues.get(tissueSmId.getTissueId()); + } + else { + tissue = Tissue.getTissue(rs); + } + if (!oncHistoryDetailHashMap.containsKey(tissue.getOncHistoryDetailId())) { + oncHistory = OncHistoryDetail.getOncHistoryDetail(rs); + oncHistoryDetailHashMap.put(oncHistory.getOncHistoryDetailId(), oncHistory); + } + if (tissueSmId != null) { + tissue.setSmIdBasedOnType(tissueSmId, rs); + } + tissues.put(tissue.getTissueId(), tissue); + } + for (Tissue tissue : tissues.values()) { + TissueList tissueList = new TissueList(oncHistoryDetailHashMap.get(tissue.getOncHistoryDetailId()), null, ptId); if (!tissue.isTDeleted() && StringUtils.isNotBlank(tissue.getTissueId())) { tissueList.setTissue(tissue); From 4047aab91dc537ca95086551c75898f1eceae037 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Wed, 1 Dec 2021 13:08:37 -0500 Subject: [PATCH 16/20] throwing errors for null accession number and added checks wheen creating dummies --- .../org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java | 2 +- .../org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java | 8 +++++--- .../org/broadinstitute/dsm/route/ClinicalKitsRoute.java | 3 --- .../dsm/route/CreateClinicalDummyKitRoute.java | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java index acfcf5587..653c41912 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/kit/ClinicalKitDao.java @@ -55,7 +55,7 @@ public Optional getClinicalKitFromSMId(String smIdValue){ Integer.parseInt(rs.getString(DBConstants.DDP_INSTANCE_ID)), rs.getString(DBConstants.DDP_PARTICIPANT_ID)); dbVals.resultValue = clinicalKitWrapper; - + logger.info("found clinical kit for sm id value: " + smIdValue); } } catch (Exception e) { diff --git a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java index e3af8b6db..eda78a08d 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java +++ b/src/main/java/org/broadinstitute/dsm/db/dto/kit/ClinicalKitDto.java @@ -106,9 +106,8 @@ public void setGender(String genderString) { } - public ClinicalKitDto getClinicalKitBasedONSmId(String smIdValue) { - logger.info("Checking the kit for SM Id value"); + logger.info("Checking the kit for SM Id value " + smIdValue); ClinicalKitDao clinicalKitDao = new ClinicalKitDao(); Optional maybeClinicalKitWrapper = clinicalKitDao.getClinicalKitFromSMId(smIdValue); maybeClinicalKitWrapper.orElseThrow(); @@ -116,7 +115,10 @@ public ClinicalKitDto getClinicalKitBasedONSmId(String smIdValue) { ClinicalKitDto clinicalKitDto = clinicalKitWrapper.getClinicalKitDto(); DDPInstance ddpInstance = DDPInstance.getDDPInstanceById(clinicalKitWrapper.getDdpInstanceId()); clinicalKitDto.setNecessaryParticipantDataToClinicalKit(clinicalKitWrapper.getDdpParticipantId(), ddpInstance); - return clinicalKitDto; + if (StringUtils.isNotBlank(clinicalKitDto.getAccessionNumber())) { + return clinicalKitDto; + } + throw new RuntimeException("The kit doesn't have an accession number! SM ID is: " + smIdValue); } public void setNecessaryParticipantDataToClinicalKit(String ddpParticipantId, DDPInstance ddpInstance) { diff --git a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java index 5c90f9018..9242fc01b 100644 --- a/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/ClinicalKitsRoute.java @@ -20,9 +20,6 @@ import java.util.Optional; public class ClinicalKitsRoute implements Route { - private String FIRSTNAME = "firstName"; - private String LASTNAME = "lastName"; - private String DATE_OF_BIRtH = "dateOfBirth"; private static final Logger logger = LoggerFactory.getLogger(ClinicalKitsRoute.class); diff --git a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java index 1566a26b7..c257b3284 100644 --- a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java @@ -86,7 +86,7 @@ else if (kitTypeString.equalsIgnoreCase(FFPE_SECTION)) { String ddpParticipantId = oncHistoryDetail.getParticipantId(); Optional maybeParticipant = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); logger.info("found randomOncHistoryDetailId " + randomOncHistoryDetailId); - while (oncHistoryDetail == null || maybeParticipant.isEmpty() || maybeParticipant.get().getProfile().map(ESProfile::getHruid).isEmpty()) { + while (oncHistoryDetail == null || StringUtils.isBlank(oncHistoryDetail.getAccessionNumber()) || maybeParticipant.isEmpty() || maybeParticipant.get().getProfile().map(ESProfile::getHruid).isEmpty()) { randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); ddpParticipantId = oncHistoryDetail.getParticipantId(); From 3f837260dd7d56277166971614f4fae8972b0b19 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Thu, 9 Dec 2021 17:21:38 -0500 Subject: [PATCH 17/20] Changed the way of making onc history to be better readable --- .../dsm/db/OncHistoryDetail.java | 75 ++++++++++--------- .../broadinstitute/dsm/model/TissueList.java | 4 +- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 47f133dab..0fc319270 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -318,7 +318,6 @@ public static Map> getOncHistoryDetails(@NonNull try (ResultSet rs = stmt.executeQuery()) { Map oncHistoryMap = new HashMap<>(); while (rs.next()) { - String ddpParticipantId = rs.getString(DBConstants.DDP_PARTICIPANT_ID); String oncHistoryDetailId = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); TissueSmId tissueSmId = Tissue.getSMIds(rs); Tissue tissue; @@ -333,29 +332,31 @@ public static Map> getOncHistoryDetails(@NonNull } tissues.put(tissue.getTissueId(), tissue); + if (!oncHistoryMap.containsKey(oncHistoryDetailId)) { + OncHistoryDetail oncHistoryDetail = getOncHistoryDetail(rs); + oncHistoryMap.put(oncHistoryDetailId, oncHistoryDetail); + } + + } + //add tissues to their onc history + for (Tissue tissue : tissues.values()) { + String tissueOncHistoryDetailId = tissue.getOncHistoryDetailId(); + OncHistoryDetail oncHistoryDetail = oncHistoryMap.get(tissueOncHistoryDetailId); + oncHistoryDetail.getTissues().add(tissue); + }// add onchistories to their particiapnt + for (OncHistoryDetail oncHistoryDetail : oncHistoryMap.values()) { //check if oncHistoryDetails is already in map List oncHistoryDataList = new ArrayList<>(); + String ddpParticipantId = oncHistoryDetail.getParticipantId(); if (oncHistory.containsKey(ddpParticipantId)) { oncHistoryDataList = oncHistory.get(ddpParticipantId); } - else { - oncHistory.put(ddpParticipantId, oncHistoryDataList); - oncHistoryMap = new HashMap<>(); - } - - OncHistoryDetail oncHistoryDetail = null; - if (oncHistoryMap.containsKey(oncHistoryDetailId)) { - oncHistoryDetail = oncHistoryMap.get(oncHistoryDetailId); - oncHistoryDetail.getTissues().removeIf(tissue1 -> tissue1.getTissueId() == tissue.getTissueId()); - oncHistoryDetail.addTissue(tissue); - } - else { - oncHistoryDetail = getOncHistoryDetail(rs); - oncHistoryDetail.addTissue(tissue); - oncHistoryDataList.add(oncHistoryDetail); - } - oncHistoryMap.put(oncHistoryDetailId, oncHistoryDetail); + oncHistoryDataList.add(oncHistoryDetail); + oncHistory.put(ddpParticipantId, oncHistoryDataList); } + + } catch (Exception e){ + dbVals.resultException = e; } } catch (SQLException ex) { @@ -386,9 +387,7 @@ public static Map> getOncHistoryDetails(@NonNull try (ResultSet rs = stmt.executeQuery()) { Map oncHistoryMap = new HashMap<>(); while (rs.next()) { - String ddpParticipantId = rs.getString(DBConstants.DDP_PARTICIPANT_ID); String oncHistoryDetailId = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); - TissueSmId tissueSmId = Tissue.getSMIds(rs); Tissue tissue; if (tissueSmId != null && tissues.containsKey(tissueSmId.getTissueId())) { @@ -402,29 +401,31 @@ public static Map> getOncHistoryDetails(@NonNull } tissues.put(tissue.getTissueId(), tissue); + if (!oncHistoryMap.containsKey(oncHistoryDetailId)) { + OncHistoryDetail oncHistoryDetail = getOncHistoryDetail(rs); + oncHistoryMap.put(oncHistoryDetailId, oncHistoryDetail); + } + + } + //add tissues to their onc history + for (Tissue tissue : tissues.values()) { + String tissueOncHistoryDetailId = tissue.getOncHistoryDetailId(); + OncHistoryDetail oncHistoryDetail = oncHistoryMap.get(tissueOncHistoryDetailId); + oncHistoryDetail.getTissues().add(tissue); + }// add onchistories to their particiapnt + for (OncHistoryDetail oncHistoryDetail : oncHistoryMap.values()) { //check if oncHistoryDetails is already in map List oncHistoryDataList = new ArrayList<>(); + String ddpParticipantId = oncHistoryDetail.getParticipantId(); if (oncHistory.containsKey(ddpParticipantId)) { oncHistoryDataList = oncHistory.get(ddpParticipantId); } - else { - oncHistory.put(ddpParticipantId, oncHistoryDataList); - oncHistoryMap = new HashMap<>(); - } - - OncHistoryDetail oncHistoryDetail = null; - if (oncHistoryMap.containsKey(oncHistoryDetailId)) { - oncHistoryDetail = oncHistoryMap.get(oncHistoryDetailId); - oncHistoryDetail.getTissues().removeIf(tissue1 -> tissue.getTissueId() == tissue1.getTissueId()); - oncHistoryDetail.addTissue(tissue); - } - else { - oncHistoryDetail = getOncHistoryDetail(rs); - oncHistoryDetail.addTissue(tissue); - oncHistoryDataList.add(oncHistoryDetail); - } - oncHistoryMap.put(oncHistoryDetailId, oncHistoryDetail); + oncHistoryDataList.add(oncHistoryDetail); + oncHistory.put(ddpParticipantId, oncHistoryDataList); } + + } catch (Exception e){ + dbVals.resultException = e; } } catch (SQLException ex) { diff --git a/src/main/java/org/broadinstitute/dsm/model/TissueList.java b/src/main/java/org/broadinstitute/dsm/model/TissueList.java index 3eec7eb4c..945d4b3b6 100644 --- a/src/main/java/org/broadinstitute/dsm/model/TissueList.java +++ b/src/main/java/org/broadinstitute/dsm/model/TissueList.java @@ -82,7 +82,9 @@ public static List getAllTissueListsForRealm(String realm, String qu if (tissueSmId != null) { tissue.setSmIdBasedOnType(tissueSmId, rs); } - tissues.put(tissue.getTissueId(), tissue); + if (tissue.getTissueId() != null) { + tissues.put(tissue.getTissueId(), tissue); + } } for (Tissue tissue : tissues.values()) { TissueList tissueList = new TissueList(oncHistoryDetailHashMap.get(tissue.getOncHistoryDetailId()), null, ptId); From b63b4b10aae4c40a4b07cf5cab5a0d347b6a1991 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Thu, 9 Dec 2021 20:26:52 -0500 Subject: [PATCH 18/20] added unique constraint --- .../org/broadinstitute/dsm/db/TissueSmId.java | 4 +++ .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 29 +++++++++++++++++++ .../org/broadinstitute/dsm/model/Patch.java | 1 + .../broadinstitute/dsm/route/PatchRoute.java | 5 ++++ 4 files changed, 39 insertions(+) diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java index 6079184ad..1fb3cffb2 100644 --- a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -71,6 +71,10 @@ public static TissueSmId getSMIdsForTissueId(ResultSet rs) { return tissueSmId; } + public static boolean isUniqueSmId(String smIdValue) { + return new TissueSMIDDao().isUnique(smIdValue); + } + public String createNewSmId(String tissueId, String userId, String smIdType) { String smIdId = new TissueSMIDDao().createNewSMIDForTissue(tissueId, userId, smIdType); return smIdId; diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java index 4e3080e7b..19b8ae0fc 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java @@ -19,6 +19,7 @@ public class TissueSMIDDao { 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 static final String SQL_INSERT_SM_ID_WITH_VALUE = "INSERT INTO sm_id SET tissue_id = ?, sm_id_type_id = ?, last_changed = ?, changed_by = ?, sm_id_value = ?"; + public static final String SQL_SELECT_SM_ID_VALUE = "SELECT sm_id_value from sm_id where sm_id_value = ? and Not deleted <=> 1"; public String getTypeForName(String type) { SimpleResult results = inTransaction((conn) -> { @@ -124,4 +125,32 @@ public String createNewSMIDForTissue(String tissueId, String userId, String smId return (String) results.resultValue; } } + + + public boolean isUnique(String smIdValue) { + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement stmt = conn.prepareStatement(SQL_SELECT_SM_ID_VALUE)) { + stmt.setString(1, smIdValue); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + dbVals.resultValue = false; + } + else{ + dbVals.resultValue = true; + } + } + } + catch (SQLException ex) { + dbVals.resultException = ex; + } + return dbVals; + }); + + if (results.resultException != null) { + throw new RuntimeException("Error getting values from sm_id table matching " + smIdValue, results.resultException); + } + + return (boolean) results.resultValue; + } } diff --git a/src/main/java/org/broadinstitute/dsm/model/Patch.java b/src/main/java/org/broadinstitute/dsm/model/Patch.java index 9197f3c16..deae2ed87 100644 --- a/src/main/java/org/broadinstitute/dsm/model/Patch.java +++ b/src/main/java/org/broadinstitute/dsm/model/Patch.java @@ -32,6 +32,7 @@ public class Patch { public static final String PARTICIPANT_DATA_ID = "participantDataId"; public static final String DDP_PARTICIPANT_ID = "ddpParticipantId"; public static final String TISSUEID = "tissueId"; + public static final String SM_ID_VALUE = "sm.smIdValue"; private String id; private String parent; //for new added rows at oncHistoryDetails/tissue diff --git a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java index 013cef963..47899ef83 100644 --- a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java @@ -140,6 +140,11 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { } else { // mr changes + if(Patch.TISSUEID.equals(patch.getParent()) && patch.getNameValue().getName().equals(Patch.SM_ID_VALUE)){ + if(StringUtils.isNotBlank(String.valueOf(patch.getNameValue().getValue())) && !TissueSmId.isUniqueSmId(String.valueOf(patch.getNameValue().getValue()))){ + return new Result(500, "Duplicate value"); + } + } DBElement dbElement = patchUtil.getColumnNameMap().get(patch.getNameValue().getName()); if (dbElement != null) { if (Patch.patch(patch.getId(), patch.getUser(), patch.getNameValue(), dbElement)) { From 0d3c589e6aebac0f4cf10c1dd877eb3d70f4ca4b Mon Sep 17 00:00:00 2001 From: pegahtah Date: Tue, 28 Dec 2021 16:54:52 -0800 Subject: [PATCH 19/20] fixes from prod changes after QA --- .../dsm/db/OncHistoryDetail.java | 32 ++++++--------- .../org/broadinstitute/dsm/db/Tissue.java | 3 +- .../org/broadinstitute/dsm/db/TissueSmId.java | 39 ++++++++++++++---- .../dsm/db/dao/ddp/tissue/TissueSMIDDao.java | 40 ++++++++++++++++--- .../broadinstitute/dsm/model/TissueList.java | 30 +++++++++----- .../broadinstitute/dsm/route/PatchRoute.java | 16 +++++--- 6 files changed, 112 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java index 0fc319270..5842e6a6a 100644 --- a/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java +++ b/src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java @@ -36,7 +36,7 @@ public class OncHistoryDetail { private static final Logger logger = LoggerFactory.getLogger(OncHistoryDetail.class); - public static final String SQL_SELECT_ONC_HISTORY_DETAIL = "SELECT p.ddp_participant_id, oD.onc_history_detail_id, oD.request, oD.deleted, oD.fax_sent, oD.tissue_received, oD.medical_record_id, oD.date_px, oD.type_px, " + + public static final String SQL_SELECT_ONC_HISTORY_DETAIL = "SELECT p.ddp_participant_id, p.participant_id, oD.onc_history_detail_id, oD.request, oD.deleted, oD.fax_sent, oD.tissue_received, oD.medical_record_id, oD.date_px, oD.type_px, " + "oD.location_px, oD.histology, oD.accession_number, oD.facility, oD.phone, oD.fax, oD.notes, oD.additional_values_json, " + "oD.request, oD.fax_sent, oD.fax_sent_by, oD.fax_confirmed, oD.fax_sent_2, oD.fax_sent_2_by, oD.fax_confirmed_2, oD.fax_sent_3, " + "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, " + @@ -172,6 +172,7 @@ public class OncHistoryDetail { private boolean unableToObtain; private String participantId; + private String ddpParticipantId; private List tissues; @@ -221,7 +222,7 @@ public OncHistoryDetail(String oncHistoryDetailId, String medicalRecordId, Strin String tFaxSent2, String tFaxSent2By, String tFaxConfirmed2, String tFaxSent3, String tFaxSent3By, String tFaxConfirmed3, String tissueReceived, String gender, String additionalValues, List tissues, - String tissueProblemOption, String destructionPolicy, boolean unableToObtain) { + String tissueProblemOption, String destructionPolicy, boolean unableToObtain, String participantId, String ddpParticipantId) { this.oncHistoryDetailId = oncHistoryDetailId; this.medicalRecordId = medicalRecordId; this.datePX = datePX; @@ -250,6 +251,8 @@ public OncHistoryDetail(String oncHistoryDetailId, String medicalRecordId, Strin this.tissueProblemOption = tissueProblemOption; this.destructionPolicy = destructionPolicy; this.unableToObtain = unableToObtain; + this.participantId = participantId; + this.ddpParticipantId = ddpParticipantId; } public static OncHistoryDetail getOncHistoryDetail(@NonNull ResultSet rs) throws SQLException { @@ -281,14 +284,11 @@ public static OncHistoryDetail getOncHistoryDetail(@NonNull ResultSet rs) throws rs.getString(DBConstants.DDP_ONC_HISTORY_DETAIL_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.ADDITIONAL_VALUES), tissues, rs.getString(DBConstants.TISSUE_PROBLEM_OPTION), rs.getString(DBConstants.DESTRUCTION_POLICY), - rs.getBoolean(DBConstants.UNABLE_OBTAIN_TISSUE) + rs.getBoolean(DBConstants.UNABLE_OBTAIN_TISSUE), + rs.getString(DBConstants.PARTICIPANT_ID), + rs.getString(DBConstants.DDP_PARTICIPANT_ID) ); - try { - oncHistoryDetail.setParticipantId(rs.getString(DBConstants.DDP_PARTICIPANT_ID)); - } - catch (java.sql.SQLException e) { - oncHistoryDetail.setParticipantId(null); - } + return oncHistoryDetail; } @@ -346,11 +346,8 @@ public static Map> getOncHistoryDetails(@NonNull }// add onchistories to their particiapnt for (OncHistoryDetail oncHistoryDetail : oncHistoryMap.values()) { //check if oncHistoryDetails is already in map - List oncHistoryDataList = new ArrayList<>(); - String ddpParticipantId = oncHistoryDetail.getParticipantId(); - if (oncHistory.containsKey(ddpParticipantId)) { - oncHistoryDataList = oncHistory.get(ddpParticipantId); - } + String ddpParticipantId = oncHistoryDetail.getDdpParticipantId(); + List oncHistoryDataList = oncHistory.getOrDefault(ddpParticipantId, new ArrayList<>()); oncHistoryDataList.add(oncHistoryDetail); oncHistory.put(ddpParticipantId, oncHistoryDataList); } @@ -415,11 +412,8 @@ public static Map> getOncHistoryDetails(@NonNull }// add onchistories to their particiapnt for (OncHistoryDetail oncHistoryDetail : oncHistoryMap.values()) { //check if oncHistoryDetails is already in map - List oncHistoryDataList = new ArrayList<>(); - String ddpParticipantId = oncHistoryDetail.getParticipantId(); - if (oncHistory.containsKey(ddpParticipantId)) { - oncHistoryDataList = oncHistory.get(ddpParticipantId); - } + String ddpParticipantId = oncHistoryDetail.getDdpParticipantId(); + List oncHistoryDataList = oncHistory.getOrDefault(ddpParticipantId, new ArrayList<>()); oncHistoryDataList.add(oncHistoryDetail); oncHistory.put(ddpParticipantId, oncHistoryDataList); } diff --git a/src/main/java/org/broadinstitute/dsm/db/Tissue.java b/src/main/java/org/broadinstitute/dsm/db/Tissue.java index befade866..ad4ca7a55 100644 --- a/src/main/java/org/broadinstitute/dsm/db/Tissue.java +++ b/src/main/java/org/broadinstitute/dsm/db/Tissue.java @@ -33,7 +33,7 @@ public class Tissue { "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, 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 (deleted <=> 1) AND onc_history_detail_id = ?"; + "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) " + @@ -172,7 +172,6 @@ public Tissue(String tissueId, String oncHistoryDetailId, String tNotes, Integer } public static Tissue getTissue(@NonNull ResultSet rs) throws SQLException { - Tissue tissue = new Tissue( rs.getString("t." + DBConstants.TISSUE_ID), rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID), diff --git a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java index 1fb3cffb2..8fd133465 100644 --- a/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java +++ b/src/main/java/org/broadinstitute/dsm/db/TissueSmId.java @@ -1,15 +1,20 @@ 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 ( @@ -54,16 +59,18 @@ public static TissueSmId getSMIdsForTissueId(ResultSet rs) { TissueSmId tissueSmId = null; try { - if (rs.getString(DBConstants.SM_ID_PK) == null) + 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) + rs.getString("sm." + DBConstants.TISSUE_ID) ); - if(tissueSmId!=null) - tissueSmId.setDeleted(rs.getBoolean("sm."+DBConstants.DELETED)); + if (tissueSmId != null) { + tissueSmId.setDeleted(rs.getBoolean("sm." + DBConstants.DELETED)); + } } catch (SQLException e) { logger.error("problem getting tissue sm ids", e); @@ -71,12 +78,30 @@ public static TissueSmId getSMIdsForTissueId(ResultSet rs) { 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(String tissueId, String userId, String smIdType) { - String smIdId = new TissueSMIDDao().createNewSMIDForTissue(tissueId, userId, smIdType); - return smIdId; + public String createNewSmId(@NonNull String tissueId, String userId, @NonNull List 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); + } } } diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java index 19b8ae0fc..20221df8a 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/ddp/tissue/TissueSMIDDao.java @@ -1,5 +1,6 @@ package org.broadinstitute.dsm.db.dao.ddp.tissue; +import lombok.NonNull; import org.broadinstitute.ddp.db.SimpleResult; import org.broadinstitute.dsm.statics.DBConstants; import org.slf4j.Logger; @@ -17,9 +18,10 @@ public class TissueSMIDDao { public static final String SQL_GET_SM_ID_BASED_ON_TISSUE_ID=" SELECT * from sm_id sm where sm.tissue_id= ? and NOT sm.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 static final String SQL_INSERT_SM_ID = "INSERT INTO sm_id SET tissue_id = ?, sm_id_type_id = ?, sm_id_value=?, last_changed = ?, changed_by = ?"; public static final String SQL_INSERT_SM_ID_WITH_VALUE = "INSERT INTO sm_id SET tissue_id = ?, sm_id_type_id = ?, last_changed = ?, changed_by = ?, sm_id_value = ?"; - public static final String SQL_SELECT_SM_ID_VALUE = "SELECT sm_id_value from sm_id where sm_id_value = ? and Not deleted <=> 1"; + public static final String SQL_SELECT_SM_ID_VALUE_WITH_ID = "SELECT sm_id_value from sm_id where sm_id_value = ? and NOT sm_id_pk = ? and Not deleted <=> 1"; + public static final String SQL_SELECT_SM_ID_VALUE = "SELECT sm_id_value from sm_id where sm_id_value = ? and Not deleted <=> 1"; public String getTypeForName(String type) { SimpleResult results = inTransaction((conn) -> { @@ -87,15 +89,16 @@ public String createNewSMIDForTissueWithValue(String tissueId, String userId, St } } - public String createNewSMIDForTissue(String tissueId, String userId, String smIdType) { + public String createNewSMIDForTissue(String tissueId, String userId, @NonNull String smIdType, @NonNull String smIdValue) { 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); + stmt.setString(3, smIdValue); + stmt.setLong(4, System.currentTimeMillis()); + stmt.setString(5, userId); int result = stmt.executeUpdate(); if (result == 1) { try (ResultSet rs = stmt.getGeneratedKeys()) { @@ -126,6 +129,33 @@ public String createNewSMIDForTissue(String tissueId, String userId, String smId } } + public boolean isUnique(String smIdValue, String smIdPk) { + SimpleResult results = inTransaction((conn) -> { + SimpleResult dbVals = new SimpleResult(); + try (PreparedStatement stmt = conn.prepareStatement(SQL_SELECT_SM_ID_VALUE_WITH_ID)) { + stmt.setString(1, smIdValue); + stmt.setString(2, smIdPk);// added to let updating + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + dbVals.resultValue = false; + } + else{ + dbVals.resultValue = true; + } + } + } + catch (SQLException ex) { + dbVals.resultException = ex; + } + return dbVals; + }); + + if (results.resultException != null) { + throw new RuntimeException("Error getting values from sm_id table matching " + smIdValue, results.resultException); + } + + return (boolean) results.resultValue; + } public boolean isUnique(String smIdValue) { SimpleResult results = inTransaction((conn) -> { diff --git a/src/main/java/org/broadinstitute/dsm/model/TissueList.java b/src/main/java/org/broadinstitute/dsm/model/TissueList.java index 945d4b3b6..2782b0d14 100644 --- a/src/main/java/org/broadinstitute/dsm/model/TissueList.java +++ b/src/main/java/org/broadinstitute/dsm/model/TissueList.java @@ -21,7 +21,7 @@ @Data public class TissueList { public static final Logger logger = LoggerFactory.getLogger(TissueList.class); - public static final String SQL_SELECT_ALL_ONC_HISTORY_TISSUE_FOR_REALM = "SELECT p.ddp_participant_id," + + public static final String SQL_SELECT_ALL_ONC_HISTORY_TISSUE_FOR_REALM = "SELECT p.ddp_participant_id, p.participant_id, " + "oD.onc_history_detail_id, oD.request, oD.deleted, oD.fax_sent, oD.tissue_received, oD.medical_record_id, oD.date_px, oD.type_px, " + "oD.location_px, oD.histology, oD.accession_number, oD.facility, oD.phone, oD.fax, oD.notes, oD.additional_values_json, " + "oD.request, oD.fax_sent, oD.fax_sent_by, oD.fax_confirmed, oD.fax_sent_2, oD.fax_sent_2_by, oD.fax_confirmed_2, oD.fax_sent_3, " + @@ -42,11 +42,13 @@ public class TissueList { private OncHistoryDetail oncHistoryDetails; private Tissue tissue; private String ddpParticipantId; + private String participantId; - public TissueList(OncHistoryDetail OncHistoryDetails, Tissue tissue, String ddpParticipantId) { + public TissueList(OncHistoryDetail OncHistoryDetails, Tissue tissue, String ddpParticipantId, String participantId) { this.oncHistoryDetails = OncHistoryDetails; this.tissue = tissue; this.ddpParticipantId = ddpParticipantId; + this.participantId = participantId; } @@ -64,9 +66,8 @@ public static List getAllTissueListsForRealm(String realm, String qu stmt.setString(1, realm); try (ResultSet rs = stmt.executeQuery()) { OncHistoryDetail oncHistory = null; - String ptId = null; while (rs.next()) { - ptId = rs.getString(DBConstants.DDP_PARTICIPANT_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.DDP_PARTICIPANT_ID); + String participantId = rs.getString(DBConstants.DDP_PARTICIPANT_ALIAS + DBConstants.ALIAS_DELIMITER + DBConstants.PARTICIPANT_ID); TissueSmId tissueSmId = Tissue.getSMIds(rs); Tissue tissue; if (tissueSmId != null && tissues.containsKey(tissueSmId.getTissueId())) { @@ -87,12 +88,23 @@ public static List getAllTissueListsForRealm(String realm, String qu } } for (Tissue tissue : tissues.values()) { - TissueList tissueList = new TissueList(oncHistoryDetailHashMap.get(tissue.getOncHistoryDetailId()), null, ptId); - - if (!tissue.isTDeleted() && StringUtils.isNotBlank(tissue.getTissueId())) { - tissueList.setTissue(tissue); + String tissueOncHistoryDetailId = tissue.getOncHistoryDetailId(); + OncHistoryDetail oncHistoryDetail = oncHistoryDetailHashMap.get(tissueOncHistoryDetailId); + oncHistoryDetail.getTissues().add(tissue); + }// add onchistories to their particiapnt + for (OncHistoryDetail oncHistoryDetail : oncHistoryDetailHashMap.values()) { + if (oncHistoryDetail.getTissues() == null || oncHistoryDetail.getTissues().isEmpty()){ + TissueList tissueList = new TissueList(oncHistoryDetail, null, oncHistoryDetail.getDdpParticipantId(), oncHistoryDetail.getParticipantId()); + results.add(tissueList); + continue; + } + for (Tissue tissue : oncHistoryDetail.getTissues()) { + TissueList tissueList = new TissueList(oncHistoryDetail, null, oncHistoryDetail.getDdpParticipantId(), oncHistoryDetail.getParticipantId()); + if (!tissue.isTDeleted() && StringUtils.isNotBlank(tissue.getTissueId())) { + tissueList.setTissue(tissue); + } + results.add(tissueList); } - results.add(tissueList); } dbVals.resultValue = results; } diff --git a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java index 47899ef83..835c3fc73 100644 --- a/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/PatchRoute.java @@ -140,8 +140,8 @@ else if (EventTypeDao.EVENT.equals(action.getType())) { } else { // mr changes - if(Patch.TISSUEID.equals(patch.getParent()) && patch.getNameValue().getName().equals(Patch.SM_ID_VALUE)){ - if(StringUtils.isNotBlank(String.valueOf(patch.getNameValue().getValue())) && !TissueSmId.isUniqueSmId(String.valueOf(patch.getNameValue().getValue()))){ + if (Patch.TISSUEID.equals(patch.getParent()) && patch.getNameValue().getName().equals(Patch.SM_ID_VALUE)) { + if (StringUtils.isNotBlank(String.valueOf(patch.getNameValue().getValue())) && !TissueSmId.isUniqueSmId(String.valueOf(patch.getNameValue().getValue()), patch.getId())) { return new Result(500, "Duplicate value"); } } @@ -280,10 +280,14 @@ else if (Patch.ONC_HISTORY_ID.equals(patch.getParent())) { } } else if (Patch.TISSUEID.equals(patch.getParent())) { - String smIdPk = new TissueSmId().createNewSmId(patch.getParentId(), patch.getUser(), (String) patch.getNameValue().getValue()); - Map map = new HashMap<>(); - map.put("smId", smIdPk); - return new Result(200, gson.toJson(map)); + try { + String smIdPk = new TissueSmId().createNewSmId(patch.getParentId(), patch.getUser(), patch.getNameValues()); + Map map = new HashMap<>(); + map.put("smId", smIdPk); + return new Result(200, gson.toJson(map)); + }catch (DuplicateException e) { + return new Result(500, "Duplicate value"); + } } else if (Patch.PARTICIPANT_DATA_ID.equals(patch.getParent())) { String participantDataId = null; From 212bba9d544ebe458a180bb580ad4af401ba88c9 Mon Sep 17 00:00:00 2001 From: pegahtah Date: Mon, 3 Jan 2022 13:00:51 -0500 Subject: [PATCH 20/20] fixed the clinical kit bug and added more conditions for creating the random clinical kit --- .../dsm/db/dao/kit/BSPDummyKitDao.java | 3 ++- .../dsm/route/CreateClinicalDummyKitRoute.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java b/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java index b1869d7ee..64b9b1df2 100644 --- a/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java +++ b/src/main/java/org/broadinstitute/dsm/db/dao/kit/BSPDummyKitDao.java @@ -89,12 +89,13 @@ public Optional getRandomParticipantIdForStudy(String ddpInstanceId) { public 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))) { + try (PreparedStatement stmt = conn.prepareStatement(DBUtil.getFinalQuery(OncHistoryDetail.SQL_SELECT_ONC_HISTORY_DETAIL + " AND oD.accession_number is not null ", SQL_SELECT_RANDOM_SUFFIX))) { stmt.setString(1, ddpInstanceName); ResultSet rs = stmt.executeQuery(); if (rs.next()) { dbVals.resultValue = rs.getString(DBConstants.ONC_HISTORY_DETAIL_ID); }else{ + throw new RuntimeException("Couldn't find a valid random onc history with accession number in realm "+ddpInstanceName); } } diff --git a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java index c257b3284..fd1d6c0bd 100644 --- a/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java +++ b/src/main/java/org/broadinstitute/dsm/route/CreateClinicalDummyKitRoute.java @@ -81,17 +81,24 @@ else if (kitTypeString.equalsIgnoreCase(FFPE_SECTION)) { else { throw new RuntimeException("The FFPE kit type does not match any of the valid types " + kitTypeString); } + int tries = 0; String randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); OncHistoryDetail oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); - String ddpParticipantId = oncHistoryDetail.getParticipantId(); + String ddpParticipantId = oncHistoryDetail.getDdpParticipantId(); Optional maybeParticipant = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); logger.info("found randomOncHistoryDetailId " + randomOncHistoryDetailId); - while (oncHistoryDetail == null || StringUtils.isBlank(oncHistoryDetail.getAccessionNumber()) || maybeParticipant.isEmpty() || maybeParticipant.get().getProfile().map(ESProfile::getHruid).isEmpty()) { + logger.info("found short id " + maybeParticipant.get().getProfile().map(ESProfile::getHruid)); + while (tries < 10 && (oncHistoryDetail == null || StringUtils.isBlank(oncHistoryDetail.getAccessionNumber()) || maybeParticipant.isEmpty() || maybeParticipant.get().getProfile().map(ESProfile::getHruid).isEmpty())) { randomOncHistoryDetailId = bspDummyKitDao.getRandomOncHistoryForStudy(ddpInstance.getName()); oncHistoryDetail = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()); - ddpParticipantId = oncHistoryDetail.getParticipantId(); - logger.info("found randomOncHistoryDetailId " + randomOncHistoryDetailId); + ddpParticipantId = oncHistoryDetail.getDdpParticipantId(); maybeParticipant = ElasticSearchUtil.getParticipantESDataByParticipantId(ddpInstance.getParticipantIndexES(), ddpParticipantId); + logger.info("found randomOncHistoryDetailId " + randomOncHistoryDetailId); + logger.info("found short id " + maybeParticipant.get().getProfile().map(ESProfile::getHruid)); + tries++; + } + if(tries >= 10 ){ + throw new RuntimeException("couldn't find a valid onc history to create dummy"); } List tissueIds = OncHistoryDetail.getOncHistoryDetail(randomOncHistoryDetailId, ddpInstance.getName()).getTissues(); String tissueId;