Search in sources :

Example 1 with InstanceLocations

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

the class WadoRS method buildResponse.

private void buildResponse(Target target, int[] frameList, int[] attributePath, AsyncResponse ar, Output output, final RetrieveContext ctx, Date lastModified) throws IOException {
    LOG.debug("Query for matching {}", target);
    service.calculateMatches(ctx);
    LOG.info("retrieve{}: {} Matches", target, ctx.getNumberOfMatches());
    if (ctx.getNumberOfMatches() == 0)
        throw new WebApplicationException(errResponse("No matches found.", Response.Status.NOT_FOUND));
    // Collection<InstanceLocations> notAccessable = service.removeNotAccessableMatches(ctx);
    responseStatus = Response.Status.OK;
    if (frameList != null) {
        Attributes attrs = ctx.getMatches().get(0).getAttributes();
        if (!attrs.containsValue(Tag.Rows))
            throw new WebApplicationException(errResponse("Not an image.", Response.Status.NOT_FOUND));
        frameList = adjustFrameList(frameList, attrs.getInt(Tag.NumberOfFrames, 1));
        if (frameList.length == 0)
            throw new WebApplicationException(errResponse("No such frame.", Response.Status.NOT_FOUND));
    }
    output = output.adjust(this, frameList, ctx);
    Collection<InstanceLocations> notAccepted = output.removeNotAcceptedMatches(this, ctx, frameList, attributePath);
    if (ctx.getMatches().isEmpty()) {
        Response errResp = notAccepted.isEmpty() ? errResponse("No matches found.", Response.Status.NOT_FOUND) : errResponse("Not accepted instances present.", Response.Status.NOT_ACCEPTABLE);
        throw new WebApplicationException(errResp);
    }
    if (!notAccepted.isEmpty())
        responseStatus = Response.Status.PARTIAL_CONTENT;
    if (lastModified == null)
        lastModified = service.getLastModifiedFromMatches(ctx, ignorePatientUpdate);
    retrieveStart.fire(ctx);
    ar.register((CompletionCallback) throwable -> {
        SafeClose.close(compressedMFPixelDataOutput);
        SafeClose.close(uncompressedFramesOutput);
        SafeClose.close(compressedFramesOutput);
        SafeClose.close(decompressFramesOutput);
        purgeSpoolDirectory();
        ctx.getRetrieveService().updateLocations(ctx);
        ctx.setException(throwable);
        retrieveEnd.fire(ctx);
    });
    Object entity = output.entity(this, target, ctx, frameList, attributePath);
    ar.resume(output.response(this, lastModified, entity).build());
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) AsyncResponse(javax.ws.rs.container.AsyncResponse) AttributeSet(org.dcm4chee.arc.conf.AttributeSet) KeycloakContext(org.dcm4chee.arc.keycloak.KeycloakContext) StreamResult(javax.xml.transform.stream.StreamResult) LoggerFactory(org.slf4j.LoggerFactory) DirectoryStream(java.nio.file.DirectoryStream) JSONWriter(org.dcm4che3.json.JSONWriter) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) SAXTransformer(org.dcm4che3.io.SAXTransformer) WebApplication(org.dcm4che3.net.WebApplication) URI(java.net.URI) ZipEntry(java.util.zip.ZipEntry) AsyncResponse(javax.ws.rs.container.AsyncResponse) Suspended(javax.ws.rs.container.Suspended) Collectors(java.util.stream.Collectors) Device(org.dcm4che3.net.Device) List(java.util.List) Stream(java.util.stream.Stream) javax.ws.rs(javax.ws.rs) OutputPart(org.jboss.resteasy.plugins.providers.multipart.OutputPart) CompletionCallback(javax.ws.rs.container.CompletionCallback) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) Pattern(javax.validation.constraints.Pattern) Entity(org.dcm4chee.arc.conf.Entity) MultipartRelatedOutput(org.jboss.resteasy.plugins.providers.multipart.MultipartRelatedOutput) JsonGenerator(javax.json.stream.JsonGenerator) IntStream(java.util.stream.IntStream) ZipOutputStream(java.util.zip.ZipOutputStream) java.util(java.util) DicomImageReadParam(org.dcm4che3.imageio.plugins.dcm.DicomImageReadParam) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) RecordType(org.dcm4che3.media.RecordType) Function(java.util.function.Function) Inject(javax.inject.Inject) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) DicomObjectOutput(org.dcm4chee.arc.retrieve.stream.DicomObjectOutput) Json(javax.json.Json) org.dcm4che3.data(org.dcm4che3.data) org.dcm4chee.arc.retrieve(org.dcm4chee.arc.retrieve) Event(javax.enterprise.event.Event) MediaTypeUtils(org.dcm4chee.arc.rs.util.MediaTypeUtils) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ICCProfile(org.dcm4che3.image.ICCProfile) RecordFactory(org.dcm4che3.media.RecordFactory) ValidValueOf(org.dcm4chee.arc.validation.constraints.ValidValueOf) javax.ws.rs.core(javax.ws.rs.core) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) java.awt(java.awt) MediaTypes(org.dcm4che3.ws.rs.MediaTypes) DicomDirWriter(org.dcm4che3.media.DicomDirWriter) java.io(java.io) Paths(java.nio.file.Paths) DicomInputStream(org.dcm4che3.io.DicomInputStream) RequestScoped(javax.enterprise.context.RequestScoped) org.dcm4che3.util(org.dcm4che3.util)

