Search in sources :

Example 1 with SerializableComplexObsHandler

use of org.openmrs.obs.SerializableComplexObsHandler 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)

Aggregations

Date (java.util.Date)1 Concept (org.openmrs.Concept)1 Field (org.openmrs.Field)1 FormField (org.openmrs.FormField)1 ComplexObsHandler (org.openmrs.obs.ComplexObsHandler)1 SerializableComplexObsHandler (org.openmrs.obs.SerializableComplexObsHandler)1