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