Skip to content

Commit

Permalink
TRUNK-3202 Add JUnit test for getting by identifier type in method Hi…
Browse files Browse the repository at this point in the history
…bernatePatientDAO.getPatientIdentifiers
  • Loading branch information
akolodziejski authored and rkorytkowski committed Mar 29, 2013
1 parent 179d541 commit 959a6db
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/api/PatientService.java
Expand Up @@ -304,7 +304,7 @@ public List<Patient> getPatients(String name, String identifier, List<PatientIde
* @should return only non voided patients and patient identifiers
* @throws APIException
* @should fetch patient identifiers that exactly matches given identifier
* @should fetch patient identifiers that partially matches given identifier
* @should not fetch patient identifiers that partially matches given identifier
* @should fetch patient identifiers that match given patient identifier types
* @should fetch patient identifiers that match given locations
* @should fetch patient identifiers that match given patients
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/api/db/PatientDAO.java
Expand Up @@ -76,6 +76,8 @@ public List<Patient> getPatients(String name, String identifier, List<PatientIde
* @should return all matching non voided patient identifiers if is preferred is set to false
* @should fetch all patient identifiers belong to given patient
* @should fetch all patient identifiers belong to given patients
* @should fetch patient identifiers that equals given identifier
* @should not fetch patient identifiers that partially matches given identifier
*/
public List<PatientIdentifier> getPatientIdentifiers(String identifier,
List<PatientIdentifierType> patientIdentifierTypes, List<Location> locations, List<Patient> patients,
Expand Down
Expand Up @@ -255,7 +255,6 @@ public List<PatientIdentifier> getPatientIdentifiers(String identifier,
// make sure the patient object isn't voided
criteria.add(Expression.eq("voided", false));

// TODO add junit test for getting by identifier (and for not getting by partial here)
if (identifier != null)
criteria.add(Expression.eq("identifier", identifier));

Expand Down
31 changes: 31 additions & 0 deletions api/src/test/java/org/openmrs/api/db/PatientDAOTest.java
Expand Up @@ -280,6 +280,37 @@ public void getPatientIdentifiers_shouldLimitByResultsByLocation() throws Except
Assert.assertEquals("12345K", patientIdentifiers.get(0).getIdentifier());
}

/**
* @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
* @verifies not fetch patient identifiers that partially matches given identifier
*/
@Test
public void getPatientIdentifiers_shouldNotFetchPatientIdentifiersThatPartiallyMatchesGivenIdentifier() throws Exception {

String identifier = "123"; // identifier [12345K] exist in test dataSet

List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(identifier,
new ArrayList<PatientIdentifierType>(), new ArrayList<Location>(), new ArrayList<Patient>(), null);

Assert.assertTrue(patientIdentifiers.isEmpty());
}

/**
* @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
* @verifies fetch patient identifiers that equals given identifier
*/
@Test
public void getPatientIdentifiers_shouldFetchPatientIdentifiersThatEqualsGivenIdentifier() throws Exception {

String identifier = "101";

List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(identifier,
new ArrayList<PatientIdentifierType>(), new ArrayList<Location>(), new ArrayList<Patient>(), null);

Assert.assertEquals(1, patientIdentifiers.size());
Assert.assertEquals(identifier, patientIdentifiers.get(0).getIdentifier());
}

/**
* @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
* @verifies return all matching non voided patient identifiers if is preferred is set to false
Expand Down

0 comments on commit 959a6db

Please sign in to comment.