Skip to content

Commit 7e87b3f

Browse files
committed
improved workaround
1 parent cd0e9ec commit 7e87b3f

File tree

4 files changed

+74
-15
lines changed

4 files changed

+74
-15
lines changed

dsf-fhir/dsf-fhir-server/src/test/java/dev/dsf/fhir/integration/BundleIntegrationTest.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.hl7.fhir.r4.model.Bundle;
2424
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
2525
import org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent;
26-
import org.hl7.fhir.r4.model.Bundle.BundleEntryResponseComponent;
2726
import org.hl7.fhir.r4.model.Bundle.BundleLinkComponent;
2827
import org.hl7.fhir.r4.model.Bundle.BundleType;
2928
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
@@ -359,29 +358,50 @@ private Bundle createFailingTestBundle(BundleType type, IdType resourceToDelete)
359358
}
360359

361360
@Test
362-
public void createBundleInBundle() throws Exception
361+
public void createBundleInBundle1() throws Exception
363362
{
364-
StructureDefinition sd = readTestBundleProfile();
363+
StructureDefinition sd = readTestBundleProfile("test-bundle-profile1.xml");
365364
getWebserviceClient().create(sd);
366365

367366
Bundle b = new Bundle().setType(BundleType.BATCH);
368367
b.getMeta().addProfile(sd.getUrl() + "|" + sd.getVersion());
369-
b.addEntry()
370-
.setResource(new Bundle().setType(BundleType.SEARCHSET)
371-
.addLink(new BundleLinkComponent().setRelation("self").setUrl("Medication")).setTotal(0))
372-
.setResponse(new BundleEntryResponseComponent().setStatus("200"));
368+
369+
b.addEntry().setRequest(new BundleEntryRequestComponent().setMethod(HTTPVerb.GET).setUrl("Conset"));
370+
b.addEntry().setRequest(new BundleEntryRequestComponent().setMethod(HTTPVerb.GET).setUrl("Condition"));
371+
373372
getReadAccessHelper().addAll(b);
373+
Bundle created = getWebserviceClient().create(b);
374374

375+
assertNotNull(created);
376+
assertNotNull(created.getIdElement());
377+
assertNotNull(created.getIdElement().getIdPart());
378+
}
379+
380+
@Test
381+
public void createBundleInBundle2() throws Exception
382+
{
383+
StructureDefinition sd = readTestBundleProfile("test-bundle-profile2.xml");
384+
getWebserviceClient().create(sd);
385+
386+
Bundle b = new Bundle().setType(BundleType.BATCHRESPONSE);
387+
b.getMeta().addProfile(sd.getUrl() + "|" + sd.getVersion());
388+
389+
BundleEntryComponent e = b.addEntry();
390+
e.setResource(new Bundle().setType(BundleType.SEARCHSET).setTotal(0)
391+
.addLink(new BundleLinkComponent().setRelation("self").setUrl("Medication")));
392+
e.getResponse().setStatus("200");
393+
394+
getReadAccessHelper().addAll(b);
375395
Bundle created = getWebserviceClient().create(b);
396+
376397
assertNotNull(created);
377398
assertNotNull(created.getIdElement());
378399
assertNotNull(created.getIdElement().getIdPart());
379400
}
380401

381-
private StructureDefinition readTestBundleProfile() throws IOException
402+
private StructureDefinition readTestBundleProfile(String bundleFile) throws IOException
382403
{
383-
try (InputStream in = Files
384-
.newInputStream(Paths.get("src/test/resources/integration/bundle/test-bundle-profile.xml")))
404+
try (InputStream in = Files.newInputStream(Paths.get("src/test/resources/integration/bundle", bundleFile)))
385405
{
386406
return fhirContext.newXmlParser().parseResource(StructureDefinition.class, in);
387407
}

dsf-fhir/dsf-fhir-server/src/test/resources/integration/bundle/test-bundle-profile.xml renamed to dsf-fhir/dsf-fhir-server/src/test/resources/integration/bundle/test-bundle-profile1.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<code value="ALL" />
77
</tag>
88
</meta>
9-
<url value="http://dev.dsf/fhir/Bundle/test-bundle" />
10-
<name value="SearchBundleReport" />
9+
<url value="http://dev.dsf/fhir/Bundle/test-bundle1" />
10+
<name value="TestBundle1" />
1111
<fhirVersion value="4.0.1" />
1212
<version value="2.0.0" />
1313
<status value="active" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
<StructureDefinition xmlns="http://hl7.org/fhir">
3+
<meta>
4+
<tag>
5+
<system value="http://dsf.dev/fhir/CodeSystem/read-access-tag" />
6+
<code value="ALL" />
7+
</tag>
8+
</meta>
9+
<url value="http://dev.dsf/fhir/Bundle/test-bundle2" />
10+
<name value="TestBundle2" />
11+
<fhirVersion value="4.0.1" />
12+
<version value="2.0.0" />
13+
<status value="active" />
14+
<date value="2025-03-31" />
15+
<experimental value="false" />
16+
<abstract value="false" />
17+
<kind value="resource" />
18+
<type value="Bundle" />
19+
<baseDefinition value="http://hl7.org/fhir/StructureDefinition/Bundle" />
20+
<derivation value="constraint" />
21+
<differential>
22+
<element id="Bundle.type">
23+
<path value="Bundle.type" />
24+
<fixedCode value="batch-response" />
25+
</element>
26+
<element id="Bundle.entry.resource">
27+
<path value="Bundle.entry.resource" />
28+
<min value="1" />
29+
</element>
30+
<element id="Bundle.entry.response">
31+
<path value="Bundle.entry.response" />
32+
<min value="1" />
33+
</element>
34+
</differential>
35+
</StructureDefinition>

dsf-fhir/dsf-fhir-validation/src/main/java/dev/dsf/fhir/validation/ResourceInResourceValidator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Objects;
55
import java.util.function.Predicate;
6+
import java.util.regex.Pattern;
67
import java.util.stream.Stream;
78

89
import org.hl7.fhir.r4.model.Bundle;
@@ -16,6 +17,9 @@
1617

1718
public class ResourceInResourceValidator implements ResourceValidator
1819
{
20+
private static final Pattern BUNDLE_MIN_REQUIRED_FOUND_ZERO_PATTERN = Pattern
21+
.compile("Bundle.entry: minimum required = (?:[1-9]{1}(?:[0-9]+)?), but only found 0");
22+
1923
private final FhirContext fhirContext;
2024
private final ResourceValidator delegate;
2125

@@ -57,8 +61,8 @@ private Predicate<SingleValidationMessage> filterBundleEntryMinimumIfEntriesPres
5761
List<BundleEntryComponent> entries)
5862
{
5963
return message -> !(!entries.isEmpty() && ResultSeverityEnum.ERROR.equals(message.getSeverity())
60-
&& "Bundle".equals(message.getLocationString()) && message.getMessage() != null
61-
&& message.getMessage().startsWith("Bundle.entry: minimum required = 1, but only found 0")
62-
&& "Validation_VAL_Profile_Minimum".equals(message.getMessageId()));
64+
&& "Bundle".equals(message.getLocationString())
65+
&& "Validation_VAL_Profile_Minimum".equals(message.getMessageId()) && message.getMessage() != null
66+
&& BUNDLE_MIN_REQUIRED_FOUND_ZERO_PATTERN.matcher(message.getMessage()).find());
6367
}
6468
}

0 commit comments

Comments
 (0)