@Test
  public void testSchematronResourceValidator() throws IOException {
    String res =
        IOUtils.toString(
            getClass().getClassLoader().getResourceAsStream("patient-example-dicom.json"));
    Patient p = ourCtx.newJsonParser().parseResource(Patient.class, res);

    FhirValidator val = ourCtx.newValidator();
    val.setValidateAgainstStandardSchema(false);
    val.setValidateAgainstStandardSchematron(true);

    ValidationResult validationResult = val.validateWithResult(p);
    assertTrue(validationResult.isSuccessful());

    p.getTelecomFirstRep().setValue("123-4567");
    validationResult = val.validateWithResult(p);
    assertFalse(validationResult.isSuccessful());
    OperationOutcome operationOutcome = (OperationOutcome) validationResult.toOperationOutcome();
    ourLog.info(
        ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
    assertEquals(1, operationOutcome.getIssue().size());
    assertThat(operationOutcome.getIssueFirstRep().getDiagnostics(), containsString("cpt-2:"));

    p.getTelecomFirstRep().setSystem(ContactPointSystemEnum.EMAIL);
    validationResult = val.validateWithResult(p);
    assertTrue(validationResult.isSuccessful());
  }
  @SuppressWarnings("deprecation")
  @Test
  public void testSchemaResourceValidator() throws IOException {
    String res =
        IOUtils.toString(
            getClass().getClassLoader().getResourceAsStream("patient-example-dicom.json"));
    Patient p = ourCtx.newJsonParser().parseResource(Patient.class, res);

    ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p));

    FhirValidator val = ourCtx.newValidator();
    val.setValidateAgainstStandardSchema(true);
    val.setValidateAgainstStandardSchematron(false);

    val.validate(p);

    p.getAnimal().getBreed().setText("The Breed");
    try {
      val.validate(p);
      fail();
    } catch (ValidationFailureException e) {
      OperationOutcome operationOutcome = (OperationOutcome) e.getOperationOutcome();
      ourLog.info(
          ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
      assertEquals(1, operationOutcome.getIssue().size());
      assertThat(
          operationOutcome.getIssueFirstRep().getDetailsElement().getValue(),
          containsString("cvc-complex-type"));
    }
  }
  private FhirValidator createFhirValidator() {

    AllergyIntolerance allergy = new AllergyIntolerance();
    allergy.getSubstance().addCoding().setCode("some substance");

    FhirValidator val = ourCtx.newValidator();
    val.setValidateAgainstStandardSchema(true);
    val.setValidateAgainstStandardSchematron(true);
    return val;
  }