-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef78b46
commit 99c5bc9
Showing
2 changed files
with
825 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
.../src/test/java/org/hl7/fhir/r4/validation/ConvertedStructureDefinitionValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.hl7.fhir.r4.validation; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.context.support.IValidationSupport; | ||
import ca.uhn.fhir.test.BaseTest; | ||
import ca.uhn.fhir.validation.FhirValidator; | ||
import ca.uhn.fhir.validation.ValidationResult; | ||
import org.hl7.fhir.common.hapi.validation.support.PrePopulatedValidationSupport; | ||
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; | ||
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; | ||
import org.hl7.fhir.r4.model.StructureDefinition; | ||
import org.hl7.fhir.r4.model.Extension; | ||
import org.hl7.fhir.r4.model.Patient; | ||
import org.hl7.fhir.r4.model.StringType; | ||
import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* See #6424 | ||
*/ | ||
public class ConvertedStructureDefinitionValidationTest extends BaseTest { | ||
|
||
private static final Logger ourLog = LoggerFactory.getLogger(ConvertedStructureDefinitionValidationTest.class); | ||
private final FhirContext myCtx = FhirContext.forR4Cached(); | ||
|
||
@Test | ||
public void test() throws Exception { | ||
|
||
PrePopulatedValidationSupport val = new PrePopulatedValidationSupport(myCtx); | ||
val.addStructureDefinition(loadResource(myCtx, StructureDefinition.class, "r4/extension-patient-citizenship.json")); | ||
|
||
IValidationSupport builtInValidationSupport = myCtx.getValidationSupport(); | ||
ValidationSupportChain validationSupport = new ValidationSupportChain(val, builtInValidationSupport); | ||
FhirInstanceValidator instanceValidator = new FhirInstanceValidator(validationSupport); | ||
instanceValidator.setBestPracticeWarningLevel(BestPracticeWarningLevel.Ignore); | ||
|
||
FhirValidator validator = myCtx.newValidator(); | ||
validator.registerValidatorModule(instanceValidator); | ||
|
||
Patient patient = new Patient(); | ||
patient.setActive(true); | ||
|
||
Extension citizenship = patient.addExtension(); | ||
citizenship.setUrl("http://hl7.org/fhir/StructureDefinition/patient-citizenship"); | ||
citizenship.addExtension("period", new StringType("NOT A PERIOD")); | ||
|
||
ValidationResult outcome = validator.validateWithResult(patient); | ||
ourLog.info(myCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.toOperationOutcome())); | ||
|
||
instanceValidator.invalidateCaches(); | ||
|
||
outcome = validator.validateWithResult(patient); | ||
ourLog.info(myCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.toOperationOutcome())); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.