From 85ec9d9264006a98df06f7a3e0e585a8a6fd8488 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 10 Dec 2015 08:24:12 -0500 Subject: [PATCH 01/16] Work on 2.1 structures --- .../interceptor/GZipContentInterceptor.java | 20 +++++++++++++++++++ .../ca/uhn/fhir/rest/gclient/IDelete.java | 4 +--- .../AbstractJaxRsConformanceProvider.java | 20 +++++++++++++++++++ .../server/AbstractJaxRsPageProvider.java | 20 +++++++++++++++++++ .../jaxrs/server/AbstractJaxRsProvider.java | 20 +++++++++++++++++++ .../server/AbstractJaxRsResourceProvider.java | 20 +++++++++++++++++++ .../JaxRsExceptionInterceptor.java | 20 +++++++++++++++++++ .../interceptor/JaxRsResponseException.java | 20 +++++++++++++++++++ .../server/util/JaxRsMethodBindings.java | 20 +++++++++++++++++++ .../fhir/jaxrs/server/util/JaxRsRequest.java | 20 +++++++++++++++++++ .../fhir/jaxrs/server/util/JaxRsResponse.java | 20 +++++++++++++++++++ hapi-fhir-jpaserver-base/pom.xml | 12 ++++++++--- .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 6 ++++-- .../fhir/jpa/dao/BaseHapiFhirResourceDao.java | 6 ------ .../fhir/jpa/dao/FhirResourceDaoDstu21.java | 20 +++++++++++++++++++ .../main/java/ca/uhn/fhir/jpa/dao/IDao.java | 7 +++++++ .../provider/ServletSubRequestDetails.java | 20 +++++++++++++++++++ .../provider/ServerConformanceProvider.java | 20 +++++++++++++++++++ .../ca/uhn/fhir/model/dstu21/FhirDstu21.java | 2 +- .../fhir/model/dstu21/composite/AgeDt.java | 2 +- .../composite/BoundCodeableConceptDt.java | 2 +- .../model/dstu21/composite/ContainedDt.java | 2 +- .../fhir/model/dstu21/composite/CountDt.java | 2 +- .../model/dstu21/composite/DistanceDt.java | 2 +- .../model/dstu21/composite/DurationDt.java | 2 +- .../fhir/model/dstu21/composite/MoneyDt.java | 2 +- .../model/dstu21/composite/NarrativeDt.java | 2 +- .../dstu21/composite/ResourceReferenceDt.java | 2 +- .../dstu21/composite/SimpleQuantityDt.java | 2 +- .../model/dstu21/resource/BaseResource.java | 2 +- .../provider/dstu21/Dstu21BundleFactory.java | 2 +- .../dstu21/ServerConformanceProvider.java | 2 +- .../dstu21/ServerProfileProvider.java | 2 +- 33 files changed, 296 insertions(+), 29 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java index c4d73341395..c5b7803c647 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/GZipContentInterceptor.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.rest.client.interceptor; +/* + * #%L + * HAPI FHIR - Core Library + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java index 6c0441897b3..a8f24b7bcc3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IDelete.java @@ -3,8 +3,6 @@ package ca.uhn.fhir.rest.gclient; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import ca.uhn.fhir.model.api.IResource; - /* * #%L * HAPI FHIR - Core Library @@ -27,7 +25,7 @@ import ca.uhn.fhir.model.api.IResource; public interface IDelete { - IDeleteTyped resource(IResource theResource); + IDeleteTyped resource(IBaseResource theResource); IDeleteTyped resourceById(IIdType theId); diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java index bbef3d408a4..8e5ee0eb7e5 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Method; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java index b37fa58a482..0ff71ac2b38 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsPageProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.util.Collections; import java.util.List; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java index 40613f02104..bba5f03b374 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java index 0a13cfb697a..b0b21b2c105 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.net.URL; import java.util.Collections; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java index f4665f8d0b1..fa2e1af41f6 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptor.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.interceptor; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import javax.interceptor.AroundInvoke; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java index 893fd23c1f1..ebc57bcd467 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseException.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.interceptor; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import javax.ejb.ApplicationException; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java index 1113ddb5fa6..f7e41277be6 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindings.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.util; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.lang.reflect.Method; import java.util.concurrent.ConcurrentHashMap; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java index 296a5f2faa7..15176703bc6 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequest.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.util; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.io.InputStream; import java.io.Reader; diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java index 7239427e5ba..3fa1825f8f5 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jaxrs.server.util; +/* + * #%L + * HAPI FHIR JAX-RS Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.io.IOException; import java.io.StringWriter; import java.io.UnsupportedEncodingException; diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index a1f03e72b3c..cb51285fed3 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -436,6 +436,7 @@ true + - org.hibernate hibernate-core - ${hibernate_version} + + + org.hibernate + hibernate-core + ${hibernate_version} + + o10g @@ -501,6 +506,7 @@ + --> diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 18fa1b5623f..4e2c11ae0e0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -1079,13 +1079,15 @@ public abstract class BaseHapiFhirDao implements IDao { return retVal; } - protected IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) { + @Override + public IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation) { RuntimeResourceDefinition type = myContext.getResourceDefinition(theEntity.getResourceType()); return toResource(type.getImplementingClass(), theEntity, theForHistoryOperation); } + @Override @SuppressWarnings("unchecked") - protected R toResource(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) { + public R toResource(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation) { String resourceText = null; switch (theEntity.getEncoding()) { case JSON: diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index de093babbc9..164e09ff683 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -33,10 +33,7 @@ import java.util.Map.Entry; import java.util.Set; import javax.annotation.PostConstruct; -import javax.persistence.EntityManager; import javax.persistence.NoResultException; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceContextType; import javax.persistence.TemporalType; import javax.persistence.TypedQuery; @@ -97,9 +94,6 @@ public abstract class BaseHapiFhirResourceDao extends BaseH @Autowired private DaoConfig myDaoConfig; - @PersistenceContext(type = PersistenceContextType.TRANSACTION) - protected EntityManager myEntityManager; - @Autowired protected PlatformTransactionManager myPlatformTransactionManager; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java index 2f7fe2765a6..4bbea00a5a3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu21.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jpa.dao; +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.util.ArrayList; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java index 37138dbe796..86711d7cd92 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IDao.java @@ -1,5 +1,8 @@ package ca.uhn.fhir.jpa.dao; +import org.hl7.fhir.instance.model.api.IBaseResource; + +import ca.uhn.fhir.jpa.entity.BaseHasResource; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; @@ -40,5 +43,9 @@ public interface IDao { } }; + IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation); + + R toResource(Class theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation); + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/ServletSubRequestDetails.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/ServletSubRequestDetails.java index 4ef0cfa7407..1d86e6adb6f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/ServletSubRequestDetails.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/ServletSubRequestDetails.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.jpa.provider; +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java index 60d60eebf36..797aaa78911 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java @@ -1,5 +1,25 @@ package ca.uhn.fhir.rest.server.provider; +/* + * #%L + * HAPI FHIR Structures - DSTU1 (FHIR v0.80) + * %% + * Copyright (C) 2014 - 2015 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/FhirDstu21.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/FhirDstu21.java index 69b8ea2ae22..d6b72dd3ec6 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/FhirDstu21.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/FhirDstu21.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.model.dstu21; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/AgeDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/AgeDt.java index dbe097639fe..e74017f7999 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/AgeDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/AgeDt.java @@ -6,7 +6,7 @@ import ca.uhn.fhir.model.primitive.IntegerDt; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/BoundCodeableConceptDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/BoundCodeableConceptDt.java index e0f5f671a8e..129c89aff4d 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/BoundCodeableConceptDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/BoundCodeableConceptDt.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.model.dstu21.composite; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ContainedDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ContainedDt.java index 3f3f2f2322d..cc759d73507 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ContainedDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ContainedDt.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.model.dstu21.composite; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/CountDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/CountDt.java index dc4c6bb065b..d90d4b8df26 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/CountDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/CountDt.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.model.dstu21.composite.QuantityDt; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DistanceDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DistanceDt.java index 7a250bc2a4e..d18f8b6fa97 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DistanceDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DistanceDt.java @@ -6,7 +6,7 @@ import ca.uhn.fhir.model.primitive.IntegerDt; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DurationDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DurationDt.java index 3d5a625061a..757f70b90b6 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DurationDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/DurationDt.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.model.dstu21.composite.QuantityDt; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java index 0fbd046dfef..5c6a3b37d5f 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/MoneyDt.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.model.dstu21.composite.QuantityDt; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/NarrativeDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/NarrativeDt.java index 3992f47c60a..029c7124c64 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/NarrativeDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/NarrativeDt.java @@ -18,7 +18,7 @@ package ca.uhn.fhir.model.dstu21.composite; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ResourceReferenceDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ResourceReferenceDt.java index 54ce5c234da..da354c2a114 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ResourceReferenceDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/ResourceReferenceDt.java @@ -18,7 +18,7 @@ package ca.uhn.fhir.model.dstu21.composite; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/SimpleQuantityDt.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/SimpleQuantityDt.java index 8e8f43f18ae..501a9141631 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/SimpleQuantityDt.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/composite/SimpleQuantityDt.java @@ -7,7 +7,7 @@ import ca.uhn.fhir.model.dstu21.valueset.QuantityComparatorEnum; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/resource/BaseResource.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/resource/BaseResource.java index 3ba203e5d65..50001ccb4f3 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/resource/BaseResource.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/model/dstu21/resource/BaseResource.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.model.dstu21.resource; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/Dstu21BundleFactory.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/Dstu21BundleFactory.java index f482a840387..7aee87a599f 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/Dstu21BundleFactory.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/Dstu21BundleFactory.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.rest.server.provider.dstu21; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerConformanceProvider.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerConformanceProvider.java index d62ab301515..11af44ccb68 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerConformanceProvider.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerConformanceProvider.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.rest.server.provider.dstu21; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerProfileProvider.java b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerProfileProvider.java index 01b8162d0a4..68dac70f747 100644 --- a/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerProfileProvider.java +++ b/hapi-fhir-structures-dstu2.1/src/main/java/ca/uhn/fhir/rest/server/provider/dstu21/ServerProfileProvider.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.rest.server.provider.dstu21; /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) + * HAPI FHIR Structures - DSTU2.1 (FHIR v1.1.x) * %% * Copyright (C) 2014 - 2015 University Health Network * %% From 97d6d096639bb2256255905d18d96afad1dc5a68 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 08:17:33 -0500 Subject: [PATCH 02/16] Work on #240 - Not yet working in JPA --- .../java/ca/uhn/fhir/model/api/Include.java | 67 ++++- .../ca/uhn/fhir/jpa/dao/SearchBuilder.java | 6 +- .../FhirResourceDaoDstu2SearchFtTest.java | 7 +- .../FhirResourceDaoDstu2SearchNoFtTest.java | 33 ++- .../ca/uhn/fhir/rest/server/IncludeTest.java | 276 ++++++++++-------- pom.xml | 30 +- src/changes/changes.xml | 10 + 7 files changed, 278 insertions(+), 151 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java index 3da5dd95043..6fbb2d505f8 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java @@ -2,6 +2,8 @@ package ca.uhn.fhir.model.api; import org.apache.commons.lang3.builder.ToStringBuilder; +import ch.qos.logback.core.db.dialect.MySQLDialect; + /* * #%L * HAPI FHIR - Core Library @@ -34,7 +36,7 @@ public class Include { private boolean myRecurse; private String myValue; - private boolean myImmutable; + private final boolean myImmutable; /** * Constructor for non-recursive include @@ -44,10 +46,11 @@ public class Include { */ public Include(String theValue) { myValue = theValue; + myImmutable = false; } /** - * Constructor for non-recursive include + * Constructor for an include * * @param theValue * The _include value, e.g. "Patient:name" @@ -57,6 +60,21 @@ public class Include { public Include(String theValue, boolean theRecurse) { myValue = theValue; myRecurse = theRecurse; + myImmutable = false; + } + + /** + * Constructor for an include + * + * @param theValue + * The _include value, e.g. "Patient:name" + * @param theRecurse + * Should the include recurse + */ + public Include(String theValue, boolean theRecurse, boolean theImmutable) { + myValue = theValue; + myRecurse = theRecurse; + myImmutable = theImmutable; } /** @@ -132,9 +150,18 @@ public class Include { myValue = theValue; } + /** + * Is this object {@link #toLocked() locked}? + */ + public boolean isLocked() { + return myImmutable; + } + + /** + * Return a new + */ public Include toLocked() { - Include retVal = new Include(myValue, myRecurse); - retVal.myImmutable = true; + Include retVal = new Include(myValue, myRecurse, true); return retVal; } @@ -145,4 +172,36 @@ public class Include { builder.append("recurse", myRecurse); return builder.toString(); } + + /** + * Creates and returns a new copy of this Include with the given type. The + * following table shows what will be returned: + * + * + * + * + * + *
Initial ContentstheResourceTypeOutput
Patient:careProviderOrganizationPatient:careProvider:Organization
Patient:careProvider:PractitionerOrganizationPatient:careProvider:Organization
Patient(any){@link IllegalStateException}
+ * + * @param theResourceType The resource type (e.g. "Organization") + * @return A new copy of the include. Note that if this include is {@link #toLocked() locked}, the returned include will be too + */ + public Include withType(String theResourceType) { + StringBuilder b = new StringBuilder(); + b.append(myValue); + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == b.length() - 1) { + throw new IllegalStateException("This include does not contain a value in the format [ResourceType]:[paramName]"); + } + int secondColon = myValue.indexOf(':', firstColon + 1); + if (secondColon != -1) { + b.delete(secondColon, b.length()); + } + + b.append(":"); + b.append(theResourceType); + Include retVal = new Include(b.toString(), myRecurse, myImmutable); + return retVal; + } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index baacd661955..83b375b1507 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -1322,7 +1322,7 @@ public class SearchBuilder { * * @param theLastUpdated */ - private HashSet loadReverseIncludes(Collection theMatches, Set theRevIncludes, boolean theReverseMode, EverythingModeEnum theEverythingModeEnum, DateRangeParam theLastUpdated) { + private HashSet loadReverseIncludes(Collection theMatches, Set theRevIncludes, boolean theReverseMode, DateRangeParam theLastUpdated) { if (theMatches.size() == 0) { return new HashSet(); } @@ -1595,7 +1595,7 @@ public class SearchBuilder { final Set revIncludedPids; if (theParams.getEverythingMode() == null) { if (theParams.getRevIncludes() != null && theParams.getRevIncludes().isEmpty() == false) { - revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, null, lu); + revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, lu); } else { revIncludedPids = new HashSet(); } @@ -1623,7 +1623,7 @@ public class SearchBuilder { // Load includes pidsSubList = new ArrayList(pidsSubList); - revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, null, theParams.getLastUpdated())); + revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, theParams.getLastUpdated())); // Execute the query and make sure we return distinct results List resources = new ArrayList(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java index 79b09e9ddc8..3217a6c9ce8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java @@ -4,7 +4,9 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import java.util.List; @@ -14,9 +16,8 @@ import javax.servlet.http.HttpServletRequest; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Test; -import ca.uhn.fhir.jpa.dao.FhirSearchDao; -import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.FhirSearchDao.Suggestion; +import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.model.dstu2.resource.Device; import ca.uhn.fhir.model.dstu2.resource.Media; import ca.uhn.fhir.model.dstu2.resource.Observation; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index 0d5dab1ba81..e1010cd45eb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -1430,25 +1430,36 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1Parent"); - parentOrgId = myOrganizationDao.create(org).getId(); + parentOrgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); } + IIdType orgId; + IIdType patientId; { Organization org = new Organization(); org.getNameElement().setValue(methodName + "_O1"); org.setPartOf(new ResourceReferenceDt(parentOrgId)); - IIdType orgId = myOrganizationDao.create(org).getId(); + orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless(); Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().addFamily("Tester_" + methodName + "_P1").addGiven("Joe"); patient.getManagingOrganization().setReference(orgId); - myPatientDao.create(patient); + patient.addCareProvider().setReference(orgId); + patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); } + IIdType practId2; + { + Practitioner pract = new Practitioner(); + pract.getName().addFamily(methodName + "_PRACT1"); + practId2 = myPractitionerDao.create(pract).getId().toUnqualifiedVersionless(); + } + IIdType patientId2; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().addFamily("Tester_" + methodName + "_P2").addGiven("John"); - myPatientDao.create(patient); + patient.addCareProvider().setReference(practId2); + patientId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); } { @@ -1527,6 +1538,20 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { assertEquals(1, patients.size()); assertEquals(Patient.class, patients.get(0).getClass()); } + { + // Untyped include + SearchParameterMap params = new SearchParameterMap(); + params.addInclude(Patient.INCLUDE_CAREPROVIDER); + List ids = toUnqualifiedVersionlessIds(myPatientDao.search(params)); + assertThat(ids, containsInAnyOrder(orgId, patientId, patientId2, practId2)); + } + { +// // Typed include +// SearchParameterMap params = new SearchParameterMap(); +// params.addInclude(Patient.INCLUDE_CAREPROVIDER.withType("Practitioner")); +// List ids = toUnqualifiedVersionlessIds(myPatientDao.search(params)); +// assertThat(ids, containsInAnyOrder(patientId, patientId2, practId2)); + } } @SuppressWarnings("unused") diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java index a05fa753f46..8bc9e169ed6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java @@ -1,7 +1,10 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Arrays; @@ -51,56 +54,21 @@ import ca.uhn.fhir.util.PortUtil; public class IncludeTest { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IncludeTest.class); private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; @Test - public void testNoIncludes() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); - - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(0, p.getName().size()); - assertEquals("Hello", p.getId().getIdPart()); - } - - @Test - public void testOneInclude() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); - - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(1, p.getName().size()); - assertEquals("Hello", p.getId().getIdPart()); - assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); - } - - // @Test - public void testMixedContainedAndNonContained() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); + public void testBadInclude() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=baz"); HttpResponse status = ourClient.execute(httpGet); + assertEquals(400, status.getStatusLine().getStatusCode()); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - assertEquals(4, bundle.size()); + assertThat(responseContent, containsString("Invalid _include parameter value")); } @Test @@ -128,6 +96,32 @@ public class IncludeTest { } + @Test + public void testIIncludedResourcesNonContainedInDeclaredExtension() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=declaredExtInclude&_pretty=true"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + + ourLog.info(responseContent); + + assertEquals(4, bundle.size()); + assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); + assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); + assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); + assertEquals(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless()); + + Patient p1 = (Patient) bundle.toListOfResources().get(0); + assertEquals(0, p1.getContained().getContainedResources().size()); + + Patient p2 = (Patient) bundle.toListOfResources().get(1); + assertEquals(0, p2.getContained().getContainedResources().size()); + + } + @Test public void testIIncludedResourcesNonContainedInExtension() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true"); @@ -179,29 +173,79 @@ public class IncludeTest { } @Test - public void testIIncludedResourcesNonContainedInDeclaredExtension() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=declaredExtInclude&_pretty=true"); + public void testIncludeWithType() { + assertEquals("Patient:careProvider:Practitioner", new Include("Patient:careProvider", true).withType("Practitioner").getValue()); + assertEquals(true, new Include("Patient:careProvider", true).withType("Practitioner").isRecurse()); + assertEquals(false, new Include("Patient:careProvider:Organization", true).withType("Practitioner").isLocked()); + + assertEquals("Patient:careProvider:Practitioner", new Include("Patient:careProvider:Organization", true).withType("Practitioner").getValue()); + assertEquals(true, new Include("Patient:careProvider:Organization", true).toLocked().withType("Practitioner").isLocked()); + + try { + new Include("").withType("Patient"); + fail(); + } catch (IllegalStateException e) { + // good + } + try { + new Include("Patient").withType("Patient"); + fail(); + } catch (IllegalStateException e) { + // good + } + try { + new Include("Patient:").withType("Patient"); + fail(); + } catch (IllegalStateException e) { + // good + } + } + + // @Test + public void testMixedContainedAndNonContained() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info(responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(4, bundle.size()); + } + + @Test + public void testNoIncludes() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); - ourLog.info(responseContent); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(0, p.getName().size()); + assertEquals("Hello", p.getId().getIdPart()); + } - assertEquals(4, bundle.size()); - assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); - assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); - assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); - assertEquals(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless()); + @Test + public void testOneInclude() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); - Patient p1 = (Patient) bundle.toListOfResources().get(0); - assertEquals(0, p1.getContained().getContainedResources().size()); - - Patient p2 = (Patient) bundle.toListOfResources().get(1); - assertEquals(0, p2.getContained().getContainedResources().size()); + assertEquals(200, status.getStatusLine().getStatusCode()); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(1, p.getName().size()); + assertEquals("Hello", p.getId().getIdPart()); + assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); } @Test @@ -226,18 +270,6 @@ public class IncludeTest { } - @Test - public void testBadInclude() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=baz"); - HttpResponse status = ourClient.execute(httpGet); - assertEquals(400, status.getStatusLine().getStatusCode()); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info(responseContent); - assertThat(responseContent, containsString("Invalid _include parameter value")); - } - @AfterClass public static void afterClass() throws Exception { ourServer.stop(); @@ -268,27 +300,20 @@ public class IncludeTest { } - @ResourceDef(name = "Patient") - public static class ExtPatient extends Patient { - @Child(name = "secondOrg") - @Extension(url = "http://foo#secondOrg", definedLocally = false, isModifier = false) - private ResourceReferenceDt mySecondOrg; + public static void main(String[] args) { - @Override - public boolean isEmpty() { - return super.isEmpty() && ElementUtil.isEmpty(mySecondOrg); - } + Organization org = new Organization(); + org.setId("Organization/65546"); + org.getName().setValue("Contained Test Organization"); - public ResourceReferenceDt getSecondOrg() { - if (mySecondOrg == null) { - mySecondOrg = new ResourceReferenceDt(); - } - return mySecondOrg; - } + Patient patient = new Patient(); + patient.setId("Patient/1333"); + patient.addIdentifier("urn:mrns", "253345"); + patient.getManagingOrganization().setResource(patient); - public void setSecondOrg(ResourceReferenceDt theSecondOrg) { - mySecondOrg = theSecondOrg; - } + System.out.println(FhirContext.forDstu1().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient)); + + patient.getManagingOrganization().getReference(); } @@ -345,11 +370,10 @@ public class IncludeTest { */ public static class DummyPatientResourceProvider implements IResourceProvider { - @Search(queryName = "normalInclude") - public List normalInclude() { + @Search(queryName = "containedInclude") + public List containedInclude() { Organization o1 = new Organization(); o1.getName().setValue("o1"); - o1.setId("o1"); Patient p1 = new Patient(); p1.setId("p1"); @@ -364,25 +388,6 @@ public class IncludeTest { return Arrays.asList(p1, p2); } - @Search(queryName = "extInclude") - public List extInclude() { - Organization o1 = new Organization(); - o1.getName().setValue("o1"); - o1.setId("o1"); - - Patient p1 = new Patient(); - p1.setId("p1"); - p1.addIdentifier().setLabel("p1"); - p1.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); - - Patient p2 = new Patient(); - p2.setId("p2"); - p2.addIdentifier().setLabel("p2"); - p2.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); - - return Arrays.asList(p1, p2); - } - @Search(queryName = "declaredExtInclude") public List declaredExtInclude() { Organization o1 = new Organization(); @@ -407,20 +412,21 @@ public class IncludeTest { return Arrays.asList(p1, p2); } - @Search(queryName = "containedInclude") - public List containedInclude() { + @Search(queryName = "extInclude") + public List extInclude() { Organization o1 = new Organization(); o1.getName().setValue("o1"); + o1.setId("o1"); Patient p1 = new Patient(); p1.setId("p1"); p1.addIdentifier().setLabel("p1"); - p1.getManagingOrganization().setResource(o1); + p1.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); Patient p2 = new Patient(); p2.setId("p2"); p2.addIdentifier().setLabel("p2"); - p2.getManagingOrganization().setResource(o1); + p2.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); return Arrays.asList(p1, p2); } @@ -449,22 +455,48 @@ public class IncludeTest { return Patient.class; } + @Search(queryName = "normalInclude") + public List normalInclude() { + Organization o1 = new Organization(); + o1.getName().setValue("o1"); + o1.setId("o1"); + + Patient p1 = new Patient(); + p1.setId("p1"); + p1.addIdentifier().setLabel("p1"); + p1.getManagingOrganization().setResource(o1); + + Patient p2 = new Patient(); + p2.setId("p2"); + p2.addIdentifier().setLabel("p2"); + p2.getManagingOrganization().setResource(o1); + + return Arrays.asList(p1, p2); + } + } - public static void main(String[] args) { + @ResourceDef(name = "Patient") + public static class ExtPatient extends Patient { + @Child(name = "secondOrg") + @Extension(url = "http://foo#secondOrg", definedLocally = false, isModifier = false) + private ResourceReferenceDt mySecondOrg; - Organization org = new Organization(); - org.setId("Organization/65546"); - org.getName().setValue("Contained Test Organization"); + public ResourceReferenceDt getSecondOrg() { + if (mySecondOrg == null) { + mySecondOrg = new ResourceReferenceDt(); + } + return mySecondOrg; + } - Patient patient = new Patient(); - patient.setId("Patient/1333"); - patient.addIdentifier("urn:mrns", "253345"); - patient.getManagingOrganization().setResource(patient); + @Override + public boolean isEmpty() { + return super.isEmpty() && ElementUtil.isEmpty(mySecondOrg); + } - System.out.println(FhirContext.forDstu1().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient)); - - patient.getManagingOrganization().getReference(); + public void setSecondOrg(ResourceReferenceDt theSecondOrg) { + mySecondOrg = theSecondOrg; + } } diff --git a/pom.xml b/pom.xml index ad590bd4675..004e9ec2661 100644 --- a/pom.xml +++ b/pom.xml @@ -240,7 +240,7 @@ 9.2.14.v20151106 - 5.0.3.Final + 5.0.5.Final 5.2.2.Final 2.5.3 2.18.1 @@ -251,7 +251,7 @@ 1.1.8 2.7.1 4.3.6 - 4.2.2.RELEASE + 4.2.3.RELEASE 2.1.4.RELEASE 1.0.1 1.6 @@ -277,7 +277,7 @@ com.google.guava guava - 18.0 + 19.0 com.phloc @@ -392,12 +392,12 @@ org.apache.lucene lucene-highlighter - 5.3.0 + 5.3.1 org.apache.lucene lucene-analyzers-phonetic - 5.3.0 + 5.3.1 org.apache.maven.doxia @@ -407,17 +407,17 @@ org.apache.maven.scm maven-scm-api - 1.9 + 1.9.4 org.apache.maven.scm maven-scm-manager-plexus - 1.9 + 1.9.4 org.apache.maven.scm maven-scm-provider-gitexe - 1.9 + 1.9.4 org.apache.maven.wagon @@ -552,7 +552,7 @@ org.hibernate hibernate-search-orm - 5.5.0.Final + 5.5.1.Final org.javassist @@ -562,17 +562,17 @@ org.slf4j slf4j-android - 1.7.12 + 1.7.13 org.slf4j slf4j-api - 1.7.12 + 1.7.13 org.slf4j jcl-over-slf4j - 1.7.12 + 1.7.13 org.springframework @@ -663,7 +663,7 @@ org.apache.felix maven-bundle-plugin - 3.0.0 + 3.0.1 org.apache.maven.plugins @@ -931,12 +931,12 @@ org.apache.maven.plugins maven-checkstyle-plugin - 2.15 + 2.17 com.puppycrawl.tools checkstyle - 6.11.2 + 6.13 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7d1d44d95bb..c10efad57cb 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,16 @@ + + Bump the version of a few dependencies to the + latest versions (dependent HAPI modules listed in brackets): + +
  • Hibernate (JPA, Web Tester): 5.0.3 -> 5.0.5
  • +
  • Springframework (JPA, Web Tester): 4.2.2 -> 4.2.3
  • + + ]]> +
    Remove a dependency on a Java 1.7 class (ReflectiveOperationException) in several spots in the From 5c47c0c75c44cc47e26a96304c7e39d223e1fa0c Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 09:08:40 -0500 Subject: [PATCH 03/16] Gitignore tweak --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a717ce95fa7..0bc1caebc61 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ nohup.out tmp.txt *.hprof tmp.txt +ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString/ # Vagrant stuff. .vagrant From 2eaa1eddaebf7d2f5830222d315a2ecd67e861e5 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 14 Dec 2015 18:22:21 -0500 Subject: [PATCH 04/16] Fix compile --- .../main/java/ca/uhn/fhir/rest/client/GenericClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java index 6b568af7fde..7379e30da6f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java @@ -853,10 +853,10 @@ public class GenericClient extends BaseClient implements IGenericClient { } @Override - public IDeleteTyped resource(IResource theResource) { + public IDeleteTyped resource(IBaseResource theResource) { Validate.notNull(theResource, "theResource can not be null"); - IdDt id = theResource.getId(); - Validate.notNull(id, "theResource.getId() can not be null"); + IIdType id = theResource.getIdElement(); + Validate.notNull(id, "theResource.getIdElement() can not be null"); if (id.hasResourceType() == false || id.hasIdPart() == false) { throw new IllegalArgumentException("theResource.getId() must contain a resource type and logical ID at a minimum (e.g. Patient/1234), found: " + id.getValue()); } From feaf33dfd9e71dbf48599d10c4566de484ef12d1 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 14 Dec 2015 18:25:55 -0500 Subject: [PATCH 05/16] Fix breaking test --- .../java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java index 7bf718619f2..1da1a27b4f0 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java @@ -65,7 +65,7 @@ public class BaseDateTimeDtTest { DateTimeDt dt = DateTimeDt.withCurrentTime(); String str = dt.getValueAsString(); char offset = str.charAt(19); - if (offset != '+' && offset != '-') { + if (offset != '+' && offset != '-' && offset != 'Z') { fail("No timezone provided: " + str); } } @@ -75,7 +75,7 @@ public class BaseDateTimeDtTest { InstantDt dt = InstantDt.withCurrentTime(); String str = dt.getValueAsString(); char offset = str.charAt(23); - if (offset != '+' && offset != '-') { + if (offset != '+' && offset != '-' && offset != 'Z') { fail("No timezone provided: " + str); } } From 96c0267fe178f16c93551bef2dd02ef639c1423f Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 14 Dec 2015 18:35:42 -0500 Subject: [PATCH 06/16] Add logging to stupid failing travis test --- .../src/test/java/ca/uhn/fhir/parser/JsonParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java index 72293c22dcc..8e8e8c2b7a7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java @@ -1341,7 +1341,7 @@ public class JsonParserTest { ourLog.info("Expected: {}", exp); ourLog.info("Actual : {}", act); - assertEquals(exp, act); + assertEquals("\nExpected: " + exp + "\nActual : " + act, exp, act); } From d95bd269c02db6dcc80bd206e7aa7868e5405924 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 21:04:27 -0500 Subject: [PATCH 07/16] Correctly encode value[x] field names when the datatype is a profiled type such as markdown --- .../context/RuntimeChildChoiceDefinition.java | 36 +++++++++------- .../ca/uhn/fhir/parser/JsonParserTest.java | 8 ++-- .../uhn/fhir/parser/XmlParserDstu21Test.java | 41 ++++++++---------- .../uhn/fhir/parser/XmlParserDstu2Test.java | 42 +++++++++++++++++++ src/changes/changes.xml | 6 +++ 5 files changed, 89 insertions(+), 44 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java index e4fa19185aa..940e1e09027 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java @@ -109,22 +109,26 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini } else { nextDef = theClassToElementDefinitions.get(next); BaseRuntimeElementDefinition nextDefForChoice = nextDef; - if (nextDef instanceof IRuntimeDatatypeDefinition) { - IRuntimeDatatypeDefinition nextDefDatatype = (IRuntimeDatatypeDefinition) nextDef; - if (nextDefDatatype.getProfileOf() != null) { - /* - * Elements which are called foo[x] and have a choice which is a profiled datatype must use the - * unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the - * element fooString when encoded, because markdown is a profile of string. This is according to the - * FHIR spec - */ - nextDefForChoice = null; - nonPreferred = true; - Class profileType = nextDefDatatype.getProfileOf(); - BaseRuntimeElementDefinition elementDef = theClassToElementDefinitions.get(profileType); - elementName = getElementName() + StringUtils.capitalize(elementDef.getName()); - } - } + /* + * In HAPI 1.3 the following applied: + * Elements which are called foo[x] and have a choice which is a profiled datatype must use the + * unprofiled datatype as the element name. E.g. if foo[x] allows markdown as a datatype, it calls the + * element fooString when encoded, because markdown is a profile of string. This is according to the + * FHIR spec + * + * As of HAPI 1.4 this has been disabled after conversation with Grahame. It appears + * that it is not correct behaviour. + */ +// if (nextDef instanceof IRuntimeDatatypeDefinition) { +// IRuntimeDatatypeDefinition nextDefDatatype = (IRuntimeDatatypeDefinition) nextDef; +// if (nextDefDatatype.getProfileOf() != null) { +// nextDefForChoice = null; +// nonPreferred = true; +// Class profileType = nextDefDatatype.getProfileOf(); +// BaseRuntimeElementDefinition elementDef = theClassToElementDefinitions.get(profileType); +// elementName = getElementName() + StringUtils.capitalize(elementDef.getName()); +// } +// } if (nextDefForChoice != null) { elementName = getElementName() + StringUtils.capitalize(nextDefForChoice.getName()); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java index 8e8e8c2b7a7..2aba8ae130c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java @@ -20,9 +20,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import net.sf.json.JSON; -import net.sf.json.JSONSerializer; - import org.apache.commons.io.IOUtils; import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; @@ -30,7 +27,6 @@ import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import ca.uhn.fhir.context.ConfigurationException; @@ -68,6 +64,7 @@ import ca.uhn.fhir.model.dstu.resource.ValueSet.DefineConcept; import ca.uhn.fhir.model.dstu.valueset.AddressUseEnum; import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum; import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum; +import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.DecimalDt; @@ -76,6 +73,8 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.XhtmlDt; import ca.uhn.fhir.narrative.INarrativeGenerator; +import net.sf.json.JSON; +import net.sf.json.JSONSerializer; public class JsonParserTest { private static FhirContext ourCtx; @@ -1323,6 +1322,7 @@ public class JsonParserTest { List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions(); ExtensionDt undeclaredExtension = undeclaredExtensions.get(0); assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl()); + assertEquals("VV", ((CodeDt)undeclaredExtension.getValue()).getValue()); ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out)); diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java index 594108bfc25..4c22561ba96 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java @@ -125,7 +125,7 @@ public class XmlParserDstu21Test { assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent()); } - + @Test public void testEncodeEmptyBinary() { String output = ourCtx.newXmlParser().encodeResourceToString(new Binary()); @@ -142,18 +142,16 @@ public class XmlParserDstu21Test { ourCtx.newJsonParser().parseResource(encoded); } - @Test public void testEncodeDoesntIncludeUuidId() { Patient p = new Patient(); p.setId(new IdDt("urn:uuid:42795ed8-041f-4ebf-b6f4-78ef6f64c2f2")); p.addIdentifier().setSystem("ACME"); - + String actual = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p); assertThat(actual, not(containsString("78ef6f64c2f2"))); } - - + @Test public void testContainedResourceInExtensionUndeclared() { Patient p = new Patient(); @@ -341,11 +339,9 @@ public class XmlParserDstu21Test { String enc = ourCtx.newXmlParser().encodeResourceToString(patient); assertThat(enc, containsString("")); assertThat(enc, containsString("")); - assertThat(enc, containsString( - "")); + assertThat(enc, containsString("")); assertThat(enc, containsString("")); - assertThat(enc, containsString( - "")); + assertThat(enc, containsString("")); /* * Now parse this back @@ -541,7 +537,8 @@ public class XmlParserDstu21Test { /** * See #216 - Profiled datatypes should use their unprofiled parent type as the choice[x] name */ - @Test @Ignore + @Test + @Ignore public void testEncodeAndParseProfiledDatatypeChoice() throws Exception { IParser xmlParser = ourCtx.newXmlParser(); @@ -751,10 +748,8 @@ public class XmlParserDstu21Test { ourLog.info(encoded); // @formatter:on - assertThat(encoded, - stringContainsInOrder("", "", "", "", "", "", - "", "", "", "", "", "", "", "", - "", "", "")); + assertThat(encoded, stringContainsInOrder("", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "")); //@formatter:off } @@ -786,10 +781,8 @@ public class XmlParserDstu21Test { ourLog.info(encoded); //@formatter:on - assertThat(encoded, - stringContainsInOrder("", "", "", "", "", "", - "", "", "", "", "", "", "", "", - "", "", "")); + assertThat(encoded, stringContainsInOrder("", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "")); //@formatter:off } @@ -824,10 +817,8 @@ public class XmlParserDstu21Test { ourLog.info(encoded); //@formatter:on - assertThat(encoded, - stringContainsInOrder("", "", "", "", "", "", - "", "", "", "", "", "", "", "", - "", "", "")); + assertThat(encoded, stringContainsInOrder("", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "")); //@formatter:off } @@ -1630,7 +1621,8 @@ public class XmlParserDstu21Test { /** * See #191 */ - @Test @Ignore + @Test + @Ignore public void testParseBundleWithLinksOfUnknownRelation() throws Exception { String input = IOUtils.toString(XmlParserDstu21Test.class.getResourceAsStream("/bundle_orion.xml")); ca.uhn.fhir.model.dstu21.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu21.resource.Bundle.class, input); @@ -1664,7 +1656,8 @@ public class XmlParserDstu21Test { /** * see #144 and #146 */ - @Test @Ignore + @Test + @Ignore public void testParseContained() { FhirContext c = FhirContext.forDstu2(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java index 60b4b940d0e..2000571c53c 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java @@ -68,6 +68,7 @@ import ca.uhn.fhir.model.dstu2.resource.MedicationOrder; import ca.uhn.fhir.model.dstu2.resource.MedicationStatement; import ca.uhn.fhir.model.dstu2.resource.Observation; import ca.uhn.fhir.model.dstu2.resource.Organization; +import ca.uhn.fhir.model.dstu2.resource.Parameters; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.AddressUseEnum; import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum; @@ -84,6 +85,7 @@ import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.model.primitive.MarkdownDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation; import ca.uhn.fhir.rest.client.IGenericClient; @@ -93,6 +95,46 @@ public class XmlParserDstu2Test { private static final FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XmlParserDstu2Test.class); + @Test + public void testChoiceTypeWithProfiledType() { + //@formatter:off + String input = "\n" + + " \n" + + " \n" + + " \n" + + ""; + //@formatter:on + + Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, input); + assertEquals(1, parsed.getUndeclaredExtensions().size()); + ExtensionDt ext = parsed.getUndeclaredExtensions().get(0); + assertEquals("http://example.com", ext.getUrl()); + assertEquals("THIS IS MARKDOWN", ((MarkdownDt)ext.getValue()).getValue()); + + String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed); + assertThat(encoded, containsString("")); + } + + + @Test + public void testChoiceTypeWithProfiledType2() { + Parameters par = new Parameters(); + par.addParameter().setValue((StringDt)new StringDt().setValue("ST")); + par.addParameter().setValue((MarkdownDt)new MarkdownDt().setValue("MD")); + + String str = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(par); + ourLog.info(str); + + assertThat(str, stringContainsInOrder("", "")); + + par = ourCtx.newXmlParser().parseResource(Parameters.class, str); + assertEquals(2, par.getParameter().size()); + assertEquals(StringDt.class, par.getParameter().get(0).getValue().getClass()); + assertEquals(MarkdownDt.class, par.getParameter().get(1).getValue().getClass()); + } + + + @Test public void testBundleWithBinary() { //@formatter:off diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c10efad57cb..a467f8728ec 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -65,6 +65,12 @@ remains committed to supporting JDK 6+ in the compiled library, but these days it can only be built using JDK 8. Thanks to joelsch for the PR! + + When serializing a value[x] field, if the value type was a profiled type (e.g. markdown is a + profile of string) HAPI 1.3 would use the base type in the element name, e.g. + valueString instead of valueMarkdown. After discussion with Grahame, this appears to + be incorrect behaviour so it has been fixed. +
    From a623003a5643650fb13b04c8a32f4ad037bc1cf3 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 21:50:35 -0500 Subject: [PATCH 08/16] Fix #240 - Support target resource type in server _include and _revinclude values --- .../java/ca/uhn/fhir/model/api/Include.java | 159 ++++++++++++------ .../ca/uhn/fhir/jpa/dao/SearchBuilder.java | 22 ++- .../ca/uhn/fhir/jpa/entity/ResourceLink.java | 23 ++- .../FhirResourceDaoDstu2SearchNoFtTest.java | 14 +- .../ca/uhn/fhir/rest/server/IncludeTest.java | 2 + src/changes/changes.xml | 5 + 6 files changed, 159 insertions(+), 66 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java index 6fbb2d505f8..a545745c658 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Include.java @@ -1,8 +1,9 @@ package ca.uhn.fhir.model.api; -import org.apache.commons.lang3.builder.ToStringBuilder; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; -import ch.qos.logback.core.db.dialect.MySQLDialect; +import org.apache.commons.lang3.builder.ToStringBuilder; /* * #%L @@ -34,9 +35,9 @@ import ch.qos.logback.core.db.dialect.MySQLDialect; */ public class Include { + private final boolean myImmutable; private boolean myRecurse; private String myValue; - private final boolean myImmutable; /** * Constructor for non-recursive include @@ -91,22 +92,6 @@ public class Include { return new Include(myValue, true); } - public String getValue() { - return myValue; - } - - /** - * See the note on equality on the {@link Include class documentation} - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (myRecurse ? 1231 : 1237); - result = prime * result + ((myValue == null) ? 0 : myValue.hashCode()); - return result; - } - /** * See the note on equality on the {@link Include class documentation} */ @@ -135,6 +120,73 @@ public class Include { return true; } + /** + * Returns the portion of the value before the first colon + */ + public String getParamType() { + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == myValue.length() - 1) { + return null; + } + return myValue.substring(0, firstColon); + } + + /** + * Returns the portion of the value after the first colon but before the second colon + */ + public String getParamName() { + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == myValue.length() - 1) { + return null; + } + int secondColon = myValue.indexOf(':', firstColon + 1); + if (secondColon != -1) { + return myValue.substring(firstColon + 1, secondColon); + } else { + return myValue.substring(firstColon + 1); + } + } + + /** + * Returns the portion of the string after the second colon, or null if there are not two colons in the value. + */ + public String getParamTargetType() { + int firstColon = myValue.indexOf(':'); + if (firstColon == -1 || firstColon == myValue.length() - 1) { + return null; + } + int secondColon = myValue.indexOf(':', firstColon + 1); + if (secondColon != -1) { + return myValue.substring(secondColon + 1); + } else { + return null; + } + + } + + public String getValue() { + return myValue; + } + + /** + * See the note on equality on the {@link Include class documentation} + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (myRecurse ? 1231 : 1237); + result = prime * result + ((myValue == null) ? 0 : myValue.hashCode()); + return result; + } + + /** + * Is this object {@link #toLocked() locked}? + */ + public boolean isLocked() { + return myImmutable; + } + public boolean isRecurse() { return myRecurse; } @@ -151,20 +203,13 @@ public class Include { } /** - * Is this object {@link #toLocked() locked}? - */ - public boolean isLocked() { - return myImmutable; - } - - /** - * Return a new + * Return a new */ public Include toLocked() { Include retVal = new Include(myValue, myRecurse, true); return retVal; } - + @Override public String toString() { ToStringBuilder builder = new ToStringBuilder(this); @@ -172,36 +217,56 @@ public class Include { builder.append("recurse", myRecurse); return builder.toString(); } - + /** - * Creates and returns a new copy of this Include with the given type. The - * following table shows what will be returned: + * Creates and returns a new copy of this Include with the given type. The following table shows what will be + * returned: * - * - * - * - * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * *
    Initial ContentstheResourceTypeOutput
    Patient:careProviderOrganizationPatient:careProvider:Organization
    Patient:careProvider:PractitionerOrganizationPatient:careProvider:Organization
    Patient(any){@link IllegalStateException}
    Initial ContentstheResourceTypeOutput
    Patient:careProvider + * OrganizationPatient:careProvider:Organization
    Patient:careProvider:Practitioner + * OrganizationPatient:careProvider:Organization
    Patient + * (any){@link IllegalStateException}
    * - * @param theResourceType The resource type (e.g. "Organization") - * @return A new copy of the include. Note that if this include is {@link #toLocked() locked}, the returned include will be too + * @param theResourceType + * The resource type (e.g. "Organization") + * @return A new copy of the include. Note that if this include is {@link #toLocked() locked}, the returned include + * will be too */ public Include withType(String theResourceType) { StringBuilder b = new StringBuilder(); - b.append(myValue); - int firstColon = myValue.indexOf(':'); - if (firstColon == -1 || firstColon == b.length() - 1) { + + String paramType = getParamType(); + String paramName = getParamName(); + if (isBlank(paramType) || isBlank(paramName)) { throw new IllegalStateException("This include does not contain a value in the format [ResourceType]:[paramName]"); } - int secondColon = myValue.indexOf(':', firstColon + 1); - if (secondColon != -1) { - b.delete(secondColon, b.length()); - } - + b.append(paramType); b.append(":"); - b.append(theResourceType); + b.append(paramName); + + if (isNotBlank(theResourceType)) { + b.append(':'); + b.append(theResourceType); + } Include retVal = new Include(b.toString(), myRecurse, myImmutable); return retVal; } - + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index 83b375b1507..a49496397e3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -1,5 +1,7 @@ package ca.uhn.fhir.jpa.dao; +import static org.apache.commons.lang3.StringUtils.defaultString; + /* * #%L * HAPI FHIR JPA Server @@ -1378,19 +1380,18 @@ public class SearchBuilder { if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) { paths = Collections.singletonList(nextInclude.getValue()); } else { - int colonIdx = nextInclude.getValue().indexOf(':'); - if (colonIdx < 2) { + String resType = nextInclude.getParamType(); + if (isBlank(resType)) { continue; } - String resType = nextInclude.getValue().substring(0, colonIdx); RuntimeResourceDefinition def = myContext.getResourceDefinition(resType); if (def == null) { ourLog.warn("Unknown resource type in include/revinclude=" + nextInclude.getValue()); continue; } - String paramName = nextInclude.getValue().substring(colonIdx + 1); - RuntimeSearchParam param = def.getSearchParam(paramName); + String paramName = nextInclude.getParamName(); + RuntimeSearchParam param = isNotBlank(paramName) ? def.getSearchParam(paramName) : null; if (param == null) { ourLog.warn("Unknown param name in include/revinclude=" + nextInclude.getValue()); continue; @@ -1399,11 +1400,20 @@ public class SearchBuilder { paths = param.getPathsSplit(); } + String targetResourceType = defaultString(nextInclude.getParamTargetType(), null); for (String nextPath : paths) { - String sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)"; + String sql; + if (targetResourceType != null) { + sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type"; + } else { + sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)"; + } TypedQuery q = myEntityManager.createQuery(sql, ResourceLink.class); q.setParameter("src_path", nextPath); q.setParameter("target_pids", nextRoundMatches); + if (targetResourceType != null) { + q.setParameter("target_resource_type", targetResourceType); + } List results = q.getResultList(); for (ResourceLink resourceLink : results) { if (theReverseMode) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceLink.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceLink.java index 8d45916f071..02b1db83eac 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceLink.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceLink.java @@ -36,6 +36,7 @@ import javax.persistence.Table; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.hibernate.annotations.ColumnDefault; import org.hibernate.search.annotations.Field; @Entity @@ -64,6 +65,11 @@ public class ResourceLink implements Serializable { @Column(name = "SRC_RESOURCE_ID", insertable = false, updatable = false, nullable = false) private Long mySourceResourcePid; + @Column(name = "SOURCE_RESOURCE_TYPE", nullable=false, length=ResourceTable.RESTYPE_LEN) + @ColumnDefault("''") // TODO: remove this (it's only here for simplifying upgrades of 1.3 -> 1.4) + @Field() + private String mySourceResourceType; + @ManyToOne(optional = false, fetch=FetchType.LAZY) @JoinColumn(name = "TARGET_RESOURCE_ID", referencedColumnName = "RES_ID", nullable = false) private ResourceTable myTargetResource; @@ -71,18 +77,21 @@ public class ResourceLink implements Serializable { @Column(name = "TARGET_RESOURCE_ID", insertable = false, updatable = false, nullable = false) @Field() private Long myTargetResourcePid; - + + @Column(name = "TARGET_RESOURCE_TYPE", nullable=false, length=ResourceTable.RESTYPE_LEN) + @ColumnDefault("''") // TODO: remove this (it's only here for simplifying upgrades of 1.3 -> 1.4) + @Field() + private String myTargetResourceType; + public ResourceLink() { super(); } public ResourceLink(String theSourcePath, ResourceTable theSourceResource, ResourceTable theTargetResource) { super(); - mySourcePath = theSourcePath; - mySourceResource = theSourceResource; - mySourceResourcePid = theSourceResource.getId(); - myTargetResource = theTargetResource; - myTargetResourcePid = theTargetResource.getId(); + setSourcePath(theSourcePath); + setSourceResource(theSourceResource); + setTargetResource(theTargetResource); } @Override @@ -140,12 +149,14 @@ public class ResourceLink implements Serializable { public void setSourceResource(ResourceTable theSourceResource) { mySourceResource = theSourceResource; mySourceResourcePid = theSourceResource.getId(); + mySourceResourceType = theSourceResource.getResourceType(); } public void setTargetResource(ResourceTable theTargetResource) { Validate.notNull(theTargetResource); myTargetResource = theTargetResource; myTargetResourcePid = theTargetResource.getId(); + myTargetResourceType = theTargetResource.getResourceType(); } @Override diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index e1010cd45eb..03820122be1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -1462,6 +1462,13 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { patientId2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); } + { + // Typed include + SearchParameterMap params = new SearchParameterMap(); + params.addInclude(Patient.INCLUDE_CAREPROVIDER.withType("Practitioner")); + List ids = toUnqualifiedVersionlessIds(myPatientDao.search(params)); + assertThat(ids, containsInAnyOrder(patientId, patientId2, practId2)); + } { // No includes SearchParameterMap params = new SearchParameterMap(); @@ -1545,13 +1552,6 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { List ids = toUnqualifiedVersionlessIds(myPatientDao.search(params)); assertThat(ids, containsInAnyOrder(orgId, patientId, patientId2, practId2)); } - { -// // Typed include -// SearchParameterMap params = new SearchParameterMap(); -// params.addInclude(Patient.INCLUDE_CAREPROVIDER.withType("Practitioner")); -// List ids = toUnqualifiedVersionlessIds(myPatientDao.search(params)); -// assertThat(ids, containsInAnyOrder(patientId, patientId2, practId2)); - } } @SuppressWarnings("unused") diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java index 8bc9e169ed6..ccbe4e00a69 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java @@ -177,6 +177,8 @@ public class IncludeTest { assertEquals("Patient:careProvider:Practitioner", new Include("Patient:careProvider", true).withType("Practitioner").getValue()); assertEquals(true, new Include("Patient:careProvider", true).withType("Practitioner").isRecurse()); assertEquals(false, new Include("Patient:careProvider:Organization", true).withType("Practitioner").isLocked()); + assertEquals("Practitioner", new Include("Patient:careProvider", true).withType("Practitioner").getParamTargetType()); + assertEquals(null, new Include("Patient:careProvider", true).getParamTargetType()); assertEquals("Patient:careProvider:Practitioner", new Include("Patient:careProvider:Organization", true).withType("Practitioner").getValue()); assertEquals(true, new Include("Patient:careProvider:Organization", true).toLocked().withType("Practitioner").isLocked()); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a467f8728ec..b6e46d48b9a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -71,6 +71,11 @@ valueString instead of valueMarkdown. After discussion with Grahame, this appears to be incorrect behaviour so it has been fixed.
    + + Support target parameter type in _include / _revinclude values, e.g. + _include=Patient:careProvider:Organization. Thanks to Joe Portner + for reporting! +
    From 60261672c1739c303af499f34e9fd7888b76068f Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 22:05:32 -0500 Subject: [PATCH 09/16] Stricter errors to try and fix travis.. --- .../src/test/java/ca/uhn/fhir/parser/JsonParserTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java index 2aba8ae130c..b9a1c60b928 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java @@ -1317,7 +1317,9 @@ public class JsonParserTest { public void testSimpleResourceEncode() throws IOException { String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); - Patient obs = ourCtx.newXmlParser().parseResource(Patient.class, xmlString); + IParser parser = ourCtx.newXmlParser(); + parser.setParserErrorHandler(new StrictErrorHandler()); + Patient obs = parser.parseResource(Patient.class, xmlString); List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions(); ExtensionDt undeclaredExtension = undeclaredExtensions.get(0); @@ -1376,8 +1378,7 @@ public class JsonParserTest { ourLog.info("Expected: {}", exp); ourLog.info("Actual : {}", act); - assertEquals(exp, act); - + assertEquals("\nExpected: " + exp + "\nActual : " + act, exp, act); } @Test From b2a9836cdab3e48c88ed1fe98c6cf5f320d8b20e Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 22:12:54 -0500 Subject: [PATCH 10/16] More logging to try and figure out the travis failures --- .../RuntimeChildUndeclaredExtensionDefinition.java | 2 +- .../src/main/java/ca/uhn/fhir/parser/ParserState.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index 2aa52514c92..b3e313a2c22 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -178,7 +178,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD * type. */ if (!qualifiedName.startsWith("ca.uhn.fhir.model")) { - if (!qualifiedName.startsWith("org.hl7.fhir.instance.model")) { + if (!qualifiedName.startsWith("org.hl7.fhir")) { continue; } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index 658918f384c..b91d8667e0a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; @@ -1731,9 +1732,10 @@ class ParserState { public void enteringNewElement(String theNamespaceUri, String theLocalPart) throws DataFormatException { BaseRuntimeElementDefinition target = myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildByName(theLocalPart); if (target == null) { - myErrorHandler.unknownElement(null, theLocalPart); - push(new SwallowChildrenWholeState(getPreResourceState())); - return; + throw new DataFormatException("Unknown " + theLocalPart + " - Valid names are: " + new TreeSet(myContext.getRuntimeChildUndeclaredExtensionDefinition().getValidChildNames())); +// myErrorHandler.unknownElement(null, theLocalPart); +// push(new SwallowChildrenWholeState(getPreResourceState())); +// return; } switch (target.getChildType()) { From 0bf5172de623fc3ed3f07a51b84ac1355ed82605 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 22:28:03 -0500 Subject: [PATCH 11/16] More travis work --- .../src/main/java/ca/uhn/fhir/context/ModelScanner.java | 6 ++++++ .../context/RuntimeChildUndeclaredExtensionDefinition.java | 7 +++++++ .../src/main/java/ca/uhn/fhir/parser/ParserState.java | 1 + 3 files changed, 14 insertions(+) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index b29e20b3829..a2f17f3c9f6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -82,6 +82,7 @@ import ca.uhn.fhir.model.base.composite.BaseContainedDt; import ca.uhn.fhir.model.base.composite.BaseNarrativeDt; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.primitive.BoundCodeDt; +import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.ICodedDatatype; import ca.uhn.fhir.model.primitive.XhtmlDt; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; @@ -193,6 +194,11 @@ class ModelScanner { myVersionTypes = scanVersionPropertyFile(theDatatypes, resourceTypes, myVersion); + // FIXME: remove + if (myVersionTypes.contains(CodeDt.class) == false) { + throw new ConfigurationException("Did not request CodeDt: " + new TreeSet>(myVersionTypes)); + } + // toScan.add(DateDt.class); // toScan.add(CodeDt.class); // toScan.add(DecimalDt.class); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index b3e313a2c22..470e613fe77 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import org.apache.commons.lang3.text.WordUtils; import org.hl7.fhir.instance.model.api.IBase; @@ -34,6 +35,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; +import ca.uhn.fhir.model.primitive.CodeDt; public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition { @@ -153,6 +155,11 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD myDatatypeToAttributeName = new HashMap, String>(); myDatatypeToDefinition = new HashMap, BaseRuntimeElementDefinition>(); + // FIXME: remove + if (theClassToElementDefinitions.containsKey(CodeDt.class) == false) { + throw new ConfigurationException("Did not request CodeDt: " + new TreeSet>(theClassToElementDefinitions.keySet())); + } + // for (theContext.get) for (BaseRuntimeElementDefinition next : theClassToElementDefinitions.values()) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index b91d8667e0a..4dc0b6ba053 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -1732,6 +1732,7 @@ class ParserState { public void enteringNewElement(String theNamespaceUri, String theLocalPart) throws DataFormatException { BaseRuntimeElementDefinition target = myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildByName(theLocalPart); if (target == null) { + //FIXME: fix this throw new DataFormatException("Unknown " + theLocalPart + " - Valid names are: " + new TreeSet(myContext.getRuntimeChildUndeclaredExtensionDefinition().getValidChildNames())); // myErrorHandler.unknownElement(null, theLocalPart); // push(new SwallowChildrenWholeState(getPreResourceState())); From c8535b72b6af978bf6fd1fa9a5261f9493b5b9b1 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 22:34:53 -0500 Subject: [PATCH 12/16] More travis --- .../src/main/java/ca/uhn/fhir/context/ModelScanner.java | 3 ++- .../context/RuntimeChildUndeclaredExtensionDefinition.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index a2f17f3c9f6..2c6a90f1537 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -34,6 +34,7 @@ import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -196,7 +197,7 @@ class ModelScanner { // FIXME: remove if (myVersionTypes.contains(CodeDt.class) == false) { - throw new ConfigurationException("Did not request CodeDt: " + new TreeSet>(myVersionTypes)); + throw new ConfigurationException("Did not request CodeDt: " + myVersionTypes); } // toScan.add(DateDt.class); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index 470e613fe77..a6133c704ef 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -157,7 +157,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD // FIXME: remove if (theClassToElementDefinitions.containsKey(CodeDt.class) == false) { - throw new ConfigurationException("Did not request CodeDt: " + new TreeSet>(theClassToElementDefinitions.keySet())); + throw new ConfigurationException("Did not request CodeDt: " + (theClassToElementDefinitions.keySet())); } // for (theContext.get) From 2b0a800d98c758b16c99d8e5f2fc07f6dcd159ec Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 22:44:05 -0500 Subject: [PATCH 13/16] travis.... --- .../src/main/java/ca/uhn/fhir/context/ModelScanner.java | 7 ++++++- .../context/RuntimeChildUndeclaredExtensionDefinition.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index 2c6a90f1537..3555e6e816b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -48,6 +48,7 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import org.apache.commons.io.IOUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; @@ -197,7 +198,11 @@ class ModelScanner { // FIXME: remove if (myVersionTypes.contains(CodeDt.class) == false) { - throw new ConfigurationException("Did not request CodeDt: " + myVersionTypes); + try { + throw new ConfigurationException("Did not request CodeDt1: " + myVersionTypes + "\ndatatypes: " + theDatatypes + "\n\n" + IOUtils.toString(myVersion.getVersionImplementation().getFhirVersionPropertiesFile())); + } catch (IOException e) { + throw new ConfigurationException("FAILED: " + e.toString()); + } } // toScan.add(DateDt.class); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index a6133c704ef..363f9d66c14 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -157,7 +157,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD // FIXME: remove if (theClassToElementDefinitions.containsKey(CodeDt.class) == false) { - throw new ConfigurationException("Did not request CodeDt: " + (theClassToElementDefinitions.keySet())); + throw new ConfigurationException("Did not request CodeDt2: " + (theClassToElementDefinitions.keySet())); } // for (theContext.get) From 2fd135736379044c2aa7673e79840a472603d640 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 14 Dec 2015 22:58:47 -0500 Subject: [PATCH 14/16] More travis --- .../tinder/parser/DatatypeGeneratorUsingSpreadsheet.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/DatatypeGeneratorUsingSpreadsheet.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/DatatypeGeneratorUsingSpreadsheet.java index f4fef323e24..462f3a41082 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/DatatypeGeneratorUsingSpreadsheet.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/DatatypeGeneratorUsingSpreadsheet.java @@ -68,7 +68,9 @@ public class DatatypeGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP for (ClassInfo classInfo : tlc) { DatatypeDef def = Class.forName(classInfo.getName()).getAnnotation(DatatypeDef.class); if (def != null) { - getNameToDatatypeClass().put(def.name(), classInfo.getName()); + if (classInfo.getName().contains("Bound") == false) { + getNameToDatatypeClass().put(def.name(), classInfo.getName()); + } } } } catch (IOException e) { @@ -82,7 +84,9 @@ public class DatatypeGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP for (ClassInfo classInfo : tlc) { DatatypeDef def = Class.forName(classInfo.getName()).getAnnotation(DatatypeDef.class); if (def != null) { - getNameToDatatypeClass().put(def.name(), classInfo.getName()); + if (classInfo.getName().contains("Bound") == false) { + getNameToDatatypeClass().put(def.name(), classInfo.getName()); + } } } } catch (IOException e) { From 22ff1db183bdc1eac85e38f3a73263254dd2ffe8 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 15 Dec 2015 07:14:21 -0500 Subject: [PATCH 15/16] Work on tests --- .../java/ca/uhn/fhir/context/ModelScanner.java | 12 ------------ ...untimeChildUndeclaredExtensionDefinition.java | 16 ---------------- .../ca/uhn/fhir/narrative/narratives.properties | 3 +++ .../ca/uhn/fhir/parser/XmlParserDstu2Test.java | 6 +++--- 4 files changed, 6 insertions(+), 31 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index 3555e6e816b..69dbb5f9f5b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -34,7 +34,6 @@ import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -48,7 +47,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -import org.apache.commons.io.IOUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; @@ -84,7 +82,6 @@ import ca.uhn.fhir.model.base.composite.BaseContainedDt; import ca.uhn.fhir.model.base.composite.BaseNarrativeDt; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.primitive.BoundCodeDt; -import ca.uhn.fhir.model.primitive.CodeDt; import ca.uhn.fhir.model.primitive.ICodedDatatype; import ca.uhn.fhir.model.primitive.XhtmlDt; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; @@ -195,15 +192,6 @@ class ModelScanner { Map> resourceTypes = myNameToResourceType; myVersionTypes = scanVersionPropertyFile(theDatatypes, resourceTypes, myVersion); - - // FIXME: remove - if (myVersionTypes.contains(CodeDt.class) == false) { - try { - throw new ConfigurationException("Did not request CodeDt1: " + myVersionTypes + "\ndatatypes: " + theDatatypes + "\n\n" + IOUtils.toString(myVersion.getVersionImplementation().getFhirVersionPropertiesFile())); - } catch (IOException e) { - throw new ConfigurationException("FAILED: " + e.toString()); - } - } // toScan.add(DateDt.class); // toScan.add(CodeDt.class); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index 363f9d66c14..c9da31aaf5c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -155,18 +155,8 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD myDatatypeToAttributeName = new HashMap, String>(); myDatatypeToDefinition = new HashMap, BaseRuntimeElementDefinition>(); - // FIXME: remove - if (theClassToElementDefinitions.containsKey(CodeDt.class) == false) { - throw new ConfigurationException("Did not request CodeDt2: " + (theClassToElementDefinitions.keySet())); - } - -// for (theContext.get) - for (BaseRuntimeElementDefinition next : theClassToElementDefinitions.values()) { if (next instanceof IRuntimeDatatypeDefinition) { - // if (next.getName().equals("CodeableConcept")) { - // System.out.println(); - // } myDatatypeToDefinition.put(next.getImplementingClass(), next); @@ -205,12 +195,6 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD myAttributeNameToDefinition = datatypeAttributeNameToDefinition; -// for (Entry> next : myAttributeNameToDefinition.entrySet()) { -// @SuppressWarnings("unchecked") -// Class type = (Class) next.getValue().getImplementingClass(); -// myDatatypeToDefinition.put(type, next.getValue()); -// } - /* * Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1 */ diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties index 7c720eeea08..13cf6b32f7e 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties @@ -67,6 +67,9 @@ patient.title=classpath:ca/uhn/fhir/narrative/title/Patient.html medicationprescription.class=ca.uhn.fhir.model.dstu.resource.MedicationPrescription medicationprescription.narrative=classpath:ca/uhn/fhir/narrative/MedicationPrescription.html medicationprescription.title=classpath:ca/uhn/fhir/narrative/title/MedicationPrescription.html +medicationorder.class=ca.uhn.fhir.model.dstu2.resource.MedicationOrder +medicationorder.narrative=classpath:ca/uhn/fhir/narrative/MedicationPrescription.html +medicationorder.title=classpath:ca/uhn/fhir/narrative/title/MedicationPrescription.html medication.class=ca.uhn.fhir.model.dstu.resource.Medication medication.narrative=classpath:ca/uhn/fhir/narrative/Medication.html diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java index 2000571c53c..d59dd49af22 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java @@ -564,7 +564,7 @@ public class XmlParserDstu2Test { } /** - * Test for #233 + * Test for #233 - This was reversed after a conversation with Grahame */ @Test public void testEncodeAndParseProfiledDatatype() { @@ -572,7 +572,7 @@ public class XmlParserDstu2Test { mo.addDosageInstruction().getTiming().getRepeat().setBounds(new DurationDt().setCode("code")); String out = ourCtx.newXmlParser().encodeResourceToString(mo); ourLog.info(out); - assertThat(out, containsString("")); + assertThat(out, containsString("")); mo = ourCtx.newXmlParser().parseResource(MedicationOrder.class, out); DurationDt duration = (DurationDt) mo.getDosageInstruction().get(0).getTiming().getRepeat().getBounds(); @@ -592,7 +592,7 @@ public class XmlParserDstu2Test { assertEquals("1", q.getValueElement().getValueAsString()); String output = xmlParser.encodeResourceToString(ms); - assertThat(output, containsString("")); + assertThat(output, containsString("")); } @Test From 3005c9a7667fdfa8dc1a3366e361f4f74fe33626 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 15 Dec 2015 09:11:01 -0500 Subject: [PATCH 16/16] Still working on unit tests --- .../src/main/java/ca/uhn/fhir/parser/ParserState.java | 8 +++----- .../resources/ca/uhn/fhir/narrative/narratives.properties | 3 --- .../test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java | 3 +++ .../DefaultThymeleafNarrativeGeneratorTestDstu2.java | 2 ++ .../test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java | 4 ++++ .../ca/uhn/fhir/rest/client/GenericClientDstu2Test.java | 2 +- hapi-fhir-structures-hl7org-dstu2/pom.xml | 2 +- .../java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java | 6 ++++-- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index 4dc0b6ba053..d4445b09910 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -1732,11 +1732,9 @@ class ParserState { public void enteringNewElement(String theNamespaceUri, String theLocalPart) throws DataFormatException { BaseRuntimeElementDefinition target = myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildByName(theLocalPart); if (target == null) { - //FIXME: fix this - throw new DataFormatException("Unknown " + theLocalPart + " - Valid names are: " + new TreeSet(myContext.getRuntimeChildUndeclaredExtensionDefinition().getValidChildNames())); -// myErrorHandler.unknownElement(null, theLocalPart); -// push(new SwallowChildrenWholeState(getPreResourceState())); -// return; + myErrorHandler.unknownElement(null, theLocalPart); + push(new SwallowChildrenWholeState(getPreResourceState())); + return; } switch (target.getChildType()) { diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties index 13cf6b32f7e..7c720eeea08 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties @@ -67,9 +67,6 @@ patient.title=classpath:ca/uhn/fhir/narrative/title/Patient.html medicationprescription.class=ca.uhn.fhir.model.dstu.resource.MedicationPrescription medicationprescription.narrative=classpath:ca/uhn/fhir/narrative/MedicationPrescription.html medicationprescription.title=classpath:ca/uhn/fhir/narrative/title/MedicationPrescription.html -medicationorder.class=ca.uhn.fhir.model.dstu2.resource.MedicationOrder -medicationorder.narrative=classpath:ca/uhn/fhir/narrative/MedicationPrescription.html -medicationorder.title=classpath:ca/uhn/fhir/narrative/title/MedicationPrescription.html medication.class=ca.uhn.fhir.model.dstu.resource.Medication medication.narrative=classpath:ca/uhn/fhir/narrative/Medication.html diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java index 4c22561ba96..2980a023bd2 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu21Test.java @@ -520,8 +520,11 @@ public class XmlParserDstu21Test { /** * Test for #233 + * + * This was rolled back after a conversation with grahame */ @Test + @Ignore public void testEncodeAndParseProfiledDatatype() { MedicationOrder mo = new MedicationOrder(); mo.addDosageInstruction().getTiming().getRepeat().setBounds(new DurationDt().setCode("code")); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java index 5417f9b0e41..e978ace5a8c 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java @@ -9,6 +9,7 @@ import java.util.Date; import org.hamcrest.core.StringContains; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -195,6 +196,7 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 { } @Test + @Ignore public void testGenerateMedicationPrescription() { MedicationOrder mp = new MedicationOrder(); mp.setId("12345"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java index d59dd49af22..20f9803b44a 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java @@ -32,6 +32,7 @@ import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -581,8 +582,11 @@ public class XmlParserDstu2Test { /** * See #216 - Profiled datatypes should use their unprofiled parent type as the choice[x] name + * + * Disabled because we reverted this change after a conversation with Grahame */ @Test + @Ignore public void testEncodeAndParseProfiledDatatypeChoice() throws Exception { IParser xmlParser = ourCtx.newXmlParser(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java index 9a106f8d5aa..fd9383f26f0 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java @@ -1143,7 +1143,7 @@ public class GenericClientDstu2Test { assertEquals("http://example.com/fhir/Patient/1/$validate-code", capt.getAllValues().get(idx).getURI().toASCIIString()); ourLog.info(extractBody(capt, idx)); - assertEquals("",extractBody(capt, idx)); + assertEquals("",extractBody(capt, idx)); } diff --git a/hapi-fhir-structures-hl7org-dstu2/pom.xml b/hapi-fhir-structures-hl7org-dstu2/pom.xml index 02ca6fc4f6f..fddc434d616 100644 --- a/hapi-fhir-structures-hl7org-dstu2/pom.xml +++ b/hapi-fhir-structures-hl7org-dstu2/pom.xml @@ -182,7 +182,7 @@ maven-surefire-plugin 2.19 - false + true random -Dfile.encoding=UTF-8 false diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java index 89a36a392d4..755e8e6cd6a 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java @@ -26,7 +26,6 @@ import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.Address; -import org.hl7.fhir.instance.model.Attachment; import org.hl7.fhir.instance.model.Address.AddressUse; import org.hl7.fhir.instance.model.Address.AddressUseEnumFactory; import org.hl7.fhir.instance.model.Binary; @@ -49,7 +48,6 @@ import org.hl7.fhir.instance.model.Identifier.IdentifierUse; import org.hl7.fhir.instance.model.InstantType; import org.hl7.fhir.instance.model.MedicationStatement; import org.hl7.fhir.instance.model.Narrative.NarrativeStatus; -import org.hl7.fhir.instance.model.annotations.Child; import org.hl7.fhir.instance.model.Observation; import org.hl7.fhir.instance.model.Organization; import org.hl7.fhir.instance.model.Patient; @@ -62,6 +60,7 @@ import org.hl7.fhir.instance.model.StringType; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import org.xml.sax.SAXException; @@ -91,8 +90,11 @@ public class XmlParserHl7OrgDstu2Test { /** * See #216 - Profiled datatypes should use their unprofiled parent type as the choice[x] name + * + * Disabled after conversation with Grahame */ @Test + @Ignore public void testEncodeAndParseProfiledDatatypeChoice() throws Exception { IParser xmlParser = ourCtx.newXmlParser();