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 f3fb2e366bd..d8b55b96c26 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 @@ -909,6 +909,14 @@ public class GenericClient extends BaseClient implements IGenericClient { myCriterionList.add((ICriterionInternal) theCriterion); return this; } + + @Override + public IDeleteWithQuery resourceConditionalByType(Class theResourceType) { + Validate.notNull(theResourceType, "theResourceType can not be null"); + myCriterionList = new CriterionList(); + myResourceType = myContext.getResourceDefinition(theResourceType).getName(); + return this; + } } @SuppressWarnings({ "rawtypes", "unchecked" }) 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 464e41fa02e..6c0441897b3 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 @@ -1,5 +1,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; @@ -43,8 +44,15 @@ public interface IDelete { IDeleteTyped resourceConditionalByUrl(String theSearchUrl); /** + * Delete using a conditional/match URL. The query parameters will be added in the next part of the call chain. * @since HAPI 0.9 / FHIR DSTU 2 */ IDeleteWithQuery resourceConditionalByType(String theResourceType); + /** + * Delete using a conditional/match URL. The query parameters will be added in the next part of the call chain. + * @since HAPI 1.3 + */ + IDeleteWithQuery resourceConditionalByType(Class theResourceType); + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java index ed15bef1127..ab0a5bc377a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseException.java @@ -73,6 +73,10 @@ public abstract class BaseServerResponseException extends RuntimeException { private String myResponseMimeType; private int myStatusCode; + public static void main (String[] args) { + BaseServerResponseException.class.getName(); + } + /** * Constructor * 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 72d1a98b8c8..7b5f7002baf 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 @@ -129,6 +129,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.FhirTerser; @@ -149,6 +150,9 @@ public abstract class BaseHapiFhirResourceDao extends BaseH @Autowired private PlatformTransactionManager myPlatformTransactionManager; + @Autowired + private DaoConfig myDaoConfig; + private String myResourceName; private Class myResourceType; private String mySecondaryPrimaryKeyParamName; @@ -1309,7 +1313,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH throw new InvalidRequestException("Trying to delete " + theId + " but this is not the current version"); } - validateOkToDeleteOrThrowPreconditionFailedException(entity); + validateOkToDeleteOrThrowResourceVersionConflictException(entity); // Notify interceptors ActionRequestDetails requestDetails = new ActionRequestDetails(theId, theId.getResourceType()); @@ -1332,26 +1336,31 @@ public abstract class BaseHapiFhirResourceDao extends BaseH if (resource.isEmpty()) { throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "unableToDeleteNotFound", theUrl)); } else if (resource.size() > 1) { - throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirDao.class, "transactionOperationWithMultipleMatchFailure", "DELETE", theUrl, resource.size())); + if (myDaoConfig.isAllowMultipleDelete() == false) { + throw new PreconditionFailedException(getContext().getLocalizer().getMessage(BaseHapiFhirDao.class, "transactionOperationWithMultipleMatchFailure", "DELETE", theUrl, resource.size())); + } } - Long pid = resource.iterator().next(); - ResourceTable entity = myEntityManager.find(ResourceTable.class, pid); - - validateOkToDeleteOrThrowPreconditionFailedException(entity); - - // Notify interceptors - IdDt idToDelete = entity.getIdDt(); - ActionRequestDetails requestDetails = new ActionRequestDetails(idToDelete, idToDelete.getResourceType()); - notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); - - // Perform delete - Date updateTime = new Date(); - ResourceTable savedEntity = updateEntity(null, entity, true, updateTime, updateTime); - notifyWriteCompleted(); - - ourLog.info("Processed delete on {} in {}ms", theUrl, w.getMillisAndRestart()); - return toMethodOutcome(savedEntity, null); + for (Long pid : resource) { + ResourceTable entity = myEntityManager.find(ResourceTable.class, pid); + + validateOkToDeleteOrThrowResourceVersionConflictException(entity); + + // Notify interceptors + IdDt idToDelete = entity.getIdDt(); + ActionRequestDetails requestDetails = new ActionRequestDetails(idToDelete, idToDelete.getResourceType()); + notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails); + + // Perform delete + Date updateTime = new Date(); + updateEntity(null, entity, true, updateTime, updateTime); + notifyWriteCompleted(); + + } + + ourLog.info("Processed delete on {} (matched {} resource(s)) in {}ms", new Object[] {theUrl, resource.size(), w.getMillisAndRestart()}); + + return new DaoMethodOutcome(); } private DaoMethodOutcome doCreate(T theResource, String theIfNoneExist, boolean thePerformIndexing, Date theUpdateTime) { @@ -2512,7 +2521,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH } } - protected void validateOkToDeleteOrThrowPreconditionFailedException(ResourceTable theEntity) { + protected void validateOkToDeleteOrThrowResourceVersionConflictException(ResourceTable theEntity) { TypedQuery query = myEntityManager.createQuery("SELECT l FROM ResourceLink l WHERE l.myTargetResourcePid = :target_pid", ResourceLink.class); query.setParameter("target_pid", theEntity.getId()); query.setMaxResults(1); @@ -2526,7 +2535,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH String sourceId = link.getSourceResource().getIdDt().toUnqualifiedVersionless().getValue(); String sourcePath = link.getSourcePath(); - throw new PreconditionFailedException( + throw new ResourceVersionConflictException( "Unable to delete " + targetId + " because at least one resource has a reference to this resource. First reference found was resource " + sourceId + " in path " + sourcePath); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java index fdee1094b20..2f4ba217f2e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java @@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; public class DaoConfig { + private boolean myAllowMultipleDelete; private int myHardSearchLimit = 1000; private int myHardTagListLimit = 1000; private int myIncludeLimit = 2000; @@ -74,6 +75,14 @@ public class DaoConfig { return mySubscriptionPollDelay; } + public Long getSubscriptionPurgeInactiveAfterMillis() { + return mySubscriptionPurgeInactiveAfterMillis; + } + + public boolean isAllowMultipleDelete() { + return myAllowMultipleDelete; + } + /** * See {@link #setSubscriptionEnabled(boolean)} */ @@ -81,6 +90,10 @@ public class DaoConfig { return mySubscriptionEnabled; } + public void setAllowMultipleDelete(boolean theAllowMultipleDelete) { + myAllowMultipleDelete = theAllowMultipleDelete; + } + public void setHardSearchLimit(int theHardSearchLimit) { myHardSearchLimit = theHardSearchLimit; } @@ -144,10 +157,6 @@ public class DaoConfig { mySubscriptionPollDelay = theSubscriptionPollDelay; } - public void setSubscriptionPurgeInactiveAfterSeconds(int theSeconds) { - setSubscriptionPurgeInactiveAfterMillis(theSeconds * DateUtils.MILLIS_PER_SECOND); - } - public void setSubscriptionPurgeInactiveAfterMillis(Long theMillis) { if (theMillis != null) { Validate.exclusiveBetween(0, Long.MAX_VALUE, theMillis); @@ -155,8 +164,8 @@ public class DaoConfig { mySubscriptionPurgeInactiveAfterMillis = theMillis; } - public Long getSubscriptionPurgeInactiveAfterMillis() { - return mySubscriptionPurgeInactiveAfterMillis; + public void setSubscriptionPurgeInactiveAfterSeconds(int theSeconds) { + setSubscriptionPurgeInactiveAfterMillis(theSeconds * DateUtils.MILLIS_PER_SECOND); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java index bb439a260b5..6a94380b24b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2.java @@ -49,6 +49,7 @@ import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.validation.DefaultProfileValidationSupport; @@ -105,11 +106,11 @@ public class FhirResourceDaoDstu2 extends BaseHapiFhirResou final ResourceTable entity = readEntityLatestVersion(theId); OperationOutcome oo = new OperationOutcome(); try { - validateOkToDeleteOrThrowPreconditionFailedException(entity); + validateOkToDeleteOrThrowResourceVersionConflictException(entity); oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Ok to delete"); - } catch (PreconditionFailedException e) { + } catch (ResourceVersionConflictException e) { oo.addIssue().setSeverity(IssueSeverityEnum.ERROR).setDiagnostics(e.getMessage()); - throw new PreconditionFailedException(e.getMessage(), oo); + throw new ResourceVersionConflictException(e.getMessage(), oo); } return new MethodOutcome(new IdDt(theId.getValue()), oo); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProviderDstu2.java index 318bb8e52a1..ec77e43dc58 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProviderDstu2.java @@ -28,12 +28,14 @@ import javax.servlet.http.HttpServletRequest; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResourceSearchParam; +import ca.uhn.fhir.model.dstu2.valueset.ConditionalDeleteStatusEnum; import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.SearchParamTypeEnum; import ca.uhn.fhir.model.primitive.BoundCodeDt; @@ -48,11 +50,13 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider { private IFhirSystemDao mySystemDao; private volatile Conformance myCachedValue; private RestfulServer myRestfulServer; + private DaoConfig myDaoConfig; - public JpaConformanceProviderDstu2(RestfulServer theRestfulServer, IFhirSystemDao theSystemDao) { + public JpaConformanceProviderDstu2(RestfulServer theRestfulServer, IFhirSystemDao theSystemDao, DaoConfig theDaoConfig) { super(theRestfulServer); myRestfulServer = theRestfulServer; mySystemDao = theSystemDao; + myDaoConfig = theDaoConfig; super.setCache(false); } @@ -63,17 +67,23 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider { Map counts = mySystemDao.getResourceCounts(); FhirContext ctx = myRestfulServer.getFhirContext(); - + retVal = super.getServerConformance(theRequest); for (Rest nextRest : retVal.getRest()) { + for (RestResource nextResource : nextRest.getResource()) { + ConditionalDeleteStatusEnum conditionalDelete = nextResource.getConditionalDeleteElement().getValueAsEnum(); + if (conditionalDelete == ConditionalDeleteStatusEnum.MULTIPLE_DELETES_SUPPORTED && myDaoConfig.isAllowMultipleDelete() == false) { + nextResource.setConditionalDelete(ConditionalDeleteStatusEnum.SINGLE_DELETES_SUPPORTED); + } + // Add resource counts Long count = counts.get(nextResource.getTypeElement().getValueAsString()); if (count != null) { nextResource.addUndeclaredExtension(false, ExtensionConstants.CONF_RESOURCE_COUNT, new DecimalDt(count)); } - + // Add chained params for (RestResourceSearchParam nextParam : nextResource.getSearchParam()) { if (nextParam.getTypeElement().getValueAsEnum() == SearchParamTypeEnum.REFERENCE) { @@ -86,7 +96,7 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider { } } } - + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java index cb14c240d7b..73bd3e45bcf 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaResourceProviderDstu2.java @@ -69,8 +69,8 @@ public class JpaResourceProviderDstu2 extends BaseJpaResour } } - @Delete - public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam String theConditional) { + @Delete() + public MethodOutcome delete(HttpServletRequest theRequest, @IdParam IdDt theResource, @ConditionalUrlParam(supportsMultiple=true) String theConditional) { startRequest(theRequest); try { if (theConditional != null) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java index c30151deee2..508eac46eb2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java @@ -97,6 +97,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; @@ -683,7 +684,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { try { myOrganizationDao.delete(orgId); fail(); - } catch (PreconditionFailedException e) { + } catch (ResourceVersionConflictException e) { assertThat(e.getMessage(), containsString("Unable to delete Organization/" + orgId.getIdPart() + " because at least one resource has a reference to this resource. First reference found was resource Patient/" + patId.getIdPart() + " in path Patient.managingOrganization")); } @@ -839,6 +840,8 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } + + @Test public void testHistoryByForcedId() { IIdType idv1; @@ -2088,21 +2091,21 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { pm = new SearchParameterMap(); pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName)); - pm.setSort(new SortSpec(Patient.SP_RES_ID)); + pm.setSort(new SortSpec(BaseResource.SP_RES_ID)); actual = toUnqualifiedVersionlessIds(myPatientDao.search(pm)); assertEquals(5, actual.size()); assertThat(actual, contains(idMethodName, id1, id2, id3, id4)); pm = new SearchParameterMap(); pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName)); - pm.setSort(new SortSpec(Patient.SP_RES_ID).setOrder(SortOrderEnum.ASC)); + pm.setSort(new SortSpec(BaseResource.SP_RES_ID).setOrder(SortOrderEnum.ASC)); actual = toUnqualifiedVersionlessIds(myPatientDao.search(pm)); assertEquals(5, actual.size()); assertThat(actual, contains(idMethodName, id1, id2, id3, id4)); pm = new SearchParameterMap(); pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName)); - pm.setSort(new SortSpec(Patient.SP_RES_ID).setOrder(SortOrderEnum.DESC)); + pm.setSort(new SortSpec(BaseResource.SP_RES_ID).setOrder(SortOrderEnum.DESC)); actual = toUnqualifiedVersionlessIds(myPatientDao.search(pm)); assertEquals(5, actual.size()); assertThat(actual, contains(id4, id3, id2, id1, idMethodName)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2ValidateTest.java index 7e326e609e3..abac25951e7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2ValidateTest.java @@ -25,6 +25,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2ValidateTest.class); @@ -141,9 +142,9 @@ public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { OperationOutcome outcome=null; try { - myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null); - fail(); - } catch (PreconditionFailedException e) { + myOrganizationDao.validate(null, orgId, null, null, ValidationModeEnum.DELETE, null); + fail(); + } catch (ResourceVersionConflictException e) { outcome= (OperationOutcome) e.getOperationOutcome(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java index 2027d7037ba..b50c92ffc20 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java @@ -671,7 +671,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2Test { try { mySystemDao.transaction(request); fail(); - } catch (ResourceNotFoundException e) { + } catch (PreconditionFailedException e) { assertThat(e.getMessage(), containsString("resource with match URL \"Patient?")); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java index 5d07d6b2e11..10f421d97a2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java @@ -101,7 +101,7 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { restServer.setPlainProviders(mySystemProvider); - JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(restServer, mySystemDao); + JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(restServer, mySystemDao, myDaoConfig); confProvider.setImplementationDescription("THIS IS THE DESC"); restServer.setServerConformanceProvider(confProvider); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index 1fc1dd02490..b787eaf4a5f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -91,6 +91,8 @@ import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { @@ -99,6 +101,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { // private static JpaConformanceProvider ourConfProvider; + @Override + public void before() throws Exception { + super.before(); + + myDaoConfig.setAllowMultipleDelete(true); + } + private void checkParamMissing(String paramName) throws IOException, ClientProtocolException { HttpGet get = new HttpGet(ourServerBase + "/Observation?" + paramName + ":missing=false"); CloseableHttpResponse resp = ourHttpClient.execute(get); @@ -106,6 +115,60 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { assertEquals(200, resp.getStatusLine().getStatusCode()); } + @Test + public void testBundleCreate() throws Exception { + IGenericClient client = ourClient; + + String resBody = IOUtils.toString(ResourceProviderDstu2Test.class.getResource("/document-father.json")); + IIdType id = client.create().resource(resBody).execute().getId(); + + ourLog.info("Created: {}", id); + + ca.uhn.fhir.model.dstu2.resource.Bundle bundle = client.read().resource(ca.uhn.fhir.model.dstu2.resource.Bundle.class).withId(id).execute(); + + ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); + } + + @Test + public void testBundleCreateWithTypeTransaction() throws Exception { + IGenericClient client = ourClient; + + String resBody = IOUtils.toString(ResourceProviderDstu2Test.class.getResource("/document-father.json")); + resBody = resBody.replace("\"type\": \"document\"", "\"type\": \"transaction\""); + try { + client.create().resource(resBody).execute().getId(); + fail(); + } catch (UnprocessableEntityException e) { + assertThat(e.getMessage(), containsString("Unable to store a Bundle resource on this server with a Bundle.type value other than 'document' - Value was: transaction")); + } + } + + + // private void delete(String theResourceType, String theParamName, String theParamValue) { + // Bundle resources; + // do { + // IQuery forResource = ourClient.search().forResource(theResourceType); + // if (theParamName != null) { + // forResource = forResource.where(new StringClientParam(theParamName).matches().value(theParamValue)); + // } + // resources = forResource.execute(); + // for (IResource next : resources.toListOfResources()) { + // ourLog.info("Deleting resource: {}", next.getId()); + // ourClient.delete().resource(next).execute(); + // } + // } while (resources.size() > 0); + // } + // + // private void deleteToken(String theResourceType, String theParamName, String theParamSystem, String theParamValue) + // { + // Bundle resources = ourClient.search().forResource(theResourceType).where(new + // TokenClientParam(theParamName).exactly().systemAndCode(theParamSystem, theParamValue)).execute(); + // for (IResource next : resources.toListOfResources()) { + // ourLog.info("Deleting resource: {}", next.getId()); + // ourClient.delete().resource(next).execute(); + // } + // } + @Test public void testCodeSearch() { Subscription subs = new Subscription(); @@ -152,87 +215,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } - - // private void delete(String theResourceType, String theParamName, String theParamValue) { - // Bundle resources; - // do { - // IQuery forResource = ourClient.search().forResource(theResourceType); - // if (theParamName != null) { - // forResource = forResource.where(new StringClientParam(theParamName).matches().value(theParamValue)); - // } - // resources = forResource.execute(); - // for (IResource next : resources.toListOfResources()) { - // ourLog.info("Deleting resource: {}", next.getId()); - // ourClient.delete().resource(next).execute(); - // } - // } while (resources.size() > 0); - // } - // - // private void deleteToken(String theResourceType, String theParamName, String theParamSystem, String theParamValue) - // { - // Bundle resources = ourClient.search().forResource(theResourceType).where(new - // TokenClientParam(theParamName).exactly().systemAndCode(theParamSystem, theParamValue)).execute(); - // for (IResource next : resources.toListOfResources()) { - // ourLog.info("Deleting resource: {}", next.getId()); - // ourClient.delete().resource(next).execute(); - // } - // } - - @Test - public void testSearchByIdOr() { - IIdType id1; - { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("urn:system").setValue("001"); - id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); - } - IIdType id2; - { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("urn:system").setValue("001"); - id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); - } - - //@formatter:off - Bundle found = ourClient - .search() - .forResource(Patient.class) - .where(Patient.RES_ID.matches().values(id1.getIdPart(), id2.getIdPart())) - .and(Patient.RES_ID.matches().value(id1.getIdPart())) - .execute(); - //@formatter:on - - assertThat(toIdListUnqualifiedVersionless(found), containsInAnyOrder(id1)); - } - - @Test - public void testBundleCreate() throws Exception { - IGenericClient client = ourClient; - - String resBody = IOUtils.toString(ResourceProviderDstu2Test.class.getResource("/document-father.json")); - IIdType id = client.create().resource(resBody).execute().getId(); - - ourLog.info("Created: {}", id); - - ca.uhn.fhir.model.dstu2.resource.Bundle bundle = client.read().resource(ca.uhn.fhir.model.dstu2.resource.Bundle.class).withId(id).execute(); - - ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); - } - - @Test - public void testBundleCreateWithTypeTransaction() throws Exception { - IGenericClient client = ourClient; - - String resBody = IOUtils.toString(ResourceProviderDstu2Test.class.getResource("/document-father.json")); - resBody = resBody.replace("\"type\": \"document\"", "\"type\": \"transaction\""); - try { - client.create().resource(resBody).execute().getId(); - fail(); - } catch (UnprocessableEntityException e) { - assertThat(e.getMessage(), containsString("Unable to store a Bundle resource on this server with a Bundle.type value other than 'document' - Value was: transaction")); - } - } - @Test public void testCountParam() throws Exception { // NB this does not get used- The paging provider has its own limits built in @@ -256,19 +238,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } - @Test - public void testCreateWithForcedId() throws IOException { - String methodName = "testCreateWithForcedId"; - - Patient p = new Patient(); - p.addName().addFamily(methodName); - p.setId(methodName); - - IIdType optId = ourClient.update().resource(p).execute().getId(); - assertEquals(methodName, optId.getIdPart()); - assertEquals("1", optId.getVersionIdPart()); - } - @Test public void testCreateQuestionnaireResponseWithValidation() throws IOException { ValueSet options = new ValueSet(); @@ -377,6 +346,19 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } } + @Test + public void testCreateWithForcedId() throws IOException { + String methodName = "testCreateWithForcedId"; + + Patient p = new Patient(); + p.addName().addFamily(methodName); + p.setId(methodName); + + IIdType optId = ourClient.update().resource(p).execute().getId(); + assertEquals(methodName, optId.getIdPart()); + assertEquals("1", optId.getVersionIdPart()); + } + @Test public void testDeepChaining() { Location l1 = new Location(); @@ -412,6 +394,63 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } + @Test + public void testDeleteConditionalMultiple() { + String methodName = "testDeleteConditionalMultiple"; + + myDaoConfig.setAllowMultipleDelete(false); + + Patient p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.addName().addFamily("FAM1"); + IIdType id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + + p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.addName().addFamily("FAM2"); + IIdType id2 = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + + try { + //@formatter:off + ourClient + .delete() + .resourceConditionalByType(Patient.class) + .where(Patient.IDENTIFIER.exactly().code(methodName)) + .execute(); + //@formatter:on + fail(); + } catch (PreconditionFailedException e) { + assertEquals("HTTP 412 Precondition Failed: Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources", e.getMessage()); + } + + // Not deleted yet.. + ourClient.read().resource("Patient").withId(id1).execute(); + ourClient.read().resource("Patient").withId(id2).execute(); + + myDaoConfig.setAllowMultipleDelete(true); + + //@formatter:off + ourClient + .delete() + .resourceConditionalByType(Patient.class) + .where(Patient.IDENTIFIER.exactly().code(methodName)) + .execute(); + //@formatter:on + + try { + ourClient.read().resource("Patient").withId(id1).execute(); + fail(); + } catch (ResourceGoneException e) { + // good + } + try { + ourClient.read().resource("Patient").withId(id2).execute(); + fail(); + } catch (ResourceGoneException e) { + // good + } + } + @Test public void testDeleteInvalidReference() throws IOException { HttpDelete delete = new HttpDelete(ourServerBase + "/Patient"); @@ -425,7 +464,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { response.close(); } } - + @Test public void testDeleteResourceConditional1() throws IOException { String methodName = "testDeleteResourceConditional1"; @@ -465,7 +504,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } } - + /** * Based on email from Rene Spronk */ @@ -592,300 +631,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } - /** - * See #147 - */ - @Test - public void testEverythingPatientDoesntRepeatPatient() throws Exception { - ca.uhn.fhir.model.dstu2.resource.Bundle b; - b = myFhirCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/bug147-bundle.json"))); - - ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute(); - List ids = new ArrayList(); - for (Entry next : resp.getEntry()) { - IdDt toAdd = new IdDt(next.getResponse().getLocation()).toUnqualifiedVersionless(); - ids.add(toAdd); - } - ourLog.info("Created: " + ids.toString()); - - IdDt patientId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); - assertEquals("Patient", patientId.getResourceType()); - - { - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); - b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); - - ids = new ArrayList(); - boolean dupes = false; - for (Entry next : b.getEntry()) { - IdDt toAdd = next.getResource().getId().toUnqualifiedVersionless(); - dupes = dupes | ids.contains(toAdd); - ids.add(toAdd); - } - ourLog.info("$everything: " + ids.toString()); - - assertFalse(ids.toString(), dupes); - } - - /* - * Now try with a size specified - */ - { - Parameters input = new Parameters(); - input.addParameter().setName(Constants.PARAM_COUNT).setValue(new UnsignedIntDt(100)); - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withParameters(input).execute(); - b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); - - ids = new ArrayList(); - boolean dupes = false; - for (Entry next : b.getEntry()) { - IdDt toAdd = next.getResource().getId().toUnqualifiedVersionless(); - dupes = dupes | ids.contains(toAdd); - ids.add(toAdd); - } - ourLog.info("$everything: " + ids.toString()); - - assertFalse(ids.toString(), dupes); - assertThat(ids.toString(), containsString("Condition")); - assertThat(ids.size(), greaterThan(10)); - } - } - - @Test - public void testEverythingPatientWithLastUpdatedAndSort() throws Exception { - String methodName = "testEverythingWithLastUpdatedAndSort"; - - Organization org = new Organization(); - org.setName(methodName); - IIdType oId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); - - long time1 = System.currentTimeMillis(); - Thread.sleep(10); - - Patient p = new Patient(); - p.addName().addFamily(methodName); - p.getManagingOrganization().setReference(oId); - IIdType pId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); - - long time2 = System.currentTimeMillis(); - Thread.sleep(10); - - Condition c = new Condition(); - c.getCode().setText(methodName); - c.getPatient().setReference(pId); - IIdType cId = ourClient.create().resource(c).execute().getId().toUnqualifiedVersionless(); - - Thread.sleep(10); - long time3 = System.currentTimeMillis(); - - // %3E=> %3C=< - - HttpGet get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time1)).getValueAsString()); - CloseableHttpResponse response = ourHttpClient.execute(get); - try { - assertEquals(200, response.getStatusLine().getStatusCode()); - String output = IOUtils.toString(response.getEntity().getContent()); - IOUtils.closeQuietly(response.getEntity().getContent()); - ourLog.info(output); - List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); - ourLog.info(ids.toString()); - assertThat(ids, containsInAnyOrder(pId, cId)); - } finally { - response.close(); - } - - get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time2)).getValueAsString() + "&_lastUpdated=%3C" + new InstantDt(new Date(time3)).getValueAsString()); - response = ourHttpClient.execute(get); - try { - assertEquals(200, response.getStatusLine().getStatusCode()); - String output = IOUtils.toString(response.getEntity().getContent()); - IOUtils.closeQuietly(response.getEntity().getContent()); - ourLog.info(output); - List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); - ourLog.info(ids.toString()); - assertThat(ids, containsInAnyOrder(cId)); - } finally { - response.close(); - } - - get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time1)).getValueAsString() + "&_sort=_lastUpdated"); - response = ourHttpClient.execute(get); - try { - assertEquals(200, response.getStatusLine().getStatusCode()); - String output = IOUtils.toString(response.getEntity().getContent()); - IOUtils.closeQuietly(response.getEntity().getContent()); - ourLog.info(output); - List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); - ourLog.info(ids.toString()); - assertThat(ids, contains(pId, cId)); - } finally { - response.close(); - } - - get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_sort:desc=_lastUpdated"); - response = ourHttpClient.execute(get); - try { - assertEquals(200, response.getStatusLine().getStatusCode()); - String output = IOUtils.toString(response.getEntity().getContent()); - IOUtils.closeQuietly(response.getEntity().getContent()); - ourLog.info(output); - List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); - ourLog.info(ids.toString()); - assertThat(ids, contains(cId, pId, oId)); - } finally { - response.close(); - } - - } - - /** - * See #148 - */ - @Test - public void testEverythingPatientIncludesCondition() throws Exception { - ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle(); - Patient p = new Patient(); - p.setId("1"); - b.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.POST); - - Condition c = new Condition(); - c.getPatient().setReference("Patient/1"); - b.addEntry().setResource(c).getRequest().setMethod(HTTPVerbEnum.POST); - - ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute(); - - ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp)); - - IdDt patientId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); - assertEquals("Patient", patientId.getResourceType()); - - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); - b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); - - List ids = new ArrayList(); - for (Entry next : b.getEntry()) { - IdDt toAdd = next.getResource().getId().toUnqualifiedVersionless(); - ids.add(toAdd); - } - - assertThat(ids.toString(), containsString("Patient/")); - assertThat(ids.toString(), containsString("Condition/")); - - } - - @Test - public void testEverythingPatientType() throws Exception { - String methodName = "testEverythingPatientType"; - - Organization o1 = new Organization(); - o1.setName(methodName+"1"); - IIdType o1Id = ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); - Organization o2 = new Organization(); - o2.setName(methodName+"2"); - IIdType o2Id = ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); - - Patient p1 = new Patient(); - p1.addName().addFamily(methodName+"1"); - p1.getManagingOrganization().setReference(o1Id); - IIdType p1Id = ourClient.create().resource(p1).execute().getId().toUnqualifiedVersionless(); - Patient p2 = new Patient(); - p2.addName().addFamily(methodName+"2"); - p2.getManagingOrganization().setReference(o2Id); - IIdType p2Id = ourClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); - - Condition c1 = new Condition(); - c1.getPatient().setReference(p1Id); - IIdType c1Id = ourClient.create().resource(c1).execute().getId().toUnqualifiedVersionless(); - Condition c2 = new Condition(); - c2.getPatient().setReference(p2Id); - IIdType c2Id = ourClient.create().resource(c2).execute().getId().toUnqualifiedVersionless(); - - Condition c3 = new Condition(); - c3.addIdentifier().setValue(methodName+"3"); - IIdType c3Id = ourClient.create().resource(c3).execute().getId().toUnqualifiedVersionless(); - - Parameters output = ourClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute(); - ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); - List ids = toUnqualifiedVersionlessIds(b); - - assertThat(ids, containsInAnyOrder(o1Id, o2Id, p1Id, p2Id, c1Id, c2Id)); - assertThat(ids, not(containsInRelativeOrder(c3Id))); - } - - - - /** - * Test for #226 - */ - @Test - public void testEverythingPatientIncludesBackReferences() throws Exception { - String methodName = "testEverythingIncludesBackReferences"; - - Medication med = new Medication(); - med.getCode().setText(methodName); - IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); - - Patient pat = new Patient(); - pat.addAddress().addLine(methodName); - IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); - - MedicationOrder mo = new MedicationOrder(); - mo.getPatient().setReference(patId); - mo.setMedication(new ResourceReferenceDt(medId)); - IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); - - Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); - ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); - List ids = toUnqualifiedVersionlessIds(b); - ourLog.info(ids.toString()); - assertThat(ids, containsInAnyOrder(patId, medId, moId)); - } - - @Test - public void testEverythingPatientOperation() throws Exception { - String methodName = "testEverythingOperation"; - - Organization org1parent = new Organization(); - org1parent.setId("org1parent"); - org1parent.setName(methodName + "1parent"); - IIdType orgId1parent = ourClient.update().resource(org1parent).execute().getId().toUnqualifiedVersionless(); - - Organization org1 = new Organization(); - org1.setName(methodName + "1"); - org1.getPartOf().setReference(orgId1parent); - IIdType orgId1 = ourClient.create().resource(org1).execute().getId().toUnqualifiedVersionless(); - - Patient p = new Patient(); - p.addName().addFamily(methodName); - p.getManagingOrganization().setReference(orgId1); - IIdType patientId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); - - Organization org2 = new Organization(); - org2.setName(methodName + "1"); - IIdType orgId2 = ourClient.create().resource(org2).execute().getId().toUnqualifiedVersionless(); - - Device dev = new Device(); - dev.setModel(methodName); - dev.getOwner().setReference(orgId2); - IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); - - Observation obs = new Observation(); - obs.getSubject().setReference(patientId); - obs.getDevice().setReference(devId); - IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); - - Encounter enc = new Encounter(); - enc.getPatient().setReference(patientId); - IIdType encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); - - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); - ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); - List ids = toUnqualifiedVersionlessIds(b); - assertThat(ids, containsInAnyOrder(patientId, devId, obsId, encId, orgId1, orgId2, orgId1parent)); - - ourLog.info(ids.toString()); - } - @Test public void testEverythingEncounterInstance() throws Exception { String methodName = "testEverythingEncounterInstance"; @@ -1008,6 +753,300 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { ourLog.info(ids.toString()); } + /** + * See #147 + */ + @Test + public void testEverythingPatientDoesntRepeatPatient() throws Exception { + ca.uhn.fhir.model.dstu2.resource.Bundle b; + b = myFhirCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/bug147-bundle.json"))); + + ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute(); + List ids = new ArrayList(); + for (Entry next : resp.getEntry()) { + IdDt toAdd = new IdDt(next.getResponse().getLocation()).toUnqualifiedVersionless(); + ids.add(toAdd); + } + ourLog.info("Created: " + ids.toString()); + + IdDt patientId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); + assertEquals("Patient", patientId.getResourceType()); + + { + Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); + b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); + + ids = new ArrayList(); + boolean dupes = false; + for (Entry next : b.getEntry()) { + IdDt toAdd = next.getResource().getId().toUnqualifiedVersionless(); + dupes = dupes | ids.contains(toAdd); + ids.add(toAdd); + } + ourLog.info("$everything: " + ids.toString()); + + assertFalse(ids.toString(), dupes); + } + + /* + * Now try with a size specified + */ + { + Parameters input = new Parameters(); + input.addParameter().setName(Constants.PARAM_COUNT).setValue(new UnsignedIntDt(100)); + Parameters output = ourClient.operation().onInstance(patientId).named("everything").withParameters(input).execute(); + b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); + + ids = new ArrayList(); + boolean dupes = false; + for (Entry next : b.getEntry()) { + IdDt toAdd = next.getResource().getId().toUnqualifiedVersionless(); + dupes = dupes | ids.contains(toAdd); + ids.add(toAdd); + } + ourLog.info("$everything: " + ids.toString()); + + assertFalse(ids.toString(), dupes); + assertThat(ids.toString(), containsString("Condition")); + assertThat(ids.size(), greaterThan(10)); + } + } + + /** + * Test for #226 + */ + @Test + public void testEverythingPatientIncludesBackReferences() throws Exception { + String methodName = "testEverythingIncludesBackReferences"; + + Medication med = new Medication(); + med.getCode().setText(methodName); + IIdType medId = myMedicationDao.create(med).getId().toUnqualifiedVersionless(); + + Patient pat = new Patient(); + pat.addAddress().addLine(methodName); + IIdType patId = myPatientDao.create(pat).getId().toUnqualifiedVersionless(); + + MedicationOrder mo = new MedicationOrder(); + mo.getPatient().setReference(patId); + mo.setMedication(new ResourceReferenceDt(medId)); + IIdType moId = myMedicationOrderDao.create(mo).getId().toUnqualifiedVersionless(); + + Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); + ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); + List ids = toUnqualifiedVersionlessIds(b); + ourLog.info(ids.toString()); + assertThat(ids, containsInAnyOrder(patId, medId, moId)); + } + + /** + * See #148 + */ + @Test + public void testEverythingPatientIncludesCondition() throws Exception { + ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle(); + Patient p = new Patient(); + p.setId("1"); + b.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.POST); + + Condition c = new Condition(); + c.getPatient().setReference("Patient/1"); + b.addEntry().setResource(c).getRequest().setMethod(HTTPVerbEnum.POST); + + ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute(); + + ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp)); + + IdDt patientId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); + assertEquals("Patient", patientId.getResourceType()); + + Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); + b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); + + List ids = new ArrayList(); + for (Entry next : b.getEntry()) { + IdDt toAdd = next.getResource().getId().toUnqualifiedVersionless(); + ids.add(toAdd); + } + + assertThat(ids.toString(), containsString("Patient/")); + assertThat(ids.toString(), containsString("Condition/")); + + } + + + + @Test + public void testEverythingPatientOperation() throws Exception { + String methodName = "testEverythingOperation"; + + Organization org1parent = new Organization(); + org1parent.setId("org1parent"); + org1parent.setName(methodName + "1parent"); + IIdType orgId1parent = ourClient.update().resource(org1parent).execute().getId().toUnqualifiedVersionless(); + + Organization org1 = new Organization(); + org1.setName(methodName + "1"); + org1.getPartOf().setReference(orgId1parent); + IIdType orgId1 = ourClient.create().resource(org1).execute().getId().toUnqualifiedVersionless(); + + Patient p = new Patient(); + p.addName().addFamily(methodName); + p.getManagingOrganization().setReference(orgId1); + IIdType patientId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + + Organization org2 = new Organization(); + org2.setName(methodName + "1"); + IIdType orgId2 = ourClient.create().resource(org2).execute().getId().toUnqualifiedVersionless(); + + Device dev = new Device(); + dev.setModel(methodName); + dev.getOwner().setReference(orgId2); + IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); + + Observation obs = new Observation(); + obs.getSubject().setReference(patientId); + obs.getDevice().setReference(devId); + IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); + + Encounter enc = new Encounter(); + enc.getPatient().setReference(patientId); + IIdType encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); + + Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); + ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); + List ids = toUnqualifiedVersionlessIds(b); + assertThat(ids, containsInAnyOrder(patientId, devId, obsId, encId, orgId1, orgId2, orgId1parent)); + + ourLog.info(ids.toString()); + } + + @Test + public void testEverythingPatientType() throws Exception { + String methodName = "testEverythingPatientType"; + + Organization o1 = new Organization(); + o1.setName(methodName+"1"); + IIdType o1Id = ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); + Organization o2 = new Organization(); + o2.setName(methodName+"2"); + IIdType o2Id = ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); + + Patient p1 = new Patient(); + p1.addName().addFamily(methodName+"1"); + p1.getManagingOrganization().setReference(o1Id); + IIdType p1Id = ourClient.create().resource(p1).execute().getId().toUnqualifiedVersionless(); + Patient p2 = new Patient(); + p2.addName().addFamily(methodName+"2"); + p2.getManagingOrganization().setReference(o2Id); + IIdType p2Id = ourClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); + + Condition c1 = new Condition(); + c1.getPatient().setReference(p1Id); + IIdType c1Id = ourClient.create().resource(c1).execute().getId().toUnqualifiedVersionless(); + Condition c2 = new Condition(); + c2.getPatient().setReference(p2Id); + IIdType c2Id = ourClient.create().resource(c2).execute().getId().toUnqualifiedVersionless(); + + Condition c3 = new Condition(); + c3.addIdentifier().setValue(methodName+"3"); + IIdType c3Id = ourClient.create().resource(c3).execute().getId().toUnqualifiedVersionless(); + + Parameters output = ourClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute(); + ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource(); + List ids = toUnqualifiedVersionlessIds(b); + + assertThat(ids, containsInAnyOrder(o1Id, o2Id, p1Id, p2Id, c1Id, c2Id)); + assertThat(ids, not(containsInRelativeOrder(c3Id))); + } + + @Test + public void testEverythingPatientWithLastUpdatedAndSort() throws Exception { + String methodName = "testEverythingWithLastUpdatedAndSort"; + + Organization org = new Organization(); + org.setName(methodName); + IIdType oId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); + + long time1 = System.currentTimeMillis(); + Thread.sleep(10); + + Patient p = new Patient(); + p.addName().addFamily(methodName); + p.getManagingOrganization().setReference(oId); + IIdType pId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + + long time2 = System.currentTimeMillis(); + Thread.sleep(10); + + Condition c = new Condition(); + c.getCode().setText(methodName); + c.getPatient().setReference(pId); + IIdType cId = ourClient.create().resource(c).execute().getId().toUnqualifiedVersionless(); + + Thread.sleep(10); + long time3 = System.currentTimeMillis(); + + // %3E=> %3C=< + + HttpGet get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time1)).getValueAsString()); + CloseableHttpResponse response = ourHttpClient.execute(get); + try { + assertEquals(200, response.getStatusLine().getStatusCode()); + String output = IOUtils.toString(response.getEntity().getContent()); + IOUtils.closeQuietly(response.getEntity().getContent()); + ourLog.info(output); + List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); + ourLog.info(ids.toString()); + assertThat(ids, containsInAnyOrder(pId, cId)); + } finally { + response.close(); + } + + get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time2)).getValueAsString() + "&_lastUpdated=%3C" + new InstantDt(new Date(time3)).getValueAsString()); + response = ourHttpClient.execute(get); + try { + assertEquals(200, response.getStatusLine().getStatusCode()); + String output = IOUtils.toString(response.getEntity().getContent()); + IOUtils.closeQuietly(response.getEntity().getContent()); + ourLog.info(output); + List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); + ourLog.info(ids.toString()); + assertThat(ids, containsInAnyOrder(cId)); + } finally { + response.close(); + } + + get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time1)).getValueAsString() + "&_sort=_lastUpdated"); + response = ourHttpClient.execute(get); + try { + assertEquals(200, response.getStatusLine().getStatusCode()); + String output = IOUtils.toString(response.getEntity().getContent()); + IOUtils.closeQuietly(response.getEntity().getContent()); + ourLog.info(output); + List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); + ourLog.info(ids.toString()); + assertThat(ids, contains(pId, cId)); + } finally { + response.close(); + } + + get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_sort:desc=_lastUpdated"); + response = ourHttpClient.execute(get); + try { + assertEquals(200, response.getStatusLine().getStatusCode()); + String output = IOUtils.toString(response.getEntity().getContent()); + IOUtils.closeQuietly(response.getEntity().getContent()); + ourLog.info(output); + List ids = toIdListUnqualifiedVersionless(myFhirCtx.newXmlParser().parseBundle(output)); + ourLog.info(ids.toString()); + assertThat(ids, contains(cId, pId, oId)); + } finally { + response.close(); + } + + } + @Test public void testGetResourceCountsOperation() throws Exception { String methodName = "testMetaOperations"; @@ -1086,6 +1125,29 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } } + @Test + public void testMetaOperations() throws Exception { + String methodName = "testMetaOperations"; + + Patient pt = new Patient(); + pt.addName().addFamily(methodName); + IIdType id = ourClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); + + MetaDt meta = ourClient.meta().get(MetaDt.class).fromResource(id).execute(); + assertEquals(0, meta.getTag().size()); + + MetaDt inMeta = new MetaDt(); + inMeta.addTag().setSystem("urn:system1").setCode("urn:code1"); + meta = ourClient.meta().add().onResource(id).meta(inMeta).execute(); + assertEquals(1, meta.getTag().size()); + + inMeta = new MetaDt(); + inMeta.addTag().setSystem("urn:system1").setCode("urn:code1"); + meta = ourClient.meta().delete().onResource(id).meta(inMeta).execute(); + assertEquals(0, meta.getTag().size()); + + } + @Test public void testMetaOperationWithNoMetaParameter() throws Exception { Patient p = new Patient(); @@ -1130,29 +1192,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } - @Test - public void testMetaOperations() throws Exception { - String methodName = "testMetaOperations"; - - Patient pt = new Patient(); - pt.addName().addFamily(methodName); - IIdType id = ourClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); - - MetaDt meta = ourClient.meta().get(MetaDt.class).fromResource(id).execute(); - assertEquals(0, meta.getTag().size()); - - MetaDt inMeta = new MetaDt(); - inMeta.addTag().setSystem("urn:system1").setCode("urn:code1"); - meta = ourClient.meta().add().onResource(id).meta(inMeta).execute(); - assertEquals(1, meta.getTag().size()); - - inMeta = new MetaDt(); - inMeta.addTag().setSystem("urn:system1").setCode("urn:code1"); - meta = ourClient.meta().delete().onResource(id).meta(inMeta).execute(); - assertEquals(0, meta.getTag().size()); - - } - /** * Test for issue #60 */ @@ -1293,6 +1332,33 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } + @Test + public void testSearchByIdOr() { + IIdType id1; + { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue("001"); + id1 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + } + IIdType id2; + { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue("001"); + id2 = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + } + + //@formatter:off + Bundle found = ourClient + .search() + .forResource(Patient.class) + .where(Patient.RES_ID.matches().values(id1.getIdPart(), id2.getIdPart())) + .and(Patient.RES_ID.matches().value(id1.getIdPart())) + .execute(); + //@formatter:on + + assertThat(toIdListUnqualifiedVersionless(found), containsInAnyOrder(id1)); + } + @Test public void testSearchByResourceChain() { @@ -1752,6 +1818,21 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } } + @Test + public void testTransaction() throws Exception { + String contents = loadClasspath("/update.xml"); + HttpPost post = new HttpPost(ourServerBase); + post.setEntity(new StringEntity(contents, ContentType.create("application/xml+fhir", "UTF-8"))); + CloseableHttpResponse resp = ourHttpClient.execute(post); + try { + assertEquals(200, resp.getStatusLine().getStatusCode()); + String output= IOUtils.toString(resp.getEntity().getContent()); + ourLog.info(output); + } finally { + resp.close(); + } + } + @Test public void testTryToCreateResourceWithReferenceThatDoesntExist() { Patient p1 = new Patient(); @@ -1769,17 +1850,24 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } @Test - public void testTransaction() throws Exception { - String contents = loadClasspath("/update.xml"); - HttpPost post = new HttpPost(ourServerBase); - post.setEntity(new StringEntity(contents, ContentType.create("application/xml+fhir", "UTF-8"))); - CloseableHttpResponse resp = ourHttpClient.execute(post); + public void testUpdateInvalidReference() throws IOException, Exception { + String methodName = "testUpdateInvalidReference"; + + Patient pt = new Patient(); + pt.addName().addFamily(methodName); + String resource = myFhirCtx.newXmlParser().encodeResourceToString(pt); + + HttpPut post = new HttpPut(ourServerBase + "/Patient"); + post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + CloseableHttpResponse response = ourHttpClient.execute(post); try { - assertEquals(200, resp.getStatusLine().getStatusCode()); - String output= IOUtils.toString(resp.getEntity().getContent()); - ourLog.info(output); + String responseString = IOUtils.toString(response.getEntity().getContent()); + ourLog.info(responseString); + assertThat(responseString, containsString("
Can not update a resource with no ID
")); + assertThat(responseString, containsString("Can not update a resource with no ID")); - assertThat(responseString, containsString(" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index a204a42f37d..30b9f331d73 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -9,6 +9,7 @@ import org.springframework.web.context.WebApplicationContext; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; +import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu1; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; @@ -80,7 +81,7 @@ public class JpaServerDemo extends RestfulServer { setServerConformanceProvider(confProvider); } else { IFhirSystemDao systemDao = myAppCtx.getBean("mySystemDaoDstu2", IFhirSystemDao.class); - JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao); + JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao, myAppCtx.getBean(DaoConfig.class)); confProvider.setImplementationDescription("Example Server"); setServerConformanceProvider(confProvider); } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index 5f664b32c88..49e81ac4ec3 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -14,6 +14,7 @@ import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.WebApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu1; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; @@ -83,7 +84,7 @@ public class TestRestfulServer extends RestfulServer { systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class); systemDao = myAppCtx.getBean("mySystemDaoDstu2", IFhirSystemDao.class); etagSupport = ETagSupportEnum.ENABLED; - JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao); + JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(this, systemDao, myAppCtx.getBean(DaoConfig.class)); confProvider.setImplementationDescription(implDesc); setServerConformanceProvider(confProvider); baseUrlProperty = "fhir.baseurl.dstu2"; diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java index 134409888cd..79fa17ca469 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java @@ -37,9 +37,11 @@ public class SubscriptionPlaygroundController extends BaseController { Bundle resp = client .search() .forResource(Subscription.class) - .where(Subscription.TYPE.exactly().code(SubscriptionChannelTypeEnum.WEBSOCKET.getCode())) - .and(Subscription.STATUS.exactly().code(SubscriptionStatusEnum.ACTIVE.getCode())) +// .where(Subscription.TYPE.exactly().code(SubscriptionChannelTypeEnum.WEBSOCKET.getCode())) +// .and(Subscription.STATUS.exactly().code(SubscriptionStatusEnum.ACTIVE.getCode())) .returnBundle(Bundle.class) + .sort().descending(Subscription.TYPE) + .sort().ascending(Subscription.STATUS) .execute(); //@formatter:off diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml index a8806709641..f09765e053c 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml @@ -17,6 +17,7 @@ + diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/subscriptions.html b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/subscriptions.html index 0b162c24b2b..b1168130471 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/subscriptions.html +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/subscriptions.html @@ -30,96 +30,108 @@
-

- This page is a test playground for WebSocket Subscriptions -

+

This page is a test playground for WebSocket + Subscriptions

- +
- - - - -
- - -
- - - - - - - - - - -
IDCriteria
- - - -
- + + + + +
+ + +
+ + + + + + + + + + + + + +
IDCriteriaTypeStatus
+ + + + + +
+ +

There are + currently no subscriptions on this server.

+ +
+ + +
+
+
Enter a criteria in the text box + below and then click subscribe to create a dynamic + subscription and then display the results as they arrive.
+
+ +
+
+
+
Criteria
+ +
- - -
-
-
- Enter a criteria in the text box below and then click subscribe to - create a dynamic subscription and then display the results as they - arrive. -
-
- -
-
-
-
- Criteria -
- -
-
-
- -
-
- +
+
-
- - - +
+
+
- + -
+ diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans.vm index 531170061a0..d80186fdc79 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans.vm @@ -15,6 +15,7 @@ + @@ -23,6 +24,7 @@ #if ( ${versionCapitalized} == 'Dstu2' ) + @@ -41,7 +43,7 @@ #foreach ( $res in $resources ) #else class="ca.uhn.fhir.jpa.dao.FhirResourceDao${versionCapitalized}">