Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDP-6034-SMIDS #320

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/main/java/org/broadinstitute/dsm/db/MedicalRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@
import com.google.gson.Gson;
import lombok.Data;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;
import org.broadinstitute.ddp.db.SimpleResult;
import org.broadinstitute.ddp.handlers.util.InstitutionDetail;
import org.broadinstitute.ddp.handlers.util.MedicalInfo;
import org.broadinstitute.dsm.DSMServer;
import org.broadinstitute.dsm.db.structure.ColumnName;
import org.broadinstitute.dsm.db.structure.DbDateConversion;
import org.broadinstitute.dsm.db.structure.SqlDateConverter;
import org.broadinstitute.dsm.db.structure.TableName;
import org.broadinstitute.dsm.model.FollowUp;
import org.broadinstitute.dsm.statics.*;
import org.broadinstitute.dsm.statics.DBConstants;
import org.broadinstitute.dsm.statics.QueryExtension;
import org.broadinstitute.dsm.statics.RequestParameter;
import org.broadinstitute.dsm.statics.RoutePath;
import org.broadinstitute.dsm.util.DBUtil;
import org.broadinstitute.dsm.util.DDPRequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

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

Expand Down
117 changes: 104 additions & 13 deletions src/main/java/org/broadinstitute/dsm/db/OncHistoryDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

Expand All @@ -37,23 +40,25 @@ 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 " +
" 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) " +
"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," +
" phone, fax, notes, additional_values_json, request, fax_sent, fax_sent_by, fax_confirmed, fax_sent_2, fax_sent_2_by, fax_confirmed_2, fax_sent_3, fax_sent_3_by, fax_confirmed_3," +
" 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) " +
Expand Down Expand Up @@ -110,40 +115,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)
Expand Down Expand Up @@ -278,7 +283,12 @@ 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));
Copy link
Collaborator

Choose a reason for hiding this comment

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

participantId or ddpParticipantId?

}
catch (java.sql.SQLException e) {
oncHistoryDetail.setParticipantId(null);
}
return oncHistoryDetail;
}

Expand All @@ -300,17 +310,97 @@ public static Map<String, List<OncHistoryDetail>> getOncHistoryDetailsByParticip
public static Map<String, List<OncHistoryDetail>> getOncHistoryDetails(@NonNull String realm, String queryAddition) {
logger.info("Collection oncHistoryDetail information");
Map<String, List<OncHistoryDetail>> oncHistory = new HashMap<>();
HashMap<String, Tissue> 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)) {
stmt.setString(1, realm);
try (ResultSet rs = stmt.executeQuery()) {
Map<String, OncHistoryDetail> 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())) {
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<OncHistoryDetail> 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.getTissues().removeIf(tissue1 -> tissue1.getTissueId() == tissue.getTissueId());
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 Map<String, List<OncHistoryDetail>> getOncHistoryDetails(@NonNull String realm, String queryAddition, List<String> values) {
logger.info("Collection oncHistoryDetail information");
Map<String, List<OncHistoryDetail>> oncHistory = new HashMap<>();
HashMap<String, Tissue> 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)) {
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<String, OncHistoryDetail> 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);
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<OncHistoryDetail> oncHistoryDataList = new ArrayList<>();
Expand All @@ -325,6 +415,7 @@ public static Map<String, List<OncHistoryDetail>> 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 {
Expand Down
Loading