Search in sources :

Example 11 with InstanceLocations

use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.

the class RetrieveServiceImpl method openLocationInputStream.

@Override
public LocationInputStream openLocationInputStream(RetrieveContext ctx, InstanceLocations inst) throws IOException {
    String studyInstanceUID = inst.getAttributes().getString(Tag.StudyInstanceUID);
    ArchiveDeviceExtension arcdev = getArchiveDeviceExtension();
    Map<Availability, List<Location>> locationsByAvailability = inst.getLocations().stream().filter(Location::isDicomFile).collect(Collectors.groupingBy(l -> arcdev.getStorageDescriptor(l.getStorageID()).getInstanceAvailability()));
    List<Location> locations = locationsByAvailability.get(Availability.ONLINE);
    if (locations == null)
        locations = locationsByAvailability.get(Availability.NEARLINE);
    else if (locationsByAvailability.containsKey(Availability.NEARLINE))
        locations.addAll(locationsByAvailability.get(Availability.NEARLINE));
    if (locations == null || locations.isEmpty()) {
        throw new IOException("Failed to find location of " + inst);
    }
    IOException ex = null;
    for (Location location : locations) {
        try {
            LOG.debug("Read {} from {}", inst, location);
            return openLocationInputStream(getStorage(location.getStorageID(), ctx), location, studyInstanceUID);
        } catch (IOException e) {
            ex = e;
            Location.Status errStatus = toStatus(e);
            if (errStatus == Location.Status.MISSING_OBJECT && !exists(location)) {
                LOG.warn("{} of {} no longer exists", location, inst);
                ctx.incrementMissing();
            } else {
                LOG.warn("Failed to read {} from {}:\n", inst, location, e);
                ctx.getUpdateLocations().add(new UpdateLocation(inst, location, errStatus, null));
            }
        }
    }
    throw ex;
}
Also used : SCU(org.dcm4che3.net.TransferCapability.Role.SCU) Templates(javax.xml.transform.Templates) NoSuchFileException(java.nio.file.NoSuchFileException) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) SCP(org.dcm4che3.net.TransferCapability.Role.SCP) LeadingCFindSCPQueryCache(org.dcm4chee.arc.LeadingCFindSCPQueryCache) org.dcm4chee.arc.entity(org.dcm4chee.arc.entity) javax.persistence.criteria(javax.persistence.criteria) Transcoder(org.dcm4che3.imageio.codec.Transcoder) ZipEntry(java.util.zip.ZipEntry) ReadContext(org.dcm4chee.arc.storage.ReadContext) StoreSession(org.dcm4chee.arc.store.StoreSession) QueryRetrieveLevel2(org.dcm4che3.net.service.QueryRetrieveLevel2) CFindSCUAttributeCoercion(org.dcm4chee.arc.query.scu.CFindSCUAttributeCoercion) DeIdentificationAttributesCoercion(org.dcm4che3.deident.DeIdentificationAttributesCoercion) MetricsService(org.dcm4chee.arc.metrics.MetricsService) org.dcm4che3.net(org.dcm4che3.net) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) IWebApplicationCache(org.dcm4che3.conf.api.IWebApplicationCache) StorageFactory(org.dcm4chee.arc.storage.StorageFactory) ApplicationScoped(javax.enterprise.context.ApplicationScoped) org.dcm4che3.io(org.dcm4che3.io) Storage(org.dcm4chee.arc.storage.Storage) java.util(java.util) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) ZipInputStream(java.util.zip.ZipInputStream) StoreService(org.dcm4chee.arc.store.StoreService) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) CoercionFactory(org.dcm4chee.arc.coerce.CoercionFactory) JSONReader(org.dcm4che3.json.JSONReader) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) Json(javax.json.Json) org.dcm4che3.data(org.dcm4che3.data) IApplicationEntityCache(org.dcm4che3.conf.api.IApplicationEntityCache) Tuple(javax.persistence.Tuple) org.dcm4chee.arc.retrieve(org.dcm4chee.arc.retrieve) Event(javax.enterprise.event.Event) CFindSCU(org.dcm4chee.arc.query.scu.CFindSCU) CodeCache(org.dcm4chee.arc.code.CodeCache) org.dcm4chee.arc.conf(org.dcm4chee.arc.conf) Logger(org.slf4j.Logger) PrivateTag(org.dcm4che3.dict.archive.PrivateTag) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) UpdateLocation(org.dcm4chee.arc.store.UpdateLocation) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) QueryBuilder(org.dcm4chee.arc.query.util.QueryBuilder) InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) InputStreamReader(java.io.InputStreamReader) org.dcm4che3.util(org.dcm4che3.util) InputStream(java.io.InputStream) UpdateLocation(org.dcm4chee.arc.store.UpdateLocation) IOException(java.io.IOException) UpdateLocation(org.dcm4chee.arc.store.UpdateLocation)

