0

I am trying to write validation by using HAPi validation.

 FhirContext fhirContext = FhirContext.forR4();
    FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
    FhirValidator validator = fhirContext.newValidator();

    validator.registerValidatorModule(instanceValidator);
    ValidationResult result = validator.validateWithResult(requestPayload);

Even if I use standard FHIR Patient structure definition , the validation fails.

However if I remove the FHIRInstanceValidator registry code, the validation works fine and returns true.

Where am I going wrong, when is FHIRInstanceValidator actually used?

  • From the HAPI docs (http://hapifhir.io/doc_validation.html), is says "To execute the validator, you simply create an instance of FhirInstanceValidator and register it to new validator, as shown in the example below. ", so sounds to me like it is mandatory? You can go through the link above to see all the various validations and some examples for each type of validation. – BlessedHIT Dec 12 '19 at 16:52

1 Answers1

0

See my answer here Hapi Resource Validator Unable to validate the Observation resource.

It depends on the version of HAPI FHIR that you're using. In later versions, the Schematron validation has been deprecated and the InstanceValidator is the recommended validator to be used.