This commit is contained in:
James Agnew 2016-09-08 14:22:47 -04:00
parent 6357c38180
commit dbaff992b0
2 changed files with 278 additions and 331 deletions

View File

@ -44,6 +44,7 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
import ca.uhn.fhir.jpa.dao.FhirResourceDaoDstu2; import ca.uhn.fhir.jpa.dao.FhirResourceDaoDstu2;
import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3Test;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.TagTypeEnum; import ca.uhn.fhir.jpa.entity.TagTypeEnum;
import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.IQueryParameterType;
@ -804,7 +805,8 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
myOrganizationDao.delete(orgId, mySrd); myOrganizationDao.delete(orgId, mySrd);
fail(); fail();
} catch (ResourceVersionConflictException e) { } catch (ResourceVersionConflictException e) {
assertThat(e.getMessage(), containsString("Delete failed because of constraint")); FhirResourceDaoDstu3Test.assertConflictException(e);
} }
myPatientDao.delete(patId, mySrd); myPatientDao.delete(patId, mySrd);

View File

@ -23,67 +23,25 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import java.io.IOException; import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains; import org.hamcrest.core.StringContains;
import org.hl7.fhir.dstu3.model.Age; import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.BaseResource;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Bundle.BundleType; import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu3.model.CarePlan;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.CompartmentDefinition;
import org.hl7.fhir.dstu3.model.ConceptMap;
import org.hl7.fhir.dstu3.model.Condition;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.Device;
import org.hl7.fhir.dstu3.model.DiagnosticReport;
import org.hl7.fhir.dstu3.model.Encounter;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.Enumerations.ConformanceResourceStatus; import org.hl7.fhir.dstu3.model.Enumerations.ConformanceResourceStatus;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.NamingSystem;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.OperationDefinition;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity; import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.dstu3.model.OperationOutcome.IssueType; import org.hl7.fhir.dstu3.model.OperationOutcome.IssueType;
import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Period;
import org.hl7.fhir.dstu3.model.Quantity;
import org.hl7.fhir.dstu3.model.Quantity.QuantityComparator; import org.hl7.fhir.dstu3.model.Quantity.QuantityComparator;
import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.dstu3.model.Range;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.SimpleQuantity;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.Timing;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.valuesets.ObservationCategory;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -100,7 +58,6 @@ import ca.uhn.fhir.jpa.entity.TagTypeEnum;
import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
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.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum;
@ -109,34 +66,18 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.*;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.QuantityParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.*;
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.ResourceVersionConflictException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "deprecation" })
public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3Test.class);
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
}
private void assertGone(IIdType theId) { private void assertGone(IIdType theId) {
try { try {
assertNotGone(theId); assertNotGone(theId);
@ -145,99 +86,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
// good // good
} }
} }
@Test
public void testDeleteWithHas() {
Observation obs1 = new Observation();
obs1.setStatus(ObservationStatus.FINAL);
IIdType obs1id = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.setStatus(ObservationStatus.FINAL);
IIdType obs2id = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
DiagnosticReport rpt = new DiagnosticReport();
rpt.addIdentifier().setSystem("foo").setValue("IDENTIFIER");
rpt.addResult(new Reference(obs2id));
IIdType rptId = myDiagnosticReportDao.create(rpt).getId().toUnqualifiedVersionless();
myObservationDao.read(obs1id);
myObservationDao.read(obs2id);
try {
myObservationDao.deleteByUrl("Observation?_has:DiagnosticReport:result:identifier=foo|IDENTIFIER", mySrd);
fail();
} catch (ResourceVersionConflictException e) {
assertThat(e.getMessage(), matchesPattern("Unable to delete Observation/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource Observation/[0-9]+ in path DiagnosticReport.result"));
}
myObservationDao.read(obs1id);
myObservationDao.read(obs2id);
}
@Test
public void testCodeSystemCreateAndDelete() {
CodeSystem cs = new CodeSystem();
cs.setStatus(ConformanceResourceStatus.DRAFT);
IIdType id = myCodeSystemDao.create(cs, mySrd).getId().toUnqualifiedVersionless();
myCodeSystemDao.delete(id, mySrd);
assertGone(id.toUnqualifiedVersionless());
}
@Test
public void testIndexConditionWithAllOnsetTypes() {
// DateTimeType.class, Age.class, Period.class, Range.class, StringType.class
Condition c0 = new Condition();
c0.setOnset(new DateTimeType("2011-01-01"));
IIdType id0 = myConditionDao.create(c0, mySrd).getId().toUnqualifiedVersionless();
Condition c1 = new Condition();
c1.setOnset(new Age().setValue(100L).setCode("AGECODE"));
IIdType id1 = myConditionDao.create(c1, mySrd).getId().toUnqualifiedVersionless();
Condition c2 = new Condition();
c2.setOnset(new Period().setStart(new Date()).setEnd(new Date()));
IIdType id2 = myConditionDao.create(c2, mySrd).getId().toUnqualifiedVersionless();
Condition c3 = new Condition();
c3.setOnset(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(200L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(300L)));
IIdType id3 = myConditionDao.create(c3, mySrd).getId().toUnqualifiedVersionless();
Condition c4 = new Condition();
c4.setOnset(new StringType("FOO"));
IIdType id4 = myConditionDao.create(c4, mySrd).getId().toUnqualifiedVersionless();
}
@Test
@Ignore
public void testCreateBuiltInProfiles() throws Exception {
org.hl7.fhir.dstu3.model.Bundle bundle;
String name = "profiles-resources";
ourLog.info("Uploading " + name);
String vsContents;
vsContents = IOUtils.toString(FhirResourceDaoDstu3Test.class.getResourceAsStream("/org/hl7/fhir/instance/model/dstu3/profile/" + name + ".xml"), "UTF-8");
bundle = myFhirCtx.newXmlParser().parseResource(org.hl7.fhir.dstu3.model.Bundle.class, vsContents);
for (BundleEntryComponent i : bundle.getEntry()) {
org.hl7.fhir.dstu3.model.Resource next = i.getResource();
ourLog.debug(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(next));
if (next instanceof StructureDefinition) {
myStructureDefinitionDao.update((StructureDefinition) next, mySrd);
} else if (next instanceof CompartmentDefinition) {
myCompartmentDefinitionDao.update((CompartmentDefinition) next, mySrd);
} else if (next instanceof OperationDefinition) {
myOperationDefinitionDao.update((OperationDefinition) next, mySrd);
} else {
fail(next.getClass().getName());
}
}
}
/** /**
* This gets called from assertGone too! Careful about exceptions... * This gets called from assertGone too! Careful about exceptions...
@ -253,7 +101,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
fail("Can't handle type: " + theId.getResourceType()); fail("Can't handle type: " + theId.getResourceType());
} }
} }
private List<String> extractNames(IBundleProvider theSearch) { private List<String> extractNames(IBundleProvider theSearch) {
ArrayList<String> retVal = new ArrayList<String>(); ArrayList<String> retVal = new ArrayList<String>();
for (IBaseResource next : theSearch.getResources(0, theSearch.size())) { for (IBaseResource next : theSearch.getResources(0, theSearch.size())) {
@ -268,7 +116,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
retVal.addCoding().setSystem(theSystem).setCode(theCode); retVal.addCoding().setSystem(theSystem).setCode(theCode);
return retVal; return retVal;
} }
private void sort(ArrayList<Coding> thePublished) { private void sort(ArrayList<Coding> thePublished) {
ArrayList<Coding> tags = new ArrayList<Coding>(thePublished); ArrayList<Coding> tags = new ArrayList<Coding>(thePublished);
Collections.sort(tags, new Comparator<Coding>() { Collections.sort(tags, new Comparator<Coding>() {
@ -295,7 +143,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
}); });
} }
private List<UriType> sortIds(List<UriType> theProfiles) { private List<UriType> sortIds(List<UriType> theProfiles) {
ArrayList<UriType> retVal = new ArrayList<UriType>(theProfiles); ArrayList<UriType> retVal = new ArrayList<UriType>(theProfiles);
Collections.sort(retVal, new Comparator<UriType>() { Collections.sort(retVal, new Comparator<UriType>() {
@ -367,26 +215,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
} }
@Test
public void testCreateDifferentTypesWithSameForcedId() {
String idName = "forcedId";
Patient pat = new Patient();
pat.setId(idName);
pat.addName().addFamily("FAM");
IIdType patId = myPatientDao.update(pat, mySrd).getId();
assertEquals("Patient/" + idName, patId.toUnqualifiedVersionless().getValue());
Observation obs = new Observation();
obs.setId(idName);
obs.getCode().addCoding().setSystem("foo").setCode("testCreateDifferentTypesWithSameForcedId");
IIdType obsId = myObservationDao.update(obs, mySrd).getId();
assertEquals("Observation/" + idName, obsId.toUnqualifiedVersionless().getValue());
pat = myPatientDao.read(patId.toUnqualifiedVersionless(), mySrd);
obs = myObservationDao.read(obsId.toUnqualifiedVersionless(), mySrd);
}
@Test @Test
public void testChoiceParamDateAlt() { public void testChoiceParamDateAlt() {
Observation o2 = new Observation(); Observation o2 = new Observation();
@ -432,7 +260,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
@Test @Test
public void testChoiceParamDateRange() { public void testChoiceParamDateRange() {
Observation o1 = new Observation(); Observation o1 = new Observation();
@ -585,6 +412,108 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
} }
@Test
public void testCodeSystemCreateAndDelete() {
CodeSystem cs = new CodeSystem();
cs.setStatus(ConformanceResourceStatus.DRAFT);
IIdType id = myCodeSystemDao.create(cs, mySrd).getId().toUnqualifiedVersionless();
myCodeSystemDao.delete(id, mySrd);
assertGone(id.toUnqualifiedVersionless());
}
@Test
@Ignore
public void testCreateBuiltInProfiles() throws Exception {
org.hl7.fhir.dstu3.model.Bundle bundle;
String name = "profiles-resources";
ourLog.info("Uploading " + name);
String vsContents;
vsContents = IOUtils.toString(FhirResourceDaoDstu3Test.class.getResourceAsStream("/org/hl7/fhir/instance/model/dstu3/profile/" + name + ".xml"), "UTF-8");
bundle = myFhirCtx.newXmlParser().parseResource(org.hl7.fhir.dstu3.model.Bundle.class, vsContents);
for (BundleEntryComponent i : bundle.getEntry()) {
org.hl7.fhir.dstu3.model.Resource next = i.getResource();
ourLog.debug(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(next));
if (next instanceof StructureDefinition) {
myStructureDefinitionDao.update((StructureDefinition) next, mySrd);
} else if (next instanceof CompartmentDefinition) {
myCompartmentDefinitionDao.update((CompartmentDefinition) next, mySrd);
} else if (next instanceof OperationDefinition) {
myOperationDefinitionDao.update((OperationDefinition) next, mySrd);
} else {
fail(next.getClass().getName());
}
}
}
@Test
public void testCreateBundleAllowsDocumentAndCollection() {
String methodName = "testCreateBundleAllowsDocumentAndCollection";
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType pid = myPatientDao.create(p, mySrd).getId();
p.setId(pid);
ourLog.info("Created patient, got it: {}", pid);
Bundle bundle = new Bundle();
bundle.setType(null);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
try {
myBundleDao.create(bundle, mySrd);
fail();
} catch (UnprocessableEntityException e) {
assertEquals("Unable to store a Bundle resource on this server with a Bundle.type value of: (missing)", e.getMessage());
}
bundle = new Bundle();
bundle.setType(BundleType.SEARCHSET);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
try {
myBundleDao.create(bundle, mySrd);
fail();
} catch (UnprocessableEntityException e) {
assertEquals("Unable to store a Bundle resource on this server with a Bundle.type value of: searchset", e.getMessage());
}
bundle = new Bundle();
bundle.setType(BundleType.COLLECTION);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
myBundleDao.create(bundle, mySrd);
bundle = new Bundle();
bundle.setType(BundleType.DOCUMENT);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
myBundleDao.create(bundle, mySrd);
}
@Test
public void testCreateDifferentTypesWithSameForcedId() {
String idName = "forcedId";
Patient pat = new Patient();
pat.setId(idName);
pat.addName().addFamily("FAM");
IIdType patId = myPatientDao.update(pat, mySrd).getId();
assertEquals("Patient/" + idName, patId.toUnqualifiedVersionless().getValue());
Observation obs = new Observation();
obs.setId(idName);
obs.getCode().addCoding().setSystem("foo").setCode("testCreateDifferentTypesWithSameForcedId");
IIdType obsId = myObservationDao.update(obs, mySrd).getId();
assertEquals("Observation/" + idName, obsId.toUnqualifiedVersionless().getValue());
pat = myPatientDao.read(patId.toUnqualifiedVersionless(), mySrd);
obs = myObservationDao.read(obsId.toUnqualifiedVersionless(), mySrd);
}
@Test @Test
public void testCreateLongString() { public void testCreateLongString() {
//@formatter:off //@formatter:off
@ -654,7 +583,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
p.addIdentifier().setSystem("urn:system").setValue("testCreateTextIdFails"); p.addIdentifier().setSystem("urn:system").setValue("testCreateTextIdFails");
p.addName().addFamily("Hello"); p.addName().addFamily("Hello");
ArrayList<Coding> tl = new ArrayList<Coding>();
p.getMeta().addTag().setSystem(Constants.TAG_SUBSETTED_SYSTEM).setCode(Constants.TAG_SUBSETTED_CODE); p.getMeta().addTag().setSystem(Constants.TAG_SUBSETTED_SYSTEM).setCode(Constants.TAG_SUBSETTED_CODE);
try { try {
@ -675,79 +603,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
assertNotEquals("ABC", id); assertNotEquals("ABC", id);
} }
@Test
public void testTimingSearchParams() throws Exception {
Date before = new DateTimeType("2011-01-01T10:00:00Z").getValue();
Date middle = new DateTimeType("2011-01-02T10:00:00Z").getValue();
Date after = new DateTimeType("2011-01-03T10:00:00Z").getValue();
CarePlan cp = new CarePlan();
cp.addActivity().getDetail().setScheduled(new Timing().addEvent(before).addEvent(middle).addEvent(after));
cp.addActivity().getDetail();
IIdType id = myCarePlanDao.create(cp, mySrd).getId().toUnqualifiedVersionless();
CarePlan cp2 = new CarePlan();
cp2.addActivity().getDetail().setScheduled(new StringType("FOO"));
cp2.addActivity().getDetail();
IIdType id2 = myCarePlanDao.create(cp2, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap params;
params = new SearchParameterMap();
params.add(CarePlan.SP_ACTIVITYDATE, new DateRangeParam("2010-01-01T10:00:00Z", null));
assertThat(toUnqualifiedVersionlessIdValues(myCarePlanDao.search(params)), contains(id.getValue()));
params = new SearchParameterMap();
params.add(CarePlan.SP_ACTIVITYDATE, new DateRangeParam("2011-01-01T10:00:00Z", null));
assertThat(toUnqualifiedVersionlessIdValues(myCarePlanDao.search(params)), contains(id.getValue()));
params = new SearchParameterMap();
params.add(CarePlan.SP_ACTIVITYDATE, new DateRangeParam("2012-01-01T10:00:00Z", null));
assertThat(toUnqualifiedVersionlessIdValues(myCarePlanDao.search(params)), empty());
}
@Test
public void testCreateBundleAllowsDocumentAndCollection() {
String methodName = "testCreateBundleAllowsDocumentAndCollection";
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
IIdType pid = myPatientDao.create(p, mySrd).getId();
p.setId(pid);
ourLog.info("Created patient, got it: {}", pid);
Bundle bundle = new Bundle();
bundle.setType(null);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
try {
myBundleDao.create(bundle, mySrd);
fail();
} catch (UnprocessableEntityException e) {
assertEquals("Unable to store a Bundle resource on this server with a Bundle.type value of: (missing)", e.getMessage());
}
bundle = new Bundle();
bundle.setType(BundleType.SEARCHSET);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
try {
myBundleDao.create(bundle, mySrd);
fail();
} catch (UnprocessableEntityException e) {
assertEquals("Unable to store a Bundle resource on this server with a Bundle.type value of: searchset", e.getMessage());
}
bundle = new Bundle();
bundle.setType(BundleType.COLLECTION);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
myBundleDao.create(bundle, mySrd);
bundle = new Bundle();
bundle.setType(BundleType.DOCUMENT);
bundle.addEntry().setResource(p).setFullUrl(pid.toUnqualifiedVersionless().getValue());
myBundleDao.create(bundle, mySrd);
}
@Test @Test
public void testCreateWithIfNoneExistBasic() { public void testCreateWithIfNoneExistBasic() {
String methodName = "testCreateWithIfNoneExistBasic"; String methodName = "testCreateWithIfNoneExistBasic";
@ -1118,7 +973,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
myOrganizationDao.delete(orgId, mySrd); myOrganizationDao.delete(orgId, mySrd);
fail(); fail();
} catch (ResourceVersionConflictException e) { } catch (ResourceVersionConflictException e) {
assertThat(e.getMessage(), containsString("Delete failed because of constraint")); assertConflictException(e);
} }
myPatientDao.delete(patId, mySrd); myPatientDao.delete(patId, mySrd);
@ -1235,6 +1090,35 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
assertEquals(id2, gotId); assertEquals(id2, gotId);
} }
@Test
public void testDeleteWithHas() {
Observation obs1 = new Observation();
obs1.setStatus(ObservationStatus.FINAL);
IIdType obs1id = myObservationDao.create(obs1).getId().toUnqualifiedVersionless();
Observation obs2 = new Observation();
obs2.setStatus(ObservationStatus.FINAL);
IIdType obs2id = myObservationDao.create(obs2).getId().toUnqualifiedVersionless();
DiagnosticReport rpt = new DiagnosticReport();
rpt.addIdentifier().setSystem("foo").setValue("IDENTIFIER");
rpt.addResult(new Reference(obs2id));
myDiagnosticReportDao.create(rpt).getId().toUnqualifiedVersionless();
myObservationDao.read(obs1id);
myObservationDao.read(obs2id);
try {
myObservationDao.deleteByUrl("Observation?_has:DiagnosticReport:result:identifier=foo|IDENTIFIER", mySrd);
fail();
} catch (ResourceVersionConflictException e) {
assertConflictException(e);
}
myObservationDao.read(obs1id);
myObservationDao.read(obs2id);
}
@Test @Test
public void testDeleteWithMatchUrl() { public void testDeleteWithMatchUrl() {
String methodName = "testDeleteWithMatchUrl"; String methodName = "testDeleteWithMatchUrl";
@ -1302,8 +1186,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
public void testDeleteWithMatchUrlChainedProfile() { public void testDeleteWithMatchUrlChainedProfile() {
String methodName = "testDeleteWithMatchUrlChainedProfile"; String methodName = "testDeleteWithMatchUrlChainedProfile";
List<IdType> profileList = new ArrayList<IdType>();
Organization org = new Organization(); Organization org = new Organization();
org.getMeta().getProfile().add(new IdType("http://foo")); org.getMeta().getProfile().add(new IdType("http://foo"));
@ -1495,37 +1377,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
assertNotEquals(idv1, idv2); assertNotEquals(idv1, idv2);
} }
@Test
public void testHistoryWithFromAndTo() throws Exception {
String methodName = "testHistoryWithFromAndTo";
Patient patient = new Patient();
patient.addName().addFamily(methodName);
IIdType id = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
List<Date> preDates = Lists.newArrayList();
List<String> ids = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
Thread.sleep(100);
preDates.add(new Date());
Thread.sleep(100);
patient.setId(id);
patient.getName().get(0).getFamily().get(0).setValue(methodName + "_i");
ids.add(myPatientDao.update(patient, mySrd).getId().toUnqualified().getValue());
}
List<String> idValues;
idValues = toUnqualifiedIdValues(myPatientDao.history(id, preDates.get(0), preDates.get(3), mySrd));
assertThat(idValues, contains(ids.get(2), ids.get(1), ids.get(0)));
idValues = toUnqualifiedIdValues(myPatientDao.history(preDates.get(0), preDates.get(3), mySrd));
assertThat(idValues, contains(ids.get(2), ids.get(1), ids.get(0)));
idValues = toUnqualifiedIdValues(mySystemDao.history(preDates.get(0), preDates.get(3), mySrd));
assertThat(idValues, contains(ids.get(2), ids.get(1), ids.get(0)));
}
@Test @Test
public void testHistoryOverMultiplePages() throws Exception { public void testHistoryOverMultiplePages() throws Exception {
String methodName = "testHistoryOverMultiplePages"; String methodName = "testHistoryOverMultiplePages";
@ -1676,45 +1527,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
@Test
public void testHistoryWithFutureSinceDate() throws Exception {
Date before = new Date();
Thread.sleep(10);
Patient inPatient = new Patient();
inPatient.addName().addFamily("version1");
inPatient.getMeta().addProfile("http://example.com/1");
myPatientDao.create(inPatient, mySrd).getId().toUnqualifiedVersionless();
Thread.sleep(10);
Date after = new Date();
// No since
IBundleProvider history = myPatientDao.history((Date)null, null, mySrd);
assertEquals(1, history.size());
Patient outPatient = (Patient) history.getResources(0, 1).get(0);
assertEquals("version1", inPatient.getName().get(0).getFamilyAsSingleString());
List<String> profiles = toStringList(outPatient.getMeta().getProfile());
assertThat(profiles, contains("http://example.com/1"));
// Before since
history = myPatientDao.history(before, null, mySrd);
assertEquals(1, history.size());
outPatient = (Patient) history.getResources(0, 1).get(0);
assertEquals("version1", inPatient.getName().get(0).getFamilyAsSingleString());
profiles = toStringList(outPatient.getMeta().getProfile());
assertThat(profiles, contains("http://example.com/1"));
// After since
history = myPatientDao.history(after, null, mySrd);
assertEquals(0, history.size());
}
@Test @Test
public void testHistoryReflectsMetaOperations() throws Exception { public void testHistoryReflectsMetaOperations() throws Exception {
Patient inPatient = new Patient(); Patient inPatient = new Patient();
@ -1799,6 +1611,76 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
assertEquals(BundleEntryTransactionMethodEnum.POST.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(2))); assertEquals(BundleEntryTransactionMethodEnum.POST.getCode(), ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get((IAnyResource) entries.get(2)));
} }
@Test
public void testHistoryWithFromAndTo() throws Exception {
String methodName = "testHistoryWithFromAndTo";
Patient patient = new Patient();
patient.addName().addFamily(methodName);
IIdType id = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
List<Date> preDates = Lists.newArrayList();
List<String> ids = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
Thread.sleep(100);
preDates.add(new Date());
Thread.sleep(100);
patient.setId(id);
patient.getName().get(0).getFamily().get(0).setValue(methodName + "_i");
ids.add(myPatientDao.update(patient, mySrd).getId().toUnqualified().getValue());
}
List<String> idValues;
idValues = toUnqualifiedIdValues(myPatientDao.history(id, preDates.get(0), preDates.get(3), mySrd));
assertThat(idValues, contains(ids.get(2), ids.get(1), ids.get(0)));
idValues = toUnqualifiedIdValues(myPatientDao.history(preDates.get(0), preDates.get(3), mySrd));
assertThat(idValues, contains(ids.get(2), ids.get(1), ids.get(0)));
idValues = toUnqualifiedIdValues(mySystemDao.history(preDates.get(0), preDates.get(3), mySrd));
assertThat(idValues, contains(ids.get(2), ids.get(1), ids.get(0)));
}
@Test
public void testHistoryWithFutureSinceDate() throws Exception {
Date before = new Date();
Thread.sleep(10);
Patient inPatient = new Patient();
inPatient.addName().addFamily("version1");
inPatient.getMeta().addProfile("http://example.com/1");
myPatientDao.create(inPatient, mySrd).getId().toUnqualifiedVersionless();
Thread.sleep(10);
Date after = new Date();
// No since
IBundleProvider history = myPatientDao.history((Date)null, null, mySrd);
assertEquals(1, history.size());
Patient outPatient = (Patient) history.getResources(0, 1).get(0);
assertEquals("version1", inPatient.getName().get(0).getFamilyAsSingleString());
List<String> profiles = toStringList(outPatient.getMeta().getProfile());
assertThat(profiles, contains("http://example.com/1"));
// Before since
history = myPatientDao.history(before, null, mySrd);
assertEquals(1, history.size());
outPatient = (Patient) history.getResources(0, 1).get(0);
assertEquals("version1", inPatient.getName().get(0).getFamilyAsSingleString());
profiles = toStringList(outPatient.getMeta().getProfile());
assertThat(profiles, contains("http://example.com/1"));
// After since
history = myPatientDao.history(after, null, mySrd);
assertEquals(0, history.size());
}
@Test @Test
public void testHistoryWithInvalidId() throws Exception { public void testHistoryWithInvalidId() throws Exception {
try { try {
@ -1879,6 +1761,31 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
} }
@Test
public void testIndexConditionWithAllOnsetTypes() {
// DateTimeType.class, Age.class, Period.class, Range.class, StringType.class
Condition c0 = new Condition();
c0.setOnset(new DateTimeType("2011-01-01"));
myConditionDao.create(c0, mySrd).getId().toUnqualifiedVersionless();
Condition c1 = new Condition();
c1.setOnset(new Age().setValue(100L).setCode("AGECODE"));
myConditionDao.create(c1, mySrd).getId().toUnqualifiedVersionless();
Condition c2 = new Condition();
c2.setOnset(new Period().setStart(new Date()).setEnd(new Date()));
myConditionDao.create(c2, mySrd).getId().toUnqualifiedVersionless();
Condition c3 = new Condition();
c3.setOnset(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(200L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(300L)));
myConditionDao.create(c3, mySrd).getId().toUnqualifiedVersionless();
Condition c4 = new Condition();
c4.setOnset(new StringType("FOO"));
myConditionDao.create(c4, mySrd).getId().toUnqualifiedVersionless();
}
@Test @Test
public void testInstanceMetaOperations() { public void testInstanceMetaOperations() {
String methodName = "testMetaRead"; String methodName = "testMetaRead";
@ -1889,11 +1796,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
patient.getMeta().addTag("tag_scheme1", "tag_code1", "tag_display1"); patient.getMeta().addTag("tag_scheme1", "tag_code1", "tag_display1");
patient.getMeta().addTag("tag_scheme2", "tag_code2", "tag_display2"); patient.getMeta().addTag("tag_scheme2", "tag_code2", "tag_display2");
List<BaseCodingDt> securityLabels = new ArrayList<BaseCodingDt>();
patient.getMeta().addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1").setDisplay("seclabel_dis1"); patient.getMeta().addSecurity().setSystem("seclabel_sys1").setCode("seclabel_code1").setDisplay("seclabel_dis1");
patient.getMeta().addSecurity().setSystem("seclabel_sys2").setCode("seclabel_code2").setDisplay("seclabel_dis2"); patient.getMeta().addSecurity().setSystem("seclabel_sys2").setCode("seclabel_code2").setDisplay("seclabel_dis2");
ArrayList<IdType> profiles = new ArrayList<IdType>();
patient.getMeta().addProfile(("http://profile/1")); patient.getMeta().addProfile(("http://profile/1"));
patient.getMeta().addProfile(("http://profile/2")); patient.getMeta().addProfile(("http://profile/2"));
@ -3337,6 +3242,37 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
@Test
public void testTimingSearchParams() throws Exception {
Date before = new DateTimeType("2011-01-01T10:00:00Z").getValue();
Date middle = new DateTimeType("2011-01-02T10:00:00Z").getValue();
Date after = new DateTimeType("2011-01-03T10:00:00Z").getValue();
CarePlan cp = new CarePlan();
cp.addActivity().getDetail().setScheduled(new Timing().addEvent(before).addEvent(middle).addEvent(after));
cp.addActivity().getDetail();
IIdType id = myCarePlanDao.create(cp, mySrd).getId().toUnqualifiedVersionless();
CarePlan cp2 = new CarePlan();
cp2.addActivity().getDetail().setScheduled(new StringType("FOO"));
cp2.addActivity().getDetail();
myCarePlanDao.create(cp2, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap params;
params = new SearchParameterMap();
params.add(CarePlan.SP_ACTIVITYDATE, new DateRangeParam("2010-01-01T10:00:00Z", null));
assertThat(toUnqualifiedVersionlessIdValues(myCarePlanDao.search(params)), contains(id.getValue()));
params = new SearchParameterMap();
params.add(CarePlan.SP_ACTIVITYDATE, new DateRangeParam("2011-01-01T10:00:00Z", null));
assertThat(toUnqualifiedVersionlessIdValues(myCarePlanDao.search(params)), contains(id.getValue()));
params = new SearchParameterMap();
params.add(CarePlan.SP_ACTIVITYDATE, new DateRangeParam("2012-01-01T10:00:00Z", null));
assertThat(toUnqualifiedVersionlessIdValues(myCarePlanDao.search(params)), empty());
}
@Test @Test
public void testTokenParamWhichIsTooLong() { public void testTokenParamWhichIsTooLong() {
@ -3372,6 +3308,15 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
} }
} }
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
}
public static void assertConflictException(ResourceVersionConflictException e) {
assertThat(e.getMessage(), matchesPattern("Unable to delete Observation/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource Observation/[0-9]+ in path DiagnosticReport.result"));
}
private static List<String> toStringList(List<UriType> theUriType) { private static List<String> toStringList(List<UriType> theUriType) {
ArrayList<String> retVal = new ArrayList<String>(); ArrayList<String> retVal = new ArrayList<String>();
for (UriType next : theUriType) { for (UriType next : theUriType) {