Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@
*/
package io.redlink.more.studymanager.model.transformer;

import io.redlink.more.studymanager.api.v1.model.AdherenceCheckScheduleEnumDTO;
import io.redlink.more.studymanager.api.v1.model.GoalAdherenceCheckDTO;
import io.redlink.more.studymanager.api.v1.model.GoalConfigurationDTO;
import io.redlink.more.studymanager.api.v1.model.GoalConsentDTO;
import io.redlink.more.studymanager.api.v1.model.GoalTemplateCategoriesDTO;
import io.redlink.more.studymanager.api.v1.model.GoalTemplateDTO;
import io.redlink.more.studymanager.api.v1.model.GoalTopicDTO;
import io.redlink.more.studymanager.api.v1.model.IntegrationInfoDTO;
import io.redlink.more.studymanager.api.v1.model.InterventionDTO;
import io.redlink.more.studymanager.api.v1.model.ParticipantInfoDTO;
import io.redlink.more.studymanager.api.v1.model.StudyImportExportDTO;
import io.redlink.more.studymanager.core.properties.GoalTemplateProperties;
import io.redlink.more.studymanager.model.GoalAdherenceCheck;
import io.redlink.more.studymanager.model.GoalTemplate;
import io.redlink.more.studymanager.model.GoalTopic;
import io.redlink.more.studymanager.model.IntegrationInfo;
import io.redlink.more.studymanager.model.StudyImportExport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand All @@ -23,6 +37,8 @@

public final class ImportExportTransformer {

private static final Logger log = LoggerFactory.getLogger(ImportExportTransformer.class);

private ImportExportTransformer() {}

public static StudyImportExport fromStudyImportExportDTO_V1(StudyImportExportDTO dto) {
Expand All @@ -47,7 +63,53 @@ public static StudyImportExport fromStudyImportExportDTO_V1(StudyImportExportDTO
))
)
.setParticipants(transform(dto.getParticipants(), ImportExportTransformer::fromParticipantDTO_V1))
.setIntegrations(transform(dto.getIntegrations(), ImportExportTransformer::fromIntegrationExportDTO_V1));
.setIntegrations(transform(dto.getIntegrations(), ImportExportTransformer::fromIntegrationExportDTO_V1))
.setStudyGoalConfig(fromStudyGoalConfigDTO_V1(dto.getStudy().getStudyId(), dto.getGoalConfiguration()))
.setGoalTemplates(transform(dto.getGoalTemplates(), ImportExportTransformer::fromGoalTemplateDTO_V1));
}

private static GoalTemplate fromGoalTemplateDTO_V1(GoalTemplateDTO dto) {
return new GoalTemplate()
.setStudyId(dto.getStudyId())
.setTemplateId(dto.getTemplateId())
.setType(dto.getType())
.setKind(dto.getCategories().getKind().getValue())
.setTopicKeys(Set.copyOf(dto.getCategories().getTopics()))
.setAdherenceCheckIds(dto.getAdherenceChecks().stream().map(AdherenceCheckScheduleEnumDTO::ordinal).collect(Collectors.toSet()))
.setObservationGroupIds(dto.getObservationGroupIds())
.setStudyGroupId(dto.getStudyGroupId())
.setTitle(dto.getTitle())
.setParticipantTitle(dto.getParticipantTitle())
.setParticipantInfo(dto.getParticipantInfo())
.setProperties(new GoalTemplateProperties(dto.getProperties()));


}

private static StudyImportExport.StudyGoalConfigData fromStudyGoalConfigDTO_V1(long studyId, GoalConfigurationDTO dto) {
var config = new StudyImportExport.StudyGoalConfigData(studyId);
config.setAchievability(dto.getConsent() == null ? null : dto.getConsent().getAchievability())
.setCommitment(dto.getConsent() == null ? null : dto.getConsent().getCommitment())
.setUnderstandability(dto.getConsent() == null ? null : dto.getConsent().getUnderstandability());
config.setTopics(transform(dto.getTopics(), gtDto -> fromGoalTopicDTO_V1(studyId, gtDto)));
config.setAdherenceChecks(transform(dto.getAdherenceChecks(), acDto -> fromAdherenceCheckDTO_V1(studyId, acDto)));
return config;
}

private static GoalAdherenceCheck fromAdherenceCheckDTO_V1(long studyId, GoalAdherenceCheckDTO dto) {
return new GoalAdherenceCheck()
.setStudyId(studyId)
.setCheckId(dto.getCheck().ordinal())
.setTitle(dto.getCheck().getValue())
.setTime(dto.getTime());
}

private static GoalTopic fromGoalTopicDTO_V1(long studyId, GoalTopicDTO dto) {
return new GoalTopic()
.setStudyId(studyId)
.setKey(dto.getKey())
.setTitle(dto.getTitle())
.setDescription(dto.getDescription());
}

public static StudyImportExportDTO toStudyImportExportDTO_V1(StudyImportExport studyImportExport) {
Expand All @@ -71,7 +133,57 @@ public static StudyImportExportDTO toStudyImportExportDTO_V1(StudyImportExport s
)
))
.participants(transform(studyImportExport.getParticipants(), ImportExportTransformer::toParticipantDTO_V1))
.integrations(transform(studyImportExport.getIntegrations(), ImportExportTransformer::toIntegrationInfoDTO_V1));
.integrations(transform(studyImportExport.getIntegrations(), ImportExportTransformer::toIntegrationInfoDTO_V1))
.goalConfiguration(toGoalConfigurationDTO_V1(studyImportExport.getStudyGoalConfig()))
.goalTemplates(transform(studyImportExport.getGoalTemplates(), ImportExportTransformer::toGoalTemplateDTO_V1));
}

