Mercurial > hg > orthanc-java
comparison Samples/FHIR/src/main/java/FhirConfiguration.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 be.uclouvain.orthanc.Functions; | |
26 | |
27 import org.json.JSONObject; | |
28 | |
29 import java.net.MalformedURLException; | |
30 import java.net.URI; | |
31 import java.net.URISyntaxException; | |
32 import java.net.URL; | |
33 | |
34 public class FhirConfiguration { | |
35 static private final String KEY_FHIR = "FHIR"; | |
36 static private final String KEY_DICOM_WEB = "DicomWeb"; | |
37 static private final String KEY_ROOT = "Root"; | |
38 static private final String KEY_BASE_URL = "BaseUrl"; | |
39 | |
40 private String serverBaseUrl = "http://localhost:8042/fhir"; | |
41 private String dicomWebRelativeUri = "../dicom-web"; | |
42 | |
43 FhirConfiguration() { | |
44 JSONObject configuration = new JSONObject(Functions.getConfiguration()); | |
45 | |
46 if (configuration.has(KEY_FHIR)) { | |
47 JSONObject fhir = configuration.getJSONObject(KEY_FHIR); | |
48 if (fhir.has(KEY_BASE_URL)) { | |
49 serverBaseUrl = fhir.getString(KEY_BASE_URL); | |
50 } | |
51 } | |
52 | |
53 if (configuration.has(KEY_DICOM_WEB)) { | |
54 JSONObject dicomWeb = configuration.getJSONObject(KEY_DICOM_WEB); | |
55 if (dicomWeb.has(KEY_ROOT)) { | |
56 dicomWebRelativeUri = "../" + dicomWeb.getString(KEY_ROOT); | |
57 } | |
58 } | |
59 | |
60 if (!serverBaseUrl.endsWith("/")) { | |
61 serverBaseUrl = serverBaseUrl + "/"; | |
62 } | |
63 } | |
64 | |
65 public String getServerBaseUrl() { | |
66 return serverBaseUrl; | |
67 } | |
68 | |
69 public String getDicomWebBaseUrl() { | |
70 /** | |
71 * From URL: <scheme>://<authority><path>?<query>#<fragment> | |
72 */ | |
73 | |
74 try { | |
75 URL url = new URL(serverBaseUrl); | |
76 URI uri = new URI(url.getPath()); | |
77 return url.getProtocol() + "://" + url.getAuthority() + uri.resolve(dicomWebRelativeUri); | |
78 } catch (MalformedURLException | URISyntaxException e) { | |
79 throw new IllegalArgumentException("Bad URL for DICOMweb: " + serverBaseUrl + dicomWebRelativeUri); | |
80 } | |
81 } | |
82 } |