Skip to content

Commit 5c71601

Browse files
committed
Handled downloading of survey request / ignore option for some fields
1 parent 6ebfab7 commit 5c71601

3 files changed

Lines changed: 73 additions & 34 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/symptoms/SymptomsDto.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5207,57 +5207,51 @@ public void setOtherNeurolocalSymptomText(String otherNeurolocalSymptomText) {
52075207
this.otherNeurolocalSymptomText = otherNeurolocalSymptomText;
52085208
}
52095209

5210+
public SymptomState getCoughingAtNight() {
5211+
return coughingAtNight;
5212+
}
5213+
5214+
public void setCoughingAtNight(SymptomState coughingAtNight) {
5215+
this.coughingAtNight = coughingAtNight;
5216+
}
5217+
52105218
public SymptomState getLossOfAppetite() {
52115219
return lossOfAppetite;
52125220
}
52135221

5214-
public SymptomsDto setLossOfAppetite(SymptomState lossOfAppetite) {
5222+
public void setLossOfAppetite(SymptomState lossOfAppetite) {
52155223
this.lossOfAppetite = lossOfAppetite;
5216-
return this;
52175224
}
52185225

52195226
public SymptomState getFlatulence() {
52205227
return flatulence;
52215228
}
52225229

5223-
public SymptomsDto setFlatulence(SymptomState flatulence) {
5230+
public void setFlatulence(SymptomState flatulence) {
52245231
this.flatulence = flatulence;
5225-
return this;
52265232
}
52275233

52285234
public SymptomState getSmellyBurps() {
52295235
return smellyBurps;
52305236
}
52315237

5232-
public SymptomsDto setSmellyBurps(SymptomState smellyBurps) {
5238+
public void setSmellyBurps(SymptomState smellyBurps) {
52335239
this.smellyBurps = smellyBurps;
5234-
return this;
52355240
}
52365241

52375242
public SymptomState getCoughingAttacks() {
52385243
return coughingAttacks;
52395244
}
52405245

5241-
public SymptomsDto setCoughingAttacks(SymptomState coughingAttacks) {
5246+
public void setCoughingAttacks(SymptomState coughingAttacks) {
52425247
this.coughingAttacks = coughingAttacks;
5243-
return this;
5244-
}
5245-
5246-
public SymptomState getCoughingAtNight() {
5247-
return coughingAtNight;
5248-
}
5249-
5250-
public SymptomsDto setCoughingAtNight(SymptomState coughingAtNight) {
5251-
this.coughingAtNight = coughingAtNight;
5252-
return this;
52535248
}
52545249

52555250
public SymptomState getAbdominalCramps() {
52565251
return abdominalCramps;
52575252
}
52585253

5259-
public SymptomsDto setAbdominalCramps(SymptomState abdominalCramps) {
5254+
public void setAbdominalCramps(SymptomState abdominalCramps) {
52605255
this.abdominalCramps = abdominalCramps;
5261-
return this;
52625256
}
52635257
}

sormas-ui/src/main/java/de/symeda/sormas/ui/externalmessage/ExternalMessageGrid.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class ExternalMessageGrid extends FilteredGrid<ExternalMessageIndexDto, E
7171
private static final String PLACEHOLDER_SPACE = String.join("", Collections.nCopies(35, "&nbsp"));
7272
private static final String PDF_FILENAME_FORMAT = "sormas_lab_message_%s_%s.pdf";
7373
private static final String XML_FILENAME_FORMAT = "sormas_lab_message_%s_%s.xml";
74+
private static final String SURVEY_FILENAME_FORMAT = "sormas_survey_%s_%s.json";
7475

7576
private DataProviderListener<ExternalMessageIndexDto> dataProviderListener;
7677

@@ -236,19 +237,30 @@ private Component buildProcessComponent(ExternalMessageIndexDto indexDto) {
236237
}
237238
}
238239

239-
private Button buildDownloadButton(ExternalMessageIndexDto labMessage) {
240+
private Button buildDownloadButton(ExternalMessageIndexDto externalMessageIndex) {
240241
Button downloadButton = new Button(VaadinIcons.DOWNLOAD);
241242
downloadButton.setDescription(I18nProperties.getString(Strings.headingExternalMessageDownload));
242-
final String fileName =
243-
String.format(XML_FILENAME_FORMAT, DataHelper.getShortUuid(labMessage.getUuid()), DateHelper.formatDateForExport(new Date()));
243+
244+
String fileName;
245+
String mimeType;
246+
if (externalMessageIndex.getType() == ExternalMessageType.SURVEY_RESPONSE) {
247+
fileName = String
248+
.format(SURVEY_FILENAME_FORMAT, DataHelper.getShortUuid(externalMessageIndex.getUuid()), DateHelper.formatDateForExport(new Date()));
249+
250+
mimeType = "application/json";
251+
} else {
252+
fileName = String
253+
.format(XML_FILENAME_FORMAT, DataHelper.getShortUuid(externalMessageIndex.getUuid()), DateHelper.formatDateForExport(new Date()));
254+
mimeType = "application/xml";
255+
}
244256

245257
StreamResource streamResource = new StreamResource(
246258
() -> ControllerProvider.getExternalMessageController()
247-
.downloadExternalMessageAttachment(labMessage.getUuid())
259+
.downloadExternalMessageAttachment(externalMessageIndex.getUuid())
248260
.map(ByteArrayInputStream::new)
249261
.orElse(null),
250262
fileName);
251-
streamResource.setMIMEType("application/xml");
263+
streamResource.setMIMEType(mimeType);
252264

253265
FileDownloader fileDownloader = new FileDownloader(streamResource);
254266
fileDownloader.extend(downloadButton);

sormas-ui/src/main/java/de/symeda/sormas/ui/externalmessage/surveyresponse/SurveyResponseFailureEditor.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Map;
1919

2020
import com.vaadin.ui.Button;
21+
import com.vaadin.ui.CheckBox;
2122
import com.vaadin.ui.FormLayout;
2223
import com.vaadin.ui.HorizontalLayout;
2324
import com.vaadin.ui.Label;
@@ -40,9 +41,11 @@
4041
import de.symeda.sormas.api.patch.partial_retrieval.DisplayablePartialRetrievalResponse;
4142
import de.symeda.sormas.ui.utils.ButtonHelper;
4243
import de.symeda.sormas.ui.utils.CssStyles;
44+
import de.symeda.sormas.ui.utils.VaadinUiUtil;
4345

4446
/**
4547
* Modal editor window allowing users to correct failed survey response fields and reprocess.
48+
* Each failed field can be ignored (excluded from reprocessing) or have its key renamed.
4649
*/
4750
public class SurveyResponseFailureEditor extends Window {
4851

@@ -76,7 +79,9 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
7679
FormLayout failuresForm = new FormLayout();
7780
failuresForm.setMargin(false);
7881

79-
Map<String, TextField> fieldEditors = new HashMap<>();
82+
Map<String, CheckBox> ignoreCheckboxes = new HashMap<>();
83+
Map<String, TextField> keyEditors = new HashMap<>();
84+
Map<String, TextField> valueEditors = new HashMap<>();
8085

8186
for (Map.Entry<String, DataPatchFailure> entry : failures.entrySet()) {
8287
String fieldPath = entry.getKey();
@@ -91,6 +96,11 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
9196
fieldContainer.setMargin(false);
9297
fieldContainer.setSpacing(false);
9398

99+
// Ignore checkbox
100+
CheckBox ignoreCheckbox = new CheckBox(I18nProperties.getCaption(Captions.surveyResponseIgnoreField));
101+
ignoreCheckboxes.put(fieldPath, ignoreCheckbox);
102+
fieldContainer.addComponent(ignoreCheckbox);
103+
94104
Label causeLabel = new Label(I18nProperties.getCaption(Captions.surveyResponseFailureCause) + ": " + causeName);
95105
CssStyles.style(causeLabel, CssStyles.LABEL_SMALL, CssStyles.LABEL_SECONDARY);
96106
fieldContainer.addComponent(causeLabel);
@@ -100,14 +110,28 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
100110
CssStyles.style(currentValueLabel, CssStyles.LABEL_SMALL, CssStyles.LABEL_SECONDARY);
101111
fieldContainer.addComponent(currentValueLabel);
102112

103-
TextField valueField = new TextField();
104-
valueField.setCaption(fieldLabel);
113+
// Key rename field
114+
TextField keyField = new TextField(I18nProperties.getCaption(Captions.surveyResponseKeyName));
115+
keyField.setValue(fieldPath);
116+
keyField.setWidth(100, Unit.PERCENTAGE);
117+
keyEditors.put(fieldPath, keyField);
118+
fieldContainer.addComponent(keyField);
119+
120+
// Value field
121+
TextField valueField = new TextField(fieldLabel);
105122
valueField.setWidth(100, Unit.PERCENTAGE);
106123
if (failure.getProvidedFieldValue() != null) {
107124
valueField.setValue(failure.getProvidedFieldValue().toString());
108125
}
126+
valueEditors.put(fieldPath, valueField);
109127
fieldContainer.addComponent(valueField);
110-
fieldEditors.put(fieldPath, valueField);
128+
129+
// Wire ignore checkbox to disable key/value fields
130+
ignoreCheckbox.addValueChangeListener(event -> {
131+
boolean ignored = Boolean.TRUE.equals(event.getValue());
132+
keyField.setEnabled(!ignored);
133+
valueField.setEnabled(!ignored);
134+
});
111135

112136
failuresForm.addComponent(fieldContainer);
113137
}
@@ -124,10 +148,12 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
124148
FormLayout validForm = new FormLayout();
125149
validForm.setMargin(true);
126150

127-
for (Map.Entry<String, Object> entry : validValues.entrySet()) {
128-
String fieldPath = entry.getKey();
151+
VaadinUiUtil.showWarningPopup(String.format("validValues: [%s]", validValues));
152+
153+
for (Map.Entry<String, Object> validEntry : validValues.entrySet()) {
154+
String fieldPath = validEntry.getKey();
129155
String fieldLabel = resolveFieldName(fieldPath, displayData);
130-
Label label = new Label(entry.getValue() != null ? entry.getValue().toString() : "");
156+
Label label = new Label(validEntry.getValue() != null ? validEntry.getValue().toString() : "");
131157
label.setCaption(fieldLabel);
132158
validForm.addComponent(label);
133159
}
@@ -144,9 +170,16 @@ public SurveyResponseFailureEditor(ExternalMessageDto externalMessage, Displayab
144170
Button saveAndReprocessButton =
145171
ButtonHelper.createButton(Captions.actionSaveAndReprocess, I18nProperties.getCaption(Captions.actionSaveAndReprocess), e -> {
146172
Map<String, Object> correctedDictionary = new HashMap<>(validValues);
147-
for (Map.Entry<String, TextField> editorEntry : fieldEditors.entrySet()) {
148-
String value = editorEntry.getValue().getValue();
149-
correctedDictionary.put(editorEntry.getKey(), value);
173+
for (String fieldPath : valueEditors.keySet()) {
174+
CheckBox ignoreCheckbox = ignoreCheckboxes.get(fieldPath);
175+
if (ignoreCheckbox != null && Boolean.TRUE.equals(ignoreCheckbox.getValue())) {
176+
continue;
177+
}
178+
String key = keyEditors.get(fieldPath).getValue();
179+
if (key == null || key.trim().isEmpty()) {
180+
key = fieldPath;
181+
}
182+
correctedDictionary.put(key, valueEditors.get(fieldPath).getValue());
150183
}
151184

152185
FacadeProvider.getExternalMessageFacade().reprocessSurveyResponse(externalMessage.getUuid(), correctedDictionary);

0 commit comments

Comments
 (0)