private static GoalConfigurationDTO toGoalConfigurationDTO_V1(StudyImportExport.StudyGoalConfigData goalConfig){
return new GoalConfigurationDTO()
.consent(new GoalConsentDTO()
.achievability(goalConfig.getAchievability())
.commitment(goalConfig.getCommitment())
.understandability(goalConfig.getUnderstandability()))
.topics(transform(goalConfig.getTopics(), ImportExportTransformer::toGoalTopicDTO_V1))
.adherenceChecks(transform(goalConfig.getAdherenceChecks(), ImportExportTransformer::goalAdherenceCheckDTO_V1));
}

private static GoalTopicDTO toGoalTopicDTO_V1(GoalTopic goalTopic){
return new GoalTopicDTO()
.title(goalTopic.getTitle())
.key(goalTopic.getKey())
.description(goalTopic.getDescription());
}

private static GoalTemplateDTO toGoalTemplateDTO_V1(GoalTemplate goalTemplate){
return new GoalTemplateDTO()
.studyId(goalTemplate.getStudyId())
.title(goalTemplate.getTitle())
.templateId(goalTemplate.getTemplateId())
.adherenceChecks(transform(goalTemplate.getAdherenceCheckIds(), ImportExportTransformer::toAdherenceCheckEnumDTO_V1))
.categories(toGoalTemplateCategoriesDTO_V1(goalTemplate))
.observationGroupIds(goalTemplate.getObservationGroupIds())
.studyGroupId(goalTemplate.getStudyGroupId())
.type(goalTemplate.getType())
.participantInfo(goalTemplate.getParticipantInfo())
.participantTitle(goalTemplate.getParticipantTitle())
.properties(goalTemplate.getProperties());
}

private static GoalTemplateCategoriesDTO toGoalTemplateCategoriesDTO_V1(GoalTemplate goalTemplate){
return new GoalTemplateCategoriesDTO()
.kind(GoalTemplateCategoriesDTO.KindEnum.fromValue(goalTemplate.getKind()))
.topics(goalTemplate.getTopicKeys() == null ? null : List.copyOf(goalTemplate.getTopicKeys()));
}

private static AdherenceCheckScheduleEnumDTO toAdherenceCheckEnumDTO_V1(Integer adherenceCheckId){
return AdherenceCheckScheduleEnumDTO.values()[adherenceCheckId];
}

private static GoalAdherenceCheckDTO goalAdherenceCheckDTO_V1(GoalAdherenceCheck goalAdherenceCheck){
return new GoalAdherenceCheckDTO()
.check(AdherenceCheckScheduleEnumDTO.values()[goalAdherenceCheck.getCheckId()]) //we store the ordinal as checkID
.time(goalAdherenceCheck.getTime());
}

private static ParticipantInfoDTO toParticipantDTO_V1(StudyImportExport.ParticipantInfo participant) {
Expand All @@ -86,9 +198,9 @@ private static StudyImportExport.ParticipantInfo fromParticipantDTO_V1(Participa
participant.getObservationGroups() == null ? Collections.emptySet() : participant.getObservationGroups());
}

private static <S, T> List<T> transform(List<S> list, Function<S, T> transformer) {
if (list == null) { return List.of(); }
return list.stream().map(transformer).toList();
private static <S, T> List<T> transform(Collection<S> elements, Function<S, T> transformer) {
if (elements == null) { return List.of(); }
return elements.stream().map(transformer).toList();
}

private static IntegrationInfoDTO toIntegrationInfoDTO_V1(IntegrationInfo integration) {
Expand Down
47 changes: 47 additions & 0 deletions studymanager/src/main/resources/openapi/StudyManagerAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,12 @@ components:
type: array
items:
$ref: '#/components/schemas/IntegrationInfo'
goalConfiguration:
$ref: '#/components/schemas/GoalConfiguration'
goalTemplates:
type: array
items:
$ref: '#/components/schemas/GoalTemplate'

ParticipantInfo:
type: object
Expand All @@ -2721,6 +2727,47 @@ components:
observationId:
$ref: '#/components/schemas/Id'

GoalConfiguration:
type: object
properties:
consent:
$ref: '#/components/schemas/GoalConsent'
topics:
type: array
items:
$ref: '#/components/schemas/GoalTopic'
adherenceChecks:
type: array
items:
$ref: '#/components/schemas/GoalAdherenceCheck'
required:
- topics
- adherenceChecks

GoalConsent:
type: object
properties:
commitment:
type: string
achievability:
type: string
understandability:
type: string

GoalAdherenceCheck:
type: object
description: aktivates an adherence check enum member for the study and assigns a time to it
properties:
check:
$ref: '#/components/schemas/AdherenceCheckScheduleEnum'
time:
type: string
format: time
required:
- check
- time


UserSearchResultList:
type: object
properties:
Expand Down
Loading
Loading