Search in sources :

Example 1 with EncounterVisitHandler

use of org.openmrs.api.handler.EncounterVisitHandler in project openmrs-core by openmrs.

the class EncounterServiceTest method getActiveEncounterVisitHandler_shouldReturnBeanHaveBeenRegisteredWithGivenName.

@Test
public void getActiveEncounterVisitHandler_shouldReturnBeanHaveBeenRegisteredWithGivenName() {
    String correctBeanName = OpenmrsConstants.REGISTERED_COMPONENT_NAME_PREFIX + "existingOrNewVisitAssignmentHandler";
    GlobalProperty visitHandlerProperty = new GlobalProperty(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER, correctBeanName);
    Context.getAdministrationService().saveGlobalProperty(visitHandlerProperty);
    EncounterVisitHandler activeEncounterVisitHandler = Context.getEncounterService().getActiveEncounterVisitHandler();
    Assert.assertNotNull(activeEncounterVisitHandler);
}
Also used : EncounterVisitHandler(org.openmrs.api.handler.EncounterVisitHandler) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 2 with EncounterVisitHandler

use of org.openmrs.api.handler.EncounterVisitHandler in project openmrs-core by openmrs.

the class EncounterServiceTest method getVisitAssignmentHandlers_shouldReturnTheExistingOrNewVisitAssignmentHandler.

/**
 * @see EncounterService#getVisitAssignmentHandlers()
 */
@Test
public void getVisitAssignmentHandlers_shouldReturnTheExistingOrNewVisitAssignmentHandler() {
    List<EncounterVisitHandler> handlers = Context.getEncounterService().getEncounterVisitHandlers();
    boolean found = false;
    for (EncounterVisitHandler handler : handlers) {
        if (handler instanceof ExistingOrNewVisitAssignmentHandler) {
            found = true;
            break;
        }
    }
    Assert.assertTrue("The 'existing or new visit only assignment' handler was not found", found);
}
Also used : ExistingOrNewVisitAssignmentHandler(org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler) EncounterVisitHandler(org.openmrs.api.handler.EncounterVisitHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 3 with EncounterVisitHandler

use of org.openmrs.api.handler.EncounterVisitHandler in project openmrs-core by openmrs.

the class EncounterServiceTest method getVisitAssignmentHandlers_shouldReturnTheExistingVisitOnlyAssignmentHandler.

/**
 * @see EncounterService#getVisitAssignmentHandlers()
 */
@Test
public void getVisitAssignmentHandlers_shouldReturnTheExistingVisitOnlyAssignmentHandler() {
    List<EncounterVisitHandler> handlers = Context.getEncounterService().getEncounterVisitHandlers();
    boolean found = false;
    for (EncounterVisitHandler handler : handlers) {
        if (handler instanceof ExistingVisitAssignmentHandler) {
            found = true;
            break;
        }
    }
    Assert.assertTrue("The 'existing visit only assignment' handler was not found", found);
}
Also used : EncounterVisitHandler(org.openmrs.api.handler.EncounterVisitHandler) ExistingVisitAssignmentHandler(org.openmrs.api.handler.ExistingVisitAssignmentHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 4 with EncounterVisitHandler

use of org.openmrs.api.handler.EncounterVisitHandler in project openmrs-core by openmrs.

the class EncounterServiceTest method getVisitAssignmentHandlers_shouldReturnTheNoAssignmentHandler.

/**
 * @see EncounterService#getVisitAssignmentHandlers()
 */
@Test
public void getVisitAssignmentHandlers_shouldReturnTheNoAssignmentHandler() {
    List<EncounterVisitHandler> handlers = Context.getEncounterService().getEncounterVisitHandlers();
    boolean found = false;
    for (EncounterVisitHandler handler : handlers) {
        if (handler instanceof NoVisitAssignmentHandler)
            found = true;
    }
    Assert.assertTrue("The basic 'no assignment' handler was not found", found);
}
Also used : EncounterVisitHandler(org.openmrs.api.handler.EncounterVisitHandler) NoVisitAssignmentHandler(org.openmrs.api.handler.NoVisitAssignmentHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 5 with EncounterVisitHandler

use of org.openmrs.api.handler.EncounterVisitHandler in project openmrs-core by openmrs.

the class EncounterServiceImpl method getActiveEncounterVisitHandler.

/**
 * @see org.openmrs.api.EncounterService#getActiveEncounterVisitHandler()
 */
@Override
@Transactional(readOnly = true)
public EncounterVisitHandler getActiveEncounterVisitHandler() throws APIException {
    String handlerGlobalValue = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER, null);
    if (StringUtils.isBlank(handlerGlobalValue)) {
        return null;
    }
    EncounterVisitHandler handler;
    // convention = [NamePrefix:beanName] or [className]
    String namePrefix = OpenmrsConstants.REGISTERED_COMPONENT_NAME_PREFIX;
    if (handlerGlobalValue.startsWith(namePrefix)) {
        String beanName = handlerGlobalValue.substring(namePrefix.length());
        handler = Context.getRegisteredComponent(beanName, EncounterVisitHandler.class);
    } else {
        Object instance;
        try {
            instance = OpenmrsClassLoader.getInstance().loadClass(handlerGlobalValue).newInstance();
        } catch (Exception ex) {
            throw new APIException("failed.instantiate.assignment.handler", new Object[] { handlerGlobalValue }, ex);
        }
        if (instance instanceof EncounterVisitHandler) {
            handler = (EncounterVisitHandler) instance;
        } else {
            throw new APIException("assignment.handler.should.implement.EncounterVisitHandler", (Object[]) null);
        }
    }
    return handler;
}
Also used : APIException(org.openmrs.api.APIException) EncounterVisitHandler(org.openmrs.api.handler.EncounterVisitHandler) APIException(org.openmrs.api.APIException) EncounterTypeLockedException(org.openmrs.api.EncounterTypeLockedException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EncounterVisitHandler (org.openmrs.api.handler.EncounterVisitHandler)6 Test (org.junit.Test)5 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)5 ExistingOrNewVisitAssignmentHandler (org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler)2 GlobalProperty (org.openmrs.GlobalProperty)1 APIException (org.openmrs.api.APIException)1 EncounterTypeLockedException (org.openmrs.api.EncounterTypeLockedException)1 ExistingVisitAssignmentHandler (org.openmrs.api.handler.ExistingVisitAssignmentHandler)1 NoVisitAssignmentHandler (org.openmrs.api.handler.NoVisitAssignmentHandler)1 Transactional (org.springframework.transaction.annotation.Transactional)1