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. 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 * Investigate adding support for FHIR's RDF (Turtle) encoding to HAPI

View File

@ -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-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-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 [Badge-License]: https://img.shields.io/badge/license-apache%202.0-60C060.svg

View File

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

View File

@ -30,6 +30,4 @@ public class AndroidMarker {
public static void configureContext(FhirContext theContext) { public static void configureContext(FhirContext theContext) {
theContext.setRestfulClientFactory(new OkHttpRestfulClientFactory(theContext)); theContext.setRestfulClientFactory(new OkHttpRestfulClientFactory(theContext));
} }
} }

View File

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

View File

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

View File

@ -61,7 +61,9 @@ public abstract class BaseRuntimeChildDefinition {
public abstract boolean isSummary(); 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 @Override
public String toString() { public String toString() {
@ -99,8 +101,10 @@ public abstract class BaseRuntimeChildDefinition {
} }
} }
BaseRuntimeElementDefinition<?> findResourceReferenceDefinition(Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { BaseRuntimeElementDefinition<?> findResourceReferenceDefinition(
for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> next : theClassToElementDefinitions.entrySet()) { Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> next :
theClassToElementDefinitions.entrySet()) {
if (IBaseReference.class.isAssignableFrom(next.getKey())) { if (IBaseReference.class.isAssignableFrom(next.getKey())) {
return next.getValue(); return next.getValue();
} }

View File

@ -46,11 +46,15 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
private boolean myModifier; private boolean myModifier;
private boolean mySummary; 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(); super();
Validate.notNull(theField, "No field specified"); Validate.notNull(theField, "No field specified");
ValidateUtil.isGreaterThanOrEqualTo(theChildAnnotation.min(), 0, "Min must be >= 0"); 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"); Validate.notBlank(theElementName, "Element name must not be blank");
myField = theField; myField = theField;
@ -76,7 +80,6 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
myAccessor = new FieldPlainAccessor(); myAccessor = new FieldPlainAccessor();
myMutator = new FieldPlainMutator(); myMutator = new FieldPlainMutator();
} }
} }
@Override @Override
@ -147,7 +150,6 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
} }
return retVal; return retVal;
} }
} }
protected final class FieldListMutator implements IMutator { protected final class FieldListMutator implements IMutator {
@ -181,10 +183,12 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
public void remove(IBase theTarget, int theIndex) { public void remove(IBase theTarget, int theIndex) {
List<IBase> existingList = (List<IBase>) getFieldValue(theTarget, myField); List<IBase> existingList = (List<IBase>) getFieldValue(theTarget, myField);
if (existingList == null) { 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()) { 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); existingList.remove(theIndex);
} }
@ -202,7 +206,7 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
@Override @Override
public <T extends IBase> Optional<T> getFirstValueOrNull(IBase theTarget) { 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 @Override
public void remove(IBase theTarget, int theIndex) { 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); 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> { 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 final FhirContext myContext;
private Map<String, Integer> forcedOrder = null; private Map<String, Integer> forcedOrder = null;
private List<BaseRuntimeChildDefinition> myChildren = new ArrayList<>(); 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; private volatile SealingStateEnum mySealed = SealingStateEnum.NOT_SEALED;
@SuppressWarnings("unchecked") @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); super(theName, theImplementingClass, theStandardType);
myContext = theContext; myContext = theContext;
@ -126,7 +132,6 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
} }
} }
} }
void addChild(BaseRuntimeChildDefinition theNext) { void addChild(BaseRuntimeChildDefinition theNext) {
@ -134,7 +139,8 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
throw new NullPointerException(Msg.code(1698)); throw new NullPointerException(Msg.code(1698));
} }
if (theNext.getExtensionUrl() != null) { 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); myChildren.add(theNext);
} }
@ -145,11 +151,13 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
return myNameToChild.get(theName); return myNameToChild.get(theName);
} }
public BaseRuntimeChildDefinition getChildByNameOrThrowDataFormatException(String theName) throws DataFormatException { public BaseRuntimeChildDefinition getChildByNameOrThrowDataFormatException(String theName)
throws DataFormatException {
validateSealed(); validateSealed();
BaseRuntimeChildDefinition retVal = myNameToChild.get(theName); BaseRuntimeChildDefinition retVal = myNameToChild.get(theName);
if (retVal == null) { 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; return retVal;
} }
@ -160,13 +168,11 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
return myChildren; return myChildren;
} }
public List<BaseRuntimeChildDefinition> getChildrenAndExtension() { public List<BaseRuntimeChildDefinition> getChildrenAndExtension() {
validateSealed(); validateSealed();
return myChildrenAndExtensions; return myChildrenAndExtensions;
} }
/** /**
* Has this class been sealed * Has this class been sealed
*/ */
@ -178,12 +184,14 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
void populateScanAlso(Set<Class<? extends IBase>> theScanAlso) { void populateScanAlso(Set<Class<? extends IBase>> theScanAlso) {
for (ScannedField next : myScannedFields) { for (ScannedField next : myScannedFields) {
if (IBase.class.isAssignableFrom(next.getElementType())) { 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()); theScanAlso.add((Class<? extends IBase>) next.getElementType());
} }
} }
for (Class<? extends IBase> nextChildType : next.getChoiceTypes()) { 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); theScanAlso.add(nextChildType);
} }
} }
@ -233,17 +241,20 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
this.addExtension((RuntimeChildDeclaredExtensionDefinition) nextExt); this.addExtension((RuntimeChildDeclaredExtensionDefinition) nextExt);
} }
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void scanCompositeElementForChildren(Set<String> elementNames, TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToElementDef, private void scanCompositeElementForChildren(
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToExtensionDef) { Set<String> elementNames,
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToElementDef,
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToExtensionDef) {
int baseElementOrder = 0; int baseElementOrder = 0;
for (ScannedField next : myScannedFields) { for (ScannedField next : myScannedFields) {
if (next.isFirstFieldInNewClass()) { if (next.isFirstFieldInNewClass()) {
baseElementOrder = theOrderToElementDef.isEmpty() ? 0 : theOrderToElementDef.lastEntry().getKey() + 1; baseElementOrder = theOrderToElementDef.isEmpty()
? 0
: theOrderToElementDef.lastEntry().getKey() + 1;
} }
Class<?> declaringClass = next.getField().getDeclaringClass(); Class<?> declaringClass = next.getField().getDeclaringClass();
@ -281,8 +292,12 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
} }
if (order == Child.REPLACE_PARENT) { 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 throw new ConfigurationException(
+ ") but no parent element with extension URL " + extensionAttr.url() + " could be found on type " + nextField.getDeclaringClass().getSimpleName()); 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 { } else {
@ -308,16 +323,18 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
} }
if (order == Child.REPLACE_PARENT) { 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 throw new ConfigurationException(Msg.code(1702) + "Field " + nextField.getName()
+ ") but no parent element with name " + elementName + " could be found on type " + nextField.getDeclaringClass().getSimpleName()); + "' 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) { 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) { 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(); List<Class<? extends IBase>> choiceTypes = next.getChoiceTypes();
if (orderMap.containsKey(order)) { 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)) { 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(); Class<?> nextElementType = next.getElementType();
BaseRuntimeDeclaredChildDefinition def; BaseRuntimeDeclaredChildDefinition def;
if (childAnnotation.name().equals("extension") && IBaseExtension.class.isAssignableFrom(nextElementType)) { if (childAnnotation.name().equals("extension") && IBaseExtension.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildExtension(nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation); def = new RuntimeChildExtension(
} else if (childAnnotation.name().equals("modifierExtension") && IBaseExtension.class.isAssignableFrom(nextElementType)) { nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation);
def = new RuntimeChildExtension(nextField, childAnnotation.name(), childAnnotation, descriptionAnnotation); } else if (childAnnotation.name().equals("modifierExtension")
} else if (BaseContainedDt.class.isAssignableFrom(nextElementType) || (childAnnotation.name().equals("contained") && IBaseResource.class.isAssignableFrom(nextElementType))) { && 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 * Child is contained resources
*/ */
def = new RuntimeChildContainedResources(nextField, childAnnotation, descriptionAnnotation, elementName); def = new RuntimeChildContainedResources(
} else if (IAnyResource.class.isAssignableFrom(nextElementType) || IResource.class.equals(nextElementType)) { 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 * Child is a resource as a direct child, as in Bundle.entry.resource
*/ */
def = new RuntimeChildDirectResource(nextField, childAnnotation, descriptionAnnotation, elementName); def = new RuntimeChildDirectResource(nextField, childAnnotation, descriptionAnnotation, elementName);
} else { } else {
childIsChoiceType |= choiceTypes.size() > 1; childIsChoiceType |= choiceTypes.size() > 1;
if (extensionAttr == null && childIsChoiceType && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) && !IBaseReference.class.isAssignableFrom(nextElementType)) { if (extensionAttr == null
def = new RuntimeChildChoiceDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, choiceTypes); && childIsChoiceType
&& !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)
&& !IBaseReference.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildChoiceDefinition(
nextField, elementName, childAnnotation, descriptionAnnotation, choiceTypes);
} else if (extensionAttr != null) { } else if (extensionAttr != null) {
/* /*
* Child is an extension * Child is an extension
@ -374,72 +406,124 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
Class<? extends IBase> et = (Class<? extends IBase>) nextElementType; Class<? extends IBase> et = (Class<? extends IBase>) nextElementType;
Object binder = null; 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); 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)) { 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 * Child is a resource reference
*/ */
List<Class<? extends IBaseResource>> refTypesList = new ArrayList<>(); List<Class<? extends IBaseResource>> refTypesList = new ArrayList<>();
for (Class<? extends IElement> nextType : childAnnotation.type()) { for (Class<? extends IElement> nextType : childAnnotation.type()) {
if (IBaseReference.class.isAssignableFrom(nextType)) { 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; continue;
} else if (IBaseResource.class.isAssignableFrom(nextType) == false) { } 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); 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) } else if (IResourceBlock.class.isAssignableFrom(nextElementType)
|| IBaseDatatypeElement.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? * 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; Class<? extends IBase> blockDef = (Class<? extends IBase>) nextElementType;
def = new RuntimeChildResourceBlockDefinition(myContext, nextField, childAnnotation, descriptionAnnotation, elementName, blockDef); def = new RuntimeChildResourceBlockDefinition(
} else if (IDatatype.class.equals(nextElementType) || IElement.class.equals(nextElementType) || "Type".equals(nextElementType.getSimpleName()) myContext, nextField, childAnnotation, descriptionAnnotation, elementName, blockDef);
|| IBaseDatatype.class.equals(nextElementType)) { } 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); def = new RuntimeChildAny(nextField, elementName, childAnnotation, descriptionAnnotation);
} else if (IDatatype.class.isAssignableFrom(nextElementType) || IPrimitiveType.class.isAssignableFrom(nextElementType) || ICompositeType.class.isAssignableFrom(nextElementType) } else if (IDatatype.class.isAssignableFrom(nextElementType)
|| IBaseDatatype.class.isAssignableFrom(nextElementType) || IBaseExtension.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; Class<? extends IBase> nextDatatype = (Class<? extends IBase>) nextElementType;
if (IPrimitiveType.class.isAssignableFrom(nextElementType)) { if (IPrimitiveType.class.isAssignableFrom(nextElementType)) {
if (nextElementType.equals(BoundCodeDt.class)) { if (nextElementType.equals(BoundCodeDt.class)) {
IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField); IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField);
Class<? extends Enum<?>> enumType = ModelScanner.determineEnumTypeForBoundField(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)) { } else if (IBaseEnumeration.class.isAssignableFrom(nextElementType)) {
Class<? extends Enum<?>> binderType = ModelScanner.determineEnumTypeForBoundField(nextField); Class<? extends Enum<?>> binderType =
def = new RuntimeChildPrimitiveEnumerationDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype, binderType); ModelScanner.determineEnumTypeForBoundField(nextField);
def = new RuntimeChildPrimitiveEnumerationDatatypeDefinition(
nextField,
elementName,
childAnnotation,
descriptionAnnotation,
nextDatatype,
binderType);
} else { } else {
def = new RuntimeChildPrimitiveDatatypeDefinition(nextField, elementName, descriptionAnnotation, childAnnotation, nextDatatype); def = new RuntimeChildPrimitiveDatatypeDefinition(
nextField, elementName, descriptionAnnotation, childAnnotation, nextDatatype);
} }
} else { } else {
if (IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) { if (IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) {
IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField); IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField);
Class<? extends Enum<?>> enumType = ModelScanner.determineEnumTypeForBoundField(nextField); Class<? extends Enum<?>> enumType = ModelScanner.determineEnumTypeForBoundField(nextField);
def = new RuntimeChildCompositeBoundDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype, binder, enumType); def = new RuntimeChildCompositeBoundDatatypeDefinition(
} else if (BaseNarrativeDt.class.isAssignableFrom(nextElementType) || INarrative.class.isAssignableFrom(nextElementType)) { nextField,
def = new RuntimeChildNarrativeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype); 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 { } else {
def = new RuntimeChildCompositeDatatypeDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype); def = new RuntimeChildCompositeDatatypeDefinition(
nextField, elementName, childAnnotation, descriptionAnnotation, nextDatatype);
} }
} }
} else { } 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); Binding bindingAnnotation = ModelScanner.pullAnnotation(nextField, Binding.class);
@ -448,7 +532,6 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
def.setBindingValueSet(bindingAnnotation.valueSet()); def.setBindingValueSet(bindingAnnotation.valueSet());
} }
} }
} }
def.setReplacedParentDefinition(replacedParent); def.setReplacedParentDefinition(replacedParent);
@ -458,7 +541,9 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
@Override @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) { if (mySealed == SealingStateEnum.SEALED) {
return; return;
} }
@ -485,7 +570,8 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
for (String nextName : next.getValidChildNames()) { for (String nextName : next.getValidChildNames()) {
if (myNameToChild.containsKey(nextName)) { 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); myNameToChild.put(nextName, next);
} }
@ -538,7 +624,6 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
} }
@Override @Override
protected void validateSealed() { protected void validateSealed() {
if (mySealed != SealingStateEnum.SEALED) { 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; int index = theDefaultAtEnd ? theChildren.size() : -1;
for (ListIterator<BaseRuntimeChildDefinition> iter = theChildren.listIterator(); iter.hasNext(); ) { for (ListIterator<BaseRuntimeChildDefinition> iter = theChildren.listIterator(); iter.hasNext(); ) {
if (iter.next().getElementName().equals(theName)) { if (iter.next().getElementName().equals(theName)) {
@ -620,5 +706,4 @@ public abstract class BaseRuntimeElementCompositeDefinition<T extends IBase> ext
} }
return index; return index;
} }
} }

View File

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

View File

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

View File

@ -42,5 +42,4 @@ public class ConfigurationException extends RuntimeException {
public ConfigurationException(Throwable theCause) { public ConfigurationException(Throwable theCause) {
super(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.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -75,6 +73,8 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.Set; 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 * 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 { public class FhirContext {
private static final List<Class<? extends IBaseResource>> EMPTY_LIST = Collections.emptyList(); 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 static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirContext.class);
private final IFhirVersion myVersion; private final IFhirVersion myVersion;
private final Map<String, Class<? extends IBaseResource>> myDefaultTypeForProfile = new HashMap<>(); private final Map<String, Class<? extends IBaseResource>> myDefaultTypeForProfile = new HashMap<>();
private final Set<PerformanceOptionsEnum> myPerformanceOptions = new HashSet<>(); private final Set<PerformanceOptionsEnum> myPerformanceOptions = new HashSet<>();
private final Collection<Class<? extends IBaseResource>> myResourceTypesToScan; private final Collection<Class<? extends IBaseResource>> myResourceTypesToScan;
private AddProfileTagEnum myAddProfileTagWhenEncoding = AddProfileTagEnum.ONLY_FOR_CUSTOM; 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 ArrayList<Class<? extends IBase>> myCustomTypes;
private volatile Map<String, RuntimeResourceDefinition> myIdToResourceDefinition = Collections.emptyMap(); private volatile Map<String, RuntimeResourceDefinition> myIdToResourceDefinition = Collections.emptyMap();
private volatile boolean myInitialized; private volatile boolean myInitialized;
@ -122,7 +124,8 @@ public class FhirContext {
private volatile IRestfulClientFactory myRestfulClientFactory; private volatile IRestfulClientFactory myRestfulClientFactory;
private volatile RuntimeChildUndeclaredExtensionDefinition myRuntimeChildUndeclaredExtensionDefinition; private volatile RuntimeChildUndeclaredExtensionDefinition myRuntimeChildUndeclaredExtensionDefinition;
private IValidationSupport myValidationSupport; 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 Set<String> myResourceNames;
private volatile Boolean myFormatXmlSupported; private volatile Boolean myFormatXmlSupported;
private volatile Boolean myFormatJsonSupported; private volatile Boolean myFormatJsonSupported;
@ -175,12 +178,15 @@ public class FhirContext {
this(theVersion, null); 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(); VersionUtil.getVersion();
if (theVersion != null) { if (theVersion != null) {
if (!theVersion.isPresentOnClasspath()) { 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(); myVersion = theVersion.getVersionImplementation();
} else if (FhirVersionEnum.DSTU2.isPresentOnClasspath()) { } else if (FhirVersionEnum.DSTU2.isPresentOnClasspath()) {
@ -196,18 +202,25 @@ public class FhirContext {
} else if (FhirVersionEnum.R4B.isPresentOnClasspath()) { } else if (FhirVersionEnum.R4B.isPresentOnClasspath()) {
myVersion = FhirVersionEnum.R4B.getVersionImplementation(); myVersion = FhirVersionEnum.R4B.getVersionImplementation();
} else { } 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) { 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()", ourLog.info(
myVersion.getVersion().name()); "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 { } else {
if (HapiSystemProperties.isUnitTestModeEnabled()) { if (HapiSystemProperties.isUnitTestModeEnabled()) {
String calledAt = ExceptionUtils.getStackFrames(new Throwable())[4]; 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 { } 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) { } catch (ClassNotFoundException e) {
ourLog.trace("Android mode not detected"); ourLog.trace("Android mode not detected");
} }
} }
/** /**
* @since 5.6.0 * @since 5.6.0
*/ */
@ -246,7 +257,6 @@ public class FhirContext {
return forCached(FhirVersionEnum.DSTU2_HL7ORG); return forCached(FhirVersionEnum.DSTU2_HL7ORG);
} }
/** /**
* @since 5.5.0 * @since 5.5.0
*/ */
@ -475,7 +485,9 @@ public class FhirContext {
Validate.notNull(theResourceType, "theResourceType can not be null"); Validate.notNull(theResourceType, "theResourceType can not be null");
if (Modifier.isAbstract(theResourceType.getModifiers())) { 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); RuntimeResourceDefinition retVal = (RuntimeResourceDefinition) myClassToElementDefinition.get(theResourceType);
@ -486,7 +498,8 @@ public class FhirContext {
return retVal; 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"); Validate.notNull(theVersion, "theVersion can not be null");
validateInitialized(); validateInitialized();
@ -500,7 +513,8 @@ public class FhirContext {
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = new HashMap<>(); Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = new HashMap<>();
ModelScanner.scanVersionPropertyFile(null, nameToType, theVersion, existing); 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.putAll(myVersionToNameToResourceType);
newVersionToNameToResourceType.put(theVersion, nameToType); newVersionToNameToResourceType.put(theVersion, nameToType);
myVersionToNameToResourceType = newVersionToNameToResourceType; myVersionToNameToResourceType = newVersionToNameToResourceType;
@ -575,7 +589,8 @@ public class FhirContext {
// Multiple spots in HAPI FHIR and Smile CDR depend on DataFormatException // Multiple spots in HAPI FHIR and Smile CDR depend on DataFormatException
// being thrown by this method, don't change that. // 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)) { if (IBaseResource.class.isAssignableFrom(clazz)) {
retVal = scanResourceType(clazz); retVal = scanResourceType(clazz);
@ -645,9 +660,13 @@ public class FhirContext {
public IRestfulClientFactory getRestfulClientFactory() { public IRestfulClientFactory getRestfulClientFactory() {
if (myRestfulClientFactory == null) { if (myRestfulClientFactory == null) {
try { 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) { } 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; return myRestfulClientFactory;
@ -684,20 +703,31 @@ public class FhirContext {
* If hapi-fhir-validation is on the classpath, we can create a much more robust * If hapi-fhir-validation is on the classpath, we can create a much more robust
* validation chain using the classes found in that package * validation chain using the classes found in that package
*/ */
String inMemoryTermSvcType = "org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport"; String inMemoryTermSvcType =
String commonCodeSystemsSupportType = "org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService"; "org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport";
String commonCodeSystemsSupportType =
"org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService";
if (ReflectionUtil.typeExists(inMemoryTermSvcType)) { if (ReflectionUtil.typeExists(inMemoryTermSvcType)) {
IValidationSupport inMemoryTermSvc = ReflectionUtil.newInstanceOrReturnNull(inMemoryTermSvcType, IValidationSupport.class, new Class<?>[]{FhirContext.class}, new Object[]{this}); IValidationSupport inMemoryTermSvc = ReflectionUtil.newInstanceOrReturnNull(
IValidationSupport commonCodeSystemsSupport = ReflectionUtil.newInstanceOrReturnNull(commonCodeSystemsSupportType, IValidationSupport.class, new Class<?>[]{FhirContext.class}, new Object[]{this}); inMemoryTermSvcType,
retVal = ReflectionUtil.newInstanceOrReturnNull("org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain", IValidationSupport.class, new Class<?>[]{IValidationSupport[].class}, new Object[]{new IValidationSupport[]{ IValidationSupport.class,
retVal, new Class<?>[] {FhirContext.class},
inMemoryTermSvc, new Object[] {this});
commonCodeSystemsSupport IValidationSupport commonCodeSystemsSupport = ReflectionUtil.newInstanceOrReturnNull(
}}); commonCodeSystemsSupportType,
assert retVal != null : "Failed to instantiate " + "org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain"; 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; myValidationSupport = retVal;
} }
return retVal; return retVal;
@ -758,20 +788,20 @@ public class FhirContext {
return retVal; return retVal;
} }
/** /**
* @return Returns <code>true</code> if the NDJSON serialization format is supported, based on the * @return Returns <code>true</code> if the NDJSON serialization format is supported, based on the
* available libraries on the classpath. * available libraries on the classpath.
* *
* @since 5.6.0 * @since 5.6.0
*/ */
public boolean isFormatNDJsonSupported() { public boolean isFormatNDJsonSupported() {
Boolean retVal = myFormatNDJsonSupported; Boolean retVal = myFormatNDJsonSupported;
if (retVal == null) { if (retVal == null) {
retVal = tryToInitParser(() -> newNDJsonParser()); retVal = tryToInitParser(() -> newNDJsonParser());
myFormatNDJsonSupported = retVal; myFormatNDJsonSupported = retVal;
} }
return retVal; return retVal;
} }
/** /**
* @return Returns <code>true</code> if the RDF serialization format is supported, based on the * @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); return new JsonParser(this, myParserErrorHandler);
} }
/** /**
* Create and return a new NDJSON parser. * Create and return a new NDJSON parser.
* *
* <p> * <p>
* Thread safety: <b>Parsers are not guaranteed to be thread safe</b>. Create a new parser instance for every thread * 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. * or every message being parsed/encoded.
* </p> * </p>
* <p> * <p>
* Performance Note: <b>This method is cheap</b> to call, and may be called once for every message being processed * 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 * without incurring any performance penalty
* </p> * </p>
* <p> * <p>
* The NDJsonParser provided here is expected to translate between legal NDJson and FHIR Bundles. * 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 * 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. * 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 * 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. * or where it is asked to decode into anything other than a FHIR Bundle.
* </p> * </p>
*/ */
public IParser newNDJsonParser() { public IParser newNDJsonParser() {
return new NDJsonParser(this, myParserErrorHandler); return new NDJsonParser(this, myParserErrorHandler);
} }
/** /**
* Create and return a new RDF parser. * Create and return a new RDF parser.
@ -1005,7 +1035,8 @@ public class FhirContext {
return (RuntimeResourceDefinition) defs.get(theResourceType); 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<>(); List<Class<? extends IBase>> typesToScan = new ArrayList<>();
if (theResourceTypes != null) { if (theResourceTypes != null) {
typesToScan.addAll(theResourceTypes); typesToScan.addAll(theResourceTypes);
@ -1022,7 +1053,8 @@ public class FhirContext {
Map<String, BaseRuntimeElementDefinition<?>> nameToElementDefinition = new HashMap<>(); Map<String, BaseRuntimeElementDefinition<?>> nameToElementDefinition = new HashMap<>();
nameToElementDefinition.putAll(myNameToElementDefinition); nameToElementDefinition.putAll(myNameToElementDefinition);
for (Entry<String, BaseRuntimeElementDefinition<?>> next : scanner.getNameToElementDefinitions().entrySet()) { for (Entry<String, BaseRuntimeElementDefinition<?>> next :
scanner.getNameToElementDefinitions().entrySet()) {
if (!nameToElementDefinition.containsKey(next.getKey())) { if (!nameToElementDefinition.containsKey(next.getKey())) {
nameToElementDefinition.put(next.getKey().toLowerCase(), next.getValue()); nameToElementDefinition.put(next.getKey().toLowerCase(), next.getValue());
} }
@ -1030,7 +1062,8 @@ public class FhirContext {
Map<String, RuntimeResourceDefinition> nameToResourceDefinition = new HashMap<>(); Map<String, RuntimeResourceDefinition> nameToResourceDefinition = new HashMap<>();
nameToResourceDefinition.putAll(myNameToResourceDefinition); nameToResourceDefinition.putAll(myNameToResourceDefinition);
for (Entry<String, RuntimeResourceDefinition> next : scanner.getNameToResourceDefinition().entrySet()) { for (Entry<String, RuntimeResourceDefinition> next :
scanner.getNameToResourceDefinition().entrySet()) {
if (!nameToResourceDefinition.containsKey(next.getKey())) { if (!nameToResourceDefinition.containsKey(next.getKey())) {
nameToResourceDefinition.put(next.getKey(), next.getValue()); nameToResourceDefinition.put(next.getKey(), next.getValue());
} }
@ -1043,7 +1076,8 @@ public class FhirContext {
if (next instanceof RuntimeResourceDefinition) { if (next instanceof RuntimeResourceDefinition) {
if ("Bundle".equals(next.getName())) { if ("Bundle".equals(next.getName())) {
if (!IBaseBundle.class.isAssignableFrom(next.getImplementingClass())) { 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"}) @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) { if (theResourceTypes == null) {
return null; return null;
} }
@ -1146,13 +1181,15 @@ public class FhirContext {
} }
public IPrimitiveType<Boolean> newPrimitiveBoolean(Boolean theValue) { 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); retval.setValue(theValue);
return retval; return retval;
} }
public IPrimitiveType<String > newPrimitiveString(String theValue) { public IPrimitiveType<String> newPrimitiveString(String theValue) {
IPrimitiveType<String> retval = (IPrimitiveType<String>) getElementDefinition("string").newInstance(); IPrimitiveType<String> retval =
(IPrimitiveType<String>) getElementDefinition("string").newInstance();
retval.setValue(theValue); retval.setValue(theValue);
return retval; return retval;
} }
@ -1237,7 +1274,8 @@ public class FhirContext {
return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, v -> new FhirContext(v)); 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); ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<>(1);
retVal.add(theResourceType); retVal.add(theResourceType);
return retVal; return retVal;
@ -1248,11 +1286,11 @@ public class FhirContext {
ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<Class<? extends IBaseResource>>(1); ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<Class<? extends IBaseResource>>(1);
for (Class<?> clazz : theResourceTypes) { for (Class<?> clazz : theResourceTypes) {
if (!IResource.class.isAssignableFrom(clazz)) { 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); retVal.add((Class<? extends IResource>) clazz);
} }
return retVal; return retVal;
} }
} }

View File

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

View File

@ -31,5 +31,4 @@ public interface IRuntimeDatatypeDefinition {
boolean isProfileOf(Class<? extends IBaseDatatype> theType); 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.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@ -68,6 +67,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import javax.annotation.Nonnull;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
@ -85,8 +85,12 @@ class ModelScanner {
private Set<Class<? extends IBase>> myVersionTypes; private Set<Class<? extends IBase>> myVersionTypes;
ModelScanner(FhirContext theContext, FhirVersionEnum theVersion, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingDefinitions, ModelScanner(
@Nonnull Collection<Class<? extends IBase>> theResourceTypes) throws ConfigurationException { FhirContext theContext,
FhirVersionEnum theVersion,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theExistingDefinitions,
@Nonnull Collection<Class<? extends IBase>> theResourceTypes)
throws ConfigurationException {
myContext = theContext; myContext = theContext;
myVersion = theVersion; myVersion = theVersion;
@ -118,7 +122,9 @@ class ModelScanner {
return myRuntimeChildUndeclaredExtensionDefinition; 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) { if (theExistingDefinitions != null) {
myClassToElementDefinitions.putAll(theExistingDefinitions); myClassToElementDefinitions.putAll(theExistingDefinitions);
} }
@ -140,7 +146,8 @@ class ModelScanner {
myScanAlso.clear(); myScanAlso.clear();
} while (!typesToScan.isEmpty()); } 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())) { if (theExistingDefinitions != null && theExistingDefinitions.containsKey(nextEntry.getKey())) {
continue; continue;
} }
@ -178,7 +185,9 @@ class ModelScanner {
ResourceDef resourceDefinition = pullAnnotation(theClass, ResourceDef.class); ResourceDef resourceDefinition = pullAnnotation(theClass, ResourceDef.class);
if (resourceDefinition != null) { if (resourceDefinition != null) {
if (!IBaseResource.class.isAssignableFrom(theClass)) { 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") @SuppressWarnings("unchecked")
Class<? extends IBaseResource> resClass = (Class<? extends IBaseResource>) theClass; Class<? extends IBaseResource> resClass = (Class<? extends IBaseResource>) theClass;
@ -204,10 +213,14 @@ class ModelScanner {
Block blockDefinition = pullAnnotation(theClass, Block.class); Block blockDefinition = pullAnnotation(theClass, Block.class);
if (blockDefinition != null) { 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); scanBlock(theClass);
} else { } 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; 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 // Just in case someone messes up when upgrading from DSTU2
if (myContext.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { if (myContext.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
if (BaseIdentifiableElement.class.isAssignableFrom(theClass)) { 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); blockDef.populateScanAlso(myScanAlso);
myClassToElementDefinitions.put(theClass, blockDef); myClassToElementDefinitions.put(theClass, blockDef);
@ -243,11 +260,13 @@ class ModelScanner {
RuntimeCompositeDatatypeDefinition elementDef; RuntimeCompositeDatatypeDefinition elementDef;
if (theClass.equals(ExtensionDt.class)) { 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)) { // } else if (IBaseMetaType.class.isAssignableFrom(theClass)) {
// resourceDef = new RuntimeMetaDefinition(theDatatypeDefinition, theClass, isStandardType(theClass)); // resourceDef = new RuntimeMetaDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} else { } else {
elementDef = new RuntimeCompositeDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions); elementDef = new RuntimeCompositeDatatypeDefinition(
theDatatypeDefinition, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions);
} }
myClassToElementDefinitions.put(theClass, elementDef); myClassToElementDefinitions.put(theClass, elementDef);
myNameToElementDefinitions.put(elementDef.getName().toLowerCase(), elementDef); myNameToElementDefinitions.put(elementDef.getName().toLowerCase(), elementDef);
@ -260,12 +279,14 @@ class ModelScanner {
elementDef.populateScanAlso(myScanAlso); 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()); ourLog.debug("Scanning resource class: {}", theClass.getName());
String resourceName = theDatatypeDefinition.name(); String resourceName = theDatatypeDefinition.name();
if (isBlank(resourceName)) { 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; BaseRuntimeElementDefinition<?> elementDef;
@ -280,7 +301,8 @@ class ModelScanner {
} else if (IIdType.class.isAssignableFrom(theClass)) { } else if (IIdType.class.isAssignableFrom(theClass)) {
elementDef = new RuntimeIdDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass)); elementDef = new RuntimeIdDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} else { } else {
elementDef = new RuntimePrimitiveDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass)); elementDef =
new RuntimePrimitiveDatatypeDefinition(theDatatypeDefinition, theClass, isStandardType(theClass));
} }
myClassToElementDefinitions.put(theClass, elementDef); myClassToElementDefinitions.put(theClass, elementDef);
if (!theDatatypeDefinition.isSpecialization()) { if (!theDatatypeDefinition.isSpecialization()) {
@ -312,8 +334,9 @@ class ModelScanner {
parent = parent.getSuperclass(); parent = parent.getSuperclass();
} }
if (isBlank(resourceName)) { if (isBlank(resourceName)) {
throw new ConfigurationException(Msg.code(1719) + "Resource type @" + ResourceDef.class.getSimpleName() + " annotation contains no resource name(): " + theClass.getCanonicalName() throw new ConfigurationException(Msg.code(1719) + "Resource type @" + ResourceDef.class.getSimpleName()
+ " - This is only allowed for types that extend other resource types "); + " 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(); String resourceId = resourceDefinition.id();
if (!isBlank(resourceId)) { if (!isBlank(resourceId)) {
if (myIdToResourceDefinition.containsKey(resourceId)) { if (myIdToResourceDefinition.containsKey(resourceId)) {
throw new ConfigurationException(Msg.code(1720) + "The following resource types have the same ID of '" + resourceId + "' - " + theClass.getCanonicalName() + " and " throw new ConfigurationException(Msg.code(1720) + "The following resource types have the same ID of '"
+ myIdToResourceDefinition.get(resourceId).getImplementingClass().getCanonicalName()); + 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); myClassToElementDefinitions.put(theClass, resourceDef);
if (primaryNameProvider) { if (primaryNameProvider) {
if (resourceDef.getStructureVersion() == myVersion) { if (resourceDef.getStructureVersion() == myVersion) {
@ -360,7 +388,8 @@ class ModelScanner {
return resourceName; 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<String, RuntimeSearchParam> nameToParam = new HashMap<>();
Map<Field, SearchParamDefinition> compositeFields = new LinkedHashMap<>(); Map<Field, SearchParamDefinition> compositeFields = new LinkedHashMap<>();
@ -384,9 +413,11 @@ class ModelScanner {
for (Field nextField : fields) { for (Field nextField : fields) {
SearchParamDefinition searchParam = pullAnnotation(nextField, SearchParamDefinition.class); SearchParamDefinition searchParam = pullAnnotation(nextField, SearchParamDefinition.class);
if (searchParam != null) { if (searchParam != null) {
RestSearchParameterTypeEnum paramType = RestSearchParameterTypeEnum.forCode(searchParam.type().toLowerCase()); RestSearchParameterTypeEnum paramType =
RestSearchParameterTypeEnum.forCode(searchParam.type().toLowerCase());
if (paramType == null) { 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; Set<String> providesMembershipInCompartments;
providesMembershipInCompartments = new HashSet<>(); providesMembershipInCompartments = new HashSet<>();
@ -425,12 +456,23 @@ class ModelScanner {
String name = searchParam.name(); String name = searchParam.name();
url = toCanonicalSearchParameterUri(theResourceDef, 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); theResourceDef.addSearchParam(param);
nameToParam.put(param.getName(), param); nameToParam.put(param.getName(), param);
} }
} }
} }
private String toCanonicalSearchParameterUri(RuntimeResourceDefinition theResourceDef, String theName) { private String toCanonicalSearchParameterUri(RuntimeResourceDefinition theResourceDef, String theName) {
@ -455,7 +497,9 @@ class ModelScanner {
if (List.class.equals(nextElementType)) { if (List.class.equals(nextElementType)) {
nextElementType = ReflectionUtil.getGenericCollectionTypeOfField(next); nextElementType = ReflectionUtil.getGenericCollectionTypeOfField(next);
} else if (Collection.class.isAssignableFrom(nextElementType)) { } 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; return nextElementType;
} }
@ -464,7 +508,8 @@ class ModelScanner {
static IValueSetEnumBinder<Enum<?>> getBoundCodeBinder(Field theNext) { static IValueSetEnumBinder<Enum<?>> getBoundCodeBinder(Field theNext) {
Class<?> bound = getGenericCollectionTypeOfCodedField(theNext); Class<?> bound = getGenericCollectionTypeOfCodedField(theNext);
if (bound == null) { 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"; String fieldName = "VALUESET_BINDER";
@ -472,7 +517,11 @@ class ModelScanner {
Field bindingField = bound.getField(fieldName); Field bindingField = bound.getField(fieldName);
return (IValueSetEnumBinder<Enum<?>>) bindingField.get(null); return (IValueSetEnumBinder<Enum<?>>) bindingField.get(null);
} catch (Exception e) { } 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) { static Class<? extends Enum<?>> determineEnumTypeForBoundField(Field next) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(next); Class<? extends Enum<?>> enumType =
(Class<? extends Enum<?>>) ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(next);
return enumType; return enumType;
} }
@ -506,7 +556,11 @@ class ModelScanner {
return type; 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<>(); Set<Class<? extends IBase>> retVal = new HashSet<>();
try (InputStream str = theVersion.getVersionImplementation().getFhirVersionPropertiesFile()) { try (InputStream str = theVersion.getVersionImplementation().getFhirVersionPropertiesFile()) {
@ -537,12 +591,16 @@ class ModelScanner {
Class<? extends IBaseDatatype> nextClass = (Class<? extends IBaseDatatype>) dtType; Class<? extends IBaseDatatype> nextClass = (Class<? extends IBaseDatatype>) dtType;
theDatatypes.add(nextClass); theDatatypes.add(nextClass);
} else { } 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; continue;
} }
} catch (ClassNotFoundException e) { } 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.")) { } else if (nextKey.startsWith("resource.")) {
@ -550,27 +608,33 @@ class ModelScanner {
String resName = nextKey.substring("resource.".length()).toLowerCase(); String resName = nextKey.substring("resource.".length()).toLowerCase();
try { try {
@SuppressWarnings("unchecked") @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)) { if (theExistingElementDefinitions.containsKey(nextClass)) {
continue; continue;
} }
if (!IBaseResource.class.isAssignableFrom(nextClass)) { 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); theResourceTypes.put(resName, nextClass);
} catch (ClassNotFoundException e) { } 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 { } 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) { } 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; return retVal;
} }
} }

View File

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

View File

@ -35,5 +35,4 @@ public enum PerformanceOptionsEnum {
* </p> * </p>
*/ */
DEFERRED_MODEL_SCANNING DEFERRED_MODEL_SCANNING
} }

View File

@ -19,6 +19,15 @@
*/ */
package ca.uhn.fhir.context; 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.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -26,24 +35,17 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; 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 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); super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation);
} }
@Override @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>>(); List<Class<? extends IBase>> choiceTypes = new ArrayList<Class<? extends IBase>>();
for (Class<? extends IBase> next : theClassToElementDefinitions.keySet()) { for (Class<? extends IBase> next : theClassToElementDefinitions.keySet()) {
@ -62,11 +64,14 @@ public class RuntimeChildAny extends RuntimeChildChoiceDefinition {
} }
} }
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); choiceTypes.add(next);
} }
} }
Collections.sort(choiceTypes,new Comparator<Class<?>>(){ Collections.sort(choiceTypes, new Comparator<Class<?>>() {
@Override @Override
public int compare(Class<?> theO1, Class<?> theO2) { public int compare(Class<?> theO1, Class<?> theO2) {
boolean o1res = IResource.class.isAssignableFrom(theO1); boolean o1res = IResource.class.isAssignableFrom(theO1);
@ -77,16 +82,14 @@ public class RuntimeChildAny extends RuntimeChildChoiceDefinition {
return -1; return -1;
} else if (o1res == false && o2res == false) { } else if (o1res == false && o2res == false) {
return 0; return 0;
}else { } else {
return 1; return 1;
} }
}}); }
});
setChoiceTypes(choiceTypes); setChoiceTypes(choiceTypes);
super.sealAndInitialize(theContext, theClassToElementDefinitions); super.sealAndInitialize(theContext, theClassToElementDefinitions);
} }
} }

