New formatting rules and pre-commit hooks (#5027)

* pre-apply spotless

* New pre-format checkpoint

* Once-over the repository

* Add pre-commit hook

* New github action

* excludes

* Revert "Once-over the repository"

This reverts commit 89334ba8d1.

* Once-over the repo

* do not inherit

* Revert "Once-over the repo"

This reverts commit 31ed8731ad.

* Add baisc license support to spotless

* Move license

* Fix inclusions

* Fix inclusions

* Fix licensing

* license fixes

* Remove dead file that is only a license

* Remove dead class

* remove dead file

* Tighten licensing

* Tighten licensing

* Tighten licensing

* Tighten licensing

* Remove specific package

* Make the precommit hook executable

* Fix ordering

* rollback license

* wip

* Add to deployable pom

* remove file

* Fix location

* Remove dead comment

* wipP

* Fix ratchet

* Fix up error

* Add pre-commit

* precommit fixes

* wip

* wip

* Autoformat

* remove dead pom parts

* replace internal hook with pre-commit

* Fix fetch-depth for checker action

* Remove ratchet and filter

* fix up

* rename

* Add comment check

* rework message

* First once-over of the repo

* wip

* format
This commit is contained in:
Tadgh 2023-07-11 17:36:44 -07:00 committed by GitHub
parent 1ce2043dcd
commit 52f3ef5992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2203 changed files with 63312 additions and 43299 deletions

33
.github/workflows/spotless.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: mvn spotless:check (Formatting)
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
build:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: spotless:check
run: mvn spotless:check
- uses: mshick/add-pr-comment@v2
if: always()
with:
message-success: |
Formatting check succeeded!
message-failure: |
**This Pull Request has failed the formatting check**
Please run `mvn spotless:apply` or `mvn clean install -DskipTests` to fix the formatting issues.
You can automate this auto-formatting process to execute on the git pre-push hook, by installing [pre-commit](https://pre-commit.com/) and then calling `pre-commit install --hook-type pre-push`. This will cause formatting to run automatically whenever you push.

10
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# If you wish to automatically format your code on every commit, please install this pre-commit hook by using the pre-commit framework, and running `pre-commit install`
repos:
- repo: https://github.com/ejba/pre-commit-maven
rev: v0.3.3
hooks:
- id: maven-spotless-apply
stages: [pre-push]

View File

@ -5,4 +5,3 @@ This page is a work in progress!
It serves as a place to list potential help a new volunteer could offer.
* Investigate adding support for FHIR's RDF (Turtle) encoding to HAPI

View File

@ -25,7 +25,7 @@ http://hapi.fhir.org/
This project is Open Source, licensed under the Apache Software License 2.0.
Please see [this wiki page][Link-wiki] for information on where to get help with HAPI FHIR.
Please see [this wiki page][Link-wiki] for information on where to get help with HAPI FHIR.
Please see [Smile CDR][Link-SmileCDR] for information on commercial support.
@ -43,5 +43,3 @@ Please see [Smile CDR][Link-SmileCDR] for information on commercial support.
[Badge-MavenCentral]: https://maven-badges.herokuapp.com/maven-central/ca.uhn.hapi.fhir/hapi-fhir-base/badge.svg
[Badge-CodeCov]: https://codecov.io/gh/hapifhir/hapi-fhir/branch/master/graph/badge.svg?token=zHfnKfQB9X
[Badge-License]: https://img.shields.io/badge/license-apache%202.0-60C060.svg

View File

@ -17,6 +17,12 @@
<build>
<plugins>
<!-- Anything deployable inherits the parent spotless configuration -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<inherited>true</inherited>
</plugin>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>

View File

@ -23,13 +23,11 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory;
/**
* This class exists in order to ensure that
* This class exists in order to ensure that
*/
public class AndroidMarker {
public static void configureContext(FhirContext theContext) {
theContext.setRestfulClientFactory(new OkHttpRestfulClientFactory(theContext));
}
}

View File

@ -28,5 +28,4 @@ public interface IHapiBootOrder {
int SUBSCRIPTION_MATCHING_CHANNEL_HANDLER = 300;
int AFTER_SUBSCRIPTION_INITIALIZED = 310;
}

View File

@ -19,19 +19,18 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDeclaredChildDefinition {
Logger ourLog = LoggerFactory.getLogger(BaseRuntimeChildDatatypeDefinition.class);
@ -39,11 +38,18 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl
private BaseRuntimeElementDefinition<?> myElementDefinition;
public BaseRuntimeChildDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype) {
public BaseRuntimeChildDatatypeDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
Class<? extends IBase> theDatatype) {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
// should use RuntimeChildAny
assert Modifier.isInterface(theDatatype.getModifiers()) == false : "Type of " + theDatatype + " shouldn't be here";
assert Modifier.isAbstract(theDatatype.getModifiers()) == false : "Type of " + theDatatype + " shouldn't be here";
assert Modifier.isInterface(theDatatype.getModifiers()) == false
: "Type of " + theDatatype + " shouldn't be here";
assert Modifier.isAbstract(theDatatype.getModifiers()) == false
: "Type of " + theDatatype + " shouldn't be here";
myDatatype = theDatatype;
}
@ -97,7 +103,9 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myElementDefinition = theClassToElementDefinitions.get(getDatatype());
if (myElementDefinition == null) {
myElementDefinition = theContext.getElementDefinition(getDatatype());
@ -109,5 +117,4 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl
public String toString() {
return getClass().getSimpleName() + "[" + getElementName() + "]";
}
}

View File

@ -61,7 +61,9 @@ public abstract class BaseRuntimeChildDefinition {
public abstract boolean isSummary();
abstract void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions);
abstract void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions);
@Override
public String toString() {
@ -99,13 +101,15 @@ public abstract class BaseRuntimeChildDefinition {
}
}
BaseRuntimeElementDefinition<?> findResourceReferenceDefinition(Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> next : theClassToElementDefinitions.entrySet()) {
BaseRuntimeElementDefinition<?> findResourceReferenceDefinition(
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> next :
theClassToElementDefinitions.entrySet()) {
if (IBaseReference.class.isAssignableFrom(next.getKey())) {
return next.getValue();
}
}
// Shouldn't happen
throw new IllegalStateException(Msg.code(1692) + "Unable to find reference type");
}

View File

@ -46,11 +46,15 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
private boolean myModifier;
private boolean mySummary;
BaseRuntimeDeclaredChildDefinition(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName) throws ConfigurationException {
BaseRuntimeDeclaredChildDefinition(
Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName)
throws ConfigurationException {
super();
Validate.notNull(theField, "No field specified");
ValidateUtil.isGreaterThanOrEqualTo(theChildAnnotation.min(), 0, "Min must be >= 0");
Validate.isTrue(theChildAnnotation.max() == -1 || theChildAnnotation.max() >= theChildAnnotation.min(), "Max must be >= Min (unless it is -1 / unlimited)");
Validate.isTrue(
theChildAnnotation.max() == -1 || theChildAnnotation.max() >= theChildAnnotation.min(),
"Max must be >= Min (unless it is -1 / unlimited)");
Validate.notBlank(theElementName, "Element name must not be blank");
myField = theField;
@ -76,7 +80,6 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
myAccessor = new FieldPlainAccessor();
myMutator = new FieldPlainMutator();
}
}
@Override
@ -147,7 +150,6 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
}
return retVal;
}
}
protected final class FieldListMutator implements IMutator {
@ -181,10 +183,12 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
public void remove(IBase theTarget, int theIndex) {
List<IBase> existingList = (List<IBase>) getFieldValue(theTarget, myField);
if (existingList == null) {
throw new IndexOutOfBoundsException(Msg.code(2143) + "Can not remove element at index " + theIndex + " from list - List is null");
throw new IndexOutOfBoundsException(
Msg.code(2143) + "Can not remove element at index " + theIndex + " from list - List is null");
}
if (theIndex >= existingList.size()) {
throw new IndexOutOfBoundsException(Msg.code(2144) + "Can not remove element at index " + theIndex + " from list - List size is " + existingList.size());
throw new IndexOutOfBoundsException(Msg.code(2144) + "Can not remove element at index " + theIndex
+ " from list - List size is " + existingList.size());
}
existingList.remove(theIndex);
}
@ -202,7 +206,7 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
@Override
public <T extends IBase> Optional<T> getFirstValueOrNull(IBase theTarget) {
return Optional.ofNullable(((T)getFieldValue(theTarget, myField)));
return Optional.ofNullable(((T) getFieldValue(theTarget, myField)));
}
}
@ -219,7 +223,9 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
@Override
public void remove(IBase theTarget, int theIndex) {
throw new UnsupportedOperationException(Msg.code(2142) + "Remove by index can only be called on a list-valued field. '" + myField.getName() + "' is a single-valued field.");
throw new UnsupportedOperationException(
Msg.code(2142) + "Remove by index can only be called on a list-valued field. '" + myField.getName()
+ "' is a single-valued field.");
}
}
@ -238,5 +244,4 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
throw new ConfigurationException(Msg.code(1737) + "Failed to get value", e);
}
}
}

View File

