Search in sources :

Example 6 with AdministrationService

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

the class ModuleUtil method getModuleRepository.

/**
 * Gets the folder where modules are stored. ModuleExceptions are thrown on errors
 *
 * @return folder containing modules
 * @should use the runtime property as the first choice if specified
 * @should return the correct file if the runtime property is an absolute path
 */
public static File getModuleRepository() {
    String folderName = Context.getRuntimeProperties().getProperty(ModuleConstants.REPOSITORY_FOLDER_RUNTIME_PROPERTY);
    if (StringUtils.isBlank(folderName)) {
        AdministrationService as = Context.getAdministrationService();
        folderName = as.getGlobalProperty(ModuleConstants.REPOSITORY_FOLDER_PROPERTY, ModuleConstants.REPOSITORY_FOLDER_PROPERTY_DEFAULT);
    }
    // try to load the repository folder straight away.
    File folder = new File(folderName);
    // application directory
    if (!folder.exists()) {
        folder = new File(OpenmrsUtil.getApplicationDataDirectory(), folderName);
    }
    // now create the modules folder if it doesn't exist
    if (!folder.exists()) {
        log.warn("Module repository " + folder.getAbsolutePath() + " doesn't exist.  Creating directories now.");
        folder.mkdirs();
    }
    if (!folder.isDirectory()) {
        throw new ModuleException("Module repository is not a directory at: " + folder.getAbsolutePath());
    }
    return folder;
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 7 with AdministrationService

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

the class PersonServiceImpl method savePersonAttributeType.

/**
 * @see org.openmrs.api.PersonService#savePersonAttributeType(org.openmrs.PersonAttributeType)
 */
@Override
public PersonAttributeType savePersonAttributeType(PersonAttributeType type) throws APIException {
    checkIfPersonAttributeTypesAreLocked();
    if (type.getSortWeight() == null) {
        List<PersonAttributeType> allTypes = Context.getPersonService().getAllPersonAttributeTypes();
        if (!allTypes.isEmpty()) {
            type.setSortWeight(allTypes.get(allTypes.size() - 1).getSortWeight() + 1);
        } else {
            type.setSortWeight(1.0);
        }
    }
    boolean updateExisting = false;
    if (type.getId() != null) {
        updateExisting = true;
        String oldTypeName = dao.getSavedPersonAttributeTypeName(type);
        String newTypeName = type.getName();
        if (!oldTypeName.equals(newTypeName)) {
            List<GlobalProperty> props = new ArrayList<>();
            AdministrationService as = Context.getAdministrationService();
            for (String propName : OpenmrsConstants.GLOBAL_PROPERTIES_OF_PERSON_ATTRIBUTES) {
                props.add(as.getGlobalPropertyObject(propName));
            }
            for (GlobalProperty prop : props) {
                if (prop != null) {
                    String propVal = prop.getPropertyValue();
                    if (propVal != null && propVal.contains(oldTypeName)) {
                        prop.setPropertyValue(propVal.replaceFirst(oldTypeName, newTypeName));
                        as.saveGlobalProperty(prop);
                    }
                }
            }
        }
    }
    PersonAttributeType attributeType = dao.savePersonAttributeType(type);
    if (updateExisting) {
        // we need to update index in case searchable property has changed
        Context.updateSearchIndexForType(PersonAttribute.class);
    }
    return attributeType;
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) ArrayList(java.util.ArrayList) PersonAttributeType(org.openmrs.PersonAttributeType) GlobalProperty(org.openmrs.GlobalProperty)

Example 8 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-module-coreapps by openmrs.

the class VisitDetailsFragmentControllerTest method shouldReturnEncountersForVisit.

@Test
public void shouldReturnEncountersForVisit() throws ParseException {
    CoreAppsProperties coreAppsProperties = mock(CoreAppsProperties.class);
    when(coreAppsProperties.getPatientDashboardEncounterCount()).thenReturn(100);
    UiSessionContext sessionContext = mock(UiSessionContext.class);
    User authenticatedUser = new User();
    when(sessionContext.getCurrentUser()).thenReturn(authenticatedUser);
    AppContextModel appContextModel = new AppContextModel();
    when(sessionContext.generateAppContextModel()).thenReturn(appContextModel);
    authenticatedUser.addRole(createRoleForUser());
    AdministrationService administrationService = mock(AdministrationService.class);
    when(administrationService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATETIME_FORMAT)).thenReturn("dd.MMM.yyyy, HH:mm:ss");
    AppFrameworkService appFrameworkService = mock(AppFrameworkService.class);
    when(appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION)).thenReturn(generateMockEncounterTemplateExtensions());
    EncounterService encounterService = mock(EncounterService.class);
    Patient patient = mock(Patient.class);
    when(patient.getPatientId()).thenReturn(1);
    when(patient.isDead()).thenReturn(false);
    Visit visit = new Visit();
    Location visitLocation = new Location();
    visitLocation.setName("Visit Location");
    visit.setVisitId(1);
    visit.setLocation(visitLocation);
    visit.setStartDatetime(new Date());
    visit.setStopDatetime(new Date());
    visit.setCreator(authenticatedUser);
    visit.setPatient(patient);
    Location encounterLocation = new Location();
    encounterLocation.setName("Location");
    EncounterType encounterType = new EncounterType();
    encounterType.setName("Encounter Type");
    encounterType.setUuid(encounterTypeUuid);
    Provider primaryProvider = new Provider();
    primaryProvider.setName("Primary Provider");
    EncounterProvider primaryEncounterProvider = new EncounterProvider();
    primaryEncounterProvider.setProvider(primaryProvider);
    EncounterRole primaryEncounterRole = new EncounterRole();
    primaryEncounterRole.setUuid(primaryEncounterRoleUuid);
    primaryEncounterProvider.setEncounterRole(primaryEncounterRole);
    when(encounterService.getEncounterRoleByUuid(primaryEncounterRoleUuid)).thenReturn(primaryEncounterRole);
    Provider secondaryProvider = new Provider();
    secondaryProvider.setName("Secondary Provider");
    EncounterProvider secondaryEncounterProvider = new EncounterProvider();
    secondaryEncounterProvider.setProvider(secondaryProvider);
    secondaryEncounterProvider.setEncounterRole(new EncounterRole());
    Encounter encounter = new Encounter();
    encounter.setEncounterId(7);
    encounter.setEncounterDatetime(new Date());
    encounter.setLocation(encounterLocation);
    encounter.setEncounterType(encounterType);
    encounter.setEncounterProviders(new LinkedHashSet<EncounterProvider>());
    // add secondary provider so that it is the one that is "arbitrarily" returned first
    encounter.getEncounterProviders().add(secondaryEncounterProvider);
    encounter.getEncounterProviders().add(primaryEncounterProvider);
    encounter.setCreator(authenticatedUser);
    encounter.setDateCreated(new Date());
    visit.addEncounter(encounter);
    UiUtils uiUtils = new TestUiUtils(administrationService);
    VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
    SimpleObject response = controller.getVisitDetails(mock(EmrApiProperties.class), coreAppsProperties, appFrameworkService, encounterService, visit, null, null, uiUtils, sessionContext);
    List<SimpleObject> actualEncounters = (List<SimpleObject>) response.get("encounters");
    SimpleObject actualEncounter = actualEncounters.get(0);
    assertThat(response.get("startDatetime"), notNullValue());
    assertThat(response.get("stopDatetime"), notNullValue());
    assertThat((String) response.get("location"), is("Visit Location"));
    assertThat(actualEncounters.size(), is(1));
    assertThat((Integer) actualEncounter.get("encounterId"), is(7));
    assertThat((String) actualEncounter.get("location"), is("Location"));
    assertThat((SimpleObject) actualEncounter.get("encounterType"), isSimpleObjectWith("uuid", encounterType.getUuid(), "name", encounterType.getName()));
    assertThat(actualEncounter.get("encounterDatetime"), notNullValue());
    assertThat(actualEncounter.get("encounterDate"), notNullValue());
    assertThat(actualEncounter.get("encounterTime"), notNullValue());
    assertTrue((Boolean) actualEncounter.get("canEdit"));
    assertThat((String) actualEncounter.get("primaryProvider"), is("Primary Provider"));
    List<SimpleObject> actualProviders = (List<SimpleObject>) actualEncounter.get("encounterProviders");
    assertThat(actualProviders.size(), is(2));
}
Also used : UiSessionContext(org.openmrs.module.appui.UiSessionContext) EncounterProvider(org.openmrs.EncounterProvider) User(org.openmrs.User) SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) TestUiUtils(org.openmrs.module.appui.TestUiUtils) Patient(org.openmrs.Patient) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) EncounterService(org.openmrs.api.EncounterService) Date(java.util.Date) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) AdministrationService(org.openmrs.api.AdministrationService) CoreAppsProperties(org.openmrs.module.coreapps.CoreAppsProperties) EncounterRole(org.openmrs.EncounterRole) Encounter(org.openmrs.Encounter) AppFrameworkService(org.openmrs.module.appframework.service.AppFrameworkService) ArrayList(java.util.ArrayList) List(java.util.List) EncounterType(org.openmrs.EncounterType) Location(org.openmrs.Location) TestUiUtils(org.openmrs.module.appui.TestUiUtils) UiUtils(org.openmrs.ui.framework.UiUtils) Test(org.junit.Test)

