Skip to content

Commit

Permalink
Merge pull request #1301 from b2ihealthcare/feature/SO-6169-support-t…
Browse files Browse the repository at this point in the history
…ype-destination-expand-owl-members

feat(snomed): support expanding type() and destination() concepts on OWL Refset members
  • Loading branch information
cmark committed Jun 20, 2024
2 parents d5b74a0 + 4e4ecf7 commit b45cdde
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@
import com.b2international.snowowl.core.request.CommitResult;
import com.b2international.snowowl.snomed.common.SnomedConstants.Concepts;
import com.b2international.snowowl.snomed.common.SnomedRf2Headers;
import com.b2international.snowowl.snomed.core.domain.refset.DataType;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers;
import com.b2international.snowowl.snomed.core.domain.refset.*;
import com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest;
import com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants;
import com.b2international.snowowl.snomed.core.rest.SnomedComponentType;
import com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument;
import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;
import com.b2international.snowowl.test.commons.Services;
import com.b2international.snowowl.test.commons.rest.RestExtensions;
Expand Down Expand Up @@ -436,8 +432,8 @@ public void updateOwlAxiomRefsetMembers() {

assertThat(member.getClassOWLRelationships())
.containsOnly(
SnomedOWLRelationshipDocument.create(Concepts.IS_A, "410680006", 0),
SnomedOWLRelationshipDocument.create("734136001", "900000000000470007", 1)
SnomedOWLRelationship.create(Concepts.IS_A, "410680006", 0),
SnomedOWLRelationship.create("734136001", "900000000000470007", 1)
);

final Json updateRequestBody = Json.object(
Expand All @@ -455,9 +451,9 @@ public void updateOwlAxiomRefsetMembers() {

assertThat(updatedMember.getClassOWLRelationships())
.containsOnly(
SnomedOWLRelationshipDocument.create(Concepts.IS_A, "410680006", 0),
SnomedOWLRelationshipDocument.create("734136001", "900000000000470007", 1),
SnomedOWLRelationshipDocument.create("371881003", "900000000000450001", 1)
SnomedOWLRelationship.create(Concepts.IS_A, "410680006", 0),
SnomedOWLRelationship.create("734136001", "900000000000470007", 1),
SnomedOWLRelationship.create("371881003", "900000000000450001", 1)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 B2i Healthcare, https://b2ihealthcare.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.snomed.core.domain.refset;

import com.b2international.snowowl.snomed.core.domain.RelationshipValue;

/**
* @since 9.3
*/
public interface OwlRelationship {

String getTypeId();

String getDestinationId();

Integer getRelationshipGroup();

boolean hasValue();

RelationshipValue getValueAsObject();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/*
* Copyright 2024 B2i Healthcare, https://b2ihealthcare.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.snomed.core.domain.refset;

import static com.b2international.snowowl.core.domain.BaseComponent.ifNotNull;

import java.io.Serializable;
import java.util.Objects;

import com.b2international.snowowl.snomed.core.domain.RelationshipValue;
import com.b2international.snowowl.snomed.core.domain.SnomedConcept;
import com.b2international.snowowl.snomed.core.domain.SnomedRelationship;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @since 9.3
*/
public final class SnomedOWLRelationship implements OwlRelationship, Serializable {

private static final long serialVersionUID = 1L;

/**
* Enumerates expandable property keys.
*
* @since 9.3
*/
public static final class Expand {
public static final String TYPE = "type";
public static final String DESTINATION = "destination";
}

private SnomedConcept type;

private SnomedConcept destination;

private RelationshipValue value;

private Integer relationshipGroup;

/**
* @return
*/
@JsonProperty
@Override
public String getDestinationId() {
return ifNotNull(getDestination(), SnomedConcept::getId);
}

/**
* Returns the destination concept of this relationship.
*
* @return
*/
public SnomedConcept getDestination() {
return destination;
}

/**
* Returns the value associated with this relationship.
*
* @return
*/
@JsonProperty("value")
@Override
public RelationshipValue getValueAsObject() {
return value;
}

@JsonIgnore
@Override
public boolean hasValue() {
return (value != null);
}

/**
* @return
*/
@JsonIgnore
public String getValue() {
return ifNotNull(getValueAsObject(), RelationshipValue::toLiteral);
}

/**
* Returns the type identifier of this relationship.
*
* @return the relationship type identifier
*/
@JsonProperty
@Override
public String getTypeId() {
return ifNotNull(getType(), SnomedConcept::getId);
}

/**
* Returns the type concept of this relationship.
*
* @return
*/
public SnomedConcept getType() {
return type;
}

/**
* Returns the relationship group number.
*
* @return the relationship group, or 0 if this relationship can not be grouped, or is in an unnumbered, singleton group
*/
@Override
public Integer getRelationshipGroup() {
return relationshipGroup;
}

/**
* @param destination
*/
public void setDestination(SnomedConcept destination) {
this.destination = destination;
}

/**
* @param destinationId
*/
@JsonIgnore
public void setDestinationId(String destinationId) {
setDestination(ifNotNull(destinationId, SnomedConcept::new));
}

/**
* @param value
*/
@JsonProperty("value")
public void setValueAsObject(final RelationshipValue value) {
this.value = value;
}

/**
* @param literal
*/
@JsonIgnore
public void setValue(final String literal) {
setValueAsObject(RelationshipValue.fromLiteral(literal));
}

/**
* @param type
*/
public void setType(SnomedConcept type) {
this.type = type;
}

/**
* @param typeId
*/
@JsonIgnore
public void setTypeId(String typeId) {
setType(ifNotNull(typeId, SnomedConcept::new));
}

/**
* @param relationshipGroup
*/
public void setRelationshipGroup(final Integer relationshipGroup) {
this.relationshipGroup = relationshipGroup;
}

@Override
public int hashCode() {
return Objects.hash(getTypeId(), getDestinationId(), getValueAsObject(), getRelationshipGroup());
}

@Override
public boolean equals(Object obj) {
if (this == obj) { return true; }
if (obj == null) { return false; }
if (getClass() != obj.getClass()) { return false; }

final SnomedOWLRelationship other = (SnomedOWLRelationship) obj;

return Objects.equals(getTypeId(), other.getTypeId())
&& Objects.equals(getDestinationId(), other.getDestinationId())
&& Objects.equals(getValueAsObject(), other.getValueAsObject())
&& Objects.equals(getRelationshipGroup(), other.getRelationshipGroup());
}

public static SnomedOWLRelationship createFrom(final SnomedRelationship r) {
if (r.hasValue()) {
return create(r.getTypeId(), r.getValueAsObject(), r.getRelationshipGroup());
} else {
return create(r.getTypeId(), r.getDestinationId(), r.getRelationshipGroup());
}
}

public static SnomedOWLRelationship create(final String typeId, final String destinationId, final int relationshipGroup) {
SnomedOWLRelationship owlRelationship = new SnomedOWLRelationship();

owlRelationship.setTypeId(typeId);
owlRelationship.setDestinationId(destinationId);
owlRelationship.setRelationshipGroup(relationshipGroup);

return owlRelationship;
}

public static SnomedOWLRelationship create(final String typeId, final RelationshipValue value, final int relationshipGroup) {
SnomedOWLRelationship owlRelationship = new SnomedOWLRelationship();

owlRelationship.setTypeId(typeId);
owlRelationship.setValueAsObject(value);
owlRelationship.setRelationshipGroup(relationshipGroup);

return owlRelationship;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2022 B2i Healthcare, https://b2ihealthcare.com
* Copyright 2011-2024 B2i Healthcare, https://b2ihealthcare.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,6 @@
import com.b2international.snowowl.core.terminology.TerminologyComponent;
import com.b2international.snowowl.snomed.common.SnomedRf2Headers;
import com.b2international.snowowl.snomed.core.domain.*;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry;
import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
Expand Down Expand Up @@ -83,6 +82,7 @@ public final class SnomedReferenceSetMember extends SnomedComponent {
public static final class Expand {
public static final String REFERENCED_COMPONENT = "referencedComponent";
public static final String TARGET_COMPONENT = "targetComponent";
public static final String OWL_RELATIONSHIPS = "owlRelationships";
}

public static final Function<SnomedReferenceSetMember, String> GET_REFERENCED_COMPONENT_ID = (member) -> member.getReferencedComponent().getId();
Expand Down Expand Up @@ -114,9 +114,9 @@ public static final class Fields extends SnomedComponent.Fields {
private SnomedCoreComponent referencedComponent;
private String refsetId;
private Map<String, Object> properties = newHashMap();
private List<SnomedOWLRelationshipDocument> equivalentOWLRelationships;
private List<SnomedOWLRelationshipDocument> classOWLRelationships;
private List<SnomedOWLRelationshipDocument> gciOWLRelationships;
private List<SnomedOWLRelationship> equivalentOWLRelationships;
private List<SnomedOWLRelationship> classOWLRelationships;
private List<SnomedOWLRelationship> gciOWLRelationships;

@Override
public String getComponentType() {
Expand Down Expand Up @@ -190,27 +190,27 @@ public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}

public List<SnomedOWLRelationshipDocument> getEquivalentOWLRelationships() {
public List<SnomedOWLRelationship> getEquivalentOWLRelationships() {
return equivalentOWLRelationships;
}

public void setEquivalentOWLRelationships(List<SnomedOWLRelationshipDocument> equivalentOWLRelationships) {
public void setEquivalentOWLRelationships(List<SnomedOWLRelationship> equivalentOWLRelationships) {
this.equivalentOWLRelationships = equivalentOWLRelationships;
}

public List<SnomedOWLRelationshipDocument> getClassOWLRelationships() {
public List<SnomedOWLRelationship> getClassOWLRelationships() {
return classOWLRelationships;
}

public void setClassOWLRelationships(List<SnomedOWLRelationshipDocument> classOWLRelationships) {
public void setClassOWLRelationships(List<SnomedOWLRelationship> classOWLRelationships) {
this.classOWLRelationships = classOWLRelationships;
}

public List<SnomedOWLRelationshipDocument> getGciOWLRelationships() {
public List<SnomedOWLRelationship> getGciOWLRelationships() {
return gciOWLRelationships;
}

public void setGciOWLRelationships(List<SnomedOWLRelationshipDocument> gciOWLRelationships) {
public void setGciOWLRelationships(List<SnomedOWLRelationship> gciOWLRelationships) {
this.gciOWLRelationships = gciOWLRelationships;
}

Expand Down
Loading

0 comments on commit b45cdde

Please sign in to comment.