-
Notifications
You must be signed in to change notification settings - Fork 17
[DPC-5384] Me/dpc 5384 dw upgrade #3004
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
base: main
Are you sure you want to change the base?
Changes from all commits
6129a37
95c2974
e5e4858
e94dc22
c49a07d
7a864d0
ab314b3
c665ad2
1c51a66
7acc265
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ static Stream<Arguments> downloadArgs() { | |
| @ParameterizedTest | ||
| @MethodSource("downloadArgs") | ||
| void canDownloadFiles(boolean compressFile, Map<String, String> requestHeaders) throws IOException { | ||
| String testData = "test data".repeat(500); | ||
| String testData = "test data".repeat(50); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @MEspositoE14s, instead of using |
||
| String fileName = createTestExport(testData, compressFile); | ||
|
|
||
| try (ClassicHttpResponse response = downloadExport(fileName, requestHeaders)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,27 +3,40 @@ | |
| import ca.uhn.fhir.context.FhirContext; | ||
| import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; | ||
| import ca.uhn.fhir.validation.FhirValidator; | ||
| import ca.uhn.fhir.validation.ValidationOptions; | ||
| import com.google.inject.AbstractModule; | ||
| import com.google.inject.Provides; | ||
| import com.google.inject.Scopes; | ||
| import com.google.inject.TypeLiteral; | ||
| import com.google.inject.multibindings.Multibinder; | ||
| import gov.cms.dpc.fhir.DPCIdentifierSystem; | ||
| import gov.cms.dpc.fhir.configuration.DPCFHIRConfiguration.FHIRValidationConfiguration; | ||
| import gov.cms.dpc.fhir.validations.DPCProfileSupport; | ||
| import gov.cms.dpc.fhir.validations.ProfileValidator; | ||
| import gov.cms.dpc.fhir.validations.profiles.PatientProfile; | ||
| import io.dropwizard.jersey.validation.Validators; | ||
| import jakarta.inject.Singleton; | ||
| import jakarta.validation.ConstraintValidator; | ||
| import jakarta.validation.ConstraintValidatorFactory; | ||
| import jakarta.validation.Validator; | ||
| import jakarta.validation.ValidatorFactory; | ||
| import org.glassfish.jersey.server.internal.inject.ConfiguredValidator; | ||
| import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; | ||
| import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; | ||
| import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; | ||
| import org.hl7.fhir.dstu3.model.Enumerations; | ||
| import org.hl7.fhir.dstu3.model.Patient; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.sql.Date; | ||
|
|
||
|
|
||
| /** | ||
| * Guice module for setting up the required Validation components, if requested by the application | ||
| */ | ||
| public class FHIRValidationModule extends AbstractModule { | ||
| private static final Logger logger = LoggerFactory.getLogger(FHIRValidationModule.class); | ||
|
|
||
| private final FHIRValidationConfiguration config; | ||
|
|
||
|
|
@@ -41,11 +54,9 @@ protected void configure() { | |
| constraintBinder.addBinding().to(ProfileValidator.class); | ||
|
|
||
| bind(ConstraintValidatorFactory.class).to(InjectingConstraintValidatorFactory.class); | ||
| bind(ValidatorFactory.class).toProvider(ValidatorFactoryProvider.class); | ||
| bind(ConfiguredValidator.class).to(InjectingConfiguredValidator.class); | ||
|
|
||
| bind(DPCProfileSupport.class).in(Scopes.SINGLETON); | ||
| bind(FhirValidator.class).toProvider(FHIRValidatorProvider.class); | ||
|
Comment on lines
-44
to
-48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come we no longer need |
||
| } | ||
|
|
||
| @Provides | ||
|
|
@@ -58,6 +69,14 @@ Validator provideValidator(ValidatorFactory factory) { | |
| return factory.getValidator(); | ||
| } | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| ValidatorFactory provideValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) { | ||
| return Validators.newConfiguration() | ||
| .constraintValidatorFactory(constraintValidatorFactory) | ||
| .buildValidatorFactory(); | ||
| } | ||
|
|
||
| @Provides | ||
| ValidationSupportChain provideSupportChain(DPCProfileSupport dpcModule) { | ||
| FhirContext ctx = FhirContext.forDstu3(); | ||
|
|
@@ -66,4 +85,39 @@ ValidationSupportChain provideSupportChain(DPCProfileSupport dpcModule) { | |
| new DefaultProfileValidationSupport(ctx), | ||
| new InMemoryTerminologyServerValidationSupport(ctx)); | ||
| } | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| public FhirValidator provideFhirValidator(FhirContext ctx, | ||
| ValidationSupportChain supportChain) { | ||
| final FhirValidator fhirValidator = ctx.newValidator(); | ||
| final FhirInstanceValidator instanceValidator = new FhirInstanceValidator(supportChain); | ||
|
|
||
| fhirValidator.registerValidatorModule(instanceValidator); | ||
| primeValidator(fhirValidator); | ||
|
|
||
| return fhirValidator; | ||
| } | ||
|
|
||
| /** | ||
| * Helper method that primes the Validator cache by creating a dummy patient and validating it. | ||
| * This is really dumb, but it avoids issues where the tests timeout when running in CI. | ||
| * Is necessary in order to address DPC-608 | ||
| * <p> | ||
| * We may need to add more resources here in the future, if things continue to be slow. | ||
| * | ||
| * @param validator - {@link FhirValidator} validator to prime | ||
| */ | ||
| private void primeValidator(FhirValidator validator) { | ||
| logger.trace("Validating dummy patient"); | ||
| final Patient patient = new Patient(); | ||
| patient.addName().addGiven("Dummy").setFamily("Patient"); | ||
| patient.addIdentifier().setSystem(DPCIdentifierSystem.MBI.getSystem()).setValue("test-mbi"); | ||
| patient.setGender(Enumerations.AdministrativeGender.MALE); | ||
| patient.setBirthDate(Date.valueOf("1990-01-01")); | ||
|
|
||
| final ValidationOptions op = new ValidationOptions(); | ||
| op.addProfile(PatientProfile.PROFILE_URI); | ||
| validator.validateWithResult(patient, op); | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package gov.cms.dpc.fhir.validations.dropwizard; | ||
|
|
||
| import ca.uhn.fhir.context.FhirContext; | ||
| import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; | ||
| import ca.uhn.fhir.validation.FhirValidator; | ||
| import gov.cms.dpc.fhir.configuration.DPCFHIRConfiguration; | ||
| import jakarta.validation.ConstraintValidatorFactory; | ||
| import jakarta.validation.ValidatorFactory; | ||
| import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; | ||
| import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| class FHIRValidationModuleUnitTest { | ||
| private final DPCFHIRConfiguration.FHIRValidationConfiguration config = mock(DPCFHIRConfiguration.FHIRValidationConfiguration.class); | ||
| private final ConstraintValidatorFactory cvf = mock(ConstraintValidatorFactory.class); | ||
| private final FHIRValidationModule validationModule = new FHIRValidationModule(config); | ||
|
|
||
| @Test | ||
| void createsValidatorFactory() { | ||
| ValidatorFactory factory = validationModule.provideValidatorFactory(cvf); | ||
| assertInstanceOf(ValidatorFactory.class, factory); | ||
| } | ||
|
|
||
| @Test | ||
| void createsValidator() { | ||
| FhirContext ctx = FhirContext.forDstu3(); | ||
| ValidationSupportChain chain = new ValidationSupportChain( | ||
| new DefaultProfileValidationSupport(ctx), | ||
| new InMemoryTerminologyServerValidationSupport(ctx)); | ||
|
|
||
| FhirValidator validator = validationModule.provideFhirValidator(ctx, chain); | ||
| assertInstanceOf(FhirValidator.class, validator); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reduced this because the test is still occasionally failing due to resource limitations.