Validation of custom resource structures

75 views
Skip to first unread message

Poseidon

unread,
Oct 25, 2016, 4:58:15 AM10/25/16
to HAPI FHIR
Hello,

I've added a custom resource structure to my project, just as portrayed here: http://hapifhir.io/doc_custom_structures.html. Now when POSTing a new instance of this structure to my backend, the resource validation fails:

Validating failed:
* Location: null
* Severity: ERROR
* Message : cvc-elt.1: Deklaration des Elements 'FertilizationReport' kann nicht gefunden werden.
* Location: null
* Severity: FATAL
* Message : No profile found for resource type FertilizationReport

I tried adding Validation Support to my validator instance, but that does not seem to do the trick:

public class AHRValidationSupport implements IValidationSupport {


   
@Override
   
public ValueSet.ValueSetExpansionComponent expandValueSet(FhirContext theContext, ValueSet.ConceptSetComponent theInclude) {
       
return null;
   
}


   
@Override
   
public ValueSet fetchCodeSystem(FhirContext theContext, String theSystem) {
       
return null;
   
}


   
@Override
   
public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) {


       
System.out.println(theClass.getCanonicalName() + ", "+theUri);


       
if (theUri.equals("http://ahr.copa.inso.tuwien.ac.at/StructureDefinition/FertilizationReport") || theClass == FertilizationReport.class) {
           
System.out.println("Return new fert report");
           
return (T)(new FertilizationReport());
       
}


       
return null;
   
}


   
@Override
   
public boolean isCodeSystemSupported(FhirContext theContext, String theSystem) {
       
return false;
   
}


   
@Override
   
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
       
return null;
   
}
}

And in the spring config.

    @Bean
   
public FhirValidator fhirValidator() {


       
FhirValidator validator = fhirContext().newValidator();
        validator
.registerValidatorModule(new SchemaBaseValidator(fhirContext()));
       
FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
        validator
.registerValidatorModule(instanceValidator);


       
//Add validation support for ahr structures
       
ValidationSupportChain valSupport = new ValidationSupportChain(new DefaultProfileValidationSupport(),new AHRValidationSupport());
        instanceValidator
.setValidationSupport(valSupport);


       
return validator;
   
}

It seems like my AHRValidationSupport instance is not even executed once. Is there something wrong with my code? Is there any other way to enable validation for my resource?

Regards
Reply all
Reply to author
Forward
0 new messages