use of org.hl7.fhir.r4b.formats.IParser in project geoprism-registry by terraframe.
the class FhirImportTest method testBasicImport.
@Request
@Test
public void testBasicImport() throws InterruptedException {
try {
FhirExternalSystem system = createExternalSystem();
SynchronizationConfig config = createSyncConfig(system);
FhirSyncImportConfig iConfig = (FhirSyncImportConfig) config.buildConfiguration();
FhirResourceProcessor processor = FhirFactory.getProcessor(iConfig.getImplementation());
IParser parser = FhirContext.forR4().newJsonParser();
Bundle bundle = new Bundle();
bundle.addEntry(new BundleEntryComponent().setResource((Resource) parser.parseResource(this.getClass().getResourceAsStream("/fhir/organization.json"))));
bundle.addEntry(new BundleEntryComponent().setResource((Resource) parser.parseResource(this.getClass().getResourceAsStream("/fhir/location.json"))));
FhirResourceImporter importer = new FhirResourceImporter(new BasicFhirConnection(system), processor, null, null);
importer.synchronize(bundle);
ServerGeoObjectIF geoobject = new ServerGeoObjectService().getGeoObjectByCode("USATestDataHsTwo", "USATestDataHealthStop");
geoobject.setDate(new Date());
LocalizedValue displayLabel = geoobject.getDisplayLabel();
Assert.assertEquals("USATestDataHsTwo ZZZZZZZ", displayLabel.getValue());
} finally {
TestDataSet.deleteExternalSystems("FHIRImportTest");
}
}
use of org.hl7.fhir.r4b.formats.IParser in project redmatch by aehrc.
the class RedmatchApi method save.
private void save(Map<String, List<DomainResource>> grouped, Path tgtDir, ProgressReporter progressReporter, CancelChecker cancelToken) throws IOException {
try {
log.info("Saving to output folder " + tgtDir);
if (progressReporter != null) {
progressReporter.reportProgress(Progress.reportStart("Saving files"));
}
IParser jsonParser = ctx.newJsonParser();
double div = grouped.size() / 100.0;
int i = 0;
for (String key : grouped.keySet()) {
File f = new File(tgtDir.toFile(), key + ".ndjson");
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
for (DomainResource dr : grouped.get(key)) {
jsonParser.encodeResourceToWriter(dr, bw);
bw.newLine();
}
}
i++;
if (progressReporter != null) {
progressReporter.reportProgress(Progress.reportProgress((int) Math.floor(i / div)));
}
if (cancelToken != null && cancelToken.isCanceled()) {
return;
}
}
} finally {
if (progressReporter != null) {
progressReporter.reportProgress(Progress.reportEnd());
}
}
}
use of org.hl7.fhir.r4b.formats.IParser in project nia-patient-switching-standard-adaptor by NHSDigital.
the class SDSServiceTest method parseResponses.
@BeforeAll
public static void parseResponses() throws IOException {
FhirContext context = FhirContext.forDstu3();
context.newJsonParser();
context.setParserErrorHandler(new StrictErrorHandler());
IParser jsonParser = context.newJsonParser();
readResponsesFromFile();
ehrResponseBundle = jsonParser.parseResource(Bundle.class, sdsResponseEHRExtract);
copcResponseBundle = jsonParser.parseResource(Bundle.class, sdsResponseCopcMessage);
noResultsBundle = jsonParser.parseResource(Bundle.class, sdsResponseNoResults);
}
use of org.hl7.fhir.r4b.formats.IParser in project CRD by HL7-DaVinci.
the class CdsConnectFileStore method processFhirFiles.
private void processFhirFiles(List<CdsConnectFile> files, String topic) {
// process the fhir resource files
// setup the proper FHIR Context for the version of FHIR we are dealing with
FhirContext r4ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
IParser r4parser = r4ctx.newJsonParser();
// suppress the unknown element warnings
r4parser.setParserErrorHandler(new SuppressParserErrorHandler());
// process all of the files found within the topic/artifact
for (CdsConnectFile file : files) {
String path = file.getPath();
String filename = file.getFilename();
if (filename.endsWith(".json")) {
logger.info(" process: FHIR Resource: " + filename);
String[] parts = filename.split("-");
if (parts.length > 2) {
// String resourceType = parts[0];
String fhirVersion = parts[1];
String name = parts[2];
IBaseResource baseResource = null;
byte[] fileContents = file.getCqlBundle();
if (fhirVersion.equalsIgnoreCase("R4")) {
baseResource = r4parser.parseResource(new ByteArrayInputStream(fileContents));
}
processFhirResource(baseResource, path, filename, fhirVersion, topic);
}
}
}
}
use of org.hl7.fhir.r4b.formats.IParser in project CRD by HL7-DaVinci.
the class GitHubFileStore method processFhirFolder.
private void processFhirFolder(String topic, String fhirVersion, String fhirPath) {
fhirVersion = fhirVersion.toUpperCase();
logger.info(" GitHubFileStore::processFhirFolder(): " + fhirVersion + ": " + fhirPath);
// setup the proper FHIR Context for the version of FHIR we are dealing with
FhirContext ctx = null;
if (fhirVersion.equalsIgnoreCase("R4")) {
ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
} else {
logger.warn("unsupported FHIR version: " + fhirVersion + ", skipping folder");
return;
}
IParser parser = ctx.newJsonParser();
// suppress the unknown element warnings
parser.setParserErrorHandler(new SuppressParserErrorHandler());
for (String folder : connection.getDirectory(fhirPath)) {
if (folder.equalsIgnoreCase("resources")) {
String fullFolderPath = fhirPath + "/" + folder;
for (String resource : connection.getDirectory(fullFolderPath)) {
String filename = resource;
String fullFilePath = fullFolderPath + "/" + filename;
logger.info(" process: FHIR Resource: " + filename);
String[] parts = filename.split("-");
if (parts.length > 2) {
// = parts[0];
String resourceType;
if (!parts[1].equalsIgnoreCase(fhirVersion)) {
logger.warn("GitHubFileStore::processFhirFolder() warning: FhirVersion doesn't match!");
continue;
}
InputStream inputStream = connection.getFile(fullFilePath);
if (inputStream != null) {
IBaseResource baseResource = parser.parseResource(inputStream);
processFhirResource(baseResource, filename, filename, fhirVersion, topic);
} else {
logger.warn("could not find file: " + fullFilePath);
continue;
}
}
}
}
}
}
Aggregations