@ -69,7 +69,8 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> extends BaseRuntimeElementDefinition<T> {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseRuntimeElementCompositeDefinition.class);
private static final org.slf4j.Logger ourLog =
org.slf4j.LoggerFactory.getLogger(BaseRuntimeElementCompositeDefinition.class);
private final FhirContext myContext;
private Map<String, Integer> forcedOrder = null;
private List<BaseRuntimeChildDefinition> myChildren = new ArrayList<>();
@ -80,7 +81,12 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
private volatile SealingStateEnum mySealed = SealingStateEnum.NOT_SEALED;
@SuppressWarnings("unchecked")
public BaseRuntimeElementCompositeDefinition(String theName, Class<? extends T> theImplementingClass, boolean theStandardType, FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public BaseRuntimeElementCompositeDefinition(
String theName,
Class<? extends T> theImplementingClass,
boolean theStandardType,
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theName, theImplementingClass, theStandardType);
myContext = theContext;
@ -126,7 +132,6 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
}
}
}
void addChild(BaseRuntimeChildDefinition theNext) {
@ -134,7 +139,8 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
throw new NullPointerException(Msg.code(1698));
}
if (theNext.getExtensionUrl() != null) {
throw new IllegalArgumentException(Msg.code(1699) + "Shouldn't haven an extension URL, use addExtension instead");
throw new IllegalArgumentException(
Msg.code(1699) + "Shouldn't haven an extension URL, use addExtension instead");
}
myChildren.add(theNext);
}
@ -145,11 +151,13 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
return myNameToChild.get(theName);
}
public BaseRuntimeChildDefinition getChildByNameOrThrowDataFormatException(String theName) throws DataFormatException {
public BaseRuntimeChildDefinition getChildByNameOrThrowDataFormatException(String theName)
throws DataFormatException {
validateSealed();
BaseRuntimeChildDefinition retVal = myNameToChild.get(theName);
if (retVal == null) {
throw new DataFormatException(Msg.code(1700) + "Unknown child name '" + theName + "' in element " + getName() + " - Valid names are: " + new TreeSet<String>(myNameToChild.keySet()));
throw new DataFormatException(Msg.code(1700) + "Unknown child name '" + theName + "' in element "
+ getName() + " - Valid names are: " + new TreeSet<String>(myNameToChild.keySet()));
}
return retVal;
}
@ -160,13 +168,11 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
return myChildren;
}
public List<BaseRuntimeChildDefinition> getChildrenAndExtension() {
validateSealed();
return myChildrenAndExtensions;
}
/**
* Has this class been sealed
*/
@ -178,12 +184,14 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
void populateScanAlso(Set<Class<? extends IBase>> theScanAlso) {
for (ScannedField next : myScannedFields) {
if (IBase.class.isAssignableFrom(next.getElementType())) {
if (next.getElementType().isInterface() == false && Modifier.isAbstract(next.getElementType().getModifiers()) == false) {
if (next.getElementType().isInterface() == false
&& Modifier.isAbstract(next.getElementType().getModifiers()) == false) {
theScanAlso.add((Class<? extends IBase>) next.getElementType());
}
}
for (Class<? extends IBase> nextChildType : next.getChoiceTypes()) {
if (nextChildType.isInterface() == false && Modifier.isAbstract(nextChildType.getModifiers()) == false) {
if (nextChildType.isInterface() == false
&& Modifier.isAbstract(nextChildType.getModifiers()) == false) {
theScanAlso.add(nextChildType);
}
}
@ -233,17 +241,20 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
this.addExtension((RuntimeChildDeclaredExtensionDefinition) nextExt);
}
}
}
@SuppressWarnings("unchecked")
private void scanCompositeElementForChildren(Set<String> elementNames, TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToElementDef,
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToExtensionDef) {
private void scanCompositeElementForChildren(
Set<String> elementNames,
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToElementDef,
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToExtensionDef) {
int baseElementOrder = 0;
for (ScannedField next : myScannedFields) {
if (next.isFirstFieldInNewClass()) {
baseElementOrder = theOrderToElementDef.isEmpty() ? 0 : theOrderToElementDef.lastEntry().getKey() + 1;
baseElementOrder = theOrderToElementDef.isEmpty()
? 0
: theOrderToElementDef.lastEntry().getKey() + 1;
}
Class<?> declaringClass = next.getField().getDeclaringClass();
@ -281,8 +292,12 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
}
if (order == Child.REPLACE_PARENT) {
throw new ConfigurationException(Msg.code(1701) + "Field " + nextField.getName() + "' on target type " + declaringClass.getSimpleName() + " has order() of REPLACE_PARENT (" + Child.REPLACE_PARENT
+ ") but no parent element with extension URL " + extensionAttr.url() + " could be found on type " + nextField.getDeclaringClass().getSimpleName());
throw new ConfigurationException(
Msg.code(1701) + "Field " + nextField.getName() + "' on target type "
+ declaringClass.getSimpleName() + " has order() of REPLACE_PARENT ("
+ Child.REPLACE_PARENT + ") but no parent element with extension URL "
+ extensionAttr.url() + " could be found on type "
+ nextField.getDeclaringClass().getSimpleName());
}
} else {
@ -308,16 +323,18 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
}
if (order == Child.REPLACE_PARENT) {
throw new ConfigurationException(Msg.code(1702) + "Field " + nextField.getName() + "' on target type " + declaringClass.getSimpleName() + " has order() of REPLACE_PARENT (" + Child.REPLACE_PARENT
+ ") but no parent element with name " + elementName + " could be found on type " + nextField.getDeclaringClass().getSimpleName());
throw new ConfigurationException(Msg.code(1702) + "Field " + nextField.getName()
+ "' on target type " + declaringClass.getSimpleName()
+ " has order() of REPLACE_PARENT (" + Child.REPLACE_PARENT
+ ") but no parent element with name " + elementName + " could be found on type "
+ nextField.getDeclaringClass().getSimpleName());
}
}
}
if (order < 0 && order != Child.ORDER_UNKNOWN) {
throw new ConfigurationException(Msg.code(1703) + "Invalid order '" + order + "' on @Child for field '" + nextField.getName() + "' on target type: " + declaringClass);
throw new ConfigurationException(Msg.code(1703) + "Invalid order '" + order + "' on @Child for field '"
+ nextField.getName() + "' on target type: " + declaringClass);
}
if (order != Child.ORDER_UNKNOWN && !orderIsReplaceParent) {
@ -339,34 +356,49 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
List<Class<? extends IBase>> choiceTypes = next.getChoiceTypes();
if (orderMap.containsKey(order)) {
throw new ConfigurationException(Msg.code(1704) + "Detected duplicate field order '" + childAnnotation.order() + "' for element named '" + elementName + "' in type '" + declaringClass.getCanonicalName() + "' - Already had: " + orderMap.get(order).getElementName());
throw new ConfigurationException(Msg.code(1704) + "Detected duplicate field order '"
+ childAnnotation.order() + "' for element named '" + elementName + "' in type '"
+ declaringClass.getCanonicalName() + "' - Already had: "
+ orderMap.get(order).getElementName());
}
if (elementNames.contains(elementName)) {
throw new ConfigurationException(Msg.code(1705) + "Detected duplicate field name '" + elementName + "' in type '" + declaringClass.getCanonicalName() + "'");
throw new ConfigurationException(Msg.code(1705) + "Detected duplicate field name '" + elementName
+ "' in type '" + declaringClass.getCanonicalName() + "'");
}
Class<?> nextElementType = next.getElementType();
BaseRuntimeDeclaredChildDefinition def;
if (childAnnotation.name().equals("extension") && IBaseExtension.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildExtension(nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation);
} else if (childAnnotation.name().equals("modifierExtension") && IBaseExtension.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildExtension(nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation);
} else if (BaseContainedDt.class.isAssignableFrom(nextElementType) || (childAnnotation.name().equals("contained") && IBaseResource.class.isAssignableFrom(nextElementType))) {
def = new RuntimeChildExtension(
nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation);
} else if (childAnnotation.name().equals("modifierExtension")
&& IBaseExtension.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildExtension(
nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation);
} else if (BaseContainedDt.class.isAssignableFrom(nextElementType)
|| (childAnnotation.name().equals("contained")
&& IBaseResource.class.isAssignableFrom(nextElementType))) {
/*
* Child is contained resources
*/
def = new RuntimeChildContainedResources(nextField, childAnnotation, descriptionAnnotation, elementName);
} else if (IAnyResource.class.isAssignableFrom(nextElementType) || IResource.class.equals(nextElementType)) {
def = new RuntimeChildContainedResources(
nextField, childAnnotation, descriptionAnnotation, elementName);
} else if (IAnyResource.class.isAssignableFrom(nextElementType)
|| IResource.class.equals(nextElementType)) {
/*
* Child is a resource as a direct child, as in Bundle.entry.resource
*/
def = new RuntimeChildDirectResource(nextField, childAnnotation, descriptionAnnotation, elementName);
} else {
childIsChoiceType |= choiceTypes.size() > 1;
if (extensionAttr == null && childIsChoiceType && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) && !IBaseReference.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildChoiceDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, choiceTypes);
if (extensionAttr == null
&& childIsChoiceType
&& !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)
&& !IBaseReference.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildChoiceDefinition(
nextField, elementName, childAnnotation, descriptionAnnotation, choiceTypes);
} else if (extensionAttr != null) {
/*
* Child is an extension
@ -374,72 +406,124 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
Class<? extends IBase> et = (Class<? extends IBase>) nextElementType;
Object binder = null;
if (BoundCodeDt.class.isAssignableFrom(nextElementType) || IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) {
if (BoundCodeDt.class.isAssignableFrom(nextElementType)
|| IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) {
binder = ModelScanner.getBoundCodeBinder(nextField);
}
def = new RuntimeChildDeclaredExtensionDefinition(nextField, childAnnotation, descriptionAnnotation, extensionAttr, elementName, extensionAttr.url(), et, binder);
def = new RuntimeChildDeclaredExtensionDefinition(
nextField,
childAnnotation,
descriptionAnnotation,
extensionAttr,
elementName,
extensionAttr.url(),
et,
binder);
if (IBaseEnumeration.class.isAssignableFrom(nextElementType)) {
((RuntimeChildDeclaredExtensionDefinition) def).setEnumerationType(ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(nextField));
((RuntimeChildDeclaredExtensionDefinition) def)
.setEnumerationType(
ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(
nextField));
}
} else if (BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) || IBaseReference.class.isAssignableFrom(nextElementType)) {
} else if (BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)
|| IBaseReference.class.isAssignableFrom(nextElementType)) {
/*
* Child is a resource reference
*/
List<Class<? extends IBaseResource>> refTypesList = new ArrayList<>();
for (Class<? extends IElement> nextType : childAnnotation.type()) {
if (IBaseReference.class.isAssignableFrom(nextType)) {
refTypesList.add(myContext.getVersion().getVersion().isRi() ? IAnyResource.class : IResource.class);
refTypesList.add(
myContext.getVersion().getVersion().isRi() ? IAnyResource.class : IResource.class);
continue;
} else if (IBaseResource.class.isAssignableFrom(nextType) == false) {
throw new ConfigurationException(Msg.code(1706) + "Field '" + nextField.getName() + "' in class '" + nextField.getDeclaringClass().getCanonicalName() + "' is of type " + BaseResourceReferenceDt.class + " but contains a non-resource type: " + nextType.getCanonicalName());
throw new ConfigurationException(
Msg.code(1706) + "Field '" + nextField.getName() + "' in class '"
+ nextField.getDeclaringClass().getCanonicalName() + "' is of type "
+ BaseResourceReferenceDt.class + " but contains a non-resource type: "
+ nextType.getCanonicalName());
}
refTypesList.add((Class<? extends IBaseResource>) nextType);
}
def = new RuntimeChildResourceDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, refTypesList);
def = new RuntimeChildResourceDefinition(
nextField, elementName, childAnnotation, descriptionAnnotation, refTypesList);
} else if (IResourceBlock.class.isAssignableFrom(nextElementType) || IBaseBackboneElement.class.isAssignableFrom(nextElementType)
|| IBaseDatatypeElement.class.isAssignableFrom(nextElementType)) {
} else if (IResourceBlock.class.isAssignableFrom(nextElementType)
|| IBaseBackboneElement.class.isAssignableFrom(nextElementType)
|| IBaseDatatypeElement.class.isAssignableFrom(nextElementType)) {
/*
* Child is a resource block (i.e. a sub-tag within a resource) TODO: do these have a better name according to HL7?
*/
Class<? extends IBase> blockDef = (Class<? extends IBase>) nextElementType;
def = new RuntimeChildResourceBlockDefinition(myContext, nextField, childAnnotation, descriptionAnnotation, elementName, blockDef);
} else if (IDatatype.class.equals(nextElementType) || IElement.class.equals(nextElementType) || "Type".equals(nextElementType.getSimpleName())
|| IBaseDatatype.class.equals(nextElementType)) {
def = new RuntimeChildResourceBlockDefinition(
myContext, nextField, childAnnotation, descriptionAnnotation, elementName, blockDef);
} else if (IDatatype.class.equals(nextElementType)
|| IElement.class.equals(nextElementType)
|| "Type".equals(nextElementType.getSimpleName())
|| IBaseDatatype.class.equals(nextElementType)) {
def = new RuntimeChildAny(nextField, elementName, childAnnotation, descriptionAnnotation);
} else if (IDatatype.class.isAssignableFrom(nextElementType) || IPrimitiveType.class.isAssignableFrom(nextElementType) || ICompositeType.class.isAssignableFrom(nextElementType)
|| IBaseDatatype.class.isAssignableFrom(nextElementType) || IBaseExtension.class.isAssignableFrom(nextElementType)) {
} else if (IDatatype.class.isAssignableFrom(nextElementType)
|| IPrimitiveType.class.isAssignableFrom(nextElementType)
|| ICompositeType.class.isAssignableFrom(nextElementType)
|| IBaseDatatype.class.isAssignableFrom(nextElementType)
|| IBaseExtension.class.isAssignableFrom(nextElementType)) {
Class<? extends IBase> nextDatatype = (Class<? extends IBase>) nextElementType;
if (IPrimitiveType.class.isAssignableFrom(nextElementType)) {
if (nextElementType.equals(BoundCodeDt.class)) {
IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField);
Class<? extends Enum<?>> enumType = ModelScanner.determineEnumTypeForBoundField(nextField);
def = new RuntimeChildPrimitiveBoundCodeDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype, binder, enumType);
def = new RuntimeChildPrimitiveBoundCodeDatatypeDefinition(
nextField,
elementName,
childAnnotation,
descriptionAnnotation,
nextDatatype,
binder,
enumType);
} else if (IBaseEnumeration.class.isAssignableFrom(nextElementType)) {
Class<? extends Enum<?>> binderType = ModelScanner.determineEnumTypeForBoundField(nextField);
def = new RuntimeChildPrimitiveEnumerationDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype, binderType);
Class<? extends Enum<?>> binderType =
ModelScanner.determineEnumTypeForBoundField(nextField);
def = new RuntimeChildPrimitiveEnumerationDatatypeDefinition(
nextField,
elementName,
childAnnotation,
descriptionAnnotation,
nextDatatype,
binderType);
} else {
def = new RuntimeChildPrimitiveDatatypeDefinition(nextField, elementName, descriptionAnnotation, childAnnotation, nextDatatype);
def = new RuntimeChildPrimitiveDatatypeDefinition(
nextField, elementName, descriptionAnnotation, childAnnotation, nextDatatype);
}
} else {
if (IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) {
IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField);
Class<? extends Enum<?>> enumType = ModelScanner.determineEnumTypeForBoundField(nextField);
def = new RuntimeChildCompositeBoundDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype, binder, enumType);
} else if (BaseNarrativeDt.class.isAssignableFrom(nextElementType) || INarrative.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildNarrativeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype);
def = new RuntimeChildCompositeBoundDatatypeDefinition(
nextField,
elementName,
childAnnotation,
descriptionAnnotation,
nextDatatype,
binder,
enumType);
} else if (BaseNarrativeDt.class.isAssignableFrom(nextElementType)
|| INarrative.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildNarrativeDefinition(
nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype);
} else {
def = new RuntimeChildCompositeDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype);
def = new RuntimeChildCompositeDatatypeDefinition(
nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype);
}
}
} else {
throw new ConfigurationException(Msg.code(1707) + "Field '" + elementName + "' in type '" + declaringClass.getCanonicalName() + "' is not a valid child type: " + nextElementType);
throw new ConfigurationException(Msg.code(1707) + "Field '" + elementName + "' in type '"
+ declaringClass.getCanonicalName() + "' is not a valid child type: " + nextElementType);
}
Binding bindingAnnotation = ModelScanner.pullAnnotation(nextField, Binding.class);
@ -448,7 +532,6 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
def.setBindingValueSet(bindingAnnotation.valueSet());
}
}
}
def.setReplacedParentDefinition(replacedParent);
@ -458,7 +541,9 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
if (mySealed == SealingStateEnum.SEALED) {
return;
}
@ -485,7 +570,8 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
for (String nextName : next.getValidChildNames()) {
if (myNameToChild.containsKey(nextName)) {
throw new ConfigurationException(Msg.code(1708) + "Duplicate child name[" + nextName + "] in Element[" + getName() + "]");
throw new ConfigurationException(Msg.code(1708) + "Duplicate child name[" + nextName
+ "] in Element[" + getName() + "]");
}
myNameToChild.put(nextName, next);
}
@ -538,7 +624,6 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
}
@Override
protected void validateSealed() {
if (mySealed != SealingStateEnum.SEALED) {
@ -610,7 +695,8 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
}
private static int findIndex(List<BaseRuntimeChildDefinition> theChildren, String theName, boolean theDefaultAtEnd) {
private static int findIndex(
List<BaseRuntimeChildDefinition> theChildren, String theName, boolean theDefaultAtEnd) {
int index = theDefaultAtEnd ? theChildren.size() : -1;
for (ListIterator<BaseRuntimeChildDefinition> iter = theChildren.listIterator(); iter.hasNext(); ) {
if (iter.next().getElementName().equals(theName)) {
@ -620,5 +706,4 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
}
return index;
}
}

View File

@ -25,14 +25,14 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class BaseRuntimeElementDefinition<T extends IBase> {
@ -47,7 +47,8 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
private Map<String, RuntimeChildDeclaredExtensionDefinition> myUrlToExtension = new HashMap<>();
private BaseRuntimeElementDefinition<?> myRootParentDefinition;
public BaseRuntimeElementDefinition(String theName, Class<? extends T> theImplementingClass, boolean theStandardType) {
public BaseRuntimeElementDefinition(
String theName, Class<? extends T> theImplementingClass, boolean theStandardType) {
assert StringUtils.isNotBlank(theName);
assert theImplementingClass != null;
@ -57,7 +58,6 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
name = name.substring(0, name.length() - 2);
}
myName = name;
myStandardType = theStandardType;
myImplementingClass = theImplementingClass;
@ -100,7 +100,8 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
}
}
if (retVal == null) {
throw new ConfigurationException(Msg.code(1695) + "Class " + getImplementingClass() + " has no constructor with a single argument of type " + argumentType);
throw new ConfigurationException(Msg.code(1695) + "Class " + getImplementingClass()
+ " has no constructor with a single argument of type " + argumentType);
}
myConstructors.put(argumentType, retVal);
}
@ -110,12 +111,15 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
/**
* @return Returns null if none
*/
public RuntimeChildDeclaredExtensionDefinition getDeclaredExtension(String theExtensionUrl, final String serverBaseUrl) {
public RuntimeChildDeclaredExtensionDefinition getDeclaredExtension(
String theExtensionUrl, final String serverBaseUrl) {
validateSealed();
RuntimeChildDeclaredExtensionDefinition definition = myUrlToExtension.get(theExtensionUrl);
if (definition == null && StringUtils.isNotBlank(serverBaseUrl)) {
for (final Map.Entry<String, RuntimeChildDeclaredExtensionDefinition> entry : myUrlToExtension.entrySet()) {
final String key = (!UrlUtil.isValid(entry.getKey()) && StringUtils.isNotBlank(serverBaseUrl)) ? serverBaseUrl + entry.getKey() : entry.getKey();
final String key = (!UrlUtil.isValid(entry.getKey()) && StringUtils.isNotBlank(serverBaseUrl))
? serverBaseUrl + entry.getKey()
: entry.getKey();
if (key.equals(theExtensionUrl)) {
definition = entry.getValue();
break;
@ -173,7 +177,10 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
return getConstructor(theArgument).newInstance(theArgument);
} catch (Exception e) {
throw new ConfigurationException(Msg.code(1696) + "Failed to instantiate type:" + getImplementingClass().getName(), e);
throw new ConfigurationException(
Msg.code(1696) + "Failed to instantiate type:"
+ getImplementingClass().getName(),
e);
}
}
@ -187,7 +194,9 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
*
* @param theContext TODO
*/
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
for (BaseRuntimeChildDefinition next : myExtensions) {
next.sealAndInitialize(theContext, theClassToElementDefinitions);
}
@ -195,7 +204,8 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
for (RuntimeChildDeclaredExtensionDefinition next : myExtensions) {
String extUrl = next.getExtensionUrl();
if (myUrlToExtension.containsKey(extUrl)) {
throw new ConfigurationException(Msg.code(1697) + "Duplicate extension URL[" + extUrl + "] in Element[" + getName() + "]");
throw new ConfigurationException(
Msg.code(1697) + "Duplicate extension URL[" + extUrl + "] in Element[" + getName() + "]");
}
myUrlToExtension.put(extUrl, next);
if (next.isModifier()) {
@ -203,7 +213,6 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
} else {
myExtensionsNonModifier.add(next);
}
}
myExtensions = Collections.unmodifiableList(myExtensions);
@ -216,12 +225,12 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
}
parent = parent.getSuperclass();
} while (!parent.equals(Object.class));
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + getName() + ", " + getImplementingClass().getSimpleName() + "]";
return getClass().getSimpleName() + "[" + getName() + ", "
+ getImplementingClass().getSimpleName() + "]";
}
protected void validateSealed() {
@ -245,7 +254,8 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
/**
* HAPI structure style.
*/
CONTAINED_RESOURCES, EXTENSION_DECLARED,
CONTAINED_RESOURCES,
EXTENSION_DECLARED,
ID_DATATYPE,
PRIMITIVE_DATATYPE,
/**
@ -260,7 +270,5 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
RESOURCE_BLOCK,
UNDECL_EXT,
}
}

View File

@ -20,8 +20,6 @@
package ca.uhn.fhir.context;
public enum ComboSearchParamType {
UNIQUE,
NON_UNIQUE
}

View File

@ -20,7 +20,7 @@
package ca.uhn.fhir.context;
/**
* Non-checked exception indicating that HAPI was unable to initialize due to
* Non-checked exception indicating that HAPI was unable to initialize due to
* a detected configuration problem.
*/
public class ConfigurationException extends RuntimeException {
@ -42,5 +42,4 @@ public class ConfigurationException extends RuntimeException {
public ConfigurationException(Throwable theCause) {
super(theCause);
}
}

View File

@ -56,8 +56,6 @@ import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
@ -75,6 +73,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* The FHIR context is the central starting point for the use of the HAPI FHIR API. It should be created once, and then
@ -100,14 +100,16 @@ import java.util.Set;
public class FhirContext {
private static final List<Class<? extends IBaseResource>> EMPTY_LIST = Collections.emptyList();
private static final Map<FhirVersionEnum, FhirContext> ourStaticContexts = Collections.synchronizedMap(new EnumMap<>(FhirVersionEnum.class));
private static final Map<FhirVersionEnum, FhirContext> ourStaticContexts =
Collections.synchronizedMap(new EnumMap<>(FhirVersionEnum.class));
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirContext.class);
private final IFhirVersion myVersion;
private final Map<String, Class<? extends IBaseResource>> myDefaultTypeForProfile = new HashMap<>();
private final Set<PerformanceOptionsEnum> myPerformanceOptions = new HashSet<>();
private final Collection<Class<? extends IBaseResource>> myResourceTypesToScan;
private AddProfileTagEnum myAddProfileTagWhenEncoding = AddProfileTagEnum.ONLY_FOR_CUSTOM;
private volatile Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> myClassToElementDefinition = Collections.emptyMap();
private volatile Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> myClassToElementDefinition =
Collections.emptyMap();
private ArrayList<Class<? extends IBase>> myCustomTypes;
private volatile Map<String, RuntimeResourceDefinition> myIdToResourceDefinition = Collections.emptyMap();
private volatile boolean myInitialized;
@ -122,7 +124,8 @@ public class FhirContext {
private volatile IRestfulClientFactory myRestfulClientFactory;
private volatile RuntimeChildUndeclaredExtensionDefinition myRuntimeChildUndeclaredExtensionDefinition;
private IValidationSupport myValidationSupport;
private Map<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>> myVersionToNameToResourceType = Collections.emptyMap();
private Map<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>> myVersionToNameToResourceType =
Collections.emptyMap();
private volatile Set<String> myResourceNames;
private volatile Boolean myFormatXmlSupported;
private volatile Boolean myFormatJsonSupported;
@ -175,12 +178,15 @@ public class FhirContext {
this(theVersion, null);
}
private FhirContext(final FhirVersionEnum theVersion, final Collection<Class<? extends IBaseResource>> theResourceTypes) {
private FhirContext(
final FhirVersionEnum theVersion, final Collection<Class<? extends IBaseResource>> theResourceTypes) {
VersionUtil.getVersion();
if (theVersion != null) {
if (!theVersion.isPresentOnClasspath()) {
throw new IllegalStateException(Msg.code(1680) + getLocalizer().getMessage(FhirContext.class, "noStructuresForSpecifiedVersion", theVersion.name()));
throw new IllegalStateException(Msg.code(1680)
+ getLocalizer()
.getMessage(FhirContext.class, "noStructuresForSpecifiedVersion", theVersion.name()));
}
myVersion = theVersion.getVersionImplementation();
} else if (FhirVersionEnum.DSTU2.isPresentOnClasspath()) {
@ -196,18 +202,25 @@ public class FhirContext {
} else if (FhirVersionEnum.R4B.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.R4B.getVersionImplementation();
} else {
throw new IllegalStateException(Msg.code(1681) + getLocalizer().getMessage(FhirContext.class, "noStructures"));
throw new IllegalStateException(
Msg.code(1681) + getLocalizer().getMessage(FhirContext.class, "noStructures"));
}
if (theVersion == null) {
ourLog.info("Creating new FhirContext with auto-detected version [{}]. It is recommended to explicitly select a version for future compatibility by invoking FhirContext.forDstuX()",
myVersion.getVersion().name());
ourLog.info(
"Creating new FhirContext with auto-detected version [{}]. It is recommended to explicitly select a version for future compatibility by invoking FhirContext.forDstuX()",
myVersion.getVersion().name());
} else {
if (HapiSystemProperties.isUnitTestModeEnabled()) {
String calledAt = ExceptionUtils.getStackFrames(new Throwable())[4];
ourLog.info("Creating new FHIR context for FHIR version [{}]{}", myVersion.getVersion().name(), calledAt);
ourLog.info(
"Creating new FHIR context for FHIR version [{}]{}",
myVersion.getVersion().name(),
calledAt);
} else {
ourLog.info("Creating new FHIR context for FHIR version [{}]", myVersion.getVersion().name());
ourLog.info(
"Creating new FHIR context for FHIR version [{}]",
myVersion.getVersion().name());
}
}
@ -228,10 +241,8 @@ public class FhirContext {
} catch (ClassNotFoundException e) {
ourLog.trace("Android mode not detected");
}
}
/**
* @since 5.6.0
*/
@ -246,7 +257,6 @@ public class FhirContext {
return forCached(FhirVersionEnum.DSTU2_HL7ORG);
}
/**
* @since 5.5.0
*/
@ -475,7 +485,9 @@ public class FhirContext {
Validate.notNull(theResourceType, "theResourceType can not be null");
if (Modifier.isAbstract(theResourceType.getModifiers())) {
throw new IllegalArgumentException(Msg.code(1682) + "Can not scan abstract or interface class (resource definitions must be concrete classes): " + theResourceType.getName());
throw new IllegalArgumentException(Msg.code(1682)
+ "Can not scan abstract or interface class (resource definitions must be concrete classes): "
+ theResourceType.getName());
}
RuntimeResourceDefinition retVal = (RuntimeResourceDefinition) myClassToElementDefinition.get(theResourceType);
@ -486,7 +498,8 @@ public class FhirContext {
return retVal;
}
public RuntimeResourceDefinition getResourceDefinition(final FhirVersionEnum theVersion, final String theResourceName) {
public RuntimeResourceDefinition getResourceDefinition(
final FhirVersionEnum theVersion, final String theResourceName) {
Validate.notNull(theVersion, "theVersion can not be null");
validateInitialized();
@ -500,7 +513,8 @@ public class FhirContext {
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = new HashMap<>();
ModelScanner.scanVersionPropertyFile(null, nameToType, theVersion, existing);
Map<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>> newVersionToNameToResourceType = new HashMap<>();
Map<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>> newVersionToNameToResourceType =
new HashMap<>();
newVersionToNameToResourceType.putAll(myVersionToNameToResourceType);
newVersionToNameToResourceType.put(theVersion, nameToType);
myVersionToNameToResourceType = newVersionToNameToResourceType;
@ -575,7 +589,8 @@ public class FhirContext {
// Multiple spots in HAPI FHIR and Smile CDR depend on DataFormatException
// being thrown by this method, don't change that.
// ***********************************************************************
throw new DataFormatException(Msg.code(1684) + createUnknownResourceNameError(theResourceName, myVersion.getVersion()));
throw new DataFormatException(
Msg.code(1684) + createUnknownResourceNameError(theResourceName, myVersion.getVersion()));
}
if (IBaseResource.class.isAssignableFrom(clazz)) {
retVal = scanResourceType(clazz);
@ -645,9 +660,13 @@ public class FhirContext {
public IRestfulClientFactory getRestfulClientFactory() {
if (myRestfulClientFactory == null) {
try {
myRestfulClientFactory = (IRestfulClientFactory) ReflectionUtil.newInstance(Class.forName("ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory"), FhirContext.class, this);
myRestfulClientFactory = (IRestfulClientFactory) ReflectionUtil.newInstance(
Class.forName("ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory"),
FhirContext.class,
this);
} catch (ClassNotFoundException e) {
throw new ConfigurationException(Msg.code(1686) + "hapi-fhir-client does not appear to be on the classpath");
throw new ConfigurationException(
Msg.code(1686) + "hapi-fhir-client does not appear to be on the classpath");
}
}
return myRestfulClientFactory;
@ -684,20 +703,31 @@ public class FhirContext {
* If hapi-fhir-validation is on the classpath, we can create a much more robust
* validation chain using the classes found in that package
*/
String inMemoryTermSvcType = "org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport";
String commonCodeSystemsSupportType = "org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService";
String inMemoryTermSvcType =
"org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport";
String commonCodeSystemsSupportType =
"org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService";
if (ReflectionUtil.typeExists(inMemoryTermSvcType)) {
IValidationSupport inMemoryTermSvc = ReflectionUtil.newInstanceOrReturnNull(inMemoryTermSvcType, IValidationSupport.class, new Class<?>[]{FhirContext.class}, new Object[]{this});
IValidationSupport commonCodeSystemsSupport = ReflectionUtil.newInstanceOrReturnNull(commonCodeSystemsSupportType, IValidationSupport.class, new Class<?>[]{FhirContext.class}, new Object[]{this});
retVal = ReflectionUtil.newInstanceOrReturnNull("org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain", IValidationSupport.class, new Class<?>[]{IValidationSupport[].class}, new Object[]{new IValidationSupport[]{
retVal,
inMemoryTermSvc,
commonCodeSystemsSupport
}});
assert retVal != null : "Failed to instantiate " + "org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain";
IValidationSupport inMemoryTermSvc = ReflectionUtil.newInstanceOrReturnNull(
inMemoryTermSvcType,
IValidationSupport.class,
new Class<?>[] {FhirContext.class},
new Object[] {this});
IValidationSupport commonCodeSystemsSupport = ReflectionUtil.newInstanceOrReturnNull(
commonCodeSystemsSupportType,
IValidationSupport.class,
new Class<?>[] {FhirContext.class},
new Object[] {this});
retVal = ReflectionUtil.newInstanceOrReturnNull(
"org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain",
IValidationSupport.class,
new Class<?>[] {IValidationSupport[].class},
new Object[] {new IValidationSupport[] {retVal, inMemoryTermSvc, commonCodeSystemsSupport}});
assert retVal != null
: "Failed to instantiate "
+ "org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain";
}
myValidationSupport = retVal;
}
return retVal;
@ -758,20 +788,20 @@ public class FhirContext {
return retVal;
}
/**
* @return Returns <code>true</code> if the NDJSON serialization format is supported, based on the
* available libraries on the classpath.
*
* @since 5.6.0
*/
public boolean isFormatNDJsonSupported() {
Boolean retVal = myFormatNDJsonSupported;
if (retVal == null) {
retVal = tryToInitParser(() -> newNDJsonParser());
myFormatNDJsonSupported = retVal;
}
return retVal;
}
/**
* @return Returns <code>true</code> if the NDJSON serialization format is supported, based on the
* available libraries on the classpath.
*
* @since 5.6.0
*/
public boolean isFormatNDJsonSupported() {
Boolean retVal = myFormatNDJsonSupported;
if (retVal == null) {
retVal = tryToInitParser(() -> newNDJsonParser());
myFormatNDJsonSupported = retVal;
}
return retVal;
}
/**
* @return Returns <code>true</code> if the RDF serialization format is supported, based on the
@ -839,28 +869,28 @@ public class FhirContext {
return new JsonParser(this, myParserErrorHandler);
}
/**
* Create and return a new NDJSON parser.
*
* <p>
* Thread safety: <b>Parsers are not guaranteed to be thread safe</b>. Create a new parser instance for every thread
* or every message being parsed/encoded.
* </p>
* <p>
* Performance Note: <b>This method is cheap</b> to call, and may be called once for every message being processed
* without incurring any performance penalty
* </p>
* <p>
* The NDJsonParser provided here is expected to translate between legal NDJson and FHIR Bundles.
* In particular, it is able to encode the resources in a FHIR Bundle to NDJson, as well as decode
* NDJson into a FHIR "collection"-type Bundle populated with the resources described in the NDJson.
* It will throw an exception in the event where it is asked to encode to anything other than a FHIR Bundle
* or where it is asked to decode into anything other than a FHIR Bundle.
* </p>
*/
public IParser newNDJsonParser() {
return new NDJsonParser(this, myParserErrorHandler);
}
/**
* Create and return a new NDJSON parser.
*
* <p>
* Thread safety: <b>Parsers are not guaranteed to be thread safe</b>. Create a new parser instance for every thread
* or every message being parsed/encoded.
* </p>
* <p>
* Performance Note: <b>This method is cheap</b> to call, and may be called once for every message being processed
* without incurring any performance penalty
* </p>
* <p>
* The NDJsonParser provided here is expected to translate between legal NDJson and FHIR Bundles.
* In particular, it is able to encode the resources in a FHIR Bundle to NDJson, as well as decode
* NDJson into a FHIR "collection"-type Bundle populated with the resources described in the NDJson.
* It will throw an exception in the event where it is asked to encode to anything other than a FHIR Bundle
* or where it is asked to decode into anything other than a FHIR Bundle.
* </p>
*/
public IParser newNDJsonParser() {
return new NDJsonParser(this, myParserErrorHandler);
}
/**
* Create and return a new RDF parser.
@ -1005,7 +1035,8 @@ public class FhirContext {
return (RuntimeResourceDefinition) defs.get(theResourceType);
}
private synchronized Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> scanResourceTypes(final Collection<Class<? extends IElement>> theResourceTypes) {
private synchronized Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> scanResourceTypes(
final Collection<Class<? extends IElement>> theResourceTypes) {
List<Class<? extends IBase>> typesToScan = new ArrayList<>();
if (theResourceTypes != null) {
typesToScan.addAll(theResourceTypes);
@ -1022,7 +1053,8 @@ public class FhirContext {
Map<String, BaseRuntimeElementDefinition<?>> nameToElementDefinition = new HashMap<>();
nameToElementDefinition.putAll(myNameToElementDefinition);
for (Entry<String, BaseRuntimeElementDefinition<?>> next : scanner.getNameToElementDefinitions().entrySet()) {
for (Entry<String, BaseRuntimeElementDefinition<?>> next :
scanner.getNameToElementDefinitions().entrySet()) {
if (!nameToElementDefinition.containsKey(next.getKey())) {
nameToElementDefinition.put(next.getKey().toLowerCase(), next.getValue());
}
@ -1030,7 +1062,8 @@ public class FhirContext {
Map<String, RuntimeResourceDefinition> nameToResourceDefinition = new HashMap<>();
nameToResourceDefinition.putAll(myNameToResourceDefinition);
for (Entry<String, RuntimeResourceDefinition> next : scanner.getNameToResourceDefinition().entrySet()) {
for (Entry<String, RuntimeResourceDefinition> next :
scanner.getNameToResourceDefinition().entrySet()) {
if (!nameToResourceDefinition.containsKey(next.getKey())) {
nameToResourceDefinition.put(next.getKey(), next.getValue());
}
@ -1043,7 +1076,8 @@ public class FhirContext {
if (next instanceof RuntimeResourceDefinition) {
if ("Bundle".equals(next.getName())) {
if (!IBaseBundle.class.isAssignableFrom(next.getImplementingClass())) {
throw new ConfigurationException(Msg.code(1687) + "Resource type declares resource name Bundle but does not implement IBaseBundle");
throw new ConfigurationException(Msg.code(1687)
+ "Resource type declares resource name Bundle but does not implement IBaseBundle");
}
}
}
@ -1111,7 +1145,8 @@ public class FhirContext {
}
@SuppressWarnings({"cast"})
private List<Class<? extends IElement>> toElementList(final Collection<Class<? extends IBaseResource>> theResourceTypes) {
private List<Class<? extends IElement>> toElementList(
final Collection<Class<? extends IBaseResource>> theResourceTypes) {
if (theResourceTypes == null) {
return null;
}
@ -1146,13 +1181,15 @@ public class FhirContext {
}
public IPrimitiveType<Boolean> newPrimitiveBoolean(Boolean theValue) {
IPrimitiveType<Boolean> retval = (IPrimitiveType<Boolean>) getElementDefinition("boolean").newInstance();
IPrimitiveType<Boolean> retval =
(IPrimitiveType<Boolean>) getElementDefinition("boolean").newInstance();
retval.setValue(theValue);
return retval;
}
public IPrimitiveType<String > newPrimitiveString(String theValue) {
IPrimitiveType<String> retval = (IPrimitiveType<String>) getElementDefinition("string").newInstance();
public IPrimitiveType<String> newPrimitiveString(String theValue) {
IPrimitiveType<String> retval =
(IPrimitiveType<String>) getElementDefinition("string").newInstance();
retval.setValue(theValue);
return retval;
}
@ -1237,7 +1274,8 @@ public class FhirContext {
return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, v -> new FhirContext(v));
}
private static Collection<Class<? extends IBaseResource>> toCollection(Class<? extends IBaseResource> theResourceType) {
private static Collection<Class<? extends IBaseResource>> toCollection(
Class<? extends IBaseResource> theResourceType) {
ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<>(1);
retVal.add(theResourceType);
return retVal;
@ -1248,11 +1286,11 @@ public class FhirContext {
ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<Class<? extends IBaseResource>>(1);
for (Class<?> clazz : theResourceTypes) {
if (!IResource.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException(Msg.code(1688) + clazz.getCanonicalName() + " is not an instance of " + IResource.class.getSimpleName());
throw new IllegalArgumentException(Msg.code(1688) + clazz.getCanonicalName() + " is not an instance of "
+ IResource.class.getSimpleName());
}
retVal.add((Class<? extends IResource>) clazz);
}
return retVal;
}
}

View File

@ -57,7 +57,11 @@ public enum FhirVersionEnum {
private volatile IFhirVersion myVersionImplementation;
private String myFhirVersionString;
FhirVersionEnum(String theVersionClass, FhirVersionEnum theEquivalent, boolean theIsRi, IVersionProvider theVersionExtractor) {
FhirVersionEnum(
String theVersionClass,
FhirVersionEnum theEquivalent,
boolean theIsRi,
IVersionProvider theVersionExtractor) {
myVersionClass = theVersionClass;
myEquivalent = theEquivalent;
myFhirVersionString = theVersionExtractor.provideVersion();
@ -74,7 +78,8 @@ public enum FhirVersionEnum {
}
if (myVersionImplementation == null) {
try {
myVersionImplementation = (IFhirVersion) Class.forName(myVersionClass).newInstance();
myVersionImplementation =
(IFhirVersion) Class.forName(myVersionClass).newInstance();
} catch (Exception e) {
throw new InternalErrorException(Msg.code(1710) + "Failed to instantiate FHIR version " + name(), e);
}
@ -143,7 +148,6 @@ public enum FhirVersionEnum {
return FhirContext.forCached(this);
}
private interface IVersionProvider {
String provideVersion();
}
@ -168,7 +172,6 @@ public enum FhirVersionEnum {
default:
return determineVersionForType(theFhirType.getSuperclass());
}
}
private static class Version implements IVersionProvider {
@ -184,7 +187,6 @@ public enum FhirVersionEnum {
public String provideVersion() {
return myVersion;
}
}
/**
@ -208,7 +210,6 @@ public enum FhirVersionEnum {
public String provideVersion() {
return myVersion;
}
}
private static class R4Version implements IVersionProvider {
@ -228,7 +229,6 @@ public enum FhirVersionEnum {
public String provideVersion() {
return myVersion;
}
}
private static class R4BVersion implements IVersionProvider {
@ -248,7 +248,6 @@ public enum FhirVersionEnum {
public String provideVersion() {
return myVersion;
}
}
private static class R5Version implements IVersionProvider {
@ -268,7 +267,6 @@ public enum FhirVersionEnum {
public String provideVersion() {
return myVersion;
}
}
/**
@ -312,5 +310,4 @@ public enum FhirVersionEnum {
return null;
}
}

View File

@ -25,11 +25,10 @@ import org.hl7.fhir.instance.model.api.IBaseDatatype;
public interface IRuntimeDatatypeDefinition {
boolean isSpecialization();
public Class<? extends IBaseDatatype> getProfileOf();
boolean isProfileOf(Class<? extends IBaseDatatype> theType);
public Class<? extends IBase> getImplementingClass();
public Class<? extends IBase> getImplementingClass();
}

View File

@ -48,7 +48,6 @@ import org.hl7.fhir.instance.model.api.ICompositeType;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
@ -68,6 +67,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import javax.annotation.Nonnull;
import static org.apache.commons.lang3.StringUtils.isBlank;
@ -85,8 +85,12 @@ class ModelScanner {
private Set<Class<? extends IBase>> myVersionTypes;
ModelScanner(FhirContext theContext, FhirVersionEnum theVersion, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingDefinitions,
@Nonnull Collection<Class<? extends IBase>> theResourceTypes) throws ConfigurationException {
ModelScanner(
FhirContext theContext,
FhirVersionEnum theVersion,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingDefinitions,
@Nonnull Collection<Class<? extends IBase>> theResourceTypes)
throws ConfigurationException {
myContext = theContext;
myVersion = theVersion;
@ -118,7 +122,9 @@ class ModelScanner {
return myRuntimeChildUndeclaredExtensionDefinition;
}
private void init(Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingDefinitions, Set<Class<? extends IBase>> theTypesToScan) {
private void init(
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingDefinitions,
Set<Class<? extends IBase>> theTypesToScan) {
if (theExistingDefinitions != null) {
myClassToElementDefinitions.putAll(theExistingDefinitions);
}
@ -140,7 +146,8 @@ class ModelScanner {
myScanAlso.clear();
} while (!typesToScan.isEmpty());
for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> nextEntry : myClassToElementDefinitions.entrySet()) {
for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> nextEntry :
myClassToElementDefinitions.entrySet()) {
if (theExistingDefinitions != null && theExistingDefinitions.containsKey(nextEntry.getKey())) {
continue;
}
@ -178,7 +185,9 @@ class ModelScanner {
ResourceDef resourceDefinition = pullAnnotation(theClass, ResourceDef.class);
if (resourceDefinition != null) {
if (!IBaseResource.class.isAssignableFrom(theClass)) {
throw new ConfigurationException(Msg.code(1714) + "Resource type contains a @" + ResourceDef.class.getSimpleName() + " annotation but does not implement " + IResource.class.getCanonicalName() + ": " + theClass.getCanonicalName());
throw new ConfigurationException(Msg.code(1714) + "Resource type contains a @"
+ ResourceDef.class.getSimpleName() + " annotation but does not implement "
+ IResource.class.getCanonicalName() + ": " + theClass.getCanonicalName());
}
@SuppressWarnings("unchecked")
Class<? extends IBaseResource> resClass = (Class<? extends IBaseResource>) theClass;
@ -204,10 +213,14 @@ class ModelScanner {
Block blockDefinition = pullAnnotation(theClass, Block.class);
if (blockDefinition != null) {
if (IResourceBlock.class.isAssignableFrom(theClass) || IBaseBackboneElement.class.isAssignableFrom(theClass) || IBaseDatatypeElement.class.isAssignableFrom(theClass)) {
if (IResourceBlock.class.isAssignableFrom(theClass)
|| IBaseBackboneElement.class.isAssignableFrom(theClass)
|| IBaseDatatypeElement.class.isAssignableFrom(theClass)) {
scanBlock(theClass);
} else {
throw new ConfigurationException(Msg.code(1715) + "Type contains a @" + Block.class.getSimpleName() + " annotation but does not implement " + IResourceBlock.class.getCanonicalName() + ": " + theClass.getCanonicalName());
throw new ConfigurationException(Msg.code(1715) + "Type contains a @" + Block.class.getSimpleName()
+ " annotation but does not implement " + IResourceBlock.class.getCanonicalName() + ": "
+ theClass.getCanonicalName());
}
}
@ -216,7 +229,8 @@ class ModelScanner {
return;
}
throw new ConfigurationException(Msg.code(1716) + "Resource class[" + theClass.getName() + "] does not contain any valid HAPI-FHIR annotations");
throw new ConfigurationException(Msg.code(1716) + "Resource class[" + theClass.getName()
+ "] does not contain any valid HAPI-FHIR annotations");
}
}
@ -228,11 +242,14 @@ class ModelScanner {
// Just in case someone messes up when upgrading from DSTU2
if (myContext.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
if (BaseIdentifiableElement.class.isAssignableFrom(theClass)) {
throw new ConfigurationException(Msg.code(1717) + "@Block class for version " + myContext.getVersion().getVersion().name() + " should not extend " + BaseIdentifiableElement.class.getSimpleName() + ": " + theClass.getName());
throw new ConfigurationException(Msg.code(1717) + "@Block class for version "
+ myContext.getVersion().getVersion().name() + " should not extend "
+ BaseIdentifiableElement.class.getSimpleName() + ": " + theClass.getName());
}
}
RuntimeResourceBlockDefinition blockDef = new RuntimeResourceBlockDefinition(blockName, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions);
RuntimeResourceBlockDefinition blockDef = new RuntimeResourceBlockDefinition(
blockName, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions);
blockDef.populateScanAlso(myScanAlso);
myClassToElementDefinitions.put(theClass, blockDef);
@ -243,11 +260,13 @@ class ModelScanner {
RuntimeCompositeDatatypeDefinition elementDef;
if (theClass.equals(ExtensionDt.class)) {
elementDef = new RuntimeExtensionDtDefinition(theDatatypeDefinition, theClass, true, myContext, myClassToElementDefinitions);
elementDef = new RuntimeExtensionDtDefinition(
theDatatypeDefinition, theClass, true, myContext, myClassToElementDefinitions);
// } else if (IBaseMetaType.class.isAssignableFrom(theClass)) {
// resourceDef = new RuntimeMetaDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} else {
elementDef = new RuntimeCompositeDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions);
elementDef = new RuntimeCompositeDatatypeDefinition(
theDatatypeDefinition, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions);
}
myClassToElementDefinitions.put(theClass, elementDef);
myNameToElementDefinitions.put(elementDef.getName().toLowerCase(), elementDef);
@ -260,12 +279,14 @@ class ModelScanner {
elementDef.populateScanAlso(myScanAlso);
}
private String scanPrimitiveDatatype(Class<? extends IPrimitiveType<?>> theClass, DatatypeDef theDatatypeDefinition) {
private String scanPrimitiveDatatype(
Class<? extends IPrimitiveType<?>> theClass, DatatypeDef theDatatypeDefinition) {
ourLog.debug("Scanning resource class: {}", theClass.getName());
String resourceName = theDatatypeDefinition.name();
if (isBlank(resourceName)) {
throw new ConfigurationException(Msg.code(1718) + "Resource type @" + ResourceDef.class.getSimpleName() + " annotation contains no resource name: " + theClass.getCanonicalName());
throw new ConfigurationException(Msg.code(1718) + "Resource type @" + ResourceDef.class.getSimpleName()
+ " annotation contains no resource name: " + theClass.getCanonicalName());
}
BaseRuntimeElementDefinition<?> elementDef;
@ -280,7 +301,8 @@ class ModelScanner {
} else if (IIdType.class.isAssignableFrom(theClass)) {
elementDef = new RuntimeIdDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} else {
elementDef = new RuntimePrimitiveDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
elementDef =
new RuntimePrimitiveDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
}
myClassToElementDefinitions.put(theClass, elementDef);
if (!theDatatypeDefinition.isSpecialization()) {
@ -312,8 +334,9 @@ class ModelScanner {
parent = parent.getSuperclass();
}
if (isBlank(resourceName)) {
throw new ConfigurationException(Msg.code(1719) + "Resource type @" + ResourceDef.class.getSimpleName() + " annotation contains no resource name(): " + theClass.getCanonicalName()
+ " - This is only allowed for types that extend other resource types ");
throw new ConfigurationException(Msg.code(1719) + "Resource type @" + ResourceDef.class.getSimpleName()
+ " annotation contains no resource name(): " + theClass.getCanonicalName()
+ " - This is only allowed for types that extend other resource types ");
}
}
@ -329,12 +352,17 @@ class ModelScanner {
String resourceId = resourceDefinition.id();
if (!isBlank(resourceId)) {
if (myIdToResourceDefinition.containsKey(resourceId)) {
throw new ConfigurationException(Msg.code(1720) + "The following resource types have the same ID of '" + resourceId + "' - " + theClass.getCanonicalName() + " and "
+ myIdToResourceDefinition.get(resourceId).getImplementingClass().getCanonicalName());
throw new ConfigurationException(Msg.code(1720) + "The following resource types have the same ID of '"
+ resourceId + "' - " + theClass.getCanonicalName() + " and "
+ myIdToResourceDefinition
.get(resourceId)
.getImplementingClass()
.getCanonicalName());
}
}
RuntimeResourceDefinition resourceDef = new RuntimeResourceDefinition(myContext, resourceName, theClass, resourceDefinition, standardType, myClassToElementDefinitions);
RuntimeResourceDefinition resourceDef = new RuntimeResourceDefinition(
myContext, resourceName, theClass, resourceDefinition, standardType, myClassToElementDefinitions);
myClassToElementDefinitions.put(theClass, resourceDef);
if (primaryNameProvider) {
if (resourceDef.getStructureVersion() == myVersion) {
@ -360,7 +388,8 @@ class ModelScanner {
return resourceName;
}
private void scanResourceForSearchParams(Class<? extends IBaseResource> theClass, RuntimeResourceDefinition theResourceDef) {
private void scanResourceForSearchParams(
Class<? extends IBaseResource> theClass, RuntimeResourceDefinition theResourceDef) {
Map<String, RuntimeSearchParam> nameToParam = new HashMap<>();
Map<Field, SearchParamDefinition> compositeFields = new LinkedHashMap<>();
@ -384,9 +413,11 @@ class ModelScanner {
for (Field nextField : fields) {
SearchParamDefinition searchParam = pullAnnotation(nextField, SearchParamDefinition.class);
if (searchParam != null) {
RestSearchParameterTypeEnum paramType = RestSearchParameterTypeEnum.forCode(searchParam.type().toLowerCase());
RestSearchParameterTypeEnum paramType =
RestSearchParameterTypeEnum.forCode(searchParam.type().toLowerCase());
if (paramType == null) {
throw new ConfigurationException(Msg.code(1721) + "Search param " + searchParam.name() + " has an invalid type: " + searchParam.type());
throw new ConfigurationException(Msg.code(1721) + "Search param " + searchParam.name()
+ " has an invalid type: " + searchParam.type());
}
Set<String> providesMembershipInCompartments;
providesMembershipInCompartments = new HashSet<>();
@ -425,12 +456,23 @@ class ModelScanner {
String name = searchParam.name();
url = toCanonicalSearchParameterUri(theResourceDef, name);
}
RuntimeSearchParam param = new RuntimeSearchParam(null, url, searchParam.name(), searchParam.description(), searchParam.path(), paramType, providesMembershipInCompartments, toTargetList(searchParam.target()), RuntimeSearchParamStatusEnum.ACTIVE, null, components, base);
RuntimeSearchParam param = new RuntimeSearchParam(
null,
url,
searchParam.name(),
searchParam.description(),
searchParam.path(),
paramType,
providesMembershipInCompartments,
toTargetList(searchParam.target()),
RuntimeSearchParamStatusEnum.ACTIVE,
null,
components,
base);
theResourceDef.addSearchParam(param);
nameToParam.put(param.getName(), param);
}
}
}
private String toCanonicalSearchParameterUri(RuntimeResourceDefinition theResourceDef, String theName) {
@ -455,7 +497,9 @@ class ModelScanner {
if (List.class.equals(nextElementType)) {
nextElementType = ReflectionUtil.getGenericCollectionTypeOfField(next);
} else if (Collection.class.isAssignableFrom(nextElementType)) {
throw new ConfigurationException(Msg.code(1722) + "Field '" + next.getName() + "' in type '" + next.getClass().getCanonicalName() + "' is a Collection - Only java.util.List curently supported");
throw new ConfigurationException(Msg.code(1722) + "Field '" + next.getName() + "' in type '"
+ next.getClass().getCanonicalName()
+ "' is a Collection - Only java.util.List curently supported");
}
return nextElementType;
}
@ -464,7 +508,8 @@ class ModelScanner {
static IValueSetEnumBinder<Enum<?>> getBoundCodeBinder(Field theNext) {
Class<?> bound = getGenericCollectionTypeOfCodedField(theNext);
if (bound == null) {
throw new ConfigurationException(Msg.code(1723) + "Field '" + theNext + "' has no parameter for " + BoundCodeDt.class.getSimpleName() + " to determine enum type");
throw new ConfigurationException(Msg.code(1723) + "Field '" + theNext + "' has no parameter for "
+ BoundCodeDt.class.getSimpleName() + " to determine enum type");
}
String fieldName = "VALUESET_BINDER";
@ -472,7 +517,11 @@ class ModelScanner {
Field bindingField = bound.getField(fieldName);
return (IValueSetEnumBinder<Enum<?>>) bindingField.get(null);
} catch (Exception e) {
throw new ConfigurationException(Msg.code(1724) + "Field '" + theNext + "' has type parameter " + bound.getCanonicalName() + " but this class has no valueset binding field (must have a field called " + fieldName + ")", e);
throw new ConfigurationException(
Msg.code(1724) + "Field '" + theNext + "' has type parameter " + bound.getCanonicalName()
+ " but this class has no valueset binding field (must have a field called " + fieldName
+ ")",
e);
}
}
@ -488,7 +537,8 @@ class ModelScanner {
static Class<? extends Enum<?>> determineEnumTypeForBoundField(Field next) {
@SuppressWarnings("unchecked")
Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(next);
Class<? extends Enum<?>> enumType =
(Class<? extends Enum<?>>) ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(next);
return enumType;
}
@ -506,7 +556,11 @@ class ModelScanner {
return type;
}
static Set<Class<? extends IBase>> scanVersionPropertyFile(Set<Class<? extends IBase>> theDatatypes, Map<String, Class<? extends IBaseResource>> theResourceTypes, FhirVersionEnum theVersion, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingElementDefinitions) {
static Set<Class<? extends IBase>> scanVersionPropertyFile(
Set<Class<? extends IBase>> theDatatypes,
Map<String, Class<? extends IBaseResource>> theResourceTypes,
FhirVersionEnum theVersion,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingElementDefinitions) {
Set<Class<? extends IBase>> retVal = new HashSet<>();
try (InputStream str = theVersion.getVersionImplementation().getFhirVersionPropertiesFile()) {
@ -537,12 +591,16 @@ class ModelScanner {
Class<? extends IBaseDatatype> nextClass = (Class<? extends IBaseDatatype>) dtType;
theDatatypes.add(nextClass);
} else {
ourLog.warn("Class is not assignable from " + IElement.class.getSimpleName() + " or " + IBaseDatatype.class.getSimpleName() + ": " + nextValue);
ourLog.warn("Class is not assignable from " + IElement.class.getSimpleName() + " or "
+ IBaseDatatype.class.getSimpleName() + ": " + nextValue);
continue;
}
} catch (ClassNotFoundException e) {
throw new ConfigurationException(Msg.code(1725) + "Unknown class[" + nextValue + "] for data type definition: " + nextKey.substring("datatype.".length()), e);
throw new ConfigurationException(
Msg.code(1725) + "Unknown class[" + nextValue + "] for data type definition: "
+ nextKey.substring("datatype.".length()),
e);
}
}
} else if (nextKey.startsWith("resource.")) {
@ -550,27 +608,33 @@ class ModelScanner {
String resName = nextKey.substring("resource.".length()).toLowerCase();
try {
@SuppressWarnings("unchecked")
Class<? extends IBaseResource> nextClass = (Class<? extends IBaseResource>) Class.forName(nextValue);
Class<? extends IBaseResource> nextClass =
(Class<? extends IBaseResource>) Class.forName(nextValue);
if (theExistingElementDefinitions.containsKey(nextClass)) {
continue;
}
if (!IBaseResource.class.isAssignableFrom(nextClass)) {
throw new ConfigurationException(Msg.code(1726) + "Class is not assignable from " + IBaseResource.class.getSimpleName() + ": " + nextValue);
throw new ConfigurationException(Msg.code(1726) + "Class is not assignable from "
+ IBaseResource.class.getSimpleName() + ": " + nextValue);
}
theResourceTypes.put(resName, nextClass);
} catch (ClassNotFoundException e) {
throw new ConfigurationException(Msg.code(1727) + "Unknown class[" + nextValue + "] for resource definition: " + nextKey.substring("resource.".length()), e);
throw new ConfigurationException(
Msg.code(1727) + "Unknown class[" + nextValue + "] for resource definition: "
+ nextKey.substring("resource.".length()),
e);
}
} else {
throw new ConfigurationException(Msg.code(1728) + "Unexpected property in version property file: " + nextKey + "=" + nextValue);
throw new ConfigurationException(Msg.code(1728) + "Unexpected property in version property file: "
+ nextKey + "=" + nextValue);
}
}
} catch (IOException e) {
throw new ConfigurationException(Msg.code(1729) + "Failed to load model property file from classpath: " + "/ca/uhn/fhir/model/dstu/model.properties");
throw new ConfigurationException(Msg.code(1729) + "Failed to load model property file from classpath: "
+ "/ca/uhn/fhir/model/dstu/model.properties");
}
return retVal;
}
}

View File

@ -200,9 +200,9 @@ public class ParserOptions {
* Bundle.entry.fullUrl
* @return Returns a reference to <code>this</code> parser so that method calls can be chained together
*/
public ParserOptions setOverrideResourceIdWithBundleEntryFullUrl(boolean theOverrideResourceIdWithBundleEntryFullUrl) {
public ParserOptions setOverrideResourceIdWithBundleEntryFullUrl(
boolean theOverrideResourceIdWithBundleEntryFullUrl) {
myOverrideResourceIdWithBundleEntryFullUrl = theOverrideResourceIdWithBundleEntryFullUrl;
return this;
}
}

View File

@ -25,15 +25,14 @@ package ca.uhn.fhir.context;
public enum PerformanceOptionsEnum {
/**
* When this option is set, model classes will not be scanned for children until the
* When this option is set, model classes will not be scanned for children until the
* child list for the given type is actually accessed.
* <p>
* The effect of this option is that reflection operations to scan children will be
* deferred, and some may never happen if specific model types aren't actually used.
* This option is useful on environments where reflection is particularly slow, e.g.
* Android or low powered devices.
* </p>
* </p>
*/
DEFERRED_MODEL_SCANNING
}

View File

@ -19,6 +19,15 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.primitive.XhtmlDt;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
import org.hl7.fhir.instance.model.api.IBaseReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
@ -26,47 +35,43 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
import org.hl7.fhir.instance.model.api.IBaseReference;
import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.primitive.XhtmlDt;
public class RuntimeChildAny extends RuntimeChildChoiceDefinition {
public RuntimeChildAny(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
public RuntimeChildAny(
Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation);
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
List<Class<? extends IBase>> choiceTypes = new ArrayList<Class<? extends IBase>>();
for (Class<? extends IBase> next : theClassToElementDefinitions.keySet()) {
if (next.equals(XhtmlDt.class)) {
continue;
}
BaseRuntimeElementDefinition<?> nextDef = theClassToElementDefinitions.get(next);
if (nextDef instanceof IRuntimeDatatypeDefinition) {
if (((IRuntimeDatatypeDefinition) nextDef).isSpecialization()) {
/*
* Things like BoundCodeDt shoudn't be considered as valid options for an "any" choice, since
* we'll already have CodeDt as an option
* Things like BoundCodeDt shoudn't be considered as valid options for an "any" choice, since
* we'll already have CodeDt as an option
*/
continue;
}
}
if (IResource.class.isAssignableFrom(next) || IDatatype.class.isAssignableFrom(next) || IBaseDatatype.class.isAssignableFrom(next) || IBaseReference.class.isAssignableFrom(next)) {
if (IResource.class.isAssignableFrom(next)
|| IDatatype.class.isAssignableFrom(next)
|| IBaseDatatype.class.isAssignableFrom(next)
|| IBaseReference.class.isAssignableFrom(next)) {
choiceTypes.add(next);
}
}
Collections.sort(choiceTypes,new Comparator<Class<?>>(){
Collections.sort(choiceTypes, new Comparator<Class<?>>() {
@Override
public int compare(Class<?> theO1, Class<?> theO2) {
boolean o1res = IResource.class.isAssignableFrom(theO1);
@ -77,16 +82,14 @@ public class RuntimeChildAny extends RuntimeChildChoiceDefinition {
return -1;
} else if (o1res == false && o2res == false) {
return 0;
}else {
} else {
return 1;
}
}});
}
});
setChoiceTypes(choiceTypes);
super.sealAndInitialize(theContext, theClassToElementDefinitions);
}
}

View File

@ -49,7 +49,12 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
/**
* Constructor
*/
public RuntimeChildChoiceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List<Class<? extends IBase>> theChoiceTypes) {
public RuntimeChildChoiceDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
List<Class<? extends IBase>> theChoiceTypes) {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
myChoiceTypes = Collections.unmodifiableList(theChoiceTypes);
@ -57,10 +62,11 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
/**
* Constructor
*
*
* For extension, if myChoiceTypes will be set some other way
*/
RuntimeChildChoiceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
RuntimeChildChoiceDefinition(
Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
}
@ -79,14 +85,17 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
@Override
public BaseRuntimeElementDefinition<?> getChildByName(String theName) {
assert myNameToChildDefinition.containsKey(theName) : "Can't find child '" + theName + "' in names: " + myNameToChildDefinition.keySet();
assert myNameToChildDefinition.containsKey(theName)
: "Can't find child '" + theName + "' in names: " + myNameToChildDefinition.keySet();
return myNameToChildDefinition.get(theName);
}
@SuppressWarnings("unchecked")
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myNameToChildDefinition = new HashMap<String, BaseRuntimeElementDefinition<?>>();
myDatatypeToElementName = new HashMap<Class<? extends IBase>, String>();
myDatatypeToElementDefinition = new HashMap<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>();
@ -105,7 +114,7 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
myNameToChildDefinition.put(getElementName() + "Reference", nextDef);
myNameToChildDefinition.put(getElementName() + "Resource", nextDef);
myResourceTypes.add((Class<? extends IBaseResource>) next);
} else {
@ -118,7 +127,7 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
* unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the
* element fooString when encoded, because markdown is a profile of string. This is according to the
* FHIR spec
*
*
* Note that as of HAPI 1.4 this applies only to non-primitive datatypes after discussion
* with Grahame.
*/
@ -158,7 +167,9 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
if (myDatatypeToElementName.containsKey(next)) {
String existing = myDatatypeToElementName.get(next);
if (!existing.equals(elementName)) {
throw new ConfigurationException(Msg.code(1693) + "Already have element name " + existing + " for datatype " + next.getSimpleName() + " in " + getElementName() + ", cannot add " + elementName);
throw new ConfigurationException(
Msg.code(1693) + "Already have element name " + existing + " for datatype "
+ next.getSimpleName() + " in " + getElementName() + ", cannot add " + elementName);
}
} else {
myDatatypeToElementName.put(next, elementName);
@ -171,7 +182,6 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
myResourceTypes = Collections.unmodifiableList(myResourceTypes);
}
public List<Class<? extends IBaseResource>> getResourceTypes() {
return myResourceTypes;
}
@ -190,5 +200,4 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
public Set<Class<? extends IBase>> getValidChildTypes() {
return Collections.unmodifiableSet((myDatatypeToElementDefinition.keySet()));
}
}

View File

@ -19,25 +19,31 @@
*/
package ca.uhn.fhir.context;
import java.lang.reflect.Field;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.IValueSetEnumBinder;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
public class RuntimeChildCompositeBoundDatatypeDefinition extends RuntimeChildCompositeDatatypeDefinition {
private IValueSetEnumBinder<Enum<?>> myBinder;
private Class<? extends Enum<?>> myEnumType;
public RuntimeChildCompositeBoundDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype, IValueSetEnumBinder<Enum<?>> theBinder, Class<? extends Enum<?>> theEnumType) {
public RuntimeChildCompositeBoundDatatypeDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
Class<? extends IBase> theDatatype,
IValueSetEnumBinder<Enum<?>> theBinder,
Class<? extends Enum<?>> theEnumType) {
super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype);
Validate.notNull(theBinder, "theBinder must not be null");
Validate.notNull(theEnumType, "theEnumType must not be null");
myBinder = theBinder;
myEnumType = theEnumType;
}
@ -51,5 +57,4 @@ public class RuntimeChildCompositeBoundDatatypeDefinition extends RuntimeChildCo
public Class<? extends Enum<?>> getBoundEnumType() {
return myEnumType;
}
}

View File

@ -19,18 +19,20 @@
*/
package ca.uhn.fhir.context;
import java.lang.reflect.Field;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
public class RuntimeChildCompositeDatatypeDefinition extends BaseRuntimeChildDatatypeDefinition {
public RuntimeChildCompositeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype) {
super(theField, theElementName, theChildAnnotation,theDescriptionAnnotation, theDatatype);
public RuntimeChildCompositeDatatypeDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
Class<? extends IBase> theDatatype) {
super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype);
}
}

View File

@ -36,7 +36,9 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi
private BaseRuntimeElementDefinition<?> myElem;
RuntimeChildContainedResources(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName) throws ConfigurationException {
RuntimeChildContainedResources(
Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName)
throws ConfigurationException {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
}
@ -72,7 +74,9 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
Class<?> actualType = theContext.getVersion().getContainedType();
if (BaseContainedDt.class.isAssignableFrom(actualType)) {
@SuppressWarnings("unchecked")
@ -81,8 +85,8 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi
} else if (List.class.isAssignableFrom(actualType)) {
myElem = new RuntimeElemContainedResourceList(IBaseResource.class, false);
} else {
throw new ConfigurationException(Msg.code(1735) + "Fhir Version definition returned invalid contained type: " + actualType);
throw new ConfigurationException(
Msg.code(1735) + "Fhir Version definition returned invalid contained type: " + actualType);
}
}
}

View File

@ -19,7 +19,12 @@
*/
package ca.uhn.fhir.context;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.util.ReflectionUtil;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@ -29,13 +34,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.util.ReflectionUtil;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceDefinition {
@ -56,8 +55,15 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
* @param theDefinedLocally
* See {@link Extension#definedLocally()}
*/
RuntimeChildDeclaredExtensionDefinition(Field theField, Child theChild, Description theDescriptionAnnotation, Extension theExtension, String theElementName, String theExtensionUrl,
Class<? extends IBase> theChildType, Object theBoundTypeBinder)
RuntimeChildDeclaredExtensionDefinition(
Field theField,
Child theChild,
Description theDescriptionAnnotation,
Extension theExtension,
String theElementName,
String theExtensionUrl,
Class<? extends IBase> theChildType,
Object theBoundTypeBinder)
throws ConfigurationException {
super(theField, theElementName, theChild, theDescriptionAnnotation);
assert isNotBlank(theExtensionUrl);
@ -116,7 +122,6 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
return "modifierExtension";
}
return "extension";
}
return retVal;
}
@ -124,7 +129,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
@Override
public BaseRuntimeElementDefinition<?> getChildByName(String theName) {
String name = theName;
if ("extension".equals(name)||"modifierExtension".equals(name)) {
if ("extension".equals(name) || "modifierExtension".equals(name)) {
if (myChildResourceBlock != null) {
return myChildResourceBlock;
}
@ -136,7 +141,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
if (getValidChildNames().contains(name) == false) {
return null;
}
return super.getChildByName(name);
}
@ -169,7 +174,9 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myUrlToChildExtension = new HashMap<String, RuntimeChildDeclaredExtensionDefinition>();
BaseRuntimeElementDefinition<?> elementDef = theClassToElementDefinitions.get(myChildType);
@ -184,17 +191,19 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
}
}
if (elementDef instanceof RuntimePrimitiveDatatypeDefinition || elementDef instanceof RuntimeCompositeDatatypeDefinition) {
// myDatatypeChildName = "value" + elementDef.getName().substring(0, 1).toUpperCase() + elementDef.getName().substring(1);
// if ("valueResourceReference".equals(myDatatypeChildName)) {
// Per one of the examples here: http://hl7.org/implement/standards/fhir/extensibility.html#extension
// myDatatypeChildName = "valueResource";
// List<Class<? extends IBaseResource>> types = new ArrayList<Class<? extends IBaseResource>>();
// types.add(IBaseResource.class);
// myChildDef = findResourceReferenceDefinition(theClassToElementDefinitions);
// } else {
myChildDef = elementDef;
// }
if (elementDef instanceof RuntimePrimitiveDatatypeDefinition
|| elementDef instanceof RuntimeCompositeDatatypeDefinition) {
// myDatatypeChildName = "value" + elementDef.getName().substring(0, 1).toUpperCase() +
// elementDef.getName().substring(1);
// if ("valueResourceReference".equals(myDatatypeChildName)) {
// Per one of the examples here: http://hl7.org/implement/standards/fhir/extensibility.html#extension
// myDatatypeChildName = "valueResource";
// List<Class<? extends IBaseResource>> types = new ArrayList<Class<? extends IBaseResource>>();
// types.add(IBaseResource.class);
// myChildDef = findResourceReferenceDefinition(theClassToElementDefinitions);
// } else {
myChildDef = elementDef;
// }
} else if (elementDef instanceof RuntimeResourceBlockDefinition) {
RuntimeResourceBlockDefinition extDef = ((RuntimeResourceBlockDefinition) elementDef);
for (RuntimeChildDeclaredExtensionDefinition next : extDef.getExtensions()) {
@ -215,5 +224,4 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
public Class<? extends IBase> getChildType() {
return myChildType;
}
}

View File

@ -19,23 +19,24 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
public class RuntimeChildDirectResource extends BaseRuntimeDeclaredChildDefinition {
// private RuntimeElemContainedResources myElem;
// private RuntimeElemContainedResources myElem;
private FhirContext myContext;
RuntimeChildDirectResource(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName) throws ConfigurationException {
RuntimeChildDirectResource(
Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName)
throws ConfigurationException {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
}
@ -61,8 +62,9 @@ public class RuntimeChildDirectResource extends BaseRuntimeDeclaredChildDefiniti
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myContext = theContext;
}
}

View File

@ -112,7 +112,9 @@ public class RuntimeChildExt extends BaseRuntimeChildDefinition {
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myNameToChild = new HashMap<>();
myDatatypeToChild = new HashMap<>();
myDatatypeToChildName = new HashMap<>();

View File

@ -19,20 +19,20 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
public class RuntimeChildExtension extends RuntimeChildAny {
// private RuntimeChildUndeclaredExtensionDefinition myExtensionElement;
// private RuntimeChildUndeclaredExtensionDefinition myExtensionElement;
public RuntimeChildExtension(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
public RuntimeChildExtension(
Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation);
}
@ -53,21 +53,21 @@ public class RuntimeChildExtension extends RuntimeChildAny {
}
return super.getChildByName(theName);
}
// @Override
// public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) {
// if (IBaseExtension.class.isAssignableFrom(theDatatype)) {
// return myExtensionElement;
// }
// return super.getChildElementDefinitionByDatatype(theDatatype);
// }
//
// @Override
// void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
// super.sealAndInitialize(theContext, theClassToElementDefinitions);
//
// myExtensionElement = theContext.getRuntimeChildUndeclaredExtensionDefinition();
// }
// @Override
// public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) {
// if (IBaseExtension.class.isAssignableFrom(theDatatype)) {
// return myExtensionElement;
// }
// return super.getChildElementDefinitionByDatatype(theDatatype);
// }
//
// @Override
// void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>
// theClassToElementDefinitions) {
// super.sealAndInitialize(theContext, theClassToElementDefinitions);
//
// myExtensionElement = theContext.getRuntimeChildUndeclaredExtensionDefinition();
// }
}

View File

@ -19,18 +19,20 @@
*/
package ca.uhn.fhir.context;
import java.lang.reflect.Field;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
public class RuntimeChildNarrativeDefinition extends RuntimeChildCompositeDatatypeDefinition {
public RuntimeChildNarrativeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype) {
super(theField, theElementName, theChildAnnotation,theDescriptionAnnotation, theDatatype);
public RuntimeChildNarrativeDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
Class<? extends IBase> theDatatype) {
super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype);
}
}

View File

@ -19,19 +19,25 @@
*/
package ca.uhn.fhir.context;
import java.lang.reflect.Field;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
public class RuntimeChildPrimitiveBoundCodeDatatypeDefinition extends RuntimeChildPrimitiveDatatypeDefinition {
private Object myBinder;
private Class<? extends Enum<?>> myEnumType;
public RuntimeChildPrimitiveBoundCodeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype, Object theBinder, Class<? extends Enum<?>> theEnumType) {
public RuntimeChildPrimitiveBoundCodeDatatypeDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
Class<? extends IBase> theDatatype,
Object theBinder,
Class<? extends Enum<?>> theEnumType) {
super(theField, theElementName, theDescriptionAnnotation, theChildAnnotation, theDatatype);
myBinder = theBinder;
@ -47,5 +53,4 @@ public class RuntimeChildPrimitiveBoundCodeDatatypeDefinition extends RuntimeChi
public Object getInstanceConstructorArguments() {
return myBinder;
}
}

View File

@ -19,17 +19,20 @@
*/
package ca.uhn.fhir.context;
import java.lang.reflect.Field;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
public class RuntimeChildPrimitiveDatatypeDefinition extends BaseRuntimeChildDatatypeDefinition {
public RuntimeChildPrimitiveDatatypeDefinition(Field theField, String theElementName, Description theDescriptionAnnotation, Child theChildAnnotation, Class<? extends IBase> theDatatype) {
public RuntimeChildPrimitiveDatatypeDefinition(
Field theField,
String theElementName,
Description theDescriptionAnnotation,
Child theChildAnnotation,
Class<? extends IBase> theDatatype) {
super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype);
}
}

View File

@ -31,7 +31,13 @@ public class RuntimeChildPrimitiveEnumerationDatatypeDefinition extends RuntimeC
private Object myBinder;
private Class<? extends Enum<?>> myEnumType;
public RuntimeChildPrimitiveEnumerationDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype, Class<? extends Enum<?>> theBinderType) {
public RuntimeChildPrimitiveEnumerationDatatypeDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
Class<? extends IBase> theDatatype,
Class<? extends Enum<?>> theBinderType) {
super(theField, theElementName, theDescriptionAnnotation, theChildAnnotation, theDatatype);
myEnumType = theBinderType;
@ -64,5 +70,4 @@ public class RuntimeChildPrimitiveEnumerationDatatypeDefinition extends RuntimeC
}
return retVal;
}
}

View File

@ -19,23 +19,29 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import org.hl7.fhir.instance.model.api.IBase;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChildDefinition {
// private RuntimeResourceBlockDefinition myElementDef;
// private RuntimeResourceBlockDefinition myElementDef;
private Class<? extends IBase> myResourceBlockType;
private FhirContext myContext;
public RuntimeChildResourceBlockDefinition(FhirContext theContext, Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName, Class<? extends IBase> theResourceBlockType) throws ConfigurationException {
public RuntimeChildResourceBlockDefinition(
FhirContext theContext,
Field theField,
Child theChildAnnotation,
Description theDescriptionAnnotation,
String theElementName,
Class<? extends IBase> theResourceBlockType)
throws ConfigurationException {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
myContext = theContext;
myResourceBlockType = theResourceBlockType;
@ -75,8 +81,9 @@ public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChil
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
// myElementDef = (RuntimeResourceBlockDefinition) theClassToElementDefinitions.get(myResourceBlockType);
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
// myElementDef = (RuntimeResourceBlockDefinition) theClassToElementDefinitions.get(myResourceBlockType);
}
}

View File

@ -42,7 +42,12 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi
/**
* Constructor
*/
public RuntimeChildResourceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List<Class<? extends IBaseResource>> theResourceTypes) {
public RuntimeChildResourceDefinition(
Field theField,
String theElementName,
Child theChildAnnotation,
Description theDescriptionAnnotation,
List<Class<? extends IBaseResource>> theResourceTypes) {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
myResourceTypes = theResourceTypes;
@ -79,12 +84,14 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myRuntimeDef = findResourceReferenceDefinition(theClassToElementDefinitions);
myValidChildNames = new HashSet<String>();
myValidChildNames.add(getElementName());
/*
* [elementName]Resource is not actually valid FHIR but we've encountered it in the wild
* so we'll accept it just to be nice
@ -94,26 +101,28 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi
/*
* Below has been disabled- We used to allow field names to contain the name of the resource
* that they accepted. This wasn't valid but we accepted it just to be flexible because there
* were some bad examples containing this. This causes conflicts with actual field names in
* recent definitions though, so it has been disabled as of HAPI 0.9
* were some bad examples containing this. This causes conflicts with actual field names in
* recent definitions though, so it has been disabled as of HAPI 0.9
*/
// for (Class<? extends IBaseResource> next : myResourceTypes) {
// if (next == IResource.class) {
// for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> nextEntry : theClassToElementDefinitions.entrySet()) {
// if (IResource.class.isAssignableFrom(nextEntry.getKey())) {
// RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) nextEntry.getValue();
// myValidChildNames.add(getElementName() + nextDef.getName());
// }
// }
// }
// else {
// RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) theClassToElementDefinitions.get(next);
// if (nextDef == null) {
// throw new ConfigurationException(Msg.code(1691) + "Can't find child of type: " + next.getCanonicalName() + " in " + getField().getDeclaringClass());
// }
// myValidChildNames.add(getElementName() + nextDef.getName());
// }
// }
// for (Class<? extends IBaseResource> next : myResourceTypes) {
// if (next == IResource.class) {
// for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> nextEntry :
// theClassToElementDefinitions.entrySet()) {
// if (IResource.class.isAssignableFrom(nextEntry.getKey())) {
// RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) nextEntry.getValue();
// myValidChildNames.add(getElementName() + nextDef.getName());
// }
// }
// }
// else {
// RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) theClassToElementDefinitions.get(next);
// if (nextDef == null) {
// throw new ConfigurationException(Msg.code(1691) + "Can't find child of type: " + next.getCanonicalName()
// + " in " + getField().getDeclaringClass());
// }
// myValidChildNames.add(getElementName() + nextDef.getName());
// }
// }
myResourceTypes = Collections.unmodifiableList(myResourceTypes);
myValidChildNames = Collections.unmodifiableSet(myValidChildNames);

View File

@ -37,7 +37,8 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
private static final String VALUE_REFERENCE = "valueReference";
private static final String VALUE_RESOURCE = "valueResource";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuntimeChildUndeclaredExtensionDefinition.class);
private static final org.slf4j.Logger ourLog =
org.slf4j.LoggerFactory.getLogger(RuntimeChildUndeclaredExtensionDefinition.class);
private Map<String, BaseRuntimeElementDefinition<?>> myAttributeNameToDefinition;
private Map<Class<? extends IBase>, String> myDatatypeToAttributeName;
private Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> myDatatypeToDefinition;
@ -46,7 +47,10 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
// nothing
}
private void addReferenceBinding(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions, String value) {
private void addReferenceBinding(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions,
String value) {
BaseRuntimeElementDefinition<?> def = findResourceReferenceDefinition(theClassToElementDefinitions);
myAttributeNameToDefinition.put(value, def);
@ -58,7 +62,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def);
myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def);
}
}
@Override
@ -72,7 +75,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
}
return new ArrayList<>(target.getUndeclaredExtensions());
}
};
}
@ -134,7 +136,9 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
Map<String, BaseRuntimeElementDefinition<?>> datatypeAttributeNameToDefinition = new HashMap<>();
myDatatypeToAttributeName = new HashMap<>();
myDatatypeToDefinition = new HashMap<>();
@ -149,7 +153,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
ourLog.trace("Not adding specialization: {}", next.getImplementingClass());
}
if (!next.isStandardType()) {
continue;
}
@ -180,7 +183,10 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
// CodeType should win. If we aren't in a situation like that, there is a problem with the
// model so we should bail.
if (!existing.isStandardType()) {
throw new ConfigurationException(Msg.code(1734) + "More than one child of " + getElementName() + " matches attribute name " + attrName + ". Found [" + existing.getImplementingClass().getName() + "] and [" + next.getImplementingClass().getName() + "]");
throw new ConfigurationException(Msg.code(1734) + "More than one child of " + getElementName()
+ " matches attribute name " + attrName + ". Found ["
+ existing.getImplementingClass().getName() + "] and ["
+ next.getImplementingClass().getName() + "]");
}
}
@ -192,7 +198,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
myAttributeNameToDefinition = datatypeAttributeNameToDefinition;
/*
* Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1
*/
@ -203,5 +208,4 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
public static String createExtensionChildName(BaseRuntimeElementDefinition<?> next) {
return "value" + WordUtils.capitalize(next.getName());
}
}

