Search in sources :

Example 16 with Module

use of org.openmrs.module.Module in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivator method started.

/**
 * @see ModuleActivator#started()
 */
public void started() {
    try {
        // currently only one of these
        Config config = Context.getRegisteredComponents(Config.class).get(0);
        AdministrationService administrationService = Context.getAdministrationService();
        ReportService reportService = Context.getService(ReportService.class);
        ReportDefinitionService reportDefinitionService = Context.getService(ReportDefinitionService.class);
        SerializedObjectDAO serializedObjectDAO = Context.getRegisteredComponents(SerializedObjectDAO.class).get(0);
        PrinterService printerService = Context.getService(PrinterService.class);
        DispositionService dispositionService = Context.getService(DispositionService.class);
        removeOldPrivileges();
        setDispositionConfig(config, dispositionService);
        // register our custom print handlers
        PrinterSetup.registerPrintHandlers(printerService);
        // set up html forms--this must happen *after* MDS packages are installed, so that forms defined in code/github
        // take precedent over any in MDS packages; therefore we still do this in the Mirebalais module, not PIH Core
        HtmlFormSetup.setupHtmlForms(config);
        // configure default dashboard in coreapps
        updateGlobalProperty(CoreAppsConstants.GP_DASHBOARD_URL, config.getDashboardUrl());
        // configure default visits page in coreapps
        updateGlobalProperty(CoreAppsConstants.GP_VISITS_PAGE_URL, config.getVisitPageUrl());
        // configure default specific visit detail page in coreapps
        updateGlobalProperty(CoreAppsConstants.GP_VISITS_PAGE_WITH_SPECIFIC_URL, config.getVisitsPageWithSpecificUrl());
        if (config.isComponentEnabled(Components.LEGACY_MPI)) {
            LegacyMasterPatientIndexSetup.setupConnectionToMasterPatientIndex(customProperties);
        }
        if (config.isComponentEnabled(Components.ARCHIVES)) {
            ArchivesSetup.setupCloseStaleCreateRequestsTask();
            ArchivesSetup.setupCloseStalePullRequestsTask();
        }
        if (config.isComponentEnabled(Components.APPOINTMENT_SCHEDULING)) {
            AppointmentSchedulingSetup.setupMarkAppointmentAsMissedOrCompletedTask();
            if (config.getCountry().equals(ConfigDescriptor.Country.HAITI)) {
                AppointmentSchedulingSetup.customizeDailyAppointmentsDataSet();
            }
        }
        if (config.isComponentEnabled(Components.RADIOLOGY) && config.getSite().equals(ConfigDescriptor.Site.MIREBALAIS)) {
            updateGlobalProperty(OpenmrsConstants.GP_ORDER_NUMBER_GENERATOR_BEAN_ID, MirebalaisConstants.RADIOLOGY_ORDER_NUMBER_GENERATOR_BEAN_ID);
        }
        if (!testMode) {
            if (config.isComponentEnabled(Components.OVERVIEW_REPORTS) || config.isComponentEnabled(Components.DATA_EXPORTS)) {
                // must happen after location tags have been configured
                ReportSetup.setupReports(reportService, reportDefinitionService, administrationService, serializedObjectDAO, config);
            }
            // do app and extension configuration
            Context.getRegisteredComponent("customAppLoaderFactory", CustomAppLoaderFactory.class).setReadyForRefresh(true);
            ModuleFactory.getStartedModuleById("appframework").getModuleActivator().contextRefreshed();
            // on first startup, these modules may not have been able to configure their global propertes correctly because
            // all metadata was not loaded; we call the started method here to complete setup
            ModuleFactory.getStartedModuleById("registrationapp").getModuleActivator().started();
        }
    } catch (Exception e) {
        Module mod = ModuleFactory.getModuleById(MirebalaisConstants.MIREBALAIS_MODULE_ID);
        ModuleFactory.stopModule(mod);
        throw new RuntimeException("failed to setup the required modules", e);
    }
    log.info("Mirebalais Hospital Module started");
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) ReportService(org.openmrs.module.reporting.report.service.ReportService) AdministrationService(org.openmrs.api.AdministrationService) ReportDefinitionService(org.openmrs.module.reporting.report.definition.service.ReportDefinitionService) CustomAppLoaderFactory(org.openmrs.module.mirebalais.apploader.CustomAppLoaderFactory) Config(org.openmrs.module.pihcore.config.Config) PrinterService(org.openmrs.module.printer.PrinterService) Module(org.openmrs.module.Module) SerializedObjectDAO(org.openmrs.api.db.SerializedObjectDAO)

Example 17 with Module

use of org.openmrs.module.Module in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivator method contextRefreshed.

/**
 * @see ModuleActivator#contextRefreshed()
 */
public void contextRefreshed() {
    try {
        // currently only one of these
        Config config = Context.getRegisteredComponents(Config.class).get(0);
        // Reload configuration based on runtime properties values, defaulting to mirebalais if nothing found
        String configs = Context.getRuntimeProperties().getProperty(ConfigLoader.PIH_CONFIGURATION_RUNTIME_PROPERTY, "mirebalais");
        config.reload(ConfigLoader.load(configs));
        log.info("Mirebalais Hospital Module refreshed");
    } catch (Exception e) {
        Module mod = ModuleFactory.getModuleById(MirebalaisConstants.MIREBALAIS_MODULE_ID);
        ModuleFactory.stopModule(mod);
        throw new RuntimeException("failed to setup the required modules", e);
    }
}
Also used : Config(org.openmrs.module.pihcore.config.Config) Module(org.openmrs.module.Module)

Example 18 with Module

