Search in sources :

Example 1 with TimeTracker

use of org.hl7.fhir.utilities.TimeTracker in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConvertService method initValidationEngine.

@EventListener(ApplicationReadyEvent.class)
protected void initValidationEngine() throws IOException, URISyntaxException {
    String definitions = VersionUtilities.packageForVersion(PACKAGE_VERSION) + "#" + VersionUtilities.getCurrentVersion(PACKAGE_VERSION);
    this.validationEngine = new ValidationEngine(definitions, FhirPublication.R4, PACKAGE_VERSION, new TimeTracker());
    // Loading structure definitions from official package and uploading custom definitions if needed from resources
    this.validationEngine.loadPackage(SDOH_CLINICAL_CARE_PACKAGE, SDOH_CLINICAL_CARE_VERSION);
    // Loading  custom structure definitions, copying all resources from jar to local folder to be able for HAPI to
    // upload them. Just passing resources folder is not working for "in jar" files.
    loadStructureDefinitions();
}
Also used : TimeTracker(org.hl7.fhir.utilities.TimeTracker) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) EventListener(org.springframework.context.event.EventListener)

Example 2 with TimeTracker

use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.

the class ValidationService method validateSources.

public ValidationResponse validateSources(ValidationRequest request) throws Exception {
    if (request.getCliContext().getSv() == null) {
        String sv = determineVersion(request.getCliContext(), request.sessionId);
        request.getCliContext().setSv(sv);
    }
    String definitions = VersionUtilities.packageForVersion(request.getCliContext().getSv()) + "#" + VersionUtilities.getCurrentVersion(request.getCliContext().getSv());
    String sessionId = initializeValidator(request.getCliContext(), definitions, new TimeTracker(), request.sessionId);
    ValidationEngine validator = sessionCache.fetchSessionValidatorEngine(sessionId);
    if (request.getCliContext().getProfiles().size() > 0) {
        System.out.println("  .. validate " + request.listSourceFiles() + " against " + request.getCliContext().getProfiles().toString());
    } else {
        System.out.println("  .. validate " + request.listSourceFiles());
    }
    ValidationResponse response = new ValidationResponse().setSessionId(sessionId);
    for (FileInfo fp : request.getFilesToValidate()) {
        List<ValidationMessage> messages = new ArrayList<>();
        validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), request.getCliContext().getProfiles(), messages);
        ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp);
        messages.forEach(outcome::addMessage);
        response.addOutcome(outcome);
    }
    System.out.println("  Max Memory: " + Runtime.getRuntime().maxMemory());
    return response;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) TimeTracker(org.hl7.fhir.utilities.TimeTracker) ArrayList(java.util.ArrayList) ValidationEngine(org.hl7.fhir.validation.ValidationEngine)

Example 3 with TimeTracker

use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.

the class ValidationEngine method loadCoreDefinitions.

/**
 * @param src
 * @param recursive
 * @param terminologyCachePath
 * @param userAgent
 * @param tt
 * @param loggingService
 * @throws FHIRException
 * @throws IOException
 *
 * @see IgLoader#loadIgSource(String, boolean, boolean) loadIgSource for detailed description of the src parameter
 */
private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt, IWorkerContext.ILoggingService loggingService) throws FHIRException, IOException {
    NpmPackage npm = getPcm().loadPackage(src, null);
    if (npm != null) {
        version = npm.fhirVersion();
        SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService);
        if (terminologyCachePath != null)
            contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
        if (userAgent != null) {
            contextBuilder.withUserAgent(userAgent);
        }
        context = contextBuilder.fromPackage(npm, ValidatorUtils.loaderForVersion(version));
    } else {
        Map<String, byte[]> source = igLoader.loadIgSource(src, recursive, true);
        if (version == null) {
            version = getVersionFromPack(source);
        }
        SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
        if (terminologyCachePath != null)
            contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
        if (userAgent != null) {
            contextBuilder.withUserAgent(userAgent);
        }
        context = contextBuilder.fromDefinitions(source, ValidatorUtils.loaderForVersion(version), new PackageVersion(src, new Date()));
        ValidatorUtils.grabNatives(getBinaries(), source, "http://hl7.org/fhir");
    }
    // on https://chat.fhir.org/#narrow/stream/179167-hapi
    try {
        ClassLoader classLoader = ValidationEngine.class.getClassLoader();
        InputStream ue = classLoader.getResourceAsStream("ucum-essence.xml");
        context.setUcumService(new UcumEssenceService(ue));
    } catch (Exception e) {
        throw new FHIRException("Error loading UCUM from embedded ucum-essence.xml: " + e.getMessage(), e);
    }
    initContext(tt);
}
Also used : SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext) PackageVersion(org.hl7.fhir.r5.context.IWorkerContext.PackageVersion) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UcumEssenceService(org.fhir.ucum.UcumEssenceService) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 4 with TimeTracker

