Skip to content

Commit 3e27038

Browse files
committed
Fix legacy pathogen-test method/category dropped on load for disease-hidden methods
1 parent d7c60b1 commit 3e27038

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

sormas-api/src/test/java/de/symeda/sormas/api/sample/PathogenTestTypeTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,19 @@ public void legacyTestTypeStillResolvesForExistingDiseaseConfiguration() {
130130
.getVisibleValues(PathogenTestType.class, Disease.INVASIVE_PNEUMOCOCCAL_INFECTION);
131131
assertThat(visibleForIpi, hasItem(PathogenTestType.SEQUENCING));
132132
}
133+
134+
@Test
135+
public void diseaseHiddenLegacyMethodIsDroppedByVisibleValues() {
136+
// Guards the scenario behind the retainType re-add in FormComponent#updateTestTypeItemsByCategory
137+
// and the retainCategory re-add in #getVisibleTestCategories: a legacy method that is
138+
// @Diseases(hide = true) for a disease is excluded by getVisibleValues for that disease, so a
139+
// saved test recorded with it can only be kept selectable by adding it back explicitly.
140+
List<PathogenTestType> visibleForDengue =
141+
de.symeda.sormas.api.utils.Diseases.DiseasesConfiguration.getVisibleValues(PathogenTestType.class, Disease.DENGUE);
142+
assertFalse(
143+
visibleForDengue.contains(PathogenTestType.ANTIBODY_DETECTION),
144+
"ANTIBODY_DETECTION is hidden for DENGUE, so it must not be among the disease-visible values");
145+
// Its category is still resolvable from the method itself, independent of disease visibility.
146+
assertThat(PathogenTestType.getCategory(PathogenTestType.ANTIBODY_DETECTION), is(PathogenTestCategory.SEROLOGICAL_TESTS));
147+
}
133148
}

sormas-ui/src/main/java/de/symeda/sormas/ui/samples/components/TestMethodComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ public void setDto(PathogenTestDto dto) {
390390
// test recorded with a now-hidden/legacy method still loads and displays its method + category.
391391
PathogenTestType savedType = dto != null ? dto.getTestType() : null;
392392
PathogenTestCategory savedCategory = PathogenTestType.getCategory(savedType);
393+
// A legacy/hidden saved method's category may not be among the scoped categories; include it so
394+
// the selection is a member of the combo's items (Vaadin 8 won't display a value outside them).
395+
testCategoryField.setItems(getVisibleTestCategories(currentDisease, savedCategory));
393396
testCategoryField.setValue(savedCategory);
394397
updateTestTypeItemsByCategory(testTypeField, currentDisease, savedCategory, savedType);
395398
super.setDto(dto);

sormas-ui/src/main/java/de/symeda/sormas/ui/utils/FormComponent.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,14 @@ protected static void updateTestTypeItemsByCategory(
322322
.stream()
323323
.filter(type -> type == retainType || PathogenTestType.isSelectableForNewTests(type))
324324
.filter(type -> type == retainType || category == null || PathogenTestType.getCategory(type) == category)
325-
.sorted(Comparator.comparing(Object::toString))
326325
.collect(Collectors.toList());
326+
// getVisibleValues drops values marked @Diseases(hide = true) for this disease, so the
327+
// type == retainType guards above cannot re-add a saved legacy method that is hidden here.
328+
// Add it explicitly so an existing test recorded with such a method still loads and displays.
329+
if (retainType != null && !filtered.contains(retainType)) {
330+
filtered.add(retainType);
331+
}
332+
filtered.sort(Comparator.comparing(Object::toString));
327333
comboBox.setItems(filtered);
328334
if (retainType != null && filtered.contains(retainType)) {
329335
comboBox.setValue(retainType);
@@ -335,14 +341,26 @@ protected static void updateTestTypeItemsByCategory(
335341
* for the given disease, so empty categories are not offered. Sorted alphabetically.
336342
*/
337343
protected static List<PathogenTestCategory> getVisibleTestCategories(Disease disease) {
344+
return getVisibleTestCategories(disease, null);
345+
}
346+
347+
/**
348+
* As {@link #getVisibleTestCategories(Disease)} but additionally includes {@code retainCategory}
349+
* even when no selectable, disease-visible method maps to it — used when loading an existing test
350+
* whose (possibly legacy/hidden) method's category would otherwise be absent from the selector.
351+
*/
352+
protected static List<PathogenTestCategory> getVisibleTestCategories(Disease disease, PathogenTestCategory retainCategory) {
338353
List<PathogenTestCategory> categories = Diseases.DiseasesConfiguration.getVisibleValues(PathogenTestType.class, disease)
339354
.stream()
340355
.filter(PathogenTestType::isSelectableForNewTests)
341356
.map(PathogenTestType::getCategory)
342357
.filter(java.util.Objects::nonNull)
343358
.distinct()
344-
.sorted(Comparator.comparing(Object::toString))
345359
.collect(Collectors.toList());
360+
if (retainCategory != null && !categories.contains(retainCategory)) {
361+
categories.add(retainCategory);
362+
}
363+
categories.sort(Comparator.comparing(Object::toString));
346364
return categories;
347365
}
348366

0 commit comments

Comments
 (0)