View File

@ -49,7 +49,12 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
/** /**
* Constructor * 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); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
myChoiceTypes = Collections.unmodifiableList(theChoiceTypes); myChoiceTypes = Collections.unmodifiableList(theChoiceTypes);
@ -60,7 +65,8 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
* *
* For extension, if myChoiceTypes will be set some other way * 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); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
} }
@ -79,14 +85,17 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
@Override @Override
public BaseRuntimeElementDefinition<?> getChildByName(String theName) { 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); return myNameToChildDefinition.get(theName);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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<?>>(); myNameToChildDefinition = new HashMap<String, BaseRuntimeElementDefinition<?>>();
myDatatypeToElementName = new HashMap<Class<? extends IBase>, String>(); myDatatypeToElementName = new HashMap<Class<? extends IBase>, String>();
myDatatypeToElementDefinition = new HashMap<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>(); myDatatypeToElementDefinition = new HashMap<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>();
@ -158,7 +167,9 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
if (myDatatypeToElementName.containsKey(next)) { if (myDatatypeToElementName.containsKey(next)) {
String existing = myDatatypeToElementName.get(next); String existing = myDatatypeToElementName.get(next);
if (!existing.equals(elementName)) { 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 { } else {
myDatatypeToElementName.put(next, elementName); myDatatypeToElementName.put(next, elementName);
@ -171,7 +182,6 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
myResourceTypes = Collections.unmodifiableList(myResourceTypes); myResourceTypes = Collections.unmodifiableList(myResourceTypes);
} }
public List<Class<? extends IBaseResource>> getResourceTypes() { public List<Class<? extends IBaseResource>> getResourceTypes() {
return myResourceTypes; return myResourceTypes;
} }
@ -190,5 +200,4 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
public Set<Class<? extends IBase>> getValidChildTypes() { public Set<Class<? extends IBase>> getValidChildTypes() {
return Collections.unmodifiableSet((myDatatypeToElementDefinition.keySet())); return Collections.unmodifiableSet((myDatatypeToElementDefinition.keySet()));
} }
} }

View File

@ -19,21 +19,27 @@
*/ */
package ca.uhn.fhir.context; 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.IValueSetEnumBinder;
import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description; 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 { public class RuntimeChildCompositeBoundDatatypeDefinition extends RuntimeChildCompositeDatatypeDefinition {
private IValueSetEnumBinder<Enum<?>> myBinder; private IValueSetEnumBinder<Enum<?>> myBinder;
private Class<? extends Enum<?>> myEnumType; 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); super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype);
Validate.notNull(theBinder, "theBinder must not be null"); Validate.notNull(theBinder, "theBinder must not be null");
Validate.notNull(theEnumType, "theEnumType must not be null"); Validate.notNull(theEnumType, "theEnumType must not be null");
@ -51,5 +57,4 @@ public class RuntimeChildCompositeBoundDatatypeDefinition extends RuntimeChildCo
public Class<? extends Enum<?>> getBoundEnumType() { public Class<? extends Enum<?>> getBoundEnumType() {
return myEnumType; return myEnumType;
} }
} }

