@Transactional public class FormServiceImpl extends BaseOpenmrsService implements FormService
FormService
 This class should not be instantiated alone, get a service class from the Context: Context.getFormService();
Context, 
FormService| Constructor and Description | 
|---|
| FormServiceImpl()Default empty constructor | 
| Modifier and Type | Method and Description | 
|---|---|
| void | checkIfFormsAreLocked()Checks if the forms are locked, and if they are throws an exception when saving or deleting a form | 
| Form | duplicateForm(Form form)Duplicate this form and form_fields associated with this form | 
| List<Field> | getAllFields()Fetches all Fields in the database, including retired ones | 
| List<Field> | getAllFields(boolean includeRetired)Fetches all Fields in the database, possibly including retired ones | 
| List<FieldType> | getAllFieldTypes()Get all field types in the database including the retired ones | 
| List<FieldType> | getAllFieldTypes(boolean includeRetired)Get all field types in the database with or without retired ones | 
| List<FormField> | getAllFormFields()Returns all FormFields in the database | 
| List<Form> | getAllForms()Gets all Forms, including retired ones. | 
| List<Form> | getAllForms(boolean includeRetired)Gets all forms, possibly including retired ones | 
| Field | getField(Integer fieldId)Gets a Field by internal database id | 
| FieldAnswer | getFieldAnswerByUuid(String uuid)Get FieldAnswer by its UUID | 
| Field | getFieldByUuid(String uuid)Get Field by its UUID | 
| List<Field> | getFields(Collection<Form> forms,
         Collection<FieldType> fieldTypes,
         Collection<Concept> concepts,
         Collection<String> tableNames,
         Collection<String> attributeNames,
         Boolean selectMultiple,
         Collection<FieldAnswer> containsAllAnswers,
         Collection<FieldAnswer> containsAnyAnswer,
         Boolean retired)Returns all Fields that match these (nullable) criteria | 
| List<Field> | getFields(String fuzzySearchPhrase)Find all Fields whose names are similar to or contain the given phrase. | 
| List<Field> | getFieldsByConcept(Concept concept)Finds all Fields that point to the given concept, including retired ones. | 
| FieldType | getFieldType(Integer fieldTypeId)Get fieldType by internal identifier | 
| FieldType | getFieldTypeByName(String name)Get FieldType by its name | 
| FieldType | getFieldTypeByUuid(String uuid)Get FieldType by its UUID | 
| Form | getForm(Integer formId)Get form by internal form identifier | 
| Form | getForm(String name)Get form by exact name match. | 
| Form | getForm(String name,
       String version)Get form by exact name & version match. | 
| Form | getFormByUuid(String uuid)Get Form by its UUID | 
| Integer | getFormCount(String partialName,
            Boolean published,
            Collection<EncounterType> encounterTypes,
            Boolean retired,
            Collection<FormField> containingAnyFormField,
            Collection<FormField> containingAllFormFields,
            Collection<Field> fields)Same as
  FormService.getForms(String, Boolean, Collection, Boolean, Collection, Collection, Collection)except that it returns an integer that is the size of the list that would be returned | 
| FormField | getFormField(Form form,
            Concept concept,
            Collection<FormField> ignoreFormFields,
            boolean force)Finds the FormField defined for this form/concept combination while discounting any form
 field found in the  ignoreFormFieldscollection This method was added when
 needing to relate observations to form fields during a display. | 
| FormField | getFormField(Integer formFieldId)Gets a FormField by internal database id | 
| FormField | getFormFieldByUuid(String uuid)Get FormField by its UUID | 
| FormResource | getFormResource(Form form,
               String name)Finds a FormResource based on a given Form and name | 
| FormResource | getFormResource(Integer formResourceId)Finds a FormResource by its id | 
| FormResource | getFormResourceByUuid(String uuid)Finds a FormResource by its uuid | 
| Collection<FormResource> | getFormResourcesForForm(Form form)Finds all FormResources tied to a given form | 
| List<Form> | getForms(String fuzzyName,
        boolean onlyLatestVersion)Gets all forms with name similar to the given name. | 
| List<Form> | getForms(String partialName,
        Boolean published,
        Collection<EncounterType> encounterTypes,
        Boolean retired,
        Collection<FormField> containingAnyFormField,
        Collection<FormField> containingAllFormFields,
        Collection<Field> fields)Gets all forms that match all the (nullable) criteria | 
