Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Supported features:

- Fluent Java API for configuring and running the export
- System, group and patient level export
- All Bulk Data v2 [query parameters](https://hl7.org/fhir/uv/bulkdata/export.html#query-parameters)
- Bulk Data v2 [query parameters](https://hl7.org/fhir/uv/bulkdata/export.html#query-parameters)
(with some limitations for patient references)
- Bulk Data v3 `_until` query parameter
- Asymmetric and
symmetric [SMART authentication profiles](https://www.hl7.org/fhir/smart-app-launch/client-authentication.html)
- Automatic token endpoint discovery with SMART configuration discovery
Expand Down Expand Up @@ -132,6 +133,7 @@ final BulkExportResult result = BulkExportClient.groupBuilder("BMCHealthNet")
.withOutputDir(outputDir)
.withOutputFormat("ndjson")
.withSince(Instant.parse("2015-01-01T00:00:00.000Z"))
.withUntil(Instant.parse("2024-01-01T00:00:00.000Z"))
.withTypes(List.of("Patient", "Condition"))
.withType("Observation")
.withElements(List.of("id", "status"))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>au.csiro.fhir</groupId>
<version>1.0.3</version>
<version>1.0.4-SNAPSHOT</version>
<artifactId>bulk-export</artifactId>
<packaging>jar</packaging>

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/au/csiro/fhir/export/BulkExportClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public class BulkExportClient {
@Builder.Default
Instant since = null;

/**
* The time to end the export at. If null, the server's current time is used. The value of the
* `_until` parameter in the export request.
*/
@Nullable
@Builder.Default
Instant until = null;

/**
* The types of resources to export. The value of the `_type` parameter in the export request.
*/
Expand Down Expand Up @@ -355,6 +363,7 @@ BulkExportRequest buildBulkExportRequest() {
._outputFormat(outputFormat)
._type(types)
._since(since)
._until(until)
._elements(elements)
._typeFilter(typeFilters)
.includeAssociatedData(includeAssociatedData)
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/au/csiro/fhir/export/ws/BulkExportRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,20 @@ public boolean isPatientSupported() {

/**
* The date and time to use as the lower bound for the export. The value of the '_since' query
* parameter.
*/
@Nullable
@Builder.Default
Instant _since = null;

/**
* The date and time to use as the upper bound for the export. The value of the '_until' query
* parameter.
*/
@Nullable
@Builder.Default
Instant _until = null;

/**
* The types of resources to export. The value of the '_type' query parameter.
*/
Expand Down Expand Up @@ -208,6 +217,8 @@ public Parameters toParameters() {
.map(s -> Parameter.of("_outputFormat", s)).stream(),
Optional.ofNullable(_since)
.map(s -> Parameter.of("_since", s)).stream(),
Optional.ofNullable(_until)
.map(u -> Parameter.of("_until", u)).stream(),
optionalOfList(_type)
.map(e -> Parameter.of("_type", String.join(",", e))).stream(),
optionalOfList(_elements)
Expand Down Expand Up @@ -242,6 +253,10 @@ public URI toRequestURI(@Nonnull final URI endpointUri) {
uriBuilder.addParameter("_since",
FhirFormats.formatFhirInstant(Objects.requireNonNull(get_since())));
}
if (get_until() != null) {
uriBuilder.addParameter("_until",
FhirFormats.formatFhirInstant(Objects.requireNonNull(get_until())));
}
if (!get_type().isEmpty()) {
uriBuilder.addParameter("_type", String.join(",", get_type()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,14 @@ void testExportFailsTimeOutInDownload(@Nonnull final WireMockRuntimeInfo wmRunti

stubFor(get(urlPathEqualTo("/file/00"))
.willReturn(aResponse()
.withFixedDelay(2_000)
.withFixedDelay(10_000)
.withStatus(200)
.withBody(RESOURCE_00))
);

stubFor(get(urlPathEqualTo("/file/01"))
.willReturn(aResponse()
.withFixedDelay(2_000)
.withFixedDelay(10_000)
.withStatus(200)
.withBody(RESOURCE_01))
);
Expand All @@ -736,7 +736,7 @@ void testExportFailsTimeOutInDownload(@Nonnull final WireMockRuntimeInfo wmRunti
BulkExportClient.builder()
.withFhirEndpointUrl(bulkExportDemoServerEndpoint)
.withOutputDir(exportDir.getPath())
.withTimeout(Duration.ofSeconds(3))
.withTimeout(Duration.ofSeconds(5))
.build()
.export()
);
Expand Down
44 changes: 40 additions & 4 deletions src/test/java/au/csiro/fhir/export/ws/BulkExportRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void testToParametersWithWithAllValuesSet() {
final BulkExportRequest request = BulkExportRequest.builder()
._outputFormat("fhir+ndjson")
._since(Instant.parse("2023-08-01T00:00:00Z"))
._until(Instant.parse("2023-12-31T23:59:59Z"))
._type(List.of("Patient", "Condition"))
._elements(List.of("Patient.name", "Patient.birthDate"))
._typeFilter(List.of("Patient?active=true", "Condition?clinicalStatus=active"))
Expand All @@ -60,6 +61,7 @@ void testToParametersWithWithAllValuesSet() {
Parameters.of(
Parameter.of("_outputFormat", "fhir+ndjson"),
Parameter.of("_since", Instant.parse("2023-08-01T00:00:00Z")),
Parameter.of("_until", Instant.parse("2023-12-31T23:59:59Z")),
Parameter.of("_type", "Patient,Condition"),
Parameter.of("_elements", "Patient.name,Patient.birthDate"),
Parameter.of("_typeFilter", "Patient?active=true,Condition?clinicalStatus=active"),
Expand All @@ -70,6 +72,19 @@ void testToParametersWithWithAllValuesSet() {
request.toParameters());
}

@Test
void testToParametersWithOnlyUntil() {
// Test that _until can be used independently of _since.
final BulkExportRequest request = BulkExportRequest.builder()
._until(Instant.parse("2024-06-15T12:00:00.500Z"))
.build();
assertEquals(
Parameters.of(
Parameter.of("_until", Instant.parse("2024-06-15T12:00:00.500Z"))
),
request.toParameters());
}

@Test
void testDefaultRequestUri() {
final URI baseUri = URI.create("http://example.com/fhir");
Expand All @@ -81,10 +96,12 @@ void testDefaultRequestUri() {
@Test
void testNonDefaultRequestUri() {
final URI baseUri = URI.create("http://test.com/fhir");
final Instant testInstant = Instant.parse("2023-01-11T00:00:00.1234Z");
final Instant sinceInstant = Instant.parse("2023-01-11T00:00:00.1234Z");
final Instant untilInstant = Instant.parse("2023-12-31T23:59:59.9876Z");
assertEquals(URI.create(
"http://test.com/fhir?_outputFormat=xml"
+ "&_since=2023-01-11T00%3A00%3A00.123Z"
+ "&_until=2023-12-31T23%3A59%3A59.987Z"
+ "&_type=Patient%2CObservation"
+ "&_elements=Patient.id%2CCondition.status"
+ "&_typeFilter=Patient.active%3Dtrue%2CObservation.status%3Dfinal"
Expand All @@ -94,13 +111,27 @@ void testNonDefaultRequestUri() {
._type(List.of("Patient", "Observation"))
._elements(List.of("Patient.id", "Condition.status"))
._typeFilter(List.of("Patient.active=true", "Observation.status=final"))
._since(testInstant)
._since(sinceInstant)
._until(untilInstant)
.includeAssociatedData(List.of(AssociatedData.RELEVANT_PROVENANCE_RESOURCES,
AssociatedData.custom("customYYY")))
.build().toRequestURI(baseUri)
);
}

@Test
void testRequestUriWithOnlyUntil() {
// Test that _until can be used independently in URI without _since.
final URI baseUri = URI.create("http://test.com/fhir");
final Instant untilInstant = Instant.parse("2024-06-15T12:00:00.500Z");
assertEquals(URI.create(
"http://test.com/fhir?_until=2024-06-15T12%3A00%3A00.500Z"),
BulkExportRequest.builder()
._until(untilInstant)
.build().toRequestURI(baseUri)
);
}


@Test
void testCreateDefaultSystemExportRequest() {
Expand All @@ -118,20 +149,23 @@ void testCreateDefaultSystemExportRequest() {

@Test
void testCreatesAllValuesSystemExportRequest() {
final Instant testInstant = Instant.parse("2023-01-11T00:00:00.1234Z");
final Instant sinceInstant = Instant.parse("2023-01-11T00:00:00.1234Z");
final Instant untilInstant = Instant.parse("2023-12-31T23:59:59.9876Z");
final BulkExportRequest request = BulkExportRequest.builder()
._outputFormat("xml")
._type(List.of("Patient", "Observation"))
._elements(List.of("Patient.id", "Condition.status"))
._typeFilter(List.of("Patient.active=true", "Observation.status=final"))
._since(testInstant)
._since(sinceInstant)
._until(untilInstant)
.includeAssociatedData(List.of(AssociatedData.LATEST_PROVENANCE_RESOURCES,
AssociatedData.custom("customZZZ")))
.build();
final HttpUriRequest httpRequest = request.toHttpRequest(URI.create("http://test.com/fhir"));
assertEquals("GET", httpRequest.getMethod());
assertEquals("http://test.com/fhir/$export?_outputFormat=xml"
+ "&_since=2023-01-11T00%3A00%3A00.123Z"
+ "&_until=2023-12-31T23%3A59%3A59.987Z"
+ "&_type=Patient%2CObservation"
+ "&_elements=Patient.id%2CCondition.status"
+ "&_typeFilter=Patient.active%3Dtrue%2CObservation.status%3Dfinal"
Expand Down Expand Up @@ -219,6 +253,7 @@ void testCreateGroupLevelExportPostRequest() throws IOException {
.level(new GroupLevel("id0001"))
._outputFormat("fhir+ndjson")
._since(Instant.parse("2023-08-01T00:00:00Z"))
._until(Instant.parse("2023-12-31T23:59:59Z"))
._type(List.of("Patient", "Condition"))
._elements(List.of("Patient.name", "Patient.birthDate"))
._typeFilter(List.of("Patient?active=true", "Condition?clinicalStatus=active"))
Expand All @@ -241,6 +276,7 @@ void testCreateGroupLevelExportPostRequest() throws IOException {
Parameters.of(
Parameter.of("_outputFormat", "fhir+ndjson"),
Parameter.of("_since", Instant.parse("2023-08-01T00:00:00Z")),
Parameter.of("_until", Instant.parse("2023-12-31T23:59:59Z")),
Parameter.of("_type", "Patient,Condition"),
Parameter.of("_elements", "Patient.name,Patient.birthDate"),
Parameter.of("_typeFilter", "Patient?active=true,Condition?clinicalStatus=active"),
Expand Down