Search in sources :

Example 16 with RelationshipValue

use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.

the class SnomedConcreteValueApiTest method updateConcreteValueWithSamePropertiesShouldNotCauseAnyChange.

@Test
public void updateConcreteValueWithSamePropertiesShouldNotCauseAnyChange() throws Exception {
    final String relationshipId = createNewConcreteValue(branchPath);
    final SnomedRelationship concreteValue = getRelationship(relationshipId);
    // explicitly create a new Boolean object with same value to simulate deserialization "bug"
    concreteValue.setActive(new Boolean(true));
    // same value as set in createNewConcreteValue(String)
    concreteValue.setValueAsObject(new RelationshipValue("Hello World!"));
    Boolean updated = SnomedRequests.prepareCommit().setCommitComment("Update concrete value").setBody(concreteValue.toUpdateRequest()).build(branchPath.getPath()).execute(getBus()).getSync(1, TimeUnit.MINUTES).getResultAs(Boolean.class);
    assertFalse(updated);
}
Also used : SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 17 with RelationshipValue

use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.

the class SnomedConcreteValueApiTest method createConcreteValueWithReservedId.

@Test
public void createConcreteValueWithReservedId() {
    ISnomedIdentifierService identifierService = getServiceForClass(ISnomedIdentifierService.class);
    String relationshipId = Iterables.getOnlyElement(identifierService.reserve(null, ComponentCategory.RELATIONSHIP, 1));
    Json requestBody = createConcreteValueRequestBody(Concepts.ROOT_CONCEPT, Concepts.PART_OF, new RelationshipValue("string value")).with("id", relationshipId).with("commitComment", "Created new concrete value with reserved identifier");
    createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody).statusCode(201).header("Location", endsWith("/" + relationshipId));
    SctId concreteValueSctId = SnomedRequests.identifiers().prepareGet().setComponentId(relationshipId).buildAsync().execute(getBus()).getSync().first().get();
    assertEquals(IdentifierStatus.ASSIGNED.getSerializedName(), concreteValueSctId.getStatus());
}
Also used : ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) Json(com.b2international.commons.json.Json) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 18 with RelationshipValue

use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.

the class SnomedConcreteValueApiTest method deleteInactiveConcreteValue.

@Test
public void deleteInactiveConcreteValue() {
    String sourceId = createNewConcept(branchPath);
    String relationshipId = createNewConcreteValue(branchPath, sourceId, Concepts.PART_OF, new RelationshipValue("hello world!"));
    Json requestBody = Json.object("active", false, "commitComment", "Inactivated concrete value");
    updateComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId, requestBody).statusCode(204);
    deleteComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId, false).statusCode(204);
    getComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId).statusCode(404);
    /* 
		 * Source concept should still exist at this point (the deletion plan should not 
		 * consider removing it with the concrete value).
		 */
    getComponent(branchPath, SnomedComponentType.CONCEPT, sourceId).statusCode(200);
}
Also used : RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 19 with RelationshipValue

use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.

the class SnomedConcreteValueApiTest method createConcreteValueInvalidSource.

@Test
public void createConcreteValueInvalidSource() {
    Json requestBody = createConcreteValueRequestBody("11110000", Concepts.PART_OF, new RelationshipValue(new BigDecimal("3.334"))).with("commitComment", "Created new concrete value with invalid sourceId");
    createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody).statusCode(400);
}
Also used : Json(com.b2international.commons.json.Json) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 20 with RelationshipValue

use of com.b2international.snowowl.snomed.core.domain.RelationshipValue in project snow-owl by b2ihealthcare.

the class SnomedFhirCodeSystemLookupConverter method expandProperties.

