Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9cddcf7753ca
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 571f23ab35b2
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on May 23, 2013

  1. TRUNK-3765 [Show the fully-specified birthdate date format like it di…

    …d previously on patient search results]
    k-joseph committed May 23, 2013
    Copy the full SHA
    db560e3 View commit details
  2. Copy the full SHA
    8dda4d0 View commit details

Commits on Jul 31, 2013

  1. Merge pull request #323 from k-joseph/TRUNK-3765

    TRUNK-3765
    dkayiwa committed Jul 31, 2013
    2
    Copy the full SHA
    571f23a View commit details
8 changes: 8 additions & 0 deletions api/src/main/java/org/openmrs/util/OpenmrsConstants.java
Original file line number Diff line number Diff line change
@@ -983,6 +983,11 @@ public static final Collection<String> AUTO_ROLES() {
*/
public static final String GP_SEARCH_WIDGET_MAXIMUM_RESULTS = "searchWidget.maximumResults";

/**
* Global property for the Date format to be used to display date under search widgets and auto-completes
*/
public static final String GP_SEARCH_DATE_DISPLAY_FORMAT = "searchWidget.dateDisplayFormat";

/**
* Global property name for enabling/disabling concept map type management
*/
@@ -1439,6 +1444,9 @@ public static final List<GlobalProperty> CORE_GLOBAL_PROPERTIES() {
"400",
"Specifies time interval in milliseconds when searching, between keyboard keyup event and triggering the search off, should be higher if most users are slow when typing so as to minimise the load on the server"));

props.add(new GlobalProperty(GP_SEARCH_DATE_DISPLAY_FORMAT, null,
"Date display format to be used to display the date somewhere in the UI i.e the search widgets and autocompletes"));

props.add(new GlobalProperty(GLOBAL_PROPERTY_DEFAULT_LOCATION_NAME, "Unknown Location",
"The name of the location to use as a system default"));
props
76 changes: 73 additions & 3 deletions web/src/main/java/org/openmrs/web/WebUtil.java
Original file line number Diff line number Diff line change
@@ -13,18 +13,29 @@
*/
package org.openmrs.web;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.GlobalProperty;
import org.openmrs.api.GlobalPropertyListener;
import org.openmrs.api.context.Context;
import org.openmrs.util.Format.FORMAT_TYPE;
import org.openmrs.util.LocaleUtility;
import org.openmrs.util.OpenmrsConstants;
import org.openmrs.util.OpenmrsDateFormat;

public class WebUtil {
public class WebUtil implements GlobalPropertyListener {

private static Log log = LogFactory.getLog(WebUtil.class);

private static String defaultDateCache = null;

public static String escapeHTML(String s) {

if (s == null)
@@ -171,12 +182,71 @@ public static String sanitizeLocales(String localesString) {
}

/**
* Method that returns WebConstants.WEBAPP_NAME or an empty string if WebConstants.WEBAPP_NAME is empty.
*
* Method that returns WebConstants.WEBAPP_NAME or an empty string if WebConstants.WEBAPP_NAME
* is empty.
*
* @return return WebConstants.WEBAPP_NAME or empty string if WebConstants.WEBAPP_NAME is null
* @should return empty string if WebConstants.WEBAPP_NAME is null
*/
public static String getContextPath() {
return StringUtils.isEmpty(WebConstants.WEBAPP_NAME) ? "" : "/" + WebConstants.WEBAPP_NAME;
}

public static String formatDate(Date date) {
return formatDate(date, Context.getLocale(), FORMAT_TYPE.DATE);
}

public static String formatDate(Date date, Locale locale, FORMAT_TYPE type) {
log.debug("Formatting date: " + date + " with locale " + locale);

DateFormat dateFormat = null;

if (type == FORMAT_TYPE.TIMESTAMP) {
String dateTimeFormat = Context.getAdministrationService().getGlobalPropertyValue(
OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT, null);
if (StringUtils.isEmpty(dateTimeFormat))
dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
else
dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(dateTimeFormat), locale);
} else if (type == FORMAT_TYPE.TIME) {
String timeFormat = Context.getAdministrationService().getGlobalPropertyValue(
OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT, null);
if (StringUtils.isEmpty(timeFormat))
dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
else
dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(timeFormat), locale);
} else if (type == FORMAT_TYPE.DATE) {
String formatValue = Context.getAdministrationService().getGlobalPropertyValue(
OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT, "");
if (StringUtils.isEmpty(formatValue))
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
else
dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(formatValue), locale);
}
return date == null ? "" : dateFormat.format(date);
}

/**
* @see org.openmrs.api.GlobalPropertyListener#supportsPropertyName(java.lang.String)
*/
@Override
public boolean supportsPropertyName(String propertyName) {
return OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT.equals(propertyName);
}

/**
* @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty)
*/
@Override
public void globalPropertyChanged(GlobalProperty newValue) {
defaultDateCache = null;
}

/**
* @see org.openmrs.api.GlobalPropertyListener#globalPropertyDeleted(java.lang.String)
*/
@Override
public void globalPropertyDeleted(String propertyName) {
defaultDateCache = null;
}
}
5 changes: 3 additions & 2 deletions web/src/main/java/org/openmrs/web/dwr/PersonListItem.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.openmrs.PersonAttribute;
import org.openmrs.PersonName;
import org.openmrs.util.Format;
import org.openmrs.web.WebUtil;

/**
* A mini/simplified Person object. Used as the return object from DWR methods to allow javascript
@@ -135,13 +136,13 @@ public PersonListItem(Person person) {

gender = person.getGender();
birthdate = person.getBirthdate();
birthdateString = Format.format(person.getBirthdate());
birthdateString = WebUtil.formatDate(person.getBirthdate());
birthdateEstimated = person.isBirthdateEstimated();
age = person.getAge();
voided = person.isPersonVoided();

if (person.getDeathDate() != null) {
this.deathDateString = Format.format(person.getDeathDate());
this.deathDateString = WebUtil.formatDate(person.getDeathDate());
}
deathdateEstimated = person.getDeathdateEstimated();

1 change: 1 addition & 0 deletions web/src/main/resources/openmrs-servlet.xml
Original file line number Diff line number Diff line change
@@ -1266,6 +1266,7 @@
<list value-type="org.openmrs.api.GlobalPropertyListener">
<bean class="org.openmrs.web.controller.PseudoStaticContentController" />
<bean class="org.openmrs.web.dwr.DWRPatientService" />
<bean class="org.openmrs.web.WebUtil" />
</list>
</property>
</bean>