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

Validation with unknown profile #6608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public void testValidateStorageResponseCodeBad() {
List<SingleValidationMessage> all = logResultsAndReturnErrorOnes(result);
assertThat(result.isSuccessful()).as(all.toString()).isFalse();
assertThat(result.getMessages().get(0).getMessage()).startsWith("Unknown code 'https://hapifhir.io/fhir/CodeSystem/hapi-fhir-storage-response-code#foo'");

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.fhirpath.BaseValidationTestWithInlineMocks;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import ca.uhn.fhir.validation.ValidationOptions;
import ca.uhn.fhir.validation.ValidationResult;
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator;
import org.hl7.fhir.r4.model.MedicationRequest;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ParserWithValidationR4Test extends BaseValidationTestWithInlineMocks {
private static final FhirContext ourCtx = FhirContext.forR4();

Expand All @@ -30,6 +37,44 @@ public void testActivityDefinitionElementsOrder() throws IOException {
validationResult.getMessages().forEach(System.out::println);
}

// https://www.hl7.org/fhir/r4/resource-operation-validate.html
@Test
public void validate_withUnknownProfile_shouldFail() {
// setup
IParser parser = ourCtx.newJsonParser();
Patient patient;
{
String patientStr = """
{
"resourceType": "Patient",
"name": [{
"family": "Hirasawa",
"given": [ "yui" ]
}]
}
""";
patient = parser.parseResource(Patient.class, patientStr);
}

// test
ValidationOptions options = new ValidationOptions();
options.addProfile("http://tempuri.org/does-not-exist");

final FhirInstanceValidator instanceValidator = new FhirInstanceValidator(ourCtx);
FhirValidator validator = ourCtx.newValidator();

// test
validator.registerValidatorModule(instanceValidator);
ValidationResult validationResult = validator.validateWithResult(patient, options);

// verify
assertFalse(validationResult.isSuccessful());
assertTrue(validationResult.getMessages().stream()
.anyMatch(r -> r.getSeverity() == ResultSeverityEnum.ERROR));
// TODO - add validation for the specific error to be thrown
}


private IValidationSupport getValidationSupport() {
return new ValidationSupportChain(new DefaultProfileValidationSupport(ourCtx));
}
Expand Down
Loading