Added composite sort test case for R5
This commit is contained in:
parent
dcbdc83d8e
commit
0411967e26
|
@ -1,13 +1,16 @@
|
|||
package ca.uhn.fhir.jpa.provider.r5;
|
||||
|
||||
import ca.uhn.fhir.jpa.api.config.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.entity.Search;
|
||||
import ca.uhn.fhir.jpa.model.search.SearchStatusEnum;
|
||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
||||
import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor;
|
||||
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
@ -16,24 +19,29 @@ import org.apache.http.entity.ContentType;
|
|||
import org.apache.http.entity.StringEntity;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r5.model.Bundle;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.r5.model.CodeableConcept;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
import org.hl7.fhir.r5.model.IdType;
|
||||
import org.hl7.fhir.r5.model.Observation;
|
||||
import org.hl7.fhir.r5.model.Observation.ObservationComponentComponent;
|
||||
import org.hl7.fhir.r5.model.Patient;
|
||||
import org.hl7.fhir.r5.model.Quantity;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import ca.uhn.fhir.jpa.api.config.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.entity.Search;
|
||||
import ca.uhn.fhir.jpa.model.search.SearchStatusEnum;
|
||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
||||
import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor;
|
||||
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
public class ResourceProviderR5Test extends BaseResourceProviderR5Test {
|
||||
|
@ -246,5 +254,109 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test {
|
|||
assertEquals(0, output.getEntry().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithCompositeSort() throws IOException {
|
||||
|
||||
IIdType pid0;
|
||||
IIdType oid1;
|
||||
IIdType oid2;
|
||||
IIdType oid3;
|
||||
IIdType oid4;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
||||
patient.addName().setFamily("Tester").addGiven("Joe");
|
||||
pid0 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
{
|
||||
Observation obs = new Observation();
|
||||
obs.addIdentifier().setSystem("urn:system").setValue("FOO");
|
||||
obs.getSubject().setReferenceElement(pid0);
|
||||
|
||||
ObservationComponentComponent comp = obs.addComponent();
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("2345-7").setSystem("http://loinc.org");
|
||||
comp.setCode(cc);
|
||||
comp.setValue(new Quantity().setValue(200));
|
||||
|
||||
oid1 = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless();
|
||||
|
||||
ourLog.info("Observation: \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs));
|
||||
}
|
||||
|
||||
{
|
||||
Observation obs = new Observation();
|
||||
obs.addIdentifier().setSystem("urn:system").setValue("FOO");
|
||||
obs.getSubject().setReferenceElement(pid0);
|
||||
|
||||
ObservationComponentComponent comp = obs.addComponent();
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("2345-7").setSystem("http://loinc.org");
|
||||
comp.setCode(cc);
|
||||
comp.setValue(new Quantity().setValue(300));
|
||||
|
||||
oid2 = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless();
|
||||
|
||||
ourLog.info("Observation: \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs));
|
||||
}
|
||||
|
||||
{
|
||||
Observation obs = new Observation();
|
||||
obs.addIdentifier().setSystem("urn:system").setValue("FOO");
|
||||
obs.getSubject().setReferenceElement(pid0);
|
||||
|
||||
ObservationComponentComponent comp = obs.addComponent();
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("2345-7").setSystem("http://loinc.org");
|
||||
comp.setCode(cc);
|
||||
comp.setValue(new Quantity().setValue(150));
|
||||
|
||||
oid3 = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless();
|
||||
|
||||
ourLog.info("Observation: \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs));
|
||||
}
|
||||
|
||||
{
|
||||
Observation obs = new Observation();
|
||||
obs.addIdentifier().setSystem("urn:system").setValue("FOO");
|
||||
obs.getSubject().setReferenceElement(pid0);
|
||||
|
||||
ObservationComponentComponent comp = obs.addComponent();
|
||||
CodeableConcept cc = new CodeableConcept();
|
||||
cc.addCoding().setCode("2345-7").setSystem("http://loinc.org");
|
||||
comp.setCode(cc);
|
||||
comp.setValue(new Quantity().setValue(250));
|
||||
oid4 = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless();
|
||||
|
||||
ourLog.info("Observation: \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs));
|
||||
}
|
||||
|
||||
String uri = ourServerBase + "/Observation?_sort=combo-code-value-quantity";
|
||||
Bundle found;
|
||||
|
||||
HttpGet get = new HttpGet(uri);
|
||||
try (CloseableHttpResponse resp = ourHttpClient.execute(get)) {
|
||||
String output = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);
|
||||
found = myFhirCtx.newXmlParser().parseResource(Bundle.class, output);
|
||||
}
|
||||
|
||||
ourLog.info("Bundle: \n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(found));
|
||||
|
||||
List<IdType> list = toUnqualifiedVersionlessIds(found);
|
||||
assertEquals(4, found.getEntry().size());
|
||||
assertEquals(oid3, list.get(0));
|
||||
assertEquals(oid1, list.get(1));
|
||||
assertEquals(oid4, list.get(2));
|
||||
assertEquals(oid2, list.get(3));
|
||||
}
|
||||
|
||||
protected List<IdType> toUnqualifiedVersionlessIds(Bundle theFound) {
|
||||
List<IdType> retVal = new ArrayList<>();
|
||||
for (BundleEntryComponent next : theFound.getEntry()) {
|
||||
if (next.getResource()!= null) {
|
||||
retVal.add(next.getResource().getIdElement().toUnqualifiedVersionless());
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue