/** * @see org.openmrs.api.FormService#getFieldsByConcept(org.openmrs.Concept) */ @Override @Transactional(readOnly = true) public List<Field> getFieldsByConcept(Concept concept) throws APIException { return Context.getFormService().getFields(null, null, Collections.singleton(concept), null, null, null, null, null, null); }
/** * @see org.openmrs.api.FormService#getPublishedForms() */ @Override @Transactional(readOnly = true) public List<Form> getPublishedForms() throws APIException { return Context.getFormService().getForms(null, true, null, false, null, null, null); }
/** * @see org.openmrs.api.FormService#purgeField(org.openmrs.Field) */ @Override public void purgeField(Field field) throws APIException { Context.getFormService().purgeField(field, false); }
/** * @see org.openmrs.api.FormService#getAllForms() */ @Override @Transactional(readOnly = true) public List<Form> getAllForms() throws APIException { return Context.getFormService().getAllForms(true); }
/** * @see org.openmrs.api.FormService#getAllFieldTypes() */ @Override @Transactional(readOnly = true) public List<FieldType> getAllFieldTypes() throws APIException { return Context.getFormService().getAllFieldTypes(true); }
/** * @see org.openmrs.api.FormService#unretireField(org.openmrs.Field) */ @Override public Field unretireField(Field field) throws APIException { if (field.getRetired()) { field.setRetired(false); return Context.getFormService().saveField(field); } else { return field; } }
/** * @see org.openmrs.api.FormService#retireField(org.openmrs.Field) */ @Override public Field retireField(Field field) throws APIException { if (!field.getRetired()) { field.setRetired(true); return Context.getFormService().saveField(field); } else { return field; } }
/** * @see FormService#getAllForms(boolean) */ @Test public void getAllForms_shouldReturnAllFormsWithRetiredIfParameterMentionedAsTrue() { List<Form> forms = Context.getFormService().getAllForms(true); int currentFormsSize = forms.size(); assertEquals(1, currentFormsSize); Context.getFormService().saveForm(createMockForm(true)); forms = Context.getFormService().getAllForms(true); assertEquals(currentFormsSize + 1 , forms.size()); }
/** * @see FormService#getForm(String) */ @Test public void getForm_shouldReturnFormIfFormFound() { Form form = Context.getFormService().getForm("form_name_2"); assertNull(form); // create Form with form_name_2 and version 2.0 Context.getFormService().saveForm(createMockForm(false)); form = Context.getFormService().getForm("form_name_2"); assertNotNull(form); }
@Test public void getForm_shouldReturnFormIfFormFoundWithNameAndVersion() { Form form = Context.getFormService().getForm("form_name_2", "2.0"); assertNull(form); // create Form with form_name_2 and version 2.0 Context.getFormService().saveForm(createMockForm(false)); form = Context.getFormService().getForm("form_name_2", "2.0"); assertNotNull(form); }
/** * @see FormService#getFieldAnswerByUuid(String) */ @Test public void getFieldAnswerByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getFormService().getFieldAnswerByUuid("some invalid uuid")); }
/** * @see FormService#getFieldByUuid(String) */ @Test public void getFieldByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getFormService().getFieldByUuid("some invalid uuid")); }
/** * @see FormService#getFormByUuid(String) */ @Test public void getFormByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getFormService().getFormByUuid("some invalid uuid")); }
/** * @see FormService#getFormsContainingConcept(Concept) */ @Test public void getFormsContainingConcept_shouldGetAllFormsForConcept() { Concept concept = Context.getConceptService().getConcept(3); assertEquals(1, Context.getFormService().getFormsContainingConcept(concept).size()); }
/** * @see FormService#getFieldByUuid(String) */ @Test public void getFieldByUuid_shouldFindObjectGivenValidUuid() { String uuid = "db016b7d-39a5-4911-89da-0eefbfef7cb2"; Field field = Context.getFormService().getFieldByUuid(uuid); assertEquals(1, (int) field.getFieldId()); }
/** * @see FormService#duplicateForm(Form)} * @throws FormsLockedException */ @Test(expected = FormsLockedException.class) public void duplicateForm_shouldThrowAnErrorWhenTryingToDuplicateFormWhileFormsAreLocked() { FormService fs = Context.getFormService(); createFormsLockedGPAndSetValue("true"); Form form = fs.getForm(1); fs.duplicateForm(form); }
/** * @see FormService#getFieldTypeByUuid(String) */ @Test public void getFieldTypeByUuid_shouldFindObjectGivenValidUuid() { String uuid = "e7016b7d-39a5-4911-89da-0eefbfef7cb5"; FieldType fieldType = Context.getFormService().getFieldTypeByUuid(uuid); assertEquals(2, (int) fieldType.getFieldTypeId()); }
/** * @see FormService#getFormField(Form,Concept,Collection<QFormField;>,null) */ @Test public void getFormField_shouldSimplyReturnNullForNonexistentConcepts() { // test a non existent concept assertNull(Context.getFormService().getFormField(new Form(1), new Concept(293934), null, false)); }
/** * @see FormService#saveForm(Form) * @throws FormsLockedException */ @Test(expected = FormsLockedException.class) public void saveForm_shouldThrowAnErrorWhenTryingToSaveAnExistingFormWhileFormsAreLocked() { FormService fs = Context.getFormService(); createFormsLockedGPAndSetValue("true"); Form form = fs.getForm(1); form.setName("modified basic form"); fs.saveForm(form); }
/** * @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); }