| List<Form> | getFormsContainingConcept(Concept concept)Returns all forms that contain the given concept as a field in their schema. | 
| List<Form> | getPublishedForms()Returns all published forms (not including retired ones) | 
| int | mergeDuplicateFields()Audit form, consolidate similar fields | 
| void | purgeField(Field field)Completely removes a Field from the database. | 
| void | purgeField(Field field,
          boolean cascade)Completely removes a Field from the database. | 
| void | purgeFieldType(FieldType fieldType)Deletes the given field type from the database. | 
| void | purgeForm(Form form)Completely remove a Form from the database. | 
| void | purgeForm(Form form,
         boolean cascade)Completely remove a Form from the database. | 
| void | purgeFormField(FormField formField)Completely removes the given FormField from the database. | 
| void | purgeFormResource(FormResource formResource)Purges a form resource | 
| Field | retireField(Field field)Retires field | 
| void | retireForm(Form form,
          String reason)Retires the Form, leaving it in the database, but removing it from data entry screens | 
| Field | saveField(Field field)Creates or updates the given Field | 
| FieldType | saveFieldType(FieldType fieldType)Saves the given field type to the database | 
| Form | saveForm(Form form)Create or update the given Form in the database | 
| FormField | saveFormField(FormField formField)Creates or updates the given FormField | 
| FormResource | saveFormResource(FormResource formResource)Saves or updates the given form resource | 
| void | setFormDAO(FormDAO dao)Method used to inject the data access object. | 
| Field | unretireField(Field field)Unretires field | 
| void | unretireForm(Form form)Unretires a Form that had previous been retired. | 
onShutdown, onStartupclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonShutdown, onStartuppublic void setFormDAO(FormDAO dao)
dao - @Transactional(readOnly=true) public Form getForm(Integer formId) throws APIException
FormServicegetForm in interface FormServiceformId - internal identifierAPIException - Should return null if no form exists with given formId
 Should return the requested formFormService.getForm(java.lang.Integer)public Form duplicateForm(Form form) throws APIException
duplicateForm in interface FormServiceform - APIExceptionFormService.duplicateForm(org.openmrs.Form)public void retireForm(Form form, String reason) throws APIException
FormServiceretireForm in interface FormServiceform - the Form to retirereason - the retiredReason to setAPIException - Should set the retired bit before savingFormService.retireForm(org.openmrs.Form, java.lang.String)public void unretireForm(Form form) throws APIException
FormServiceunretireForm in interface FormServiceform - the Form to reviveAPIException - Should unset the retired bit before savingFormService.unretireForm(org.openmrs.Form)@Transactional(readOnly=true) public List<FieldType> getAllFieldTypes() throws APIException
FormServicegetAllFieldTypes in interface FormServiceAPIException - Should also get retired field typesFormService.getAllFieldTypes()@Transactional(readOnly=true) public List<FieldType> getAllFieldTypes(boolean includeRetired) throws APIException
FormServicegetAllFieldTypes in interface FormServiceincludeRetired - true/false whether to include the retired field typesAPIException - Should get all field types including retired when includeRetired equals true
 Should get all field types excluding retired when includeRetired equals falseFormService.getAllFieldTypes(boolean)@Transactional(readOnly=true) public FieldType getFieldType(Integer fieldTypeId) throws APIException
FormServicegetFieldType in interface FormServicefieldTypeId - Integer id of FieldType to getAPIException - Should return null when no field type matching given idFormService.getFieldType(java.lang.Integer)@Transactional(readOnly=true) public Field getField(Integer fieldId) throws APIException
FormServicegetField in interface FormServicefieldId - the id of the Field to fetchAPIException - Should return null if no field exists with given fieldIdFormService.getField(java.lang.Integer)@Transactional(readOnly=true) public FormField getFormField(Integer formFieldId) throws APIException
FormServicegetFormField in interface FormServiceformFieldId - the internal id to search onAPIException - Should return null if no formField exists with given idFormService.getFormField(java.lang.Integer)@Transactional(readOnly=true) public FormField getFormField(Form form, Concept concept, Collection<FormField> ignoreFormFields, boolean force) throws APIException
FormServiceignoreFormFields collection This method was added when
 needing to relate observations to form fields during a display. The use case would be that
 you know a Concept for a obs, which was defined on a form (via a formField). You can relate
 the formFields to Concepts easily enough, but if a Form reuses a Concept in two separate
 FormFields you don't want to only associate that first formField with that concept. So, keep
 a running list of formFields you've seen and pass them back in here to rule them out.getFormField in interface FormServiceform - Form that this concept was found onconcept - Concept (question) on this form that is being requestedignoreFormFields - FormFields to ignore (aka already seen formfields)force - if true and there are zero matches because all formFields were ignored (because
            of ignoreFormFields) than the first result is returnedAPIException - Should get form fields by form and concept
 Should not fail with null ignoreFormFields argument
 Should simply return null for nonexistent concepts
 Should simply return null for nonexistent forms
 Should ignore formFields passed to ignoreFormFieldsFormService.getFormField(org.openmrs.Form, org.openmrs.Concept,
      java.util.Collection, boolean)@Transactional(readOnly=true) public Field getFieldByUuid(String uuid) throws APIException
