class CompartmentUtil {

    public static final Map<String, CompartmentCache> buildCompartmentMap() {
        Map<String, CompartmentCache> cachedCompartmentMap = compartmentMap;

        if (cachedCompartmentMap == null) {
            // If cachedCompartmentMap is empty, there is something else going on.

            cachedCompartmentMap = new HashMap<>();

            try (InputStreamReader reader = new InputStreamReader(CompartmentUtil.class.getResourceAsStream(RESOURCE))) {
                Bundle bundle = FHIRParser.parser(Format.JSON).parse(reader);

                FHIRPathEvaluator evaluator = FHIRPathEvaluator.evaluator();
                EvaluationContext evaluationContext = new EvaluationContext(bundle);

                Collection<FHIRPathNode> result = evaluator.evaluate(evaluationContext, FHIR_PATH_BUNDLE_ENTRY);

                Iterator<FHIRPathNode> iter = result.iterator();
                while (iter.hasNext()) {
                    FHIRPathResourceNode node = iter.next().asResourceNode();

                    // Convert to Resource and lookup.
                    CompartmentDefinition compartmentDefinition = node.resource().as(CompartmentDefinition.class);

                    // The cached object (a smaller/lighter lookup resource) used for point lookups
                    CompartmentCache compartmentDefinitionCache = new CompartmentCache();

                    // Iterates over the resources embedded in the CompartmentDefinition.
                    for (Resource resource : compartmentDefinition.getResource()) {
                        String inclusionCode = resource.getCode().getValue();
                        List<com.ibm.fhir.model.type.String> params = resource.getParam();
                        // Make sure to only add the valid resource types (at least with one inclusion) instead of all types.
                        if (!params.isEmpty()) {
                            compartmentDefinitionCache.add(inclusionCode, params);
                        }
                    }

                    String codeCacheName = compartmentDefinition.getCode().getValue();
                    cachedCompartmentMap.put(codeCacheName, compartmentDefinitionCache);

                }

                // Make unmodifiable.
                cachedCompartmentMap = Collections.unmodifiableMap(cachedCompartmentMap);

            } catch (FHIRException e) {
                log.warning(String.format(PARSE_EXCEPTION, FROM_STREAM));
            } catch (IOException e1) {
                log.warning(String.format(IO_EXCEPTION, FROM_STREAM));
            }
        }

        return cachedCompartmentMap;

    }

    private  CompartmentUtil();

}