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);
}
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());
}
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);
}
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");
}
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");
}
Aggregations