Skip to content

Commit

Permalink
#382 - Change display and translations structure for criteria and con…
Browse files Browse the repository at this point in the history
…cepts

- use correct onto tag in integration test
- fix display entry for ontology item relations
  • Loading branch information
michael-82 committed Jan 14, 2025
1 parent 65a2632 commit bbdf144
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
needs: tests
runs-on: ubuntu-latest
env:
ONTOLOGY_GIT_TAG: v3.0.1
ONTOLOGY_GIT_TAG: v3.0.2-alpha
ELASTIC_HOST: http://localhost:9200
ELASTIC_FILEPATH: https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/TAGPLACEHOLDER/
ELASTIC_FILENAME: elastic.zip
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.numcodex.feasibility_gui_backend.terminology.api;

import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry;
import de.numcodex.feasibility_gui_backend.terminology.es.model.OntologyItemRelationsDocument;
import de.numcodex.feasibility_gui_backend.terminology.es.model.Relative;
import lombok.Builder;

import java.util.Collection;

@Builder
public record RelationEntry(
DisplayEntry display,
Collection<Relative> parents,
Collection<Relative> children,
Collection<Relative> relatedTerms
) {

public static RelationEntry of(OntologyItemRelationsDocument document) {
return RelationEntry.builder()
.display(DisplayEntry.of(document.display()))
.parents(document.parents())
.children(document.children())
.relatedTerms(document.relatedTerms())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import co.elastic.clients.elasticsearch._types.query_dsl.*;
import de.numcodex.feasibility_gui_backend.terminology.api.EsSearchResult;
import de.numcodex.feasibility_gui_backend.terminology.api.EsSearchResultEntry;
import de.numcodex.feasibility_gui_backend.terminology.api.RelationEntry;
import de.numcodex.feasibility_gui_backend.terminology.es.model.*;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemEsRepository;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemNotFoundException;
Expand Down Expand Up @@ -191,14 +192,15 @@ private SearchHits<OntologyListItemDocument> findByNameOrTermcode(String keyword

}

public OntologyItemRelationsDocument getOntologyItemRelationsByHash(String hash) {
public RelationEntry getRelationEntryByHash(String hash) {
var ontologyItem = ontologyItemEsRepository.findById(hash).orElseThrow(OntologyItemNotFoundException::new);
return OntologyItemRelationsDocument.builder()
var ontologyItemRelationsDocument = OntologyItemRelationsDocument.builder()
.display(ontologyItem.display())
.parents(ontologyItem.parents())
.children(ontologyItem.children())
.relatedTerms(ontologyItem.relatedTerms())
.build();
return RelationEntry.of(ontologyItemRelationsDocument);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import de.numcodex.feasibility_gui_backend.terminology.TerminologyService;
import de.numcodex.feasibility_gui_backend.terminology.api.*;
import de.numcodex.feasibility_gui_backend.terminology.es.TerminologyEsService;
import de.numcodex.feasibility_gui_backend.terminology.es.model.OntologyItemRelationsDocument;
import de.numcodex.feasibility_gui_backend.terminology.es.model.TermFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
Expand Down Expand Up @@ -51,23 +50,23 @@ public List<TermFilter> getAvailableFilters() {
}

@GetMapping("entry/search")
public EsSearchResult searchOntologyItemsCriteriaQuery2(@RequestParam("searchterm") String keyword,
@RequestParam(value = "criteria-sets", required = false) List<String> criteriaSets,
@RequestParam(value = "contexts", required = false) List<String> contexts,
@RequestParam(value = "kds-modules", required = false) List<String> kdsModules,
@RequestParam(value = "terminologies", required = false) List<String> terminologies,
@RequestParam(value = "availability", required = false, defaultValue = "false") boolean availability,
@RequestParam(value = "page-size", required = false, defaultValue = "20") int pageSize,
@RequestParam(value = "page", required = false, defaultValue = "0") int page) {
public EsSearchResult searchOntologyItemsCriteriaQuery(@RequestParam("searchterm") String keyword,
@RequestParam(value = "criteria-sets", required = false) List<String> criteriaSets,
@RequestParam(value = "contexts", required = false) List<String> contexts,
@RequestParam(value = "kds-modules", required = false) List<String> kdsModules,
@RequestParam(value = "terminologies", required = false) List<String> terminologies,
@RequestParam(value = "availability", required = false, defaultValue = "false") boolean availability,
@RequestParam(value = "page-size", required = false, defaultValue = "20") int pageSize,
@RequestParam(value = "page", required = false, defaultValue = "0") int page) {


return terminologyEsService
.performOntologySearchWithPaging(keyword, criteriaSets, contexts, kdsModules, terminologies, availability, pageSize, page);
}

@GetMapping("entry/{hash}/relations")
public OntologyItemRelationsDocument getOntologyItemRelationsByHash(@PathVariable("hash") String hash) {
return terminologyEsService.getOntologyItemRelationsByHash(hash);
public RelationEntry getOntologyItemRelationsByHash(@PathVariable("hash") String hash) {
return terminologyEsService.getRelationEntryByHash(hash);
}

@GetMapping("entry/{hash}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void testGetSearchResultEntryByHash_throwsOnNotFound() {
@Test
void testGetSearchRelationsByHash_succeeds() {
String entryId = "e2fcb288-0d08-3272-8f32-64b8f1cfe095";
var relations = assertDoesNotThrow(() -> terminologyEsService.getOntologyItemRelationsByHash(entryId));
var relations = assertDoesNotThrow(() -> terminologyEsService.getRelationEntryByHash(entryId));
assertThat(relations).isNotNull();
assertThat(relations.parents()).isNotNull();
assertThat(relations.parents()).isNotEmpty();
Expand All @@ -178,6 +178,6 @@ void testGetSearchRelationsByHash_succeeds() {

@Test
void testGetSearchRelationsByHash_throwsOnNotFound() {
assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getOntologyItemRelationsByHash("invalid-id"));
assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getRelationEntryByHash("invalid-id"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ void testPerformOntologySearchWithRepoAndPaging_throwsOnInvalidPageSize() {
}

@Test
void testGetOntologyItemRelationsByHash_succeeds() {
void testGetRelationEntryByHash_succeeds() {
String id = UUID.randomUUID().toString();
OntologyItemDocument dummyOntologyItem = createDummyOntologyItem(id);
doReturn(Optional.of(dummyOntologyItem)).when(ontologyItemEsRepository).findById(any(String.class));

var ontologyItemRelationsDocument = assertDoesNotThrow(() -> terminologyEsService.getOntologyItemRelationsByHash(id));
var ontologyItemRelationsDocument = assertDoesNotThrow(() -> terminologyEsService.getRelationEntryByHash(id));
assertThat(ontologyItemRelationsDocument).isNotNull();
assertThat(ontologyItemRelationsDocument.relatedTerms()).isEqualTo(dummyOntologyItem.relatedTerms());
assertThat(ontologyItemRelationsDocument.children()).isEqualTo(dummyOntologyItem.children());
Expand All @@ -189,10 +189,10 @@ void testGetOntologyItemRelationsByHash_succeeds() {
}

@Test
void testGetOntologyItemRelationsByHash_throwsOnNotFound() {
void testGetRelationEntryByHash_throwsOnNotFound() {
doReturn(Optional.empty()).when(ontologyItemEsRepository).findById(any(String.class));

assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getOntologyItemRelationsByHash("id"));
assertThrows(OntologyItemNotFoundException.class, () -> terminologyEsService.getRelationEntryByHash("id"));
}

private OntologyListItemDocument createDummyOntologyListItem(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void testSearchOntologyItemsCriteriaQuery_failsOnUnauthorized() throws Ex
@WithMockUser(roles = "DATAPORTAL_TEST_USER")
public void testGetOntologyItemRelationsByHash_succeeds() throws Exception {
var dummyOntologyItemRelations = createDummyOntologyItemRelations();
doReturn(dummyOntologyItemRelations).when(terminologyEsService).getOntologyItemRelationsByHash(any(String.class));
doReturn(dummyOntologyItemRelations).when(terminologyEsService).getRelationEntryByHash(any(String.class));

mockMvc.perform(get(URI.create(PATH_API + PATH_TERMINOLOGY + "/entry/abc/relations")).with(csrf()))
.andExpect(status().isOk())
Expand All @@ -170,7 +170,7 @@ public void testGetOntologyItemRelationsByHash_succeeds() throws Exception {
@Test
public void testGetOntologyItemRelationsByHash_failsOnUnauthorized() throws Exception {
var dummyOntologyItemRelations = createDummyOntologyItemRelations();
doReturn(dummyOntologyItemRelations).when(terminologyEsService).getOntologyItemRelationsByHash(any(String.class));
doReturn(dummyOntologyItemRelations).when(terminologyEsService).getRelationEntryByHash(any(String.class));

mockMvc.perform(get(URI.create(PATH_API + PATH_TERMINOLOGY + "/entry/abc/relations")).with(csrf()))
.andExpect(status().isUnauthorized());
Expand Down

0 comments on commit bbdf144

Please sign in to comment.