Skip to content

Commit

Permalink
Fix edge case bug on advanced search
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed May 25, 2021
1 parent 13bf29e commit 725051b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=0.6.15-SNAPSHOT
VERSION_NAME=0.6.16-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Child Library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void search(final Map<String, String> editMap, final ChildAdvancedSearchC
}

private Response<String> globalSearch(Map<String, String> searchParameters) {
if (Boolean.parseBoolean(ChildLibrary.getInstance().getProperties()
.getProperty(ChildAppProperties.KEY.USE_NEW_ADVANCE_SEARCH_APPROACH, "false"))) {
if (ChildLibrary.getInstance().getProperties().isTrue(ChildAppProperties.KEY.USE_NEW_ADVANCE_SEARCH_APPROACH)) {
return retrieveRemoteClients(searchParameters);
}
String paramString = "";
Expand Down Expand Up @@ -144,9 +143,8 @@ private String generateChildSearchParameters(Map<String, String> searchParameter

//Handle name param - use either firs/last name //TODO server does not support full name
String name = searchParameters.remove(Constants.KEY.FIRST_NAME);
if (StringUtils.isBlank(name)) {
name = searchParameters.remove(Constants.KEY.LAST_NAME);
}
String lastname = searchParameters.remove(Constants.KEY.LAST_NAME);
name = StringUtils.isNotBlank(name) ? name : lastname;

if (StringUtils.isNotBlank(name)) {
queryParamStringBuilder.append("?name=").append(name);
Expand Down Expand Up @@ -177,7 +175,7 @@ private String getChildBirthDateParameter(Map<String, String> searchParameters,
String[] birthDates = birthDatesString != null ? birthDatesString.split(":") : new String[]{};
if (birthDates != null && birthDates.length == 2 && StringUtils.isNotBlank(name)) {
birthDate = String.format("&birthdate=%s:%s", birthDates[0], birthDates[1]);
} else if (birthDates.length == 2 && StringUtils.isBlank(name)) {
} else if (birthDates != null && birthDates.length == 2 && StringUtils.isBlank(name)) {
birthDate = String.format("?birthdate=%s:%s", birthDates[0], birthDates[1]);
}

Expand Down Expand Up @@ -260,17 +258,16 @@ public SearchMother invoke() {
String motherSearchParameters = "";

String name = searchParameters.remove(Constants.KEY.MOTHER_FIRST_NAME);
if (StringUtils.isBlank(name)) {
name = searchParameters.remove(Constants.KEY.MOTHER_LAST_NAME);
}
String lastname = searchParameters.remove(Constants.KEY.MOTHER_LAST_NAME);
name = StringUtils.isNotBlank(name) ? name : lastname;

if (StringUtils.isNotBlank(name)) {
motherSearchParameters = String.format("?name=%s", name);
}

String phoneNumber = searchParameters.remove(getMotherGuardianPhoneNumber());
if (StringUtils.isNotBlank(motherSearchParameters) && StringUtils.isNotBlank(phoneNumber)) {
motherSearchParameters = String.format("&attribute=%s:%s", getMotherGuardianPhoneNumber(), phoneNumber);
motherSearchParameters = String.format("%s&attribute=%s:%s", motherSearchParameters, getMotherGuardianPhoneNumber(), phoneNumber);
} else if (StringUtils.isBlank(motherSearchParameters) && StringUtils.isNotBlank(phoneNumber)) {
motherSearchParameters = String.format("?attribute=%s:%s", getMotherGuardianPhoneNumber(), phoneNumber);
}
Expand Down

0 comments on commit 725051b

Please sign in to comment.