27
27
import ca .uhn .fhir .rest .server .IResourceProvider ;
28
28
import lombok .Getter ;
29
29
import lombok .extern .slf4j .Slf4j ;
30
+ import org .openmrs .api .context .Context ;
30
31
import org .openmrs .module .BaseModuleActivator ;
31
32
import org .openmrs .module .Module ;
32
33
import org .openmrs .module .ModuleException ;
36
37
import org .openmrs .module .fhir2 .api .spi .ModuleLifecycleListener ;
37
38
import org .openmrs .module .fhir2 .api .spi .ServiceClassLoader ;
38
39
import org .openmrs .module .fhir2 .api .translators .FhirTranslator ;
40
+ import org .openmrs .module .fhir2 .api .util .FhirGlobalPropertyHolder ;
39
41
import org .openmrs .module .fhir2 .model .GroupMember ;
40
42
import org .springframework .beans .BeansException ;
41
43
import org .springframework .context .ApplicationContext ;
@@ -53,6 +55,8 @@ public class FhirActivator extends BaseModuleActivator implements ApplicationCon
53
55
@ Getter
54
56
private static ConfigurableApplicationContext applicationContext ;
55
57
58
+ private static FhirGlobalPropertyHolder globalPropertyHolder = null ;
59
+
56
60
private final Map <String , Set <Class <?>>> services = new HashMap <>();
57
61
58
62
private final List <ModuleLifecycleListener > lifecycleListeners = new ArrayList <>();
@@ -65,8 +69,6 @@ public void started() {
65
69
throw new ModuleException ("Cannot load FHIR2 module as the main application context is not available" );
66
70
}
67
71
68
- applicationContext .getBean ("fhirR4" , FhirContext .class ).registerCustomType (GroupMember .class );
69
-
70
72
loadModules ();
71
73
started = true ;
72
74
log .info ("Started FHIR" );
@@ -86,6 +88,13 @@ public void contextRefreshed() {
86
88
return ;
87
89
}
88
90
91
+ if (globalPropertyHolder == null ) {
92
+ globalPropertyHolder = new FhirGlobalPropertyHolder ();
93
+ Context .getAdministrationService ().addGlobalPropertyListener (globalPropertyHolder );
94
+ }
95
+
96
+ FhirGlobalPropertyHolder .reset ();
97
+
89
98
applicationContext .getBean ("fhirR4" , FhirContext .class ).registerCustomType (GroupMember .class );
90
99
loadModules ();
91
100
@@ -95,13 +104,18 @@ public void contextRefreshed() {
95
104
@ Override
96
105
public void willStop () {
97
106
lifecycleListeners .forEach (ModuleLifecycleListener ::willStop );
98
- unloadModules ();
107
+
108
+ if (globalPropertyHolder != null ) {
109
+ Context .getAdministrationService ().removeGlobalPropertyListener (globalPropertyHolder );
110
+ }
99
111
}
100
112
101
113
@ Override
102
114
public void stopped () {
103
115
lifecycleListeners .forEach (ModuleLifecycleListener ::stopped );
116
+ unloadModules ();
104
117
118
+ globalPropertyHolder = null ;
105
119
started = false ;
106
120
log .info ("Shutdown FHIR" );
107
121
}
@@ -117,7 +131,7 @@ public void removeModuleLifecycleLister(@Nonnull ModuleLifecycleListener lifecyc
117
131
}
118
132
119
133
@ Override
120
- public void setApplicationContext (ApplicationContext applicationContext ) throws BeansException {
134
+ public void setApplicationContext (@ Nonnull ApplicationContext applicationContext ) throws BeansException {
121
135
if (applicationContext instanceof ConfigurableApplicationContext ) {
122
136
FhirActivator .applicationContext = (ConfigurableApplicationContext ) applicationContext ;
123
137
}
0 commit comments