Search in sources :

Example 46 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project synthea by synthetichealth.

the class HospitalExporterTestR4 method testFHIRExport.

@Test
public void testFHIRExport() throws Exception {
    FhirContext ctx = FhirR4.getContext();
    FhirValidator validator = ctx.newValidator();
    validator.setValidateAgainstStandardSchema(true);
    validator.setValidateAgainstStandardSchematron(true);
    File tempOutputFolder = tempFolder.newFolder();
    Config.set("exporter.baseDirectory", tempOutputFolder.toString());
    Config.set("exporter.hospital.fhir.export", "true");
    Config.set("exporter.fhir.transaction_bundle", "true");
    // set this manually, in case it has already been loaded.
    FhirR4.TRANSACTION_BUNDLE = true;
    TestHelper.loadTestProperties();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Location location = new Location(Generator.DEFAULT_STATE, null);
    Provider.clear();
    Provider.loadProviders(location, ProviderTest.providerRandom);
    assertNotNull(Provider.getProviderList());
    assertFalse(Provider.getProviderList().isEmpty());
    Provider.getProviderList().get(0).incrementEncounters(EncounterType.WELLNESS, 0);
    HospitalExporterR4.export(new DefaultRandomNumberGenerator(0L), 0L);
    File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir").toFile();
    assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
    File expectedExportFile = expectedExportFolder.toPath().resolve("hospitalInformation0.json").toFile();
    assertTrue(expectedExportFile.exists() && expectedExportFile.isFile());
    FileReader fileReader = new FileReader(expectedExportFile.getPath());
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    StringBuilder fhirJson = new StringBuilder();
    String line = null;
    while ((line = bufferedReader.readLine()) != null) {
        fhirJson.append(line);
    }
    bufferedReader.close();
    IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson.toString());
    ValidationResult result = validator.validateWithResult(resource);
    if (result.isSuccessful() == false) {
        for (SingleValidationMessage message : result.getMessages()) {
            System.out.println(message.getSeverity().toString() + ": " + message.getMessage());
        }
    }
    assertTrue(result.isSuccessful());
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) SingleValidationMessage(ca.uhn.fhir.validation.SingleValidationMessage) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FhirValidator(ca.uhn.fhir.validation.FhirValidator) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValidationResult(ca.uhn.fhir.validation.ValidationResult) File(java.io.File) Location(org.mitre.synthea.world.geography.Location) Test(org.junit.Test) ProviderTest(org.mitre.synthea.world.agents.ProviderTest)

Example 47 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project synthea by synthetichealth.

the class HospitalExporterTestStu3 method testFHIRExport.

@Test
public void testFHIRExport() throws Exception {
    FhirContext ctx = FhirStu3.getContext();
    FhirValidator validator = ctx.newValidator();
    validator.setValidateAgainstStandardSchema(true);
    validator.setValidateAgainstStandardSchematron(true);
    File tempOutputFolder = tempFolder.newFolder();
    Config.set("exporter.baseDirectory", tempOutputFolder.toString());
    Config.set("exporter.hospital.fhir_stu3.export", "true");
    Config.set("exporter.fhir.transaction_bundle", "true");
    // set this manually, in case it has already been loaded.
    FhirStu3.TRANSACTION_BUNDLE = true;
    TestHelper.loadTestProperties();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Location location = new Location(Generator.DEFAULT_STATE, null);
    Provider.clear();
    Provider.loadProviders(location, ProviderTest.providerRandom);
    assertNotNull(Provider.getProviderList());
    assertFalse(Provider.getProviderList().isEmpty());
    Provider.getProviderList().get(0).incrementEncounters(EncounterType.WELLNESS, 0);
    HospitalExporterStu3.export(0L);
    File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir_stu3").toFile();
    assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
    File expectedExportFile = expectedExportFolder.toPath().resolve("hospitalInformation0.json").toFile();
    assertTrue(expectedExportFile.exists() && expectedExportFile.isFile());
    FileReader fileReader = new FileReader(expectedExportFile.getPath());
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    StringBuilder fhirJson = new StringBuilder();
    String line = null;
    while ((line = bufferedReader.readLine()) != null) {
        fhirJson.append(line);
    }
    bufferedReader.close();
    IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson.toString());
    ValidationResult result = validator.validateWithResult(resource);
    if (result.isSuccessful() == false) {
        for (SingleValidationMessage message : result.getMessages()) {
            System.out.println(message.getSeverity().toString() + ": " + message.getMessage());
        }
    }
    assertTrue(result.isSuccessful());
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) SingleValidationMessage(ca.uhn.fhir.validation.SingleValidationMessage) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FhirValidator(ca.uhn.fhir.validation.FhirValidator) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValidationResult(ca.uhn.fhir.validation.ValidationResult) File(java.io.File) Location(org.mitre.synthea.world.geography.Location) Test(org.junit.Test) ProviderTest(org.mitre.synthea.world.agents.ProviderTest)

Example 48 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project dpc-app by CMSgov.

the class CapabilitiesTest method capabilitiesIsValid.

@Test
void capabilitiesIsValid() {
    final CapabilityStatement capabilities = Capabilities.getCapabilities("https://sandbox.dpc.cms.gov/api/v1");
    final ValidationResult validationResult = validator.validateWithResult(capabilities);
    assertTrue(validationResult.isSuccessful(), validationResultsToString(validationResult));
}
Also used : CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) ValidationResult(ca.uhn.fhir.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 49 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult 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)

Example 50 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project dpc-app by CMSgov.

the class PractitionerValidationTest method testHasIdentifier.

@Test
void testHasIdentifier() {
    final Practitioner practitioner = generateFakePractitioner();
    practitioner.addName().setFamily("Patient").addGiven("Test");
    final ValidationResult result = fhirValidator.validateWithResult(practitioner);
    assertAll(() -> assertFalse(result.isSuccessful(), "Should have failed validation"), () -> assertEquals(1, result.getMessages().size(), "Should have a single failure"));
    // Add an NPI
    practitioner.addIdentifier().setSystem(DPCIdentifierSystem.MBI.getSystem()).setValue("test-mbi");
    final ValidationResult r2 = fhirValidator.validateWithResult(practitioner);
    assertAll(() -> assertFalse(r2.isSuccessful(), "Should have failed validation"), () -> assertEquals(2, r2.getMessages().size(), "Should have two failures for ID slice"));
    practitioner.addIdentifier().setSystem(DPCIdentifierSystem.NPPES.getSystem()).setValue("test-npi");
    final ValidationResult r3 = fhirValidator.validateWithResult(practitioner);
    assertTrue(r3.isSuccessful(), "Should have passed");
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) ValidationResult(ca.uhn.fhir.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)32 IOException (java.io.IOException)22 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)17 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)15 FileNotFoundException (java.io.FileNotFoundException)14 ValidationResult (ca.uhn.fhir.validation.ValidationResult)12 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)12 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)10 ValidationResult (org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult)10 ArrayList (java.util.ArrayList)9 Coding (org.hl7.fhir.r5.model.Coding)9 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)7 ValidationResult (org.hl7.fhir.r4.context.IWorkerContext.ValidationResult)7 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)7 FHIRLexerException (org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)7