Skip to content

Commit

Permalink
Issue #111: requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
drtyyj committed Apr 18, 2024
1 parent c29528d commit 2e4eb69
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.redlink.more.data.api.app.v1.model.ParticipantDTO;
import io.redlink.more.data.api.app.v1.webservices.ExternalDataApi;
import io.redlink.more.data.controller.transformer.DataTransformer;
import io.redlink.more.data.controller.transformer.StudyTransformer;
import io.redlink.more.data.controller.transformer.ParticipantTransformer;
import io.redlink.more.data.exception.BadRequestException;
import io.redlink.more.data.model.ApiRoutingInfo;
import io.redlink.more.data.model.RoutingInfo;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ResponseEntity<List<ParticipantDTO>> listParticipants(String moreApiToken
return ResponseEntity.ok(
externalService.listParticipants(apiRoutingInfo.studyId(), apiRoutingInfo.studyGroupId())
.stream()
.map(StudyTransformer::toDTO)
.map(ParticipantTransformer::toDTO)
.toList()
);
} catch(IndexOutOfBoundsException | NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.redlink.more.data.controller.transformer;

import io.redlink.more.data.api.app.v1.model.ParticipantDTO;
import io.redlink.more.data.api.app.v1.model.ParticipantStatusDTO;
import io.redlink.more.data.model.Participant;

public final class ParticipantTransformer {

private ParticipantTransformer() {}

public static ParticipantDTO toDTO(Participant participant) {
if(participant == null) {
return null;
}
return new ParticipantDTO(
String.valueOf(participant.id()),
participant.alias(),
ParticipantStatusDTO.fromValue(participant.status()),
participant.studyGroupId(),
BaseTransformers.toOffsetDateTime(participant.start())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ public static SimpleParticipantDTO toDTO(SimpleParticipant participant) {
.alias(participant.alias());
}

public static ParticipantDTO toDTO(Participant participant) {
if(participant == null) {
return null;
}
return new ParticipantDTO(
participant.id(),
participant.alias(),
ParticipantStatusDTO.fromValue(participant.status()),
participant.studyGroupId(),
BaseTransformers.toOffsetDateTime(participant.start())
);
}

public static ContactInfoDTO toDTO(Contact contact) {
return new ContactInfoDTO()
.institute(contact.institute())
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/io/redlink/more/data/repository/StudyRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ public class StudyRepository {

private static final String SQL_LIST_PARTICIPANTS_BY_STUDY =
"SELECT participant_id, alias, status, study_group_id, start FROM participants " +
"WHERE study_id = ?";

private static final String SQL_LIST_PARTICIPANTS_BY_STUDY_AND_GROUP =
"SELECT participant_id, alias, status, study_group_id, start FROM participants " +
"WHERE study_id = ? AND study_group_id = ?";
"WHERE study_id = :study_id AND (study_group_id = :study_group_id OR :study_group_id::INT IS NULL)";

private static final String GET_OBSERVATION_PROPERTIES_FOR_PARTICIPANT =
"SELECT properties FROM participant_observation_properties " +
Expand Down Expand Up @@ -202,9 +198,19 @@ public Optional<SimpleParticipant> findParticipant(RoutingInfo routingInfo) {

public List<Participant> listParticipants(long studyId, int groupId) {
if(groupId < 0) {
return jdbcTemplate.query(SQL_LIST_PARTICIPANTS_BY_STUDY, getParticipantRowMapper(), studyId);
return namedTemplate.query(
SQL_LIST_PARTICIPANTS_BY_STUDY,
new MapSqlParameterSource()
.addValue("study_id", studyId)
.addValue("study_group_id", null),
getParticipantRowMapper());
} else {
return jdbcTemplate.query(SQL_LIST_PARTICIPANTS_BY_STUDY_AND_GROUP, getParticipantRowMapper(), studyId, groupId);
return namedTemplate.query(
SQL_LIST_PARTICIPANTS_BY_STUDY,
new MapSqlParameterSource()
.addValue("study_id", studyId)
.addValue("study_group_id", groupId),
getParticipantRowMapper());
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/openapi/ExternalAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ components:
description: A participant for a study
properties:
participantId:
type: integer
format: int32
type: string
alias:
type: string
status:
Expand Down

0 comments on commit 2e4eb69

Please sign in to comment.