Skip to content

Commit

Permalink
Add pageSize to EverythingDataSelectorConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
trobanga committed Jan 7, 2025
1 parent 0cec360 commit ccb264c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .github/test/cd-agent/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
logging.level:
care.smith.fts: DEBUG
care.smith.fts.cda: TRACE
2 changes: 2 additions & 0 deletions .github/test/cd-agent/projects/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConsentedPatientBundle> select(ConsentedPatient patient) {
log.info("pageSize: {}", pageSize);
return pidResolver
.resolve(patient.id())
.flatMapMany(fhirId -> fetchEverything(patient, fhirId))
Expand Down Expand Up @@ -81,8 +85,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 +96,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

0 comments on commit ccb264c

Please sign in to comment.