@Override
public List<Property> expandProperties(ServiceProvider context, CodeSystem codeSystem, Concept concept, LookupRequest lookupRequest) {
    SnomedConcept snomedConcept = concept.getInternalConceptAs();
    List<Property> properties = new ArrayList<>();
    // add basic SNOMED properties
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.INACTIVE)) {
        properties.add(CoreSnomedConceptProperties.INACTIVE.propertyOf(!snomedConcept.isActive()));
    }
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.MODULE_ID)) {
        properties.add(CoreSnomedConceptProperties.MODULE_ID.propertyOf(snomedConcept.getModuleId()));
    }
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.SUFFICIENTLY_DEFINED)) {
        properties.add(CoreSnomedConceptProperties.SUFFICIENTLY_DEFINED.propertyOf(!snomedConcept.isPrimitive()));
    }
    if (lookupRequest.isPropertyRequested(CoreSnomedConceptProperties.EFFECTIVE_TIME)) {
        properties.add(CoreSnomedConceptProperties.EFFECTIVE_TIME.propertyOf(EffectiveTimes.format(snomedConcept.getEffectiveTime(), DateFormats.SHORT)));
    }
    // Optionally requested properties
    boolean requestedChild = lookupRequest.containsProperty(CommonConceptProperties.CHILD.getCode());
    boolean requestedParent = lookupRequest.containsProperty(CommonConceptProperties.PARENT.getCode());
    if (requestedChild && snomedConcept.getDescendants() != null) {
        for (SnomedConcept child : snomedConcept.getDescendants()) {
            properties.add(CommonConceptProperties.CHILD.propertyOf(child.getId(), SnomedDisplayTermType.PT.getLabel(child)));
        }
    }
    if (requestedParent && snomedConcept.getAncestors() != null) {
        for (SnomedConcept parent : snomedConcept.getAncestors()) {
            properties.add(CommonConceptProperties.PARENT.propertyOf(parent.getId(), SnomedDisplayTermType.PT.getLabel(parent)));
        }
    }
    // Relationship Properties
    Set<String> relationshipTypeIds = lookupRequest.getPropertyCodes().stream().map(p -> {
        if (p.startsWith(SnomedTerminologyComponentConstants.SNOMED_URI_BASE)) {
            // URI prefixed properties
            return p.substring(p.lastIndexOf('/') + 1, p.length());
        } else {
            // use as is, so users won't need to define full URI for each SNOMED CT property, ID is enough
            return p;
        }
    }).filter(// only SNOMED CT Concept IDs
    SnomedIdentifiers::isConceptIdentifier).collect(Collectors.toSet());
    if (!relationshipTypeIds.isEmpty()) {
        SnomedRequests.prepareSearchRelationship().all().filterByActive(true).filterByCharacteristicType(Concepts.INFERRED_RELATIONSHIP).filterBySource(concept.getId()).filterByTypes(relationshipTypeIds).build(codeSystem.getResourceURI()).getRequest().execute(context).forEach(r -> {
            Property.Builder propertyBuilder = Property.builder().code(r.getTypeId());
            if (r.hasValue()) {
                RelationshipValue value = r.getValueAsObject();
                value.map(i -> propertyBuilder.valueInteger(i), d -> propertyBuilder.valueDecimal(d.doubleValue()), s -> propertyBuilder.valueString(s));
            } else {
                propertyBuilder.valueCode(r.getDestinationId());
            }
            properties.add(propertyBuilder.build());
        });
    }
    if (properties.isEmpty()) {
        return null;
    } else {
        return properties;
    }
}
Also used : ArrayList(java.util.ArrayList) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Property(com.b2international.snowowl.fhir.core.model.codesystem.Property)

Aggregations

RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)20 Test (org.junit.Test)13 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)12 Json (com.b2international.commons.json.Json)11 BigDecimal (java.math.BigDecimal)4 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)3 Expressions (com.b2international.index.query.Expressions)2 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)2 Expressions (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions)2 ArrayList (java.util.ArrayList)2 CompareUtils (com.b2international.commons.CompareUtils)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 NotImplementedException (com.b2international.commons.exceptions.NotImplementedException)1 Options (com.b2international.commons.options.Options)1 Expression (com.b2international.index.query.Expression)1 Query (com.b2international.index.query.Query)1 BaseRevisionIndexTest (com.b2international.index.revision.BaseRevisionIndexTest)1 ID (com.b2international.index.revision.Revision.Fields.ID)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 com.b2international.snomed.ecl.ecl (com.b2international.snomed.ecl.ecl)1