FormServicegetFieldByUuid in interface FormServiceAPIExceptionFormService.getFieldByUuid(java.lang.String)@Transactional(readOnly=true) public FieldAnswer getFieldAnswerByUuid(String uuid) throws APIException
FormServicegetFieldAnswerByUuid in interface FormServiceAPIException@Transactional(readOnly=true) public FieldType getFieldTypeByUuid(String uuid) throws APIException
FormServicegetFieldTypeByUuid in interface FormServiceAPIExceptionFormService.getFieldTypeByUuid(java.lang.String)@Transactional(readOnly=true) public FieldType getFieldTypeByName(String name) throws APIException
FormServicegetFieldTypeByName in interface FormServiceAPIExceptionFormService.getFieldTypeByName(java.lang.String)@Transactional(readOnly=true) public Form getFormByUuid(String uuid) throws APIException
FormServicegetFormByUuid in interface FormServiceAPIExceptionFormService.getFormByUuid(java.lang.String)@Transactional(readOnly=true) public FormField getFormFieldByUuid(String uuid) throws APIException
FormServicegetFormFieldByUuid in interface FormServiceAPIExceptionFormService.getFormFieldByUuid(java.lang.String)@Transactional(readOnly=true) public List<Field> getAllFields() throws APIException
FormServicegetAllFields in interface FormServiceAPIException - Should get all fields including retiredFormService.getAllFields()@Transactional(readOnly=true) public List<Field> getAllFields(boolean includeRetired) throws APIException
FormServicegetAllFields in interface FormServiceincludeRetired - whether or not to include retired FieldsAPIException - Should get all fields including retired when includeRetired is true
 Should get all fields excluding retired when includeRetired is falseFormService.getAllFields(boolean)@Transactional(readOnly=true) public List<FormField> getAllFormFields() throws APIException
FormServicegetAllFormFields in interface FormServiceAPIException - Should get all form fields including retiredFormService.getAllFormFields()@Transactional(readOnly=true) public List<Form> getAllForms() throws APIException
FormServicegetAllForms in interface FormServiceAPIException - Should return all forms including retiredFormService.getAllForms()@Transactional(readOnly=true) public List<Form> getAllForms(boolean includeRetired) throws APIException
FormServicegetAllForms in interface FormServiceincludeRetired - whether or not to return retired formsAPIException - Should return retired forms if includeRetired is true
 Should not return retired forms if includeRetired is falseFormService.getAllForms(boolean)@Transactional(readOnly=true) public List<Field> getFields(Collection<Form> forms, Collection<FieldType> fieldTypes, Collection<Concept> concepts, Collection<String> tableNames, Collection<String> attributeNames, Boolean selectMultiple, Collection<FieldAnswer> containsAllAnswers, Collection<FieldAnswer> containsAnyAnswer, Boolean retired) throws APIException
FormServicegetFields in interface FormServiceforms - on any of these FormsfieldTypes - having any of these FieldTypesconcepts - for any of these ConceptstableNames - for any of these table namesattributeNames - for any of these attribute namesselectMultiple - whether to return only select-multi fieldscontainsAllAnswers - fields with all the following answerscontainsAnyAnswer - fields with any of the following answersretired - only retired/unretired fieldsAPIException - Should get fields with form in given forms
 Should get fields with type in given fieldTypes
 Should get fields with concept in given concepts
 Should get fields with tableName in given tableNames
 Should get fields with attributeName in given attributeNames
 Should get fields with selectMultiple equals true when given selectMultiple equals trueFormService.getFields(java.util.Collection, java.util.Collection,
      java.util.Collection, java.util.Collection, java.util.Collection, java.lang.Boolean,
      java.util.Collection, java.util.Collection, java.lang.Boolean)@Transactional(readOnly=true) public Form getForm(String name) throws APIException
