diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java index a2a309c22f2..206e2df015b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeSearchParam.java @@ -1,6 +1,9 @@ package ca.uhn.fhir.context; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.StringTokenizer; import ca.uhn.fhir.model.dstu.valueset.SearchParamTypeEnum; @@ -65,4 +68,19 @@ public class RuntimeSearchParam { return myPath; } + public List getPathsSplit() { + String path = getPath(); + if (path.indexOf('|')==-1) { + return Collections.singletonList(path); + } + + List retVal = new ArrayList(); + StringTokenizer tok = new StringTokenizer(path, "|"); + while (tok.hasMoreElements()) { + String nextPath = tok.nextToken().trim(); + retVal.add(nextPath.trim()); + } + return retVal; + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java index b2e406b1b37..1c634d695fa 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java @@ -20,10 +20,12 @@ package ca.uhn.fhir.util; * #L% */ - import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; import org.hl7.fhir.instance.model.IBaseResource; import java.util.Set; @@ -32,37 +34,52 @@ import java.util.Set; * Created by Bill de Beaubien on 2/26/2015. */ public class ResourceReferenceInfo { - private String myOwningResource; - private String myName; - private BaseResourceReferenceDt myResource; + private String myOwningResource; + private String myName; + private BaseResourceReferenceDt myResource; - public ResourceReferenceInfo(IBaseResource theOwningResource, String theName, BaseResourceReferenceDt theResource) { - myOwningResource = theOwningResource.getClass().getAnnotation(ResourceDef.class).name(); - myName = theName; - myResource = theResource; - } + public ResourceReferenceInfo(IBaseResource theOwningResource, String theName, BaseResourceReferenceDt theResource) { + myOwningResource = theOwningResource.getClass().getAnnotation(ResourceDef.class).name(); + myName = theName; + myResource = theResource; + } - public String getName() { - return myName; - } + @Override + public String toString() { + ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + b.append("name", myName); + b.append("resource", myResource.getReference()); + return b.build(); + } - public BaseResourceReferenceDt getResourceReference() { - return myResource; - } + public String getName() { + return myName; + } - public boolean matchesIncludeSet(Set theIncludes) { - if (theIncludes == null) - return false; - for (Include include : theIncludes) { - if (matchesInclude(include)) - return true; - } - return false; - } + public BaseResourceReferenceDt getResourceReference() { + return myResource; + } - public boolean matchesInclude(Include theInclude) { - if (theInclude.getValue().equals("*")) - return true; - return (theInclude.getValue().equals(myOwningResource + "." + myName)); - } + public boolean matchesIncludeSet(Set theIncludes) { + if (theIncludes == null) + return false; + for (Include include : theIncludes) { + if (matchesInclude(include)) + return true; + } + return false; + } + + public boolean matchesInclude(Include theInclude) { + if (theInclude.getValue().equals("*")) { + return true; + } + if (theInclude.getValue().indexOf(':') != -1) { + // DSTU2 style + return (theInclude.getValue().equals(myOwningResource + ':' + myName)); + } else { + // DSTU1 style + return (theInclude.getValue().equals(myOwningResource + '.' + myName)); + } + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java index a948d2e1a57..bfde2b15321 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java @@ -345,7 +345,25 @@ public abstract class BaseFhirDao implements IDao { CriteriaBuilder builder = myEntityManager.getCriteriaBuilder(); CriteriaQuery cq = builder.createQuery(TagDefinition.class); Root from = cq.from(TagDefinition.class); - cq.where(builder.and(builder.equal(from.get("mySystem"), theScheme), builder.equal(from.get("myCode"), theTerm))); + + //@formatter:off + if (isNotBlank(theScheme)) { + cq.where( + builder.and( + builder.equal(from.get("myTagType"), theTagType), + builder.equal(from.get("mySystem"), theScheme), + builder.equal(from.get("myCode"), theTerm)) + ); + } else { + cq.where( + builder.and( + builder.equal(from.get("myTagType"), theTagType), + builder.isNull(from.get("mySystem")), + builder.equal(from.get("myCode"), theTerm)) + ); + } + //@formatter:on + TypedQuery q = myEntityManager.createQuery(cq); try { return q.getSingleResult(); @@ -382,7 +400,7 @@ public abstract class BaseFhirDao implements IDao { CriteriaQuery cq = builder.createQuery(TagDefinition.class); Root from = cq.from(TagDefinition.class); cq.where(from.get("myId").in(tagIds)); - cq.orderBy(builder.asc(from.get("myScheme")), builder.asc(from.get("myTerm"))); + cq.orderBy(builder.asc(from.get("mySystem")), builder.asc(from.get("myCode"))); TypedQuery q = myEntityManager.createQuery(cq); q.setMaxResults(getConfig().getHardTagListLimit()); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java index 7c60fe063e5..2d4eeb18a5d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java @@ -20,7 +20,8 @@ package ca.uhn.fhir.jpa.dao; * #L% */ -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.math.BigDecimal; import java.util.ArrayList; @@ -79,7 +80,6 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken; import ca.uhn.fhir.jpa.entity.ResourceLink; import ca.uhn.fhir.jpa.entity.ResourceTable; -import ca.uhn.fhir.jpa.entity.ResourceTag; import ca.uhn.fhir.jpa.entity.TagDefinition; import ca.uhn.fhir.jpa.entity.TagTypeEnum; import ca.uhn.fhir.jpa.util.StopWatch; @@ -1354,6 +1354,11 @@ public abstract class BaseFhirResourceDao extends BaseFhirD List retVal = new ArrayList(); loadResourcesByPid(pidsSubList, retVal, BundleEntrySearchModeEnum.MATCH); + // Load _revinclude resources + if (theParams.getRevIncludes() != null && theParams.getRevIncludes().isEmpty()==false) { + loadReverseIncludes(pidsSubList, retVal, theParams.getRevIncludes()); + } + // Load _include resources if (theParams.getIncludes() != null && theParams.getIncludes().isEmpty() == false) { Set previouslyLoadedPids = new HashSet(); @@ -1393,14 +1398,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD } } - if (!includePids.isEmpty()) { - ourLog.info("Loading {} included resources", includePids.size()); - resources = loadResourcesById(includePids); - for (IResource next : resources) { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(next, BundleEntrySearchModeEnum.INCLUDE); - } - retVal.addAll(resources); - } + resources = addResourcesAsIncludesById(retVal, includePids, resources); } while (includePids.size() > 0 && previouslyLoadedPids.size() < getConfig().getIncludeLimit()); if (previouslyLoadedPids.size() >= getConfig().getIncludeLimit()) { @@ -1427,6 +1425,61 @@ public abstract class BaseFhirResourceDao extends BaseFhirD return retVal; } + private List addResourcesAsIncludesById(List theListToPopulate, Set includePids, List resources) { + if (!includePids.isEmpty()) { + ourLog.info("Loading {} included resources", includePids.size()); + resources = loadResourcesById(includePids); + for (IResource next : resources) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(next, BundleEntrySearchModeEnum.INCLUDE); + } + theListToPopulate.addAll(resources); + } + return resources; + } + + protected void loadReverseIncludes(List theMatches, List theResourceListToPopulate, Set theRevIncludes) { + if (theMatches.size() == 0) { + return; + } + + Long[] matchesArray = theMatches.toArray(new Long[theMatches.size()]); + Set pidsToInclude = new HashSet(); + + for (Include nextInclude : theRevIncludes) { + int colonIdx = nextInclude.getValue().indexOf(':'); + if (colonIdx < 2) { + continue; + } + String resType = nextInclude.getValue().substring(0, colonIdx); + RuntimeResourceDefinition def = getContext().getResourceDefinition(resType); + if (def == null) { + ourLog.warn("Unknown resource type in _revinclude=" + nextInclude.getValue()); + continue; + } + + String paramName = nextInclude.getValue().substring(colonIdx+1); + RuntimeSearchParam param = def.getSearchParam(paramName); + if (param == null) { + ourLog.warn("Unknown param name in _revinclude=" + nextInclude.getValue()); + continue; + } + + for (String nextPath : param.getPathsSplit()) { + String sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r.myTargetResourcePid IN :target_pids"; + TypedQuery q = myEntityManager.createQuery(sql, ResourceLink.class); + q.setParameter("src_path", nextPath); + q.setParameter("target_pids", matchesArray); + List results = q.getResultList(); + for (ResourceLink resourceLink : results) { + pidsToInclude.add(resourceLink.getSourceResourcePid()); + } + } + + loadResourcesByPid(pidsToInclude, theResourceListToPopulate, BundleEntrySearchModeEnum.INCLUDE); + } + } + + @Override public IBundleProvider search(String theParameterName, IQueryParameterType theValue) { return search(Collections.singletonMap(theParameterName, theValue)); @@ -1817,7 +1870,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD myEntityManager.merge(entity); notifyWriteCompleted(); ourLog.info("Processed metaAddOperation on {} in {}ms", new Object[] { theResourceId, w.getMillisAndRestart() }); - + return metaGetOperation(theResourceId); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirSystemDao.java index 8a82b7d6c74..9476595f5c9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirSystemDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirSystemDao.java @@ -33,6 +33,9 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.util.StopWatch; import ca.uhn.fhir.model.api.TagList; @@ -44,6 +47,12 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; public abstract class BaseFhirSystemDao extends BaseFhirDao implements IFhirSystemDao { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseFhirSystemDao.class); + @Transactional(propagation=Propagation.REQUIRED) + @Override + public void deleteAllTagsOnServer() { + myEntityManager.createQuery("DELETE from ResourceTag t").executeUpdate(); + } + @PersistenceContext() protected EntityManager myEntityManager; 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 fbf98bb6d5f..9860fe972b4 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 @@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.dao; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.StringTokenizer; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; @@ -22,9 +21,7 @@ public class FhirResourceDaoDstu2 extends BaseFhirResourceD } else if (theInclude.getValue().startsWith(theResourceDef.getName() + ":")) { values = new ArrayList(); RuntimeSearchParam sp = theResourceDef.getSearchParam(theInclude.getValue().substring(theInclude.getValue().indexOf(':')+1)); - StringTokenizer tok = new StringTokenizer(sp.getPath(), "|"); - while (tok.hasMoreElements()) { - String nextPath = tok.nextToken().trim(); + for (String nextPath : sp.getPathsSplit()) { values.addAll(theTerser.getValues(theResource, nextPath)); } } else { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java index 2c732c3658f..8f464222ba0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirSystemDao.java @@ -45,4 +45,9 @@ public interface IFhirSystemDao extends IDao { */ MetaDt metaGetOperation(); + /** + * Use with caution! This deletes everything!! + */ + void deleteAllTagsOnServer(); + } 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 4191736306c..b94a4f8c64d 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 @@ -41,6 +41,7 @@ public class SearchParameterMap extends HashMap myIncludes; + private Set myRevIncludes; private SortSpec mySort; public void add(String theName, IQueryParameterAnd theAnd) { @@ -97,6 +98,10 @@ public class SearchParameterMap extends HashMap getRevIncludes() { + return myRevIncludes; + } + public SortSpec getSort() { return mySort; } @@ -109,6 +114,10 @@ public class SearchParameterMap extends HashMap theRevIncludes) { + myRevIncludes = theRevIncludes; + } + public void setSort(SortSpec theSort) { mySort = theSort; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java index 652d0bba13b..40cd16cfa8b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java @@ -33,6 +33,8 @@ import javax.persistence.MappedSuperclass; @MappedSuperclass public abstract class BaseResourceIndexedSearchParam implements Serializable { + static final int MAX_SP_NAME = 100; + private static final long serialVersionUID = 1L; @Id @@ -40,7 +42,7 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { @Column(name = "SP_ID") private Long myId; - @Column(name = "SP_NAME", length = 100, nullable=false) + @Column(name = "SP_NAME", length = MAX_SP_NAME, nullable=false) private String myParamName; @ManyToOne(optional = false) 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 b8df7029280..1e0f7da517e 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 @@ -1,6 +1,12 @@ package ca.uhn.fhir.jpa.dao; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -90,6 +96,7 @@ public class FhirResourceDaoDstu2Test { private static IFhirResourceDao ourObservationDao; private static IFhirResourceDao ourOrganizationDao; private static IFhirResourceDao ourPatientDao; + private static IFhirSystemDao ourSystemDao; @Test public void testChoiceParamConcept() { @@ -839,6 +846,244 @@ public class FhirResourceDaoDstu2Test { } + @Test + public void testResourceInstanceMetaOperation() { + deleteEverything(); + + String methodName = "testResourceInstanceMetaOperation"; + IdDt id1, id2; + { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue(methodName); + patient.addName().addFamily("Tester").addGiven("Joe"); + id1 = ourPatientDao.create(patient).getId(); + + MetaDt metaAdd = new MetaDt(); + metaAdd.addTag().setSystem((String) null).setCode("Dog").setDisplay("Puppies"); + metaAdd.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"); + metaAdd.addProfile("http://profile/1"); + ourPatientDao.metaAddOperation(id1, metaAdd); + } + { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue(methodName); + patient.addName().addFamily("Tester").addGiven("Joe"); + TagList tagList = new TagList(); + tagList.addTag("http://foo", "Cat", "Kittens"); + ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList); + + List securityLabels = new ArrayList(); + securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2")); + ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels); + + ArrayList profiles = new ArrayList(); + profiles.add(new IdDt("http://profile/2")); + ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); + + id2 = ourPatientDao.create(patient).getId(); + } + { + Device device = new Device(); + device.addIdentifier().setSystem("urn:system").setValue(methodName); + TagList tagList = new TagList(); + tagList.addTag("http://foo", "Foo", "Bars"); + ResourceMetadataKeyEnum.TAG_LIST.put(device, tagList); + + List securityLabels = new ArrayList(); + securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3")); + ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels); + + ArrayList profiles = new ArrayList(); + profiles.add(new IdDt("http://profile/3")); + ResourceMetadataKeyEnum.PROFILES.put(device, profiles); + + ourDeviceDao.create(device); + } + + MetaDt meta; + + meta = ourPatientDao.metaGetOperation(); + List published = meta.getTag(); + assertEquals(2, published.size()); + assertEquals(null, published.get(0).getSystem()); + assertEquals("Dog", published.get(0).getCode()); + assertEquals("Puppies", published.get(0).getDisplay()); + assertEquals("http://foo", published.get(1).getSystem()); + assertEquals("Cat", published.get(1).getCode()); + assertEquals("Kittens", published.get(1).getDisplay()); + List secLabels = meta.getSecurity(); + assertEquals(2, secLabels.size()); + assertEquals("seclabel:sys:1", secLabels.get(0).getSystemElement().getValue()); + assertEquals("seclabel:code:1", secLabels.get(0).getCodeElement().getValue()); + assertEquals("seclabel:dis:1", secLabels.get(0).getDisplayElement().getValue()); + assertEquals("seclabel:sys:2", secLabels.get(1).getSystemElement().getValue()); + assertEquals("seclabel:code:2", secLabels.get(1).getCodeElement().getValue()); + assertEquals("seclabel:dis:2", secLabels.get(1).getDisplayElement().getValue()); + List profiles = meta.getProfile(); + assertEquals(2, profiles.size()); + assertEquals("http://profile/1", profiles.get(0).getValue()); + assertEquals("http://profile/2", profiles.get(1).getValue()); + + meta = ourPatientDao.metaGetOperation(id2); + published = meta.getTag(); + assertEquals(1, published.size()); + assertEquals("http://foo", published.get(0).getSystem()); + assertEquals("Cat", published.get(0).getCode()); + assertEquals("Kittens", published.get(0).getDisplay()); + secLabels = meta.getSecurity(); + assertEquals(1, secLabels.size()); + assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); + assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); + assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); + profiles = meta.getProfile(); + assertEquals(1, profiles.size()); + assertEquals("http://profile/2", profiles.get(0).getValue()); + + { + MetaDt metaDel = new MetaDt(); + metaDel.addTag().setSystem((String) null).setCode("Dog"); + metaDel.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1"); + metaDel.addProfile("http://profile/1"); + ourPatientDao.metaDeleteOperation(id1, metaDel); + } + + meta = ourPatientDao.metaGetOperation(); + published = meta.getTag(); + assertEquals(1, published.size()); + assertEquals("http://foo", published.get(0).getSystem()); + assertEquals("Cat", published.get(0).getCode()); + assertEquals("Kittens", published.get(0).getDisplay()); + secLabels = meta.getSecurity(); + assertEquals(1, secLabels.size()); + assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); + assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); + assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); + profiles = meta.getProfile(); + assertEquals(1, profiles.size()); + assertEquals("http://profile/2", profiles.get(0).getValue()); + + } + + @Test + public void testResourceMetaOperation() { + deleteEverything(); + + String methodName = "testResourceMetaOperation"; + IdDt id1, id2; + { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue(methodName); + patient.addName().addFamily("Tester").addGiven("Joe"); + TagList tagList = new TagList(); + tagList.addTag(null, "Dog", "Puppies"); + ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList); + + List securityLabels = new ArrayList(); + securityLabels.add(new CodingDt().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1")); + ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels); + + ArrayList profiles = new ArrayList(); + profiles.add(new IdDt("http://profile/1")); + ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); + + id1 = ourPatientDao.create(patient).getId(); + } + { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue(methodName); + patient.addName().addFamily("Tester").addGiven("Joe"); + TagList tagList = new TagList(); + tagList.addTag("http://foo", "Cat", "Kittens"); + ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList); + + List securityLabels = new ArrayList(); + securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2")); + ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels); + + ArrayList profiles = new ArrayList(); + profiles.add(new IdDt("http://profile/2")); + ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); + + id2 = ourPatientDao.create(patient).getId(); + } + { + Device device = new Device(); + device.addIdentifier().setSystem("urn:system").setValue(methodName); + TagList tagList = new TagList(); + tagList.addTag("http://foo", "Foo", "Bars"); + ResourceMetadataKeyEnum.TAG_LIST.put(device, tagList); + + List securityLabels = new ArrayList(); + securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3")); + ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels); + + ArrayList profiles = new ArrayList(); + profiles.add(new IdDt("http://profile/3")); + ResourceMetadataKeyEnum.PROFILES.put(device, profiles); + + ourDeviceDao.create(device); + } + + MetaDt meta; + + meta = ourPatientDao.metaGetOperation(); + List published = meta.getTag(); + assertEquals(2, published.size()); + assertEquals(null, published.get(0).getSystem()); + assertEquals("Dog", published.get(0).getCode()); + assertEquals("Puppies", published.get(0).getDisplay()); + assertEquals("http://foo", published.get(1).getSystem()); + assertEquals("Cat", published.get(1).getCode()); + assertEquals("Kittens", published.get(1).getDisplay()); + List secLabels = meta.getSecurity(); + assertEquals(2, secLabels.size()); + assertEquals("seclabel:sys:1", secLabels.get(0).getSystemElement().getValue()); + assertEquals("seclabel:code:1", secLabels.get(0).getCodeElement().getValue()); + assertEquals("seclabel:dis:1", secLabels.get(0).getDisplayElement().getValue()); + assertEquals("seclabel:sys:2", secLabels.get(1).getSystemElement().getValue()); + assertEquals("seclabel:code:2", secLabels.get(1).getCodeElement().getValue()); + assertEquals("seclabel:dis:2", secLabels.get(1).getDisplayElement().getValue()); + List profiles = meta.getProfile(); + assertEquals(2, profiles.size()); + assertEquals("http://profile/1", profiles.get(0).getValue()); + assertEquals("http://profile/2", profiles.get(1).getValue()); + + meta = ourPatientDao.metaGetOperation(id2); + published = meta.getTag(); + assertEquals(1, published.size()); + assertEquals("http://foo", published.get(0).getSystem()); + assertEquals("Cat", published.get(0).getCode()); + assertEquals("Kittens", published.get(0).getDisplay()); + secLabels = meta.getSecurity(); + assertEquals(1, secLabels.size()); + assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); + assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); + assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); + profiles = meta.getProfile(); + assertEquals(1, profiles.size()); + assertEquals("http://profile/2", profiles.get(0).getValue()); + + ourPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog"); + ourPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1"); + ourPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseFhirDao.NS_JPA_PROFILE, "http://profile/1"); + + meta = ourPatientDao.metaGetOperation(); + published = meta.getTag(); + assertEquals(1, published.size()); + assertEquals("http://foo", published.get(0).getSystem()); + assertEquals("Cat", published.get(0).getCode()); + assertEquals("Kittens", published.get(0).getDisplay()); + secLabels = meta.getSecurity(); + assertEquals(1, secLabels.size()); + assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); + assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); + assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); + profiles = meta.getProfile(); + assertEquals(1, profiles.size()); + assertEquals("http://profile/2", profiles.get(0).getValue()); + + } + @Test public void testSearchAll() { { @@ -2066,241 +2311,12 @@ public class FhirResourceDaoDstu2Test { ourOrganizationDao = ourCtx.getBean("myOrganizationDaoDstu2", IFhirResourceDao.class); ourLocationDao = ourCtx.getBean("myLocationDaoDstu2", IFhirResourceDao.class); ourEncounterDao = ourCtx.getBean("myEncounterDaoDstu2", IFhirResourceDao.class); + ourSystemDao = ourCtx.getBean("mySystemDaoDstu2", IFhirSystemDao.class); ourFhirCtx = ourCtx.getBean(FhirContext.class); } - @Test - public void testResourceMetaOperation() { - String methodName = "testResourceMetaOperation"; - IdDt id1, id2; - { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("urn:system").setValue(methodName); - patient.addName().addFamily("Tester").addGiven("Joe"); - TagList tagList = new TagList(); - tagList.addTag(null, "Dog", "Puppies"); - ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList); - - List securityLabels = new ArrayList(); - securityLabels.add(new CodingDt().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1")); - ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels); - - ArrayList profiles = new ArrayList(); - profiles.add(new IdDt("http://profile/1")); - ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - - id1 = ourPatientDao.create(patient).getId(); - } - { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("urn:system").setValue(methodName); - patient.addName().addFamily("Tester").addGiven("Joe"); - TagList tagList = new TagList(); - tagList.addTag("http://foo", "Cat", "Kittens"); - ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList); - - List securityLabels = new ArrayList(); - securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2")); - ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels); - - ArrayList profiles = new ArrayList(); - profiles.add(new IdDt("http://profile/2")); - ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - - id2 = ourPatientDao.create(patient).getId(); - } - { - Device device = new Device(); - device.addIdentifier().setSystem("urn:system").setValue(methodName); - TagList tagList = new TagList(); - tagList.addTag("http://foo", "Foo", "Bars"); - ResourceMetadataKeyEnum.TAG_LIST.put(device, tagList); - - List securityLabels = new ArrayList(); - securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3")); - ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels); - - ArrayList profiles = new ArrayList(); - profiles.add(new IdDt("http://profile/3")); - ResourceMetadataKeyEnum.PROFILES.put(device, profiles); - - ourDeviceDao.create(device); - } - - MetaDt meta; - - meta = ourPatientDao.metaGetOperation(); - List published = meta.getTag(); - assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); - assertEquals("Dog", published.get(0).getCode()); - assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals("http://foo", published.get(1).getSystem()); - assertEquals("Cat", published.get(1).getCode()); - assertEquals("Kittens", published.get(1).getDisplay()); - List secLabels = meta.getSecurity(); - assertEquals(2, secLabels.size()); - assertEquals("seclabel:sys:1", secLabels.get(0).getSystemElement().getValue()); - assertEquals("seclabel:code:1", secLabels.get(0).getCodeElement().getValue()); - assertEquals("seclabel:dis:1", secLabels.get(0).getDisplayElement().getValue()); - assertEquals("seclabel:sys:2", secLabels.get(1).getSystemElement().getValue()); - assertEquals("seclabel:code:2", secLabels.get(1).getCodeElement().getValue()); - assertEquals("seclabel:dis:2", secLabels.get(1).getDisplayElement().getValue()); - List profiles = meta.getProfile(); - assertEquals(2, profiles.size()); - assertEquals("http://profile/1", profiles.get(0).getValue()); - assertEquals("http://profile/2", profiles.get(1).getValue()); - - meta = ourPatientDao.metaGetOperation(id2); - published = meta.getTag(); - assertEquals(1, published.size()); - assertEquals("http://foo", published.get(0).getSystem()); - assertEquals("Cat", published.get(0).getCode()); - assertEquals("Kittens", published.get(0).getDisplay()); - secLabels = meta.getSecurity(); - assertEquals(1, secLabels.size()); - assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); - assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); - assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); - profiles = meta.getProfile(); - assertEquals(1, profiles.size()); - assertEquals("http://profile/2", profiles.get(0).getValue()); - - ourPatientDao.removeTag(id1, TagTypeEnum.TAG, null, "Dog"); - ourPatientDao.removeTag(id1, TagTypeEnum.SECURITY_LABEL, "seclabel:sys:1", "seclabel:code:1"); - ourPatientDao.removeTag(id1, TagTypeEnum.PROFILE, BaseFhirDao.NS_JPA_PROFILE, "http://profile/1"); - - meta = ourPatientDao.metaGetOperation(); - published = meta.getTag(); - assertEquals(1, published.size()); - assertEquals("http://foo", published.get(0).getSystem()); - assertEquals("Cat", published.get(0).getCode()); - assertEquals("Kittens", published.get(0).getDisplay()); - secLabels = meta.getSecurity(); - assertEquals(1, secLabels.size()); - assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); - assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); - assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); - profiles = meta.getProfile(); - assertEquals(1, profiles.size()); - assertEquals("http://profile/2", profiles.get(0).getValue()); - - } - - @Test - public void testResourceInstanceMetaOperation() { - String methodName = "testResourceInstanceMetaOperation"; - IdDt id1, id2; - { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("urn:system").setValue(methodName); - patient.addName().addFamily("Tester").addGiven("Joe"); - id1 = ourPatientDao.create(patient).getId(); - - MetaDt metaAdd = new MetaDt(); - metaAdd.addTag().setSystem((String) null).setCode("Dog").setDisplay("Puppies"); - metaAdd.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"); - metaAdd.addProfile("http://profile/1"); - ourPatientDao.metaAddOperation(id1, metaAdd); - } - { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("urn:system").setValue(methodName); - patient.addName().addFamily("Tester").addGiven("Joe"); - TagList tagList = new TagList(); - tagList.addTag("http://foo", "Cat", "Kittens"); - ResourceMetadataKeyEnum.TAG_LIST.put(patient, tagList); - - List securityLabels = new ArrayList(); - securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2")); - ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels); - - ArrayList profiles = new ArrayList(); - profiles.add(new IdDt("http://profile/2")); - ResourceMetadataKeyEnum.PROFILES.put(patient, profiles); - - id2 = ourPatientDao.create(patient).getId(); - } - { - Device device = new Device(); - device.addIdentifier().setSystem("urn:system").setValue(methodName); - TagList tagList = new TagList(); - tagList.addTag("http://foo", "Foo", "Bars"); - ResourceMetadataKeyEnum.TAG_LIST.put(device, tagList); - - List securityLabels = new ArrayList(); - securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3")); - ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels); - - ArrayList profiles = new ArrayList(); - profiles.add(new IdDt("http://profile/3")); - ResourceMetadataKeyEnum.PROFILES.put(device, profiles); - - ourDeviceDao.create(device); - } - - MetaDt meta; - - meta = ourPatientDao.metaGetOperation(); - List published = meta.getTag(); - assertEquals(2, published.size()); - assertEquals(null, published.get(0).getSystem()); - assertEquals("Dog", published.get(0).getCode()); - assertEquals("Puppies", published.get(0).getDisplay()); - assertEquals("http://foo", published.get(1).getSystem()); - assertEquals("Cat", published.get(1).getCode()); - assertEquals("Kittens", published.get(1).getDisplay()); - List secLabels = meta.getSecurity(); - assertEquals(2, secLabels.size()); - assertEquals("seclabel:sys:1", secLabels.get(0).getSystemElement().getValue()); - assertEquals("seclabel:code:1", secLabels.get(0).getCodeElement().getValue()); - assertEquals("seclabel:dis:1", secLabels.get(0).getDisplayElement().getValue()); - assertEquals("seclabel:sys:2", secLabels.get(1).getSystemElement().getValue()); - assertEquals("seclabel:code:2", secLabels.get(1).getCodeElement().getValue()); - assertEquals("seclabel:dis:2", secLabels.get(1).getDisplayElement().getValue()); - List profiles = meta.getProfile(); - assertEquals(2, profiles.size()); - assertEquals("http://profile/1", profiles.get(0).getValue()); - assertEquals("http://profile/2", profiles.get(1).getValue()); - - meta = ourPatientDao.metaGetOperation(id2); - published = meta.getTag(); - assertEquals(1, published.size()); - assertEquals("http://foo", published.get(0).getSystem()); - assertEquals("Cat", published.get(0).getCode()); - assertEquals("Kittens", published.get(0).getDisplay()); - secLabels = meta.getSecurity(); - assertEquals(1, secLabels.size()); - assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); - assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); - assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); - profiles = meta.getProfile(); - assertEquals(1, profiles.size()); - assertEquals("http://profile/2", profiles.get(0).getValue()); - - { - MetaDt metaDel = new MetaDt(); - metaDel.addTag().setSystem((String) null).setCode("Dog"); - metaDel.addSecurity().setSystem("seclabel:sys:1").setCode("seclabel:code:1"); - metaDel.addProfile("http://profile/1"); - ourPatientDao.metaDeleteOperation(id1, metaDel); - } - - meta = ourPatientDao.metaGetOperation(); - published = meta.getTag(); - assertEquals(1, published.size()); - assertEquals("http://foo", published.get(0).getSystem()); - assertEquals("Cat", published.get(0).getCode()); - assertEquals("Kittens", published.get(0).getDisplay()); - secLabels = meta.getSecurity(); - assertEquals(1, secLabels.size()); - assertEquals("seclabel:sys:2", secLabels.get(0).getSystemElement().getValue()); - assertEquals("seclabel:code:2", secLabels.get(0).getCodeElement().getValue()); - assertEquals("seclabel:dis:2", secLabels.get(0).getDisplayElement().getValue()); - profiles = meta.getProfile(); - assertEquals(1, profiles.size()); - assertEquals("http://profile/2", profiles.get(0).getValue()); - + private static void deleteEverything() { + FhirSystemDaoDstu2Test.doDeleteEverything(ourSystemDao); } } 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 20b2879dbd1..baafdb37905 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 @@ -5,7 +5,6 @@ import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -33,10 +32,10 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.model.dstu2.resource.Observation; import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.UriDt; -import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -52,7 +51,7 @@ public class FhirSystemDaoDstu2Test { private static IFhirResourceDao ourPatientDao; private static IFhirSystemDao ourSystemDao; private static IFhirResourceDao ourObservationDao; - + @Test public void testTransactionCreateMatchUrlWithOneMatch() { String methodName = "testTransactionCreateMatchUrlWithOneMatch"; @@ -678,6 +677,12 @@ public class FhirSystemDaoDstu2Test { @Test public void testSystemMetaOperation() { + deleteEverything(); + + MetaDt meta = ourSystemDao.metaGetOperation(); + List published = meta.getTag(); + assertEquals(0, published.size()); + String methodName = "testSystemMetaOperation"; IdDt id1; { @@ -717,10 +722,8 @@ public class FhirSystemDaoDstu2Test { ourPatientDao.create(patient); } - MetaDt meta; - meta = ourSystemDao.metaGetOperation(); - List published = meta.getTag(); + published = meta.getTag(); assertEquals(2, published.size()); assertEquals(null, published.get(0).getSystem()); assertEquals("Dog", published.get(0).getCode()); @@ -762,4 +765,26 @@ public class FhirSystemDaoDstu2Test { } + private void deleteEverything() { + FhirSystemDaoDstu2Test.doDeleteEverything(ourSystemDao); + } + + static void doDeleteEverything(IFhirSystemDao systemDao) { + IBundleProvider all = systemDao.history(null); + List allRes = all.getResources(0, all.size()); + for (IResource iResource : allRes) { + if (ResourceMetadataKeyEnum.DELETED_AT.get(iResource) == null) { + ourLog.info("Deleting: {}", iResource.getId()); + + Bundle b = new Bundle(); + b.setType(BundleTypeEnum.TRANSACTION); + String url = iResource.getId().toVersionless().getValue(); + b.addEntry().getTransaction().setMethod(HTTPVerbEnum.DELETE).setUrl(url); + systemDao.transaction(b); + } + } + + systemDao.deleteAllTagsOnServer(); + } + } diff --git a/hapi-fhir-structures-dstu/pom.xml b/hapi-fhir-structures-dstu/pom.xml index 92011d4570a..1e3c28910b3 100644 --- a/hapi-fhir-structures-dstu/pom.xml +++ b/hapi-fhir-structures-dstu/pom.xml @@ -59,12 +59,6 @@ ${jetty_version} test - - org.eclipse.jetty - jetty-servlet - ${jetty_version} - test - org.eclipse.jetty jetty-util diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java index b6393f31066..a03fce86c87 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java @@ -73,7 +73,7 @@ public class ExceptionInterceptorMethodTest { when(myInterceptor.handleException(any(RequestDetails.class), any(Throwable.class), any(HttpServletRequest.class), any(HttpServletResponse.class))).thenAnswer(new Answer() { @Override public Boolean answer(InvocationOnMock theInvocation) throws Throwable { - HttpServletResponse resp = (HttpServletResponse) theInvocation.getArguments()[4]; + HttpServletResponse resp = (HttpServletResponse) theInvocation.getArguments()[3]; resp.setStatus(405); resp.setContentType("text/plain"); resp.getWriter().write("HELP IM A BUG"); diff --git a/hapi-fhir-structures-dstu2/pom.xml b/hapi-fhir-structures-dstu2/pom.xml index 883b98d8ba1..e1499bf3c1a 100644 --- a/hapi-fhir-structures-dstu2/pom.xml +++ b/hapi-fhir-structures-dstu2/pom.xml @@ -49,12 +49,6 @@ ${jetty_version} test - - org.eclipse.jetty - jetty-servlet - ${jetty_version} - test - org.eclipse.jetty jetty-server diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java index e80fbd68f59..19f662d8245 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu2.resource.*; import ca.uhn.fhir.model.dstu2.resource.Bundle; + import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -89,7 +90,8 @@ public class Dstu2BundleFactoryTest { @Test public void whenIncludeIsDiagnosticReportSubject_bundle_shouldIncludePatient() throws Exception { - Bundle bundle = makeBundle(BundleInclusionRule.BASED_ON_INCLUDES, includes(DiagnosticReport.INCLUDE_SUBJECT.getValue())); + Set includes = includes(DiagnosticReport.INCLUDE_SUBJECT.getValue()); + Bundle bundle = makeBundle(BundleInclusionRule.BASED_ON_INCLUDES, includes); assertEquals(2, bundle.getEntry().size()); assertEquals(1, numberOfEntriesOfType(bundle, DiagnosticReport.class)); diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm index 00d9bba5876..4331f6ed3e5 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm @@ -63,6 +63,11 @@ public class ${className}ResourceProvider extends JpaResourceProvider${versionCa #end #end +#if ( $version != 'dstu' ) + @IncludeParam(reverse=true) + Set theRevIncludes, +#end + @IncludeParam(allow= { #foreach ( $param in $searchParamsReference ) #set ( $haveMore = $foreach.hasNext ) @@ -94,7 +99,9 @@ public class ${className}ResourceProvider extends JpaResourceProvider${versionCa #foreach ( $param in $searchParams ) paramMap.add("${param.name}", the${param.nameCapitalized}); #end - +#if ( $version != 'dstu' ) + paramMap.setRevIncludes(theRevIncludes); +#end paramMap.setIncludes(theIncludes); paramMap.setSort(theSort); paramMap.setCount(theCount);