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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations