Skip to content

Commit

Permalink
Merge pull request #1421 from mozzy11/develop
Browse files Browse the repository at this point in the history
Patient date of birth should be consistent between Date Locales
  • Loading branch information
mozzy11 authored Jan 21, 2025
2 parents df526c9 + dc448a7 commit 3da9fe3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/common/CustomDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CustomDatePicker = (props) => {
}

function handleInputChange(e) {
const inputValue = event.target.value;
const inputValue = e.target.value;

const isFrenchLocale =
configurationProperties.DEFAULT_DATE_LOCALE === "fr-FR";
Expand All @@ -34,9 +34,9 @@ const CustomDatePicker = (props) => {
: /^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/\d{4}$/;

if (partialDateRegex.test(inputValue)) {
event.target.value = inputValue;
e.target.value = inputValue;
} else {
event.target.value = ""; // Clear invalid input
e.target.value = ""; // Clear invalid input
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<minor.version>1</minor.version>
<state.version>0</state.version>
<!-- 0 = alpha, 1 = beta, 2 = rc, 3 = deployable -->
<fix.version>2</fix.version>
<fix.version>3</fix.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<liquibase.propertyFile>${project.basedir}/liquibase/liquibase.properties</liquibase.propertyFile>
<castor.version>1.4.1</castor.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package org.openelisglobal.common.provider.query;

import java.math.BigDecimal;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.common.util.DateUtil;

public class PatientSearchResults {

Expand Down Expand Up @@ -76,7 +79,7 @@ public String getGender() {
}

public String getDOB() {
return birthdate;
return getFormatedBirthDate();
}

public String getNationalId() {
Expand All @@ -88,7 +91,7 @@ public String getSTNumber() {
}

public String getBirthdate() {
return birthdate;
return getFormatedBirthDate();
}

public void setBirthdate(String birthdate) {
Expand Down Expand Up @@ -198,4 +201,14 @@ public String getContactPhone() {
public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone;
}

public String getFormatedBirthDate() {
String format1 = "dd/MM/yyyy";
String format2 = "MM/dd/yyyy";
birthdate = ConfigurationProperties.getInstance().getPropertyValue(Property.DEFAULT_DATE_LOCALE).equals("fr-FR")
? DateUtil.formatStringDate(birthdate, format1)
: DateUtil.formatStringDate(birthdate, format2);

return birthdate;
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/openelisglobal/common/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ public static java.sql.Date convertDateTimeToSqlDate(Date date) throws LIMSRunti
}

public static String formatStringDate(String dateStr, String outputFormat) {
if (dateStr == null) {
return "";
}
// Define the input date formats
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("MM/dd/yyyy");
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("dd/MM/yyyy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface SearchResultsDAO {
String ID_PARAM = "id";
String GUID = "guid";
String DATE_OF_BIRTH = "dateOfBirth";
String DATE_OF_BIRTH_FORMATED = "dateOfBirthFormatted";
String GENDER = "gender";

String ID_TYPE_FOR_ST = "stNumberId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import org.openelisglobal.common.exception.LIMSRuntimeException;
import org.openelisglobal.common.log.LogEvent;
import org.openelisglobal.common.provider.query.PatientSearchResults;
import org.openelisglobal.common.util.ConfigurationProperties;
import org.openelisglobal.common.util.ConfigurationProperties.Property;
import org.openelisglobal.common.util.DateUtil;
import org.openelisglobal.patientidentitytype.util.PatientIdentityTypeMap;
import org.openelisglobal.sample.dao.SearchResultsDAO;
import org.springframework.context.annotation.Primary;
Expand Down Expand Up @@ -129,6 +132,7 @@ public List<PatientSearchResults> getSearchResults(String lastName, String first
externalID = '%' + externalID + '%';
// patientID = '%' + patientID + '%';
// guid = '%' + guid + '%';
String dobFormated = '%' + getFormatedDOB(dateOfBirth) + '%';
dateOfBirth = '%' + dateOfBirth + '%';
// gender = '%' + gender + '%';

Expand Down Expand Up @@ -158,6 +162,7 @@ public List<PatientSearchResults> getSearchResults(String lastName, String first
}
if (queryDateOfBirth) {
query.setParameter(DATE_OF_BIRTH, dateOfBirth);
query.setParameter(DATE_OF_BIRTH_FORMATED, dobFormated);
}
if (queryGender) {
query.setParameter(GENDER, gender);
Expand Down Expand Up @@ -248,6 +253,7 @@ public List<PatientSearchResults> getSearchResultsExact(String lastName, String
}
if (queryDateOfBirth) {
query.setParameter(DATE_OF_BIRTH, dateOfBirth);
query.setParameter(DATE_OF_BIRTH_FORMATED, getFormatedDOB(dateOfBirth));
}
if (queryGender) {
query.setParameter(GENDER, gender);
Expand All @@ -272,6 +278,15 @@ public List<PatientSearchResults> getSearchResultsExact(String lastName, String
return results;
}

private String getFormatedDOB(String dob) {
String format1 = "dd/MM/yyyy";
String format2 = "MM/dd/yyyy";
String dobFormated = ConfigurationProperties.getInstance().getPropertyValue(Property.DEFAULT_DATE_LOCALE)
.equals("fr-FR") ? DateUtil.formatStringDate(dob, format2) : DateUtil.formatStringDate(dob, format1);

return dobFormated;
}

/**
* @param lastName
* @param firstName
Expand Down Expand Up @@ -367,6 +382,8 @@ private String buildQueryString(boolean lastName, boolean firstName, boolean STN
if (dateOfBirth) {
queryBuilder.append(" p.entered_birth_date ilike :");
queryBuilder.append(DATE_OF_BIRTH);
queryBuilder.append(" or p.entered_birth_date ilike :");
queryBuilder.append(DATE_OF_BIRTH_FORMATED);
queryBuilder.append(" and");
}

Expand Down

0 comments on commit 3da9fe3

Please sign in to comment.