public DateTimeWidget() { // create the Date and Time widgets dateWidget = new DateWidget(); timeWidget = new TimeWidget(); }
/** * @see org.openmrs.module.htmlformentry.widget.Widget#generateHtml(org.openmrs.module.htmlformentry.FormEntryContext) */ @Override public String generateHtml(FormEntryContext context) { // have the date and time widgets generate their HTML String dateHTML = dateWidget.generateHtml(context); String timeHTML = timeWidget.generateHtml(context); // combine them and return them return dateHTML + " " + timeHTML; }
/** * @see org.openmrs.module.htmlformentry.widget.Widget#setInitialValue(java.lang.Object) */ @Override public void setInitialValue(Object value) { initialValue = (Date) value; // set the underlying date and time widgets with the initial value dateWidget.setInitialValue(initialValue); timeWidget.setInitialValue(initialValue); }
@Test public void testHidden() throws Exception { Date date = new SimpleDateFormat("HH:mm:ss").parse("18:09:35"); TimeWidget widget = new TimeWidget(); widget.setHidden(true); widget.setInitialValue(date); FormEntryContext formEntryContext = mock(FormEntryContext.class); when(formEntryContext.getFieldName(widget)).thenReturn("w1"); String html = widget.generateHtml(formEntryContext); assertTrue(html.contains("<input type=\"hidden\" class=\"hfe-hours\" name=\"w1hours\" value=\"18\"/>")); assertTrue(html.contains("<input type=\"hidden\" class=\"hfe-minutes\" name=\"w1minutes\" value=\"09\"/>")); assertTrue(html.contains("<input type=\"hidden\" class=\"hfe-seconds\" name=\"w1seconds\" value=\"35\"/>")); }
timeWidget = new TimeWidget(); timeErrorWidget = new ErrorWidget(); if (context.getExistingEncounter() != null) { timeWidget.setInitialValue(context.getExistingEncounter().getEncounterDatetime()); } else if (parameters.get("defaultDate") != null) { timeWidget.setInitialValue(parameters.get("defaultDate")); timeWidget.setHideSeconds(true); dateWidget.setHidden(true); if (timeWidget != null) { timeWidget.setHidden(true);
@Test public void testTimeFormat() throws Exception { Date date = new SimpleDateFormat("HH:mm:ss").parse("18:09:35"); TimeWidget widget = new TimeWidget(); widget.setInitialValue(date); // Test default if GP is missing setGlobalProperty(""); testTimeFormat(widget, "18:09"); // Test specific GP value setGlobalProperty("h:mm a"); testTimeFormat(widget, "6:09 PM"); // Test specific widget value widget.setTimeFormat("mm.ss"); testTimeFormat(widget, "09.35"); }
if (!timeWidget.isHidden() || (context.getMode() == Mode.VIEW)) { ret.append(" "); ret.append(timeWidget.generateHtml(context)); if (context.getMode() != Mode.VIEW) ret.append(timeErrorWidget.generateHtml(context));
valueWidget = new DateWidget(); } else if (ConceptDatatype.TIME.equals(concept.getDatatype().getHl7Abbreviation())) { valueWidget = new TimeWidget(); if(hideSeconds){ ((TimeWidget) valueWidget).setHideSeconds(true); timeWidget = new TimeWidget(); if(hideSeconds){ timeWidget.setHideSeconds(true);
/** * @see org.openmrs.module.htmlformentry.widget.Widget#getValue(org.openmrs.module.htmlformentry.FormEntryContext, javax.servlet.http.HttpServletRequest) */ @Override public Object getValue(FormEntryContext context, HttpServletRequest request) { // get the values from the associated date and time widgets Date date = dateWidget.getValue(context, request); Date time = (Date) timeWidget.getValue(context, request); return HtmlFormEntryUtil.combineDateAndTime(date, time); }
String toPrint = ""; if (initialValue != null) { toPrint = timeFormat().format(initialValue); return WidgetFactory.displayValue(toPrint); } else {
Date date = (Date) dateWidget.getValue(context, submission); if (timeWidget != null) { Date time = (Date) timeWidget.getValue(context, submission); date = HtmlFormEntryUtil.combineDateAndTime(date, time);
protected void testTimeFormat(TimeWidget widget, String expectedValue) { FormEntryContext formEntryContext = mock(FormEntryContext.class); when(formEntryContext.getMode()).thenReturn(FormEntryContext.Mode.VIEW); String html = widget.generateHtml(formEntryContext); String expected = "<span class=\"value\">" + expectedValue + "</span>"; assertEquals(expected, html); }
Date time = (Date) timeWidget.getValue(session.getContext(), submission); Encounter e = session.getSubmissionActions().getCurrentEncounter(); Date dateAndTime = HtmlFormEntryUtil.combineDateAndTime(e.getEncounterDatetime(), time);