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

RA-2052 - Do not set global property on startup if it is already conf… #147

Merged
merged 1 commit into from
Oct 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.openmrs.module.registrationapp;


import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.PatientIdentifierType;
Expand All @@ -36,7 +37,6 @@ public class RegistrationAppActivator extends BaseModuleActivator {
@Override
public void started() {
setupIdentifierTypeGlobalProperties(Context.getAdministrationService(), Context.getService(IdentifierSourceService.class));

super.started();
}

Expand All @@ -45,12 +45,13 @@ private void setupIdentifierTypeGlobalProperties(AdministrationService administr
// identifier type from the EMR API module, if possible. (This may not be possible if things aren't configured right,
// e.g. due to module startup order, in which case we log a warning and continue.)
try {
EmrApiProperties emrApiProperties = Context.getRegisteredComponents(EmrApiProperties.class).iterator().next();
PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();

IdentifierSource sourceForPrimaryType = identifierSourceService.getAutoGenerationOption(primaryIdentifierType).getSource();

administrationService.setGlobalProperty(RegistrationCoreConstants.GP_OPENMRS_IDENTIFIER_SOURCE_ID, sourceForPrimaryType.getId().toString());
String existingValue = administrationService.getGlobalProperty(RegistrationCoreConstants.GP_OPENMRS_IDENTIFIER_SOURCE_ID);
if (StringUtils.isBlank(existingValue)) {
EmrApiProperties emrApiProperties = Context.getRegisteredComponents(EmrApiProperties.class).iterator().next();
PatientIdentifierType primaryIdentifierType = emrApiProperties.getPrimaryIdentifierType();
IdentifierSource sourceForPrimaryType = identifierSourceService.getAutoGenerationOption(primaryIdentifierType).getSource();
administrationService.setGlobalProperty(RegistrationCoreConstants.GP_OPENMRS_IDENTIFIER_SOURCE_ID, sourceForPrimaryType.getId().toString());
}
}
catch (Exception ex) {
log.warn("Failed to set global property for " + RegistrationCoreConstants.GP_OPENMRS_IDENTIFIER_SOURCE_ID + " based on " + EmrApiConstants.PRIMARY_IDENTIFIER_TYPE + ". Will try again at next module startup.", ex);
Expand Down
Loading