Skip to content

Commit

Permalink
Create a new PersonAddress/PersonName when an address/name field is c…
Browse files Browse the repository at this point in the history
…hanged respectively in the short patient form - TRUNK-1972

git-svn-id: http://svn.openmrs.org/openmrs/trunk@18180 5bac5841-c719-aa4e-b3fe-cce5062f897a
  • Loading branch information
wluyima committed Feb 11, 2011
1 parent 5e77b77 commit 8dd0cdc
Show file tree
Hide file tree
Showing 9 changed files with 662 additions and 48 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/org/openmrs/PersonAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public PersonAddress(Integer personAddressId) {
*/
public String toString() {
return "a1:" + getAddress1() + ", a2:" + getAddress2() + ", cv:" + getCityVillage() + ", sp:" + getStateProvince()
+ ", c:" + getCountry() + ", cd:" + getCountyDistrict() + ", nc:" + getNeighborhoodCell() + ", pc:"
+ ", c:" + getCountry() + ", cd:" + getCountyDistrict() + ", nc:" + getAddress3() + ", pc:"
+ getPostalCode() + ", lat:" + getLatitude() + ", long:" + getLongitude();
}

Expand Down Expand Up @@ -410,8 +410,8 @@ public void setNeighborhoodCell(String address3) {
*/
public boolean isBlank() {
return getAddress1() == null && getAddress2() == null && getCityVillage() == null && getStateProvince() == null
&& getCountry() == null && getCountyDistrict() == null && getNeighborhoodCell() == null
&& getPostalCode() == null && getLatitude() == null && getLongitude() == null;
&& getCountry() == null && getCountyDistrict() == null && getAddress3() == null && getPostalCode() == null
&& getLatitude() == null && getLongitude() == null;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions api/src/main/java/org/openmrs/PersonName.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public boolean equals(Object obj) {
return (this.personNameId.equals(pname.getPersonNameId()));
else {
return (OpenmrsUtil.nullSafeEquals(getPerson(), pname.getPerson())
&& OpenmrsUtil.nullSafeEquals(getGivenName(), pname.getGivenName())
&& OpenmrsUtil.nullSafeEquals(getMiddleName(), pname.getMiddleName()) && OpenmrsUtil.nullSafeEquals(
getFamilyName(), pname.getFamilyName()));
&& OpenmrsUtil.nullSafeEqualsIgnoreCase(getGivenName(), pname.getGivenName())
&& OpenmrsUtil.nullSafeEqualsIgnoreCase(getMiddleName(), pname.getMiddleName()) && OpenmrsUtil
.nullSafeEqualsIgnoreCase(getFamilyName(), pname.getFamilyName()));
}

}
Expand Down Expand Up @@ -503,7 +503,6 @@ public void setVoidReason(String voidReason) {
* {@link #getMiddleName()}, etc are null, they are not included in the returned name
*
* @return all of the parts of this {@link PersonName} joined with spaces
*
* @should not put spaces around an empty middle name
*/
public String getFullName() {
Expand Down
19 changes: 19 additions & 0 deletions api/src/main/java/org/openmrs/util/OpenmrsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2344,4 +2344,23 @@ public static Properties getRuntimeProperties(String applicationName) {
return null;
}
}

/**
* Performs a case insensitive Comparison of two strings taking care of null values
*
* @param s1 the string to compare
* @param s2 the string to compare
* @return
* @should return false if only one of the strings is null
* @should be case insensitive
* @since 1.8
*/
public static boolean nullSafeEqualsIgnoreCase(String s1, String s2) {
if (s1 == null)
return s2 == null;
else if (s2 == null)
return false;

return s1.equalsIgnoreCase(s2);
}
}
18 changes: 18 additions & 0 deletions api/src/test/java/org/openmrs/util/OpenmrsUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,4 +756,22 @@ public void shortenedStackTrace_shouldRemoveSpringframeworkAndReflectionRelatedL
public void shortenedStackTrace_shouldReturnNullIfStackTraceIsNull() throws Exception {
Assert.assertNull("null value was not returned with null parameter", OpenmrsUtil.shortenedStackTrace(null));
}

/**
* @see {@link OpenmrsUtil#nullSafeEqualsIgnoreCase(String,String)}
*/
@Test
@Verifies(value = "should be case insensitive", method = "nullSafeEqualsIgnoreCase(String,String)")
public void nullSafeEqualsIgnoreCase_shouldBeCaseInsensitive() throws Exception {
Assert.assertTrue(OpenmrsUtil.nullSafeEqualsIgnoreCase("equal", "Equal"));
}

/**
* @see {@link OpenmrsUtil#nullSafeEqualsIgnoreCase(String,String)}
*/
@Test
@Verifies(value = "should return false if only one of the strings is null", method = "nullSafeEqualsIgnoreCase(String,String)")
public void nullSafeEqualsIgnoreCase_shouldReturnFalseIfOnlyOneOfTheStringsIsNull() throws Exception {
Assert.assertFalse(OpenmrsUtil.nullSafeEqualsIgnoreCase(null, ""));
}
}
Loading

0 comments on commit 8dd0cdc

Please sign in to comment.