Skip to content

Commit

Permalink
fix(fhir): make sure includeDesignations parameter is propagated...
Browse files Browse the repository at this point in the history
...to internal request evaluation

Partially fixes https://snowowl.atlassian.net/browse/SO-5901
  • Loading branch information
cmark committed May 16, 2024
1 parent b093fcf commit dfba2b2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.b2international.snowowl.fhir.core.codesystems.FilterOperator;
import com.b2international.snowowl.fhir.core.codesystems.PublicationStatus;
import com.b2international.snowowl.fhir.core.exceptions.BadRequestException;
import com.b2international.snowowl.fhir.core.model.Designation;
import com.b2international.snowowl.fhir.core.model.ResourceResponseEntry;
import com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem;
import com.b2international.snowowl.fhir.core.model.dt.Uri;
Expand Down Expand Up @@ -247,11 +248,16 @@ private ValueSet computeFhirValueSetUsingUrl(ServiceProvider context, String url
.after(concepts.getSearchAfter());

for (Concept concept : concepts) {
expansion.addContains(Contains.builder()
.code(concept.getId())
.system(baseUrl)
.display(concept.getTerm())
.build());
var contains = Contains.builder()
.system(baseUrl)
.code(concept.getId())
.display(concept.getTerm());

if (Boolean.TRUE.equals(request.getIncludeDesignations())) {
contains.designations(Designation.fromDescriptions(concept.getDescriptions()));
}

expansion.addContains(contains.build());
}

return valueSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,34 @@ public void expandSnomedCodeSystemURL_FhirVsEclChildOfRoot() throws Exception {
.body("expansion.contains[0].display", equalTo("Substance (substance)"));
}

@Test
public void expandSnomedCodeSystemURL_IncludeDesignations() throws Exception {
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT)
.queryParam("url", RestExtensions.encodeQueryParameter(SnomedTerminologyComponentConstants.SNOMED_URI_SCT + "/900000000000207008?fhir_vs=ecl/<!138875005"))
.queryParam("includeDesignations", true)
.when().get("/ValueSet/$expand")
.then()
.statusCode(200)
.body("resourceType", equalTo("ValueSet"))
.body("id", notNullValue())
.body("expansion.total", equalTo(16)) // minified dataset only has 16 top level nodes
.body("expansion.contains[0].code", equalTo("105590001"))
.body("expansion.contains[0].system", equalTo(SNOMEDCT_URL))
.body("expansion.contains[0].display", equalTo("Substance (substance)"))
.body("expansion.contains[0].designation[0].value", equalTo("Substance"))
.body("expansion.contains[0].designation[0].language", equalTo("en"))
.body("expansion.contains[0].designation[1].value", equalTo("Substance"))
.body("expansion.contains[0].designation[1].language", equalTo("en-x-900000000000508004"))
.body("expansion.contains[0].designation[2].value", equalTo("Substance"))
.body("expansion.contains[0].designation[2].language", equalTo("en-x-900000000000509007"))
.body("expansion.contains[0].designation[3].value", equalTo("Substance (substance)"))
.body("expansion.contains[0].designation[3].language", equalTo("en"))
.body("expansion.contains[0].designation[4].value", equalTo("Substance (substance)"))
.body("expansion.contains[0].designation[4].language", equalTo("en-x-900000000000508004"))
.body("expansion.contains[0].designation[5].value", equalTo("Substance (substance)"))
.body("expansion.contains[0].designation[5].language", equalTo("en-x-900000000000509007"));
}

@Test
public void expandSnomedCodeSystemURL_FhirVsRefSetRoot() throws Exception {
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT)
Expand All @@ -122,7 +150,7 @@ public void expandSnomedCodeSystemURL_FhirVsRefSetRoot() throws Exception {
.body("expansion.total", equalTo(0))
.body("expansion.contains.code", nullValue());
}

@Test
public void expandSnomedCodeSystemURL_AfterAndNext() throws Exception {
givenAuthenticatedRequest(FHIR_ROOT_CONTEXT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public Promise<ResponseEntity<byte[]>> expandType(
.count(count)
.displayLanguage(displayLanguage == null ? null : new Code(displayLanguage))
.withHistorySupplements(withHistorySupplements)
.includeDesignations(includeDesignations)
.build();

return expand(expandRequest, nextUriBuilder, accept, _format, _pretty);
Expand Down Expand Up @@ -378,6 +379,7 @@ public Promise<ResponseEntity<byte[]>> expandInstance(
.count(count)
.displayLanguage(displayLanguage == null ? null : new Code(displayLanguage))
.withHistorySupplements(withHistorySupplements)
.includeDesignations(includeDesignations)
.build();

return expand(expandRequest, nextUriBuilder, accept, _format, _pretty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.SortedSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -145,7 +146,9 @@ private Concept toConcept(ResourceURI codeSystem, SnomedConcept snomedConcept, S
public static SortedSet<Description> generateGenericDescriptions(SnomedDescriptions descriptions) {
return descriptions.stream()
.flatMap(description -> {
final String languageCode = description.getLanguageCode();
// FIXME falling back to en when the languageCode is not available on concept descriptions
// descriptions expand is needed but only when the requestor truly needs them, but that requires a bit larger set of changes
final String languageCode = Optional.ofNullable(description.getLanguageCode()).orElse("en");
var acceptabilityDesignations = description.getAcceptabilityMap().keySet().stream()
.map(refsetId -> new ExtendedLocale(languageCode, null, refsetId))
.map(language -> new Description(description.getTerm(), language.toString()).withInternalDescription(description));
Expand Down

0 comments on commit dfba2b2

Please sign in to comment.