Skip to content

Commit

Permalink
Merge pull request #220 from medizininformatik-initiative/feature/219…
Browse files Browse the repository at this point in the history
…-make-order-of-ui-tree-categories-configurable-via-env-var

#219 - Make order of UI tree categories configurable via env var
  • Loading branch information
juliangruendner authored Nov 9, 2023
2 parents dc9449d + 598e9aa commit 2f5f939
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public class TerminologyService {
private final MappingRepository mappingRepository;

private String uiProfilePath;
private static final List<String> SORTED_CATEGORIES = List.of("Einwilligung", "MII_PR_Consent_Einwilligung", "Bioprobe",
"Diagnose", "Laboruntersuchung", "Medikamentenverabreichung", "Person", "ProfileSpecimenBioprobe", "Prozedur");

@Value("${app.ontologyOrder}")
private List<String> sortedCategories;
private Map<UUID, TerminologyEntry> terminologyEntries = new HashMap<>();
private List<CategoryEntry> categoryEntries = new ArrayList<>();
private Map<UUID, TerminologyEntry> terminologyEntriesWithOnlyDirectChildren = new HashMap<>();
Expand Down Expand Up @@ -128,9 +129,18 @@ public TerminologyEntry getEntry(UUID nodeId) throws NodeNotFoundException {
}

public List<CategoryEntry> getCategories() {
categoryEntries.sort(
Comparator.comparing(value -> SORTED_CATEGORIES.indexOf(value.getDisplay())));
return categoryEntries;
var sortedCategoryEntries = new ArrayList<CategoryEntry>();

List<CategoryEntry> found = categoryEntries.stream().filter(value -> sortedCategories.contains(value.getDisplay())).collect(Collectors.toList());
List<CategoryEntry> notFound = categoryEntries.stream().filter(value -> !sortedCategories.contains(value.getDisplay())).collect(Collectors.toList());

found.sort(Comparator.comparing(value -> sortedCategories.indexOf(value.getDisplay())));
notFound.sort(Comparator.comparing(CategoryEntry::getDisplay));

sortedCategoryEntries.addAll(found);
sortedCategoryEntries.addAll(notFound);

return sortedCategoryEntries;
}

public List<TerminologyEntry> getSelectableEntries(String query, UUID categoryId) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ management:
app:
# AKTIN or DSF or MOCK or DIRECT
ontologyFolder: ${ONTOLOGY_FILES_FOLDER_UI:ontology/ui_trees}
ontologyOrder: ${ONTOLOGY_ORDER:Diagnose, Prozedur, Person, Laboruntersuchung, Medikamente, Bioprobe, Einwilligung}
mappingsFile: ${MAPPINGS_FILE:ontology/mapping_cql.json}
conceptTreeFile: ${CONCEPT_TREE_FILE:ontology/mapping_tree.json}
fhirTranslationEnabled: ${FHIR_TRANSLATE_ENABLED:false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;

import java.io.IOException;
import java.util.List;
Expand All @@ -30,6 +31,8 @@ class TerminologyServiceTest {

private static UUID CATEGORY_1_ID = UUID.fromString("2ec77ac6-2547-2aff-031b-337d9ff80cff");
private static UUID CATEGORY_2_ID = UUID.fromString("457b3f3b-bf4e-45da-b676-dc63d31942dd");
private static UUID CATEGORY_A_ID = UUID.fromString("30a20f30-77db-11ee-b962-0242ac120002");
private static UUID CATEGORY_B_ID = UUID.fromString("385d2db8-77db-11ee-b962-0242ac120002");
private static UUID VALID_NODE_ID_CAT1 = UUID.fromString("72ceaea9-c1ff-2e94-5fc0-7ba34feca654");
private static UUID VALID_NODE_ID_CAT2 = UUID.fromString("33ca0320-81e5-406f-bdfd-c649e443ddd6");

Expand Down Expand Up @@ -81,17 +84,40 @@ void testGetEntry_throwsOnUnknown() throws IOException {
}

@Test
void testGetCategories() throws IOException {
void testGetCategories_order1() throws IOException {
var terminologyService = createTerminologyService("src/test/resources/ontology/ui_profiles");
var categoriesResult = assertDoesNotThrow(() -> terminologyService.getCategories());
ReflectionTestUtils.setField(terminologyService, "sortedCategories", List.of("Category2", "Category3", "Category1"));

var categoriesResult = assertDoesNotThrow(terminologyService::getCategories);
assertNotNull(categoriesResult);
assertFalse(categoriesResult.isEmpty());
assertThat(categoriesResult)
.hasSize(4)
.extracting(CategoryEntry::getDisplay, CategoryEntry::getCatId)
.containsExactly(
tuple("Category2", CATEGORY_2_ID),
tuple("Category1", CATEGORY_1_ID),
tuple("CategoryA", CATEGORY_A_ID),
tuple("CategoryB", CATEGORY_B_ID)
);
}

@Test
void testGetCategories_order2() throws IOException {
var terminologyService = createTerminologyService("src/test/resources/ontology/ui_profiles");
ReflectionTestUtils.setField(terminologyService, "sortedCategories", List.of("CategoryB", "CategoryX", "CategoryY"));

var categoriesResult = assertDoesNotThrow(terminologyService::getCategories);
assertNotNull(categoriesResult);
assertFalse(categoriesResult.isEmpty());
assertThat(categoriesResult)
.hasSize(2)
.hasSize(4)
.extracting(CategoryEntry::getDisplay, CategoryEntry::getCatId)
.containsExactlyInAnyOrder(
.containsExactly(
tuple("CategoryB", CATEGORY_B_ID),
tuple("Category1", CATEGORY_1_ID),
tuple("Category2", CATEGORY_2_ID)
tuple("Category2", CATEGORY_2_ID),
tuple("CategoryA", CATEGORY_A_ID)
);
}

Expand Down
60 changes: 60 additions & 0 deletions src/test/resources/ontology/ui_profiles/CategoryA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"children": [
{
"context": {
"code": "CategoryA",
"display": "CategoryA",
"system": "fdpg.mii.cds",
"version": "1.0.0"
},
"display": "Termcode A_1",
"id": "33ca0320-81e5-406f-bdfd-c649e443ddd6",
"leaf": true,
"selectable": true,
"termCodes": [
{
"code": "tcA_1",
"display": "Termcode A_1",
"system": "http://some.system/",
"version": "http://some.system/123/version/456"
}
]
},
{
"context": {
"code": "CategoryA",
"display": "CategoryA",
"system": "fdpg.mii.cds",
"version": "1.0.0"
},
"display": "Termcode A_2",
"id": "0da2a746-d23f-4668-9160-51d83edbd02c",
"leaf": true,
"selectable": true,
"termCodes": [
{
"code": "tcA_2",
"display": "Termcode A_2",
"system": "http://some.system/",
"version": "http://some.system/123/version/456"
}
]
}
],
"context": {
"code": "CategoryA",
"display": "CategoryA",
"system": "fdpg.mii.cds"
},
"display": "CategoryA",
"id": "30a20f30-77db-11ee-b962-0242ac120002",
"leaf": false,
"selectable": false,
"termCodes": [
{
"code": "CategoryA",
"display": "CategoryA",
"system": "fdpg.mii.cds"
}
]
}
60 changes: 60 additions & 0 deletions src/test/resources/ontology/ui_profiles/CategoryB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"children": [
{
"context": {
"code": "CategoryB",
"display": "CategoryB",
"system": "fdpg.mii.cds",
"version": "1.0.0"
},
"display": "Termcode B_1",
"id": "33ca0320-81e5-406f-bdfd-c649e443ddd6",
"leaf": true,
"selectable": true,
"termCodes": [
{
"code": "tcB_1",
"display": "Termcode B_1",
"system": "http://some.system/",
"version": "http://some.system/123/version/456"
}
]
},
{
"context": {
"code": "CategoryB",
"display": "CategoryB",
"system": "fdpg.mii.cds",
"version": "1.0.0"
},
"display": "Termcode B_2",
"id": "0da2a746-d23f-4668-9160-51d83edbd02c",
"leaf": true,
"selectable": true,
"termCodes": [
{
"code": "tcB_2",
"display": "Termcode B_2",
"system": "http://some.system/",
"version": "http://some.system/123/version/456"
}
]
}
],
"context": {
"code": "CategoryB",
"display": "CategoryB",
"system": "fdpg.mii.cds"
},
"display": "CategoryB",
"id": "385d2db8-77db-11ee-b962-0242ac120002",
"leaf": false,
"selectable": false,
"termCodes": [
{
"code": "CategoryB",
"display": "CategoryB",
"system": "fdpg.mii.cds"
}
]
}

0 comments on commit 2f5f939

Please sign in to comment.