Skip to content

Commit

Permalink
RA-2052 - Do not set global property on startup if it is already conf…
Browse files Browse the repository at this point in the history
…igured (#147)
  • Loading branch information
mseaton authored Oct 4, 2024
1 parent 975d6f2 commit 657d5ae
Showing 1 changed file with 8 additions and 7 deletions.
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

0 comments on commit 657d5ae

Please sign in to comment.