Example 12 with InstanceLocations

use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.

the class ImageDocumentSource method imagingDocumentSourceRetrieveRenderedImagingDocumentSet.

@Override
public RetrieveRenderedImagingDocumentSetResponseType imagingDocumentSourceRetrieveRenderedImagingDocumentSet(RetrieveRenderedImagingDocumentSetRequestType req) {
    log(req);
    RetrieveRenderedImagingDocumentSetResponseType rsp = new RetrieveRenderedImagingDocumentSetResponseType();
    RegistryResponseType regRsp = new RegistryResponseType();
    rsp.setRegistryResponse(regRsp);
    MultivaluedHashMap<String, RenderedDocumentRequest> map = new MultivaluedHashMap<>();
    RetrieveContext ctx = newRetrieveContextXDSI(req, map);
    if (calculateMatches(ctx, regRsp, map)) {
        retrieveStart.fire(ctx);
        RenderedImageDataHandler dh = null;
        ImageReader imageReader = getDicomImageReader();
        ImageWriter imageWriter = getImageWriter(MediaTypes.IMAGE_JPEG_TYPE);
        for (InstanceLocations match : ctx.getMatches()) {
            if (!ctx.copyToRetrieveCache(match)) {
                for (RenderedDocumentRequest docReq : map.get(match.getSopInstanceUID())) {
                    dh = new RenderedImageDataHandler(ctx, match, docReq, imageReader, imageWriter);
                    rsp.getRenderedDocumentResponse().add(createRenderedDocumentResponse(docReq, dh));
                }
            }
        }
        ctx.copyToRetrieveCache(null);
        InstanceLocations match;
        while ((match = ctx.copiedToRetrieveCache()) != null) {
            for (RenderedDocumentRequest docReq : map.get(match.getSopInstanceUID())) {
                dh = new RenderedImageDataHandler(ctx, match, docReq, imageReader, imageWriter);
                rsp.getRenderedDocumentResponse().add(createRenderedDocumentResponse(docReq, dh));
            }
        }
        if (dh != null)
            dh.setRetrieveEnd(retrieveEnd);
    }
    regRsp.setStatus(regRsp.getRegistryErrorList() == null ? XDS_STATUS_SUCCESS : rsp.getRenderedDocumentResponse().isEmpty() ? XDS_STATUS_FAILURE : XDS_STATUS_PARTIAL_SUCCESS);
    log(rsp);
    return rsp;
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) ImageWriter(javax.imageio.ImageWriter) RenderedDocumentRequest(org.dcm4che3.xdsi.RetrieveRenderedImagingDocumentSetRequestType.StudyRequest.SeriesRequest.RenderedDocumentRequest) ImageReader(javax.imageio.ImageReader)

Example 13 with InstanceLocations

use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.

the class CompressionScheduler method process.