View File

@ -19,18 +19,20 @@
*/ */
package ca.uhn.fhir.context; 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.Child;
import ca.uhn.fhir.model.api.annotation.Description; 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 class RuntimeChildCompositeDatatypeDefinition extends BaseRuntimeChildDatatypeDefinition {
public RuntimeChildCompositeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype) { public RuntimeChildCompositeDatatypeDefinition(
super(theField, theElementName, theChildAnnotation,theDescriptionAnnotation, theDatatype); 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; 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); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
} }
@ -72,7 +74,9 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi
} }
@Override @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(); Class<?> actualType = theContext.getVersion().getContainedType();
if (BaseContainedDt.class.isAssignableFrom(actualType)) { if (BaseContainedDt.class.isAssignableFrom(actualType)) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -81,8 +85,8 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi
} else if (List.class.isAssignableFrom(actualType)) { } else if (List.class.isAssignableFrom(actualType)) {
myElem = new RuntimeElemContainedResourceList(IBaseResource.class, false); myElem = new RuntimeElemContainedResourceList(IBaseResource.class, false);
} else { } 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; 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.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -29,13 +34,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase; 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;
public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceDefinition { public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceDefinition {
@ -56,8 +55,15 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
* @param theDefinedLocally * @param theDefinedLocally
* See {@link Extension#definedLocally()} * See {@link Extension#definedLocally()}
*/ */
RuntimeChildDeclaredExtensionDefinition(Field theField, Child theChild, Description theDescriptionAnnotation, Extension theExtension, String theElementName, String theExtensionUrl, RuntimeChildDeclaredExtensionDefinition(
Class<? extends IBase> theChildType, Object theBoundTypeBinder) Field theField,
Child theChild,
Description theDescriptionAnnotation,
Extension theExtension,
String theElementName,
String theExtensionUrl,
Class<? extends IBase> theChildType,
Object theBoundTypeBinder)
throws ConfigurationException { throws ConfigurationException {
super(theField, theElementName, theChild, theDescriptionAnnotation); super(theField, theElementName, theChild, theDescriptionAnnotation);
assert isNotBlank(theExtensionUrl); assert isNotBlank(theExtensionUrl);
@ -116,7 +122,6 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
return "modifierExtension"; return "modifierExtension";
} }
return "extension"; return "extension";
} }
return retVal; return retVal;
} }
@ -124,7 +129,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
@Override @Override
public BaseRuntimeElementDefinition<?> getChildByName(String theName) { public BaseRuntimeElementDefinition<?> getChildByName(String theName) {
String name = theName; String name = theName;
if ("extension".equals(name)||"modifierExtension".equals(name)) { if ("extension".equals(name) || "modifierExtension".equals(name)) {
if (myChildResourceBlock != null) { if (myChildResourceBlock != null) {
return myChildResourceBlock; return myChildResourceBlock;
} }
@ -169,7 +174,9 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
} }
@Override @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>(); myUrlToChildExtension = new HashMap<String, RuntimeChildDeclaredExtensionDefinition>();
BaseRuntimeElementDefinition<?> elementDef = theClassToElementDefinitions.get(myChildType); BaseRuntimeElementDefinition<?> elementDef = theClassToElementDefinitions.get(myChildType);
@ -184,17 +191,19 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
} }
} }
if (elementDef instanceof RuntimePrimitiveDatatypeDefinition || elementDef instanceof RuntimeCompositeDatatypeDefinition) { if (elementDef instanceof RuntimePrimitiveDatatypeDefinition
// myDatatypeChildName = "value" + elementDef.getName().substring(0, 1).toUpperCase() + elementDef.getName().substring(1); || elementDef instanceof RuntimeCompositeDatatypeDefinition) {
// if ("valueResourceReference".equals(myDatatypeChildName)) { // myDatatypeChildName = "value" + elementDef.getName().substring(0, 1).toUpperCase() +
// Per one of the examples here: http://hl7.org/implement/standards/fhir/extensibility.html#extension // elementDef.getName().substring(1);
// myDatatypeChildName = "valueResource"; // if ("valueResourceReference".equals(myDatatypeChildName)) {
// List<Class<? extends IBaseResource>> types = new ArrayList<Class<? extends IBaseResource>>(); // Per one of the examples here: http://hl7.org/implement/standards/fhir/extensibility.html#extension
// types.add(IBaseResource.class); // myDatatypeChildName = "valueResource";
// myChildDef = findResourceReferenceDefinition(theClassToElementDefinitions); // List<Class<? extends IBaseResource>> types = new ArrayList<Class<? extends IBaseResource>>();
// } else { // types.add(IBaseResource.class);
myChildDef = elementDef; // myChildDef = findResourceReferenceDefinition(theClassToElementDefinitions);
// } // } else {
myChildDef = elementDef;
// }
} else if (elementDef instanceof RuntimeResourceBlockDefinition) { } else if (elementDef instanceof RuntimeResourceBlockDefinition) {
RuntimeResourceBlockDefinition extDef = ((RuntimeResourceBlockDefinition) elementDef); RuntimeResourceBlockDefinition extDef = ((RuntimeResourceBlockDefinition) elementDef);
for (RuntimeChildDeclaredExtensionDefinition next : extDef.getExtensions()) { for (RuntimeChildDeclaredExtensionDefinition next : extDef.getExtensions()) {
@ -215,5 +224,4 @@ public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceD
public Class<? extends IBase> getChildType() { public Class<? extends IBase> getChildType() {
return myChildType; return myChildType;
} }
} }

View File

@ -19,23 +19,24 @@
*/ */
package ca.uhn.fhir.context; 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.lang.reflect.Field;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; 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 { public class RuntimeChildDirectResource extends BaseRuntimeDeclaredChildDefinition {
// private RuntimeElemContainedResources myElem; // private RuntimeElemContainedResources myElem;
private FhirContext myContext; 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); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
} }
@ -61,8 +62,9 @@ public class RuntimeChildDirectResource extends BaseRuntimeDeclaredChildDefiniti
} }
@Override @Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myContext = theContext; myContext = theContext;
} }
} }

