Search in sources :

Example 46 with Attachment

use of com.ibm.cloud.cloudant.v1.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 47 with Attachment

use of com.ibm.cloud.cloudant.v1.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 48 with Attachment

use of com.ibm.cloud.cloudant.v1.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 49 with Attachment

use of com.ibm.cloud.cloudant.v1.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)

Example 50 with Attachment

use of com.ibm.cloud.cloudant.v1.model.Attachment in project cloudant-java-sdk by IBM.

the class PutAttachmentOptionsTest method testPutAttachmentOptions.

@Test
public void testPutAttachmentOptions() throws Throwable {
    PutAttachmentOptions putAttachmentOptionsModel = new PutAttachmentOptions.Builder().db("testString").docId("testString").attachmentName("testString").attachment(TestUtilities.createMockStream("This is a mock file.")).contentType("application/octet-stream").ifMatch("testString").rev("testString").build();
    assertEquals(putAttachmentOptionsModel.db(), "testString");
    assertEquals(putAttachmentOptionsModel.docId(), "testString");
    assertEquals(putAttachmentOptionsModel.attachmentName(), "testString");
    assertEquals(IOUtils.toString(putAttachmentOptionsModel.attachment()), IOUtils.toString(TestUtilities.createMockStream("This is a mock file.")));
    assertEquals(putAttachmentOptionsModel.contentType(), "application/octet-stream");
    assertEquals(putAttachmentOptionsModel.ifMatch(), "testString");
    assertEquals(putAttachmentOptionsModel.rev(), "testString");
}
Also used : PutAttachmentOptions(com.ibm.cloud.cloudant.v1.model.PutAttachmentOptions) Test(org.testng.annotations.Test)

Aggregations

Attachment (org.hl7.fhir.r4.model.Attachment)33 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)19 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)17 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)16 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)16 Reference (org.hl7.fhir.r4.model.Reference)15 HashMap (java.util.HashMap)11 Document (com.ibm.cloud.cloudant.v1.model.Document)10 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)9 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)8 Observation (org.hl7.fhir.r4.model.Observation)8 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)7 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 Coding (org.hl7.fhir.r4.model.Coding)7 Resource (org.hl7.fhir.r4.model.Resource)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 NotImplementedException (org.apache.commons.lang3.NotImplementedException)6