Example 9 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getVisitTypeColorCodes.

private Map<String, Object> getVisitTypeColorCodes(VisitType visitType) {
    Map<String, Object> colorCode = new HashMap<String, Object>();
    AdministrationService adminService = Context.getAdministrationService();
    String propertyValue = adminService.getGlobalProperty(CoreAppsConstants.VISIT_TYPE_COLORS);
    try {
        if (StringUtils.isNotEmpty(propertyValue)) {
            ArrayNode array = new ObjectMapper().readValue(propertyValue, ArrayNode.class);
            for (JsonNode node : array) {
                String visitTypeUuid = node.path("uuid").getTextValue();
                if (visitType.getUuid().equalsIgnoreCase(visitTypeUuid)) {
                    colorCode.put("uuid", visitTypeUuid);
                    String color = node.path("color").getTextValue();
                    colorCode.put("color", color);
                    String shortName = node.path("shortName").getTextValue();
                    colorCode.put("shortName", shortName);
                }
            }
        }
    } catch (IOException ex) {
        LOG.error("Error retrieving visit type color codes, " + ex);
    }
    return colorCode;
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 10 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method showVisitTypeOnPatientHeaderSection.

public boolean showVisitTypeOnPatientHeaderSection() {
    AdministrationService adminService = Context.getAdministrationService();
    String propertyValue = adminService.getGlobalProperty(CoreAppsConstants.SHOW_VISIT_TYPE_PATIENT_HEADER_SECTION);
    Boolean result = new Boolean(propertyValue);
    return result;
}
Also used : AdministrationService(org.openmrs.api.AdministrationService)

Aggregations

AdministrationService (org.openmrs.api.AdministrationService)25 GlobalProperty (org.openmrs.GlobalProperty)8 ArrayList (java.util.ArrayList)5 User (org.openmrs.User)4 Test (org.junit.Test)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 EncounterType (org.openmrs.EncounterType)2 APIException (org.openmrs.api.APIException)2 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1