private void process(ApplicationEntity ae, Series.Compression compr) {
    ArchiveAEExtension arcAE = ae.getAEExtensionNotNull(ArchiveAEExtension.class);
    if (compr.instancePurgeState == Series.InstancePurgeState.PURGED) {
        try (StoreSession session = storeService.newStoreSession(ae)) {
            storeService.restoreInstances(session, compr.studyInstanceUID, compr.seriesInstanceUID, arcAE.getPurgeInstanceRecordsDelay());
        } catch (Exception e) {
            LOG.warn("Failed to restore Instance records for compression of Series[iuid={}] of Study[iuid={}]:\n", compr.seriesInstanceUID, compr.studyInstanceUID, e);
            return;
        }
    }
    try (RetrieveContext retrCtx = retrieveService.newRetrieveContext(ae.getAETitle(), compr.studyInstanceUID, compr.seriesInstanceUID, null);
        StoreSession session = storeService.newStoreSession(ae)) {
        retrieveService.calculateMatches(retrCtx);
        LOG.info("Start compression of {} Instances of Series[iuid={}] of Study[iuid={}]", retrCtx.getNumberOfMatches(), compr.seriesInstanceUID, compr.studyInstanceUID);
        int failures = 0;
        int completed = 0;
        int skipped = 0;
        ArchiveCompressionRule compressionRule = new ArchiveCompressionRule();
        compressionRule.setTransferSyntax(compr.transferSyntaxUID);
        compressionRule.setImageWriteParams(compr.imageWriteParams());
        for (InstanceLocations inst : retrCtx.getMatches()) {
            if (alreadyCompressed(inst.getLocations(), compr.transferSyntaxUID)) {
                LOG.info("{} of Series[iuid={}] of Study[iuid={}] already compressed with {} - skipped", inst, compr.seriesInstanceUID, compr.studyInstanceUID, UID.nameOf(compr.transferSyntaxUID));
                skipped++;
                continue;
            }
            try (LocationInputStream lis = retrieveService.openLocationInputStream(retrCtx, inst)) {
                StoreContext ctx = storeService.newStoreContext(session);
                ctx.setCompressionRule(compressionRule);
                storeService.compress(ctx, inst, lis.stream);
                completed++;
            } catch (Exception e) {
                LOG.info("Failed to compress {} of Series[iuid={}] of Study[iuid={}]:\n", inst, compr.seriesInstanceUID, compr.studyInstanceUID, e);
                failures++;
            }
        }
        ejb.updateDB(compr, completed, failures);
        LOG.info("Finished compression of {} Instances of Series[iuid={}] of Study[iuid={}] - {} failures, {} skipped", completed, compr.seriesInstanceUID, compr.studyInstanceUID, failures, skipped);
        retrieveService.updateLocations(retrCtx);
    } catch (IOException e) {
        LOG.warn("Failed to calculate Instances for compression of Series[iuid={}] of Study[iuid={}]:\n", compr.seriesInstanceUID, compr.studyInstanceUID, e);
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) LocationInputStream(org.dcm4chee.arc.retrieve.LocationInputStream) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) IOException(java.io.IOException) IOException(java.io.IOException) StoreSession(org.dcm4chee.arc.store.StoreSession) StoreContext(org.dcm4chee.arc.store.StoreContext)

Example 14 with InstanceLocations

use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.

the class Curve2PRExporter method export.

@Override
public Outcome export(ExportContext ctx) throws Exception {
    ApplicationEntity ae;
    List<Attributes> results = new ArrayList<>();
    try (RetrieveContext retrieveContext = retrieveService.newRetrieveContext(ctx.getAETitle(), ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID())) {
        ae = retrieveContext.getLocalApplicationEntity();
        retrieveContext.setHttpServletRequestInfo(ctx.getHttpServletRequestInfo());
        if (!retrieveService.calculateMatches(retrieveContext))
            return new Outcome(Task.Status.WARNING, noMatches(ctx));
        for (InstanceLocations instanceLocations : retrieveContext.getMatches()) {
            if (isImage(instanceLocations))
                curve2pr(retrieveContext, instanceLocations, results);
        }
    }
    if (results.isEmpty())
        return new Outcome(Task.Status.COMPLETED, noPresentationStateCreated(ctx));
    int totInstanceRefs = 0;
    int instanceRefs;
    try (StoreSession session = storeService.newStoreSession(ctx.getHttpServletRequestInfo(), ae, ctx.getAETitle(), properties.get("SourceAET"))) {
        for (Attributes pr : results) {
            totInstanceRefs += instanceRefs = countInstanceRefs(pr);
            trimSoftcopyVOILUT(pr, instanceRefs);
            trimDisplayAreaSelection(pr);
            StoreContext storeCtx = storeService.newStoreContext(session);
            storeCtx.setReceiveTransferSyntax(UID.ExplicitVRLittleEndian);
            storeService.store(storeCtx, pr);
        }
    }
    return new Outcome(Task.Status.COMPLETED, toMessage(ctx, results.size(), totInstanceRefs));
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) Outcome(org.dcm4chee.arc.qmgt.Outcome) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) StoreSession(org.dcm4chee.arc.store.StoreSession) StoreContext(org.dcm4chee.arc.store.StoreContext)

