Merge branch 'dstu2_final' of github.com:jamesagnew/hapi-fhir into dstu2_final

This commit is contained in:
James Agnew 2015-08-09 17:38:19 -04:00
commit 4d8efb6455
6 changed files with 174 additions and 99 deletions

View File

@ -957,6 +957,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");

View File

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

View File

@ -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;
@ -100,7 +98,7 @@ import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
import ca.uhn.fhir.model.base.composite.BaseQuantityDt; import ca.uhn.fhir.model.base.composite.BaseQuantityDt;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum; import ca.uhn.fhir.model.dstu.resource.OperationOutcome.Issue;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum; import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
import ca.uhn.fhir.model.dstu2.composite.CodingDt; import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.composite.MetaDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt;
@ -133,6 +131,7 @@ import ca.uhn.fhir.util.ObjectUtil;
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseHapiFhirDao implements IFhirResourceDao<T> { public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseHapiFhirDao implements IFhirResourceDao<T> {
static final String OO_SEVERITY_WARN = "warning";
static final String OO_SEVERITY_INFO = "information"; static final String OO_SEVERITY_INFO = "information";
static final String OO_SEVERITY_ERROR = "error"; static final String OO_SEVERITY_ERROR = "error";
@ -381,8 +380,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) {
@ -1034,8 +1032,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;
@ -1054,8 +1051,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);
@ -1069,8 +1065,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) {
@ -1249,8 +1244,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());
@ -1327,8 +1321,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);
@ -1366,8 +1359,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);
@ -1851,8 +1844,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>();
@ -1900,8 +1893,9 @@ 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) Issue issue = oo.addIssue();
.setDetails("Not all _include resources were actually included as the request surpassed the limit of " + getConfig().getIncludeLimit() + " resources"); issue.getSeverity().setValue(OO_SEVERITY_WARN);
issue.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);
} }
} }
@ -2083,7 +2077,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;

View File

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

View File

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

View File

@ -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;
@ -48,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;
@ -61,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.QuestionnaireResponse; import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse;
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;
@ -111,6 +100,16 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
private static IFhirResourceDao<QuestionnaireResponse> ourQuestionnaireResponseDao; private static IFhirResourceDao<QuestionnaireResponse> ourQuestionnaireResponseDao;
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 testCreateOperationOutcome() { public void testCreateOperationOutcome() {
@ -125,6 +124,9 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
assertEquals(org.hl7.fhir.instance.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseHapiFhirResourceDao.OO_SEVERITY_INFO); assertEquals(org.hl7.fhir.instance.model.OperationOutcome.IssueSeverity.INFORMATION.toCode(), BaseHapiFhirResourceDao.OO_SEVERITY_INFO);
assertEquals(ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum.INFORMATION.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_INFO); assertEquals(ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum.INFORMATION.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_INFO);
assertEquals(ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum.INFORMATION.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_INFO); assertEquals(ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum.INFORMATION.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_INFO);
assertEquals(org.hl7.fhir.instance.model.OperationOutcome.IssueSeverity.WARNING.toCode(), BaseHapiFhirResourceDao.OO_SEVERITY_WARN);
assertEquals(ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum.WARNING.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_WARN);
assertEquals(ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum.WARNING.getCode(), BaseHapiFhirResourceDao.OO_SEVERITY_WARN);
} }
@Test @Test
@ -229,6 +231,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).getDiagnostics());
}
@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).getDiagnostics());
}
@Test @Test
public void testCreateTextIdFails() { public void testCreateTextIdFails() {
Patient p = new Patient(); Patient p = new Patient();
@ -1441,6 +1459,56 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
} }
} }
@Test
public void testSearchPractitionerPhoneAndEmailParam() {
String methodName = "testSearchPractitionerPhoneAndEmailParam";
IIdType id1;
{
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setValue("123");
id1 = ourPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
}
IIdType id2;
{
Practitioner patient = new Practitioner();
patient.getName().addFamily(methodName);
patient.addTelecom().setSystem(ContactPointSystemEnum.EMAIL).setValue("abc");
id2 = ourPractitionerDao.create(patient).getId().toUnqualifiedVersionless();
}
Map<String, IQueryParameterType> params;
List<IIdType> patients;
params = new HashMap<String, IQueryParameterType>();
params.put(Practitioner.SP_FAMILY, new StringDt(methodName));
patients = toUnqualifiedVersionlessIds(ourPractitionerDao.search(params));
assertEquals(2, patients.size());
assertThat(patients, containsInAnyOrder(id1, id2));
params = new HashMap<String, IQueryParameterType>();
params.put(Practitioner.SP_FAMILY, new StringParam(methodName));
params.put(Practitioner.SP_EMAIL, new TokenParam(null, "abc"));
patients = toUnqualifiedVersionlessIds(ourPractitionerDao.search(params));
assertEquals(1, patients.size());
assertThat(patients, containsInAnyOrder(id2));
params = new HashMap<String, IQueryParameterType>();
params.put(Practitioner.SP_FAMILY, new StringParam(methodName));
params.put(Practitioner.SP_EMAIL, new TokenParam(null, "123"));
patients = toUnqualifiedVersionlessIds(ourPractitionerDao.search(params));
assertEquals(0, patients.size());
params = new HashMap<String, IQueryParameterType>();
params.put(Practitioner.SP_FAMILY, new StringParam(methodName));
params.put(Practitioner.SP_PHONE, new TokenParam(null, "123"));
patients = toUnqualifiedVersionlessIds(ourPractitionerDao.search(params));
assertEquals(1, patients.size());
assertThat(patients, containsInAnyOrder(id1));
}
@Test @Test
public void testSearchNameParam() { public void testSearchNameParam() {
IIdType id1; IIdType id1;
@ -1705,6 +1773,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
} }
@Test @Test
public void testSearchStringParam() { public void testSearchStringParam() {
{ {
@ -1761,7 +1830,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
} }
@Test @Test
public void testSearchStringParamWithNonNormalized() { public void testSearchStringParamWithNonNormalized() {
{ {
@ -2461,6 +2529,54 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
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
*/ */
@ -2525,63 +2641,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
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() {
Organization o1 = new Organization(); Organization o1 = new Organization();
@ -2993,6 +3052,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);