Skip to content

Commit

Permalink
Merge pull request #1352 from b2ihealthcare/issue/snomed-owl-relation…
Browse files Browse the repository at this point in the history
…ship-utility-methods

OWL Relationship utility methods
  • Loading branch information
cmark authored Dec 6, 2024
2 parents 67682e6 + ca2675e commit cf47866
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
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.b2international.snowowl.snomed.datastore.StatementFragment;
import com.b2international.snowowl.snomed.datastore.StatementFragmentWithDestination;
import com.b2international.snowowl.snomed.datastore.StatementFragmentWithValue;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedOWLRelationshipDocument;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -204,6 +208,14 @@ public static SnomedOWLRelationship createFrom(final SnomedRelationship r) {
}
}

public static SnomedOWLRelationship createFrom(final SnomedOWLRelationshipDocument 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();

Expand All @@ -224,4 +236,38 @@ public static SnomedOWLRelationship create(final String typeId, final Relationsh
return owlRelationship;
}

@JsonIgnore
public StatementFragment toStatementFragment(final int groupOffset) {
final int adjustedGroup;
if (relationshipGroup == 0) {
adjustedGroup = relationshipGroup;
} else {
adjustedGroup = relationshipGroup + groupOffset;
}

if (getDestinationId() != null) {
return new StatementFragmentWithDestination(
Long.parseLong(getTypeId()), // typeId
adjustedGroup, // adjustedGroup
0, // unionGroup
false, // universal
-1L, // statementId
-1L, // moduleId
false, // released
Long.parseLong(getDestinationId()), // destinationId
false); // destinationNegated
} else {
return new StatementFragmentWithValue(
Long.parseLong(getTypeId()), // typeId
adjustedGroup, // adjustedGroup
0, // unionGroup
false, // universal
-1L, // statementId
-1L, // moduleId
false, // released
value.type(), // valueType
value.toRawValue()); // rawValue
}
}

}

0 comments on commit cf47866

Please sign in to comment.