Fix #286 - Resource chains not added to conformance statement
This commit is contained in:
parent
00f0ea4a0b
commit
0f07cac496
|
@ -72,6 +72,7 @@ import ca.uhn.fhir.rest.method.IParameter;
|
|||
import ca.uhn.fhir.rest.method.OperationMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.OperationMethodBinding.ReturnType;
|
||||
import ca.uhn.fhir.rest.method.OperationParameter;
|
||||
import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchParameter;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
|
@ -434,6 +435,15 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
|
|||
if (StringUtils.isNotBlank(chain)) {
|
||||
param.addChain(chain);
|
||||
}
|
||||
|
||||
if (nextParameter.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
|
||||
for (String nextWhitelist : new TreeSet<String>(nextParameter.getQualifierWhitelist())) {
|
||||
if (nextWhitelist.startsWith(".")) {
|
||||
param.addChain(nextWhitelist.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
param.setDocumentation(nextParamDescription);
|
||||
if (nextParameter.getParamType() != null) {
|
||||
param.getTypeElement().setValueAsString(nextParameter.getParamType().getCode());
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
|
||||
package org.hl7.fhir.dstu21.hapi.rest.server;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.hl7.fhir.dstu21.model.Organization;
|
||||
import org.hl7.fhir.dstu21.model.Patient;
|
||||
import org.hl7.fhir.dstu21.model.Practitioner;
|
||||
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.annotation.Description;
|
||||
import ca.uhn.fhir.rest.annotation.IncludeParam;
|
||||
import ca.uhn.fhir.rest.annotation.OptionalParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.Sort;
|
||||
import ca.uhn.fhir.rest.api.SortSpec;
|
||||
// import ca.uhn.fhir.model.dstu.resource.Binary;
|
||||
// import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
// import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
|
||||
import ca.uhn.fhir.rest.param.StringAndListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenAndListParam;
|
||||
import ca.uhn.fhir.rest.param.UriAndListParam;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
|
||||
public class PatientResourceProvider implements IResourceProvider
|
||||
{
|
||||
|
||||
@Override
|
||||
public Class<Patient> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@Search()
|
||||
public ca.uhn.fhir.rest.server.IBundleProvider search(
|
||||
javax.servlet.http.HttpServletRequest theServletRequest,
|
||||
|
||||
@Description(shortDefinition="The resource identity")
|
||||
@OptionalParam(name="_id")
|
||||
StringAndListParam theId,
|
||||
|
||||
@Description(shortDefinition="The resource language")
|
||||
@OptionalParam(name="_language")
|
||||
StringAndListParam theResourceLanguage,
|
||||
|
||||
@Description(shortDefinition="Search the contents of the resource's data using a fulltext search")
|
||||
@OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_CONTENT)
|
||||
StringAndListParam theFtContent,
|
||||
|
||||
@Description(shortDefinition="Search the contents of the resource's narrative using a fulltext search")
|
||||
@OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_TEXT)
|
||||
StringAndListParam theFtText,
|
||||
|
||||
@Description(shortDefinition="Search for resources which have the given tag")
|
||||
@OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_TAG)
|
||||
TokenAndListParam theSearchForTag,
|
||||
|
||||
@Description(shortDefinition="Search for resources which have the given security labels")
|
||||
@OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_SECURITY)
|
||||
TokenAndListParam theSearchForSecurity,
|
||||
|
||||
@Description(shortDefinition="Search for resources which have the given profile")
|
||||
@OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_PROFILE)
|
||||
UriAndListParam theSearchForProfile,
|
||||
|
||||
|
||||
@Description(shortDefinition="A patient identifier")
|
||||
@OptionalParam(name="identifier")
|
||||
TokenAndListParam theIdentifier,
|
||||
|
||||
@Description(shortDefinition="A portion of either family or given name of the patient")
|
||||
@OptionalParam(name="name")
|
||||
StringAndListParam theName,
|
||||
|
||||
@Description(shortDefinition="A portion of the family name of the patient")
|
||||
@OptionalParam(name="family")
|
||||
StringAndListParam theFamily,
|
||||
|
||||
@Description(shortDefinition="A portion of the given name of the patient")
|
||||
@OptionalParam(name="given")
|
||||
StringAndListParam theGiven,
|
||||
|
||||
@Description(shortDefinition="A portion of either family or given name using some kind of phonetic matching algorithm")
|
||||
@OptionalParam(name="phonetic")
|
||||
StringAndListParam thePhonetic,
|
||||
|
||||
@Description(shortDefinition="The value in any kind of telecom details of the patient")
|
||||
@OptionalParam(name="telecom")
|
||||
TokenAndListParam theTelecom,
|
||||
|
||||
@Description(shortDefinition="A value in a phone contact")
|
||||
@OptionalParam(name="phone")
|
||||
TokenAndListParam thePhone,
|
||||
|
||||
@Description(shortDefinition="A value in an email contact")
|
||||
@OptionalParam(name="email")
|
||||
TokenAndListParam theEmail,
|
||||
|
||||
@Description(shortDefinition="An address in any kind of address/part of the patient")
|
||||
@OptionalParam(name="address")
|
||||
StringAndListParam theAddress,
|
||||
|
||||
@Description(shortDefinition="A city specified in an address")
|
||||
@OptionalParam(name="address-city")
|
||||
StringAndListParam theAddress_city,
|
||||
|
||||
@Description(shortDefinition="A state specified in an address")
|
||||
@OptionalParam(name="address-state")
|
||||
StringAndListParam theAddress_state,
|
||||
|
||||
@Description(shortDefinition="A postalCode specified in an address")
|
||||
@OptionalParam(name="address-postalcode")
|
||||
StringAndListParam theAddress_postalcode,
|
||||
|
||||
@Description(shortDefinition="A country specified in an address")
|
||||
@OptionalParam(name="address-country")
|
||||
StringAndListParam theAddress_country,
|
||||
|
||||
@Description(shortDefinition="A use code specified in an address")
|
||||
@OptionalParam(name="address-use")
|
||||
TokenAndListParam theAddress_use,
|
||||
|
||||
@Description(shortDefinition="Gender of the patient")
|
||||
@OptionalParam(name="gender")
|
||||
TokenAndListParam theGender,
|
||||
|
||||
@Description(shortDefinition="Language code (irrespective of use value)")
|
||||
@OptionalParam(name="language")
|
||||
TokenAndListParam theLanguage,
|
||||
|
||||
@Description(shortDefinition="The patient's date of birth")
|
||||
@OptionalParam(name="birthdate")
|
||||
DateRangeParam theBirthdate,
|
||||
|
||||
@Description(shortDefinition="The organization at which this person is a patient")
|
||||
@OptionalParam(name="organization", targetTypes={ Organization.class } )
|
||||
ReferenceAndListParam theOrganization,
|
||||
|
||||
@Description(shortDefinition="Patient's nominated care provider, could be a care manager, not the organization that manages the record")
|
||||
@OptionalParam(name="careprovider", targetTypes={ Organization.class , Practitioner.class } )
|
||||
ReferenceAndListParam theCareprovider,
|
||||
|
||||
@Description(shortDefinition="Whether the patient record is active")
|
||||
@OptionalParam(name="active")
|
||||
TokenAndListParam theActive,
|
||||
|
||||
@Description(shortDefinition="The species for animal patients")
|
||||
@OptionalParam(name="animal-species")
|
||||
TokenAndListParam theAnimal_species,
|
||||
|
||||
@Description(shortDefinition="The breed for animal patients")
|
||||
@OptionalParam(name="animal-breed")
|
||||
TokenAndListParam theAnimal_breed,
|
||||
|
||||
@Description(shortDefinition="All patients linked to the given patient")
|
||||
@OptionalParam(name="link", targetTypes={ Patient.class } )
|
||||
ReferenceAndListParam theLink,
|
||||
|
||||
@Description(shortDefinition="This patient has been marked as deceased, or as a death date entered")
|
||||
@OptionalParam(name="deceased")
|
||||
TokenAndListParam theDeceased,
|
||||
|
||||
@Description(shortDefinition="The date of death has been provided and satisfies this search value")
|
||||
@OptionalParam(name="deathdate")
|
||||
DateRangeParam theDeathdate,
|
||||
|
||||
@IncludeParam(reverse=true)
|
||||
Set<Include> theRevIncludes,
|
||||
@Description(shortDefinition="Only return resources which were last updated as specified by the given range")
|
||||
@OptionalParam(name="_lastUpdated")
|
||||
DateRangeParam theLastUpdated,
|
||||
|
||||
@IncludeParam(allow= {
|
||||
"Patient:careprovider" , "Patient:link" , "Patient:organization" , "Patient:careprovider" , "Patient:link" , "Patient:organization" , "Patient:careprovider" , "Patient:link" , "Patient:organization" , "*"
|
||||
})
|
||||
Set<Include> theIncludes,
|
||||
|
||||
@Sort
|
||||
SortSpec theSort,
|
||||
|
||||
@ca.uhn.fhir.rest.annotation.Count
|
||||
Integer theCount
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,739 @@
|
|||
package org.hl7.fhir.dstu21.hapi.rest.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.hl7.fhir.dstu21.model.Conformance;
|
||||
import org.hl7.fhir.dstu21.model.Conformance.ConditionalDeleteStatus;
|
||||
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestComponent;
|
||||
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestResourceComponent;
|
||||
import org.hl7.fhir.dstu21.model.Conformance.ConformanceRestResourceSearchParamComponent;
|
||||
import org.hl7.fhir.dstu21.model.Conformance.SystemRestfulInteraction;
|
||||
import org.hl7.fhir.dstu21.model.Conformance.TypeRestfulInteraction;
|
||||
import org.hl7.fhir.dstu21.model.DateType;
|
||||
import org.hl7.fhir.dstu21.model.DiagnosticReport;
|
||||
import org.hl7.fhir.dstu21.model.IdType;
|
||||
import org.hl7.fhir.dstu21.model.OperationDefinition;
|
||||
import org.hl7.fhir.dstu21.model.Patient;
|
||||
import org.hl7.fhir.dstu21.model.StringType;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.annotation.Description;
|
||||
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
|
||||
import ca.uhn.fhir.rest.annotation.Create;
|
||||
import ca.uhn.fhir.rest.annotation.Delete;
|
||||
import ca.uhn.fhir.rest.annotation.History;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.IncludeParam;
|
||||
import ca.uhn.fhir.rest.annotation.Operation;
|
||||
import ca.uhn.fhir.rest.annotation.OperationParam;
|
||||
import ca.uhn.fhir.rest.annotation.OptionalParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.Update;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.method.BaseMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.IParameter;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchParameter;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
|
||||
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.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.ResourceBinding;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
|
||||
public class ServerConformanceProviderDstu21Test {
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu2_1();
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderDstu21Test.class);
|
||||
|
||||
private HttpServletRequest createHttpServletRequest() {
|
||||
HttpServletRequest req = mock(HttpServletRequest.class);
|
||||
when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search");
|
||||
when(req.getServletPath()).thenReturn("/fhir");
|
||||
when(req.getRequestURL()).thenReturn(new StringBuffer().append("http://fhirstorm.dyndns.org:8080/FhirStorm/fhir/Patient/_search"));
|
||||
when(req.getContextPath()).thenReturn("/FhirStorm");
|
||||
return req;
|
||||
}
|
||||
|
||||
private ServletConfig createServletConfig() {
|
||||
ServletConfig sc = mock(ServletConfig.class);
|
||||
when(sc.getServletContext()).thenReturn(null);
|
||||
return sc;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditionalOperations() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new ConditionalProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
ConformanceRestResourceComponent res = conformance.getRest().get(0).getResource().get(1);
|
||||
assertEquals("Patient", res.getType());
|
||||
|
||||
assertTrue(res.getConditionalCreate());
|
||||
assertEquals(ConditionalDeleteStatus.MULTIPLE, res.getConditionalDelete());
|
||||
assertTrue(res.getConditionalUpdate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedOperationReturningBundle() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new ProviderWithExtendedOperationReturningBundle());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
assertEquals(1, conformance.getRest().get(0).getOperation().size());
|
||||
assertEquals("$everything", conformance.getRest().get(0).getOperation().get(0).getName());
|
||||
assertEquals("OperationDefinition/everything", conformance.getRest().get(0).getOperation().get(0).getDefinition().getReferenceElement().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtendedOperationReturningBundleOperation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new ProviderWithExtendedOperationReturningBundle());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs) {
|
||||
};
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
OperationDefinition opDef = sc.readOperationDefinition(new IdType("OperationDefinition/everything"));
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(opDef);
|
||||
ourLog.info(conf);
|
||||
|
||||
assertEquals("$everything", opDef.getCode());
|
||||
assertEquals(true, opDef.getIdempotent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstanceHistorySupported() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new InstanceHistoryProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
conf = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(conformance);
|
||||
assertThat(conf, containsString("<interaction><code value=\"" + TypeRestfulInteraction.HISTORYINSTANCE.toCode() + "\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiOptionalDocumentation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new MultiOptionalProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found = false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
for (ResourceBinding resourceBinding : resourceBindings) {
|
||||
if (resourceBinding.getResourceName().equals("Patient")) {
|
||||
List<BaseMethodBinding<?>> methodBindings = resourceBinding.getMethodBindings();
|
||||
SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0);
|
||||
SearchParameter param = (SearchParameter) binding.getParameters().iterator().next();
|
||||
assertEquals("The patient's identifier", param.getDescription());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
assertThat(conf, containsString("<documentation value=\"The patient's identifier\"/>"));
|
||||
assertThat(conf, containsString("<documentation value=\"The patient's name\"/>"));
|
||||
assertThat(conf, containsString("<type value=\"token\"/>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonConditionalOperations() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new NonConditionalProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
ConformanceRestResourceComponent res = conformance.getRest().get(0).getResource().get(1);
|
||||
assertEquals("Patient", res.getType());
|
||||
|
||||
assertNull(res.getConditionalCreateElement().getValue());
|
||||
assertNull(res.getConditionalDeleteElement().getValue());
|
||||
assertNull(res.getConditionalUpdateElement().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationDocumentation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found = false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
for (ResourceBinding resourceBinding : resourceBindings) {
|
||||
if (resourceBinding.getResourceName().equals("Patient")) {
|
||||
List<BaseMethodBinding<?>> methodBindings = resourceBinding.getMethodBindings();
|
||||
SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0);
|
||||
for (IParameter next : binding.getParameters()) {
|
||||
SearchParameter param = (SearchParameter) next;
|
||||
if (param.getDescription().contains("The patient's identifier (MRN or other card number")) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info("AAAAAA" + conf);
|
||||
|
||||
assertThat(conf, containsString("<documentation value=\"The patient's identifier (MRN or other card number)\"/>"));
|
||||
assertThat(conf, containsString("<type value=\"token\"/>"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationOnNoTypes() throws Exception {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new PlainProviderWithExtendedOperationOnNoType());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs) {
|
||||
@Override
|
||||
public Conformance getServerConformance(HttpServletRequest theRequest) {
|
||||
return super.getServerConformance(theRequest);
|
||||
}
|
||||
};
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance sconf = sc.getServerConformance(createHttpServletRequest());
|
||||
assertEquals("OperationDefinition/plain", sconf.getRest().get(0).getOperation().get(0).getDefinition().getReferenceElement().getValue());
|
||||
|
||||
OperationDefinition opDef = sc.readOperationDefinition(new IdType("OperationDefinition/plain"));
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(opDef);
|
||||
ourLog.info(conf);
|
||||
|
||||
assertEquals("$plain", opDef.getCode());
|
||||
assertEquals(true, opDef.getIdempotent());
|
||||
assertEquals(3, opDef.getParameter().size());
|
||||
assertEquals("start", opDef.getParameter().get(0).getName());
|
||||
assertEquals("in", opDef.getParameter().get(0).getUse().toCode());
|
||||
assertEquals("0", opDef.getParameter().get(0).getMinElement().getValueAsString());
|
||||
assertEquals("date", opDef.getParameter().get(0).getTypeElement().getValueAsString());
|
||||
|
||||
assertEquals("out1", opDef.getParameter().get(2).getName());
|
||||
assertEquals("out", opDef.getParameter().get(2).getUse().toCode());
|
||||
assertEquals("1", opDef.getParameter().get(2).getMinElement().getValueAsString());
|
||||
assertEquals("2", opDef.getParameter().get(2).getMaxElement().getValueAsString());
|
||||
assertEquals("string", opDef.getParameter().get(2).getTypeElement().getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProviderWithRequiredAndOptional() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new ProviderWithRequiredAndOptional());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
ConformanceRestComponent rest = conformance.getRest().get(0);
|
||||
ConformanceRestResourceComponent res = rest.getResource().get(0);
|
||||
assertEquals("DiagnosticReport", res.getType());
|
||||
|
||||
assertEquals(DiagnosticReport.SP_SUBJECT, res.getSearchParam().get(0).getName());
|
||||
assertEquals("identifier", res.getSearchParam().get(0).getChain().get(0).getValue());
|
||||
|
||||
assertEquals(DiagnosticReport.SP_CODE, res.getSearchParam().get(1).getName());
|
||||
|
||||
assertEquals(DiagnosticReport.SP_DATE, res.getSearchParam().get(2).getName());
|
||||
|
||||
assertEquals(1, res.getSearchInclude().size());
|
||||
assertEquals("DiagnosticReport.result", res.getSearchInclude().get(0).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAndVReadSupported() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new VreadProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
conf = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(conformance);
|
||||
assertThat(conf, containsString("<interaction><code value=\"vread\"/></interaction>"));
|
||||
assertThat(conf, containsString("<interaction><code value=\"read\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadSupported() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new ReadProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
conf = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(conformance);
|
||||
assertThat(conf, not(containsString("<interaction><code value=\"vread\"/></interaction>")));
|
||||
assertThat(conf, containsString("<interaction><code value=\"read\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchParameterDocumentation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found = false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
for (ResourceBinding resourceBinding : resourceBindings) {
|
||||
if (resourceBinding.getResourceName().equals("Patient")) {
|
||||
List<BaseMethodBinding<?>> methodBindings = resourceBinding.getMethodBindings();
|
||||
SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0);
|
||||
for (IParameter next : binding.getParameters()) {
|
||||
SearchParameter param = (SearchParameter) next;
|
||||
if (param.getDescription().contains("The patient's identifier (MRN or other card number")) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
assertThat(conf, containsString("<documentation value=\"The patient's identifier (MRN or other card number)\"/>"));
|
||||
assertThat(conf, containsString("<type value=\"token\"/>"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #286
|
||||
*/
|
||||
@Test
|
||||
public void testSearchReferenceParameterWithWhitelistDocumentation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProviderWithWhitelist());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found = false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
for (ResourceBinding resourceBinding : resourceBindings) {
|
||||
if (resourceBinding.getResourceName().equals("Patient")) {
|
||||
List<BaseMethodBinding<?>> methodBindings = resourceBinding.getMethodBindings();
|
||||
SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0);
|
||||
SearchParameter param = (SearchParameter) binding.getParameters().get(0);
|
||||
assertEquals("The organization at which this person is a patient", param.getDescription());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
ConformanceRestResourceComponent resource = findRestResource(conformance, "Patient");
|
||||
|
||||
ConformanceRestResourceSearchParamComponent param = resource.getSearchParam().get(0);
|
||||
assertEquals("bar", param.getChain().get(0).getValue());
|
||||
assertEquals("foo", param.getChain().get(1).getValue());
|
||||
assertEquals(2, param.getChain().size());
|
||||
}
|
||||
|
||||
private ConformanceRestResourceComponent findRestResource(Conformance conformance, String wantResource) throws Exception {
|
||||
ConformanceRestResourceComponent resource = null;
|
||||
for (ConformanceRestResourceComponent next : conformance.getRest().get(0).getResource()) {
|
||||
if (next.getType().equals(wantResource)) {
|
||||
resource = next;
|
||||
}
|
||||
}
|
||||
if (resource == null) {
|
||||
throw new Exception("Could not find resource: " + wantResource);
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* See #286
|
||||
*/
|
||||
@Test
|
||||
public void testSearchReferenceParameterDocumentation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new PatientResourceProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found = false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
for (ResourceBinding resourceBinding : resourceBindings) {
|
||||
if (resourceBinding.getResourceName().equals("Patient")) {
|
||||
List<BaseMethodBinding<?>> methodBindings = resourceBinding.getMethodBindings();
|
||||
SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0);
|
||||
SearchParameter param = (SearchParameter) binding.getParameters().get(25);
|
||||
assertEquals("The organization at which this person is a patient", param.getDescription());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemHistorySupported() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SystemHistoryProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
conf = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(conformance);
|
||||
assertThat(conf, containsString("<interaction><code value=\"" + SystemRestfulInteraction.HISTORYSYSTEM.toCode() + "\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeHistorySupported() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new TypeHistoryProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
conf = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(conformance);
|
||||
assertThat(conf, containsString("<interaction><code value=\"" + TypeRestfulInteraction.HISTORYTYPE.toCode() + "\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateGeneratedStatement() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new MultiOptionalProvider());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance));
|
||||
|
||||
ValidationResult result = ourCtx.newValidator().validateWithResult(conformance);
|
||||
assertTrue(result.getMessages().toString(), result.isSuccessful());
|
||||
}
|
||||
|
||||
public static class ConditionalProvider implements IResourceProvider {
|
||||
|
||||
@Create
|
||||
public MethodOutcome create(@ResourceParam Patient thePatient, @ConditionalUrlParam String theConditionalUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Delete
|
||||
public MethodOutcome delete(@IdParam IdType theId, @ConditionalUrlParam(supportsMultiple = true) String theConditionalUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IBaseResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@Update
|
||||
public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient, @ConditionalUrlParam String theConditionalUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class InstanceHistoryProvider implements IResourceProvider {
|
||||
@Override
|
||||
public Class<? extends IBaseResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@History
|
||||
public List<IBaseResource> history(@IdParam IdType theId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class MultiOptionalProvider {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient(@Description(shortDefinition = "The patient's identifier") @OptionalParam(name = Patient.SP_IDENTIFIER) TokenParam theIdentifier, @Description(shortDefinition = "The patient's name") @OptionalParam(name = Patient.SP_NAME) StringParam theName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class NonConditionalProvider implements IResourceProvider {
|
||||
|
||||
@Create
|
||||
public MethodOutcome create(@ResourceParam Patient thePatient) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Delete
|
||||
public MethodOutcome delete(@IdParam IdType theId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IBaseResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@Update
|
||||
public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class PlainProviderWithExtendedOperationOnNoType {
|
||||
|
||||
@Operation(name = "plain", idempotent = true, returnParameters = { @OperationParam(min = 1, max = 2, name = "out1", type = StringType.class) })
|
||||
public ca.uhn.fhir.rest.server.IBundleProvider everything(javax.servlet.http.HttpServletRequest theServletRequest, @IdParam IdType theId, @OperationParam(name = "start") DateType theStart, @OperationParam(name = "end") DateType theEnd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ProviderWithExtendedOperationReturningBundle implements IResourceProvider {
|
||||
|
||||
@Operation(name = "everything", idempotent = true)
|
||||
public ca.uhn.fhir.rest.server.IBundleProvider everything(javax.servlet.http.HttpServletRequest theServletRequest, @IdParam IdType theId, @OperationParam(name = "start") DateType theStart, @OperationParam(name = "end") DateType theEnd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IBaseResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ProviderWithRequiredAndOptional {
|
||||
|
||||
@Description(shortDefinition = "This is a search for stuff!")
|
||||
@Search
|
||||
public List<DiagnosticReport> findDiagnosticReportsByPatient(@RequiredParam(name = DiagnosticReport.SP_SUBJECT + '.' + Patient.SP_IDENTIFIER) TokenParam thePatientId, @OptionalParam(name = DiagnosticReport.SP_CODE) TokenOrListParam theNames,
|
||||
@OptionalParam(name = DiagnosticReport.SP_DATE) DateRangeParam theDateRange, @IncludeParam(allow = { "DiagnosticReport.result" }) Set<Include> theIncludes) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class ReadProvider {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient(@Description(shortDefinition = "The patient's identifier (MRN or other card number)") @RequiredParam(name = Patient.SP_IDENTIFIER) TokenParam theIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Read(version = false)
|
||||
public Patient readPatient(@IdParam IdType theId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SearchProvider {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient1(@Description(shortDefinition = "The patient's identifier (MRN or other card number)") @RequiredParam(name = Patient.SP_IDENTIFIER) TokenParam theIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient2(@Description(shortDefinition = "All patients linked to the given patient") @OptionalParam(name = "link", targetTypes = { Patient.class }) ReferenceAndListParam theLink) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SearchProviderWithWhitelist {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient1(
|
||||
@Description(shortDefinition = "The organization at which this person is a patient")
|
||||
@RequiredParam(name = Patient.SP_ORGANIZATION, chainWhitelist= {"foo", "bar"})
|
||||
ReferenceAndListParam theIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SystemHistoryProvider {
|
||||
|
||||
@History
|
||||
public List<IBaseResource> history() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class TypeHistoryProvider implements IResourceProvider {
|
||||
|
||||
@Override
|
||||
public Class<? extends IBaseResource> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@History
|
||||
public List<IBaseResource> history() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class VreadProvider {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient(@Description(shortDefinition = "The patient's identifier (MRN or other card number)") @RequiredParam(name = Patient.SP_IDENTIFIER) TokenParam theIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Read(version = true)
|
||||
public Patient readPatient(@IdParam IdType theId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -72,6 +72,7 @@ import ca.uhn.fhir.rest.method.IParameter;
|
|||
import ca.uhn.fhir.rest.method.OperationMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.OperationMethodBinding.ReturnType;
|
||||
import ca.uhn.fhir.rest.method.OperationParameter;
|
||||
import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchParameter;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
|
@ -423,6 +424,15 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
|
|||
if (StringUtils.isNotBlank(chain)) {
|
||||
param.addChain(chain);
|
||||
}
|
||||
|
||||
if (nextParameter.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
|
||||
for (String nextWhitelist : new TreeSet<String>(nextParameter.getQualifierWhitelist())) {
|
||||
if (nextWhitelist.startsWith(".")) {
|
||||
param.addChain(nextWhitelist.substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
param.setDocumentation(nextParamDescription);
|
||||
if (nextParameter.getParamType() != null) {
|
||||
param.getTypeElement().setValueAsString(nextParameter.getParamType().getCode());
|
||||
|
|
|
@ -26,6 +26,7 @@ import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
|||
import ca.uhn.fhir.model.dstu2.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResourceSearchParam;
|
||||
import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu2.resource.OperationDefinition;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
|
@ -401,6 +402,61 @@ public class ServerConformanceProviderDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #286
|
||||
*/
|
||||
@Test
|
||||
public void testSearchReferenceParameterWithWhitelistDocumentation() throws Exception {
|
||||
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProviderWithWhitelist());
|
||||
|
||||
ServerConformanceProvider sc = new ServerConformanceProvider(rs);
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
|
||||
boolean found = false;
|
||||
Collection<ResourceBinding> resourceBindings = rs.getResourceBindings();
|
||||
for (ResourceBinding resourceBinding : resourceBindings) {
|
||||
if (resourceBinding.getResourceName().equals("Patient")) {
|
||||
List<BaseMethodBinding<?>> methodBindings = resourceBinding.getMethodBindings();
|
||||
SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0);
|
||||
SearchParameter param = (SearchParameter) binding.getParameters().get(0);
|
||||
assertEquals("The organization at which this person is a patient", param.getDescription());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
Conformance conformance = sc.getServerConformance(createHttpServletRequest());
|
||||
|
||||
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance);
|
||||
ourLog.info(conf);
|
||||
|
||||
RestResource resource = findRestResource(conformance, "Patient");
|
||||
|
||||
RestResourceSearchParam param = resource.getSearchParam().get(0);
|
||||
assertEquals("bar", param.getChain().get(0).getValue());
|
||||
assertEquals("foo", param.getChain().get(1).getValue());
|
||||
assertEquals(2, param.getChain().size());
|
||||
}
|
||||
|
||||
private RestResource findRestResource(Conformance conformance, String wantResource) throws Exception {
|
||||
RestResource resource = null;
|
||||
for (RestResource next : conformance.getRest().get(0).getResource()) {
|
||||
if (next.getType().equals(wantResource)) {
|
||||
resource = next;
|
||||
}
|
||||
}
|
||||
if (resource == null) {
|
||||
throw new Exception("Could not find resource: " + wantResource);
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* See #286
|
||||
*/
|
||||
@Test
|
||||
public void testSearchReferenceParameterDocumentation() throws Exception {
|
||||
|
||||
|
@ -611,9 +667,6 @@ public class ServerConformanceProviderDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class SearchProvider {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
|
@ -628,6 +681,18 @@ public class ServerConformanceProviderDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
public static class SearchProviderWithWhitelist {
|
||||
|
||||
@Search(type = Patient.class)
|
||||
public Patient findPatient1(
|
||||
@Description(shortDefinition = "The organization at which this person is a patient")
|
||||
@RequiredParam(name = Patient.SP_ORGANIZATION, chainWhitelist= {"foo", "bar"})
|
||||
ReferenceAndListParam theIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SystemHistoryProvider {
|
||||
|
||||
@History
|
||||
|
|
|
@ -154,6 +154,11 @@
|
|||
Add support for new modifier types on Token search params in Server and
|
||||
annotation client.
|
||||
</action>
|
||||
<action type="fix" issue="286">
|
||||
Server conformance statement should include search parameter chains if the
|
||||
chains are explicitly defined via @Search(whitelist={....}). Thanks to lcamilo15
|
||||
for reporting!
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.3" date="2015-11-14">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue