|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package ca.uhn.fhir.jpa.dao.dstu3;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.hamcrest.Matchers.empty;
|
|
|
|
|
import static org.hamcrest.Matchers.emptyString;
|
|
|
|
|
import static org.hamcrest.Matchers.endsWith;
|
|
|
|
|
import static org.hamcrest.Matchers.greaterThan;
|
|
|
|
@ -27,25 +28,14 @@ import java.util.List;
|
|
|
|
|
import javax.mail.Quota.Resource;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Appointment;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.*;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryResponseComponent;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Coding;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.IdType;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Medication;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.MedicationOrder;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Meta;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Observation;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.OperationOutcome;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Patient;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Reference;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.UriType;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.ValueSet;
|
|
|
|
|
import org.hl7.fhir.instance.model.api.IAnyResource;
|
|
|
|
|
import org.hl7.fhir.instance.model.api.IIdType;
|
|
|
|
|
import org.junit.After;
|
|
|
|
@ -68,10 +58,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
|
|
|
|
|
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
|
|
|
|
import ca.uhn.fhir.rest.server.Constants;
|
|
|
|
|
import ca.uhn.fhir.rest.server.IBundleProvider;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.*;
|
|
|
|
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
|
|
|
|
import ca.uhn.fhir.util.TestUtil;
|
|
|
|
|
|
|
|
|
@ -79,62 +66,9 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu3Test.class);
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClassClearContext() {
|
|
|
|
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See #410
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testContainedArePreservedForBug410() throws IOException {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/bug-410-bundle.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
Bundle output = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output));
|
|
|
|
|
|
|
|
|
|
IdType id = new IdType(output.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
MedicationOrder mo = myMedicationOrderDao.read(id);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(mo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionDoesNotAllowDanglingTemporaryIds() throws Exception {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/cdr-bundle.json"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
BundleEntryComponent entry = bundle.addEntry();
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.getManagingOrganization().setReference("urn:uuid:30ce60cf-f7cb-4196-961f-cadafa8b7ff5");
|
|
|
|
|
entry.setResource(p);
|
|
|
|
|
entry.getRequest().setMethod(HTTPVerb.POST);
|
|
|
|
|
entry.getRequest().setUrl("Patient");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (InvalidRequestException e) {
|
|
|
|
|
assertEquals("Unable to satisfy placeholder ID: urn:uuid:30ce60cf-f7cb-4196-961f-cadafa8b7ff5", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionDoesNotLeavePlaceholderIds() throws Exception {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/cdr-bundle.json"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, input);
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
IBundleProvider history = mySystemDao.history(null, null, null);
|
|
|
|
|
Bundle list = toBundle(history);
|
|
|
|
|
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(list));
|
|
|
|
|
|
|
|
|
|
assertEquals(6, list.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p = find(list, Patient.class, 0);
|
|
|
|
|
assertTrue(p.getIdElement().isIdPartValidLong());
|
|
|
|
|
assertTrue(p.getGeneralPractitionerFirstRep().getReferenceElement().isIdPartValidLong());
|
|
|
|
|
@After
|
|
|
|
|
public void after() {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@ -153,89 +87,61 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See #410
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionFromBundle2() throws Exception {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/transaction-bundle.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
public void testContainedArePreservedForBug410() throws IOException {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/bug-410-bundle.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
Bundle response = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
|
|
|
|
assertEquals("201 Created", response.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertThat(response.getEntry().get(0).getResponse().getLocation(), matchesPattern("Practitioner/[0-9]+/_history/1"));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Now a second time
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
response = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
|
|
|
|
assertEquals("200 OK", response.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertThat(response.getEntry().get(0).getResponse().getLocation(), matchesPattern("Practitioner/[0-9]+/_history/1"));
|
|
|
|
|
Bundle output = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output));
|
|
|
|
|
|
|
|
|
|
IdType id = new IdType(output.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
MedicationOrder mo = myMedicationOrderDao.read(id);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(mo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithNullReference() {
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addName().addFamily("family");
|
|
|
|
|
final IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
|
|
|
|
|
public void testDeleteWithHas() {
|
|
|
|
|
Observation obs1 = new Observation();
|
|
|
|
|
obs1.setStatus(ObservationStatus.FINAL);
|
|
|
|
|
IIdType obs1id = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
Bundle inputBundle = new Bundle();
|
|
|
|
|
Observation obs2 = new Observation();
|
|
|
|
|
obs2.setStatus(ObservationStatus.FINAL);
|
|
|
|
|
IIdType obs2id = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
Patient app0 = new Patient();
|
|
|
|
|
app0.addName().addFamily("NEW PATIENT");
|
|
|
|
|
String placeholderId0 = IdDt.newRandomUuid().getValue();
|
|
|
|
|
inputBundle
|
|
|
|
|
.addEntry()
|
|
|
|
|
.setResource(app0)
|
|
|
|
|
.setFullUrl(placeholderId0)
|
|
|
|
|
.getRequest()
|
|
|
|
|
.setMethod(HTTPVerb.POST)
|
|
|
|
|
.setUrl("Patient");
|
|
|
|
|
//@formatter:on
|
|
|
|
|
DiagnosticReport rpt = new DiagnosticReport();
|
|
|
|
|
rpt.addIdentifier().setSystem("foo").setValue("IDENTIFIER");
|
|
|
|
|
rpt.addResult(new Reference(obs2id));
|
|
|
|
|
IIdType rptId = myDiagnosticReportDao.create(rpt).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
Appointment app1 = new Appointment();
|
|
|
|
|
app1.addParticipant().getActor().setReference(id.getValue());
|
|
|
|
|
inputBundle
|
|
|
|
|
.addEntry()
|
|
|
|
|
.setResource(app1)
|
|
|
|
|
.getRequest()
|
|
|
|
|
.setMethod(HTTPVerb.POST)
|
|
|
|
|
.setUrl("Appointment");
|
|
|
|
|
//@formatter:on
|
|
|
|
|
myObservationDao.read(obs1id);
|
|
|
|
|
myObservationDao.read(obs2id);
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
Appointment app2 = new Appointment();
|
|
|
|
|
app2.addParticipant().getActor().setDisplay("NO REF");
|
|
|
|
|
app2.addParticipant().getActor().setDisplay("YES REF").setReference(placeholderId0);
|
|
|
|
|
inputBundle
|
|
|
|
|
.addEntry()
|
|
|
|
|
.setResource(app2)
|
|
|
|
|
.getRequest()
|
|
|
|
|
.setMethod(HTTPVerb.POST)
|
|
|
|
|
.setUrl("Appointment");
|
|
|
|
|
//@formatter:on
|
|
|
|
|
rpt = new DiagnosticReport();
|
|
|
|
|
rpt.addIdentifier().setSystem("foo").setValue("IDENTIFIER");
|
|
|
|
|
|
|
|
|
|
Bundle outputBundle = mySystemDao.transaction(mySrd, inputBundle);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(outputBundle));
|
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
|
b.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Observation?_has:DiagnosticReport:result:identifier=foo|IDENTIFIER");
|
|
|
|
|
b.addEntry().setResource(rpt).getRequest().setMethod(HTTPVerb.PUT).setUrl("DiagnosticReport?identifier=foo|IDENTIFIER");
|
|
|
|
|
mySystemDao.transaction(mySrd, b);
|
|
|
|
|
|
|
|
|
|
assertEquals(3, outputBundle.getEntry().size());
|
|
|
|
|
IdDt id0 = new IdDt(outputBundle.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdDt id2 = new IdDt(outputBundle.getEntry().get(2).getResponse().getLocation());
|
|
|
|
|
myObservationDao.read(obs1id);
|
|
|
|
|
try {
|
|
|
|
|
myObservationDao.read(obs2id);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (ResourceGoneException e) {
|
|
|
|
|
// good
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app2 = myAppointmentDao.read(id2, mySrd);
|
|
|
|
|
assertEquals("NO REF", app2.getParticipant().get(0).getActor().getDisplay());
|
|
|
|
|
assertEquals(null, app2.getParticipant().get(0).getActor().getReference());
|
|
|
|
|
assertEquals("YES REF", app2.getParticipant().get(1).getActor().getDisplay());
|
|
|
|
|
assertEquals(id0.toUnqualifiedVersionless().getValue(), app2.getParticipant().get(1).getActor().getReference());
|
|
|
|
|
rpt = myDiagnosticReportDao.read(rptId);
|
|
|
|
|
assertThat(rpt.getResult(), empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testReindexing() {
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
@ -431,108 +337,28 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInlineMatchUrl() throws Exception {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.addIdentifier().setSystem("http://www.ghh.org/identifiers").setValue("condreftestpatid1");
|
|
|
|
|
myPatientDao.create(patient, mySrd);
|
|
|
|
|
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/simone-conditional-url.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
Bundle response = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInlineMatchUrlMultipleMatches() throws Exception {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.addIdentifier().setSystem("http://www.ghh.org/identifiers").setValue("condreftestpatid1");
|
|
|
|
|
myPatientDao.create(patient, mySrd);
|
|
|
|
|
|
|
|
|
|
patient = new Patient();
|
|
|
|
|
patient.addIdentifier().setSystem("http://www.ghh.org/identifiers").setValue("condreftestpatid1");
|
|
|
|
|
myPatientDao.create(patient, mySrd);
|
|
|
|
|
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/simone-conditional-url.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (PreconditionFailedException e) {
|
|
|
|
|
assertEquals("Invalid match URL \"Patient?identifier=http://www.ghh.org/identifiers|condreftestpatid1\" - Multiple resources match this search", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInlineMatchUrlNoMatches() throws Exception {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/simone-conditional-url.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (ResourceNotFoundException e) {
|
|
|
|
|
assertEquals("Invalid match URL \"Patient?identifier=http://www.ghh.org/identifiers|condreftestpatid1\" - No resources match this search", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateMatchUrlWithOneMatch() {
|
|
|
|
|
String methodName = "testTransactionCreateMatchUrlWithOneMatch";
|
|
|
|
|
public void testTransactionCreateInlineMatchUrlWithNoMatches() {
|
|
|
|
|
String methodName = "testTransactionCreateInlineMatchUrlWithNoMatches";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
p.setId("Patient/" + methodName);
|
|
|
|
|
IIdType id = myPatientDao.update(p, mySrd).getId();
|
|
|
|
|
ourLog.info("Created patient, got it: {}", id);
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
p.addName().addFamily("Hello");
|
|
|
|
|
p.setId("Patient/" + methodName);
|
|
|
|
|
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setIfNoneExist("Patient?identifier=urn%3Asystem%7C" + methodName);
|
|
|
|
|
|
|
|
|
|
Observation o = new Observation();
|
|
|
|
|
o.getCode().setText("Some Observation");
|
|
|
|
|
o.getSubject().setReference("Patient/" + methodName);
|
|
|
|
|
o.getSubject().setReference("Patient?identifier=urn%3Asystem%7C" + methodName);
|
|
|
|
|
request.addEntry().setResource(o).getRequest().setMethod(HTTPVerb.POST);
|
|
|
|
|
|
|
|
|
|
Bundle resp = mySystemDao.transaction(mySrd, request);
|
|
|
|
|
assertEquals(2, resp.getEntry().size());
|
|
|
|
|
|
|
|
|
|
BundleEntryComponent respEntry = resp.getEntry().get(0);
|
|
|
|
|
assertEquals(Constants.STATUS_HTTP_200_OK + " OK", respEntry.getResponse().getStatus());
|
|
|
|
|
assertThat(respEntry.getResponse().getLocation(), endsWith("Patient/" + id.getIdPart() + "/_history/1"));
|
|
|
|
|
assertEquals("1", respEntry.getResponse().getEtag());
|
|
|
|
|
|
|
|
|
|
respEntry = resp.getEntry().get(1);
|
|
|
|
|
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
|
|
|
|
|
assertThat(respEntry.getResponse().getLocation(), containsString("Observation/"));
|
|
|
|
|
assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1"));
|
|
|
|
|
assertEquals("1", respEntry.getResponse().getEtag());
|
|
|
|
|
|
|
|
|
|
o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()), mySrd);
|
|
|
|
|
assertEquals(id.toVersionless().getValue(), o.getSubject().getReference());
|
|
|
|
|
assertEquals("1", o.getIdElement().getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (ResourceNotFoundException e) {
|
|
|
|
|
assertEquals("Invalid match URL \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateInlineMatchUrlWithNoMatches\" - No resources match this search", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void after() {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateInlineMatchUrlWithOneMatch() {
|
|
|
|
@ -635,27 +461,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateInlineMatchUrlWithNoMatches() {
|
|
|
|
|
String methodName = "testTransactionCreateInlineMatchUrlWithNoMatches";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Observation o = new Observation();
|
|
|
|
|
o.getCode().setText("Some Observation");
|
|
|
|
|
o.getSubject().setReference("Patient?identifier=urn%3Asystem%7C" + methodName);
|
|
|
|
|
request.addEntry().setResource(o).getRequest().setMethod(HTTPVerb.POST);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (ResourceNotFoundException e) {
|
|
|
|
|
assertEquals("Invalid match URL \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateInlineMatchUrlWithNoMatches\" - No resources match this search", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateInlineMatchUrlWithTwoMatches() {
|
|
|
|
|
String methodName = "testTransactionCreateInlineMatchUrlWithTwoMatches";
|
|
|
|
@ -684,6 +489,48 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateMatchUrlWithOneMatch() {
|
|
|
|
|
String methodName = "testTransactionCreateMatchUrlWithOneMatch";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
p.setId("Patient/" + methodName);
|
|
|
|
|
IIdType id = myPatientDao.update(p, mySrd).getId();
|
|
|
|
|
ourLog.info("Created patient, got it: {}", id);
|
|
|
|
|
|
|
|
|
|
p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
p.addName().addFamily("Hello");
|
|
|
|
|
p.setId("Patient/" + methodName);
|
|
|
|
|
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setIfNoneExist("Patient?identifier=urn%3Asystem%7C" + methodName);
|
|
|
|
|
|
|
|
|
|
Observation o = new Observation();
|
|
|
|
|
o.getCode().setText("Some Observation");
|
|
|
|
|
o.getSubject().setReference("Patient/" + methodName);
|
|
|
|
|
request.addEntry().setResource(o).getRequest().setMethod(HTTPVerb.POST);
|
|
|
|
|
|
|
|
|
|
Bundle resp = mySystemDao.transaction(mySrd, request);
|
|
|
|
|
assertEquals(2, resp.getEntry().size());
|
|
|
|
|
|
|
|
|
|
BundleEntryComponent respEntry = resp.getEntry().get(0);
|
|
|
|
|
assertEquals(Constants.STATUS_HTTP_200_OK + " OK", respEntry.getResponse().getStatus());
|
|
|
|
|
assertThat(respEntry.getResponse().getLocation(), endsWith("Patient/" + id.getIdPart() + "/_history/1"));
|
|
|
|
|
assertEquals("1", respEntry.getResponse().getEtag());
|
|
|
|
|
|
|
|
|
|
respEntry = resp.getEntry().get(1);
|
|
|
|
|
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
|
|
|
|
|
assertThat(respEntry.getResponse().getLocation(), containsString("Observation/"));
|
|
|
|
|
assertThat(respEntry.getResponse().getLocation(), endsWith("/_history/1"));
|
|
|
|
|
assertEquals("1", respEntry.getResponse().getEtag());
|
|
|
|
|
|
|
|
|
|
o = (Observation) myObservationDao.read(new IdType(respEntry.getResponse().getLocationElement()), mySrd);
|
|
|
|
|
assertEquals(id.toVersionless().getValue(), o.getSubject().getReference());
|
|
|
|
|
assertEquals("1", o.getIdElement().getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateMatchUrlWithTwoMatch() {
|
|
|
|
|
String methodName = "testTransactionCreateMatchUrlWithTwoMatch";
|
|
|
|
@ -836,49 +683,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithPutUsingUrl() {
|
|
|
|
|
String methodName = "testTransactionCreateWithPutUsingUrl";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
request.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
Observation o = new Observation();
|
|
|
|
|
o.getSubject().setReference("Patient/" + methodName);
|
|
|
|
|
request.addEntry().setResource(o).getRequest().setMethod(HTTPVerb.PUT).setUrl("Observation/a" + methodName);
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.PUT).setUrl("Patient/" + methodName);
|
|
|
|
|
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
|
|
|
|
|
myObservationDao.read(new IdType("Observation/a" + methodName), mySrd);
|
|
|
|
|
myPatientDao.read(new IdType("Patient/" + methodName), mySrd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithPutUsingAbsoluteUrl() {
|
|
|
|
|
String methodName = "testTransactionCreateWithPutUsingAbsoluteUrl";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
request.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.PUT).setUrl("http://localhost/server/base/Patient/" + methodName);
|
|
|
|
|
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
|
|
|
|
|
myPatientDao.read(new IdType("Patient/" + methodName), mySrd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithPutUsingUrl2() throws Exception {
|
|
|
|
|
String req = IOUtils.toString(FhirSystemDaoDstu3Test.class.getResourceAsStream("/bundle-dstu3.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle request = myFhirCtx.newXmlParser().parseResource(Bundle.class, req);
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithInvalidMatchUrl() {
|
|
|
|
|
String methodName = "testTransactionCreateWithInvalidMatchUrl";
|
|
|
|
@ -952,6 +756,48 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithPutUsingAbsoluteUrl() {
|
|
|
|
|
String methodName = "testTransactionCreateWithPutUsingAbsoluteUrl";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
request.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.PUT).setUrl("http://localhost/server/base/Patient/" + methodName);
|
|
|
|
|
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
|
|
|
|
|
myPatientDao.read(new IdType("Patient/" + methodName), mySrd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithPutUsingUrl() {
|
|
|
|
|
String methodName = "testTransactionCreateWithPutUsingUrl";
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
|
request.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
Observation o = new Observation();
|
|
|
|
|
o.getSubject().setReference("Patient/" + methodName);
|
|
|
|
|
request.addEntry().setResource(o).getRequest().setMethod(HTTPVerb.PUT).setUrl("Observation/a" + methodName);
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
|
|
|
|
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.PUT).setUrl("Patient/" + methodName);
|
|
|
|
|
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
|
|
|
|
|
myObservationDao.read(new IdType("Observation/a" + methodName), mySrd);
|
|
|
|
|
myPatientDao.read(new IdType("Patient/" + methodName), mySrd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionCreateWithPutUsingUrl2() throws Exception {
|
|
|
|
|
String req = IOUtils.toString(FhirSystemDaoDstu3Test.class.getResourceAsStream("/bundle-dstu3.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle request = myFhirCtx.newXmlParser().parseResource(Bundle.class, req);
|
|
|
|
|
mySystemDao.transaction(mySrd, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionDeleteByResourceId() {
|
|
|
|
|
String methodName = "testTransactionDeleteByResourceId";
|
|
|
|
@ -1188,6 +1034,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionDeleteMatchUrlWithZeroMatch() {
|
|
|
|
|
String methodName = "testTransactionDeleteMatchUrlWithZeroMatch";
|
|
|
|
@ -1232,6 +1079,43 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionDoesNotAllowDanglingTemporaryIds() throws Exception {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/cdr-bundle.json"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
BundleEntryComponent entry = bundle.addEntry();
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.getManagingOrganization().setReference("urn:uuid:30ce60cf-f7cb-4196-961f-cadafa8b7ff5");
|
|
|
|
|
entry.setResource(p);
|
|
|
|
|
entry.getRequest().setMethod(HTTPVerb.POST);
|
|
|
|
|
entry.getRequest().setUrl("Patient");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (InvalidRequestException e) {
|
|
|
|
|
assertEquals("Unable to satisfy placeholder ID: urn:uuid:30ce60cf-f7cb-4196-961f-cadafa8b7ff5", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionDoesNotLeavePlaceholderIds() throws Exception {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/cdr-bundle.json"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, input);
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
IBundleProvider history = mySystemDao.history(null, null, null);
|
|
|
|
|
Bundle list = toBundle(history);
|
|
|
|
|
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(list));
|
|
|
|
|
|
|
|
|
|
assertEquals(6, list.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p = find(list, Patient.class, 0);
|
|
|
|
|
assertTrue(p.getIdElement().isIdPartValidLong());
|
|
|
|
|
assertTrue(p.getGeneralPractitionerFirstRep().getReferenceElement().isIdPartValidLong());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected = InvalidRequestException.class)
|
|
|
|
|
public void testTransactionFailsWithDuplicateIds() {
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
@ -1268,44 +1152,26 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
assertEquals("Patient/temp6789", p.getLink().get(0).getOther().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format changed, source isn't valid
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testTransactionWithBundledValidationSourceAndTarget() throws Exception {
|
|
|
|
|
public void testTransactionFromBundle2() throws Exception {
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/transaction-bundle.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
Bundle response = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/questionnaire-sdc-profile-example-ussg-fht.xml");
|
|
|
|
|
String bundleStr = IOUtils.toString(bundleRes, StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, bundleStr);
|
|
|
|
|
|
|
|
|
|
Bundle resp = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp);
|
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
encoded = myFhirCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(resp);
|
|
|
|
|
//@formatter:off
|
|
|
|
|
assertThat(encoded, containsString("\"response\":{" +
|
|
|
|
|
"\"status\":\"201 Created\"," +
|
|
|
|
|
"\"location\":\"Questionnaire/54127-6/_history/1\","));
|
|
|
|
|
//@formatter:on
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
|
|
|
|
assertEquals("201 Created", response.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertThat(response.getEntry().get(0).getResponse().getLocation(), matchesPattern("Practitioner/[0-9]+/_history/1"));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Upload again to update
|
|
|
|
|
* Now a second time
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
resp = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
response = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp);
|
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
encoded = myFhirCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(resp);
|
|
|
|
|
//@formatter:off
|
|
|
|
|
assertThat(encoded, containsString("\"response\":{" +
|
|
|
|
|
"\"status\":\"200 OK\"," +
|
|
|
|
|
"\"location\":\"Questionnaire/54127-6/_history/2\","));
|
|
|
|
|
//@formatter:on
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
|
|
|
|
assertEquals("200 OK", response.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertThat(response.getEntry().get(0).getResponse().getLocation(), matchesPattern("Practitioner/[0-9]+/_history/1"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1367,6 +1233,25 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Bundle testTransactionOrderingCreateBundle(String methodName, int pass, IdType patientPlaceholderId) {
|
|
|
|
|
Bundle req = new Bundle();
|
|
|
|
|
req.addEntry().getRequest().setMethod(HTTPVerb.GET).setUrl("Patient?identifier=" + methodName);
|
|
|
|
|
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.getSubject().setReferenceElement(patientPlaceholderId);
|
|
|
|
|
obs.addIdentifier().setValue(methodName);
|
|
|
|
|
obs.getCode().setText(methodName + pass);
|
|
|
|
|
req.addEntry().setResource(obs).getRequest().setMethod(HTTPVerb.PUT).setUrl("Observation?identifier=" + methodName);
|
|
|
|
|
|
|
|
|
|
Patient pat = new Patient();
|
|
|
|
|
pat.addIdentifier().setValue(methodName);
|
|
|
|
|
pat.addName().addFamily(methodName + pass);
|
|
|
|
|
req.addEntry().setResource(pat).setFullUrl(patientPlaceholderId.getValue()).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient");
|
|
|
|
|
|
|
|
|
|
req.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient?identifier=" + methodName);
|
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void testTransactionOrderingValidateResponse(int pass, Bundle resp) {
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));
|
|
|
|
|
assertEquals(4, resp.getEntry().size());
|
|
|
|
@ -1395,25 +1280,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
assertThat(respGetBundle.getLink("self").getUrl(), endsWith("/Patient?identifier=testTransactionOrdering"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Bundle testTransactionOrderingCreateBundle(String methodName, int pass, IdType patientPlaceholderId) {
|
|
|
|
|
Bundle req = new Bundle();
|
|
|
|
|
req.addEntry().getRequest().setMethod(HTTPVerb.GET).setUrl("Patient?identifier=" + methodName);
|
|
|
|
|
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.getSubject().setReferenceElement(patientPlaceholderId);
|
|
|
|
|
obs.addIdentifier().setValue(methodName);
|
|
|
|
|
obs.getCode().setText(methodName + pass);
|
|
|
|
|
req.addEntry().setResource(obs).getRequest().setMethod(HTTPVerb.PUT).setUrl("Observation?identifier=" + methodName);
|
|
|
|
|
|
|
|
|
|
Patient pat = new Patient();
|
|
|
|
|
pat.addIdentifier().setValue(methodName);
|
|
|
|
|
pat.addName().addFamily(methodName + pass);
|
|
|
|
|
req.addEntry().setResource(pat).setFullUrl(patientPlaceholderId.getValue()).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient");
|
|
|
|
|
|
|
|
|
|
req.addEntry().getRequest().setMethod(HTTPVerb.DELETE).setUrl("Patient?identifier=" + methodName);
|
|
|
|
|
return req;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionReadAndSearch() {
|
|
|
|
|
String methodName = "testTransactionReadAndSearch";
|
|
|
|
@ -1746,6 +1612,103 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format changed, source isn't valid
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testTransactionWithBundledValidationSourceAndTarget() throws Exception {
|
|
|
|
|
|
|
|
|
|
InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/questionnaire-sdc-profile-example-ussg-fht.xml");
|
|
|
|
|
String bundleStr = IOUtils.toString(bundleRes, StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, bundleStr);
|
|
|
|
|
|
|
|
|
|
Bundle resp = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp);
|
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
encoded = myFhirCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(resp);
|
|
|
|
|
//@formatter:off
|
|
|
|
|
assertThat(encoded, containsString("\"response\":{" +
|
|
|
|
|
"\"status\":\"201 Created\"," +
|
|
|
|
|
"\"location\":\"Questionnaire/54127-6/_history/1\","));
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Upload again to update
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
resp = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
|
|
|
|
|
encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp);
|
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
encoded = myFhirCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(resp);
|
|
|
|
|
//@formatter:off
|
|
|
|
|
assertThat(encoded, containsString("\"response\":{" +
|
|
|
|
|
"\"status\":\"200 OK\"," +
|
|
|
|
|
"\"location\":\"Questionnaire/54127-6/_history/2\","));
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInlineMatchUrl() throws Exception {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.addIdentifier().setSystem("http://www.ghh.org/identifiers").setValue("condreftestpatid1");
|
|
|
|
|
myPatientDao.create(patient, mySrd);
|
|
|
|
|
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/simone-conditional-url.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
Bundle response = mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInlineMatchUrlMultipleMatches() throws Exception {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.addIdentifier().setSystem("http://www.ghh.org/identifiers").setValue("condreftestpatid1");
|
|
|
|
|
myPatientDao.create(patient, mySrd);
|
|
|
|
|
|
|
|
|
|
patient = new Patient();
|
|
|
|
|
patient.addIdentifier().setSystem("http://www.ghh.org/identifiers").setValue("condreftestpatid1");
|
|
|
|
|
myPatientDao.create(patient, mySrd);
|
|
|
|
|
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/simone-conditional-url.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (PreconditionFailedException e) {
|
|
|
|
|
assertEquals("Invalid match URL \"Patient?identifier=http://www.ghh.org/identifiers|condreftestpatid1\" - Multiple resources match this search", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInlineMatchUrlNoMatches() throws Exception {
|
|
|
|
|
myDaoConfig.setAllowInlineMatchUrlReferences(true);
|
|
|
|
|
|
|
|
|
|
String input = IOUtils.toString(getClass().getResourceAsStream("/simone-conditional-url.xml"), StandardCharsets.UTF_8);
|
|
|
|
|
Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mySystemDao.transaction(mySrd, bundle);
|
|
|
|
|
fail();
|
|
|
|
|
} catch (ResourceNotFoundException e) {
|
|
|
|
|
assertEquals("Invalid match URL \"Patient?identifier=http://www.ghh.org/identifiers|condreftestpatid1\" - No resources match this search", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithInvalidType() {
|
|
|
|
|
Bundle request = new Bundle();
|
|
|
|
@ -1762,6 +1725,64 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithNullReference() {
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.addName().addFamily("family");
|
|
|
|
|
final IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
|
|
|
|
|
|
|
|
|
|
Bundle inputBundle = new Bundle();
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
Patient app0 = new Patient();
|
|
|
|
|
app0.addName().addFamily("NEW PATIENT");
|
|
|
|
|
String placeholderId0 = IdDt.newRandomUuid().getValue();
|
|
|
|
|
inputBundle
|
|
|
|
|
.addEntry()
|
|
|
|
|
.setResource(app0)
|
|
|
|
|
.setFullUrl(placeholderId0)
|
|
|
|
|
.getRequest()
|
|
|
|
|
.setMethod(HTTPVerb.POST)
|
|
|
|
|
.setUrl("Patient");
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
Appointment app1 = new Appointment();
|
|
|
|
|
app1.addParticipant().getActor().setReference(id.getValue());
|
|
|
|
|
inputBundle
|
|
|
|
|
.addEntry()
|
|
|
|
|
.setResource(app1)
|
|
|
|
|
.getRequest()
|
|
|
|
|
.setMethod(HTTPVerb.POST)
|
|
|
|
|
.setUrl("Appointment");
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
Appointment app2 = new Appointment();
|
|
|
|
|
app2.addParticipant().getActor().setDisplay("NO REF");
|
|
|
|
|
app2.addParticipant().getActor().setDisplay("YES REF").setReference(placeholderId0);
|
|
|
|
|
inputBundle
|
|
|
|
|
.addEntry()
|
|
|
|
|
.setResource(app2)
|
|
|
|
|
.getRequest()
|
|
|
|
|
.setMethod(HTTPVerb.POST)
|
|
|
|
|
.setUrl("Appointment");
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
Bundle outputBundle = mySystemDao.transaction(mySrd, inputBundle);
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(outputBundle));
|
|
|
|
|
|
|
|
|
|
assertEquals(3, outputBundle.getEntry().size());
|
|
|
|
|
IdDt id0 = new IdDt(outputBundle.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdDt id2 = new IdDt(outputBundle.getEntry().get(2).getResponse().getLocation());
|
|
|
|
|
|
|
|
|
|
app2 = myAppointmentDao.read(id2, mySrd);
|
|
|
|
|
assertEquals("NO REF", app2.getParticipant().get(0).getActor().getDisplay());
|
|
|
|
|
assertEquals(null, app2.getParticipant().get(0).getActor().getReference());
|
|
|
|
|
assertEquals("YES REF", app2.getParticipant().get(1).getActor().getDisplay());
|
|
|
|
|
assertEquals(id0.toUnqualifiedVersionless().getValue(), app2.getParticipant().get(1).getActor().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithReferenceToCreateIfNoneExist() {
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
@ -1815,6 +1836,46 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
assertNotEquals(medOrderId1, medOrderId2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithRelativeOidIds() throws Exception {
|
|
|
|
|
Bundle res = new Bundle();
|
|
|
|
|
res.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
Patient p1 = new Patient();
|
|
|
|
|
p1.setId("urn:oid:0.1.2.3");
|
|
|
|
|
p1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds01");
|
|
|
|
|
res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient");
|
|
|
|
|
|
|
|
|
|
Observation o1 = new Observation();
|
|
|
|
|
o1.setId("cid:observation1");
|
|
|
|
|
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
|
|
|
|
|
o1.setSubject(new Reference("urn:oid:0.1.2.3"));
|
|
|
|
|
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
|
|
|
|
|
|
|
|
|
|
Observation o2 = new Observation();
|
|
|
|
|
o2.setId("cid:observation2");
|
|
|
|
|
o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03");
|
|
|
|
|
o2.setSubject(new Reference("urn:oid:0.1.2.3"));
|
|
|
|
|
res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
|
|
|
|
|
|
|
|
|
|
Bundle resp = mySystemDao.transaction(mySrd, res);
|
|
|
|
|
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));
|
|
|
|
|
|
|
|
|
|
assertEquals(BundleType.TRANSACTIONRESPONSE, resp.getTypeElement().getValue());
|
|
|
|
|
assertEquals(3, resp.getEntry().size());
|
|
|
|
|
|
|
|
|
|
assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
|
|
|
|
|
assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
|
|
|
|
|
assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
|
|
|
|
|
|
|
|
|
|
o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), mySrd);
|
|
|
|
|
o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), mySrd);
|
|
|
|
|
assertThat(o1.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
|
|
|
|
|
assertThat(o2.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// /**
|
|
|
|
@ -1917,46 +1978,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTransactionWithRelativeOidIds() throws Exception {
|
|
|
|
|
Bundle res = new Bundle();
|
|
|
|
|
res.setType(BundleType.TRANSACTION);
|
|
|
|
|
|
|
|
|
|
Patient p1 = new Patient();
|
|
|
|
|
p1.setId("urn:oid:0.1.2.3");
|
|
|
|
|
p1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds01");
|
|
|
|
|
res.addEntry().setResource(p1).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient");
|
|
|
|
|
|
|
|
|
|
Observation o1 = new Observation();
|
|
|
|
|
o1.setId("cid:observation1");
|
|
|
|
|
o1.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds02");
|
|
|
|
|
o1.setSubject(new Reference("urn:oid:0.1.2.3"));
|
|
|
|
|
res.addEntry().setResource(o1).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
|
|
|
|
|
|
|
|
|
|
Observation o2 = new Observation();
|
|
|
|
|
o2.setId("cid:observation2");
|
|
|
|
|
o2.addIdentifier().setSystem("system").setValue("testTransactionWithRelativeOidIds03");
|
|
|
|
|
o2.setSubject(new Reference("urn:oid:0.1.2.3"));
|
|
|
|
|
res.addEntry().setResource(o2).getRequest().setMethod(HTTPVerb.POST).setUrl("Observation");
|
|
|
|
|
|
|
|
|
|
Bundle resp = mySystemDao.transaction(mySrd, res);
|
|
|
|
|
|
|
|
|
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));
|
|
|
|
|
|
|
|
|
|
assertEquals(BundleType.TRANSACTIONRESPONSE, resp.getTypeElement().getValue());
|
|
|
|
|
assertEquals(3, resp.getEntry().size());
|
|
|
|
|
|
|
|
|
|
assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
|
|
|
|
|
assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
|
|
|
|
|
assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"));
|
|
|
|
|
|
|
|
|
|
o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), mySrd);
|
|
|
|
|
o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), mySrd);
|
|
|
|
|
assertThat(o1.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
|
|
|
|
|
assertThat(o2.getSubject().getReferenceElement().getValue(), endsWith("Patient/" + p1.getIdElement().getIdPart()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is not the correct way to do it, but we'll allow it to be lenient
|
|
|
|
|
*/
|
|
|
|
@ -2000,4 +2021,9 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClassClearContext() {
|
|
|
|
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|