Merge remote-tracking branch 'origin/master' into hl7org_structs

This commit is contained in:
James Agnew 2014-12-10 11:09:44 -05:00
commit 463fe249e6
15 changed files with 320 additions and 35 deletions

View File

@ -223,6 +223,13 @@
</profile>
<profile>
<id>ANDROID</id>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId>
<version>0.8-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@ -238,6 +245,18 @@
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<artifactSet>
<includes>
<!--
<include>javax.json:javax.json-api</include>
-->
<include>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu</include>
<include>org.glassfish:javax.json</include>
<include>org.codehaus.woodstox:woodstox-core-asl</include>
<include>javax.xml.stream:stax-api</include>
<include>org.codehaus.woodstox:stax2-api</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>javax.xml.stream</pattern>

View File

@ -137,7 +137,7 @@ public abstract class BaseRuntimeElementDefinition<T extends IElement> {
for (RuntimeChildDeclaredExtensionDefinition next : myExtensions) {
String extUrl = next.getExtensionUrl();
if (myUrlToExtension.containsKey(extUrl)) {
throw new ConfigurationException("Duplicate extension URL: " + extUrl);
throw new ConfigurationException("Duplicate extension URL[" + extUrl + "] in Element[" + getName() + "]");
} else {
myUrlToExtension.put(extUrl, next);
}

View File

@ -294,7 +294,7 @@ class ModelScanner {
}
if (blockDefinition == null && datatypeDefinition == null && resourceDefinition == null) {
throw new ConfigurationException("Resource type does not contain any valid HAPI-FHIR annotations: " + theClass.getCanonicalName());
throw new ConfigurationException("Resource class[" + theClass.getName() + "] does not contain any valid HAPI-FHIR annotations");
}
}

View File

@ -104,24 +104,20 @@ public abstract class BaseHumanNameDt extends BaseIdentifiableElement {
}
/**
* Gets the value(s) for <b>text</b> (Text representation of the full name).
* creating it if it does
* not exist. Will not return <code>null</code>.
* Gets the value(s) for <b>text</b> (Text representation of the full name). creating it if it does not exist. Will not return <code>null</code>.
*
* <p>
* <b>Definition:</b>
* A full text representation of the name
* </p>
* <p>
* <b>Definition:</b> A full text representation of the name
* </p>
*/
public abstract StringDt getText() ;
public abstract StringDt getTextElement();
/**
* Sets the value(s) for <b>text</b> (Text representation of the full name)
*
* <p>
* <b>Definition:</b>
* A full text representation of the name
* </p>
* <p>
* <b>Definition:</b> A full text representation of the name
* </p>
*/
public abstract BaseHumanNameDt setText(StringDt theValue);
@ -133,14 +129,25 @@ public abstract class BaseHumanNameDt extends BaseIdentifiableElement {
return b.toString();
}
public String getNameAsSingleString(){
/**
* Returns all of the components of the name (prefix, given, family, suffix) as a
* single string with a single spaced string separating each part.
* <p>
* If none of the parts are populated, returns the {@link #getTextElement() text}
* element value instead.
* </p>
*/
public String getNameAsSingleString() {
List<StringDt> nameParts = new ArrayList<StringDt>();
nameParts.addAll(getPrefix());
nameParts.addAll(getGiven());
nameParts.addAll(getFamily());
nameParts.addAll(getSuffix());
if(nameParts.size() > 0) return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(nameParts);
else return getText().getValue();
if (nameParts.size() > 0) {
return ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated(nameParts);
} else {
return getTextElement().getValue();
}
}
}

View File

@ -41,6 +41,7 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import ca.uhn.fhir.util.VersionUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.exception.ExceptionUtils;
@ -50,6 +51,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
@ -723,16 +725,19 @@ public class RestfulServer extends HttpServlet {
Collection<IResourceProvider> resourceProvider = getResourceProviders();
if (resourceProvider != null) {
Map<Class<? extends IResource>, IResourceProvider> typeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider>();
Map<String, IResourceProvider> typeToProvider = new HashMap<String, IResourceProvider>();
for (IResourceProvider nextProvider : resourceProvider) {
Class<? extends IResource> resourceType = nextProvider.getResourceType();
if (resourceType == null) {
throw new NullPointerException("getResourceType() on class '" + nextProvider.getClass().getCanonicalName() + "' returned null");
}
if (typeToProvider.containsKey(resourceType)) {
throw new ServletException("Multiple providers for type: " + resourceType.getCanonicalName());
String resourceName = myFhirContext.getResourceDefinition(resourceType).getName();
if (typeToProvider.containsKey(resourceName)) {
throw new ServletException("Multiple resource providers return resource type[" + resourceName + "]: First[" + typeToProvider.get(resourceName).getClass().getCanonicalName() + "] and Second[" + nextProvider.getClass().getCanonicalName() + "]");
}
typeToProvider.put(resourceType, nextProvider);
typeToProvider.put(resourceName, nextProvider);
providedResourceScanner.scanForProvidedResources(nextProvider);
}
ourLog.info("Got {} resource providers", typeToProvider.size());

View File

@ -33,6 +33,7 @@ import java.util.Map;
import ca.uhn.fhir.context.*;
import ca.uhn.fhir.model.api.ICompositeDatatype;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
@ -57,7 +58,7 @@ import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
public class FhirDstu1 implements IFhirVersion {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirDstu1.class);
private Map<RuntimeChildDeclaredExtensionDefinition, String> myExtensionDefToCode = new HashMap<RuntimeChildDeclaredExtensionDefinition, String>();
// private Map<RuntimeChildDeclaredExtensionDefinition, String> myExtensionDefToCode = new HashMap<RuntimeChildDeclaredExtensionDefinition, String>();
private String myId;
@Override
@ -158,7 +159,7 @@ public class FhirDstu1 implements IFhirVersion {
String expectedPath = StringUtils.join(path, '.');
ourLog.info("Filling profile for: {} - Path: {}", expectedPath);
ourLog.debug("Filling profile for: {} - Path: {}", expectedPath);
String name = def.getName();
if (!expectedPath.equals(name)) {
path.pollLast();
@ -267,11 +268,12 @@ public class FhirDstu1 implements IFhirVersion {
return retVal;
}
private void scanForExtensions(Profile theProfile, BaseRuntimeElementDefinition<?> def) {
private Map<RuntimeChildDeclaredExtensionDefinition, String> scanForExtensions(Profile theProfile, BaseRuntimeElementDefinition<?> def) {
BaseRuntimeElementCompositeDefinition<?> cdef = ((BaseRuntimeElementCompositeDefinition<?>) def);
Map<RuntimeChildDeclaredExtensionDefinition, String> extensionDefToCode = new HashMap<RuntimeChildDeclaredExtensionDefinition, String>();
for (RuntimeChildDeclaredExtensionDefinition nextChild : cdef.getExtensions()) {
if (myExtensionDefToCode.containsKey(nextChild)) {
if (extensionDefToCode.containsKey(nextChild)) {
continue;
}
@ -288,10 +290,10 @@ public class FhirDstu1 implements IFhirVersion {
}
defn.setCode(code);
if (myExtensionDefToCode.values().contains(code)) {
if (extensionDefToCode.values().contains(code)) {
throw new IllegalStateException("Duplicate extension code: " + code);
}
myExtensionDefToCode.put(nextChild, code);
extensionDefToCode.put(nextChild, code);
if (nextChild.getChildType() != null && IPrimitiveDatatype.class.isAssignableFrom(nextChild.getChildType())) {
RuntimePrimitiveDatatypeDefinition pdef = (RuntimePrimitiveDatatypeDefinition) nextChild.getSingleChildOrThrow();
@ -306,11 +308,13 @@ public class FhirDstu1 implements IFhirVersion {
for (RuntimeChildDeclaredExtensionDefinition nextChildExt : pdef.getExtensions()) {
StructureElementDefinitionType type = defn.getDefinition().addType();
type.setCode(DataTypeEnum.EXTENSION);
type.setProfile("#" + myExtensionDefToCode.get(nextChildExt));
type.setProfile("#" + extensionDefToCode.get(nextChildExt));
}
}
}
return extensionDefToCode;
}
@Override

View File

@ -0,0 +1,82 @@
package ca.uhn.fhir.context;
import junit.framework.TestCase;
import org.junit.Test;
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.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ProvidesResources;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.resource.Profile;
import ca.uhn.fhir.model.primitive.StringDt;
/**
* Created by Bill de Beaubien on 12/10/2014.
*/
public class DuplicateExtensionTest extends TestCase {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DuplicateExtensionTest.class);
@Test
public void testScannerShouldAddProvidedResources() {
FhirContext ctx = new FhirContext();
RuntimeResourceDefinition patientDef = ctx.getResourceDefinition(CustomPatient.class);
Profile profile = (Profile) patientDef.toProfile();
String res = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(profile);
ourLog.info(res);
RuntimeResourceDefinition observationDef = ctx.getResourceDefinition(CustomObservation.class);
profile = (Profile) observationDef.toProfile();
}
@ResourceDef(name = "Observation", id = "CustomObservation")
class CustomObservation extends Observation {
@Child(name = "idExt", order = 0)
@Extension(url = "http://foo.org#id", definedLocally = true, isModifier = false)
@Description(shortDefinition = "Contains the id of the resource")
private StringDt myIdExt;
public StringDt getIdExt() {
if (myIdExt == null) {
myIdExt = new StringDt();
}
return myIdExt;
}
public void setIdExt(StringDt theIdExt) {
myIdExt = theIdExt;
}
}
@ProvidesResources(resources = CustomObservation.class)
class CustomObservationProvider {
}
@ResourceDef(name = "Patient", id = "CustomPatient")
class CustomPatient extends Patient {
@Child(name = "idExt", order = 0)
@Extension(url = "http://foo.org#id", definedLocally = true, isModifier = false)
@Description(shortDefinition = "Contains the id of the resource")
private StringDt myIdExt;
public StringDt getIdExt() {
if (myIdExt == null) {
myIdExt = new StringDt();
}
return myIdExt;
}
public void setIdExt(StringDt theIdExt) {
myIdExt = theIdExt;
}
}
@ProvidesResources(resources = CustomPatient.class)
class CustomPatientProvider {
}
}

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
@ -10,8 +11,13 @@ import org.hamcrest.core.StringContains;
import org.junit.Test;
import ca.uhn.fhir.model.api.BaseResource;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.dstu.composite.ContainedDt;
import ca.uhn.fhir.model.dstu.composite.NarrativeDt;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
@ -62,6 +68,21 @@ public class ServerInvalidDefinitionTest {
}
}
@Test
public void testMultipleResourceProviderForSameType() {
RestfulServer srv = new RestfulServer();
srv.setResourceProviders(new PatientResourceProvider1(), new PatientResourceProvider2());
try {
srv.init();
fail();
} catch (ServletException e) {
assertThat(e.getCause().toString(), StringContains.containsString("[Patient]"));
assertThat(e.getCause().toString(), StringContains.containsString("PatientResourceProvider1]"));
assertThat(e.getCause().toString(), StringContains.containsString("PatientResourceProvider2]"));
}
}
@Test
public void testSearchWithId() {
RestfulServer srv = new RestfulServer();
@ -76,6 +97,19 @@ public class ServerInvalidDefinitionTest {
}
}
@Test
public void testProviderWithNonResourceType() {
RestfulServer srv = new RestfulServer();
srv.setResourceProviders(new ProviderWithNonResourceType());
try {
srv.init();
fail();
} catch (ServletException e) {
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
assertThat(e.getCause().toString(), StringContains.containsString("does not contain any valid HAPI-FHIR annotations"));
}
}
/**
* Normal, should initialize properly
*/
@ -128,6 +162,74 @@ public class ServerInvalidDefinitionTest {
}
public static class ProviderWithNonResourceType implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return new IResource() {
@Override
public boolean isEmpty() {
return false;
}
@Override
public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
return null;
}
@Override
public void setResourceMetadata(Map<ResourceMetadataKeyEnum<?>, Object> theMap) {
}
@Override
public void setLanguage(CodeDt theLanguage) {
}
@Override
public void setId(IdDt theId) {
}
@Override
public NarrativeDt getText() {
return null;
}
@Override
public String getResourceName() {
return null;
}
@Override
public Map<ResourceMetadataKeyEnum<?>, Object> getResourceMetadata() {
return null;
}
@Override
public CodeDt getLanguage() {
return null;
}
@Override
public IdDt getId() {
return null;
}
@Override
public ContainedDt getContained() {
return null;
}
}.getClass();
}
@Search
public List<Patient> read(@IdParam IdDt theId, @RequiredParam(name = "aaa") StringParam theParam) {
return null;
}
}
public static class InvalidSpecialParameterNameResourceProvider implements IResourceProvider {
@Override
@ -156,4 +258,32 @@ public class ServerInvalidDefinitionTest {
}
public static class PatientResourceProvider1 implements IResourceProvider {
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
@Read
public Patient read(@IdParam IdDt theId) {
return null;
}
}
public static class PatientResourceProvider2 implements IResourceProvider {
@Override
public Class<Patient> getResourceType() {
return Patient.class;
}
@Read
public Patient read(@IdParam IdDt theId) {
return null;
}
}
}

View File

@ -0,0 +1 @@
/bin/

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hapi-fhir-structures-hl7org-dev</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -566,6 +566,11 @@ public class HumanNameDt
return this;
}
@Override
public StringDt getTextElement() {
return getText();
}

View File

@ -114,6 +114,11 @@
<name>Tahura Chaudhry</name>
<organization>University Health Network</organization>
</developer>
<developer>
<id>b.debeaubien</id>
<name>Bill de Beaubien</name>
<organization>Systems Made Simple</organization>
</developer>
</developers>
<licenses>

View File

@ -9,7 +9,7 @@
<dependent-module archiveName="hapi-fhir-structures-dstu-0.8-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-structures-dstu/hapi-fhir-structures-dstu">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module deploy-path="/" handle="module:/overlay/prj/hapi-fhir-testpage-overlay?includes=**/**&amp;excludes=META-INF/MANIFEST.MF">
<dependent-module deploy-path="/" handle="module:/overlay/var/M2_REPO/ca/uhn/hapi/fhir/hapi-fhir-testpage-overlay/0.8-SNAPSHOT/hapi-fhir-testpage-overlay-0.8-SNAPSHOT.war?unpackFolder=target/m2e-wtp/overlays&amp;includes=**/**&amp;excludes=META-INF/MANIFEST.MF">
<dependency-type>consumes</dependency-type>
</dependent-module>
<dependent-module deploy-path="/" handle="module:/overlay/slf/?includes=**/**&amp;excludes=META-INF/MANIFEST.MF">

View File

@ -43,7 +43,7 @@ public class MyOrganization extends Organization {
* of this file.
*/
@Description(shortDefinition="Contains emergency contact details")
@Extension(url = "http://foo#billingCode", isModifier = false, definedLocally = true)
@Extension(url = "http://foo#emergencyContact", isModifier = false, definedLocally = true)
@Child(name = "emergencyContact", min=0, max=Child.MAX_UNLIMITED)
private List<EmergencyContact> myEmergencyContact;

View File

@ -169,6 +169,10 @@
Encoding a Binary resource without a content type set should not result in a NullPointerException. Thanks
to Alexander Kley for reporting!
</action>
<action type="add">
Server gives a more helpful error message if multiple IResourceProvider implementations
are provided for the same resource type. Thanks to wanghaisheng for the idea!
</action>
</release>
<release version="0.7" date="2014-Oct-23">
<action type="add" issue="30">