Search in sources :

Example 21 with ParticipantCohortStatus

use of org.pmiops.workbench.db.model.ParticipantCohortStatus in project workbench by all-of-us.

the class CohortReviewController method createParticipantCohortStatusesList.

/**
 * Helper method that builds a list of {@link ParticipantCohortStatus} from BigQuery results.
 *
 * @param cohortReviewId
 * @param result
 * @param rm
 * @return
 */
private List<ParticipantCohortStatus> createParticipantCohortStatusesList(Long cohortReviewId, QueryResult result, Map<String, Integer> rm) {
    List<ParticipantCohortStatus> participantCohortStatuses = new ArrayList<>();
    for (List<FieldValue> row : result.iterateAll()) {
        String birthDateTimeString = bigQueryService.getString(row, rm.get("birth_datetime"));
        if (birthDateTimeString == null) {
            throw new BigQueryException(500, "birth_datetime is null at position: " + rm.get("birth_datetime"));
        }
        java.util.Date birthDate = Date.from(Instant.ofEpochMilli(Double.valueOf(birthDateTimeString).longValue() * 1000));
        participantCohortStatuses.add(new ParticipantCohortStatus().participantKey(new ParticipantCohortStatusKey(cohortReviewId, bigQueryService.getLong(row, rm.get("person_id")))).status(CohortStatus.NOT_REVIEWED).birthDate(new java.sql.Date(birthDate.getTime())).genderConceptId(bigQueryService.getLong(row, rm.get("gender_concept_id"))).raceConceptId(bigQueryService.getLong(row, rm.get("race_concept_id"))).ethnicityConceptId(bigQueryService.getLong(row, rm.get("ethnicity_concept_id"))));
    }
    return participantCohortStatuses;
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ArrayList(java.util.ArrayList) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) FieldValue(com.google.cloud.bigquery.FieldValue) BigQueryException(com.google.cloud.bigquery.BigQueryException) Date(java.sql.Date)

Example 22 with ParticipantCohortStatus

use of org.pmiops.workbench.db.model.ParticipantCohortStatus in project workbench by all-of-us.

the class CohortMaterializationServiceTest method makeStatus.

private ParticipantCohortStatus makeStatus(long cohortReviewId, long participantId, CohortStatus status) {
    ParticipantCohortStatusKey key = new ParticipantCohortStatusKey();
    key.setCohortReviewId(cohortReviewId);
    key.setParticipantId(participantId);
    ParticipantCohortStatus result = new ParticipantCohortStatus();
    result.setStatus(status);
    result.setParticipantKey(key);
    return result;
}
Also used : ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey)

Example 23 with ParticipantCohortStatus

use of org.pmiops.workbench.db.model.ParticipantCohortStatus in project workbench by all-of-us.

the class ParticipantCohortStatusDaoImpl method saveParticipantCohortStatusesCustom.

@Override
public void saveParticipantCohortStatusesCustom(List<ParticipantCohortStatus> participantCohortStatuses) {
    Statement statement = null;
    Connection connection = null;
    int index = 0;
    String sqlStatement = INSERT_SQL_TEMPLATE;
    try {
        connection = jdbcTemplate.getDataSource().getConnection();
        statement = connection.createStatement();
        connection.setAutoCommit(false);
        for (ParticipantCohortStatus pcs : participantCohortStatuses) {
            String birthDate = pcs.getBirthDate() == null ? "NULL" : "'" + pcs.getBirthDate().toString() + "'";
            String nextSql = String.format(NEXT_INSERT, birthDate, pcs.getEthnicityConceptId(), pcs.getGenderConceptId(), pcs.getRaceConceptId(), // this represents NOT_REVIEWED
            3, pcs.getParticipantKey().getCohortReviewId(), pcs.getParticipantKey().getParticipantId());
            sqlStatement = sqlStatement.equals(INSERT_SQL_TEMPLATE) ? sqlStatement + nextSql : sqlStatement + ", " + nextSql;
            if (++index % BATCH_SIZE == 0) {
                statement.execute(sqlStatement);
                sqlStatement = INSERT_SQL_TEMPLATE;
            }
        }
        if (!sqlStatement.equals(INSERT_SQL_TEMPLATE)) {
            statement.execute(sqlStatement);
        }
        connection.commit();
    } catch (SQLException ex) {
        log.log(Level.INFO, "SQLException: " + ex.getMessage());
        rollback(connection);
        throw new RuntimeException("SQLException: " + ex.getMessage(), ex);
    } finally {
        turnOnAutoCommit(connection);
        close(statement);
        close(connection);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) Connection(java.sql.Connection)

Aggregations

ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)23 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)14 Test (org.junit.Test)12 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)9 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)9 Date (java.sql.Date)6 CohortReview (org.pmiops.workbench.db.model.CohortReview)6 Workspace (org.pmiops.workbench.db.model.Workspace)6 Filter (org.pmiops.workbench.model.Filter)5 ArrayList (java.util.ArrayList)4 Cohort (org.pmiops.workbench.db.model.Cohort)4 org.pmiops.workbench.model (org.pmiops.workbench.model)3 Timestamp (java.sql.Timestamp)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 BigQueryException (com.google.cloud.bigquery.BigQueryException)1 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryResult (com.google.cloud.bigquery.QueryResult)1 Gson (com.google.gson.Gson)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1