diff --git a/boot/ipf-atna-spring-boot-starter/pom.xml b/boot/ipf-atna-spring-boot-starter/pom.xml index 4c9ad1af90..7409472888 100644 --- a/boot/ipf-atna-spring-boot-starter/pom.xml +++ b/boot/ipf-atna-spring-boot-starter/pom.xml @@ -57,6 +57,11 @@ spring-security-web true + + org.apache.httpcomponents.client5 + httpclient5 + true + @@ -64,13 +69,6 @@ spring-boot-test test - org.springframework spring-test diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStartEventListener.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStartEventListener.java index 2dd0956079..8c3fd83de8 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStartEventListener.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStartEventListener.java @@ -16,6 +16,7 @@ package org.openehealth.ipf.boot.atna; +import lombok.NonNull; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; import org.openehealth.ipf.commons.audit.event.ApplicationActivityBuilder; @@ -27,9 +28,6 @@ import static java.util.Objects.requireNonNull; -/** - * - */ public class ApplicationStartEventListener implements ApplicationListener { private final AuditContext auditContext; @@ -42,7 +40,7 @@ public ApplicationStartEventListener(AuditContext auditContext) { } @Override - public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { + public void onApplicationEvent(@NonNull ContextRefreshedEvent contextRefreshedEvent) { if (contextRefreshedEvent.getApplicationContext() == applicationContext) { auditContext.audit( new ApplicationActivityBuilder.ApplicationStart(EventOutcomeIndicator.Success) diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStopEventListener.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStopEventListener.java index f391b50ac4..d532f7a6cb 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStopEventListener.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/ApplicationStopEventListener.java @@ -16,6 +16,7 @@ package org.openehealth.ipf.boot.atna; +import lombok.NonNull; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; import org.openehealth.ipf.commons.audit.event.ApplicationActivityBuilder; @@ -27,9 +28,6 @@ import static java.util.Objects.requireNonNull; -/** - * - */ public class ApplicationStopEventListener implements ApplicationListener { private final AuditContext auditContext; @@ -42,7 +40,7 @@ public ApplicationStopEventListener(AuditContext auditContext) { } @Override - public void onApplicationEvent(ContextClosedEvent contextClosedEvent) { + public void onApplicationEvent(@NonNull ContextClosedEvent contextClosedEvent) { if (contextClosedEvent.getApplicationContext() == applicationContext) { auditContext.audit( new ApplicationActivityBuilder.ApplicationStop(EventOutcomeIndicator.Success) diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuditContextCustomizer.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuditContextCustomizer.java new file mode 100644 index 0000000000..9fc9a93509 --- /dev/null +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuditContextCustomizer.java @@ -0,0 +1,32 @@ +/* + * Copyright 2018 the original author or authors. + * + * 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. + */ + +package org.openehealth.ipf.boot.atna; + +import org.openehealth.ipf.commons.audit.AuditContext; + +/** + * Customizer that can be used to manipulate auto-configured {@link AuditContext} beans + * + * @author Christian Ohr + */ +public interface AuditContextCustomizer { + + void customizeAuditContext(AuditContext auditContext); + + AuditContextCustomizer NOOP = auditContext -> { + }; +} diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuthenticationListener.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuthenticationListener.java index 024a729fd9..0c969f1941 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuthenticationListener.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/AuthenticationListener.java @@ -16,6 +16,7 @@ package org.openehealth.ipf.boot.atna; +import lombok.NonNull; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; import org.openehealth.ipf.commons.audit.event.UserAuthenticationBuilder; @@ -42,7 +43,7 @@ public AuthenticationListener(AuditContext auditContext) { } @Override - public void onApplicationEvent(AbstractAuthenticationEvent authenticationEvent) { + public void onApplicationEvent(@NonNull AbstractAuthenticationEvent authenticationEvent) { delegateListener.onApplicationEvent(authenticationEvent); var outcome = authenticationEvent instanceof AbstractAuthenticationFailureEvent ? @@ -50,11 +51,9 @@ public void onApplicationEvent(AbstractAuthenticationEvent authenticationEvent) EventOutcomeIndicator.Success; var details = authenticationEvent.getAuthentication().getDetails(); - if (details instanceof WebAuthenticationDetails) { - var webAuthenticationDetails = (WebAuthenticationDetails) details; + if (details instanceof WebAuthenticationDetails webAuthenticationDetails) { var principal = authenticationEvent.getAuthentication().getPrincipal(); - if (principal instanceof UserDetails) { - var userDetails = (UserDetails) principal; + if (principal instanceof UserDetails userDetails) { var builder = new UserAuthenticationBuilder.Login(outcome) .setAuditSource(auditContext); diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfiguration.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfiguration.java index 042b67f3c9..b8a98f07a8 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfiguration.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfiguration.java @@ -35,9 +35,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; -/** - * - */ @Configuration @EnableConfigurationProperties(IpfAtnaConfigurationProperties.class) public class IpfAtnaAutoConfiguration { @@ -45,6 +42,7 @@ public class IpfAtnaAutoConfiguration { @Bean @ConditionalOnMissingBean public AuditContext auditContext(IpfAtnaConfigurationProperties config, + AuditContextCustomizer auditContextCustomizer, AuditTransmissionProtocol auditTransmissionProtocol, AuditMessageQueue auditMessageQueue, TlsParameters tlsParameters, @@ -54,29 +52,38 @@ public AuditContext auditContext(IpfAtnaConfigurationProperties config, WsAuditDatasetEnricher wsAuditDatasetEnricher, FhirAuditDatasetEnricher fhirAuditDatasetEnricher, @Value("${spring.application.name}") String appName) { + DefaultAuditContext auditContext; if (config.getBalp() != null) { - return balpConfiguration(defaultContextConfiguration(new DefaultBalpAuditContext(), config, - auditTransmissionProtocol, auditMessageQueue, tlsParameters, auditMetadataProvider, - auditExceptionHandler, auditMessagePostProcessor, wsAuditDatasetEnricher, - fhirAuditDatasetEnricher, appName), config); + auditContext = new DefaultBalpAuditContext(); + configureBalpAuditContext((DefaultBalpAuditContext) auditContext, config); } else { - return defaultContextConfiguration(new DefaultAuditContext(), config, auditTransmissionProtocol, - auditMessageQueue, tlsParameters, auditMetadataProvider, auditExceptionHandler, - auditMessagePostProcessor, wsAuditDatasetEnricher, fhirAuditDatasetEnricher, appName); + auditContext = new DefaultAuditContext(); } + configureDefaultAuditContext(auditContext, config, auditTransmissionProtocol, + auditMessageQueue, tlsParameters, auditMetadataProvider, auditExceptionHandler, + auditMessagePostProcessor, wsAuditDatasetEnricher, fhirAuditDatasetEnricher, appName); + auditContextCustomizer.customizeAuditContext(auditContext); + return auditContext; } - private T defaultContextConfiguration(T auditContext, - IpfAtnaConfigurationProperties config, - AuditTransmissionProtocol auditTransmissionProtocol, - AuditMessageQueue auditMessageQueue, - TlsParameters tlsParameters, - AuditMetadataProvider auditMetadataProvider, - AuditExceptionHandler auditExceptionHandler, - AuditMessagePostProcessor auditMessagePostProcessor, - WsAuditDatasetEnricher wsAuditDatasetEnricher, - FhirAuditDatasetEnricher fhirAuditDatasetEnricher, - @Value("${spring.application.name}") String appName) { + @Bean + @ConditionalOnMissingBean(AuditContextCustomizer.class) + public AuditContextCustomizer auditContextCustomizer() { + return AuditContextCustomizer.NOOP; + } + + + private void configureDefaultAuditContext(DefaultAuditContext auditContext, + IpfAtnaConfigurationProperties config, + AuditTransmissionProtocol auditTransmissionProtocol, + AuditMessageQueue auditMessageQueue, + TlsParameters tlsParameters, + AuditMetadataProvider auditMetadataProvider, + AuditExceptionHandler auditExceptionHandler, + AuditMessagePostProcessor auditMessagePostProcessor, + WsAuditDatasetEnricher wsAuditDatasetEnricher, + FhirAuditDatasetEnricher fhirAuditDatasetEnricher, + @Value("${spring.application.name}") String appName) { auditContext.setAuditEnabled(config.isAuditEnabled()); @@ -103,65 +110,63 @@ private T defaultContextConfiguration(T auditCon if (fhirAuditDatasetEnricher != FhirAuditDatasetEnricher.NONE) { auditContext.setFhirAuditDatasetEnricher(fhirAuditDatasetEnricher); } - - return auditContext; } - private DefaultBalpAuditContext balpConfiguration(DefaultBalpAuditContext auditContext, IpfAtnaConfigurationProperties config) { - if (config.getBalp() != null) { - auditContext.setAuditRepositoryContextPath(config.getBalp().getAuditRepositoryContextPath()); + private void configureBalpAuditContext(DefaultBalpAuditContext auditContext, IpfAtnaConfigurationProperties config) { + auditContext.setAuditRepositoryContextPath(config.getBalp().getAuditRepositoryContextPath()); - if (isNotBlank(config.getBalp().getAuditEventSerializationType())) { - auditContext.setSerializationStrategy( - config.getBalp().getAuditEventSerializationType().equalsIgnoreCase("json") ? - new BalpJsonSerializationStrategy() : new BalpXmlSerializationStrategy()); + if (isNotBlank(config.getBalp().getAuditEventSerializationType())) { + auditContext.setSerializationStrategy( + config.getBalp().getAuditEventSerializationType().equalsIgnoreCase("json") ? + new BalpJsonSerializationStrategy() : new BalpXmlSerializationStrategy()); + } + var oAuth = config.getBalp().getOauth(); + var props = auditContext.getBalpJwtExtractorProperties(); + + if (oAuth != null) { + if (oAuth.getIdPath() != null) { + props.setIdPath(oAuth.getIdPath()); + } + if (oAuth.getClientIdPath() != null) { + props.setClientIdPath(oAuth.getClientIdPath()); } - if (config.getBalp().getOauth() != null) { - if (config.getBalp().getOauth().getIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setIdPath(config.getBalp().getOauth().getIdPath()); - } - if (config.getBalp().getOauth().getClientIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setClientIdPath(config.getBalp().getOauth().getClientIdPath()); - } - if (config.getBalp().getOauth().getIssuerPath() != null) { - auditContext.getBalpJwtExtractorProperties().setIssuerPath(config.getBalp().getOauth().getIssuerPath()); - } - if (config.getBalp().getOauth().getSubjectPath() != null) { - auditContext.getBalpJwtExtractorProperties().setSubjectPath(config.getBalp().getOauth().getSubjectPath()); - } - if (config.getBalp().getOauth().getSubjectNamePath() != null) { - auditContext.getBalpJwtExtractorProperties().setSubjectNamePath(config.getBalp().getOauth().getSubjectNamePath()); - } - if (config.getBalp().getOauth().getSubjectRolePath() != null) { - auditContext.getBalpJwtExtractorProperties().setSubjectRolePath(config.getBalp().getOauth().getSubjectRolePath()); - } - if (config.getBalp().getOauth().getSubjectOrganizationIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setSubjectOrganizationIdPath(config.getBalp().getOauth().getSubjectOrganizationIdPath()); - } - if (config.getBalp().getOauth().getPurposeOfUsePath() != null) { - auditContext.getBalpJwtExtractorProperties().setPurposeOfUsePath(config.getBalp().getOauth().getPurposeOfUsePath()); - } - if (config.getBalp().getOauth().getHomeCommunityIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setHomeCommunityIdPath(config.getBalp().getOauth().getHomeCommunityIdPath()); - } - if (config.getBalp().getOauth().getNationalProviderIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setNationalProviderIdPath(config.getBalp().getOauth().getNationalProviderIdPath()); - } - if (config.getBalp().getOauth().getDocIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setDocIdPath(config.getBalp().getOauth().getDocIdPath()); - } - if (config.getBalp().getOauth().getPatientIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setPatientIdPath(config.getBalp().getOauth().getPatientIdPath()); - } - if (config.getBalp().getOauth().getPersonIdPath() != null) { - auditContext.getBalpJwtExtractorProperties().setPersonIdPath(config.getBalp().getOauth().getPersonIdPath()); - } - if (config.getBalp().getOauth().getAcpPath() != null) { - auditContext.getBalpJwtExtractorProperties().setAcpPath(config.getBalp().getOauth().getAcpPath()); - } + if (oAuth.getIssuerPath() != null) { + props.setIssuerPath(oAuth.getIssuerPath()); + } + if (oAuth.getSubjectPath() != null) { + props.setSubjectPath(oAuth.getSubjectPath()); + } + if (oAuth.getSubjectNamePath() != null) { + props.setSubjectNamePath(oAuth.getSubjectNamePath()); + } + if (oAuth.getSubjectRolePath() != null) { + props.setSubjectRolePath(oAuth.getSubjectRolePath()); + } + if (oAuth.getSubjectOrganizationIdPath() != null) { + props.setSubjectOrganizationIdPath(oAuth.getSubjectOrganizationIdPath()); + } + if (oAuth.getPurposeOfUsePath() != null) { + props.setPurposeOfUsePath(oAuth.getPurposeOfUsePath()); + } + if (oAuth.getHomeCommunityIdPath() != null) { + props.setHomeCommunityIdPath(oAuth.getHomeCommunityIdPath()); + } + if (oAuth.getNationalProviderIdPath() != null) { + props.setNationalProviderIdPath(oAuth.getNationalProviderIdPath()); + } + if (oAuth.getDocIdPath() != null) { + props.setDocIdPath(oAuth.getDocIdPath()); + } + if (oAuth.getPatientIdPath() != null) { + props.setPatientIdPath(oAuth.getPatientIdPath()); + } + if (oAuth.getPersonIdPath() != null) { + props.setPersonIdPath(oAuth.getPersonIdPath()); + } + if (oAuth.getAcpPath() != null) { + props.setAcpPath(oAuth.getAcpPath()); } } - return auditContext; } // The following beans configure aud strategies (formats, queues, exception handlers) and diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaConfigurationProperties.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaConfigurationProperties.java index 0269edc80f..091500d3af 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaConfigurationProperties.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaConfigurationProperties.java @@ -30,9 +30,6 @@ import org.openehealth.ipf.commons.audit.types.AuditSource; import org.springframework.boot.context.properties.ConfigurationProperties; -/** - * - */ @ConfigurationProperties(prefix = "ipf.atna") public class IpfAtnaConfigurationProperties { diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaSpringSecurityAutoConfiguration.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaSpringSecurityAutoConfiguration.java index 6e9c0bbfd2..87f36c3043 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaSpringSecurityAutoConfiguration.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/IpfAtnaSpringSecurityAutoConfiguration.java @@ -26,9 +26,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.event.AbstractAuthenticationEvent; -/** - * - */ @ConditionalOnClass({AbstractAuthenticationEvent.class}) @Configuration @EnableConfigurationProperties(IpfAtnaConfigurationProperties.class) diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestClientAuditMessageQueue.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestClientAuditMessageQueue.java new file mode 100644 index 0000000000..c399372c23 --- /dev/null +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestClientAuditMessageQueue.java @@ -0,0 +1,114 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.boot.atna; + +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.queue.AbstractAuditMessageQueue; +import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClientException; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.http.HttpHeaders.encodeBasicAuth; + +/** + * Alternative to {@link org.openehealth.ipf.commons.audit.queue.BasicHttpAuditMessageQueue}, + * using Spring's RestClient / RestClient.Builder classes + */ +public class RestClientAuditMessageQueue extends AbstractAuditMessageQueue { + + private final RestClient.Builder restClientBuilder; + private final URI uri; + private long connectTimeout = -1; + private long readTimeout = -1; + + private RestClient restClient; + + public RestClientAuditMessageQueue(RestClient.Builder restClientBuilder, URI uri) { + this(restClientBuilder, uri, null, null); + } + + /** + * @param uri URL + * @param user user name, maybe null + * @param password password, maybe null + */ + public RestClientAuditMessageQueue(RestClient.Builder restClientBuilder, URI uri, String user, String password) { + var builder = restClientBuilder + .defaultHeader(CONTENT_TYPE, MediaType.TEXT_XML.toString()); + if (user != null && !user.isEmpty() && password != null && !password.isEmpty()) { + builder = builder.defaultHeader( + HttpHeaders.AUTHORIZATION, + encodeBasicAuth(user, password, null)); + } + this.uri = uri; + this.restClientBuilder = customize(builder); + initRestClient(); + } + + protected RestClient.Builder customize(RestClient.Builder builder) { + return builder; + } + + @Override + protected void handle(AuditContext auditContext, String auditRecord) { + try { + var response = restClient.post() + .uri(uri) + .headers(httpHeaders -> { + httpHeaders.add(X_IPF_ATNA_TIMESTAMP, auditContext.getAuditMetadataProvider().getTimestamp()); + httpHeaders.add(X_IPF_ATNA_HOSTNAME, auditContext.getAuditMetadataProvider().getHostname()); + httpHeaders.add(X_IPF_ATNA_PROCESSID, auditContext.getAuditMetadataProvider().getProcessID()); + httpHeaders.add(X_IPF_ATNA_APPLICATION, auditContext.getAuditMetadataProvider().getSendingApplication()); + }) + .body(auditRecord) + .retrieve() + .toBodilessEntity(); + } catch (RestClientException e) { + auditContext.getAuditExceptionHandler().handleException(auditContext, e, auditRecord); + } + } + + public void setConnectTimeout(long connectTimeoutMillis) { + this.connectTimeout = connectTimeoutMillis; + initRestClient(); + } + + public void setReadTimeout(long readTimeoutMillis) { + this.readTimeout = readTimeoutMillis; + initRestClient(); + } + + private synchronized void initRestClient() { + this.restClient = this.restClientBuilder + .requestFactory(ClientHttpRequestFactoryBuilder.httpComponents() + .withDefaultRequestConfigCustomizer(rcc -> { + if (connectTimeout > 0) { + rcc.setConnectionRequestTimeout(connectTimeout, TimeUnit.MILLISECONDS); + } + if (readTimeout > 0) { + rcc.setResponseTimeout(readTimeout, TimeUnit.MILLISECONDS); + } + }) + .build()) + .build(); + } +} diff --git a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueue.java b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueue.java index 65c4321729..36daa72d27 100644 --- a/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueue.java +++ b/boot/ipf-atna-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueue.java @@ -25,7 +25,6 @@ import org.springframework.web.client.RestOperations; import java.net.URI; -import java.nio.charset.StandardCharsets; import java.time.Duration; import static java.util.Objects.requireNonNull; @@ -62,19 +61,19 @@ public RestTemplateAuditMessageQueue(RestTemplateBuilder restTemplateBuilder, UR this.restTemplateBuilder = restTemplateBuilder .defaultHeader( CONTENT_TYPE, - new MediaType("text", "xml", StandardCharsets.UTF_8).toString()); + MediaType.TEXT_XML.toString()); initRestTemplate(); } @Override protected void handle(AuditContext auditContext, String auditRecord) { try { - HttpHeaders httpHeaders = new HttpHeaders(); + var httpHeaders = new HttpHeaders(); httpHeaders.add(X_IPF_ATNA_TIMESTAMP, auditContext.getAuditMetadataProvider().getTimestamp()); httpHeaders.add(X_IPF_ATNA_HOSTNAME, auditContext.getAuditMetadataProvider().getHostname()); httpHeaders.add(X_IPF_ATNA_PROCESSID, auditContext.getAuditMetadataProvider().getProcessID()); httpHeaders.add(X_IPF_ATNA_APPLICATION, auditContext.getAuditMetadataProvider().getSendingApplication()); - HttpEntity entity = new HttpEntity<>(auditRecord, httpHeaders); + var entity = new HttpEntity<>(auditRecord, httpHeaders); restTemplate.postForEntity(uri, entity, Void.class); } catch (RestClientException e) { auditContext.getAuditExceptionHandler().handleException(auditContext, e, auditRecord); @@ -94,10 +93,10 @@ public void setReadTimeout(long readTimeoutMillis) { private synchronized void initRestTemplate() { var builder = this.restTemplateBuilder; if (connectTimeout >= 0) { - builder = builder.setConnectTimeout(Duration.ofMillis(connectTimeout)); + builder = builder.connectTimeout(Duration.ofMillis(connectTimeout)); } if (readTimeout >= 0) { - builder = builder.setReadTimeout(Duration.ofMillis(readTimeout)); + builder = builder.readTimeout(Duration.ofMillis(readTimeout)); } if (user != null && !user.isEmpty() && password != null && !password.isEmpty()) { builder = builder.basicAuthentication(user, password); diff --git a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfigurationTest.java b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfigurationTest.java index 565cac25f8..bd2f0c0fd5 100644 --- a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfigurationTest.java +++ b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaAutoConfigurationTest.java @@ -24,8 +24,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** @@ -39,13 +38,13 @@ public class IpfAtnaAutoConfigurationTest { private AuditContext auditContext; @Test - public void testAtnaSettings() throws Exception { + public void testAtnaSettings() { assertEquals("atna-test", auditContext.getAuditSourceId()); assertEquals("mysite", auditContext.getAuditEnterpriseSiteId()); assertEquals("localhost", auditContext.getAuditRepositoryHostName()); assertEquals(1342, auditContext.getAuditRepositoryPort()); assertEquals("TLS", auditContext.getAuditTransmissionProtocol().getTransportName()); - assertTrue(auditContext.getAuditMessageQueue() instanceof AsynchronousAuditMessageQueue); + assertInstanceOf(AsynchronousAuditMessageQueue.class, auditContext.getAuditMessageQueue()); } } diff --git a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaBalpAutoConfigurationTest.java b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaBalpAutoConfigurationTest.java index 3dd1f9d999..482ba95573 100644 --- a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaBalpAutoConfigurationTest.java +++ b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/IpfAtnaBalpAutoConfigurationTest.java @@ -16,7 +16,6 @@ package org.openehealth.ipf.boot.atna; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openehealth.ipf.commons.audit.AuditContext; @@ -27,9 +26,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** @@ -44,15 +41,15 @@ public class IpfAtnaBalpAutoConfigurationTest { private AuditContext auditContext; @Test - public void testAtnaWithBalpSettings() throws Exception { - assertTrue(auditContext instanceof BalpAuditContext); + public void testAtnaWithBalpSettings() { + assertInstanceOf(BalpAuditContext.class, auditContext); assertEquals("atna-test", auditContext.getAuditSourceId()); assertEquals("mysite", auditContext.getAuditEnterpriseSiteId()); assertEquals("localhost", auditContext.getAuditRepositoryHostName()); assertEquals(1342, auditContext.getAuditRepositoryPort()); assertEquals("FHIR-REST-TLS", auditContext.getAuditTransmissionProtocol().getTransportName()); - assertTrue(auditContext.getAuditMessageQueue() instanceof AsynchronousAuditMessageQueue); + assertInstanceOf(AsynchronousAuditMessageQueue.class, auditContext.getAuditMessageQueue()); assertEquals("fhir", ((BalpAuditContext)auditContext).getAuditRepositoryContextPath()); assertArrayEquals(new String[]{"cid","client-id","my-client-id-path"}, diff --git a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestClientAuditMessageQueueTest.java b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestClientAuditMessageQueueTest.java new file mode 100644 index 0000000000..c9d11df2d1 --- /dev/null +++ b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestClientAuditMessageQueueTest.java @@ -0,0 +1,145 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.boot.atna; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockserver.client.MockServerClient; +import org.mockserver.integration.ClientAndServer; +import org.openehealth.ipf.commons.audit.DefaultAuditContext; +import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; +import org.openehealth.ipf.commons.audit.event.ApplicationActivityBuilder; +import org.openehealth.ipf.commons.audit.protocol.RecordingAuditMessageTransmission; +import org.openehealth.ipf.commons.audit.utils.AuditUtils; +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClientException; + +import java.net.ServerSocket; +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockserver.integration.ClientAndServer.startClientAndServer; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +public class RestClientAuditMessageQueueTest { + + private int port; + private ClientAndServer mockServer; + private RestClientAuditMessageQueue atnaQueue; + private DefaultAuditContext auditContext; + private Throwable caught; + + @BeforeEach + public void setup() { + port = freePort(); + mockServer = startClientAndServer(port); + auditContext = new DefaultAuditContext(); + auditContext.setAuditTransmissionProtocol(new RecordingAuditMessageTransmission()); + auditContext.setAuditExceptionHandler((auditContext, t, auditMessages) -> + caught = t); + auditContext.setAuditEnabled(true); + } + + @AfterEach + public void tearDown() { + caught = null; + if (mockServer != null) mockServer.stop(); + } + + @Test + public void testSuccessfulAudit() { + try (var server = new MockServerClient("127.0.0.1", port)) { + server + .when( + request() + .withMethod("POST") + .withPath("/audit")) + .respond( + response() + .withStatusCode(200) + .withDelay(TimeUnit.MILLISECONDS, 10) + ); + + // Setup producer + atnaQueue = new RestClientAuditMessageQueue( + RestClient.builder(), + URI.create("http://localhost:" + port + "/audit")); + auditContext.setAuditMessageQueue(atnaQueue); + sendAudit(); + } + } + + @Test + public void testUnsuccessfulAudit() { + try (var server = new MockServerClient("127.0.0.1", port)) { + server + .when( + request() + .withMethod("POST") + .withPath("/audit")) + .respond( + response() + .withStatusCode(404) + .withDelay(TimeUnit.MILLISECONDS, 10) + ); + + // Setup producer + atnaQueue = new RestClientAuditMessageQueue( + RestClient.builder(), + URI.create("http://localhost:" + port + "/audit")); + auditContext.setAuditMessageQueue(atnaQueue); + sendAudit(); + assertThat(caught, instanceOf(RestClientException.class)); + } + } + + @Test + public void testAuditSomewhere() { + atnaQueue = new RestClientAuditMessageQueue( + RestClient.builder(), + URI.create("http://localhost:" + freePort() + "/audit")); + atnaQueue.setConnectTimeout(500); + auditContext.setAuditMessageQueue(atnaQueue); + sendAudit(); + assertThat(caught, instanceOf(RestClientException.class)); + } + + private void sendAudit() { + auditContext.audit( + new ApplicationActivityBuilder.ApplicationStart(EventOutcomeIndicator.Success) + .setAuditSource(auditContext) + .setApplicationParticipant( + "appName", + null, + null, + AuditUtils.getLocalHostName()) + .addApplicationStarterParticipant(System.getProperty("user.name")) + .getMessages()); + } + + private static int freePort() { + try (var serverSocket = new ServerSocket(0)) { + return serverSocket.getLocalPort(); + } catch (Exception e) { + return -1; + } + } + +} diff --git a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueueTest.java b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueueTest.java index e7aa14fecd..4f587b55d9 100644 --- a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueueTest.java +++ b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/RestTemplateAuditMessageQueueTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023 the original author or authors. + * + * 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. + */ package org.openehealth.ipf.boot.atna; import org.junit.jupiter.api.AfterEach; @@ -25,21 +40,20 @@ public class RestTemplateAuditMessageQueueTest { - private int port; private ClientAndServer mockServer; private RestTemplateAuditMessageQueue atnaQueue; private DefaultAuditContext auditContext; private Throwable caught; - @BeforeEach public void setup() { port = freePort(); mockServer = startClientAndServer(port); auditContext = new DefaultAuditContext(); auditContext.setAuditTransmissionProtocol(new RecordingAuditMessageTransmission()); - auditContext.setAuditExceptionHandler((auditContext, t, auditMessages) -> caught = t); + auditContext.setAuditExceptionHandler((auditContext, t, auditMessages) -> + caught = t); auditContext.setAuditEnabled(true); } @@ -64,7 +78,9 @@ public void testSuccessfulAudit() { ); // Setup producer - atnaQueue = new RestTemplateAuditMessageQueue(new RestTemplateBuilder(), URI.create("http://localhost:" + port + "/audit")); + atnaQueue = new RestTemplateAuditMessageQueue( + new RestTemplateBuilder(), + URI.create("http://localhost:" + port + "/audit")); auditContext.setAuditMessageQueue(atnaQueue); sendAudit(); } @@ -85,7 +101,9 @@ public void testUnsuccessfulAudit() { ); // Setup producer - atnaQueue = new RestTemplateAuditMessageQueue(new RestTemplateBuilder(), URI.create("http://localhost:" + port + "/audit")); + atnaQueue = new RestTemplateAuditMessageQueue( + new RestTemplateBuilder(), + URI.create("http://localhost:" + port + "/audit")); auditContext.setAuditMessageQueue(atnaQueue); sendAudit(); assertThat(caught, instanceOf(RestClientException.class)); diff --git a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/TestApplication.java b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/TestApplication.java index 8107dd6c26..90f6b2e9a5 100644 --- a/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/TestApplication.java +++ b/boot/ipf-atna-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/atna/TestApplication.java @@ -25,7 +25,7 @@ @SpringBootApplication public class TestApplication { - public static void main(String[] args) throws Exception { + public static void main(String[] args) { SpringApplication.run(TestApplication.class, args); } diff --git a/boot/ipf-fhir-r4-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/fhir/IpfFhirAutoConfiguration.java b/boot/ipf-fhir-r4-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/fhir/IpfFhirAutoConfiguration.java index 13f6054596..e1c7bf4934 100644 --- a/boot/ipf-fhir-r4-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/fhir/IpfFhirAutoConfiguration.java +++ b/boot/ipf-fhir-r4-spring-boot-starter/src/main/java/org/openehealth/ipf/boot/fhir/IpfFhirAutoConfiguration.java @@ -19,11 +19,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.narrative.INarrativeGenerator; import ca.uhn.fhir.narrative2.NullNarrativeGenerator; -import ca.uhn.fhir.rest.server.ApacheProxyAddressStrategy; -import ca.uhn.fhir.rest.server.IPagingProvider; -import ca.uhn.fhir.rest.server.IServerAddressStrategy; -import ca.uhn.fhir.rest.server.IServerConformanceProvider; -import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.rest.server.*; +import jakarta.servlet.Filter; import org.hl7.fhir.instance.model.api.IBaseConformance; import org.openehealth.ipf.boot.atna.IpfAtnaAutoConfiguration; import org.openehealth.ipf.commons.ihe.fhir.IpfFhirServlet; @@ -44,7 +41,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.filter.CorsFilter; -import jakarta.servlet.Filter; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; @@ -152,6 +148,16 @@ public IpfFhirServlet fhirServlet( if (narrativeGenerator != null) { fhirServlet.setNarrativeGenerator(narrativeGenerator); } + // Register server interceptor for ITI-119 if on classpath + try { + var clazz = Class.forName("org.openehealth.ipf.commons.ihe.fhir.iti119.MatchGradeEnumInterceptor"); + fhirServlet.registerInterceptor(clazz.getConstructor().newInstance()); + } catch (ClassNotFoundException e) { + // ok + } catch (Exception e) { + // should never happen + throw new RuntimeException(e); + } return fhirServlet; } diff --git a/boot/ipf-fhir-r4-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/fhir/FhirApplicationTest.java b/boot/ipf-fhir-r4-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/fhir/FhirApplicationTest.java index 135b366347..b440556c4a 100644 --- a/boot/ipf-fhir-r4-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/fhir/FhirApplicationTest.java +++ b/boot/ipf-fhir-r4-spring-boot-starter/src/test/java/org/openehealth/ipf/boot/fhir/FhirApplicationTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.openehealth.ipf.boot.IpfAutoConfiguration; import org.openehealth.ipf.commons.core.config.ContextFacade; import org.openehealth.ipf.commons.map.MappingService; import org.openehealth.ipf.commons.spring.map.config.CustomMappings; diff --git a/commons/audit/pom.xml b/commons/audit/pom.xml index b5da03d076..99e3f917c2 100644 --- a/commons/audit/pom.xml +++ b/commons/audit/pom.xml @@ -16,6 +16,10 @@ org.jdom jdom2 + + io.micrometer + context-propagation + io.netty netty-handler @@ -36,11 +40,6 @@ jakarta.jms-api true - - ca.uhn.hapi.fhir - hapi-fhir-base - true - diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/AuditContext.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/AuditContext.java index 909d879992..b43816fc8d 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/AuditContext.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/AuditContext.java @@ -16,6 +16,7 @@ package org.openehealth.ipf.commons.audit; +import io.micrometer.context.ContextRegistry; import org.openehealth.ipf.commons.audit.handler.AuditExceptionHandler; import org.openehealth.ipf.commons.audit.marshal.SerializationStrategy; import org.openehealth.ipf.commons.audit.marshal.dicom.Current; @@ -25,6 +26,7 @@ import org.openehealth.ipf.commons.audit.types.AuditSource; import java.net.InetAddress; +import java.util.List; import java.util.stream.Stream; /** @@ -120,6 +122,10 @@ default void audit(AuditMessage... messages) { } } + /** + * Returns audit metadata e.g. for populating the RFC 5424 header + * @return audit metadata + */ default AuditMetadataProvider getAuditMetadataProvider() { return AuditMetadataProvider.getDefault(); } @@ -169,6 +175,14 @@ default String getAuditValueIfMissing() { */ boolean isIncludeParticipantsFromResponse(); + /** + * Returns a registry of {@link io.micrometer.context.ThreadLocalAccessor} instances that are used to propagate context + * when asynchronously queuing audit records. + * + * @return context registry + */ + ContextRegistry getContextRegistry(); + static AuditContext noAudit() { return DefaultAuditContext.NO_AUDIT; } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/BalpAuditContext.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/BalpAuditContext.java index ba2ac1307c..9a0e99f04e 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/BalpAuditContext.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/BalpAuditContext.java @@ -16,6 +16,8 @@ package org.openehealth.ipf.commons.audit; /** + * Extended AuditContext interface with properties required for IHE BALP. + * * @author Boris Stanojevic * @since 4.8 */ diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/CustomTlsParameters.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/CustomTlsParameters.java index afb9081eb1..ab90fcee97 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/CustomTlsParameters.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/CustomTlsParameters.java @@ -222,8 +222,8 @@ public SSLContext getSSLContext(boolean serverSide) { if (keyManagers != null && certAlias != null) { for (var i = 0; i < keyManagers.length; i++) { - if (keyManagers[i] instanceof X509KeyManager) { - keyManagers[i] = new AliasX509ExtendedKeyManager((X509KeyManager) keyManagers[i], certAlias); + if (keyManagers[i] instanceof X509KeyManager x509KeyManager) { + keyManagers[i] = new AliasX509ExtendedKeyManager(x509KeyManager, certAlias); } } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultAuditContext.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultAuditContext.java index ef81129bec..34c6f21575 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultAuditContext.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultAuditContext.java @@ -16,6 +16,8 @@ package org.openehealth.ipf.commons.audit; +import io.micrometer.context.ContextRegistry; +import io.micrometer.context.integration.Slf4jThreadLocalAccessor; import lombok.Getter; import lombok.Setter; import org.openehealth.ipf.commons.audit.codes.AuditSourceType; @@ -34,6 +36,12 @@ import java.net.UnknownHostException; /** + * Default implementation of an AuditContext. By default, audit is written to localhost:514 via UDP. + *

+ * The {@link ContextRegistry} returned by {@link #getContextRegistry()} will always contain an instance + * of {@link Slf4jThreadLocalAccessor} in order to propagate MDC context to an + * potentially asynchronous auditor. + * * @author Christian Ohr * @since 3.5 */ @@ -107,6 +115,10 @@ public class DefaultAuditContext implements AuditContext { @Setter private FhirAuditDatasetEnricher fhirAuditDatasetEnricher; + @Getter + private final ContextRegistry contextRegistry = new ContextRegistry() + .registerThreadLocalAccessor(new Slf4jThreadLocalAccessor()); + public String getAuditRepositoryTransport() { return auditTransmissionProtocol.getTransportName(); } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultBalpAuditContext.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultBalpAuditContext.java index 52275131bc..25fd54ac52 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultBalpAuditContext.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/DefaultBalpAuditContext.java @@ -18,6 +18,9 @@ import lombok.Getter; import lombok.Setter; +/** + * Default implementation of a {@link BalpAuditContext}. + */ public class DefaultBalpAuditContext extends DefaultAuditContext implements BalpAuditContext { @Getter diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/handler/LoggingAuditExceptionHandler.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/handler/LoggingAuditExceptionHandler.java index 88d22f8421..20d7861898 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/handler/LoggingAuditExceptionHandler.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/handler/LoggingAuditExceptionHandler.java @@ -28,11 +28,11 @@ */ public class LoggingAuditExceptionHandler implements AuditExceptionHandler { - private static final Logger LOG = LoggerFactory.getLogger(LoggingAuditExceptionHandler.class); + private static final Logger log = LoggerFactory.getLogger(LoggingAuditExceptionHandler.class); @Override public void handleException(AuditContext auditContext, Throwable throwable, String auditMessage) { - LOG.warn("Failed to send ATNA audit event to destination {}:{} ({})", + log.warn("Failed to send ATNA audit event to destination {}:{} ({})", auditContext.getAuditRepositoryHostName(), auditContext.getAuditRepositoryPort(), auditContext.getAuditRepositoryAddress().getHostAddress(), diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/marshal/dicom/DICOM2016a.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/marshal/dicom/DICOM2016a.java index 157eca5a24..00cba27136 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/marshal/dicom/DICOM2016a.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/marshal/dicom/DICOM2016a.java @@ -96,9 +96,7 @@ protected Element eventIdentification(EventIdentificationType eventIdentificatio element.setAttribute(EVENT_ACTION_CODE, eventIdentification.getEventActionCode().getValue()); element.setAttribute(EVENT_DATE_TIME, eventIdentification.getEventDateTime().toString()); element.setAttribute(EVENT_OUTCOME_INDICATOR, eventIdentification.getEventOutcomeIndicator().getValue().toString()); - if (eventIdentification.getEventID() != null) { - element.addContent(codedValueType(EVENT_ID, eventIdentification.getEventID())); - } + element.addContent(codedValueType(EVENT_ID, eventIdentification.getEventID())); eventIdentification.getEventTypeCode().stream() .map(eventTypeCode -> codedValueType(EVENT_TYPE_CODE, eventTypeCode)) .forEach(element::addContent); diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/model/Validateable.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/model/Validateable.java index 0c020364b9..8004fdb4db 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/model/Validateable.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/model/Validateable.java @@ -26,7 +26,6 @@ public interface Validateable { * Validates the constructed audit message against the specification, because API does not completely * prevent constructing incomplete or inconsistent messages. * - * @throws org.openehealth.ipf.commons.audit.AuditException */ void validate(); diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/AuditTransmissionChannel.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/AuditTransmissionChannel.java index 1d22b2a813..33e7b613ce 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/AuditTransmissionChannel.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/AuditTransmissionChannel.java @@ -61,8 +61,8 @@ public String getProtocolName() { } public AuditTransmissionProtocol makeInstance(TlsParameters tlsParameters) { - ServiceLoader loader = ServiceLoader.load(AuditTransmissionProtocolProvider.class); - for (AuditTransmissionProtocolProvider provider : loader) { + var loader = ServiceLoader.load(AuditTransmissionProtocolProvider.class); + for (var provider : loader) { if (protocolClass.equals(provider.getClass().getName())) { return provider.createAuditTransmissionProtocol(tlsParameters); } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NettyTLSSyslogSenderImpl.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NettyTLSSyslogSenderImpl.java index 3064d761a9..9120fd4a95 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NettyTLSSyslogSenderImpl.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NettyTLSSyslogSenderImpl.java @@ -49,7 +49,7 @@ */ public class NettyTLSSyslogSenderImpl extends NioTLSSyslogSenderImpl { - private static final Logger LOG = LoggerFactory.getLogger(NettyTLSSyslogSenderImpl.class); + private static final Logger log = LoggerFactory.getLogger(NettyTLSSyslogSenderImpl.class); private int workerThreads = 1; private long connectTimeoutMillis = 5000; @@ -137,7 +137,7 @@ public Bootstrap getBootstrap() { @Override public void shutdown() { if (workerGroup != null) { - LOG.info("TLS Channel to Audit Repository at {}:{} is closed", host, port); + log.info("TLS Channel to Audit Repository at {}:{} is closed", host, port); workerGroup.shutdownGracefully(); } } @@ -161,7 +161,7 @@ public ChannelFuture getHandle() { public void write(byte[] bytes) { // The write operation is asynchronous. var channel = getHandle().channel(); - LOG.trace("Writing {} bytes using session: {}", bytes.length, channel); + log.trace("Writing {} bytes using session: {}", bytes.length, channel); try { if (!channel.writeAndFlush(Unpooled.wrappedBuffer(bytes)).await(sendTimeout)) { throw new AuditException("Could not send audit message to " + host + ":" + port); @@ -186,13 +186,13 @@ public InboundHandler(String host, int port) { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - LOG.info("TLS Channel to Audit Repository at {}:{} is now active", host, port); + log.info("TLS Channel to Audit Repository at {}:{} is now active", host, port); super.channelActive(ctx); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - LOG.info("Exception on receiving message for context {}", ctx, cause); + log.info("Exception on receiving message for context {}", ctx, cause); if (ctx != null) { ctx.close(); } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NioTLSSyslogSenderImpl.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NioTLSSyslogSenderImpl.java index 7fd465662c..e5e9e1798f 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NioTLSSyslogSenderImpl.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/NioTLSSyslogSenderImpl.java @@ -35,7 +35,7 @@ */ public abstract class NioTLSSyslogSenderImpl> extends RFC5425Protocol implements AuditTransmissionProtocol { - private static final Logger LOG = LoggerFactory.getLogger(NioTLSSyslogSenderImpl.class); + private static final Logger log = LoggerFactory.getLogger(NioTLSSyslogSenderImpl.class); private boolean loggingEnabled = false; private final TlsParameters tlsParameters; @@ -63,15 +63,15 @@ public void send(AuditContext auditContext, AuditMetadataProvider auditMetadataP if (auditMessage != null) { Destination destination = getDestination(auditContext.getAuditRepositoryHostName(), auditContext.getAuditRepositoryPort()); var payload = getTransportPayload(auditMetadataProvider, auditMessage); - if (LOG.isDebugEnabled()) { - LOG.debug("Auditing {} bytes to {}:{}", + if (log.isDebugEnabled()) { + log.debug("Auditing {} bytes to {}:{}", payload.length, auditContext.getAuditRepositoryHostName(), auditContext.getAuditRepositoryPort()); } destination.write(payload); - if (LOG.isTraceEnabled()) { - LOG.trace(new String(payload, StandardCharsets.UTF_8)); + if (log.isTraceEnabled()) { + log.trace(new String(payload, StandardCharsets.UTF_8)); } } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/ReactorNettyTLSSyslogSenderImpl.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/ReactorNettyTLSSyslogSenderImpl.java index 5a0ef90957..40463618b2 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/ReactorNettyTLSSyslogSenderImpl.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/ReactorNettyTLSSyslogSenderImpl.java @@ -25,9 +25,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.netty.Connection; +import reactor.netty.internal.util.Metrics; import reactor.netty.resources.LoopResources; import reactor.netty.tcp.TcpClient; -import reactor.util.Metrics; import java.time.Duration; import java.util.concurrent.TimeUnit; @@ -42,7 +42,7 @@ */ public class ReactorNettyTLSSyslogSenderImpl extends NioTLSSyslogSenderImpl { - private static final Logger LOG = LoggerFactory.getLogger(ReactorNettyTLSSyslogSenderImpl.class); + private static final Logger log = LoggerFactory.getLogger(ReactorNettyTLSSyslogSenderImpl.class); private int workerThreads = 1; private long connectTimeoutMillis = 5000; @@ -119,11 +119,11 @@ public static final class ReactorNettyDestination implements NioTLSSyslogSenderI .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) connectTimeout) .option(ChannelOption.SO_KEEPALIVE, true) .wiretap(getClass().getName(), LogLevel.TRACE) - .metrics(Metrics.isInstrumentationAvailable()) + .metrics(Metrics.isMicrometerAvailable()) .secure(spec -> spec.sslContext(sslContext)) - .doOnConnect(config -> LOG.info("TLS Syslog Client is about to be started")) - .doOnConnected(connection -> LOG.info("TLS Syslog Client connected to {}", connection.address())) - .doOnDisconnected(connection -> LOG.info("TLS Syslog Client disconnected from {}", connection.address())); + .doOnConnect(config -> log.info("TLS Syslog Client is about to be started")) + .doOnConnected(connection -> log.info("TLS Syslog Client connected to {}", connection.address())) + .doOnDisconnected(connection -> log.info("TLS Syslog Client disconnected from {}", connection.address())); } @@ -150,7 +150,7 @@ public Connection getHandle() { public void write(byte[] bytes) { // The write operation is asynchronous. var channel = getHandle().channel(); - LOG.trace("Writing {} bytes using session: {}", bytes.length, channel); + log.trace("Writing {} bytes using session: {}", bytes.length, channel); try { if (!channel.writeAndFlush(Unpooled.wrappedBuffer(bytes)).await(sendTimeout)) { throw new AuditException("Could not send audit message to " + host + ":" + port); diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/RecordingAuditMessageTransmission.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/RecordingAuditMessageTransmission.java index 443fa34c38..6e08193992 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/RecordingAuditMessageTransmission.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/RecordingAuditMessageTransmission.java @@ -16,11 +16,14 @@ package org.openehealth.ipf.commons.audit.protocol; +import lombok.Setter; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.AuditMetadataProvider; import org.openehealth.ipf.commons.audit.TlsParameters; +import org.openehealth.ipf.commons.audit.model.AuditMessage; import java.util.*; +import java.util.function.Consumer; /** * For testing only: an implementation that records the audit message strings in memory instead of sending them to @@ -31,6 +34,9 @@ */ public class RecordingAuditMessageTransmission implements AuditTransmissionProtocol { + @Setter + private Consumer consumer = auditMessage -> {}; + public RecordingAuditMessageTransmission() { } @@ -45,6 +51,7 @@ public RecordingAuditMessageTransmission(TlsParameters dummy) { @Override public void send(AuditContext auditContext, AuditMetadataProvider auditMetadataProvider, String auditMessage) { if (auditMessage != null) { + consumer.accept(auditMessage); messages.add(auditMessage); } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/TLSSyslogSenderImpl.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/TLSSyslogSenderImpl.java index 284e5a37a1..80a760b2bb 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/TLSSyslogSenderImpl.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/TLSSyslogSenderImpl.java @@ -55,7 +55,7 @@ */ public class TLSSyslogSenderImpl extends RFC5425Protocol implements AuditTransmissionProtocol { - private static final Logger LOG = LoggerFactory.getLogger(TLSSyslogSenderImpl.class); + private static final Logger log = LoggerFactory.getLogger(TLSSyslogSenderImpl.class); private static final int MIN_SO_TIMEOUT = 1; private static final Boolean DEFAULT_SOCKET_KEEPALIVE = Boolean.TRUE; @@ -118,23 +118,23 @@ private Socket getSocket(AuditContext auditContext) { public void send(AuditContext auditContext, AuditMetadataProvider auditMetadataProvider, String auditMessage) throws Exception { if (auditMessage != null) { var msgBytes = getTransportPayload(auditMetadataProvider, auditMessage); - LOG.debug("Auditing {} bytes to {}:{}", + log.debug("Auditing {} bytes to {}:{}", msgBytes.length, auditContext.getAuditRepositoryHostName(), auditContext.getAuditRepositoryPort()); try { doSend(auditContext, msgBytes); - if (LOG.isTraceEnabled()) { - LOG.trace(new String(msgBytes, StandardCharsets.UTF_8)); + if (log.isTraceEnabled()) { + log.trace(new String(msgBytes, StandardCharsets.UTF_8)); } } catch (SocketException | SocketTimeoutException e) { try { - LOG.info("Failed to use existing TLS socket. Will create a new connection and retry."); + log.info("Failed to use existing TLS socket. Will create a new connection and retry."); closeSocket(socket.get()); socket.set(null); doSend(auditContext, msgBytes); } catch (Exception exception) { - LOG.error("Failed to audit using new TLS socket, giving up - this audit message will be lost."); + log.error("Failed to audit using new TLS socket, giving up - this audit message will be lost."); closeSocket(socket.get()); socket.set(null); // re-throw the exception so caller knows what happened @@ -157,30 +157,30 @@ private synchronized void doSend(AuditContext auditContext, byte[] msgBytes) final var socket = getSocket(auditContext); if (socketTestPolicy.isBeforeWrite()) { - LOG.trace("Testing whether socket connection is alive and well before attempting to write"); + log.trace("Testing whether socket connection is alive and well before attempting to write"); if (!isSocketConnectionAlive(socket)) { closeSocket(socket); throw new FastSocketException( "Read-test before write operation determined that the socket connection is dead"); } - LOG.debug("Socket connection is confirmed to be alive."); + log.debug("Socket connection is confirmed to be alive."); } - LOG.trace("Now writing out ATNA record"); + log.trace("Now writing out ATNA record"); var out = socket.getOutputStream(); out.write(msgBytes); out.flush(); - LOG.trace("ATNA record has been written ({} bytes)", msgBytes.length); + log.trace("ATNA record has been written ({} bytes)", msgBytes.length); if (socketTestPolicy.isAfterWrite()) { - LOG.trace( + log.trace( "Testing whether socket connection is alive and well after write to confirm the write operation"); if (!isSocketConnectionAlive(socket)) { closeSocket(socket); throw new FastSocketException( "Read-test after write operation determined that the socket connection is dead"); } - LOG.debug("Socket connection is confirmed alive. Assuming write operation has succeeded"); + log.debug("Socket connection is confirmed alive. Assuming write operation has succeeded"); } } @@ -250,23 +250,23 @@ private boolean isSocketConnectionAlive(final Socket socket) { if (socket.getSoTimeout() > 0) { final var nextByte = socket.getInputStream().read(); if (nextByte > -1) { - LOG.warn( + log.warn( "Socket test was able to read a byte from the socket other than the 'stream closed' value of -1. " + "This should never happen since SYSLOG is a simplex (write only) protocol! Byte value read from stream: {}", nextByte); isAlive = true; } else { - LOG.debug("Socket test read '-1' -> connection closed by server."); + log.debug("Socket test read '-1' -> connection closed by server."); isAlive = false; } } else { throw new IllegalStateException("Test requires an SO_TIMEOUT greater than zero set on the socket."); } } catch (SocketTimeoutException e) { - LOG.debug("Socket read timed out; assuming the connection is still alive."); + log.debug("Socket read timed out; assuming the connection is still alive."); isAlive = true; } catch (IOException e) { - LOG.warn("Socket read failed for non-timeout reason; assuming the connection is dead."); + log.warn("Socket read failed for non-timeout reason; assuming the connection is dead."); isAlive = false; } @@ -283,7 +283,7 @@ private void closeSocket(final Socket socket) { try { socket.close(); } catch (IOException e) { - LOG.debug( + log.debug( "Failed to close pre-existing socket. As we are either shutting down or are in the process of replacing the socket this is not really a worry... Message: {}", e.getMessage()); } @@ -329,7 +329,6 @@ public boolean isAfterWrite() { * @author taastrad */ private static class FastSocketException extends SocketException { - private static final long serialVersionUID = 1L; public FastSocketException(final String msg) { super(msg); diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/UDPSyslogSenderImpl.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/UDPSyslogSenderImpl.java index 72eb8d3074..1ab58d1348 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/UDPSyslogSenderImpl.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/protocol/UDPSyslogSenderImpl.java @@ -41,7 +41,7 @@ */ public class UDPSyslogSenderImpl extends RFC5424Protocol implements AuditTransmissionProtocol { - private static final Logger LOG = LoggerFactory.getLogger(UDPSyslogSenderImpl.class); + private static final Logger log = LoggerFactory.getLogger(UDPSyslogSenderImpl.class); private static final int MAX_DATAGRAM_PACKET_SIZE = 65479; public UDPSyslogSenderImpl() { @@ -64,7 +64,7 @@ public void send(AuditContext auditContext, AuditMetadataProvider auditMetadataP try (var socket = new DatagramSocket()) { var msgBytes = getTransportPayload(auditMetadataProvider, auditMessage); var inetAddress = auditContext.getAuditRepositoryAddress(); - LOG.debug("Auditing {} bytes to {}:{} ({})", + log.debug("Auditing {} bytes to {}:{} ({})", msgBytes.length, auditContext.getAuditRepositoryHostName(), auditContext.getAuditRepositoryPort(), @@ -75,8 +75,8 @@ public void send(AuditContext auditContext, AuditMetadataProvider auditMetadataP inetAddress, auditContext.getAuditRepositoryPort()); socket.send(packet); - if (LOG.isTraceEnabled()) { - LOG.trace(new String(msgBytes, StandardCharsets.UTF_8)); + if (log.isTraceEnabled()) { + log.trace(new String(msgBytes, StandardCharsets.UTF_8)); } } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AbstractAuditMessageQueue.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AbstractAuditMessageQueue.java index a75f0bbb77..0bcca9e7b4 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AbstractAuditMessageQueue.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AbstractAuditMessageQueue.java @@ -18,7 +18,6 @@ import lombok.Setter; import org.openehealth.ipf.commons.audit.AuditContext; -import org.openehealth.ipf.commons.audit.FhirContextHolder; import org.openehealth.ipf.commons.audit.model.AuditMessage; import java.util.stream.Stream; @@ -30,8 +29,8 @@ * and send it to an ATNA repository using the configured {@link org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol}, *

*

- * There may be other use cases such as forwarding AuditMessages as object into a Camel Route or in-memory storage - * or convert them into FHIR AuditEvents. In this case, implement your own {@link AuditMessageQueue}. + * There may be other use cases such as forwarding AuditMessages as object into a Camel Route or in-memory storage. + * In this case, implement your own {@link AuditMessageQueue}. *

* * @author Christian Ohr @@ -40,7 +39,6 @@ public abstract class AbstractAuditMessageQueue implements AuditMessageQueue { - @Setter private boolean pretty = false; @@ -51,7 +49,6 @@ public void audit(AuditContext auditContext, AuditMessage... auditMessages) { .map(msg -> auditContext.getSerializationStrategy().marshal(msg, pretty)) .forEach(msg -> handle(auditContext, msg)); } - FhirContextHolder.remove(); } protected abstract void handle(AuditContext auditContext, String auditRecord); diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueue.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueue.java index 8bee6c37f4..2dacf6bd5f 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueue.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueue.java @@ -16,13 +16,12 @@ package org.openehealth.ipf.commons.audit.queue; -import ca.uhn.fhir.context.FhirContext; +import io.micrometer.context.ContextExecutorService; +import io.micrometer.context.ContextSnapshotFactory; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.AuditException; -import org.openehealth.ipf.commons.audit.FhirContextHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.MDC; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; @@ -43,7 +42,7 @@ */ public class AsynchronousAuditMessageQueue extends AbstractAuditMessageQueue { - private static final Logger LOG = LoggerFactory.getLogger(AsynchronousAuditMessageQueue.class); + private static final Logger log = LoggerFactory.getLogger(AsynchronousAuditMessageQueue.class); private ExecutorService executorService; private int shutdownTimeoutSeconds = 30; @@ -69,9 +68,13 @@ public void setShutdownTimeoutSeconds(int shutdownTimeoutSeconds) { @Override protected void handle(AuditContext auditContext, String auditRecord) { if (auditRecord != null) { - var runnable = runnable(auditContext, auditRecord, FhirContextHolder.get()); + var runnable = runnable(auditContext, auditRecord); if (executorService != null && !executorService.isShutdown()) { - CompletableFuture.runAsync(runnable, executorService) + var executor = ContextExecutorService.wrap(executorService, + ContextSnapshotFactory.builder() + .contextRegistry(auditContext.getContextRegistry()) + .build()); + CompletableFuture.runAsync(runnable, executor) .exceptionally(e -> { auditContext.getAuditExceptionHandler().handleException(auditContext, e, auditRecord); return null; @@ -82,20 +85,12 @@ protected void handle(AuditContext auditContext, String auditRecord) { } } - private Runnable runnable(AuditContext auditContext, String auditRecord, FhirContext fhirContext) { - // Copy the MDC contextMap to re-use it in the worker thread - // See this recommendation here: http://logback.qos.ch/manual/mdc.html#managedThreads - var mdcContextMap = MDC.getCopyOfContextMap(); + private Runnable runnable(AuditContext auditContext, String auditRecord) { return () -> { try { - MDC.setContextMap(mdcContextMap); - FhirContextHolder.setCurrentContext(fhirContext); auditContext.getAuditTransmissionProtocol().send(auditContext, auditRecord); } catch (Exception e) { throw new AuditException(e); - } finally { - MDC.clear(); - FhirContextHolder.remove(); } }; } @@ -106,11 +101,11 @@ public void shutdown() { executorService.shutdown(); try { if (!executorService.awaitTermination(shutdownTimeoutSeconds, TimeUnit.SECONDS)) { - LOG.warn("Timeout occurred when flushing Audit events, some events might have been lost"); + log.warn("Timeout occurred when flushing Audit events, some events might have been lost"); executorService.shutdownNow(); } } catch (InterruptedException e) { - LOG.warn("Thread interrupt when flushing ATNA events, some events might have been lost", e); + log.warn("Thread interrupt when flushing ATNA events, some events might have been lost", e); } } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/BasicHttpAuditMessageQueue.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/BasicHttpAuditMessageQueue.java index 5671546855..2adadb059a 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/BasicHttpAuditMessageQueue.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/BasicHttpAuditMessageQueue.java @@ -15,6 +15,7 @@ */ package org.openehealth.ipf.commons.audit.queue; +import lombok.Setter; import org.openehealth.ipf.commons.audit.AuditContext; import java.io.DataOutputStream; @@ -44,7 +45,9 @@ public class BasicHttpAuditMessageQueue extends AbstractAuditMessageQueue { private final String user; private final String password; + @Setter private int connectTimeout = -1; + @Setter private int readTimeout = -1; @@ -100,14 +103,6 @@ private void initializeConnection(HttpURLConnection connection, AuditContext aud connection.setUseCaches(false); } - public void setConnectTimeout(int connectTimeout) { - this.connectTimeout = connectTimeout; - } - - public void setReadTimeout(int readTimeout) { - this.readTimeout = readTimeout; - } - private HttpURLConnection openConnection() throws IOException { var connection = (HttpURLConnection) url.openConnection(); if (user != null) { diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageListener.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageListener.java index 2f66a1bf0f..f6a4639017 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageListener.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageListener.java @@ -42,7 +42,7 @@ */ public class JmsAuditMessageListener implements MessageListener { - private static final Logger LOG = LoggerFactory.getLogger(JmsAuditMessageListener.class); + private static final Logger log = LoggerFactory.getLogger(JmsAuditMessageListener.class); private final AuditContext auditContext; @@ -69,9 +69,9 @@ public void onMessage(Message message) { ); auditContext.getAuditTransmissionProtocol().send(auditContext, auditMetadataProvider, text); } catch (JMSException jmsException1) { - LOG.error("Could not obtain text from JMS message", jmsException1); + log.error("Could not obtain text from JMS message", jmsException1); } catch (Exception e) { - LOG.warn("Could not send audit message, rolling back", e); + log.warn("Could not send audit message, rolling back", e); throw new RuntimeException(e); } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/Rfc5424Decoder.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/Rfc5424Decoder.java index 26aba7c164..efeec32a41 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/Rfc5424Decoder.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/Rfc5424Decoder.java @@ -44,7 +44,7 @@ */ class Rfc5424Decoder extends MessageToMessageDecoder { - private static final Logger LOG = LoggerFactory.getLogger(Rfc5424Decoder.class); + private static final Logger log = LoggerFactory.getLogger(Rfc5424Decoder.class); private static final SyslogParser syslogParser = new SyslogParserBuilder() .withNilPolicy(NilPolicy.OMIT) @@ -66,13 +66,12 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) } private static Map decode(SocketAddress socketAddress, ByteBuf msg) { - if (LOG.isDebugEnabled()) { - LOG.debug("Decoding message with {} bytes into RFC 5424 map.", msg.readableBytes()); + if (log.isDebugEnabled()) { + log.debug("Decoding message with {} bytes into RFC 5424 map.", msg.readableBytes()); } var map = parseByteBuf(msg); - if (socketAddress instanceof InetSocketAddress) { + if (socketAddress instanceof InetSocketAddress inetSocketAddress) { var enriched = new HashMap<>(map); - var inetSocketAddress = (InetSocketAddress) socketAddress; enriched.put(SYSLOG_REMOTE_HOST, inetSocketAddress.getHostName()); enriched.put(SYSLOG_REMOTE_PORT, inetSocketAddress.getPort()); enriched.put(SYSLOG_REMOTE_IP, inetSocketAddress.getAddress().getHostAddress()); diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/SyslogServer.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/SyslogServer.java index 20cf0f4369..4d1bce2d8a 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/SyslogServer.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/SyslogServer.java @@ -15,6 +15,7 @@ */ package org.openehealth.ipf.commons.audit.server; +import lombok.Setter; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import reactor.netty.DisposableChannel; @@ -47,6 +48,8 @@ public abstract class SyslogServer implements Close protected T channel; protected final Consumer> consumer; protected final Consumer errorConsumer; + @Setter + protected int timeoutSeconds = TIMEOUT; /** * @param consumer consumer for handled syslog frames @@ -85,7 +88,7 @@ public SocketAddress address() { */ public void stop() { if (channel != null) { - channel.disposeNow(Duration.ofSeconds(TIMEOUT)); + channel.disposeNow(Duration.ofSeconds(timeoutSeconds)); } channel = null; } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/TlsSyslogServer.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/TlsSyslogServer.java index 8ed88d8689..808b970469 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/TlsSyslogServer.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/TlsSyslogServer.java @@ -38,7 +38,7 @@ */ public class TlsSyslogServer extends SyslogServer { - private static final Logger LOG = LoggerFactory.getLogger(TlsSyslogServer.class); + private static final Logger log = LoggerFactory.getLogger(TlsSyslogServer.class); protected final TlsParameters tlsParameters; public TlsSyslogServer(Consumer> consumer, @@ -60,16 +60,19 @@ public TlsSyslogServer doStart(String host, int port) { .host(host) .port(port) .option(ChannelOption.SO_REUSEADDR, true) - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int)Duration.ofSeconds(timeoutSeconds).toMillis()) .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(65535)) .wiretap(getClass().getName(), LogLevel.TRACE) .metrics(Metrics.isMicrometerAvailable()) .secure(spec -> spec.sslContext(sslContext)) - .doOnBind(serverBootstrap -> LOG.info("TLS Syslog Server is about to be started")) - .doOnBound(disposableServer -> LOG.info("TLS Syslog Server bound on {}", disposableServer.address())) - .doOnUnbound(disposableServer -> LOG.info("TLS Syslog Server unbound from {}", disposableServer.address())) + .doOnBind(serverBootstrap -> + log.info("TLS Syslog Server is about to be started")) + .doOnBound(disposableServer -> + log.info("TLS Syslog Server bound on {}", disposableServer.address())) + .doOnUnbound(disposableServer -> + log.info("TLS Syslog Server unbound from {}", disposableServer.address())) .doOnConnection(connection -> { - LOG.debug("Received connection from {}", connection.channel().localAddress()); + log.debug("Received connection from {}", connection.channel().localAddress()); connection .addHandlerLast(new Rfc5425Decoder()) // extract frame .addHandlerLast(new Rfc5424Decoder()); // parse frame, fast enough for receiver thread @@ -79,7 +82,7 @@ public TlsSyslogServer doStart(String host, int port) { .flatMap(this::handleMap) .doOnError(errorConsumer) .then()) - .bindNow(Duration.ofSeconds(TIMEOUT)); + .bindNow(Duration.ofSeconds(timeoutSeconds)); return this; } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/UdpSyslogServer.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/UdpSyslogServer.java index b20e2b28b1..bd66a51cb4 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/UdpSyslogServer.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/UdpSyslogServer.java @@ -22,8 +22,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.netty.Connection; +import reactor.netty.internal.util.Metrics; import reactor.netty.udp.UdpServer; -import reactor.util.Metrics; import java.time.Duration; import java.util.Map; @@ -37,7 +37,7 @@ */ public class UdpSyslogServer extends SyslogServer { - private static final Logger LOG = LoggerFactory.getLogger(UdpSyslogServer.class); + private static final Logger log = LoggerFactory.getLogger(UdpSyslogServer.class); public UdpSyslogServer(Consumer> consumer, Consumer errorConsumer) { @@ -48,20 +48,23 @@ public UdpSyslogServer(Consumer> consumer, public UdpSyslogServer doStart(String host, int port) { channel = UdpServer.create() .option(ChannelOption.SO_REUSEADDR, true) - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int)Duration.ofSeconds(timeoutSeconds).toMillis()) .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(65535)) .host(host) .port(port) .wiretap(getClass().getName(), LogLevel.TRACE) - .metrics(Metrics.isInstrumentationAvailable()) + .metrics(Metrics.isMicrometerAvailable()) // This does not work! //.doOnBound(connection -> connection // .addHandler(new Rfc5426Decoder()) // .addHandler(new Rfc5424Decoder())) - .doOnBind(serverBootstrap -> LOG.info("UDP Syslog Server is about to be started")) - .doOnBound(disposableServer -> LOG.info("UDP Syslog Server bound on {}", disposableServer.channel().localAddress())) - .doOnUnbound(disposableServer -> LOG.info("UDP Syslog Server unbound from {}", disposableServer.channel().localAddress())) + .doOnBind(serverBootstrap -> + log.info("UDP Syslog Server is about to be started")) + .doOnBound(disposableServer -> + log.info("UDP Syslog Server bound on {}", disposableServer.channel().localAddress())) + .doOnUnbound(disposableServer -> + log.info("UDP Syslog Server unbound from {}", disposableServer.channel().localAddress())) .handle((udpInbound, udpOutbound) -> udpInbound .receiveObject() // Because the handlers don't seem to step in, we handle it here @@ -70,7 +73,7 @@ public UdpSyslogServer doStart(String host, int port) { .flatMap(this::handleMap) .doOnError(errorConsumer) .then()) - .bindNow(Duration.ofSeconds(TIMEOUT)); + .bindNow(Duration.ofSeconds(timeoutSeconds)); return this; } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventCollector.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventCollector.java index 5fa75a078d..fa7e7238c5 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventCollector.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventCollector.java @@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Predicate; -import java.util.stream.Collectors; /** * A simple collector of Syslog events @@ -39,7 +38,7 @@ */ public class SyslogEventCollector implements Consumer> { - private static final Logger LOG = LoggerFactory.getLogger(SyslogEventCollector.class); + private static final Logger log = LoggerFactory.getLogger(SyslogEventCollector.class); private static final AuditParser PARSER = new DICOMAuditParser(); private final Collection> syslogMaps = new ConcurrentLinkedQueue<>(); @@ -85,7 +84,7 @@ private SyslogEventCollector() { @Override public void accept(Map syslogMap) { - LOG.debug("Collecting syslog event {}", syslogMap); + log.debug("Collecting syslog event {}", syslogMap); syslogMaps.add(syslogMap); } @@ -96,7 +95,7 @@ public Collection> getSyslogEvents() { public Collection> getSyslogEvents(Predicate> predicate) { return syslogMaps.stream() .filter(predicate) - .collect(Collectors.toUnmodifiableList()); + .toList(); } public void reset() { diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventDICOMPrinter.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventDICOMPrinter.java index 82f33ced8c..e70187fa21 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventDICOMPrinter.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/server/support/SyslogEventDICOMPrinter.java @@ -33,7 +33,7 @@ */ public class SyslogEventDICOMPrinter { - private static final Logger LOG = LoggerFactory.getLogger(SyslogEventDICOMPrinter.class); + private static final Logger log = LoggerFactory.getLogger(SyslogEventDICOMPrinter.class); private static final AuditParser PARSER = new DICOMAuditParser(); public static EventConsumer newEventConsumer(String channel) { @@ -44,18 +44,18 @@ public static ErrorConsumer newErrorConsumer() { return new ErrorConsumer(); } - private static class ErrorConsumer implements Consumer { + public static class ErrorConsumer implements Consumer { private ErrorConsumer() { } @Override public void accept(Throwable throwable) { - LOG.error("Error occurred while receiving a syslog event: ", throwable); + log.error("Error occurred while receiving a syslog event: ", throwable); } } - private static class EventConsumer implements Consumer> { + public static class EventConsumer implements Consumer> { private final String channel; @@ -65,21 +65,21 @@ private EventConsumer(String channel) { @Override public void accept(Map syslogMap) { - LOG.info("Received event on {} from {}:{}", + log.info("Received event on {} from {}:{}", channel, syslogMap.get("syslog.remote.host"), syslogMap.get("syslog.remote.port")); - LOG.info("Syslog Metadata: AppName: {}, HostName: {}, Timestamp: {}", + log.info("Syslog Metadata: AppName: {}, HostName: {}, Timestamp: {}", syslogMap.get(SyslogFieldKeys.HEADER_APPNAME.getField()), syslogMap.get(SyslogFieldKeys.HEADER_HOSTNAME.getField()), syslogMap.get(SyslogFieldKeys.HEADER_TIMESTAMP.getField())); try { var auditMessage = parse(syslogMap); - LOG.info("DICOM Payload is"); - LOG.info("{}", auditMessage); + log.info("DICOM Payload is"); + log.info("{}", auditMessage); } catch (Exception e) { - LOG.warn("Could not parse payload:", e); - LOG.info("{}", syslogMap.get(SyslogFieldKeys.MESSAGE.getField())); + log.warn("Could not parse payload:", e); + log.info("{}", syslogMap.get(SyslogFieldKeys.MESSAGE.getField())); } } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParser.java b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParser.java index 2a6ee16eb9..d686ccdaff 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParser.java +++ b/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParser.java @@ -56,7 +56,6 @@ import java.util.Base64; import java.util.List; import java.util.function.Function; -import java.util.stream.Collectors; import static org.openehealth.ipf.commons.audit.XMLNames.*; @@ -202,7 +201,7 @@ private void mapInto(List container, Element element, String name, Functi container.addAll( element.getChildren(name).stream() .map(mapper) - .collect(Collectors.toList())); + .toList()); } private EventId eventId(Element codedValueElement) { @@ -245,10 +244,10 @@ private T codedValue(Element element, Function f) { private Instant dateTime(String s) { var parsed = DATE_TIME_FORMATTER.parseBest(s, Instant::from, LocalDateTime::from); - if (parsed instanceof Instant) { - return (Instant) parsed; - } else if (parsed instanceof LocalDateTime) { - return ((LocalDateTime) parsed).atOffset(ZoneOffset.UTC).toInstant(); + if (parsed instanceof Instant instant) { + return instant; + } else if (parsed instanceof LocalDateTime localDateTime) { + return localDateTime.atOffset(ZoneOffset.UTC).toInstant(); } else { throw new AuditException("Could not parse " + s + " to Instant"); } diff --git a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AbstractAuditorIntegrationTest.java b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AbstractAuditorIntegrationTest.java index 122c0122ac..3772ddaf01 100644 --- a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AbstractAuditorIntegrationTest.java +++ b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AbstractAuditorIntegrationTest.java @@ -35,7 +35,7 @@ */ abstract class AbstractAuditorIntegrationTest { - private static final Logger LOG = LoggerFactory.getLogger(AbstractAuditorIntegrationTest.class); + private static final Logger log = LoggerFactory.getLogger(AbstractAuditorIntegrationTest.class); static final String CLIENT_KEY_STORE; static final String CLIENT_KEY_STORE_PASS = "initinit"; @@ -91,7 +91,7 @@ void sendAudit() { } void sendAudit(String userName) { - LOG.debug("Sending audit record"); + log.debug("Sending audit record"); auditContext.audit( new ApplicationActivityBuilder.ApplicationStart(EventOutcomeIndicator.Success) .setAuditSource(auditContext) @@ -108,7 +108,7 @@ int freePort() { try (var serverSocket = new ServerSocket(0)) { return serverSocket.getLocalPort(); } catch (Exception e) { - LOG.error(e.getMessage()); + log.error(e.getMessage()); return -1; } } diff --git a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AuditRecordServer.java b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AuditRecordServer.java index 9636c67bcc..a22a425cbd 100644 --- a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AuditRecordServer.java +++ b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/AuditRecordServer.java @@ -35,7 +35,7 @@ */ public class AuditRecordServer { - private static final Logger LOG = LoggerFactory.getLogger(AuditRecordServer.class); + private static final Logger log = LoggerFactory.getLogger(AuditRecordServer.class); private static Optional> getSyslogServer( String channel, @@ -52,11 +52,11 @@ private static Optional> getSyslogServer( public static void main(String... args) throws Exception { if (args.length < 2) { - LOG.error("Usage: AuditRecordServer (-1 for not launching channel, 0 for using a random port)"); + log.error("Usage: AuditRecordServer (-1 for not launching channel, 0 for using a random port)"); } else { final var tlsSyslogServer = getSyslogServer("TLS", TlsSyslogServer::new, Integer.parseInt(args[0])); final var udpSyslogServer = getSyslogServer("UDP", UdpSyslogServer::new, Integer.parseInt(args[1])); - LOG.info("Waiting for requests..."); + log.info("Waiting for requests..."); Runtime.getRuntime().addShutdownHook(new Thread(() -> { tlsSyslogServer.ifPresent(SyslogServer::stop); udpSyslogServer.ifPresent(SyslogServer::stop); diff --git a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/TLSAuditorFailingIntegrationTest.java b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/TLSAuditorFailingIntegrationTest.java index c083336097..b130a152dc 100644 --- a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/TLSAuditorFailingIntegrationTest.java +++ b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/TLSAuditorFailingIntegrationTest.java @@ -30,7 +30,7 @@ public class TLSAuditorFailingIntegrationTest extends AbstractAuditorIntegrationTest { - private static final Logger LOG = LoggerFactory.getLogger(TLSAuditorFailingIntegrationTest.class); + private static final Logger log = LoggerFactory.getLogger(TLSAuditorFailingIntegrationTest.class); private CustomTlsParameters tlsParameters; diff --git a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueueTest.java b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueueTest.java index 9c3e51c485..9bb24f3d58 100644 --- a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueueTest.java +++ b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/AsynchronousAuditMessageQueueTest.java @@ -16,14 +16,21 @@ package org.openehealth.ipf.commons.audit.queue; +import io.micrometer.context.ThreadLocalAccessor; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openehealth.ipf.commons.audit.DefaultAuditContext; import org.openehealth.ipf.commons.audit.marshal.dicom.Current; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol; +import org.openehealth.ipf.commons.audit.protocol.RecordingAuditMessageTransmission; import java.util.concurrent.Executors; +import java.util.function.Consumer; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; import static org.mockito.Mockito.*; /** @@ -32,37 +39,44 @@ public class AsynchronousAuditMessageQueueTest { @Test - public void sendMessageWithoutExecutor() throws Exception { - final var messageSender = mock(AuditTransmissionProtocol.class); + public void sendMessageWithoutExecutor() { final var context = new DefaultAuditContext(); context.setAuditEnabled(true); + final var auditMessageTransmission = new RecordingAuditMessageTransmission(); var queue = new AsynchronousAuditMessageQueue(); context.setAuditMessageQueue(queue); - context.setAuditTransmissionProtocol(messageSender); + context.setAuditTransmissionProtocol(auditMessageTransmission); var auditMessage = someAuditEventMessage(); context.audit(auditMessage); - - verify(messageSender).send(context, Current.toString(auditMessage, false)); - verifyNoMoreInteractions(messageSender); + assertThat(auditMessageTransmission.getMessages(), hasSize(1)); + assertThat(auditMessageTransmission.getFirstMessage().orElseThrow(), equalTo(Current.toString(auditMessage, false))); } @Test - public void sendMessageWithExecutor() throws Exception { - final var messageSender = mock(AuditTransmissionProtocol.class); + public void sendMessageWithExecutorAndThreadLocal() throws Exception { final var context = new DefaultAuditContext(); + context.getContextRegistry().registerThreadLocalAccessor(new CustomThreadLocalAccessor()); context.setAuditEnabled(true); + + final var auditMessageTransmission = new RecordingAuditMessageTransmission(); + final var value = "someValue"; + CustomThreadLocalHolder.set(value); + // assert that value has been transferred to audit thread + auditMessageTransmission.setConsumer(s -> assertThat(CustomThreadLocalHolder.get(), equalTo(value))); + var queue = new AsynchronousAuditMessageQueue(); context.setAuditMessageQueue(queue); - context.setAuditTransmissionProtocol(messageSender); + context.setAuditTransmissionProtocol(auditMessageTransmission); + try { queue.setExecutorService(Executors.newSingleThreadExecutor()); var auditMessage = someAuditEventMessage(); context.audit(auditMessage); Thread.sleep(500); - verify(messageSender).send(context, Current.toString(auditMessage, false)); - verifyNoMoreInteractions(messageSender); + assertThat(auditMessageTransmission.getMessages(), hasSize(1)); + assertThat(auditMessageTransmission.getFirstMessage().orElseThrow(), equalTo(Current.toString(auditMessage, false))); } finally { queue.shutdown(); } @@ -72,4 +86,45 @@ private AuditMessage someAuditEventMessage() { return mock(AuditMessage.class); } + private static class CustomThreadLocalHolder { + private static final ThreadLocal value = new ThreadLocal<>(); + + public static void set(String newValue) { + value.set(newValue); + } + + public static String get() { + return value.get(); + } + + public static void remove() { + value.remove(); + } + } + + private static class CustomThreadLocalAccessor implements ThreadLocalAccessor { + + public static final String KEY = "value"; + + @Override + public String getValue() { + return CustomThreadLocalHolder.get(); + } + + @Override + public Object key() { + return KEY; + } + + @Override + public void setValue(String value) { + CustomThreadLocalHolder.set(value); + } + + @Override + public void setValue() { + CustomThreadLocalHolder.remove(); + } + } + } diff --git a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageQueueTest.java b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageQueueTest.java index b665825e8c..f9f9682c16 100644 --- a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageQueueTest.java +++ b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/queue/JmsAuditMessageQueueTest.java @@ -40,7 +40,7 @@ */ public class JmsAuditMessageQueueTest { - private static final Logger LOG = LoggerFactory.getLogger(JmsAuditMessageQueueTest.class); + private static final Logger log = LoggerFactory.getLogger(JmsAuditMessageQueueTest.class); private static final String JMS_BROKER_URL = "tcp://localhost:61616"; private static final String JMS_QUEUE_NAME = "atna"; @@ -105,7 +105,7 @@ public void testActiveMQ() throws Exception { } private void sendAudit() { - LOG.debug("Sending audit record"); + log.debug("Sending audit record"); auditContext.audit( new ApplicationActivityBuilder.ApplicationStart(EventOutcomeIndicator.Success) .setAuditSource(auditContext) diff --git a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParserTest.java b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParserTest.java index e66b31b0de..bcb44d6fc6 100644 --- a/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParserTest.java +++ b/commons/audit/src/test/java/org/openehealth/ipf/commons/audit/unmarshal/dicom/DICOMAuditParserTest.java @@ -20,7 +20,7 @@ public class DICOMAuditParserTest { - private static final Logger LOG = LoggerFactory.getLogger(DICOMAuditParser.class); + private static final Logger log = LoggerFactory.getLogger(DICOMAuditParserTest.class); @Test public void roundtrip() throws IOException, URISyntaxException { @@ -28,7 +28,7 @@ public void roundtrip() throws IOException, URISyntaxException { var parser = new DICOMAuditParser(); var files = getAllFilesFromResource("audit"); for (var file : files) { - LOG.debug("Parsing {}", file); + log.debug("Parsing {}", file); var read = Files.readString(file, StandardCharsets.UTF_8); var auditMessage = parser.parse(read, true); var written = Current.INSTANCE.marshal(auditMessage, true); @@ -46,10 +46,9 @@ public void roundtrip() throws IOException, URISyntaxException { private List getAllFilesFromResource(String folder) throws URISyntaxException, IOException { var classLoader = getClass().getClassLoader(); var resource = classLoader.getResource(folder); - var collect = Files.walk(Paths.get(resource.toURI())) + + return Files.walk(Paths.get(resource.toURI())) .filter(Files::isRegularFile) .collect(Collectors.toList()); - - return collect; } } diff --git a/commons/core/pom.xml b/commons/core/pom.xml index 9397257250..5d602bfb63 100644 --- a/commons/core/pom.xml +++ b/commons/core/pom.xml @@ -21,7 +21,6 @@ org.vibur vibur-object-pool - org.glassfish.jaxb jaxb-runtime diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/ContentMap.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/ContentMap.java index 19f37c77f6..b31cad7efd 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/ContentMap.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/ContentMap.java @@ -31,12 +31,12 @@ */ @XmlTransient public class ContentMap { - private static final transient Logger LOG = LoggerFactory.getLogger(ContentMap.class); + private static final Logger log = LoggerFactory.getLogger(ContentMap.class); // synchronized manually private transient final Map, Object> map = new HashMap<>(); - private static transient TypeConverter conversionService; + private static TypeConverter conversionService; /** @@ -54,12 +54,12 @@ public class ContentMap { public T getContent(Class targetType) { var result = (T) map.get(targetType); if (result != null) { - LOG.debug("Return existing content of type {}", targetType); + log.debug("Return existing content of type {}", targetType); return result; } if (conversionService == null) { - LOG.debug("Conversion service not configured"); + log.debug("Conversion service not configured"); return null; } @@ -69,7 +69,7 @@ public T getContent(Class targetType) { if (conversionService.canConvert(sourceTypeEntry.getKey(), targetType)) { result = conversionService.convert(sourceTypeEntry.getValue(), targetType); if (result != null) { - LOG.debug("Successfully generated {} from {}", targetType, sourceTypeEntry.getKey()); + log.debug("Successfully generated {} from {}", targetType, sourceTypeEntry.getKey()); setContent(targetType, result); return result; } @@ -77,7 +77,7 @@ public T getContent(Class targetType) { } } - LOG.debug("Could not find appropriate converter for the target type {}", targetType); + log.debug("Could not find appropriate converter for the target type {}", targetType); return null; } diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/URN.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/URN.java index 657a711e35..cde8afd312 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/URN.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/URN.java @@ -15,8 +15,10 @@ */ package org.openehealth.ipf.commons.core; +import lombok.NonNull; import org.ietf.jgss.Oid; +import java.io.Serial; import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; @@ -35,6 +37,7 @@ */ public final class URN implements Comparable, Serializable { + @Serial private static final long serialVersionUID = -7978304633360508549L; public static final String UUID = "uuid"; public static final String OID = "oid"; @@ -73,7 +76,7 @@ public URN(String namespaceId, String namespaceSpecificString) throws URISyntaxE } @Override - public int compareTo(URN urn) { + public int compareTo(@NonNull URN urn) { return equals(urn) ? 0 : uri.compareTo(urn.uri); } diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ContextFacade.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ContextFacade.java index 52a99e01da..574a60640a 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ContextFacade.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ContextFacade.java @@ -35,11 +35,11 @@ public class ContextFacade { private static Registry instance; - private static final Logger LOG = LoggerFactory.getLogger(ContextFacade.class); + private static final Logger log = LoggerFactory.getLogger(ContextFacade.class); public static synchronized void setRegistry(Registry registry) { if (instance != null && !registry.equals(instance)) - LOG.info("Re-initializing the registry"); + log.info("Re-initializing the registry"); instance = registry; } diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ExtensionModuleFactory.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ExtensionModuleFactory.java index feeba133b9..583bc18dbb 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ExtensionModuleFactory.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/config/ExtensionModuleFactory.java @@ -35,7 +35,7 @@ */ public class ExtensionModuleFactory extends PropertiesModuleFactory { - private static final Logger LOG = LoggerFactory.getLogger(ExtensionModuleFactory.class); + private static final Logger log = LoggerFactory.getLogger(ExtensionModuleFactory.class); private static final String MODULE_NAME_INITIALIZER_CLASS = "moduleInitializerClass"; public ExtensionModuleFactory() { @@ -43,13 +43,13 @@ public ExtensionModuleFactory() { @Override public ExtensionModule newModule(Properties properties, ClassLoader classLoader) { - LOG.info("Registering new extension module {} defined in class {}", + log.info("Registering new extension module {} defined in class {}", properties.getProperty(MODULE_NAME_KEY), properties.getProperty(MetaInfExtensionModule.MODULE_INSTANCE_CLASSES_KEY)); var module = createExtensionModule(properties, classLoader); - if (LOG.isDebugEnabled()) { + if (log.isDebugEnabled()) { for(var method : module.getMetaMethods()) { - LOG.debug("registered method: {}", method); + log.debug("registered method: {}", method); } } if (properties.containsKey(MODULE_NAME_INITIALIZER_CLASS)) { @@ -58,7 +58,7 @@ public ExtensionModule newModule(Properties properties, ClassLoader classLoader) var initializerClass = Class.forName(initializerClassName); initializerClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { - LOG.warn("Unable to initialize extension using {}.", initializerClassName, e); + log.warn("Unable to initialize extension using {}.", initializerClassName, e); } } diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/extend/config/DynamicExtensionConfigurer.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/extend/config/DynamicExtensionConfigurer.java index e31396fc24..fea9b0db2f 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/extend/config/DynamicExtensionConfigurer.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/extend/config/DynamicExtensionConfigurer.java @@ -43,7 +43,7 @@ public class DynamicExtensionConfigurer extends OrderedConfigurer { - private static final Logger LOG = LoggerFactory.getLogger(DynamicExtensionConfigurer.class); + private static final Logger log = LoggerFactory.getLogger(DynamicExtensionConfigurer.class); public DynamicExtensionConfigurer() { setOrder(2); @@ -52,7 +52,7 @@ public DynamicExtensionConfigurer() { @Override public void configure(DynamicExtension extension) { if (extension != null) { - LOG.info("Registering new extension module {} defined in class {}", + log.info("Registering new extension module {} defined in class {}", extension.getModuleName(), extension.getClass()); var module = DynamicExtensionModule.newModule(extension); addExtensionMethods(module); @@ -76,7 +76,7 @@ public static void addExtensionMethods(ExtensionModule module) { } else { ((MetaClassRegistryImpl)metaClassRegistry).getInstanceMethods().add(metaMethod); } - LOG.debug("registered method: {}", metaMethod); + log.debug("registered method: {}", metaMethod); } for (var cachedClassEntry : classMap.entrySet()) { cachedClassEntry.getKey().addNewMopMethods(cachedClassEntry.getValue()); diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Converter.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Converter.java index c29fa3f443..765eaba1da 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Converter.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Converter.java @@ -42,8 +42,6 @@ public abstract class Converter implements Parser, Renderer, Transmo * * @param message message to be converted * @return converted message - * @throws ParseException - * @throws RenderException */ public final String convert(String message, Object... params) { var parsed = parse(message, params); diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Parser.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Parser.java index d54cbdcb07..cf908f1e0e 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Parser.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Parser.java @@ -36,10 +36,9 @@ public interface Parser { * Parses a message and returns an internal representation of the * information. * - * @param message - * @param params + * @param message message + * @param params parse parameters * @return the parsed message - * @throws ParseException */ S parse(String message, Object... params); @@ -47,12 +46,11 @@ public interface Parser { * Parses a message and returns an internal representation of the * information. * - * @param message - * @param params + * @param message message to be parsed + * @param params parse parameters * @return the parsed message * @throws IOException * if reading from stream fails - * @throws ParseException */ S parse(InputStream message, Object... params) throws IOException; @@ -60,24 +58,23 @@ public interface Parser { * Parses a message and returns an internal representation of the * information. * - * @param source - * @param params + * @param source message to be parsed + * @param params parse parameters * @return the parsed message * @throws IOException * if reading from stream fails - * @throws ParseException */ S parse(Source source, Object... params) throws IOException; /** * Parses a message and returns an internal representation of the * information. - * - * @param params + * + * @param reader message to be parsed + * @param params parse parameters * @return the parsed message * @throws IOException * if reading from stream fails - * @throws ParseException */ S parse(Reader reader, Object... params) throws IOException; diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Renderer.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Renderer.java index c5badca933..2c69680b36 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Renderer.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Renderer.java @@ -34,52 +34,48 @@ public interface Renderer { /** * Renders the model into its external representation. * - * @param model + * @param model model to be rendered * @param params * dynamic information used during rendering. See the respective * implementation class documentation if this is required or * supported. * @return the external representation of the model - * @throws RenderException */ Result render(final T model, Result result, final Object... params) throws IOException; /** * Renders the model into its external representation. * - * @param model + * @param model model to be rendered * @param params * dynamic information used during rendering. See the respective * implementation class documentation if this is required or * supported. * @return the external representation of the model - * @throws RenderException */ OutputStream render(final T model, OutputStream result, final Object... params) throws IOException; /** * Renders the model into its external representation. * - * @param model + * @param model model to be rendered * @param params * dynamic information used during rendering. See the respective * implementation class documentation if this is required or * supported. * @return the external representation of the model - * @throws RenderException */ Writer render(final T model, Writer result, final Object... params) throws IOException; /** * Renders the model into its external representation. * - * @param model + * @param model model to be rendered * @param params * dynamic information used during rendering. See the respective * implementation class documentation if this is required or * supported. * @return the external representation of the model - * @throws RenderException */ String render(final T model, final Object... params); diff --git a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Transmogrifier.java b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Transmogrifier.java index 68f701faee..1b9813fea0 100644 --- a/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Transmogrifier.java +++ b/commons/core/src/main/java/org/openehealth/ipf/commons/core/modules/api/Transmogrifier.java @@ -31,7 +31,7 @@ public interface Transmogrifier { * Transmogrifies an object into another one. * * @param object what goes in - * @param params + * @param params parameters * @return what comes out */ T zap(S object, Object... params); diff --git a/commons/core/src/test/java/org/openehealth/ipf/commons/core/URNTest.java b/commons/core/src/test/java/org/openehealth/ipf/commons/core/URNTest.java index 8866f3edfc..910931fefb 100644 --- a/commons/core/src/test/java/org/openehealth/ipf/commons/core/URNTest.java +++ b/commons/core/src/test/java/org/openehealth/ipf/commons/core/URNTest.java @@ -31,7 +31,7 @@ public void testCorrectOID() throws URISyntaxException { } @Test - public void testCorrectUUID() throws URISyntaxException { + public void testCorrectUUID() { var uuid = UUID.randomUUID(); var urn = new URN(uuid); assertEquals("uuid", urn.getNamespaceId()); @@ -77,6 +77,6 @@ public void testHashCode() throws URISyntaxException { @Test public void testFromOid() throws GSSException, URISyntaxException { var oid = "2.999.2.3.2.43.54"; - assertEquals(URN.create("urn:oid:" + oid), new URN(new Oid(oid))); + assertEquals(new URN(new Oid(oid)), URN.create("urn:oid:" + oid)); } } diff --git a/commons/core/src/test/java/org/openehealth/ipf/commons/core/modules/api/ValidationExceptionTest.java b/commons/core/src/test/java/org/openehealth/ipf/commons/core/modules/api/ValidationExceptionTest.java index 13ea805e9d..80b4c4fb43 100644 --- a/commons/core/src/test/java/org/openehealth/ipf/commons/core/modules/api/ValidationExceptionTest.java +++ b/commons/core/src/test/java/org/openehealth/ipf/commons/core/modules/api/ValidationExceptionTest.java @@ -68,7 +68,7 @@ public void testMessages() { // ----------------- causes = new Throwable[] {}; s = new ValidationException(message, causes).getMessage(); - assertEquals(s, message); + assertEquals(message, s); s = new ValidationException(causes).getMessage(); assertEquals(s, ValidationException.class.getName()); @@ -76,7 +76,7 @@ public void testMessages() { // ----------------- causes = null; s = new ValidationException(message, causes).getMessage(); - assertEquals(s, message); + assertEquals(message, s); s = new ValidationException(causes).getMessage(); assertEquals(s, ValidationException.class.getName()); @@ -84,7 +84,7 @@ public void testMessages() { // ----------------- Throwable cause = null; s = new ValidationException(message, cause).getMessage(); - assertEquals(s, message); + assertEquals(message, s); s = new ValidationException(cause).getMessage(); assertEquals(s, ValidationException.class.getName()); diff --git a/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRule.java b/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRule.java index 6919a2f093..d6fe070dcc 100644 --- a/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRule.java +++ b/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRule.java @@ -50,7 +50,7 @@ */ public class ConditionalRule implements TestRule { - private static final Logger LOG = LoggerFactory.getLogger(ConditionalRule.class); + private static final Logger log = LoggerFactory.getLogger(ConditionalRule.class); private Predicate predicate; private String reason; @@ -129,7 +129,7 @@ public void evaluate() throws Throwable { statement.evaluate(); } catch (Throwable e) { if (isIgnoredException(e)) { - LOG.warn("Did not execute test {}: {} ", description, conditionalRule.getReason()); + log.warn("Did not execute test {}: {} ", description, conditionalRule.getReason()); return; } throw e; diff --git a/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRuleTest.java b/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRuleTest.java index 19455ea2e3..c80096aaea 100644 --- a/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRuleTest.java +++ b/commons/core/src/test/java/org/openehealth/ipf/commons/core/test/ConditionalRuleTest.java @@ -28,7 +28,7 @@ public class ConditionalRuleTest { private static final String currentArchitecture = System.getProperty("os.name"); - @Rule public ConditionalRule rule = new ConditionalRule() + @Rule public final ConditionalRule rule = new ConditionalRule() .ifSystemPropertyIs("os.name", currentArchitecture); @Test diff --git a/commons/ihe/core/pom.xml b/commons/ihe/core/pom.xml index 9f473f6069..d36f5f182f 100644 --- a/commons/ihe/core/pom.xml +++ b/commons/ihe/core/pom.xml @@ -21,8 +21,8 @@ ca.uhn.hapi hapi-base + true - commons-io commons-io @@ -33,10 +33,6 @@ spring-expression true - - org.apache.commons - commons-lang3 - diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/HL7DTM.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/HL7DTM.java index f045557fa3..b41dce5310 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/HL7DTM.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/HL7DTM.java @@ -17,7 +17,6 @@ import ca.uhn.hl7v2.model.DataTypeException; import ca.uhn.hl7v2.model.primitive.CommonTS; -import org.apache.commons.lang3.StringUtils; import java.time.Instant; import java.time.ZoneId; @@ -46,7 +45,7 @@ public class HL7DTM { * @throws DataTypeException if the DTM string is invalid. */ public static ZonedDateTime toZonedDateTime(String s) throws DataTypeException { - if (StringUtils.isEmpty(s)) { + if (s == null || s.isEmpty()) { return null; } diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/SerializableEnumInteractionId.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/SerializableEnumInteractionId.java index 058dcbffc5..edb886c95c 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/SerializableEnumInteractionId.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/SerializableEnumInteractionId.java @@ -15,12 +15,14 @@ */ package org.openehealth.ipf.commons.ihe.core; +import java.io.Serial; import java.io.Serializable; /** * */ public class SerializableEnumInteractionId & InteractionId> implements Serializable, InteractionId { + @Serial private static final long serialVersionUID = -2740691943593482233L; private final String interaction; diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditDataset.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditDataset.java index 71129df2b5..b0b4ce2cbe 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditDataset.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditDataset.java @@ -18,7 +18,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.apache.commons.lang3.StringUtils; import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; import org.openehealth.ipf.commons.audit.types.ActiveParticipantRoleId; import org.openehealth.ipf.commons.audit.utils.AuditUtils; @@ -53,7 +52,7 @@ public HumanUser(String id, String name, Collection rol } public boolean isEmpty() { - return StringUtils.isAllBlank(id, name); + return (id == null || id.trim().isEmpty()) && (name == null || name.trim().isEmpty()); } } diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditStrategySupport.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditStrategySupport.java index 633e50e09b..99c7ff95ed 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditStrategySupport.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/AuditStrategySupport.java @@ -19,7 +19,6 @@ import lombok.AccessLevel; import lombok.Getter; import org.openehealth.ipf.commons.audit.AuditContext; -import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; import org.openehealth.ipf.commons.audit.model.AuditMessage; import java.util.Map; diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPHIExportBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPHIExportBuilder.java new file mode 100644 index 0000000000..7db1262c71 --- /dev/null +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPHIExportBuilder.java @@ -0,0 +1,38 @@ +/* + * Copyright 2025 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.core.atna.event; + +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.codes.EventActionCode; +import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; +import org.openehealth.ipf.commons.audit.types.EventType; +import org.openehealth.ipf.commons.audit.types.PurposeOfUse; +import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset; + +public class DefaultPHIExportBuilder extends PHIExportBuilder { + + public DefaultPHIExportBuilder(AuditContext auditContext, AuditDataset auditDataset, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventType, purposesOfUse); + } + + public DefaultPHIExportBuilder(AuditContext auditContext, AuditDataset auditDataset, EventActionCode eventActionCode, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventActionCode, eventType, purposesOfUse); + } + + public DefaultPHIExportBuilder(AuditContext auditContext, AuditDataset auditDataset, EventOutcomeIndicator eventOutcomeIndicator, String eventOutcomeDescription, EventActionCode eventActionCode, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventOutcomeIndicator, eventOutcomeDescription, eventActionCode, eventType, purposesOfUse); + } +} diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPHIImportBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPHIImportBuilder.java new file mode 100644 index 0000000000..adcfbc5ffb --- /dev/null +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPHIImportBuilder.java @@ -0,0 +1,39 @@ +/* + * Copyright 2025 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.core.atna.event; + +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.codes.EventActionCode; +import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; +import org.openehealth.ipf.commons.audit.types.EventType; +import org.openehealth.ipf.commons.audit.types.PurposeOfUse; +import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset; + +public class DefaultPHIImportBuilder extends PHIImportBuilder { + + + public DefaultPHIImportBuilder(AuditContext auditContext, AuditDataset auditDataset, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventType, purposesOfUse); + } + + public DefaultPHIImportBuilder(AuditContext auditContext, AuditDataset auditDataset, EventActionCode eventActionCode, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventActionCode, eventType, purposesOfUse); + } + + public DefaultPHIImportBuilder(AuditContext auditContext, AuditDataset auditDataset, EventOutcomeIndicator eventOutcomeIndicator, String eventOutcomeDescription, EventActionCode eventActionCode, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventOutcomeIndicator, eventOutcomeDescription, eventActionCode, eventType, purposesOfUse); + } +} diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPatientRecordEventBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPatientRecordEventBuilder.java new file mode 100644 index 0000000000..db26e53764 --- /dev/null +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultPatientRecordEventBuilder.java @@ -0,0 +1,34 @@ +/* + * Copyright 2025 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.core.atna.event; + +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.codes.EventActionCode; +import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator; +import org.openehealth.ipf.commons.audit.types.EventType; +import org.openehealth.ipf.commons.audit.types.PurposeOfUse; +import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset; + +public class DefaultPatientRecordEventBuilder extends PatientRecordEventBuilder { + + public DefaultPatientRecordEventBuilder(AuditContext auditContext, AuditDataset auditDataset, EventActionCode action, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, action, eventType, purposesOfUse); + } + + public DefaultPatientRecordEventBuilder(AuditContext auditContext, AuditDataset auditDataset, EventOutcomeIndicator eventOutcomeIndicator, String eventOutcomeDescription, EventActionCode action, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventOutcomeIndicator, eventOutcomeDescription, action, eventType, purposesOfUse); + } +} diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultQueryInformationBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultQueryInformationBuilder.java new file mode 100644 index 0000000000..3c90775b78 --- /dev/null +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DefaultQueryInformationBuilder.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.core.atna.event; + +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.types.EventType; +import org.openehealth.ipf.commons.audit.types.PurposeOfUse; +import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset; + +public class DefaultQueryInformationBuilder extends QueryInformationBuilder { + + public DefaultQueryInformationBuilder(AuditContext auditContext, AuditDataset auditDataset, EventType eventType, PurposeOfUse... purposesOfUse) { + super(auditContext, auditDataset, eventType, purposesOfUse); + } +} diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DicomInstancesAccessedAuditBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DicomInstancesAccessedAuditBuilder.java index b5c3635ccc..d9c626a74d 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DicomInstancesAccessedAuditBuilder.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/DicomInstancesAccessedAuditBuilder.java @@ -122,8 +122,4 @@ public T addTransferredStudyParticipantObject(final String studyId, final List> extends IHEAuditMessageBuilder { +public abstract class PHIExportBuilder> extends IHEAuditMessageBuilder { public PHIExportBuilder(AuditContext auditContext, AuditDataset auditDataset, @@ -128,8 +128,4 @@ public T addExportedEntity( return self(); } - @Override - public void validate() { - super.validate(); - } } \ No newline at end of file diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PHIImportBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PHIImportBuilder.java index 4df0b283a1..395550850c 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PHIImportBuilder.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PHIImportBuilder.java @@ -38,7 +38,7 @@ * @author Christian Ohr * @since 3.5 */ -public class PHIImportBuilder> extends IHEAuditMessageBuilder { +public abstract class PHIImportBuilder> extends IHEAuditMessageBuilder { public PHIImportBuilder(AuditContext auditContext, @@ -119,8 +119,4 @@ public T addImportedEntity( return self(); } - @Override - public void validate() { - super.validate(); - } } diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PatientRecordEventBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PatientRecordEventBuilder.java index c5271953f0..46675e5ed5 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PatientRecordEventBuilder.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/PatientRecordEventBuilder.java @@ -38,7 +38,7 @@ * @author Christian Ohr * @since 3.5 */ -public class PatientRecordEventBuilder> extends IHEAuditMessageBuilder { +public abstract class PatientRecordEventBuilder> extends IHEAuditMessageBuilder { private static final Pattern PATIENT_ID_PATTERN = Pattern.compile("^.+?\\^\\^\\^.*?&.+?&ISO(\\^.*){0,4}$"); diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/QueryInformationBuilder.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/QueryInformationBuilder.java index a815436562..f57fbde7f1 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/QueryInformationBuilder.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/atna/event/QueryInformationBuilder.java @@ -39,7 +39,7 @@ * @author Christian Ohr * @since 3.5 */ -public class QueryInformationBuilder> extends IHEAuditMessageBuilder { +public abstract class QueryInformationBuilder> extends IHEAuditMessageBuilder { public QueryInformationBuilder(AuditContext auditContext, AuditDataset auditDataset, @@ -150,8 +150,4 @@ public T setQueryParameters( return self(); } - @Override - public void validate() { - super.validate(); - } } diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainException.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainException.java index 20053238c9..fc3c038b74 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainException.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainException.java @@ -19,7 +19,6 @@ * @author Dmytro Rud */ public class ChainException extends RuntimeException { - private static final long serialVersionUID = 8260494759500343474L; public ChainException(String message) { super(message); diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtils.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtils.java index f8336ebd4d..71e3818861 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtils.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtils.java @@ -30,7 +30,7 @@ */ public class ChainUtils { - private static final transient Logger LOG = LoggerFactory.getLogger(ChainUtils.class); + private static final Logger log = LoggerFactory.getLogger(ChainUtils.class); /** * Extends an initial chain with elements from a custom collection. @@ -59,7 +59,7 @@ public static List createChain(List initial, Collect // check whether element with this ID is already in the chain if (chainIds.contains(cid)) { - LOG.debug("Element {} is already in the chain, ignore it", cid); + log.debug("Element {} is already in the chain, ignore it", cid); iter.remove(); successful = true; continue; @@ -73,10 +73,10 @@ public static List createChain(List initial, Collect (c.getBefore().contains(other.getId()) && !(other.getAfter().contains(cid))) || (c.getAfter().contains(other.getId()) && !(other.getBefore().contains(cid))) ) - .collect(Collectors.toList()); + .toList(); if (!unprocessedDependencies.isEmpty()) { - LOG.debug("Element {} depends on {}", cid, + log.debug("Element {} depends on {}", cid, unprocessedDependencies.stream() .map(Chainable::getId) .collect(Collectors.joining(" "))); @@ -91,12 +91,12 @@ public static List createChain(List initial, Collect var beforeIndices = c.getBefore().stream() .map(chainIds::indexOf) .filter(value -> value >= 0) - .collect(Collectors.toList()); + .toList(); var afterIndices = c.getAfter().stream() .map(chainIds::indexOf) .filter(value -> value >= 0) - .collect(Collectors.toList()); + .toList(); var minBeforePosition = 0; var maxAfterPosition = 0; @@ -123,12 +123,12 @@ public static List createChain(List initial, Collect chain.add(position, c); chainIds.add(position, cid); iter.remove(); - LOG.debug("Inserted element {} at position {}", cid, position); + log.debug("Inserted element {} at position {}", cid, position); successful = true; } if (successful) { - LOG.debug("Iteration result: {} elements in the chain, {} elements left", chain.size(), unprocessed.size()); + log.debug("Iteration result: {} elements in the chain, {} elements left", chain.size(), unprocessed.size()); } else { throw new ChainException("Cannot build a chain, probably there is a dependency loop"); } diff --git a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/payload/PayloadLoggerBase.java b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/payload/PayloadLoggerBase.java index 6afb1878a8..aa5a19cad4 100644 --- a/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/payload/PayloadLoggerBase.java +++ b/commons/ihe/core/src/main/java/org/openehealth/ipf/commons/ihe/core/payload/PayloadLoggerBase.java @@ -68,7 +68,7 @@ * @author Dmytro Rud */ abstract public class PayloadLoggerBase { - private static final transient Logger LOG = LoggerFactory.getLogger(PayloadLoggerBase.class); + private static final Logger log = LoggerFactory.getLogger(PayloadLoggerBase.class); private static final AtomicLong SEQUENCE_ID_GENERATOR = new AtomicLong(0L); @@ -97,15 +97,15 @@ protected void doLogPayload(T context, String charsetName, String... payloadPiec return; } if ((errorCountLimit >= 0) && (errorCount.get() >= errorCountLimit)) { - LOG.warn("Error count limit has bean reached, reset the counter to enable further trials"); + log.warn("Error count limit has bean reached, reset the counter to enable further trials"); return; } if (Boolean.getBoolean(PROPERTY_CONSOLE)) { // use regular Java logging - if (LOG.isDebugEnabled()) { + if (log.isDebugEnabled()) { var output = String.join("", payloadPieces); - LOG.debug(output); + log.debug(output); } } else { // compute the file path and write payload pieces into this file @@ -121,7 +121,7 @@ protected void doLogPayload(T context, String charsetName, String... payloadPiec errorCount.set(0); } catch (IOException e) { errorCount.incrementAndGet(); - LOG.warn("Cannot write into " + path, e); + log.warn("Cannot write into {}", path, e); } } } @@ -129,7 +129,7 @@ protected void doLogPayload(T context, String charsetName, String... payloadPiec public boolean canProcess() { if ((!enabled) || Boolean.getBoolean(PROPERTY_DISABLED)) { - LOG.trace("Message payload logging is disabled"); + log.trace("Message payload logging is disabled"); return false; } return true; diff --git a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/HL7DTMTest.java b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/HL7DTMTest.java index 1c7488f3fb..bd9d5e5af4 100644 --- a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/HL7DTMTest.java +++ b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/HL7DTMTest.java @@ -25,11 +25,35 @@ public class HL7DTMTest { @Test - public void testToZonedDateTime() throws DataTypeException { + public void testToZonedDateTimeWithoutTimezone() throws DataTypeException { assertEquals(ZonedDateTime.parse("2007-08-10T14:09:00+00:00").toInstant(), HL7DTM.toZonedDateTime("20070810140900").toInstant()); } + @Test + public void testToZonedDateTimeWithTimezone() throws DataTypeException { + assertEquals(ZonedDateTime.parse("2007-08-10T14:09:00+01:00").toInstant(), + HL7DTM.toZonedDateTime("20070810140900+0100").toInstant()); + } + + @Test + public void testToZonedDateTimeWithoutSeconds() throws DataTypeException { + assertEquals(ZonedDateTime.parse("2007-08-10T14:09:00+00:00").toInstant(), + HL7DTM.toZonedDateTime("200708101409").toInstant()); + } + + @Test + public void testToZonedDateTimeWithoutMinutes() throws DataTypeException { + assertEquals(ZonedDateTime.parse("2007-08-10T14:00:00+00:00").toInstant(), + HL7DTM.toZonedDateTime("2007081014").toInstant()); + } + + @Test + public void testToZonedDateTimeWithoutHours() throws DataTypeException { + assertEquals(ZonedDateTime.parse("2007-08-10T00:00:00+00:00").toInstant(), + HL7DTM.toZonedDateTime("20070810+0000").toInstant()); + } + @Test public void testToSimpleString() { assertEquals("20070810140900", HL7DTM.toSimpleString(ZonedDateTime.parse("2007-08-10T14:09:00+00:00"))); diff --git a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/InteractionIdTest.java b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/InteractionIdTest.java index 32c54bac61..2db3022829 100644 --- a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/InteractionIdTest.java +++ b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/InteractionIdTest.java @@ -75,9 +75,9 @@ enum Interactions implements InteractionId { Interaction2("int2", "description2"); @Getter - private String name; + private final String name; @Getter - private String description; + private final String description; } @@ -99,9 +99,9 @@ enum Interactions implements InteractionId { Interaction4("int4", "description4"); @Getter - private String name; + private final String name; @Getter - private String description; + private final String description; } diff --git a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/atna/MockedAuditMessageQueue.java b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/atna/MockedAuditMessageQueue.java index 10e2fcdcdd..244a222e3a 100644 --- a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/atna/MockedAuditMessageQueue.java +++ b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/atna/MockedAuditMessageQueue.java @@ -40,10 +40,11 @@ public class MockedAuditMessageQueue implements AbstractMockedAuditMessageQueue { private static final String NEW_VALIDATION_SCHEMA = "/atna2.xsd"; - private XsdValidator validator = new XsdValidator(); + private final XsdValidator validator = new XsdValidator(); private final boolean needValidation; @Getter + final List messages = Collections.synchronizedList(new ArrayList<>()); public MockedAuditMessageQueue() { diff --git a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtilsTest.java b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtilsTest.java index a89c390b49..09f660609b 100644 --- a/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtilsTest.java +++ b/commons/ihe/core/src/test/java/org/openehealth/ipf/commons/ihe/core/chain/ChainUtilsTest.java @@ -82,9 +82,7 @@ public void testBeforeEqualsToAfter() { new MyChainable("c4", "c2", ""), new MyChainable("c5", "i4", "i4") // should fail, Before==After ); - Assertions.assertThrows(ChainException.class, () -> { - doTest(custom, "dummy"); - }); + Assertions.assertThrows(ChainException.class, () -> doTest(custom, "dummy")); } @@ -97,9 +95,7 @@ public void testBeforeGreaterThanAfter() { new MyChainable("c4", "c2", ""), new MyChainable("c5", "i3", "i4") // should fail, Before>After ); - Assertions.assertThrows(ChainException.class, () -> { - doTest(custom, "dummy"); - }); + Assertions.assertThrows(ChainException.class, () -> doTest(custom, "dummy")); } @@ -110,9 +106,7 @@ public void testDependencyLoop() { new MyChainable("c2", "c1", "c3"), new MyChainable("c3", "c1", "c2") ); - Assertions.assertThrows(ChainException.class, () -> { - doTest(custom, "dummy"); - }); + Assertions.assertThrows(ChainException.class, () -> doTest(custom, "dummy")); } } diff --git a/commons/ihe/fhir/core/pom.xml b/commons/ihe/fhir/core/pom.xml index ad697c0269..39c38ecf71 100644 --- a/commons/ihe/fhir/core/pom.xml +++ b/commons/ihe/fhir/core/pom.xml @@ -16,17 +16,6 @@ ca.uhn.hapi.fhir hapi-fhir-server - - - com.github.bbottema - emailaddress-rfc2822 - - - - - com.github.bbottema - emailaddress-rfc2822 - 2.3.1 ca.uhn.hapi.fhir @@ -63,6 +52,7 @@ com.nimbusds nimbus-jose-jwt + true org.apache.httpcomponents.client5 @@ -102,11 +92,6 @@ net.java.quickcheck quickcheck - - ca.uhn.hapi.fhir - hapi-fhir-structures-dstu3 - test - ca.uhn.hapi.fhir hapi-fhir-structures-r4 diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractBundleProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractBundleProvider.java index 5c3eee990f..fad921c496 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractBundleProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractBundleProvider.java @@ -85,8 +85,8 @@ public String getUuid() { public void sortIfApplicable(List resources) { if (sort && headers.containsKey(FHIR_REQUEST_PARAMETERS)) { var searchParameters = headers.get(FHIR_REQUEST_PARAMETERS); - if (searchParameters instanceof FhirSearchAndSortParameters) { - ((FhirSearchAndSortParameters)searchParameters).sort(resources); + if (searchParameters instanceof FhirSearchAndSortParameters fhirSearchAndSortParameters) { + fhirSearchAndSortParameters.sort(resources); } } } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractPlainProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractPlainProvider.java index 6557d3e5cf..90937acf29 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractPlainProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/AbstractPlainProvider.java @@ -41,7 +41,7 @@ */ public abstract class AbstractPlainProvider extends FhirProvider { - private static final Logger LOG = LoggerFactory.getLogger(AbstractPlainProvider.class); + private static final Logger log = LoggerFactory.getLogger(AbstractPlainProvider.class); private RequestConsumer consumer; @@ -62,14 +62,14 @@ public void setConsumer(RequestConsumer consumer) { throw new IllegalStateException("This provider is already used by a different consumer: " + consumer); } this.consumer = consumer; - LOG.info("Connected consumer {} to provider {}", consumer, this); + log.info("Connected consumer {} to provider {}", consumer, this); } @Override public void unsetConsumer(RequestConsumer consumer) { if (this.consumer == consumer) { this.consumer = null; - LOG.info("Disconnected consumer {} from provider {}", consumer, this); + log.info("Disconnected consumer {} from provider {}", consumer, this); } } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/ApacheHttpRequest5.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/ApacheHttpRequest5.java index b1b7532a2c..c157f81a04 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/ApacheHttpRequest5.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/ApacheHttpRequest5.java @@ -23,7 +23,6 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.routing.RoutingSupport; import org.apache.hc.core5.http.ClassicHttpRequest; -import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpException; diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/DefaultFhirRegistry.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/DefaultFhirRegistry.java index 90f38c41b2..e6ecdc7146 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/DefaultFhirRegistry.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/DefaultFhirRegistry.java @@ -33,7 +33,7 @@ */ public class DefaultFhirRegistry implements FhirRegistry { - private static final Logger LOG = LoggerFactory.getLogger(DefaultFhirRegistry.class); + private static final Logger log = LoggerFactory.getLogger(DefaultFhirRegistry.class); private static final Map registries = new ConcurrentHashMap<>(); @@ -61,33 +61,33 @@ public static FhirRegistry removeFhirRegistry(String name) { @Override public void register(Object resourceProvider) { - if (!(resourceProvider instanceof FhirProvider) || ((FhirProvider)resourceProvider).requiresRegistration()) { + if (!(resourceProvider instanceof FhirProvider fhirProvider) || fhirProvider.requiresRegistration()) { if (resourceProviders.add(resourceProvider)) { for (var servlet : servlets) { servlet.registerProvider(resourceProvider); } } else { - LOG.info("Resource Provider {} was already registered. Ignored registration.", resourceProvider); + log.info("Resource Provider {} was already registered. Ignored registration.", resourceProvider); } } } @Override public void unregister(Object resourceProvider) { - if (!(resourceProvider instanceof FhirProvider) || ((FhirProvider)resourceProvider).requiresDeregistration()) { + if (!(resourceProvider instanceof FhirProvider fhirProvider) || fhirProvider.requiresDeregistration()) { if (resourceProviders.remove(resourceProvider)) { for (var provider : servlets) { provider.unregisterProvider(resourceProvider); } } else { - LOG.info("Resource Provider {} was not registered. Ignored deregistration.", resourceProvider); + log.info("Resource Provider {} was not registered. Ignored deregistration.", resourceProvider); } } } @Override public void register(RestfulServer servlet) { - LOG.debug("Registering FHIR servlet with name {}. Providers registered so far: {}", + log.debug("Registering FHIR servlet with name {}. Providers registered so far: {}", servlet.getServletName(), resourceProviders.size()); servlets.add(servlet); servlet.registerProviders(resourceProviders); @@ -95,7 +95,7 @@ public void register(RestfulServer servlet) { @Override public void unregister(RestfulServer servlet) { - LOG.debug("Unregistering FHIR Servlet with name {} and {} connected providers", + log.debug("Unregistering FHIR Servlet with name {} and {} connected providers", servlet.getServletName(), resourceProviders.size()); servlets.remove(servlet); servlet.unregisterProviders(resourceProviders); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/EagerBundleProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/EagerBundleProvider.java index 500d06bb4f..f2aac672a8 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/EagerBundleProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/EagerBundleProvider.java @@ -16,6 +16,7 @@ package org.openehealth.ipf.commons.ihe.fhir; +import lombok.NonNull; import org.hl7.fhir.instance.model.api.IBaseResource; import java.util.List; @@ -41,7 +42,7 @@ public EagerBundleProvider(RequestConsumer consumer, boolean sort, Object payloa } @Override - public List getResources(int fromIndex, int toIndex) { + public @NonNull List getResources(int fromIndex, int toIndex) { var resources = fetchResources(); return resources.subList(fromIndex, Math.min(toIndex, resources.size())); } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java index 456cf533d1..5351d0f82e 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/FhirProvider.java @@ -19,7 +19,6 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import javax.security.cert.X509Certificate; import jakarta.servlet.http.HttpServletRequest; import java.io.Serializable; import java.util.*; diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/HttpClient5Builder.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/HttpClient5Builder.java index 335b9d556f..e00f7e70aa 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/HttpClient5Builder.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/HttpClient5Builder.java @@ -21,7 +21,7 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; -import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.client5.http.ssl.TlsSocketStrategy; import org.apache.hc.core5.http.HttpHost; import java.util.function.Consumer; @@ -69,8 +69,8 @@ public CloseableHttpClient build() { .build(); } - void setSSLSocketFactory(SSLConnectionSocketFactory sslSocketFactory) { - connectionManagerBuilder.setSSLSocketFactory(sslSocketFactory); + public void setSSLSocketFactory(TlsSocketStrategy tlsSocketStrategy) { + connectionManagerBuilder.setTlsSocketStrategy(tlsSocketStrategy); } } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IgBasedFhirContextSupplier.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IgBasedFhirContextSupplier.java index 7e9c8c4e98..807dfb0dcf 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IgBasedFhirContextSupplier.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IgBasedFhirContextSupplier.java @@ -42,7 +42,7 @@ public static FhirContext getContext(FhirContext fhirContext, String... igResour } var npmValidationSupport = new NpmPackageValidationSupport(fhirContext); - for (String igResource : igResources) { + for (var igResource : igResources) { npmValidationSupport.loadPackageFromClasspath(igResource); } @@ -53,8 +53,8 @@ public static FhirContext getContext(FhirContext fhirContext, String... igResour new InMemoryTerminologyServerValidationSupport(fhirContext))); return fhirContext.setFhirValidatorFactory(ctx -> { - FhirValidator validator = new FhirValidator(ctx); - FhirInstanceValidator instanceValidator = new FhirInstanceValidator(validationSupport); + var validator = new FhirValidator(ctx); + var instanceValidator = new FhirInstanceValidator(validationSupport); validator.registerValidatorModule(instanceValidator); return validator; }); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IpfFhirServlet.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IpfFhirServlet.java index d61d52996f..d62b43eb6b 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IpfFhirServlet.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/IpfFhirServlet.java @@ -50,7 +50,7 @@ */ public class IpfFhirServlet extends RestfulServer { - private static final Logger LOG = LoggerFactory.getLogger(IpfFhirServlet.class); + private static final Logger log = LoggerFactory.getLogger(IpfFhirServlet.class); private static final String SERVLET_FHIR_VERSION_PARAMETER_NAME = "fhirVersion"; private static final String SERVLET_LOGGING_PARAMETER_NAME = "logging"; @@ -134,7 +134,7 @@ public void init(ServletConfig config) throws ServletException { throw new ServletException(e); } - LOG.debug("Initializing IpfFhirServlet {}", servletName); + log.debug("Initializing IpfFhirServlet {}", servletName); if (config.getInitParameter(SERVLET_FHIR_VERSION_PARAMETER_NAME) != null) { fhirVersion = FhirVersionEnum.valueOf(config.getInitParameter(SERVLET_FHIR_VERSION_PARAMETER_NAME)); @@ -177,11 +177,11 @@ public void destroy() { try { registry.unregister(this); } catch (Exception e) { - LOG.warn("Problem while unregistering servlet {}", getServletName(), e); + log.warn("Problem while unregistering servlet {}", getServletName(), e); } } super.destroy(); - LOG.info("Destroyed IpfFhirServlet [{}]", getServletName()); + log.info("Destroyed IpfFhirServlet [{}]", getServletName()); } /** diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/LazyBundleProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/LazyBundleProvider.java index 6fe36cbea6..8d108385ed 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/LazyBundleProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/LazyBundleProvider.java @@ -20,6 +20,7 @@ import com.google.common.collect.Range; import com.google.common.collect.RangeSet; import com.google.common.collect.TreeRangeSet; +import lombok.NonNull; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +51,7 @@ */ public class LazyBundleProvider extends AbstractBundleProvider { - private static final Logger LOG = LoggerFactory.getLogger(LazyBundleProvider.class); + private static final Logger log = LoggerFactory.getLogger(LazyBundleProvider.class); private final boolean cacheResults; private int size = -1; @@ -84,27 +85,27 @@ public LazyBundleProvider(RequestConsumer consumer, boolean cacheResults, boolea } @Override - public List getResources(int fromIndex, int toIndex) { + public @NonNull List getResources(int fromIndex, int toIndex) { if (!cacheResults) { var result = getPartialResult(fromIndex, toIndex); sortIfApplicable(result); return result; } - LOG.debug("Cached results contain the following ranges: {}. Requesting resources from index {} to {}", resultRanges, fromIndex, toIndex); + log.debug("Cached results contain the following ranges: {}. Requesting resources from index {} to {}", resultRanges, fromIndex, toIndex); var wanted = Range.closedOpen(fromIndex, toIndex); var needed = resultRanges.required(wanted); - LOG.debug("Requiring the following ranges {}", needed); + log.debug("Requiring the following ranges {}", needed); for (var requiredRange : needed.asDescendingSetOfRanges()) { - LOG.debug("Now requesting the following range {}", requiredRange); + log.debug("Now requesting the following range {}", requiredRange); var results = getPartialResult(requiredRange.lowerEndpoint(), requiredRange.upperEndpoint()); - LOG.debug("Got back a list of size {}", results.size()); + log.debug("Got back a list of size {}", results.size()); if (!results.isEmpty()) { cacheAll(requiredRange.lowerEndpoint(), results); // Take care, potentially less elements than requested have been retrieved resultRanges.add(Range.closedOpen(requiredRange.lowerEndpoint(), requiredRange.lowerEndpoint() + results.size())); } } - LOG.debug("Cached results now contain the following ranges: {}", resultRanges); + log.debug("Cached results now contain the following ranges: {}", resultRanges); // Everything went OK, return whatever we got return cachedResults.subList(fromIndex, Math.min(cachedResults.size(), Math.min(cachedResults.size(), toIndex))); @@ -130,7 +131,7 @@ public Integer size() { private void cacheAll(int fromIndex, List resources) { if (cachedResults.size() <= fromIndex) { for (var i = cachedResults.size(); i < fromIndex; i++) { - LOG.debug("Adding null for index {}", i); + log.debug("Adding null for index {}", i); cachedResults.add(null); } cachedResults.addAll(resources); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/MethanolHttpResponse.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/MethanolHttpResponse.java index 986cc576cf..d311170d1f 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/MethanolHttpResponse.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/MethanolHttpResponse.java @@ -45,7 +45,7 @@ public MethanolHttpResponse(HttpResponse response, StopWatch stopWa * Buffers the response entity. This is usually only called when HAPI client interceptors * want to do some logging or response capturing. * - * @throws IOException + * @throws IOException IOException */ @Override public void bufferEntity() throws IOException { diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/QueryClientRequestFactory.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/QueryClientRequestFactory.java index ff06387502..e043bcf340 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/QueryClientRequestFactory.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/QueryClientRequestFactory.java @@ -42,14 +42,13 @@ public QueryClientRequestFactory(Class type, Class b @Override public IClientExecutable, T> getClientExecutable(IGenericClient client, Object requestData, Map parameters) { IQuery query; - if (requestData instanceof ICriterion) { + if (requestData instanceof ICriterion criterion) { query = client.search() .forResource(type) - .where((ICriterion) requestData); - } else if (requestData instanceof ICriterion[]) { + .where(criterion); + } else if (requestData instanceof ICriterion[] criteria) { query = client.search() .forResource(type); - ICriterion[] criteria = (ICriterion[]) requestData; if (criteria.length > 0) { query = query.where(criteria[0]); if (criteria.length > 1) { diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SharedFhirProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SharedFhirProvider.java index 5426af7692..3bb0814b87 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SharedFhirProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SharedFhirProvider.java @@ -45,7 +45,7 @@ */ public abstract class SharedFhirProvider extends FhirProvider { - private static final Logger LOG = LoggerFactory.getLogger(SharedFhirProvider.class); + private static final Logger log = LoggerFactory.getLogger(SharedFhirProvider.class); private FhirContext fhirContext; private final List consumers = new ArrayList<>(); @@ -115,7 +115,7 @@ public void setConsumer(RequestConsumer consumer) { throw new IllegalStateException("Consumer has a different FhirContext than the others: " + consumer); } consumers.add(consumer); - LOG.info("Connected consumer {} to provider {}", consumer, this); + log.info("Connected consumer {} to provider {}", consumer, this); } boolean conflictingFhirContext(FhirContext otherFhirContext) { @@ -130,7 +130,7 @@ boolean conflictingFhirContext(FhirContext otherFhirContext) { @Override public void unsetConsumer(RequestConsumer consumer) { if (consumers.remove(consumer)) { - LOG.info("Disconnected consumer {} from provider {}", consumer, this); + log.info("Disconnected consumer {} from provider {}", consumer, this); } if (consumers.isEmpty()) { fhirContext = null; diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SpringCachePagingProvider.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SpringCachePagingProvider.java index a5ed4a8849..ecbe564a21 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SpringCachePagingProvider.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SpringCachePagingProvider.java @@ -22,6 +22,7 @@ import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; @@ -82,7 +83,7 @@ public String storeResultList(RequestDetails requestDetails, IBundleProvider bun } @Override - public IBundleProvider retrieveResultList(RequestDetails requestDetails, String id) { + public IBundleProvider retrieveResultList(RequestDetails requestDetails, @NonNull String id) { return distributed ? deserialize(cache.get(id, List.class)) : cache.get(id, IBundleProvider.class); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareApacheRestfulClient5Factory.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareApacheRestfulClient5Factory.java index 5f0362839a..e139d7859b 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareApacheRestfulClient5Factory.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareApacheRestfulClient5Factory.java @@ -23,8 +23,10 @@ import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder; +import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy; +import org.apache.hc.client5.http.ssl.HttpsSupport; import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.ssl.SSLContexts; import org.apache.hc.core5.util.Timeout; import org.openehealth.ipf.commons.ihe.fhir.translation.FhirSecurityInformation; @@ -139,14 +141,14 @@ public ApacheFhirSecurityInformation(boolean secure, SSLContext sslContext, Host @Override public void configureHttpClientBuilder(HttpClient5Builder builder) { if (isSecure()) { - var connectionSocketFactoryBuilder = SSLConnectionSocketFactoryBuilder.create().useSystemProperties(); - if (getSslContext() != null) { - connectionSocketFactoryBuilder.setSslContext(getSslContext()); - } - if (getHostnameVerifier() != null) { - connectionSocketFactoryBuilder.setHostnameVerifier(getHostnameVerifier()); - } - builder.setSSLSocketFactory(connectionSocketFactoryBuilder.build()); + var sslContext = getSslContext() != null ? + getSslContext() : + SSLContexts.createSystemDefault(); + var hostnameVerifier = getHostnameVerifier() != null ? + getHostnameVerifier() : + HttpsSupport.getDefaultHostnameVerifier(); + var tlsStrategy = new DefaultClientTlsStrategy(sslContext, hostnameVerifier); + builder.setSSLSocketFactory(tlsStrategy); } } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareMethanolRestfulClientFactory.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareMethanolRestfulClientFactory.java index d53107dbe4..47831a2023 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareMethanolRestfulClientFactory.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/SslAwareMethanolRestfulClientFactory.java @@ -126,7 +126,7 @@ protected synchronized Methanol getNativeHttpClient() { .autoAcceptEncoding(true) .proxy(proxy != null ? ProxySelector.of(proxy) : ProxySelector.getDefault()); if (executor != null) { - builder = builder.executor(executor); + builder.executor(executor); } // Chance to override or instrument httpClient = customizeHttpClientBuilder(builder).build(); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/AbstractFhirAuditStrategy.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/AbstractFhirAuditStrategy.java index 745806f0bb..d893b4e16d 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/AbstractFhirAuditStrategy.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/AbstractFhirAuditStrategy.java @@ -44,6 +44,16 @@ protected AbstractFhirAuditStrategy(boolean serverSide) { super(serverSide); } + @Override + public void doAudit(AuditContext auditContext, T auditDataset) { + try { + FhirContextHolder.setCurrentContext(auditDataset.getFhirContext()); + super.doAudit(auditContext, auditDataset); + } finally { + FhirContextHolder.remove(); + } + } + @Override public T enrichAuditDatasetFromRequest(T auditDataset, Object request, Map parameters) { @@ -89,15 +99,15 @@ public EventOutcomeIndicator getEventOutcomeIndicator(T auditDataset, Object res * @return event outcome code */ protected EventOutcomeIndicator getEventOutcomeCodeFromResource(T auditDataset, IBaseResource resource) { - return resource instanceof IBaseOperationOutcome ? - getEventOutcomeCodeFromOperationOutcome(auditDataset.getFhirContext(), (O)resource) : + return resource instanceof IBaseOperationOutcome outcome ? + getEventOutcomeCodeFromOperationOutcome(auditDataset.getFhirContext(), (O)outcome) : EventOutcomeIndicator.Success; } @Override public String getEventOutcomeDescription(T auditDataset, Object response) { - return response instanceof IBaseOperationOutcome ? - getEventOutcomeDescriptionFromOperationOutcome(auditDataset.getFhirContext(), (O)response) : + return response instanceof IBaseOperationOutcome outcome ? + getEventOutcomeDescriptionFromOperationOutcome(auditDataset.getFhirContext(), (O)outcome) : null; } diff --git a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/FhirContextHolder.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirContextHolder.java similarity index 90% rename from commons/audit/src/main/java/org/openehealth/ipf/commons/audit/FhirContextHolder.java rename to commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirContextHolder.java index 36e0e8b952..d7f1a5239a 100644 --- a/commons/audit/src/main/java/org/openehealth/ipf/commons/audit/FhirContextHolder.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirContextHolder.java @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.openehealth.ipf.commons.audit; +package org.openehealth.ipf.commons.ihe.fhir.audit; import ca.uhn.fhir.context.FhirContext; +/** + * Thread-local holder for a FhirContext instance + */ public class FhirContextHolder { private static final ThreadLocal currentFhirContext = new ThreadLocal<>(); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirContextThreadLocalAccessor.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirContextThreadLocalAccessor.java new file mode 100644 index 0000000000..33aa9dbb56 --- /dev/null +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirContextThreadLocalAccessor.java @@ -0,0 +1,51 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.audit; + +import ca.uhn.fhir.context.FhirContext; +import io.micrometer.context.ThreadLocalAccessor; + +/** + * ThreadLocalAccessor for a {@link FhirContextHolder}. Register an instance + * to the {@link org.openehealth.ipf.commons.audit.AuditContext} using + * {@link io.micrometer.context.ContextRegistry#registerThreadLocalAccessor(ThreadLocalAccessor)} + * to be able to reuse a predefined {@link FhirContext} for audit record serialization via + * {@link org.openehealth.ipf.commons.ihe.fhir.audit.protocol.AbstractFhirRestTLSAuditRecordSender} subclasses. + */ +public class FhirContextThreadLocalAccessor implements ThreadLocalAccessor { + + public static final String KEY = "fhir.context"; + + @Override + public Object key() { + return KEY; + } + + @Override + public FhirContext getValue() { + return FhirContextHolder.get(); + } + + @Override + public void setValue(FhirContext value) { + FhirContextHolder.setCurrentContext(value); + } + + @Override + public void setValue() { + FhirContextHolder.remove(); + } +} diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirQueryAuditStrategy.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirQueryAuditStrategy.java index ee1c9a305a..4c4fbce6ac 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirQueryAuditStrategy.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/FhirQueryAuditStrategy.java @@ -22,7 +22,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Map; -import java.util.stream.Collectors; import static org.openehealth.ipf.commons.ihe.fhir.Constants.HTTP_QUERY; diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericFhirAuditStrategy.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericFhirAuditStrategy.java index 1b8df93bcb..7bd048ba0a 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericFhirAuditStrategy.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericFhirAuditStrategy.java @@ -78,12 +78,12 @@ public GenericFhirAuditDataset enrichAuditDatasetFromRequest(GenericFhirAuditDat auditDataset.setOperation(operation); // Resource in the request? Extract Patient ID and Sensitivity at this point - if (request instanceof IDomainResource) { - addResourceData(auditDataset, (IDomainResource) request); - } else if (request instanceof IBaseBinary) { - addResourceData(auditDataset, (IBaseBinary) request); - } else if (request instanceof IIdType) { - auditDataset.setResourceId(((IIdType) request).toUnqualifiedVersionless()); + if (request instanceof IDomainResource domainResource) { + addResourceData(auditDataset, domainResource); + } else if (request instanceof IBaseBinary binary) { + addResourceData(auditDataset, binary); + } else if (request instanceof IIdType id) { + auditDataset.setResourceId(id.toUnqualifiedVersionless()); } // For instance-level operations e.g. PUT, DELETE, EXTENDED_OPERATION_INSTANCE: set resource ID and patient ID @@ -99,10 +99,10 @@ public GenericFhirAuditDataset enrichAuditDatasetFromRequest(GenericFhirAuditDat } // Domain Resource in the request? Extract Patient ID and Sensitivity at this point - if (request instanceof IDomainResource) { - addResourceData(auditDataset, (IDomainResource) request); - } else if (request instanceof IIdType) { - auditDataset.setResourceId((IIdType) request); + if (request instanceof IDomainResource domainResource) { + addResourceData(auditDataset, domainResource); + } else if (request instanceof IIdType id) { + auditDataset.setResourceId(id); } if (requestDetails != null && requestDetails.getRestOperationType() != null) { @@ -132,10 +132,9 @@ public GenericFhirAuditDataset enrichAuditDatasetFromRequest(GenericFhirAuditDat @Override public boolean enrichAuditDatasetFromResponse(GenericFhirAuditDataset auditDataset, Object response, AuditContext auditContext) { // Domain Resource in the request? Extract Patient ID and Sensitivity at this point - if (response instanceof IDomainResource) { - addResourceData(auditDataset, (IDomainResource) response); - } - if (response instanceof MethodOutcome methodOutcome) { + if (response instanceof IDomainResource domainResource) { + addResourceData(auditDataset, domainResource); + } else if (response instanceof MethodOutcome methodOutcome) { if (methodOutcome.getCreated() != null && methodOutcome.getCreated()) { auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success); } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericPatientIdExtractor.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericPatientIdExtractor.java index 363b367c8d..40be0913e7 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericPatientIdExtractor.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/GenericPatientIdExtractor.java @@ -50,7 +50,7 @@ public Optional patientReferenceFromResource(IBaseReso if (resource != null) { var resourceDefinition = fhirContext.getResourceDefinition(resource); if (PATIENT.equals(resourceDefinition.getName())) { - String id = resource.getIdElement().getIdPart(); + var id = resource.getIdElement().getIdPart(); return id != null ? Optional.of(patientReference(id)) : Optional.empty(); } else { try { @@ -69,7 +69,7 @@ public Optional patientReferenceFromResource(IBaseReso // There is probably a bug in HAPI FHIR for expressions like DocumentReference.subject.where(resolve() is Patient) // resolve() always returns null instead of the actual reference value, see FhirPathEngine#funcResolve() private String simplifyPath(String path) { - int idx = path.indexOf(".where"); + var idx = path.indexOf(".where"); return idx < 0 ? path : path.substring(0, idx); } diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/SwissEprFhirAuditDatasetEnricher.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/SwissEprFhirAuditDatasetEnricher.java index 46732c50c7..8918b361f5 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/SwissEprFhirAuditDatasetEnricher.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/SwissEprFhirAuditDatasetEnricher.java @@ -48,10 +48,10 @@ private static void enrichAuditDataset(AuditDataset auditDataset, Map parameters, String key, AuditDataset auditDataset) { if (auditDataset.getW3cTraceContextId() == null) { - Object value = parameters.get(key); + var value = parameters.get(key); if (value != null) { - Map> headers = (Map>) value; - for (String name : headers.keySet()) { + var headers = (Map>) value; + for (var name : headers.keySet()) { if ("traceparent".equalsIgnoreCase(name)) { auditDataset.setW3cTraceContextId(headers.get(name).get(0)); return; diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractor.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractor.java index d488b7c6f9..4c6bbb6df4 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractor.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractor.java @@ -19,7 +19,7 @@ public class BalpJwtClaimsExtractor { - private static final Logger LOG = LoggerFactory.getLogger(BalpJwtClaimsExtractor.class); + private static final Logger log = LoggerFactory.getLogger(BalpJwtClaimsExtractor.class); public Optional extractId(JWT jwt, BalpJwtExtractorProperties balpJwtExtractorProperties) { return Optional.ofNullable(extractStringClaimFromJWT(jwt, balpJwtExtractorProperties.getIdPath())); @@ -82,31 +82,31 @@ public Optional extractBppcAcp(JWT jwt, BalpJwtExtractorProperties balpJ } private String extractStringClaimFromJWT(JWT jwt, String[] expressions){ - Optional finalClaimForExpression = getFinalClaimSet(jwt, expressions); + var finalClaimForExpression = getFinalClaimSet(jwt, expressions); if (finalClaimForExpression.isPresent()) { - JWTClaimsSet claimsSet = finalClaimForExpression.get().jwtClaimsSet(); - String expression = finalClaimForExpression.get().expression(); + var claimsSet = finalClaimForExpression.get().jwtClaimsSet(); + var expression = finalClaimForExpression.get().expression(); try { return claimsSet.getStringClaim(expression); } catch (ParseException pe) { - LOG.warn("Not string claims present for expression key '" + expression + "'", pe); + log.warn("Not string claims present for expression key '{}'", expression, pe); } } return null; } private Set extractListClaimFromJWT(JWT jwt, String[] expressions){ - Optional finalClaimForExpression = getFinalClaimSet(jwt, expressions); + var finalClaimForExpression = getFinalClaimSet(jwt, expressions); if (finalClaimForExpression.isPresent()) { - JWTClaimsSet claimsSet = finalClaimForExpression.get().jwtClaimsSet(); - String expression = finalClaimForExpression.get().expression(); + var claimsSet = finalClaimForExpression.get().jwtClaimsSet(); + var expression = finalClaimForExpression.get().expression(); try { - List values = claimsSet.getListClaim(expression); + var values = claimsSet.getListClaim(expression); if (values != null && !values.isEmpty()) { return values.stream().map(Objects::toString).collect(Collectors.toSet()); } } catch (ParseException pe) { - LOG.warn("Not list claims present for expression key '" + expression + "'", pe); + log.warn("Not list claims present for expression key '{}'", expression, pe); } } return null; @@ -119,8 +119,8 @@ private Optional getFinalClaimSet(JWT jwt, String[] expressions) { for (var expression: expressions) { try { if (expression.contains(":")) { - JWTClaimsSet extracted = jwt.getJWTClaimsSet(); - List structure = List.of(expression.split("\\:")); + var extracted = jwt.getJWTClaimsSet(); + var structure = List.of(expression.split("\\:")); Iterator structureIterator = structure.listIterator(); String subExpression = null; while (structureIterator.hasNext()) { @@ -142,7 +142,7 @@ private Optional getFinalClaimSet(JWT jwt, String[] expressions) { } } } catch (ParseException pe) { - LOG.debug("Not claimset present for expression key: " + pe.getMessage()); + log.debug("Not claimset present for expression key: {}", pe.getMessage()); } } return Optional.empty(); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtParser.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtParser.java index fd2d438ade..05f446e844 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtParser.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtParser.java @@ -15,13 +15,13 @@ public class BalpJwtParser { private static final BalpJwtClaimsExtractor claimsExtractor = new BalpJwtClaimsExtractor(); - private static final Logger LOG = LoggerFactory.getLogger(BalpJwtParser.class); + private static final Logger log = LoggerFactory.getLogger(BalpJwtParser.class); public static Optional parseAuthorizationToBalpDataSet(String authenticationHeader, BalpJwtExtractorProperties balpJwtExtractorProperties) { - Optional jwt = parseAuthenticationToJWT(authenticationHeader); + var jwt = parseAuthenticationToJWT(authenticationHeader); return jwt.map(value -> { - BalpJwtDataSet balpJwtDataSet = parseJwtToBalpDataSet(value, claimsExtractor, balpJwtExtractorProperties); + var balpJwtDataSet = parseJwtToBalpDataSet(value, claimsExtractor, balpJwtExtractorProperties); balpJwtDataSet.setOpaqueJwt(authenticationHeader.substring(authenticationHeader.length() - 32)); return balpJwtDataSet; }); @@ -31,11 +31,11 @@ public static Optional parseAuthenticationToJWT(String authenticationHeader if (isBlank(authenticationHeader) || !authenticationHeader.toLowerCase().startsWith("bearer ")) return Optional.empty(); - String bearer = authenticationHeader.replaceAll("^[Bb][Ee][Aa][Rr][Ee][Rr][ ]+", ""); + var bearer = authenticationHeader.replaceAll("^[Bb][Ee][Aa][Rr][Ee][Rr][ ]+", ""); try { return Optional.of(JWTParser.parse(bearer)); } catch (ParseException pe) { - LOG.debug("Invalid JWT token", pe); + log.debug("Invalid JWT token", pe); return Optional.empty(); } } @@ -43,7 +43,7 @@ public static Optional parseAuthenticationToJWT(String authenticationHeader public static BalpJwtDataSet parseJwtToBalpDataSet(JWT jwt, BalpJwtClaimsExtractor claimsExtractor, BalpJwtExtractorProperties balpJwtExtractorProperties) { - BalpJwtDataSet balpJwtDataSet = new BalpJwtDataSet(); + var balpJwtDataSet = new BalpJwtDataSet(); claimsExtractor.extractIssuer(jwt, balpJwtExtractorProperties).ifPresent(balpJwtDataSet::setIssuer); claimsExtractor.extractId(jwt, balpJwtExtractorProperties).ifPresent(balpJwtDataSet::setJwtId); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/codes/FhirEventTypeCode.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/codes/FhirEventTypeCode.java index f831f25d6c..d281c2170d 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/codes/FhirEventTypeCode.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/codes/FhirEventTypeCode.java @@ -37,6 +37,7 @@ public enum FhirEventTypeCode implements EventType, EnumeratedCodedValue> void addJwtParticipant(D delegate, FhirAuditDataset auditDataset, AuditContext auditContext) { - BalpJwtExtractorProperties balpJwtExtractorProperties = (auditContext instanceof BalpAuditContext)? + var balpJwtExtractorProperties = (auditContext instanceof BalpAuditContext)? ((BalpAuditContext)auditContext).getBalpJwtExtractorProperties() : DEFAULT_BALP_JWT_EXTRACTOR_PROPERTIES; - Optional balpDataSet = BalpJwtParser.parseAuthorizationToBalpDataSet( + var balpDataSet = BalpJwtParser.parseAuthorizationToBalpDataSet( auditDataset.getAuthorization(), balpJwtExtractorProperties); balpDataSet.ifPresent(dataSet -> { if (isNotBlank(dataSet.getIheBppcPatientId())) { @@ -56,7 +54,7 @@ public static > void addJwtParticipant(D de null); } if (isNotBlank(dataSet.getIheIuaSubjectOrganizationId())) { - ActiveParticipantType ap = new ActiveParticipantType(dataSet.getIheIuaSubjectOrganizationId(), true); + var ap = new ActiveParticipantType(dataSet.getIheIuaSubjectOrganizationId(), true); ap.setUserName(dataSet.getIheIuaSubjectOrganization()); ap.getRoleIDCodes().add( ActiveParticipantRoleId.of(CodedValueType.of(dataSet.getIheIuaSubjectOrganizationId(), @@ -64,7 +62,7 @@ public static > void addJwtParticipant(D de delegate.addActiveParticipant(ap); } if (isNotBlank(dataSet.getJwtId())) { - ActiveParticipantType ap = new ActiveParticipantType(dataSet.getSubject(), true); + var ap = new ActiveParticipantType(dataSet.getSubject(), true); ap.getRoleIDCodes().add( ActiveParticipantRoleId.of(CodedValueType.of(dataSet.getJwtId(), OUSER_AGENT_TYPE_SYSTEM_NAME, "oAuth Token ID"))); @@ -84,7 +82,7 @@ public static > void addJwtParticipant(D de } delegate.addActiveParticipant(ap); if (isNotBlank(dataSet.getClientId())) { - ActiveParticipantType clientAp = new ActiveParticipantType( + var clientAp = new ActiveParticipantType( dataSet.getClientId(), !auditDataset.isServerSide()); clientAp.getRoleIDCodes().add( ActiveParticipantRoleId.of(CodedValueType.of(dataSet.getClientId(), @@ -92,7 +90,7 @@ public static > void addJwtParticipant(D de delegate.addActiveParticipant(clientAp); } } else if (isNotBlank(dataSet.getOpaqueJwt())) { - ActiveParticipantType ap = new ActiveParticipantType(dataSet.getSubject(), true); + var ap = new ActiveParticipantType(dataSet.getSubject(), true); ap.getRoleIDCodes().add( ActiveParticipantRoleId.of(CodedValueType.of(dataSet.getOpaqueJwt(), OUSER_AGENT_TYPE_OPAQUE_SYSTEM_NAME, "oAuth Opaque Token"))); @@ -100,8 +98,4 @@ public static > void addJwtParticipant(D de }); } - private BalpAuditContext balpAuditContext(AuditContext auditContext) { - return auditContext instanceof BalpAuditContext? (BalpAuditContext) auditContext : null; - } - } \ No newline at end of file diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSAuditRecordSender.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSAuditRecordSender.java index 91318a6c59..1977123eda 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSAuditRecordSender.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSAuditRecordSender.java @@ -16,14 +16,17 @@ package org.openehealth.ipf.commons.ihe.fhir.audit.protocol; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IRestfulClientFactory; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.impl.RestfulClientFactory; -import org.openehealth.ipf.commons.audit.*; +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.AuditMetadataProvider; +import org.openehealth.ipf.commons.audit.BalpAuditContext; +import org.openehealth.ipf.commons.audit.TlsParameters; import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol; import org.openehealth.ipf.commons.ihe.fhir.SslAwareAbstractRestfulClientFactory; +import org.openehealth.ipf.commons.ihe.fhir.audit.FhirContextHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +46,7 @@ public abstract class AbstractFhirRestTLSAuditRecordSender implements AuditTrans private static final String BASE_URL_FORMAT = "https://%s:%s/%s"; private FhirContext context; private TlsParameters tlsParameters; - private static final Logger LOG = LoggerFactory.getLogger(AbstractFhirRestTLSAuditRecordSender.class); + private static final Logger log = LoggerFactory.getLogger(AbstractFhirRestTLSAuditRecordSender.class); public AbstractFhirRestTLSAuditRecordSender(final FhirContext context, String baseUrl) { this.context = Objects.requireNonNull(context, "FhirContext must not be null"); @@ -73,19 +76,19 @@ public void send(AuditContext auditContext, var clientFactory = new TlsParametersAwareRestfulClientFactory( this.context, this.tlsParameters); - String baseUrl = String.format(BASE_URL_FORMAT, + var baseUrl = String.format(BASE_URL_FORMAT, auditContext.getAuditRepositoryHostName(), auditContext.getAuditRepositoryPort(), - (auditContext instanceof BalpAuditContext balpAuditContext)? + (auditContext instanceof BalpAuditContext balpAuditContext) ? balpAuditContext.getAuditRepositoryContextPath() : ""); createClient(clientFactory.getRestfulClientFactory(), baseUrl); } - MethodOutcome outcome = client + var outcome = client .create() .resource(auditEvent) .execute(); - LOG.debug("Audit Repository Response: {}", outcome.getResponseStatusCode()); + log.debug("Audit Repository Response: {}", outcome.getResponseStatusCode()); } private synchronized void createClient(IRestfulClientFactory restfulClientFactory, String baseUrl) { @@ -109,7 +112,7 @@ public TlsParametersAwareRestfulClientFactory(FhirContext fhirContext, TlsParame } private RestfulClientFactory createRestfulFactory(TlsParameters tlsParameters) { - SslAwareAbstractRestfulClientFactory factory = createSslAwareClientFactory(fhirContext); + var factory = createSslAwareClientFactory(fhirContext); factory.setServerValidationMode(ServerValidationModeEnum.NEVER); factory.initializeSecurityInformation(true, tlsParameters.getSSLContext(false), null, "", ""); diff --git a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/translation/InvalidUriSyntaxException.java b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/translation/InvalidUriSyntaxException.java index 3ef1ce8347..8fe0bdc1ef 100644 --- a/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/translation/InvalidUriSyntaxException.java +++ b/commons/ihe/fhir/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/translation/InvalidUriSyntaxException.java @@ -20,7 +20,6 @@ * */ public class InvalidUriSyntaxException extends FhirTranslationException { - private static final long serialVersionUID = 1336184411958893119L; public InvalidUriSyntaxException(String uri, Throwable cause) { super("URI " + uri + " has invalid syntax", cause); diff --git a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractorTest.java b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractorTest.java index dfd0bd7ff6..5cad1128b4 100644 --- a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractorTest.java +++ b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/auth/BalpJwtClaimsExtractorTest.java @@ -19,7 +19,7 @@ public class BalpJwtClaimsExtractorTest { private final BalpJwtGenerator balpJwtGenerator = new BalpJwtGenerator(); @Test - void testExtractor() throws Exception { + void testExtractor() { String generatedJwt = balpJwtGenerator.next(); JWT jwt = parseJWT(generatedJwt); @@ -72,37 +72,38 @@ private JWT parseJWT(String jwt) { } } - private static final String jwtAsString = "{\n" + - " \"aud\": \"master-realm\",\n" + - " \"sub\": \"f7fc9091-7b8a-42e0-a829-6c4ba22d38b2\",\n" + - " \"extensions\": {\n" + - " \"ihe_iua\": {\n" + - " \"subject_organization_id\": \"urn:oid:1.2.3.19161\",\n" + - " \"home_community_id\": \"urn:oid:1.2.3.43740\",\n" + - " \"national_provider_identifier\": \"urn:oid:1.2.3.48200\",\n" + - " \"subject_role\": [\n" + - " \"my-role-1\",\n" + - " \"my-role-2\"\n" + - " ],\n" + - " \"purpose_of_use\": [\n" + - " \"1.0.14265.1\",\n" + - " \"1.0.14265.2\"\n" + - " ],\n" + - " \"subject_name\": \"Dr. John Smith\",\n" + - " \"subject_organization\": \"Central Hospital\",\n" + - " \"person_id\": \"ABC9586\"\n" + - " },\n" + - " \"ihe_bppc\": {\n" + - " \"patient_id\": \"31494^^^&1.2.840.113619.6.197&ISO\",\n" + - " \"doc_id\": \"urn:oid:1.2.3.29380\",\n" + - " \"acp\": \"urn:oid:1.2.3.32574\"\n" + - " }\n" + - " },\n" + - " \"nbf\": 1706531233,\n" + - " \"iss\": \"https://localhost:8443/auth/realms/master\",\n" + - " \"typ\": \"Bearer\",\n" + - " \"exp\": 1706531353,\n" + - " \"jti\": \"e2093a98-9dcd-4947-b5cb-ee5b47c089c5\",\n" + - " \"client_id\": \"pbrBkyXksp\"\n" + - "}"; + private static final String jwtAsString = """ + { + "aud": "master-realm", + "sub": "f7fc9091-7b8a-42e0-a829-6c4ba22d38b2", + "extensions": { + "ihe_iua": { + "subject_organization_id": "urn:oid:1.2.3.19161", + "home_community_id": "urn:oid:1.2.3.43740", + "national_provider_identifier": "urn:oid:1.2.3.48200", + "subject_role": [ + "my-role-1", + "my-role-2" + ], + "purpose_of_use": [ + "1.0.14265.1", + "1.0.14265.2" + ], + "subject_name": "Dr. John Smith", + "subject_organization": "Central Hospital", + "person_id": "ABC9586" + }, + "ihe_bppc": { + "patient_id": "31494^^^&1.2.840.113619.6.197&ISO", + "doc_id": "urn:oid:1.2.3.29380", + "acp": "urn:oid:1.2.3.32574" + } + }, + "nbf": 1706531233, + "iss": "https://localhost:8443/auth/realms/master", + "typ": "Bearer", + "exp": 1706531353, + "jti": "e2093a98-9dcd-4947-b5cb-ee5b47c089c5", + "client_id": "pbrBkyXksp" + }"""; } diff --git a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSSenderIntegrationTest.java b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSSenderIntegrationTest.java index 93c9eab3f8..42a6da4c1a 100644 --- a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSSenderIntegrationTest.java +++ b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/protocol/AbstractFhirRestTLSSenderIntegrationTest.java @@ -25,7 +25,7 @@ public abstract class AbstractFhirRestTLSSenderIntegrationTest { protected DefaultBalpAuditContext auditContext; - private static final Logger LOG = LoggerFactory.getLogger(AbstractFhirRestTLSSenderIntegrationTest.class); + private static final Logger log = LoggerFactory.getLogger(AbstractFhirRestTLSSenderIntegrationTest.class); @BeforeEach public void setup() { @@ -55,9 +55,9 @@ TlsParameters setupDefaultTlsParameter() { @AfterEach public void tearDown() { - LOG.info("FhirAuditRepository size: " + FhirAuditRepository.getAuditEvents().size() + ". Cleanup...."); + log.info("FhirAuditRepository size: {}. Cleanup....", FhirAuditRepository.getAuditEvents().size()); FhirAuditRepository.clearAuditEvents(); - LOG.info("FhirAuditRepository size: " + FhirAuditRepository.getAuditEvents().size()); + log.info("FhirAuditRepository size: {}", FhirAuditRepository.getAuditEvents().size()); } @Test @@ -74,7 +74,7 @@ public void testTwoWayTLSFlooding() { } void sendAudit(String userName) { - LOG.debug("Sending audit record"); + log.debug("Sending audit record"); auditContext.audit( new ApplicationActivityBuilder.ApplicationStop(EventOutcomeIndicator.Success) .setAuditSource(auditContext) diff --git a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/queue/FhirDelegateMockedMessageQueue.java b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/queue/FhirDelegateMockedMessageQueue.java index 83bc681872..5c551845c3 100644 --- a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/queue/FhirDelegateMockedMessageQueue.java +++ b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/queue/FhirDelegateMockedMessageQueue.java @@ -5,7 +5,6 @@ import org.openehealth.ipf.commons.audit.queue.AbstractMockedAuditMessageQueue; import org.openehealth.ipf.commons.audit.queue.AsynchronousAuditMessageQueue; import org.openehealth.ipf.commons.audit.queue.AuditMessageQueue; -import org.openehealth.ipf.commons.audit.queue.SynchronousAuditMessageQueue; import java.util.List; diff --git a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/server/TLSBalpRepository.java b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/server/TLSBalpRepository.java index a2f5720d9c..38eaf9228b 100644 --- a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/server/TLSBalpRepository.java +++ b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/audit/server/TLSBalpRepository.java @@ -31,13 +31,12 @@ import org.slf4j.LoggerFactory; import java.io.Closeable; -import java.io.IOException; import static io.undertow.servlet.Servlets.*; public class TLSBalpRepository implements Closeable { - private static final Logger LOG = LoggerFactory.getLogger(TLSBalpRepository.class); + private static final Logger log = LoggerFactory.getLogger(TLSBalpRepository.class); protected final TlsParameters tlsParameters; private Undertow server; private final int httpsPort; @@ -53,13 +52,13 @@ public TLSBalpRepository(int httpsPort) { } @Override - public void close() throws IOException { + public void close() { stop(); } public void stop() { if (server != null) server.stop(); - LOG.info("successfully stopped FHIR Audit Server"); + log.info("successfully stopped FHIR Audit Server"); } public Undertow start() throws ServletException { @@ -85,7 +84,7 @@ public Undertow start() throws ServletException { .setHandler(path) .build(); server.start(); - LOG.info("successfully started FHIR Audit Server on port {}", httpsPort); + log.info("successfully started FHIR Audit Server on port {}", httpsPort); return server; } static class FhirServletInitiator implements InstanceFactory { diff --git a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/extension/FhirAuditRepository.java b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/extension/FhirAuditRepository.java index 23e419bc45..4b41998196 100644 --- a/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/extension/FhirAuditRepository.java +++ b/commons/ihe/fhir/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/extension/FhirAuditRepository.java @@ -3,10 +3,6 @@ import io.undertow.Handlers; import io.undertow.Undertow; import io.undertow.UndertowOptions; -import io.undertow.server.HttpHandler; -import io.undertow.server.handlers.PathHandler; -import io.undertow.servlet.api.DeploymentInfo; -import io.undertow.servlet.api.DeploymentManager; import io.undertow.servlet.api.InstanceFactory; import io.undertow.servlet.api.InstanceHandle; import net.java.quickcheck.generator.PrimitiveGenerators; diff --git a/commons/ihe/fhir/r4/audit/pom.xml b/commons/ihe/fhir/r4/audit/pom.xml index dac8c29fda..29f1bad764 100644 --- a/commons/ihe/fhir/r4/audit/pom.xml +++ b/commons/ihe/fhir/r4/audit/pom.xml @@ -25,12 +25,6 @@ test - - - org.springframework - spring-core - test - org.easymock easymock diff --git a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java index a89994e44a..b80fc6899f 100644 --- a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java +++ b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java @@ -38,6 +38,7 @@ public enum Interactions implements FhirInteractionId fhirTransactionConfiguration; } diff --git a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81AuditStrategy.java b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81AuditStrategy.java index ea34050148..1d71b398ec 100644 --- a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81AuditStrategy.java +++ b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81AuditStrategy.java @@ -46,8 +46,7 @@ public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirAuditEvent @Override public boolean enrichAuditDatasetFromResponse(FhirAuditEventQueryAuditDataset auditDataset, Object response, AuditContext auditContext) { - if (response instanceof Bundle) { - var bundle = (Bundle) response; + if (response instanceof Bundle bundle) { bundle.getEntry().stream() .filter(bundleEntryComponent -> bundleEntryComponent.getResource() instanceof AuditEvent) .map(Bundle.BundleEntryComponent::getFullUrl) diff --git a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java index d2f2278e9e..a7c1e5d7ab 100644 --- a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java +++ b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java @@ -28,7 +28,7 @@ * @author Christian Ohr * @since 3.6 */ -public class Iti81ClientRequestFactory extends QueryClientRequestFactory { +public class Iti81ClientRequestFactory extends QueryClientRequestFactory { public Iti81ClientRequestFactory() { super(AuditEvent.class, Bundle.class); diff --git a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81SearchParameters.java b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81SearchParameters.java index c6f4c295d5..0a2650faf2 100644 --- a/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81SearchParameters.java +++ b/commons/ihe/fhir/r4/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81SearchParameters.java @@ -37,8 +37,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @since 3.6 @@ -83,11 +82,17 @@ public Optional> comparatorFor(String paramName) { } private static final Comparator CP_DATE = nullsLast(comparing(AuditEvent::getRecorded)); - private static final Comparator CP_ADDRESS = nullsLast(comparing(auditEvent -> { - if (!auditEvent.hasAgent()) return null; - var agent = auditEvent.getAgentFirstRep(); - if (!agent.hasNetwork()) return null; - return agent.getNetwork().getAddressElement().getValueNotNull(); - })); + private static final Comparator CP_ADDRESS = comparing( + Iti81SearchParameters::getNetworkAddress, nullsLast(naturalOrder())); + + private static String getNetworkAddress(AuditEvent auditEvent) { + if (auditEvent.hasAgent()) { + var agent = auditEvent.getAgentFirstRep(); + if (agent.hasNetwork()) { + return agent.getNetwork().getAddressElement().getValueNotNull(); + } + } + return null; + } } diff --git a/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/FhirToXacmlTranslator.groovy b/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/FhirToXacmlTranslator.groovy index 9d8101c85f..5b083f51e7 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/FhirToXacmlTranslator.groovy +++ b/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/FhirToXacmlTranslator.groovy @@ -134,7 +134,7 @@ class FhirToXacmlTranslator { * @return PPQ-2 request POJO */ XACMLPolicyQueryType translatePpq5To2Request(String httpQuery) { - List params = URLEncodedUtils.parse(httpQuery, StandardCharsets.UTF_8); + List params = URLEncodedUtils.parse(httpQuery, StandardCharsets.UTF_8) def policySetId = params.find { it.name == Consent.SP_IDENTIFIER }?.value if (policySetId) { return ppqMessageCreator.createPolicyQuery([policySetId]) diff --git a/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/XacmlToFhirTranslator.groovy b/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/XacmlToFhirTranslator.groovy index af80ea304e..fa9d30524d 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/XacmlToFhirTranslator.groovy +++ b/commons/ihe/fhir/r4/chppqm/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/chppqm/translation/XacmlToFhirTranslator.groovy @@ -219,7 +219,7 @@ class XacmlToFhirTranslator { * Rethrows a UnknownPolicySetIdFault as a FHIR exception. */ static void translateUnknownPolicySetIdFault(UnknownPolicySetIdFaultMessage fault) { - throw new ResourceNotFoundException("Unknown policy set " + fault.getFaultInfo().getMessage()); + throw new ResourceNotFoundException("Unknown policy set " + fault.getFaultInfo().getMessage()) } /** diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmConsentCreator.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmConsentCreator.java index 20c09ac1f5..574410f40f 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmConsentCreator.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmConsentCreator.java @@ -45,7 +45,7 @@ private static Consent createConsent( Date endDate, List purposesOfUse) { - Consent consent = new Consent() + var consent = new Consent() .addIdentifier(new Identifier() .setType(new CodeableConcept(new Coding() .setSystem(ChPpqmUtils.CodingSystems.CONSENT_IDENTIFIER_TYPE) diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmUtils.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmUtils.java index 208a5a97ea..b49ef4f4cd 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmUtils.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/ChPpqmUtils.java @@ -18,12 +18,9 @@ import ca.uhn.fhir.context.FhirContext; import lombok.experimental.UtilityClass; -import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Consent; -import org.hl7.fhir.r4.model.Identifier; import org.openehealth.ipf.commons.ihe.fhir.IgBasedFhirContextSupplier; import java.io.IOException; @@ -33,7 +30,6 @@ /** * @author Dmytro Rud - * @since */ @UtilityClass public class ChPpqmUtils { @@ -73,18 +69,18 @@ public static class Profiles { } public static class CodingSystems { - public static String CONSENT_IDENTIFIER_TYPE = "http://fhir.ch/ig/ch-epr-fhir/CodeSystem/PpqmConsentIdentifierType"; - public static String GLN = "urn:oid:2.51.1.3"; + public static final String CONSENT_IDENTIFIER_TYPE = "http://fhir.ch/ig/ch-epr-fhir/CodeSystem/PpqmConsentIdentifierType"; + public static final String GLN = "urn:oid:2.51.1.3"; } public static class ConsentIdTypes { - public static String POLICY_SET_ID = "policySetId"; - public static String TEMPLATE_ID = "templateId"; + public static final String POLICY_SET_ID = "policySetId"; + public static final String TEMPLATE_ID = "templateId"; } public static String extractConsentId(Consent consent, String idType) { - for (Identifier identifier : consent.getIdentifier()) { - for (Coding coding : identifier.getType().getCoding()) { + for (var identifier : consent.getIdentifier()) { + for (var coding : identifier.getType().getCoding()) { if (ChPpqmUtils.CodingSystems.CONSENT_IDENTIFIER_TYPE.equalsIgnoreCase(coding.getSystem()) && idType.equals(coding.getCode())) { @@ -102,8 +98,8 @@ public static String extractConsentIdFromUrl(String url) { if (url.contains("#")) { url = url.substring(0, url.indexOf('#')); } - List params = URLEncodedUtils.parse(url, StandardCharsets.UTF_8); - for (NameValuePair param : params) { + var params = URLEncodedUtils.parse(url, StandardCharsets.UTF_8); + for (var param : params) { if (Consent.SP_IDENTIFIER.equals(param.getName())) { return param.getValue(); } @@ -131,12 +127,12 @@ public static String createUrl(String consentId) { } public static Bundle createPpq4SubmitRequestBundle(Collection consents, Bundle.HTTPVerb httpMethod) { - Bundle bundle = new Bundle(); + var bundle = new Bundle(); bundle.setId(UUID.randomUUID().toString()); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.getMeta().addProfile(Profiles.FEED_REQUEST_BUNDLE); - for (Consent consent : consents) { - Bundle.BundleEntryComponent entry = new Bundle.BundleEntryComponent(); + for (var consent : consents) { + var entry = new Bundle.BundleEntryComponent(); entry.getRequest().setMethod(httpMethod); entry.setResource(consent); switch (httpMethod) { @@ -156,12 +152,12 @@ public static Bundle createPpq4SubmitRequestBundle(Collection consents, } public static Bundle createPpq4DeleteRequestBundle(Collection consentIds) { - Bundle bundle = new Bundle(); + var bundle = new Bundle(); bundle.setId(UUID.randomUUID().toString()); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.getMeta().addProfile(Profiles.FEED_REQUEST_BUNDLE); - for (String consentId : consentIds) { - Bundle.BundleEntryComponent entry = new Bundle.BundleEntryComponent(); + for (var consentId : consentIds) { + var entry = new Bundle.BundleEntryComponent(); entry.getRequest().setMethod(Bundle.HTTPVerb.DELETE); entry.getRequest().setUrl(createUrl(consentId)); bundle.getEntry().add(entry); diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3AuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3AuditStrategy.java index ce1a949833..40d10e3ecb 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3AuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3AuditStrategy.java @@ -18,7 +18,6 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import lombok.extern.slf4j.Slf4j; import org.hl7.fhir.r4.model.Consent; -import org.hl7.fhir.r4.model.Identifier; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.codes.EventActionCode; import org.openehealth.ipf.commons.ihe.fhir.Constants; @@ -43,7 +42,7 @@ public ChPpqmAuditDataset createAuditDataset() { @Override public ChPpqmAuditDataset enrichAuditDatasetFromRequest(ChPpqmAuditDataset auditDataset, Object request, Map parameters) { super.enrichAuditDatasetFromRequest(auditDataset, request, parameters); - String method = (String) parameters.get(Constants.HTTP_METHOD); + var method = (String) parameters.get(Constants.HTTP_METHOD); switch (method) { case "POST": auditDataset.setAction(EventActionCode.Create); @@ -65,15 +64,15 @@ public ChPpqmAuditDataset enrichAuditDatasetFromRequest(ChPpqmAuditDataset audit } private static void enrichAuditDatasetFromConsent(ChPpqmAuditDataset auditDataset, Object resource) { - Consent consent = (Consent) resource; + var consent = (Consent) resource; auditDataset.getPolicyAndPolicySetIds().add(ChPpqmUtils.extractConsentId(consent, ChPpqmUtils.ConsentIdTypes.POLICY_SET_ID)); - Identifier pid = consent.getPatient().getIdentifier(); + var pid = consent.getPatient().getIdentifier(); auditDataset.getPatientIds().add(String.format("%s^^^&%s&ISO", pid.getValue(), pid.getSystem().substring(8))); } @Override public boolean enrichAuditDatasetFromResponse(ChPpqmAuditDataset auditDataset, Object response, AuditContext auditContext) { - MethodOutcome methodOutcome = (MethodOutcome) response; + var methodOutcome = (MethodOutcome) response; if ((auditDataset.getAction() == EventActionCode.Update) && Boolean.TRUE.equals(methodOutcome.getCreated())) { auditDataset.setAction(EventActionCode.Create); } diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ClientAuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ClientAuditStrategy.java index 03a1143e60..3d365077c8 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ClientAuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ClientAuditStrategy.java @@ -19,7 +19,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIExportBuilder; import org.openehealth.ipf.commons.ihe.fhir.chppqm.ChPpqmAuditDataset; import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode.MobilePrivacyPolicyFeed; @@ -32,7 +32,7 @@ public ChPpq3ClientAuditStrategy() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, ChPpqmAuditDataset auditDataset) { - return new PHIExportBuilder<>(auditContext, auditDataset, MobilePrivacyPolicyFeed) + return new DefaultPHIExportBuilder(auditContext, auditDataset, MobilePrivacyPolicyFeed) .setPatient(auditDataset.getPatientId()) .addSecurityResourceParticipantObjects(ParticipantObjectIdType.of(MobilePrivacyPolicyFeed), auditDataset.getPolicyAndPolicySetIds()) .getMessages(); diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3RequestFactory.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3RequestFactory.java index 14c96e8dad..c6b98a2271 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3RequestFactory.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3RequestFactory.java @@ -33,24 +33,22 @@ public IClientExecutable getClientExecutable( Object requestData, Map parameters) { - String method = (String) parameters.get(Constants.HTTP_METHOD); - switch (method) { - case "POST": - return client.create().resource((Consent) requestData); - case "PUT": - Consent consent = (Consent) requestData; - String consentId = ChPpqmUtils.extractConsentId(consent, ChPpqmUtils.ConsentIdTypes.POLICY_SET_ID); - return client.update() - .resource(consent) - .conditional() - .where(Consent.IDENTIFIER.exactly().identifier(consentId)); - case "DELETE": - return client.delete() - .resourceConditionalByType(Consent.class) - .where(Consent.IDENTIFIER.exactly().identifier((String) requestData)); - default: - throw new RuntimeException("Unknown method: " + method); - } + var method = (String) parameters.get(Constants.HTTP_METHOD); + return switch (method) { + case "POST" -> client.create().resource((Consent) requestData); + case "PUT" -> { + var consent = (Consent) requestData; + var consentId = ChPpqmUtils.extractConsentId(consent, ChPpqmUtils.ConsentIdTypes.POLICY_SET_ID); + yield client.update() + .resource(consent) + .conditional() + .where(Consent.IDENTIFIER.exactly().identifier(consentId)); + } + case "DELETE" -> client.delete() + .resourceConditionalByType(Consent.class) + .where(Consent.IDENTIFIER.exactly().identifier((String) requestData)); + default -> throw new RuntimeException("Unknown method: " + method); + }; } } diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ResourceProvider.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ResourceProvider.java index 9f1d33020f..780085accd 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ResourceProvider.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ResourceProvider.java @@ -67,7 +67,7 @@ public MethodOutcome deleteConsent( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { - String consentId = ChPpqmUtils.extractConsentIdFromUrl(condition); + var consentId = ChPpqmUtils.extractConsentIdFromUrl(condition); return requestAction(consentId, null, httpServletRequest, httpServletResponse, requestDetails); } diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ServerAuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ServerAuditStrategy.java index a433622821..146531afc2 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ServerAuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3ServerAuditStrategy.java @@ -19,7 +19,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIImportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIImportBuilder; import org.openehealth.ipf.commons.ihe.fhir.chppqm.ChPpqmAuditDataset; import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode.MobilePrivacyPolicyFeed; @@ -32,7 +32,7 @@ public ChPpq3ServerAuditStrategy() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, ChPpqmAuditDataset auditDataset) { - return new PHIImportBuilder<>(auditContext, auditDataset, MobilePrivacyPolicyFeed) + return new DefaultPHIImportBuilder(auditContext, auditDataset, MobilePrivacyPolicyFeed) .setPatient(auditDataset.getPatientId()) .addSecurityResourceParticipantObjects(ParticipantObjectIdType.of(MobilePrivacyPolicyFeed), auditDataset.getPolicyAndPolicySetIds()) .getMessages(); diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3Validator.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3Validator.java index 5cf3ff44b8..ad02759726 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3Validator.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq3/ChPpq3Validator.java @@ -38,14 +38,14 @@ public void validateRequest(Object payload, Map parameters) { } private OperationOutcome doValidateRequest(Object payload, Map parameters) { - String method = parameters.get(Constants.HTTP_METHOD).toString(); + var method = parameters.get(Constants.HTTP_METHOD).toString(); switch (method) { case "POST": case "PUT": return validateProfileConformance((Resource) payload, ChPpqmUtils.TEMPLATE_PROFILE_URIS); case "DELETE": - String resourceId = (String) payload; + var resourceId = (String) payload; if (StringUtils.isBlank(resourceId)) { return new OperationOutcome() .addIssue(new OperationOutcome.OperationOutcomeIssueComponent() diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4AuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4AuditStrategy.java index 80f0b02df6..cb2864b65a 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4AuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4AuditStrategy.java @@ -43,9 +43,9 @@ public ChPpqmAuditDataset createAuditDataset() { @Override public ChPpqmAuditDataset enrichAuditDatasetFromRequest(ChPpqmAuditDataset auditDataset, Object request, Map parameters) { super.enrichAuditDatasetFromRequest(auditDataset, request, parameters); - Bundle bundle = (Bundle) request; + var bundle = (Bundle) request; if (!bundle.getEntry().isEmpty()) { - Bundle.HTTPVerb method = bundle.getEntry().get(0).getRequest().getMethod(); + var method = bundle.getEntry().get(0).getRequest().getMethod(); switch (method) { case POST: auditDataset.setAction(EventActionCode.Create); @@ -67,8 +67,8 @@ public ChPpqmAuditDataset enrichAuditDatasetFromRequest(ChPpqmAuditDataset audit } private static void extractConsentIdsFromEntryResources(ChPpqmAuditDataset auditDataset, Bundle bundle) { - for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { - Consent consent = (Consent) entry.getResource(); + for (var entry : bundle.getEntry()) { + var consent = (Consent) entry.getResource(); auditDataset.getPolicyAndPolicySetIds().add(ChPpqmUtils.extractConsentId(consent, ChPpqmUtils.ConsentIdTypes.POLICY_SET_ID)); } } @@ -76,10 +76,9 @@ private static void extractConsentIdsFromEntryResources(ChPpqmAuditDataset audit @Override public boolean enrichAuditDatasetFromResponse(ChPpqmAuditDataset auditDataset, Object response, AuditContext auditContext) { if (super.enrichAuditDatasetFromResponse(auditDataset, response, auditContext)) { - if (response instanceof Bundle) { - Bundle bundle = (Bundle) response; - for (Bundle.BundleEntryComponent entry : bundle.getEntry()) { - String status = entry.getResponse().getStatus(); + if (response instanceof Bundle bundle) { + for (var entry : bundle.getEntry()) { + var status = entry.getResponse().getStatus(); if ((status != null) && status.startsWith("2")) { if ((auditDataset.getAction() == EventActionCode.Update) && status.startsWith("201")) { auditDataset.setAction(EventActionCode.Create); diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ClientAuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ClientAuditStrategy.java index e73d17bb3a..c2fc831feb 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ClientAuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ClientAuditStrategy.java @@ -19,7 +19,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIExportBuilder; import org.openehealth.ipf.commons.ihe.fhir.chppqm.ChPpqmAuditDataset; import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode.MobilePrivacyPolicyBundleFeed; @@ -32,7 +32,7 @@ public ChPpq4ClientAuditStrategy() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, ChPpqmAuditDataset auditDataset) { - return new PHIExportBuilder<>(auditContext, auditDataset, MobilePrivacyPolicyBundleFeed) + return new DefaultPHIExportBuilder(auditContext, auditDataset, MobilePrivacyPolicyBundleFeed) .setPatient(auditDataset.getPatientId()) .addSecurityResourceParticipantObjects(ParticipantObjectIdType.of(MobilePrivacyPolicyBundleFeed), auditDataset.getPolicyAndPolicySetIds()) .getMessages(); diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ServerAuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ServerAuditStrategy.java index 6b5c3ca1ab..9d08d5c575 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ServerAuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4ServerAuditStrategy.java @@ -19,7 +19,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIImportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIImportBuilder; import org.openehealth.ipf.commons.ihe.fhir.chppqm.ChPpqmAuditDataset; import static org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode.MobilePrivacyPolicyBundleFeed; @@ -32,7 +32,7 @@ public ChPpq4ServerAuditStrategy() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, ChPpqmAuditDataset auditDataset) { - return new PHIImportBuilder<>(auditContext, auditDataset, MobilePrivacyPolicyBundleFeed) + return new DefaultPHIImportBuilder(auditContext, auditDataset, MobilePrivacyPolicyBundleFeed) .setPatient(auditDataset.getPatientId()) .addSecurityResourceParticipantObjects(ParticipantObjectIdType.of(MobilePrivacyPolicyBundleFeed), auditDataset.getPolicyAndPolicySetIds()) .getMessages(); diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4Validator.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4Validator.java index 04b72bfe6b..50765cb61d 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4Validator.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq4/ChPpq4Validator.java @@ -38,8 +38,8 @@ public void validateRequest(Object payload, Map parameters) { @Override public void validateResponse(Object payload, Map parameters) { - Bundle bundle = (Bundle) payload; - OperationOutcome outcome = validateProfileConformance(bundle, "http://hl7.org/fhir/StructureDefinition/Bundle"); + var bundle = (Bundle) payload; + var outcome = validateProfileConformance(bundle, "http://hl7.org/fhir/StructureDefinition/Bundle"); if (bundle.getType() != Bundle.BundleType.TRANSACTIONRESPONSE) { outcome.addIssue(new OperationOutcome.OperationOutcomeIssueComponent() .setSeverity(OperationOutcome.IssueSeverity.ERROR) diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5AuditStrategy.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5AuditStrategy.java index 3de5e2292f..1068cf1ec5 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5AuditStrategy.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5AuditStrategy.java @@ -19,7 +19,7 @@ import lombok.extern.slf4j.Slf4j; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; @@ -35,7 +35,7 @@ public ChPpq5AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder(auditContext, auditDataset, MobilePrivacyPolicyRetrieve) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, MobilePrivacyPolicyRetrieve) .addPatients(auditDataset.getPatientIds()) .setQueryParameters("MobilePrivacyPolicyQuery", MobilePrivacyPolicyQuery, diff --git a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5ResourceProvider.java b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5ResourceProvider.java index 90806f1918..9bc892c6d1 100644 --- a/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5ResourceProvider.java +++ b/commons/ihe/fhir/r4/chppqm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/chppqm/chppq5/ChPpq5ResourceProvider.java @@ -38,7 +38,7 @@ public IBundleProvider searchConsents( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { - ChPpq5SearchParameters searchParameters = new ChPpq5SearchParameters(getFhirContext(), patientId, consentId); + var searchParameters = new ChPpq5SearchParameters(getFhirContext(), patientId, consentId); return requestBundleProvider(null, searchParameters, ResourceType.Consent.name(), httpServletRequest, httpServletResponse, requestDetails); } diff --git a/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java b/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java index b30881ede8..422e688433 100644 --- a/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java +++ b/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java @@ -42,7 +42,7 @@ public class AbstractNamingSystemServiceImpl implements NamingSystemService { public void addNamingSystems(Bundle bundle) { this.namingSystems.merge(bundle.getIdElement().getIdPart(), setOfNamingSystems(bundle), (set1, set2) -> { - var result = new HashSet(set1); + var result = new HashSet<>(set1); result.addAll(set2); return result; }); diff --git a/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/IgBasedInstanceValidator.java b/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/IgBasedInstanceValidator.java index e35452448f..6023b7e633 100644 --- a/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/IgBasedInstanceValidator.java +++ b/commons/ihe/fhir/r4/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/IgBasedInstanceValidator.java @@ -18,11 +18,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ValidationResult; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.Resource; import org.openehealth.ipf.commons.ihe.fhir.FhirTransactionValidator; @@ -49,9 +46,9 @@ protected IgBasedInstanceValidator(FhirContext fhirContext) { * @return {@link OperationOutcome} containing or not containing validation errors (never null). */ protected OperationOutcome validateProfileConformance(Resource resource, Set allowedProfileUris) { - String profileUri = allowedProfileUris.iterator().next(); + var profileUri = allowedProfileUris.iterator().next(); if (profileUri.startsWith(STANDARD_PREFIX)) { - String expectedResourceType = profileUri.substring(STANDARD_PREFIX.length()); + var expectedResourceType = profileUri.substring(STANDARD_PREFIX.length()); if (resource.fhirType().equals(expectedResourceType)) { return doValidate(resource); } else { @@ -62,7 +59,7 @@ protected OperationOutcome validateProfileConformance(Resource resource, Set oAuthEventAgent = oAuthActiveParticipantToAgent(ap); + var oAuthEventAgent = oAuthActiveParticipantToAgent(ap); return oAuthEventAgent.orElseGet(() -> new AuditEvent.AuditEventAgentComponent() .setType(ap.getRoleIDCodes().isEmpty() ? null : codedValueTypeToCodeableConcept(ap.getRoleIDCodes().get(0), DCM_SYSTEM_NAME)) .setWho(new Reference().setDisplay(ap.getUserID())) @@ -152,9 +152,9 @@ protected AuditEvent.AuditEventAgentComponent activeParticipantToAgent(ActivePar } private Optional oAuthActiveParticipantToAgent(ActiveParticipantType ap) { - Optional oUser = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), OUSER_AGENT_TYPE_SYSTEM_NAME); + var oUser = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), OUSER_AGENT_TYPE_SYSTEM_NAME); if (oUser.isPresent()) { - AuditEvent.AuditEventAgentComponent agent = new AuditEvent.AuditEventAgentComponent() + var agent = new AuditEvent.AuditEventAgentComponent() .setType(systemAndCodeToCodeableConcept(OUSER_AGENT_TYPE_SYSTEM_NAME, OUSER_AGENT_TYPE_CODE, "information recipient")) .addPolicy(oUser.get()) .setName(ap.getUserName()) @@ -171,7 +171,7 @@ private Optional oAuthActiveParticipantToAg systemAndCodeToCodeableConcept(OUSER_AGENT_ROLE_SYSTEM_NAME, purpose, ""))); return Optional.of(agent); } - Optional oClient = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), DCM_SYSTEM_NAME); + var oClient = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), DCM_SYSTEM_NAME); if (oClient.isPresent()) { return Optional.of(new AuditEvent.AuditEventAgentComponent() .setType(systemAndCodeToCodeableConcept(DCM_SYSTEM_NAME, DCM_OCLIENT_CODE, "Application")) @@ -179,7 +179,7 @@ private Optional oAuthActiveParticipantToAg .setWho(new Reference().setIdentifier( new Identifier().setValue(oClient.get())).setDisplay(ap.getUserName()))); } - Optional opaqueToken = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), + var opaqueToken = getOAuthAttrFromKnownRoleIdCode(ap.getRoleIDCodes(), OUSER_AGENT_TYPE_OPAQUE_SYSTEM_NAME); if (opaqueToken.isPresent()) { return Optional.of(new AuditEvent.AuditEventAgentComponent() diff --git a/commons/ihe/fhir/r4/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java b/commons/ihe/fhir/r4/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java index 77f41eea3f..8d837be168 100644 --- a/commons/ihe/fhir/r4/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java +++ b/commons/ihe/fhir/r4/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java @@ -29,42 +29,41 @@ */ public class DefaultUriMapperTest { - private BidiMappingService mappingService; private DefaultUriMapper uriMapper; @BeforeEach public void setup() { - mappingService = new BidiMappingService(); + BidiMappingService mappingService = new BidiMappingService(); mappingService.setMappingScript(getClass().getResource("/mapping.map")); uriMapper = new DefaultUriMapper(mappingService, "uriToOid", "uriToNamespace"); } @Test - public void testTranslateOidUrn() throws Exception { + public void testTranslateOidUrn() { var oid = "1.2.3.4.5.6.7.8.9"; - assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).get()); + assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).orElse(null)); } @Test - public void testTranslateUriToOid() throws Exception { + public void testTranslateUriToOid() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/1"; - assertEquals("1.2.3.4", uriMapper.uriToOid(uri).get()); + assertEquals("1.2.3.4", uriMapper.uriToOid(uri).orElse(null)); } @Test - public void testTranslateUriToOidFails() throws Exception { + public void testTranslateUriToOidFails() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/9"; assertFalse(uriMapper.uriToOid(uri).isPresent()); } @Test - public void testTranslatePinUrn() throws Exception { + public void testTranslatePinUrn() { var namespace = "namespace"; - assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).get()); + assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).orElse(null)); } @Test - public void testTranslateUriToNamespace() throws Exception { + public void testTranslateUriToNamespace() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/1"; assertEquals("fhir1", uriMapper.uriToNamespace(uri).get()); uri = "http://org.openehealth/ipf/commons/ihe/fhir/9"; @@ -72,7 +71,7 @@ public void testTranslateUriToNamespace() throws Exception { } @Test - public void testTranslateNamespaceToUri() throws Exception { + public void testTranslateNamespaceToUri() { var namespace = "fhir1"; assertEquals("http://org.openehealth/ipf/commons/ihe/fhir/1", uriMapper.namespaceToUri(namespace)); } diff --git a/commons/ihe/fhir/r4/mhd/pom.xml b/commons/ihe/fhir/r4/mhd/pom.xml index 57aa799de5..2eae9d1500 100644 --- a/commons/ihe/fhir/r4/mhd/pom.xml +++ b/commons/ihe/fhir/r4/mhd/pom.xml @@ -32,12 +32,6 @@ hapi-fhir-validation-resources-r4 - - - org.springframework - spring-core - test - org.easymock easymock diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105AuditStrategy.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105AuditStrategy.java index f5949875bd..7e3f13cee9 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105AuditStrategy.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105AuditStrategy.java @@ -41,8 +41,8 @@ public Iti105AuditDataset createAuditDataset() { public Iti105AuditDataset enrichAuditDatasetFromRequest(Iti105AuditDataset auditDataset, Object request, Map parameters) { var dataset = super.enrichAuditDatasetFromRequest(auditDataset, request, parameters); - if (request instanceof DocumentReference) { - dataset.enrichDatasetFromDocumentReference((DocumentReference) request); + if (request instanceof DocumentReference documentReference) { + dataset.enrichDatasetFromDocumentReference(documentReference); } return dataset; } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105RequestFactory.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105RequestFactory.java index 5b6685ca66..b4aeb358a8 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105RequestFactory.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105RequestFactory.java @@ -16,7 +16,6 @@ package org.openehealth.ipf.commons.ihe.fhir.iti105; -import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.gclient.IClientExecutable; import org.hl7.fhir.r4.model.DocumentReference; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java index d99e6360d1..419d39b7a4 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java @@ -51,7 +51,6 @@ import java.util.Optional; import java.util.Scanner; import java.util.function.Function; -import java.util.stream.Collectors; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.*; @@ -65,7 +64,7 @@ */ public class Iti65Validator extends FhirTransactionValidator.Support { - private static final Logger LOG = LoggerFactory.getLogger(Iti65Validator.class); + private static final Logger log = LoggerFactory.getLogger(Iti65Validator.class); private static final String IHE_PROFILE_PREFIX = "http://ihe.net/fhir/StructureDefinition/"; private final FhirContext fhirContext; @@ -73,11 +72,11 @@ public class Iti65Validator extends FhirTransactionValidator.Support { public Iti65Validator(FhirContext fhirContext) { this.fhirContext = fhirContext; - LOG.info("Initializing Validator for ITI-65 bundles"); + log.info("Initializing Validator for ITI-65 bundles"); validationSupportv320 = loadStructureDefinitionsv320(new DefaultProfileValidationSupport(fhirContext), "Minimal"); validationSupportv320 = loadStructureDefinitionsv320(validationSupportv320, "Comprehensive"); validationSupportv320 = new CachingValidationSupport(validationSupportv320); - LOG.info("Initialized Validator for ITI-65 bundles"); + log.info("Initialized Validator for ITI-65 bundles"); } @Override @@ -184,26 +183,24 @@ protected void validateBundleConsistency320(Bundle bundle) { .flatMap(Collection::stream) .map(Bundle.BundleEntryComponent::getResource) .forEach(resource -> { - if (resource instanceof DocumentManifest) { - var dm = (DocumentManifest) resource; + if (resource instanceof DocumentManifest dm) { for (var content : dm.getContent()) { try { expectedReferenceFullUrls.add(content.getReference()); } catch (Exception ignored) { } } - patientReferences.add(getSubjectReference(resource, r -> dm.getSubject())); - } else if (resource instanceof DocumentReference) { - var dr = (DocumentReference) resource; + patientReferences.add(getSubjectReference(dm, DocumentManifest::getSubject)); + } else if (resource instanceof DocumentReference dr) { for (var content : dr.getContent()) { var url = content.getAttachment().getUrl(); if (!url.startsWith("http")) { expectedBinaryFullUrls.add(url); } } - patientReferences.add(getSubjectReference(resource, r -> ((DocumentReference) r).getSubject())); - } else if (resource instanceof ListResource) { - patientReferences.add(getSubjectReference(resource, r -> ((ListResource) r).getSubject())); + patientReferences.add(getSubjectReference(dr, DocumentReference::getSubject)); + } else if (resource instanceof ListResource listResource) { + patientReferences.add(getSubjectReference(listResource, ListResource::getSubject)); } else if (!(resource instanceof Binary)) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, @@ -291,7 +288,7 @@ protected void validateBundleConsistency421(Bundle bundle) { .map(Bundle.BundleEntryComponent::getResource) .map(ListResource.class::cast) .filter(this::isListSubmissionSet) - .collect(Collectors.toList()); + .toList(); if (submissionSets.size() != 1) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, @@ -317,8 +314,7 @@ protected void validateBundleConsistency421(Bundle bundle) { .flatMap(Collection::stream) .map(Bundle.BundleEntryComponent::getResource) .forEach(resource -> { - if (resource instanceof ListResource) { - var listResource = (ListResource) resource; + if (resource instanceof ListResource listResource) { if (isListSubmissionSet(listResource)) { for (var entry : listResource.getEntry()) { try { @@ -327,16 +323,15 @@ protected void validateBundleConsistency421(Bundle bundle) { } } } - patientReferences.add(getSubjectReference(resource, r -> listResource.getSubject())); - } else if (resource instanceof DocumentReference) { - var dr = (DocumentReference) resource; + patientReferences.add(getSubjectReference(listResource, ListResource::getSubject)); + } else if (resource instanceof DocumentReference dr) { for (var content : dr.getContent()) { var url = content.getAttachment().getUrl(); if (!url.startsWith("http")) { expectedBinaryFullUrls.add(url); } } - patientReferences.add(getSubjectReference(resource, r -> ((DocumentReference) r).getSubject())); + patientReferences.add(getSubjectReference(dr, DocumentReference::getSubject)); } else if (!(resource instanceof Binary)) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, @@ -413,7 +408,7 @@ private boolean isListSubmissionSet(ListResource listResource) { UNCONTAINED_COMPREHENSIVE_SUBMISSIONSET_TYPE_LIST.hasProfile(listResource); } - private String getSubjectReference(Resource resource, Function f) { + private String getSubjectReference(T resource, Function f) { var reference = f.apply(resource); if (reference == null) { throw FhirUtils.unprocessableEntity( diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java index 8e587b9654..ef5e5a9ffb 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java @@ -17,7 +17,6 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66DocumentManifestSearchParameters.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66DocumentManifestSearchParameters.java index 668ef23d74..37ae115ad8 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66DocumentManifestSearchParameters.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66DocumentManifestSearchParameters.java @@ -30,8 +30,7 @@ import java.util.*; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @since 3.6 @@ -92,23 +91,25 @@ public List getPatientIdParam() { } - private static final Comparator CP_CREATED = nullsLast(comparing(DocumentManifest::getCreated)); + private static final Comparator CP_CREATED = comparing( + DocumentManifest::getCreated, nullsLast(naturalOrder())); - private static final Comparator CP_AUTHOR = nullsLast(comparing(documentManifest -> { + private static final Comparator CP_AUTHOR = comparing( + Iti66DocumentManifestSearchParameters::getAuthorName, nullsLast(naturalOrder())); + + private static String getAuthorName(DocumentManifest documentManifest) { if (!documentManifest.hasAuthor()) return null; var author = documentManifest.getAuthorFirstRep(); - if (author.getResource() instanceof PractitionerRole) { - var practitionerRole = (PractitionerRole) author.getResource(); + if (author.getResource() instanceof PractitionerRole practitionerRole) { if (!practitionerRole.hasPractitioner()) return null; author = practitionerRole.getPractitioner(); } if (author.getResource() == null) return null; - if (author.getResource() instanceof Practitioner) { - var practitioner = (Practitioner) author.getResource(); + if (author.getResource() instanceof Practitioner practitioner) { if (!practitioner.hasName()) return null; var name = practitioner.getNameFirstRep(); return name.getFamilyElement().getValueNotNull() + name.getGivenAsSingleString(); } return null; - })); + } } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java index 5b24f728f1..5ea41760f6 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66SearchParameters.java @@ -16,23 +16,10 @@ package org.openehealth.ipf.commons.ihe.fhir.iti66; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.param.ReferenceAndListParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.StringParam; -import ca.uhn.fhir.rest.param.TokenParam; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.SuperBuilder; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Practitioner; import org.openehealth.ipf.commons.ihe.fhir.FhirSearchAndSortParameters; -import java.util.Collections; -import java.util.List; -import java.util.Set; - /** * Common SearchParameter base class for ITI-66 transactions * @param diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java index 91ab8a6355..719412d5ea 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java @@ -17,7 +17,6 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java index 85135642a2..01228d83f5 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ResourceProvider.java @@ -107,8 +107,8 @@ public IBundleProvider documentReferenceSearch( // Handle "related" parameters - ReferenceOrListParam relatedParam = new ReferenceOrListParam(); - TokenOrListParam relatedIdParam = new TokenOrListParam(); + var relatedParam = new ReferenceOrListParam(); + var relatedIdParam = new TokenOrListParam(); if (relatedRef != null) { relatedParam = relatedRef; } else if (relatedId != null) { diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java index 65fbcd9d79..a5cadbca7e 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67SearchParameters.java @@ -42,8 +42,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; import static org.openehealth.ipf.commons.ihe.fhir.iti67.Iti67ResourceProvider.STU3_INDEXED; /** @@ -119,24 +118,26 @@ public Optional> comparatorFor(String paramName) { return Optional.empty(); } - private static final Comparator CP_DATE = nullsLast(comparing(DocumentReference::getDate)); + private static final Comparator CP_DATE = comparing( + DocumentReference::getDate, nullsLast(naturalOrder())); - private static final Comparator CP_AUTHOR = nullsLast(comparing(documentReference -> { + private static final Comparator CP_AUTHOR = comparing( + Iti67SearchParameters::getAuthorName, nullsLast(naturalOrder())); + + private static String getAuthorName(DocumentReference documentReference) { if (!documentReference.hasAuthor()) return null; var author = documentReference.getAuthorFirstRep(); - if (author.getResource() instanceof PractitionerRole) { - var practitionerRole = (PractitionerRole) author.getResource(); + if (author.getResource() instanceof PractitionerRole practitionerRole) { if (!practitionerRole.hasPractitioner()) return null; - author = practitionerRole.getPractitioner(); + author = practitionerRole.getPractitioner(); } if (author.getResource() == null) return null; - if (author.getResource() instanceof Practitioner) { - var practitioner = (Practitioner) author.getResource(); + if (author.getResource() instanceof Practitioner practitioner) { if (!practitioner.hasName()) return null; var name = practitioner.getNameFirstRep(); return name.getFamilyElement().getValueNotNull() + name.getGivenAsSingleString(); } return null; - })); + } } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67StrictResourceProvider.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67StrictResourceProvider.java index cfef2d0935..01aaef0549 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67StrictResourceProvider.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67StrictResourceProvider.java @@ -88,8 +88,8 @@ public IBundleProvider documentReferenceSearch( .forEach(relatedTokenParam::addOr); } - ReferenceOrListParam relatedParam = new ReferenceOrListParam(); - TokenOrListParam relatedIdParam = new TokenOrListParam(); + var relatedParam = new ReferenceOrListParam(); + var relatedIdParam = new TokenOrListParam(); if (related != null) { related.getValuesAsQueryTokens().stream() .filter(referenceParam -> !DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())) diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java index 4bcfe8ce7e..4b2584008c 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java @@ -22,7 +22,6 @@ import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCodeRole; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpPHIExportBuilder; @@ -46,7 +45,7 @@ public Iti68AuditDataset enrichAuditDatasetFromRequest(Iti68AuditDataset auditDa @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, Iti68AuditDataset auditDataset) { - BalpPHIExportBuilder builder = new BalpPHIExportBuilder(auditContext, auditDataset, + var builder = new BalpPHIExportBuilder(auditContext, auditDataset, EventActionCode.Create, FhirEventTypeCode.MobileDocumentRetrieval) .setPatient(auditDataset.getPatientId()); diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68bin/Iti68BinaryServerAuditStrategy.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68bin/Iti68BinaryServerAuditStrategy.java index b6fcee9a98..217fe0d10d 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68bin/Iti68BinaryServerAuditStrategy.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68bin/Iti68BinaryServerAuditStrategy.java @@ -20,7 +20,6 @@ import org.openehealth.ipf.commons.audit.codes.EventActionCode; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpPHIExportBuilder; @@ -46,7 +45,7 @@ public FhirAuditDataset enrichAuditDatasetFromRequest(FhirAuditDataset auditData @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirAuditDataset auditDataset) { - BalpPHIExportBuilder builder = new BalpPHIExportBuilder(auditContext, auditDataset, + var builder = new BalpPHIExportBuilder(auditContext, auditDataset, EventActionCode.Create, FhirEventTypeCode.MobileDocumentRetrieval) .setPatient(auditDataset.getPatientId()); diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdConstants.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdConstants.java index 7c0d3cc349..0148117aca 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdConstants.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdConstants.java @@ -15,8 +15,6 @@ */ package org.openehealth.ipf.commons.ihe.fhir.mhd; -import org.hl7.fhir.r4.model.Coding; - interface MhdConstants { // Bundle Profiles V4 diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdValidator.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdValidator.java index bb95c76f02..32e748f01a 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdValidator.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/MhdValidator.java @@ -85,4 +85,13 @@ public void validateRequest(Object payload, Map parameters) { } } + @Override + public void validateResponse(Object payload, Map parameters) { + var resource = (IBaseResource) payload; + var validationResult = validator.validateWithResult(resource); + if (!validationResult.isSuccessful()) { + var operationOutcome = validationResult.toOperationOutcome(); + throw FhirUtils.exception(UnprocessableEntityException::new, operationOutcome, "Validation Failed"); + } + } } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/ComprehensiveProvideDocumentBundle.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/ComprehensiveProvideDocumentBundle.java index b92ecf3705..5afc06efcb 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/ComprehensiveProvideDocumentBundle.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/ComprehensiveProvideDocumentBundle.java @@ -17,8 +17,6 @@ import ca.uhn.fhir.model.api.annotation.ResourceDef; import org.hl7.fhir.r4.model.Binary; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Resource; import org.openehealth.ipf.commons.ihe.fhir.mhd.Mhd421; import org.openehealth.ipf.commons.ihe.fhir.support.FhirUtils; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/FolderList.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/FolderList.java index 3a658e25c6..749510fe51 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/FolderList.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/FolderList.java @@ -17,8 +17,6 @@ import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.ListResource; -import org.ietf.jgss.Oid; public abstract class FolderList> extends MhdList { diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MhdList.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MhdList.java index 4c0fd3c6ad..4451179aed 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MhdList.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MhdList.java @@ -20,7 +20,6 @@ import ca.uhn.fhir.model.api.annotation.Extension; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.util.ElementUtil; -import org.hl7.fhir.r4.model.Annotation; import org.hl7.fhir.r4.model.Base; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.ListResource; @@ -64,7 +63,7 @@ public List getDesignationType() { } public CodeableConcept addDesignationType() { - CodeableConcept codeableConcept = new CodeableConcept(); + var codeableConcept = new CodeableConcept(); addDesignationType(codeableConcept); return codeableConcept; } @@ -92,7 +91,7 @@ public CodeableConcept getDesignationTypeFirstRep() { public boolean hasDesignationType() { if (this.designationType == null) return false; - for (CodeableConcept item : this.designationType) + for (var item : this.designationType) if (!item.isEmpty()) return true; return false; @@ -111,10 +110,10 @@ public T setEntryUuidIdentifier(UUID uuid) { @Override public void copyValues(ListResource dst) { super.copyValues(dst); - MhdList mhdList = (MhdList) dst; + var mhdList = (MhdList) dst; if (designationType != null) { mhdList.designationType = new ArrayList<>(); - for (CodeableConcept i : designationType) + for (var i : designationType) mhdList.designationType.add(i.copy()); } } @@ -125,7 +124,7 @@ public boolean equalsDeep(Base other_) { return false; if (!(other_ instanceof MhdList)) return false; - MhdList o = (MhdList) other_; + var o = (MhdList) other_; return compareDeep(designationType, o.designationType, true); } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalDocumentReference.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalDocumentReference.java index 783a338505..6ecdd349f8 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalDocumentReference.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalDocumentReference.java @@ -16,12 +16,9 @@ package org.openehealth.ipf.commons.ihe.fhir.mhd.model; import ca.uhn.fhir.model.api.annotation.ResourceDef; -import org.hl7.fhir.r4.model.DocumentReference; import org.hl7.fhir.r4.model.Enumerations; -import org.openehealth.ipf.commons.ihe.fhir.mhd.Mhd421; import java.util.Date; -import java.util.UUID; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.MINIMAL_DOCUMENT_REFERENCE; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.MINIMAL_DOCUMENT_REFERENCE_PROFILE; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalSubmissionSetList.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalSubmissionSetList.java index 6fc0c11ba4..10496184d2 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalSubmissionSetList.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/MinimalSubmissionSetList.java @@ -16,7 +16,6 @@ package org.openehealth.ipf.commons.ihe.fhir.mhd.model; import ca.uhn.fhir.model.api.annotation.ResourceDef; -import org.hl7.fhir.r4.model.ListResource; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.MINIMAL_SUBMISSIONSET_TYPE_LIST; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.MINIMAL_SUBMISSIONSET_TYPE_LIST_PROFILE; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/Source.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/Source.java index f1e461b667..3545b52d8d 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/Source.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/Source.java @@ -19,7 +19,6 @@ import ca.uhn.fhir.model.api.annotation.DatatypeDef; import ca.uhn.fhir.model.api.annotation.Extension; import ca.uhn.fhir.util.ElementUtil; -import lombok.Getter; import org.hl7.fhir.r4.model.Base; import org.hl7.fhir.r4.model.Reference; @@ -66,9 +65,8 @@ public Source copy() { public boolean equalsDeep(Base other_) { if (!super.equalsDeep(other_)) return false; - if (!(other_ instanceof Source)) + if (!(other_ instanceof Source o)) return false; - Source o = (Source) other_; return compareDeep(authorOrg, o.authorOrg, true); } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/UncontainedComprehensiveSubmissionSetList.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/UncontainedComprehensiveSubmissionSetList.java index b0ef23da82..d7ad241421 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/UncontainedComprehensiveSubmissionSetList.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/mhd/model/UncontainedComprehensiveSubmissionSetList.java @@ -16,7 +16,6 @@ package org.openehealth.ipf.commons.ihe.fhir.mhd.model; import ca.uhn.fhir.model.api.annotation.ResourceDef; -import org.hl7.fhir.r4.model.ListResource; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.UNCONTAINED_COMPREHENSIVE_SUBMISSIONSET_TYPE_LIST; import static org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile.UNCONTAINED_COMPREHENSIVE_SUBMISSIONSET_TYPE_LIST_PROFILE; diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5AuditStrategy.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5AuditStrategy.java index 02c74ed0ab..aa5ad09b95 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5AuditStrategy.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5AuditStrategy.java @@ -22,7 +22,7 @@ import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCodeRole; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.model.TypeValuePairType; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.Constants; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; @@ -58,7 +58,7 @@ public AuditMessage[] makeAuditMessage(final AuditContext auditContext, if (endpointUrl != null && endpointUrl.lastIndexOf("$") >= 0) { operation = endpointUrl.substring(endpointUrl.lastIndexOf("$")); } - return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.QueryPharmacyDocumentsOverMhd) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.QueryPharmacyDocumentsOverMhd) .addPatients(auditDataset.getPatientIds()) .setQueryParameters( operation, @@ -97,11 +97,10 @@ public FhirQueryAuditDataset enrichAuditDatasetFromRequest(final FhirQueryAuditD if (tokenParams != null) { tokenParams.forEach(t -> addPatientId.accept(t.getValue(), t.getSystem())); } - } else if (request instanceof Parameters) { - final var bodyParameters = (Parameters) request; + } else if (request instanceof Parameters bodyParameters) { final var patientIdentifier = bodyParameters.getParameterValues(Pharm5ResourceProvider.SP_PATIENT_IDENTIFIER); - if (patientIdentifier instanceof StringType) { - final var parts = ((StringType) patientIdentifier).getValue().split("\\|"); + if (patientIdentifier instanceof StringType s) { + final var parts = s.getValue().split("\\|"); addPatientId.accept(parts[1], parts[0]); } } diff --git a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5ClientRequestFactory.java b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5ClientRequestFactory.java index 7b01961981..ef55239e14 100644 --- a/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5ClientRequestFactory.java +++ b/commons/ihe/fhir/r4/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pharm5/Pharm5ClientRequestFactory.java @@ -47,11 +47,11 @@ public class Pharm5ClientRequestFactory implements ClientRequestFactory CP_DATE = nullsLast(comparing(DocumentReference::getDate)); + private static final Comparator CP_DATE = comparing( + DocumentReference::getDate, nullsLast(naturalOrder())); - private static final Comparator CP_AUTHOR = nullsLast(comparing(documentReference -> { + private static final Comparator CP_AUTHOR = comparing( + Pharm5SearchParameters::getAuthorName, nullsLast(naturalOrder())); + + private static String getAuthorName(DocumentReference documentReference) { if (!documentReference.hasAuthor()) return null; var author = documentReference.getAuthorFirstRep(); - if (author.getResource() instanceof PractitionerRole) { - var practitionerRole = (PractitionerRole) author.getResource(); + if (author.getResource() instanceof PractitionerRole practitionerRole) { if (!practitionerRole.hasPractitioner()) return null; author = practitionerRole.getPractitioner(); } if (author.getResource() == null) return null; - if (author.getResource() instanceof Practitioner) { - var practitioner = (Practitioner) author.getResource(); + if (author.getResource() instanceof Practitioner practitioner) { if (!practitioner.hasName()) return null; var name = practitioner.getNameFirstRep(); return name.getFamilyElement().getValueNotNull() + name.getGivenAsSingleString(); } return null; - })); + } } diff --git a/commons/ihe/fhir/r4/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105ValidatorTest.java b/commons/ihe/fhir/r4/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105ValidatorTest.java index e5d8dd29d7..5c64364c07 100644 --- a/commons/ihe/fhir/r4/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105ValidatorTest.java +++ b/commons/ihe/fhir/r4/mhd/src/test/java/org/openehealth/ipf/commons/ihe/fhir/iti105/Iti105ValidatorTest.java @@ -14,8 +14,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfile; -import org.openehealth.ipf.commons.ihe.fhir.mhd.MhdProfiles; -import org.openehealth.ipf.commons.ihe.fhir.mhd.MhdValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +31,7 @@ public class Iti105ValidatorTest { - private static final Logger LOG = LoggerFactory.getLogger(Iti105ValidatorTest.class); + private static final Logger log = LoggerFactory.getLogger(Iti105ValidatorTest.class); static Iti105Validator iti105Validator; @@ -57,7 +55,7 @@ void testInvalidConformance() throws Exception { ); assertNotNull(exception); var oo = (OperationOutcome) exception.getOperationOutcome(); - oo.getIssue().forEach(ooc -> LOG.error(ooc.getSeverity().getDisplay() + " : " + ooc.getDiagnostics())); + oo.getIssue().forEach(ooc -> log.error("{} : {}", ooc.getSeverity().getDisplay(), ooc.getDiagnostics())); } private static DocumentReference validDocumentreference() throws NoSuchAlgorithmException { diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy b/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy index f5c64d0f63..4bf0c0541a 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy +++ b/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy @@ -53,7 +53,7 @@ import static java.util.Objects.requireNonNull */ class PdqResponseToPdqmResponseTranslator implements ToFhirTranslator { - private static final Logger LOG = LoggerFactory.getLogger(PdqResponseToPdqmResponseTranslator) + private static final Logger log = LoggerFactory.getLogger(PdqResponseToPdqmResponseTranslator) private final UriMapper uriMapper String pdqSupplierResourceIdentifierUri @@ -131,7 +131,7 @@ class PdqResponseToPdqmResponseTranslator implements ToFhirTranslator { if (resourcePid) { patient.setId(new IdType('Patient', resourcePid[1].value)) } else { - LOG.warn("No ID found with resource system URI {}", pdqSupplierResourceIdentifierUri) + log.warn("No ID found with resource system URI {}", pdqSupplierResourceIdentifierUri) } convertIdentifiers(pid[3](), patient.getIdentifier()) diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy b/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy index 9590168ac3..1cb5df8f26 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy +++ b/commons/ihe/fhir/r4/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy @@ -201,7 +201,7 @@ class PdqmRequestToPdqQueryTranslator implements FhirTranslator { } protected String convertBirthDate(DateAndListParam birthDateParam) { - var birthDate = firstOrNull(searchDateList(birthDateParam)) + def birthDate = firstOrNull(searchDateList(birthDateParam)) return birthDate ? FastDateFormat.getInstance('yyyyMMdd').format(birthDate) : null } diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/AdditionalResourceMetadataKeyEnum.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/AdditionalResourceMetadataKeyEnum.java new file mode 100644 index 0000000000..afe27085df --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/AdditionalResourceMetadataKeyEnum.java @@ -0,0 +1,26 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import org.hl7.fhir.r4.model.codesystems.MatchGrade; + +public abstract class AdditionalResourceMetadataKeyEnum { + + public static final ResourceMetadataKeyEnum ENTRY_MATCH_GRADE = + new ResourceMetadataKeyEnum<>("ENTRY_MATCH_GRADE", MatchGrade.class) {}; + +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119AuditStrategy.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119AuditStrategy.java new file mode 100644 index 0000000000..34023f381c --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119AuditStrategy.java @@ -0,0 +1,62 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import org.hl7.fhir.r4.model.Parameters; +import org.openehealth.ipf.commons.audit.AuditContext; +import org.openehealth.ipf.commons.audit.model.AuditMessage; +import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; +import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; +import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; +import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirParticipantObjectIdTypeCode; +import org.openehealth.ipf.commons.ihe.fhir.audit.events.BalpQueryInformationBuilder; + +import java.util.Map; + +/** + * Strategy for auditing ITI-78 transactions + * + * @author Christian Ohr + * @since 3.6 + */ +class Iti119AuditStrategy extends FhirQueryAuditStrategy { + + protected Iti119AuditStrategy(boolean serverSide) { + super(serverSide); + } + + @Override + public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { + return new BalpQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.PatientDemographicsMatch) + .addPatients(auditDataset.getPatientIds()) + .setQueryParameters( + "PatientDemographicsMatch", + FhirParticipantObjectIdTypeCode.PatientDemographicsMatch, + auditDataset.getQueryString()) + + .getMessages(); + } + + @Override + public FhirQueryAuditDataset enrichAuditDatasetFromRequest(FhirQueryAuditDataset auditDataset, Object request, Map parameters) { + var dataset = super.enrichAuditDatasetFromRequest(auditDataset, request, parameters); + if (request instanceof Parameters p && auditDataset.getFhirContext() != null) { + dataset.setQueryString(auditDataset.getFhirContext().newJsonParser().encodeToString(p)); + } + return dataset; + } + +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ClientAuditStrategy.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ClientAuditStrategy.java new file mode 100644 index 0000000000..9401d32c6b --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ClientAuditStrategy.java @@ -0,0 +1,30 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +/** + * Strategy for auditing ITI-119 transactions on the client side + * + * @author Christian Ohr + * @since 5.0 + */ +public class Iti119ClientAuditStrategy extends Iti119AuditStrategy { + + public Iti119ClientAuditStrategy() { + super(false); + } + +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ClientRequestFactory.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ClientRequestFactory.java new file mode 100644 index 0000000000..3ca3eb8287 --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ClientRequestFactory.java @@ -0,0 +1,70 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ + +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.gclient.IClientExecutable; +import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInput; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.StringType; +import org.openehealth.ipf.commons.ihe.fhir.ClientRequestFactory; + +import java.util.Map; + +import static org.openehealth.ipf.commons.ihe.fhir.iti119.Iti119Constants.RESOURCE; + +/** + * Request Factory for Iti-119 requests + * + * @author Christian Ohr + * @since 5.0 + */ +public class Iti119ClientRequestFactory implements ClientRequestFactory> { + + @Override + public IClientExecutable, ?> getClientExecutable(IGenericClient client, Object requestData, Map parameters) { + + if (requestData instanceof Parameters p) { + return getClientExecutable(client, p); + } + + var p = new Parameters(); + if (requestData instanceof Patient patient) { + p.addParameter().setResource(patient); + } else if (parameters.containsKey(RESOURCE) && parameters.get(RESOURCE) instanceof Patient patient) { + p.addParameter().setResource(patient); + } + parameters.entrySet().stream() + .filter(entry -> Iti119Constants.ITI119_PARAMETERS.contains(entry.getKey())) + .forEach(entry -> p.addParameter() + .setName(entry.getKey()) + .setValue(new StringType(entry.getValue().toString()))); + + return getClientExecutable(client, p); + } + + + private IClientExecutable, ?> getClientExecutable(IGenericClient client, Parameters requestData) { + return client.operation() + .onType(Patient.class) + .named(Iti119Constants.PDQM_MATCH_OPERATION_NAME) + .withParameters(requestData) + .returnResourceType(Bundle.class); + } +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119Constants.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119Constants.java new file mode 100644 index 0000000000..035926993e --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119Constants.java @@ -0,0 +1,40 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ + +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import org.openehealth.ipf.commons.ihe.fhir.Constants; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Christian Ohr + * @since 5.0 + */ +public interface Iti119Constants { + + String RESOURCE = "resource"; + String ONLY_CERTAIN_MATCHES = "onlyCertainMatches"; + String COUNT = "count"; + + Set ITI119_PARAMETERS = new HashSet<>(Arrays.asList( + ONLY_CERTAIN_MATCHES, + COUNT)); + + String PDQM_MATCH_OPERATION_NAME = "$match"; +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ResourceProvider.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ResourceProvider.java new file mode 100644 index 0000000000..38c71c9f03 --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ResourceProvider.java @@ -0,0 +1,80 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ + +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; +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.Sort; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.PositiveIntType; +import org.hl7.fhir.r4.model.ResourceType; +import org.openehealth.ipf.commons.ihe.fhir.AbstractPlainProvider; +import org.openehealth.ipf.commons.ihe.fhir.iti78.PdqPatient; + +import java.util.Set; + +import static org.openehealth.ipf.commons.ihe.fhir.iti119.Iti119Constants.*; + +/** + * Resource Provider for PDQm Match (ITI-119) for R4 + * + * @author Christian Ohr + * @since 5.0 + */ +public class Iti119ResourceProvider extends AbstractPlainProvider { + + /** + * Handles the PDQm Match request + * + * @param resource patient match input + * @param onlyCertainMatches may be optionally set to true to indicate that the Patient Demographics Consumer + * would only like matches returned when they are certain to be matches for the subject of the request + * @param count can be used to limit the number of results the Patient Demographics Supplier returns + * @param httpServletRequest servlet request + * @param httpServletResponse servlet response + * @param sortSpec sort specification + * @param includeSpec include specification + * @param requestDetails request details + * @return {@link IBundleProvider} instance that manages retrieving patients + */ + @SuppressWarnings("unused") + @Operation(name = PDQM_MATCH_OPERATION_NAME, type = PdqPatient.class, bundleType = BundleTypeEnum.SEARCHSET) + public IBundleProvider pdqmMatch( + @OperationParam(name = RESOURCE, type = Patient.class) Patient resource, + @OperationParam(name = ONLY_CERTAIN_MATCHES, type = BooleanType.class) BooleanType onlyCertainMatches, + @OperationParam(name = COUNT, type = PositiveIntType.class) PositiveIntType count, + @Sort SortSpec sortSpec, + @IncludeParam Set includeSpec, + RequestDetails requestDetails, + HttpServletRequest httpServletRequest, + HttpServletResponse httpServletResponse) { + + // Run down the route + return requestBundleProvider(requestDetails.getResource(), null, ResourceType.Patient.name(), + httpServletRequest, httpServletResponse, requestDetails); + } + +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ServerAuditStrategy.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ServerAuditStrategy.java new file mode 100644 index 0000000000..814ff4cf1e --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119ServerAuditStrategy.java @@ -0,0 +1,30 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +/** + * Strategy for auditing ITI-119 transactions on the server side + * + * @author Christian Ohr + * @since 5.0 + */ +public class Iti119ServerAuditStrategy extends Iti119AuditStrategy { + + public Iti119ServerAuditStrategy() { + super(true); + } + +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119TransactionConfiguration.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119TransactionConfiguration.java new file mode 100644 index 0000000000..d7d6a5d1f5 --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/Iti119TransactionConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import ca.uhn.fhir.context.FhirVersionEnum; +import org.openehealth.ipf.commons.ihe.fhir.FhirTransactionConfiguration; +import org.openehealth.ipf.commons.ihe.fhir.FhirTransactionValidator; +import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; +import org.openehealth.ipf.commons.ihe.fhir.iti78.Iti78QueryResourceClientRequestFactory; + +/** + * Standard Configuration for Iti119Component. Supports lazy-loading by default. + * + * @author Christian Ohr + * @since 5.0 + */ +public class Iti119TransactionConfiguration extends FhirTransactionConfiguration { + + public Iti119TransactionConfiguration() { + super("pdqm-iti119", + "Patient Demographics Match", + true, + new Iti119ClientAuditStrategy(), + new Iti119ServerAuditStrategy(), + FhirVersionEnum.R4, + new Iti119ResourceProvider(), // Consumer side. Accept patient searches + new Iti119ClientRequestFactory(), + FhirTransactionValidator.NO_VALIDATION); + setSupportsLazyLoading(true); + } +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/MatchGradeEnumInterceptor.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/MatchGradeEnumInterceptor.java new file mode 100644 index 0000000000..72d70393f7 --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/MatchGradeEnumInterceptor.java @@ -0,0 +1,61 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import ca.uhn.fhir.interceptor.api.Hook; +import ca.uhn.fhir.interceptor.api.Interceptor; +import ca.uhn.fhir.interceptor.api.Pointcut; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Coding; + +import java.util.Optional; + +import static org.openehealth.ipf.commons.ihe.fhir.iti119.AdditionalResourceMetadataKeyEnum.ENTRY_MATCH_GRADE; + +/** + * There is no universal mechanism to attach any kind of search attribute to a response bundle. As ITI-119 asks + * for a custom attribute that cannot been easily be handled within the BundleFactory, an interceptor is required. + * An instance of this interceptor must be registered with the {@link ca.uhn.fhir.rest.server.RestfulServer RestfulServer} or + * the {@link org.openehealth.ipf.commons.ihe.fhir.IpfFhirServlet IpfFhirServlet} subclass. The Spring Boot starter does + * this automatically. + */ +@Interceptor +public class MatchGradeEnumInterceptor { + + public static final String MATCH_GRADE_EXTENSION_URL = "http://hl7.org/fhir/StructureDefinition/match-grade"; + + @Hook(Pointcut.SERVER_OUTGOING_RESPONSE) + @SuppressWarnings("unused") + public void insertMatchGrades(RequestDetails requestDetails, IBaseResource resource) { + if (resource instanceof Bundle bundle) { + bundle.getEntry().stream() + .filter(Bundle.BundleEntryComponent::hasResource) + .filter(Bundle.BundleEntryComponent::hasSearch) + .filter(bc -> Bundle.SearchEntryMode.MATCH.equals(bc.getSearch().getMode())) + .forEach(entry -> + Optional.ofNullable(ENTRY_MATCH_GRADE.get(entry.getResource())).ifPresent(matchGrade -> + entry.getSearch().addExtension( + MATCH_GRADE_EXTENSION_URL, + new Coding() + .setSystem(matchGrade.getSystem()) + .setCode(matchGrade.toCode())) + ) + ); + } + } +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/PdqmMatchInputPatient.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/PdqmMatchInputPatient.java new file mode 100644 index 0000000000..a45540455c --- /dev/null +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti119/PdqmMatchInputPatient.java @@ -0,0 +1,66 @@ +/* + * Copyright 2015 the original author or authors. + * + * 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. + */ + +package org.openehealth.ipf.commons.ihe.fhir.iti119; + +import ca.uhn.fhir.model.api.annotation.Extension; +import ca.uhn.fhir.model.api.annotation.*; +import ca.uhn.fhir.rest.gclient.DateClientParam; +import ca.uhn.fhir.rest.gclient.StringClientParam; +import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.util.ElementUtil; +import org.hl7.fhir.instance.model.api.IAnyResource; +import org.hl7.fhir.r4.model.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * Patient as defined by the PDQm specification + * + * @author Christian Ohr + * @since 5.0 + */ +@ResourceDef(name = "Patient", id = "pdqm", profile = "https://profiles.ihe.net/ITI/PDQm/StructureDefinition/IHE.PDQm.MatchInputPatient") +public class PdqmMatchInputPatient extends Patient { + + + @Child(name = "mothersMaidenName") + @Extension(url = "http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName", definedLocally = false) + @Description(shortDefinition = "Mother's maiden name of a patient") + private HumanName mothersMaidenName; + + @Override + public boolean isEmpty() { + return super.isEmpty() && ElementUtil.isEmpty(mothersMaidenName); + } + + public HumanName getMothersMaidenName() { + if (mothersMaidenName == null) { + mothersMaidenName = new HumanName(); + } + return mothersMaidenName; + } + + public void setMothersMaidenName(HumanName mothersMaidenName) { + this.mothersMaidenName = mothersMaidenName; + } + + public boolean hasMothersMaidenName() { + return this.mothersMaidenName != null && !this.mothersMaidenName.isEmpty(); + } + +} diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java index 2208ff4746..45418bb93f 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java @@ -53,8 +53,7 @@ public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAudit @Override public FhirQueryAuditDataset enrichAuditDatasetFromRequest(FhirQueryAuditDataset auditDataset, Object request, Map parameters) { var dataset = super.enrichAuditDatasetFromRequest(auditDataset, request, parameters); - if (request instanceof IdType) { - var idType = (IdType) request; + if (request instanceof IdType idType) { dataset.getPatientIds().add(idType.getValue()); } return dataset; diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java index afac5d38f3..e4daf7800f 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java @@ -28,7 +28,7 @@ * @author Christian Ohr * @since 3.6 */ -public class Iti78QueryResourceClientRequestFactory extends QueryClientRequestFactory { +public class Iti78QueryResourceClientRequestFactory extends QueryClientRequestFactory { public Iti78QueryResourceClientRequestFactory() { super(Patient.class, Bundle.class); diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78SearchParameters.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78SearchParameters.java index a2ee959d64..a4a6cdea16 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78SearchParameters.java +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78SearchParameters.java @@ -83,12 +83,12 @@ public List getPatientIdParam() { @Override public Optional> comparatorFor(String paramName) { - switch (paramName) { - case PdqPatient.SP_BIRTHDATE : return Optional.of(CP_DATE); - case PdqPatient.SP_FAMILY: return Optional.of(CP_FAMILY); - case PdqPatient.SP_GIVEN: return Optional.of(CP_GIVEN); - } - return Optional.empty(); + return switch (paramName) { + case PdqPatient.SP_BIRTHDATE -> Optional.of(CP_DATE); + case PdqPatient.SP_FAMILY -> Optional.of(CP_FAMILY); + case PdqPatient.SP_GIVEN -> Optional.of(CP_GIVEN); + default -> Optional.empty(); + }; } private static final Comparator CP_DATE = nullsLast(comparing(PdqPatient::getBirthDate)); diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java index 284e9dba96..fe289ca3ac 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java @@ -64,11 +64,9 @@ public FhirQueryAuditDataset enrichAuditDatasetFromRequest(FhirQueryAuditDataset .map(Parameters.ParametersParameterComponent::getValue) .findFirst().orElseThrow(() -> new RuntimeException("No sourceIdentifier in PIX query")); - if (sourceIdentifier instanceof Identifier) { - var identifier = (Identifier) sourceIdentifier; + if (sourceIdentifier instanceof Identifier identifier) { dataset.getPatientIds().add(String.format("%s|%s", identifier.getSystem(), identifier.getValue())); - } else if (sourceIdentifier instanceof StringType) { - var identifier = (StringType) sourceIdentifier; + } else if (sourceIdentifier instanceof StringType identifier) { dataset.getPatientIds().add(identifier.getValue()); } else { dataset.getPatientIds().add(sourceIdentifier.toString()); diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java index 6c4a7631dd..1d6cc888a7 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java @@ -37,8 +37,8 @@ public class Iti83ClientRequestFactory implements ClientRequestFactory, ?> getClientExecutable(IGenericClient client, Object requestData, Map parameters) { - if (requestData instanceof Parameters) { - return getClientExecutable(client, (Parameters) requestData); + if (requestData instanceof Parameters p) { + return getClientExecutable(client, p); } else { var p = new Parameters(); parameters.entrySet().stream() diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pixpdq/PDQM.java b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pixpdq/PDQM.java index 427ec638c9..a9e3b35293 100644 --- a/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pixpdq/PDQM.java +++ b/commons/ihe/fhir/r4/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pixpdq/PDQM.java @@ -22,6 +22,7 @@ import org.openehealth.ipf.commons.ihe.fhir.FhirInteractionId; import org.openehealth.ipf.commons.ihe.fhir.FhirTransactionConfiguration; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; +import org.openehealth.ipf.commons.ihe.fhir.iti119.Iti119TransactionConfiguration; import org.openehealth.ipf.commons.ihe.fhir.iti78.Iti78TransactionConfiguration; import java.util.Arrays; @@ -36,7 +37,8 @@ public class PDQM implements IntegrationProfile { @AllArgsConstructor public enum Interactions implements FhirInteractionId { - ITI_78(ITI_78_CONFIG); + ITI_78(ITI_78_CONFIG), + ITI_119(ITI_119_CONFIG); @Getter private final FhirTransactionConfiguration fhirTransactionConfiguration; @@ -48,4 +50,5 @@ public List getInteractionIds() { } private static final Iti78TransactionConfiguration ITI_78_CONFIG = new Iti78TransactionConfiguration(); + private static final Iti119TransactionConfiguration ITI_119_CONFIG = new Iti119TransactionConfiguration(); } diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/resources/META-INF/profiles/ihe.iti.pdqm.r4.tgz b/commons/ihe/fhir/r4/pixpdq/src/main/resources/META-INF/profiles/ihe.iti.pdqm.r4.tgz new file mode 100644 index 0000000000..176db1b333 Binary files /dev/null and b/commons/ihe/fhir/r4/pixpdq/src/main/resources/META-INF/profiles/ihe.iti.pdqm.r4.tgz differ diff --git a/commons/ihe/fhir/r4/pixpdq/src/main/resources/META-INF/profiles/ihe.iti.pixm.r4.tgz b/commons/ihe/fhir/r4/pixpdq/src/main/resources/META-INF/profiles/ihe.iti.pixm.r4.tgz new file mode 100644 index 0000000000..ee8d2efd07 Binary files /dev/null and b/commons/ihe/fhir/r4/pixpdq/src/main/resources/META-INF/profiles/ihe.iti.pixm.r4.tgz differ diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/DiagnosticReportSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/DiagnosticReportSearchParameters.java index 8790659adf..1600d98e69 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/DiagnosticReportSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/DiagnosticReportSearchParameters.java @@ -34,8 +34,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @author Christian Ohr @@ -69,13 +68,15 @@ public class DiagnosticReportSearchParameters extends Pcc44CommonSearchParameter @Override protected Optional> comparatorFor(String paramName) { - if (DiagnosticReport.SP_DATE.equals(paramName)) { - return Optional.of(nullsLast(CP_EFFECTIVE)); - } - return Optional.empty(); + return DiagnosticReport.SP_DATE.equals(paramName) ? + Optional.of(CP_EFFECTIVE) : + Optional.empty(); } - private static final Comparator CP_EFFECTIVE = nullsLast(comparing(diagnosticReport -> { + private static final Comparator CP_EFFECTIVE = comparing( + DiagnosticReportSearchParameters::getEffectiveStartTime, nullsLast(naturalOrder())); + + private static String getEffectiveStartTime(DiagnosticReport diagnosticReport) { if (!diagnosticReport.hasEffective()) return null; var effective = diagnosticReport.getEffective(); if (effective instanceof DateTimeType) { @@ -83,5 +84,5 @@ protected Optional> comparatorFor(String paramName) } else { return diagnosticReport.getEffectivePeriod().getStartElement().getValueAsString(); } - })); + } } diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/EncounterSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/EncounterSearchParameters.java index 8fe15b04e7..feb057998a 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/EncounterSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/EncounterSearchParameters.java @@ -32,8 +32,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @author Christian Ohr @@ -60,14 +59,12 @@ public class EncounterSearchParameters extends Pcc44CommonSearchParameters> comparatorFor(String paramName) { - if (Encounter.SP_DATE.equals(paramName)) { - return Optional.of(nullsLast(CP_PERIOD)); - } - return Optional.empty(); + return Encounter.SP_DATE.equals(paramName) ? + Optional.of(CP_PERIOD) : + Optional.empty(); } - private static final Comparator CP_PERIOD = nullsLast(comparing(encounter -> { - if (!encounter.hasPeriod()) return null; - return encounter.getPeriod().getStart(); - })); + private static final Comparator CP_PERIOD = comparing( + encounter -> !encounter.hasPeriod() ? null : encounter.getPeriod().getStart(), + nullsLast(naturalOrder())); } diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ImmunizationSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ImmunizationSearchParameters.java index e48d0fff73..5cb38f5daa 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ImmunizationSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ImmunizationSearchParameters.java @@ -29,8 +29,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @author Christian Ohr @@ -51,14 +50,14 @@ public class ImmunizationSearchParameters extends Pcc44CommonSearchParameters> comparatorFor(String paramName) { - if (Immunization.SP_DATE.equals(paramName)) { - return Optional.of(nullsLast(CP_OCCURRENCE)); - } - return Optional.empty(); + return Immunization.SP_DATE.equals(paramName) ? + Optional.of(CP_OCCURRENCE) : + Optional.empty(); } - private static final Comparator CP_OCCURRENCE = nullsLast(comparing(immunization -> { - if (!immunization.hasOccurrenceDateTimeType()) return null; - return immunization.getOccurrenceDateTimeType().getValue(); - })); + private static final Comparator CP_OCCURRENCE = comparing( + immunization -> !immunization.hasOccurrenceDateTimeType() ? + null : + immunization.getOccurrenceDateTimeType().getValue(), + nullsLast(naturalOrder())); } diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationRequestSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationRequestSearchParameters.java index df889e668d..114a68084f 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationRequestSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationRequestSearchParameters.java @@ -51,8 +51,8 @@ public class MedicationRequestSearchParameters extends Pcc44CommonSearchParamete @Override protected Optional> comparatorFor(String paramName) { - switch (paramName) { - case MedicationRequest.SP_AUTHOREDON: return Optional.of(nullsLast(comparing(MedicationRequest::getAuthoredOn))); + if (paramName.equals(MedicationRequest.SP_AUTHOREDON)) { + return Optional.of(nullsLast(comparing(MedicationRequest::getAuthoredOn))); } return Optional.empty(); } diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationStatementSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationStatementSearchParameters.java index 6d63c15ea6..1adbc19313 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationStatementSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/MedicationStatementSearchParameters.java @@ -30,8 +30,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @author Christian Ohr @@ -52,13 +51,16 @@ public class MedicationStatementSearchParameters extends Pcc44CommonSearchParame @Override protected Optional> comparatorFor(String paramName) { - if (MedicationStatement.SP_EFFECTIVE.equals(paramName)) { - return Optional.of(nullsLast(CP_EFFECTIVE)); - } - return Optional.empty(); + return MedicationStatement.SP_EFFECTIVE.equals(paramName) ? + Optional.of(CP_EFFECTIVE) : + Optional.empty(); } - private static final Comparator CP_EFFECTIVE = nullsLast(comparing(medicationStatement -> { + private static final Comparator CP_EFFECTIVE = comparing( + MedicationStatementSearchParameters::getEffectiveStartTime, + nullsLast(naturalOrder())); + + private static String getEffectiveStartTime(MedicationStatement medicationStatement) { if (!medicationStatement.hasEffective()) return null; var effective = medicationStatement.getEffective(); if (effective instanceof DateTimeType) { @@ -66,5 +68,5 @@ protected Optional> comparatorFor(String paramNa } else { return medicationStatement.getEffectivePeriod().getStartElement().getValueAsString(); } - })); + } } diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ObservationSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ObservationSearchParameters.java index ef96ed2dc6..773a1eb16b 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ObservationSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ObservationSearchParameters.java @@ -36,8 +36,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @author Christian Ohr @@ -73,13 +72,16 @@ public class ObservationSearchParameters extends Pcc44CommonSearchParameters> comparatorFor(String paramName) { - if (Observation.SP_DATE.equals(paramName)) { - return Optional.of(nullsLast(CP_EFFECTIVE)); - } - return Optional.empty(); + return Observation.SP_DATE.equals(paramName) ? + Optional.of(CP_EFFECTIVE) : + Optional.empty(); } - private static final Comparator CP_EFFECTIVE = nullsLast(comparing(observation -> { + private static final Comparator CP_EFFECTIVE = comparing( + ObservationSearchParameters::getEffectiveStartTime, + nullsLast(naturalOrder())); + + private static String getEffectiveStartTime(Observation observation) { if (!observation.hasEffective()) return null; var effective = observation.getEffective(); if (effective instanceof DateTimeType) { @@ -91,5 +93,5 @@ protected Optional> comparatorFor(String paramName) { } else { return null; } - })); + } } diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java index 20f04f2e1e..e7af1547fe 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java @@ -17,7 +17,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; @@ -36,7 +36,7 @@ public Pcc44AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobileQueryExistingData) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileQueryExistingData) .addPatients(auditDataset.getPatientIds()) .setQueryParameters("MobileQueryExistingData", FhirParticipantObjectIdTypeCode.MobileQueryExistingData, diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java index c28a26b4ca..11d35a475e 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java @@ -40,14 +40,13 @@ public class Pcc44ClientRequestFactory implements ClientRequestFactory, ?> getClientExecutable(IGenericClient client, Object requestData, Map parameters) { IQuery query; var queriedResourceType = (String) parameters.get(Constants.FHIR_RESOURCE_TYPE_HEADER); - if (requestData instanceof ICriterion) { + if (requestData instanceof ICriterion criterion) { query = client.search() .forResource(queriedResourceType) - .where((ICriterion) requestData); - } else if (requestData instanceof ICriterion[]) { + .where(criterion); + } else if (requestData instanceof ICriterion[] criteria) { query = client.search() .forResource(queriedResourceType); - ICriterion[] criteria = (ICriterion[]) requestData; if (criteria.length > 0) { query = query.where(criteria[0]); if (criteria.length > 1) { diff --git a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ProcedureSearchParameters.java b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ProcedureSearchParameters.java index 038eaff30a..3e604c4559 100644 --- a/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ProcedureSearchParameters.java +++ b/commons/ihe/fhir/r4/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/ProcedureSearchParameters.java @@ -35,8 +35,7 @@ import java.util.Optional; import java.util.Set; -import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsLast; +import static java.util.Comparator.*; /** * @author Christian Ohr @@ -63,13 +62,16 @@ public class ProcedureSearchParameters extends Pcc44CommonSearchParameters> comparatorFor(String paramName) { - if (Procedure.SP_DATE.equals(paramName)) { - return Optional.of(nullsLast(CP_PERFORMED)); - } - return Optional.empty(); + return Procedure.SP_DATE.equals(paramName) ? + Optional.of(CP_PERFORMED) : + Optional.empty(); } - private static final Comparator CP_PERFORMED = nullsLast(comparing(procedure -> { + private static final Comparator CP_PERFORMED = comparing( + ProcedureSearchParameters::getPerformedStartTime, + nullsLast(naturalOrder())); + + private static String getPerformedStartTime(Procedure procedure) { if (!procedure.hasPerformed()) return null; var performed = procedure.getPerformed(); if (performed instanceof DateTimeType) { @@ -81,5 +83,5 @@ protected Optional> comparatorFor(String paramName) { } else { return null; } - })); + } } diff --git a/commons/ihe/fhir/stu3/audit/pom.xml b/commons/ihe/fhir/stu3/audit/pom.xml index 4f2d4042c4..e81c28e274 100644 --- a/commons/ihe/fhir/stu3/audit/pom.xml +++ b/commons/ihe/fhir/stu3/audit/pom.xml @@ -18,12 +18,6 @@ ipf-commons-ihe-fhir-stu3-core - - - org.springframework - spring-core - test - org.easymock easymock diff --git a/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java b/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java index 89515b38e1..c25093ddd5 100644 --- a/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java +++ b/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/atna/ATNA.java @@ -38,6 +38,7 @@ public enum Interactions implements FhirInteractionId { ITI_81(ITI_81_CONFIG); @Getter + final FhirTransactionConfiguration fhirTransactionConfiguration; } diff --git a/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java b/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java index 0ba7dae3ab..47a2d22b47 100644 --- a/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java +++ b/commons/ihe/fhir/stu3/audit/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti81/Iti81ClientRequestFactory.java @@ -28,7 +28,7 @@ * @author Christian Ohr * @since 3.1 */ -public class Iti81ClientRequestFactory extends QueryClientRequestFactory { +public class Iti81ClientRequestFactory extends QueryClientRequestFactory { public Iti81ClientRequestFactory() { super(AuditEvent.class, Bundle.class); diff --git a/commons/ihe/fhir/stu3/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java b/commons/ihe/fhir/stu3/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java index 9a3dbc50f4..ec38b25912 100644 --- a/commons/ihe/fhir/stu3/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java +++ b/commons/ihe/fhir/stu3/core/src/main/java/org/openehealth/ipf/commons/ihe/fhir/support/AbstractNamingSystemServiceImpl.java @@ -42,7 +42,7 @@ public class AbstractNamingSystemServiceImpl implements NamingSystemService { public void addNamingSystems(Bundle bundle) { this.namingSystems.merge(bundle.getIdElement().getIdPart(), setOfNamingSystems(bundle), (set1, set2) -> { - var result = new HashSet(set1); + var result = new HashSet<>(set1); result.addAll(set2); return result; }); diff --git a/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/AbstractSystemUriMapperTest.java b/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/AbstractSystemUriMapperTest.java index cac7c2b8e9..04993a022d 100644 --- a/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/AbstractSystemUriMapperTest.java +++ b/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/AbstractSystemUriMapperTest.java @@ -40,31 +40,31 @@ public void setup() { protected abstract UriMapper initMapper(DefaultNamingSystemServiceImpl namingSystemService); @Test - public void testTranslateOidUrn() throws Exception { + public void testTranslateOidUrn() { var oid = "1.2.3.4.5.6.7.8.9"; - assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).get()); + assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).orElse(null)); } @Test - public void testTranslateUriToOid() throws Exception { + public void testTranslateUriToOid() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/1"; - assertEquals("1.2.3.4", uriMapper.uriToOid(uri).get()); + assertEquals("1.2.3.4", uriMapper.uriToOid(uri).orElse(null)); } @Test - public void testTranslateUriToOidFails() throws Exception { + public void testTranslateUriToOidFails() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/9"; assertFalse(uriMapper.uriToOid(uri).isPresent()); } @Test - public void testTranslatePinUrn() throws Exception { + public void testTranslatePinUrn() { var namespace = "namespace"; - assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).get()); + assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).orElse(null)); } @Test - public void testTranslateUriToNamespace() throws Exception { + public void testTranslateUriToNamespace() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/1"; assertEquals("fhir1", uriMapper.uriToNamespace(uri).get()); uri = "http://org.openehealth/ipf/commons/ihe/fhir/9"; @@ -72,7 +72,7 @@ public void testTranslateUriToNamespace() throws Exception { } @Test - public void testTranslateNamespaceToUri() throws Exception { + public void testTranslateNamespaceToUri() { var namespace = "fhir1"; assertEquals("http://org.openehealth/ipf/commons/ihe/fhir/1", uriMapper.namespaceToUri(namespace)); } diff --git a/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java b/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java index 77f41eea3f..8d837be168 100644 --- a/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java +++ b/commons/ihe/fhir/stu3/core/src/test/java/org/openehealth/ipf/commons/ihe/fhir/support/translation/DefaultUriMapperTest.java @@ -29,42 +29,41 @@ */ public class DefaultUriMapperTest { - private BidiMappingService mappingService; private DefaultUriMapper uriMapper; @BeforeEach public void setup() { - mappingService = new BidiMappingService(); + BidiMappingService mappingService = new BidiMappingService(); mappingService.setMappingScript(getClass().getResource("/mapping.map")); uriMapper = new DefaultUriMapper(mappingService, "uriToOid", "uriToNamespace"); } @Test - public void testTranslateOidUrn() throws Exception { + public void testTranslateOidUrn() { var oid = "1.2.3.4.5.6.7.8.9"; - assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).get()); + assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).orElse(null)); } @Test - public void testTranslateUriToOid() throws Exception { + public void testTranslateUriToOid() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/1"; - assertEquals("1.2.3.4", uriMapper.uriToOid(uri).get()); + assertEquals("1.2.3.4", uriMapper.uriToOid(uri).orElse(null)); } @Test - public void testTranslateUriToOidFails() throws Exception { + public void testTranslateUriToOidFails() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/9"; assertFalse(uriMapper.uriToOid(uri).isPresent()); } @Test - public void testTranslatePinUrn() throws Exception { + public void testTranslatePinUrn() { var namespace = "namespace"; - assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).get()); + assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).orElse(null)); } @Test - public void testTranslateUriToNamespace() throws Exception { + public void testTranslateUriToNamespace() { var uri = "http://org.openehealth/ipf/commons/ihe/fhir/1"; assertEquals("fhir1", uriMapper.uriToNamespace(uri).get()); uri = "http://org.openehealth/ipf/commons/ihe/fhir/9"; @@ -72,7 +71,7 @@ public void testTranslateUriToNamespace() throws Exception { } @Test - public void testTranslateNamespaceToUri() throws Exception { + public void testTranslateNamespaceToUri() { var namespace = "fhir1"; assertEquals("http://org.openehealth/ipf/commons/ihe/fhir/1", uriMapper.namespaceToUri(namespace)); } diff --git a/commons/ihe/fhir/stu3/mhd/pom.xml b/commons/ihe/fhir/stu3/mhd/pom.xml index 7360c74048..31b74413cf 100644 --- a/commons/ihe/fhir/stu3/mhd/pom.xml +++ b/commons/ihe/fhir/stu3/mhd/pom.xml @@ -33,12 +33,6 @@ hapi-fhir-validation-resources-dstu3 - - - org.springframework - spring-core - test - org.easymock easymock diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ClientAuditStrategy.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ClientAuditStrategy.java index dc700378ad..24777b4963 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ClientAuditStrategy.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ClientAuditStrategy.java @@ -20,7 +20,7 @@ import org.openehealth.ipf.commons.audit.codes.ParticipantObjectIdTypeCode; import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCodeRole; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIExportBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; import java.util.Collections; @@ -36,7 +36,7 @@ public Iti65ClientAuditStrategy() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, Iti65AuditDataset auditDataset) { - return new PHIExportBuilder<>(auditContext, auditDataset, FhirEventTypeCode.ProvideDocumentBundle) + return new DefaultPHIExportBuilder(auditContext, auditDataset, FhirEventTypeCode.ProvideDocumentBundle) .setPatient(auditDataset.getPatientId()) .addExportedEntity( auditDataset.getDocumentManifestUuid() != null ? diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ServerAuditStrategy.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ServerAuditStrategy.java index bcba287c0d..7703b9fd23 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ServerAuditStrategy.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65ServerAuditStrategy.java @@ -20,7 +20,7 @@ import org.openehealth.ipf.commons.audit.codes.ParticipantObjectIdTypeCode; import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCodeRole; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIImportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIImportBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; import java.util.Collections; @@ -36,7 +36,7 @@ public Iti65ServerAuditStrategy() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, Iti65AuditDataset auditDataset) { - return new PHIImportBuilder<>(auditContext, auditDataset, FhirEventTypeCode.ProvideDocumentBundle) + return new DefaultPHIImportBuilder(auditContext, auditDataset, FhirEventTypeCode.ProvideDocumentBundle) .setPatient(auditDataset.getPatientId()) .addImportedEntity( auditDataset.getDocumentManifestUuid(), diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java index 24c00f3493..b60322eb41 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti65/Iti65Validator.java @@ -154,26 +154,24 @@ protected void validateBundleConsistency(Bundle bundle) { .flatMap(Collection::stream) .map(Bundle.BundleEntryComponent::getResource) .forEach(resource -> { - if (resource instanceof DocumentManifest) { - var dm = (DocumentManifest) resource; + if (resource instanceof DocumentManifest dm) { for (var content : dm.getContent()) { try { expectedReferenceFullUrls.add(content.getPReference().getReference()); } catch (Exception ignored) { } } - patientReferences.add(getSubjectReference(resource, r -> dm.getSubject())); - } else if (resource instanceof DocumentReference) { - var dr = (DocumentReference) resource; + patientReferences.add(getSubjectReference(dm, DocumentManifest::getSubject)); + } else if (resource instanceof DocumentReference dr) { for (var content : dr.getContent()) { var url = content.getAttachment().getUrl(); if (!url.startsWith("http")) { expectedBinaryFullUrls.add(url); } } - patientReferences.add(getSubjectReference(resource, r -> ((DocumentReference) r).getSubject())); - } else if (resource instanceof ListResource) { - patientReferences.add(getSubjectReference(resource, r -> ((ListResource) r).getSubject())); + patientReferences.add(getSubjectReference(dr, DocumentReference::getSubject)); + } else if (resource instanceof ListResource listResource) { + patientReferences.add(getSubjectReference(listResource, ListResource::getSubject)); } else if (!(resource instanceof Binary)) { throw FhirUtils.unprocessableEntity( OperationOutcome.IssueSeverity.ERROR, @@ -245,7 +243,7 @@ protected void validateBundleConsistency(Bundle bundle) { } - private String getSubjectReference(Resource resource, Function f) { + private String getSubjectReference(T resource, Function f) { var reference = f.apply(resource); if (reference == null) { throw FhirUtils.unprocessableEntity( diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java index d205181c1e..74c90ec20a 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66AuditStrategy.java @@ -17,7 +17,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; @@ -37,7 +37,7 @@ public Iti66AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentManifestQuery) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentManifestQuery) .addPatients(auditDataset.getPatientIds()) .setQueryParameters("MobileDocumentManifestQuery", FhirParticipantObjectIdTypeCode.MobileDocumentManifestQuery, diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ClientRequestFactory.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ClientRequestFactory.java index 4cec90d1ee..670d7a69dc 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ClientRequestFactory.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti66/Iti66ClientRequestFactory.java @@ -26,7 +26,7 @@ * @author Christian Ohr * @since 3.2 */ -public class Iti66ClientRequestFactory extends QueryClientRequestFactory { +public class Iti66ClientRequestFactory extends QueryClientRequestFactory { public Iti66ClientRequestFactory() { super(DocumentManifest.class, Bundle.class); diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java index 172538a80e..f43054dc4d 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67AuditStrategy.java @@ -17,7 +17,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; @@ -35,7 +35,7 @@ public Iti67AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentReferenceQuery) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileDocumentReferenceQuery) .addPatients(auditDataset.getPatientIds()) .setQueryParameters("MobileDocumentReferenceQuery", FhirParticipantObjectIdTypeCode.MobileDocumentReferenceQuery, diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ClientRequestFactory.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ClientRequestFactory.java index b977bdfa75..e13d3e5d6d 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ClientRequestFactory.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti67/Iti67ClientRequestFactory.java @@ -26,7 +26,7 @@ * @author Christian Ohr * @since 3.4 */ -public class Iti67ClientRequestFactory extends QueryClientRequestFactory { +public class Iti67ClientRequestFactory extends QueryClientRequestFactory { public Iti67ClientRequestFactory() { super(DocumentReference.class, Bundle.class); diff --git a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java index fca11053d7..e65170ea43 100644 --- a/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java +++ b/commons/ihe/fhir/stu3/mhd/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti68/Iti68ServerAuditStrategy.java @@ -22,7 +22,7 @@ import org.openehealth.ipf.commons.audit.codes.ParticipantObjectTypeCodeRole; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PHIExportBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPHIExportBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; import java.util.Map; @@ -44,7 +44,7 @@ public Iti68AuditDataset enrichAuditDatasetFromRequest(Iti68AuditDataset auditDa @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, Iti68AuditDataset auditDataset) { - PHIExportBuilder builder = new PHIExportBuilder<>(auditContext, auditDataset, + var builder = new DefaultPHIExportBuilder(auditContext, auditDataset, EventActionCode.Create, FhirEventTypeCode.MobileDocumentRetrieval) .setPatient(auditDataset.getPatientId()); diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy b/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy index 7a9dad593d..9d493db93d 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqResponseToPdqmResponseTranslator.groovy @@ -53,7 +53,7 @@ import static java.util.Objects.requireNonNull */ class PdqResponseToPdqmResponseTranslator implements ToFhirTranslator { - private static final Logger LOG = LoggerFactory.getLogger(PdqResponseToPdqmResponseTranslator) + private static final Logger log = LoggerFactory.getLogger(PdqResponseToPdqmResponseTranslator) private final UriMapper uriMapper String pdqSupplierResourceIdentifierUri @@ -88,7 +88,7 @@ class PdqResponseToPdqmResponseTranslator implements ToFhirTranslator { switch (ackCode) { case 'OK': return handleRegularSearchResponse(message.QUERY_RESPONSE()) // Case 1,2 case 'NF': return handleRegularSearchResponse(null) // Case 3 - case 'AE': return handleErrorResponse(message) // Cases 4-5 + case 'AE': return handleErrorResponse(message as RSP_K21) // Cases 4-5 default: throw new InternalErrorException("Unexpected ack code " + ackCode) } } @@ -131,7 +131,7 @@ class PdqResponseToPdqmResponseTranslator implements ToFhirTranslator { if (resourcePid) { patient.setId(new IdType('Patient', resourcePid[1].value)) } else { - LOG.warn("No ID found with resource system URI {}", pdqSupplierResourceIdentifierUri) + log.warn("No ID found with resource system URI {}", pdqSupplierResourceIdentifierUri) } convertIdentifiers(pid[3](), patient.getIdentifier()) diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy b/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy index 433c57a9c7..f6c9deeba1 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti78/PdqmRequestToPdqQueryTranslator.groovy @@ -135,7 +135,7 @@ class PdqmRequestToPdqQueryTranslator implements FhirTranslator { // Handle identifiers - List requestedDomainOids + List requestedDomainOids = null Optional searchIdentifier = Optional.empty() TokenParam resourceIdParam = searchParameters._id @@ -155,8 +155,9 @@ class PdqmRequestToPdqQueryTranslator implements FhirTranslator { // Requested domains have no identifier value. If the resource identifier system is not included here, // add it because otherwise we don't know the resource ID in the response. - requestedDomainOids = identifiers?.findAll { it.isPresent() && it.get().hasOnlySystem() } - ?.collect { it.get().oid } + requestedDomainOids = identifiers?.findAll { + it.isPresent() && it.get().hasOnlySystem() + }?.collect { it.get().oid } } // If requestedDomains is set but the pdqSupplierResourceIdentifierOid is not part of it, add it. @@ -200,7 +201,7 @@ class PdqmRequestToPdqQueryTranslator implements FhirTranslator { } protected String convertBirthDate(DateAndListParam birthDateParam) { - Date birthDate = firstOrNull(searchDateList(birthDateParam)) + def birthDate = firstOrNull(searchDateList(birthDateParam)) return birthDate ? FastDateFormat.getInstance('yyyyMMdd').format(birthDate) : null } @@ -218,7 +219,7 @@ class PdqmRequestToPdqQueryTranslator implements FhirTranslator { param?.valuesAsQueryTokens?.collect { searchString(it.valuesAsQueryTokens.find(), forceExactSearch) } } - protected List searchDateList(DateAndListParam param) { + protected List searchDateList(DateAndListParam param) { param?.valuesAsQueryTokens?.collect { searchDate(it.valuesAsQueryTokens.find()) } } diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti83/PixQueryResponseToPixmResponseTranslator.groovy b/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti83/PixQueryResponseToPixmResponseTranslator.groovy index d95890d71b..fe46429e37 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti83/PixQueryResponseToPixmResponseTranslator.groovy +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/groovy/org/openehealth/ipf/commons/ihe/fhir/iti83/PixQueryResponseToPixmResponseTranslator.groovy @@ -52,7 +52,7 @@ class PixQueryResponseToPixmResponseTranslator implements ToFhirTranslator { map.put(part.name, part.value) } - handleSourceIdentifier(qry, map[Constants.SOURCE_IDENTIFIER_NAME]) + handleSourceIdentifier(qry, map[Constants.SOURCE_IDENTIFIER_NAME] as Identifier) - UriType requestedDomain = map[Constants.TARGET_SYSTEM_NAME] + UriType requestedDomain = map[Constants.TARGET_SYSTEM_NAME] as UriType if (requestedDomain) { if (!Utils.populateIdentifier(Utils.nextRepetition(qry.QPD[4]), uriMapper, requestedDomain.value)) { // UriMapper is not able to derive a PIX OID/Namespace for the target domain URI, Error Case 5 diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java index 9605ff86d6..31cafd9864 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78AuditStrategy.java @@ -18,7 +18,7 @@ import org.hl7.fhir.dstu3.model.IdType; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; @@ -40,7 +40,7 @@ protected Iti78AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobilePatientDemographicsQuery) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobilePatientDemographicsQuery) .addPatients(auditDataset.getPatientIds()) .setQueryParameters( "MobilePatientDemographicsQuery", @@ -53,8 +53,7 @@ public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAudit @Override public FhirQueryAuditDataset enrichAuditDatasetFromRequest(FhirQueryAuditDataset auditDataset, Object request, Map parameters) { var dataset = super.enrichAuditDatasetFromRequest(auditDataset, request, parameters); - if (request instanceof IdType) { - var idType = (IdType) request; + if (request instanceof IdType idType) { dataset.getPatientIds().add(idType.getValue()); } return dataset; diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java index 224f12bda7..e15fc925c0 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti78/Iti78QueryResourceClientRequestFactory.java @@ -28,7 +28,7 @@ * @author Christian Ohr * @since 3.4 */ -public class Iti78QueryResourceClientRequestFactory extends QueryClientRequestFactory { +public class Iti78QueryResourceClientRequestFactory extends QueryClientRequestFactory { public Iti78QueryResourceClientRequestFactory() { super(Patient.class, Bundle.class); diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java index 2b226a4018..0a7534f5bc 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83AuditStrategy.java @@ -20,7 +20,7 @@ import org.hl7.fhir.dstu3.model.StringType; import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.Constants; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; @@ -43,7 +43,7 @@ public Iti83AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobilePatientIdentifierCrossReferenceQuery) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobilePatientIdentifierCrossReferenceQuery) .addPatients(auditDataset.getPatientIds()) .setQueryParameters( "PIXmQuery", @@ -64,11 +64,9 @@ public FhirQueryAuditDataset enrichAuditDatasetFromRequest(FhirQueryAuditDataset .map(Parameters.ParametersParameterComponent::getValue) .findFirst().orElseThrow(() -> new RuntimeException("No sourceIdentifier in PIX query")); - if (sourceIdentifier instanceof Identifier) { - var identifier = (Identifier) sourceIdentifier; + if (sourceIdentifier instanceof Identifier identifier) { dataset.getPatientIds().add(String.format("%s|%s", identifier.getSystem(), identifier.getValue())); - } else if (sourceIdentifier instanceof StringType) { - var identifier = (StringType) sourceIdentifier; + } else if (sourceIdentifier instanceof StringType identifier) { dataset.getPatientIds().add(identifier.getValue()); } else { dataset.getPatientIds().add(sourceIdentifier.toString()); diff --git a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java index 472ec6ccd1..b21d864b83 100644 --- a/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java +++ b/commons/ihe/fhir/stu3/pixpdq/src/main/java/org/openehealth/ipf/commons/ihe/fhir/iti83/Iti83ClientRequestFactory.java @@ -37,8 +37,8 @@ public class Iti83ClientRequestFactory implements ClientRequestFactory, ?> getClientExecutable(IGenericClient client, Object requestData, Map parameters) { - if (requestData instanceof Parameters) { - return getClientExecutable(client, (Parameters) requestData); + if (requestData instanceof Parameters p) { + return getClientExecutable(client, p); } else { var p = new Parameters(); parameters.entrySet().stream() diff --git a/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java b/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java index 26d658cf83..4b25af4f44 100644 --- a/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java +++ b/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44AuditStrategy.java @@ -17,7 +17,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditDataset; import org.openehealth.ipf.commons.ihe.fhir.audit.FhirQueryAuditStrategy; import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode; @@ -36,7 +36,7 @@ public Pcc44AuditStrategy(boolean serverSide) { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FhirQueryAuditDataset auditDataset) { - return new QueryInformationBuilder<>(auditContext, auditDataset, FhirEventTypeCode.MobileQueryExistingData) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, FhirEventTypeCode.MobileQueryExistingData) .addPatients(auditDataset.getPatientIds()) .setQueryParameters("MobileQueryExistingData", FhirParticipantObjectIdTypeCode.MobileQueryExistingData, diff --git a/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java b/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java index caf980a297..3a1055715d 100644 --- a/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java +++ b/commons/ihe/fhir/stu3/qedm/src/main/java/org/openehealth/ipf/commons/ihe/fhir/pcc44/Pcc44ClientRequestFactory.java @@ -39,14 +39,13 @@ public class Pcc44ClientRequestFactory implements ClientRequestFactory, ?> getClientExecutable(IGenericClient client, Object requestData, Map parameters) { IQuery query; var queriedResourceType = (String) parameters.get(Constants.FHIR_RESOURCE_TYPE_HEADER); - if (requestData instanceof ICriterion) { + if (requestData instanceof ICriterion criterion) { query = client.search() .forResource(queriedResourceType) - .where((ICriterion) requestData); - } else if (requestData instanceof ICriterion[]) { + .where(criterion); + } else if (requestData instanceof ICriterion[] criteria) { query = client.search() .forResource(queriedResourceType); - ICriterion[] criteria = (ICriterion[]) requestData; if (criteria.length > 0) { query = query.where(criteria[0]); if (criteria.length > 1) { diff --git a/commons/ihe/hl7v2/pom.xml b/commons/ihe/hl7v2/pom.xml index 04acfaf68b..d1fd569758 100644 --- a/commons/ihe/hl7v2/pom.xml +++ b/commons/ihe/hl7v2/pom.xml @@ -62,11 +62,6 @@ micrometer-tracing true - - io.micrometer - micrometer-tracing-bridge-brave - test - io.netty netty-handler @@ -90,6 +85,16 @@ ${project.version} test + + io.micrometer + micrometer-tracing-bridge-brave + test + + + io.micrometer + micrometer-tracing-bridge-otel + test + diff --git a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/audit/AuditUtils.groovy b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/audit/AuditUtils.groovy index 628eaa8876..47353d7d70 100644 --- a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/audit/AuditUtils.groovy +++ b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/audit/AuditUtils.groovy @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory * @author Dmytro Rud */ class AuditUtils { - private static final transient Logger LOG = LoggerFactory.getLogger(AuditUtils.class) + private static final transient Logger log = LoggerFactory.getLogger(AuditUtils.class) private AuditUtils() { throw new IllegalStateException('Helper class, do not instantiate') diff --git a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageGetter.groovy b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageGetter.groovy index 9ed53146b8..263344b551 100644 --- a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageGetter.groovy +++ b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageGetter.groovy @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory */ class Hl7MessageGetter implements Propagator.Getter { - private static final Logger LOG = LoggerFactory.getLogger(Hl7MessageGetter) + private static final Logger log = LoggerFactory.getLogger(Hl7MessageGetter) private final String segmentName Hl7MessageGetter(String segmentName = 'ZTR') { @@ -43,8 +43,8 @@ class Hl7MessageGetter implements Propagator.Getter { def qip = qips ? qips().find { q -> q[1].value == key } : null String value = qip ? qip[2]?.value : null - if (LOG.isDebugEnabled()) { - LOG.debug("Extracted trace context with key [{}] and value [{}]", key, value) + if (log.isDebugEnabled()) { + log.debug("Extracted trace context with key [{}] and value [{}]", key, value) } value } diff --git a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageSetter.groovy b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageSetter.groovy index ae7ada6bcf..e07a972d4f 100644 --- a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageSetter.groovy +++ b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/Hl7MessageSetter.groovy @@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory */ class Hl7MessageSetter implements Propagator.Setter { - private static final Logger LOG = LoggerFactory.getLogger(Hl7MessageSetter) + private static final Logger log = LoggerFactory.getLogger(Hl7MessageSetter) private final String segmentName @@ -53,8 +53,8 @@ class Hl7MessageSetter implements Propagator.Setter { def varies = nextRepetition(seg[1]) varies.data = qip - if (LOG.isDebugEnabled()) { - LOG.debug("Added trace context with key [{}] and value [{}]", key, value) + if (log.isDebugEnabled()) { + log.debug("Added trace context with key [{}] and value [{}]", key, value) } } } diff --git a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageTracer.groovy b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageTracer.groovy index 6dd15c762e..1eb02d4b18 100644 --- a/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageTracer.groovy +++ b/commons/ihe/hl7v2/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageTracer.groovy @@ -35,12 +35,13 @@ class MessageTracer { private static final String HL7_SENDING_FACILITY = "MSH-4" private static final String HL7_MESSAGE_TYPE = "MSH-9-1" private static final String HL7_TRIGGER_EVENT = "MSH-9-2" + private static final String HL7_MESSAGE_ID = "MSH-10" private static final String HL7_PROCESSING_ID = "MSH-11" private final Tracer tracer private final boolean removeSegment private final String segmentName - private final Propagator propagator; + private final Propagator propagator private final Propagator.Setter setter private final Propagator.Getter getter @@ -56,7 +57,7 @@ class MessageTracer { this.segmentName = segmentName this.setter = new Hl7MessageSetter(segmentName) this.getter = new Hl7MessageGetter(segmentName) - this.propagator = propagator; + this.propagator = propagator } void sendMessage(Message msg, String name, Handler sender) { @@ -99,6 +100,7 @@ class MessageTracer { .tag(HL7_SENDING_FACILITY, msg.MSH[4]?.value ?: '') .tag(HL7_MESSAGE_TYPE, msg.MSH[9][1]?.value ?: '') .tag(HL7_TRIGGER_EVENT, msg.MSH[9][2]?.value ?: '') + .tag(HL7_MESSAGE_ID, msg.MSH[10]?.value ?: '') .tag(HL7_PROCESSING_ID, msg.MSH[11]?.value ?: '') .start() } diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/Hl7v2AcceptanceException.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/Hl7v2AcceptanceException.java index a2aea83b7d..66fb76612f 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/Hl7v2AcceptanceException.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/Hl7v2AcceptanceException.java @@ -25,8 +25,6 @@ */ public class Hl7v2AcceptanceException extends HL7Exception { - private static final long serialVersionUID = -954901285020747868L; - public Hl7v2AcceptanceException(String message, ErrorCode code) { super(message, code); } diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/QpdAwareNakFactory.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/QpdAwareNakFactory.java index 08fd9b7e8f..a3751c441b 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/QpdAwareNakFactory.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/QpdAwareNakFactory.java @@ -34,7 +34,7 @@ */ public class QpdAwareNakFactory extends NakFactory { - private static final Logger LOG = LoggerFactory.getLogger(QpdAwareNakFactory.class); + private static final Logger log = LoggerFactory.getLogger(QpdAwareNakFactory.class); private final String messageType, triggerEvent; @@ -68,7 +68,7 @@ public Message createNak0(Message originalMessage, HL7Exception e, Acknowledgmen messageType, triggerEvent); - LOG.info("Creating NAK response event of type {}", ack.getClass().getName()); + log.info("Creating NAK response event of type {}", ack.getClass().getName()); e.populateResponse(ack, ackTypeCode, 0); @@ -80,7 +80,7 @@ public Message createNak0(Message originalMessage, HL7Exception e, Acknowledgmen if (origQpd != null) { var queryTag = Terser.get(origQpd, 2, 0, 1, 1); Terser.set(ackQak, 1, 0, 1, 1, queryTag); - LOG.debug("Set QAK-1 to {}", queryTag); + log.debug("Set QAK-1 to {}", queryTag); } Terser.set(ackQak, 2, 0, 1, 1, "AE"); diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/MllpAuditDataset.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/MllpAuditDataset.java index 9f54def442..b002eb77b4 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/MllpAuditDataset.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/MllpAuditDataset.java @@ -20,6 +20,7 @@ import org.openehealth.ipf.commons.audit.utils.AuditUtils; import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset; +import java.io.Serial; import java.util.Collections; import java.util.List; @@ -31,6 +32,7 @@ */ public abstract class MllpAuditDataset extends AuditDataset { + @Serial private static final long serialVersionUID = -4427222097816361541L; /** diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti10/Iti10AuditStrategy.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti10/Iti10AuditStrategy.java index 4638c433d2..05721c5fcc 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti10/Iti10AuditStrategy.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti10/Iti10AuditStrategy.java @@ -20,9 +20,9 @@ import org.openehealth.ipf.commons.audit.codes.EventActionCode; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder; -import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPatientRecordEventBuilder; import org.openehealth.ipf.commons.ihe.hl7v2.audit.QueryAuditDataset; +import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; import java.util.Map; @@ -45,7 +45,7 @@ public QueryAuditDataset enrichAuditDatasetFromRequest(QueryAuditDataset auditDa @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, QueryAuditDataset auditDataset) { - return new PatientRecordEventBuilder( + return new DefaultPatientRecordEventBuilder( auditContext, auditDataset, isServerSide() ? EventActionCode.Update : EventActionCode.Read, diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti30/Iti30AuditStrategy.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti30/Iti30AuditStrategy.java index 97e477ad50..9d83e1877a 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti30/Iti30AuditStrategy.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti30/Iti30AuditStrategy.java @@ -21,7 +21,7 @@ import org.openehealth.ipf.commons.audit.codes.EventActionCode; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPatientRecordEventBuilder; import org.openehealth.ipf.commons.ihe.hl7v2.audit.FeedAuditDataset; import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; @@ -41,33 +41,27 @@ public FeedAuditDataset enrichAuditDatasetFromRequest(FeedAuditDataset auditData @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FeedAuditDataset auditDataset) { - switch (auditDataset.getMessageType()) { - case "A28": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true) - }; - case "A31": - case "A47": - case "A24": - case "A37": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) - }; - case "A40": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false), - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) - }; - default: + return switch (auditDataset.getMessageType()) { + case "A28" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true) + }; + case "A31", "A47", "A24", "A37" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) + }; + case "A40" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false), + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) + }; + default -> throw new AuditException("Cannot create audit message for event " + auditDataset.getMessageType()); - } + }; } protected AuditMessage patientRecordAuditMessage(AuditContext auditContext, final FeedAuditDataset auditDataset, EventActionCode eventActionCode, boolean newPatientId) { - return new PatientRecordEventBuilder<>(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityManagement) + return new DefaultPatientRecordEventBuilder(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityManagement) // Type=MSH-10 (the literal string), Value=the value of MSH-10 (from the message content, base64 encoded) .addPatients( diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti31/Iti31AuditStrategy.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti31/Iti31AuditStrategy.java index 841cdc567f..65c8ad82cf 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti31/Iti31AuditStrategy.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti31/Iti31AuditStrategy.java @@ -21,7 +21,7 @@ import org.openehealth.ipf.commons.audit.codes.EventActionCode; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPatientRecordEventBuilder; import org.openehealth.ipf.commons.ihe.hl7v2.audit.FeedAuditDataset; import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; @@ -42,59 +42,31 @@ public FeedAuditDataset enrichAuditDatasetFromRequest(FeedAuditDataset auditData @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FeedAuditDataset auditDataset) { - switch (auditDataset.getMessageType()) { - case "A01": - case "A04": - case "A05": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true) - }; - case "A02": - case "A03": - case "A06": - case "A07": - case "A08": - case "A09": - case "A10": - case "A12": - case "A13": - case "A14": - case "A15": - case "A16": - case "A25": - case "A26": - case "A27": - case "A32": - case "A33": - case "A38": - case "A44": - case "A52": - case "A53": - case "A54": - case "A55": - case "Z99": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) - }; - case "A40": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false), - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) - }; - case "A41": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, true) - }; - default: + return switch (auditDataset.getMessageType()) { + case "A01", "A04", "A05" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true) + }; + case "A02", "A03", "A06", "A07", "A08", "A09", "A10", "A12", "A13", "A14", "A15", "A16", "A25", "A26", + "A27", "A32", "A33", "A38", "A44", "A52", "A53", "A54", "A55", "Z99" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) + }; + case "A40" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false), + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) + }; + case "A41" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, true) + }; + default -> throw new AuditException("Cannot create audit message for event " + auditDataset.getMessageType()); - } + }; } protected AuditMessage patientRecordAuditMessage(AuditContext auditContext, final FeedAuditDataset auditDataset, EventActionCode eventActionCode, boolean newPatientId) { - return new PatientRecordEventBuilder<>(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityManagement) + return new DefaultPatientRecordEventBuilder(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityManagement) // Type=MSH-10 (the literal string), Value=the value of MSH-10 (from the message content, base64 encoded) .addPatients( diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti64/IHEPatientRecordChangeLinkBuilder.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti64/IHEPatientRecordChangeLinkBuilder.java index b4bd4b9c27..f47563fc3e 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti64/IHEPatientRecordChangeLinkBuilder.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti64/IHEPatientRecordChangeLinkBuilder.java @@ -133,8 +133,4 @@ public IHEPatientRecordChangeLinkBuilder setSubmissionSet(Iti64AuditDataset audi return this; } - @Override - public void validate() { - super.validate(); - } } diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti8/Iti8AuditStrategy.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti8/Iti8AuditStrategy.java index 21d0de9a68..8d2b658ed7 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti8/Iti8AuditStrategy.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti8/Iti8AuditStrategy.java @@ -21,7 +21,7 @@ import org.openehealth.ipf.commons.audit.codes.EventActionCode; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPatientRecordEventBuilder; import org.openehealth.ipf.commons.ihe.hl7v2.audit.FeedAuditDataset; import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; @@ -46,25 +46,20 @@ public FeedAuditDataset createAuditDataset() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, FeedAuditDataset auditDataset) { - switch (auditDataset.getMessageType()) { - case "A01": - case "A04": - case "A05": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true) - }; - case "A08": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) - }; - case "A40": - return new AuditMessage[]{ - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false), - patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) - }; - default: + return switch (auditDataset.getMessageType()) { + case "A01", "A04", "A05" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Create, true) + }; + case "A08" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) + }; + case "A40" -> new AuditMessage[]{ + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Delete, false), + patientRecordAuditMessage(auditContext, auditDataset, EventActionCode.Update, true) + }; + default -> throw new AuditException("Cannot create audit message for event " + auditDataset.getMessageType()); - } + }; } @@ -72,7 +67,7 @@ protected AuditMessage patientRecordAuditMessage(AuditContext auditContext, final FeedAuditDataset auditDataset, EventActionCode eventActionCode, boolean newPatientId) { - return new PatientRecordEventBuilder<>(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityFeed) + return new DefaultPatientRecordEventBuilder(auditContext, auditDataset, eventActionCode, MllpEventTypeCode.PatientIdentityFeed) // Type=MSH-10 (the literal string), Value=the value of MSH-10 (from the message content, base64 encoded) .addPatients( diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti9/Iti9AuditStrategy.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti9/Iti9AuditStrategy.java index 6b2695a076..fa38a2b027 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti9/Iti9AuditStrategy.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/iti9/Iti9AuditStrategy.java @@ -19,7 +19,7 @@ import org.openehealth.ipf.commons.audit.AuditContext; import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; import org.openehealth.ipf.commons.ihe.hl7v2.audit.QueryAuditDataset; @@ -54,7 +54,7 @@ public boolean enrichAuditDatasetFromResponse(QueryAuditDataset auditDataset, @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, QueryAuditDataset auditDataset) { - return new QueryInformationBuilder(auditContext,auditDataset, MllpEventTypeCode.PIXQuery) + return new DefaultQueryInformationBuilder(auditContext,auditDataset, MllpEventTypeCode.PIXQuery) .setQueryParameters( auditDataset.getMessageControlId(), PIXQuery, diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/pdqcore/PdqAuditStrategy.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/pdqcore/PdqAuditStrategy.java index baf275873c..2500c07699 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/pdqcore/PdqAuditStrategy.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/audit/pdqcore/PdqAuditStrategy.java @@ -20,7 +20,7 @@ import org.openehealth.ipf.commons.audit.model.AuditMessage; import org.openehealth.ipf.commons.audit.types.ParticipantObjectIdType; import org.openehealth.ipf.commons.ihe.core.atna.AuditStrategySupport; -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder; +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder; import org.openehealth.ipf.commons.ihe.hl7v2.audit.codes.MllpEventTypeCode; import org.openehealth.ipf.commons.ihe.hl7v2.audit.QueryAuditDataset; @@ -63,7 +63,7 @@ public QueryAuditDataset createAuditDataset() { @Override public AuditMessage[] makeAuditMessage(AuditContext auditContext, QueryAuditDataset auditDataset) { - return new QueryInformationBuilder(auditContext, auditDataset, eventTypeCode) + return new DefaultQueryInformationBuilder(auditContext, auditDataset, eventTypeCode) .setQueryParameters( auditDataset.getMessageControlId(), participantObjectIdType, diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pam/v25/message/ADT_A01.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pam/v25/message/ADT_A01.java index 1ce11016d9..718f063d14 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pam/v25/message/ADT_A01.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pam/v25/message/ADT_A01.java @@ -52,7 +52,6 @@ protected Map, Cardinality> structures(Map, Cardinality> structures(Map, Cardinality> structures(Map, Cardinality> structures(Map, Cardinality> structures(Map, Cardinality> structures(Map, Cardinality> structures(Map new CE(getMessage()); + case 1, 4, 5, 6 -> new ST(getMessage()); + case 2 -> new QIP(getMessage()); + case 3 -> new NM(getMessage()); + case 7 -> new CX(getMessage()); + default -> null; + }; } } \ No newline at end of file diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pix/v231/message/ADT_A01.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pix/v231/message/ADT_A01.java index c768c32e6e..33d1cd1616 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pix/v231/message/ADT_A01.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pix/v231/message/ADT_A01.java @@ -45,7 +45,6 @@ protected Map, Cardinality> structures(Map new CE(getMessage()); + case 1 -> new ST(getMessage()); + case 2, 3 -> new CX(getMessage()); + default -> null; + }; } } \ No newline at end of file diff --git a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/storage/JCacheInteractiveContinuationStorage.java b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/storage/JCacheInteractiveContinuationStorage.java index cc97b713c2..e6bf7378e3 100644 --- a/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/storage/JCacheInteractiveContinuationStorage.java +++ b/commons/ihe/hl7v2/src/main/java/org/openehealth/ipf/commons/ihe/hl7v2/storage/JCacheInteractiveContinuationStorage.java @@ -34,7 +34,7 @@ */ public class JCacheInteractiveContinuationStorage implements InteractiveContinuationStorage { - private static final Logger LOG = LoggerFactory.getLogger(JCacheInteractiveContinuationStorage.class); + private static final Logger log = LoggerFactory.getLogger(JCacheInteractiveContinuationStorage.class); private final Cache cache; @@ -48,7 +48,7 @@ public JCacheInteractiveContinuationStorage(Cache(clientSpan.tags()), new HashMap<>(serverSpan.tags())) assertNotEquals(clientSpan.id(), serverSpan.id()) assertEquals(clientSpan.id(), serverSpan.parentId()) + assertEquals(clientSpan.traceId(), serverSpan.traceId()) } class MockReporter extends SpanHandler { diff --git a/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageOtelTracerTest.groovy b/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageOtelTracerTest.groovy new file mode 100644 index 0000000000..e302d8daac --- /dev/null +++ b/commons/ihe/hl7v2/src/test/groovy/org/openehealth/ipf/commons/ihe/hl7v2/tracing/MessageOtelTracerTest.groovy @@ -0,0 +1,100 @@ +/* + * Copyright 2024 the original author or authors. + * + * 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. + */ + +package org.openehealth.ipf.commons.ihe.hl7v2.tracing + + +import ca.uhn.hl7v2.HapiContext +import ca.uhn.hl7v2.model.Message +import io.micrometer.tracing.SpanCustomizer +import io.micrometer.tracing.otel.bridge.ArrayListSpanProcessor +import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext +import io.micrometer.tracing.otel.bridge.OtelPropagator +import io.micrometer.tracing.otel.bridge.OtelTracer +import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.context.propagation.ContextPropagators +import io.opentelemetry.extension.trace.propagation.B3Propagator +import io.opentelemetry.sdk.OpenTelemetrySdk +import io.opentelemetry.sdk.resources.Resource +import io.opentelemetry.sdk.trace.SdkTracerProvider +import io.opentelemetry.sdk.trace.samplers.Sampler +import org.junit.jupiter.api.Test +import org.openehealth.ipf.commons.ihe.hl7v2.definitions.HapiContextFactory +import org.openehealth.ipf.modules.hl7.message.MessageUtils + +import static org.junit.jupiter.api.Assertions.* + +/** + * @author Christian Ohr + */ +class MessageOtelTracerTest { + + private static final HapiContext CONTEXT = HapiContextFactory.createHapiContext() + + @Test + void traceMessage() { + ArrayListSpanProcessor reporter = new ArrayListSpanProcessor() + + // Otel setup + var sdkTracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(reporter) + .setResource(Resource.getDefault()) + .setSampler(Sampler.alwaysOn()) + .build() + var otelPropagator = ContextPropagators.create(B3Propagator.injectingMultiHeaders()) + var openTelemetrySdkBuilder = OpenTelemetrySdk.builder() + .setPropagators(otelPropagator) + .setTracerProvider(sdkTracerProvider) + var otelTracer = openTelemetrySdkBuilder.build().getTracer("io.micrometer.micrometer-tracing") + + // Micrometer Otel Bridge + def propagator = new OtelPropagator(otelPropagator, otelTracer) + def tracer = new OtelTracer(otelTracer, new OtelCurrentTraceContext(), new OtelTracer.EventPublisher() { + @Override + void publishEvent(Object event) { + } + }) + + def messageTracer = new MessageTracer(tracer, propagator) + def sending = MessageUtils.makeMessage(CONTEXT, 'ORU', 'R01', '2.5') + + messageTracer.sendMessage(sending, "producer", new Handler() { + @Override + void accept(Message receiving, SpanCustomizer sc1) { + Thread.sleep(100) + messageTracer.receiveMessage(receiving, "consumer", new Handler() { + @Override + void accept(Message received, SpanCustomizer sc2) { + assertTrue(received.get('ZTR').empty) + } + }) + } + }) + + // Check a few things + assertEquals(2, reporter.spans().size()) + + def clientSpan = reporter.spans().find { span -> span.kind == SpanKind.CLIENT } + def serverSpan = reporter.spans().find { span -> span.kind == SpanKind.SERVER } + + assertFalse(clientSpan.attributes.isEmpty()) + assertEquals(clientSpan.attributes.asMap(), serverSpan.attributes.asMap()) + assertNotEquals(clientSpan.spanId, serverSpan.spanId) + assertEquals(clientSpan.traceId, serverSpan.traceId) + assertEquals(clientSpan.spanId, serverSpan.parentSpanId) + } + +} diff --git a/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSP_K21Test.java b/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSPK21Test.java similarity index 80% rename from commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSP_K21Test.java rename to commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSPK21Test.java index 7cae102bb2..f86082b238 100644 --- a/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSP_K21Test.java +++ b/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSPK21Test.java @@ -18,16 +18,14 @@ import ca.uhn.hl7v2.model.v25.group.RSP_K21_QUERY_RESPONSE; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests the fix of issue #69 (Problem with RSP_K21.getRSP_K21_QUERY_RESPONSE()) * * @author Mitko Kolev */ -public class RSP_K21Test { +public class RSPK21Test { @Test public void testGetQUERY_RESPONSE(){ @@ -35,7 +33,7 @@ public void testGetQUERY_RESPONSE(){ var msg = new RSP_K21(); var response = msg.getQUERY_RESPONSE(); assertNotNull (response); - assertTrue(response instanceof RSP_K21_QUERY_RESPONSE); + assertInstanceOf(RSP_K21_QUERY_RESPONSE.class, response); } @Test @@ -45,7 +43,7 @@ public void testGetRSP_K21_QUERY_RESPONSEReps(){ } @Test - public void testGetRSP_K21_QUERY_RESPONSERepsWithParams() throws Exception { + public void testGetRSP_K21_QUERY_RESPONSERepsWithParams() { var msg = new RSP_K21(); var response = msg.getQUERY_RESPONSE(0); assertNotNull (response); diff --git a/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSP_ZV2Test.java b/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSPZV2Test.java similarity index 93% rename from commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSP_ZV2Test.java rename to commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSPZV2Test.java index d9ebfa0665..ee16b8288d 100644 --- a/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSP_ZV2Test.java +++ b/commons/ihe/hl7v2/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2/definitions/pdq/v25/message/RSPZV2Test.java @@ -26,7 +26,7 @@ * * @author Mitko Kolev */ -public class RSP_ZV2Test { +public class RSPZV2Test { @Test public void testGetQUERY_RESPONSE(){ @@ -43,7 +43,7 @@ public void testGetRSP_ZV2_QUERY_RESPONSEReps(){ } @Test - public void testGetRSP_ZV2_QUERY_RESPONSERepsWithParams() throws Exception { + public void testGetRSP_ZV2_QUERY_RESPONSERepsWithParams() { var msg = new RSP_ZV2(); var response = msg.getQUERY_RESPONSE(0); assertNotNull (response); diff --git a/commons/ihe/hl7v2ws/pom.xml b/commons/ihe/hl7v2ws/pom.xml index b353e7c849..f73f54e75a 100644 --- a/commons/ihe/hl7v2ws/pom.xml +++ b/commons/ihe/hl7v2ws/pom.xml @@ -29,6 +29,7 @@ org.openehealth.ipf.gazelle ipf-gazelle-validation-profiles-pcd + true diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/AbstractPCD01ValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/AbstractPCD01ValidatorTest.java index 52e93a11d8..18149c8f23 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/AbstractPCD01ValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/AbstractPCD01ValidatorTest.java @@ -31,7 +31,7 @@ public abstract class AbstractPCD01ValidatorTest { - private HapiContext hapiContext = HapiContextFactory.createHapiContext(PcdTransactions.PCD1); + private final HapiContext hapiContext = HapiContextFactory.createHapiContext(PcdTransactions.PCD1); protected ORU_R01 maximumMessage; diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/Pcd01ValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/Pcd01ValidatorTest.java index fdf9e103a0..29b36a5e14 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/Pcd01ValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/Pcd01ValidatorTest.java @@ -29,19 +29,19 @@ */ public class Pcd01ValidatorTest extends AbstractPCD01ValidatorTest { - static String MSH = "MSH|^~\\&|AcmeInc^ACDE48234567ABCD^EUI-64||||20090713090030+0500||ORU^R01^ORU_R01|MSGID1234|P|2.6|||NE|AL|||||IHE PCD ORU-R01 2006^HL7^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r"; - static String PID = "PID|||789567^^^Imaginary Hospital^PI||Doe^John^Joseph^^^^L^A|||M\r"; - static String OBR = "OBR|1|AB12345^AcmeAHDInc^ACDE48234567ABCD^EUI-64|CD12345^AcmeAHDInc^ACDE48234567ABCD^EUI-64|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|||20090813095715+0500\r"; - static String OBX1 = "OBX|1||528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|||||||R|||||||0123456789ABCDEF^EUI-64\r"; - static String OBX2 = "OBX|2||150020^MDC_PRESS_BLD_NONINV^MDC|1.0.1|||||||R|||20090813095715+0500\r"; - static String OBX3 = "OBX|3|NM|150021^MDC_PRESS_BLD_NONINV_SYS^MDC|1.0.1.1|120|266016^MDC_DIM_MMHG^MDC|||||R\r"; - static String OBX4 = "OBX|4|NM|150022^MDC_PRESS_BLD_NONINV_DIA^MDC|1.0.1.2|80|266016^MDC_DIM_MMHG^MDC|||||R\r"; - static String VALID = MSH + PID + OBR + OBX1 + OBX2 + OBX3 + OBX4; + static final String MSH = "MSH|^~\\&|AcmeInc^ACDE48234567ABCD^EUI-64||||20090713090030+0500||ORU^R01^ORU_R01|MSGID1234|P|2.6|||NE|AL|||||IHE PCD ORU-R01 2006^HL7^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r"; + static final String PID = "PID|||789567^^^Imaginary Hospital^PI||Doe^John^Joseph^^^^L^A|||M\r"; + static final String OBR = "OBR|1|AB12345^AcmeAHDInc^ACDE48234567ABCD^EUI-64|CD12345^AcmeAHDInc^ACDE48234567ABCD^EUI-64|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|||20090813095715+0500\r"; + static final String OBX1 = "OBX|1||528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|||||||R|||||||0123456789ABCDEF^EUI-64\r"; + static final String OBX2 = "OBX|2||150020^MDC_PRESS_BLD_NONINV^MDC|1.0.1|||||||R|||20090813095715+0500\r"; + static final String OBX3 = "OBX|3|NM|150021^MDC_PRESS_BLD_NONINV_SYS^MDC|1.0.1.1|120|266016^MDC_DIM_MMHG^MDC|||||R\r"; + static final String OBX4 = "OBX|4|NM|150022^MDC_PRESS_BLD_NONINV_DIA^MDC|1.0.1.2|80|266016^MDC_DIM_MMHG^MDC|||||R\r"; + static final String VALID = MSH + PID + OBR + OBX1 + OBX2 + OBX3 + OBX4; - static String ACK_MSH = "MSH|^~\\&|Stepstone||AcmeInc^ACDE48234567ABCD^EUI64||20090726095731+0500||ACK^R01^ACK|AMSGID1234|P|2.6|||NE|AL|||||IHE PCD ORU-R01 2006^HL7^2.16.840.1.113883.9.n.m^HL7\r"; - static String MSA = "MSA|CE|20070701132554000008\r"; - static String ERR = "ERR|||100|E|||Missing required OBR segment\r"; - static String VALID_RESPONSE = ACK_MSH + MSA + ERR; + static final String ACK_MSH = "MSH|^~\\&|Stepstone||AcmeInc^ACDE48234567ABCD^EUI64||20090726095731+0500||ACK^R01^ACK|AMSGID1234|P|2.6|||NE|AL|||||IHE PCD ORU-R01 2006^HL7^2.16.840.1.113883.9.n.m^HL7\r"; + static final String MSA = "MSA|CE|20070701132554000008\r"; + static final String ERR = "ERR|||100|E|||Missing required OBR segment\r"; + static final String VALID_RESPONSE = ACK_MSH + MSA + ERR; @Test diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01DataTypesTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01DataTypesTest.java similarity index 95% rename from commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01DataTypesTest.java rename to commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01DataTypesTest.java index 8fa4a66ff9..73649bb2a4 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01DataTypesTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01DataTypesTest.java @@ -24,7 +24,7 @@ * @author Kingsley Nwaigbo * */ -public class QA_Pcd01DataTypesTest extends AbstractPCD01ValidatorTest { +public class QAPcd01DataTypesTest extends AbstractPCD01ValidatorTest { // ################ Data types ############################### @@ -136,7 +136,7 @@ public void testXTN_AllFilledPID13_NET() throws HL7Exception { } @Test - public void testMissingXTN2() throws HL7Exception { + public void testMissingXTN2() { assertThrows(HL7Exception.class, () -> validate(maxMsgReplace("^PRN^PH^^^^123456", "^^PH^wan@continua.com^001^760^123456^02^Any text^GA"))); } diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01MSHValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01MSHValidatorTest.java similarity index 94% rename from commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01MSHValidatorTest.java rename to commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01MSHValidatorTest.java index cbd6fd2ced..9a33406c63 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01MSHValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01MSHValidatorTest.java @@ -24,7 +24,7 @@ * @author Kingsley Nwaigbo * */ -public class QA_Pcd01MSHValidatorTest extends AbstractPCD01ValidatorTest { +public class QAPcd01MSHValidatorTest extends AbstractPCD01ValidatorTest { @Test public void testMaximalMessage() throws HL7Exception { diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01OBRValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01OBRValidatorTest.java similarity index 95% rename from commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01OBRValidatorTest.java rename to commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01OBRValidatorTest.java index 6618ac64db..aa820feaf3 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01OBRValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01OBRValidatorTest.java @@ -27,7 +27,7 @@ * */ @Disabled -public class QA_Pcd01OBRValidatorTest extends AbstractPCD01ValidatorTest { +public class QAPcd01OBRValidatorTest extends AbstractPCD01ValidatorTest { @Test public void testMaximalMessage() throws HL7Exception { diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01OBXValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01OBXValidatorTest.java similarity index 95% rename from commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01OBXValidatorTest.java rename to commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01OBXValidatorTest.java index b5add56929..1ca51328d7 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01OBXValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01OBXValidatorTest.java @@ -29,7 +29,7 @@ * */ @Disabled -public class QA_Pcd01OBXValidatorTest extends AbstractPCD01ValidatorTest { +public class QAPcd01OBXValidatorTest extends AbstractPCD01ValidatorTest { @Test public void testSyntheticMessageTrimmed() throws HL7Exception{ @@ -64,7 +64,7 @@ public void testOBX2_SN() { @Disabled @Test - public void testMissingOBX2_filledOBX11() throws HL7Exception { + public void testMissingOBX2_filledOBX11() { // The check "OBX-2 must be valued if the value of OBX-11 is not X" seems to be too restrictive // add the checkOBX2WhenOBX11NotX in PCD01Validator to switch on the check. assertThrows(ValidationException.class, () -> diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01PIDPV1ValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01PIDPV1ValidatorTest.java similarity index 94% rename from commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01PIDPV1ValidatorTest.java rename to commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01PIDPV1ValidatorTest.java index e029bbb7fb..40f87bae3b 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QA_Pcd01PIDPV1ValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/pcd01/QAPcd01PIDPV1ValidatorTest.java @@ -24,7 +24,7 @@ * @author Kingsley Nwaigbo * */ -public class QA_Pcd01PIDPV1ValidatorTest extends AbstractPCD01ValidatorTest { +public class QAPcd01PIDPV1ValidatorTest extends AbstractPCD01ValidatorTest { // ################ PID Segment tests ############################### diff --git a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/wan/ContinuaWanValidatorTest.java b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/wan/ContinuaWanValidatorTest.java index 7472ec3c1b..0a1f55bbaa 100644 --- a/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/wan/ContinuaWanValidatorTest.java +++ b/commons/ihe/hl7v2ws/src/test/java/org/openehealth/ipf/commons/ihe/hl7v2ws/wan/ContinuaWanValidatorTest.java @@ -84,6 +84,7 @@ public void testInvalidResponseMessage() { assertThrows(ValidationException.class, () -> validate(load(getParser(), "wan/invalid-wan-response.hl7v2"))); } + @Test @Disabled @Override public void testSyntheticResponseMessage() { diff --git a/commons/ihe/hl7v3/pom.xml b/commons/ihe/hl7v3/pom.xml index f59b948ce1..1ab8ea12fa 100644 --- a/commons/ihe/hl7v3/pom.xml +++ b/commons/ihe/hl7v3/pom.xml @@ -35,12 +35,6 @@ spring-context true - org.apache.commons commons-lang3 diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditStrategy.groovy index 7c3da957fc..36cd105544 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditStrategy.groovy @@ -30,7 +30,7 @@ import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.iiToCx */ abstract class Hl7v3AuditStrategy extends AuditStrategySupport { - private static final transient Logger LOG = LoggerFactory.getLogger(Hl7v3AuditStrategy.class) + private static final transient Logger log = LoggerFactory.getLogger(Hl7v3AuditStrategy.class) Hl7v3AuditStrategy(boolean serverSide) { super(serverSide) @@ -67,7 +67,7 @@ abstract class Hl7v3AuditStrategy extends AuditStrategySupport 0 ? auditDataset.patientIds.head() : null) : auditDataset.oldPatientId - return new PatientRecordEventBuilder<>(auditContext, auditDataset, eventActionCode, Hl7v3EventTypeCode.PatientIdentityFeed, auditDataset.purposesOfUse) + return new DefaultPatientRecordEventBuilder(auditContext, auditDataset, eventActionCode, Hl7v3EventTypeCode.PatientIdentityFeed, auditDataset.purposesOfUse) // Type=II (the literal string), Value=the value of the message ID (from the message content, base64 encoded) .addPatients("II", auditDataset.messageId, patientId) diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti45/Iti45AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti45/Iti45AuditStrategy.groovy index 04d4258d63..147c6a5e5d 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti45/Iti45AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti45/Iti45AuditStrategy.groovy @@ -18,16 +18,13 @@ package org.openehealth.ipf.commons.ihe.hl7v3.iti45 import groovy.xml.slurpersupport.GPathResult import org.openehealth.ipf.commons.audit.AuditContext import org.openehealth.ipf.commons.audit.model.AuditMessage -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditStrategy import org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3EventTypeCode +import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.* import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.PIXQuery -import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.idString -import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.iiToCx -import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.render - /** * @author Dmytro Rud */ @@ -74,7 +71,7 @@ class Iti45AuditStrategy extends Hl7v3AuditStrategy { @Override AuditMessage[] makeAuditMessage(AuditContext auditContext, Hl7v3AuditDataset auditDataset) { - new QueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.PIXQuery, auditDataset.getPurposesOfUse()) + new DefaultQueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.PIXQuery, auditDataset.getPurposesOfUse()) .addPatients(auditDataset.patientIds) .setQueryParameters(auditDataset.messageId, PIXQuery, auditDataset.requestPayload) .getMessages() diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti46/Iti46AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti46/Iti46AuditStrategy.groovy index e01ef1743b..0be7aa92ea 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti46/Iti46AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti46/Iti46AuditStrategy.groovy @@ -18,7 +18,7 @@ package org.openehealth.ipf.commons.ihe.hl7v3.iti46 import org.openehealth.ipf.commons.audit.AuditContext import org.openehealth.ipf.commons.audit.codes.EventActionCode import org.openehealth.ipf.commons.audit.model.AuditMessage -import org.openehealth.ipf.commons.ihe.core.atna.event.PatientRecordEventBuilder +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultPatientRecordEventBuilder import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditStrategy import org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3EventTypeCode @@ -51,7 +51,7 @@ class Iti46AuditStrategy extends Hl7v3AuditStrategy { @Override AuditMessage[] makeAuditMessage(AuditContext auditContext, Hl7v3AuditDataset auditDataset) { - new PatientRecordEventBuilder( + new DefaultPatientRecordEventBuilder( auditContext, auditDataset, isServerSide() ? EventActionCode.Update : EventActionCode.Read, diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti47/Iti47AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti47/Iti47AuditStrategy.groovy index afab6e9bbb..7660e010db 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti47/Iti47AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti47/Iti47AuditStrategy.groovy @@ -18,14 +18,14 @@ package org.openehealth.ipf.commons.ihe.hl7v3.iti47 import groovy.xml.slurpersupport.GPathResult import org.openehealth.ipf.commons.audit.AuditContext import org.openehealth.ipf.commons.audit.model.AuditMessage -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditStrategy import org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3EventTypeCode -import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.PatientDemographicsQuery import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.idString import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.render +import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.PatientDemographicsQuery /** * @author Dmytro Rud @@ -74,7 +74,7 @@ class Iti47AuditStrategy extends Hl7v3AuditStrategy { @Override AuditMessage[] makeAuditMessage(AuditContext auditContext, Hl7v3AuditDataset auditDataset) { - new QueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.PatientDemographicsQuery, auditDataset.getPurposesOfUse()) + new DefaultQueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.PatientDemographicsQuery, auditDataset.getPurposesOfUse()) .setQueryParameters(auditDataset.messageId, PatientDemographicsQuery, auditDataset.requestPayload) .addPatients(auditDataset.patientIds) .getMessages() diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55AuditStrategy.groovy index 4c38523569..6afbd46da2 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55AuditStrategy.groovy @@ -17,14 +17,14 @@ package org.openehealth.ipf.commons.ihe.hl7v3.iti55 import org.openehealth.ipf.commons.audit.AuditContext import org.openehealth.ipf.commons.audit.model.AuditMessage +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder import org.openehealth.ipf.commons.ihe.core.atna.event.IHEAuditMessageBuilder -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset import org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3EventTypeCode import org.openehealth.ipf.commons.ihe.hl7v3.iti47.Iti47AuditStrategy -import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.CrossGatewayPatientDiscovery import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.idString +import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.CrossGatewayPatientDiscovery /** * Generic audit strategy for ITI-55 (XCPD). @@ -54,7 +54,7 @@ class Iti55AuditStrategy extends Iti47AuditStrategy { @Override AuditMessage[] makeAuditMessage(AuditContext auditContext, Hl7v3AuditDataset auditDataset) { - QueryInformationBuilder builder = new QueryInformationBuilder<>(auditContext, auditDataset, Hl7v3EventTypeCode.CrossGatewayPatientDiscovery, auditDataset.getPurposesOfUse()) + def builder = new DefaultQueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.CrossGatewayPatientDiscovery, auditDataset.getPurposesOfUse()) // No patient identifiers are included for the Initiating Gateway if (isServerSide()) { builder.addPatients(auditDataset.patientIds) diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55Utils.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55Utils.groovy index 14d7b68139..a2ca3718c0 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55Utils.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti55/Iti55Utils.groovy @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory * @author Dmytro Rud */ abstract class Iti55Utils { - private static final transient Logger LOG = LoggerFactory.getLogger(Iti55Utils.class) + private static final transient Logger log = LoggerFactory.getLogger(Iti55Utils.class) private Iti55Utils() { throw new IllegalStateException('cannot instantiate helper class') diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti56/Iti56AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti56/Iti56AuditStrategy.groovy index a1ddb3ffa4..0653600cad 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti56/Iti56AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/iti56/Iti56AuditStrategy.groovy @@ -19,15 +19,15 @@ import groovy.xml.slurpersupport.GPathResult import org.openehealth.ipf.commons.audit.AuditContext import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator import org.openehealth.ipf.commons.audit.model.AuditMessage -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditStrategy import org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3EventTypeCode import org.slf4j.Logger import org.slf4j.LoggerFactory -import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.PatientLocationQuery import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.iiToCx +import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.PatientLocationQuery /** * Generic audit strategy for ITI-56 (XCPD). @@ -36,7 +36,7 @@ import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.iiToCx */ class Iti56AuditStrategy extends Hl7v3AuditStrategy { - private static final Logger LOG = LoggerFactory.getLogger(Iti56AuditStrategy) + private static final Logger log = LoggerFactory.getLogger(Iti56AuditStrategy) Iti56AuditStrategy(boolean serverSide) { super(serverSide) @@ -57,7 +57,7 @@ class Iti56AuditStrategy extends Hl7v3AuditStrategy { (gpath.namespaceURI() == 'urn:ihe:iti:xcpd:2009')) ? EventOutcomeIndicator.Success : EventOutcomeIndicator.SeriousFailure } catch (Exception e) { - LOG.error('Exception in ITI-56 audit strategy', e) + log.error('Exception in ITI-56 audit strategy', e) return EventOutcomeIndicator.MajorFailure } } @@ -71,7 +71,7 @@ class Iti56AuditStrategy extends Hl7v3AuditStrategy { @Override AuditMessage[] makeAuditMessage(AuditContext auditContext, Hl7v3AuditDataset auditDataset) { - new QueryInformationBuilder<>(auditContext, auditDataset, Hl7v3EventTypeCode.PatientLocationQuery, auditDataset.getPurposesOfUse()) + new DefaultQueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.PatientLocationQuery, auditDataset.getPurposesOfUse()) .addPatients(auditDataset.patientIds) .setQueryParameters("PatientLocationQueryRequest", PatientLocationQuery, auditDataset.requestPayload) .getMessages() diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/pcc1/Pcc1AuditStrategy.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/pcc1/Pcc1AuditStrategy.groovy index dc52ecd0bb..250d549ff5 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/pcc1/Pcc1AuditStrategy.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/pcc1/Pcc1AuditStrategy.groovy @@ -18,15 +18,14 @@ package org.openehealth.ipf.commons.ihe.hl7v3.pcc1 import groovy.xml.slurpersupport.GPathResult import org.openehealth.ipf.commons.audit.AuditContext import org.openehealth.ipf.commons.audit.model.AuditMessage -import org.openehealth.ipf.commons.ihe.core.atna.event.QueryInformationBuilder +import org.openehealth.ipf.commons.ihe.core.atna.event.DefaultQueryInformationBuilder import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditStrategy import org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3EventTypeCode -import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.QueryExistingData import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.idString import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.render - +import static org.openehealth.ipf.commons.ihe.hl7v3.audit.codes.Hl7v3ParticipantObjectIdTypeCode.QueryExistingData /** * @author Dmytro Rud */ @@ -49,7 +48,8 @@ class Pcc1AuditStrategy extends Hl7v3AuditStrategy { // patient IDs from request def patientIds = [] as Set addPatientIds(qbp.parameterList.patientId.value, patientIds) - auditDataset.setPatientIds(patientIds.toArray(new String[patientIds.size()]) ?: null) + String[] patientIdArray = patientIds.toArray(new String[patientIds.size()]) + auditDataset.setPatientIds(patientIdArray ?: null) // dump of the "queryByParameter" element auditDataset.requestPayload = render(qbp) @@ -58,7 +58,7 @@ class Pcc1AuditStrategy extends Hl7v3AuditStrategy { @Override AuditMessage[] makeAuditMessage(AuditContext auditContext, Hl7v3AuditDataset auditDataset) { - new QueryInformationBuilder<>(auditContext, auditDataset, Hl7v3EventTypeCode.QueryExistingData, auditDataset.getPurposesOfUse()) + new DefaultQueryInformationBuilder(auditContext, auditDataset, Hl7v3EventTypeCode.QueryExistingData, auditDataset.getPurposesOfUse()) .setQueryParameters(auditDataset.messageId, QueryExistingData, auditDataset.requestPayload) .addPatients(auditDataset.patientIds) .getMessages() diff --git a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/translation/Utils.groovy b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/translation/Utils.groovy index ebf9e3ab21..c92a5d79fe 100644 --- a/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/translation/Utils.groovy +++ b/commons/ihe/hl7v3/src/main/groovy/org/openehealth/ipf/commons/ihe/hl7v3/translation/Utils.groovy @@ -33,7 +33,7 @@ import static org.openehealth.ipf.commons.ihe.hl7v3.Hl7v3Utils.* class Utils { public static final String HL7V2_NULL = '""' - private static final Pattern OID_PATTERN = Pattern.compile("[1-9][0-9]*(\\.(0|([1-9][0-9]*)))+"); + private static final Pattern OID_PATTERN = Pattern.compile("[1-9][0-9]*(\\.(0|([1-9][0-9]*)))+") /** * Returns the next repetition of the given HL7 v2 field/segment/etc. diff --git a/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/Hl7v3ValidationProfile.java b/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/Hl7v3ValidationProfile.java index e0bd5fecd7..fc0364eba4 100644 --- a/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/Hl7v3ValidationProfile.java +++ b/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/Hl7v3ValidationProfile.java @@ -30,7 +30,7 @@ public class Hl7v3ValidationProfile implements CombinedXmlValidationProfile { public static final String DEFAULT_XSD = ""; public static final String GAZELLE_PIXPDQV3_SCHEMATRON = "/schematron/gazelle-pixpdqv3.sch.xml"; - static class Row { + public static class Row { private static final String HL7V3_SCHEMAS_PATH = "/schema/HL7V3/NE2008/multicacheschemas/"; @Getter final String rootElementName; diff --git a/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditDataset.java b/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditDataset.java index 82b294f8c6..acae63457a 100644 --- a/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditDataset.java +++ b/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/audit/Hl7v3AuditDataset.java @@ -19,6 +19,8 @@ import lombok.Setter; import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset; +import java.io.Serial; + /** * Generic audit dataset for IHE PIX/PDQ v3 transactions. @@ -27,6 +29,7 @@ */ public class Hl7v3AuditDataset extends WsAuditDataset { + @Serial private static final long serialVersionUID = -7303748425104562452L; /** HL7v3 message ID. */ diff --git a/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/storage/EhcacheHl7v3ContinuationStorage.java b/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/storage/EhcacheHl7v3ContinuationStorage.java index 3e78b2ca72..18a7d78c28 100644 --- a/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/storage/EhcacheHl7v3ContinuationStorage.java +++ b/commons/ihe/hl7v3/src/main/java/org/openehealth/ipf/commons/ihe/hl7v3/storage/EhcacheHl7v3ContinuationStorage.java @@ -21,8 +21,6 @@ import java.io.Serializable; -import static java.util.Objects.requireNonNull; - /** * @author Dmytro Rud * @author Christian Ohr diff --git a/commons/ihe/hl7v3model/pom.xml b/commons/ihe/hl7v3model/pom.xml index 92e546e73e..9521466514 100644 --- a/commons/ihe/hl7v3model/pom.xml +++ b/commons/ihe/hl7v3model/pom.xml @@ -17,6 +17,10 @@ org.openehealth.ipf.commons ipf-commons-ihe-core + + ca.uhn.hapi + hapi-base + org.apache.commons commons-lang3 diff --git a/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/DoubleAdapter.java b/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/DoubleAdapter.java index 0d42a8c002..a58844453f 100644 --- a/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/DoubleAdapter.java +++ b/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/DoubleAdapter.java @@ -12,10 +12,9 @@ public class DoubleAdapter extends XmlAdapter{ * * @param v the double to be marshalled * @return the marshaling - * @throws Exception the exception thrown if problem during marshalling - */ + */ @Override - public String marshal(final Double v) throws Exception { + public String marshal(final Double v) { if ((v != null) && !Double.isInfinite(v) && !Double.isNaN(v)) { return String.valueOf(v.doubleValue()); } @@ -27,10 +26,9 @@ public String marshal(final Double v) throws Exception { * * @param v the String to be unmarshalled. * @return the double, result of unmarshalling. - * @throws Exception thrown if problem of unmarshalling. - */ + */ @Override - public Double unmarshal(final String v) throws Exception { + public Double unmarshal(final String v) { if ((v == null) || (v.isEmpty())){ return null; } diff --git a/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/IntegerAdapter.java b/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/IntegerAdapter.java index bd5263a3d7..e8bc5b7b50 100644 --- a/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/IntegerAdapter.java +++ b/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/adapters/IntegerAdapter.java @@ -5,7 +5,7 @@ public class IntegerAdapter extends XmlAdapter{ @Override - public String marshal(final Integer v) throws Exception { + public String marshal(final Integer v) { if (v != null) { return String.valueOf(v.intValue()); } @@ -13,7 +13,7 @@ public String marshal(final Integer v) throws Exception { } @Override - public Integer unmarshal(final String v) throws Exception { + public Integer unmarshal(final String v) { if ((v == null) || (v.isEmpty())){ return null; } diff --git a/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/com/templates/Template.java b/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/com/templates/Template.java index 3454670261..f5d7fa2397 100644 --- a/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/com/templates/Template.java +++ b/commons/ihe/hl7v3model/src/main/java/net/ihe/gazelle/com/templates/Template.java @@ -8,9 +8,11 @@ package net.ihe.gazelle.com.templates; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; @@ -52,7 +54,8 @@ public class Template implements Serializable { /** * */ - private static final long serialVersionUID = 1L; + @Serial + private static final long serialVersionUID = 1L; private List templateId; @@ -147,11 +150,7 @@ public List