View File

@ -30,32 +30,40 @@ import java.util.Map;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompositeDefinition<ICompositeType> implements IRuntimeDatatypeDefinition {
public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompositeDefinition<ICompositeType>
implements IRuntimeDatatypeDefinition {
private boolean mySpecialization;
private Class<? extends IBaseDatatype> myProfileOfType;
private BaseRuntimeElementDefinition<?> myProfileOf;
public RuntimeCompositeDatatypeDefinition(DatatypeDef theDef, Class<? extends ICompositeType> theImplementingClass, boolean theStandardType, FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public RuntimeCompositeDatatypeDefinition(
DatatypeDef theDef,
Class<? extends ICompositeType> theImplementingClass,
boolean theStandardType,
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theDef.name(), theImplementingClass, theStandardType, theContext, theClassToElementDefinitions);
String resourceName = theDef.name();
if (isBlank(resourceName)) {
throw new ConfigurationException(Msg.code(1712) + "Resource type @" + ResourceDef.class.getSimpleName() + " annotation contains no resource name: " + theImplementingClass.getCanonicalName());
throw new ConfigurationException(Msg.code(1712) + "Resource type @" + ResourceDef.class.getSimpleName()
+ " annotation contains no resource name: " + theImplementingClass.getCanonicalName());
}
mySpecialization = theDef.isSpecialization();
myProfileOfType = theDef.profileOf();
if (myProfileOfType.equals(IBaseDatatype.class)) {
myProfileOfType = null;
}
}
@Override
public void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super.sealAndInitialize(theContext, theClassToElementDefinitions);
if (myProfileOfType != null) {
myProfileOf = theClassToElementDefinitions.get(myProfileOfType);
if (myProfileOf == null) {
@ -91,6 +99,4 @@ public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompos
}
return false;
}
}

View File

@ -22,7 +22,7 @@ package ca.uhn.fhir.context;
import org.hl7.fhir.instance.model.api.IBaseResource;
/**
* HL7org structures use a List for contained instead of a distinct datatype
* HL7org structures use a List for contained instead of a distinct datatype
*/
public class RuntimeElemContainedResourceList extends BaseRuntimeElementDefinition<IBaseResource> {
@ -34,5 +34,4 @@ public class RuntimeElemContainedResourceList extends BaseRuntimeElementDefiniti
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.CONTAINED_RESOURCE_LIST;
}
}

