-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImplementationGuideParser.java
More file actions
43 lines (35 loc) · 1.42 KB
/
ImplementationGuideParser.java
File metadata and controls
43 lines (35 loc) · 1.42 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
package software.nhs.fhirvalidator.service;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.utilities.npm.NpmPackage;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
public class ImplementationGuideParser {
private final FhirContext fhirContext;
Logger log = LoggerFactory.getLogger(ImplementationGuideParser.class);
public ImplementationGuideParser(FhirContext fhirContext) {
this.fhirContext = fhirContext;
}
public <T extends Resource> List<T> getResourcesOfType(NpmPackage npmPackage, Class<T> resourceType)
throws IOException {
IParser jsonParser = fhirContext.newJsonParser();
return npmPackage.listResources(resourceType.getSimpleName())
.stream()
.map(t -> {
try {
return npmPackage.loadResource(t);
} catch (IOException ex) {
log.error(ex.getMessage(), ex);
throw new RuntimeException("error in getResourcesOfTypes", ex);
}
})
.map(jsonParser::parseResource)
.filter(resourceType::isInstance)
.map(resourceType::cast)
.collect(Collectors.toList());
}
}