Skip to content

Commit

Permalink
New method to return EncounterRole objects by their name - TRUNK-3891
Browse files Browse the repository at this point in the history
author:surangak
  • Loading branch information
dkayiwa committed Nov 22, 2013
1 parent e7d0ac7 commit 09e6105
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
24 changes: 20 additions & 4 deletions api/src/main/java/org/openmrs/api/EncounterService.java
Expand Up @@ -355,7 +355,8 @@ public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, D
* @throws APIException
* @should retire type and set attributes
* @should throw error if given null reason parameter
* @should should throw error when trying to retire encounter type when encounter types are locked
* @should should throw error when trying to retire encounter type when encounter types are
* locked
*/
@Authorized( { PrivilegeConstants.MANAGE_ENCOUNTER_TYPES })
public EncounterType retireEncounterType(EncounterType encounterType, String reason) throws APIException;
Expand All @@ -367,7 +368,8 @@ public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, D
* @param encounterType the encounter type to unretire
* @throws APIException
* @should unretire type and unmark attributes
* @should should throw error when trying to unretire encounter type when encounter types are locked
* @should should throw error when trying to unretire encounter type when encounter types are
* locked
*/
@Authorized( { PrivilegeConstants.MANAGE_ENCOUNTER_TYPES })
public EncounterType unretireEncounterType(EncounterType encounterType) throws APIException;
Expand All @@ -378,7 +380,8 @@ public List<Encounter> getEncounters(Patient who, Location loc, Date fromDate, D
* @param encounterType
* @throws APIException
* @should purge type
* @should should throw error when trying to delete encounter type when encounter types are locked
* @should should throw error when trying to delete encounter type when encounter types are
* locked
*/
@Authorized( { PrivilegeConstants.PURGE_ENCOUNTER_TYPES })
public void purgeEncounterType(EncounterType encounterType) throws APIException;
Expand Down Expand Up @@ -917,9 +920,22 @@ public Integer getEncountersByVisitsAndPatientCount(Patient patient, boolean inc
public boolean canViewEncounter(Encounter encounter, User subject);

/**
* Check if the encounter types are locked, and if so, throw exception during manipulation of encounter type
* Check if the encounter types are locked, and if so, throw exception during manipulation of
* encounter type
*
* @throws EncounterTypeLockedException
*/
public void checkIfEncounterTypesAreLocked() throws EncounterTypeLockedException;

/**
* Get EncounterRoles by name
*
* @param name
* @return List of EncounterRole objects
* @since 1.11
* @should find encounter roles based on their name
*/

@Authorized( { PrivilegeConstants.GET_ENCOUNTER_ROLES })
public List<EncounterRole> getEncounterRolesByName(String name);
}
10 changes: 10 additions & 0 deletions api/src/main/java/org/openmrs/api/db/EncounterDAO.java
Expand Up @@ -259,4 +259,14 @@ List<Encounter> getEncountersByVisitsAndPatient(Patient patient, boolean include
*/
Integer getEncountersByVisitsAndPatientCount(Patient patient, boolean includeVoided, String query);

/**
* Get encounter roles by name
*
* @param name encounter role name
* @return encounter roles
* @throws org.openmrs.api.db.DAOException
* @see org.openmrs.api.EncounterRoleService#getEncounterRolesByName(String name)
*/

public List<EncounterRole> getEncounterRolesByName(String name) throws DAOException;
}
Expand Up @@ -624,4 +624,14 @@ private void addEncountersByPatientCriteria(Criteria criteria, Patient patient,
criteria.addOrder(Order.desc("encounterDatetime"));
criteria.addOrder(Order.desc("encounterId"));
}

/**
* @see org.openmrs.api.db.EncounterDAO#getEncounterRolesByName(String)
*/

@Override
public List<EncounterRole> getEncounterRolesByName(String name) throws DAOException {
return sessionFactory.getCurrentSession().createCriteria(EncounterRole.class).add(Restrictions.eq("name", name))
.list();
}
}
Expand Up @@ -1029,4 +1029,12 @@ public void checkIfEncounterTypesAreLocked() {
}
}

/**
* @see org.openmrs.api.EncounterService#getEncounterRolesByName(String)
*/

