# HG changeset patch # User Sebastien Jodogne # Date 1697710846 -7200 # Node ID 6b9433432ee0b340624f1607c35261a5525f1fb2 # Parent 88c1614fb3dc6f32fe474055a6e9ff3cb3405271 added dcm4che sample diff -r 88c1614fb3dc -r 6b9433432ee0 .hgignore --- 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/ diff -r 88c1614fb3dc -r 6b9433432ee0 .reuse/dep5 --- 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 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 diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Basic/NOTES.txt --- 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: diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Basic/configuration.json --- 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" } } diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Basic/configuration.json.license --- /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 diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Basic/pom.xml --- 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 @@ OrthancJava - Basic + Sample 0.0-SNAPSHOT diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Dcm4Che/NOTES.txt --- /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 diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Dcm4Che/configuration.json --- /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" + } +} diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Dcm4Che/configuration.json.license --- /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 diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Dcm4Che/pom.xml --- /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 @@ + + + + + + 4.0.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + + + package + + single + + + + + + jar-with-dependencies + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-source + generate-sources + + add-source + + + + ${project.basedir}/../../JavaSDK/be/uclouvain/orthanc + + + + + + + + + + OrthancJava + Sample + 0.0-SNAPSHOT + + + + dcm4che + https://www.dcm4che.org/maven2/ + + + + + + + org.dcm4che + dcm4che-core + 5.29.1 + + + diff -r 88c1614fb3dc -r 6b9433432ee0 Samples/Dcm4Che/src/main/java/Main.java --- /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 . + **/ + + +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 headers, + Map 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()); + } + } + } + }); + } +}