Search in sources :

Example 1 with ProfileValidator

use of org.hl7.fhir.validation.profile.ProfileValidator in project dpc-app by CMSgov.

the class APITestHelpers method buildResourceExtension.

/**
 * Build Dropwizard test instance with a specific subset of Resources and Providers
 *
 * @param ctx        - {@link FhirContext} context to use
 * @param resources  - {@link List} of resources to add to test instance
 * @param providers  - {@link List} of providers to add to test instance
 * @param validation - {@code true} enable custom validation. {@code false} Disable custom validation
 * @return - {@link ResourceExtension}
 */
public static ResourceExtension buildResourceExtension(FhirContext ctx, List<Object> resources, List<Object> providers, boolean validation) {
    final FHIRHandler fhirHandler = new FHIRHandler(ctx);
    final var builder = ResourceExtension.builder().setRegisterDefaultExceptionMappers(false).setTestContainerFactory(new GrizzlyWebTestContainerFactory()).addProvider(fhirHandler).addProvider(new BundleHandler(fhirHandler)).addProvider(JerseyExceptionHandler.class).addProvider(PersistenceExceptionHandler.class).addProvider(HAPIExceptionHandler.class).addProvider(DefaultFHIRExceptionHandler.class).addProvider(JsonParseExceptionMapper.class).addProvider(new AuthValueFactoryProvider.Binder<>(OrganizationPrincipal.class));
    // Optionally enable validation
    if (validation) {
        // Validation config
        final DPCFHIRConfiguration.FHIRValidationConfiguration config = new DPCFHIRConfiguration.FHIRValidationConfiguration();
        config.setEnabled(true);
        config.setSchematronValidation(true);
        config.setSchemaValidation(true);
        final DPCProfileSupport dpcModule = new DPCProfileSupport(ctx);
        final ValidationSupportChain support = new ValidationSupportChain(new DefaultProfileValidationSupport(), dpcModule);
        final InjectingConstraintValidatorFactory constraintFactory = new InjectingConstraintValidatorFactory(Set.of(new ProfileValidator(new FHIRValidatorProvider(ctx, config, support).get())));
        builder.setValidator(provideValidator(constraintFactory));
    }
    resources.forEach(builder::addResource);
    providers.forEach(builder::addProvider);
    return builder.build();
}
Also used : DPCFHIRConfiguration(gov.cms.dpc.fhir.configuration.DPCFHIRConfiguration) FHIRHandler(gov.cms.dpc.fhir.dropwizard.handlers.FHIRHandler) AuthValueFactoryProvider(io.dropwizard.auth.AuthValueFactoryProvider) DefaultProfileValidationSupport(org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport) FHIRValidatorProvider(gov.cms.dpc.fhir.validations.dropwizard.FHIRValidatorProvider) JsonParseExceptionMapper(gov.cms.dpc.api.exceptions.JsonParseExceptionMapper) BundleHandler(gov.cms.dpc.fhir.dropwizard.handlers.BundleHandler) ProfileValidator(gov.cms.dpc.fhir.validations.ProfileValidator) GrizzlyWebTestContainerFactory(org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory) OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) DPCProfileSupport(gov.cms.dpc.fhir.validations.DPCProfileSupport) JerseyExceptionHandler(gov.cms.dpc.fhir.dropwizard.handlers.exceptions.JerseyExceptionHandler) HAPIExceptionHandler(gov.cms.dpc.fhir.dropwizard.handlers.exceptions.HAPIExceptionHandler) ValidationSupportChain(org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain) InjectingConstraintValidatorFactory(gov.cms.dpc.fhir.validations.dropwizard.InjectingConstraintValidatorFactory)

Example 2 with ProfileValidator

use of org.hl7.fhir.validation.profile.ProfileValidator in project kindling by HL7.

the class Publisher method validateProfile.

