Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • FormFilter module adds the capability to restrict the list of available forms on form entry tab of patient dashboard.
  • This module depends on FormEntry module.
  • Steps to assign a filter to a form are described here.
  • Currently At present , FormFilter module restricts form list by 3 aspects on the patient dashboard mainly by 3 scenarios.
    1. Patient , on who's dashboard the forms are shown.
    2. User , who want to view form list on a patient dashboard.
    3. General , other factors.

...

  • All filters implement FormFilterHandler interface and shouldDisplayForm(Patient p, User u) method returns true or false to show the form or and false if not required.
Code Block
/**
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
package org.openmrs.module.formfilter;

import org.openmrs.Patient;
import org.openmrs.User;

/**
 * This interface helps to create form filters.
 * @author goutham
 */
public interface FormFilterHandler {


 /**
  * This method holds the logic to return true or false for given 
  * Patient and User. 
  *  
  * @return True/False ,if filter properties satisfy provided condition.
  */
 public boolean shouldDisplayForm(Patient p, User u);

}

...

  • Filtering is based on "Anding" i.e if any one assigned filter returns a false ,form fails to show on then form does not appear on the patient dashboard.
  • All filters should have a single string parameter constructor .It which takes filter properties as input. This constructor can be used to initialize filter properties.
    Example:
    Code Block
    package org.openmrs.module.formfilter.impl;
    
    import java.lang.reflect.Field;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.openmrs.Patient;
    import org.openmrs.User;
    import org.openmrs.module.formfilter.FormFilterHandler;
    
    /**
     * This class will provide patient age based form filter.
     */
    public class AgeFormFilter implements FormFilterHandler {
    
    	protected Log log = LogFactory.getLog(getClass());
    
    	/**
    	 * Default Constructor
    	 */
    	public AgeFormFilter()
    	{
    
    	}
    
    	/**
    	 * Constructor sets class field values.
    	 * @param properties ,string property from FormFilterProperty class in key=value based format
    	 * Example: minimumAge=value&maximumAge=value
    	 */
    	public AgeFormFilter(String properties){
    		for (String string : properties.split("&")) {
    	        String str[]=string.split("=");
    	        try {
    	            Field field=this.getClass().getDeclaredField(str[0]);
    	            field.set(this, (Object)Integer.parseInt(str[1]));
                }catch (Exception e) {
                	log.info(e);
                }
    		}
    
    	}
    
    	private int minimumAge;
    
    	private int maximumAge;
    
    
    	/**
    	 * @return minimumAge
    	 */
        public int getMinimumAge() {
        	return minimumAge;
        }
    
        /**
    	 * Sets maximumAge
    	 *
    	 * @param maximumAge
    	 */
        public void setMinimumAge(int minimumAge) {
        	this.minimumAge = minimumAge;
        }
    
    
        /**
    	 * @return maximumAge
    	 */
        public int getMaximumAge() {
        	return maximumAge;
        }
    
    	/**
    	 * Sets maximumAge
    	 *
    	 * @param maximumAge
    	 */
        public void setMaximumAge(int maximumAge) {
        	this.maximumAge = maximumAge;
        }
    
        /**
         * @see org.openmrs.module.formfilter.FormFilterHandler#shouldDisplayForm(org.openmrs.Patient, org.openmrs.User)
         * @return True , if patient age lies between minimumAge and maximumAge.
         * @return False, if patient age does not between minimumAge and maximumAge.
         */
        @Override
        public boolean shouldDisplayForm(Patient p, User u) {
    	    // TODO Auto-generated method stub
    
    	    if((p.getAge()>=minimumAge) && (p.getAge()<=maximumAge))
    	    {
    	    	return true;
    	    }
    	    return false;
        }
    
    }
    

Filters

Based on above mentioned the 3 categories currently mentioned above , currently  they are 6 filters defined in form filter module.

...

3)Cohort Form Filter
Patient should be defined in the cohort.
Parameter: a)Cohort
 
Form is shown on dashboard if the patient is defined in "Male Cohort"

4)Date Form Filter
Form is shown compared to today By default the date field in the form is compared with today's date.
Parameter: a) Date  b) when to show "before" or "after".
Example:

Form is shown "before" 15/08/2012(date)

...