Skip to content

Commit 596a879

Browse files
committed
Fix Bundle URL
1 parent b2dfa3a commit 596a879

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/main/java/de/medizininformatikinitiative/torch/model/management/ResourceBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private Bundle.BundleEntryComponent createBundleEntry(Resource resource) {
269269
Bundle.BundleEntryComponent entryComponent = new Bundle.BundleEntryComponent();
270270
entryComponent.setResource(resource);
271271
Bundle.BundleEntryRequestComponent request = new Bundle.BundleEntryRequestComponent();
272-
request.setUrl(resource.getId());
272+
request.setUrl(resource.getResourceType() + "/" + resource.getId());
273273
request.setMethod(PUT);
274274
entryComponent.setRequest(request);
275275
return entryComponent;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.medizininformatikinitiative.torch;
22

33
import de.medizininformatikinitiative.torch.assertions.BundleAssert;
4+
import org.hl7.fhir.r4.model.Bundle;
45
import org.hl7.fhir.r4.model.ResourceType;
56
import org.junit.jupiter.api.AfterAll;
67
import org.junit.jupiter.api.BeforeAll;
@@ -12,6 +13,7 @@
1213
import java.io.IOException;
1314
import java.nio.file.Files;
1415
import java.nio.file.Path;
16+
import java.util.List;
1517

1618
import static de.medizininformatikinitiative.torch.TestUtils.nodeFromValueString;
1719
import static de.medizininformatikinitiative.torch.assertions.Assertions.assertThat;
@@ -37,7 +39,7 @@ static void setUp() throws IOException {
3739

3840
torchClient = environment.torchClient();
3941
fileServerClient = environment.fileServerClient();
40-
var blazeClient = environment.blazeClient();
42+
FhirClient blazeClient = environment.blazeClient();
4143

4244
logger.info("Uploading test data...");
4345
var bundle = Files.readString(Path.of("target/kds-testdata-2024.0.1/resources/Bundle-mii-exa-test-data-bundle.json"));
@@ -57,8 +59,8 @@ public void testExamples() throws IOException {
5759
var statusResponse = torchClient.pollStatus(statusUrl).block();
5860
assertThat(statusResponse).isNotNull();
5961

60-
var coreBundles = statusResponse.coreBundleUrl().stream().flatMap(fileServerClient::fetchBundles).toList();
61-
var patientBundles = statusResponse.patientBundleUrls().stream().flatMap(fileServerClient::fetchBundles).toList();
62+
List<Bundle> coreBundles = statusResponse.coreBundleUrl().stream().flatMap(fileServerClient::fetchBundles).toList();
63+
List<Bundle> patientBundles = statusResponse.patientBundleUrls().stream().flatMap(fileServerClient::fetchBundles).toList();
6264

6365
assertThat(coreBundles, BundleAssert.class).singleElement().containsNEntries(0);
6466
assertThat(patientBundles).hasSize(3);
@@ -110,10 +112,13 @@ public void testExamples() throws IOException {
110112
.extractElementsAt("code.coding.code")
111113
.containsExactly(nodeFromValueString("C16.9")));
112114

113-
// test that IDs are properly formatted
114115
assertThat(patientBundles).allSatisfy(bundle ->
115116
assertThat(bundle).extractResourcesByType(ResourceType.Condition).allSatisfy(
116117
r -> assertThat(r).extractChildrenStringsAt("subject.reference").satisfiesExactly(id -> assertThat(id).startsWith("Patient/"))
117118
));
119+
120+
assertThat(patientBundles).allSatisfy(bundle ->
121+
assertThat(bundle).allRequestsMatchResourceIdentity());
122+
118123
}
119124
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ static void uploadTestData(String testName) throws IOException {
5959

6060
public void executeStandardTests(List<Bundle> patientBundles) {
6161

62+
assertThat(patientBundles).allSatisfy(bundle ->
63+
assertThat(bundle).allRequestsMatchResourceIdentity());
64+
6265
// test if referenced IDs match the actual patient's IDs
6366
assertThat(patientBundles).allSatisfy(bundle -> Assertions.assertThat(bundle).extractOnlyPatient().satisfies(patient ->
6467
Assertions.assertThat(bundle).extractResourcesByType(ResourceType.Condition).allSatisfy(condition ->

src/test/java/de/medizininformatikinitiative/torch/assertions/BundleAssert.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public ListAssert<String> extractBatchBundleUrls() {
5555
return new ListAssert<>(fhirPathEngine.evaluate(actual, "Bundle.entry.request.url", UriType.class).stream().map(UriType::getValueAsString).toList());
5656
}
5757

58+
public BundleAssert allRequestsMatchResourceIdentity() {
59+
boolean allMatch = actual.getEntry().stream().allMatch(entry ->
60+
entry.getRequest().getUrl().equals(entry.getResource().getId())
61+
);
62+
if (!allMatch) {
63+
failWithMessage("Expected bundle to resource ids to match request urls");
64+
}
65+
66+
return myself;
67+
}
68+
5869
/**
5970
* Extracts the only patient of the bundle.
6071
* <p>

0 commit comments

Comments
 (0)