@@ -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