View File

@ -32,5 +32,4 @@ public class RuntimeElemContainedResources extends BaseRuntimeElementDefinition<
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.CONTAINED_RESOURCES;
}
}

View File

@ -31,5 +31,4 @@ public class RuntimeElementDirectResource extends BaseRuntimeElementDefinition<I
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.RESOURCE;
}
}

View File

@ -19,21 +19,25 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.ICompositeType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.ICompositeType;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefinition {
private List<BaseRuntimeChildDefinition> myChildren;
public RuntimeExtensionDtDefinition(DatatypeDef theDef, Class<? extends ICompositeType> theImplementingClass, boolean theStandardType, FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public RuntimeExtensionDtDefinition(
DatatypeDef theDef,
Class<? extends ICompositeType> theImplementingClass,
boolean theStandardType,
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theDef, theImplementingClass, theStandardType, theContext, theClassToElementDefinitions);
}
@ -47,14 +51,16 @@ public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefini
}
@Override
public void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super.sealAndInitialize(theContext, theClassToElementDefinitions);
/*
* The "url" child is a weird child because it is not parsed and encoded in the normal way,
* so we exclude it here
* so we exclude it here
*/
List<BaseRuntimeChildDefinition> superChildren = super.getChildren();
ArrayList<BaseRuntimeChildDefinition> children = new ArrayList<BaseRuntimeChildDefinition>();
for (BaseRuntimeChildDefinition baseRuntimeChildDefinition : superChildren) {
@ -63,8 +69,7 @@ public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefini
}
children.add(baseRuntimeChildDefinition);
}
myChildren = Collections.unmodifiableList(children);
}
}

