Search in sources :

Example 81 with Attachment

use of org.hl7.fhir.r5.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);
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 82 with Attachment

use of org.hl7.fhir.r5.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;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Attachment(org.hl7.fhir.r4.model.Attachment) Library(org.hl7.fhir.r4.model.Library) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 83 with Attachment

use of org.hl7.fhir.r5.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();
}
Also used : CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) LibrarySourceProvider(org.opencds.cqf.common.providers.LibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) CqlLibrarySourceProvider(com.ibm.cohort.cql.provider.CqlLibrarySourceProvider) SourceProviderBasedCqlLibrarySourceProvider(com.ibm.cohort.cql.provider.SourceProviderBasedCqlLibrarySourceProvider) Attachment(org.hl7.fhir.r4.model.Attachment) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) ResolverLibraryResolutionProvider(com.ibm.cohort.cql.hapi.provider.ResolverLibraryResolutionProvider)

Example 84 with Attachment

use of org.hl7.fhir.r5.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;
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(org.hl7.fhir.r4.model.Attachment) CqlLibrary(com.ibm.cohort.cql.library.CqlLibrary) Library(org.cqframework.cql.elm.execution.Library)

Example 85 with Attachment

use of org.hl7.fhir.r5.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);
}
Also used : Attachment(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Attachment) InterruptedIOException(java.io.InterruptedIOException) ParseException(org.json.simple.parser.ParseException) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) IOException(java.io.IOException)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 ArrayList (java.util.ArrayList)32 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)17 Reference (org.hl7.fhir.r4.model.Reference)17 Test (org.testng.annotations.Test)17 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)16 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 HashMap (java.util.HashMap)12 Coding (org.hl7.fhir.r4.model.Coding)11 Document (com.ibm.cloud.cloudant.v1.model.Document)10 List (java.util.List)10 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)10 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)9 Observation (org.hl7.fhir.r4.model.Observation)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Resource (org.hl7.fhir.r4.model.Resource)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)7