Mercurial > hg > orthanc-java
comparison Samples/Dcm4Che/src/main/java/Main.java @ 10:6b9433432ee0
added dcm4che sample
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Oct 2023 12:20:46 +0200 |
parents | |
children | b69bc09e2969 |
comparison
equal
deleted
inserted
replaced
9:88c1614fb3dc | 10:6b9433432ee0 |
---|---|
1 /** | |
2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium | |
3 * SPDX-License-Identifier: GPL-3.0-or-later | |
4 */ | |
5 | |
6 /** | |
7 * Java plugin for Orthanc | |
8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium | |
9 * | |
10 * This program is free software: you can redistribute it and/or | |
11 * modify it under the terms of the GNU General Public License as | |
12 * published by the Free Software Foundation, either version 3 of the | |
13 * License, or (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, but | |
16 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 * General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 **/ | |
23 | |
24 | |
25 import be.uclouvain.orthanc.Callbacks; | |
26 import be.uclouvain.orthanc.RestOutput; | |
27 import be.uclouvain.orthanc.HttpMethod; | |
28 | |
29 import org.dcm4che3.data.Attributes; | |
30 import org.dcm4che3.io.DicomInputStream; | |
31 | |
32 import java.io.ByteArrayInputStream; | |
33 import java.io.IOException; | |
34 import java.util.Map; | |
35 | |
36 public class Main { | |
37 static { | |
38 Callbacks.register("/dcm4che-parse", new Callbacks.OnRestRequest() { | |
39 @Override | |
40 public void call(RestOutput output, | |
41 HttpMethod method, | |
42 String uri, | |
43 String[] regularExpressionGroups, | |
44 Map<String, String> headers, | |
45 Map<String, String> getParameters, | |
46 byte[] body) { | |
47 if (method != HttpMethod.POST) { | |
48 output.sendMethodNotAllowed("POST"); | |
49 } else { | |
50 ByteArrayInputStream stream = new ByteArrayInputStream(body); | |
51 | |
52 try (DicomInputStream din = new DicomInputStream(stream)) { | |
53 Attributes dataset = din.readDataset(); | |
54 output.answerBuffer(dataset.toString().getBytes(), "text/plain"); | |
55 } catch (IOException e) { | |
56 output.sendHttpStatus((short) 400, "Cannot parse DICOM file\n".getBytes()); | |
57 } | |
58 } | |
59 } | |
60 }); | |
61 } | |
62 } |