Add lastupdated to capabilitystatement (#2530)

* Add lastupdated to capabilitystatement

* Test fix

* Test fix
This commit is contained in:
James Agnew 2021-04-08 13:23:21 -04:00 committed by GitHub
parent f70648484a
commit edfe1ae8e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1843 additions and 1770 deletions

View File

@ -65,6 +65,19 @@ public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProv
}
@Test
public void testLastUpdatedIncluded() {
CapabilityStatement cs = myClient.capabilities().ofType(CapabilityStatement.class).execute();
List<CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent> fooSearchParams = findSearchParams(cs, "Patient", "_lastUpdated");
assertEquals(1, fooSearchParams.size());
assertEquals("_lastUpdated", fooSearchParams.get(0).getName());
assertEquals("http://localhost:" + ourPort + "/fhir/context/SearchParameter/Patient-_lastUpdated", fooSearchParams.get(0).getDefinition());
assertEquals("Only return resources which were last updated as specified by the given range", fooSearchParams.get(0).getDocumentation());
assertEquals(Enumerations.SearchParamType.DATE, fooSearchParams.get(0).getType());
}
@Override
@AfterEach
public void after() throws Exception {
@ -119,10 +132,10 @@ public class ServerCapabilityStatementProviderJpaR4Test extends BaseResourceProv
.execute();
List<String> includes = findIncludes(cs, "Patient");
assertThat(includes.toString(), includes, contains("*", "Patient:general-practitioner", "Patient:link", "Patient:organization"));
assertThat(includes.toString(), includes, containsInAnyOrder("*", "Patient:general-practitioner", "Patient:link", "Patient:organization"));
includes = findIncludes(cs, "Observation");
assertThat(includes.toString(), includes, contains("*", "Observation:based-on", "Observation:derived-from", "Observation:device", "Observation:encounter", "Observation:focus", "Observation:foo", "Observation:has-member", "Observation:part-of", "Observation:patient", "Observation:performer", "Observation:specimen", "Observation:subject"));
assertThat(includes.toString(), includes, containsInAnyOrder("*", "Observation:based-on", "Observation:derived-from", "Observation:device", "Observation:encounter", "Observation:focus", "Observation:foo", "Observation:has-member", "Observation:part-of", "Observation:patient", "Observation:performer", "Observation:specimen", "Observation:subject"));
List<String> revIncludes = findRevIncludes(cs, "Patient");
assertThat(revIncludes.toString(), revIncludes, hasItems(

View File

@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -349,16 +350,35 @@ public class ServerCapabilityStatementProvider implements IServerConformanceProv
}
ISearchParamRegistry serverConfiguration;
if (myServerConfiguration != null) {
serverConfiguration = myServerConfiguration;
} else {
serverConfiguration = myServer.createConfiguration();
}
/*
* If we have an explicit registry (which will be the case in the JPA server) we use it as priority,
* but also fill in any gaps using params from the server itself. This makes sure we include
* global params like _lastUpdated
*/
Map<String, RuntimeSearchParam> searchParams;
ISearchParamRegistry searchParamRegistry;
if (mySearchParamRegistry != null) {
searchParamRegistry = mySearchParamRegistry;
} else if (myServerConfiguration != null) {
searchParamRegistry = myServerConfiguration;
searchParams = new HashMap<>(mySearchParamRegistry.getActiveSearchParams(resourceName));
for (Entry<String, RuntimeSearchParam> nextBuiltInSp : serverConfiguration.getActiveSearchParams(resourceName).entrySet()) {
if (nextBuiltInSp.getKey().startsWith("_") && !searchParams.containsKey(nextBuiltInSp.getKey())) {
searchParams.put(nextBuiltInSp.getKey(), nextBuiltInSp.getValue());
}
}
} else {
searchParamRegistry = myServer.createConfiguration();
searchParamRegistry = serverConfiguration;
searchParams = serverConfiguration.getActiveSearchParams(resourceName);
}
Map<String, RuntimeSearchParam> searchParams = searchParamRegistry.getActiveSearchParams(resourceName);
for (RuntimeSearchParam next : searchParams.values()) {
IBase searchParam = terser.addElement(resource, "searchParam");
terser.addElement(searchParam, "name", next.getName());
@ -412,9 +432,7 @@ public class ServerCapabilityStatementProvider implements IServerConformanceProv
continue;
}
for (RuntimeSearchParam t : searchParamRegistry
.getActiveSearchParams(nextResourceName)
.values()) {
for (RuntimeSearchParam t : searchParamRegistry.getActiveSearchParams(nextResourceName).values()) {
if (t.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
if (isNotBlank(t.getName())) {
boolean appropriateTarget = false;

View File

@ -756,6 +756,48 @@ public class ServerCapabilityStatementProviderR4Test {
assertThat(searchParamNames, containsInAnyOrder("patient.birthdate", "patient.family", "patient.given", "date"));
}
@Test
public void testIncludeLastUpdatedSearchParam() throws Exception {
class MyProvider implements IResourceProvider {
@Override
public Class<DiagnosticReport> getResourceType() {
return DiagnosticReport.class;
}
@Search
public List<IBaseResource> search(@OptionalParam(name = DiagnosticReport.SP_DATE)
DateRangeParam range,
@Description(shortDefinition = "Only return resources which were last updated as specified by the given range")
@OptionalParam(name = "_lastUpdated")
DateRangeParam theLastUpdated
) {
return null;
}
}
RestfulServer rs = new RestfulServer(myCtx);
rs.setProviders(new MyProvider());
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider(rs) {
};
rs.setServerConformanceProvider(sc);
rs.init(createServletConfig());
CapabilityStatement opDef = (CapabilityStatement) sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
validate(opDef);
CapabilityStatementRestResourceComponent resource = opDef.getRest().get(0).getResource().get(0);
assertEquals("DiagnosticReport", resource.getType());
List<String> searchParamNames = resource.getSearchParam().stream().map(t -> t.getName()).collect(Collectors.toList());
assertThat(searchParamNames, containsInAnyOrder("date", "_lastUpdated"));
}
@Test
public void testSystemLevelNamedQueryWithParameters() throws Exception {
RestfulServer rs = new RestfulServer(myCtx);