Skip to content

Commit 97673e3

Browse files
author
Rupert Westenthaler
committed
MORE-Platform#385: GoalConfig and GoalTemplates are now included in the Import/Export Webservice API! Implementation + UnitTest extensions
1 parent 7f3517d commit 97673e3

3 files changed

Lines changed: 323 additions & 14 deletions

File tree

studymanager/src/main/java/io/redlink/more/studymanager/model/transformer/ImportExportTransformer.java

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@
88
*/
99
package io.redlink.more.studymanager.model.transformer;
1010

11+
import io.redlink.more.studymanager.api.v1.model.AdherenceCheckScheduleEnumDTO;
12+
import io.redlink.more.studymanager.api.v1.model.GoalAdherenceCheckDTO;
13+
import io.redlink.more.studymanager.api.v1.model.GoalConfigurationDTO;
14+
import io.redlink.more.studymanager.api.v1.model.GoalConsentDTO;
15+
import io.redlink.more.studymanager.api.v1.model.GoalTemplateCategoriesDTO;
16+
import io.redlink.more.studymanager.api.v1.model.GoalTemplateDTO;
17+
import io.redlink.more.studymanager.api.v1.model.GoalTopicDTO;
1118
import io.redlink.more.studymanager.api.v1.model.IntegrationInfoDTO;
1219
import io.redlink.more.studymanager.api.v1.model.InterventionDTO;
1320
import io.redlink.more.studymanager.api.v1.model.ParticipantInfoDTO;
1421
import io.redlink.more.studymanager.api.v1.model.StudyImportExportDTO;
22+
import io.redlink.more.studymanager.core.properties.GoalTemplateProperties;
23+
import io.redlink.more.studymanager.model.GoalAdherenceCheck;
24+
import io.redlink.more.studymanager.model.GoalTemplate;
25+
import io.redlink.more.studymanager.model.GoalTopic;
1526
import io.redlink.more.studymanager.model.IntegrationInfo;
1627
import io.redlink.more.studymanager.model.StudyImportExport;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
1730

31+
import java.util.Collection;
1832
import java.util.Collections;
1933
import java.util.List;
2034
import java.util.Set;
@@ -23,6 +37,8 @@
2337

2438
public final class ImportExportTransformer {
2539

40+
private static final Logger log = LoggerFactory.getLogger(ImportExportTransformer.class);
41+
2642
private ImportExportTransformer() {}
2743

2844
public static StudyImportExport fromStudyImportExportDTO_V1(StudyImportExportDTO dto) {
@@ -47,7 +63,53 @@ public static StudyImportExport fromStudyImportExportDTO_V1(StudyImportExportDTO
4763
))
4864
)
4965
.setParticipants(transform(dto.getParticipants(), ImportExportTransformer::fromParticipantDTO_V1))
50-
.setIntegrations(transform(dto.getIntegrations(), ImportExportTransformer::fromIntegrationExportDTO_V1));
66+
.setIntegrations(transform(dto.getIntegrations(), ImportExportTransformer::fromIntegrationExportDTO_V1))
67+
.setStudyGoalConfig(fromStudyGoalConfigDTO_V1(dto.getStudy().getStudyId(), dto.getGoalConfiguration()))
68+
.setGoalTemplates(transform(dto.getGoalTemplates(), ImportExportTransformer::fromGoalTemplateDTO_V1));
69+
}
70+
71+
private static GoalTemplate fromGoalTemplateDTO_V1(GoalTemplateDTO dto) {
72+
return new GoalTemplate()
73+
.setStudyId(dto.getStudyId())
74+
.setTemplateId(dto.getTemplateId())
75+
.setType(dto.getType())
76+
.setKind(dto.getCategories().getKind().getValue())
77+
.setTopicKeys(Set.copyOf(dto.getCategories().getTopics()))
78+
.setAdherenceCheckIds(dto.getAdherenceChecks().stream().map(AdherenceCheckScheduleEnumDTO::ordinal).collect(Collectors.toSet()))
79+
.setObservationGroupIds(dto.getObservationGroupIds())
80+
.setStudyGroupId(dto.getStudyGroupId())
81+
.setTitle(dto.getTitle())
82+
.setParticipantTitle(dto.getParticipantTitle())
83+
.setParticipantInfo(dto.getParticipantInfo())
84+
.setProperties(new GoalTemplateProperties(dto.getProperties()));
85+
86+
87+
}
88+
89+
private static StudyImportExport.StudyGoalConfigData fromStudyGoalConfigDTO_V1(long studyId, GoalConfigurationDTO dto) {
90+
var config = new StudyImportExport.StudyGoalConfigData(studyId);
91+
config.setAchievability(dto.getConsent() == null ? null : dto.getConsent().getAchievability())
92+
.setCommitment(dto.getConsent() == null ? null : dto.getConsent().getCommitment())
93+
.setUnderstandability(dto.getConsent() == null ? null : dto.getConsent().getUnderstandability());
94+
config.setTopics(transform(dto.getTopics(), gtDto -> fromGoalTopicDTO_V1(studyId, gtDto)));
95+
config.setAdherenceChecks(transform(dto.getAdherenceChecks(), acDto -> fromAdherenceCheckDTO_V1(studyId, acDto)));
96+
return config;
97+
}
98+
99+
private static GoalAdherenceCheck fromAdherenceCheckDTO_V1(long studyId, GoalAdherenceCheckDTO dto) {
100+
return new GoalAdherenceCheck()
101+
.setStudyId(studyId)
102+
.setCheckId(dto.getCheck().ordinal())
103+
.setTitle(dto.getCheck().getValue())
104+
.setTime(dto.getTime());
105+
}
106+
107+
private static GoalTopic fromGoalTopicDTO_V1(long studyId, GoalTopicDTO dto) {
108+
return new GoalTopic()
109+
.setStudyId(studyId)
110+
.setKey(dto.getKey())
111+
.setTitle(dto.getTitle())
112+
.setDescription(dto.getDescription());
51113
}
52114

