Skip to content

Commit

Permalink
Fix #546: IHE RAD-69: Retrieve Imaging Document Set
Browse files Browse the repository at this point in the history
  • Loading branch information
gunterze committed Feb 21, 2017
1 parent 9d3ba87 commit 7b1d823
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
6 changes: 6 additions & 0 deletions dcm4chee-arc-retrieve-xdsi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-entity</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che.dcm4chee-arc</groupId>
<artifactId>dcm4chee-arc-retrieve</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@

package org.dcm4chee.arc.retrieve.xdsi;

import org.dcm4che3.data.UID;
import org.dcm4che3.net.Device;
import org.dcm4che3.net.service.DicomServiceException;
import org.dcm4che3.ws.rs.MediaTypes;
import org.dcm4chee.arc.conf.ArchiveDeviceExtension;
import org.dcm4chee.arc.entity.Location;
import org.dcm4chee.arc.retrieve.*;

import javax.activation.DataHandler;
Expand All @@ -52,7 +54,6 @@
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.BindingType;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.soap.Addressing;
import javax.xml.ws.soap.MTOM;
import javax.xml.ws.soap.SOAPBinding;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class ImageDocumentSource implements ImagingDocumentSourcePortType {
public static final String XDS_ERR_MISSING_DOCUMENT = "XDSMissingDocument";
public static final String XDS_ERR_DOCUMENT_SOURCE_ERROR = "XDSDocumentSourceError";
public static final String DICOM_OBJECT_NOT_FOUND = "DICOM Object not found";
public static final String MISSING_TRANSFER_SYNTAX_UIDLIST = "Missing TransferSyntaxUIDList";
public static final String NO_ACCEPTABLE_TRANSFER_SYNTAX = "DICOM Object not acceptable according provided TransferSyntaxUIDList";

@Inject
private RetrieveService retrieveService;
Expand All @@ -92,8 +93,6 @@ public class ImageDocumentSource implements ImagingDocumentSourcePortType {
@Inject
private HttpServletRequest request;

private WebServiceContext wsctx;

@Inject @RetrieveStart
private Event<RetrieveContext> retrieveStart;

Expand All @@ -107,47 +106,26 @@ public RetrieveDocumentSetResponseType imagingDocumentSourceRetrieveImagingDocum
RegistryResponseType regRsp = new RegistryResponseType();
rsp.setRegistryResponse(regRsp);
DocumentRequests docReqs = new DocumentRequests(req.getStudyRequest());
RetrieveContext ctx = retrieveService.newRetrieveContextXDSI(request, getLocalAET(),
docReqs.studyUIDs, docReqs.seriesUIDs, docReqs.objectUIDs);
List<String> tsuids = req.getTransferSyntaxUIDList().getTransferSyntaxUID();
if (!validateTransferSyntaxes(tsuids)) {
addRegisterErrors(regRsp, docReqs, XDS_ERR_DOCUMENT_SOURCE_ERROR, MISSING_TRANSFER_SYNTAX_UIDLIST);
} else {
RetrieveContext ctx = retrieveService.newRetrieveContextXDSI(request, getLocalAET(),
docReqs.studyUIDs, docReqs.seriesUIDs, docReqs.objectUIDs);
try {
retrieveService.calculateMatches(ctx);
if (validateMatches(ctx, docReqs, regRsp)) {
retrieveStart.fire(ctx);
int n = ctx.getNumberOfMatches();
for (InstanceLocations match : ctx.getMatches()) {
DicomDataHandler dh = new DicomDataHandler(ctx, match, tsuids);
rsp.getDocumentResponse().add(
createDocumentResponse(docReqs.get(match.getSopInstanceUID()),
dh));
if (--n == 0)
dh.setRetrieveEnd(retrieveEnd);
}
}
} catch (DicomServiceException e) {
addRegisterErrors(regRsp, docReqs, XDS_ERR_DOCUMENT_SOURCE_ERROR, e.getMessage());
if (calculateMatches(ctx, docReqs, regRsp, tsuids)) {
retrieveStart.fire(ctx);
DicomDataHandler dh = null;
for (InstanceLocations match : ctx.getMatches()) {
dh = new DicomDataHandler(ctx, match, tsuids);
rsp.getDocumentResponse().add(
createDocumentResponse(docReqs.get(match.getSopInstanceUID()), dh));
}
if (dh != null)
dh.setRetrieveEnd(retrieveEnd);
}
regRsp.setStatus(regRsp.getRegistryErrorList() == null ? XDS_B_STATUS_SUCCESS
: rsp.getDocumentResponse().isEmpty() ? XDS_B_STATUS_FAILURE
: XDS_B_STATUS_PARTIAL_SUCCESS);
return rsp;
}

private boolean validateTransferSyntaxes(List<String> tsuids) {
if (tsuids.isEmpty())
return false;

for (String tsuid : tsuids) {
if (tsuid.isEmpty())
return false;
}
return true;
}

private void addRegisterErrors(
RegistryResponseType regRsp, DocumentRequests docReqs, String errorCode, String codeContext) {
List<RegistryError> errors = errors(regRsp);
Expand All @@ -156,12 +134,20 @@ private void addRegisterErrors(
}
}

private boolean validateMatches(RetrieveContext ctx, DocumentRequests docReqs, RegistryResponseType regRsp) {
private boolean calculateMatches(
RetrieveContext ctx, DocumentRequests docReqs, RegistryResponseType regRsp, List<String> tsuids) {
try {
retrieveService.calculateMatches(ctx);
} catch (DicomServiceException e) {
addRegisterErrors(regRsp, docReqs, XDS_ERR_DOCUMENT_SOURCE_ERROR, e.getMessage());
return false;
}
List<InstanceLocations> matches = ctx.getMatches();
HashSet<String> iuids = new HashSet<>(docReqs.keySet());
Iterator<InstanceLocations> iter = matches.iterator();
while (iter.hasNext()) {
if (!iuids.remove(iter.next().getSopInstanceUID()))
InstanceLocations match = iter.next();
if (!iuids.remove(match.getSopInstanceUID()) || !validateTransferSyntax(match, regRsp, tsuids))
iter.remove();
}
for (String iuid : iuids) {
Expand All @@ -173,6 +159,20 @@ private boolean validateMatches(RetrieveContext ctx, DocumentRequests docReqs, R
return !matches.isEmpty();
}

private boolean validateTransferSyntax(InstanceLocations match, RegistryResponseType regRsp, List<String> tsuids) {
for (Location location : match.getLocations()) {
if (tsuids.contains(location.getTransferSyntaxUID()))
return true;
}
if (tsuids.contains(UID.ExplicitVRLittleEndian) || tsuids.contains(UID.ImplicitVRLittleEndian))
return true;

errors(regRsp).add(createRegistryError(
XDS_ERR_MISSING_DOCUMENT, NO_ACCEPTABLE_TRANSFER_SYNTAX, XDS_ERR_SEVERITY_ERROR,
match.getSopInstanceUID()));
return false;
}

private RegistryError createRegistryError(
String errorCode, String codeContext, String severity, String location) {
RegistryError error = new RegistryError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,12 @@ public Transcoder openTranscoder(RetrieveContext ctx, InstanceLocations inst,
LocationDicomInputStream locationInputStream = openLocationInputStream(ctx, inst);
String tsuid = locationInputStream.getLocation().getTransferSyntaxUID();
if (!tsuids.isEmpty() && !tsuids.contains(tsuid)) {
tsuid = fmi || tsuids.contains(UID.ExplicitVRLittleEndian)
? UID.ExplicitVRLittleEndian
: UID.ImplicitVRLittleEndian;
if (tsuids.contains(UID.ExplicitVRLittleEndian))
tsuid = UID.ExplicitVRLittleEndian;
else if (tsuids.contains(UID.ImplicitVRLittleEndian))
tsuid = UID.ExplicitVRLittleEndian;
else
throw new NoPresentationContextException(inst.getSopClassUID(), tsuid);
}
Transcoder transcoder = new Transcoder(locationInputStream.getDicomInputStream());
transcoder.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
Expand Down

0 comments on commit 7b1d823

Please sign in to comment.