comparison Samples/FHIR/src/main/java/Main.java @ 31:7579255a14f8

calling destroy() on the FHIR server at shutdown
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jun 2024 20:56:03 +0200
parents 296798e75896
children
comparison
equal deleted inserted replaced
30:296798e75896 31:7579255a14f8
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **/ 22 **/
23 23
24 24
25 import be.uclouvain.orthanc.Callbacks; 25 import be.uclouvain.orthanc.Callbacks;
26 import be.uclouvain.orthanc.ChangeType;
27 import be.uclouvain.orthanc.ResourceType;
26 28
27 import ca.uhn.fhir.context.FhirContext; 29 import ca.uhn.fhir.context.FhirContext;
28 import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy; 30 import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
29 import ca.uhn.fhir.rest.server.IResourceProvider; 31 import ca.uhn.fhir.rest.server.IResourceProvider;
30 import ca.uhn.fhir.rest.server.RestfulServer; 32 import ca.uhn.fhir.rest.server.RestfulServer;
37 import java.util.Properties; 39 import java.util.Properties;
38 import javax.servlet.ServletException; 40 import javax.servlet.ServletException;
39 41
40 42
41 public class Main extends RestfulServer { 43 public class Main extends RestfulServer {
42 Main() throws ServletException { 44 Main() {
43 setFhirContext(FhirContext.forR5()); 45 setFhirContext(FhirContext.forR5());
44 46
45 setServerName("Orthanc FHIR server"); 47 setServerName("Orthanc FHIR server");
46 48
47 try (InputStream is = Main.class.getResourceAsStream("app.properties")) { 49 try (InputStream is = Main.class.getResourceAsStream("app.properties")) {
64 resourceProviders.add(new ImagingStudyProvider(connection)); 66 resourceProviders.add(new ImagingStudyProvider(connection));
65 resourceProviders.add(new EndpointProvider(connection)); 67 resourceProviders.add(new EndpointProvider(connection));
66 setResourceProviders(resourceProviders); 68 setResourceProviders(resourceProviders);
67 } 69 }
68 70
71 private static Main main = new Main();
72
69 static { 73 static {
70 Main main;
71
72 try { 74 try {
73 main = new Main();
74 main.init(new MockServletConfig()); 75 main.init(new MockServletConfig());
75 } catch (ServletException e) { 76 } catch (ServletException e) {
76 throw new RuntimeException("Cannot start the HAPI FHIR server"); 77 throw new RuntimeException("Cannot start the HAPI FHIR server");
77 } 78 }
78 79
80 Callbacks.register(new Callbacks.OnChange() {
81 @Override
82 public void call(ChangeType changeType, ResourceType resourceType, String resourceId) {
83 if (changeType == ChangeType.ORTHANC_STOPPED) {
84 main.destroy();
85 }
86 }
87 });
88
79 Callbacks.register("/fhir(/.*)", new FhirRequestHandler(main)); 89 Callbacks.register("/fhir(/.*)", new FhirRequestHandler(main));
80 Callbacks.register("/fhir", new FhirRequestHandler(main)); 90 Callbacks.register("/fhir", new FhirRequestHandler(main));
81 } 91 }
82 } 92 }