Changeset 4599
- Timestamp:
- 06/10/08 17:35:23 (5 months ago)
- Files:
-
- openmrs-modules/tribe/metadata/config.xml (modified) (1 diff)
- openmrs-modules/tribe/metadata/messages_it.properties (modified) (1 diff)
- openmrs-modules/tribe/metadata/sqldiff.xml (modified) (1 diff)
- openmrs-modules/tribe/metadata/tribe_upgrade.sql (deleted)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/Tribe.java (modified) (1 diff)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/TribeActivator.java (modified) (2 diffs)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/TribeService.java (modified) (3 diffs)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/db/TribeDAO.java (modified) (2 diffs)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/db/hibernate/HibernateTribeDAO.java (modified) (6 diffs)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/extension/html/PatientDashboardHeader.java (added)
- openmrs-modules/tribe/src/org/openmrs/module/tribe/impl/TribeServiceImpl.java (modified) (5 diffs)
- openmrs-modules/tribe/web/src/org/openmrs/module/tribe/web/controller/TribeFormController.java (modified) (1 diff)
- openmrs-modules/tribe/web/src/org/openmrs/module/tribe/web/controller/TribeListController.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs-modules/tribe/metadata/config.xml
r4505 r4599 26 26 </extension> 27 27 28 <extension> 29 <point>org.openmrs.patientDashboard.Header</point> 30 <class>@MODULE_PACKAGE@.extension.html.PatientDashboardHeader</class> 31 </extension> 28 32 29 33 <!-- AOP openmrs-modules/tribe/metadata/messages_it.properties
r4505 r4599 1 1 @MODULE_ID@.title=Tribe Module 2 2 @MODULE_ID@.manage=Gestisci le tribu' 3 3 4 @MODULE_ID@.manage.title=Gestione delle Tribu' 4 5 @MODULE_ID@.title=Schermata della Tribu' openmrs-modules/tribe/metadata/sqldiff.xml
r4505 r4599 22 22 </description> 23 23 <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; 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; 30 31 INSERT 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()); 30 34 </sql> 31 35 </diff> openmrs-modules/tribe/src/org/openmrs/module/tribe/Tribe.java
r4505 r4599 165 165 } 166 166 167 168 /** 169 * listField.tag generic fieldGen handler value 170 */ 167 171 public String getValue() { 168 172 return String.valueOf(tribeId); 169 173 } 170 174 175 /** 176 * listField.tag generic fieldGen handler label 177 */ 171 178 public String getLabel() { 172 179 return name; openmrs-modules/tribe/src/org/openmrs/module/tribe/TribeActivator.java
r4505 r4599 16 16 import org.apache.commons.logging.Log; 17 17 import org.apache.commons.logging.LogFactory; 18 import org.openmrs.api.AdministrationService; 19 import org.openmrs.api.context.Context; 18 20 import org.openmrs.module.Activator; 21 import org.openmrs.module.ModuleException; 22 import org.openmrs.util.OpenmrsClassLoader; 19 23 20 24 /** … … 31 35 public void startup() { 32 36 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 33 85 } 34 86 openmrs-modules/tribe/src/org/openmrs/module/tribe/TribeService.java
r4505 r4599 21 21 import org.openmrs.api.OpenmrsService; 22 22 import org.openmrs.module.tribe.db.TribeDAO; 23 import org.openmrs.util.OpenmrsConstants; 23 24 import org.springframework.transaction.annotation.Transactional; 24 25 26 /** 27 * Tribe objects administration functions 28 * 29 */ 25 30 @Transactional 26 31 public interface TribeService extends OpenmrsService { … … 33 38 34 39 /** 40 * Create or update Tribe 35 41 */ 36 public void createTribe(Tribe tribe) throws APIException; 42 @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES }) 43 public void saveTribe(Tribe tribe) throws APIException; 37 44 38 45 /** 39 * Update Tribe46 * Purge Tribe 40 47 */ 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; 47 50 48 51 /** 49 52 * Retire Tribe 50 53 */ 54 @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES }) 51 55 public void retireTribe(Tribe tribe) throws APIException; 52 56 … … 54 58 * Unretire Tribe 55 59 */ 60 @Authorized( { TribeConstants.PRIV_MANAGE_TRIBES }) 56 61 public void unretireTribe(Tribe tribe) throws APIException; 57 62 openmrs-modules/tribe/src/org/openmrs/module/tribe/db/TribeDAO.java
r4505 r4599 21 21 22 22 public interface TribeDAO { 23 23 24 /** 24 * Create a newTribe25 * @param Tribe to create 25 * Create or update Tribe 26 * @param Tribe to create or update 26 27 * @throws DAOException 27 28 */ 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; 36 30 37 31 /** … … 40 34 * @throws DAOException 41 35 */ 42 public void deleteTribe(Tribe tribe) throws DAOException;36 public void purgeTribe(Tribe tribe) throws DAOException; 43 37 44 38 /** openmrs-modules/tribe/src/org/openmrs/module/tribe/db/hibernate/HibernateTribeDAO.java
r4505 r4599 47 47 48 48 /** 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 /**56 49 * @see org.openmrs.api.db.AdministrationService#updateTribe(org.openmrs.Tribe) 57 50 */ 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); 63 53 } 64 54 … … 66 56 * @see org.openmrs.api.db.AdministrationService#deleteTribe(org.openmrs.Tribe) 67 57 */ 68 public void deleteTribe(Tribe tribe) throws DAOException {58 public void purgeTribe(Tribe tribe) throws DAOException { 69 59 sessionFactory.getCurrentSession().delete(tribe); 70 60 } … … 75 65 public void retireTribe(Tribe tribe) throws DAOException { 76 66 tribe.setRetired(true); 77 updateTribe(tribe);67 saveTribe(tribe); 78 68 } 79 69 … … 83 73 public void unretireTribe(Tribe tribe) throws DAOException { 84 74 tribe.setRetired(false); 85 updateTribe(tribe);75 saveTribe(tribe); 86 76 } 87 77 … … 100 90 /** 101 91 * @see org.openmrs.api.PatientService#getTribes() 102 * @deprecated tribe will be moved to patient attribute103 92 */ 104 93 @SuppressWarnings("unchecked") … … 113 102 /** 114 103 * @see org.openmrs.api.PatientService#findTribes() 115 * @deprecated tribe will be moved to patient attribute116 104 */ 117 105 @SuppressWarnings("unchecked") openmrs-modules/tribe/src/org/openmrs/module/tribe/impl/TribeServiceImpl.java
r4505 r4599 37 37 38 38 /** 39 * Create a new Tribe40 *41 * @param Tribe to create42 * @throws APIException43 */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 /**53 39 * Update Tribe 54 40 * … … 56 42 * @throws APIException 57 43 */ 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); 64 46 } 65 47 … … 70 52 * @throws APIException 71 53 */ 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); 78 56 } 79 57 … … 85 63 */ 86 64 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 91 65 dao.retireTribe(tribe); 92 66 } … … 99 73 */ 100 74 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 105 75 dao.unretireTribe(tribe); 106 76 } openmrs-modules/tribe/web/src/org/openmrs/module/tribe/web/controller/TribeFormController.java
r4505 r4599 69 69 if (Context.isAuthenticated()) { 70 70 Tribe tribe = (Tribe)obj; 71 ((TribeService)Context.getService(TribeService.class)). updateTribe(tribe);71 ((TribeService)Context.getService(TribeService.class)).saveTribe(tribe); 72 72 view = getSuccessView(); 73 73 openmrs-modules/tribe/web/src/org/openmrs/module/tribe/web/controller/TribeListController.java
r4505 r4599 87 87 String changed = msa.getMessage("general.changed"); 88 88 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 } 103 105 } 104 106 }