Working on valueset operations in JPA
This commit is contained in:
parent
d5b99c2c10
commit
89965fb6bd
|
@ -0,0 +1,113 @@
|
||||||
|
package ca.uhn.fhir.jpa.provider;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* HAPI FHIR JPA Server
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2014 - 2015 University Health Network
|
||||||
|
* %%
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.ValueSet;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeInclude;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.ValueSet.DefineConcept;
|
||||||
|
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||||
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
|
import ca.uhn.fhir.model.primitive.StringDt;
|
||||||
|
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||||
|
import ca.uhn.fhir.rest.annotation.Operation;
|
||||||
|
import ca.uhn.fhir.rest.annotation.OperationParam;
|
||||||
|
|
||||||
|
public class BaseJpaResourceProviderValueSetDstu2 extends JpaResourceProviderDstu2<ValueSet> {
|
||||||
|
|
||||||
|
@Operation(name = "$expand", idempotent = true)
|
||||||
|
public ValueSet everything(HttpServletRequest theServletRequest, @IdParam IdDt theId, @OperationParam(name = "filter") StringDt theFilter) {
|
||||||
|
startRequest(theServletRequest);
|
||||||
|
try {
|
||||||
|
ValueSet retVal = new ValueSet();
|
||||||
|
retVal.setDate(DateTimeDt.withCurrentTime());
|
||||||
|
|
||||||
|
ValueSet source = read(theServletRequest, theId);
|
||||||
|
|
||||||
|
Map<String, ComposeInclude> systemToCompose = new HashMap<String, ComposeInclude>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add composed concepts
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (ComposeInclude nextInclude : source.getCompose().getInclude()) {
|
||||||
|
for (ComposeIncludeConcept next : nextInclude.getConcept()) {
|
||||||
|
ComposeInclude include = null;
|
||||||
|
if (theFilter == null || theFilter.isEmpty()) {
|
||||||
|
if (include == null) {
|
||||||
|
include = getOrAddComposeInclude(retVal, systemToCompose, nextInclude.getSystem());
|
||||||
|
}
|
||||||
|
include.addConcept(next);
|
||||||
|
} else {
|
||||||
|
String filter = theFilter.getValue().toLowerCase();
|
||||||
|
if (next.getDisplay().toLowerCase().contains(filter) || next.getCode().toLowerCase().contains(filter)) {
|
||||||
|
if (include == null) {
|
||||||
|
include = getOrAddComposeInclude(retVal, systemToCompose, nextInclude.getSystem());
|
||||||
|
}
|
||||||
|
include.addConcept(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add defined concepts
|
||||||
|
*/
|
||||||
|
|
||||||
|
ComposeInclude include = null;
|
||||||
|
for (DefineConcept next : source.getDefine().getConcept()) {
|
||||||
|
if (theFilter == null || theFilter.isEmpty()) {
|
||||||
|
if (include == null) {
|
||||||
|
include = getOrAddComposeInclude(retVal, systemToCompose, source.getDefine().getSystem());
|
||||||
|
}
|
||||||
|
include.addConcept(new ComposeIncludeConcept().setCode(next.getCode()).setDisplay(next.getDisplay()));
|
||||||
|
} else {
|
||||||
|
String filter = theFilter.getValue().toLowerCase();
|
||||||
|
if (next.getDisplay().toLowerCase().contains(filter) || next.getCode().toLowerCase().contains(filter)) {
|
||||||
|
include.addConcept(new ComposeIncludeConcept().setCode(next.getCode()).setDisplay(next.getDisplay()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
endRequest(theServletRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComposeInclude getOrAddComposeInclude(ValueSet retVal, Map<String, ComposeInclude> systemToCompose, String system) {
|
||||||
|
ComposeInclude include;
|
||||||
|
include = systemToCompose.get(system);
|
||||||
|
if (include == null) {
|
||||||
|
include = retVal.getCompose().addInclude();
|
||||||
|
include.setSystem(system);
|
||||||
|
systemToCompose.put(system, include);
|
||||||
|
}
|
||||||
|
return include;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -64,6 +64,7 @@ import ca.uhn.fhir.model.dstu2.resource.Observation;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.ValueSet;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.EncounterStateEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.EncounterStateEnum;
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
||||||
|
@ -95,8 +96,8 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
private static ClassPathXmlApplicationContext ourAppCtx;
|
private static ClassPathXmlApplicationContext ourAppCtx;
|
||||||
private static IGenericClient ourClient;
|
private static IGenericClient ourClient;
|
||||||
private static DaoConfig ourDaoConfig;
|
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu2();
|
private static FhirContext ourCtx = FhirContext.forDstu2();
|
||||||
|
private static DaoConfig ourDaoConfig;
|
||||||
private static CloseableHttpClient ourHttpClient;
|
private static CloseableHttpClient ourHttpClient;
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2Test.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2Test.class);
|
||||||
private static IFhirResourceDao<Organization> ourOrganizationDao;
|
private static IFhirResourceDao<Organization> ourOrganizationDao;
|
||||||
|
@ -339,7 +340,8 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try it with a raw socket call. The Apache client won't let us use the unescaped "|" in the URL but we want to make sure that works too..
|
* Try it with a raw socket call. The Apache client won't let us use the unescaped "|" in the URL but we want to
|
||||||
|
* make sure that works too..
|
||||||
*/
|
*/
|
||||||
Socket sock = new Socket();
|
Socket sock = new Socket();
|
||||||
sock.setSoTimeout(3000);
|
sock.setSoTimeout(3000);
|
||||||
|
@ -713,8 +715,7 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
|
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
|
||||||
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
|
||||||
|
|
||||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint()
|
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint().execute();
|
||||||
.execute();
|
|
||||||
assertEquals(1, actual.size());
|
assertEquals(1, actual.size());
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||||
|
|
||||||
|
@ -756,34 +757,97 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithInclude() throws Exception {
|
public void testSearchLastUpdatedParamRp() throws InterruptedException {
|
||||||
Organization org = new Organization();
|
String methodName = "testSearchLastUpdatedParamRp";
|
||||||
org.addIdentifier().setSystem("urn:system:rpdstu2").setValue("testSearchWithInclude01");
|
|
||||||
IdDt orgId = (IdDt) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId();
|
|
||||||
|
|
||||||
Patient pat = new Patient();
|
int sleep = 100;
|
||||||
pat.addIdentifier().setSystem("urn:system:rpdstu2").setValue("testSearchWithInclude02");
|
Thread.sleep(sleep);
|
||||||
pat.getManagingOrganization().setReference(orgId);
|
|
||||||
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
|
||||||
|
|
||||||
|
DateTimeDt beforeAny = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
|
||||||
|
IdDt id1a;
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
||||||
|
patient.addName().addFamily(methodName).addGiven("Joe");
|
||||||
|
id1a = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
||||||
|
}
|
||||||
|
IdDt id1b;
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
||||||
|
patient.addName().addFamily(methodName + "XXXX").addGiven("Joe");
|
||||||
|
id1b = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.sleep(1100);
|
||||||
|
DateTimeDt beforeR2 = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
|
||||||
|
Thread.sleep(1100);
|
||||||
|
|
||||||
|
IdDt id2;
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
||||||
|
patient.addName().addFamily(methodName).addGiven("John");
|
||||||
|
id2 = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
Bundle found = ourClient
|
Bundle found = ourClient.search()
|
||||||
.search()
|
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpdstu2","testSearchWithInclude02"))
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
.include(Patient.INCLUDE_ORGANIZATION)
|
|
||||||
.prettyPrint()
|
|
||||||
.execute();
|
.execute();
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
assertEquals(2, found.size());
|
assertThat(patients, hasItems(id1a, id1b, id2));
|
||||||
assertEquals(Patient.class, found.getEntries().get(0).getResource().getClass());
|
}
|
||||||
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntries().get(0).getSearchMode().getValueAsEnum());
|
{
|
||||||
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntries().get(0).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
//@formatter:off
|
||||||
assertThat(found.getEntries().get(0).getResource().getText().getDiv().getValueAsString(), containsString("<table class=\"hapiPropertyTable"));
|
Bundle found = ourClient.search()
|
||||||
assertEquals(Organization.class, found.getEntries().get(1).getResource().getClass());
|
.forResource(Patient.class)
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntries().get(1).getSearchMode().getValueAsEnum());
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntries().get(1).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
.lastUpdated(new DateRangeParam(beforeAny, null))
|
||||||
|
.execute();
|
||||||
|
//@formatter:on
|
||||||
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
|
assertThat(patients, hasItems(id1a, id1b, id2));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
//@formatter:off
|
||||||
|
Bundle found = ourClient.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
|
.lastUpdated(new DateRangeParam(beforeR2, null))
|
||||||
|
.execute();
|
||||||
|
//@formatter:on
|
||||||
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
|
assertThat(patients, hasItems(id2));
|
||||||
|
assertThat(patients, not(hasItems(id1a, id1b)));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
//@formatter:off
|
||||||
|
Bundle found = ourClient.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
|
.lastUpdated(new DateRangeParam(beforeAny, beforeR2))
|
||||||
|
.execute();
|
||||||
|
//@formatter:on
|
||||||
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
|
assertThat(patients.toString(), patients, not(hasItems(id2)));
|
||||||
|
assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
//@formatter:off
|
||||||
|
Bundle found = ourClient.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
||||||
|
.lastUpdated(new DateRangeParam(null, beforeR2))
|
||||||
|
.execute();
|
||||||
|
//@formatter:on
|
||||||
|
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
||||||
|
assertThat(patients, (hasItems(id1a, id1b)));
|
||||||
|
assertThat(patients, not(hasItems(id2)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -813,6 +877,36 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
assertTrue(value.before(after));
|
assertTrue(value.before(after));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchWithInclude() throws Exception {
|
||||||
|
Organization org = new Organization();
|
||||||
|
org.addIdentifier().setSystem("urn:system:rpdstu2").setValue("testSearchWithInclude01");
|
||||||
|
IdDt orgId = (IdDt) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId();
|
||||||
|
|
||||||
|
Patient pat = new Patient();
|
||||||
|
pat.addIdentifier().setSystem("urn:system:rpdstu2").setValue("testSearchWithInclude02");
|
||||||
|
pat.getManagingOrganization().setReference(orgId);
|
||||||
|
ourClient.create().resource(pat).prettyPrint().encodedXml().execute().getId();
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
|
Bundle found = ourClient
|
||||||
|
.search()
|
||||||
|
.forResource(Patient.class)
|
||||||
|
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpdstu2","testSearchWithInclude02"))
|
||||||
|
.include(Patient.INCLUDE_ORGANIZATION)
|
||||||
|
.prettyPrint()
|
||||||
|
.execute();
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
|
assertEquals(2, found.size());
|
||||||
|
assertEquals(Patient.class, found.getEntries().get(0).getResource().getClass());
|
||||||
|
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntries().get(0).getSearchMode().getValueAsEnum());
|
||||||
|
assertEquals(BundleEntrySearchModeEnum.MATCH, found.getEntries().get(0).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
||||||
|
assertThat(found.getEntries().get(0).getResource().getText().getDiv().getValueAsString(), containsString("<table class=\"hapiPropertyTable"));
|
||||||
|
assertEquals(Organization.class, found.getEntries().get(1).getResource().getClass());
|
||||||
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntries().get(1).getSearchMode().getValueAsEnum());
|
||||||
|
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntries().get(1).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWithMissing() throws Exception {
|
public void testSearchWithMissing() throws Exception {
|
||||||
|
@ -990,7 +1084,6 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateResourceWithPrefer() throws IOException, Exception {
|
public void testUpdateResourceWithPrefer() throws IOException, Exception {
|
||||||
String methodName = "testUpdateResourceWithPrefer";
|
String methodName = "testUpdateResourceWithPrefer";
|
||||||
|
@ -1036,7 +1129,6 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateWithClientSuppliedIdWhichDoesntExist() {
|
public void testUpdateWithClientSuppliedIdWhichDoesntExist() {
|
||||||
deleteToken("Patient", Patient.SP_IDENTIFIER, "urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2");
|
deleteToken("Patient", Patient.SP_IDENTIFIER, "urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2");
|
||||||
|
@ -1049,8 +1141,7 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
assertThat(p1Id.getValue(), containsString("Patient/testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2/_history"));
|
assertThat(p1Id.getValue(), containsString("Patient/testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2/_history"));
|
||||||
|
|
||||||
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2"))
|
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistRpDstu2")).encodedJson().prettyPrint().execute();
|
||||||
.encodedJson().prettyPrint().execute();
|
|
||||||
assertEquals(1, actual.size());
|
assertEquals(1, actual.size());
|
||||||
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
|
||||||
|
|
||||||
|
@ -1083,32 +1174,52 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
public void testValueSetExpandOperartion() throws IOException {
|
||||||
|
|
||||||
@Test
|
ValueSet upload = ourCtx.newXmlParser().parseResource(ValueSet.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/extensional-case-2.xml")));
|
||||||
public void testValidateResourceWithId() throws IOException {
|
IIdType vsid = ourClient.create().resource(upload).execute().getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
Patient patient = new Patient();
|
HttpGet get = new HttpGet(ourServerBase + "/ValueSet/" + vsid.getIdPart() + "/$expand");
|
||||||
patient.addName().addGiven("James");
|
CloseableHttpResponse response = ourHttpClient.execute(get);
|
||||||
patient.setBirthDate(new DateDt("2011-02-02"));
|
|
||||||
|
|
||||||
Parameters input = new Parameters();
|
|
||||||
input.addParameter().setName("resource").setResource(patient);
|
|
||||||
|
|
||||||
String inputStr = ourCtx.newXmlParser().encodeResourceToString(input);
|
|
||||||
ourLog.info(inputStr);
|
|
||||||
|
|
||||||
HttpPost post = new HttpPost(ourServerBase + "/Patient/123/$validate");
|
|
||||||
post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
|
||||||
|
|
||||||
CloseableHttpResponse response = ourHttpClient.execute(post);
|
|
||||||
try {
|
try {
|
||||||
String resp = IOUtils.toString(response.getEntity().getContent());
|
String resp = IOUtils.toString(response.getEntity().getContent());
|
||||||
ourLog.info(resp);
|
ourLog.info(resp);
|
||||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
//@formatter:on
|
||||||
|
assertThat(resp, stringContainsInOrder(
|
||||||
|
"<ValueSet xmlns=\"http://hl7.org/fhir\">",
|
||||||
|
"<compose>" ,
|
||||||
|
"<include>" ,
|
||||||
|
"<system value=\"http://loinc.org\"/>" ,
|
||||||
|
"<concept>" ,
|
||||||
|
"<code value=\"11378-7\"/>" ,
|
||||||
|
"<display value=\"Systolic blood pressure at First encounter\"/>" ,
|
||||||
|
"</concept>"));
|
||||||
|
//@formatter:off
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(response.getEntity().getContent());
|
IOUtils.closeQuietly(response.getEntity().getContent());
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Filter
|
||||||
|
*/
|
||||||
|
|
||||||
|
get = new HttpGet(ourServerBase + "/ValueSet/" + vsid.getIdPart() + "/$expand?filter=systolic");
|
||||||
|
response = ourHttpClient.execute(get);
|
||||||
|
try {
|
||||||
|
String resp = IOUtils.toString(response.getEntity().getContent());
|
||||||
|
ourLog.info(resp);
|
||||||
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
assertThat(resp, stringContainsInOrder(
|
||||||
|
"<code value=\"11378-7\"/>" ,
|
||||||
|
"<display value=\"Systolic blood pressure at First encounter\"/>"));
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(response.getEntity().getContent());
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1139,6 +1250,33 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateResourceWithId() throws IOException {
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addName().addGiven("James");
|
||||||
|
patient.setBirthDate(new DateDt("2011-02-02"));
|
||||||
|
|
||||||
|
Parameters input = new Parameters();
|
||||||
|
input.addParameter().setName("resource").setResource(patient);
|
||||||
|
|
||||||
|
String inputStr = ourCtx.newXmlParser().encodeResourceToString(input);
|
||||||
|
ourLog.info(inputStr);
|
||||||
|
|
||||||
|
HttpPost post = new HttpPost(ourServerBase + "/Patient/123/$validate");
|
||||||
|
post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||||
|
|
||||||
|
CloseableHttpResponse response = ourHttpClient.execute(post);
|
||||||
|
try {
|
||||||
|
String resp = IOUtils.toString(response.getEntity().getContent());
|
||||||
|
ourLog.info(resp);
|
||||||
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(response.getEntity().getContent());
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<IdDt> toIdListUnqualifiedVersionless(Bundle found) {
|
private List<IdDt> toIdListUnqualifiedVersionless(Bundle found) {
|
||||||
List<IdDt> list = new ArrayList<IdDt>();
|
List<IdDt> list = new ArrayList<IdDt>();
|
||||||
for (BundleEntry next : found.getEntries()) {
|
for (BundleEntry next : found.getEntries()) {
|
||||||
|
@ -1204,101 +1342,4 @@ public class ResourceProviderDstu2Test extends BaseJpaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchLastUpdatedParamRp() throws InterruptedException {
|
|
||||||
String methodName = "testSearchLastUpdatedParamRp";
|
|
||||||
|
|
||||||
int sleep = 100;
|
|
||||||
Thread.sleep(sleep);
|
|
||||||
|
|
||||||
DateTimeDt beforeAny = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
|
|
||||||
IdDt id1a;
|
|
||||||
{
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
|
||||||
patient.addName().addFamily(methodName).addGiven("Joe");
|
|
||||||
id1a = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
|
||||||
}
|
|
||||||
IdDt id1b;
|
|
||||||
{
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
|
||||||
patient.addName().addFamily(methodName + "XXXX").addGiven("Joe");
|
|
||||||
id1b = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.sleep(1100);
|
|
||||||
DateTimeDt beforeR2 = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI);
|
|
||||||
Thread.sleep(1100);
|
|
||||||
|
|
||||||
IdDt id2;
|
|
||||||
{
|
|
||||||
Patient patient = new Patient();
|
|
||||||
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
|
||||||
patient.addName().addFamily(methodName).addGiven("John");
|
|
||||||
id2 = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
|
||||||
.forResource(Patient.class)
|
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
|
||||||
.execute();
|
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
|
||||||
assertThat(patients, hasItems(id1a, id1b, id2));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
|
||||||
.forResource(Patient.class)
|
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
|
||||||
.lastUpdated(new DateRangeParam(beforeAny, null))
|
|
||||||
.execute();
|
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
|
||||||
assertThat(patients, hasItems(id1a, id1b, id2));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
|
||||||
.forResource(Patient.class)
|
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
|
||||||
.lastUpdated(new DateRangeParam(beforeR2, null))
|
|
||||||
.execute();
|
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
|
||||||
assertThat(patients, hasItems(id2));
|
|
||||||
assertThat(patients, not(hasItems(id1a, id1b)));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
|
||||||
.forResource(Patient.class)
|
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
|
||||||
.lastUpdated(new DateRangeParam(beforeAny, beforeR2))
|
|
||||||
.execute();
|
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
|
||||||
assertThat(patients.toString(), patients, not(hasItems(id2)));
|
|
||||||
assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//@formatter:off
|
|
||||||
Bundle found = ourClient.search()
|
|
||||||
.forResource(Patient.class)
|
|
||||||
.where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp"))
|
|
||||||
.lastUpdated(new DateRangeParam(null, beforeR2))
|
|
||||||
.execute();
|
|
||||||
//@formatter:on
|
|
||||||
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
|
|
||||||
assertThat(patients, (hasItems(id1a, id1b)));
|
|
||||||
assertThat(patients, not(hasItems(id2)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
<ValueSet xmlns="http://hl7.org/fhir">
|
||||||
|
<id value="extensional-case-2" />
|
||||||
|
<text>
|
||||||
|
<status value="generated" />
|
||||||
|
<div xmlns="http://www.w3.org/1999/xhtml">A selection of codes from http://loinc.org</div>
|
||||||
|
</text>
|
||||||
|
<identifier>
|
||||||
|
<value
|
||||||
|
value="http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2" />
|
||||||
|
</identifier>
|
||||||
|
<name value="Terminology Services Connectation #1 Extensional case #2" />
|
||||||
|
<publisher value="Grahame Grieve" />
|
||||||
|
<contact>
|
||||||
|
<telecom>
|
||||||
|
<system value="email" />
|
||||||
|
<value value="grahame@healthintersections.com.au" />
|
||||||
|
</telecom>
|
||||||
|
</contact>
|
||||||
|
<description value="an enumeration of codes defined by LOINC" />
|
||||||
|
<status value="draft" />
|
||||||
|
<experimental value="true" />
|
||||||
|
<compose>
|
||||||
|
<include>
|
||||||
|
<system value="http://loinc.org" />
|
||||||
|
<concept>
|
||||||
|
<code value="11378-7" />
|
||||||
|
<display value="Systolic blood pressure at First encounter" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8493-9" />
|
||||||
|
<display value="Systolic blood pressure 10 hour minimum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8494-7" />
|
||||||
|
<display value="Systolic blood pressure 12 hour minimum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8495-4" />
|
||||||
|
<display value="Systolic blood pressure 24 hour minimum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8450-9" />
|
||||||
|
<display value="Systolic blood pressure--expiration" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8451-7" />
|
||||||
|
<display value="Systolic blood pressure--inspiration" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8452-5" />
|
||||||
|
<display value="Systolic blood pressure.inspiration - expiration" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8459-0" />
|
||||||
|
<display value="Systolic blood pressure--sitting" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8460-8" />
|
||||||
|
<display value="Systolic blood pressure--standing" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8461-6" />
|
||||||
|
<display value="Systolic blood pressure--supine" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8479-8" />
|
||||||
|
<display value="Systolic blood pressure by palpation" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8480-6" />
|
||||||
|
<display value="Systolic blood pressure" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8481-4" />
|
||||||
|
<display value="Systolic blood pressure 1 hour maximum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8482-2" />
|
||||||
|
<display value="Systolic blood pressure 8 hour maximum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8483-0" />
|
||||||
|
<display value="Systolic blood pressure 10 hour maximum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8484-8" />
|
||||||
|
<display value="Systolic blood pressure 12 hour maximum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8485-5" />
|
||||||
|
<display value="Systolic blood pressure 24 hour maximum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8486-3" />
|
||||||
|
<display value="Systolic blood pressure 1 hour mean" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8487-1" />
|
||||||
|
<display value="Systolic blood pressure 8 hour mean" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8488-9" />
|
||||||
|
<display value="Systolic blood pressure 10 hour mean" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8489-7" />
|
||||||
|
<display value="Systolic blood pressure 12 hour mean" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8490-5" />
|
||||||
|
<display value="Systolic blood pressure 24 hour mean" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8491-3" />
|
||||||
|
<display value="Systolic blood pressure 1 hour minimum" />
|
||||||
|
</concept>
|
||||||
|
<concept>
|
||||||
|
<code value="8492-1" />
|
||||||
|
<display value="Systolic blood pressure 8 hour minimum" />
|
||||||
|
</concept>
|
||||||
|
</include>
|
||||||
|
</compose>
|
||||||
|
</ValueSet>
|
Loading…
Reference in New Issue