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

- fix tests
  • Loading branch information
michael-82 committed Oct 22, 2024
1 parent e95a64c commit b37c77b
Show file tree
Hide file tree
Showing 10 changed files with 1,531 additions and 491 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import de.numcodex.feasibility_gui_backend.common.api.TermCode;
import de.numcodex.feasibility_gui_backend.terminology.es.model.CodeableConceptDocument;
import de.numcodex.feasibility_gui_backend.terminology.es.model.Display;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.CodeableConceptEsRepository;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemNotFoundException;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -56,7 +57,13 @@ void testPerformCodeableConceptSearchWithRepoAndPaging_succeedsWithoutValueSetFi

assertNotNull(result);
assertEquals(dummySearchHitsPage.getTotalHits(), result.getTotalHits());
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().termCode(), result.getResults().get(0));
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().termCode(), result.getResults().get(0).termCode());
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().display().original(), result.getResults().get(0).display().original());
assertThat(result.getResults().get(0).display().translations().containsAll(
List.of(
dummySearchHitsPage.getSearchHits().get(0).getContent().display().deDe(),
dummySearchHitsPage.getSearchHits().get(0).getContent().display().enUs()))
);
}

@Test
Expand All @@ -68,7 +75,13 @@ void testPerformCodeableConceptSearchWithRepoAndPaging_succeedsWithNullValueSetF

assertNotNull(result);
assertEquals(dummySearchHitsPage.getTotalHits(), result.getTotalHits());
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().termCode(), result.getResults().get(0));
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().termCode(), result.getResults().get(0).termCode());
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().display().original(), result.getResults().get(0).display().original());
assertThat(result.getResults().get(0).display().translations().containsAll(
List.of(
dummySearchHitsPage.getSearchHits().get(0).getContent().display().deDe(),
dummySearchHitsPage.getSearchHits().get(0).getContent().display().enUs()))
);
}

@Test
Expand All @@ -80,7 +93,13 @@ void testPerformCodeableConceptSearchWithRepoAndPaging_succeedsWithValueSetFilte

assertNotNull(result);
assertEquals(dummySearchHitsPage.getTotalHits(), result.getTotalHits());
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().termCode(), result.getResults().get(0));
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().termCode(), result.getResults().get(0).termCode());
assertEquals(dummySearchHitsPage.getSearchHits().get(0).getContent().display().original(), result.getResults().get(0).display().original());
assertThat(result.getResults().get(0).display().translations().containsAll(
List.of(
dummySearchHitsPage.getSearchHits().get(0).getContent().display().deDe(),
dummySearchHitsPage.getSearchHits().get(0).getContent().display().enUs()))
);
}

@Test
Expand Down Expand Up @@ -113,7 +132,14 @@ void testGetSearchResultEntryByCode_succeeds() {
var result = assertDoesNotThrow(() -> codeableConceptService.getSearchResultEntryByCode("1"));

assertNotNull(result);
assertEquals(dummyCodeableConceptDocument.termCode(), result);
assertEquals(dummyCodeableConceptDocument.termCode(), result.termCode());
assertEquals(dummyCodeableConceptDocument.display().original(), result.display().original());
assertThat(result.display().translations().containsAll(
List.of(
dummyCodeableConceptDocument.display().deDe(),
dummyCodeableConceptDocument.display().enUs()
)
));
}

@Test
Expand Down Expand Up @@ -150,10 +176,19 @@ private CodeableConceptDocument createDummyCodeableConceptDocument(String id) {
return CodeableConceptDocument.builder()
.id(id)
.termCode(createDummyTermcode())
.display(createDummyDisplay())
.valueSets(List.of())
.build();
}

private Display createDummyDisplay() {
return Display.builder()
.original("code-1")
.deDe("Code 1")
.enUs("Code One")
.build();
}

