Search in sources :

Example 16 with ValidationOptions

use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContextTests method testValidateCodingWithServer.

@Test
public void testValidateCodingWithServer() throws IOException {
    ValidationOptions validationOptions = new ValidationOptions().guessSystem().setVersionFlexible(false).noClient();
    ValueSet valueSet = new ValueSet();
    Coding coding = new Coding();
    Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, coding, valueSet);
    Mockito.doReturn(pIn).when(context).constructParameters(validationOptions, coding);
    Mockito.doReturn(expectedValidationResult).when(context).validateOnServer(valueSet, pIn, validationOptions);
    ValidationContextCarrier ctxt = mock(ValidationContextCarrier.class);
    IWorkerContext.ValidationResult actualValidationResult = context.validateCode(validationOptions, coding, valueSet, ctxt);
    assertEquals(expectedValidationResult, actualValidationResult);
    Mockito.verify(valueSetCheckerSimple, times(0)).validateCode(coding);
    Mockito.verify(terminologyCache).getValidation(cacheToken);
    Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, true);
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) ValidationContextCarrier(org.hl7.fhir.r5.utils.validation.ValidationContextCarrier) ValidationOptions(org.hl7.fhir.utilities.validation.ValidationOptions) ValueSet(org.hl7.fhir.r5.model.ValueSet) Test(org.junit.jupiter.api.Test)

Example 17 with ValidationOptions

use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContextTests method testValidateCodingWithCache.

@Test
public void testValidateCodingWithCache() throws IOException {
    ValidationOptions validationOptions = new ValidationOptions().guessSystem().setVersionFlexible(false);
    ValueSet valueSet = new ValueSet();
    Coding coding = new Coding();
    Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, coding, valueSet);
    Mockito.doReturn(expectedValidationResult).when(terminologyCache).getValidation(cacheToken);
    ValidationContextCarrier ctxt = mock(ValidationContextCarrier.class);
    IWorkerContext.ValidationResult actualValidationResult = context.validateCode(validationOptions, coding, valueSet, ctxt);
    assertEquals(expectedValidationResult, actualValidationResult);
    Mockito.verify(valueSetCheckerSimple, times(0)).validateCode(coding);
    Mockito.verify(terminologyCache).getValidation(cacheToken);
    Mockito.verify(terminologyCache, times(0)).cacheValidation(any(), any(), anyBoolean());
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) ValidationContextCarrier(org.hl7.fhir.r5.utils.validation.ValidationContextCarrier) ValidationOptions(org.hl7.fhir.utilities.validation.ValidationOptions) ValueSet(org.hl7.fhir.r5.model.ValueSet) Test(org.junit.jupiter.api.Test)

Example 18 with ValidationOptions

use of org.hl7.fhir.utilities.validation.ValidationOptions in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContextTests method testValidateCodableConceptWithServer.

@Test
public void testValidateCodableConceptWithServer() throws IOException {
    CodeableConcept codeableConcept = new CodeableConcept();
    ValueSet valueSet = new ValueSet();
    ValidationOptions validationOptions = CacheTestUtils.validationOptions.noClient();
    Mockito.doReturn(pIn).when(context).constructParameters(validationOptions, codeableConcept);
    Mockito.doReturn(expectedValidationResult).when(context).validateOnServer(valueSet, pIn, validationOptions);
    Mockito.doReturn(cacheToken).when(terminologyCache).generateValidationToken(validationOptions, codeableConcept, valueSet);
    IWorkerContext.ValidationResult validationResultB = context.validateCode(validationOptions, codeableConcept, valueSet);
    assertEquals(expectedValidationResult, validationResultB);
    Mockito.verify(valueSetCheckerSimple, times(0)).validateCode(codeableConcept);
    Mockito.verify(terminologyCache).cacheValidation(cacheToken, expectedValidationResult, true);
    Mockito.verify(context).validateOnServer(valueSet, pIn, validationOptions);
}
Also used : ValidationOptions(org.hl7.fhir.utilities.validation.ValidationOptions) ValueSet(org.hl7.fhir.r5.model.ValueSet) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Example 19 with ValidationOptions

use of org.hl7.fhir.utilities.validation.ValidationOptions in project dpc-app by CMSgov.

the class OrganizationValidationTest method testAddress.

