use of org.hl7.fhir.r4.model.BaseResource in project CRD by HL7-DaVinci.
the class CommonFileStore method processFhirFolder.
private void processFhirFolder(String topic, String fhirVersion, File fhirPath) {
fhirVersion = fhirVersion.toUpperCase();
logger.info(" CommonFileStore::processFhirFolder(): " + fhirVersion + ": " + fhirPath.getName());
// setup the proper FHIR Context for the version of FHIR we are dealing with
FhirContext ctx = null;
if (fhirVersion.equalsIgnoreCase("R4")) {
ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
} else {
logger.warn("unsupported FHIR version: " + fhirVersion + ", skipping folder");
return;
}
IParser parser = ctx.newJsonParser();
// suppress the unknown element warnings
parser.setParserErrorHandler(new SuppressParserErrorHandler());
File[] directories = fhirPath.listFiles();
for (File folder : directories) {
if (folder.getName().equalsIgnoreCase("resources") && folder.isDirectory()) {
File[] resources = folder.listFiles();
for (File resource : resources) {
if (resource.isFile()) {
String filename = resource.getName();
logger.info(" process: FHIR Resource: " + filename);
String[] parts = filename.split("-");
if (parts.length > 2) {
if (!parts[1].equalsIgnoreCase(fhirVersion)) {
logger.warn("CommonFileStore::processFhirFolder() warning: FhirVersion doesn't match!");
continue;
}
// parse the the resource file into the correct FHIR
IBaseResource baseResource = null;
try {
baseResource = parser.parseResource(new FileInputStream(resource));
} catch (FileNotFoundException e) {
logger.warn("could not find file: " + resource.getPath());
continue;
}
processFhirResource(baseResource, filename, filename, fhirVersion, topic);
}
}
}
}
}
}
Aggregations