Skip to content

Commit

Permalink
issue #3289 - rationalize ResourceType and ResourceTypeCode (#3290)
Browse files Browse the repository at this point in the history
* issue #3289 - ResourceType and ResourceTypeCode

1. Update the CodeGenerator to combine the ResourceType and
FHIRResourceType code subtypes into a single new code subtype named
`ResourceTypeCode`
2. Rename the ResourceTypeName enum in fhir-core to ResourceType, move
the `from(String)` method there, and update ResourceTypeCode to use this
enum instead of duplicating the values in a nested class
3. Update all uses of ResourceType.Value and FHIRResourceType.Value to
use the new ResourceType enum instead

The result is
1. a simple enum we can use for ResourceType constants throughout the
codebase; and
2. a single code subtype that builds on this enum for when its used
within the fhir model

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>

* Favor ResourceType over ResourceTypeCode when not in the model

Standardize on ResourceType constants instead of ResourceTypeCode
constants.
The main difference is that ResourceTypeCode extends Code (which is an
Element) and so it can have an optional id and extensions.

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>

* fixup copyrights

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>

* update copyright on the rest of the generated classes

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Feb 16, 2022
1 parent 59e9476 commit 2dd380f
Show file tree
Hide file tree
Showing 522 changed files with 3,194 additions and 7,659 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -16,6 +16,7 @@
import java.util.stream.Collectors;

import com.ibm.fhir.core.FHIRConstants;
import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.model.format.Format;
import com.ibm.fhir.model.generator.FHIRGenerator;
import com.ibm.fhir.model.resource.SearchParameter;
Expand All @@ -27,7 +28,7 @@
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.code.BindingStrength;
import com.ibm.fhir.model.type.code.FHIRDefinedType;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.model.type.code.ResourceTypeCode;
import com.ibm.fhir.profile.ProfileSupport;
import com.ibm.fhir.registry.FHIRRegistry;

Expand All @@ -48,8 +49,8 @@ public static void main(String[] args) throws Exception {
continue; // skip the parameters defined in the base spec
}

