@Override protected List<ValidationMessage> validate(IValidationContext<?> theCtx) { Object resource = theCtx.getResource(); if (!(theCtx.getResource() instanceof IBaseResource)) { ourLog.debug("Not validating object of type {}", theCtx.getResource().getClass()); return Collections.emptyList(); } if (resource instanceof QuestionnaireResponse) { return doValidate(theCtx, (QuestionnaireResponse) resource); } RuntimeResourceDefinition def = theCtx.getFhirContext().getResourceDefinition((IBaseResource) resource); if ("QuestionnaireResponse".equals(def.getName()) == false) { return Collections.emptyList(); } /* * If we have a non-RI structure, convert it */ IParser p = theCtx.getFhirContext().newJsonParser(); String string = p.encodeResourceToString((IBaseResource) resource); QuestionnaireResponse qa = p.parseResource(QuestionnaireResponse.class, string); return doValidate(theCtx, qa); }
encodedResource = theContext.getResourceAsString(); } else { encodedResource = theContext.getFhirContext().newXmlParser().encodeResourceToString((IBaseResource) theContext.getResource());
@Override public void validateResource(IValidationContext<IBaseResource> theCtx) { if (theCtx.getResource() instanceof IBaseBundle) { IBaseBundle bundle = (IBaseBundle) theCtx.getResource(); List<IBaseResource> subResources = BundleUtil.toListOfResources(myCtx, bundle); for (IBaseResource nextSubResource : subResources) { resourceAsString = theCtx.getResourceAsString(); } else { resourceAsString = theCtx.getFhirContext().newXmlParser().encodeResourceToString(theCtx.getResource()); IErrorList errors = SchematronHelper.convertToErrorList(results, theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName());
private ISchematronResource getSchematron(IValidationContext<IBaseResource> theCtx) { Class<? extends IBaseResource> resource = theCtx.getResource().getClass(); Class<? extends IBaseResource> baseResourceClass = theCtx.getFhirContext().getResourceDefinition(resource).getBaseDefinition().getImplementingClass(); return getSchematronAndCache(theCtx, baseResourceClass); }
encodedResource = theContext.getResourceAsString(); } else { encodedResource = theContext.getFhirContext().newXmlParser().encodeResourceToString((IBaseResource) theContext.getResource());
private ISchematronResource getSchematronAndCache(IValidationContext<IBaseResource> theCtx, Class<? extends IBaseResource> theClass) { synchronized (myClassToSchematron) { ISchematronResource retVal = myClassToSchematron.get(theClass); if (retVal != null) { return retVal; } String pathToBase = myCtx.getVersion().getPathToSchemaDefinitions() + '/' + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName().toLowerCase() + ".sch"; try (InputStream baseIs = FhirValidator.class.getResourceAsStream(pathToBase)) { if (baseIs == null) { throw new InternalErrorException("Failed to load schematron for resource '" + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName() + "'. " + SchemaBaseValidator.RESOURCES_JAR_NOTE); } } catch (IOException e) { ourLog.error("Failed to close stream", e); } retVal = SchematronResourceSCH.fromClassPath(pathToBase); myClassToSchematron.put(theClass, retVal); return retVal; } } }
@Override public void validateResource(IValidationContext<IBaseResource> theCtx) { if (theCtx.getResource() instanceof IBaseBundle) { IBaseBundle bundle = (IBaseBundle) theCtx.getResource(); List<IBaseResource> subResources = BundleUtil.toListOfResources(myCtx, bundle); for (IBaseResource nextSubResource : subResources) { resourceAsString = theCtx.getResourceAsString(); } else { resourceAsString = theCtx.getFhirContext().newXmlParser().encodeResourceToString(theCtx.getResource()); IErrorList errors = SchematronHelper.convertToErrorList(results, theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName());
@Override protected List<ValidationMessage> validate(IValidationContext<?> theCtx) { Object resource = theCtx.getResource(); if (!(theCtx.getResource() instanceof IBaseResource)) { ourLog.debug("Not validating object of type {}", theCtx.getResource().getClass()); return Collections.emptyList(); } if (resource instanceof QuestionnaireResponse) { return doValidate(theCtx, (QuestionnaireResponse) resource); } RuntimeResourceDefinition def = theCtx.getFhirContext().getResourceDefinition((IBaseResource) resource); if ("QuestionnaireResponse".equals(def.getName()) == false) { return Collections.emptyList(); } /* * If we have a non-RI structure, convert it */ IParser p = theCtx.getFhirContext().newJsonParser(); String string = p.encodeResourceToString((IBaseResource) resource); QuestionnaireResponse qa = p.parseResource(QuestionnaireResponse.class, string); return doValidate(theCtx, qa); }
private ISchematronResource getSchematron(IValidationContext<IBaseResource> theCtx) { Class<? extends IBaseResource> resource = theCtx.getResource().getClass(); Class<? extends IBaseResource> baseResourceClass = theCtx.getFhirContext().getResourceDefinition(resource).getBaseDefinition().getImplementingClass(); return getSchematronAndCache(theCtx, baseResourceClass); }
private ISchematronResource getSchematronAndCache(IValidationContext<IBaseResource> theCtx, Class<? extends IBaseResource> theClass) { synchronized (myClassToSchematron) { ISchematronResource retVal = myClassToSchematron.get(theClass); if (retVal != null) { return retVal; } String pathToBase = myCtx.getVersion().getPathToSchemaDefinitions() + '/' + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName().toLowerCase() + ".sch"; try (InputStream baseIs = FhirValidator.class.getResourceAsStream(pathToBase)) { if (baseIs == null) { throw new InternalErrorException("Failed to load schematron for resource '" + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName() + "'. " + SchemaBaseValidator.RESOURCES_JAR_NOTE); } } catch (IOException e) { ourLog.error("Failed to close stream", e); } retVal = SchematronResourceSCH.fromClassPath(pathToBase); myClassToSchematron.put(theClass, retVal); return retVal; } } }