Search in sources :

Example 6 with LocationService

use of org.openmrs.api.LocationService 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 7 with LocationService

use of org.openmrs.api.LocationService in project openmrs-core by openmrs.

the class MigrationHelper method importLocations.

/**
 * Takes XML like: <something> <location name="Cerca-la-Source"/> </something> returns the
 * number of locations added
 */
public static int importLocations(Document document) {
    int ret = 0;
    LocationService ls = Context.getLocationService();
    List<Node> toAdd = new ArrayList<>();
    findNodesNamed(document, "location", toAdd);
    for (Node node : toAdd) {
        Element e = (Element) node;
        String name = e.getAttribute("name");
        if (name == null || name.length() == 0) {
            throw new IllegalArgumentException("each <location /> element must define a name attribute");
        }
        if (ls.getLocation(name) != null) {
            continue;
        }
        Location location = new Location();
        location.setName(name);
        ls.saveLocation(location);
        ++ret;
    }
    return ret;
}
Also used : LocationService(org.openmrs.api.LocationService) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Location(org.openmrs.Location)

Aggregations

LocationService (org.openmrs.api.LocationService)7 Location (org.openmrs.Location)3 VisitService (org.openmrs.api.VisitService)3 LocationTag (org.openmrs.LocationTag)2 Visit (org.openmrs.Visit)2 ConceptService (org.openmrs.api.ConceptService)2 AdtService (org.openmrs.module.emrapi.adt.AdtService)2 IdentifierSourceService (org.openmrs.module.idgen.service.IdentifierSourceService)2 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Encounter (org.openmrs.Encounter)1 LocationAttributeType (org.openmrs.LocationAttributeType)1 EncounterService (org.openmrs.api.EncounterService)1 FormService (org.openmrs.api.FormService)1 PatientService (org.openmrs.api.PatientService)1 Module (org.openmrs.module.Module)1 TestUiUtils (org.openmrs.module.appui.TestUiUtils)1