use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class CommonFileStore method processFhirFolder.
private void processFhirFolder(String topic, String fhirVersion, File fhirPath) {
fhirVersion = fhirVersion.toUpperCase();
logger.info(" CommonFileStore::processFhirFolder(): " + fhirVersion + ": " + fhirPath.getName());
// 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());
File[] directories = fhirPath.listFiles();
for (File folder : directories) {
if (folder.getName().equalsIgnoreCase("resources") && folder.isDirectory()) {
File[] resources = folder.listFiles();
for (File resource : resources) {
if (resource.isFile()) {
String filename = resource.getName();
logger.info(" process: FHIR Resource: " + filename);
String[] parts = filename.split("-");
if (parts.length > 2) {
if (!parts[1].equalsIgnoreCase(fhirVersion)) {
logger.warn("CommonFileStore::processFhirFolder() warning: FhirVersion doesn't match!");
continue;
}
// parse the the resource file into the correct FHIR
IBaseResource baseResource = null;
try {
baseResource = parser.parseResource(new FileInputStream(resource));
} catch (FileNotFoundException e) {
logger.warn("could not find file: " + resource.getPath());
continue;
}
processFhirResource(baseResource, filename, filename, fhirVersion, topic);
}
}
}
}
}
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class CommonFileStore method getFhirResourcesByTopicAsFhirBundle.
public Bundle getFhirResourcesByTopicAsFhirBundle(String fhirVersion, String resourceType, String topic, String baseUrl) {
List<FileResource> fileResources = getFhirResourcesByTopic(fhirVersion, resourceType, topic, baseUrl);
Bundle bundle = new Bundle();
if (fileResources != null && !fileResources.isEmpty()) {
for (FileResource fileResource : fileResources) {
if (fileResource != null) {
Resource resource = null;
try {
// convert the file resource into the fhir resource
resource = (Resource) parser.parseResource(fileResource.getResource().getInputStream());
BundleEntryComponent entry = new BundleEntryComponent().setResource(resource);
bundle.addEntry(entry);
} catch (IOException ioe) {
logger.error("Issue parsing FHIR file resource for preprocessing.", ioe);
return null;
}
}
}
}
return bundle;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class CommonFileStore method getFhirResourcesByTopicAsBundle.
public FileResource getFhirResourcesByTopicAsBundle(String fhirVersion, String resourceType, String topic, String baseUrl) {
Bundle bundle = getFhirResourcesByTopicAsFhirBundle(fhirVersion, resourceType, topic, baseUrl);
if (bundle.isEmpty()) {
return null;
}
byte[] resourceData = parser.encodeResourceToString(bundle).getBytes(Charset.defaultCharset());
FileResource outputFileResource = new FileResource();
outputFileResource.setResource(new ByteArrayResource(resourceData));
outputFileResource.setFilename("bundle.json");
return outputFileResource;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class LibraryContentProcessor method processResource.
/**
* Processes the Library to have content pointing to CQL replaced with embedded base64 encoded CQL file.
* Only supports relative paths to files being hosted on this server.
*/
@Override
protected Library processResource(Library inputResource, FileStore fileStore, String baseUrl) {
Library output = inputResource.copy();
List<Attachment> content = inputResource.getContent();
logger.info("Attempt to embed CQL (ELM) into Requested Library");
// if the first value in content is application/elm+json with a url, replace it with base64 encoded data
if (content.size() > 0) {
Attachment attachment = content.get(0);
if (attachment.hasUrl()) {
String url = attachment.getUrl();
// make sure this is a relative path
if (!url.toUpperCase().startsWith("HTTP")) {
// grab the topic, fhir version, and filename from the url
String[] urlParts = url.split("/");
if (urlParts.length >= 4) {
if ((attachment.getContentType().equalsIgnoreCase("application/elm+json")) || (attachment.getContentType().equalsIgnoreCase("text/cql"))) {
// content is CQL (assuming elm/json is actually CQL)
String topic = urlParts[1];
String fhirVersion = urlParts[2].toUpperCase();
String fileName = urlParts[3];
List<Attachment> attachments = new ArrayList<>();
// get the CQL data and base64 encode
FileResource cqlFileResource = fileStore.getFile(topic, fileName, fhirVersion, false);
attachments.add(base64EncodeToAttachment(cqlFileResource, "text/cql"));
// get the ELM data and base64 encode
FileResource elmFileResource = fileStore.getFile(topic, fileName, fhirVersion, true);
attachments.add(base64EncodeToAttachment(elmFileResource, "application/elm+json"));
// insert back into the Library
output.setContent(attachments);
} else {
logger.info("Content is not xml or json elm");
}
} else {
logger.info("URL doesn't split properly: " + url);
}
} else {
logger.info("URL is NOT relative");
}
} else {
logger.info("Content is not a url");
}
} else {
logger.info("No content in library");
}
return output;
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project CRD by HL7-DaVinci.
the class RuleFinder method findRules.
public List<RuleMapping> findRules(String topic, String fhirVersion) {
logger.info("RuleFinder::findRules(" + topic + ", " + fhirVersion + ")");
List<RuleMapping> ruleList = new ArrayList<>();
if (ruleMappingRepository == null) {
logger.warn("RuleFinder::findRules: the ruleMappingRepository is null");
return ruleList;
}
for (RuleMapping rule : ruleMappingRepository.findRules(topic, fhirVersion)) {
ruleList.add(rule);
}
if (ruleList.size() == 0) {
logger.info("RuleFinder::findRules() returned no results for topic: " + topic + "(" + fhirVersion + ")");
}
return ruleList;
}
Aggregations