Search in sources :

Example 11 with BaseResource

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);
                    }
                }
            }
        }
    }
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) SuppressParserErrorHandler(org.hl7.davinci.SuppressParserErrorHandler) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IParser(ca.uhn.fhir.parser.IParser)

Aggregations

IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 IParser (ca.uhn.fhir.parser.IParser)3 SuppressParserErrorHandler (org.hl7.davinci.SuppressParserErrorHandler)3 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)2 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)2 PreconditionFailedException (ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException)2 IFhirTransformerException (ch.elexis.core.findings.util.fhir.IFhirTransformerException)2 ArrayList (java.util.ArrayList)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 ResourceVersionConflictException (ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1