|
4 | 4 |
|
5 | 5 | import org.hl7.fhir.instance.model.api.IBaseBundle; |
6 | 6 | import org.hl7.fhir.instance.model.api.IBaseResource; |
| 7 | +import org.hl7.fhir.r4.model.CapabilityStatement; |
7 | 8 | import org.slf4j.Logger; |
8 | 9 | import org.slf4j.LoggerFactory; |
| 10 | +import org.springframework.context.event.ContextRefreshedEvent; |
| 11 | +import org.springframework.context.event.EventListener; |
9 | 12 |
|
10 | 13 | import ca.uhn.fhir.context.FhirContext; |
11 | 14 | import ca.uhn.fhir.interceptor.api.IInterceptorService; |
@@ -99,6 +102,33 @@ public HapiFhirClientFactory(FhirContext fhirContext, String serverBase, String |
99 | 102 | clientFactory = null; |
100 | 103 | } |
101 | 104 |
|
| 105 | + @EventListener({ ContextRefreshedEvent.class }) |
| 106 | + public void onContextRefreshedEvent(ContextRefreshedEvent event) |
| 107 | + { |
| 108 | + if (isConfigured()) |
| 109 | + { |
| 110 | + try |
| 111 | + { |
| 112 | + logger.info( |
| 113 | + "Testing connection to GECCO FHIR server with {basicAuthUsername: {}, basicAuthPassword: {}, bearerToken: {}, serverBase: {}}", |
| 114 | + basicAuthUsername, basicAuthPassword != null ? "***" : "null", |
| 115 | + bearerToken != null ? "***" : "null", serverBase); |
| 116 | + |
| 117 | + CapabilityStatement statement = getFhirStoreClient().capabilities().ofType(CapabilityStatement.class) |
| 118 | + .execute(); |
| 119 | + |
| 120 | + logger.info("Connection test OK {} - {}", statement.getSoftware().getName(), |
| 121 | + statement.getSoftware().getVersion()); |
| 122 | + } |
| 123 | + catch (Exception e) |
| 124 | + { |
| 125 | + logger.error("Error while testing connection to GECCO FHIR server", e); |
| 126 | + } |
| 127 | + } |
| 128 | + else |
| 129 | + logger.warn("GECCO FHIR server Client stub implementation, no connection test performed"); |
| 130 | + } |
| 131 | + |
102 | 132 | protected boolean isConfigured() |
103 | 133 | { |
104 | 134 | return serverBase != null && !serverBase.isEmpty(); |
|
0 commit comments