Search in sources :

Example 1 with ComplexObsHandler

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);
}
Also used : ComplexObsHandler(org.openmrs.obs.ComplexObsHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 2 with ComplexObsHandler

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);
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) BinaryDataHandler(org.openmrs.obs.handler.BinaryDataHandler) HashMap(java.util.HashMap) ComplexObsHandler(org.openmrs.obs.ComplexObsHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 3 with ComplexObsHandler

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 });
        }
    }
}
Also used : Concept(org.openmrs.Concept) APIException(org.openmrs.api.APIException) ComplexData(org.openmrs.obs.ComplexData) ComplexObsHandler(org.openmrs.obs.ComplexObsHandler)

Example 4 with ComplexObsHandler

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;
}
Also used : Concept(org.openmrs.Concept) FormField(org.openmrs.FormField) Field(org.openmrs.Field) SerializableComplexObsHandler(org.openmrs.obs.SerializableComplexObsHandler) ComplexObsHandler(org.openmrs.obs.ComplexObsHandler) SerializableComplexObsHandler(org.openmrs.obs.SerializableComplexObsHandler) FormField(org.openmrs.FormField) Date(java.util.Date)

Example 5 with ComplexObsHandler

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);
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) ComplexObsHandler(org.openmrs.obs.ComplexObsHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ComplexObsHandler (org.openmrs.obs.ComplexObsHandler)9 Test (org.junit.Test)7 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)7 ImageHandler (org.openmrs.obs.handler.ImageHandler)4 HashMap (java.util.HashMap)2 Concept (org.openmrs.Concept)2 BinaryDataHandler (org.openmrs.obs.handler.BinaryDataHandler)2 Date (java.util.Date)1 Field (org.openmrs.Field)1 FormField (org.openmrs.FormField)1 APIException (org.openmrs.api.APIException)1 ComplexData (org.openmrs.obs.ComplexData)1 SerializableComplexObsHandler (org.openmrs.obs.SerializableComplexObsHandler)1 TextHandler (org.openmrs.obs.handler.TextHandler)1