Search in sources :

Example 1 with DroolsDescriptionService

use of org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService in project snomed-drools by IHTSDO.

the class DroolsRF2Validator method validateSnapshot.

public List<InvalidContent> validateSnapshot(InputStream snomedRf2EditionZip, Set<String> ruleSetNamesToRun) throws ReleaseImportException {
    long start = new Date().getTime();
    Assert.isTrue(ruleSetNamesToRun != null && !ruleSetNamesToRun.isEmpty(), "The name of at least one rule set must be specified.");
    ReleaseImporter importer = new ReleaseImporter();
    SnomedDroolsComponentRepository repository = new SnomedDroolsComponentRepository();
    logger.info("Loading components from RF2");
    LoadingProfile loadingProfile = LoadingProfile.complete;
    loadingProfile.getIncludedReferenceSetFilenamePatterns().add(".*_cRefset_Language.*");
    importer.loadSnapshotReleaseFiles(snomedRf2EditionZip, loadingProfile, new SnomedDroolsComponentFactory(repository));
    logger.info("Components loaded");
    DroolsConceptService conceptService = new DroolsConceptService(repository);
    DroolsDescriptionService descriptionService = new DroolsDescriptionService(repository);
    DroolsRelationshipService relationshipService = new DroolsRelationshipService(repository);
    Collection<DroolsConcept> concepts = repository.getConcepts();
    logger.info("Running tests");
    List<InvalidContent> invalidContents = ruleExecutor.execute(ruleSetNamesToRun, concepts, conceptService, descriptionService, relationshipService, true, false);
    logger.info("Tests complete. Total run time {} seconds", (new Date().getTime() - start) / 1000);
    logger.info("invalidContent count {}", invalidContents.size());
    return invalidContents;
}
Also used : ReleaseImporter(org.ihtsdo.otf.snomedboot.ReleaseImporter) InvalidContent(org.ihtsdo.drools.response.InvalidContent) DroolsDescriptionService(org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) DroolsConceptService(org.ihtsdo.drools.validator.rf2.service.DroolsConceptService) DroolsRelationshipService(org.ihtsdo.drools.validator.rf2.service.DroolsRelationshipService) LoadingProfile(org.ihtsdo.otf.snomedboot.factory.LoadingProfile)

Example 2 with DroolsDescriptionService

use of org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService in project snomed-drools by IHTSDO.

the class DroolsRF2Validator method validateRF2Files.

/**
 * @param extractedRF2FilesDirectories	Paths to directories containing all extracted RF2 files. This can be the snapshot files of a single or multiple code systems and
 *                                         can also include delta files for the new release.
 * @param previousReleaseDirectories	Path to directories containing extracted RF2 files from the previous release. These are used to determine the released status of
 *                                         components, that is used in some assertions.
 * @param ruleSetNamesToRun				The assertion groups to run the rules of.
 * @param currentEffectiveTime			The current effectiveTime of the latest published files, used to determine the published flag on components.
 * @param includedModules				Optional filter to validate components only in specific modules.
 * @param activeConceptsOnly            Optional filter to return invalid content only for active concepts (ignore inactive concepts).
 * @return								A collections of invalid content according to the rules within the assertion groups selected.
 * @throws ReleaseImportException		Exception thrown when application fails to load the RF2 files to be validated.
 */
public List<InvalidContent> validateRF2Files(Set<String> extractedRF2FilesDirectories, Set<String> previousReleaseDirectories, Set<String> ruleSetNamesToRun, String currentEffectiveTime, Set<String> includedModules, boolean activeConceptsOnly) throws ReleaseImportException {
    long start = new Date().getTime();
    Assert.isTrue(ruleSetNamesToRun != null && !ruleSetNamesToRun.isEmpty(), "The name of at least one rule set must be specified.");
    PreviousReleaseComponentFactory previousReleaseComponentFactory = null;
    if (previousReleaseDirectories != null) {
        previousReleaseComponentFactory = loadPreviousReleaseComponentIds(previousReleaseDirectories);
    }
    logger.info("Loading components from RF2");
    SnomedDroolsComponentRepository repository = loadComponentsFromRF2(extractedRF2FilesDirectories, currentEffectiveTime, previousReleaseComponentFactory);
    logger.info("Components loaded");
    DroolsConceptService conceptService = new DroolsConceptService(repository);
    DroolsDescriptionService descriptionService = new DroolsDescriptionService(repository, testResourceProvider);
    DroolsRelationshipService relationshipService = new DroolsRelationshipService(repository);
    Collection<DroolsConcept> concepts = repository.getConcepts();
    logger.info("Running tests");
    List<InvalidContent> invalidContents = ruleExecutor.execute(ruleSetNamesToRun, concepts, conceptService, descriptionService, relationshipService, true, false);
    invalidContents.addAll(repository.getComponentLoadingErrors());
    // Filter only invalid components that are in the specified modules list, if modules list is not specified, return all invalid components
    if (includedModules != null && !includedModules.isEmpty()) {
        logger.info("Filtering invalid contents for included module ids: {}", String.join(",", includedModules));
        invalidContents = invalidContents.stream().filter(content -> includedModules.contains(content.getComponent().getModuleId())).collect(Collectors.toList());
    }
    // Filter only active concepts
    if (activeConceptsOnly) {
        invalidContents = invalidContents.stream().filter(c -> conceptService.isActive(c.getConceptId())).collect(Collectors.toList());
    }
    // Add concept FSN to invalid contents
    for (InvalidContent invalidContent : invalidContents) {
        if (invalidContent.getConceptId() != null && !invalidContent.getConceptId().isEmpty()) {
            Set<String> fsnSet = descriptionService.getFSNs(Sets.newHashSet(invalidContent.getConceptId()));
            if (!fsnSet.isEmpty()) {
                invalidContent.setConceptFsn(fsnSet.iterator().next());
            }
        }
    }
    // Free resources after getting validation results
    repository.cleanup();
    descriptionService.getDroolsDescriptionIndex().cleanup();
    logger.info("invalidContent count {}", invalidContents.size());
    logger.info("Tests complete. Total run time {} seconds", (new Date().getTime() - start) / 1000);
    return invalidContents;
}
Also used : InvalidContent(org.ihtsdo.drools.response.InvalidContent) DroolsDescriptionService(org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) DroolsConceptService(org.ihtsdo.drools.validator.rf2.service.DroolsConceptService) DroolsRelationshipService(org.ihtsdo.drools.validator.rf2.service.DroolsRelationshipService)

Aggregations

InvalidContent (org.ihtsdo.drools.response.InvalidContent)2 DroolsConcept (org.ihtsdo.drools.validator.rf2.domain.DroolsConcept)2 DroolsConceptService (org.ihtsdo.drools.validator.rf2.service.DroolsConceptService)2 DroolsDescriptionService (org.ihtsdo.drools.validator.rf2.service.DroolsDescriptionService)2 DroolsRelationshipService (org.ihtsdo.drools.validator.rf2.service.DroolsRelationshipService)2 ReleaseImporter (org.ihtsdo.otf.snomedboot.ReleaseImporter)1 LoadingProfile (org.ihtsdo.otf.snomedboot.factory.LoadingProfile)1