Handle contact search params better
This commit is contained in:
parent
b2e17dd746
commit
12735a1446
|
@ -959,6 +959,10 @@ public class RestfulServer extends HttpServlet {
|
||||||
* Sets the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with
|
* Sets the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with
|
||||||
* the <code>_format</code> URL parameter, or with an <code>Accept</code> header in the request. The default is
|
* the <code>_format</code> URL parameter, or with an <code>Accept</code> header in the request. The default is
|
||||||
* {@link EncodingEnum#XML}.
|
* {@link EncodingEnum#XML}.
|
||||||
|
* <p>
|
||||||
|
* Note when testing this feature: Some browsers will include "application/xml" in their
|
||||||
|
* Accept header, which means that the
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void setDefaultResponseEncoding(EncodingEnum theDefaultResponseEncoding) {
|
public void setDefaultResponseEncoding(EncodingEnum theDefaultResponseEncoding) {
|
||||||
Validate.notNull(theDefaultResponseEncoding, "theDefaultResponseEncoding can not be null");
|
Validate.notNull(theDefaultResponseEncoding, "theDefaultResponseEncoding can not be null");
|
||||||
|
|
|
@ -170,6 +170,7 @@ public class FhirTerser {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> List<T> getValues(BaseRuntimeElementCompositeDefinition<?> theCurrentDef, Object theCurrentObj, List<String> theSubList, Class<T> theWantedClass) {
|
private <T> List<T> getValues(BaseRuntimeElementCompositeDefinition<?> theCurrentDef, Object theCurrentObj, List<String> theSubList, Class<T> theWantedClass) {
|
||||||
String name = theSubList.get(0);
|
String name = theSubList.get(0);
|
||||||
|
|
||||||
BaseRuntimeChildDefinition nextDef = theCurrentDef.getChildByNameOrThrowDataFormatException(name);
|
BaseRuntimeChildDefinition nextDef = theCurrentDef.getChildByNameOrThrowDataFormatException(name);
|
||||||
List<? extends IBase> values = nextDef.getAccessor().getValues(theCurrentObj);
|
List<? extends IBase> values = nextDef.getAccessor().getValues(theCurrentObj);
|
||||||
List<T> retVal = new ArrayList<T>();
|
List<T> retVal = new ArrayList<T>();
|
||||||
|
|
|
@ -19,9 +19,7 @@ package ca.uhn.fhir.jpa.dao;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
* #L%
|
* #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.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -59,7 +57,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.omg.PortableInterceptor.InterceptorOperations;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Required;
|
import org.springframework.beans.factory.annotation.Required;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
@ -293,8 +290,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
return new HashSet<Long>(q.getResultList());
|
return new HashSet<Long>(q.getResultList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addPredicateMissingFalseIfPresent(CriteriaBuilder theBuilder, String theParamName, Root<? extends BaseResourceIndexedSearchParam> from, List<Predicate> codePredicates,
|
private boolean addPredicateMissingFalseIfPresent(CriteriaBuilder theBuilder, String theParamName, Root<? extends BaseResourceIndexedSearchParam> from, List<Predicate> codePredicates, IQueryParameterType nextOr) {
|
||||||
IQueryParameterType nextOr) {
|
|
||||||
boolean missingFalse = false;
|
boolean missingFalse = false;
|
||||||
if (nextOr.getMissing() != null) {
|
if (nextOr.getMissing() != null) {
|
||||||
if (nextOr.getMissing().booleanValue() == true) {
|
if (nextOr.getMissing().booleanValue() == true) {
|
||||||
|
@ -308,8 +304,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
return missingFalse;
|
return missingFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addPredicateMissingFalseIfPresentForResourceLink(CriteriaBuilder theBuilder, String theParamName, Root<? extends ResourceLink> from, List<Predicate> codePredicates,
|
private boolean addPredicateMissingFalseIfPresentForResourceLink(CriteriaBuilder theBuilder, String theParamName, Root<? extends ResourceLink> from, List<Predicate> codePredicates, IQueryParameterType nextOr) {
|
||||||
IQueryParameterType nextOr) {
|
|
||||||
boolean missingFalse = false;
|
boolean missingFalse = false;
|
||||||
if (nextOr.getMissing() != null) {
|
if (nextOr.getMissing() != null) {
|
||||||
if (nextOr.getMissing().booleanValue() == true) {
|
if (nextOr.getMissing().booleanValue() == true) {
|
||||||
|
@ -635,11 +630,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
RuntimeResourceDefinition resDef = getContext().getResourceDefinition(ref.getResourceType());
|
RuntimeResourceDefinition resDef = getContext().getResourceDefinition(ref.getResourceType());
|
||||||
resourceTypes.add(resDef.getImplementingClass());
|
resourceTypes.add(resDef.getImplementingClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean foundChainMatch = false;
|
boolean foundChainMatch = false;
|
||||||
for (Class<? extends IBaseResource> nextType : resourceTypes) {
|
for (Class<? extends IBaseResource> nextType : resourceTypes) {
|
||||||
RuntimeResourceDefinition typeDef = getContext().getResourceDefinition(nextType);
|
RuntimeResourceDefinition typeDef = getContext().getResourceDefinition(nextType);
|
||||||
|
|
||||||
String chain = ref.getChain();
|
String chain = ref.getChain();
|
||||||
String remainingChain = null;
|
String remainingChain = null;
|
||||||
int chainDotIndex = chain.indexOf('.');
|
int chainDotIndex = chain.indexOf('.');
|
||||||
|
@ -658,23 +653,23 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
ourLog.debug("Don't have a DAO for type {}", nextType.getSimpleName(), param);
|
ourLog.debug("Don't have a DAO for type {}", nextType.getSimpleName(), param);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
IQueryParameterType chainValue;
|
IQueryParameterType chainValue;
|
||||||
if (remainingChain != null) {
|
if (remainingChain != null) {
|
||||||
if (param.getParamType() != RestSearchParameterTypeEnum.REFERENCE) {
|
if (param.getParamType() != RestSearchParameterTypeEnum.REFERENCE) {
|
||||||
ourLog.debug("Type {} parameter {} is not a reference, can not chain {}", new Object[] { nextType.getSimpleName(), chain, remainingChain });
|
ourLog.debug("Type {} parameter {} is not a reference, can not chain {}", new Object[] { nextType.getSimpleName(), chain, remainingChain });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
chainValue = new ReferenceParam();
|
chainValue = new ReferenceParam();
|
||||||
chainValue.setValueAsQueryToken(null, resourceId);
|
chainValue.setValueAsQueryToken(null, resourceId);
|
||||||
((ReferenceParam)chainValue).setChain(remainingChain);
|
((ReferenceParam) chainValue).setChain(remainingChain);
|
||||||
} else {
|
} else {
|
||||||
chainValue = toParameterType(param, resourceId);
|
chainValue = toParameterType(param, resourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
foundChainMatch = true;
|
foundChainMatch = true;
|
||||||
|
|
||||||
Set<Long> pids = dao.searchForIds(chain, chainValue);
|
Set<Long> pids = dao.searchForIds(chain, chainValue);
|
||||||
if (pids.isEmpty()) {
|
if (pids.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -684,7 +679,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
codePredicates.add(eq);
|
codePredicates.add(eq);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundChainMatch) {
|
if (!foundChainMatch) {
|
||||||
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "invalidParameterChain", theParamName + '.' + ref.getChain()));
|
throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "invalidParameterChain", theParamName + '.' + ref.getChain()));
|
||||||
}
|
}
|
||||||
|
@ -892,11 +887,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IBaseOperationOutcome createErrorOperationOutcome(String theMessage) {
|
protected IBaseOperationOutcome createErrorOperationOutcome(String theMessage) {
|
||||||
return createOperationOutcome(IssueSeverityEnum.ERROR.getCode(), theMessage);
|
return createOperationOutcome("error", theMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IBaseOperationOutcome createInfoOperationOutcome(String theMessage) {
|
protected IBaseOperationOutcome createInfoOperationOutcome(String theMessage) {
|
||||||
return createOperationOutcome(IssueSeverityEnum.INFORMATION.getCode(), theMessage);
|
return createOperationOutcome("information", theMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage);
|
protected abstract IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage);
|
||||||
|
@ -961,8 +956,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate createPredicateString(IQueryParameterType theParameter, String theParamName, CriteriaBuilder theBuilder,
|
private Predicate createPredicateString(IQueryParameterType theParameter, String theParamName, CriteriaBuilder theBuilder, From<ResourceIndexedSearchParamString, ResourceIndexedSearchParamString> theFrom) {
|
||||||
From<ResourceIndexedSearchParamString, ResourceIndexedSearchParamString> theFrom) {
|
|
||||||
String rawSearchTerm;
|
String rawSearchTerm;
|
||||||
if (theParameter instanceof TokenParam) {
|
if (theParameter instanceof TokenParam) {
|
||||||
TokenParam id = (TokenParam) theParameter;
|
TokenParam id = (TokenParam) theParameter;
|
||||||
|
@ -981,8 +975,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawSearchTerm.length() > ResourceIndexedSearchParamString.MAX_LENGTH) {
|
if (rawSearchTerm.length() > ResourceIndexedSearchParamString.MAX_LENGTH) {
|
||||||
throw new InvalidRequestException("Parameter[" + theParamName + "] has length (" + rawSearchTerm.length() + ") that is longer than maximum allowed ("
|
throw new InvalidRequestException("Parameter[" + theParamName + "] has length (" + rawSearchTerm.length() + ") that is longer than maximum allowed (" + ResourceIndexedSearchParamString.MAX_LENGTH + "): " + rawSearchTerm);
|
||||||
+ ResourceIndexedSearchParamString.MAX_LENGTH + "): " + rawSearchTerm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String likeExpression = normalizeString(rawSearchTerm);
|
String likeExpression = normalizeString(rawSearchTerm);
|
||||||
|
@ -996,8 +989,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
return singleCode;
|
return singleCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate createPredicateToken(IQueryParameterType theParameter, String theParamName, CriteriaBuilder theBuilder,
|
private Predicate createPredicateToken(IQueryParameterType theParameter, String theParamName, CriteriaBuilder theBuilder, From<ResourceIndexedSearchParamToken, ResourceIndexedSearchParamToken> theFrom) {
|
||||||
From<ResourceIndexedSearchParamToken, ResourceIndexedSearchParamToken> theFrom) {
|
|
||||||
String code;
|
String code;
|
||||||
String system;
|
String system;
|
||||||
if (theParameter instanceof TokenParam) {
|
if (theParameter instanceof TokenParam) {
|
||||||
|
@ -1017,12 +1009,10 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system != null && system.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) {
|
if (system != null && system.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) {
|
||||||
throw new InvalidRequestException("Parameter[" + theParamName + "] has system (" + system.length() + ") that is longer than maximum allowed (" + ResourceIndexedSearchParamToken.MAX_LENGTH
|
throw new InvalidRequestException("Parameter[" + theParamName + "] has system (" + system.length() + ") that is longer than maximum allowed (" + ResourceIndexedSearchParamToken.MAX_LENGTH + "): " + system);
|
||||||
+ "): " + system);
|
|
||||||
}
|
}
|
||||||
if (code != null && code.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) {
|
if (code != null && code.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) {
|
||||||
throw new InvalidRequestException("Parameter[" + theParamName + "] has code (" + code.length() + ") that is longer than maximum allowed (" + ResourceIndexedSearchParamToken.MAX_LENGTH
|
throw new InvalidRequestException("Parameter[" + theParamName + "] has code (" + code.length() + ") that is longer than maximum allowed (" + ResourceIndexedSearchParamToken.MAX_LENGTH + "): " + code);
|
||||||
+ "): " + code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Predicate> singleCodePredicates = (new ArrayList<Predicate>());
|
ArrayList<Predicate> singleCodePredicates = (new ArrayList<Predicate>());
|
||||||
|
@ -1096,13 +1086,13 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
}
|
}
|
||||||
|
|
||||||
From<?, ?> stringJoin = theFrom.join(joinAttrName, JoinType.INNER);
|
From<?, ?> stringJoin = theFrom.join(joinAttrName, JoinType.INNER);
|
||||||
|
|
||||||
if (param.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
|
if (param.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
|
||||||
thePredicates.add(stringJoin.get("mySourcePath").as(String.class).in(param.getPathsSplit()));
|
thePredicates.add(stringJoin.get("mySourcePath").as(String.class).in(param.getPathsSplit()));
|
||||||
} else {
|
} else {
|
||||||
thePredicates.add(theBuilder.equal(stringJoin.get("myParamName"), theSort.getParamName()));
|
thePredicates.add(theBuilder.equal(stringJoin.get("myParamName"), theSort.getParamName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Predicate p = theBuilder.equal(stringJoin.get("myParamName"), theSort.getParamName());
|
// Predicate p = theBuilder.equal(stringJoin.get("myParamName"), theSort.getParamName());
|
||||||
// Predicate pn = theBuilder.isNull(stringJoin.get("myParamName"));
|
// Predicate pn = theBuilder.isNull(stringJoin.get("myParamName"));
|
||||||
// thePredicates.add(theBuilder.or(p, pn));
|
// thePredicates.add(theBuilder.or(p, pn));
|
||||||
|
@ -1176,8 +1166,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
|
|
||||||
if (isNotBlank(theResource.getId().getIdPart())) {
|
if (isNotBlank(theResource.getId().getIdPart())) {
|
||||||
if (isValidPid(theResource.getId())) {
|
if (isValidPid(theResource.getId())) {
|
||||||
throw new UnprocessableEntityException(
|
throw new UnprocessableEntityException("This server cannot create an entity with a user-specified numeric ID - Client should not specify an ID when creating a new resource, or should include at least one letter in the ID to force a client-defined ID");
|
||||||
"This server cannot create an entity with a user-specified numeric ID - Client should not specify an ID when creating a new resource, or should include at least one letter in the ID to force a client-defined ID");
|
|
||||||
}
|
}
|
||||||
createForcedIdIfNeeded(entity, theResource.getId());
|
createForcedIdIfNeeded(entity, theResource.getId());
|
||||||
|
|
||||||
|
@ -1197,7 +1186,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
DaoMethodOutcome outcome = toMethodOutcome(entity, theResource).setCreated(true);
|
DaoMethodOutcome outcome = toMethodOutcome(entity, theResource).setCreated(true);
|
||||||
|
|
||||||
notifyWriteCompleted();
|
notifyWriteCompleted();
|
||||||
|
|
||||||
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulCreate", outcome.getId(), w.getMillisAndRestart());
|
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulCreate", outcome.getId(), w.getMillisAndRestart());
|
||||||
outcome.setOperationOutcome(createInfoOperationOutcome(msg));
|
outcome.setOperationOutcome(createInfoOperationOutcome(msg));
|
||||||
|
|
||||||
|
@ -1254,8 +1243,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
|
|
||||||
final T current = currentTmp;
|
final T current = currentTmp;
|
||||||
|
|
||||||
String querySring = "SELECT count(h) FROM ResourceHistoryTable h " + "WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE" + " AND h.myUpdated < :END"
|
String querySring = "SELECT count(h) FROM ResourceHistoryTable h " + "WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE" + " AND h.myUpdated < :END" + (theSince != null ? " AND h.myUpdated >= :SINCE" : "");
|
||||||
+ (theSince != null ? " AND h.myUpdated >= :SINCE" : "");
|
|
||||||
TypedQuery<Long> countQuery = myEntityManager.createQuery(querySring, Long.class);
|
TypedQuery<Long> countQuery = myEntityManager.createQuery(querySring, Long.class);
|
||||||
countQuery.setParameter("PID", translateForcedIdToPid(theId));
|
countQuery.setParameter("PID", translateForcedIdToPid(theId));
|
||||||
countQuery.setParameter("RESTYPE", resourceType);
|
countQuery.setParameter("RESTYPE", resourceType);
|
||||||
|
@ -1293,8 +1281,8 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
retVal.add(current);
|
retVal.add(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery("SELECT h FROM ResourceHistoryTable h WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE AND h.myUpdated < :END "
|
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery("SELECT h FROM ResourceHistoryTable h WHERE h.myResourceId = :PID AND h.myResourceType = :RESTYPE AND h.myUpdated < :END " + (theSince != null ? " AND h.myUpdated >= :SINCE" : "") + " ORDER BY h.myUpdated ASC",
|
||||||
+ (theSince != null ? " AND h.myUpdated >= :SINCE" : "") + " ORDER BY h.myUpdated ASC", ResourceHistoryTable.class);
|
ResourceHistoryTable.class);
|
||||||
q.setParameter("PID", translateForcedIdToPid(theId));
|
q.setParameter("PID", translateForcedIdToPid(theId));
|
||||||
q.setParameter("RESTYPE", resourceType);
|
q.setParameter("RESTYPE", resourceType);
|
||||||
q.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
|
q.setParameter("END", end.getValue(), TemporalType.TIMESTAMP);
|
||||||
|
@ -1594,8 +1582,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
if (theId.hasVersionIdPart()) {
|
if (theId.hasVersionIdPart()) {
|
||||||
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery(
|
TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery("SELECT t from ResourceHistoryTable t WHERE t.myResourceId = :RID AND t.myResourceType = :RTYP AND t.myResourceVersion = :RVER", ResourceHistoryTable.class);
|
||||||
"SELECT t from ResourceHistoryTable t WHERE t.myResourceId = :RID AND t.myResourceType = :RTYP AND t.myResourceVersion = :RVER", ResourceHistoryTable.class);
|
|
||||||
q.setParameter("RID", pid);
|
q.setParameter("RID", pid);
|
||||||
q.setParameter("RTYP", myResourceName);
|
q.setParameter("RTYP", myResourceName);
|
||||||
q.setParameter("RVER", Long.parseLong(theId.getVersionIdPart()));
|
q.setParameter("RVER", Long.parseLong(theId.getVersionIdPart()));
|
||||||
|
@ -1778,8 +1765,8 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
loadResourcesByPid(pidsSubList, retVal, BundleEntrySearchModeEnum.MATCH);
|
loadResourcesByPid(pidsSubList, retVal, BundleEntrySearchModeEnum.MATCH);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load _include resources - Note that _revincludes are handled differently than _include ones, as they are counted towards the total count and paged, so they are loaded outside the
|
* Load _include resources - Note that _revincludes are handled differently than _include ones, as
|
||||||
* bundle provider
|
* they are counted towards the total count and paged, so they are loaded outside the bundle provider
|
||||||
*/
|
*/
|
||||||
if (theParams.getIncludes() != null && theParams.getIncludes().isEmpty() == false) {
|
if (theParams.getIncludes() != null && theParams.getIncludes().isEmpty() == false) {
|
||||||
Set<IIdType> previouslyLoadedPids = new HashSet<IIdType>();
|
Set<IIdType> previouslyLoadedPids = new HashSet<IIdType>();
|
||||||
|
@ -1827,8 +1814,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
|
|
||||||
if (previouslyLoadedPids.size() >= getConfig().getIncludeLimit()) {
|
if (previouslyLoadedPids.size() >= getConfig().getIncludeLimit()) {
|
||||||
OperationOutcome oo = new OperationOutcome();
|
OperationOutcome oo = new OperationOutcome();
|
||||||
oo.addIssue().setSeverity(IssueSeverityEnum.WARNING)
|
oo.addIssue().setSeverity(IssueSeverityEnum.WARNING).setDetails("Not all _include resources were actually included as the request surpassed the limit of " + getConfig().getIncludeLimit() + " resources");
|
||||||
.setDetails("Not all _include resources were actually included as the request surpassed the limit of " + getConfig().getIncludeLimit() + " resources");
|
|
||||||
retVal.add(0, oo);
|
retVal.add(0, oo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2006,7 +1992,8 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set, the given param will be treated as a secondary primary key, and multiple resources will not be able to share the same value.
|
* If set, the given param will be treated as a secondary primary key, and multiple resources will not be able to
|
||||||
|
* share the same value.
|
||||||
*/
|
*/
|
||||||
public void setSecondaryPrimaryKeyParamName(String theSecondaryPrimaryKeyParamName) {
|
public void setSecondaryPrimaryKeyParamName(String theSecondaryPrimaryKeyParamName) {
|
||||||
mySecondaryPrimaryKeyParamName = theSecondaryPrimaryKeyParamName;
|
mySecondaryPrimaryKeyParamName = theSecondaryPrimaryKeyParamName;
|
||||||
|
@ -2136,7 +2123,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
ResourceTable savedEntity = updateEntity(theResource, entity, true, null, thePerformIndexing, true);
|
ResourceTable savedEntity = updateEntity(theResource, entity, true, null, thePerformIndexing, true);
|
||||||
|
|
||||||
notifyWriteCompleted();
|
notifyWriteCompleted();
|
||||||
|
|
||||||
DaoMethodOutcome outcome = toMethodOutcome(savedEntity, theResource).setCreated(false);
|
DaoMethodOutcome outcome = toMethodOutcome(savedEntity, theResource).setCreated(false);
|
||||||
|
|
||||||
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulCreate", outcome.getId(), w.getMillisAndRestart());
|
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulCreate", outcome.getId(), w.getMillisAndRestart());
|
||||||
|
@ -2160,8 +2147,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
||||||
|
|
||||||
private void validateResourceType(BaseHasResource entity) {
|
private void validateResourceType(BaseHasResource entity) {
|
||||||
if (!myResourceName.equals(entity.getResourceType())) {
|
if (!myResourceName.equals(entity.getResourceType())) {
|
||||||
throw new ResourceNotFoundException("Resource with ID " + entity.getIdDt().getIdPart() + " exists but it is not of type " + myResourceName + ", found resource of type "
|
throw new ResourceNotFoundException("Resource with ID " + entity.getIdDt().getIdPart() + " exists but it is not of type " + myResourceName + ", found resource of type " + entity.getResourceType());
|
||||||
+ entity.getResourceType());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class BaseSearchParamExtractor {
|
||||||
values.addAll(t.getValues(theResource, nextPathTrimmed));
|
values.addAll(t.getValues(theResource, nextPathTrimmed));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
|
||||||
ourLog.warn("Failed to index values from path[{}] in resource type[{}]: ", new Object[] { nextPathTrimmed, def.getName(), e.toString() } );
|
ourLog.warn("Failed to index values from path[{}] in resource type[{}]: {}", new Object[] { nextPathTrimmed, def.getName(), e.toString(), e } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
|
|
|
@ -424,6 +424,16 @@ class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implements ISea
|
||||||
List<String> systems = new ArrayList<String>();
|
List<String> systems = new ArrayList<String>();
|
||||||
List<String> codes = new ArrayList<String>();
|
List<String> codes = new ArrayList<String>();
|
||||||
|
|
||||||
|
String needContactPointSystem = null;
|
||||||
|
if (nextPath.endsWith("(system=phone)")) {
|
||||||
|
nextPath = nextPath.substring(0, nextPath.length() - "(system=phone)".length());
|
||||||
|
needContactPointSystem = "phone";
|
||||||
|
}
|
||||||
|
if (nextPath.endsWith("(system=email)")) {
|
||||||
|
nextPath = nextPath.substring(0, nextPath.length() - "(system=email)".length());
|
||||||
|
needContactPointSystem = "email";
|
||||||
|
}
|
||||||
|
|
||||||
for (Object nextObject : extractValues(nextPath, theResource)) {
|
for (Object nextObject : extractValues(nextPath, theResource)) {
|
||||||
|
|
||||||
// Patient:language
|
// Patient:language
|
||||||
|
@ -444,6 +454,11 @@ class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implements ISea
|
||||||
if (nextValue.isEmpty()) {
|
if (nextValue.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isNotBlank(needContactPointSystem)) {
|
||||||
|
if (!needContactPointSystem.equals(nextValue.getSystemElement().getValueAsString())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
systems.add(nextValue.getSystemElement().getValueAsString());
|
systems.add(nextValue.getSystemElement().getValueAsString());
|
||||||
codes.add(nextValue.getValueElement().getValue());
|
codes.add(nextValue.getValueElement().getValue());
|
||||||
} else if (nextObject instanceof IPrimitiveDatatype<?>) {
|
} else if (nextObject instanceof IPrimitiveDatatype<?>) {
|
||||||
|
|
|
@ -1,22 +1,7 @@
|
||||||
package ca.uhn.fhir.jpa.dao;
|
package ca.uhn.fhir.jpa.dao;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.junit.Assert.*;
|
||||||
import static org.hamcrest.Matchers.containsInRelativeOrder;
|
|
||||||
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.hasItems;
|
|
||||||
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;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -36,9 +21,6 @@ import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.jmx.access.InvalidInvocationException;
|
|
||||||
|
|
||||||
import com.ctc.wstx.util.StringUtil;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
||||||
|
@ -51,6 +33,7 @@ import ca.uhn.fhir.model.api.TagList;
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
|
import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
|
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
||||||
|
@ -64,12 +47,15 @@ import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Encounter;
|
import ca.uhn.fhir.model.dstu2.resource.Encounter;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Location;
|
import ca.uhn.fhir.model.dstu2.resource.Location;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Observation;
|
import ca.uhn.fhir.model.dstu2.resource.Observation;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Questionnaire;
|
import ca.uhn.fhir.model.dstu2.resource.Questionnaire;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.QuestionnaireAnswers;
|
import ca.uhn.fhir.model.dstu2.resource.QuestionnaireAnswers;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
|
||||||
|
import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
||||||
|
import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.QuantityComparatorEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.QuantityComparatorEnum;
|
||||||
import ca.uhn.fhir.model.primitive.DateDt;
|
import ca.uhn.fhir.model.primitive.DateDt;
|
||||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||||
|
@ -113,7 +99,17 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
private static IFhirResourceDao<QuestionnaireAnswers> ourQuestionnaireAnswersDao;
|
private static IFhirResourceDao<QuestionnaireAnswers> ourQuestionnaireAnswersDao;
|
||||||
private static IFhirResourceDao<Questionnaire> ourQuestionnaireDao;
|
private static IFhirResourceDao<Questionnaire> ourQuestionnaireDao;
|
||||||
private static IFhirSystemDao<Bundle> ourSystemDao;
|
private static IFhirSystemDao<Bundle> ourSystemDao;
|
||||||
|
private static IFhirResourceDao<Practitioner> ourPractitionerDao;
|
||||||
|
|
||||||
|
private List<String> extractNames(IBundleProvider theSearch) {
|
||||||
|
ArrayList<String> retVal = new ArrayList<String>();
|
||||||
|
for (IBaseResource next : theSearch.getResources(0, theSearch.size())) {
|
||||||
|
Patient nextPt = (Patient)next;
|
||||||
|
retVal.add(nextPt.getNameFirstRep().getNameAsSingleString());
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChoiceParamConcept() {
|
public void testChoiceParamConcept() {
|
||||||
Observation o1 = new Observation();
|
Observation o1 = new Observation();
|
||||||
|
@ -216,6 +212,22 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateOperationOutcomeError() {
|
||||||
|
FhirResourceDaoDstu2<Bundle> dao = new FhirResourceDaoDstu2<Bundle>();
|
||||||
|
OperationOutcome oo = (OperationOutcome) dao.createErrorOperationOutcome("my message");
|
||||||
|
assertEquals(IssueSeverityEnum.ERROR.getCode(), oo.getIssue().get(0).getSeverity());
|
||||||
|
assertEquals("my message", oo.getIssue().get(0).getDetails());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateOperationOutcomeInfo() {
|
||||||
|
FhirResourceDaoDstu2<Bundle> dao = new FhirResourceDaoDstu2<Bundle>();
|
||||||
|
OperationOutcome oo = (OperationOutcome) dao.createInfoOperationOutcome("my message");
|
||||||
|
assertEquals(IssueSeverityEnum.INFORMATION.getCode(), oo.getIssue().get(0).getSeverity());
|
||||||
|
assertEquals("my message", oo.getIssue().get(0).getDetails());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTextIdFails() {
|
public void testCreateTextIdFails() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -1428,6 +1440,47 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchPractitionerEmailParam() {
|
||||||
|
String methodName = "testSearchPractitionerEmailParam";
|
||||||
|
IIdType id1;
|
||||||
|
{
|
||||||
|
Practitioner patient = new Practitioner();
|
||||||
|
patient.getName().addFamily(methodName);
|
||||||
|
patient.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setValue("123");
|
||||||
|
id1 = ourPractitionerDao.create(patient).getId();
|
||||||
|
}
|
||||||
|
IIdType id2;
|
||||||
|
{
|
||||||
|
Practitioner patient = new Practitioner();
|
||||||
|
patient.getName().addFamily(methodName);
|
||||||
|
patient.addTelecom().setSystem(ContactPointSystemEnum.EMAIL).setValue("abc");
|
||||||
|
id2 = ourPractitionerDao.create(patient).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, IQueryParameterType> params;
|
||||||
|
List<Patient> patients;
|
||||||
|
|
||||||
|
params = new HashMap<String, IQueryParameterType>();
|
||||||
|
params.put(Practitioner.SP_FAMILY, new StringDt(methodName));
|
||||||
|
patients = toList(ourPractitionerDao.search(params));
|
||||||
|
assertEquals(2, patients.size());
|
||||||
|
|
||||||
|
params = new HashMap<String, IQueryParameterType>();
|
||||||
|
params.put(Practitioner.SP_FAMILY, new StringParam(methodName));
|
||||||
|
params.put(Practitioner.SP_EMAIL, new TokenParam(null, "abc"));
|
||||||
|
patients = toList(ourPractitionerDao.search(params));
|
||||||
|
assertEquals(1, patients.size());
|
||||||
|
|
||||||
|
params = new HashMap<String, IQueryParameterType>();
|
||||||
|
params.put(Practitioner.SP_FAMILY, new StringParam(methodName));
|
||||||
|
params.put(Practitioner.SP_EMAIL, new TokenParam(null, "123"));
|
||||||
|
patients = toList(ourPractitionerDao.search(params));
|
||||||
|
assertEquals(0, patients.size());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchNameParam() {
|
public void testSearchNameParam() {
|
||||||
IIdType id1;
|
IIdType id1;
|
||||||
|
@ -1692,6 +1745,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchStringParam() {
|
public void testSearchStringParam() {
|
||||||
{
|
{
|
||||||
|
@ -1748,7 +1802,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchStringParamWithNonNormalized() {
|
public void testSearchStringParamWithNonNormalized() {
|
||||||
{
|
{
|
||||||
|
@ -2373,6 +2426,54 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
assertThat(actual.subList(0, 2), containsInAnyOrder(id2, id4));
|
assertThat(actual.subList(0, 2), containsInAnyOrder(id2, id4));
|
||||||
assertThat(actual.subList(2, 4), containsInAnyOrder(id1, id3));
|
assertThat(actual.subList(2, 4), containsInAnyOrder(id1, id3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSortByString01() {
|
||||||
|
Patient p = new Patient();
|
||||||
|
String string = "testSortByString01";
|
||||||
|
p.addIdentifier().setSystem("urn:system").setValue(string);
|
||||||
|
p.addName().addFamily("testSortF1").addGiven("testSortG1");
|
||||||
|
IIdType id1 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
// Create out of order
|
||||||
|
p = new Patient();
|
||||||
|
p.addIdentifier().setSystem("urn:system").setValue(string);
|
||||||
|
p.addName().addFamily("testSortF3").addGiven("testSortG3");
|
||||||
|
IIdType id3 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
p = new Patient();
|
||||||
|
p.addIdentifier().setSystem("urn:system").setValue(string);
|
||||||
|
p.addName().addFamily("testSortF2").addGiven("testSortG2");
|
||||||
|
IIdType id2 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
p = new Patient();
|
||||||
|
p.addIdentifier().setSystem("urn:system").setValue(string);
|
||||||
|
IIdType id4 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
SearchParameterMap pm;
|
||||||
|
List<IIdType> actual;
|
||||||
|
|
||||||
|
pm = new SearchParameterMap();
|
||||||
|
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", string));
|
||||||
|
pm.setSort(new SortSpec(Patient.SP_FAMILY));
|
||||||
|
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
||||||
|
assertEquals(4, actual.size());
|
||||||
|
assertThat(actual, contains(id1, id2, id3, id4));
|
||||||
|
|
||||||
|
pm = new SearchParameterMap();
|
||||||
|
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", string));
|
||||||
|
pm.setSort(new SortSpec(Patient.SP_FAMILY).setOrder(SortOrderEnum.ASC));
|
||||||
|
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
||||||
|
assertEquals(4, actual.size());
|
||||||
|
assertThat(actual, contains(id1, id2, id3, id4));
|
||||||
|
|
||||||
|
pm = new SearchParameterMap();
|
||||||
|
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", string));
|
||||||
|
pm.setSort(new SortSpec(Patient.SP_FAMILY).setOrder(SortOrderEnum.DESC));
|
||||||
|
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
||||||
|
assertEquals(4, actual.size());
|
||||||
|
assertThat(actual, contains(id3, id2, id1, id4));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #198
|
* See #198
|
||||||
|
@ -2437,63 +2538,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
assertThat(names.subList(0, 2), contains("Giv2 Fam2", "Giv1 Fam2"));
|
assertThat(names.subList(0, 2), contains("Giv2 Fam2", "Giv1 Fam2"));
|
||||||
assertThat(names.subList(2, 4), contains("Giv2 Fam1", "Giv1 Fam1"));
|
assertThat(names.subList(2, 4), contains("Giv2 Fam1", "Giv1 Fam1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> extractNames(IBundleProvider theSearch) {
|
|
||||||
ArrayList<String> retVal = new ArrayList<String>();
|
|
||||||
for (IBaseResource next : theSearch.getResources(0, theSearch.size())) {
|
|
||||||
Patient nextPt = (Patient)next;
|
|
||||||
retVal.add(nextPt.getNameFirstRep().getNameAsSingleString());
|
|
||||||
}
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSortByString01() {
|
|
||||||
Patient p = new Patient();
|
|
||||||
String string = "testSortByString01";
|
|
||||||
p.addIdentifier().setSystem("urn:system").setValue(string);
|
|
||||||
p.addName().addFamily("testSortF1").addGiven("testSortG1");
|
|
||||||
IIdType id1 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
|
||||||
|
|
||||||
// Create out of order
|
|
||||||
p = new Patient();
|
|
||||||
p.addIdentifier().setSystem("urn:system").setValue(string);
|
|
||||||
p.addName().addFamily("testSortF3").addGiven("testSortG3");
|
|
||||||
IIdType id3 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
|
||||||
|
|
||||||
p = new Patient();
|
|
||||||
p.addIdentifier().setSystem("urn:system").setValue(string);
|
|
||||||
p.addName().addFamily("testSortF2").addGiven("testSortG2");
|
|
||||||
IIdType id2 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
|
||||||
|
|
||||||
p = new Patient();
|
|
||||||
p.addIdentifier().setSystem("urn:system").setValue(string);
|
|
||||||
IIdType id4 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
|
||||||
|
|
||||||
SearchParameterMap pm;
|
|
||||||
List<IIdType> actual;
|
|
||||||
|
|
||||||
pm = new SearchParameterMap();
|
|
||||||
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", string));
|
|
||||||
pm.setSort(new SortSpec(Patient.SP_FAMILY));
|
|
||||||
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
|
||||||
assertEquals(4, actual.size());
|
|
||||||
assertThat(actual, contains(id1, id2, id3, id4));
|
|
||||||
|
|
||||||
pm = new SearchParameterMap();
|
|
||||||
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", string));
|
|
||||||
pm.setSort(new SortSpec(Patient.SP_FAMILY).setOrder(SortOrderEnum.ASC));
|
|
||||||
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
|
||||||
assertEquals(4, actual.size());
|
|
||||||
assertThat(actual, contains(id1, id2, id3, id4));
|
|
||||||
|
|
||||||
pm = new SearchParameterMap();
|
|
||||||
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", string));
|
|
||||||
pm.setSort(new SortSpec(Patient.SP_FAMILY).setOrder(SortOrderEnum.DESC));
|
|
||||||
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
|
||||||
assertEquals(4, actual.size());
|
|
||||||
assertThat(actual, contains(id3, id2, id1, id4));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStoreUnversionedResources() {
|
public void testStoreUnversionedResources() {
|
||||||
|
@ -2906,6 +2950,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
ourCtx = new ClassPathXmlApplicationContext("hapi-fhir-server-resourceproviders-dstu2.xml", "fhir-jpabase-spring-test-config.xml");
|
ourCtx = new ClassPathXmlApplicationContext("hapi-fhir-server-resourceproviders-dstu2.xml", "fhir-jpabase-spring-test-config.xml");
|
||||||
ourPatientDao = ourCtx.getBean("myPatientDaoDstu2", IFhirResourceDao.class);
|
ourPatientDao = ourCtx.getBean("myPatientDaoDstu2", IFhirResourceDao.class);
|
||||||
|
ourPractitionerDao = ourCtx.getBean("myPractitionerDaoDstu2", IFhirResourceDao.class);
|
||||||
ourObservationDao = ourCtx.getBean("myObservationDaoDstu2", IFhirResourceDao.class);
|
ourObservationDao = ourCtx.getBean("myObservationDaoDstu2", IFhirResourceDao.class);
|
||||||
ourDiagnosticReportDao = ourCtx.getBean("myDiagnosticReportDaoDstu2", IFhirResourceDao.class);
|
ourDiagnosticReportDao = ourCtx.getBean("myDiagnosticReportDaoDstu2", IFhirResourceDao.class);
|
||||||
ourDeviceDao = ourCtx.getBean("myDeviceDaoDstu2", IFhirResourceDao.class);
|
ourDeviceDao = ourCtx.getBean("myDeviceDaoDstu2", IFhirResourceDao.class);
|
||||||
|
|
Loading…
Reference in New Issue