53115
public static StudyImportExportDTO toStudyImportExportDTO_V1(StudyImportExport studyImportExport) {
@@ -71,7 +133,57 @@ public static StudyImportExportDTO toStudyImportExportDTO_V1(StudyImportExport s
71133
)
72134
))
73135
.participants(transform(studyImportExport.getParticipants(), ImportExportTransformer::toParticipantDTO_V1))
74-
.integrations(transform(studyImportExport.getIntegrations(), ImportExportTransformer::toIntegrationInfoDTO_V1));
136+
.integrations(transform(studyImportExport.getIntegrations(), ImportExportTransformer::toIntegrationInfoDTO_V1))
137+
.goalConfiguration(toGoalConfigurationDTO_V1(studyImportExport.getStudyGoalConfig()))
138+
.goalTemplates(transform(studyImportExport.getGoalTemplates(), ImportExportTransformer::toGoalTemplateDTO_V1));
139+
}
140+
141+
private static GoalConfigurationDTO toGoalConfigurationDTO_V1(StudyImportExport.StudyGoalConfigData goalConfig){
142+
return new GoalConfigurationDTO()
143+
.consent(new GoalConsentDTO()
144+
.achievability(goalConfig.getAchievability())
145+
.commitment(goalConfig.getCommitment())
146+
.understandability(goalConfig.getUnderstandability()))
147+
.topics(transform(goalConfig.getTopics(), ImportExportTransformer::toGoalTopicDTO_V1))
148+
.adherenceChecks(transform(goalConfig.getAdherenceChecks(), ImportExportTransformer::goalAdherenceCheckDTO_V1));
149+
}
150+
151+
private static GoalTopicDTO toGoalTopicDTO_V1(GoalTopic goalTopic){
152+
return new GoalTopicDTO()
153+
.title(goalTopic.getTitle())
154+
.key(goalTopic.getKey())
155+
.description(goalTopic.getDescription());
156+
}
157+
158+
private static GoalTemplateDTO toGoalTemplateDTO_V1(GoalTemplate goalTemplate){
159+
return new GoalTemplateDTO()
160+
.studyId(goalTemplate.getStudyId())
161+
.title(goalTemplate.getTitle())
162+
.templateId(goalTemplate.getTemplateId())
163+
.adherenceChecks(transform(goalTemplate.getAdherenceCheckIds(), ImportExportTransformer::toAdherenceCheckEnumDTO_V1))
164+
.categories(toGoalTemplateCategoriesDTO_V1(goalTemplate))
165+
.observationGroupIds(goalTemplate.getObservationGroupIds())
166+
.studyGroupId(goalTemplate.getStudyGroupId())
167+
.type(goalTemplate.getType())
168+
.participantInfo(goalTemplate.getParticipantInfo())
169+
.participantTitle(goalTemplate.getParticipantTitle())
170+
.properties(goalTemplate.getProperties());
171+
}
172+
173+
private static GoalTemplateCategoriesDTO toGoalTemplateCategoriesDTO_V1(GoalTemplate goalTemplate){
174+
return new GoalTemplateCategoriesDTO()
175+
.kind(GoalTemplateCategoriesDTO.KindEnum.fromValue(goalTemplate.getKind()))
176+
.topics(goalTemplate.getTopicKeys() == null ? null : List.copyOf(goalTemplate.getTopicKeys()));
177+
}
178+
179+
private static AdherenceCheckScheduleEnumDTO toAdherenceCheckEnumDTO_V1(Integer adherenceCheckId){
180+
return AdherenceCheckScheduleEnumDTO.values()[adherenceCheckId];
181+
}
182+
183+
private static GoalAdherenceCheckDTO goalAdherenceCheckDTO_V1(GoalAdherenceCheck goalAdherenceCheck){
184+
return new GoalAdherenceCheckDTO()
185+
.check(AdherenceCheckScheduleEnumDTO.values()[goalAdherenceCheck.getCheckId()]) //we store the ordinal as checkID
186+
.time(goalAdherenceCheck.getTime());
75187
}
76188

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

