|
|
|
@ -42,10 +42,7 @@ import org.apache.http.entity.ContentType;
|
|
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.*;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.SearchEntryMode;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.*;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Encounter.EncounterLocationComponent;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Encounter.EncounterStatus;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
|
|
|
|
@ -74,6 +71,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
|
|
|
|
import ca.uhn.fhir.rest.api.SummaryEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.api.ValidationModeEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.client.IGenericClient;
|
|
|
|
|
import ca.uhn.fhir.rest.gclient.StringClientParam;
|
|
|
|
|
import ca.uhn.fhir.rest.param.*;
|
|
|
|
|
import ca.uhn.fhir.rest.server.Constants;
|
|
|
|
|
import ca.uhn.fhir.rest.server.IBundleProvider;
|
|
|
|
@ -101,13 +99,13 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
obs1.setValue(new Quantity(123));
|
|
|
|
|
obs1.setComment("obs1");
|
|
|
|
|
IIdType id1 = myObservationDao.create(obs1, mySrd).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Observation obs2 = new Observation();
|
|
|
|
|
obs2.getCode().setText("Diastolic Blood Pressure");
|
|
|
|
|
obs2.setStatus(ObservationStatus.FINAL);
|
|
|
|
|
obs2.setValue(new Quantity(81));
|
|
|
|
|
IIdType id2 = myObservationDao.create(obs2, mySrd).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpGet get = new HttpGet(ourServerBase + "/Observation?_content=systolic&_pretty=true");
|
|
|
|
|
CloseableHttpResponse response = ourHttpClient.execute(get);
|
|
|
|
|
try {
|
|
|
|
@ -119,7 +117,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
response.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See #441
|
|
|
|
|
*/
|
|
|
|
@ -128,7 +126,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
Medication medication = new Medication();
|
|
|
|
|
medication.getCode().addCoding().setSystem("SYSTEM").setCode("04823543");
|
|
|
|
|
IIdType medId = myMedicationDao.create(medication).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MedicationAdministration ma = new MedicationAdministration();
|
|
|
|
|
ma.setMedication(new Reference(medId));
|
|
|
|
|
IIdType moId = myMedicationAdministrationDao.create(ma).getId().toUnqualifiedVersionless();
|
|
|
|
@ -146,8 +144,6 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Per message from David Hay on Skype
|
|
|
|
|
*/
|
|
|
|
@ -156,32 +152,26 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
String inputString = IOUtils.toString(getClass().getResourceAsStream("/david_big_bundle.json"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle inputBundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, inputString);
|
|
|
|
|
inputBundle.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<String> allIds = new TreeSet<String>();
|
|
|
|
|
for (BundleEntryComponent nextEntry : inputBundle.getEntry()) {
|
|
|
|
|
nextEntry.getRequest().setMethod(HTTPVerb.PUT);
|
|
|
|
|
nextEntry.getRequest().setUrl(nextEntry.getResource().getId());
|
|
|
|
|
allIds.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mySystemDao.transaction(mySrd, inputBundle);
|
|
|
|
|
|
|
|
|
|
Bundle responseBundle = ourClient
|
|
|
|
|
.operation()
|
|
|
|
|
.onInstance(new IdType("Patient/A161443"))
|
|
|
|
|
.named("everything")
|
|
|
|
|
.withParameter(Parameters.class, "_count", new IntegerType(50))
|
|
|
|
|
.useHttpGet()
|
|
|
|
|
.returnResourceType(Bundle.class)
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
Bundle responseBundle = ourClient.operation().onInstance(new IdType("Patient/A161443")).named("everything").withParameter(Parameters.class, "_count", new IntegerType(50)).useHttpGet()
|
|
|
|
|
.returnResourceType(Bundle.class).execute();
|
|
|
|
|
|
|
|
|
|
TreeSet<String> ids = new TreeSet<String>();
|
|
|
|
|
for (int i = 0; i < responseBundle.getEntry().size(); i++) {
|
|
|
|
|
for (BundleEntryComponent nextEntry : responseBundle.getEntry()) {
|
|
|
|
|
ids.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String nextUrl = responseBundle.getLink("next").getUrl();
|
|
|
|
|
responseBundle = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl);
|
|
|
|
|
for (int i = 0; i < responseBundle.getEntry().size(); i++) {
|
|
|
|
@ -189,20 +179,84 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
ids.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(ids, hasItem("List/A161444"));
|
|
|
|
|
assertThat(ids, hasItem("List/A161468"));
|
|
|
|
|
assertThat(ids, hasItem("List/A161500"));
|
|
|
|
|
|
|
|
|
|
assertEquals(null, responseBundle.getLink("next"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ourLog.info("Expected {} - {}", allIds.size(), allIds);
|
|
|
|
|
ourLog.info("Actual {} - {}", ids.size(), ids);
|
|
|
|
|
assertEquals(allIds, ids);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Per message from David Hay on Skype
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testEverythingWithLargeSet2() throws Exception {
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.setActive(true);
|
|
|
|
|
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < 77; i++) {
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.setId("A" + StringUtils.leftPad(Integer.toString(i), 2, '0'));
|
|
|
|
|
obs.setSubject(new Reference(id));
|
|
|
|
|
ourClient.update().resource(obs).execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bundle responseBundle = ourClient.operation().onInstance(id).named("everything").withParameter(Parameters.class, "_count", new IntegerType(50)).useHttpGet().returnResourceType(Bundle.class)
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
TreeSet<String> ids = new TreeSet<String>();
|
|
|
|
|
for (int i = 0; i < responseBundle.getEntry().size(); i++) {
|
|
|
|
|
for (BundleEntryComponent nextEntry : responseBundle.getEntry()) {
|
|
|
|
|
ids.add(nextEntry.getResource().getIdElement().getIdPart());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ourLog.info("Have {} IDs: {}", ids.size(), ids);
|
|
|
|
|
|
|
|
|
|
BundleLinkComponent nextLink = responseBundle.getLink("next");
|
|
|
|
|
while (nextLink != null) {
|
|
|
|
|
String nextUrl = nextLink.getUrl();
|
|
|
|
|
responseBundle = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl);
|
|
|
|
|
for (int i = 0; i < responseBundle.getEntry().size(); i++) {
|
|
|
|
|
for (BundleEntryComponent nextEntry : responseBundle.getEntry()) {
|
|
|
|
|
ids.add(nextEntry.getResource().getIdElement().getIdPart());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ourLog.info("Have {} IDs: {}", ids.size(), ids);
|
|
|
|
|
nextLink = responseBundle.getLink("next");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assertThat(ids, hasItem(id.getIdPart()));
|
|
|
|
|
for (int i = 1; i < 77; i++) {
|
|
|
|
|
assertThat(ids, hasItem("A" + StringUtils.leftPad(Integer.toString(i), 2, '0')));
|
|
|
|
|
}
|
|
|
|
|
assertEquals(77, ids.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEmptySearch() throws Exception {
|
|
|
|
|
Bundle responseBundle;
|
|
|
|
|
|
|
|
|
|
responseBundle = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute();
|
|
|
|
|
assertEquals(0, responseBundle.getTotal());
|
|
|
|
|
|
|
|
|
|
responseBundle = ourClient.search().forResource(Patient.class).where(Patient.NAME.matches().value("AAA")).returnBundle(Bundle.class).execute();
|
|
|
|
|
assertEquals(0, responseBundle.getTotal());
|
|
|
|
|
|
|
|
|
|
responseBundle = ourClient.search().forResource(Patient.class).where(new StringClientParam("_content").matches().value("AAA")).returnBundle(Bundle.class).execute();
|
|
|
|
|
assertEquals(0, responseBundle.getTotal());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See #411
|
|
|
|
|
*
|
|
|
|
@ -214,15 +268,15 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
patient.addIdentifier().setSystem("urn:system").setValue("0");
|
|
|
|
|
patient.addName().addFamily("testSearchWithMixedParams").addGiven("Joe");
|
|
|
|
|
myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(ourServerBase + "/Patient/_search?_format=application/xml");
|
|
|
|
|
httpPost.addHeader("Cache-Control","no-cache");
|
|
|
|
|
|
|
|
|
|
HttpPost httpPost = new HttpPost(ourServerBase + "/Patient/_search?_format=application/xml");
|
|
|
|
|
httpPost.addHeader("Cache-Control", "no-cache");
|
|
|
|
|
List<NameValuePair> parameters = Lists.newArrayList();
|
|
|
|
|
parameters.add(new BasicNameValuePair("name", "Smith"));
|
|
|
|
|
httpPost.setEntity(new UrlEncodedFormEntity(parameters));
|
|
|
|
|
|
|
|
|
|
ourLog.info("Outgoing post: {}", httpPost);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpResponse status = ourHttpClient.execute(httpPost);
|
|
|
|
|
try {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
|
|
|
|
@ -234,7 +288,6 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSearchPagingKeepsOldSearches() throws Exception {
|
|
|
|
|
String methodName = "testSearchPagingKeepsOldSearches";
|
|
|
|
@ -1875,7 +1928,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
|
|
|
|
|
|
|
|
|
assertEquals(id.withVersion("1").getValue(), history.getEntry().get(2).getResource().getId());
|
|
|
|
|
assertEquals(1, ((Patient) history.getEntry().get(2).getResource()).getName().size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
myBundleDao.validate(history, null, null, null, null, null, mySrd);
|
|
|
|
|
} catch (PreconditionFailedException e) {
|
|
|
|
|