Skip to content

Commit

Permalink
Merge pull request #505 from medizininformatik-initiative/500-make-de…
Browse files Browse the repository at this point in the history
…faultpagesize-in-everythingdataselector-configurable

Add `pageSize` to EverythingDataSelectorConfig
  • Loading branch information
trobanga authored Jan 7, 2025
2 parents 5de852c + bfcf844 commit b679046
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 24 deletions.
8 changes: 5 additions & 3 deletions .github/test/cd-agent/projects/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ dataSelector:
fhirServer:
# Base URL of the FHIR server endpoint
baseUrl: http://cd-hds:8080/fhir
# Patient identifier resolution configuration
# (optional) Patient identifier resolution configuration
resolve:
# System URL for patient identifier lookup
patientIdentifierSystem: http://fts.smith.care
# (default: 500) Maximum size of bundles requested from cd-hds
pageSize: 500

### Deidentificator Configuration
##! https://medizininformatik-initiative.github.io/fts-next/configuration/cd-agent/deidentificator
Expand All @@ -49,9 +51,9 @@ deidentificator:
domains:
# TCA domain to store pseudonyms in
pseudonym: MII
# TCA domain to store peudonym salts in
# TCA domain to store pseudonym salts in
salt: MII
# TCA domain to store dateshift salts in
# TCA domain to store dateShift salts in
dateShift: MII
# Dates should be shifted a maximum of this amount
# specified as an ISO-8601 duration (e.g., P1D means 1 day)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ 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;
}

@Override
Expand Down Expand Up @@ -81,8 +83,7 @@ private Mono<Bundle> fetchNextPage(Bundle bundle) {
}

private Function<UriBuilder, URI> withoutConsent(IIdType fhirId) {
return (uriBuilder) ->
uriBuilder.queryParam("_count", defaultPageSize).build(fhirId.getIdPart());
return (uriBuilder) -> uriBuilder.queryParam("_count", pageSize).build(fhirId.getIdPart());
}

private Function<UriBuilder, URI> withConsent(ConsentedPatient patient, IIdType fhirId) {
Expand All @@ -93,7 +94,7 @@ private Function<UriBuilder, URI> 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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Class<EverythingDataSelectorConfig> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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)));
Expand Down
12 changes: 12 additions & 0 deletions docs/cd-agent/data-selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dataSelector:
baseUrl: http://cd-hds:8080/fhir
resolve:
patientIdentifierSystem: http://fts.smith.care
pageSize: 500
```
## Fields
Expand Down Expand Up @@ -46,6 +47,17 @@ The "everything" data selector uses the FHIR servers `patient/$everything` opera
patientIdentifierSystem: http://custom.identifier.system
```

#### `pageSize`

* **Description**: Specifies the maximum number of FHIR resources to be included in a single bundle
when requesting data from the clinical domain health data storage (cd-hds).
This parameter helps control memory usage and network load by limiting the size of data transfers.
* **Type**: Integer
* **Default**: 500
* **Example**:
```yaml
pageSize: 1000
## Notes
the `$everything` operation.
Expand Down

0 comments on commit b679046

Please sign in to comment.