View File

@ -19,13 +19,14 @@
*/
package ca.uhn.fhir.context;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
public class RuntimeIdDatatypeDefinition extends RuntimePrimitiveDatatypeDefinition
implements IRuntimeDatatypeDefinition {
public class RuntimeIdDatatypeDefinition extends RuntimePrimitiveDatatypeDefinition implements IRuntimeDatatypeDefinition {
public RuntimeIdDatatypeDefinition(DatatypeDef theDef, Class<? extends IPrimitiveType<?>> theImplementingClass, boolean theStandardType) {
public RuntimeIdDatatypeDefinition(
DatatypeDef theDef, Class<? extends IPrimitiveType<?>> theImplementingClass, boolean theStandardType) {
super(theDef, theImplementingClass, theStandardType);
}
@ -33,5 +34,4 @@ public class RuntimeIdDatatypeDefinition extends RuntimePrimitiveDatatypeDefinit
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.ID_DATATYPE;
}
}

View File

@ -35,7 +35,8 @@ import java.util.Map;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefinition<IPrimitiveType<?>> implements IRuntimeDatatypeDefinition {
public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefinition<IPrimitiveType<?>>
implements IRuntimeDatatypeDefinition {
private Class<?> myNativeType;
private BaseRuntimeElementDefinition<?> myProfileOf;
@ -44,12 +45,14 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
private List<BaseRuntimeChildDefinition> myChildren;
private RuntimeChildExt myRuntimeChildExt;
public RuntimePrimitiveDatatypeDefinition(DatatypeDef theDef, Class<? extends IPrimitiveType<?>> theImplementingClass, boolean theStandardType) {
public RuntimePrimitiveDatatypeDefinition(
DatatypeDef theDef, Class<? extends IPrimitiveType<?>> theImplementingClass, boolean theStandardType) {
super(theDef.name(), theImplementingClass, theStandardType);
String resourceName = theDef.name();
if (isBlank(resourceName)) {
throw new ConfigurationException(Msg.code(1689) + "Resource type @" + ResourceDef.class.getSimpleName() + " annotation contains no resource name: " + theImplementingClass.getCanonicalName());
throw new ConfigurationException(Msg.code(1689) + "Resource type @" + ResourceDef.class.getSimpleName()
+ " annotation contains no resource name: " + theImplementingClass.getCanonicalName());
}
mySpecialization = theDef.isSpecialization();
@ -83,7 +86,8 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
Type rawType = superPt.getRawType();
if (rawType instanceof Class) {
Class<?> rawClass = (Class<?>) rawType;
if (rawClass.getName().endsWith(".BasePrimitive") || rawClass.getName().endsWith(".PrimitiveType")) {
if (rawClass.getName().endsWith(".BasePrimitive")
|| rawClass.getName().endsWith(".PrimitiveType")) {
Type typeVariable = superPt.getActualTypeArguments()[0];
if (typeVariable instanceof Class) {
myNativeType = (Class<?>) typeVariable;
@ -128,7 +132,9 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super.sealAndInitialize(theContext, theClassToElementDefinitions);
if (myProfileOfType != null) {
@ -153,5 +159,4 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
myChildren.add(myRuntimeChildExt);
myChildren = Collections.unmodifiableList(myChildren);
}
}

View File

@ -19,15 +19,15 @@
*/
package ca.uhn.fhir.context;
import java.util.Map;
import ca.uhn.fhir.model.primitive.XhtmlDt;
import org.hl7.fhir.instance.model.api.IBase;
import ca.uhn.fhir.model.primitive.XhtmlDt;
import java.util.Map;
public class RuntimePrimitiveDatatypeNarrativeDefinition extends BaseRuntimeElementDefinition<XhtmlDt> {
public class RuntimePrimitiveDatatypeNarrativeDefinition extends BaseRuntimeElementDefinition<XhtmlDt> {
public RuntimePrimitiveDatatypeNarrativeDefinition(String theName, Class<XhtmlDt> theImplementingClass, boolean theStandardType) {
public RuntimePrimitiveDatatypeNarrativeDefinition(
String theName, Class<XhtmlDt> theImplementingClass, boolean theStandardType) {
super(theName, theImplementingClass, theStandardType);
}
@ -37,8 +37,9 @@ public class RuntimePrimitiveDatatypeNarrativeDefinition extends BaseRuntimeEle
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
// nothing
}
}

View File

@ -19,14 +19,15 @@
*/
package ca.uhn.fhir.context;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseXhtml;
public class RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition extends BaseRuntimeElementDefinition<IBaseXhtml> {
import java.util.Map;
public RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition(String theName, Class<? extends IBaseXhtml> theImplementingClass, boolean theStandardType) {
public class RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition extends BaseRuntimeElementDefinition<IBaseXhtml> {
public RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition(
String theName, Class<? extends IBaseXhtml> theImplementingClass, boolean theStandardType) {
super(theName, theImplementingClass, theStandardType);
}
@ -36,8 +37,9 @@ public class RuntimePrimitiveDatatypeXhtmlHl7OrgDefinition extends BaseRuntimeE
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
// nothing
}
}

View File

@ -19,13 +19,18 @@
*/
package ca.uhn.fhir.context;
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase;
import java.util.Map;
public class RuntimeResourceBlockDefinition extends BaseRuntimeElementCompositeDefinition<IBase> {
public RuntimeResourceBlockDefinition(String theName, Class<? extends IBase> theImplementingClass, boolean theStandardType, FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public RuntimeResourceBlockDefinition(
String theName,
Class<? extends IBase> theImplementingClass,
boolean theStandardType,
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theName, theImplementingClass, theStandardType, theContext, theClassToElementDefinitions);
}
@ -33,5 +38,4 @@ public class RuntimeResourceBlockDefinition extends BaseRuntimeElementCompositeD
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.RESOURCE_BLOCK;
}
}

View File

@ -48,9 +48,13 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
private final FhirVersionEnum myStructureVersion;
private volatile RuntimeResourceDefinition myBaseDefinition;
public RuntimeResourceDefinition(FhirContext theContext, String theResourceName, Class<? extends IBaseResource> theClass, ResourceDef theResourceAnnotation, boolean theStandardType, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public RuntimeResourceDefinition(
FhirContext theContext,
String theResourceName,
Class<? extends IBaseResource> theClass,
ResourceDef theResourceAnnotation,
boolean theStandardType,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theResourceName, theClass, theStandardType, theContext, theClassToElementDefinitions);
myContext = theContext;
myResourceProfile = theResourceAnnotation.profile();
@ -60,23 +64,35 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
try {
instance = theClass.getConstructor().newInstance();
} catch (Exception e) {
throw new ConfigurationException(Msg.code(1730) + myContext.getLocalizer().getMessage(getClass(), "nonInstantiableType", theClass.getName(), e.toString()), e);
throw new ConfigurationException(
Msg.code(1730)
+ myContext
.getLocalizer()
.getMessage(getClass(), "nonInstantiableType", theClass.getName(), e.toString()),
e);
}
myStructureVersion = instance.getStructureFhirVersionEnum();
if (myStructureVersion != theContext.getVersion().getVersion()) {
if (myStructureVersion == FhirVersionEnum.R5 && theContext.getVersion().getVersion() == FhirVersionEnum.R4B) {
if (myStructureVersion == FhirVersionEnum.R5
&& theContext.getVersion().getVersion() == FhirVersionEnum.R4B) {
// TODO: remove this exception once we've bumped FHIR core to a new version
// TODO: also fix the TODO in ModelScanner
// TODO: also fix the TODO in RestfulServerUtils
// TODO: also fix the TODO in BaseParser
} else {
throw new ConfigurationException(Msg.code(1731) + myContext.getLocalizer().getMessage(getClass(), "typeWrongVersion", theContext.getVersion().getVersion(), theClass.getName(), myStructureVersion));
throw new ConfigurationException(Msg.code(1731)
+ myContext
.getLocalizer()
.getMessage(
getClass(),
"typeWrongVersion",
theContext.getVersion().getVersion(),
theClass.getName(),
myStructureVersion));
}
}
}
public void addSearchParam(RuntimeSearchParam theParam) {
myNameToSearchParam.put(theParam.getName(), theParam);
}
@ -113,7 +129,8 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
@SuppressWarnings("unchecked")
public <T> Class<T> getImplementingClass(Class<T> theClass) {
if (!theClass.isAssignableFrom(getImplementingClass())) {
throw new ConfigurationException(Msg.code(1732) + "Unable to convert " + getImplementingClass() + " to " + theClass);
throw new ConfigurationException(
Msg.code(1732) + "Unable to convert " + getImplementingClass() + " to " + theClass);
}
return (Class<T>) getImplementingClass();
}
@ -176,7 +193,9 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
@SuppressWarnings("unchecked")
@Override
public void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
public void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super.sealAndInitialize(theContext, theClassToElementDefinitions);
myNameToSearchParam = Collections.unmodifiableMap(myNameToSearchParam);
@ -202,7 +221,8 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
if (!compartmentNameToSearchParams.containsKey(nextCompartment)) {
compartmentNameToSearchParams.put(nextCompartment, new ArrayList<>());
}
List<RuntimeSearchParam> searchParamsForCompartment = compartmentNameToSearchParams.get(nextCompartment);
List<RuntimeSearchParam> searchParamsForCompartment =
compartmentNameToSearchParams.get(nextCompartment);
searchParamsForCompartment.add(next);
/*
@ -239,7 +259,7 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
myBaseType = (Class<? extends IBaseResource>) target;
}
} while (target.equals(Object.class) == false);
/*
* See #504:
* Bundle types may not have extensions
@ -247,11 +267,11 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
if (hasExtensions()) {
if (IAnyResource.class.isAssignableFrom(getImplementingClass())) {
if (!IDomainResource.class.isAssignableFrom(getImplementingClass())) {
throw new ConfigurationException(Msg.code(1733) + "Class \"" + getImplementingClass() + "\" is invalid. This resource type is not a DomainResource, it must not have extensions");
throw new ConfigurationException(Msg.code(1733) + "Class \"" + getImplementingClass()
+ "\" is invalid. This resource type is not a DomainResource, it must not have extensions");
}
}
}
}
private String massagePathForCompartmentSimilarity(String thePath) {
@ -286,5 +306,4 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
return retVal;
}
}

View File

@ -20,7 +20,6 @@
package ca.uhn.fhir.context;
import ca.uhn.fhir.context.phonetic.IPhoneticEncoder;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@ -28,10 +27,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -39,9 +35,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringTokenizer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.trim;
@ -66,22 +63,67 @@ public class RuntimeSearchParam {
/**
* Constructor
*/
public RuntimeSearchParam(IIdType theId, String theUri, String theName, String theDescription, String thePath, RestSearchParameterTypeEnum theParamType,
Set<String> theProvidesMembershipInCompartments, Set<String> theTargets, RuntimeSearchParamStatusEnum theStatus, Collection<String> theBase) {
this(theId, theUri, theName, theDescription, thePath, theParamType, theProvidesMembershipInCompartments, theTargets, theStatus, null, Collections.emptyList(), theBase);
public RuntimeSearchParam(
IIdType theId,
String theUri,
String theName,
String theDescription,
String thePath,
RestSearchParameterTypeEnum theParamType,
Set<String> theProvidesMembershipInCompartments,
Set<String> theTargets,
RuntimeSearchParamStatusEnum theStatus,
Collection<String> theBase) {
this(
theId,
theUri,
theName,
theDescription,
thePath,
theParamType,
theProvidesMembershipInCompartments,
theTargets,
theStatus,
null,
Collections.emptyList(),
theBase);
}
/**
* Copy constructor
*/
public RuntimeSearchParam(RuntimeSearchParam theSp) {
this(theSp.getId(), theSp.getUri(), theSp.getName(), theSp.getDescription(), theSp.getPath(), theSp.getParamType(), theSp.getProvidesMembershipInCompartments(), theSp.getTargets(), theSp.getStatus(), theSp.getComboSearchParamType(), theSp.getComponents(), theSp.getBase());
this(
theSp.getId(),
theSp.getUri(),
theSp.getName(),
theSp.getDescription(),
theSp.getPath(),
theSp.getParamType(),
theSp.getProvidesMembershipInCompartments(),
theSp.getTargets(),
theSp.getStatus(),
theSp.getComboSearchParamType(),
theSp.getComponents(),
theSp.getBase());
}
/**
* Constructor
*/
public RuntimeSearchParam(IIdType theId, String theUri, String theName, String theDescription, String thePath, RestSearchParameterTypeEnum theParamType, Set<String> theProvidesMembershipInCompartments, Set<String> theTargets, RuntimeSearchParamStatusEnum theStatus, ComboSearchParamType theComboSearchParamType, List<Component> theComponents, Collection<String> theBase) {
public RuntimeSearchParam(
IIdType theId,
String theUri,
String theName,
String theDescription,
String thePath,
RestSearchParameterTypeEnum theParamType,
Set<String> theProvidesMembershipInCompartments,
Set<String> theTargets,
RuntimeSearchParamStatusEnum theStatus,
ComboSearchParamType theComboSearchParamType,
List<Component> theComponents,
Collection<String> theBase) {
super();
myId = theId;
@ -160,12 +202,12 @@ public class RuntimeSearchParam {
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("base", myBase)
.append("name", myName)
.append("path", myPath)
.append("id", myId)
.append("uri", myUri)
.toString();
.append("base", myBase)
.append("name", myName)
.append("path", myPath)
.append("id", myId)
.append("uri", myUri)
.toString();
}
public IIdType getId() {
@ -185,21 +227,21 @@ public class RuntimeSearchParam {
RuntimeSearchParam that = (RuntimeSearchParam) theO;
return new EqualsBuilder()
.append(getId(), that.getId())
.append(getName(), that.getName())
.append(getPath(), that.getPath())
.append(getUri(), that.getUri())
.isEquals();
.append(getId(), that.getId())
.append(getName(), that.getName())
.append(getPath(), that.getPath())
.append(getUri(), that.getUri())
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(getId())
.append(getName())
.append(getPath())
.append(getUri())
.toHashCode();
.append(getId())
.append(getName())
.append(getPath())
.append(getUri())
.toHashCode();
}
public Set<String> getBase() {
@ -375,15 +417,14 @@ public class RuntimeSearchParam {
public Component(String theExpression, String theReference) {
myExpression = theExpression;
myReference = theReference;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("expression", myExpression)
.append("reference", myReference)
.toString();
.append("expression", myExpression)
.append("reference", myReference)
.toString();
}
public String getExpression() {
@ -394,5 +435,4 @@ public class RuntimeSearchParam {
return myReference;
}
}
}

View File

@ -23,7 +23,7 @@ import ca.uhn.fhir.context.FhirContext;
/**
* RESTful server behaviour for automatically adding profile tags when serializing resources
*
*
* @see FhirContext#setAddProfileTagWhenEncoding(AddProfileTagEnum)
*/
public enum AddProfileTagEnum {
@ -34,7 +34,7 @@ public enum AddProfileTagEnum {
/**
* Add any profile tags that returned resources appear to conform to
*
*
* @deprecated This mode causes even FHIR's default profiles to be exported in the
* resource metadata section. This is not generally expected behaviour from other
* systems and it offers no real benefit, so it will be removed at some point. This

View File

@ -19,18 +19,18 @@
*/
package ca.uhn.fhir.context.api;
import java.util.Set;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.util.ResourceReferenceInfo;
import java.util.Set;
/**
* Created by Bill de Beaubien on 3/4/2015.
*
* Controls how bundles decide whether referenced resources should be included
*/
public enum BundleInclusionRule {
/**
* Decision is based on whether the resource's Include is in the IncludeSet (e.g. DiagnosticReport.result). Note that the resource has to be populated to be included.
*
@ -38,7 +38,8 @@ public enum BundleInclusionRule {
*/
BASED_ON_INCLUDES {
@Override
public boolean shouldIncludeReferencedResource(ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) {
public boolean shouldIncludeReferencedResource(
ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) {
return theReferenceInfo.matchesIncludeSet(theIncludes);
}
},
@ -50,10 +51,12 @@ public enum BundleInclusionRule {
*/
BASED_ON_RESOURCE_PRESENCE {
@Override
public boolean shouldIncludeReferencedResource(ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) {
public boolean shouldIncludeReferencedResource(
ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) {
return true;
}
};
public abstract boolean shouldIncludeReferencedResource(ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes);
public abstract boolean shouldIncludeReferencedResource(
ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes);
}

View File

@ -46,7 +46,8 @@ public class ApacheEncoder implements IPhoneticEncoder {
@Override
public String encode(String theString) {
try {
// If the string contains a space, encode alpha parts separately so, for example, numbers are preserved in address lines.
// If the string contains a space, encode alpha parts separately so, for example, numbers are preserved in
// address lines.
if (theString.contains(" ")) {
return encodeStringWithSpaces(theString);
}

View File

@ -22,7 +22,8 @@ package ca.uhn.fhir.context.phonetic;
import com.google.common.base.CharMatcher;
// Useful for numerical identifiers like phone numbers, address parts etc.
// This should not be used where decimals are important. A new "quantity encoder" should be added to handle cases like that.
// This should not be used where decimals are important. A new "quantity encoder" should be added to handle cases like
// that.
public class NumericEncoder implements IPhoneticEncoder {
@Override
public String name() {

View File

@ -39,8 +39,8 @@ public class ConceptValidationOptions {
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("inferSystem", myInferSystem)
.toString();
.append("inferSystem", myInferSystem)
.toString();
}
public boolean isValidateDisplay() {

View File

@ -27,12 +27,12 @@ import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
/**
* This class returns the vocabulary that is shipped with the base FHIR
@ -46,13 +46,15 @@ import java.util.Optional;
*/
public class DefaultProfileValidationSupport implements IValidationSupport {
private static final Map<FhirVersionEnum, IValidationSupport> ourImplementations = Collections.synchronizedMap(new HashMap<>());
private static final Map<FhirVersionEnum, IValidationSupport> ourImplementations =
Collections.synchronizedMap(new HashMap<>());
private final FhirContext myCtx;
/**
* This module just delegates all calls to a concrete implementation which will
* be in this field. Which implementation gets used depends on the FHIR version.
*/
private final IValidationSupport myDelegate;
private final Runnable myFlush;
/**
@ -76,8 +78,12 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
* make this hard to clean up. At some point it'd be nice to figure out
* a cleaner solution though.
*/
strategy = ReflectionUtil.newInstance("org.hl7.fhir.common.hapi.validation.support.DefaultProfileValidationSupportNpmStrategy", IValidationSupport.class, new Class[]{FhirContext.class}, new Object[]{theFhirContext});
((ILockable)strategy).lock();
strategy = ReflectionUtil.newInstance(
"org.hl7.fhir.common.hapi.validation.support.DefaultProfileValidationSupportNpmStrategy",
IValidationSupport.class,
new Class[] {FhirContext.class},
new Object[] {theFhirContext});
((ILockable) strategy).lock();
} else {
strategy = new DefaultProfileValidationSupportBundleStrategy(theFhirContext);
}
@ -87,9 +93,9 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
myDelegate = strategy;
if (myDelegate instanceof DefaultProfileValidationSupportBundleStrategy) {
myFlush = ()->((DefaultProfileValidationSupportBundleStrategy) myDelegate).flush();
myFlush = () -> ((DefaultProfileValidationSupportBundleStrategy) myDelegate).flush();
} else {
myFlush = ()->{};
myFlush = () -> {};
}
}
@ -109,7 +115,6 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
return myDelegate.fetchAllNonBaseStructureDefinitions();
}
@Override
public IBaseResource fetchCodeSystem(String theSystem) {
return myDelegate.fetchCodeSystem(theSystem);
@ -134,17 +139,18 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
return myCtx;
}
@Nullable
public static String getConformanceResourceUrl(FhirContext theFhirContext, IBaseResource theResource) {
String urlValueString = null;
Optional<IBase> urlValue = theFhirContext.getResourceDefinition(theResource).getChildByName("url").getAccessor().getFirstValueOrNull(theResource);
Optional<IBase> urlValue = theFhirContext
.getResourceDefinition(theResource)
.getChildByName("url")
.getAccessor()
.getFirstValueOrNull(theResource);
if (urlValue.isPresent()) {
IPrimitiveType<?> urlValueType = (IPrimitiveType<?>) urlValue.get();
urlValueString = urlValueType.getValueAsString();
}
return urlValueString;
}
}

View File

@ -23,20 +23,16 @@ import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.parser.LenientErrorHandler;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.util.BundleUtil;
import ca.uhn.fhir.util.ClasspathUtil;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -46,8 +42,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import javax.annotation.Nullable;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ -55,7 +51,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
private static final String URL_PREFIX_STRUCTURE_DEFINITION = "http://hl7.org/fhir/StructureDefinition/";
private static final String URL_PREFIX_STRUCTURE_DEFINITION_BASE = "http://hl7.org/fhir/";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultProfileValidationSupport.class);
private static final org.slf4j.Logger ourLog =
org.slf4j.LoggerFactory.getLogger(DefaultProfileValidationSupport.class);
private final FhirContext myCtx;
private Map<String, IBaseResource> myCodeSystems;
@ -73,7 +70,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
myCtx = theFhirContext;
}
private void initializeResourceLists() {
if (myTerminologyResources != null && myStructureDefinitionResources != null) {
@ -90,7 +86,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml");
Properties profileNameProperties = new Properties();
try {
profileNameProperties.load(DefaultProfileValidationSupport.class.getResourceAsStream("/org/hl7/fhir/instance/model/profile/profiles.properties"));
profileNameProperties.load(DefaultProfileValidationSupport.class.getResourceAsStream(
"/org/hl7/fhir/instance/model/profile/profiles.properties"));
for (Object nextKey : profileNameProperties.keySet()) {
structureDefinitionResources.add("/org/hl7/fhir/instance/model/profile/" + nextKey);
}
@ -148,7 +145,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
myStructureDefinitionResources = structureDefinitionResources;
}
@Override
public List<IBaseResource> fetchAllConformanceResources() {
ArrayList<IBaseResource> retVal = new ArrayList<>();
@ -169,7 +165,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
return null;
}
@Override
public IBaseResource fetchCodeSystem(String theSystem) {
return fetchCodeSystemOrValueSet(theSystem, true);
@ -208,8 +203,12 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
candidate = valueSets.get(system);
}
if (candidate != null && isNotBlank(version) && !system.startsWith("http://hl7.org") && !system.startsWith("http://terminology.hl7.org")) {
if (!StringUtils.equals(version, myCtx.newTerser().getSinglePrimitiveValueOrNull(candidate, "version"))) {
if (candidate != null
&& isNotBlank(version)
&& !system.startsWith("http://hl7.org")
&& !system.startsWith("http://terminology.hl7.org")) {
if (!StringUtils.equals(
version, myCtx.newTerser().getSinglePrimitiveValueOrNull(candidate, "version"))) {
candidate = null;
}
}
@ -239,7 +238,9 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
* search parameters eg "value.as(String)" when it should be
* "value.as(string)". This lets us be a bit lenient about this.
*/
if (myCtx.getVersion().getVersion() == FhirVersionEnum.R4 || myCtx.getVersion().getVersion() == FhirVersionEnum.R4B || myCtx.getVersion().getVersion() == FhirVersionEnum.R5) {
if (myCtx.getVersion().getVersion() == FhirVersionEnum.R4
|| myCtx.getVersion().getVersion() == FhirVersionEnum.R4B
|| myCtx.getVersion().getVersion() == FhirVersionEnum.R5) {
String end = url.substring(URL_PREFIX_STRUCTURE_DEFINITION.length());
if (Character.isUpperCase(end.charAt(0))) {
String newEnd = Character.toLowerCase(end.charAt(0)) + end.substring(1);
@ -251,9 +252,7 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
}
}
}
}
}
return retVal;
}
@ -289,7 +288,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
return structureDefinitions;
}
private void loadCodeSystems(Map<String, IBaseResource> theCodeSystems, Map<String, IBaseResource> theValueSets, String theClasspath) {
private void loadCodeSystems(
Map<String, IBaseResource> theCodeSystems, Map<String, IBaseResource> theValueSets, String theClasspath) {
ourLog.info("Loading CodeSystem/ValueSet from classpath: {}", theClasspath);
InputStream inputStream = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath);
InputStreamReader reader = null;
@ -319,8 +319,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
switch (myCtx.getVersion().getVersion()) {
case DSTU2:
case DSTU2_HL7ORG:
IPrimitiveType<?> codeSystem = myCtx.newTerser().getSingleValueOrNull(next, "ValueSet.codeSystem.system", IPrimitiveType.class);
IPrimitiveType<?> codeSystem = myCtx.newTerser()
.getSingleValueOrNull(next, "ValueSet.codeSystem.system", IPrimitiveType.class);
if (codeSystem != null && isNotBlank(codeSystem.getValueAsString())) {
theCodeSystems.put(codeSystem.getValueAsString(), next);
}
@ -336,8 +336,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
break;
}
}
}
} finally {
try {
@ -356,15 +354,14 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
// Load built-in system
if (myCtx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
String storageCodeEnum = ClasspathUtil.loadResource("ca/uhn/fhir/context/support/HapiFhirStorageResponseCode.json");
IBaseResource storageCodeCodeSystem = myCtx.newJsonParser().setParserErrorHandler(new LenientErrorHandler()).parseResource(storageCodeEnum);
String storageCodeEnum =
ClasspathUtil.loadResource("ca/uhn/fhir/context/support/HapiFhirStorageResponseCode.json");
IBaseResource storageCodeCodeSystem = myCtx.newJsonParser()
.setParserErrorHandler(new LenientErrorHandler())
.parseResource(storageCodeEnum);
String url = myCtx.newTerser().getSinglePrimitiveValueOrNull(storageCodeCodeSystem, "url");
theCodeSystems.put(url, storageCodeCodeSystem);
}
}
private void loadStructureDefinitions(Map<String, IBaseResource> theCodeSystems, String theClasspath) {
@ -372,7 +369,12 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
String packageUserData = null;
if (myCtx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
packageUserData = "hl7.fhir." + myCtx.getVersion().getVersion().name().replace("DSTU", "R").toLowerCase(Locale.US);
packageUserData = "hl7.fhir."
+ myCtx.getVersion()
.getVersion()
.name()
.replace("DSTU", "R")
.toLowerCase(Locale.US);
}
try (InputStream valueSetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath)) {
@ -389,7 +391,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
if (isNotBlank(url)) {
theCodeSystems.put(url, next);
}
}
// This is used by the validator to determine which package a given SD came from.
@ -397,7 +398,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
if (packageUserData != null) {
next.setUserData("package", packageUserData);
}
}
}
} else {
@ -426,5 +426,4 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
ArrayList<IBaseResource> retVal = new ArrayList<>(theMap.values());
return (List<T>) Collections.unmodifiableList(retVal);
}
}

View File

@ -34,8 +34,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -43,6 +41,8 @@ import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ -80,7 +80,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
public interface IValidationSupport {
String URL_PREFIX_VALUE_SET = "http://hl7.org/fhir/ValueSet/";
/**
* Expands the given portion of a ValueSet
*
@ -91,7 +90,10 @@ public interface IValidationSupport {
* @return The expansion, or null
*/
@Nullable
default ValueSetExpansionOutcome expandValueSet(ValidationSupportContext theValidationSupportContext, @Nullable ValueSetExpansionOptions theExpansionOptions, @Nonnull IBaseResource theValueSetToExpand) {
default ValueSetExpansionOutcome expandValueSet(
ValidationSupportContext theValidationSupportContext,
@Nullable ValueSetExpansionOptions theExpansionOptions,
@Nonnull IBaseResource theValueSetToExpand) {
return null;
}
@ -107,11 +109,16 @@ public interface IValidationSupport {
* @since 6.0.0
*/
@Nullable
default ValueSetExpansionOutcome expandValueSet(ValidationSupportContext theValidationSupportContext, @Nullable ValueSetExpansionOptions theExpansionOptions, @Nonnull String theValueSetUrlToExpand) throws ResourceNotFoundException {
default ValueSetExpansionOutcome expandValueSet(
ValidationSupportContext theValidationSupportContext,
@Nullable ValueSetExpansionOptions theExpansionOptions,
@Nonnull String theValueSetUrlToExpand)
throws ResourceNotFoundException {
Validate.notBlank(theValueSetUrlToExpand, "theValueSetUrlToExpand must not be null or blank");
IBaseResource valueSet = fetchValueSet(theValueSetUrlToExpand);
if (valueSet == null) {
throw new ResourceNotFoundException(Msg.code(2024) + "Unknown ValueSet: " + UrlUtil.escapeUrlParam(theValueSetUrlToExpand));
throw new ResourceNotFoundException(
Msg.code(2024) + "Unknown ValueSet: " + UrlUtil.escapeUrlParam(theValueSetUrlToExpand));
}
return expandValueSet(theValidationSupportContext, theExpansionOptions, valueSet);
}
@ -200,17 +207,14 @@ public interface IValidationSupport {
Validate.notBlank(theUri, "theUri must not be null or blank");
if (theClass == null) {
Supplier<IBaseResource>[] sources = new Supplier[]{
() -> fetchStructureDefinition(theUri),
() -> fetchValueSet(theUri),
() -> fetchCodeSystem(theUri)
Supplier<IBaseResource>[] sources = new Supplier[] {
() -> fetchStructureDefinition(theUri), () -> fetchValueSet(theUri), () -> fetchCodeSystem(theUri)
};
return (T) Arrays
.stream(sources)
.map(t -> t.get())
.filter(t -> t != null)
.findFirst()
.orElse(null);
return (T) Arrays.stream(sources)
.map(t -> t.get())
.filter(t -> t != null)
.findFirst()
.orElse(null);
}
switch (getFhirContext().getResourceType(theClass)) {
@ -289,7 +293,13 @@ public interface IValidationSupport {
* @return Returns a validation result object
*/
@Nullable
default CodeValidationResult validateCode(@Nonnull ValidationSupportContext theValidationSupportContext, @Nonnull ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
default CodeValidationResult validateCode(
@Nonnull ValidationSupportContext theValidationSupportContext,
@Nonnull ConceptValidationOptions theOptions,
String theCodeSystem,
String theCode,
String theDisplay,
String theValueSetUrl) {
return null;
}
@ -307,7 +317,13 @@ public interface IValidationSupport {
* @return Returns a validation result object, or <code>null</code> if this validation support module can not handle this kind of request
*/
@Nullable
default CodeValidationResult validateCodeInValueSet(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) {
default CodeValidationResult validateCodeInValueSet(
ValidationSupportContext theValidationSupportContext,
ConceptValidationOptions theOptions,
String theCodeSystem,
String theCode,
String theDisplay,
@Nonnull IBaseResource theValueSet) {
return null;
}
@ -321,7 +337,11 @@ public interface IValidationSupport {
* @param theDisplayLanguage to filter out the designation by the display language. To return all designation, set this value to <code>null</code>.
*/
@Nullable
default LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode, String theDisplayLanguage) {
default LookupCodeResult lookupCode(
ValidationSupportContext theValidationSupportContext,
String theSystem,
String theCode,
String theDisplayLanguage) {
return null;
}
@ -334,7 +354,8 @@ public interface IValidationSupport {
* @param theCode The code
*/
@Nullable
default LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode) {
default LookupCodeResult lookupCode(
ValidationSupportContext theValidationSupportContext, String theSystem, String theCode) {
return lookupCode(theValidationSupportContext, theSystem, theCode, null);
}
@ -358,7 +379,12 @@ public interface IValidationSupport {
* @return Returns null if this module does not know how to handle this request
*/
@Nullable
default IBaseResource generateSnapshot(ValidationSupportContext theValidationSupportContext, IBaseResource theInput, String theUrl, String theWebUrl, String theProfileName) {
default IBaseResource generateSnapshot(
ValidationSupportContext theValidationSupportContext,
IBaseResource theInput,
String theUrl,
String theWebUrl,
String theProfileName) {
return null;
}
@ -755,11 +781,13 @@ public interface IValidationSupport {
public void throwNotFoundIfAppropriate() {
if (isFound() == false) {
throw new ResourceNotFoundException(Msg.code(1738) + "Unable to find code[" + getSearchedForCode() + "] in system[" + getSearchedForSystem() + "]");
throw new ResourceNotFoundException(Msg.code(1738) + "Unable to find code[" + getSearchedForCode()
+ "] in system[" + getSearchedForSystem() + "]");
}
}
public IBaseParameters toParameters(FhirContext theContext, List<? extends IPrimitiveType<String>> theProperties) {
public IBaseParameters toParameters(
FhirContext theContext, List<? extends IPrimitiveType<String>> theProperties) {
IBaseParameters retVal = ParametersUtil.newInstance(theContext);
if (isNotBlank(getCodeSystemDisplayName())) {
@ -775,10 +803,9 @@ public interface IValidationSupport {
Set<String> properties = Collections.emptySet();
if (theProperties != null) {
properties = theProperties
.stream()
.map(IPrimitiveType::getValueAsString)
.collect(Collectors.toSet());
properties = theProperties.stream()
.map(IPrimitiveType::getValueAsString)
.collect(Collectors.toSet());
}
for (IValidationSupport.BaseConceptProperty next : myProperties) {
@ -797,7 +824,8 @@ public interface IValidationSupport {
ParametersUtil.addPartString(theContext, property, "value", prop.getValue());
} else if (next instanceof IValidationSupport.CodingConceptProperty) {
IValidationSupport.CodingConceptProperty prop = (IValidationSupport.CodingConceptProperty) next;
ParametersUtil.addPartCoding(theContext, property, "value", prop.getCodeSystem(), prop.getCode(), prop.getDisplay());
ParametersUtil.addPartCoding(
theContext, property, "value", prop.getCodeSystem(), prop.getCode(), prop.getDisplay());
} else {
throw new IllegalStateException(Msg.code(1739) + "Don't know how to handle " + next.getClass());
}
@ -809,7 +837,8 @@ public interface IValidationSupport {
IBase property = ParametersUtil.addParameterToParameters(theContext, retVal, "designation");
ParametersUtil.addPartCode(theContext, property, "language", next.getLanguage());
ParametersUtil.addPartCoding(theContext, property, "use", next.getUseSystem(), next.getUseCode(), next.getUseDisplay());
ParametersUtil.addPartCoding(
theContext, property, "use", next.getUseSystem(), next.getUseCode(), next.getUseDisplay());
ParametersUtil.addPartString(theContext, property, "value", next.getValue());
}
}
@ -819,13 +848,12 @@ public interface IValidationSupport {
public static LookupCodeResult notFound(String theSearchedForSystem, String theSearchedForCode) {
return new LookupCodeResult()
.setFound(false)
.setSearchedForSystem(theSearchedForSystem)
.setSearchedForCode(theSearchedForCode);
.setFound(false)
.setSearchedForSystem(theSearchedForSystem)
.setSearchedForCode(theSearchedForCode);
}
}
class TranslateCodeRequest {
private final String myTargetSystemUrl;
private final String myConceptMapUrl;
@ -848,14 +876,14 @@ public interface IValidationSupport {
}
public TranslateCodeRequest(
List<IBaseCoding> theCodings,
String theTargetSystemUrl,
String theConceptMapUrl,
String theConceptMapVersion,
String theSourceValueSetUrl,
String theTargetValueSetUrl,
IIdType theResourceId,
boolean theReverse) {
List<IBaseCoding> theCodings,
String theTargetSystemUrl,
String theConceptMapUrl,
String theConceptMapVersion,
String theSourceValueSetUrl,
String theTargetValueSetUrl,
IIdType theResourceId,
boolean theReverse) {
myCodings = theCodings;
myTargetSystemUrl = theTargetSystemUrl;
myConceptMapUrl = theConceptMapUrl;
@ -879,29 +907,29 @@ public interface IValidationSupport {
TranslateCodeRequest that = (TranslateCodeRequest) theO;
return new EqualsBuilder()
.append(myCodings, that.myCodings)
.append(myTargetSystemUrl, that.myTargetSystemUrl)
.append(myConceptMapUrl, that.myConceptMapUrl)
.append(myConceptMapVersion, that.myConceptMapVersion)
.append(mySourceValueSetUrl, that.mySourceValueSetUrl)
.append(myTargetValueSetUrl, that.myTargetValueSetUrl)
.append(myResourceId, that.myResourceId)
.append(myReverse, that.myReverse)
.isEquals();
.append(myCodings, that.myCodings)
.append(myTargetSystemUrl, that.myTargetSystemUrl)
.append(myConceptMapUrl, that.myConceptMapUrl)
.append(myConceptMapVersion, that.myConceptMapVersion)
.append(mySourceValueSetUrl, that.mySourceValueSetUrl)
.append(myTargetValueSetUrl, that.myTargetValueSetUrl)
.append(myResourceId, that.myResourceId)
.append(myReverse, that.myReverse)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(myCodings)
.append(myTargetSystemUrl)
.append(myConceptMapUrl)
.append(myConceptMapVersion)
.append(mySourceValueSetUrl)
.append(myTargetValueSetUrl)
.append(myResourceId)
.append(myReverse)
.toHashCode();
.append(myCodings)
.append(myTargetSystemUrl)
.append(myConceptMapUrl)
.append(myConceptMapVersion)
.append(mySourceValueSetUrl)
.append(myTargetValueSetUrl)
.append(myResourceId)
.append(myReverse)
.toHashCode();
}
public List<IBaseCoding> getCodings() {

View File

@ -52,14 +52,14 @@ public class TranslateConceptResult {
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("system", mySystem)
.append("code", myCode)
.append("display", myDisplay)
.append("equivalence", myEquivalence)
.append("conceptMapUrl", myConceptMapUrl)
.append("valueSet", myValueSet)
.append("systemVersion", mySystemVersion)
.toString();
.append("system", mySystem)
.append("code", myCode)
.append("display", myDisplay)
.append("equivalence", myEquivalence)
.append("conceptMapUrl", myConceptMapUrl)
.append("valueSet", myValueSet)
.append("systemVersion", mySystemVersion)
.toString();
}
public String getCode() {

View File

@ -115,9 +115,7 @@ public class ValueSetExpansionOptions {
}
public static ValueSetExpansionOptions forOffsetAndCount(int theOffset, int theCount) {
return new ValueSetExpansionOptions()
.setOffset(theOffset)
.setCount(theCount);
return new ValueSetExpansionOptions().setOffset(theOffset).setCount(theCount);
}
public String getTheDisplayLanguage() {

View File

@ -36,5 +36,4 @@ public class FhirPathExecutionException extends InternalErrorException {
public FhirPathExecutionException(String theMessage) {
super(theMessage);
}
}

View File

@ -21,16 +21,16 @@ package ca.uhn.fhir.fhirpath;
import org.hl7.fhir.instance.model.api.IBase;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
public interface IFhirPath {
/**
* Apply the given FhirPath expression against the given input and return
* all results in a list
*
*
* @param theInput The input object (generally a resource or datatype)
* @param thePath The fluent path expression
* @param theReturnType The type to return (in order to avoid casting)
@ -47,13 +47,11 @@ public interface IFhirPath {
*/
<T extends IBase> Optional<T> evaluateFirst(IBase theInput, String thePath, Class<T> theReturnType);
/**
* Parses the expression and throws an exception if it can not parse correctly
*/
void parse(String theExpression) throws Exception;
/**
* This method can be used optionally to supply an evaluation context for the
* FHIRPath evaluator instance. The context can be used to supply data needed by

View File

@ -19,7 +19,4 @@
*/
package ca.uhn.fhir.i18n;
public final class HapiErrorCode {
}
public final class HapiErrorCode {}

View File

@ -39,8 +39,6 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.trim;
/**
* This feature is not yet in its final state and should be considered an internal part of HAPI for now - use with caution
*/
@ -48,6 +46,7 @@ public class HapiLocalizer {
@SuppressWarnings("WeakerAccess")
public static final String UNKNOWN_I18N_KEY_MESSAGE = "!MESSAGE!";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HapiLocalizer.class);
private static boolean ourFailOnMissingMessage;
private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<>();
@ -148,19 +147,18 @@ public class HapiLocalizer {
MessageFormat newMessageFormat(String theFormatString) {
StringBuilder pattern = new StringBuilder(theFormatString.trim());
for (int i = 0; i < (pattern.length()-1); i++) {
for (int i = 0; i < (pattern.length() - 1); i++) {
if (pattern.charAt(i) == '{') {
char nextChar = pattern.charAt(i+1);
char nextChar = pattern.charAt(i + 1);
if (nextChar >= '0' && nextChar <= '9') {
continue;
}
pattern.replace(i, i+1, "'{'");
pattern.replace(i, i + 1, "'{'");
int closeBraceIndex = pattern.indexOf("}", i);
if (closeBraceIndex > 0) {
i = closeBraceIndex;
pattern.replace(i, i+1, "'}'");
pattern.replace(i, i + 1, "'}'");
}
}
}
@ -175,11 +173,11 @@ public class HapiLocalizer {
}
}
public Locale getLocale() {
public Locale getLocale() {
return myLocale;
}
}
/**
/**
* This <b>global setting</b> causes the localizer to fail if any attempts
* are made to retrieve a key that does not exist. This method is primarily for
* unit tests.
@ -191,5 +189,4 @@ public class HapiLocalizer {
public static String toKey(Class<?> theType, String theKey) {
return theType.getName() + '.' + theKey;
}
}

View File

@ -26,7 +26,6 @@ public final class Msg {
* IMPORTANT: Please update the table in the following link after you add a new code:
* https://github.com/hapifhir/hapi-fhir/wiki/Bumping-Error-Code
*/
private Msg() {}
public static String code(int theCode) {

View File

@ -20,7 +20,6 @@
package ca.uhn.fhir.interceptor.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

View File

@ -24,12 +24,12 @@ import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import org.apache.commons.lang3.Validate;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
public class HookParams {
@ -38,8 +38,7 @@ public class HookParams {
/**
* Constructor
*/
public HookParams() {
}
public HookParams() {}
/**
* Constructor
@ -61,13 +60,13 @@ public class HookParams {
return doAdd(theType, theParam);
}
// /**
// * This is useful for providing a lazy-loaded (generally expensive to create)
// * parameters
// */
// public <T> HookParams addSupplier(Class<T> theType, Supplier<T> theParam) {
// return doAdd(theType, theParam);
// }
// /**
// * This is useful for providing a lazy-loaded (generally expensive to create)
// * parameters
// */
// public <T> HookParams addSupplier(Class<T> theType, Supplier<T> theParam) {
// return doAdd(theType, theParam);
// }
private <T> HookParams doAdd(Class<T> theType, Object theParam) {
Validate.isTrue(theType.equals(Supplier.class) == false, "Can not add parameters of type Supplier");
@ -110,9 +109,7 @@ public class HookParams {
}
public Collection<Object> values() {
return
Collections.unmodifiableCollection(myParams.values())
.stream()
return Collections.unmodifiableCollection(myParams.values()).stream()
.map(t -> unwrapValue(t))
.collect(Collectors.toList());
}
@ -137,10 +134,10 @@ public class HookParams {
StringBuilder b = new StringBuilder();
myParams.forEach((key, value) -> {
b.append(" ")
.append(key.getSimpleName())
.append(": ")
.append(value)
.append("\n");
.append(key.getSimpleName())
.append(": ")
.append(value)
.append("\n");
});
return b.toString();
}

View File

@ -31,5 +31,4 @@ import com.google.common.annotations.VisibleForTesting;
public interface IAnonymousInterceptor {
void invoke(IPointcut thePointcut, HookParams theArgs);
}

View File

@ -19,10 +19,10 @@
*/
package ca.uhn.fhir.interceptor.api;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import javax.annotation.Nullable;
public interface IBaseInterceptorService<POINTCUT extends IPointcut> extends IBaseInterceptorBroadcaster<POINTCUT> {

View File

@ -19,6 +19,4 @@
*/
package ca.uhn.fhir.interceptor.api;
public interface IInterceptorBroadcaster extends IBaseInterceptorBroadcaster<Pointcut> {
}
public interface IInterceptorBroadcaster extends IBaseInterceptorBroadcaster<Pointcut> {}

View File

@ -24,5 +24,4 @@ public interface IInterceptorService extends IBaseInterceptorService<Pointcut>,
void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor);
void registerAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor);
}

View File

@ -19,8 +19,8 @@
*/
package ca.uhn.fhir.interceptor.api;
import javax.annotation.Nonnull;
import java.util.List;
import javax.annotation.Nonnull;
public interface IPointcut {
@Nonnull

View File

@ -35,7 +35,7 @@ import java.lang.annotation.Target;
public @interface Interceptor {
/**
* @see #order()
* @see #order()
*/
int DEFAULT_ORDER = 0;

View File

@ -38,8 +38,6 @@ import org.apache.commons.lang3.reflect.MethodUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
@ -59,8 +57,11 @@ import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & IPointcut> implements IBaseInterceptorService<POINTCUT>, IBaseInterceptorBroadcaster<POINTCUT> {
public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & IPointcut>
implements IBaseInterceptorService<POINTCUT>, IBaseInterceptorBroadcaster<POINTCUT> {
private static final Logger ourLog = LoggerFactory.getLogger(BaseInterceptorService.class);
private final List<Object> myInterceptors = new ArrayList<>();
private final ListMultimap<POINTCUT, BaseInvoker> myGlobalInvokers = ArrayListMultimap.create();
@ -110,7 +111,6 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
Validate.notNull(thePointcut);
Validate.notNull(theInterceptor);
synchronized (myRegistryMutex) {
myAnonymousInvokers.put(thePointcut, theInvoker);
if (!isInterceptorAlreadyRegistered(theInterceptor)) {
myInterceptors.add(theInterceptor);
@ -168,7 +168,8 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
unregisterInterceptorsIf(theShouldUnregisterFunction, myAnonymousInvokers);
}
private void unregisterInterceptorsIf(Predicate<Object> theShouldUnregisterFunction, ListMultimap<POINTCUT, BaseInvoker> theGlobalInvokers) {
private void unregisterInterceptorsIf(
Predicate<Object> theShouldUnregisterFunction, ListMultimap<POINTCUT, BaseInvoker> theGlobalInvokers) {
synchronized (myRegistryMutex) {
for (Map.Entry<POINTCUT, BaseInvoker> nextInvoker : new ArrayList<>(theGlobalInvokers.entries())) {
if (theShouldUnregisterFunction.test(nextInvoker.getValue().getInterceptor())) {
@ -183,7 +184,6 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
@Override
public boolean registerInterceptor(Object theInterceptor) {
synchronized (myRegistryMutex) {
if (isInterceptorAlreadyRegistered(theInterceptor)) {
return false;
}
@ -191,7 +191,9 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
List<HookInvoker> addedInvokers = scanInterceptorAndAddToInvokerMultimap(theInterceptor, myGlobalInvokers);
if (addedInvokers.isEmpty()) {
if (myWarnOnInterceptorWithNoHooks) {
ourLog.warn("Interceptor registered with no valid hooks - Type was: {}", theInterceptor.getClass().getName());
ourLog.warn(
"Interceptor registered with no valid hooks - Type was: {}",
theInterceptor.getClass().getName());
}
return false;
}
@ -300,10 +302,9 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
@VisibleForTesting
List<Object> getInterceptorsWithInvokersForPointcut(POINTCUT thePointcut) {
return getInvokersForPointcut(thePointcut)
.stream()
.map(BaseInvoker::getInterceptor)
.collect(Collectors.toList());
return getInvokersForPointcut(thePointcut).stream()
.map(BaseInvoker::getInterceptor)
.collect(Collectors.toList());
}
/**
@ -361,13 +362,11 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
} else {
retVal = Arrays
.stream(theInvokersLists)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.sorted()
.collect(Collectors.toList());
retVal = Arrays.stream(theInvokersLists)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.sorted()
.collect(Collectors.toList());
}
return retVal;
@ -377,8 +376,17 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
* Only call this when assertions are enabled, it's expensive
*/
final boolean haveAppropriateParams(POINTCUT thePointcut, HookParams theParams) {
if (theParams.getParamsForType().values().size() != thePointcut.getParameterTypes().size()) {
throw new IllegalArgumentException(Msg.code(1909) + String.format("Wrong number of params for pointcut %s - Wanted %s but found %s", thePointcut.name(), toErrorString(thePointcut.getParameterTypes()), theParams.getParamsForType().values().stream().map(t -> t != null ? t.getClass().getSimpleName() : "null").sorted().collect(Collectors.toList())));
if (theParams.getParamsForType().values().size()
!= thePointcut.getParameterTypes().size()) {
throw new IllegalArgumentException(Msg.code(1909)
+ String.format(
"Wrong number of params for pointcut %s - Wanted %s but found %s",
thePointcut.name(),
toErrorString(thePointcut.getParameterTypes()),
theParams.getParamsForType().values().stream()
.map(t -> t != null ? t.getClass().getSimpleName() : "null")
.sorted()
.collect(Collectors.toList())));
}
List<String> wantedTypes = new ArrayList<>(thePointcut.getParameterTypes());
@ -387,15 +395,26 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
for (Class<?> nextTypeClass : givenTypes.keySet()) {
String nextTypeName = nextTypeClass.getName();
for (Object nextParamValue : givenTypes.get(nextTypeClass)) {
Validate.isTrue(nextParamValue == null || nextTypeClass.isAssignableFrom(nextParamValue.getClass()), "Invalid params for pointcut %s - %s is not of type %s", thePointcut.name(), nextParamValue != null ? nextParamValue.getClass() : "null", nextTypeClass);
Validate.isTrue(wantedTypes.remove(nextTypeName), "Invalid params for pointcut %s - Wanted %s but found %s", thePointcut.name(), toErrorString(thePointcut.getParameterTypes()), nextTypeName);
Validate.isTrue(
nextParamValue == null || nextTypeClass.isAssignableFrom(nextParamValue.getClass()),
"Invalid params for pointcut %s - %s is not of type %s",
thePointcut.name(),
nextParamValue != null ? nextParamValue.getClass() : "null",
nextTypeClass);
Validate.isTrue(
wantedTypes.remove(nextTypeName),
"Invalid params for pointcut %s - Wanted %s but found %s",
thePointcut.name(),
toErrorString(thePointcut.getParameterTypes()),
nextTypeName);
}
}
return true;
}
private List<HookInvoker> scanInterceptorAndAddToInvokerMultimap(Object theInterceptor, ListMultimap<POINTCUT, BaseInvoker> theInvokers) {
private List<HookInvoker> scanInterceptorAndAddToInvokerMultimap(
Object theInterceptor, ListMultimap<POINTCUT, BaseInvoker> theInvokers) {
Class<?> interceptorClass = theInterceptor.getClass();
int typeOrder = determineOrder(interceptorClass);
@ -403,8 +422,8 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
// Invoke the REGISTERED pointcut for any added hooks
addedInvokers.stream()
.filter(t -> Pointcut.INTERCEPTOR_REGISTERED.equals(t.getPointcut()))
.forEach(t -> t.invoke(new HookParams()));
.filter(t -> Pointcut.INTERCEPTOR_REGISTERED.equals(t.getPointcut()))
.forEach(t -> t.invoke(new HookParams()));
// Register the interceptor and its various hooks
for (HookInvoker nextAddedHook : addedInvokers) {
@ -458,7 +477,8 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
/**
* Constructor
*/
private HookInvoker(HookDescriptor theHook, @Nonnull Object theInterceptor, @Nonnull Method theHookMethod, int theOrder) {
private HookInvoker(
HookDescriptor theHook, @Nonnull Object theInterceptor, @Nonnull Method theHookMethod, int theOrder) {
super(theInterceptor, theOrder);
myPointcut = theHook.getPointcut();
myParameterTypes = theHookMethod.getParameterTypes();
@ -466,11 +486,18 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
Class<?> returnType = theHookMethod.getReturnType();
if (myPointcut.getReturnType().equals(boolean.class)) {
Validate.isTrue(boolean.class.equals(returnType) || void.class.equals(returnType), "Method does not return boolean or void: %s", theHookMethod);
Validate.isTrue(
boolean.class.equals(returnType) || void.class.equals(returnType),
"Method does not return boolean or void: %s",
theHookMethod);
} else if (myPointcut.getReturnType().equals(void.class)) {
Validate.isTrue(void.class.equals(returnType), "Method does not return void: %s", theHookMethod);
} else {
Validate.isTrue(myPointcut.getReturnType().isAssignableFrom(returnType) || void.class.equals(returnType), "Method does not return %s or void: %s", myPointcut.getReturnType(), theHookMethod);
Validate.isTrue(
myPointcut.getReturnType().isAssignableFrom(returnType) || void.class.equals(returnType),
"Method does not return %s or void: %s",
myPointcut.getReturnType(),
theHookMethod);
}
myParameterIndexes = new int[myParameterTypes.length];
@ -486,8 +513,8 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("method", myMethod)
.toString();
.append("method", myMethod)
.toString();
}
public POINTCUT getPointcut() {
@ -525,14 +552,14 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
if (targetException instanceof RuntimeException) {
throw ((RuntimeException) targetException);
} else {
throw new InternalErrorException(Msg.code(1910) + "Failure invoking interceptor for pointcut(s) " + getPointcut(), targetException);
throw new InternalErrorException(
Msg.code(1910) + "Failure invoking interceptor for pointcut(s) " + getPointcut(),
targetException);
}
} catch (Exception e) {
throw new InternalErrorException(Msg.code(1911) + e);
}
}
}
protected class HookDescriptor {
@ -552,7 +579,6 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
int getOrder() {
return myOrder;
}
}
protected abstract static class BaseInvoker implements Comparable<BaseInvoker> {
@ -577,7 +603,8 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
}
}
protected static <T extends Annotation> Optional<T> findAnnotation(AnnotatedElement theObject, Class<T> theHookClass) {
protected static <T extends Annotation> Optional<T> findAnnotation(
AnnotatedElement theObject, Class<T> theHookClass) {
T annotation;
if (theObject instanceof Method) {
annotation = MethodUtils.getAnnotation((Method) theObject, theHookClass, true, true);
@ -589,15 +616,11 @@ public abstract class BaseInterceptorService<POINTCUT extends Enum<POINTCUT> & I
private static int determineOrder(Class<?> theInterceptorClass) {
return findAnnotation(theInterceptorClass, Interceptor.class)
.map(Interceptor::order)
.orElse(Interceptor.DEFAULT_ORDER);
.map(Interceptor::order)
.orElse(Interceptor.DEFAULT_ORDER);
}
private static String toErrorString(List<String> theParameterTypes) {
return theParameterTypes
.stream()
.sorted()
.collect(Collectors.joining(","));
return theParameterTypes.stream().sorted().collect(Collectors.joining(","));
}
}

View File

@ -32,7 +32,8 @@ import org.apache.commons.lang3.Validate;
import java.lang.reflect.Method;
import java.util.Optional;
public class InterceptorService extends BaseInterceptorService<Pointcut> implements IInterceptorService, IInterceptorBroadcaster {
public class InterceptorService extends BaseInterceptorService<Pointcut>
implements IInterceptorService, IInterceptorBroadcaster {
/**
* Constructor which uses a default name of "default"
@ -55,7 +56,6 @@ public class InterceptorService extends BaseInterceptorService<Pointcut> impleme
return findAnnotation(nextMethod, Hook.class).map(t -> new HookDescriptor(t.value(), t.order()));
}
@Override
@VisibleForTesting
public void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor) {
@ -70,7 +70,6 @@ public class InterceptorService extends BaseInterceptorService<Pointcut> impleme
registerAnonymousInterceptor(thePointcut, theInterceptor, invoker);
}
private static class AnonymousLambdaInvoker extends BaseInvoker {
private final IAnonymousInterceptor myHook;
private final Pointcut myPointcut;
@ -87,6 +86,4 @@ public class InterceptorService extends BaseInterceptorService<Pointcut> impleme
return true;
}
}
}

View File

@ -30,8 +30,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
@ -39,6 +37,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
@ -47,20 +47,26 @@ import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
*/
public class RequestPartitionId implements IModelJson {
private static final RequestPartitionId ALL_PARTITIONS = new RequestPartitionId();
private static final ObjectMapper ourObjectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
private static final ObjectMapper ourObjectMapper =
new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
@JsonProperty("partitionDate")
private final LocalDate myPartitionDate;
@JsonProperty("allPartitions")
private final boolean myAllPartitions;
@JsonProperty("partitionIds")
private final List<Integer> myPartitionIds;
@JsonProperty("partitionNames")
private final List<String> myPartitionNames;
/**
* Constructor for a single partition
*/
private RequestPartitionId(@Nullable String thePartitionName, @Nullable Integer thePartitionId, @Nullable LocalDate thePartitionDate) {
private RequestPartitionId(
@Nullable String thePartitionName, @Nullable Integer thePartitionId, @Nullable LocalDate thePartitionDate) {
myPartitionIds = toListOrNull(thePartitionId);
myPartitionNames = toListOrNull(thePartitionName);
myPartitionDate = thePartitionDate;
@ -70,7 +76,10 @@ public class RequestPartitionId implements IModelJson {
/**
* Constructor for a multiple partition
*/
private RequestPartitionId(@Nullable List<String> thePartitionName, @Nullable List<Integer> thePartitionId, @Nullable LocalDate thePartitionDate) {
private RequestPartitionId(
@Nullable List<String> thePartitionName,
@Nullable List<Integer> thePartitionId,
@Nullable LocalDate thePartitionDate) {
myPartitionIds = toListOrNull(thePartitionId);
myPartitionNames = toListOrNull(thePartitionName);
myPartitionDate = thePartitionDate;
@ -147,11 +156,11 @@ public class RequestPartitionId implements IModelJson {
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(myPartitionDate)
.append(myAllPartitions)
.append(myPartitionIds)
.append(myPartitionNames)
.toHashCode();
.append(myPartitionDate)
.append(myAllPartitions)
.append(myPartitionIds)
.append(myPartitionNames)
.toHashCode();
}
public String toJson() {
@ -180,7 +189,9 @@ public class RequestPartitionId implements IModelJson {
if (isAllPartitions()) {
return false;
}
return hasPartitionIds() && getPartitionIds().size() == 1 && getPartitionIds().get(0) == null;
return hasPartitionIds()
&& getPartitionIds().size() == 1
&& getPartitionIds().get(0) == null;
}
public boolean hasPartitionId(Integer thePartitionId) {
@ -253,7 +264,8 @@ public class RequestPartitionId implements IModelJson {
}
@Nonnull
public static RequestPartitionId fromPartitionId(@Nullable Integer thePartitionId, @Nullable LocalDate thePartitionDate) {
public static RequestPartitionId fromPartitionId(
@Nullable Integer thePartitionId, @Nullable LocalDate thePartitionDate) {
return new RequestPartitionId(null, Collections.singletonList(thePartitionId), thePartitionDate);
}
@ -263,7 +275,8 @@ public class RequestPartitionId implements IModelJson {
}
@Nonnull
public static RequestPartitionId fromPartitionIds(@Nonnull Collection<Integer> thePartitionIds, @Nullable LocalDate thePartitionDate) {
public static RequestPartitionId fromPartitionIds(
@Nonnull Collection<Integer> thePartitionIds, @Nullable LocalDate thePartitionDate) {
return new RequestPartitionId(null, toListOrNull(thePartitionIds), thePartitionDate);
}
@ -278,7 +291,8 @@ public class RequestPartitionId implements IModelJson {
}
@Nonnull
public static RequestPartitionId fromPartitionName(@Nullable String thePartitionName, @Nullable LocalDate thePartitionDate) {
public static RequestPartitionId fromPartitionName(
@Nullable String thePartitionName, @Nullable LocalDate thePartitionDate) {
return new RequestPartitionId(thePartitionName, null, thePartitionDate);
}
@ -293,17 +307,20 @@ public class RequestPartitionId implements IModelJson {
}
@Nonnull
public static RequestPartitionId fromPartitionIdAndName(@Nullable Integer thePartitionId, @Nullable String thePartitionName) {
public static RequestPartitionId fromPartitionIdAndName(
@Nullable Integer thePartitionId, @Nullable String thePartitionName) {
return new RequestPartitionId(thePartitionName, thePartitionId, null);
}
@Nonnull
public static RequestPartitionId forPartitionIdAndName(@Nullable Integer thePartitionId, @Nullable String thePartitionName, @Nullable LocalDate thePartitionDate) {
public static RequestPartitionId forPartitionIdAndName(
@Nullable Integer thePartitionId, @Nullable String thePartitionName, @Nullable LocalDate thePartitionDate) {
return new RequestPartitionId(thePartitionName, thePartitionId, thePartitionDate);
}
@Nonnull
public static RequestPartitionId forPartitionIdsAndNames(List<String> thePartitionNames, List<Integer> thePartitionIds, LocalDate thePartitionDate) {
public static RequestPartitionId forPartitionIdsAndNames(
List<String> thePartitionNames, List<Integer> thePartitionIds, LocalDate thePartitionDate) {
return new RequestPartitionId(thePartitionNames, thePartitionIds, thePartitionDate);
}
@ -316,11 +333,9 @@ public class RequestPartitionId implements IModelJson {
String retVal = "(all)";
if (!theRequestPartitionId.isAllPartitions()) {
assert theRequestPartitionId.hasPartitionIds();
retVal = theRequestPartitionId
.getPartitionIds()
.stream()
.map(t -> defaultIfNull(t, "null").toString())
.collect(Collectors.joining(" "));
retVal = theRequestPartitionId.getPartitionIds().stream()
.map(t -> defaultIfNull(t, "null").toString())
.collect(Collectors.joining(" "));
}
return retVal;
}

View File

@ -44,5 +44,4 @@ public class TransactionWriteOperationsDetails {
public void setUpdateRequestUrls(List<String> theUpdateRequestUrls) {
myUpdateRequestUrls = theUpdateRequestUrls;
}
}

View File

@ -26,22 +26,42 @@ import org.hl7.fhir.instance.model.api.IBaseDatatype;
import java.util.*;
public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredExtensions {
public abstract class BaseElement implements /*IElement, */ ISupportsUndeclaredExtensions {
private static final long serialVersionUID = -3092659584634499332L;
private List<String> myFormatCommentsPost;
private List<String> myFormatCommentsPre;
private Map<String, Object> userData;
@Child(name = "extension", type = {ExtensionDt.class}, order = 0, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
@Description(shortDefinition = "Additional Content defined by implementations", formalDefinition = "May be used to represent additional information that is not part of the basic definition of the resource. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.")
@Child(
name = "extension",
type = {ExtensionDt.class},
order = 0,
min = 0,
max = Child.MAX_UNLIMITED,
modifier = false,
summary = false)
@Description(
shortDefinition = "Additional Content defined by implementations",
formalDefinition =
"May be used to represent additional information that is not part of the basic definition of the resource. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.")
private List<ExtensionDt> myUndeclaredExtensions;
/**
* May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.
*/
@Child(name = "modifierExtension", type = {ExtensionDt.class}, order = 1, min = 0, max = Child.MAX_UNLIMITED, modifier = true, summary = false)
@Description(shortDefinition = "Extensions that cannot be ignored", formalDefinition = "May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.")
@Child(
name = "modifierExtension",
type = {ExtensionDt.class},
order = 1,
min = 0,
max = Child.MAX_UNLIMITED,
modifier = true,
summary = false)
@Description(
shortDefinition = "Extensions that cannot be ignored",
formalDefinition =
"May be used to represent additional information that is not part of the basic definition of the resource, and that modifies the understanding of the element that contains it. Usually modifier elements provide negation or qualification. In order to make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.")
private List<ExtensionDt> myUndeclaredModifierExtensions;
@Override
@ -100,15 +120,13 @@ public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredEx
@Override
public List<String> getFormatCommentsPost() {
if (myFormatCommentsPost == null)
myFormatCommentsPost = new ArrayList<String>();
if (myFormatCommentsPost == null) myFormatCommentsPost = new ArrayList<String>();
return myFormatCommentsPost;
}
@Override
public List<String> getFormatCommentsPre() {
if (myFormatCommentsPre == null)
myFormatCommentsPre = new ArrayList<String>();
if (myFormatCommentsPre == null) myFormatCommentsPre = new ArrayList<String>();
return myFormatCommentsPre;
}
@ -142,13 +160,13 @@ public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredEx
@Override
public boolean hasFormatComment() {
return (myFormatCommentsPre != null && !myFormatCommentsPre.isEmpty()) || (myFormatCommentsPost != null && !myFormatCommentsPost.isEmpty());
return (myFormatCommentsPre != null && !myFormatCommentsPre.isEmpty())
|| (myFormatCommentsPost != null && !myFormatCommentsPost.isEmpty());
}
@Override
public Object getUserData(String name) {
if (userData == null)
return null;
if (userData == null) return null;
return userData.get(name);
}
@ -187,5 +205,4 @@ public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredEx
}
return true;
}
}

View File

@ -83,8 +83,7 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
private static class LockedId extends IdDt {
@CoverageIgnore
public LockedId() {
}
public LockedId() {}
@CoverageIgnore
public LockedId(String theElementSpecificId) {
@ -94,15 +93,15 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
@Override
@CoverageIgnore
public IdDt setValue(String theValue) throws DataFormatException {
throw new UnsupportedOperationException(Msg.code(1899) + "Use IElement#setElementSpecificId(String) to set the element ID for an element");
throw new UnsupportedOperationException(
Msg.code(1899) + "Use IElement#setElementSpecificId(String) to set the element ID for an element");
}
@Override
@CoverageIgnore
public void setValueAsString(String theValue) throws DataFormatException {
throw new UnsupportedOperationException(Msg.code(1900) + "Use IElement#setElementSpecificId(String) to set the element ID for an element");
throw new UnsupportedOperationException(
Msg.code(1900) + "Use IElement#setElementSpecificId(String) to set the element ID for an element");
}
}
}

View File

@ -19,25 +19,25 @@
*/
package ca.uhn.fhir.model.api;
import ca.uhn.fhir.parser.DataFormatException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import ca.uhn.fhir.parser.DataFormatException;
public abstract class BasePrimitive<T> extends BaseIdentifiableElement implements IPrimitiveDatatype<T>, Externalizable {
public abstract class BasePrimitive<T> extends BaseIdentifiableElement
implements IPrimitiveDatatype<T>, Externalizable {
private T myCoercedValue;
private String myStringValue;
/**
* Subclasses must override to convert a "coerced" value into an encoded one.
*
*
* @param theValue
* Will not be null
* @return May return null if the value does not correspond to anything
@ -82,7 +82,7 @@ public abstract class BasePrimitive<T> extends BaseIdentifiableElement implement
/**
* Subclasses must override to convert an encoded representation of this datatype into a "coerced" one
*
*
* @param theValue
* Will not be null
* @return May return null if the value does not correspond to anything
@ -123,7 +123,7 @@ public abstract class BasePrimitive<T> extends BaseIdentifiableElement implement
myStringValue = null;
} else {
// NB this might be null
myStringValue = encode(myCoercedValue);
myStringValue = encode(myCoercedValue);
}
}
@ -136,5 +136,4 @@ public abstract class BasePrimitive<T> extends BaseIdentifiableElement implement
public boolean hasValue() {
return !StringUtils.isBlank(getValueAsString());
}
}

View File

@ -33,20 +33,20 @@ import java.util.ArrayList;
import java.util.List;
@DatatypeDef(name = "Extension")
public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDatatype, IBaseExtension<ExtensionDt, IDatatype> {
public class ExtensionDt extends BaseIdentifiableElement
implements ICompositeDatatype, IBaseExtension<ExtensionDt, IDatatype> {
private static final long serialVersionUID = 6399491332783085935L;
private boolean myModifier;
@Child(name="url", type=StringDt.class, order=0, min=1, max=1)
@Child(name = "url", type = StringDt.class, order = 0, min = 1, max = 1)
private StringDt myUrl;
@Child(name = "value", type = IDatatype.class, order = 1, min = 0, max = 1)
private IBaseDatatype myValue;
public ExtensionDt() {
}
public ExtensionDt() {}
public ExtensionDt(boolean theIsModifier) {
myModifier = theIsModifier;
@ -65,7 +65,7 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
myModifier = theIsModifier;
myUrl = new StringDt(theUrl);
myValue=theValue;
myValue = theValue;
}
/**
@ -109,17 +109,19 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
* Note that if this extension contains extensions (instead of a datatype) then <b>this method will return null</b>. In that case, you must use {@link #getUndeclaredExtensions()} and
* {@link #getUndeclaredModifierExtensions()} to retrieve the child extensions.
* </p>
*
*
* @throws ClassCastException
* If the value of this extension is not a primitive datatype
*/
public IPrimitiveDatatype<?> getValueAsPrimitive() {
if (!(getValue() instanceof IPrimitiveDatatype)) {
throw new ClassCastException(Msg.code(1887) + "Extension with URL["+myUrl+"] can not be cast to primitive type, type is: "+ getClass().getCanonicalName());
throw new ClassCastException(
Msg.code(1887) + "Extension with URL[" + myUrl + "] can not be cast to primitive type, type is: "
+ getClass().getCanonicalName());
}
return (IPrimitiveDatatype<?>) getValue();
}
@Override
public boolean isEmpty() {
return super.isBaseEmpty() && (myValue == null || myValue.isEmpty());
@ -151,7 +153,7 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
}
@Override
@Deprecated //override deprecated method
@Deprecated // override deprecated method
public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
return new ArrayList<T>();
}
@ -168,7 +170,4 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
retVal.append("value", getValue());
return retVal.build();
}
}

View File

@ -21,6 +21,4 @@ package ca.uhn.fhir.model.api;
import java.io.Serializable;
public interface IBoundCodeableConcept extends Serializable {
}
public interface IBoundCodeableConcept extends Serializable {}

View File

@ -22,7 +22,8 @@ package ca.uhn.fhir.model.api;
public interface ICodingEnum {
String getCode();
String getSystem();
String getDisplay();
String getSystem();
String getDisplay();
}

View File

@ -21,8 +21,4 @@ package ca.uhn.fhir.model.api;
import org.hl7.fhir.instance.model.api.ICompositeType;
public interface ICompositeDatatype extends IDatatype, ICompositeElement, ICompositeType {
}
public interface ICompositeDatatype extends IDatatype, ICompositeElement, ICompositeType {}

View File

@ -25,18 +25,16 @@ public interface ICompositeElement extends IElement {
/**
* Returns a list containing all child elements matching a given type
*
*
* @param theType The type to match. If set to null, all child elements will be returned
*
*
* @deprecated This method is not used by HAPI at this point, so there isn't much
* point to keeping it around. We are not deleting it just so that we don't break
* existing implementer code, but you do not need to supply an implementation
* of this code in your own structures. Deprecated in HAPI FHIR 2.3 (Jan 2017).
* of this code in your own structures. Deprecated in HAPI FHIR 2.3 (Jan 2017).
* See See <a href="https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/hapi-fhir/AeV2hTDt--E/6EOgRA8YBwAJ"> for
* a discussion about this.
*/
@Deprecated
<T extends IElement>
List<T> getAllPopulatedChildElementsOfType(Class<T> theType);
<T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType);
}

View File

@ -21,6 +21,4 @@ package ca.uhn.fhir.model.api;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
public interface IDatatype extends IElement, IBaseDatatype {
}
public interface IDatatype extends IElement, IBaseDatatype {}

View File

@ -21,9 +21,4 @@ package ca.uhn.fhir.model.api;
import org.hl7.fhir.instance.model.api.IBase;
public interface IElement extends IBase {
}
public interface IElement extends IBase {}

View File

@ -19,20 +19,19 @@
*/
package ca.uhn.fhir.model.api;
import java.io.InputStream;
import java.util.Date;
import ca.uhn.fhir.context.*;
import ca.uhn.fhir.fhirpath.IFhirPath;
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
import org.hl7.fhir.instance.model.api.*;
import ca.uhn.fhir.context.*;
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
import java.io.InputStream;
import java.util.Date;
/**
* Each structure version JAR will have an implementation of this interface.
* This is used internally by HAPI and subject to change. Do not use this interface
* directly in user code.
*
*
* See also IFhirVersionServer for the hapi-fhir-server equivalent.
*/
public interface IFhirVersion {
@ -65,5 +64,4 @@ public interface IFhirVersion {
* JAR is on the classpath. Otherwise it will result in a {@link ClassNotFoundException}
*/
Object getServerVersion();
}

View File

@ -55,5 +55,4 @@ public interface IIdentifiableElement extends IElement {
*/
@Deprecated
void setId(String theId);
}

View File

@ -23,6 +23,10 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
public interface IModelJson {
}
@JsonAutoDetect(
creatorVisibility = JsonAutoDetect.Visibility.NONE,
fieldVisibility = JsonAutoDetect.Visibility.NONE,
getterVisibility = JsonAutoDetect.Visibility.NONE,
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.NONE)
public interface IModelJson {}

View File

@ -19,9 +19,8 @@
*/
package ca.uhn.fhir.model.api;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.parser.DataFormatException;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
public interface IPrimitiveDatatype<T> extends IDatatype, IPrimitiveType<T> {
@ -33,7 +32,7 @@ public interface IPrimitiveDatatype<T> extends IDatatype, IPrimitiveType<T> {
@Override
T getValue();
@Override
IPrimitiveType<T> setValue(T theValue) throws DataFormatException;
}

View File

@ -19,37 +19,35 @@
*/
package ca.uhn.fhir.model.api;
import java.io.Serializable;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.QualifiedParamList;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import java.io.Serializable;
import java.util.List;
public interface IQueryParameterAnd<T extends IQueryParameterOr<?>> extends Serializable {
/**
*
*
* <p>
* See FHIR specification
* See FHIR specification
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search SearchParameter Types</a>
* for information on the <b>token</b> format
* </p>
* @param theContext TODO
* @param theParamName TODO
*/
void setValuesAsQueryTokens(FhirContext theContext, String theParamName, List<QualifiedParamList> theParameters) throws InvalidRequestException;
void setValuesAsQueryTokens(FhirContext theContext, String theParamName, List<QualifiedParamList> theParameters)
throws InvalidRequestException;
/**
*
*
* <p>
* See FHIR specification
* See FHIR specification
* <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search SearchParameter Types</a>
* for information on the <b>token</b> format
* </p>
*/
List<T> getValuesAsQueryTokens();
}

View File

@ -19,17 +19,15 @@
*/
package ca.uhn.fhir.model.api;
import java.io.Serializable;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.QualifiedParamList;
import java.io.Serializable;
import java.util.List;
public interface IQueryParameterOr<T extends IQueryParameterType> extends Serializable {
void setValuesAsQueryTokens(FhirContext theContext, String theParamName, QualifiedParamList theParameters);
List<T> getValuesAsQueryTokens();
}

View File

@ -19,15 +19,15 @@
*/
package ca.uhn.fhir.model.api;
import java.io.Serializable;
import ca.uhn.fhir.context.FhirContext;
import java.io.Serializable;
public interface IQueryParameterType extends Serializable {
/**
* This method is generally only called by HAPI itself, and should not need to be called from user code.
*
* This method is generally only called by HAPI itself, and should not need to be called from user code.
*
* <p>
* See FHIR specification <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search
* SearchParameter Types</a> for information on the <b>token</b> format
@ -45,36 +45,35 @@ public interface IQueryParameterType extends Serializable {
/**
* Returns a representation of this parameter's value as it will be represented "over the wire". In other
* words, how it will be presented in a URL (although not URL escaped)
*
* words, how it will be presented in a URL (although not URL escaped)
*
* <p>
* See FHIR specification <a href="http://www.hl7.org/implement/standards/fhir/search.html#ptypes">2.2.2 Search
* SearchParameter Types</a> for information on the <b>token</b> format
* </p>
* @param theContext TODO
*
*
* @return Returns a representation of this parameter's value as it will be represented "over the wire". In other
* words, how it will be presented in a URL (although not URL escaped)
* words, how it will be presented in a URL (although not URL escaped)
*/
public String getValueAsQueryToken(FhirContext theContext);
/**
* This method will return any qualifier that should be appended to the parameter name (e.g ":exact"). Returns null if none are present.
*/
public String getQueryParameterQualifier();
/**
* If set to non-null value, indicates that this parameter has been populated with a "[name]:missing=true" or "[name]:missing=false" vale
* instead of a normal value
* If set to non-null value, indicates that this parameter has been populated with a "[name]:missing=true" or "[name]:missing=false" vale
* instead of a normal value
*/
Boolean getMissing();
/**
* If set to non-null value, indicates that this parameter has been populated with a "[name]:missing=true" or "[name]:missing=false" vale
* If set to non-null value, indicates that this parameter has been populated with a "[name]:missing=true" or "[name]:missing=false" vale
* instead of a normal value
*
*
* @return Returns a reference to <code>this</code> for easier method chaining
*/
IQueryParameterType setMissing(Boolean theMissing);
}

View File

@ -19,18 +19,17 @@
*/
package ca.uhn.fhir.model.api;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.base.composite.BaseContainedDt;
import ca.uhn.fhir.model.base.composite.BaseNarrativeDt;
import ca.uhn.fhir.model.base.resource.ResourceMetadataMap;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import org.hl7.fhir.instance.model.api.IBaseMetaType;
/**
* This interface is the parent interface for all FHIR Resource definition classes. Classes implementing this interface should be annotated with the {@link ResourceDef @ResourceDef} annotation.
*
*
* <p>
* Note that this class is a part of HAPI's model API, used to define structure classes. Users will often interact with this interface, but should not need to implement it directly.
* </p>
@ -66,8 +65,8 @@ public interface IResource extends ICompositeElement, org.hl7.fhir.instance.mode
/**
* Returns a view of the {@link #getResourceMetadata() resource metadata} map.
* Note that getters from this map return immutable objects, but the <code>addFoo()</code>
* and <code>setFoo()</code> methods may be used to modify metadata.
*
* and <code>setFoo()</code> methods may be used to modify metadata.
*
* @since 1.5
*/
@Override
@ -78,14 +77,14 @@ public interface IResource extends ICompositeElement, org.hl7.fhir.instance.mode
* <p>
* Keys in this map are enumerated in the {@link ResourceMetadataKeyEnum}, and each key has a specific value type that it must use.
* </p>
*
*
* @see ResourceMetadataKeyEnum for a list of allowable keys and the object types that values of a given key must use.
*/
ResourceMetadataMap getResourceMetadata();
/**
* Returns a String representing the name of this Resource. This return value is not used for anything by HAPI itself, but is provided as a convenience to developers using the API.
*
*
* @return the name of this resource, e.g. "Patient", or "Observation"
*/
String getResourceName();
@ -117,10 +116,9 @@ public interface IResource extends ICompositeElement, org.hl7.fhir.instance.mode
/**
* Sets the metadata map for this object. Metadata entries are used to get/set feed bundle entries, such as the resource version, or the last updated timestamp.
*
*
* @throws NullPointerException
* The map must not be null
*/
void setResourceMetadata(ResourceMetadataMap theMap);
}

View File

@ -27,5 +27,4 @@ import java.io.Writer;
public interface IStreamingDatatype<T> extends IPrimitiveType<T> {
void writeAsText(Writer theWriter) throws IOException;
}

View File

@ -24,7 +24,7 @@ import org.hl7.fhir.instance.model.api.IBaseDatatype;
import java.util.List;
public interface ISupportsUndeclaredExtensions extends IElement {
/**
* Returns a list containing all undeclared non-modifier extensions. The returned list
* is mutable, so it may be modified (e.g. to add or remove an extension).
@ -33,14 +33,14 @@ public interface ISupportsUndeclaredExtensions extends IElement {
/**
* Returns an <b>immutable</b> list containing all undeclared extensions (modifier and non-modifier) by extension URL
*
*
* @see #getUndeclaredExtensions() To return a mutable list which may be used to remove extensions
*/
List<ExtensionDt> getUndeclaredExtensionsByUrl(String theUrl);
/**
* Returns an <b>immutable</b> list containing all extensions (modifier and non-modifier).
*
*
* @see #getUndeclaredExtensions() To return a mutable list which may be used to remove undeclared non-modifier extensions
* @see #getUndeclaredModifierExtensions() To return a mutable list which may be used to remove undeclared modifier extensions
*/
@ -51,7 +51,7 @@ public interface ISupportsUndeclaredExtensions extends IElement {
* is mutable, so it may be modified (e.g. to add or remove an extension).
*/
List<ExtensionDt> getUndeclaredModifierExtensions();
/**
* Adds an extension to this object. This extension should have the
* following properties set:
@ -63,15 +63,15 @@ public interface ISupportsUndeclaredExtensions extends IElement {
* <li>{@link ExtensionDt#setValue(IBaseDatatype) A datatype value}</li>
* <li>{@link #addUndeclaredExtension(ExtensionDt) Further sub-extensions}</li>
* </ul>
* </ul>
*
* </ul>
*
* @param theExtension The extension to add. Can not be null.
*/
void addUndeclaredExtension(ExtensionDt theExtension);
/**
* Adds an extension to this object
*
*
* @see #getUndeclaredExtensions() To return a mutable list which may be used to remove extensions
*/
ExtensionDt addUndeclaredExtension(boolean theIsModifier, String theUrl, IBaseDatatype theValue);
@ -80,9 +80,8 @@ public interface ISupportsUndeclaredExtensions extends IElement {
* Adds an extension to this object. This method is intended for use when
* an extension is being added which will contain child extensions, as opposed to
* a datatype.
*
*
* @see #getUndeclaredExtensions() To return a mutable list which may be used to remove extensions
*/
ExtensionDt addUndeclaredExtension(boolean theIsModifier, String theUrl);
}

View File

@ -19,18 +19,15 @@
*/
package ca.uhn.fhir.model.api;
import java.io.Serializable;
public interface IValueSetEnumBinder<T extends Enum<?>> extends Serializable {
T fromCodeString(String theCodeString);
String toCodeString(T theEnum);
String toSystemString(T theEnum);
T fromCodeString(String theCodeString, String theSystemString);
}

View File

@ -42,7 +42,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class Include implements Serializable {
private static final long serialVersionUID = 1L;
private final boolean myImmutable;
private boolean myIterate;
private String myValue;
@ -52,7 +52,7 @@ public class Include implements Serializable {
/**
* Constructor for <b>non-recursive</b> include
*
*
* @param theValue
* The <code>_include</code> value, e.g. "Patient:name"
*/
@ -62,7 +62,7 @@ public class Include implements Serializable {
/**
* Constructor for an include
*
*
* @param theValue
* The <code>_include</code> value, e.g. "Patient:name"
* @param theIterate
@ -74,7 +74,7 @@ public class Include implements Serializable {
/**
* Constructor for an include
*
*
* @param theValue
* The <code>_include</code> value, e.g. "Patient:name"
* @param theIterate
@ -147,7 +147,6 @@ public class Include implements Serializable {
*/
public String getParamTargetType() {
return myParamTargetType;
}
public String getValue() {
@ -209,7 +208,7 @@ public class Include implements Serializable {
paramName = value.substring(firstColon + 1);
paramTargetType = null;
} else {
paramName = value.substring(firstColon + 1, secondColon);
paramName = value.substring(firstColon + 1, secondColon);
paramTargetType = value.substring(secondColon + 1);
}
}
@ -218,7 +217,6 @@ public class Include implements Serializable {
myParamName = paramName;
myParamTargetType = paramTargetType;
myValue = theValue;
}
/**
@ -262,7 +260,7 @@ public class Include implements Serializable {
* <th>{@link IllegalStateException}</th>
* </tr>
* </table>
*
*
* @param theResourceType
* The resource type (e.g. "Organization")
* @return A new copy of the include. Note that if this include is {@link #toLocked() locked}, the returned include
@ -270,16 +268,17 @@ public class Include implements Serializable {
*/
public Include withType(String theResourceType) {
StringBuilder b = new StringBuilder();
String paramType = getParamType();
String paramName = getParamName();
if (isBlank(paramType) || isBlank(paramName)) {
throw new IllegalStateException(Msg.code(1889) + "This include does not contain a value in the format [ResourceType]:[paramName]");
throw new IllegalStateException(
Msg.code(1889) + "This include does not contain a value in the format [ResourceType]:[paramName]");
}
b.append(paramType);
b.append(":");
b.append(paramName);
if (isNotBlank(theResourceType)) {
b.append(':');
b.append(theResourceType);
@ -287,5 +286,4 @@ public class Include implements Serializable {
Include retVal = new Include(b.toString(), myIterate, myImmutable);
return retVal;
}
}

View File

@ -65,8 +65,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link InstantDt}</b>
* </p>
*/
public static final ResourceMetadataKeyEnum<IPrimitiveType<Date>> DELETED_AT = new ResourceMetadataKeyEnum<>("DELETED_AT", IPrimitiveType.class) {
};
public static final ResourceMetadataKeyEnum<IPrimitiveType<Date>> DELETED_AT =
new ResourceMetadataKeyEnum<>("DELETED_AT", IPrimitiveType.class) {};
/**
* If present and populated with a {@link BundleEntrySearchModeEnum}, contains the "bundle entry search mode", which is the value of the status field in the Bundle entry containing this resource.
* The value for this key corresponds to field <code>Bundle.entry.search.mode</code>. This value can be set to provide a status value of "include" for included resources being returned by a
@ -78,8 +78,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link BundleEntrySearchModeEnum}</b>
* </p>
*/
public static final ResourceMetadataKeyEnum<BundleEntrySearchModeEnum> ENTRY_SEARCH_MODE = new ResourceMetadataKeyEnum<>("ENTRY_SEARCH_MODE", BundleEntrySearchModeEnum.class) {
};
public static final ResourceMetadataKeyEnum<BundleEntrySearchModeEnum> ENTRY_SEARCH_MODE =
new ResourceMetadataKeyEnum<>("ENTRY_SEARCH_MODE", BundleEntrySearchModeEnum.class) {};
/**
* If present and populated with a {@link BundleEntryTransactionMethodEnum}, contains the "bundle entry transaction operation", which is the value of the status field in the Bundle entry
* containing this resource. The value for this key corresponds to field <code>Bundle.entry.transaction.operation</code>. This value can be set in resources being transmitted to a server to
@ -92,8 +92,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>{@link BundleEntryTransactionMethodEnum}</b>
* </p>
*/
public static final ResourceMetadataKeyEnum<BundleEntryTransactionMethodEnum> ENTRY_TRANSACTION_METHOD = new ResourceMetadataKeyEnum<>("ENTRY_TRANSACTION_OPERATION", BundleEntryTransactionMethodEnum.class) {
};
public static final ResourceMetadataKeyEnum<BundleEntryTransactionMethodEnum> ENTRY_TRANSACTION_METHOD =
new ResourceMetadataKeyEnum<>("ENTRY_TRANSACTION_OPERATION", BundleEntryTransactionMethodEnum.class) {};
/**
* The value for this key represents a {@link List} of profile IDs that this resource claims to conform to.
* <p>
@ -101,8 +101,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* Values for this key are of type <b>List&lt;IdDt&gt;</b>. Note that the returned list is <i>unmodifiable</i>, so you need to create a new list and call <code>put</code> to change its value.
* </p>
*/
public static final ResourceMetadataKeyEnum<List<IdDt>> PROFILES = new ResourceMetadataKeyEnum<>("PROFILES", List.class) {
};
public static final ResourceMetadataKeyEnum<List<IdDt>> PROFILES =
new ResourceMetadataKeyEnum<>("PROFILES", List.class) {};
/**
* The value for this key is the bundle entry <b>Published</b> time. This is defined by FHIR as "Time resource copied into the feed", which is generally best left to the current time.
* <p>
@ -114,10 +114,11 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
*
* @see InstantDt
*/
public static final ResourceMetadataKeyEnum<InstantDt> PUBLISHED = new ResourceMetadataKeyEnum<>("PUBLISHED", InstantDt.class) {
};
public static final ResourceMetadataKeyEnum<List<BaseCodingDt>> SECURITY_LABELS = new ResourceMetadataKeyEnum<>("SECURITY_LABELS", List.class) {
};
public static final ResourceMetadataKeyEnum<InstantDt> PUBLISHED =
new ResourceMetadataKeyEnum<>("PUBLISHED", InstantDt.class) {};
public static final ResourceMetadataKeyEnum<List<BaseCodingDt>> SECURITY_LABELS =
new ResourceMetadataKeyEnum<>("SECURITY_LABELS", List.class) {};
/**
* The value for this key is the list of tags associated with this resource
* <p>
@ -126,8 +127,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
*
* @see TagList
*/
public static final ResourceMetadataKeyEnum<TagList> TAG_LIST = new ResourceMetadataKeyEnum<>("TAG_LIST", TagList.class) {
};
public static final ResourceMetadataKeyEnum<TagList> TAG_LIST =
new ResourceMetadataKeyEnum<>("TAG_LIST", TagList.class) {};
/**
* The value for this key is the bundle entry <b>Updated</b> time. This is defined by FHIR as "Last Updated for resource". This value is also used for populating the "Last-Modified" header in the
* case of methods that return a single resource (read, vread, etc.)
@ -137,8 +138,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
*
* @see InstantDt
*/
public static final ResourceMetadataKeyEnum<InstantDt> UPDATED = new ResourceMetadataKeyEnum<>("UPDATED", InstantDt.class) {
};
public static final ResourceMetadataKeyEnum<InstantDt> UPDATED =
new ResourceMetadataKeyEnum<>("UPDATED", InstantDt.class) {};
/**
* The value for this key is the version ID of the resource object.
* <p>
@ -148,8 +149,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* @deprecated The {@link IResource#getId()} resource ID will now be populated with the version ID via the {@link IdDt#getVersionIdPart()} method
*/
@Deprecated
public static final ResourceMetadataKeyEnum<String> VERSION = new ResourceMetadataKeyEnum<>("VERSION", String.class) {
};
public static final ResourceMetadataKeyEnum<String> VERSION =
new ResourceMetadataKeyEnum<>("VERSION", String.class) {};
/**
* The value for this key is the version ID of the resource object.
* <p>
@ -159,8 +160,9 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* @deprecated The {@link IResource#getId()} resource ID will now be populated with the version ID via the {@link IdDt#getVersionIdPart()} method
*/
@Deprecated
public static final ResourceMetadataKeyEnum<IdDt> VERSION_ID = new ResourceMetadataKeyEnum<>("VERSION_ID", IdDt.class) {
};
public static final ResourceMetadataKeyEnum<IdDt> VERSION_ID =
new ResourceMetadataKeyEnum<>("VERSION_ID", IdDt.class) {};
private static final long serialVersionUID = 1L;
private final String myValue;
private final Class<?> myType;
@ -180,9 +182,10 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
}
if (retVal != null && !myType.isAssignableFrom(retVal.getClass())) {
throw new InternalErrorException(Msg.code(1890) + "Found an object of type '" + retVal.getClass().getCanonicalName()
+ "' in resource metadata for key " + this.name() + " - Expected "
+ myType.getCanonicalName());
throw new InternalErrorException(Msg.code(1890) + "Found an object of type '"
+ retVal.getClass().getCanonicalName()
+ "' in resource metadata for key " + this.name() + " - Expected "
+ myType.getCanonicalName());
}
//noinspection unchecked
@ -191,9 +194,10 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IBaseResource theResource, T theValue) {
if (theValue != null && !myType.isAssignableFrom(theValue.getClass())) {
throw new InternalErrorException(Msg.code(1891) + "Can not put object of type '" + theValue.getClass().getCanonicalName()
+ "' in resource metadata for key " + this.name() + " - Expected "
+ myType.getCanonicalName());
throw new InternalErrorException(Msg.code(1891) + "Can not put object of type '"
+ theValue.getClass().getCanonicalName()
+ "' in resource metadata for key " + this.name() + " - Expected "
+ myType.getCanonicalName());
}
if (theResource instanceof IAnyResource) {
@ -205,12 +209,9 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
ResourceMetadataKeyEnum<?> other = (ResourceMetadataKeyEnum<?>) obj;
if (myValue == null) {
return other.myValue == null;

View File

@ -26,16 +26,20 @@ package ca.uhn.fhir.model.api;
* This is used in CRUD response OperationOutcome resources.
*/
public enum StorageResponseCodeEnum implements ICodingEnum {
SUCCESSFUL_CREATE("Create succeeded."),
SUCCESSFUL_CREATE_NO_CONDITIONAL_MATCH("Conditional create succeeded: no existing resource matched the conditional URL."),
SUCCESSFUL_CREATE_WITH_CONDITIONAL_MATCH("Conditional create succeeded: an existing resource matched the conditional URL so no action was taken."),
SUCCESSFUL_CREATE_NO_CONDITIONAL_MATCH(
"Conditional create succeeded: no existing resource matched the conditional URL."),
SUCCESSFUL_CREATE_WITH_CONDITIONAL_MATCH(
"Conditional create succeeded: an existing resource matched the conditional URL so no action was taken."),
SUCCESSFUL_UPDATE("Update succeeded."),
SUCCESSFUL_UPDATE_AS_CREATE("Update as create succeeded."),
SUCCESSFUL_UPDATE_NO_CHANGE("Update succeeded: No changes were detected so no action was taken."),
SUCCESSFUL_UPDATE_NO_CONDITIONAL_MATCH("Conditional update succeeded: no existing resource matched the conditional URL so a new resource was created."),
SUCCESSFUL_UPDATE_WITH_CONDITIONAL_MATCH("Conditional update succeeded: an existing resource matched the conditional URL and was updated."),
SUCCESSFUL_UPDATE_WITH_CONDITIONAL_MATCH_NO_CHANGE("Conditional update succeeded: an existing resource matched the conditional URL and was updated, but no changes were detected so no action was taken."),
SUCCESSFUL_UPDATE_NO_CONDITIONAL_MATCH(
"Conditional update succeeded: no existing resource matched the conditional URL so a new resource was created."),
SUCCESSFUL_UPDATE_WITH_CONDITIONAL_MATCH(
"Conditional update succeeded: an existing resource matched the conditional URL and was updated."),
SUCCESSFUL_UPDATE_WITH_CONDITIONAL_MATCH_NO_CHANGE(
"Conditional update succeeded: an existing resource matched the conditional URL and was updated, but no changes were detected so no action was taken."),
SUCCESSFUL_DELETE("Delete succeeded."),
SUCCESSFUL_DELETE_ALREADY_DELETED("Delete succeeded: Resource was already deleted so no action was taken."),
SUCCESSFUL_DELETE_NOT_FOUND("Delete succeeded: No existing resource was found so no action was taken."),
@ -44,7 +48,8 @@ public enum StorageResponseCodeEnum implements ICodingEnum {
SUCCESSFUL_PATCH_NO_CHANGE("Patch succeeded: No changes were detected so no action was taken."),
SUCCESSFUL_CONDITIONAL_PATCH("Conditional patch succeeded."),
SUCCESSFUL_CONDITIONAL_PATCH_NO_CHANGE("Conditional patch succeeded: No changes were detected so no action was taken.");
SUCCESSFUL_CONDITIONAL_PATCH_NO_CHANGE(
"Conditional patch succeeded: No changes were detected so no action was taken.");
public static final String SYSTEM = "https://hapifhir.io/fhir/CodeSystem/hapi-fhir-storage-response-code";

Some files were not shown because too many files have changed in this diff Show More