/** * @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#getForms(java.lang.String, boolean) */ @Override @Transactional(readOnly = true) public List<Form> getForms(String fuzzyName, boolean onlyLatestVersion) { // get all forms including unpublished and including retired List<Form> forms = Context.getFormService().getForms(fuzzyName, null, null, null, null, null, null); Set<String> namesAlreadySeen = new HashSet<>(); for (Iterator<Form> i = forms.iterator(); i.hasNext();) { Form form = i.next(); if (namesAlreadySeen.contains(form.getName())) { i.remove(); } else { namesAlreadySeen.add(form.getName()); } } return forms; }
/** * Make sure that multiple forms are returned if a field is on a form more than once * * @see {@link FormService#getForms(String, Boolean, java.util.Collection, Boolean, java.util.Collection, java.util.Collection, java.util.Collection) */ @Test public void getForms_shouldReturnDuplicateFormWhenGivenFieldsIncludedInFormMultipleTimes() { executeDataSet(INITIAL_FIELDS_XML); executeDataSet("org/openmrs/api/include/FormServiceTest-formFields.xml"); FormService formService = Context.getFormService(); List<Field> fields = new ArrayList<>(); fields.add(new Field(1)); List<Form> forms = formService.getForms(null, null, null, null, null, null, fields); assertEquals(3, forms.size()); }
/** * @ * @see FormService#getForms(String,Boolean,Collection,Boolean,Collection,Collection,Collection) */ @Test public void getForms_shouldReturnFormsContainingAllFormFieldsInContainingAllFormFields() { executeDataSet(INITIAL_FIELDS_XML); executeDataSet("org/openmrs/api/include/FormServiceTest-formFields.xml"); FormService formService = Context.getFormService(); Set<FormField> formFields = new HashSet<>(); formFields.add(new FormField(3)); formFields.add(new FormField(5)); formFields.add(new FormField(7)); List<Form> forms = formService.getForms(null, null, null, null, null, formFields, null); assertEquals(1, forms.size()); formFields = new HashSet<>(); formFields.add(new FormField(2)); formFields.add(new FormField(4)); formFields.add(new FormField(6)); forms = formService.getForms(null, null, null, null, null, formFields, null); assertEquals(0, forms.size()); }
/** * ensure that FormFields in containingAnyFormField parameter are considered when filtering the results * * @see {@link FormService#getForms(String, Boolean, java.util.Collection, Boolean, java.util.Collection, java.util.Collection, java.util.Collection) */ @Test public void getForms_shouldReturnFormsThatHaveAnyMatchingFormFieldsInContainingAnyFormField() { Integer numberOfExpectedForms = 2; executeDataSet(INITIAL_FIELDS_XML); executeDataSet(MULTIPLE_FORMS_FORM_FIELDS_XML); FormService formService = Context.getFormService(); Collection<FormField> containingAnyFormField = makeFormFieldCollectionSample(formService); List<Form> formsReturned = formService.getForms(null, null, null, null, containingAnyFormField, null, null); Integer currentNumberOfForms = formsReturned.size(); assertEquals(numberOfExpectedForms, currentNumberOfForms); assertTrue(wasFormsSuccessfullyFilteredByMatchingFormFieldsInContainingAnyFormField(containingAnyFormField, formsReturned)); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<Form> doSearch(RequestContext context) { return new NeedsPaging<Form>(Context.getFormService().getForms(context.getParameter("q"), false), context); }