use of org.hl7.fhir.r4b.formats.IParser in project synthea by synthetichealth.
the class ValidationSupportR4 method loadFromDirectory.
/**
* Loads the structure definitions from the given directory.
* @param rootDir the directory to load structure definitions from
* @return a list of structure definitions
* @throws Throwable when there is an error reading the structure definitions.
*/
private void loadFromDirectory(String rootDir) throws Throwable {
IParser jsonParser = FhirR4.getContext().newJsonParser();
jsonParser.setParserErrorHandler(new StrictErrorHandler());
URL profilesFolder = ClassLoader.getSystemClassLoader().getResource(rootDir);
Path path = Paths.get(profilesFolder.toURI());
Files.walk(path, Integer.MAX_VALUE).filter(Files::isReadable).filter(Files::isRegularFile).filter(p -> p.toString().endsWith(".json")).forEach(f -> {
try {
IBaseResource resource = jsonParser.parseResource(new FileReader(f.toFile()));
handleResource(resource);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
});
}
use of org.hl7.fhir.r4b.formats.IParser in project synthea by synthetichealth.
the class ValidationSupportSTU3 method loadFromDirectory.
/**
* Loads the structure definitions from the given directory.
* @param rootDir the directory to load structure definitions from
* @return a list of structure definitions
* @throws Throwable when there is an error reading the structure definitions.
*/
private void loadFromDirectory(String rootDir) throws Throwable {
IParser jsonParser = FhirStu3.getContext().newJsonParser();
jsonParser.setParserErrorHandler(new StrictErrorHandler());
URL profilesFolder = ClassLoader.getSystemClassLoader().getResource(rootDir);
Path path = Paths.get(profilesFolder.toURI());
Files.walk(path, Integer.MAX_VALUE).filter(Files::isReadable).filter(Files::isRegularFile).filter(p -> p.toString().endsWith(".json")).forEach(f -> {
try {
IBaseResource resource = jsonParser.parseResource(new FileReader(f.toFile()));
if (resource instanceof CodeSystem) {
this.addCodeSystem(resource);
} else if (resource instanceof ValueSet) {
// The PrePopulatedValidationSupport base class only supports
// R4 ValueSets so we don't validate these here
// ValueSet vs = (ValueSet) resource;
// this.addValueSet(vs);
} else if (resource instanceof StructureDefinition) {
this.addStructureDefinition(resource);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
});
}
use of org.hl7.fhir.r4b.formats.IParser in project synthea by synthetichealth.
the class FhirGroupExporterR4 method exportAndSave.
/**
* Export the current patient list as a FHIR Group resource and save it as a JSON file.
* @param stop The stop time.
*/
public static void exportAndSave(RandomNumberGenerator rand, long stop) {
if (Config.getAsBoolean("exporter.groups.fhir.export")) {
Group group = export(rand, stop);
// get output folder
List<String> folders = new ArrayList<>();
folders.add("fhir");
String baseDirectory = Config.get("exporter.baseDirectory");
File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
f.mkdirs();
Path outFilePath = null;
String groupJson = null;
if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
IParser parser = FhirR4.getContext().newJsonParser().setPrettyPrint(false);
groupJson = parser.encodeResourceToString(group);
String filename = group.getResourceType().toString() + ".ndjson";
outFilePath = f.toPath().resolve(filename);
} else {
IParser parser = FhirR4.getContext().newJsonParser().setPrettyPrint(true);
groupJson = parser.encodeResourceToString(group);
outFilePath = f.toPath().resolve("groupInformation" + stop + ".json");
}
try {
Files.write(outFilePath, Collections.singleton(groupJson), StandardOpenOption.CREATE_NEW);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.hl7.fhir.r4b.formats.IParser in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method TestDataRequirementsProcessor.
@Test
public void TestDataRequirementsProcessor() {
CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
cqlTranslatorOptions.getFormats().add(CqlTranslator.Format.JSON);
cqlTranslatorOptions.getOptions().add(CqlTranslatorOptions.Options.EnableAnnotations);
try {
/*
OpioidCDSCommon.cql
DataRequirements.cql
AdultOutpatientEncountersFHIR4.xml
AdvancedIllnessandFrailtyExclusionECQMFHIR4.xml
BCSComponent.xml
CCSComponent.xml
FHIRHelpers.xml
HBPComponent.xml
HospiceFHIR4.xml
MATGlobalCommonFunctionsFHIR4.xml
PVSComponent.xml
SupplementalDataElementsFHIR4.xml
TSCComponent.xml
BCSComponent-v0-0-001-FHIR-4-0-1.xml
CCSComponent-v0-0-001-FHIR-4-0-1.xml
HBPComponent-v0-0-001-FHIR-4-0-1.xml
PVSComponent-v0-0-001-FHIR-4-0-1.xml
TSCComponent-v0-0-001-FHIR-4-0-1.xml
PreventiveCareandWellness-v0-0-001-FHIR-4-0-1.xml
*/
// "OpioidCDS/cql/OpioidCDSCommon.cql", cqlTranslatorOptions);
CqlTranslator translator = createTranslator("CompositeMeasures/cql/EXM124-9.0.000.cql", cqlTranslatorOptions);
translator.toELM();
assertTrue(translator.getErrors().isEmpty());
libraryManager.cacheLibrary(translator.getTranslatedLibrary());
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translator.getTranslatedLibrary(), cqlTranslatorOptions, null, false);
assertTrue(moduleDefinitionLibrary.getType().getCode("http://terminology.hl7.org/CodeSystem/library-type").equalsIgnoreCase("module-definition"));
FhirContext context = getFhirContext();
IParser parser = context.newJsonParser();
String moduleDefString = parser.setPrettyPrint(true).encodeResourceToString(moduleDefinitionLibrary);
logger.debug(moduleDefString);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
use of org.hl7.fhir.r4b.formats.IParser in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method assertEqualToExpectedModuleDefinitionLibrary.
private void assertEqualToExpectedModuleDefinitionLibrary(org.hl7.fhir.r5.model.Library actualModuleDefinitionLibrary, String pathToExpectedModuleDefinitionLibrary) {
FhirContext context = getFhirContext();
IParser parser = context.newJsonParser();
org.hl7.fhir.r5.model.Library expectedModuleDefinitionLibrary = (org.hl7.fhir.r5.model.Library) parser.parseResource(DataRequirementsProcessorTest.class.getResourceAsStream(pathToExpectedModuleDefinitionLibrary));
assertNotNull(expectedModuleDefinitionLibrary);
actualModuleDefinitionLibrary.setDate(null);
expectedModuleDefinitionLibrary.setDate(null);
assertTrue(actualModuleDefinitionLibrary.equalsDeep(expectedModuleDefinitionLibrary));
}
Aggregations