88 */
99package 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 ;
1118import io .redlink .more .studymanager .api .v1 .model .IntegrationInfoDTO ;
1219import io .redlink .more .studymanager .api .v1 .model .InterventionDTO ;
1320import io .redlink .more .studymanager .api .v1 .model .ParticipantInfoDTO ;
1421import 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 ;
1526import io .redlink .more .studymanager .model .IntegrationInfo ;
1627import io .redlink .more .studymanager .model .StudyImportExport ;
28+ import org .slf4j .Logger ;
29+ import org .slf4j .LoggerFactory ;
1730
31+ import java .util .Collection ;
1832import java .util .Collections ;
1933import java .util .List ;
2034import java .util .Set ;
2337
2438public 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 ) {
0 commit comments