View File

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

View File

@ -19,20 +19,20 @@
*/ */
package ca.uhn.fhir.context; 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.lang.reflect.Field;
import java.util.Collections; import java.util.Collections;
import java.util.Set; 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 { 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); super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation);
} }
@ -54,20 +54,20 @@ public class RuntimeChildExtension extends RuntimeChildAny {
return super.getChildByName(theName); return super.getChildByName(theName);
} }
// @Override // @Override
// public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) { // public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) {
// if (IBaseExtension.class.isAssignableFrom(theDatatype)) { // if (IBaseExtension.class.isAssignableFrom(theDatatype)) {
// return myExtensionElement; // return myExtensionElement;
// } // }
// return super.getChildElementDefinitionByDatatype(theDatatype); // return super.getChildElementDefinitionByDatatype(theDatatype);
// } // }
// //
// @Override // @Override
// void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { // void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>
// super.sealAndInitialize(theContext, theClassToElementDefinitions); // theClassToElementDefinitions) {
// // super.sealAndInitialize(theContext, theClassToElementDefinitions);
// myExtensionElement = theContext.getRuntimeChildUndeclaredExtensionDefinition(); //
// } // myExtensionElement = theContext.getRuntimeChildUndeclaredExtensionDefinition();
// }
} }

View File

@ -19,18 +19,20 @@
*/ */
package ca.uhn.fhir.context; 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.Child;
import ca.uhn.fhir.model.api.annotation.Description; 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 class RuntimeChildNarrativeDefinition extends RuntimeChildCompositeDatatypeDefinition {
public RuntimeChildNarrativeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class<? extends IBase> theDatatype) { public RuntimeChildNarrativeDefinition(
super(theField, theElementName, theChildAnnotation,theDescriptionAnnotation, theDatatype); 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; 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.Child;
import ca.uhn.fhir.model.api.annotation.Description; 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 { public class RuntimeChildPrimitiveBoundCodeDatatypeDefinition extends RuntimeChildPrimitiveDatatypeDefinition {
private Object myBinder; private Object myBinder;
private Class<? extends Enum<?>> myEnumType; 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); super(theField, theElementName, theDescriptionAnnotation, theChildAnnotation, theDatatype);
myBinder = theBinder; myBinder = theBinder;
@ -47,5 +53,4 @@ public class RuntimeChildPrimitiveBoundCodeDatatypeDefinition extends RuntimeChi
public Object getInstanceConstructorArguments() { public Object getInstanceConstructorArguments() {
return myBinder; return myBinder;
} }
} }

View File

@ -19,17 +19,20 @@
*/ */
package ca.uhn.fhir.context; 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.Child;
import ca.uhn.fhir.model.api.annotation.Description; 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 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); super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype);
} }
} }

View File

@ -31,7 +31,13 @@ public class RuntimeChildPrimitiveEnumerationDatatypeDefinition extends RuntimeC
private Object myBinder; private Object myBinder;
private Class<? extends Enum<?>> myEnumType; 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); super(theField, theElementName, theDescriptionAnnotation, theChildAnnotation, theDatatype);
myEnumType = theBinderType; myEnumType = theBinderType;
@ -64,5 +70,4 @@ public class RuntimeChildPrimitiveEnumerationDatatypeDefinition extends RuntimeC
} }
return retVal; return retVal;
} }
} }

View File

