Search in sources :

Example 1 with FormField

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;
}
Also used : ArrayList(java.util.ArrayList) FormField(org.openmrs.FormField)

Example 2 with FormField

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

Example 3 with FormField

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

Example 4 with FormField

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

Example 5 with FormField

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;
}
Also used : Form(org.openmrs.Form) FormField(org.openmrs.FormField)

Aggregations

FormField (org.openmrs.FormField)14 Test (org.junit.Test)6 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)6 Form (org.openmrs.Form)5 Concept (org.openmrs.Concept)4 Field (org.openmrs.Field)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 Criteria (org.hibernate.Criteria)2 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 APIException (org.openmrs.api.APIException)1 ComplexObsHandler (org.openmrs.obs.ComplexObsHandler)1 SerializableComplexObsHandler (org.openmrs.obs.SerializableComplexObsHandler)1 BindException (org.springframework.validation.BindException)1