Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/
**/.git/
**/.mvn/
**/data/
*.md
5 changes: 5 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY dicoogle-next/target/dicoogle-next-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
5 changes: 5 additions & 0 deletions backend/dicoogle-next-protocol-dicomweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>dcm4che-json</artifactId>
<version>${dcm4che.version}</version>
</dependency>
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-imageio</artifactId>
<version>${dcm4che.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ public String instanceMetadata(
* @return the matching {@link QueryResult}
* @throws ResponseStatusException 404 if not found, 500 on I/O error
*/
public byte[] retrieveInstanceBySopUid(String sopInstanceUid, String provider) {
LOGGER.info("retrieve by sopUID={}", sopInstanceUid);
var result = dumpResult(sopInstanceUid, provider);
URI uri = result.storageUri();
try (var stream = storageRouter.requireReadable(uri.getScheme()).openForRead(uri)) {
return stream.readAllBytes();
} catch (IOException ex) {
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR,
"Failed to read DICOM instance from storage provider",
ex);
}
}

public QueryService.QueryResult dumpResult(String sopInstanceUid, String provider) {
LOGGER.info("dump request: sopUID={}", sopInstanceUid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -39,6 +50,10 @@ public class DicoogleApiController {

private static final ObjectMapper MAPPER = new ObjectMapper();

static {
ImageIO.scanForPlugins();
}

private final DicomwebQidoService qidoService;
private final DicomwebRetrieveService retrieveService;

Expand Down Expand Up @@ -143,4 +158,103 @@ public ResponseEntity<String> dumpInstance(
throw new RuntimeException("Failed to build dump response", e);
}
}

/** Serves raw DICOM bytes for a given SOPInstanceUID. Used by Cornerstone's wadouri loader. */
@GetMapping("/legacy/file")
public ResponseEntity<byte[]> legacyFile(
@RequestParam("uid") String sopInstanceUid,
@RequestParam(value = "provider", required = false) String provider) {
LOGGER.info("legacy/file request: uid={}", sopInstanceUid);
byte[] bytes = retrieveService.retrieveInstanceBySopUid(sopInstanceUid, provider);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).body(bytes);
}

/**
* Converts a DICOM instance to PNG image data. Matches the legacy Dicoogle /dic2png endpoint.
*
* <p>Uses dcm4che's ImageIO plugin to decode the DICOM pixel data, then encodes as a progressive
* (Adam7) PNG. When {@code thumbnail=true} the image is scaled to fit a 256×256 box while
* preserving aspect ratio.
*
* @param sopInstanceUid the SOP Instance UID of the DICOM object
* @param thumbnail if true, return a scaled thumbnail
* @param frame zero-based frame index for multi-frame DICOM (default 0)
* @param provider optional query provider name
* @return 200 with image/png body, 404 if not found, 500 if conversion fails
*/
@GetMapping(value = "/dic2png", produces = "image/png")
public ResponseEntity<byte[]> dic2png(
@RequestParam("SOPInstanceUID") String sopInstanceUid,
@RequestParam(value = "thumbnail", required = false) String thumbnailParam,
@RequestParam(value = "frame", required = false, defaultValue = "0") int frame,
@RequestParam(value = "provider", required = false) String provider) {
boolean thumbnail =
thumbnailParam != null
&& (thumbnailParam.isEmpty() || Boolean.parseBoolean(thumbnailParam));
byte[] dicomBytes;
try {
dicomBytes = retrieveService.retrieveInstanceBySopUid(sopInstanceUid, provider);
} catch (Exception e) {
LOGGER.warn("dic2png: no DICOM data for uid={}", sopInstanceUid, e);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "No image for SOPInstanceUID");
}
if (dicomBytes == null || dicomBytes.length == 0) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "No image for SOPInstanceUID");
}
try {
BufferedImage image;
try (ImageInputStream iis =
ImageIO.createImageInputStream(new ByteArrayInputStream(dicomBytes))) {
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("DICOM");
if (!readers.hasNext()) {
throw new IOException(
"No DICOM ImageReader available — is dcm4che-imageio on the classpath?");
}
ImageReader reader = readers.next();
reader.setInput(iis, false);
int frameCount = reader.getNumImages(true);
if (frame < 0 || frame >= frameCount) {
frame = 0;
}
image = reader.read(frame, reader.getDefaultReadParam());
}
if (image == null) {
throw new IOException("Failed to decode DICOM pixel data");
}
if (thumbnail) {
int size = 256;
int w = image.getWidth();
int h = image.getHeight();
if (w > size || h > size) {
double scale;
if (w > h) {
scale = (double) size / w;
} else {
scale = (double) size / h;
}
java.awt.Image scaled =
image.getScaledInstance(
(int) (w * scale), (int) (h * scale), java.awt.Image.SCALE_SMOOTH);
BufferedImage buf =
new BufferedImage(
scaled.getWidth(null), scaled.getHeight(null), BufferedImage.TYPE_INT_RGB);
buf.getGraphics().drawImage(scaled, 0, 0, null);
image = buf;
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();
ImageWriteParam writeParams = writer.getDefaultWriteParam();
writeParams.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);
try (ImageOutputStream ios = ImageIO.createImageOutputStream(baos)) {
writer.setOutput(ios);
writer.write(image);
}
return ResponseEntity.ok().body(baos.toByteArray());
} catch (IOException e) {
LOGGER.error("dic2png: failed to convert DICOM to PNG for uid={}", sopInstanceUid, e);
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, "Failed to convert DICOM to PNG");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ private MultiValueMap<String, String> buildQidoParams(String query, boolean keyw

if (keyword) {
// Keyword mode: expect "Key:Value" pairs separated by spaces
// "*:*" is a wildcard meaning "return all" — treat as empty filter
if ("*:*".equals(query.trim())) {
return params;
}
for (String token : query.trim().split("\\s+")) {
int colon = token.indexOf(':');
if (colon > 0 && colon < token.length() - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CMoveService {
private final Set<String> supportedLevels;
private final int maxResults;
private final List<String> dimProviders;
private final Map<String, DimseCMoveProperties.Destination> destinations;
private final DimseCMoveProperties moveProperties;
private final MeterRegistry meterRegistry;
private final LegacyProxyService legacyProxyService;
private final LegacyProxyProperties legacyProxyProperties;
Expand All @@ -55,7 +55,7 @@ public CMoveService(
.collect(java.util.stream.Collectors.toCollection(LinkedHashSet::new));
this.maxResults = properties.getMaxResults();
this.dimProviders = dimseProperties.getDimProviders();
this.destinations = Map.copyOf(properties.getDestinations());
this.moveProperties = properties;
this.meterRegistry = meterRegistry;
this.legacyProxyService = legacyProxyService;
}
Expand Down Expand Up @@ -153,7 +153,8 @@ public DimseCMoveProperties.Destination destination(String moveDestinationAet)
throw new DicomServiceException(
Status.MoveDestinationUnknown, "Move Destination is required");
}
DimseCMoveProperties.Destination destination = destinations.get(moveDestinationAet);
DimseCMoveProperties.Destination destination =
moveProperties.getDestinations().get(moveDestinationAet);
if (destination == null || destination.getHost() == null || destination.getHost().isBlank()) {
throw new DicomServiceException(
Status.MoveDestinationUnknown, "Unknown move destination: " + moveDestinationAet);
Expand All @@ -170,7 +171,7 @@ private boolean hasDestination(String moveDestinationAet) {
if (moveDestinationAet == null || moveDestinationAet.isBlank()) {
return false;
}
return destinations.containsKey(moveDestinationAet);
return moveProperties.getDestinations().containsKey(moveDestinationAet);
}

private void validateIdentifierByLevel(Attributes keys, String level)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.dicoogle.sdk.query.StorageIngestEventListener;
import org.dicoogle.sdk.storage.DimseAssociationAcceptedEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -23,7 +22,8 @@
DimseCStoreProperties.class,
DimseCFindProperties.class,
DimseCMoveProperties.class,
DimseProperties.class
DimseProperties.class,
DimseQueryRetrieveProperties.class
})
public class DimseCStoreConfig {

Expand Down Expand Up @@ -83,11 +83,8 @@ CMoveService cMoveService(
}

@Bean
@ConditionalOnProperty(prefix = "app.dimse.cstore", name = "enabled", havingValue = "true")
DimseCStoreServer dimseCStoreServer(
CStoreService cStoreService,
CFindService cFindService,
CMoveService cMoveService,
StorageRouter storageRouter,
DimseCStoreProperties properties,
List<DimseAssociationEventListener> associationEventListeners,
Expand All @@ -97,13 +94,28 @@ DimseCStoreServer dimseCStoreServer(
@Autowired(required = false) LegacyProxyService legacyProxyService) {
return new DimseCStoreServer(
cStoreService,
cFindService,
cMoveService,
storageRouter,
properties,
primaryStorageScheme,
associationEventListeners,
associationAccessPolicies,
legacyProxyService);
}

@Bean
DimseQueryRetrieveServer dimseQueryRetrieveServer(
CFindService cFindService,
CMoveService cMoveService,
StorageRouter storageRouter,
DimseQueryRetrieveProperties qrProperties,
DimseCStoreProperties cStoreProperties,
@Autowired(required = false) LegacyProxyService legacyProxyService) {
return new DimseQueryRetrieveServer(
cFindService,
cMoveService,
storageRouter,
qrProperties,
cStoreProperties,
legacyProxyService);
}
}
Loading
Loading