Skip to content

Commit c5738fd

Browse files
committed
✨ display of questionnaire results
1 parent 36cba46 commit c5738fd

8 files changed

Lines changed: 71 additions & 18 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/survey/SurveyTokenFacade.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import javax.ejb.Remote;
2121
import javax.validation.Valid;
2222

23+
import de.symeda.sormas.api.survey.external.views.ExternalSurveyView;
2324
import de.symeda.sormas.api.utils.SortProperty;
2425
import de.symeda.sormas.api.utils.Tuple;
2526

@@ -51,4 +52,10 @@ public interface SurveyTokenFacade {
5152
boolean exists(String uuid);
5253

5354
SurveyTokenReferenceDto getReferenceByUuid(String uuid);
55+
56+
/**
57+
* Fetches the questionnaire view for a survey token from the external survey provider.
58+
* Returns null if the provider is unavailable or the token has no external respondent ID.
59+
*/
60+
ExternalSurveyView getExternalSurveyView(String surveyTokenUuid);
5461
}

sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/ExternalMessage.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public class ExternalMessage extends AbstractDomainObject {
229229

230230
private ExternalMessageAdditionalDataType additionalDataType;
231231

232-
private String additionalData;
232+
private String additionalDataJson;
233233

234234
@Enumerated(EnumType.STRING)
235235
public ExternalMessageType getType() {
@@ -948,12 +948,12 @@ public ExternalMessage setAdditionalDataType(ExternalMessageAdditionalDataType a
948948

949949
@Column(columnDefinition = "jsonb")
950950
@Type(type = "jsonb")
951-
public String getAdditionalData() {
952-
return additionalData;
951+
public String getAdditionalDataJson() {
952+
return additionalDataJson;
953953
}
954954

955-
public ExternalMessage setAdditionalData(String additionalData) {
956-
this.additionalData = additionalData;
955+
public ExternalMessage setAdditionalDataJson(String additionalData) {
956+
this.additionalDataJson = additionalData;
957957
return this;
958958
}
959959
}

sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/ExternalMessageFacadeEjb.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ public ExternalMessageDto toDto(ExternalMessage source) {
534534
target.setTuberculosisBeijingLineage(source.getTuberculosisBeijingLineage());
535535

536536
ExternalMessageAdditionalDataType additionalDataType = source.getAdditionalDataType();
537-
String additionalData = source.getAdditionalData();
538-
if (additionalDataType != null && additionalData != null) {
537+
String additionalDataJson = source.getAdditionalDataJson();
538+
if (additionalDataType != null && additionalDataJson != null) {
539539
try {
540-
Object additionalDataInstance = ObjectMapperProvider.getInstance().readValue(additionalData, additionalDataType.getDataClass());
540+
Object additionalDataInstance = ObjectMapperProvider.getInstance().readValue(additionalDataJson, additionalDataType.getDataClass());
541541
if (additionalDataInstance instanceof ExternalSurveyResponseData) {
542542
target.setSurveyResponseData((ExternalSurveyResponseData) additionalDataInstance);
543543
} else {

sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/survey/AutomaticSurveyResponseProcessor.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import de.symeda.sormas.api.externalmessage.survey.ExternalMessageSurveyResponseRequest;
2121
import de.symeda.sormas.api.externalmessage.survey.ExternalMessageSurveyResponseResult;
2222
import de.symeda.sormas.api.externalmessage.survey.ExternalMessageSurveyResponseWrapper;
23-
import de.symeda.sormas.api.externalmessage.survey.ExternalSurveyResponseData;
2423
import de.symeda.sormas.api.patch.CaseDataPatchRequest;
2524
import de.symeda.sormas.api.patch.DataPatchResponse;
2625
import de.symeda.sormas.api.patch.DataPatcher;
@@ -50,20 +49,17 @@ public class AutomaticSurveyResponseProcessor {
5049
public List<SurveyResponseProcessingResult> processSurveyResponses(List<ExternalMessageDto> externalMessages)
5150
throws InterruptedException, ExecutionException {
5251

53-
List<ExternalSurveyResponseData> surveyResponseWrappers =
54-
externalMessages.stream().map(ExternalMessageDto::getSurveyResponseData).collect(Collectors.toList());
55-
56-
Map<String, String> tokenByExternalTokenIdDictionary =
52+
Map<String, String> tokenByExternalSurveyIdDictionary =
5753
externalMessages.stream().map(ExternalMessageDto::getSurveyResponseData).map(responseData -> {
5854
ExternalMessageSurveyResponseRequest request = responseData.getLatest().getRequest();
5955
return new Tuple<>(request.getExternalSurveyId(), request.getToken());
6056
}).collect(CollectorUtils.toOrderedNullSafeMap(Tuple::getFirst, Tuple::getSecond));
6157

62-
List<String> externalSurveyIds = new ArrayList<>(tokenByExternalTokenIdDictionary.keySet());
58+
List<String> externalSurveyIds = new ArrayList<>(tokenByExternalSurveyIdDictionary.keySet());
6359

6460
List<Tuple<SurveyReferenceDto, String>> tokenBySurveyReferenceTuples = surveyFacade.getByExternalIds(externalSurveyIds)
6561
.stream()
66-
.map(survey -> new Tuple<>(survey.toReference(), tokenByExternalTokenIdDictionary.get(survey.getExternalId())))
62+
.map(survey -> new Tuple<>(survey.toReference(), tokenByExternalSurveyIdDictionary.get(survey.getExternalId())))
6763
.collect(Collectors.toList());
6864

6965
List<SurveyTokenDto> surveyTokens = surveyTokenFacade.getBySurveyReferenceTokenTuples(tokenBySurveyReferenceTuples);
@@ -86,10 +82,12 @@ public List<SurveyResponseProcessingResult> processSurveyResponses(List<External
8682
return surveyResponseProcessingResult.setResultStatus(ProcessingResultStatus.CANCELED);
8783
}
8884

85+
String requestToken = request.getToken();
8986
Optional<SurveyTokenDto> surveyToken =
90-
surveyTokens.stream().filter(tokenCandidate -> tokenCandidate.getToken().equals(request.getToken())).findAny();
87+
surveyTokens.stream().filter(tokenCandidate -> tokenCandidate.getToken().equals(requestToken)).findAny();
9188

9289
if (surveyToken.isEmpty()) {
90+
logger.error("Token could not be found within available survey token DTOs: [{}]. Survey response processing is cancelled.", requestToken);
9391
return surveyResponseProcessingResult.setResultStatus(ProcessingResultStatus.CANCELED);
9492
}
9593

sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/survey/SurveyResponseProcessingResult.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import de.symeda.sormas.api.externalmessage.ExternalMessageDto;
66
import de.symeda.sormas.api.utils.dataprocessing.ProcessingResultStatus;
77

8+
/**
9+
* Wrapper object once a SurveyResponse external message was processed.
10+
* Exceptions are caught to be able to continue with the next message from the list.
11+
*/
812
public class SurveyResponseProcessingResult {
913

1014
private ExternalMessageDto externalMessage;

sormas-backend/src/main/java/de/symeda/sormas/backend/survey/SurveyTokenFacadeEjb.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.ejb.EJB;
2727
import javax.ejb.LocalBean;
2828
import javax.ejb.Stateless;
29+
import javax.inject.Inject;
2930
import javax.persistence.EntityManager;
3031
import javax.persistence.PersistenceContext;
3132
import javax.persistence.Tuple;
@@ -44,6 +45,8 @@
4445
import de.symeda.sormas.api.survey.SurveyTokenFacade;
4546
import de.symeda.sormas.api.survey.SurveyTokenIndexDto;
4647
import de.symeda.sormas.api.survey.SurveyTokenReferenceDto;
48+
import de.symeda.sormas.api.survey.external.ExternalSurveyProviderFacade;
49+
import de.symeda.sormas.api.survey.external.views.ExternalSurveyView;
4750
import de.symeda.sormas.api.user.UserRight;
4851
import de.symeda.sormas.api.utils.DataHelper;
4952
import de.symeda.sormas.api.utils.SortProperty;
@@ -89,6 +92,8 @@ public class SurveyTokenFacadeEjb implements SurveyTokenFacade {
8992
private ConfigFacadeEjb.ConfigFacadeEjbLocal configFacade;
9093
@EJB
9194
private DocumentService documentService;
95+
@Inject
96+
private ExternalSurveyProviderFacade externalSurveyProviderFacade;
9297

9398
private static final String SURVEY_TOKEN_IMPORT_TEMPLATE_FILE_NAME = "import_survey_tokens_template.csv";
9499

@@ -307,10 +312,32 @@ private SurveyTokenDto toDto(SurveyToken source) {
307312
target.setGeneratedDocument(DocumentFacadeEjb.toReferenceDto(source.getGeneratedDocument()));
308313
target.setResponseReceived(source.isResponseReceived());
309314
target.setResponseReceivedDate(source.getResponseReceivedDate());
315+
target.setExternalRespondentId(source.getExternalRespondentId());
310316

311317
return target;
312318
}
313319

320+
@Override
321+
public ExternalSurveyView getExternalSurveyView(String surveyTokenUuid) {
322+
if (externalSurveyProviderFacade == null) {
323+
return null;
324+
}
325+
326+
SurveyToken surveyToken = surveyTokenService.getByUuid(surveyTokenUuid);
327+
if (surveyToken == null) {
328+
return null;
329+
}
330+
331+
String externalRespondentId = surveyToken.getExternalRespondentId();
332+
String externalSurveyId = surveyToken.getSurvey() != null ? surveyToken.getSurvey().getExternalId() : null;
333+
334+
if (externalSurveyId == null || externalRespondentId == null) {
335+
return null;
336+
}
337+
338+
return externalSurveyProviderFacade.getExternalSurveyView(externalSurveyId, externalRespondentId);
339+
}
340+
314341
public static SurveyTokenReferenceDto toReferenceDto(SurveyToken entity) {
315342

316343
if (entity == null) {

sormas-backend/src/main/resources/sql/sormas_schema_next.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
-- TODO: meant to be merged into sormas_schema.sql - used to avoid conflicts with development branch
22

3-
-- Add fields used for
3+
-- Surveys
44
ALTER TABLE surveys
55
ADD COLUMN external_survey_id TEXT;
6+
7+
-- Survey tokens
68
ALTER TABLE surveytokens
79
ADD COLUMN external_respondent_id TEXT;
810

9-
11+
-- Surveys
1012
ALTER TABLE symptoms
1113
ADD COLUMN IF NOT EXISTS lossOfAppetite TEXT;
1214
ALTER TABLE symptoms
@@ -20,5 +22,11 @@ ALTER TABLE symptoms
2022
ALTER TABLE symptoms
2123
ADD COLUMN IF NOT EXISTS abdominalCramps TEXT;
2224

25+
-- ExternalMessage
26+
ALTER TABLE externalmessage
27+
ADD COLUMN IF NOT EXISTS additionalDataType TEXT;
28+
ALTER TABLE externalmessage
29+
ADD COLUMN IF NOT EXISTS additionalDataJson JSONB;
30+
2331
INSERT INTO schema_version (version_number, comment)
2432
VALUES (609, '#13832 - External Survey facade');

sormas-ui/src/main/java/de/symeda/sormas/ui/survey/SurveyListComponentLayout.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ protected void drawDisplayedEntries() {
179179
listEntry.setComponentAlignment(downloadButton, Alignment.TOP_RIGHT);
180180
listEntry.setExpandRatio(downloadButton, 0);
181181

182+
if (Boolean.TRUE.equals(token.getResponseReceived())) {
183+
Button eyeButton = ButtonHelper.createIconButton(null, VaadinIcons.EYE, e -> {
184+
new SurveyQuestionnaireWindow(listEntry.getToken().toReference());
185+
}, ValoTheme.BUTTON_LINK, CssStyles.BUTTON_COMPACT);
186+
listEntry.addComponent(eyeButton);
187+
listEntry.setComponentAlignment(eyeButton, Alignment.TOP_RIGHT);
188+
listEntry.setExpandRatio(eyeButton, 0);
189+
}
190+
182191
listEntry.addActionButton(String.valueOf(i), (Button.ClickListener) clickEvent -> {
183192
ControllerProvider.getSurveyTokenController().showCaseSurveyDetails(listEntry.getToken().toReference(), this::reload);
184193
}, UiUtil.permitted(isEditAllowed, UserRight.SURVEY_EDIT));

0 commit comments

Comments
 (0)