private void validateProfile(ConstraintStructure p) throws Exception {
    ProfileValidator pv = new ProfileValidator(page.getWorkerContext(), null);
    page.getValidationErrors().addAll(pv.validate(p.getResource(), true));
}
Also used : ProfileValidator(org.hl7.fhir.validation.profile.ProfileValidator)

Example 3 with ProfileValidator

use of org.hl7.fhir.validation.profile.ProfileValidator in project kindling by HL7.

the class Publisher method producePage.

// private void validateProfile(ProfileDefn profile) throws FileNotFoundException, Exception {
// for (ResourceDefn c : profile.getResources()) {
// StructureDefinition resource = loadResourceProfile(c.getName());
// ProfileValidator v = new ProfileValidator();
// v.setCandidate(c);
// v.setProfile(resource);
// v.setTypes(typeFeed);
// List<String> errors = v.evaluate();
// if (errors.size() > 0)
// throw new Exception("Error validating " + profile.metadata("name") + ": " + errors.toString());
// }
// }
// private void produceFutureReference(String n) throws Exception {
// ElementDefn e = new ElementDefn();
// e.setName(page.getIni().getStringProperty("future-resources", n));
// }
/*
  private StructureDefinition loadResourceProfile(String name) throws FileNotFoundException, Exception {
    XmlParser xml = new XmlParser();
    try {
      return (StructureDefinition) xml.parse(new CSFileInputStream(page.getFolders().dstDir + name.toLowerCase() + ".profile.xml"));
    } catch (Exception e) {
      throw new Exception("error parsing " + name, e);
    }
  }
  */
// private void produceIgPage(String source, String file, String logicalName, ImplementationGuideDefn ig) throws Exception {
// String src = TextFile.fileToString(source);
// src = page.processPageIncludes(file, src, "page", null, null, null, logicalName, null);
// // before we save this page out, we're going to figure out what it's index
// // is, and number the headers if we can
// 
// if (Utilities.noString(logicalName))
// logicalName = Utilities.fileTitle(file);
// 
// TextFile.stringToFile(src, page.getFolders().dstDir + file);
// src = addSectionNumbers(file, logicalName, src, null, 0, null, ig);
// 
// TextFile.stringToFile(src, page.getFolders().dstDir + file);
// 
// src = TextFile.fileToString(source).replace("<body>", "<body style=\"margin: 10px\">");
// src = page.processPageIncludesForBook(file, src, "page", null, null);
// cachePage(file, src, logicalName);
// }
// 
private void producePage(String file, String logicalName) throws Exception {
    String src = TextFile.fileToString(page.getFolders().srcDir + file);
    src = page.processPageIncludes(file, src, "page", null, null, null, logicalName, null, null, null);
    if (Utilities.noString(logicalName))
        logicalName = Utilities.fileTitle(file);
    TextFile.stringToFile(src, page.getFolders().dstDir + file);
    DocumentHolder doch = new DocumentHolder();
    src = addSectionNumbers(file, logicalName, src, null, 0, doch, null);
    if (!page.getDefinitions().getStructuralPages().contains(file)) {
        XhtmlNode fmm = findId(doch.doc, "fmm");
        XhtmlNode wg = findId(doch.doc, "wg");
        if (fmm == null)
            page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, -1, -1, file, "Page has no fmm level", IssueSeverity.ERROR));
        else
            page.getDefinitions().page(file).setFmm(get2ndPart(fmm.allText()));
        if (wg == null)
            page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, -1, -1, file, "Page has no workgroup", IssueSeverity.ERROR));
        else
            page.getDefinitions().page(file).setWg(wg.getChildNodes().get(0).allText());
    }
    TextFile.stringToFile(src, page.getFolders().dstDir + file);
    src = TextFile.fileToString(page.getFolders().srcDir + file).replace("<body>", "<body style=\"margin: 10px\">");
    src = page.processPageIncludesForBook(file, src, "page", null, null, null);
    cachePage(file, src, logicalName, true);
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 4 with ProfileValidator