List<ResourceType> base = searchParameter.getBase();
if (base.size() != 1 || base.get(0).getValueAsEnum() == ResourceType.Value.RESOURCE) {
List<ResourceTypeCode> base = searchParameter.getBase();
if (base.size() != 1 || base.get(0).getValueAsEnum() == ResourceType.RESOURCE) {
continue; // too complicated to handle this case right now
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -16,6 +16,7 @@
import java.util.stream.Collectors;

import com.ibm.fhir.core.FHIRConstants;
import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.model.format.Format;
import com.ibm.fhir.model.generator.FHIRGenerator;
import com.ibm.fhir.model.resource.SearchParameter;
Expand All @@ -27,7 +28,7 @@
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.code.BindingStrength;
import com.ibm.fhir.model.type.code.FHIRDefinedType;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.model.type.code.ResourceTypeCode;
import com.ibm.fhir.profile.ProfileSupport;
import com.ibm.fhir.registry.FHIRRegistry;

Expand All @@ -49,8 +50,8 @@ public static void main(String[] args) throws Exception {
continue; // skip the parameters defined in the base spec
}

List<ResourceType> base = searchParameter.getBase();
if (base.size() != 1 || base.get(0).getValueAsEnum() == ResourceType.Value.RESOURCE) {
List<ResourceTypeCode> base = searchParameter.getBase();
if (base.size() != 1 || base.get(0).getValueAsEnum() == ResourceType.RESOURCE) {
continue; // too complicated to handle this case right now
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -16,6 +16,7 @@
import java.util.stream.Collectors;

import com.ibm.fhir.core.FHIRConstants;
import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.model.format.Format;
import com.ibm.fhir.model.generator.FHIRGenerator;
import com.ibm.fhir.model.resource.SearchParameter;
Expand All @@ -27,7 +28,7 @@
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.code.BindingStrength;
import com.ibm.fhir.model.type.code.FHIRDefinedType;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.model.type.code.ResourceTypeCode;
import com.ibm.fhir.profile.ProfileSupport;
import com.ibm.fhir.registry.FHIRRegistry;

Expand All @@ -49,8 +50,8 @@ public static void main(String[] args) throws Exception {
continue; // skip the parameters defined in the base spec
}

List<ResourceType> base = searchParameter.getBase();
if (base.size() != 1 || base.get(0).getValueAsEnum() == ResourceType.Value.RESOURCE) {
List<ResourceTypeCode> base = searchParameter.getBase();
if (base.size() != 1 || base.get(0).getValueAsEnum() == ResourceType.RESOURCE) {
continue; // too complicated to handle this case right now
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -20,14 +20,15 @@
import com.ibm.fhir.client.FHIRClient;
import com.ibm.fhir.client.FHIRParameters;
import com.ibm.fhir.client.FHIRResponse;
import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.cql.Constants;
import com.ibm.fhir.cql.engine.util.FHIRClientUtil;
import com.ibm.fhir.model.resource.Bundle;
import com.ibm.fhir.model.resource.Parameters;
import com.ibm.fhir.model.resource.Parameters.Parameter;
import com.ibm.fhir.model.resource.ValueSet;
import com.ibm.fhir.model.type.code.BundleType;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.model.type.code.ResourceTypeCode;

/**
* This is an implementation of a terminology provider for the CQL Engine that uses
Expand All @@ -47,7 +48,7 @@ public boolean in(Code code, ValueSetInfo valueSet) {

try {
WebTarget target =
fhirClient.getWebTarget().path(ResourceType.VALUE_SET.getValue()).path(valueSet.getId()).path("$validate-code").queryParam("code", FHIRClientUtil.urlencode(code.getCode()));
fhirClient.getWebTarget().path(ResourceType.VALUE_SET.value()).path(valueSet.getId()).path("$validate-code").queryParam("code", FHIRClientUtil.urlencode(code.getCode()));

if (code.getSystem() != null) {
target = target.queryParam("system", FHIRClientUtil.urlencode(code.getSystem()));
Expand All @@ -73,7 +74,7 @@ public Iterable<Code> expand(ValueSetInfo valueSet) {

try {
Response response =
fhirClient.getWebTarget().path(ResourceType.VALUE_SET.getValue()).path(valueSet.getId()).path("$expand").request(MediaType.APPLICATION_JSON_TYPE).get();
fhirClient.getWebTarget().path(ResourceType.VALUE_SET.value()).path(valueSet.getId()).path("$expand").request(MediaType.APPLICATION_JSON_TYPE).get();
FHIRClientUtil.handleErrorResponse(response);

ValueSet expanded = response.readEntity(ValueSet.class);
Expand All @@ -97,7 +98,7 @@ public Iterable<Code> expand(ValueSetInfo valueSet) {
public Code lookup(Code code, CodeSystemInfo codeSystem) {
try {
Response response =
fhirClient.getWebTarget().path(ResourceType.CODE_SYSTEM.getValue()).path("$lookup").queryParam("code", FHIRClientUtil.urlencode(code.getCode())).queryParam("system", FHIRClientUtil.urlencode(code.getSystem())).request(MediaType.APPLICATION_JSON_TYPE).get();
fhirClient.getWebTarget().path(ResourceType.CODE_SYSTEM.value()).path("$lookup").queryParam("code", FHIRClientUtil.urlencode(code.getCode())).queryParam("system", FHIRClientUtil.urlencode(code.getSystem())).request(MediaType.APPLICATION_JSON_TYPE).get();
FHIRClientUtil.handleErrorResponse(response);

Parameters respParam = response.readEntity(Parameters.class);
Expand All @@ -116,15 +117,15 @@ public Code lookup(Code code, CodeSystemInfo codeSystem) {
}

/**
* Lookup a ValueSet that corresponds to the provided CQL ValueSetInfo. Only the
* Lookup a ValueSet that corresponds to the provided CQL ValueSetInfo. Only the
* ValueSetInfo.id property is supported at this time. Use of the ValueSetInfo.version
* or ValueSetInfo.codesystems properties will cause an UnsupportedOperationException.
* This method uses a search strategy that first treats the ValueSetInfo.id as a URL,
* then attempts urn:oid or urn:uuid resolution, then finally attempts plain ID-based
* resolution if nothing has been found and the value appears to be a FHIR ID.
*
*
* @param valueSet CQL ValueSetInfo with ID property populated
* @throws UnsupportedOperationException if the ValueSetInfo.codesystem property
* @throws UnsupportedOperationException if the ValueSetInfo.codesystem property
* is specified.
* @throws IllegalArgumentException if zero or more than one ValueSet were resolved
* for the specified ValueSetInfo.id property.
Expand All @@ -144,13 +145,13 @@ public void resolveByUrl(ValueSetInfo valueSet) {
// https://github.com/DBCG/cql_engine/pull/462 - Use a search path of URL, identifier, and then resource id
FHIRParameters parameters = new FHIRParameters();
parameters.searchParam("url", encodedId);
response = fhirClient.search(ResourceType.VALUE_SET.getValue(), parameters);
response = fhirClient.search(ResourceType.VALUE_SET.value(), parameters);
FHIRClientUtil.handleErrorResponse(response);
searchResults = response.getResource(Bundle.class);
if (!searchResults.hasChildren() || searchResults.getEntry().isEmpty()) {
parameters = new FHIRParameters();
parameters.searchParam("identifier", encodedId);
searchResults = fhirClient.search(ResourceType.VALUE_SET.getValue(), parameters).getResource(Bundle.class);
searchResults = fhirClient.search(ResourceType.VALUE_SET.value(), parameters).getResource(Bundle.class);
if (!searchResults.hasChildren() || searchResults.getEntry().isEmpty()) {
String id = valueSet.getId();
if (id.startsWith(Constants.URN_OID)) {
Expand All @@ -164,7 +165,7 @@ public void resolveByUrl(ValueSetInfo valueSet) {
// be a FHIR resource ID, we will try to read it.
// See https://www.hl7.org/fhir/datatypes.html#id
if (id.matches("[A-Za-z0-9\\-\\.]{1,64}")) {
response = fhirClient.read(ResourceType.VALUE_SET.getValue(), id);
response = fhirClient.read(ResourceTypeCode.VALUE_SET.getValue(), id);
if (response.getStatus() == 200) {
ValueSet vs = response.getResource(ValueSet.class);
searchResults =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -16,11 +16,11 @@
import org.opencds.cqf.cql.engine.terminology.TerminologyProvider;
import org.opencds.cqf.cql.engine.terminology.ValueSetInfo;

import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.cql.Constants;
import com.ibm.fhir.model.resource.Resource;
import com.ibm.fhir.model.resource.ValueSet;
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.persistence.SingleResourceResult;
import com.ibm.fhir.server.spi.operation.FHIRResourceHelpers;
import com.ibm.fhir.term.service.FHIRTermService;
Expand All @@ -33,7 +33,7 @@
* the IBM FHIR Server FHIRTermService API to access the terminology data.
*/
public class ServerFHIRTerminologyProvider implements TerminologyProvider {

private FHIRResourceHelpers resourceHelper;

public ServerFHIRTerminologyProvider(FHIRResourceHelpers resourceHelper) {
Expand All @@ -55,7 +55,7 @@ public boolean in(Code code, ValueSetInfo valueSetInfo) {
public Iterable<Code> expand(ValueSetInfo valueSetInfo) {
List<Code> codes;

ValueSet valueSet = resolveByUrl(valueSetInfo);
ValueSet valueSet = resolveByUrl(valueSetInfo);
ValueSet expanded = FHIRTermService.getInstance().expand(valueSet);

codes = new ArrayList<>();
Expand All @@ -81,13 +81,13 @@ public Code lookup(Code code, CodeSystemInfo codeSystem) {
}

/**
* Lookup a ValueSet that corresponds to the provided CQL ValueSetInfo. Only the
* Lookup a ValueSet that corresponds to the provided CQL ValueSetInfo. Only the
* ValueSetInfo.id property is supported at this time. Use of the ValueSetInfo.version
* or ValueSetInfo.codesystems properties will cause an UnsupportedOperationException.
* This method uses a search strategy that first treats the ValueSetInfo.id as a URL,
* then attempts urn:oid or urn:uuid resolution, then finally attempts plain ID-based
* resolution if nothing has been found and the value appears to be a FHIR ID.
*
*
* @param valueSet CQL ValueSetInfo with ID property populated
* @return resolved ValueSet resource
* @throws IllegalArgumentException if the ValueSetInfo.id could not be resolved
Expand Down Expand Up @@ -120,7 +120,7 @@ protected ValueSet resolveByUrl(ValueSetInfo valueSetInfo) {
// See https://www.hl7.org/fhir/datatypes.html#id
if (id.matches("[A-Za-z0-9\\-\\.]{1,64}")) {
try {
SingleResourceResult<? extends Resource> result = resourceHelper.doRead(ResourceType.VALUE_SET.getValue(), id, /*throwExOnMissing=*/false, /*includeDeleted=*/false, /*contextResource=*/null);
SingleResourceResult<? extends Resource> result = resourceHelper.doRead(ResourceType.VALUE_SET.value(), id, /*throwExOnMissing=*/false, /*includeDeleted=*/false, /*contextResource=*/null);
if( result.isSuccess() ) {
valueSet = (ValueSet) result.getResource();
}
Expand All @@ -129,11 +129,11 @@ protected ValueSet resolveByUrl(ValueSetInfo valueSetInfo) {
}
}
}

if( valueSet == null ) {
throw new IllegalArgumentException(String.format("Could not resolve value set %s.", valueSetInfo.getId()));
}

return valueSet;
}
}
Loading

0 comments on commit 2dd380f

Please sign in to comment.