use of com.b2international.snowowl.fhir.core.model.codesystem.Property in project snow-owl by b2ihealthcare.
the class PropertySerializationTest method subPropertyTest.
@Test
public void subPropertyTest() throws Exception {
Property property = Property.builder().code("123").valueInteger(2).description("propertyDescription").addSubProperty(SubProperty.builder().code("subCode").description("subDescription").valueInteger(1).build()).build();
Fhir fhirParameters = new Parameters.Fhir(property);
JsonPath jsonPath = JsonPath.from(objectMapper.writeValueAsString(fhirParameters));
assertThat(jsonPath.getString("resourceType"), equalTo("Parameters"));
assertThat(jsonPath.getList("parameter").size(), is(4));
assertThat(jsonPath, FhirParameterMatcher.hasParameter("code", FhirDataType.CODE, "123"));
assertThat(jsonPath, FhirParameterMatcher.hasParameter("value", FhirDataType.INTEGER, 2));
assertThat(jsonPath, FhirParameterMatcher.hasParameter("description", FhirDataType.STRING, "propertyDescription"));
assertThat(jsonPath.getString("parameter[3].name"), equalTo("subproperty"));
assertThat(jsonPath.getString("parameter[3].part[0].name"), equalTo("code"));
assertThat(jsonPath.getString("parameter[3].part[0].valueCode"), equalTo("subCode"));
assertThat(jsonPath.getString("parameter[3].part[1].name"), equalTo("value"));
assertThat(jsonPath.getInt("parameter[3].part[1].valueInteger"), equalTo(1));
assertThat(jsonPath.getString("parameter[3].part[2].name"), equalTo("description"));
assertThat(jsonPath.getString("parameter[3].part[2].valueString"), equalTo("subDescription"));
}
use of com.b2international.snowowl.fhir.core.model.codesystem.Property 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;
}
}
Aggregations