Skip to content

Commit

Permalink
BROWSE-638 Added new API to retrieve the referenced concept for a giv…
Browse files Browse the repository at this point in the history
…en LOINC code
  • Loading branch information
QuyenLy87 authored and astro-snail committed May 23, 2023
1 parent 67a9a5f commit 4d2657a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public FilterRegistrationBean<BranchPathUriRewriteFilter> getUrlRewriteFilter()
"/(.*)/members.*",
"/(.*)/expressions.*",
"/(.*)/identifiers",
"/(.*)/identifiers/.*",
"/(.*)/classifications.*",
"/(.*)/integrity-check",
"/(.*)/upgrade-integrity-check",
Expand Down
34 changes: 30 additions & 4 deletions src/main/java/org/snomed/snowstorm/rest/IdentifierController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
import org.snomed.snowstorm.core.data.services.ConceptService;
import org.snomed.snowstorm.core.data.services.DescriptionService;
import org.snomed.snowstorm.core.data.services.IdentifierComponentService;
import org.snomed.snowstorm.core.data.services.NotFoundException;
import org.snomed.snowstorm.core.data.services.identifier.IdentifierService;
import org.snomed.snowstorm.core.data.services.pojo.IdentifierSearchRequest;
import org.snomed.snowstorm.core.data.services.pojo.ResultMapPage;
import org.snomed.snowstorm.core.pojo.LanguageDialect;
import org.snomed.snowstorm.rest.pojo.ItemsPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -75,6 +74,33 @@ public ItemsPage<Identifier> findIdentifiers(
return new ItemsPage<>(identifiers);
}

@GetMapping(value = "/{branch}/identifiers/{alternateIdentifier}/referenced-concept", produces = {"application/json", "text/csv"})
@JsonView(value = View.Component.class)
public ConceptMini findIdentifierReferencedConcept(
@PathVariable String branch,
@PathVariable String alternateIdentifier,
@Parameter(description = "Accept-Language header can take the format en-x-900000000000508004 which sets the language reference set to use in the results.")
@RequestHeader(value = "Accept-Language", defaultValue = Config.DEFAULT_ACCEPT_LANG_HEADER) String acceptLanguageHeader) {
branch = BranchPathUriUtil.decodePath(branch);
Page<Identifier> identifiers = identifierComponentService.findIdentifiers(
branch,
new IdentifierSearchRequest().alternateIdentifier(alternateIdentifier),
ControllerHelper.getPageRequest(0, 50, null)
);
if (identifiers.getTotalElements() != 1) {
if (identifiers.getTotalElements() == 0) {
throw new NotFoundException(String.format("Identifier not found for alternateIdentifier %s.", alternateIdentifier) );
} else {
throw new IllegalStateException(String.format("Found more than one identifier with alternateIdentifier %s.", alternateIdentifier));
}
}
ResultMapPage<String, ConceptMini> conceptMinis = conceptService.findConceptMinis(branch, Collections.singleton(identifiers.getContent().iterator().next().getReferencedComponentId()),
ControllerHelper.parseAcceptLanguageHeaderWithDefaultFallback(acceptLanguageHeader));

ConceptMini concept = conceptMinis.getTotalElements() > 0 ? conceptMinis.getResultsMap().values().iterator().next() : null;
return ControllerHelper.throwIfNotFound("Concept", concept);
}

private void joinReferencedComponents(List<Identifier> identifiers, List<LanguageDialect> languageDialects, String branch) {
Set<String> conceptIds = identifiers.stream().map(Identifier::getReferencedComponentId).filter(IdentifierService::isConceptId).collect(Collectors.toSet());
Set<String> descriptionIds = identifiers.stream().map(Identifier::getReferencedComponentId).filter(IdentifierService::isDescriptionId).collect(Collectors.toSet());
Expand Down

0 comments on commit 4d2657a

Please sign in to comment.