Mercurial > hg > orthanc-java
comparison Samples/FHIR/src/main/java/IOrthancConnection.java @ 11:8d876a4f541b
added sample FHIR server
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 21 Oct 2023 09:53:25 +0200 |
parents | |
children | 0dc05fe76bd5 |
comparison
equal
deleted
inserted
replaced
10:6b9433432ee0 | 11:8d876a4f541b |
---|---|
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 org.json.JSONArray; | |
26 import org.json.JSONObject; | |
27 | |
28 import java.nio.charset.StandardCharsets; | |
29 import java.util.HashMap; | |
30 import java.util.Map; | |
31 | |
32 public interface IOrthancConnection { | |
33 public byte[] doGet(String uri, | |
34 Map<String, String> parameters); | |
35 | |
36 public byte[] doPost(String uri, | |
37 byte[] body); | |
38 | |
39 public static String formatGetParameters(Map<String, String> parameters) { | |
40 String result = ""; | |
41 | |
42 for (Map.Entry<String, String> entry : parameters.entrySet()) { | |
43 String item; | |
44 if (entry.getValue().isEmpty()) { | |
45 item = entry.getKey(); | |
46 } else { | |
47 item = entry.getKey() + "=" + entry.getValue(); | |
48 } | |
49 | |
50 if (result.isEmpty()) { | |
51 result = "?" + item; | |
52 } else { | |
53 result = result + "&" + item; | |
54 } | |
55 } | |
56 | |
57 return result; | |
58 } | |
59 | |
60 public static JSONObject getJSONObject(IOrthancConnection orthanc, | |
61 String uri, | |
62 Map<String, String> parameters) { | |
63 byte[] a = orthanc.doGet(uri, parameters); | |
64 return new JSONObject(new String(a, StandardCharsets.UTF_8)); | |
65 } | |
66 | |
67 public static JSONArray getJSONArray(IOrthancConnection orthanc, | |
68 String uri, | |
69 Map<String, String> parameters) { | |
70 byte[] a = orthanc.doGet(uri, parameters); | |
71 return new JSONArray(new String(a, StandardCharsets.UTF_8)); | |
72 } | |
73 | |
74 public static boolean hasPluginInstalled(IOrthancConnection orthanc, | |
75 String plugin) { | |
76 Map<String, String> empty = new HashMap<>(); | |
77 JSONArray plugins = IOrthancConnection.getJSONArray(orthanc, "/plugins", empty); | |
78 | |
79 for (int i = 0; i < plugins.length(); i++) { | |
80 if (plugins.getString(i).equals(plugin)) { | |
81 return true; | |
82 } | |
83 } | |
84 | |
85 return false; | |
86 } | |
87 } |