Search code examples
hl7-fhirhapi-fhirdstu2-fhir

Can't understand importance of Schema/Schematron Validator


I am validating resource through Schema/Schematron validator. I am providing invalid xml of patient resource to it, still it does not complain and giving output as 'Validation passed'.

As in below code snippet you can observe, I have given multiple gender and birthdate and one different tag from schema as dummytag. Also one gender tag has invalid value as 'male1':

FhirContext ctx = FhirContext.forDstu2();


 String msgString2 = "<Patient>\r\n" + 
 "        <gender value=\"male1\"/>\r\n" + 
 " <gender value=\"female\"/>\r\n" + 
 "        <birthDate>1953-12-20</birthDate>\r\n" + 
 " <birthDate>1953-12-20</birthDate>\r\n" + 
 " <dummytag>abcd</dummytag>\r\n" + 
 "</Patient>";

 IParser parser = ctx.newXmlParser();
 Patient patient = parser.parseResource(Patient.class, msgString2);

 FhirValidator val = ctx.newValidator();
 IValidatorModule module1 = new SchemaBaseValidator(ctx);
 IValidatorModule module2 = new SchematronBaseValidator(ctx);
 val.registerValidatorModule(module1);
 val.registerValidatorModule(module2);

 ValidationResult result = val.validateWithResult(patient);
 if (result.isSuccessful()) {

    System.out.println("Validation passed");

 } else {
    // We failed validation!
    System.out.println("Validation failed");
 }

So my question is can you please tell me, in which case it will print 'Validation failed'?

Regards, Amit.


Solution

  • Try it in DSTU3, which is around quite some time now, also bugfix to several XPath related issues.