Example 2 with InstanceLocations

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

the class WadoRS method writeZIP.

private Object writeZIP(RetrieveContext ctx) {
    AttributesFormat pathFormat = new AttributesFormat(ctx.getLocalApplicationEntity().getAEExtensionNotNull(ArchiveAEExtension.class).wadoZIPEntryNameFormat());
    final Collection<InstanceLocations> insts = ctx.getMatches();
    return (StreamingOutput) out -> {
        try {
            Set<String> dirPaths = new HashSet<>();
            ZipOutputStream zip = new ZipOutputStream(out);
            try (DicomDirWriter dicomDirWriter = dicomDirWriter()) {
                for (InstanceLocations inst : insts) {
                    String name = pathFormat.format(inst.getAttributes());
                    addDirEntries(zip, name, dirPaths);
                    zip.putNextEntry(new ZipEntry(name));
                    DicomObjectOutput output = new DicomObjectOutput(ctx, inst, acceptableZipTransferSyntaxes);
                    output.write(zip);
                    zip.closeEntry();
                    if (dicomDirWriter != null) {
                        addDicomDirRecords(dicomDirWriter, output.getFileMetaInformation(), inst.getAttributes(), toFileIDs(name));
                    }
                }
            }
            if (dicomdirPath != null) {
                zip.putNextEntry(new ZipEntry("DICOMDIR"));
                Files.copy(dicomdirPath, zip);
                zip.closeEntry();
            }
            zip.finish();
            zip.flush();
        } catch (Exception e) {
            throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
        }
    };
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) DicomDirWriter(org.dcm4che3.media.DicomDirWriter) ZipEntry(java.util.zip.ZipEntry) ZipOutputStream(java.util.zip.ZipOutputStream) DicomObjectOutput(org.dcm4chee.arc.retrieve.stream.DicomObjectOutput)

Example 3 with InstanceLocations

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

the class UPSStoreSCU method processA.

