Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The binding strength is not considered when validating resources against a profile #6422

Open
codeforgreen opened this issue Oct 30, 2024 · 0 comments · May be fixed by #6423
Open

The binding strength is not considered when validating resources against a profile #6422

codeforgreen opened this issue Oct 30, 2024 · 0 comments · May be fixed by #6423

Comments

@codeforgreen
Copy link
Collaborator

codeforgreen commented Oct 30, 2024

Describe the bug
The changes in #6360 introduced a bug because the issue detail code for Remote Terminology $validate-code calls was set to always be invalid-code.

The org.hl7.fhir.core, more specifically org.hl7.fhir.validation library expects invalid-code to be used only for CodeSystem $validate-code and is expecting to see codes like not-in-vs for ValueSet $validate-code in cases when a code is not found in an existing ValueSet. This happens in org.hl7.fhir.validation.instance.InstanceValidator#processTxIssues.
When trying to use a profile where a binding for an element against a ValueSet is extensible, the validate operation will return an error which is not expected in this case because the code does exist in the extended profile binding.

See: https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java#L1718

To Reproduce
Steps to reproduce the behaviour:

  1. Create a custom profile for Encounter resources and store it to a hapi-fhir repository:
    profile-encounter.json
  2. Setup a hapi-fhir client with a validator that includes an instance of RemoteTerminologyValidationSupportService with https://r4.ontoserver.csiro.au/fhir/.

e.g.

String remoteTerminologyServerUrl = "https://r4.ontoserver.csiro.au/fhir/";
FhirContext fhirCtx = FhirContext.forR4Cached();

FhirInstanceValidator fhirInstanceValidator = new FhirInstanceValidator(fhirCtx);
ValidationSupportChain validationSupport = new ValidationSupportChain(
	new DefaultProfileValidationSupport(fhirCtx),
	new RemoteTerminologyValidationSupportService(fhirCtx, remoteTerminologyServerUrl);
);

validator.setValidationSupport(validationSupport);
FhirValidator fhirValidator = fhirCtx.newValidator();
fhirValidator.registerValidatorModule(fhirInstanceValidator);
  1. Create an encounter resource instance with an identifier that should be valid according to the profile.
    e.g.
Encounter encounter = new Encounter();
encounter.getMeta().addProfile("http://example.ca/fhir/StructureDefinition/profile-encounter");
encounter.setStatus(Encounter.EncounterStatus.PLANNED);
encounter.addIdentifier()
	.getType().addCoding()
	.setSystem("http://terminology.hl7.org/CodeSystem/v2-0203")
	.setCode("VN")
	.setDisplay("Visit number");
  1. Validate the resource (runtime resource, no need to store it in the hapi-fhir repository) and check the errors which relate to code VN
IGenericClient fhirClient = fhirCtx.newRestfulGenericClient("http://localhost:8000");

MethodOutcome resultProcedure = fhirClient.validate().resource(theResource).execute();
OperationOutcome operationOutcome = (OperationOutcome) resultProcedure.getOperationOutcome();
String output = fhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(operationOutcome);
  1. You will notice the following issue with severity error:
    The provided code 'http://terminology.hl7.org/CodeSystem/v2-0203#VN' was not found in the value set 'http://hl7.org/fhir/ValueSet/identifier-type|5.0.0-ballot'

Expected behaviour
No error should be returned since the profile http://hl7.org/fhir/StructureDefinition/Identifier which is in the hierarchy states that element Identifier.type has an extensible binding and the code VN exists in CodeSystem http://terminology.hl7.org/CodeSystem/v2-0203 which is the extended binding in the profile created at step 1.

Environment (please complete the following information):

  • HAPI FHIR Version 7.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant