diff --git a/hapi-fhir-android/pom.xml b/hapi-fhir-android/pom.xml index 2dcd3a1932b..3bc12274ac0 100644 --- a/hapi-fhir-android/pom.xml +++ b/hapi-fhir-android/pom.xml @@ -59,7 +59,6 @@ org.slf4j slf4j-api - test commons-io 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 bd4f9efb6bf..72d1a98b8c8 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 @@ -74,6 +74,7 @@ import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeChildResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.jpa.entity.BaseHasResource; import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.entity.BaseTag; @@ -1615,7 +1616,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH /** * THIS SHOULD RETURN HASHSET and not jsut Set because we add to it later (so it can't be Collections.emptySet()) */ - private HashSet loadReverseIncludes(Collection theMatches, Set theRevIncludes, boolean theReverseMode) { + private HashSet loadReverseIncludes(Collection theMatches, Set theRevIncludes, boolean theReverseMode, EverythingModeEnum theEverythingModeEnum) { if (theMatches.size() == 0) { return new HashSet(); } @@ -1632,6 +1633,7 @@ public abstract class BaseHapiFhirResourceDao extends BaseH boolean addedSomeThisRound; do { HashSet pidsToInclude = new HashSet(); + Set nextRoundOmit = new HashSet(); for (Iterator iter = includes.iterator(); iter.hasNext();) { Include nextInclude = iter.next(); @@ -1648,6 +1650,11 @@ public abstract class BaseHapiFhirResourceDao extends BaseH List results = q.getResultList(); for (ResourceLink resourceLink : results) { if (theReverseMode) { + if (theEverythingModeEnum == EverythingModeEnum.ENCOUNTER) { + if (resourceLink.getSourcePath().equals("Encounter.subject") || resourceLink.getSourcePath().equals("Encounter.patient")) { + nextRoundOmit.add(resourceLink.getSourceResourcePid()); + } + } pidsToInclude.add(resourceLink.getSourceResourcePid()); } else { pidsToInclude.add(resourceLink.getTargetResourcePid()); @@ -1702,6 +1709,9 @@ public abstract class BaseHapiFhirResourceDao extends BaseH theMatches.add(next); } } + + pidsToInclude.removeAll(nextRoundOmit); + addedSomeThisRound = allAdded.addAll(pidsToInclude); nextRoundMatches = pidsToInclude; } while (includes.size() > 0 && nextRoundMatches.size() > 0 && addedSomeThisRound); @@ -2024,10 +2034,10 @@ public abstract class BaseHapiFhirResourceDao extends BaseH } // Load _include and _revinclude before filter and sort in everything mode - if (theParams.isEverythingMode() == true) { + if (theParams.getEverythingMode() != null) { if (theParams.getRevIncludes() != null && theParams.getRevIncludes().isEmpty() == false) { - loadPids.addAll(loadReverseIncludes(loadPids, theParams.getRevIncludes(), true)); - loadPids.addAll(loadReverseIncludes(loadPids, theParams.getIncludes(), false)); + loadPids.addAll(loadReverseIncludes(loadPids, theParams.getRevIncludes(), true, theParams.getEverythingMode())); + loadPids.addAll(loadReverseIncludes(loadPids, theParams.getIncludes(), false, theParams.getEverythingMode())); } } @@ -2066,9 +2076,9 @@ public abstract class BaseHapiFhirResourceDao extends BaseH // Load _revinclude resources final Set revIncludedPids; - if (theParams.isEverythingMode() == false) { + if (theParams.getEverythingMode() == null) { if (theParams.getRevIncludes() != null && theParams.getRevIncludes().isEmpty() == false) { - revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true); + revIncludedPids = loadReverseIncludes(pids, theParams.getRevIncludes(), true, null); } else { revIncludedPids = new HashSet(); } @@ -2095,9 +2105,9 @@ public abstract class BaseHapiFhirResourceDao extends BaseH List pidsSubList = pids.subList(theFromIndex, theToIndex); // Load includes - if (!theParams.isEverythingMode()) { + if (theParams.getEverythingMode()==null) { pidsSubList = new ArrayList(pidsSubList); - revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false)); + revIncludedPids.addAll(loadReverseIncludes(pidsSubList, theParams.getIncludes(), false, null)); } // Execute the query and make sure we return distinct results diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java new file mode 100644 index 00000000000..4953d09d6b2 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoEncounterDstu2.java @@ -0,0 +1,63 @@ +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 java.util.Collections; + +import javax.servlet.http.HttpServletRequest; + +import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu2.resource.Encounter; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.UnsignedIntDt; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.param.DateRangeParam; +import ca.uhn.fhir.rest.param.StringParam; +import ca.uhn.fhir.rest.server.IBundleProvider; + +public class FhirResourceDaoEncounterDstu2 extends FhirResourceDaoDstu2implements IFhirResourceDaoEncounter { + + @Override + public IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { + SearchParameterMap paramMap = new SearchParameterMap(); + if (theCount != null) { + paramMap.setCount(theCount.getValue()); + } + + paramMap.setRevIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive())); + paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive())); + paramMap.setEverythingMode(EverythingModeEnum.ENCOUNTER); + paramMap.setSort(theSort); + paramMap.setLastUpdated(theLastUpdated); + if (theId != null) { + paramMap.add("_id", new StringParam(theId.getIdPart())); + } + ca.uhn.fhir.rest.server.IBundleProvider retVal = search(paramMap); + return retVal; + } + + @Override + public IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { + return encounterInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort); + } + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java index f153e06adf5..d9c854f486a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoPatientDstu2.java @@ -24,6 +24,7 @@ import java.util.Collections; import javax.servlet.http.HttpServletRequest; +import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; @@ -36,7 +37,7 @@ import ca.uhn.fhir.rest.server.IBundleProvider; public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2implements IFhirResourceDaoPatient { @Override - public IBundleProvider everything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { + public IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { SearchParameterMap paramMap = new SearchParameterMap(); if (theCount != null) { paramMap.setCount(theCount.getValue()); @@ -44,12 +45,19 @@ public class FhirResourceDaoPatientDstu2 extends FhirResourceDaoDstu2im paramMap.setRevIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive())); paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive())); - paramMap.setEverythingMode(true); + paramMap.setEverythingMode(EverythingModeEnum.PATIENT); paramMap.setSort(theSort); paramMap.setLastUpdated(theLastUpdated); - paramMap.add("_id", new StringParam(theId.getIdPart())); + if (theId != null) { + paramMap.add("_id", new StringParam(theId.getIdPart())); + } ca.uhn.fhir.rest.server.IBundleProvider retVal = search(paramMap); return retVal; } + @Override + public IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSort) { + return patientInstanceEverything(theServletRequest, null, theCount, theLastUpdated, theSort); + } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java new file mode 100644 index 00000000000..176d1069b14 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoEncounter.java @@ -0,0 +1,39 @@ +package ca.uhn.fhir.jpa.dao; + +import javax.servlet.http.HttpServletRequest; + +/* + * #%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 org.hl7.fhir.instance.model.api.IBaseResource; + +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.UnsignedIntDt; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.param.DateRangeParam; +import ca.uhn.fhir.rest.server.IBundleProvider; + +public interface IFhirResourceDaoEncounter extends IFhirResourceDao { + + IBundleProvider encounterInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort); + + IBundleProvider encounterTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec); + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java index 171cf86bd13..270c33e00df 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoPatient.java @@ -32,6 +32,8 @@ import ca.uhn.fhir.rest.server.IBundleProvider; public interface IFhirResourceDaoPatient extends IFhirResourceDao { - IBundleProvider everything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort); + IBundleProvider patientInstanceEverything(HttpServletRequest theServletRequest, IdDt theId, UnsignedIntDt theCount, DateRangeParam theLastUpdate, SortSpec theSort); + + IBundleProvider patientTypeEverything(HttpServletRequest theServletRequest, UnsignedIntDt theCount, DateRangeParam theLastUpdated, SortSpec theSortSpec); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java index c01ef3c185d..4fef0ce7f1d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java @@ -42,7 +42,7 @@ public class SearchParameterMap extends LinkedHashMap myIncludes; private DateRangeParam myLastUpdated; private Set myRevIncludes; @@ -124,7 +124,7 @@ public class SearchParameterMap extends LinkedHashMap { + /** + * Encounter/123/$everything + */ + //@formatter:off + @Operation(name = "everything", idempotent = true) + public ca.uhn.fhir.rest.server.IBundleProvider EncounterInstanceEverything( - @Operation(name="everything", idempotent=true) - public ca.uhn.fhir.rest.server.IBundleProvider everything( - javax.servlet.http.HttpServletRequest theServletRequest, - @IdParam ca.uhn.fhir.model.primitive.IdDt theId, + javax.servlet.http.HttpServletRequest theServletRequest, + + @IdParam + ca.uhn.fhir.model.primitive.IdDt theId, - @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") - @OperationParam(name="_count") ca.uhn.fhir.model.primitive.UnsignedIntDt theCount - ){ + @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") + @OperationParam(name = Constants.PARAM_COUNT) + ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, + + @Description(shortDefinition="Only return resources which were last updated as specified by the given range") + @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) + DateRangeParam theLastUpdated, + + @Sort + SortSpec theSortSpec + ) { + //@formatter:on startRequest(theServletRequest); try { - SearchParameterMap paramMap = new SearchParameterMap(); - if (theCount != null) { - paramMap.setCount(theCount.getValue()); - } - - paramMap.setRevIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive())); - paramMap.setIncludes(Collections.singleton(IResource.INCLUDE_ALL.asRecursive())); - paramMap.setEverythingMode(true); - paramMap.add("_id", new StringParam(theId.getIdPart())); - ca.uhn.fhir.rest.server.IBundleProvider retVal = getDao().search(paramMap); - return retVal; + return ((IFhirResourceDaoEncounter)getDao()).encounterInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec); } finally { endRequest(theServletRequest); - } + }} + + /** + * /Encounter/$everything + */ + //@formatter:off + @Operation(name = "everything", idempotent = true) + public ca.uhn.fhir.rest.server.IBundleProvider EncounterTypeEverything( + + javax.servlet.http.HttpServletRequest theServletRequest, + + @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") + @OperationParam(name = Constants.PARAM_COUNT) + ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, + + @Description(shortDefinition="Only return resources which were last updated as specified by the given range") + @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) + DateRangeParam theLastUpdated, + + @Sort + SortSpec theSortSpec + ) { + //@formatter:on + + startRequest(theServletRequest); + try { + return ((IFhirResourceDaoEncounter)getDao()).encounterTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec); + } finally { + endRequest(theServletRequest); + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java index 9a0ea48058e..47d4e712b98 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderPatientDstu2.java @@ -33,8 +33,13 @@ import ca.uhn.fhir.rest.server.Constants; public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu2 { + + /** + * Patient/123/$everything + */ + //@formatter:off @Operation(name = "everything", idempotent = true) - public ca.uhn.fhir.rest.server.IBundleProvider everything( + public ca.uhn.fhir.rest.server.IBundleProvider patientInstanceEverything( javax.servlet.http.HttpServletRequest theServletRequest, @@ -49,17 +54,46 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) DateRangeParam theLastUpdated, -// @OperationParam(name = Constants.PARAM_SORT, min=0, max=1) @Sort SortSpec theSortSpec ) { + //@formatter:on startRequest(theServletRequest); try { - return ((IFhirResourceDaoPatient)getDao()).everything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec); + return ((IFhirResourceDaoPatient)getDao()).patientInstanceEverything(theServletRequest, theId, theCount, theLastUpdated, theSortSpec); } finally { endRequest(theServletRequest); - } + }} + + /** + * /Patient/$everything + */ + //@formatter:off + @Operation(name = "everything", idempotent = true) + public ca.uhn.fhir.rest.server.IBundleProvider patientTypeEverything( + + javax.servlet.http.HttpServletRequest theServletRequest, + + @Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.") + @OperationParam(name = Constants.PARAM_COUNT) + ca.uhn.fhir.model.primitive.UnsignedIntDt theCount, + + @Description(shortDefinition="Only return resources which were last updated as specified by the given range") + @OperationParam(name = Constants.PARAM_LASTUPDATED, min=0, max=1) + DateRangeParam theLastUpdated, + + @Sort + SortSpec theSortSpec + ) { + //@formatter:on + + startRequest(theServletRequest); + try { + return ((IFhirResourceDaoPatient)getDao()).patientTypeEverything(theServletRequest, theCount, theLastUpdated, theSortSpec); + } finally { + endRequest(theServletRequest); + } } 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 2142bd27f9a..1fc1dd02490 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 @@ -26,9 +26,7 @@ import java.net.Socket; import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -598,7 +596,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { * See #147 */ @Test - public void testEverythingDoesntRepeatPatient() throws Exception { + 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"))); @@ -654,12 +652,9 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } @Test - public void testEverythingWithLastUpdatedAndSort() throws Exception { + public void testEverythingPatientWithLastUpdatedAndSort() throws Exception { String methodName = "testEverythingWithLastUpdatedAndSort"; - long time0 = System.currentTimeMillis(); - Thread.sleep(10); - Organization org = new Organization(); org.setName(methodName); IIdType oId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); @@ -747,7 +742,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { * See #148 */ @Test - public void testEverythingIncludesCondition() throws Exception { + 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"); @@ -778,11 +773,52 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } + @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 testEverythingIncludesBackReferences() throws Exception { + public void testEverythingPatientIncludesBackReferences() throws Exception { String methodName = "testEverythingIncludesBackReferences"; Medication med = new Medication(); @@ -800,13 +836,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { 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(); - Set ids = toIdList(b); + List ids = toUnqualifiedVersionlessIds(b); ourLog.info(ids.toString()); assertThat(ids, containsInAnyOrder(patId, medId, moId)); } @Test - public void testEverythingOperation() throws Exception { + public void testEverythingPatientOperation() throws Exception { String methodName = "testEverythingOperation"; Organization org1parent = new Organization(); @@ -844,19 +880,132 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { 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(); - - Set ids = toIdList(b); + List ids = toUnqualifiedVersionlessIds(b); assertThat(ids, containsInAnyOrder(patientId, devId, obsId, encId, orgId1, orgId2, orgId1parent)); ourLog.info(ids.toString()); } - private Set toIdList(ca.uhn.fhir.model.dstu2.resource.Bundle b) { - Set ids = new HashSet(); - for (Entry next : b.getEntry()) { - ids.add(next.getResource().getId().toUnqualifiedVersionless()); - } - return ids; + @Test + public void testEverythingEncounterInstance() throws Exception { + String methodName = "testEverythingEncounterInstance"; + + 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(); + + Location locParent = new Location(); + locParent.setName(methodName+"Parent"); + IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless(); + + Location locChild = new Location(); + locChild.setName(methodName); + locChild.getPartOf().setReference(locPId); + IIdType locCId = ourClient.create().resource(locChild).execute().getId().toUnqualifiedVersionless(); + + Encounter encU = new Encounter(); + encU.getPatient().setReference(patientId); + encU.addLocation().getLocation().setReference(locCId); + IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless(); + + Encounter enc = new Encounter(); + enc.getPatient().setReference(patientId); + enc.addLocation().getLocation().setReference(locCId); + IIdType encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); + + Observation obs = new Observation(); + obs.getSubject().setReference(patientId); + obs.getDevice().setReference(devId); + obs.getEncounter().setReference(encId); + IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); + + Parameters output = ourClient.operation().onInstance(encId).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, encId, orgId1, orgId2, orgId1parent, locPId, locCId, obsId, devId)); + assertThat(ids, not(containsInRelativeOrder(encUId))); + + ourLog.info(ids.toString()); + } + + @Test + public void testEverythingEncounterType() throws Exception { + String methodName = "testEverythingEncounterInstance"; + + 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(); + + Location locParent = new Location(); + locParent.setName(methodName+"Parent"); + IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless(); + + Location locChild = new Location(); + locChild.setName(methodName); + locChild.getPartOf().setReference(locPId); + IIdType locCId = ourClient.create().resource(locChild).execute().getId().toUnqualifiedVersionless(); + + Encounter encU = new Encounter(); + encU.addIdentifier().setValue(methodName); + IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless(); + + Encounter enc = new Encounter(); + enc.getPatient().setReference(patientId); + enc.addLocation().getLocation().setReference(locCId); + IIdType encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); + + Observation obs = new Observation(); + obs.getSubject().setReference(patientId); + obs.getDevice().setReference(devId); + obs.getEncounter().setReference(encId); + IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); + + Parameters output = ourClient.operation().onType(Encounter.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(patientId, encUId, encId, orgId1, orgId2, orgId1parent, locPId, locCId, obsId, devId)); + + ourLog.info(ids.toString()); } @Test @@ -1348,7 +1497,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { o.getCode().setText("testSearchWithInvalidSort"); myObservationDao.create(o); //@formatter:off - Bundle found = ourClient + ourClient .search() .forResource(Observation.class) .sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet 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 1216073f3c0..531170061a0 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 @@ -41,7 +41,7 @@ #foreach ( $res in $resources ) #else class="ca.uhn.fhir.jpa.dao.FhirResourceDao${versionCapitalized}"> diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a5d7588cec7..da7b971e886 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -124,6 +124,9 @@ Remove invalid entries in OSGi Manifest. Thanks to Alexander Kley for the fix! + + JPA server now supports $everything on Patient and Encounter types (patient and encounter instance was already supported) +