89-
private static <S, T> List<T> transform(List<S> list, Function<S, T> transformer) {
90-
if (list == null) { return List.of(); }
91-
return list.stream().map(transformer).toList();
201+
private static <S, T> List<T> transform(Collection<S> elements, Function<S, T> transformer) {
202+
if (elements == null) { return List.of(); }
203+
return elements.stream().map(transformer).toList();
92204
}
93205

94206
private static IntegrationInfoDTO toIntegrationInfoDTO_V1(IntegrationInfo integration) {

studymanager/src/main/resources/openapi/StudyManagerAPI.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,12 @@ components:
27012701
type: array
27022702
items:
27032703
$ref: '#/components/schemas/IntegrationInfo'
2704+
goalConfiguration:
2705+
$ref: '#/components/schemas/GoalConfiguration'
2706+
goalTemplates:
2707+
type: array
2708+
items:
2709+
$ref: '#/components/schemas/GoalTemplate'
27042710

27052711
ParticipantInfo:
27062712
type: object
@@ -2721,6 +2727,47 @@ components:
27212727
observationId:
27222728
$ref: '#/components/schemas/Id'
27232729

2730+
GoalConfiguration:
2731+
type: object
2732+
properties:
2733+
consent:
2734+
$ref: '#/components/schemas/GoalConsent'
2735+
topics:
2736+
type: array
2737+
items:
2738+
$ref: '#/components/schemas/GoalTopic'
2739+
adherenceChecks:
2740+
type: array
2741+
items:
2742+
$ref: '#/components/schemas/GoalAdherenceCheck'
2743+
required:
2744+
- topics
2745+
- adherenceChecks
2746+
2747+
GoalConsent:
2748+
type: object
2749+
properties:
2750+
commitment:
2751+
type: string
2752+
achievability:
2753+
type: string
2754+
understandability:
2755+
type: string
2756+
2757+
GoalAdherenceCheck:
2758+
type: object
2759+
description: aktivates an adherence check enum member for the study and assigns a time to it
2760+
properties:
2761+
check:
2762+
$ref: '#/components/schemas/AdherenceCheckScheduleEnum'
2763+
time:
2764+
type: string
2765+
format: time
2766+
required:
2767+
- check
2768+
- time
2769+
2770+
27242771
UserSearchResultList:
27252772
type: object
27262773
properties:

0 commit comments

Comments
 (0)