use of org.openmrs.FormField in project openmrs-core by openmrs.
the class FormServiceTest method makeFormFieldCollectionSample.
private Collection<FormField> makeFormFieldCollectionSample(FormService formService) {
int formFieldAIdentifier = 2;
int formFieldBIdentifier = 9;
Collection<FormField> containingAnyFormField = new ArrayList<>();
FormField formFieldA = formService.getFormField(formFieldAIdentifier);
FormField formFieldB = formService.getFormField(formFieldBIdentifier);
containingAnyFormField.add(formFieldA);
containingAnyFormField.add(formFieldB);
return containingAnyFormField;
}
use of org.openmrs.FormField in project openmrs-core by openmrs.
the class FormServiceTest method getFormFieldByUuid_shouldFindObjectGivenValidUuid.
/**
* @see FormService#getFormFieldByUuid(String)
*/
@Test
public void getFormFieldByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "1c822b7b-7840-463d-ba70-e0c8338a4c2d";
FormField formField = Context.getFormService().getFormFieldByUuid(uuid);
assertEquals(2, (int) formField.getFormFieldId());
}
use of org.openmrs.FormField in project openmrs-core by openmrs.
the class FormServiceTest method getFormField_shouldNotFailWithNullIgnoreFormFieldsArgument.
/**
* @see FormService#getFormField(Form,Concept,Collection<QFormField;>,null)
*/
@Test
public void getFormField_shouldNotFailWithNullIgnoreFormFieldsArgument() {
// test that a null ignoreFormFields doesn't error out
FormField ff = Context.getFormService().getFormField(new Form(1), new Concept(3), null, false);
assertNotNull(ff);
}
use of org.openmrs.FormField in project openmrs-core by openmrs.
the class FormServiceTest method saveFormField_shouldPropagateSaveToTheFieldPropertyOnTheGivenFormField.
/**
* @see FormService#saveFormField(FormField)
*/
@Test
public void saveFormField_shouldPropagateSaveToTheFieldPropertyOnTheGivenFormField() {
// create a new Field
Field field = new Field();
field.setName("This is a new field");
field.setDescription("It should be saved along with the formField");
// put that field on a new FormField.
FormField formField = new FormField();
formField.setField(field);
formField.setForm(new Form(1));
// save the FormField
Context.getFormService().saveFormField(formField);
// the uuid should be set by this method so that the field can be saved successfully
Assert.assertNotNull(field.getUuid());
}
use of org.openmrs.FormField in project openmrs-core by openmrs.
the class FormServiceImpl method duplicateForm.
/**
* Duplicate this form and form_fields associated with this form
*
* @param form
* @return New duplicated form
* @throws APIException
* @see org.openmrs.api.FormService#duplicateForm(org.openmrs.Form)
*/
@Override
public Form duplicateForm(Form form) throws APIException {
checkIfFormsAreLocked();
// get original form id for reference later
Integer originalFormId = form.getFormId();
for (FormField formField : form.getFormFields()) {
formField.setUuid(null);
formField.setFormFieldId(null);
}
// this is required because Hibernate would recognize the original collection
form.setFormFields(new HashSet<>(form.getFormFields()));
form.setUuid(null);
form.setFormId(null);
form.setCreator(null);
form.setDateCreated(null);
form.setChangedBy(null);
form.setDateChanged(null);
Context.clearSession();
RequiredDataAdvice.recursivelyHandle(SaveHandler.class, form, null);
Form newForm = dao.duplicateForm(form);
// duplicate form resources from the old form to the new one
duplicateFormResources(Context.getFormService().getForm(originalFormId), newForm);
return newForm;
}
Aggregations