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

- remove nested declaration from elastic search documents (seems to be unnecessary, but should be monitored)
- modify swagger file to match new responses
- adapt tests to the new structure
- Change responses to codeable concept and terminology replies to the new structure
  • Loading branch information
michael-82 committed Nov 12, 2024
1 parent bce7fc1 commit 8c9c7db
Show file tree
Hide file tree
Showing 33 changed files with 1,777 additions and 586 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.numcodex.feasibility_gui_backend.common.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue;
import de.numcodex.feasibility_gui_backend.terminology.es.model.Display;
import lombok.Builder;

import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
public record DisplayEntry(
@JsonProperty String original,
@JsonProperty List<LocalizedValue> translations
) {

public static DisplayEntry of(Display display) {
return DisplayEntry.builder()
.original(display.original())
.translations(List.of(
LocalizedValue.builder()
.language("de-DE")
.value(display.deDe())
.build(),
LocalizedValue.builder()
.language("en-US")
.value(display.enUs())
.build()
))
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry;
import lombok.Builder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry;
import lombok.Builder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry;
import lombok.Builder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Builder
public class CcSearchResult {
private long totalHits;
private List<TermCode> results;
private List<CodeableConceptEntry> results;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.numcodex.feasibility_gui_backend.terminology.api;

import de.numcodex.feasibility_gui_backend.common.api.TermCode;
import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry;
import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue;
import de.numcodex.feasibility_gui_backend.terminology.es.model.CodeableConceptDocument;
import lombok.Builder;

import java.util.List;

@Builder
public record CodeableConceptEntry(
TermCode termCode,
DisplayEntry display
) {
public static CodeableConceptEntry of(CodeableConceptDocument document) {
return CodeableConceptEntry.builder()
.termCode(document.termCode())
.display(DisplayEntry.builder()
.original(document.display().original())
.translations(List.of(
LocalizedValue.builder()
.language("de-DE")
.value(document.display().deDe())
.build(),
LocalizedValue.builder()
.language("en-US")
.value(document.display().enUs())
.build()
))
.build()
)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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.OntologyListItemDocument;
import lombok.Builder;

@Builder
public record EsSearchResultEntry(
String id,
String name,
DisplayEntry display,
int availability,
String context,
String terminology,
Expand All @@ -17,7 +18,7 @@ public record EsSearchResultEntry(
public static EsSearchResultEntry of(OntologyListItemDocument ontologyListItemDocument) {
return EsSearchResultEntry.builder()
.id(ontologyListItemDocument.id())
.name(ontologyListItemDocument.name())
.display(DisplayEntry.of(ontologyListItemDocument.display()))
.availability(ontologyListItemDocument.availability())
.context(ontologyListItemDocument.context().code())
.terminology(ontologyListItemDocument.terminology())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.query_dsl.*;
import de.numcodex.feasibility_gui_backend.common.api.TermCode;
import de.numcodex.feasibility_gui_backend.terminology.api.CcSearchResult;
import de.numcodex.feasibility_gui_backend.terminology.api.CodeableConceptEntry;
import de.numcodex.feasibility_gui_backend.terminology.es.model.CodeableConceptDocument;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.CodeableConceptEsRepository;
import de.numcodex.feasibility_gui_backend.terminology.es.repository.OntologyItemNotFoundException;
Expand Down Expand Up @@ -47,17 +47,18 @@ public CcSearchResult performCodeableConceptSearchWithRepoAndPaging(String keywo
}

var searchHitPage = findByCodeOrDisplay(keyword, filterList, PageRequest.of(page, pageSize));
List<TermCode> codeableConceptEntries = new ArrayList<>();
List<CodeableConceptEntry> codeableConceptEntries = new ArrayList<>();

searchHitPage.getSearchHits().forEach(hit -> codeableConceptEntries.add(hit.getContent().termCode()));
searchHitPage.getSearchHits().forEach(hit -> codeableConceptEntries.add(CodeableConceptEntry.of(hit.getContent())));
return CcSearchResult.builder()
.totalHits(searchHitPage.getTotalHits())
.results(codeableConceptEntries)
.build();
}

public TermCode getSearchResultEntryByCode(String code) {
return repo.findById(code).orElseThrow(OntologyItemNotFoundException::new).termCode();
public CodeableConceptEntry getSearchResultEntryByCode(String code) {
var document = repo.findById(code).orElseThrow(OntologyItemNotFoundException::new);
return CodeableConceptEntry.of(document);
}

private SearchHits<CodeableConceptDocument> findByCodeOrDisplay(String keyword,
Expand Down Expand Up @@ -88,7 +89,7 @@ private SearchHits<CodeableConceptDocument> findByCodeOrDisplay(String keyword,
} else {
var mmQuery = new MultiMatchQuery.Builder()
.query(keyword)
.fields(List.of("termcode.display", "termcode.code^2"))
.fields(List.of("display.de-DE", "display.en-US", "termcode.code^2"))
.build();

boolQuery = new BoolQuery.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private SearchHits<OntologyListItemDocument> findByNameOrTermcode(String keyword
} else {
var mmQuery = new MultiMatchQuery.Builder()
.query(keyword)
.fields(List.of("name", "termcode^2"))
.fields(List.of("display.de-DE", "display.en-US", "termcode^2"))
.build();

boolQuery = new BoolQuery.Builder()
Expand Down Expand Up @@ -196,7 +196,7 @@ private SearchHits<OntologyListItemDocument> findByNameOrTermcode(String keyword
public OntologyItemRelationsDocument getOntologyItemRelationsByHash(String hash) {
var ontologyItem = ontologyItemEsRepository.findById(hash).orElseThrow(OntologyItemNotFoundException::new);
return OntologyItemRelationsDocument.builder()
.translations(ontologyItem.translations())
.display(ontologyItem.display())
.parents(ontologyItem.parents())
.children(ontologyItem.children())
.relatedTerms(ontologyItem.relatedTerms())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
@Document(indexName = "codeable_concept")
public record CodeableConceptDocument(
@Id String id,
@Field(type = FieldType.Nested, includeInParent = true, name = "termcode")
@Field(name = "termcode")
TermCode termCode,
@Field(type = FieldType.Nested, includeInParent = true, name = "value_sets")
List<String> valueSets
@Field(name = "value_sets")
List<String> valueSets,
@Field(name = "display")
Display display
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.numcodex.feasibility_gui_backend.terminology.es.model;

import lombok.Builder;
import org.springframework.data.elasticsearch.annotations.Field;

@Builder
public record Display(
String original,
@Field(name = "de-DE")
String deDe,
@Field(name = "en-US")
String enUs
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
@Document(indexName = "ontology")
public record OntologyItemDocument(
@Id String id,
String name,
int availability,
TermCode context,
String terminology,
String termcode,
@Field(name = "kds_module") String kdsModule,

@Field(type = FieldType.Nested, includeInParent = true, name = "translations")
Collection<Translation> translations,
@Field(type = FieldType.Nested, includeInParent = true, name = "parents")
@Field(name = "display")
Display display,
@Field(name = "kds_module")
String kdsModule,
@Field(name = "parents")
Collection<Relative> parents,
@Field(type = FieldType.Nested, includeInParent = true, name = "children")
@Field(name = "children")
Collection<Relative> children,
@Field(type = FieldType.Nested, includeInParent = true, name = "related_terms")
@Field(name = "related_terms")
Collection<Relative> relatedTerms
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
@Builder
@Document(indexName = "ontology")
public record OntologyItemRelationsDocument(
@Field(type = FieldType.Nested, includeInParent = true, name = "translations")
Collection<Translation> translations,
@Field(type = FieldType.Nested, includeInParent = true, name = "parents")
@Field(name = "display")
Display display,
@Field(name = "parents")
Collection<Relative> parents,
@Field(type = FieldType.Nested, includeInParent = true, name = "children")
@Field(name = "children")
Collection<Relative> children,
@Field(type = FieldType.Nested, includeInParent = true, name = "related_terms")
@Field(name = "related_terms")
Collection<Relative> relatedTerms
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Document(indexName = "ontology")
public record OntologyListItemDocument(
@Id String id,
String name,
Display display,
int availability,
TermCode context,
String terminology,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.numcodex.feasibility_gui_backend.terminology.v4;

import de.numcodex.feasibility_gui_backend.common.api.TermCode;
import de.numcodex.feasibility_gui_backend.terminology.api.CcSearchResult;
import de.numcodex.feasibility_gui_backend.terminology.api.CodeableConceptEntry;
import de.numcodex.feasibility_gui_backend.terminology.es.CodeableConceptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
Expand Down Expand Up @@ -34,7 +34,7 @@ public CcSearchResult searchOntologyItemsCriteriaQuery(@RequestParam("searchterm
}

@GetMapping(value = "/entry/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
public TermCode getCodeableConceptByCode(@PathVariable("code") String code) {
public CodeableConceptEntry getCodeableConceptByCode(@PathVariable("code") String code) {
return codeableConceptService.getSearchResultEntryByCode(code);
}
}
41 changes: 35 additions & 6 deletions src/main/resources/static/v3/api-docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/TermCode"
$ref: "#/components/schemas/CodeableConceptEntry"
401:
description: Unauthorized - please login first
403:
Expand Down Expand Up @@ -1391,10 +1391,8 @@ components:
ElasticSearchResultEntry:
type: object
properties:
name:
type: string
examples:
- Diabetes Mellitus
display:
$ref: "#/components/schemas/DisplayEntry"
contextualizedTermcodeHash:
type: string
format: uuid
Expand Down Expand Up @@ -1463,6 +1461,37 @@ components:
type: string
examples:
- icd10
LocalizedValue:
type: object
properties:
language:
type: string
examples:
- de-DE
- en-US
value:
type: string
examples:
- localized entry
- lokalisierter Eintrag
DisplayEntry:
type: object
properties:
original:
type: string
examples:
- display entry
translations:
type: array
items:
$ref: "#/components/schemas/LocalizedValue"
CodeableConceptEntry:
type: object
properties:
termCode:
$ref: "#/components/schemas/TermCode"
display:
$ref: "#/components/schemas/DisplayEntry"
CodeableConceptSearchResult:
type: object
properties:
Expand All @@ -1473,7 +1502,7 @@ components:
results:
type: array
items:
$ref: "#/components/schemas/TermCode"
$ref: "#/components/schemas/CodeableConceptEntry"
CriteriaProfileData:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import de.numcodex.feasibility_gui_backend.dse.api.DisplayEntry;
import de.numcodex.feasibility_gui_backend.common.api.DisplayEntry;
import de.numcodex.feasibility_gui_backend.dse.api.DseProfileTreeNode;
import de.numcodex.feasibility_gui_backend.dse.api.LocalizedValue;
import de.numcodex.feasibility_gui_backend.dse.persistence.DseProfile;
Expand Down
Loading

0 comments on commit 8c9c7db

Please sign in to comment.