-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFhirUtils.java
More file actions
44 lines (34 loc) · 1.41 KB
/
FhirUtils.java
File metadata and controls
44 lines (34 loc) · 1.41 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
package software.nhs.fhirvalidator.util;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.Bundle;
public final class FhirUtils {
static Logger log = LoggerFactory.getLogger(FhirUtils.class);
private FhirUtils() {
throw new IllegalStateException("Utility class");
}
public static List<IBaseResource> getResourcesOfType(IBaseResource resource, String resourceType) {
List<IBaseResource> matchingResources = new ArrayList<>();
if (resource.fhirType().equals(resourceType)) {
matchingResources.add(resource);
}
if (resource instanceof Bundle) {
Bundle bundle = (Bundle) resource;
bundle.getEntry().stream()
.map(Bundle.BundleEntryComponent::getResource)
.filter(entryResource -> entryResource.fhirType().equals(resourceType))
.forEach(matchingResources::add);
}
return matchingResources;
}
public static void applyProfile(List<IBaseResource> resources, IPrimitiveType<String> profile) {
resources.forEach(resource -> {
resource.getMeta().getProfile().clear();
resource.getMeta().addProfile(profile.getValue());
});
}
}