use of org.openmrs.obs.ComplexObsHandler in project openmrs-core by openmrs.
the class ObsServiceTest method registerHandler_shouldLoadHandlerAndRegisterKey.
/**
* @see ObsService#registerHandler(String,String)
*/
@Test
public void registerHandler_shouldLoadHandlerAndRegisterKey() {
ObsService os = Context.getObsService();
// name it something other than what we used in the previous test
os.registerHandler("DummyHandler2", "org.openmrs.obs.handler.ImageHandler");
ComplexObsHandler dummyHandler = os.getHandler("DummyHandler2");
Assert.assertNotNull(dummyHandler);
}
use of org.openmrs.obs.ComplexObsHandler in project openmrs-core by openmrs.
the class ObsServiceTest method setHandlers_shouldOverrideHandlersWithSameKey.
/**
* @see ObsService#setHandlers(Map<QString;QComplexObsHandler;>)}
*/
@Test
public void setHandlers_shouldOverrideHandlersWithSameKey() {
ObsService os = Context.getObsService();
Map<String, ComplexObsHandler> handlers = new HashMap<>();
handlers.put("DummyHandlerToOverride", new ImageHandler());
// set the handlers and make sure they're there
os.setHandlers(handlers);
ComplexObsHandler dummyHandlerToOverride = os.getHandler("DummyHandlerToOverride");
Assert.assertTrue(dummyHandlerToOverride instanceof ImageHandler);
// now override that key and make sure the new class is stored
Map<String, ComplexObsHandler> handlersAgain = new HashMap<>();
handlersAgain.put("DummyHandlerToOverride", new BinaryDataHandler());
os.setHandlers(handlersAgain);
ComplexObsHandler dummyHandlerToOverrideAgain = os.getHandler("DummyHandlerToOverride");
Assert.assertTrue(dummyHandlerToOverrideAgain instanceof BinaryDataHandler);
}
use of org.openmrs.obs.ComplexObsHandler in project openmrs-core by openmrs.
the class ObsServiceImpl method handleExistingObsWithComplexConcept.
private void handleExistingObsWithComplexConcept(Obs obs) {
ComplexData complexData = obs.getComplexData();
Concept concept = obs.getConcept();
if (null != concept && concept.isComplex() && null != complexData && null != complexData.getData()) {
// save or update complexData object on this obs
// this is done before the database save so that the obs.valueComplex
// can be filled in by the handler.
ComplexObsHandler handler = getHandler(obs);
if (null != handler) {
handler.saveObs(obs);
} else {
throw new APIException("unknown.handler", new Object[] { concept });
}
}
}
use of org.openmrs.obs.ComplexObsHandler in project openmrs-core by openmrs.
the class FormServiceImpl method saveFormField.
/**
* @see org.openmrs.api.FormService#saveFormField(org.openmrs.FormField)
*/
@Override
public FormField saveFormField(FormField formField) throws APIException {
Field field = formField.getField();
if (field.getCreator() == null) {
field.setCreator(Context.getAuthenticatedUser());
}
if (field.getDateCreated() == null) {
field.setDateCreated(new Date());
}
// set the uuid here because the RequiredDataAdvice only looks at child lists
if (field.getUuid() == null) {
field.setUuid(UUID.randomUUID().toString());
}
FormField tmpFormField = dao.saveFormField(formField);
// Include all formfields from all serializable complex obs handlers
Concept concept = tmpFormField.getField().getConcept();
if (concept != null && concept.isComplex()) {
ComplexObsHandler handler = Context.getObsService().getHandler(((ConceptComplex) concept).getHandler());
if (handler instanceof SerializableComplexObsHandler) {
SerializableComplexObsHandler sHandler = (SerializableComplexObsHandler) handler;
if (sHandler.getFormFields() != null) {
for (FormField ff : sHandler.getFormFields()) {
ff.setParent(tmpFormField);
ff.setForm(tmpFormField.getForm());
ff.setCreator(tmpFormField.getCreator());
ff.setDateCreated(tmpFormField.getDateCreated());
dao.saveFormField(ff);
}
}
}
}
return tmpFormField;
}
use of org.openmrs.obs.ComplexObsHandler in project openmrs-core by openmrs.
the class ObsServiceTest method getHandler_shouldGetHandlerWithMatchingKey.
/**
* @see ObsService#getHandler(String)
*/
@Test
public void getHandler_shouldGetHandlerWithMatchingKey() {
ObsService os = Context.getObsService();
ComplexObsHandler handler = os.getHandler("ImageHandler");
Assert.assertNotNull(handler);
Assert.assertTrue(handler instanceof ImageHandler);
}
Aggregations