use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.

the class ValidationEngine method initContext.

protected void initContext(TimeTracker tt) throws IOException {
    context.setCanNoTS(true);
    context.setCacheId(UUID.randomUUID().toString());
    // because of Forge
    context.setAllowLoadingDuplicates(true);
    context.setExpansionProfile(makeExpProfile());
    if (tt != null) {
        context.setClock(tt);
    }
    NpmPackage npmX = getPcm().loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
    context.loadFromPackage(npmX, null);
    this.fhirPathEngine = new FHIRPathEngine(context);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine)

Example 5 with TimeTracker

use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.

the class ValidatorCli method main.

public static void main(String[] args) throws Exception {
    TimeTracker tt = new TimeTracker();
    TimeTracker.Session tts = tt.start("Loading");
    args = preProcessArgs(args);
    Display.displayVersion();
    Display.displaySystemInfo();
    if (Params.hasParam(args, Params.PROXY)) {
        assert Params.getParam(args, Params.PROXY) != null : "PROXY arg passed in was NULL";
        String[] p = Params.getParam(args, Params.PROXY).split(":");
        System.setProperty(HTTP_PROXY_HOST, p[0]);
        System.setProperty(HTTP_PROXY_PORT, p[1]);
    }
    if (Params.hasParam(args, Params.PROXY_AUTH)) {
        assert Params.getParam(args, Params.PROXY) != null : "Cannot set PROXY_AUTH without setting PROXY...";
        assert Params.getParam(args, Params.PROXY_AUTH) != null : "PROXY_AUTH arg passed in was NULL...";
        String[] p = Params.getParam(args, Params.PROXY_AUTH).split(":");
        String authUser = p[0];
        String authPass = p[1];
        /*
       * For authentication, use java.net.Authenticator to set proxy's configuration and set the system properties
       * http.proxyUser and http.proxyPassword
       */
        Authenticator.setDefault(new Authenticator() {

            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(authUser, authPass.toCharArray());
            }
        });
        System.setProperty(HTTP_PROXY_USER, authUser);
        System.setProperty(HTTP_PROXY_PASS, authPass);
        System.setProperty(JAVA_USE_SYSTEM_PROXIES, "true");
        /*
       * For Java 1.8 and higher you must set
       * -Djdk.http.auth.tunneling.disabledSchemes=
       * to make proxies with Basic Authorization working with https along with Authenticator
       */
        System.setProperty(JAVA_DISABLED_TUNNELING_SCHEMES, "");
        System.setProperty(JAVA_DISABLED_PROXY_SCHEMES, "");
    }
    CliContext cliContext = Params.loadCliContext(args);
    if (Params.hasParam(args, Params.TEST)) {
        Common.runValidationEngineTests();
    } else if (shouldDisplayHelpToUser(args)) {
        Display.displayHelpDetails();
    } else if (Params.hasParam(args, Params.COMPARE)) {
        if (destinationDirectoryValid(Params.getParam(args, Params.DESTINATION))) {
            doLeftRightComparison(args, cliContext, tt);
        }
    } else {
        Display.printCliArgumentsAndInfo(args);
        doValidation(tt, tts, cliContext);
    }
}
Also used : TimeTracker(org.hl7.fhir.utilities.TimeTracker) CliContext(org.hl7.fhir.validation.cli.model.CliContext) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication)

Aggregations

ValidationEngine (org.hl7.fhir.validation.ValidationEngine)4 TimeTracker (org.hl7.fhir.utilities.TimeTracker)3 NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)2 Authenticator (java.net.Authenticator)1 PasswordAuthentication (java.net.PasswordAuthentication)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 UcumEssenceService (org.fhir.ucum.UcumEssenceService)1 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 PackageVersion (org.hl7.fhir.r5.context.IWorkerContext.PackageVersion)1 SimpleWorkerContext (org.hl7.fhir.r5.context.SimpleWorkerContext)1 SystemOutLoggingService (org.hl7.fhir.r5.context.SystemOutLoggingService)1 FHIRPathEngine (org.hl7.fhir.r5.utils.FHIRPathEngine)1 FhirPublication (org.hl7.fhir.utilities.FhirPublication)1 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)1 IgLoader (org.hl7.fhir.validation.IgLoader)1 CliContext (org.hl7.fhir.validation.cli.model.CliContext)1 EventListener (org.springframework.context.event.EventListener)1 SAXException (org.xml.sax.SAXException)1