@ -19,23 +19,29 @@
*/ */
package ca.uhn.fhir.context; 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.lang.reflect.Field;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; 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 { public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChildDefinition {
// private RuntimeResourceBlockDefinition myElementDef; // private RuntimeResourceBlockDefinition myElementDef;
private Class<? extends IBase> myResourceBlockType; private Class<? extends IBase> myResourceBlockType;
private FhirContext myContext; 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); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
myContext = theContext; myContext = theContext;
myResourceBlockType = theResourceBlockType; myResourceBlockType = theResourceBlockType;
@ -75,8 +81,9 @@ public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChil
} }
@Override @Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { void sealAndInitialize(
// myElementDef = (RuntimeResourceBlockDefinition) theClassToElementDefinitions.get(myResourceBlockType); 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 * 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); super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);
myResourceTypes = theResourceTypes; myResourceTypes = theResourceTypes;
@ -79,7 +84,9 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi
} }
@Override @Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myRuntimeDef = findResourceReferenceDefinition(theClassToElementDefinitions); myRuntimeDef = findResourceReferenceDefinition(theClassToElementDefinitions);
myValidChildNames = new HashSet<String>(); myValidChildNames = new HashSet<String>();
@ -97,23 +104,25 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi
* were some bad examples containing this. This causes conflicts with actual field names in * 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 * recent definitions though, so it has been disabled as of HAPI 0.9
*/ */
// for (Class<? extends IBaseResource> next : myResourceTypes) { // for (Class<? extends IBaseResource> next : myResourceTypes) {
// if (next == IResource.class) { // if (next == IResource.class) {
// for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> nextEntry : theClassToElementDefinitions.entrySet()) { // for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> nextEntry :
// if (IResource.class.isAssignableFrom(nextEntry.getKey())) { // theClassToElementDefinitions.entrySet()) {
// RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) nextEntry.getValue(); // if (IResource.class.isAssignableFrom(nextEntry.getKey())) {
// myValidChildNames.add(getElementName() + nextDef.getName()); // RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) nextEntry.getValue();
// } // myValidChildNames.add(getElementName() + nextDef.getName());
// } // }
// } // }
// else { // }
// RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) theClassToElementDefinitions.get(next); // else {
// if (nextDef == null) { // RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) theClassToElementDefinitions.get(next);
// throw new ConfigurationException(Msg.code(1691) + "Can't find child of type: " + next.getCanonicalName() + " in " + getField().getDeclaringClass()); // if (nextDef == null) {
// } // throw new ConfigurationException(Msg.code(1691) + "Can't find child of type: " + next.getCanonicalName()
// myValidChildNames.add(getElementName() + nextDef.getName()); // + " in " + getField().getDeclaringClass());
// } // }
// } // myValidChildNames.add(getElementName() + nextDef.getName());
// }
// }
myResourceTypes = Collections.unmodifiableList(myResourceTypes); myResourceTypes = Collections.unmodifiableList(myResourceTypes);
myValidChildNames = Collections.unmodifiableSet(myValidChildNames); 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_REFERENCE = "valueReference";
private static final String VALUE_RESOURCE = "valueResource"; 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<String, BaseRuntimeElementDefinition<?>> myAttributeNameToDefinition;
private Map<Class<? extends IBase>, String> myDatatypeToAttributeName; private Map<Class<? extends IBase>, String> myDatatypeToAttributeName;
private Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> myDatatypeToDefinition; private Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> myDatatypeToDefinition;
@ -46,7 +47,10 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
// nothing // 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); BaseRuntimeElementDefinition<?> def = findResourceReferenceDefinition(theClassToElementDefinitions);
myAttributeNameToDefinition.put(value, def); myAttributeNameToDefinition.put(value, def);
@ -58,7 +62,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def); myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def);
myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def); myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def);
} }
} }
@Override @Override
@ -72,7 +75,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
} }
return new ArrayList<>(target.getUndeclaredExtensions()); return new ArrayList<>(target.getUndeclaredExtensions());
} }
}; };
} }
@ -134,7 +136,9 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
} }
@Override @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<>(); Map<String, BaseRuntimeElementDefinition<?>> datatypeAttributeNameToDefinition = new HashMap<>();
myDatatypeToAttributeName = new HashMap<>(); myDatatypeToAttributeName = new HashMap<>();
myDatatypeToDefinition = new HashMap<>(); myDatatypeToDefinition = new HashMap<>();
@ -149,7 +153,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
ourLog.trace("Not adding specialization: {}", next.getImplementingClass()); ourLog.trace("Not adding specialization: {}", next.getImplementingClass());
} }
if (!next.isStandardType()) { if (!next.isStandardType()) {
continue; 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 // CodeType should win. If we aren't in a situation like that, there is a problem with the
// model so we should bail. // model so we should bail.
if (!existing.isStandardType()) { 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; myAttributeNameToDefinition = datatypeAttributeNameToDefinition;
/* /*
* Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1 * 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) { public static String createExtensionChildName(BaseRuntimeElementDefinition<?> next) {
return "value" + WordUtils.capitalize(next.getName()); return "value" + WordUtils.capitalize(next.getName());
} }
} }

View File

@ -30,18 +30,25 @@ import java.util.Map;
import static org.apache.commons.lang3.StringUtils.isBlank; 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 boolean mySpecialization;
private Class<? extends IBaseDatatype> myProfileOfType; private Class<? extends IBaseDatatype> myProfileOfType;
private BaseRuntimeElementDefinition<?> myProfileOf; 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); super(theDef.name(), theImplementingClass, theStandardType, theContext, theClassToElementDefinitions);
String resourceName = theDef.name(); String resourceName = theDef.name();
if (isBlank(resourceName)) { 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(); mySpecialization = theDef.isSpecialization();
@ -49,11 +56,12 @@ public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompos
if (myProfileOfType.equals(IBaseDatatype.class)) { if (myProfileOfType.equals(IBaseDatatype.class)) {
myProfileOfType = null; myProfileOfType = null;
} }
} }
@Override @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); super.sealAndInitialize(theContext, theClassToElementDefinitions);
if (myProfileOfType != null) { if (myProfileOfType != null) {
@ -91,6 +99,4 @@ public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompos
} }
return false; return false;
} }
} }

View File

@ -34,5 +34,4 @@ public class RuntimeElemContainedResourceList extends BaseRuntimeElementDefiniti
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() { public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.CONTAINED_RESOURCE_LIST; return ChildTypeEnum.CONTAINED_RESOURCE_LIST;
} }
} }

View File

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

View File

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

View File

@ -19,21 +19,25 @@
*/ */
package ca.uhn.fhir.context; 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; 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 { public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefinition {
private List<BaseRuntimeChildDefinition> myChildren; 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); super(theDef, theImplementingClass, theStandardType, theContext, theClassToElementDefinitions);
} }
@ -47,7 +51,9 @@ public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefini
} }
@Override @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); super.sealAndInitialize(theContext, theClassToElementDefinitions);
/* /*
@ -66,5 +72,4 @@ public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefini
myChildren = Collections.unmodifiableList(children); myChildren = Collections.unmodifiableList(children);
} }
} }

View File

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

View File

@ -35,7 +35,8 @@ import java.util.Map;
import static org.apache.commons.lang3.StringUtils.isBlank; 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 Class<?> myNativeType;
private BaseRuntimeElementDefinition<?> myProfileOf; private BaseRuntimeElementDefinition<?> myProfileOf;
@ -44,12 +45,14 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
private List<BaseRuntimeChildDefinition> myChildren; private List<BaseRuntimeChildDefinition> myChildren;
private RuntimeChildExt myRuntimeChildExt; 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); super(theDef.name(), theImplementingClass, theStandardType);
String resourceName = theDef.name(); String resourceName = theDef.name();
if (isBlank(resourceName)) { 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(); mySpecialization = theDef.isSpecialization();
@ -83,7 +86,8 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
Type rawType = superPt.getRawType(); Type rawType = superPt.getRawType();
if (rawType instanceof Class) { if (rawType instanceof Class) {
Class<?> rawClass = (Class<?>) rawType; 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]; Type typeVariable = superPt.getActualTypeArguments()[0];
if (typeVariable instanceof Class) { if (typeVariable instanceof Class) {
myNativeType = (Class<?>) typeVariable; myNativeType = (Class<?>) typeVariable;
@ -128,7 +132,9 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
} }
@Override @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); super.sealAndInitialize(theContext, theClassToElementDefinitions);
if (myProfileOfType != null) { if (myProfileOfType != null) {
@ -153,5 +159,4 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
myChildren.add(myRuntimeChildExt); myChildren.add(myRuntimeChildExt);
myChildren = Collections.unmodifiableList(myChildren); myChildren = Collections.unmodifiableList(myChildren);
} }
} }

View File

@ -19,15 +19,15 @@
*/ */
package ca.uhn.fhir.context; 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 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); super(theName, theImplementingClass, theStandardType);
} }
@ -37,8 +37,9 @@ public class RuntimePrimitiveDatatypeNarrativeDefinition extends BaseRuntimeEle
} }
@Override @Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { void sealAndInitialize(
FhirContext theContext,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
// nothing // nothing
} }
} }

View File

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

View File

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

View File

