Skip to content

Commit cd0e9ec

Browse files
committed
filter to remove workaround induced false positive validation error
1 parent 2fdb9d0 commit cd0e9ec

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import static org.junit.Assert.assertNotNull;
66
import static org.junit.Assert.assertTrue;
77

8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.nio.file.Files;
811
import java.nio.file.Paths;
912
import java.sql.Connection;
1013
import java.sql.PreparedStatement;
@@ -358,7 +361,11 @@ private Bundle createFailingTestBundle(BundleType type, IdType resourceToDelete)
358361
@Test
359362
public void createBundleInBundle() throws Exception
360363
{
361-
Bundle b = new Bundle().setType(BundleType.BATCHRESPONSE);
364+
StructureDefinition sd = readTestBundleProfile();
365+
getWebserviceClient().create(sd);
366+
367+
Bundle b = new Bundle().setType(BundleType.BATCH);
368+
b.getMeta().addProfile(sd.getUrl() + "|" + sd.getVersion());
362369
b.addEntry()
363370
.setResource(new Bundle().setType(BundleType.SEARCHSET)
364371
.addLink(new BundleLinkComponent().setRelation("self").setUrl("Medication")).setTotal(0))
@@ -370,4 +377,13 @@ public void createBundleInBundle() throws Exception
370377
assertNotNull(created.getIdElement());
371378
assertNotNull(created.getIdElement().getIdPart());
372379
}
380+
381+
private StructureDefinition readTestBundleProfile() throws IOException
382+
{
383+
try (InputStream in = Files
384+
.newInputStream(Paths.get("src/test/resources/integration/bundle/test-bundle-profile.xml")))
385+
{
386+
return fhirContext.newXmlParser().parseResource(StructureDefinition.class, in);
387+
}
388+
}
373389
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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-bundle" />
10+
<name value="SearchBundleReport" />
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" />
25+
</element>
26+
<element id="Bundle.entry">
27+
<path value="Bundle.entry" />
28+
<min value="1" />
29+
</element>
30+
<element id="Bundle.entry.request">
31+
<path value="Bundle.entry.request" />
32+
<min value="1" />
33+
</element>
34+
<element id="Bundle.entry.request.method">
35+
<path value="Bundle.entry.request.method" />
36+
<fixedCode value="GET" />
37+
</element>
38+
</differential>
39+
</StructureDefinition>

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import java.util.List;
44
import java.util.Objects;
5+
import java.util.function.Predicate;
56
import java.util.stream.Stream;
67

78
import org.hl7.fhir.r4.model.Bundle;
89
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
910
import org.hl7.fhir.r4.model.Resource;
1011

1112
import ca.uhn.fhir.context.FhirContext;
13+
import ca.uhn.fhir.validation.ResultSeverityEnum;
1214
import ca.uhn.fhir.validation.SingleValidationMessage;
1315
import ca.uhn.fhir.validation.ValidationResult;
1416

@@ -46,6 +48,17 @@ private ValidationResult validateBundle(Bundle bundle)
4648
.flatMap(List::stream);
4749

4850
return new ValidationResult(fhirContext,
49-
Stream.concat(bundleResult.getMessages().stream(), entryResults).toList());
51+
Stream.concat(
52+
bundleResult.getMessages().stream().filter(filterBundleEntryMinimumIfEntriesPresent(entries)),
53+
entryResults).toList());
54+
}
55+
56+
private Predicate<SingleValidationMessage> filterBundleEntryMinimumIfEntriesPresent(
57+
List<BundleEntryComponent> entries)
58+
{
59+
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()));
5063
}
5164
}

0 commit comments

Comments
 (0)