comparison Samples/FHIR/src/main/java/Main.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.Callbacks;
26 import be.uclouvain.orthanc.Functions;
27
28 import ca.uhn.fhir.context.FhirContext;
29 import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
30 import ca.uhn.fhir.rest.server.IResourceProvider;
31 import ca.uhn.fhir.rest.server.RestfulServer;
32 import org.json.JSONArray;
33 import org.json.JSONObject;
34 import org.springframework.mock.web.MockServletConfig;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40 import javax.servlet.ServletException;
41
42
43 public class Main extends RestfulServer {
44 Main() throws ServletException {
45 setFhirContext(FhirContext.forR5());
46
47 FhirConfiguration configuration = new FhirConfiguration();
48 setServerAddressStrategy(new HardcodedServerAddressStrategy(configuration.getServerBaseUrl()));
49
50 configuration.getDicomWebBaseUrl();
51
52 IOrthancConnection connection = new OrthancPluginConnection();
53
54 List<IResourceProvider> resourceProviders = new ArrayList<IResourceProvider>();
55 resourceProviders.add(new PatientProvider(connection));
56 resourceProviders.add(new ImagingStudyProvider(connection));
57 resourceProviders.add(new EndpointProvider(connection));
58 setResourceProviders(resourceProviders);
59 }
60
61 static {
62 Main main;
63
64 try {
65 main = new Main();
66 main.init(new MockServletConfig());
67 } catch (ServletException e) {
68 throw new RuntimeException("Cannot start the HAPI FHIR server");
69 }
70
71 Callbacks.register("/fhir(/.*)", new FhirRequestHandler(main));
72 Callbacks.register("/fhir", new FhirRequestHandler(main));
73 }
74 }