Skip to content

Commit d9a208a

Browse files
committed
[AEA-6305] fix validator to properly validate cpt api style fhir messages
1 parent 0b9f35c commit d9a208a

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/main/java/software/nhs/fhirvalidator/controller/ValidateController.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.hl7.fhir.instance.model.api.IBaseResource;
1212
import org.hl7.fhir.r4.model.Bundle;
1313
import org.hl7.fhir.r4.model.OperationOutcome;
14-
import org.hl7.fhir.r4.model.ResourceType;
1514
import org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent;
1615

1716
import ca.uhn.fhir.context.FhirContext;
@@ -80,7 +79,7 @@ public OperationOutcome parseAndValidateResource(String input) {
8079
| DataFormatException e) {
8180
log.error(e.toString());
8281
return OperationOutcomeUtils
83-
.createOperationOutcome(e.getMessage() != null ? e.getMessage() : "Invalid JSON", null);
82+
.createOperationOutcome((e.getMessage() != null && !e.getMessage().contains("null")) ? e.getMessage() : "Invalid JSON", null);
8483
}
8584
}
8685

@@ -101,15 +100,10 @@ private List<IBaseResource> getResourcesToValidate(IBaseResource inputResource)
101100
if (inputResource instanceof Bundle _inputResource && (_inputResource.getType() == Bundle.BundleType.SEARCHSET)) {
102101
List<IBaseResource> bundleResources = new ArrayList<>();
103102
for (Bundle.BundleEntryComponent entry : ((Bundle) inputResource).getEntry()) {
104-
if (entry.getResource().fhirType().equals("Bundle")) {
105-
bundleResources.add(entry.getResource());
106-
}
103+
bundleResources.add(entry.getResource());
107104
}
108105

109-
if (bundleResources.stream()
110-
.allMatch(resource -> ((Bundle) resource).getResourceType() == ResourceType.Bundle)) {
111-
return bundleResources;
112-
}
106+
return bundleResources;
113107
}
114108

115109
return Arrays.asList(inputResource);

src/test/resources/results/searchSet.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,43 @@
23912391
"Bundle.entry[4].resource/*Organization/154dcc4a-0006-4272-9758-9dcb8d95ce8b*/",
23922392
"Line[1] Col[3089]"
23932393
]
2394+
},
2395+
{
2396+
"extension": [
2397+
{
2398+
"url": "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-line",
2399+
"valueInteger": 1
2400+
},
2401+
{
2402+
"url": "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-col",
2403+
"valueInteger": 496
23942404
}
2395-
]
2405+
],
2406+
"severity": "warning",
2407+
"code": "processing",
2408+
"diagnostics": "Constraint failed: dom-6: 'A resource should have narrative for robust management' (defined in http://hl7.org/fhir/StructureDefinition/DomainResource) (Best Practice Recommendation)",
2409+
"location": [
2410+
"OperationOutcome",
2411+
"Line[1] Col[496]"
2412+
]
2413+
},
2414+
{
2415+
"extension": [
2416+
{
2417+
"url": "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-line",
2418+
"valueInteger": 1
2419+
},
2420+
{
2421+
"url": "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-col",
2422+
"valueInteger": 496
2423+
}
2424+
],
2425+
"severity": "warning",
2426+
"code": "processing",
2427+
"diagnostics": "Constraint failed: dom-6: 'A resource should have narrative for robust management' (defined in http://hl7.org/fhir/StructureDefinition/DomainResource) (Best Practice Recommendation)",
2428+
"location": [
2429+
"OperationOutcome",
2430+
"Line[1] Col[496]"
2431+
]
2432+
}]
23962433
}

0 commit comments

Comments
 (0)