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;
}
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;
}
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);
}
}
Aggregations