Search in sources :

Example 1 with DroolsConceptService

use of org.ihtsdo.drools.validator.rf2.service.DroolsConceptService 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 DroolsConceptService

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

the class DroolsDescriptionService method findMatchingDescriptionInHierarchy.

@Override
public // Should search all descendants of the second highest ancestor (the ancestor which is a direct child of root).
Set<Description> findMatchingDescriptionInHierarchy(Concept concept, Description description) {
    if (concept == null || concept.getId().equals(Constants.ROOT_CONCEPT)) {
        return Collections.emptySet();
    }
    Set<Description> resultSet = new HashSet<>();
    String languageCode = description.getLanguageCode();
    String term = description.getTerm();
    if (term == null || term.trim().isEmpty())
        return Collections.emptySet();
    ConceptService conceptService = new DroolsConceptService(repository);
    Set<String> conceptAncestorIds = conceptService.findStatedAncestorsOfConcept(concept);
    for (String conceptAncestorId : conceptAncestorIds) {
        Concept conceptAncestor = repository.getConcept(conceptAncestorId);
        for (Description ancestorsDescription : conceptAncestor.getDescriptions()) {
            if (ancestorsDescription.isActive() && ancestorsDescription.getLanguageCode().equals(languageCode) && ancestorsDescription.getTerm().equals(term)) {
                resultSet.add(ancestorsDescription);
            }
        }
    }
    return resultSet;
}
Also used : Concept(org.ihtsdo.drools.domain.Concept) DroolsConcept(org.ihtsdo.drools.validator.rf2.domain.DroolsConcept) Description(org.ihtsdo.drools.domain.Description) DroolsDescription(org.ihtsdo.drools.validator.rf2.domain.DroolsDescription) ConceptService(org.ihtsdo.drools.service.ConceptService) HashSet(java.util.HashSet)

Example 3 with DroolsConceptService

use of org.ihtsdo.drools.validator.rf2.service.DroolsConceptService 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

DroolsConcept (org.ihtsdo.drools.validator.rf2.domain.DroolsConcept)3 InvalidContent (org.ihtsdo.drools.response.InvalidContent)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 HashSet (java.util.HashSet)1 Concept (org.ihtsdo.drools.domain.Concept)1 Description (org.ihtsdo.drools.domain.Description)1 ConceptService (org.ihtsdo.drools.service.ConceptService)1 DroolsDescription (org.ihtsdo.drools.validator.rf2.domain.DroolsDescription)1 ReleaseImporter (org.ihtsdo.otf.snomedboot.ReleaseImporter)1 LoadingProfile (org.ihtsdo.otf.snomedboot.factory.LoadingProfile)1