/** * @deprecated Use {@link #toOperationOutcome()} instead since this method returns a view. * {@link #toOperationOutcome()} is identical to this method, but has a more suitable name so this method * will be removed at some point. */ @Deprecated public IBaseOperationOutcome getOperationOutcome() { return toOperationOutcome(); }
/** * Fail the request by throwing an {@link UnprocessableEntityException} as a result of a validation failure. * Subclasses may change this behaviour by providing alternate behaviour. */ protected void fail(RequestDetails theRequestDetails, ValidationResult theValidationResult) { throw new UnprocessableEntityException(theRequestDetails.getServer().getFhirContext(), theValidationResult.toOperationOutcome()); }
/** * Validates a resource instance, throwing a {@link ValidationFailureException} if the validation fails * * @param theResource * The resource to validate * @throws ValidationFailureException * If the validation fails * @deprecated use {@link #validateWithResult(IBaseResource)} instead */ @Deprecated public void validate(IResource theResource) throws ValidationFailureException { applyDefaultValidators(); ValidationResult validationResult = validateWithResult(theResource); if (!validationResult.isSuccessful()) { throw new ValidationFailureException(myContext, validationResult.toOperationOutcome()); } }
IBaseOperationOutcome oo = result.toOperationOutcome(); ourLog.info("Result:\n{}", xmlParser.setPrettyPrint(true).encodeResourceToString(oo));
OperationOutcome oo = (OperationOutcome) result.toOperationOutcome(); String results = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(oo); System.out.println(results);
/** * @deprecated Use {@link #toOperationOutcome()} instead since this method returns a view. * {@link #toOperationOutcome()} is identical to this method, but has a more suitable name so this method * will be removed at some point. */ @Deprecated public IBaseOperationOutcome getOperationOutcome() { return toOperationOutcome(); }
OperationOutcome oo = (OperationOutcome) result.toOperationOutcome();
retVal.setOperationOutcome(result.toOperationOutcome()); return retVal; } else { throw new PreconditionFailedException("Validation failed", result.toOperationOutcome());
retVal.setOperationOutcome(result.toOperationOutcome()); return retVal; } else { throw new PreconditionFailedException("Validation failed", result.toOperationOutcome());
for (SingleValidationMessage next : validationResult.getMessages()) { if (next.getSeverity().ordinal() >= myAddResponseOutcomeHeaderOnSeverity) { outcome = validationResult.toOperationOutcome(); break;
retVal.setOperationOutcome(result.toOperationOutcome()); return retVal; } else { throw new PreconditionFailedException("Validation failed", result.toOperationOutcome());
@Override protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave) { super.validateResourceForStorage(theResource, theEntityToSave); if (!myValidateResponses) { return; } QuestionnaireResponse qa = theResource; if (qa == null || qa.getQuestionnaire() == null || qa.getQuestionnaire().getReference() == null || qa.getQuestionnaire().getReference().isEmpty()) { return; } FhirValidator val = myRefImplCtx.newValidator(); val.setValidateAgainstStandardSchema(false); val.setValidateAgainstStandardSchematron(false); FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator(); module.setResourceLoader(new JpaResourceLoader()); module.setWorkerContext(new HapiWorkerContext(myRefImplCtx, myValidationSupport)); val.registerValidatorModule(module); ValidationResult result = val.validateWithResult(myRefImplCtx.newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(qa))); if (!result.isSuccessful()) { IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, myRefImplCtx.newJsonParser().encodeResourceToString(result.toOperationOutcome())); throw new UnprocessableEntityException(getContext(), oo); } }
/** * Fail the request by throwing an {@link UnprocessableEntityException} as a result of a validation failure. * Subclasses may change this behaviour by providing alternate behaviour. */ protected void fail(RequestDetails theRequestDetails, ValidationResult theValidationResult) { throw new UnprocessableEntityException(theRequestDetails.getServer().getFhirContext(), theValidationResult.toOperationOutcome()); }
/** * Validates a resource instance, throwing a {@link ValidationFailureException} if the validation fails * * @param theResource * The resource to validate * @throws ValidationFailureException * If the validation fails * @deprecated use {@link #validateWithResult(IBaseResource)} instead */ @Deprecated public void validate(IResource theResource) throws ValidationFailureException { applyDefaultValidators(); ValidationResult validationResult = validateWithResult(theResource); if (!validationResult.isSuccessful()) { throw new ValidationFailureException(myContext, validationResult.toOperationOutcome()); } }
public static void main(String[] args) { String input = "<Encounter xmlns=\"http://hl7.org/fhir\"></Encounter>"; // Create a new validator FhirContext ctx = FhirContext.forDstu3(); FhirValidator validator = ctx.newValidator(); // Did we succeed? ValidationResult result = validator.validateWithResult(input); System.out.println("Success: " + result.isSuccessful()); // What was the result OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome(); IParser parser = ctx.newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(outcome)); } }
@Override public void validateRequest(FhirContext context, Object payload, Map<String, Object> parameters) { Bundle transactionBundle = (Bundle) payload; validateTransactionBundle(transactionBundle); validateBundleConsistency(transactionBundle); for (Bundle.BundleEntryComponent entry : transactionBundle.getEntry()) { Class<? extends IBaseResource> clazz = entry.getResource().getClass(); if (VALIDATORS.containsKey(clazz)) { FhirValidator validator = context.newValidator(); validator.registerValidatorModule(VALIDATORS.get(clazz)); ValidationResult validationResult = validator.validateWithResult(entry.getResource()); if (!validationResult.isSuccessful()) { IBaseOperationOutcome operationOutcome = validationResult.toOperationOutcome(); throw FhirUtils.exception(UnprocessableEntityException::new, operationOutcome, "Validation Failed"); } } } }
@Override public void validateRequest(FhirContext context, Object payload, Map<String, Object> parameters) { Bundle transactionBundle = (Bundle) payload; validateTransactionBundle(transactionBundle); validateBundleConsistency(transactionBundle); for (Bundle.BundleEntryComponent entry : transactionBundle.getEntry()) { Class<? extends IBaseResource> clazz = entry.getResource().getClass(); if (VALIDATORS.containsKey(clazz)) { FhirValidator validator = context.newValidator(); validator.registerValidatorModule(VALIDATORS.get(clazz)); ValidationResult validationResult = validator.validateWithResult(entry.getResource()); if (!validationResult.isSuccessful()) { IBaseOperationOutcome operationOutcome = validationResult.toOperationOutcome(); throw FhirUtils.exception(UnprocessableEntityException::new, operationOutcome, "Validation Failed"); } } } }
@Override public void validateRequest(FhirContext context, Object payload, Map<String, Object> parameters) { Bundle transactionBundle = (Bundle) payload; validateTransactionBundle(transactionBundle); validateBundleConsistency(transactionBundle); for (Bundle.BundleEntryComponent entry : transactionBundle.getEntry()) { Class<? extends IBaseResource> clazz = entry.getResource().getClass(); if (VALIDATORS.containsKey(clazz)) { ca.uhn.fhir.validation.FhirValidator validator = context.newValidator(); validator.registerValidatorModule(VALIDATORS.get(clazz)); ValidationResult validationResult = validator.validateWithResult(entry.getResource()); if (!validationResult.isSuccessful()) { IBaseOperationOutcome operationOutcome = validationResult.toOperationOutcome(); throw FhirUtils.exception(UnprocessableEntityException::new, operationOutcome, "Validation Failed"); } } } }
public static void main(String[] args) { // Create an incomplete encounter (status is required) Encounter enc = new Encounter(); enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345"); // Create a new validator FhirContext ctx = FhirContext.forDstu3(); FhirValidator validator = ctx.newValidator(); // Did we succeed? ValidationResult result = validator.validateWithResult(enc); System.out.println("Success: " + result.isSuccessful()); // What was the result OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome(); IParser parser = ctx.newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(outcome)); } }
public static void main(String[] args) { // Create an incomplete encounter (status is required) Encounter enc = new Encounter(); enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345"); // Create a new validator FhirValidator validator = FhirContext.forDstu3().newValidator(); // Cache this object! Supplies structure definitions DefaultProfileValidationSupport support = new DefaultProfileValidationSupport(); // Create the validator FhirInstanceValidator module = new FhirInstanceValidator(support); validator.registerValidatorModule(module); // Did we succeed? IParser parser = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true); System.out.println(parser.encodeResourceToString(validator.validateWithResult(enc).toOperationOutcome())); } }