@Test
void testAddress() {
    final Organization organization = generateFakeOrganization();
    organization.addIdentifier().setSystem(DPCIdentifierSystem.NPPES.getSystem()).setValue("test-value");
    final ValidationResult result = fhirValidator.validateWithResult(organization, new ValidationOptions().addProfile(OrganizationProfile.PROFILE_URI));
    assertAll(() -> assertFalse(result.isSuccessful(), "Should have failed validation"), () -> assertEquals(1, result.getMessages().size(), "Should have a single failure"));
    // Add a text based Address
    organization.addAddress().setText("7500 Security Blvd").setType(Address.AddressType.PHYSICAL).setUse(Address.AddressUse.HOME);
    final ValidationResult r2 = fhirValidator.validateWithResult(organization, new ValidationOptions().addProfile(OrganizationProfile.PROFILE_URI));
    assertAll(() -> assertFalse(r2.isSuccessful(), "Should have failed validation"), () -> assertEquals(6, r2.getMessages().size(), "Should have multiple address failures"));
    // Add valid address
    organization.setAddress(Collections.singletonList(generateFakeAddress()));
    final ValidationResult r3 = fhirValidator.validateWithResult(organization, new ValidationOptions().addProfile(OrganizationProfile.PROFILE_URI));
    assertTrue(r3.isSuccessful(), "Should have passed");
}
Also used : OrganizationFactory.generateFakeOrganization(gov.cms.dpc.testing.factories.OrganizationFactory.generateFakeOrganization) Organization(org.hl7.fhir.dstu3.model.Organization) ValidationResult(ca.uhn.fhir.validation.ValidationResult) ValidationOptions(ca.uhn.fhir.validation.ValidationOptions) Test(org.junit.jupiter.api.Test)

Example 20 with ValidationOptions

use of org.hl7.fhir.utilities.validation.ValidationOptions in project dpc-app by CMSgov.

the class OrganizationValidationTest method testIdentifier.

@Test
void testIdentifier() {
    final Organization organization = generateFakeOrganization();
    organization.addAddress(generateFakeAddress());
    final ValidationResult result = fhirValidator.validateWithResult(organization, new ValidationOptions().addProfile(OrganizationProfile.PROFILE_URI));
    assertAll(() -> assertFalse(result.isSuccessful(), "Should have failed validation"), () -> assertEquals(1, result.getMessages().size(), "Should have a single failure"));
    organization.addIdentifier().setSystem(DPCIdentifierSystem.MBI.getSystem()).setValue("test-mbi-value");
    final ValidationResult r2 = fhirValidator.validateWithResult(organization, new ValidationOptions().addProfile(OrganizationProfile.PROFILE_URI));
    assertAll(() -> assertFalse(r2.isSuccessful(), "Should have failed validation"), () -> assertEquals(2, r2.getMessages().size(), "Should have two failures for ID"));
    // Add correct NPI
    organization.addIdentifier().setSystem(DPCIdentifierSystem.NPPES.getSystem()).setValue("test-value");
    final ValidationResult r3 = fhirValidator.validateWithResult(organization, new ValidationOptions().addProfile(OrganizationProfile.PROFILE_URI));
    assertTrue(r3.isSuccessful(), "Should have passed");
}
Also used : OrganizationFactory.generateFakeOrganization(gov.cms.dpc.testing.factories.OrganizationFactory.generateFakeOrganization) Organization(org.hl7.fhir.dstu3.model.Organization) ValidationResult(ca.uhn.fhir.validation.ValidationResult) ValidationOptions(ca.uhn.fhir.validation.ValidationOptions) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)15 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 FileNotFoundException (java.io.FileNotFoundException)8 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)8 Parameters (org.hl7.fhir.r5.model.Parameters)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 ValidationOptions (org.hl7.fhir.utilities.validation.ValidationOptions)7 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)6 Test (org.junit.jupiter.api.Test)6 Coding (org.hl7.fhir.r5.model.Coding)5 ValidationOptions (ca.uhn.fhir.validation.ValidationOptions)4 Parameters (org.hl7.fhir.r4b.model.Parameters)4 ValidationContextCarrier (org.hl7.fhir.r5.utils.validation.ValidationContextCarrier)4 ValidationResult (ca.uhn.fhir.validation.ValidationResult)3 ValueSetCheckerSimple (org.hl7.fhir.r4b.terminologies.ValueSetCheckerSimple)3 OrganizationFactory.generateFakeOrganization (gov.cms.dpc.testing.factories.OrganizationFactory.generateFakeOrganization)2 HashSet (java.util.HashSet)2 Organization (org.hl7.fhir.dstu3.model.Organization)2 CacheToken (org.hl7.fhir.r4.context.TerminologyCache.CacheToken)2