FormServicegetForm in interface FormServicename - exact name of the form to fetchAPIException - Should return null if no form has the exact form nameShould return the form with the highest version, if more than one form with the given name
         exists@Transactional(readOnly=true) public Form getForm(String name, String version) throws APIException
FormServiceFormService.getForm(String)getForm in interface FormServicename - exact name of the form to fetchversion - exact version of the form to fetchAPIException - Should get the specific version of the form with the given nameFormService.getForm(java.lang.String, java.lang.String)@Transactional(readOnly=true) public List<Form> getForms(String fuzzyName, boolean onlyLatestVersion)
FormServicegetForms in interface FormServicefuzzyName - approximate name to matchonlyLatestVersion - whether or not to return only the latest version of each form (by
            name)FormService.getForms(java.lang.String, boolean)@Transactional(readOnly=true) public List<Form> getForms(String partialName, Boolean published, Collection<EncounterType> encounterTypes, Boolean retired, Collection<FormField> containingAnyFormField, Collection<FormField> containingAllFormFields, Collection<Field> fields)
FormServicegetForms in interface FormServicepartialName - partial search of namepublished - whether the form is publishedencounterTypes - whether the form has any of these encounter typesretired - whether the form is retiredcontainingAnyFormField - includes forms that contain any of the specified FormFieldscontainingAllFormFields - includes forms that contain all of the specified FormFieldsfields - whether the form has any of these fields. If a field is used more than once on
            a form, that form is returning more than once in this listFormService.getForms(java.lang.String, java.lang.Boolean,
      java.util.Collection, java.lang.Boolean, java.util.Collection, java.util.Collection,
      java.util.Collection)@Transactional(readOnly=true) public Integer getFormCount(String partialName, Boolean published, Collection<EncounterType> encounterTypes, Boolean retired, Collection<FormField> containingAnyFormField, Collection<FormField> containingAllFormFields, Collection<Field> fields)
FormServiceFormService.getForms(String, Boolean, Collection, Boolean, Collection, Collection, Collection)
 except that it returns an integer that is the size of the list that would be returned@Transactional(readOnly=true) public List<Form> getPublishedForms() throws APIException
FormServicegetPublishedForms in interface FormServiceAPIException - Should only return published forms that are not retiredFormService.getPublishedForms()public void purgeField(Field field) throws APIException
FormServicepurgeField in interface FormServicefield - the Field to purgeAPIException - Should delete given field successfullyFormService.purgeField(org.openmrs.Field)public void purgeField(Field field, boolean cascade) throws APIException
FormServicepurgeField in interface FormServicefield - the Field to purgecascade - whether to cascade delete all FormFields pointing to this fieldAPIException - Should throw APIException if cascade is trueFormService.purgeField(org.openmrs.Field, boolean)public void purgeForm(Form form) throws APIException
FormServicepurgeForm in interface FormServiceAPIException - Should delete given form successfully
 Should delete form resources for deleted form
 Should throw an error when trying to delete a form while forms are lockedFormService.purgeForm(org.openmrs.Form)public void purgeForm(Form form, boolean cascade) throws APIException
FormServicepurgeForm in interface FormServicecascade - whether or not to cascade delete all dependent objects (including encounters!)APIException - Should throw APIException if cascade is trueFormService.purgeForm(org.openmrs.Form, boolean)public void purgeFormField(FormField formField) throws APIException
FormServicepurgeFormField in interface FormServiceformField - the FormField to purgeAPIException - Should delete the given form field successfullyFormService.purgeFormField(org.openmrs.FormField)public Field retireField(Field field) throws APIException
FormServiceretireField in interface FormServicefield - the Field to retireAPIException - Should set the retired bit before savingFormService.retireField(org.openmrs.Field)public Field saveField(Field field) throws APIException
FormServicesaveField in interface FormServicefield - the Field to saveAPIException - Should save given field successfully
 Should update an existing fieldFormService.saveField(org.openmrs.Field)public Form saveForm(Form form) throws APIException