@Override
protected void processA(UPSContext upsCtx, Attributes ups) throws Exception {
    String destinationAE = destinationAEOf(ups);
    RetrieveContext retrieveContext = calculateMatches(ups, destinationAE);
    if (retrieveContext == null) {
        throw new UPSProcessorException(NOOP_UPS, "No matching Instances found");
    }
    if (retrieveService.restrictRetrieveAccordingTransferCapabilities(retrieveContext)) {
        storeSCU.newRetrieveTaskSTORE(retrieveContext).run();
        String outcomeDescription = retrieveContext.getOutcomeDescription();
        Attributes performedProcedure = getPerformedProcedureStep(upsCtx);
        performedProcedure.setString(Tag.PerformedProcedureStepDescription, VR.LO, outcomeDescription);
        Sequence outputInformationSeq = performedProcedure.getSequence(Tag.OutputInformationSequence);
        for (InstanceLocations match : retrieveContext.getMatches()) {
            if (!retrieveContext.isFailedSOPInstanceUID(match.getSopInstanceUID())) {
                refSOPSequence(outputInformationSeq, match, destinationAE).add(toSOPRef(match));
            }
        }
        if (retrieveContext.status() != Status.Success)
            throw new DicomServiceException(retrieveContext.status(), outcomeDescription);
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) UPSProcessorException(org.dcm4chee.arc.ups.process.UPSProcessorException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 4 with InstanceLocations

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

the class CStoreForwardTask method createInstanceLocations.

private InstanceLocations createInstanceLocations(StoreContext storeCtx) {
    Instance inst = storeCtx.getStoredInstance();
    Series series = inst.getSeries();
    Study study = series.getStudy();
    Patient patient = study.getPatient();
    Attributes instAttrs = inst.getAttributes();
    Attributes seriesAttrs = series.getAttributes();
    Attributes studyAttrs = study.getAttributes();
    Attributes patAttrs = patient.getAttributes();
    Attributes.unifyCharacterSets(patAttrs, studyAttrs, seriesAttrs, instAttrs);
    instAttrs.addAll(seriesAttrs, true);
    instAttrs.addAll(studyAttrs, true);
    instAttrs.addAll(patAttrs, true);
    RetrieveService service = ctx.getRetrieveService();
    InstanceLocations instanceLocations = service.newInstanceLocations(instAttrs);
    instanceLocations.getLocations().addAll(locations(storeCtx));
    return instanceLocations;
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) RetrieveService(org.dcm4chee.arc.retrieve.RetrieveService) Attributes(org.dcm4che3.data.Attributes)

Example 5 with InstanceLocations

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

the class CStoreSCUImpl method createAARQ.

private AAssociateRQ createAARQ(RetrieveContext ctx) {
    AAssociateRQ aarq = new AAssociateRQ();
    ApplicationEntity localAE = ctx.getLocalApplicationEntity();
    ApplicationEntity destAE = ctx.getDestinationAE();
    if (!localAE.isMasqueradeCallingAETitle(ctx.getDestinationAETitle()))
        aarq.setCallingAET(ctx.getCallingAET());
    boolean noDestinationRestriction = destAE.getTransferCapabilitiesWithRole(SCP).isEmpty();
    for (Iterator<InstanceLocations> iter = ctx.getMatches().iterator(); iter.hasNext(); ) {
        InstanceLocations inst = iter.next();
        String cuid = inst.getSopClassUID();
        TransferCapability localTC = localAE.getTransferCapabilityFor(cuid, SCU);
        TransferCapability destTC = noDestinationRestriction ? null : destAE.getTransferCapabilityFor(cuid, SCP);
        if (!aarq.containsPresentationContextFor(cuid) && !isVideo(inst)) {
            if (noDestinationRestriction) {
                addPresentationContext(aarq, cuid, UID.ImplicitVRLittleEndian, localTC);
                addPresentationContext(aarq, cuid, UID.ExplicitVRLittleEndian, localTC);
            } else {
                addPresentationContext(aarq, cuid, UID.ImplicitVRLittleEndian, localTC, destTC);
                addPresentationContext(aarq, cuid, UID.ExplicitVRLittleEndian, localTC, destTC);
            }
        }
        for (Location location : inst.getLocations()) {
            String tsuid = location.getTransferSyntaxUID();
            if (!tsuid.equals(UID.ImplicitVRLittleEndian) && !tsuid.equals(UID.ExplicitVRLittleEndian))
                if (noDestinationRestriction) {
                    addPresentationContext(aarq, cuid, tsuid, localTC);
                } else {
                    addPresentationContext(aarq, cuid, tsuid, localTC, destTC);
                }
        }
    }
    return aarq;
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) AAssociateRQ(org.dcm4che3.net.pdu.AAssociateRQ) Location(org.dcm4chee.arc.entity.Location)

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