From ccb264c0890718de1866f9f33cd8d3d12bb007ea Mon Sep 17 00:00:00 2001 From: Daniel Hahne Date: Tue, 7 Jan 2025 10:41:29 +0100 Subject: [PATCH] Add `pageSize` to EverythingDataSelectorConfig --- .github/test/cd-agent/application.yaml | 3 ++ .github/test/cd-agent/projects/example.yaml | 2 + .../fts/cda/impl/EverythingDataSelector.java | 13 +++--- .../impl/EverythingDataSelectorConfig.java | 42 +++++++++++++++---- .../impl/EverythingDataSelectorFactory.java | 2 +- .../EverythingDataSelectorConfigTest.java | 23 ++++++++++ .../EverythingDataSelectorFactoryTest.java | 13 +++--- .../cda/impl/EverythingDataSelectorTest.java | 6 +-- 8 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorConfigTest.java diff --git a/.github/test/cd-agent/application.yaml b/.github/test/cd-agent/application.yaml index e69de29b..c26a9bea 100644 --- a/.github/test/cd-agent/application.yaml +++ b/.github/test/cd-agent/application.yaml @@ -0,0 +1,3 @@ +logging.level: + care.smith.fts: DEBUG + care.smith.fts.cda: TRACE diff --git a/.github/test/cd-agent/projects/example.yaml b/.github/test/cd-agent/projects/example.yaml index 893218fc..ab0cdb7b 100644 --- a/.github/test/cd-agent/projects/example.yaml +++ b/.github/test/cd-agent/projects/example.yaml @@ -33,6 +33,8 @@ dataSelector: resolve: # System URL for patient identifier lookup patientIdentifierSystem: http://fts.smith.care + # pageSize + pageSize: 499 ### Deidentificator Configuration ##! https://medizininformatik-initiative.github.io/fts-next/configuration/cd-agent/deidentificator diff --git a/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelector.java b/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelector.java index 4e5d957a..c5b01f77 100644 --- a/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelector.java +++ b/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelector.java @@ -32,21 +32,25 @@ public class EverythingDataSelector implements DataSelector { private final WebClient client; private final PatientIdResolver pidResolver; private final MeterRegistry meterRegistry; - private final int defaultPageSize = 500; + private final int pageSize; public EverythingDataSelector( Config common, WebClient client, PatientIdResolver patientIdResolver, - MeterRegistry meterRegistry) { + MeterRegistry meterRegistry, + int pageSize) { this.common = common; this.client = client; this.pidResolver = patientIdResolver; this.meterRegistry = meterRegistry; + this.pageSize = pageSize; + log.info("pageSize: {}", pageSize); } @Override public Flux select(ConsentedPatient patient) { + log.info("pageSize: {}", pageSize); return pidResolver .resolve(patient.id()) .flatMapMany(fhirId -> fetchEverything(patient, fhirId)) @@ -81,8 +85,7 @@ private Mono fetchNextPage(Bundle bundle) { } private Function withoutConsent(IIdType fhirId) { - return (uriBuilder) -> - uriBuilder.queryParam("_count", defaultPageSize).build(fhirId.getIdPart()); + return (uriBuilder) -> uriBuilder.queryParam("_count", pageSize).build(fhirId.getIdPart()); } private Function withConsent(ConsentedPatient patient, IIdType fhirId) { @@ -93,7 +96,7 @@ private Function withConsent(ConsentedPatient patient, IIdType } return (uriBuilder) -> uriBuilder - .queryParam("_count", defaultPageSize) + .queryParam("_count", pageSize) .queryParam("start", formatWithSystemTZ(period.get().start())) .queryParam("end", formatWithSystemTZ(period.get().end())) .build(Map.of("id", fhirId.getIdPart())); diff --git a/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorConfig.java b/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorConfig.java index 022191a9..54528e50 100644 --- a/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorConfig.java +++ b/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorConfig.java @@ -1,17 +1,45 @@ package care.smith.fts.cda.impl; +import static com.google.common.base.Preconditions.checkArgument; +import static lombok.AccessLevel.PRIVATE; + import care.smith.fts.cda.services.FhirResolveConfig; import care.smith.fts.util.HttpClientConfig; import jakarta.validation.constraints.NotNull; +import lombok.EqualsAndHashCode; +import lombok.Setter; +import lombok.ToString; + +@Setter(PRIVATE) +@EqualsAndHashCode +@ToString +public final class EverythingDataSelectorConfig { + + public static int DEFAULT_PAGE_SIZE = 500; -public record EverythingDataSelectorConfig( - /* Server to fetch data from */ - @NotNull HttpClientConfig fhirServer, + private @NotNull HttpClientConfig fhirServer; + private FhirResolveConfig resolve; + private int pageSize = DEFAULT_PAGE_SIZE; - /* */ - FhirResolveConfig resolve) { + private EverythingDataSelectorConfig() {} + + public EverythingDataSelectorConfig( + HttpClientConfig fhirServer, FhirResolveConfig resolve, int pageSize) { + this.fhirServer = fhirServer; + this.resolve = resolve; + checkArgument(pageSize > 0, "pageSize must be greater than 0"); + this.pageSize = pageSize; + } + + public @NotNull HttpClientConfig fhirServer() { + return fhirServer; + } + + public FhirResolveConfig resolve() { + return resolve; + } - public EverythingDataSelectorConfig(HttpClientConfig fhirServer) { - this(fhirServer, null); + public int pageSize() { + return pageSize; } } diff --git a/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorFactory.java b/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorFactory.java index 965a4cb0..ac900aa8 100644 --- a/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorFactory.java +++ b/clinical-domain-agent/src/main/java/care/smith/fts/cda/impl/EverythingDataSelectorFactory.java @@ -31,7 +31,7 @@ public Class getConfigType() { public DataSelector create(DataSelector.Config common, EverythingDataSelectorConfig config) { var client = clientFactory.create(config.fhirServer()); PatientIdResolver resolver = createResolver(config, client); - return new EverythingDataSelector(common, client, resolver, meterRegistry); + return new EverythingDataSelector(common, client, resolver, meterRegistry, config.pageSize()); } private PatientIdResolver createResolver(EverythingDataSelectorConfig config, WebClient client) { diff --git a/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorConfigTest.java b/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorConfigTest.java new file mode 100644 index 00000000..7f125822 --- /dev/null +++ b/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorConfigTest.java @@ -0,0 +1,23 @@ +package care.smith.fts.cda.impl; + +import static org.junit.jupiter.api.Assertions.*; + +import care.smith.fts.util.HttpClientConfig; +import org.junit.jupiter.api.Test; + +class EverythingDataSelectorConfigTest { + + @Test + void useDefaultIfPageSizeIsInvalid() { + assertThrows( + IllegalArgumentException.class, + () -> { + new EverythingDataSelectorConfig(new HttpClientConfig("http://localhost"), null, 0); + }); + assertThrows( + IllegalArgumentException.class, + () -> { + new EverythingDataSelectorConfig(new HttpClientConfig("http://localhost"), null, -1); + }); + } +} diff --git a/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorFactoryTest.java b/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorFactoryTest.java index 2265ce15..f7f4dcf1 100644 --- a/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorFactoryTest.java +++ b/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorFactoryTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import care.smith.fts.api.cda.DataSelector; import care.smith.fts.cda.services.FhirResolveConfig; import care.smith.fts.util.HttpClientConfig; import care.smith.fts.util.WebClientFactory; @@ -31,10 +32,11 @@ void testConfigType() { @Test void testCreateWithoutResolver() { - assertThat( - factory.create( - null, new EverythingDataSelectorConfig(new HttpClientConfig("http://localhost")))) - .isNotNull(); + var dataSelector = + factory.create( + null, + new EverythingDataSelectorConfig(new HttpClientConfig("http://localhost"), null, 500)); + assertThat(dataSelector).isNotNull(); } @Test @@ -44,7 +46,8 @@ void testCreateWithResolver() { null, new EverythingDataSelectorConfig( new HttpClientConfig("http://localhost"), - new FhirResolveConfig("https://patient-identifier.example.com")))) + new FhirResolveConfig("https://patient-identifier.example.com"), + 500))) .isNotNull(); } } diff --git a/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorTest.java b/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorTest.java index af332b83..3c12e3f0 100644 --- a/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorTest.java +++ b/clinical-domain-agent/src/test/java/care/smith/fts/cda/impl/EverythingDataSelectorTest.java @@ -46,7 +46,7 @@ void noConsentErrors() { var client = builder(); var dataSelector = new EverythingDataSelector( - common, clientFactory.create(client, server), patient, meterRegistry); + common, clientFactory.create(client, server), patient, meterRegistry, 500); create(dataSelector.select(new ConsentedPatient(PATIENT_ID))).expectError().verify(); } @@ -57,7 +57,7 @@ void noConsentSucceedsIfConsentIgnored() { DataSelector.Config common = new DataSelector.Config(true, null); var dataSelector = new EverythingDataSelector( - common, clientFactory.create(client, server), patient, meterRegistry); + common, clientFactory.create(client, server), patient, meterRegistry, 500); create(dataSelector.select(new ConsentedPatient(PATIENT_ID))).verifyComplete(); } @@ -73,7 +73,7 @@ void selectionSucceeds() throws Exception { } var dataSelector = new EverythingDataSelector( - common, clientFactory.create(client, server), patient, meterRegistry); + common, clientFactory.create(client, server), patient, meterRegistry, 500); var consentedPolicies = new ConsentedPolicies(); consentedPolicies.put("pol", new Period(ZonedDateTime.now(), ZonedDateTime.now().plusYears(5)));