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();
}
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));
}
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);
}
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();
}
Aggregations