Search in sources :

Example 1 with SystemOutLoggingService

use of org.hl7.fhir.r5.context.SystemOutLoggingService in project org.hl7.fhir.core by hapifhir.

the class ValidationService method initializeValidator.

public String initializeValidator(CliContext cliContext, String definitions, TimeTracker tt, String sessionId) throws Exception {
    tt.milestone();
    if (!sessionCache.sessionExists(sessionId)) {
        if (sessionId != null) {
            System.out.println("No such cached session exists for session id " + sessionId + ", re-instantiating validator.");
        }
        System.out.print("  Load FHIR v" + cliContext.getSv() + " from " + definitions);
        ValidationEngine validator = new ValidationEngine.ValidationEngineBuilder().withVersion(cliContext.getSv()).withTimeTracker(tt).withUserAgent("fhir/validator").fromSource(definitions);
        sessionId = sessionCache.cacheSession(validator);
        FhirPublication ver = FhirPublication.fromCode(cliContext.getSv());
        IgLoader igLoader = new IgLoader(validator.getPcm(), validator.getContext(), validator.getVersion(), validator.isDebug());
        System.out.println(" - " + validator.getContext().countAllCaches() + " resources (" + tt.milestone() + ")");
        igLoader.loadIg(validator.getIgs(), validator.getBinaries(), "hl7.terminology", false);
        System.out.print("  Terminology server " + cliContext.getTxServer());
        String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), ver);
        System.out.println(" - Version " + txver + " (" + tt.milestone() + ")");
        validator.setDebug(cliContext.isDoDebug());
        validator.getContext().setLogger(new SystemOutLoggingService(cliContext.isDoDebug()));
        for (String src : cliContext.getIgs()) {
            igLoader.loadIg(validator.getIgs(), validator.getBinaries(), src, cliContext.isRecursive());
        }
        System.out.print("  Get set... ");
        validator.setQuestionnaireMode(cliContext.getQuestionnaireMode());
        validator.setLevel(cliContext.getLevel());
        validator.setDoNative(cliContext.isDoNative());
        validator.setHintAboutNonMustSupport(cliContext.isHintAboutNonMustSupport());
        for (String s : cliContext.getExtensions()) {
            if ("*".equals(s)) {
                validator.setAnyExtensionsAllowed(true);
            } else {
                validator.getExtensionDomains().add(s);
            }
        }
        validator.setLanguage(cliContext.getLang());
        validator.setLocale(cliContext.getLocale());
        validator.setSnomedExtension(cliContext.getSnomedCTCode());
        validator.setAssumeValidRestReferences(cliContext.isAssumeValidRestReferences());
        validator.setShowMessagesFromReferences(cliContext.isShowMessagesFromReferences());
        validator.setNoExtensibleBindingMessages(cliContext.isNoExtensibleBindingMessages());
        validator.setNoUnicodeBiDiControlChars(cliContext.isNoUnicodeBiDiControlChars());
        validator.setNoInvariantChecks(cliContext.isNoInvariants());
        validator.setWantInvariantInMessage(cliContext.isWantInvariantsInMessages());
        validator.setSecurityChecks(cliContext.isSecurityChecks());
        validator.setCrumbTrails(cliContext.isCrumbTrails());
        validator.setShowTimes(cliContext.isShowTimes());
        validator.setAllowExampleUrls(cliContext.isAllowExampleUrls());
        StandAloneValidatorFetcher fetcher = new StandAloneValidatorFetcher(validator.getPcm(), validator.getContext(), validator);
        validator.setFetcher(fetcher);
        validator.getContext().setLocator(fetcher);
        validator.getBundleValidationRules().addAll(cliContext.getBundleValidationRules());
        TerminologyCache.setNoCaching(cliContext.isNoInternalCaching());
        // generate any missing snapshots
        validator.prepare();
        System.out.println(" go (" + tt.milestone() + ")");
    } else {
        System.out.println("Cached session exists for session id " + sessionId + ", returning stored validator session id.");
    }
    return sessionId;
}
Also used : IgLoader(org.hl7.fhir.validation.IgLoader) FhirPublication(org.hl7.fhir.utilities.FhirPublication) SystemOutLoggingService(org.hl7.fhir.r5.context.SystemOutLoggingService) ValidationEngine(org.hl7.fhir.validation.ValidationEngine)

Aggregations

SystemOutLoggingService (org.hl7.fhir.r5.context.SystemOutLoggingService)1 FhirPublication (org.hl7.fhir.utilities.FhirPublication)1 IgLoader (org.hl7.fhir.validation.IgLoader)1 ValidationEngine (org.hl7.fhir.validation.ValidationEngine)1