@ -48,9 +48,13 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
private final FhirVersionEnum myStructureVersion; private final FhirVersionEnum myStructureVersion;
private volatile RuntimeResourceDefinition myBaseDefinition; private volatile RuntimeResourceDefinition myBaseDefinition;
public RuntimeResourceDefinition(
FhirContext theContext,
public RuntimeResourceDefinition(FhirContext theContext, String theResourceName, Class<? extends IBaseResource> theClass, ResourceDef theResourceAnnotation, boolean theStandardType, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { String theResourceName,
Class<? extends IBaseResource> theClass,
ResourceDef theResourceAnnotation,
boolean theStandardType,
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super(theResourceName, theClass, theStandardType, theContext, theClassToElementDefinitions); super(theResourceName, theClass, theStandardType, theContext, theClassToElementDefinitions);
myContext = theContext; myContext = theContext;
myResourceProfile = theResourceAnnotation.profile(); myResourceProfile = theResourceAnnotation.profile();
@ -60,23 +64,35 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
try { try {
instance = theClass.getConstructor().newInstance(); instance = theClass.getConstructor().newInstance();
} catch (Exception e) { } 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(); myStructureVersion = instance.getStructureFhirVersionEnum();
if (myStructureVersion != theContext.getVersion().getVersion()) { 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: 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 ModelScanner
// TODO: also fix the TODO in RestfulServerUtils // TODO: also fix the TODO in RestfulServerUtils
// TODO: also fix the TODO in BaseParser // TODO: also fix the TODO in BaseParser
} else { } 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) { public void addSearchParam(RuntimeSearchParam theParam) {
myNameToSearchParam.put(theParam.getName(), theParam); myNameToSearchParam.put(theParam.getName(), theParam);
} }
@ -113,7 +129,8 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> Class<T> getImplementingClass(Class<T> theClass) { public <T> Class<T> getImplementingClass(Class<T> theClass) {
if (!theClass.isAssignableFrom(getImplementingClass())) { 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(); return (Class<T>) getImplementingClass();
} }
@ -176,7 +193,9 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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); super.sealAndInitialize(theContext, theClassToElementDefinitions);
myNameToSearchParam = Collections.unmodifiableMap(myNameToSearchParam); myNameToSearchParam = Collections.unmodifiableMap(myNameToSearchParam);
@ -202,7 +221,8 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
if (!compartmentNameToSearchParams.containsKey(nextCompartment)) { if (!compartmentNameToSearchParams.containsKey(nextCompartment)) {
compartmentNameToSearchParams.put(nextCompartment, new ArrayList<>()); compartmentNameToSearchParams.put(nextCompartment, new ArrayList<>());
} }
List<RuntimeSearchParam> searchParamsForCompartment = compartmentNameToSearchParams.get(nextCompartment); List<RuntimeSearchParam> searchParamsForCompartment =
compartmentNameToSearchParams.get(nextCompartment);
searchParamsForCompartment.add(next); searchParamsForCompartment.add(next);
/* /*
@ -247,11 +267,11 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
if (hasExtensions()) { if (hasExtensions()) {
if (IAnyResource.class.isAssignableFrom(getImplementingClass())) { if (IAnyResource.class.isAssignableFrom(getImplementingClass())) {
if (!IDomainResource.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) { private String massagePathForCompartmentSimilarity(String thePath) {
@ -286,5 +306,4 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
return retVal; return retVal;
} }
} }

View File

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

View File

@ -19,11 +19,11 @@
*/ */
package ca.uhn.fhir.context.api; package ca.uhn.fhir.context.api;
import java.util.Set;
import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.util.ResourceReferenceInfo; import ca.uhn.fhir.util.ResourceReferenceInfo;
import java.util.Set;
/** /**
* Created by Bill de Beaubien on 3/4/2015. * Created by Bill de Beaubien on 3/4/2015.
* *
@ -38,7 +38,8 @@ public enum BundleInclusionRule {
*/ */
BASED_ON_INCLUDES { BASED_ON_INCLUDES {
@Override @Override
public boolean shouldIncludeReferencedResource(ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) { public boolean shouldIncludeReferencedResource(
ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) {
return theReferenceInfo.matchesIncludeSet(theIncludes); return theReferenceInfo.matchesIncludeSet(theIncludes);
} }
}, },
@ -50,10 +51,12 @@ public enum BundleInclusionRule {
*/ */
BASED_ON_RESOURCE_PRESENCE { BASED_ON_RESOURCE_PRESENCE {
@Override @Override
public boolean shouldIncludeReferencedResource(ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) { public boolean shouldIncludeReferencedResource(
ResourceReferenceInfo theReferenceInfo, Set<Include> theIncludes) {
return true; 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 @Override
public String encode(String theString) { public String encode(String theString) {
try { 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(" ")) { if (theString.contains(" ")) {
return encodeStringWithSpaces(theString); return encodeStringWithSpaces(theString);
} }

View File

@ -22,7 +22,8 @@ package ca.uhn.fhir.context.phonetic;
import com.google.common.base.CharMatcher; import com.google.common.base.CharMatcher;
// Useful for numerical identifiers like phone numbers, address parts etc. // 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 { public class NumericEncoder implements IPhoneticEncoder {
@Override @Override
public String name() { public String name() {

View File

@ -39,8 +39,8 @@ public class ConceptValidationOptions {
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("inferSystem", myInferSystem) .append("inferSystem", myInferSystem)
.toString(); .toString();
} }
public boolean isValidateDisplay() { 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.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nullable;
/** /**
* This class returns the vocabulary that is shipped with the base FHIR * 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 { 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; private final FhirContext myCtx;
/** /**
* This module just delegates all calls to a concrete implementation which will * 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. * be in this field. Which implementation gets used depends on the FHIR version.
*/ */
private final IValidationSupport myDelegate; private final IValidationSupport myDelegate;
private final Runnable myFlush; 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 * make this hard to clean up. At some point it'd be nice to figure out
* a cleaner solution though. * a cleaner solution though.
*/ */
strategy = ReflectionUtil.newInstance("org.hl7.fhir.common.hapi.validation.support.DefaultProfileValidationSupportNpmStrategy", IValidationSupport.class, new Class[]{FhirContext.class}, new Object[]{theFhirContext}); strategy = ReflectionUtil.newInstance(
((ILockable)strategy).lock(); "org.hl7.fhir.common.hapi.validation.support.DefaultProfileValidationSupportNpmStrategy",
IValidationSupport.class,
new Class[] {FhirContext.class},
new Object[] {theFhirContext});
((ILockable) strategy).lock();
} else { } else {
strategy = new DefaultProfileValidationSupportBundleStrategy(theFhirContext); strategy = new DefaultProfileValidationSupportBundleStrategy(theFhirContext);
} }
@ -87,9 +93,9 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
myDelegate = strategy; myDelegate = strategy;
if (myDelegate instanceof DefaultProfileValidationSupportBundleStrategy) { if (myDelegate instanceof DefaultProfileValidationSupportBundleStrategy) {
myFlush = ()->((DefaultProfileValidationSupportBundleStrategy) myDelegate).flush(); myFlush = () -> ((DefaultProfileValidationSupportBundleStrategy) myDelegate).flush();
} else { } else {
myFlush = ()->{}; myFlush = () -> {};
} }
} }
@ -109,7 +115,6 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
return myDelegate.fetchAllNonBaseStructureDefinitions(); return myDelegate.fetchAllNonBaseStructureDefinitions();
} }
@Override @Override
public IBaseResource fetchCodeSystem(String theSystem) { public IBaseResource fetchCodeSystem(String theSystem) {
return myDelegate.fetchCodeSystem(theSystem); return myDelegate.fetchCodeSystem(theSystem);
@ -134,17 +139,18 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
return myCtx; return myCtx;
} }
@Nullable @Nullable
public static String getConformanceResourceUrl(FhirContext theFhirContext, IBaseResource theResource) { public static String getConformanceResourceUrl(FhirContext theFhirContext, IBaseResource theResource) {
String urlValueString = null; 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()) { if (urlValue.isPresent()) {
IPrimitiveType<?> urlValueType = (IPrimitiveType<?>) urlValue.get(); IPrimitiveType<?> urlValueType = (IPrimitiveType<?>) urlValue.get();
urlValueString = urlValueType.getValueAsString(); urlValueString = urlValueType.getValueAsString();
} }
return urlValueString; 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.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition; 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.i18n.Msg;
import ca.uhn.fhir.parser.LenientErrorHandler; import ca.uhn.fhir.parser.LenientErrorHandler;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.BundleUtil;
import ca.uhn.fhir.util.ClasspathUtil; import ca.uhn.fhir.util.ClasspathUtil;
import org.apache.commons.lang3.StringUtils; 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.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -46,8 +42,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import javax.annotation.Nullable;
import static org.apache.commons.lang3.StringUtils.isNotBlank; 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 = "http://hl7.org/fhir/StructureDefinition/";
private static final String URL_PREFIX_STRUCTURE_DEFINITION_BASE = "http://hl7.org/fhir/"; 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 final FhirContext myCtx;
private Map<String, IBaseResource> myCodeSystems; private Map<String, IBaseResource> myCodeSystems;
@ -73,7 +70,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
myCtx = theFhirContext; myCtx = theFhirContext;
} }
private void initializeResourceLists() { private void initializeResourceLists() {
if (myTerminologyResources != null && myStructureDefinitionResources != null) { if (myTerminologyResources != null && myStructureDefinitionResources != null) {
@ -90,7 +86,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml"); terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml");
Properties profileNameProperties = new Properties(); Properties profileNameProperties = new Properties();
try { 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()) { for (Object nextKey : profileNameProperties.keySet()) {
structureDefinitionResources.add("/org/hl7/fhir/instance/model/profile/" + nextKey); structureDefinitionResources.add("/org/hl7/fhir/instance/model/profile/" + nextKey);
} }
@ -148,7 +145,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
myStructureDefinitionResources = structureDefinitionResources; myStructureDefinitionResources = structureDefinitionResources;
} }
@Override @Override
public List<IBaseResource> fetchAllConformanceResources() { public List<IBaseResource> fetchAllConformanceResources() {
ArrayList<IBaseResource> retVal = new ArrayList<>(); ArrayList<IBaseResource> retVal = new ArrayList<>();
@ -169,7 +165,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
return null; return null;
} }
@Override @Override
public IBaseResource fetchCodeSystem(String theSystem) { public IBaseResource fetchCodeSystem(String theSystem) {
return fetchCodeSystemOrValueSet(theSystem, true); return fetchCodeSystemOrValueSet(theSystem, true);
@ -208,8 +203,12 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
candidate = valueSets.get(system); candidate = valueSets.get(system);
} }
if (candidate != null && isNotBlank(version) && !system.startsWith("http://hl7.org") && !system.startsWith("http://terminology.hl7.org")) { if (candidate != null
if (!StringUtils.equals(version, myCtx.newTerser().getSinglePrimitiveValueOrNull(candidate, "version"))) { && isNotBlank(version)
&& !system.startsWith("http://hl7.org")
&& !system.startsWith("http://terminology.hl7.org")) {
if (!StringUtils.equals(
version, myCtx.newTerser().getSinglePrimitiveValueOrNull(candidate, "version"))) {
candidate = null; candidate = null;
} }
} }
@ -239,7 +238,9 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
* search parameters eg "value.as(String)" when it should be * search parameters eg "value.as(String)" when it should be
* "value.as(string)". This lets us be a bit lenient about this. * "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()); String end = url.substring(URL_PREFIX_STRUCTURE_DEFINITION.length());
if (Character.isUpperCase(end.charAt(0))) { if (Character.isUpperCase(end.charAt(0))) {
String newEnd = Character.toLowerCase(end.charAt(0)) + end.substring(1); String newEnd = Character.toLowerCase(end.charAt(0)) + end.substring(1);
@ -251,9 +252,7 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
} }
} }
} }
} }
} }
return retVal; return retVal;
} }
@ -289,7 +288,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
return structureDefinitions; 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); ourLog.info("Loading CodeSystem/ValueSet from classpath: {}", theClasspath);
InputStream inputStream = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath); InputStream inputStream = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath);
InputStreamReader reader = null; InputStreamReader reader = null;
@ -319,8 +319,8 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
switch (myCtx.getVersion().getVersion()) { switch (myCtx.getVersion().getVersion()) {
case DSTU2: case DSTU2:
case DSTU2_HL7ORG: case DSTU2_HL7ORG:
IPrimitiveType<?> codeSystem = myCtx.newTerser()
IPrimitiveType<?> codeSystem = myCtx.newTerser().getSingleValueOrNull(next, "ValueSet.codeSystem.system", IPrimitiveType.class); .getSingleValueOrNull(next, "ValueSet.codeSystem.system", IPrimitiveType.class);
if (codeSystem != null && isNotBlank(codeSystem.getValueAsString())) { if (codeSystem != null && isNotBlank(codeSystem.getValueAsString())) {
theCodeSystems.put(codeSystem.getValueAsString(), next); theCodeSystems.put(codeSystem.getValueAsString(), next);
} }
@ -336,8 +336,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
break; break;
} }
} }
} }
} finally { } finally {
try { try {
@ -356,15 +354,14 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
// Load built-in system // Load built-in system
if (myCtx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { if (myCtx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
String storageCodeEnum = ClasspathUtil.loadResource("ca/uhn/fhir/context/support/HapiFhirStorageResponseCode.json"); String storageCodeEnum =
IBaseResource storageCodeCodeSystem = myCtx.newJsonParser().setParserErrorHandler(new LenientErrorHandler()).parseResource(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"); String url = myCtx.newTerser().getSinglePrimitiveValueOrNull(storageCodeCodeSystem, "url");
theCodeSystems.put(url, storageCodeCodeSystem); theCodeSystems.put(url, storageCodeCodeSystem);
} }
} }
private void loadStructureDefinitions(Map<String, IBaseResource> theCodeSystems, String theClasspath) { private void loadStructureDefinitions(Map<String, IBaseResource> theCodeSystems, String theClasspath) {
@ -372,7 +369,12 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
String packageUserData = null; String packageUserData = null;
if (myCtx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { 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)) { try (InputStream valueSetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath)) {
@ -389,7 +391,6 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
if (isNotBlank(url)) { if (isNotBlank(url)) {
theCodeSystems.put(url, next); theCodeSystems.put(url, next);
} }
} }
// This is used by the validator to determine which package a given SD came from. // 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) { if (packageUserData != null) {
next.setUserData("package", packageUserData); next.setUserData("package", packageUserData);
} }
} }
} }
} else { } else {
@ -426,5 +426,4 @@ class DefaultProfileValidationSupportBundleStrategy implements IValidationSuppor
ArrayList<IBaseResource> retVal = new ArrayList<>(theMap.values()); ArrayList<IBaseResource> retVal = new ArrayList<>(theMap.values());
return (List<T>) Collections.unmodifiableList(retVal); 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.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -43,6 +41,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; 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.defaultString;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ -80,7 +80,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
public interface IValidationSupport { public interface IValidationSupport {
String URL_PREFIX_VALUE_SET = "http://hl7.org/fhir/ValueSet/"; String URL_PREFIX_VALUE_SET = "http://hl7.org/fhir/ValueSet/";
/** /**
* Expands the given portion of a ValueSet * Expands the given portion of a ValueSet
* *
@ -91,7 +90,10 @@ public interface IValidationSupport {
* @return The expansion, or null * @return The expansion, or null
*/ */
@Nullable @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; return null;
} }
@ -107,11 +109,16 @@ public interface IValidationSupport {
* @since 6.0.0 * @since 6.0.0
*/ */
@Nullable @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"); Validate.notBlank(theValueSetUrlToExpand, "theValueSetUrlToExpand must not be null or blank");
IBaseResource valueSet = fetchValueSet(theValueSetUrlToExpand); IBaseResource valueSet = fetchValueSet(theValueSetUrlToExpand);
if (valueSet == null) { 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); return expandValueSet(theValidationSupportContext, theExpansionOptions, valueSet);
} }
@ -200,17 +207,14 @@ public interface IValidationSupport {
Validate.notBlank(theUri, "theUri must not be null or blank"); Validate.notBlank(theUri, "theUri must not be null or blank");
if (theClass == null) { if (theClass == null) {
Supplier<IBaseResource>[] sources = new Supplier[]{ Supplier<IBaseResource>[] sources = new Supplier[] {
() -> fetchStructureDefinition(theUri), () -> fetchStructureDefinition(theUri), () -> fetchValueSet(theUri), () -> fetchCodeSystem(theUri)
() -> fetchValueSet(theUri),
() -> fetchCodeSystem(theUri)
}; };
return (T) Arrays return (T) Arrays.stream(sources)
.stream(sources) .map(t -> t.get())
.map(t -> t.get()) .filter(t -> t != null)
.filter(t -> t != null) .findFirst()
.findFirst() .orElse(null);
.orElse(null);
} }
switch (getFhirContext().getResourceType(theClass)) { switch (getFhirContext().getResourceType(theClass)) {
@ -289,7 +293,13 @@ public interface IValidationSupport {
* @return Returns a validation result object * @return Returns a validation result object
*/ */
@Nullable @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; 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 * @return Returns a validation result object, or <code>null</code> if this validation support module can not handle this kind of request
*/ */
@Nullable @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; 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>. * @param theDisplayLanguage to filter out the designation by the display language. To return all designation, set this value to <code>null</code>.
*/ */
@Nullable @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; return null;
} }
@ -334,7 +354,8 @@ public interface IValidationSupport {
* @param theCode The code * @param theCode The code
*/ */
@Nullable @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); 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 * @return Returns null if this module does not know how to handle this request
*/ */
@Nullable @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; return null;
} }
@ -755,11 +781,13 @@ public interface IValidationSupport {
public void throwNotFoundIfAppropriate() { public void throwNotFoundIfAppropriate() {
if (isFound() == false) { 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); IBaseParameters retVal = ParametersUtil.newInstance(theContext);
if (isNotBlank(getCodeSystemDisplayName())) { if (isNotBlank(getCodeSystemDisplayName())) {
@ -775,10 +803,9 @@ public interface IValidationSupport {
Set<String> properties = Collections.emptySet(); Set<String> properties = Collections.emptySet();
if (theProperties != null) { if (theProperties != null) {
properties = theProperties properties = theProperties.stream()
.stream() .map(IPrimitiveType::getValueAsString)
.map(IPrimitiveType::getValueAsString) .collect(Collectors.toSet());
.collect(Collectors.toSet());
} }
for (IValidationSupport.BaseConceptProperty next : myProperties) { for (IValidationSupport.BaseConceptProperty next : myProperties) {
@ -797,7 +824,8 @@ public interface IValidationSupport {
ParametersUtil.addPartString(theContext, property, "value", prop.getValue()); ParametersUtil.addPartString(theContext, property, "value", prop.getValue());
} else if (next instanceof IValidationSupport.CodingConceptProperty) { } else if (next instanceof IValidationSupport.CodingConceptProperty) {
IValidationSupport.CodingConceptProperty prop = (IValidationSupport.CodingConceptProperty) next; 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 { } else {
throw new IllegalStateException(Msg.code(1739) + "Don't know how to handle " + next.getClass()); 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"); IBase property = ParametersUtil.addParameterToParameters(theContext, retVal, "designation");
ParametersUtil.addPartCode(theContext, property, "language", next.getLanguage()); 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()); ParametersUtil.addPartString(theContext, property, "value", next.getValue());
} }
} }
@ -819,13 +848,12 @@ public interface IValidationSupport {
public static LookupCodeResult notFound(String theSearchedForSystem, String theSearchedForCode) { public static LookupCodeResult notFound(String theSearchedForSystem, String theSearchedForCode) {
return new LookupCodeResult() return new LookupCodeResult()
.setFound(false) .setFound(false)
.setSearchedForSystem(theSearchedForSystem) .setSearchedForSystem(theSearchedForSystem)
.setSearchedForCode(theSearchedForCode); .setSearchedForCode(theSearchedForCode);
} }
} }
class TranslateCodeRequest { class TranslateCodeRequest {
private final String myTargetSystemUrl; private final String myTargetSystemUrl;
private final String myConceptMapUrl; private final String myConceptMapUrl;
@ -848,14 +876,14 @@ public interface IValidationSupport {
} }
public TranslateCodeRequest( public TranslateCodeRequest(
List<IBaseCoding> theCodings, List<IBaseCoding> theCodings,
String theTargetSystemUrl, String theTargetSystemUrl,
String theConceptMapUrl, String theConceptMapUrl,
String theConceptMapVersion, String theConceptMapVersion,
String theSourceValueSetUrl, String theSourceValueSetUrl,
String theTargetValueSetUrl, String theTargetValueSetUrl,
IIdType theResourceId, IIdType theResourceId,
boolean theReverse) { boolean theReverse) {
myCodings = theCodings; myCodings = theCodings;
myTargetSystemUrl = theTargetSystemUrl; myTargetSystemUrl = theTargetSystemUrl;
myConceptMapUrl = theConceptMapUrl; myConceptMapUrl = theConceptMapUrl;
@ -879,29 +907,29 @@ public interface IValidationSupport {
TranslateCodeRequest that = (TranslateCodeRequest) theO; TranslateCodeRequest that = (TranslateCodeRequest) theO;
return new EqualsBuilder() return new EqualsBuilder()
.append(myCodings, that.myCodings) .append(myCodings, that.myCodings)
.append(myTargetSystemUrl, that.myTargetSystemUrl) .append(myTargetSystemUrl, that.myTargetSystemUrl)
.append(myConceptMapUrl, that.myConceptMapUrl) .append(myConceptMapUrl, that.myConceptMapUrl)
.append(myConceptMapVersion, that.myConceptMapVersion) .append(myConceptMapVersion, that.myConceptMapVersion)
.append(mySourceValueSetUrl, that.mySourceValueSetUrl) .append(mySourceValueSetUrl, that.mySourceValueSetUrl)
.append(myTargetValueSetUrl, that.myTargetValueSetUrl) .append(myTargetValueSetUrl, that.myTargetValueSetUrl)
.append(myResourceId, that.myResourceId) .append(myResourceId, that.myResourceId)
.append(myReverse, that.myReverse) .append(myReverse, that.myReverse)
.isEquals(); .isEquals();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return new HashCodeBuilder(17, 37) return new HashCodeBuilder(17, 37)
.append(myCodings) .append(myCodings)
.append(myTargetSystemUrl) .append(myTargetSystemUrl)
.append(myConceptMapUrl) .append(myConceptMapUrl)
.append(myConceptMapVersion) .append(myConceptMapVersion)
.append(mySourceValueSetUrl) .append(mySourceValueSetUrl)
.append(myTargetValueSetUrl) .append(myTargetValueSetUrl)
.append(myResourceId) .append(myResourceId)
.append(myReverse) .append(myReverse)
.toHashCode(); .toHashCode();
} }
public List<IBaseCoding> getCodings() { public List<IBaseCoding> getCodings() {

View File

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

View File

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

View File

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

View File

@ -21,9 +21,9 @@ package ca.uhn.fhir.fhirpath;
import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBase;
import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nonnull;
public interface IFhirPath { public interface IFhirPath {
@ -47,13 +47,11 @@ public interface IFhirPath {
*/ */
<T extends IBase> Optional<T> evaluateFirst(IBase theInput, String thePath, Class<T> theReturnType); <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 * Parses the expression and throws an exception if it can not parse correctly
*/ */
void parse(String theExpression) throws Exception; void parse(String theExpression) throws Exception;
/** /**
* This method can be used optionally to supply an evaluation context for the * 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 * FHIRPath evaluator instance. The context can be used to supply data needed by

View File

@ -19,7 +19,4 @@
*/ */
package ca.uhn.fhir.i18n; 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.isNotBlank;
import static org.apache.commons.lang3.StringUtils.trim; 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 * 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") @SuppressWarnings("WeakerAccess")
public static final String UNKNOWN_I18N_KEY_MESSAGE = "!MESSAGE!"; public static final String UNKNOWN_I18N_KEY_MESSAGE = "!MESSAGE!";
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HapiLocalizer.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HapiLocalizer.class);
private static boolean ourFailOnMissingMessage; private static boolean ourFailOnMissingMessage;
private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<>(); private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<>();
@ -148,19 +147,18 @@ public class HapiLocalizer {
MessageFormat newMessageFormat(String theFormatString) { MessageFormat newMessageFormat(String theFormatString) {
StringBuilder pattern = new StringBuilder(theFormatString.trim()); 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) == '{') { if (pattern.charAt(i) == '{') {
char nextChar = pattern.charAt(i+1); char nextChar = pattern.charAt(i + 1);
if (nextChar >= '0' && nextChar <= '9') { if (nextChar >= '0' && nextChar <= '9') {
continue; continue;
} }
pattern.replace(i, i+1, "'{'"); pattern.replace(i, i + 1, "'{'");
int closeBraceIndex = pattern.indexOf("}", i); int closeBraceIndex = pattern.indexOf("}", i);
if (closeBraceIndex > 0) { if (closeBraceIndex > 0) {
i = closeBraceIndex; 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; return myLocale;
} }
/** /**
* This <b>global setting</b> causes the localizer to fail if any attempts * 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 * are made to retrieve a key that does not exist. This method is primarily for
* unit tests. * unit tests.
@ -191,5 +189,4 @@ public class HapiLocalizer {
public static String toKey(Class<?> theType, String theKey) { public static String toKey(Class<?> theType, String theKey) {
return theType.getName() + '.' + 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: * 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 * https://github.com/hapifhir/hapi-fhir/wiki/Bumping-Error-Code
*/ */
private Msg() {} private Msg() {}
public static String code(int theCode) { public static String code(int theCode) {

View File

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

View File

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

View File

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

View File

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

View File

@ -19,6 +19,4 @@
*/ */
package ca.uhn.fhir.interceptor.api; 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, IAnonymousInterceptor theInterceptor);
void registerAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor); void registerAnonymousInterceptor(Pointcut thePointcut, int theOrder, IAnonymousInterceptor theInterceptor);
} }

View File

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

View File

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

View File

@ -32,7 +32,8 @@ import org.apache.commons.lang3.Validate;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Optional; 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" * 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())); return findAnnotation(nextMethod, Hook.class).map(t -> new HookDescriptor(t.value(), t.order()));
} }
@Override @Override
@VisibleForTesting @VisibleForTesting
public void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor) { public void registerAnonymousInterceptor(Pointcut thePointcut, IAnonymousInterceptor theInterceptor) {
@ -70,7 +70,6 @@ public class InterceptorService extends BaseInterceptorService<Pointcut> impleme
registerAnonymousInterceptor(thePointcut, theInterceptor, invoker); registerAnonymousInterceptor(thePointcut, theInterceptor, invoker);
} }
private static class AnonymousLambdaInvoker extends BaseInvoker { private static class AnonymousLambdaInvoker extends BaseInvoker {
private final IAnonymousInterceptor myHook; private final IAnonymousInterceptor myHook;
private final Pointcut myPointcut; private final Pointcut myPointcut;
@ -87,6 +86,4 @@ public class InterceptorService extends BaseInterceptorService<Pointcut> impleme
return true; 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.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -39,6 +37,8 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; 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 { public class RequestPartitionId implements IModelJson {
private static final RequestPartitionId ALL_PARTITIONS = new RequestPartitionId(); 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") @JsonProperty("partitionDate")
private final LocalDate myPartitionDate; private final LocalDate myPartitionDate;
@JsonProperty("allPartitions") @JsonProperty("allPartitions")
private final boolean myAllPartitions; private final boolean myAllPartitions;
@JsonProperty("partitionIds") @JsonProperty("partitionIds")
private final List<Integer> myPartitionIds; private final List<Integer> myPartitionIds;
@JsonProperty("partitionNames") @JsonProperty("partitionNames")
private final List<String> myPartitionNames; private final List<String> myPartitionNames;
/** /**
* Constructor for a single partition * 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); myPartitionIds = toListOrNull(thePartitionId);
myPartitionNames = toListOrNull(thePartitionName); myPartitionNames = toListOrNull(thePartitionName);
myPartitionDate = thePartitionDate; myPartitionDate = thePartitionDate;
@ -70,7 +76,10 @@ public class RequestPartitionId implements IModelJson {
/** /**
* Constructor for a multiple partition * 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); myPartitionIds = toListOrNull(thePartitionId);
myPartitionNames = toListOrNull(thePartitionName); myPartitionNames = toListOrNull(thePartitionName);
myPartitionDate = thePartitionDate; myPartitionDate = thePartitionDate;
@ -147,11 +156,11 @@ public class RequestPartitionId implements IModelJson {
@Override @Override
public int hashCode() { public int hashCode() {
return new HashCodeBuilder(17, 37) return new HashCodeBuilder(17, 37)
.append(myPartitionDate) .append(myPartitionDate)
.append(myAllPartitions) .append(myAllPartitions)
.append(myPartitionIds) .append(myPartitionIds)
.append(myPartitionNames) .append(myPartitionNames)
.toHashCode(); .toHashCode();
} }
public String toJson() { public String toJson() {
@ -180,7 +189,9 @@ public class RequestPartitionId implements IModelJson {
if (isAllPartitions()) { if (isAllPartitions()) {
return false; 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) { public boolean hasPartitionId(Integer thePartitionId) {
@ -253,7 +264,8 @@ public class RequestPartitionId implements IModelJson {
} }
@Nonnull @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); return new RequestPartitionId(null, Collections.singletonList(thePartitionId), thePartitionDate);
} }
@ -263,7 +275,8 @@ public class RequestPartitionId implements IModelJson {
} }
@Nonnull @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); return new RequestPartitionId(null, toListOrNull(thePartitionIds), thePartitionDate);
} }
@ -278,7 +291,8 @@ public class RequestPartitionId implements IModelJson {
} }
@Nonnull @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); return new RequestPartitionId(thePartitionName, null, thePartitionDate);
} }
@ -293,17 +307,20 @@ public class RequestPartitionId implements IModelJson {
} }
@Nonnull @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); return new RequestPartitionId(thePartitionName, thePartitionId, null);
} }
@Nonnull @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); return new RequestPartitionId(thePartitionName, thePartitionId, thePartitionDate);
} }
@Nonnull @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); return new RequestPartitionId(thePartitionNames, thePartitionIds, thePartitionDate);
} }
@ -316,11 +333,9 @@ public class RequestPartitionId implements IModelJson {
String retVal = "(all)"; String retVal = "(all)";
if (!theRequestPartitionId.isAllPartitions()) { if (!theRequestPartitionId.isAllPartitions()) {
assert theRequestPartitionId.hasPartitionIds(); assert theRequestPartitionId.hasPartitionIds();
retVal = theRequestPartitionId retVal = theRequestPartitionId.getPartitionIds().stream()
.getPartitionIds() .map(t -> defaultIfNull(t, "null").toString())
.stream() .collect(Collectors.joining(" "));
.map(t -> defaultIfNull(t, "null").toString())
.collect(Collectors.joining(" "));
} }
return retVal; return retVal;
} }

View File

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

View File

@ -26,22 +26,42 @@ import org.hl7.fhir.instance.model.api.IBaseDatatype;
import java.util.*; import java.util.*;
public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredExtensions { public abstract class BaseElement implements /*IElement, */ ISupportsUndeclaredExtensions {
private static final long serialVersionUID = -3092659584634499332L; private static final long serialVersionUID = -3092659584634499332L;
private List<String> myFormatCommentsPost; private List<String> myFormatCommentsPost;
private List<String> myFormatCommentsPre; private List<String> myFormatCommentsPre;
private Map<String, Object> userData; private Map<String, Object> userData;
@Child(name = "extension", type = {ExtensionDt.class}, order = 0, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false) @Child(
@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.") 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; 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. * 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) @Child(
@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.") 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; private List<ExtensionDt> myUndeclaredModifierExtensions;
@Override @Override
@ -100,15 +120,13 @@ public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredEx
@Override @Override
public List<String> getFormatCommentsPost() { public List<String> getFormatCommentsPost() {
if (myFormatCommentsPost == null) if (myFormatCommentsPost == null) myFormatCommentsPost = new ArrayList<String>();
myFormatCommentsPost = new ArrayList<String>();
return myFormatCommentsPost; return myFormatCommentsPost;
} }
@Override @Override
public List<String> getFormatCommentsPre() { public List<String> getFormatCommentsPre() {
if (myFormatCommentsPre == null) if (myFormatCommentsPre == null) myFormatCommentsPre = new ArrayList<String>();
myFormatCommentsPre = new ArrayList<String>();
return myFormatCommentsPre; return myFormatCommentsPre;
} }
@ -142,13 +160,13 @@ public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredEx
@Override @Override
public boolean hasFormatComment() { public boolean hasFormatComment() {
return (myFormatCommentsPre != null && !myFormatCommentsPre.isEmpty()) || (myFormatCommentsPost != null && !myFormatCommentsPost.isEmpty()); return (myFormatCommentsPre != null && !myFormatCommentsPre.isEmpty())
|| (myFormatCommentsPost != null && !myFormatCommentsPost.isEmpty());
} }
@Override @Override
public Object getUserData(String name) { public Object getUserData(String name) {
if (userData == null) if (userData == null) return null;
return null;
return userData.get(name); return userData.get(name);
} }
@ -187,5 +205,4 @@ public abstract class BaseElement implements /*IElement, */ISupportsUndeclaredEx
} }
return true; return true;
} }
} }

View File

@ -83,8 +83,7 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
private static class LockedId extends IdDt { private static class LockedId extends IdDt {
@CoverageIgnore @CoverageIgnore
public LockedId() { public LockedId() {}
}
@CoverageIgnore @CoverageIgnore
public LockedId(String theElementSpecificId) { public LockedId(String theElementSpecificId) {
@ -94,15 +93,15 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId
@Override @Override
@CoverageIgnore @CoverageIgnore
public IdDt setValue(String theValue) throws DataFormatException { 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 @Override
@CoverageIgnore @CoverageIgnore
public void setValueAsString(String theValue) throws DataFormatException { 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,18 +19,18 @@
*/ */
package ca.uhn.fhir.model.api; 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.Externalizable;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import org.apache.commons.lang3.StringUtils; public abstract class BasePrimitive<T> extends BaseIdentifiableElement
import org.apache.commons.lang3.builder.EqualsBuilder; implements IPrimitiveDatatype<T>, Externalizable {
import org.apache.commons.lang3.builder.HashCodeBuilder;
import ca.uhn.fhir.parser.DataFormatException;
public abstract class BasePrimitive<T> extends BaseIdentifiableElement implements IPrimitiveDatatype<T>, Externalizable {
private T myCoercedValue; private T myCoercedValue;
private String myStringValue; private String myStringValue;
@ -123,7 +123,7 @@ public abstract class BasePrimitive<T> extends BaseIdentifiableElement implement
myStringValue = null; myStringValue = null;
} else { } else {
// NB this might be null // 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() { public boolean hasValue() {
return !StringUtils.isBlank(getValueAsString()); return !StringUtils.isBlank(getValueAsString());
} }
} }

View File

@ -33,20 +33,20 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@DatatypeDef(name = "Extension") @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 static final long serialVersionUID = 6399491332783085935L;
private boolean myModifier; 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; private StringDt myUrl;
@Child(name = "value", type = IDatatype.class, order = 1, min = 0, max = 1) @Child(name = "value", type = IDatatype.class, order = 1, min = 0, max = 1)
private IBaseDatatype myValue; private IBaseDatatype myValue;
public ExtensionDt() { public ExtensionDt() {}
}
public ExtensionDt(boolean theIsModifier) { public ExtensionDt(boolean theIsModifier) {
myModifier = theIsModifier; myModifier = theIsModifier;
@ -65,7 +65,7 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
myModifier = theIsModifier; myModifier = theIsModifier;
myUrl = new StringDt(theUrl); myUrl = new StringDt(theUrl);
myValue=theValue; myValue = theValue;
} }
/** /**
@ -115,7 +115,9 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
*/ */
public IPrimitiveDatatype<?> getValueAsPrimitive() { public IPrimitiveDatatype<?> getValueAsPrimitive() {
if (!(getValue() instanceof IPrimitiveDatatype)) { 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(); return (IPrimitiveDatatype<?>) getValue();
} }
@ -151,7 +153,7 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
} }
@Override @Override
@Deprecated //override deprecated method @Deprecated // override deprecated method
public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) { public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
return new ArrayList<T>(); return new ArrayList<T>();
} }
@ -168,7 +170,4 @@ public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDa
retVal.append("value", getValue()); retVal.append("value", getValue());
return retVal.build(); return retVal.build();
} }
} }

View File

@ -21,6 +21,4 @@ package ca.uhn.fhir.model.api;
import java.io.Serializable; 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 { public interface ICodingEnum {
String getCode(); 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; import org.hl7.fhir.instance.model.api.ICompositeType;
public interface ICompositeDatatype extends IDatatype, ICompositeElement, ICompositeType {}
public interface ICompositeDatatype extends IDatatype, ICompositeElement, ICompositeType {
}

View File

@ -36,7 +36,5 @@ public interface ICompositeElement extends IElement {
* a discussion about this. * a discussion about this.
*/ */
@Deprecated @Deprecated
<T extends IElement> <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType);
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; 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; import org.hl7.fhir.instance.model.api.IBase;
public interface IElement extends IBase {}
public interface IElement extends IBase {
}

View File

@ -19,14 +19,13 @@
*/ */
package ca.uhn.fhir.model.api; package ca.uhn.fhir.model.api;
import java.io.InputStream; import ca.uhn.fhir.context.*;
import java.util.Date;
import ca.uhn.fhir.fhirpath.IFhirPath; import ca.uhn.fhir.fhirpath.IFhirPath;
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
import org.hl7.fhir.instance.model.api.*; import org.hl7.fhir.instance.model.api.*;
import ca.uhn.fhir.context.*; import java.io.InputStream;
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory; import java.util.Date;
/** /**
* Each structure version JAR will have an implementation of this interface. * Each structure version JAR will have an implementation of this interface.
@ -65,5 +64,4 @@ public interface IFhirVersion {
* JAR is on the classpath. Otherwise it will result in a {@link ClassNotFoundException} * JAR is on the classpath. Otherwise it will result in a {@link ClassNotFoundException}
*/ */
Object getServerVersion(); Object getServerVersion();
} }

View File

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

View File

@ -23,6 +23,10 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL) @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) @JsonAutoDetect(
public interface IModelJson { 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; package ca.uhn.fhir.model.api;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.DataFormatException;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
public interface IPrimitiveDatatype<T> extends IDatatype, IPrimitiveType<T> { public interface IPrimitiveDatatype<T> extends IDatatype, IPrimitiveType<T> {

View File

@ -19,14 +19,13 @@
*/ */
package ca.uhn.fhir.model.api; package ca.uhn.fhir.model.api;
import java.io.Serializable;
import java.util.List;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.QualifiedParamList;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import java.io.Serializable;
import java.util.List;
public interface IQueryParameterAnd<T extends IQueryParameterOr<?>> extends Serializable { public interface IQueryParameterAnd<T extends IQueryParameterOr<?>> extends Serializable {
/** /**
@ -39,7 +38,8 @@ public interface IQueryParameterAnd<T extends IQueryParameterOr<?>> extends Seri
* @param theContext TODO * @param theContext TODO
* @param theParamName 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;
/** /**
* *
@ -50,6 +50,4 @@ public interface IQueryParameterAnd<T extends IQueryParameterOr<?>> extends Seri
* </p> * </p>
*/ */
List<T> getValuesAsQueryTokens(); List<T> getValuesAsQueryTokens();
} }

View File

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

View File

@ -19,10 +19,10 @@
*/ */
package ca.uhn.fhir.model.api; package ca.uhn.fhir.model.api;
import java.io.Serializable;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import java.io.Serializable;
public interface IQueryParameterType extends Serializable { public interface IQueryParameterType extends Serializable {
/** /**
@ -76,5 +76,4 @@ public interface IQueryParameterType extends Serializable {
* @return Returns a reference to <code>this</code> for easier method chaining * @return Returns a reference to <code>this</code> for easier method chaining
*/ */
IQueryParameterType setMissing(Boolean theMissing); IQueryParameterType setMissing(Boolean theMissing);
} }

View File

@ -19,14 +19,13 @@
*/ */
package ca.uhn.fhir.model.api; 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.api.annotation.ResourceDef;
import ca.uhn.fhir.model.base.composite.BaseContainedDt; import ca.uhn.fhir.model.base.composite.BaseContainedDt;
import ca.uhn.fhir.model.base.composite.BaseNarrativeDt; import ca.uhn.fhir.model.base.composite.BaseNarrativeDt;
import ca.uhn.fhir.model.base.resource.ResourceMetadataMap; import ca.uhn.fhir.model.base.resource.ResourceMetadataMap;
import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.IdDt; 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. * 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.
@ -122,5 +121,4 @@ public interface IResource extends ICompositeElement, org.hl7.fhir.instance.mode
* The map must not be null * The map must not be null
*/ */
void setResourceMetadata(ResourceMetadataMap theMap); void setResourceMetadata(ResourceMetadataMap theMap);
} }

View File

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

View File

@ -84,5 +84,4 @@ public interface ISupportsUndeclaredExtensions extends IElement {
* @see #getUndeclaredExtensions() To return a mutable list which may be used to remove extensions * @see #getUndeclaredExtensions() To return a mutable list which may be used to remove extensions
*/ */
ExtensionDt addUndeclaredExtension(boolean theIsModifier, String theUrl); ExtensionDt addUndeclaredExtension(boolean theIsModifier, String theUrl);
} }

View File

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

View File

@ -147,7 +147,6 @@ public class Include implements Serializable {
*/ */
public String getParamTargetType() { public String getParamTargetType() {
return myParamTargetType; return myParamTargetType;
} }
public String getValue() { public String getValue() {
@ -209,7 +208,7 @@ public class Include implements Serializable {
paramName = value.substring(firstColon + 1); paramName = value.substring(firstColon + 1);
paramTargetType = null; paramTargetType = null;
} else { } else {
paramName = value.substring(firstColon + 1, secondColon); paramName = value.substring(firstColon + 1, secondColon);
paramTargetType = value.substring(secondColon + 1); paramTargetType = value.substring(secondColon + 1);
} }
} }
@ -218,7 +217,6 @@ public class Include implements Serializable {
myParamName = paramName; myParamName = paramName;
myParamTargetType = paramTargetType; myParamTargetType = paramTargetType;
myValue = theValue; myValue = theValue;
} }
/** /**
@ -274,7 +272,8 @@ public class Include implements Serializable {
String paramType = getParamType(); String paramType = getParamType();
String paramName = getParamName(); String paramName = getParamName();
if (isBlank(paramType) || isBlank(paramName)) { 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(paramType);
b.append(":"); b.append(":");
@ -287,5 +286,4 @@ public class Include implements Serializable {
Include retVal = new Include(b.toString(), myIterate, myImmutable); Include retVal = new Include(b.toString(), myIterate, myImmutable);
return retVal; 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> * Values for this key are of type <b>{@link InstantDt}</b>
* </p> * </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. * 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 * 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> * Values for this key are of type <b>{@link BundleEntrySearchModeEnum}</b>
* </p> * </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 * 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 * 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> * Values for this key are of type <b>{@link BundleEntryTransactionMethodEnum}</b>
* </p> * </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. * The value for this key represents a {@link List} of profile IDs that this resource claims to conform to.
* <p> * <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. * 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> * </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. * 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> * <p>
@ -114,10 +114,11 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* *
* @see InstantDt * @see InstantDt
*/ */
public static final ResourceMetadataKeyEnum<InstantDt> PUBLISHED = new ResourceMetadataKeyEnum<>("PUBLISHED", InstantDt.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) {
}; 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 * The value for this key is the list of tags associated with this resource
* <p> * <p>
@ -126,8 +127,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* *
* @see TagList * @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 * 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.) * case of methods that return a single resource (read, vread, etc.)
@ -137,8 +138,8 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
* *
* @see InstantDt * @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. * The value for this key is the version ID of the resource object.
* <p> * <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 The {@link IResource#getId()} resource ID will now be populated with the version ID via the {@link IdDt#getVersionIdPart()} method
*/ */
@Deprecated @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. * The value for this key is the version ID of the resource object.
* <p> * <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 The {@link IResource#getId()} resource ID will now be populated with the version ID via the {@link IdDt#getVersionIdPart()} method
*/ */
@Deprecated @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 static final long serialVersionUID = 1L;
private final String myValue; private final String myValue;
private final Class<?> myType; private final Class<?> myType;
@ -180,9 +182,10 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
} }
if (retVal != null && !myType.isAssignableFrom(retVal.getClass())) { if (retVal != null && !myType.isAssignableFrom(retVal.getClass())) {
throw new InternalErrorException(Msg.code(1890) + "Found an object of type '" + retVal.getClass().getCanonicalName() throw new InternalErrorException(Msg.code(1890) + "Found an object of type '"
+ "' in resource metadata for key " + this.name() + " - Expected " + retVal.getClass().getCanonicalName()
+ myType.getCanonicalName()); + "' in resource metadata for key " + this.name() + " - Expected "
+ myType.getCanonicalName());
} }
//noinspection unchecked //noinspection unchecked
@ -191,9 +194,10 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
public void put(IBaseResource theResource, T theValue) { public void put(IBaseResource theResource, T theValue) {
if (theValue != null && !myType.isAssignableFrom(theValue.getClass())) { if (theValue != null && !myType.isAssignableFrom(theValue.getClass())) {
throw new InternalErrorException(Msg.code(1891) + "Can not put object of type '" + theValue.getClass().getCanonicalName() throw new InternalErrorException(Msg.code(1891) + "Can not put object of type '"
+ "' in resource metadata for key " + this.name() + " - Expected " + theValue.getClass().getCanonicalName()
+ myType.getCanonicalName()); + "' in resource metadata for key " + this.name() + " - Expected "
+ myType.getCanonicalName());
} }
if (theResource instanceof IAnyResource) { if (theResource instanceof IAnyResource) {
@ -205,12 +209,9 @@ public abstract class ResourceMetadataKeyEnum<T> implements Serializable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null) return false;
if (obj == null) if (getClass() != obj.getClass()) return false;
return false;
if (getClass() != obj.getClass())
return false;
ResourceMetadataKeyEnum<?> other = (ResourceMetadataKeyEnum<?>) obj; ResourceMetadataKeyEnum<?> other = (ResourceMetadataKeyEnum<?>) obj;
if (myValue == null) { if (myValue == null) {
return other.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. * This is used in CRUD response OperationOutcome resources.
*/ */
public enum StorageResponseCodeEnum implements ICodingEnum { public enum StorageResponseCodeEnum implements ICodingEnum {
SUCCESSFUL_CREATE("Create succeeded."), SUCCESSFUL_CREATE("Create succeeded."),
SUCCESSFUL_CREATE_NO_CONDITIONAL_MATCH("Conditional create succeeded: no existing resource matched the conditional URL."), SUCCESSFUL_CREATE_NO_CONDITIONAL_MATCH(
SUCCESSFUL_CREATE_WITH_CONDITIONAL_MATCH("Conditional create succeeded: an existing resource matched the conditional URL so no action was taken."), "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("Update succeeded."),
SUCCESSFUL_UPDATE_AS_CREATE("Update as create 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_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_NO_CONDITIONAL_MATCH(
SUCCESSFUL_UPDATE_WITH_CONDITIONAL_MATCH("Conditional update succeeded: an existing resource matched the conditional URL and was updated."), "Conditional update succeeded: no existing resource matched the conditional URL so a new resource was created."),
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_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("Delete succeeded."),
SUCCESSFUL_DELETE_ALREADY_DELETED("Delete succeeded: Resource was already deleted so no action was taken."), 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."), 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_PATCH_NO_CHANGE("Patch succeeded: No changes were detected so no action was taken."),
SUCCESSFUL_CONDITIONAL_PATCH("Conditional patch succeeded."), 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"; public static final String SYSTEM = "https://hapifhir.io/fhir/CodeSystem/hapi-fhir-storage-response-code";

View File

@ -61,8 +61,7 @@ public class Tag extends BaseElement implements IElement, IBaseCoding {
private String myVersion; private String myVersion;
private Boolean myUserSelected; private Boolean myUserSelected;
public Tag() { public Tag() {}
}
/** /**
* @deprecated There is no reason to create a tag with a term and not a scheme, so this constructor will be removed * @deprecated There is no reason to create a tag with a term and not a scheme, so this constructor will be removed
@ -93,7 +92,6 @@ public class Tag extends BaseElement implements IElement, IBaseCoding {
myLabel = theLabel; myLabel = theLabel;
} }
public String getLabel() { public String getLabel() {
return myLabel; return myLabel;
} }
@ -108,19 +106,15 @@ public class Tag extends BaseElement implements IElement, IBaseCoding {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null) return false;
if (obj == null) if (getClass() != obj.getClass()) return false;
return false;
if (getClass() != obj.getClass())
return false;
Tag other = (Tag) obj; Tag other = (Tag) obj;
return return Objects.equals(myScheme, other.myScheme)
Objects.equals(myScheme, other.myScheme) && && Objects.equals(myTerm, other.myTerm)
Objects.equals(myTerm, other.myTerm) && && Objects.equals(myVersion, other.myVersion)
Objects.equals(myVersion, other.myVersion) && && Objects.equals(myUserSelected, other.myUserSelected);
Objects.equals(myUserSelected, other.myUserSelected);
} }
@Override @Override
@ -211,7 +205,9 @@ public class Tag extends BaseElement implements IElement, IBaseCoding {
} }
@Override @Override
public String getVersion() { return myVersion; } public String getVersion() {
return myVersion;
}
@Override @Override
public IBaseCoding setVersion(String theVersion) { public IBaseCoding setVersion(String theVersion) {
@ -220,9 +216,13 @@ public class Tag extends BaseElement implements IElement, IBaseCoding {
} }
@Override @Override
public boolean getUserSelected() { return myUserSelected != null && myUserSelected; } public boolean getUserSelected() {
return myUserSelected != null && myUserSelected;
}
public Boolean getUserSelectedBoolean() { return myUserSelected; } public Boolean getUserSelectedBoolean() {
return myUserSelected;
}
@Override @Override
public IBaseCoding setUserSelected(boolean theUserSelected) { public IBaseCoding setUserSelected(boolean theUserSelected) {
@ -233,5 +233,4 @@ public class Tag extends BaseElement implements IElement, IBaseCoding {
public void setUserSelectedBoolean(Boolean theUserSelected) { public void setUserSelectedBoolean(Boolean theUserSelected) {
myUserSelected = theUserSelected; myUserSelected = theUserSelected;
} }
} }

View File

@ -153,18 +153,13 @@ public class TagList implements Set<Tag>, Serializable, IBase {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null) return false;
if (obj == null) if (getClass() != obj.getClass()) return false;
return false;
if (getClass() != obj.getClass())
return false;
TagList other = (TagList) obj; TagList other = (TagList) obj;
if (myTagSet == null) { if (myTagSet == null) {
if (other.myTagSet != null) if (other.myTagSet != null) return false;
return false; } else if (!myTagSet.equals(other.myTagSet)) return false;
} else if (!myTagSet.equals(other.myTagSet))
return false;
return true; return true;
} }
@ -290,5 +285,4 @@ public class TagList implements Set<Tag>, Serializable, IBase {
public void setUserData(String theName, Object theValue) { public void setUserData(String theName, Object theValue) {
throw new UnsupportedOperationException(Msg.code(1898)); throw new UnsupportedOperationException(Msg.code(1898));
} }
} }

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