private TermCode createDummyTermcode() {
return TermCode.builder()
.code("code-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@ void testSearchOntologyItemsCriteriaQuery_succeedsWith200() throws Exception {
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.totalHits").value(dummyCcSearchResult.getTotalHits()))
.andExpect(jsonPath("$.results.length()").value(dummyCcSearchResult.getResults().size()))
.andExpect(jsonPath("$.results[0].code").value(dummyCcSearchResult.getResults().get(0).termCode().code()))
.andExpect(jsonPath("$.results[0].system").value(dummyCcSearchResult.getResults().get(0).termCode().system()))
.andExpect(jsonPath("$.results[0].version").value(dummyCcSearchResult.getResults().get(0).termCode().version()))
.andExpect(jsonPath("$.results[0].display").value(dummyCcSearchResult.getResults().get(0).termCode().display()));
.andExpect(jsonPath("$.results[0].termCode.code").value(dummyCcSearchResult.getResults().get(0).termCode().code()))
.andExpect(jsonPath("$.results[0].termCode.system").value(dummyCcSearchResult.getResults().get(0).termCode().system()))
.andExpect(jsonPath("$.results[0].termCode.version").value(dummyCcSearchResult.getResults().get(0).termCode().version()))
.andExpect(jsonPath("$.results[0].termCode.display").value(dummyCcSearchResult.getResults().get(0).termCode().display()));
}

@Test
@WithMockUser(roles = "DATAPORTAL_TEST_USER")
void testGetCodeableConceptByCode_succeedsWith200() throws Exception {
TermCode dummyTermcode = createDummyTermcode();
doReturn(dummyTermcode).when(codeableConceptService).getSearchResultEntryByCode(any(String.class));
CodeableConceptEntry dummyCodeableConceptEntry = createDummyCodeableConceptEntry();
doReturn(dummyCodeableConceptEntry).when(codeableConceptService).getSearchResultEntryByCode(any(String.class));

mockMvc.perform(get(URI.create(PATH_API + PATH_CODEABLE_CONCEPT + "/entry/1")).with(csrf()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.code").value(dummyTermcode.code()))
.andExpect(jsonPath("$.system").value(dummyTermcode.system()))
.andExpect(jsonPath("$.version").value(dummyTermcode.version()))
.andExpect(jsonPath("$.display").value(dummyTermcode.display()));
.andExpect(jsonPath("$.termCode.code").value(dummyCodeableConceptEntry.termCode().code()))
.andExpect(jsonPath("$.termCode.system").value(dummyCodeableConceptEntry.termCode().system()))
.andExpect(jsonPath("$.termCode.version").value(dummyCodeableConceptEntry.termCode().version()))
.andExpect(jsonPath("$.termCode.display").value(dummyCodeableConceptEntry.termCode().display()));
}

private CcSearchResult createDummyCcSearchResult() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"index": {"_index": "codeable_concept", "_id": "A1.0"}}
{"termcode": {"code": "A1.0", "display": "foo", "system": "some-system", "version": 2010}, "value_sets": []}
{"termcode": {"code": "A1.0", "display": "foo", "system": "some-system", "version": 2010}, "display": {"original": "some-system", "en-US": "some-system", "de-DE": "some-system"}, "value_sets": []}
{"index": {"_index": "codeable_concept", "_id": "A1.1"}}
{"termcode": {"code": "A1.1", "display": "bar", "system": "another-system", "version": 2012}, "value_sets": ["some-value-set"]}
{"termcode": {"code": "A1.1", "display": "bar", "system": "another-system", "version": 2012}, "display": {"original": "another-system", "en-US": "another-system", "de-DE": "another-system"} ,"value_sets": ["some-value-set"]}
{"index": {"_index": "codeable_concept", "_id": "A2.0"}}
{"termcode": {"code": "A2.0", "display": "baz", "system": "some-system", "version": 2023}, "value_sets": []}
{"termcode": {"code": "A2.0", "display": "baz", "system": "some-system", "version": 2023}, "display": {"original": "some-system", "en-US": "some-system", "de-DE": "some-system"},"value_sets": []}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
"letter",
"digit"
]
},
"edge_ngram_tokenizer_include_punctuation": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"custom"
],
"custom_token_chars": [
"+-_"
]
},
"whitespace_tokenizer": {
"type": "simple_pattern_split",
"pattern": " "
}
},
"analyzer": {
Expand All @@ -20,9 +38,16 @@
"lowercase"
]
},
"edge_ngram_analyzer_include_punctuation": {
"type": "custom",
"tokenizer": "edge_ngram_tokenizer_include_punctuation",
"filter": [
"lowercase"
]
},
"lowercase_analyzer": {
"type": "custom",
"tokenizer": "standard",
"tokenizer": "whitespace_tokenizer",
"filter": [
"lowercase"
]
Expand All @@ -36,7 +61,7 @@
"properties": {
"code": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
},
"display": {
Expand All @@ -56,6 +81,24 @@
},
"value_sets": {
"type": "keyword"
},
"display": {
"properties": {
"original": {
"type": "text",
"index": false
},
"de-DE": {
"type": "text",
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
},
"en-US": {
"type": "text",
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
"letter",
"digit"
]
},
"edge_ngram_tokenizer_include_punctuation": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"custom"
],
"custom_token_chars": [
"+-_"
]
},
"whitespace_tokenizer": {
"type": "simple_pattern_split",
"pattern": " "
}
},
"analyzer": {
Expand All @@ -20,9 +38,16 @@
"lowercase"
]
},
"edge_ngram_analyzer_include_punctuation": {
"type": "custom",
"tokenizer": "edge_ngram_tokenizer_include_punctuation",
"filter": [
"lowercase"
]
},
"lowercase_analyzer": {
"type": "custom",
"tokenizer": "standard",
"tokenizer": "whitespace_tokenizer",
"filter": [
"lowercase"
]
Expand Down Expand Up @@ -70,10 +95,23 @@
"kds_module": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"search_analyzer": "lowercase_analyzer"
"display": {
"properties": {
"original": {
"type": "text",
"index": false
},
"de-DE": {
"type": "text",
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
},
"en-US": {
"type": "text",
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
}
}
},
"parents": {
"properties": {
Expand Down Expand Up @@ -104,7 +142,7 @@
},
"termcode": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
},
"termcodes": {
Expand All @@ -129,18 +167,6 @@
},
"terminology": {
"type": "keyword"
},
"translations": {
"properties": {
"lang": {
"type": "text",
"index": false
},
"value": {
"type": "text",
"index": false
}
}
}
}
}
Expand Down
Loading

0 comments on commit b37c77b

Please sign in to comment.