Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
07/30/08 15:52:50 (5 months ago)
Author:
bwolfe
Message:

Adding boolean exactMatch option to PatientService.getPatients

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/src/api/org/openmrs/api/db/hibernate/HibernatePatientDAO.java

    r4551 r5094  
    142142 
    143143        /** 
    144      * @see org.openmrs.api.db.PatientDAO#getPatients(java.lang.String, java.lang.String, java.util.List
     144     * @see org.openmrs.api.db.PatientDAO#getPatients(java.lang.String, java.lang.String, java.util.List, boolean
    145145     */ 
    146146        @SuppressWarnings("unchecked") 
    147147    public List<Patient> getPatients(String name, String identifier, 
    148             List<PatientIdentifierType> identifierTypes) throws DAOException { 
     148            List<PatientIdentifierType> identifierTypes, boolean matchIdentifierExactly) throws DAOException { 
    149149             
    150150        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Patient.class); 
     
    202202                                AdministrationService adminService = Context.getAdministrationService(); 
    203203                                String regex = adminService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, ""); 
    204                  
    205                         // if the regex is empty, default to a simple "like" search or if  
    206                         // we're in hsql world, also only do the simple like search (because 
    207                         // hsql doesn't know how to deal with 'regexp' 
    208                         if (regex.equals("") || HibernateUtil.isHSQLDialect(sessionFactory)) { 
    209                                         String prefix = adminService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_PREFIX, ""); 
     204                                 
     205                                // if the user wants an exact search, match on that. 
     206                        if (matchIdentifierExactly) { 
     207                                        criteria.add(Expression.eq("ids.identifier", identifier)); 
     208                                } 
     209                                // if the regex is empty, default to a simple "like" search or if  
     210                                // we're in hsql world, also only do the simple like search (because 
     211                                // hsql doesn't know how to deal with 'regexp' 
     212                                else if (regex.equals("") || HibernateUtil.isHSQLDialect(sessionFactory)) { 
     213                                String prefix = adminService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_PREFIX, ""); 
    210214                                        String suffix = adminService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SUFFIX, ""); 
    211215                                StringBuffer likeString = new StringBuffer(prefix).append(identifier)