Fix up some regressions caused by move to DSTU2 style include paths and

work on revincludes
This commit is contained in:
James Agnew 2015-03-22 16:59:10 +01:00
parent 596dd664f9
commit e84fdb33b0
16 changed files with 467 additions and 301 deletions

View File

@ -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<String> getPathsSplit() {
String path = getPath();
if (path.indexOf('|')==-1) {
return Collections.singletonList(path);
}
List<String> retVal = new ArrayList<String>();
StringTokenizer tok = new StringTokenizer(path, "|");
while (tok.hasMoreElements()) {
String nextPath = tok.nextToken().trim();
retVal.add(nextPath.trim());
}
return retVal;
}
}

View File

@ -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;
@ -42,6 +44,14 @@ public class ResourceReferenceInfo {
myResource = theResource;
}
@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 String getName() {
return myName;
}
@ -61,8 +71,15 @@ public class ResourceReferenceInfo {
}
public boolean matchesInclude(Include theInclude) {
if (theInclude.getValue().equals("*"))
if (theInclude.getValue().equals("*")) {
return true;
return (theInclude.getValue().equals(myOwningResource + "." + myName));
}
if (theInclude.getValue().indexOf(':') != -1) {
// DSTU2 style
return (theInclude.getValue().equals(myOwningResource + ':' + myName));
} else {
// DSTU1 style
return (theInclude.getValue().equals(myOwningResource + '.' + myName));
}
}
}

View File

@ -345,7 +345,25 @@ public abstract class BaseFhirDao implements IDao {
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
CriteriaQuery<TagDefinition> cq = builder.createQuery(TagDefinition.class);
Root<TagDefinition> 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<TagDefinition> q = myEntityManager.createQuery(cq);
try {
return q.getSingleResult();
@ -382,7 +400,7 @@ public abstract class BaseFhirDao implements IDao {
CriteriaQuery<TagDefinition> cq = builder.createQuery(TagDefinition.class);
Root<TagDefinition> 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<TagDefinition> q = myEntityManager.createQuery(cq);
q.setMaxResults(getConfig().getHardTagListLimit());

View File

@ -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<T extends IResource> extends BaseFhirD
List<IResource> retVal = new ArrayList<IResource>();
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<IdDt> previouslyLoadedPids = new HashSet<IdDt>();
@ -1393,14 +1398,7 @@ public abstract class BaseFhirResourceDao<T extends IResource> 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<T extends IResource> extends BaseFhirD
return retVal;
}
private List<IResource> addResourcesAsIncludesById(List<IResource> theListToPopulate, Set<IdDt> includePids, List<IResource> 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<Long> theMatches, List<IResource> theResourceListToPopulate, Set<Include> theRevIncludes) {
if (theMatches.size() == 0) {
return;
}
Long[] matchesArray = theMatches.toArray(new Long[theMatches.size()]);
Set<Long> pidsToInclude = new HashSet<Long>();
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<ResourceLink> q = myEntityManager.createQuery(sql, ResourceLink.class);
q.setParameter("src_path", nextPath);
q.setParameter("target_pids", matchesArray);
List<ResourceLink> 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));

View File

@ -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<T> extends BaseFhirDao implements IFhirSystemDao<T> {
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;

View File

@ -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<T extends IResource> extends BaseFhirResourceD
} else if (theInclude.getValue().startsWith(theResourceDef.getName() + ":")) {
values = new ArrayList<Object>();
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 {

View File

@ -45,4 +45,9 @@ public interface IFhirSystemDao<T> extends IDao {
*/
MetaDt metaGetOperation();
/**
* Use with caution! This deletes everything!!
*/
void deleteAllTagsOnServer();
}

View File

@ -41,6 +41,7 @@ public class SearchParameterMap extends HashMap<String, List<List<? extends IQue
private Integer myCount;
private Set<Include> myIncludes;
private Set<Include> myRevIncludes;
private SortSpec mySort;
public void add(String theName, IQueryParameterAnd<?> theAnd) {
@ -97,6 +98,10 @@ public class SearchParameterMap extends HashMap<String, List<List<? extends IQue
return myIncludes;
}
public Set<Include> getRevIncludes() {
return myRevIncludes;
}
public SortSpec getSort() {
return mySort;
}
@ -109,6 +114,10 @@ public class SearchParameterMap extends HashMap<String, List<List<? extends IQue
myIncludes = theIncludes;
}
public void setRevIncludes(Set<Include> theRevIncludes) {
myRevIncludes = theRevIncludes;
}
public void setSort(SortSpec theSort) {
mySort = theSort;
}

View File

@ -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)

View File

@ -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<Observation> ourObservationDao;
private static IFhirResourceDao<Organization> ourOrganizationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirSystemDao<Bundle> 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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
profiles.add(new IdDt("http://profile/3"));
ResourceMetadataKeyEnum.PROFILES.put(device, profiles);
ourDeviceDao.create(device);
}
MetaDt meta;
meta = ourPatientDao.metaGetOperation();
List<CodingDt> 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<CodingDt> 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<UriDt> 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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
profiles.add(new IdDt("http://profile/3"));
ResourceMetadataKeyEnum.PROFILES.put(device, profiles);
ourDeviceDao.create(device);
}
MetaDt meta;
meta = ourPatientDao.metaGetOperation();
List<CodingDt> 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<CodingDt> 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<UriDt> 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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:1").setCode("seclabel:code:1").setDisplay("seclabel:dis:1"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
profiles.add(new IdDt("http://profile/3"));
ResourceMetadataKeyEnum.PROFILES.put(device, profiles);
ourDeviceDao.create(device);
}
MetaDt meta;
meta = ourPatientDao.metaGetOperation();
List<CodingDt> 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<CodingDt> 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<UriDt> 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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:2").setCode("seclabel:code:2").setDisplay("seclabel:dis:2"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(patient, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
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<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
securityLabels.add(new CodingDt().setSystem("seclabel:sys:3").setCode("seclabel:code:3").setDisplay("seclabel:dis:3"));
ResourceMetadataKeyEnum.SECURITY_LABELS.put(device, securityLabels);
ArrayList<IdDt> profiles = new ArrayList<IdDt>();
profiles.add(new IdDt("http://profile/3"));
ResourceMetadataKeyEnum.PROFILES.put(device, profiles);
ourDeviceDao.create(device);
}
MetaDt meta;
meta = ourPatientDao.metaGetOperation();
List<CodingDt> 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<CodingDt> 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<UriDt> 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);
}
}

View File

@ -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;
@ -678,6 +677,12 @@ public class FhirSystemDaoDstu2Test {
@Test
public void testSystemMetaOperation() {
deleteEverything();
MetaDt meta = ourSystemDao.metaGetOperation();
List<CodingDt> 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<CodingDt> 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<Bundle> systemDao) {
IBundleProvider all = systemDao.history(null);
List<IResource> 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();
}
}

View File

@ -59,12 +59,6 @@
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>

View File

@ -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<Boolean>() {
@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");

View File

@ -49,12 +49,6 @@
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty_version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>

View File

@ -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<Include> 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));

View File

@ -63,6 +63,11 @@ public class ${className}ResourceProvider extends JpaResourceProvider${versionCa
#end
#end
#if ( $version != 'dstu' )
@IncludeParam(reverse=true)
Set<Include> 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);