-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCapabilityStatementApplier.java
More file actions
51 lines (42 loc) · 2.01 KB
/
CapabilityStatementApplier.java
File metadata and controls
51 lines (42 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package software.nhs.fhirvalidator.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.utilities.npm.NpmPackage;
import software.nhs.fhirvalidator.util.FhirUtils;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
public class CapabilityStatementApplier {
private final List<CapabilityStatement.CapabilityStatementRestResourceComponent> restResources;
Logger log = LoggerFactory.getLogger(CapabilityStatementApplier.class);
public CapabilityStatementApplier(
ImplementationGuideParser implementationGuideParser,
List<NpmPackage> npmPackages) {
this.restResources = (npmPackages.stream()
.flatMap(packageItem -> {
try {
return implementationGuideParser
.getResourcesOfType(packageItem, CapabilityStatement.class).stream();
} catch (IOException ex) {
log.error(ex.getMessage(), ex);
throw new RuntimeException("error in handleRequest", ex);
}
})
.flatMap(capabilityStatement -> capabilityStatement.getRest().stream())
.flatMap(rest -> rest.getResource().stream())
.collect(Collectors.toList()));
}
public void applyCapabilityStatementProfiles(IBaseResource resource) {
restResources.forEach(restResource -> applyRestResource(resource, restResource));
}
private void applyRestResource(
IBaseResource resource,
CapabilityStatement.CapabilityStatementRestResourceComponent restResource) {
List<IBaseResource> matchingResources = FhirUtils.getResourcesOfType(resource, restResource.getType());
if (restResource.hasProfile()) {
FhirUtils.applyProfile(matchingResources, restResource.getProfileElement());
}
}
}