use of org.hl7.fhir.dstu2.model.Attachment in project quality-measure-and-cohort-service by Alvearie.
the class R4TranslatingLibraryLoaderTest method load_invalidXmlContent.
@Test
public void load_invalidXmlContent() throws IOException {
Library library = new Library();
withIdentifiers(library, NAME, VERSION);
withContent(library, "/cql/basic/Test-1.0.0.cql", "application/elm+xml");
R4TranslatingLibraryLoader loader = getLoader(getLibraryResolver(NAME, VERSION, library));
VersionedIdentifier identifier = new VersionedIdentifier().withId(NAME).withVersion(VERSION);
String expectedPrefix = String.format("Library %s-%s elm attachment", NAME, VERSION);
assertIllegalArgumentException(() -> loader.load(identifier), expectedPrefix);
}
use of org.hl7.fhir.dstu2.model.Attachment in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluationSeederTest method createLibrary.
private Library createLibrary(String elmFile) throws IOException {
Coding libraryCoding = new Coding();
libraryCoding.setSystem(LibraryType.LOGICLIBRARY.getSystem());
libraryCoding.setCode(LibraryType.LOGICLIBRARY.toCode());
CodeableConcept libraryType = new CodeableConcept();
libraryType.setCoding(Collections.singletonList(libraryCoding));
Library library = new Library();
library.setId(libraryName + "-id");
library.setType(libraryType);
library.setName(libraryName);
library.setVersion(libraryVersion);
Attachment attachment = new Attachment();
attachment.setData(IOUtils.resourceToByteArray(elmFile));
attachment.setContentType("application/elm+xml");
library.setContent(Collections.singletonList(attachment));
return library;
}
use of org.hl7.fhir.dstu2.model.Attachment in project quality-measure-and-cohort-service by Alvearie.
the class R4TranslatingLibraryLoader method translateLibrary.
private String translateLibrary(String content, VersionedIdentifier libraryIdentifier) {
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResolutionProvider = new ResolverLibraryResolutionProvider<>(resolver);
LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment> librarySourceProvider = new LibrarySourceProvider<>(libraryResolutionProvider, org.hl7.fhir.r4.model.Library::getContent, Attachment::getContentType, Attachment::getData);
CqlLibrarySourceProvider cqlLibrarySourceProvider = new SourceProviderBasedCqlLibrarySourceProvider(librarySourceProvider);
CqlLibraryDescriptor descriptor = new CqlLibraryDescriptor().setFormat(Format.CQL).setLibraryId(libraryIdentifier.getId()).setVersion(libraryIdentifier.getVersion());
CqlLibrary library = new CqlLibrary().setDescriptor(descriptor).setContent(content);
return translator.translate(library, cqlLibrarySourceProvider).getMainLibrary().getContent();
}
use of org.hl7.fhir.dstu2.model.Attachment in project quality-measure-and-cohort-service by Alvearie.
the class R4TranslatingLibraryLoader method load.
@Override
public Library load(VersionedIdentifier libraryIdentifier) {
Library elmLibrary = null;
org.hl7.fhir.r4.model.Library fhirLibrary = resolver.resolveByName(libraryIdentifier.getId(), libraryIdentifier.getVersion());
if (fhirLibrary == null) {
throw new IllegalArgumentException(String.format("Library %s-%s not found", libraryIdentifier.getId(), libraryIdentifier.getVersion()));
}
Map<String, Attachment> mimeTypeIndex = new HashMap<>();
for (Attachment attachment : fhirLibrary.getContent()) {
if (attachment.hasContentType()) {
mimeTypeIndex.put(attachment.getContentType(), attachment);
} else {
throw new IllegalArgumentException(String.format("Library %s-%s contains an attachment with no content type", libraryIdentifier.getId(), libraryIdentifier.getVersion()));
}
}
Attachment attachment = mimeTypeIndex.get("application/elm+xml");
if (attachment != null) {
try (InputStream is = getAttachmentDataAsStream(attachment)) {
elmLibrary = CqlLibraryReader.read(is);
} catch (Exception ex) {
throw new IllegalArgumentException(String.format("Library %s-%s elm attachment failed to deserialize", libraryIdentifier.getId(), libraryIdentifier.getVersion()), ex);
}
}
if (elmLibrary == null) {
attachment = mimeTypeIndex.get("text/cql");
if (attachment == null) {
throw new IllegalArgumentException(String.format("Library %s-%s must contain either a application/elm+xml or text/cql attachment", libraryIdentifier.getId(), libraryIdentifier.getVersion()));
} else {
String content = getAttachmentDataAsString(attachment);
try {
elmLibrary = OptimizedCqlLibraryReader.read(translateLibrary(content, libraryIdentifier));
} catch (Exception ex) {
throw new IllegalArgumentException(String.format("Library %s-%s cql attachment failed to deserialize", libraryIdentifier.getId(), libraryIdentifier.getVersion()), ex);
}
}
}
return elmLibrary;
}
use of org.hl7.fhir.dstu2.model.Attachment in project manifoldcf by apache.
the class ConfluenceRepositoryConnector method processPageAsAttachment.
/**
* <p>
* Process the specific attachment
* </p>
*
* @param activeSecurity Security enabled/disabled
* @param documentIdentifier The original documentIdentifier
* @param parentRestrictions The list of parent restrictions
* @param pageId The pageId being an attachment
* @param version The version of the page
* @param activities
* @param doLog
* @throws IOException
* @throws ServiceInterruption
*/
private ProcessResult processPageAsAttachment(final boolean activeSecurity, final String documentIdentifier, final List<String> parentRestrictions, final String pageId, final String version, final IProcessActivity activities, final boolean doLog) throws ManifoldCFException, ServiceInterruption, IOException {
final String[] ids = ConfluenceUtil.getAttachmentAndPageId(pageId);
Attachment attachment = new Attachment();
try {
attachment = confluenceClient.getAttachment(ids[0]);
} catch (final Exception e) {
handlePageException(e, "attachment processing");
}
final Map<String, String> extraProperties = Maps.newHashMap();
extraProperties.put("attachedBy", ids[1]);
return processPageInternal(activeSecurity, parentRestrictions, attachment, documentIdentifier, version, activities, doLog, extraProperties);
}
Aggregations