Skip to content

Commit

Permalink
issue #1351 - Add searchInclude and searchRevInclude to capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Oct 26, 2020
1 parent c7d9192 commit 6d005cf
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -183,18 +184,28 @@ private CapabilityStatement buildCapabilityStatement() throws Exception {
// Retrieve the "resources" config property group.
PropertyGroup rsrcsGroup = FHIRConfigHelper.getPropertyGroup(FHIRConfiguration.PROPERTY_RESOURCES);

// Build the list of interactions that are supported for each resource type by default.
List<String> interactionConfig = null;
// Build the list of interactions, searchIncludes, and searchRevIncludes supported for each resource type by default.
List<Rest.Resource.Interaction> defaultInteractions = buildInteractions(ALL_INTERACTIONS);
List<com.ibm.fhir.model.type.String> defaultSearchIncludes = Collections.emptyList();
List<com.ibm.fhir.model.type.String> defaultSearchRevIncludes = Collections.emptyList();
if (rsrcsGroup != null) {
PropertyGroup parentResourcePropGroup = rsrcsGroup.getPropertyGroup(ResourceType.ValueSet.RESOURCE.value());
if (parentResourcePropGroup != null) {
interactionConfig = parentResourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_INTERACTIONS);
List<String> interactionConfig = parentResourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_INTERACTIONS);
if (interactionConfig != null) {
defaultInteractions = buildInteractions(interactionConfig);
}
List<String> searchIncludeConfig = parentResourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_SEARCH_INCLUDES);
if (searchIncludeConfig != null) {
defaultSearchIncludes = convertStringList(searchIncludeConfig);
}
List<String> searchRevIncludeConfig =
parentResourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_SEARCH_REV_INCLUDES);
if (searchRevIncludeConfig != null) {
defaultSearchRevIncludes = convertStringList(searchRevIncludeConfig);
}
}
}
if (interactionConfig == null) {
interactionConfig = ALL_INTERACTIONS;
}
List<Rest.Resource.Interaction> defaultInteractions = buildInteractions(interactionConfig);

// Build the lists of operations that are supported
List<OperationDefinition> systemOps = new ArrayList<>();
Expand Down Expand Up @@ -257,18 +268,29 @@ private CapabilityStatement buildCapabilityStatement() throws Exception {
ops.addAll(mapOperationDefinitionsToRestOperations(typeOps.get(ResourceType.ValueSet.DOMAIN_RESOURCE)));
}

List<Interaction> interactions = null;
// Build the list of interactions, searchIncludes, and searchRevIncludes supported for the resource type.
List<Interaction> interactions = defaultInteractions;
List<com.ibm.fhir.model.type.String> searchIncludes = defaultSearchIncludes;
List<com.ibm.fhir.model.type.String> searchRevIncludes = defaultSearchRevIncludes;
if (rsrcsGroup != null) {
PropertyGroup resourcePropGroup = rsrcsGroup.getPropertyGroup(resourceTypeName);
if (resourcePropGroup != null) {
List<String> resourceInteractionConfig =
resourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_INTERACTIONS);
interactions = buildInteractions(resourceInteractionConfig);
if (resourceInteractionConfig != null) {
interactions = buildInteractions(resourceInteractionConfig);
}
List<String> searchIncludeConfig = resourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_SEARCH_INCLUDES);
if (searchIncludeConfig != null) {
searchIncludes = convertStringList(searchIncludeConfig);
}
List<String> searchRevIncludeConfig =
resourcePropGroup.getStringListProperty(FHIRConfiguration.PROPERTY_FIELD_RESOURCES_SEARCH_REV_INCLUDES);
if (searchRevIncludeConfig != null) {
searchRevIncludes = convertStringList(searchRevIncludeConfig);
}
}
}
if (interactions == null) {
interactions = defaultInteractions;
}

