Hello,
I’m using HAPI FHIR 4.2.0 with R4. I’m trying to validate a ServiceRequest resource with an occurenceTiming child. However, the Timing.repeat.periodUnit element always fails with this error:
The value provided ('wk') is not in the value set http://hl7.org/fhir/ValueSet/units-of-time|4.0.0
(http://hl7.org/fhir/ValueSet/units-of-time, and a code is required from this value set)
(error message = Unknown code[wk] in system[(none)]) -
ServiceRequest.occurrence.ofType(Timing).repeat.periodUnit
The weird thing about this is that the value “wk” is most certainly in the ValueSet units-of-time, which includes (s, min, h, d, wk, mo, and a). But after doing some hard-core debugging, I noticed that the code was not able to expand the valueset’s values. The actual code validation was happening in the method org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport#validateCode. While the value set name was in fact recognized as a valid valueset, the contents of that value were empty. Programmatically, that meant that:
new ValueSetExpanderSimple(new HapiWorkerContext(theContext, this)).expand(fetchValueSet(theContext, "http://hl7.org/fhir/ValueSet/units-of-time"), null).getValueset().getExpansion().getContains()
was an empty list. But when I tested this with other valuesets they worked just fine, expanding to the correct set of codes.
Is this a bug in the HAPI FHIR validation code? If so, it kind of defeats the purpose of validation… Could I have set up the validation wrong? Maybe there is some setting that I need to change? Here is the code that does the validation:
FhirValidator validator = ctx.newValidator();
validator.registerValidatorModule(new FhirInstanceValidator(new DefaultProfileValidationSupport()));
ValidationResult result = validator.validateWithResult(fhirResource);
if (!result.isSuccessful()) {
throw new RuntimeException("FHIR output is non-compliant: \n\t- "
+ result.getMessages().stream().map(m -> m.getMessage() + " - " + m.getLocationString())
.collect(Collectors.joining("\n\t- ")));
}
Any advice or ideas would be helpful!