Example 15 with InstanceLocations

use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.

the class ImageDocumentSource method imagingDocumentSourceRetrieveImagingDocumentSet.

@Override
public RetrieveDocumentSetResponseType imagingDocumentSourceRetrieveImagingDocumentSet(RetrieveImagingDocumentSetRequestType req) {
    log(req);
    RetrieveDocumentSetResponseType rsp = new RetrieveDocumentSetResponseType();
    RegistryResponseType regRsp = new RegistryResponseType();
    rsp.setRegistryResponse(regRsp);
    MultivaluedHashMap<String, DocumentRequest> map = new MultivaluedHashMap<>();
    RetrieveContext ctx = newRetrieveContextXDSI(req, map);
    List<String> tsuids = req.getTransferSyntaxUIDList().getTransferSyntaxUID();
    if (calculateMatches(ctx, regRsp, map.keySet(), tsuids)) {
        retrieveStart.fire(ctx);
        DicomDataHandler dh = null;
        for (InstanceLocations match : ctx.getMatches()) {
            if (!ctx.copyToRetrieveCache(match)) {
                dh = new DicomDataHandler(ctx, match, tsuids);
                for (DocumentRequest docReq : map.get(match.getSopInstanceUID())) {
                    rsp.getDocumentResponse().add(createDocumentResponse(docReq, dh));
                }
            }
        }
        ctx.copyToRetrieveCache(null);
        InstanceLocations match;
        while ((match = ctx.copiedToRetrieveCache()) != null) {
            dh = new DicomDataHandler(ctx, match, tsuids);
            for (DocumentRequest docReq : map.get(match.getSopInstanceUID())) {
                rsp.getDocumentResponse().add(createDocumentResponse(docReq, dh));
            }
        }
        if (dh != null)
            dh.setRetrieveEnd(retrieveEnd);
    }
    regRsp.setStatus(regRsp.getRegistryErrorList() == null ? XDS_STATUS_SUCCESS : rsp.getDocumentResponse().isEmpty() ? XDS_STATUS_FAILURE : XDS_STATUS_PARTIAL_SUCCESS);
    log(rsp);
    return rsp;
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) DocumentRequest(org.dcm4che3.xdsi.RetrieveDocumentSetRequestType.DocumentRequest) RenderedDocumentRequest(org.dcm4che3.xdsi.RetrieveRenderedImagingDocumentSetRequestType.StudyRequest.SeriesRequest.RenderedDocumentRequest)

Aggregations

InstanceLocations (org.dcm4chee.arc.store.InstanceLocations)34 IOException (java.io.IOException)8 RetrieveContext (org.dcm4chee.arc.retrieve.RetrieveContext)7 StoreService (org.dcm4chee.arc.store.StoreService)6 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)5 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 ZipEntry (java.util.zip.ZipEntry)4 Event (javax.enterprise.event.Event)4 Inject (javax.inject.Inject)4 Attributes (org.dcm4che3.data.Attributes)4 HttpServletRequestInfo (org.dcm4chee.arc.keycloak.HttpServletRequestInfo)4 StoreSession (org.dcm4chee.arc.store.StoreSession)4 Map (java.util.Map)3 ZipOutputStream (java.util.zip.ZipOutputStream)3 Tag (org.dcm4che3.data.Tag)3 DicomInputStream (org.dcm4che3.io.DicomInputStream)3