Mercurial > hg > orthanc-java
changeset 10:6b9433432ee0
added dcm4che sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Oct 2023 12:20:46 +0200 (19 months ago) |
parents | 88c1614fb3dc |
children | 8d876a4f541b |
files | .hgignore .reuse/dep5 Samples/Basic/NOTES.txt Samples/Basic/configuration.json Samples/Basic/configuration.json.license Samples/Basic/pom.xml Samples/Dcm4Che/NOTES.txt Samples/Dcm4Che/configuration.json Samples/Dcm4Che/configuration.json.license Samples/Dcm4Che/pom.xml Samples/Dcm4Che/src/main/java/Main.java |
diffstat | 11 files changed, 196 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Thu Oct 19 11:55:38 2023 +0200 +++ b/.hgignore Thu Oct 19 12:20:46 2023 +0200 @@ -14,3 +14,6 @@ Samples/Basic/.idea/ Samples/Basic/OrthancStorage/ Samples/Basic/target/ +Samples/Dcm4Che/.idea/ +Samples/Dcm4Che/OrthancStorage/ +Samples/Dcm4Che/target/
--- a/.reuse/dep5 Thu Oct 19 11:55:38 2023 +0200 +++ b/.reuse/dep5 Thu Oct 19 12:20:46 2023 +0200 @@ -3,7 +3,7 @@ Upstream-Contact: Sebastien Jodogne <s.jodogne@gmail.com> Source: https://orthanc.uclouvain.be/ -Files: NEWS README Samples/Basic/NOTES.txt +Files: NEWS README Samples/Basic/NOTES.txt Samples/Dcm4Che/NOTES.txt Copyright: 2023 Sebastien Jodogne, UCLouvain, Belgium License: CC0-1.0
--- a/Samples/Basic/NOTES.txt Thu Oct 19 11:55:38 2023 +0200 +++ b/Samples/Basic/NOTES.txt Thu Oct 19 12:20:46 2023 +0200 @@ -1,4 +1,6 @@ -To run this sample Java plugin: + +This sample plugin installs a simple "Hello, world" route in the REST +API. To run this sample Java plugin: (1) Make sure to build the C++ plugin:
--- a/Samples/Basic/configuration.json Thu Oct 19 11:55:38 2023 +0200 +++ b/Samples/Basic/configuration.json Thu Oct 19 12:20:46 2023 +0200 @@ -2,7 +2,7 @@ "Plugins" : [ "../../Plugin/Build" ], "Java" : { "Enabled" : true, - "Classpath" : "target/Basic-0.0-SNAPSHOT-jar-with-dependencies.jar", + "Classpath" : "target/Sample-0.0-SNAPSHOT-jar-with-dependencies.jar", "InitializationClass" : "Main" } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Basic/configuration.json.license Thu Oct 19 12:20:46 2023 +0200 @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium +# SPDX-License-Identifier: GPL-3.0-or-later
--- a/Samples/Basic/pom.xml Thu Oct 19 11:55:38 2023 +0200 +++ b/Samples/Basic/pom.xml Thu Oct 19 12:20:46 2023 +0200 @@ -62,7 +62,7 @@ </build> <groupId>OrthancJava</groupId> - <artifactId>Basic</artifactId> + <artifactId>Sample</artifactId> <version>0.0-SNAPSHOT</version> <dependencies>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Dcm4Che/NOTES.txt Thu Oct 19 12:20:46 2023 +0200 @@ -0,0 +1,30 @@ + +This sample plugin shows how to combine Orthanc with the dcm4che +library. To run this sample Java plugin: + + +(1) Make sure to build the C++ plugin: + +# cd ../../Plugin/ +# mkdir Build +# cd Build +# cmake .. -DCMAKE_BUILD_TYPE=Release +# make -j4 + + +(2) Compile the Java plugin using Maven: + +# cd ../../Samples/Dcm4Che +# mvn package + + +(3) Start Orthanc: + +On Ubuntu 22.04: + +# LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/ Orthanc ./configuration.json + + +(4) Send an arbitrary DICOM file to Java: + +# curl http://localhost:8042/dcm4che-parse --data-binary @sample.dcm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Dcm4Che/configuration.json Thu Oct 19 12:20:46 2023 +0200 @@ -0,0 +1,8 @@ +{ + "Plugins" : [ "../../Plugin/Build" ], + "Java" : { + "Enabled" : true, + "Classpath" : "target/Sample-0.0-SNAPSHOT-jar-with-dependencies.jar", + "InitializationClass" : "Main" + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Dcm4Che/configuration.json.license Thu Oct 19 12:20:46 2023 +0200 @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium +# SPDX-License-Identifier: GPL-3.0-or-later
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Dcm4Che/pom.xml Thu Oct 19 12:20:46 2023 +0200 @@ -0,0 +1,83 @@ +<?xml version='1.0' encoding='UTF-8'?> + +<!-- + + SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium + SPDX-License-Identifier: GPL-3.0-or-later + +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <!-- https://stackoverflow.com/a/1729094 --> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + </plugin> + + <!-- Include the Orthanc Java SDK --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.basedir}/../../JavaSDK/be/uclouvain/orthanc</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> + + <groupId>OrthancJava</groupId> + <artifactId>Sample</artifactId> + <version>0.0-SNAPSHOT</version> + + <repositories> + <repository> + <id>dcm4che</id> + <url>https://www.dcm4che.org/maven2/</url> + </repository> + </repositories> + + <dependencies> + <!-- https://mvnrepository.com/artifact/org.dcm4che/dcm4che-core --> + <dependency> + <groupId>org.dcm4che</groupId> + <artifactId>dcm4che-core</artifactId> + <version>5.29.1</version> + </dependency> + </dependencies> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Dcm4Che/src/main/java/Main.java Thu Oct 19 12:20:46 2023 +0200 @@ -0,0 +1,62 @@ +/** + * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +/** + * Java plugin for Orthanc + * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +import be.uclouvain.orthanc.Callbacks; +import be.uclouvain.orthanc.RestOutput; +import be.uclouvain.orthanc.HttpMethod; + +import org.dcm4che3.data.Attributes; +import org.dcm4che3.io.DicomInputStream; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Map; + +public class Main { + static { + Callbacks.register("/dcm4che-parse", new Callbacks.OnRestRequest() { + @Override + public void call(RestOutput output, + HttpMethod method, + String uri, + String[] regularExpressionGroups, + Map<String, String> headers, + Map<String, String> getParameters, + byte[] body) { + if (method != HttpMethod.POST) { + output.sendMethodNotAllowed("POST"); + } else { + ByteArrayInputStream stream = new ByteArrayInputStream(body); + + try (DicomInputStream din = new DicomInputStream(stream)) { + Attributes dataset = din.readDataset(); + output.answerBuffer(dataset.toString().getBytes(), "text/plain"); + } catch (IOException e) { + output.sendHttpStatus((short) 400, "Cannot parse DICOM file\n".getBytes()); + } + } + } + }); + } +}