Source:
private ConceptMapMappings toCollectionResource(SnomedReferenceSetMembers referenceSetMembers, CodeSystemURI uri, BranchContext context, Options search) { Map<String, ComponentURI> targetComponentMap = getTargetComponentMap(context, search); List<ConceptMapMapping> mappings = referenceSetMembers.stream() .filter(m -> SnomedTerminologyComponentConstants.CONCEPT_NUMBER == m.getReferencedComponent().getTerminologyComponentId()) .map(m -> { return toMapping(m, uri, targetComponentMap.get(m.getReferenceSetId())); }) .collect(Collectors.toList()); if (!mappings.isEmpty()) { Set<String> targetIds = mappings.stream().map(ConceptMapMapping::getTargetComponentURI).map(ComponentURI::identifier).collect(Collectors.toSet()); String codeSystem = mappings.stream().findFirst().get().getTargetComponentURI().codeSystem(); if (!ComponentURI.UNSPECIFIED.codeSystem().equals(codeSystem)) { Map<String, Concept> mapTargetsById = CodeSystemRequests.prepareSearchConcepts() .filterByIds(targetIds) .build(CodeSystemURI.head(codeSystem)) .execute(context.service(IEventBus.class)) .getSync(5, TimeUnit.MINUTES) .stream() .collect(Collectors.toMap(Concept::getId, c -> c)); mappings = mappings.stream().map(mapping -> { final String mapTarget = mapping.getTargetComponentURI().identifier(); if (mapTargetsById.containsKey(mapTarget)) { return mapping.toBuilder() .targetTerm(mapTargetsById.get(mapTarget).getTerm()) .build(); } else { return mapping; } }).collect(Collectors.toList()); } } return new ConceptMapMappings( mappings, referenceSetMembers.getSearchAfter(), referenceSetMembers.getLimit(), referenceSetMembers.getTotal() ); }

Target:
private ConceptMapMappings toCollectionResource(SnomedReferenceSetMembers referenceSetMembers, CodeSystemURI uri, BranchContext context, Options search) { Map<String, ComponentURI> targetComponentMap = getTargetComponentMap(context, search); List<ConceptMapMapping> mappings = referenceSetMembers.stream() .filter(m -> SnomedTerminologyComponentConstants.CONCEPT_NUMBER == m.getReferencedComponent().getTerminologyComponentId()) .map(m -> { return toMapping(m, uri, targetComponentMap.get(m.getReferenceSetId())); }) .collect(Collectors.toList()); if (!mappings.isEmpty()) { Set<String> targetIds = mappings.stream().map(ConceptMapMapping::getTargetComponentURI).map(ComponentURI::identifier).collect(Collectors.toSet()); String codeSystem = mappings.stream().findFirst().get().getTargetComponentURI().codeSystem(); if (!ComponentURI.UNSPECIFIED.codeSystem().equals(codeSystem)) { Map<String, Concept> mapTargetsById = CodeSystemRequests.prepareSearchConcepts() .filterByIds(targetIds) .all() .build(CodeSystemURI.head(codeSystem)) .execute(context.service(IEventBus.class)) .getSync(5, TimeUnit.MINUTES) .stream() .collect(Collectors.toMap(Concept::getId, c -> c)); mappings = mappings.stream().map(mapping -> { final String mapTarget = mapping.getTargetComponentURI().identifier(); if (mapTargetsById.containsKey(mapTarget)) { return mapping.toBuilder() .targetTerm(mapTargetsById.get(mapTarget).getTerm()) .build(); } else { return mapping; } }).collect(Collectors.toList()); } } return new ConceptMapMappings( mappings, referenceSetMembers.getSearchAfter(), referenceSetMembers.getLimit(), referenceSetMembers.getTotal() ); }