Skip to content

Commit 18b5081

Browse files
committed
Do not write empty ndjson
1 parent 08845c1 commit 18b5081

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

src/main/java/de/medizininformatikinitiative/torch/model/consent/PatientBatchWithConsent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public record PatientBatchWithConsent(Map<String, PatientResourceBundle> bundles
2626
bundles = Map.copyOf(bundles);
2727
}
2828

29+
public Boolean isEmpty() {
30+
return bundles.values().stream().allMatch(PatientResourceBundle::isEmpty);
31+
}
32+
2933
public static PatientBatchWithConsent fromBatch(PatientBatch batch) {
3034
return new PatientBatchWithConsent(batch.ids().stream().collect(
3135
Collectors.toMap(Function.identity(), PatientResourceBundle::new)), false);

src/main/java/de/medizininformatikinitiative/torch/util/ResultFileManager.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
import java.nio.file.Paths;
2121
import java.nio.file.StandardOpenOption;
2222
import java.time.Duration;
23-
import java.util.ArrayList;
24-
import java.util.HashMap;
25-
import java.util.List;
26-
import java.util.Map;
27-
import java.util.Optional;
28-
import java.util.Set;
29-
import java.util.UUID;
23+
import java.util.*;
3024
import java.util.concurrent.ConcurrentHashMap;
3125
import java.util.stream.Stream;
3226

@@ -156,7 +150,10 @@ public Mono<Path> initJobDir(String jobId) {
156150
public void saveBatchToNDJSON(String jobId, PatientBatchWithConsent batch) throws IOException {
157151
requireNonNull(jobId);
158152
requireNonNull(batch);
159-
153+
if (batch.isEmpty()) {
154+
logger.trace("Attempted to save empty batch for jobId: {}", jobId);
155+
return;
156+
}
160157
var ndJsonFile = createNdJsonFile(jobId, batch);
161158

162159
try (BufferedWriter out = Files.newBufferedWriter(ndJsonFile)) {

src/test/java/de/medizininformatikinitiative/torch/CdsBlackBoxIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import static de.medizininformatikinitiative.torch.TestUtils.nodeFromValueString;
1818
import static de.medizininformatikinitiative.torch.assertions.Assertions.assertThat;
19-
import static de.medizininformatikinitiative.torch.assertions.BundleAssertFactory.BUNDLE_ASSERT;
2019
import static org.assertj.core.api.Assertions.assertThat;
2120

2221
/**
@@ -61,7 +60,7 @@ void testExamples() throws IOException {
6160
List<Bundle> coreBundles = statusResponse.coreBundleUrl().stream().flatMap(fileServerClient::fetchBundles).toList();
6261
List<Bundle> patientBundles = statusResponse.patientBundleUrls().stream().flatMap(fileServerClient::fetchBundles).toList();
6362

64-
assertThat(coreBundles).singleElement().asInstanceOf(BUNDLE_ASSERT).containsNEntries(0);
63+
assertThat(coreBundles).isEmpty();
6564
assertThat(patientBundles).hasSize(3);
6665

6766
// test if referenced IDs match the actual patient's IDs

src/test/java/de/medizininformatikinitiative/torch/CdsPerformanceBlackBoxIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void testWithoutReferences() throws IOException {
5050
var coreBundles = statusResponse.coreBundleUrl().stream().flatMap(fileServerClient::fetchBundles).toList();
5151
var patientBundles = statusResponse.patientBundleUrls().stream().flatMap(fileServerClient::fetchBundles).toList();
5252

53-
assertThat(coreBundles).singleElement().asInstanceOf(BUNDLE_ASSERT).containsNEntries(0);
53+
assertThat(coreBundles).isEmpty();
5454
assertThat(patientBundles).hasSize(25000);
5555
}
5656

src/test/java/de/medizininformatikinitiative/torch/FileServerClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public Stream<Bundle> fetchBundles(URI url) {
2222
// only use the path part of the URL here, because in the test setup the port of the file server isn't right
2323
var response = webClient.get().uri(url.getPath()).retrieve().bodyToMono(String.class).block();
2424
if (response == null) {
25-
throw new RuntimeException("Error while feting NDJSON from " + url);
25+
throw new RuntimeException("Error while fetching NDJSON from " + url);
2626
}
2727
return Stream.of(response.split("\n")).map(line -> context.newJsonParser().parseResource(Bundle.class, line));
2828
}

src/test/java/de/medizininformatikinitiative/torch/SpecificBlackBoxIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Set;
1919

2020
import static de.medizininformatikinitiative.torch.assertions.Assertions.assertThat;
21-
import static de.medizininformatikinitiative.torch.assertions.BundleAssertFactory.BUNDLE_ASSERT;
2221
import static org.assertj.core.api.Assertions.assertThat;
2322

2423
/**
@@ -101,7 +100,7 @@ void testDoubleRefResolve() throws IOException {
101100
var coreBundles = statusResponse.coreBundleUrl().stream().flatMap(fileServerClient::fetchBundles).toList();
102101
var patientBundles = statusResponse.patientBundleUrls().stream().flatMap(fileServerClient::fetchBundles).toList();
103102

104-
assertThat(coreBundles).singleElement().asInstanceOf(BUNDLE_ASSERT).containsNEntries(0);
103+
assertThat(coreBundles).isEmpty();
105104
assertThat(patientBundles).hasSize(1);
106105

107106
executeStandardTests(patientBundles);
@@ -150,7 +149,7 @@ void testMustHaveResolve() throws IOException {
150149
var coreBundles = statusResponse.coreBundleUrl().stream().flatMap(fileServerClient::fetchBundles).toList();
151150
var patientBundles = statusResponse.patientBundleUrls().stream().flatMap(fileServerClient::fetchBundles).toList();
152151

153-
assertThat(coreBundles).singleElement().asInstanceOf(BUNDLE_ASSERT).containsNEntries(0);
152+
assertThat(coreBundles).isEmpty();
154153
assertThat(patientBundles).hasSize(1);
155154

156155
executeStandardTests(patientBundles);

0 commit comments

Comments
 (0)