Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM2-642: Improve performance of loading locations by tag #547

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ jobs:
- name: Build with Maven
id: build_with_maven
run: |
mvn verify --batch-mode -P integration-test --file pom.xml
mvn clean verify --batch-mode -P integration-test --file pom.xml
- uses: actions/upload-artifact@v4
with:
name: build_artifact
path: ${{ github.workspace }}/omod/target
path: ${{ github.workspace }}/omod/target/*.omod
- name: Send data to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
23 changes: 22 additions & 1 deletion api/src/main/java/org/openmrs/module/fhir2/FhirActivator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import ca.uhn.fhir.rest.server.IResourceProvider;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.openmrs.api.context.Context;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleException;
Expand All @@ -36,6 +37,7 @@
import org.openmrs.module.fhir2.api.spi.ModuleLifecycleListener;
import org.openmrs.module.fhir2.api.spi.ServiceClassLoader;
import org.openmrs.module.fhir2.api.translators.FhirTranslator;
import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder;
import org.openmrs.module.fhir2.model.GroupMember;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
Expand All @@ -53,6 +55,8 @@ public class FhirActivator extends BaseModuleActivator implements ApplicationCon
@Getter
private static ConfigurableApplicationContext applicationContext;

private static FhirGlobalPropertyHolder globalPropertyHolder = null;

private final Map<String, Set<Class<?>>> services = new HashMap<>();

private final List<ModuleLifecycleListener> lifecycleListeners = new ArrayList<>();
Expand All @@ -76,12 +80,24 @@ public void started() {

@Override
public void willRefreshContext() {
if (globalPropertyHolder != null) {
Context.getAdministrationService().removeGlobalPropertyListener(globalPropertyHolder);
}

lifecycleListeners.forEach(ModuleLifecycleListener::willRefresh);
unloadModules();
}

@Override
public void contextRefreshed() {
if (globalPropertyHolder == null) {
globalPropertyHolder = new FhirGlobalPropertyHolder();
}

FhirGlobalPropertyHolder.reset();

Context.getAdministrationService().addGlobalPropertyListener(globalPropertyHolder);

if (!started) {
return;
}
Expand All @@ -96,12 +112,17 @@ public void contextRefreshed() {
public void willStop() {
lifecycleListeners.forEach(ModuleLifecycleListener::willStop);
unloadModules();

if (globalPropertyHolder != null) {
Context.getAdministrationService().removeGlobalPropertyListener(globalPropertyHolder);
}
}

@Override
public void stopped() {
lifecycleListeners.forEach(ModuleLifecycleListener::stopped);

globalPropertyHolder = null;
started = false;
log.info("Shutdown FHIR");
}
Expand All @@ -117,7 +138,7 @@ public void removeModuleLifecycleLister(@Nonnull ModuleLifecycleListener lifecyc
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
public void setApplicationContext(@Nonnull ApplicationContext applicationContext) throws BeansException {
if (applicationContext instanceof ConfigurableApplicationContext) {
FhirActivator.applicationContext = (ConfigurableApplicationContext) applicationContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface FhirGlobalPropertyService {

String getGlobalProperty(String property) throws APIException;

Integer getGlobalProperty(String property, Integer defaultValue);
int getGlobalPropertyAsInteger(String property, int defaultValue);

String getGlobalProperty(String property, String defaultValue);

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,30 @@
import lombok.Setter;
import org.openmrs.api.APIException;
import org.openmrs.module.fhir2.api.FhirGlobalPropertyService;
import org.openmrs.module.fhir2.api.dao.FhirGlobalPropertyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Transactional
@Setter(AccessLevel.PACKAGE)
public class FhirGlobalPropertyServiceImpl implements FhirGlobalPropertyService {

@Autowired
private FhirGlobalPropertyDao dao;

@Override
@Transactional(readOnly = true)
public String getGlobalProperty(String property) throws APIException {
return dao.getGlobalProperty(property);
return FhirGlobalPropertyHolder.getGlobalProperty(property);
}

@Override
@Transactional(readOnly = true)
public Integer getGlobalProperty(String property, Integer defaultValue) {
try {
return Integer.valueOf(getGlobalProperty(property, String.valueOf(defaultValue)));
}
catch (NumberFormatException e) {
return defaultValue;
}
public int getGlobalPropertyAsInteger(String property, int defaultValue) {
return FhirGlobalPropertyHolder.getGlobalPropertyAsInteger(property, defaultValue);
}

@Override
@Transactional(readOnly = true)
public String getGlobalProperty(String property, String defaultValue) {
return this.getGlobalProperty(property) == null ? defaultValue : this.getGlobalProperty(property);
return FhirGlobalPropertyHolder.getGlobalProperty(property, defaultValue);
}

@Override
@Transactional(readOnly = true)
public Map<String, String> getGlobalProperties(String... properties) {
return dao.getGlobalProperties(properties);
return FhirGlobalPropertyHolder.getGlobalProperties(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public List<IBaseResource> getResources(int fromIndex, int toIndex) {
@Override
public Integer preferredPageSize() {
if (pageSize == null) {
pageSize = globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
pageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
}

return pageSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public List<IBaseResource> getResources(int fromIndex, int toIndex) {
@Override
public Integer preferredPageSize() {
if (pageSize == null) {
pageSize = globalPropertyService.getGlobalProperty(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
pageSize = globalPropertyService.getGlobalPropertyAsInteger(FhirConstants.OPENMRS_FHIR_DEFAULT_PAGE_SIZE, 10);
}

return pageSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

@Component
@Setter(AccessLevel.PACKAGE)
public class AllergyIntoleranceTranslatorImpl extends BaseReferenceHandlingTranslator implements AllergyIntoleranceTranslator {
public class AllergyIntoleranceTranslatorImpl implements AllergyIntoleranceTranslator {

@Autowired
private PractitionerReferenceTranslator<User> practitionerReferenceTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ public DiagnosticReport toFhirResource(@Nonnull FhirDiagnosticReport fhirDiagnos
diagnosticReport.setId(fhirDiagnosticReport.getUuid());

if (fhirDiagnosticReport.getStatus() != null) {
diagnosticReport
.setStatus(DiagnosticReport.DiagnosticReportStatus.valueOf(fhirDiagnosticReport.getStatus().toString()));
try {
diagnosticReport.setStatus(
DiagnosticReport.DiagnosticReportStatus.valueOf(fhirDiagnosticReport.getStatus().toString()));
}
catch (IllegalArgumentException e) {
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
}
} else {
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package org.openmrs.module.fhir2.api.translators.impl;

import static org.apache.commons.lang3.Validate.notNull;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReference;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;

import javax.annotation.Nonnull;

Expand All @@ -24,7 +26,7 @@

@Component
@Setter(AccessLevel.PACKAGE)
public class EncounterLocationTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterLocationTranslator {
public class EncounterLocationTranslatorImpl implements EncounterLocationTranslator {

@Autowired
private FhirLocationDao locationDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package org.openmrs.module.fhir2.api.translators.impl;

import static org.apache.commons.lang3.Validate.notNull;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createPractitionerReference;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;

import javax.annotation.Nonnull;

Expand All @@ -27,7 +29,7 @@

@Component
@Setter(AccessLevel.PACKAGE)
public class EncounterParticipantTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterParticipantTranslator {
public class EncounterParticipantTranslatorImpl implements EncounterParticipantTranslator {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
package org.openmrs.module.fhir2.api.translators.impl;

import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createEncounterReference;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType;

import javax.annotation.Nonnull;

import lombok.AccessLevel;
Expand All @@ -23,7 +27,7 @@

@Component
@Setter(AccessLevel.PACKAGE)
public class EncounterReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements EncounterReferenceTranslator<Encounter> {
public class EncounterReferenceTranslatorImpl implements EncounterReferenceTranslator<Encounter> {

@Autowired
private FhirEncounterDao encounterDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public PatientProgram toOpenmrsType(@Nonnull EpisodeOfCare episodeOfCare) {

@Override
public PatientProgram toOpenmrsType(@Nonnull PatientProgram patientProgram, @Nonnull EpisodeOfCare episodeOfCare) {
throw new UnsupportedOperationException("Translation from FHIR resource EpisodeOfCare to OpenMRS object PatientProgram is not supported.");
throw new UnsupportedOperationException(
"Translation from FHIR resource EpisodeOfCare to OpenMRS object PatientProgram is not supported.");
}

private List<CodeableConcept> getType(PatientProgram patientProgram) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
package org.openmrs.module.fhir2.api.translators.impl;

import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.createLocationReference;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceId;
import static org.openmrs.module.fhir2.api.translators.impl.ReferenceHandlingTranslator.getReferenceType;

import javax.annotation.Nonnull;

import lombok.AccessLevel;
Expand All @@ -23,7 +27,7 @@

@Component
@Setter(AccessLevel.PACKAGE)
public class LocationReferenceTranslatorImpl extends BaseReferenceHandlingTranslator implements LocationReferenceTranslator {
public class LocationReferenceTranslatorImpl implements LocationReferenceTranslator {

@Autowired
private FhirLocationDao locationDao;
Expand Down
Loading
Loading