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 Apr 8, 2022
1 parent 0bdcadb commit 1e0d4b9
Show file tree
Hide file tree
Showing 525 changed files with 3,159 additions and 7,693 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;
}
}
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 Down Expand Up @@ -44,6 +44,7 @@
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.model.type.Url;
import com.ibm.fhir.model.type.Uuid;
import com.ibm.fhir.model.type.code.ResourceTypeCode;
import com.ibm.fhir.model.util.ModelSupport;
import com.ibm.fhir.model.util.ModelSupport.ElementInfo;
import com.ibm.fhir.model.visitor.Visitable;
Expand Down Expand Up @@ -104,7 +105,13 @@ private static Map<String, Class<?>> buildTypeMap() {

// add all code subtypes
for (Class<?> codeSubtype : ModelSupport.getCodeSubtypes()) {
if (codeSubtype == ResourceTypeCode.class) {
// special case handling for ResourceTypeCode
typeMap.put("ResourceType", codeSubtype);
typeMap.put("FHIRResourceType", codeSubtype);
}
typeMap.put(codeSubtype.getSimpleName(), codeSubtype);

}

return Collections.unmodifiableMap(typeMap);
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 Down Expand Up @@ -302,7 +302,7 @@ protected String getModifiedName(String name, IQueryParameter param) {
ReferenceParameter rp = (ReferenceParameter) param;
if (rp.getResourceTypeModifier() != null) {
paramName.append(":");
paramName.append(rp.getResourceTypeModifier().getValue());
paramName.append(rp.getResourceTypeModifier().value());
}

if (rp.getChainedProperty() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* (C) Copyright IBM Corp. 2021
* (C) Copyright IBM Corp. 2021, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
package com.ibm.fhir.cql.engine.searchparam;

import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.search.SearchConstants.Modifier;

public class ReferenceParameter extends BaseQueryParameter<ReferenceParameter> {
Expand Down Expand Up @@ -73,8 +73,8 @@ public String getParameterValue() {
@Override
public String toString() {
String rtm = null;
if (resourceTypeModifier != null && resourceTypeModifier.getValue() != null) {
rtm = resourceTypeModifier.getValue();
if (resourceTypeModifier != null) {
rtm = resourceTypeModifier.value();
}
return "ReferenceParameter [resourceTypeModifier=" + rtm + ", chainedProperty=" + chainedProperty + ", value=" + value + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import org.apache.commons.lang3.tuple.Pair;

import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.model.resource.SearchParameter;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.model.type.code.SearchParamType;
import com.ibm.fhir.search.util.SearchHelper;

Expand Down Expand Up @@ -75,7 +75,7 @@ public Pair<String, IQueryParameter> createSearchParameter(String context, Strin
if (SearchParamType.TOKEN.equals(searchParam.getType())) {
result = Pair.of(name, new TokenParameter(value).setName(name));
} else if (SearchParamType.REFERENCE.equals(searchParam.getType())) {
result = Pair.of(name, new ReferenceParameter(ResourceType.of(context), value).setName(name));
result = Pair.of(name, new ReferenceParameter(ResourceType.from(context), value).setName(name));
} else if (SearchParamType.QUANTITY.equals(searchParam.getType())) {
result = Pair.of(name, new QuantityParameter(new BigDecimal(value)).setName(name));
} else if (SearchParamType.STRING.equals(searchParam.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import com.ibm.fhir.core.ResourceType;
import com.ibm.fhir.cql.helpers.ParameterMap;
import com.ibm.fhir.cql.translator.CqlTranslationException;
import com.ibm.fhir.exception.FHIROperationException;
Expand All @@ -28,7 +29,6 @@
import com.ibm.fhir.model.type.CodeableConcept;
import com.ibm.fhir.model.type.code.IssueSeverity;
import com.ibm.fhir.model.type.code.IssueType;
import com.ibm.fhir.model.type.code.ResourceType;
import com.ibm.fhir.persistence.SingleResourceResult;
import com.ibm.fhir.registry.FHIRRegistry;
import com.ibm.fhir.search.util.SearchHelper;
Expand Down Expand Up @@ -62,7 +62,7 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class<? ext
try {
Library primaryLibrary = null;
if (operationContext.getType().equals(FHIROperationContext.Type.INSTANCE)) {
SingleResourceResult<?> readResult = resourceHelper.doRead(ResourceType.LIBRARY.getValue(), logicalId, true, false, null);
SingleResourceResult<?> readResult = resourceHelper.doRead(ResourceType.LIBRARY.value(), logicalId, true, false, null);
primaryLibrary = (Library) readResult.getResource();
} else if (operationContext.getType().equals(FHIROperationContext.Type.RESOURCE_TYPE)) {
Parameter param = paramMap.getSingletonParameter("library");
Expand Down
Loading

0 comments on commit 1e0d4b9

Please sign in to comment.