Skip to content

Commit 983b724

Browse files
authored
FM2-642: Improve performance of loading locations by tag (openmrs#547) (openmrs#552)
1 parent 9707c4d commit 983b724

File tree

64 files changed

+481
-614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+481
-614
lines changed

api/src/main/java/org/openmrs/module/fhir2/FhirActivator.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import ca.uhn.fhir.rest.server.IResourceProvider;
2828
import lombok.Getter;
2929
import lombok.extern.slf4j.Slf4j;
30+
import org.openmrs.api.context.Context;
3031
import org.openmrs.module.BaseModuleActivator;
3132
import org.openmrs.module.Module;
3233
import org.openmrs.module.ModuleException;
@@ -36,6 +37,7 @@
3637
import org.openmrs.module.fhir2.api.spi.ModuleLifecycleListener;
3738
import org.openmrs.module.fhir2.api.spi.ServiceClassLoader;
3839
import org.openmrs.module.fhir2.api.translators.FhirTranslator;
40+
import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder;
3941
import org.openmrs.module.fhir2.model.GroupMember;
4042
import org.springframework.beans.BeansException;
4143
import org.springframework.context.ApplicationContext;
@@ -53,6 +55,8 @@ public class FhirActivator extends BaseModuleActivator implements ApplicationCon
5355
@Getter
5456
private static ConfigurableApplicationContext applicationContext;
5557

58+
private static FhirGlobalPropertyHolder globalPropertyHolder = null;
59+
5660
private final Map<String, Set<Class<?>>> services = new HashMap<>();
5761

5862
private final List<ModuleLifecycleListener> lifecycleListeners = new ArrayList<>();
@@ -65,8 +69,6 @@ public void started() {
6569
throw new ModuleException("Cannot load FHIR2 module as the main application context is not available");
6670
}
6771

68-
applicationContext.getBean("fhirR4", FhirContext.class).registerCustomType(GroupMember.class);
69-
7072
loadModules();
7173
started = true;
7274
log.info("Started FHIR");
@@ -86,6 +88,13 @@ public void contextRefreshed() {
8688
return;
8789
}
8890

91+
if (globalPropertyHolder == null) {
92+
globalPropertyHolder = new FhirGlobalPropertyHolder();
93+
Context.getAdministrationService().addGlobalPropertyListener(globalPropertyHolder);
94+
}
95+
96+
FhirGlobalPropertyHolder.reset();
97+
8998
applicationContext.getBean("fhirR4", FhirContext.class).registerCustomType(GroupMember.class);
9099
loadModules();
91100

@@ -95,13 +104,18 @@ public void contextRefreshed() {
95104
@Override
96105
public void willStop() {
97106
lifecycleListeners.forEach(ModuleLifecycleListener::willStop);
98-
unloadModules();
107+
108+
if (globalPropertyHolder != null) {
109+
Context.getAdministrationService().removeGlobalPropertyListener(globalPropertyHolder);
110+
}
99111
}
100112

101113
@Override
102114
public void stopped() {
103115
lifecycleListeners.forEach(ModuleLifecycleListener::stopped);
116+
unloadModules();
104117

118+
globalPropertyHolder = null;
105119
started = false;
106120
log.info("Shutdown FHIR");
107121
}
@@ -117,7 +131,7 @@ public void removeModuleLifecycleLister(@Nonnull ModuleLifecycleListener lifecyc
117131
}
118132

119133
@Override
120-
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
134+
public void setApplicationContext(@Nonnull ApplicationContext applicationContext) throws BeansException {
121135
if (applicationContext instanceof ConfigurableApplicationContext) {
122136
FhirActivator.applicationContext = (ConfigurableApplicationContext) applicationContext;
123137
}

api/src/main/java/org/openmrs/module/fhir2/api/FhirGlobalPropertyService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface FhirGlobalPropertyService {
1717

1818
String getGlobalProperty(String property) throws APIException;
1919

20-
Integer getGlobalProperty(String property, Integer defaultValue);
20+
int getGlobalPropertyAsInteger(String property, int defaultValue);
2121

2222
String getGlobalProperty(String property, String defaultValue);
2323

api/src/main/java/org/openmrs/module/fhir2/api/dao/FhirGlobalPropertyDao.java

-29
This file was deleted.

api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirGlobalPropertyDaoImpl.java

-62
This file was deleted.

api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirGlobalPropertyServiceImpl.java

+6-21
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,30 @@
1515
import lombok.Setter;
1616
import org.openmrs.api.APIException;
1717
import org.openmrs.module.fhir2.api.FhirGlobalPropertyService;
18-
import org.openmrs.module.fhir2.api.dao.FhirGlobalPropertyDao;
19-
import org.springframework.beans.factory.annotation.Autowired;
18+
import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder;
2019
import org.springframework.stereotype.Component;
21-
import org.springframework.transaction.annotation.Transactional;
2220

2321
@Component
24-
@Transactional
2522
@Setter(AccessLevel.PACKAGE)
2623
public class FhirGlobalPropertyServiceImpl implements FhirGlobalPropertyService {
2724

28-
@Autowired
29-
private FhirGlobalPropertyDao dao;
30-
3125
@Override
32-
@Transactional(readOnly = true)
3326
public String getGlobalProperty(String property) throws APIException {
34-
return dao.getGlobalProperty(property);
27+
return FhirGlobalPropertyHolder.getGlobalProperty(property);
3528
}
3629

3730
@Override
38-
@Transactional(readOnly = true)
39-
public Integer getGlobalProperty(String property, Integer defaultValue) {
40-
try {
41-
return Integer.valueOf(getGlobalProperty(property, String.valueOf(defaultValue)));
42-
}
43-
catch (NumberFormatException e) {
44-
return defaultValue;
45-
}
31+
public int getGlobalPropertyAsInteger(String property, int defaultValue) {
32+
return FhirGlobalPropertyHolder.getGlobalPropertyAsInteger(property, defaultValue);
4633
}
4734

4835
@Override
49-
@Transactional(readOnly = true)
5036
public String getGlobalProperty(String property, String defaultValue) {
51-
return this.getGlobalProperty(property) == null ? defaultValue : this.getGlobalProperty(property);
37+
return FhirGlobalPropertyHolder.getGlobalProperty(property, defaultValue);
5238
}
5339

5440
@Override
55-
@Transactional(readOnly = true)
5641
public Map<String, String> getGlobalProperties(String... properties) {
57-
return dao.getGlobalProperties(properties);
42+
return FhirGlobalPropertyHolder.getGlobalProperties(properties);
5843
}
5944
}

api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryBundleProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public List<IBaseResource> getResources(int fromIndex, int toIndex) {
9393
@Override
9494
public Integer preferredPageSize() {
9595
if (pageSize == null) {
96-
pageSize = globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
96+
pageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
9797
}
9898

9999
return pageSize;

api/src/main/java/org/openmrs/module/fhir2/api/search/TwoSearchQueryBundleProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public List<IBaseResource> getResources(int fromIndex, int toIndex) {
122122
@Override
123123
public Integer preferredPageSize() {
124124
if (pageSize == null) {
125-
pageSize = globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
125+
pageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
126126
}
127127

128128
return pageSize;

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/AllergyIntoleranceTranslatorImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
@Component
4141
@Setter(AccessLevel.PACKAGE)
42-
public class AllergyIntoleranceTranslatorImpl extends BaseReferenceHandlingTranslator implements AllergyIntoleranceTranslator {
42+
public class AllergyIntoleranceTranslatorImpl implements AllergyIntoleranceTranslator {
4343

4444
@Autowired
4545
private PractitionerReferenceTranslator<User> practitionerReferenceTranslator;

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DiagnosticReportTranslatorImpl.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ public DiagnosticReport toFhirResource(@Nonnull FhirDiagnosticReport fhirDiagnos
6060
diagnosticReport.setId(fhirDiagnosticReport.getUuid());
6161

6262
if (fhirDiagnosticReport.getStatus() != null) {
63-
diagnosticReport
64-
.setStatus(DiagnosticReport.DiagnosticReportStatus.valueOf(fhirDiagnosticReport.getStatus().toString()));
63+
try {
64+
diagnosticReport.setStatus(
65+
DiagnosticReport.DiagnosticReportStatus.valueOf(fhirDiagnosticReport.getStatus().toString()));
66+
}
67+
catch (IllegalArgumentException e) {
68+
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
69+
}
6570
} else {
6671
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
6772
}

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterLocationTranslatorImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
package org.openmrs.module.fhir2.api.translators.impl;
1111

1212
import static org.apache.commons.lang3.Validate.notNull;
13+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReference;
14+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;
1315

1416
import javax.annotation.Nonnull;
1517

@@ -24,7 +26,7 @@
2426

2527
@Component
2628
@Setter(AccessLevel.PACKAGE)
27-
public class EncounterLocationTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterLocationTranslator {
29+
public class EncounterLocationTranslatorImpl implements EncounterLocationTranslator {
2830

2931
@Autowired
3032
private FhirLocationDao locationDao;

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterParticipantTranslatorImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
package org.openmrs.module.fhir2.api.translators.impl;
1111

1212
import static org.apache.commons.lang3.Validate.notNull;
13+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createPractitionerReference;
14+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;
1315

1416
import javax.annotation.Nonnull;
1517

@@ -27,7 +29,7 @@
2729

2830
@Component
2931
@Setter(AccessLevel.PACKAGE)
30-
public class EncounterParticipantTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterParticipantTranslator {
32+
public class EncounterParticipantTranslatorImpl implements EncounterParticipantTranslator {
3133

3234
private static final String DEFAULT_ENCOUNTER_ROLE_UUID_PROPERTY = "fhir2.encounterParticipantComponentUuid";
3335

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/EncounterReferenceTranslatorImpl.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
*/
1010
package org.openmrs.module.fhir2.api.translators.impl;
1111

12+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createEncounterReference;
13+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;
14+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType;
15+
1216
import javax.annotation.Nonnull;
1317

1418
import lombok.AccessLevel;
@@ -23,7 +27,7 @@
2327

2428
@Component
2529
@Setter(AccessLevel.PACKAGE)
26-
public class EncounterReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterReferenceTranslator<Encounter> {
30+
public class EncounterReferenceTranslatorImpl implements EncounterReferenceTranslator<Encounter> {
2731

2832
@Autowired
2933
private FhirEncounterDao encounterDao;

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/LocationReferenceTranslatorImpl.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
*/
1010
package org.openmrs.module.fhir2.api.translators.impl;
1111

12+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReference;
13+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;
14+
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType;
15+
1216
import javax.annotation.Nonnull;
1317

1418
import lombok.AccessLevel;
@@ -23,7 +27,7 @@
2327

2428
@Component
2529
@Setter(AccessLevel.PACKAGE)
26-
public class LocationReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements LocationReferenceTranslator {
30+
public class LocationReferenceTranslatorImpl implements LocationReferenceTranslator {
2731

2832
@Autowired
2933
private FhirLocationDao locationDao;

0 commit comments

Comments
 (0)