use of org.hl7.davinci.endpoint.files.FileResource in project CRD by HL7-DaVinci.
the class DataController method getFile.
/**
* Retrieve a file from the File Store.
* @param topic (case sensitive)
* @param fhirVersion (converted to uppercase)
* @param fileName (case sensitive)
* @param noconvert
* @return
* @throws IOException
*/
@GetMapping(path = "/files/{topic}/{fhirVersion}/{fileName}")
public ResponseEntity<Resource> getFile(@PathVariable String topic, @PathVariable String fhirVersion, @PathVariable String fileName, @RequestParam(required = false) boolean noconvert) throws IOException {
fhirVersion = fhirVersion.toUpperCase();
logger.info("GET /files/" + topic + "/" + fhirVersion + "/" + fileName);
FileResource fileResource = fileStore.getFile(topic, fileName, fhirVersion, !noconvert);
return processFileResource(fileResource);
}
use of org.hl7.davinci.endpoint.files.FileResource in project CRD by HL7-DaVinci.
the class FhirController method getFhirResourceById.
/**
* Retrieve a FHIR resource by id
* @param fhirVersion (converted to uppercase)
* @param resource (converted to lowercase)
* @param id (converted to lowercase)
* @return
* @throws IOException
*/
@GetMapping(path = "/fhir/{fhirVersion}/{resource}/{id}")
public ResponseEntity<Resource> getFhirResourceById(HttpServletRequest request, @PathVariable String fhirVersion, @PathVariable String resource, @PathVariable String id) throws IOException {
fhirVersion = fhirVersion.toUpperCase();
resource = resource.toLowerCase();
logger.info("GET /fhir/" + fhirVersion + "/" + resource + "/" + id);
String baseUrl = Utils.getApplicationBaseUrl(request).toString() + "/";
FileResource fileResource = fileStore.getFhirResourceById(fhirVersion, resource, id, baseUrl);
return processFileResource(fileResource);
}
use of org.hl7.davinci.endpoint.files.FileResource in project CRD by HL7-DaVinci.
the class LibraryContentProcessor method base64EncodeToAttachment.
private Attachment base64EncodeToAttachment(FileResource fileResource, String mimeType) {
Attachment attachment = new Attachment();
try {
// base64 encode
InputStream inputStream = fileResource.getResource().getInputStream();
byte[] byteData = new byte[inputStream.available()];
inputStream.read(byteData);
String encodedData = Base64.encodeBase64String(byteData);
attachment.setContentType(mimeType);
Base64BinaryType b64bType = new Base64BinaryType();
b64bType.setValueAsString(encodedData);
attachment.setDataElement(b64bType);
} catch (IOException e) {
logger.warn("failed to read the data: " + mimeType);
}
return attachment;
}
use of org.hl7.davinci.endpoint.files.FileResource in project CRD by HL7-DaVinci.
the class QuestionnaireValueSetProcessor method findAndLoadValueSet.
/**
* Finds a value set, loads it and modifies its id and url fields to work in the contains field.
*
* @param url The canonical url of the valueset to look for.
* @param valueSetMap The map of valuesets that have been loaded already.
* @return The local ID to use for the valueset. null if valueset wasn't found.
*/
private String findAndLoadValueSet(String url, Map<String, ValueSet> valueSetMap, FileStore fileStore, String baseUrl) {
if (valueSetMap.containsKey(url)) {
return valueSetMap.get(url).getId();
}
FileResource valueSetFileResource;
ValueSet valueSet;
// If URL starts with this server's base url, pull out id and search by id
if (url.startsWith(baseUrl)) {
String valueSetId = url.split("ValueSet/")[1];
valueSetFileResource = fileStore.getFhirResourceById("R4", "valueset", valueSetId, baseUrl);
} else {
valueSetFileResource = fileStore.getFhirResourceByUrl("R4", "valueset", url, baseUrl);
}
if (valueSetFileResource != null) {
// parse value set and modify ID and #URL to match.
valueSet = (ValueSet) this.parseFhirFileResource(valueSetFileResource);
String valueSetId = valueSet.getIdElement().getIdPart();
valueSet.setId(valueSetId);
valueSet.setUrl("#" + valueSetId);
// add it to the value set map so it can be reused
valueSetMap.put(url, valueSet);
return valueSetId;
} else {
return null;
}
}
use of org.hl7.davinci.endpoint.files.FileResource in project CRD by HL7-DaVinci.
the class SubQuestionnaireProcessor method processItem.
/**
* Determines if this item is a sub-questionnaire reference and returns the items to replace it with. Returns the same list
* otherwise. Also recursively continues scanning if this is just a grouping item.
*
* @param item The item to check for sub-questionnaire referece.
* @param fileStore The FileStore to be used for fetching sub-questionnaires.
* @param baseUrl The base url from the server.
* @param containedList List of contained resources to put in the assembled Questionnaire. This will be filled while iterating.
* @param extensionList List of extensions to put in the assembled Questionnaire. This will be filled while iterating.
* @return New list of items to replace this item with.
*/
private List<QuestionnaireItemComponent> processItem(QuestionnaireItemComponent item, FileStore fileStore, String baseUrl, Hashtable<String, org.hl7.fhir.r4.model.Resource> containedList, List<Extension> extensionList) {
// find if item has an extension is sub-questionnaire
Extension e = item.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/sub-questionnaire");
if (e != null) {
// read sub questionnaire from file store
CanonicalType value = e.castToCanonical(e.getValue());
logger.info("SubQuestionnaireProcessor::parseItem(): Looking for SubQuestionnaire " + value);
// strip the type off of the id if it is there
String id = value.asStringValue();
String[] parts = id.split("/");
if (parts.length > 1) {
id = parts[1];
}
boolean expandRootItem = false;
Extension expand = item.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/sub-questionnaire-expand");
if (expand != null) {
expandRootItem = expand.castToBoolean(expand.getValue()).booleanValue();
}
FileResource subFileResource = fileStore.getFhirResourceById("R4", "questionnaire", id, baseUrl, false);
if (subFileResource != null) {
Questionnaire subQuestionnaire = (Questionnaire) this.parseFhirFileResource(subFileResource);
if (subQuestionnaire != null) {
// merge extensions
for (Extension subExtension : subQuestionnaire.getExtension()) {
if (extensionList.stream().noneMatch(ext -> ext.equalsDeep(subExtension))) {
extensionList.add(subExtension);
}
}
// merge contained resources
for (org.hl7.fhir.r4.model.Resource r : subQuestionnaire.getContained()) {
containedList.put(r.getId(), r);
}
List<QuestionnaireItemComponent> rootItems = subQuestionnaire.getItem();
// there are more than one root items in sub questionnaire, don't expand
if (!expandRootItem || rootItems.size() > 1) {
return rootItems;
} else {
return rootItems.get(0).getItem();
}
} else {
// SubQuestionnaire could not be loaded
logger.warn("SubQuestionnaireProcessor::parseItem(): Could not load SubQuestionnaire " + value.asStringValue());
return Arrays.asList(item);
}
} else {
// SubQuestionnaire could not be found
logger.warn("SubQuestionnaireProcessor::parseItem(): Could not find SubQuestionnaire " + value.asStringValue());
return Arrays.asList(item);
}
}
// parse sub-items
this.processItemList(item.getItem(), fileStore, baseUrl, containedList, extensionList);
return Arrays.asList(item);
}
Aggregations