Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 4599

Show
Ignore:
Timestamp:
06/10/08 17:35:23 (5 months ago)
Author:
upul
Message:

tribe module: ticket #652,
leave a manage tribes notice page at the old location,
implement org.openmrs.patientDashboard.Header extensionPoint,
integrate upgrade sql to module code: activator,
tribe service comments,
tribe service save, purge,
tribe service priviledge annotation,
throw exception for old openmrs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/tribe/metadata/config.xml

    r4505 r4599  
    2626        </extension> 
    2727         
     28        <extension> 
     29                <point>org.openmrs.patientDashboard.Header</point> 
     30                <class>@MODULE_PACKAGE@.extension.html.PatientDashboardHeader</class> 
     31        </extension> 
    2832         
    2933        <!-- AOP 
  • openmrs-modules/tribe/metadata/messages_it.properties

    r4505 r4599  
    11@MODULE_ID@.title=Tribe Module 
    22@MODULE_ID@.manage=Gestisci le tribu' 
     3 
    34@MODULE_ID@.manage.title=Gestione delle Tribu' 
    45@MODULE_ID@.title=Schermata della Tribu' 
  • openmrs-modules/tribe/metadata/sqldiff.xml

    r4505 r4599  
    2222                </description> 
    2323                <sql> 
    24                         CREATE TABLE IF NOT EXISTS tribe ( 
    25                           tribe_id int(11) NOT NULL auto_increment, 
    26                           retired tinyint(1) NOT NULL default '0', 
    27                           name varchar(50) NOT NULL default '', 
    28                           PRIMARY KEY  (tribe_id) 
    29                         ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
     24CREATE TABLE IF NOT EXISTS tribe ( 
     25  tribe_id int(11) NOT NULL auto_increment, 
     26  retired tinyint(1) NOT NULL default '0', 
     27  name varchar(50) NOT NULL default '', 
     28  PRIMARY KEY  (tribe_id) 
     29) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
     30 
     31INSERT INTO person_attribute_type  
     32        (name, description, format, creator, date_created)  
     33        VALUES ('Tribe', 'Tribe of the person', 'org.openmrs.module.tribe.Tribe', 1, now());             
    3034                </sql> 
    3135        </diff> 
  • openmrs-modules/tribe/src/org/openmrs/module/tribe/Tribe.java

    r4505 r4599  
    165165        } 
    166166         
     167 
     168        /** 
     169         * listField.tag generic fieldGen handler value 
     170         */ 
    167171        public String getValue() { 
    168172                return String.valueOf(tribeId); 
    169173        } 
    170          
     174 
     175        /** 
     176         * listField.tag generic fieldGen handler label 
     177         */      
    171178        public String getLabel() { 
    172179                return name; 
  • openmrs-modules/tribe/src/org/openmrs/module/tribe/TribeActivator.java

    r4505 r4599  
    1616import org.apache.commons.logging.Log; 
    1717import org.apache.commons.logging.LogFactory; 
     18import org.openmrs.api.AdministrationService; 
     19import org.openmrs.api.context.Context; 
    1820import org.openmrs.module.Activator; 
     21import org.openmrs.module.ModuleException; 
     22import org.openmrs.util.OpenmrsClassLoader; 
    1923 
    2024/** 
     
    3135        public void startup() { 
    3236                log.info("Starting Tribe Module"); 
     37                 
     38                // check whether tribe module is installed in an old OpenMRS 
     39                // throw exception if it is 
     40                boolean isOldOpenMRS = true; 
     41                try { 
     42                        Class cls = OpenmrsClassLoader.getInstance().loadClass("org.openmrs.Tribe"); 
     43                } catch (ClassNotFoundException e) { 
     44                        // OpenMRS version ok 
     45                        isOldOpenMRS = false; 
     46                } 
     47                if(isOldOpenMRS) { 
     48                        throw new ModuleException("Tribe module cannot be used with this OpenMRS version. Please upgrade OpenMRS."); 
     49                } 
     50                 
     51                // now convert patient tribes to tribe attributes 
     52                AdministrationService as = Context.getAdministrationService(); 
     53 
     54                // check whether patient table has tribe column 
     55                log.info("Ignore the error message if occurs: " + 
     56                                "Error while running sql: SELECT distinct tribe from patient where 1 = 0"); 
     57                log.info("The above message indicates that you are running a new implementation " + 
     58                                "which does not have a tribe column in the patient table."); 
     59                boolean isTribeColumnExists = true; 
     60                try { 
     61                        as.executeSQL("SELECT distinct tribe from patient where 1 = 0", true); 
     62                } catch (Exception e) { 
     63                        // tribe column not found 
     64                        isTribeColumnExists = false; 
     65                } 
     66                 
     67                if(isTribeColumnExists) { 
     68                        // create tribe attributes 
     69                        log.info("Transforming tribe details"); 
     70                        as.executeSQL( 
     71                                "INSERT INTO person_attribute (person_id, value, person_attribute_type_id, creator, date_created)" 
     72                                + " SELECT patient_id, tribe,"  
     73                                + " (SELECT person_attribute_type_id FROM person_attribute_type WHERE name = 'Tribe')" 
     74                                + " , 1, now() FROM patient WHERE tribe IS NOT NULL;" 
     75                                , false); 
     76                         
     77                        // drop tribe column in patient, this will make these scripts not run again 
     78                        log.info("Dropping old tribe column"); 
     79                        as.executeSQL("ALTER TABLE patient DROP FOREIGN KEY belongs_to_tribe;", false); 
     80                        as.executeSQL("ALTER TABLE patient DROP COLUMN tribe;", false); 
     81                         
     82                        log.info("Tribe data conversion complete"); 
     83                } 
     84                 
    3385        } 
    3486         
  • openmrs-modules/tribe/src/org/openmrs/module/tribe/TribeService.java

    r4505 r4599  
    2121import org.openmrs.api.OpenmrsService; 
    2222import org.openmrs.module.tribe.db.TribeDAO; 
     23import org.openmrs.util.OpenmrsConstants; 
    2324import org.springframework.transaction.annotation.Transactional; 
    2425 
     26/** 
     27 * Tribe objects administration functions  
     28 * 
     29 */ 
    2530@Transactional 
    2631public interface TribeService extends OpenmrsService { 
     
    3338         
    3439        /** 
     40         * Create or update Tribe 
    3541         */ 
    36         public void createTribe(Tribe tribe) throws APIException; 
     42        @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES }) 
     43        public void saveTribe(Tribe tribe) throws APIException; 
    3744 
    3845        /** 
    39          * Update Tribe 
     46         * Purge Tribe 
    4047         */ 
    41         public void updateTribe(Tribe tribe) throws APIException; 
    42  
    43         /** 
    44          * Delete Tribe 
    45          */ 
    46         public void deleteTribe(Tribe tribe) throws APIException; 
     48        @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES }) 
     49        public void purgeTribe(Tribe tribe) throws APIException; 
    4750 
    4851        /** 
    4952         * Retire Tribe 
    5053         */ 
     54        @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES })      
    5155        public void retireTribe(Tribe tribe) throws APIException; 
    5256 
     
    5458         * Unretire Tribe 
    5559         */ 
     60        @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES })      
    5661        public void unretireTribe(Tribe tribe) throws APIException; 
    5762         
  • openmrs-modules/tribe/src/org/openmrs/module/tribe/db/TribeDAO.java

    r4505 r4599  
    2121 
    2222public interface TribeDAO { 
     23 
    2324        /** 
    24          * Create a new Tribe 
    25          * @param Tribe to create 
     25         * Create or update Tribe 
     26         * @param Tribe to create or update 
    2627         * @throws DAOException 
    2728         */ 
    28         public void createTribe(Tribe tribe) throws DAOException; 
    29  
    30         /** 
    31          * Update Tribe 
    32          * @param Tribe to update 
    33          * @throws DAOException 
    34          */ 
    35         public void updateTribe(Tribe tribe) throws DAOException; 
     29        public void saveTribe(Tribe tribe) throws DAOException; 
    3630 
    3731        /** 
     
    4034         * @throws DAOException 
    4135         */ 
    42         public void deleteTribe(Tribe tribe) throws DAOException;      
     36        public void purgeTribe(Tribe tribe) throws DAOException;       
    4337         
    4438        /** 
  • openmrs-modules/tribe/src/org/openmrs/module/tribe/db/hibernate/HibernateTribeDAO.java

    r4505 r4599  
    4747         
    4848        /** 
    49          * @see org.openmrs.api.db.AdministrationService#createTribe(org.openmrs.Tribe) 
    50          */ 
    51         public void createTribe(Tribe tribe) throws DAOException { 
    52                 sessionFactory.getCurrentSession().save(tribe); 
    53         } 
    54          
    55         /** 
    5649         * @see org.openmrs.api.db.AdministrationService#updateTribe(org.openmrs.Tribe) 
    5750         */ 
    58         public void updateTribe(Tribe tribe) throws DAOException { 
    59                 if (tribe.getTribeId() == null) 
    60                         createTribe(tribe); 
    61                 else 
    62                         sessionFactory.getCurrentSession().saveOrUpdate(tribe); 
     51        public void saveTribe(Tribe tribe) throws DAOException { 
     52                sessionFactory.getCurrentSession().saveOrUpdate(tribe); 
    6353        }        
    6454 
     
    6656         * @see org.openmrs.api.db.AdministrationService#deleteTribe(org.openmrs.Tribe) 
    6757         */ 
    68         public void deleteTribe(Tribe tribe) throws DAOException { 
     58        public void purgeTribe(Tribe tribe) throws DAOException { 
    6959                sessionFactory.getCurrentSession().delete(tribe); 
    7060        } 
     
    7565        public void retireTribe(Tribe tribe) throws DAOException { 
    7666                tribe.setRetired(true); 
    77                 updateTribe(tribe); 
     67                saveTribe(tribe); 
    7868        } 
    7969 
     
    8373        public void unretireTribe(Tribe tribe) throws DAOException { 
    8474                tribe.setRetired(false); 
    85                 updateTribe(tribe); 
     75                saveTribe(tribe); 
    8676        } 
    8777         
     
    10090        /** 
    10191         * @see org.openmrs.api.PatientService#getTribes() 
    102          * @deprecated tribe will be moved to patient attribute 
    10392         */ 
    10493        @SuppressWarnings("unchecked") 
     
    113102        /** 
    114103         * @see org.openmrs.api.PatientService#findTribes() 
    115          * @deprecated tribe will be moved to patient attribute 
    116104         */ 
    117105        @SuppressWarnings("unchecked") 
  • openmrs-modules/tribe/src/org/openmrs/module/tribe/impl/TribeServiceImpl.java

    r4505 r4599  
    3737 
    3838        /** 
    39          * Create a new Tribe 
    40          *  
    41          * @param Tribe to create 
    42          * @throws APIException 
    43          */ 
    44         public void createTribe(Tribe tribe) throws APIException { 
    45                 if (!Context.hasPrivilege(TribeConstants.PRIV_MANAGE_TRIBES)) 
    46                         throw new APIAuthenticationException("Privilege required: " 
    47                                 + TribeConstants.PRIV_MANAGE_TRIBES); 
    48  
    49                 dao.createTribe(tribe); 
    50         } 
    51  
    52         /** 
    5339         * Update Tribe 
    5440         *  
     
    5642         * @throws APIException 
    5743         */ 
    58         public void updateTribe(Tribe tribe) throws APIException { 
    59                 if (!Context.hasPrivilege(TribeConstants.PRIV_MANAGE_TRIBES)) 
    60                         throw new APIAuthenticationException("Privilege required: " 
    61                                 + TribeConstants.PRIV_MANAGE_TRIBES); 
    62  
    63                 dao.updateTribe(tribe); 
     44        public void saveTribe(Tribe tribe) throws APIException { 
     45                dao.saveTribe(tribe); 
    6446        } 
    6547 
     
    7052         * @throws APIException 
    7153         */ 
    72         public void deleteTribe(Tribe tribe) throws APIException { 
    73                 if (!Context.hasPrivilege(TribeConstants.PRIV_MANAGE_TRIBES)) 
    74                         throw new APIAuthenticationException("Privilege required: " 
    75                                 + TribeConstants.PRIV_MANAGE_TRIBES); 
    76  
    77                 dao.deleteTribe(tribe); 
     54        public void purgeTribe(Tribe tribe) throws APIException { 
     55                dao.purgeTribe(tribe); 
    7856        } 
    7957         
     
    8563         */ 
    8664        public void retireTribe(Tribe tribe) throws APIException { 
    87                 if (!Context.hasPrivilege(TribeConstants.PRIV_MANAGE_TRIBES)) 
    88                         throw new APIAuthenticationException("Privilege required: " 
    89                                 + TribeConstants.PRIV_MANAGE_TRIBES); 
    90  
    9165                dao.retireTribe(tribe); 
    9266        } 
     
    9973         */ 
    10074        public void unretireTribe(Tribe tribe) throws APIException { 
    101                 if (!Context.hasPrivilege(TribeConstants.PRIV_MANAGE_TRIBES)) 
    102                         throw new APIAuthenticationException("Privilege required: " 
    103                                 + TribeConstants.PRIV_MANAGE_TRIBES); 
    104  
    10575                dao.unretireTribe(tribe); 
    10676        } 
  • openmrs-modules/tribe/web/src/org/openmrs/module/tribe/web/controller/TribeFormController.java

    r4505 r4599  
    6969                if (Context.isAuthenticated()) { 
    7070                        Tribe tribe = (Tribe)obj; 
    71                         ((TribeService)Context.getService(TribeService.class)).updateTribe(tribe); 
     71                        ((TribeService)Context.getService(TribeService.class)).saveTribe(tribe); 
    7272                        view = getSuccessView(); 
    7373 
  • openmrs-modules/tribe/web/src/org/openmrs/module/tribe/web/controller/TribeListController.java

    r4505 r4599  
    8787                        String changed = msa.getMessage("general.changed"); 
    8888                        String notChanged = msa.getMessage("general.cannot.change"); 
    89                         for (String t : tribeList) { 
    90                                 //TODO convenience method deleteOrderType(Integer) ?? 
    91                                 try { 
    92                                         if (action.equals("retire")) 
    93                                                 ts.retireTribe(ts.getTribe(Integer.valueOf(t))); 
    94                                         if (action.equals("unretire")) 
    95                                                 ts.unretireTribe(ts.getTribe(Integer.valueOf(t))); 
    96                                         if (!success.equals("")) success += "<br/>"; 
    97                                         success += t + " " + changed; 
    98                                 } 
    99                                 catch (APIException e) { 
    100                                         log.warn("Error deleting tribe", e); 
    101                                         if (!error.equals("")) error += "<br/>"; 
    102                                         error += t + " " + notChanged; 
     89                         
     90                        if(tribeList != null) { 
     91                                for (String t : tribeList) { 
     92                                        try { 
     93                                                if (action.equals("retire")) 
     94                                                        ts.retireTribe(ts.getTribe(Integer.valueOf(t))); 
     95                                                if (action.equals("unretire")) 
     96                                                        ts.unretireTribe(ts.getTribe(Integer.valueOf(t))); 
     97                                                if (!success.equals("")) success += "<br/>"; 
     98                                                success += t + " " + changed; 
     99                                        } 
     100                                        catch (APIException e) { 
     101                                                log.warn("Error deleting tribe", e); 
     102                                                if (!error.equals("")) error += "<br/>"; 
     103                                                error += t + " " + notChanged; 
     104                                        } 
    103105                                } 
    104106                        }