Skip to content

Commit

Permalink
Martina | BAH-460 | set default time for birthdate to be parsable by …
Browse files Browse the repository at this point in the history
…sql Timestamp functionality
  • Loading branch information
mduemcke committed Aug 9, 2018
1 parent 4685050 commit 170944c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Map;

public class PatientSearchParameters {
private final String MIDNIGHT = "00:00:00";

private Boolean filterPatientsByLocation;
private String identifier;
private String name;
Expand Down Expand Up @@ -86,9 +88,17 @@ public void setGender(String gender) {
}

public void setBirthdate(String birthdate) {
if(StringUtils.isNotEmpty(birthdate) && birthdate.matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}")) {
this.birthdate = Timestamp.valueOf(birthdate);
if(StringUtils.isEmpty(birthdate)) {
return;
}

this.birthdate = Timestamp.valueOf(addTimeIfMissing(birthdate));
}

private String addTimeIfMissing(String birthdate) {
if(StringUtils.isNotEmpty(birthdate) && birthdate.matches("\\d{4}-\\d{2}-\\d{2}")) {
return birthdate + " " + MIDNIGHT;
} else return birthdate;
}

public Date getBirthdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ public void shouldParseTheBirtdateFromString () {
}

@Test
public void shouldIgnoreWronglyFormattedBirthdate () {
when(requestContext.getParameter("birthdate")).thenReturn("1983-01-30");
public void shouldIgnoreEmptyBirthdate () {
when(requestContext.getParameter("birthdate")).thenReturn("");
PatientSearchParameters patientSearchParameters;
patientSearchParameters = new PatientSearchParameters(requestContext);

assertNull(patientSearchParameters.getBirthdate());
}

@Test
public void shouldSetToMidnightForBirthdateIfTimeIsMissing () {
when(requestContext.getParameter("birthdate")).thenReturn("1983-01-30");
PatientSearchParameters patientSearchParameters;
patientSearchParameters = new PatientSearchParameters(requestContext);

assertEquals(Timestamp.valueOf("1983-01-30 00:00:00"), patientSearchParameters.getBirthdate());
}
}

0 comments on commit 170944c

Please sign in to comment.