@Override
public List<EncounterRole> getEncounterRolesByName(String name) {
return dao.getEncounterRolesByName(name);
}
}
26 changes: 18 additions & 8 deletions api/src/test/java/org/openmrs/api/EncounterServiceTest.java
Expand Up @@ -2439,7 +2439,6 @@ private Encounter getEncounterWithViewPrivilege() {

/**
* @see {@link EncounterService#getEncounters(String,Integer,Integer,Integer,null)}
*
*/
@Test
@Verifies(value = "should fetch encounters by patient id", method = "getEncounters(String,Integer,Integer,Integer,null)")
Expand Down Expand Up @@ -2500,7 +2499,6 @@ public void getEncounters_shouldIncludeVoidedEncountersIfIncludeVoidedIsSetToTru

/**
* @see {@link EncounterService#getEncounters(String,Integer,Integer,Integer,null)}
*
*/
@Test
@Verifies(value = "should match on the encounter type name", method = "getEncounters(String,Integer,Integer,Integer,null)")
Expand All @@ -2510,7 +2508,6 @@ public void getEncounters_shouldMatchOnTheEncounterTypeName() throws Exception {

/**
* @see {@link EncounterService#getEncounters(String,Integer,Integer,Integer,null)}
*
*/
@Test
@Verifies(value = "should match on the form name", method = "getEncounters(String,Integer,Integer,Integer,null)")
Expand All @@ -2519,8 +2516,8 @@ public void getEncounters_shouldMatchOnTheFormName() throws Exception {
}

/**
* @see {@link EncounterService#saveEncounterType(EncounterType)}}
* @see {@link EncounterService#checkIfEncounterTypesAreLocked()}}
* @see {@link EncounterService#saveEncounterType(EncounterType)}
* @see {@link EncounterService#checkIfEncounterTypesAreLocked()}
*/
@Test(expected = EncounterTypeLockedException.class)
@Verifies(value = "should throw error when trying to save encounter type when encounter types are locked", method = "saveEncounterType(EncounterType)")
Expand All @@ -2539,7 +2536,7 @@ public void saveEncounterType_shouldThrowErrorWhenTryingToSaveEncounterTypeWhenE
}

/**
* @see {@link EncounterService#retireEncounterType(EncounterType, String)}}
* @see {@link EncounterService#retireEncounterType(EncounterType, String)}
*/
@Test(expected = EncounterTypeLockedException.class)
@Verifies(value = "should throw error when trying to retire encounter type when encounter types are locked", method = "retireEncounterType(EncounterType, String)")
Expand All @@ -2557,7 +2554,7 @@ public void retireEncounterType_shouldThrowErrorWhenTryingToRetireEncounterTypeW
}

/**
* @see {@link EncounterService#unretireEncounterType(EncounterType)}}
* @see {@link EncounterService#unretireEncounterType(EncounterType)}
*/
@Test(expected = EncounterTypeLockedException.class)
@Verifies(value = "should throw error when trying to unretire encounter type when encounter types are locked", method = "unretireEncounterType(EncounterType)")
Expand All @@ -2574,7 +2571,7 @@ public void unretireEncounterType_shouldThrowErrorWhenTryingToUnretireEncounterT
}

/**
* @see {@link EncounterService#purgeEncounterType(EncounterType)}}
* @see {@link EncounterService#purgeEncounterType(EncounterType)}
*/
@Test(expected = EncounterTypeLockedException.class)
@Verifies(value = "should throw error when trying to delete encounter type when encounter types are locked", method = "purgeEncounterType(EncounterType)")
Expand All @@ -2591,4 +2588,17 @@ public void purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWh

encounterService.purgeEncounterType(encounterType);
}

@Test
@Verifies(value = "find encounter roles based on their name", method = "getEncounterRolesByName(String)")
public void getEncounterRolesByName_shouldFindEncounterRolesByName() throws Exception {
EncounterService encounterService = Context.getEncounterService();
String name = "surgeon";

List<EncounterRole> encounterRoles = encounterService.getEncounterRolesByName(name);

assertNotNull("valid EncounterROle object should be returned", encounterRoles);
assertEquals(encounterRoles.size(), 1);
assertEquals(encounterRoles.get(0).getName(), name);
}
}

0 comments on commit 09e6105

Please sign in to comment.