diff --git a/dsf-fhir/dsf-fhir-rest-adapter/src/main/java/org/highmed/dsf/fhir/adapter/HtmlFhirAdapter.java b/dsf-fhir/dsf-fhir-rest-adapter/src/main/java/org/highmed/dsf/fhir/adapter/HtmlFhirAdapter.java index 685d112aa..61687be45 100644 --- a/dsf-fhir/dsf-fhir-rest-adapter/src/main/java/org/highmed/dsf/fhir/adapter/HtmlFhirAdapter.java +++ b/dsf-fhir/dsf-fhir-rest-adapter/src/main/java/org/highmed/dsf/fhir/adapter/HtmlFhirAdapter.java @@ -178,8 +178,13 @@ private Optional getResourceUrl(T t) throws MalformedURLException else if (t instanceof Resource && t.getIdElement().getResourceType() != null && t.getIdElement().getIdPart() != null) { - return Optional.of(String.format("%s/%s/%s", serverBaseProvider.getServerBase(), - t.getIdElement().getResourceType(), t.getIdElement().getIdPart())); + if (!uriInfo.getPath().contains("_history")) + return Optional.of(String.format("%s/%s/%s", serverBaseProvider.getServerBase(), + t.getIdElement().getResourceType(), t.getIdElement().getIdPart())); + else + return Optional.of(String.format("%s/%s/%s/_history/%s", serverBaseProvider.getServerBase(), + t.getIdElement().getResourceType(), t.getIdElement().getIdPart(), + t.getIdElement().getVersionIdPart())); } else return Optional.empty(); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/history/HistoryServiceImpl.java b/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/history/HistoryServiceImpl.java index 61f725fcc..e83c1f034 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/history/HistoryServiceImpl.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/history/HistoryServiceImpl.java @@ -29,6 +29,7 @@ public class HistoryServiceImpl implements HistoryService, InitializingBean { + private final String serverBase; private final int defaultPageCount; private final ParameterConverter parameterConverter; private final ExceptionHandler exceptionHandler; @@ -36,10 +37,11 @@ public class HistoryServiceImpl implements HistoryService, InitializingBean private final HistoryDao historyDao; private final HistoryUserFilterFactory historyUserFilterFactory; - public HistoryServiceImpl(int defaultPageCount, ParameterConverter parameterConverter, + public HistoryServiceImpl(String serverBase, int defaultPageCount, ParameterConverter parameterConverter, ExceptionHandler exceptionHandler, ResponseGenerator responseGenerator, HistoryDao historyDao, HistoryUserFilterFactory historyUserFilterFactory) { + this.serverBase = serverBase; this.defaultPageCount = defaultPageCount; this.parameterConverter = parameterConverter; this.exceptionHandler = exceptionHandler; @@ -51,6 +53,7 @@ public HistoryServiceImpl(int defaultPageCount, ParameterConverter parameterConv @Override public void afterPropertiesSet() throws Exception { + Objects.requireNonNull(serverBase, "serverBase"); Objects.requireNonNull(parameterConverter, "parameterConverter"); Objects.requireNonNull(exceptionHandler, "exceptionHandler"); Objects.requireNonNull(responseGenerator, "responseGenerator"); @@ -88,19 +91,26 @@ public Bundle getHistory(User user, UriInfo uri, HttpHeaders headers, Class historyDao.readHistory(historyUserFilterFactory.getUserFilters(user), pageAndCount, atParameter, sinceParameter)); else if (resource != null && id != null) + { history = exceptionHandler.handleSqlException(() -> historyDao.readHistory( historyUserFilterFactory.getUserFilter(user, resource), pageAndCount, atParameter, sinceParameter, resource, parameterConverter.toUuid(getResourceTypeName(resource), id))); + path = resource.getAnnotation(ResourceDef.class).name(); + } else if (resource != null) + { history = exceptionHandler.handleSqlException( () -> historyDao.readHistory(historyUserFilterFactory.getUserFilter(user, resource), pageAndCount, atParameter, sinceParameter, resource)); + path = resource.getAnnotation(ResourceDef.class).name(); + } else throw new WebApplicationException(); @@ -116,7 +126,13 @@ else if (resource != null) String format = queryParameters.getFirst(SearchQuery.PARAMETER_FORMAT); String pretty = queryParameters.getFirst(SearchQuery.PARAMETER_PRETTY); - UriBuilder bundleUri = uri.getAbsolutePathBuilder(); + UriBuilder bundleUri = UriBuilder.fromPath(serverBase); + if (path != null) + bundleUri = bundleUri.path(path); + if (path != null && id != null) + bundleUri = bundleUri.path(id); + + bundleUri = bundleUri.path("_history"); atParameter.modifyBundleUri(bundleUri); sinceParameter.modifyBundleUri(bundleUri); diff --git a/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/spring/config/HistoryConfig.java b/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/spring/config/HistoryConfig.java index 3ebed1ce0..6694fa92b 100644 --- a/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/spring/config/HistoryConfig.java +++ b/dsf-fhir/dsf-fhir-server/src/main/java/org/highmed/dsf/fhir/spring/config/HistoryConfig.java @@ -12,6 +12,9 @@ @Configuration public class HistoryConfig { + @Value("${org.highmed.dsf.fhir.serverBase}") + private String serverBase; + @Value("${org.highmed.dsf.fhir.defaultPageCount}") private int defaultPageCount; @@ -30,7 +33,7 @@ public HistoryUserFilterFactory historyUserFilterFactory() @Bean public HistoryService historyService() { - return new HistoryServiceImpl(defaultPageCount, helperConfig.parameterConverter(), + return new HistoryServiceImpl(serverBase, defaultPageCount, helperConfig.parameterConverter(), helperConfig.exceptionHandler(), helperConfig.responseGenerator(), daoConfig.historyDao(), historyUserFilterFactory()); }