use of org.hl7.fhir.r4b.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());
}
use of org.hl7.fhir.r4b.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());
}
use of org.hl7.fhir.r4b.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));
}
use of org.hl7.fhir.r4b.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");
}
use of org.hl7.fhir.r4b.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");
}
Aggregations