// Build the ConformanceResource for this resource type.
Rest.Resource cr = Rest.Resource.builder()
Expand All @@ -282,6 +304,8 @@ private CapabilityStatement buildCapabilityStatement() throws Exception {
.conditionalDelete(ConditionalDeleteStatus.MULTIPLE)
.conditionalRead(ConditionalReadStatus.FULL_SUPPORT)
.searchParam(conformanceSearchParams)
.searchInclude(searchIncludes)
.searchRevInclude(searchRevIncludes)
.build();

resources.add(cr);
Expand Down Expand Up @@ -436,6 +460,18 @@ private List<Rest.Resource.Interaction> buildInteractions(List<String> interacti
return interactions;
}

/**
* Convert list of Java strings to list of FHIR strings.
* @param stringList a list of Java string, or null
* @return a list of FHIR strings, or null
*/
private List<com.ibm.fhir.model.type.String> convertStringList(List<String> stringList) {
if (stringList != null) {
return stringList.stream().map(k -> com.ibm.fhir.model.type.String.of(k)).collect(Collectors.toList());
}
return null;
}

/**
* @param rsrcsGroup the "resources" propertyGroup from the server configuration
* @return a list of resource types to support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testBuildCapabilityStatement_resources_omitted() throws Exception {
assertEquals(capabilityStatement.getRest().size(), 1, "Number of REST Elements");
CapabilityStatement.Rest restDefinition = capabilityStatement.getRest().get(0);

assertRestDefinition(restDefinition, 146, 8, 8);
assertRestDefinition(restDefinition, 146, 8, 0, 0, 8, 0, 0);
}

@Test
Expand All @@ -66,7 +66,7 @@ void testBuildCapabilityStatement_resources_empty() throws Exception {
assertEquals(capabilityStatement.getRest().size(), 1, "Number of REST Elements");
CapabilityStatement.Rest restDefinition = capabilityStatement.getRest().get(0);

assertRestDefinition(restDefinition, 146, 0, 0);
assertRestDefinition(restDefinition, 146, 0, 0, 0, 0, 0, 0);
}

@Test
Expand All @@ -81,26 +81,33 @@ void testBuildCapabilityStatement_resources_filtered() throws Exception {
assertEquals(capabilityStatement.getRest().size(), 1, "Number of REST Elements");
CapabilityStatement.Rest restDefinition = capabilityStatement.getRest().get(0);

assertRestDefinition(restDefinition, 2, 2, 4);
assertRestDefinition(restDefinition, 2, 2, 1, 0, 4, 0, 1);
}

private void assertRestDefinition(CapabilityStatement.Rest restDefinition, int numOfResources, int patientInteractions, int practitionerInteractions) {
private void assertRestDefinition(CapabilityStatement.Rest restDefinition, int numOfResources,
int patientInteractions, int patientIncludes, int patientRevIncludes,
int practitionerInteractions, int practitionerIncludes, int practitionerRevIncludes) {
assertEquals(restDefinition.getResource().size(), numOfResources, "Number of supported resources");
assertFalse(restDefinition.getResource().stream().anyMatch(r -> r.getType().getValueAsEnumConstant() == ResourceType.ValueSet.RESOURCE));
assertFalse(restDefinition.getResource().stream().anyMatch(r -> r.getType().getValueAsEnumConstant() == ResourceType.ValueSet.DOMAIN_RESOURCE));

assertInteractions(restDefinition, ResourceType.ValueSet.PATIENT, patientInteractions);
assertInteractions(restDefinition, ResourceType.ValueSet.PRACTITIONER, practitionerInteractions);
assertResourceDefinition(restDefinition, ResourceType.ValueSet.PATIENT, patientInteractions, patientIncludes, patientRevIncludes);
assertResourceDefinition(restDefinition, ResourceType.ValueSet.PRACTITIONER, practitionerInteractions, practitionerIncludes, practitionerRevIncludes);
}

private void assertInteractions(CapabilityStatement.Rest restDefinition, ResourceType.ValueSet resourceType, int numOfInteractions) {
private void assertResourceDefinition(CapabilityStatement.Rest restDefinition, ResourceType.ValueSet resourceType, int numOfInteractions,
int numIncludes, int numRevIncludes) {
Optional<CapabilityStatement.Rest.Resource> resource = restDefinition.getResource().stream()
.filter(r -> r.getType().getValueAsEnumConstant() == resourceType)
.findFirst();
assertTrue(resource.isPresent());

List<Interaction> interactions = resource.get().getInteraction();
assertEquals(interactions.size(), numOfInteractions, "Number of supported interactions for the Patient resource type");
assertEquals(interactions.size(), numOfInteractions, "Number of supported interactions for the " + resourceType + " resource type");
List<com.ibm.fhir.model.type.String> includes = resource.get().getSearchInclude();
assertEquals(includes.size(), numIncludes, "Number of supported search includes for the " + resourceType + " resource type");
List<com.ibm.fhir.model.type.String> revIncludes = resource.get().getSearchRevInclude();
assertEquals(revIncludes.size(), numRevIncludes, "Number of supported search revincludes for the " + resourceType + " resource type");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"open": true,
"Patient": {
"interactions": [],
"searchParameters": {}
"searchParameters": {},
"searchInclude": [],
"searchRevInclude": []
},
"Resource": {
"interactions": [],
"searchParameters": {}
"searchParameters": {},
"searchInclude": [],
"searchRevInclude": []
}
},
"security": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"gender": "http://hl7.org/fhir/SearchParameter/individual-gender",
"identifier": "http://hl7.org/fhir/SearchParameter/Patient-identifier",
"name": "http://hl7.org/fhir/SearchParameter/Patient-name"
}
},
"searchIncludes": ["Patient:general-practitioner"]
},
"Practitioner": {
"searchParameters": {
"name": "http://hl7.org/fhir/SearchParameter/Practitioner-name",
"identifier": "http://hl7.org/fhir/SearchParameter/Practitioner-identifier"
}
},
"searchRevIncludes": ["Patient:general-practitioner"]
},
"Resource": {
"interactions": ["read", "vread", "history", "search"],
Expand Down

0 comments on commit 6d005cf

Please sign in to comment.