use of org.snomed.snowstorm.core.data.domain.Concept in project snowstorm by IHTSDO.
the class DupeLangRefsetFixService method fixConcepts.
public void fixConcepts(String path, Set<Long> conceptIds) {
try (final Commit commit = branchService.openCommit(path)) {
final BranchCriteria branchCriteria = versionControlHelper.getBranchCriteria(path);
final Collection<Concept> concepts = conceptService.find(branchCriteria, path, conceptIds, Config.DEFAULT_LANGUAGE_DIALECTS);
List<ReferenceSetMember> membersToSave = new ArrayList<>();
for (Concept concept : concepts) {
for (Description description : concept.getDescriptions()) {
for (Map.Entry<String, Set<ReferenceSetMember>> langRefsetEntry : description.getLangRefsetMembersMap().entrySet()) {
if (langRefsetEntry.getValue().size() > 1) {
List<ReferenceSetMember> langRefsets = new ArrayList<>(langRefsetEntry.getValue());
langRefsets.sort(Comparator.comparing(ReferenceSetMember::isReleased).thenComparing(ReferenceSetMember::isActive).reversed());
for (int i = 0; i < langRefsets.size(); i++) {
boolean active = i == 0;
final ReferenceSetMember member = langRefsets.get(i);
if (member.isActive() != active) {
member.setActive(active);
member.markChanged();
membersToSave.add(member);
}
}
}
}
}
}
if (!membersToSave.isEmpty()) {
logger.info("Saving {} corrected language refset members.", membersToSave.size());
referenceSetMemberService.doSaveBatchMembers(membersToSave, commit);
commit.markSuccessful();
} else {
logger.info("No language refset members found to correct.");
}
}
}
use of org.snomed.snowstorm.core.data.domain.Concept in project snowstorm by IHTSDO.
the class FHIRValueSetProvider method validateCode.
private Parameters validateCode(IdType id, UriType urlType, StringType codeSystem, CodeType code, String display, StringType version, DateTimeType date, Coding coding, Coding codeableConcept, String context, BooleanType abstractBool, String displayLanguage, List<LanguageDialect> languageDialects) throws FHIROperationException {
String url = urlType == null ? null : urlType.primitiveValue();
doParameterValidation(url, codeSystem, code, coding, codeableConcept, context, display, date, version, abstractBool);
// Can we get a codeSystem from the URL?
if (url != null && url.startsWith(SNOMED_URI) && url.indexOf("?") > SNOMED_URI.length()) {
if (codeSystem != null) {
throw new FHIROperationException(IssueType.INVARIANT, "Cannot handle CodeSystem defined via both url and codeSystem parameter");
}
codeSystem = new StringType(url.substring(0, url.indexOf("?")));
}
if (version != null) {
if (codeSystem == null) {
codeSystem = new StringType(SNOMED_URI + "/version/" + version.toString());
} else {
fhirHelper.append(codeSystem, "/version/" + version.toString());
}
}
// From either a saved VS instance or some implcit url, can we recover some ECL?
String ecl = getECL(id, url == null ? null : url);
if (ecl != null) {
String conceptId = fhirHelper.recoverConceptId(code, coding);
BranchPath branchPath = fhirHelper.getBranchPathFromURI(codeSystem);
// Construct ECL to find the intersection of these two sets
String intersectionEcl = conceptId + " AND (" + ecl + ")";
Page<ConceptMini> result = fhirHelper.eclSearch(intersectionEcl, null, null, languageDialects, branchPath, FHIRHelper.SINGLE_ITEM_PAGE);
if (result.getContent().size() == 1) {
ConceptMini concept = result.getContent().get(0);
if (!concept.getConceptId().equals(conceptId)) {
throw new FHIROperationException(IssueType.PROCESSING, "ECL recovered an unexpected concept id (" + concept.getConceptId() + ") using " + intersectionEcl);
}
Concept fullConcept = conceptService.find(conceptId, languageDialects, branchPath.toString());
return paramMapper.mapToFHIR(fullConcept, display);
} else {
// Now it might be that in this case we do not have this ValueSet loaded at all - or it's been
// defined or the substrate has changed such that it has no members. MAINT-1261 refers
result = fhirHelper.eclSearch(ecl, null, null, languageDialects, branchPath, FHIRHelper.SINGLE_ITEM_PAGE);
if (result.getContent().size() == 0) {
throw new FHIROperationException(IssueType.PROCESSING, "Concept not found and additionally the Valueset contains no members when expanded against the specified substrate. Check any relevant reference set is actually loaded. ECL = " + ecl + ", branch path = " + branchPath);
}
return paramMapper.conceptNotFound();
}
} else {
// TODO We have some sort of enumerated valueset saved, we need to just search through the members
throw new FHIROperationException(IssueType.NOTSUPPORTED, "Validating code against enumerated ValueSets has still to be implemented");
}
}
use of org.snomed.snowstorm.core.data.domain.Concept in project snowstorm by IHTSDO.
the class HapiValueSetMapper method addExpansion.
private void addExpansion(ValueSet vs, List<ConceptMini> concepts, Map<String, Concept> conceptDetails, List<LanguageDialect> designations, Boolean includeDesignations) {
// Will autocreate
ValueSetExpansionComponent expansion = vs.getExpansion();
for (ConceptMini concept : concepts) {
ValueSetExpansionContainsComponent component = expansion.addContains().setCode(concept.getConceptId()).setSystem(SNOMED_URI);
if (conceptDetails != null && conceptDetails.containsKey(concept.getConceptId())) {
Concept c = conceptDetails.get(concept.getConceptId());
for (Description d : c.getActiveDescriptions()) {
if (includeDesignations && d.hasAcceptability(designations)) {
component.addDesignation(asDesignation(d));
}
// Use the preferred term in the specified display language.
if (!designations.isEmpty() && d.hasAcceptability(Concepts.PREFERRED, designations.get(0)) && d.getTypeId().equals(Concepts.SYNONYM)) {
component.setDisplay(d.getTerm());
boolean inactive = !c.isActive();
if (inactive) {
component.setInactive(inactive);
}
}
}
}
}
}
use of org.snomed.snowstorm.core.data.domain.Concept in project snowstorm by IHTSDO.
the class ConceptControllerSecurityTest method deleteConcept.
@Test
void deleteConcept() throws URISyntaxException {
// Create concept first
testStatusCode(HttpStatus.OK, authorHeaders, new RequestEntity<>(new Concept(Concepts.CLINICAL_FINDING).addFSN("Test"), HttpMethod.POST, new URI(url + "/browser/" + "MAIN" + "/concepts")));
RequestEntity<Object> request = new RequestEntity<>(HttpMethod.DELETE, new URI(url + "/" + "MAIN" + "/concepts/" + Concepts.CLINICAL_FINDING));
testStatusCode(HttpStatus.FORBIDDEN, userWithoutRoleHeaders, request);
testStatusCode(HttpStatus.OK, authorHeaders, request);
testStatusCode(HttpStatus.FORBIDDEN, extensionAuthorHeaders, request);
// concept already deleted
testStatusCode(HttpStatus.BAD_REQUEST, multiExtensionAuthorHeaders, request);
testStatusCode(HttpStatus.FORBIDDEN, extensionAdminHeaders, request);
testStatusCode(HttpStatus.FORBIDDEN, globalAdminHeaders, request);
// Create concept first
testStatusCode(HttpStatus.OK, extensionAuthorHeaders, new RequestEntity<>(new Concept(Concepts.CLINICAL_FINDING).addFSN("Test"), HttpMethod.POST, new URI(url + "/browser/" + "MAIN/SNOMEDCT-A" + "/concepts")));
RequestEntity<Object> requestA = new RequestEntity<>(HttpMethod.DELETE, new URI(url + "/" + "MAIN/SNOMEDCT-A" + "/concepts/" + Concepts.CLINICAL_FINDING));
testStatusCode(HttpStatus.FORBIDDEN, userWithoutRoleHeaders, requestA);
testStatusCode(HttpStatus.FORBIDDEN, authorHeaders, requestA);
testStatusCode(HttpStatus.OK, extensionAuthorHeaders, requestA);
// concept already deleted
testStatusCode(HttpStatus.BAD_REQUEST, multiExtensionAuthorHeaders, requestA);
testStatusCode(HttpStatus.FORBIDDEN, extensionAdminHeaders, requestA);
testStatusCode(HttpStatus.FORBIDDEN, globalAdminHeaders, requestA);
}
use of org.snomed.snowstorm.core.data.domain.Concept in project snowstorm by IHTSDO.
the class ConceptControllerSecurityTest method updateConcept.
@Test
void updateConcept() throws URISyntaxException {
Concept concept = new Concept(Concepts.CLINICAL_FINDING).addFSN("Test");
// Create concept first
testStatusCode(HttpStatus.OK, authorHeaders, new RequestEntity<>(concept, HttpMethod.POST, new URI(url + "/browser/" + "MAIN" + "/concepts")));
RequestEntity<Object> request = new RequestEntity<>(concept, HttpMethod.PUT, new URI(url + "/browser/" + "MAIN" + "/concepts/" + Concepts.CLINICAL_FINDING));
testStatusCode(HttpStatus.FORBIDDEN, userWithoutRoleHeaders, request);
testStatusCode(HttpStatus.OK, authorHeaders, request);
testStatusCode(HttpStatus.FORBIDDEN, extensionAuthorHeaders, request);
testStatusCode(HttpStatus.OK, multiExtensionAuthorHeaders, request);
testStatusCode(HttpStatus.FORBIDDEN, extensionAdminHeaders, request);
testStatusCode(HttpStatus.FORBIDDEN, globalAdminHeaders, request);
// Create concept first
testStatusCode(HttpStatus.OK, extensionAuthorHeaders, new RequestEntity<>(concept, HttpMethod.POST, new URI(url + "/browser/" + "MAIN/SNOMEDCT-A" + "/concepts")));
RequestEntity<Object> requestA = new RequestEntity<>(concept, HttpMethod.PUT, new URI(url + "/browser/" + "MAIN/SNOMEDCT-A" + "/concepts/" + Concepts.CLINICAL_FINDING));
testStatusCode(HttpStatus.FORBIDDEN, userWithoutRoleHeaders, requestA);
testStatusCode(HttpStatus.FORBIDDEN, authorHeaders, requestA);
testStatusCode(HttpStatus.OK, extensionAuthorHeaders, requestA);
testStatusCode(HttpStatus.OK, multiExtensionAuthorHeaders, requestA);
testStatusCode(HttpStatus.FORBIDDEN, extensionAdminHeaders, requestA);
testStatusCode(HttpStatus.FORBIDDEN, globalAdminHeaders, requestA);
}
Aggregations