use of org.openmrs.module.Module in project openmrs-module-pihcore by PIH.

the class PihCoreActivator method started.

// TODO test
@Override
public void started() {
    try {
        MetadataMappingService metadataMappingService = Context.getService(MetadataMappingService.class);
        PatientService patientService = Context.getPatientService();
        FormService formService = Context.getFormService();
        LocationService locationService = Context.getLocationService();
        EncounterService encounterService = Context.getEncounterService();
        VisitService visitService = Context.getVisitService();
        IdentifierSourceService identifierSourceService = Context.getService(IdentifierSourceService.class);
        ConceptService conceptService = Context.getService(ConceptService.class);
        if (config == null) {
            // hack to allow injecting a mock config for testing
            // currently only one of these
            config = Context.getRegisteredComponents(Config.class).get(0);
        }
        setDispositionConfig(config);
        installMetadataBundles(config);
        setGlobalProperties(config);
        setExtraIdentifierTypes(metadataMappingService, patientService, config);
        MergeActionsSetup.registerMergeActions();
        LocationTagSetup.setupLocationTags(locationService, config);
        HtmlFormSetup.setupHtmlFormEntryTagHandlers();
        MetadataMappingsSetup.setupGlobalMetadataMappings(metadataMappingService, locationService, encounterService, visitService);
        MetadataMappingsSetup.setupPrimaryIdentifierTypeBasedOnCountry(metadataMappingService, patientService, config);
        MetadataMappingsSetup.setupFormMetadataMappings(metadataMappingService);
        PatientIdentifierSetup.setupIdentifierGeneratorsIfNecessary(identifierSourceService, locationService, config);
        PacIntegrationSetup.setup(config);
        AttachmentsSetup.migrateAttachmentsConceptsIfNecessary(conceptService);
    // RetireProvidersSetup.setupRetireProvidersTask();
    } catch (Exception e) {
        Module mod = ModuleFactory.getModuleById("pihcore");
        ModuleFactory.stopModule(mod);
        throw new RuntimeException("failed to setup the required modules", e);
    }
}
Also used : LocationService(org.openmrs.api.LocationService) VisitService(org.openmrs.api.VisitService) PatientService(org.openmrs.api.PatientService) FormService(org.openmrs.api.FormService) IdentifierSourceService(org.openmrs.module.idgen.service.IdentifierSourceService) Module(org.openmrs.module.Module) ConceptService(org.openmrs.api.ConceptService) EncounterService(org.openmrs.api.EncounterService) MetadataMappingService(org.openmrs.module.metadatamapping.api.MetadataMappingService)

Example 19 with Module

use of org.openmrs.module.Module in project openmrs-core by openmrs.

the class WebModuleUtilTest method buildModuleForMessageTest.

private Module buildModuleForMessageTest() throws ParserConfigurationException {
    Properties englishMessages = new Properties();
    englishMessages.put("withoutPrefix", "Without prefix");
    Module mod = new Module("My Module");
    mod.setModuleId("mymodule");
    mod.setMessages(new HashMap<>());
    mod.getMessages().put("en", englishMessages);
    mod.setFile(new File("sampleFile.jar"));
    mod.setConfig(buildModuleConfig());
    return mod;
}
Also used : Properties(java.util.Properties) Module(org.openmrs.module.Module) File(java.io.File)

Example 20 with Module

use of org.openmrs.module.Module in project openmrs-core by openmrs.

the class Listener method loadBundledModules.

/**
 * Load the pre-packaged modules from web/WEB-INF/bundledModules. <br>
 * <br>
 * This method assumes that the api startup() and WebModuleUtil.startup() will be called later
 * for modules that loaded here
 *
 * @param servletContext the current servlet context for the webapp
 */
public static void loadBundledModules(ServletContext servletContext) {
    String path = servletContext.getRealPath("");
    path += File.separator + "WEB-INF" + File.separator + "bundledModules";
    File folder = new File(path);
    if (!folder.exists()) {
        log.warn("Bundled module folder doesn't exist: " + folder.getAbsolutePath());
        return;
    }
    if (!folder.isDirectory()) {
        log.warn("Bundled module folder isn't really a directory: " + folder.getAbsolutePath());
        return;
    }
    // loop over the modules and load the modules that we can
    File[] files = folder.listFiles();
    if (files != null) {
        for (File f : files) {
            if (!f.getName().startsWith(".")) {
                // ignore .svn folder and the like
                try {
                    Module mod = ModuleFactory.loadModule(f);
                    log.debug("Loaded bundled module: " + mod + " successfully");
                } catch (Exception e) {
                    log.warn("Error while trying to load bundled module " + f.getName() + "", e);
                }
            }
        }
    }
}
Also used : Module(org.openmrs.module.Module) File(java.io.File) ServletException(javax.servlet.ServletException) DatabaseUpdateException(org.openmrs.util.DatabaseUpdateException) InputRequiredException(org.openmrs.util.InputRequiredException) ModuleMustStartException(org.openmrs.module.ModuleMustStartException) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) IOException(java.io.IOException)

Aggregations

Module (org.openmrs.module.Module)22 File (java.io.File)8 Test (org.junit.Test)7 BaseModuleActivatorTest (org.openmrs.module.BaseModuleActivatorTest)5 IOException (java.io.IOException)3 URL (java.net.URL)3 Properties (java.util.Properties)3 JarFile (java.util.jar.JarFile)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 AdministrationService (org.openmrs.api.AdministrationService)2 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)2 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)2 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)2 Config (org.openmrs.module.pihcore.config.Config)2 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)2 InputRequiredException (org.openmrs.util.InputRequiredException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 FileInputStream (java.io.FileInputStream)1