Search in sources :

Example 6 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method saveFormResource_shouldPersistAFormResource.

/**
 * @throws ParseException
 * @see FormService#saveFormResource(org.openmrs.FormResource)
 */
@Test
public void saveFormResource_shouldPersistAFormResource() throws ParseException {
    Form form = Context.getFormService().getForm(1);
    FormResource resource = new FormResource();
    resource.setForm(form);
    resource.setName("Start Date");
    resource.setDatatypeClassname("org.openmrs.customdatatype.datatype.DateDatatype");
    Date expected = new SimpleDateFormat("yyyy-MM-dd").parse("2011-10-16");
    resource.setValue(expected);
    Context.getFormService().saveFormResource(resource);
    Integer resourceId = resource.getFormResourceId();
    Context.clearSession();
    FormResource actual = Context.getFormService().getFormResource(resourceId);
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected, actual.getValue());
}
Also used : Form(org.openmrs.Form) FormResource(org.openmrs.FormResource) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method duplicateForm_shouldClearChangedDetailsAndUpdateCreationDetails.

/**
 * @see FormService#duplicateForm(Form)
 */
@Test
public void duplicateForm_shouldClearChangedDetailsAndUpdateCreationDetails() {
    Date startOfTest = DateUtil.truncateToSeconds(new Date());
    FormService formService = Context.getFormService();
    Form form = formService.getForm(1);
    Form dupForm = formService.duplicateForm(form);
    Assert.assertNull(dupForm.getChangedBy());
    Assert.assertNull(dupForm.getDateChanged());
    assertEquals(Context.getAuthenticatedUser(), dupForm.getCreator());
    assertFalse(dupForm.getDateCreated().before(startOfTest));
}
Also used : Form(org.openmrs.Form) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with Form

use of org.openmrs.Form 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 9 with Form

use of org.openmrs.Form 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 10 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method duplicateForm_shouldGiveANewUuidToTheDuplicatedForm.

/**
 * @see FormService#duplicateForm(Form)
 */
@Test
public void duplicateForm_shouldGiveANewUuidToTheDuplicatedForm() {
    FormService formService = Context.getFormService();
    Form form = formService.getForm(1);
    String originalUUID = form.getUuid();
    Form dupForm = formService.duplicateForm(form);
    Assert.assertNotNull(dupForm.getUuid());
    Assert.assertNotSame(originalUUID, dupForm.getUuid());
}
Also used : Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Form (org.openmrs.Form)45 Test (org.junit.Test)37 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)37 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Date (java.util.Date)7 Encounter (org.openmrs.Encounter)7 FormField (org.openmrs.FormField)6 FormResource (org.openmrs.FormResource)6 Message (ca.uhn.hl7v2.model.Message)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 Patient (org.openmrs.Patient)3 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)2 HashSet (java.util.HashSet)2 Concept (org.openmrs.Concept)2 Field (org.openmrs.Field)2 Location (org.openmrs.Location)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1