use of org.hl7.fhir.validation.profile.ProfileValidator in project kindling by HL7.

the class Publisher method validate.

private void validate() throws Exception {
    page.log("Validating", LogMessageType.Process);
    ResourceValidator val = new ResourceValidator(page.getDefinitions(), page.getTranslations(), page.getCodeSystems(), page.getFolders().srcDir, fpUsages, page.getSuppressedMessages(), page.getWorkerContext());
    val.resolvePatterns();
    ProfileValidator valp = new ProfileValidator(page.getWorkerContext(), null);
    for (String n : page.getDefinitions().getTypes().keySet()) page.getValidationErrors().addAll(val.checkStucture(n, page.getDefinitions().getTypes().get(n)));
    val.checkSearchParams(page.getValidationErrors(), page.getDefinitions().getResourceByName("Resource"));
    val.checkSearchParams(page.getValidationErrors(), page.getDefinitions().getResourceByName("DomainResource"));
    for (String n : page.getDefinitions().sortedResourceNames()) if (hasBuildFlag("page-" + n.toLowerCase()))
        page.getValidationErrors().addAll(val.check(n, page.getDefinitions().getResources().get(n)));
    page.getValidationErrors().addAll(val.check("Parameters", page.getDefinitions().getResourceByName("Parameters")));
    for (String rname : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn r = page.getDefinitions().getResources().get(rname);
        checkExampleLinks(page.getValidationErrors(), r);
    }
    for (Compartment cmp : page.getDefinitions().getCompartments()) page.getValidationErrors().addAll(val.check(cmp));
    page.setPatternFinder(val.getPatternFinder());
    val.report();
    val.summariseSearchTypes(page.getSearchTypeUsage());
    val.dumpParams();
    val.close();
    checkAllOk();
}
Also used : ResourceValidator(org.hl7.fhir.definitions.validation.ResourceValidator) Compartment(org.hl7.fhir.definitions.model.Compartment) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) ProfileValidator(org.hl7.fhir.validation.profile.ProfileValidator)

Aggregations

ProfileValidator (org.hl7.fhir.validation.profile.ProfileValidator)2 OrganizationPrincipal (gov.cms.dpc.api.auth.OrganizationPrincipal)1 JsonParseExceptionMapper (gov.cms.dpc.api.exceptions.JsonParseExceptionMapper)1 DPCFHIRConfiguration (gov.cms.dpc.fhir.configuration.DPCFHIRConfiguration)1 BundleHandler (gov.cms.dpc.fhir.dropwizard.handlers.BundleHandler)1 FHIRHandler (gov.cms.dpc.fhir.dropwizard.handlers.FHIRHandler)1 HAPIExceptionHandler (gov.cms.dpc.fhir.dropwizard.handlers.exceptions.HAPIExceptionHandler)1 JerseyExceptionHandler (gov.cms.dpc.fhir.dropwizard.handlers.exceptions.JerseyExceptionHandler)1 DPCProfileSupport (gov.cms.dpc.fhir.validations.DPCProfileSupport)1 ProfileValidator (gov.cms.dpc.fhir.validations.ProfileValidator)1 FHIRValidatorProvider (gov.cms.dpc.fhir.validations.dropwizard.FHIRValidatorProvider)1 InjectingConstraintValidatorFactory (gov.cms.dpc.fhir.validations.dropwizard.InjectingConstraintValidatorFactory)1 AuthValueFactoryProvider (io.dropwizard.auth.AuthValueFactoryProvider)1 GrizzlyWebTestContainerFactory (org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory)1 Compartment (org.hl7.fhir.definitions.model.Compartment)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 ResourceValidator (org.hl7.fhir.definitions.validation.ResourceValidator)1 DefaultProfileValidationSupport (org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport)1 ValidationSupportChain (org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain)1 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)1