use of ca.uhn.fhir.validation.FhirValidator 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 ca.uhn.fhir.validation.FhirValidator in project synthea by synthetichealth.
the class HospitalExporterTestDstu2 method testFHIRExport.
@Test
public void testFHIRExport() throws Exception {
FhirContext ctx = FhirDstu2.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_dstu2.export", "true");
Config.set("exporter.fhir.transaction_bundle", "true");
// set this manually, in case it has already been loaded.
FhirDstu2.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);
HospitalExporterDstu2.export(0L);
File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir_dstu2").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());
}
Aggregations