FormServicesaveForm in interface FormServiceform - the Form to saveAPIException - Should save given form successfully
 Should update an existing form
 Should throw an error when trying to save an existing form while forms are locked
 Should throw an error when trying to save a new form while forms are lockedFormService.saveForm(org.openmrs.Form)public FormField saveFormField(FormField formField) throws APIException
FormServicesaveFormField in interface FormServiceformField - the FormField to saveAPIException - Should propagate save to the Field property on the given FormField
 Should save given formField successfully
 Should inject form fields from serializable complex obs handlersFormService.saveFormField(org.openmrs.FormField)public Field unretireField(Field field) throws APIException
FormServiceunretireField in interface FormServicefield - the Field to unretireAPIException - Should unset the retired bit before savingFormService.unretireField(org.openmrs.Field)public List<Field> getFields(String fuzzySearchPhrase) throws APIException
FormServicegetFields in interface FormServiceAPIException - Should get fields with name matching fuzzySearchPhrase at beginning
 Should get fields with name matching fuzzySearchPhrase at middle
 Should get fields with name matching fuzzySearchPhrase at end
 Should return fields in alphabetical order by nameFormService.getFields(java.lang.String)@Transactional(readOnly=true) public List<Field> getFieldsByConcept(Concept concept) throws APIException
FormServicegetFieldsByConcept in interface FormServiceconcept - the concept to search for in the Field tableAPIException - Should get fields with concept matching given conceptFormService.getFieldsByConcept(org.openmrs.Concept)@Transactional(readOnly=true) public List<Form> getFormsContainingConcept(Concept concept) throws APIException
FormServicegetFormsContainingConcept in interface FormServiceconcept - the concept to search for in formsAPIException - Should get forms with field matching given concept
 Should get all forms for conceptFormService.getFormsContainingConcept(org.openmrs.Concept)public void purgeFieldType(FieldType fieldType) throws APIException
FormServicepurgeFieldType in interface FormServicefieldType - the field type to purgeAPIException - Should delete the given field type successfullyFormService.purgeFieldType(org.openmrs.FieldType)public FieldType saveFieldType(FieldType fieldType) throws APIException
FormServicesaveFieldType in interface FormServicefieldType - the field type to saveAPIException - Should create new field type
 Should update existing field typeFormService.saveFieldType(org.openmrs.FieldType)public int mergeDuplicateFields()
                         throws APIException
FormServicemergeDuplicateFields in interface FormServiceAPIException - Should should merge fields with similar attributesFormService.mergeDuplicateFields()@Transactional(readOnly=true) public FormResource getFormResource(Integer formResourceId) throws APIException
FormServicegetFormResource in interface FormServiceformResourceId - the id of the resource
 Should find a saved FormResource
 Should return null if no FormResource foundAPIExceptionFormService.getFormResource(java.lang.Integer)@Transactional(readOnly=true) public FormResource getFormResourceByUuid(String uuid) throws APIException
FormServicegetFormResourceByUuid in interface FormServiceuuid - the uuid of the resourceAPIExceptionFormService.getFormResourceByUuid(java.lang.String)@Transactional(readOnly=true) public FormResource getFormResource(Form form, String name) throws APIException
FormServicegetFormResource in interface FormServiceform - the Form that the resource belongs toname - the name of the resourceAPIExceptionFormService.getFormResource(org.openmrs.Form, java.lang.String)public FormResource saveFormResource(FormResource formResource) throws APIException
FormServicesaveFormResource in interface FormServiceformResource - the resource to be saved
 Should persist a FormResource
 Should overwrite an existing resource with same name
 Should be able to save an XSLTAPIExceptionFormService.saveFormResource(org.openmrs.FormResource)public void purgeFormResource(FormResource formResource) throws APIException
FormServicepurgeFormResource in interface FormServiceformResource - the resource to be purged
 Should delete a form resourceAPIExceptionFormService.purgeFormResource(org.openmrs.FormResource)@Transactional(readOnly=true) public Collection<FormResource> getFormResourcesForForm(Form form) throws APIException
FormServicegetFormResourcesForForm in interface FormServiceAPIExceptionFormService.getFormResourcesForForm(org.openmrs.Form)public void checkIfFormsAreLocked()
FormServicecheckIfFormsAreLocked in interface FormServiceCopyright © 2024 OpenMRS Inc.. All rights reserved.