// TODO: in 1.7-compatible version of the module, we can replace the H17 checks
// used below with the new isDate, isTime, and isDatetime
} else {
DateWidget dateWidget = null;
TimeWidget timeWidget = null;
boolean disableTime = "false".equalsIgnoreCase(parameters.get("allowTime"));
if (ConceptDatatype.DATE.equals(concept.getDatatype().getHl7Abbreviation()) || (ConceptDatatype.DATETIME.equals(concept.getDatatype().getHl7Abbreviation()) && disableTime)) {
valueWidget = new DateWidget();
} else if (ConceptDatatype.TIME.equals(concept.getDatatype().getHl7Abbreviation())) {
valueWidget = new TimeWidget();
} else if (ConceptDatatype.DATETIME.equals(concept.getDatatype().getHl7Abbreviation())) {
dateWidget = new DateWidget();
timeWidget = new TimeWidget();
valueWidget = new DateTimeWidget(dateWidget, timeWidget);
} else {
throw new RuntimeException("Cannot handle datatype: " + concept.getDatatype().getName()
+ " (for concept " + concept.getConceptId() + ")");
}
if (defaultValue != null && parameters.get("defaultDatetime") != null) {
throw new IllegalArgumentException("Cannot set defaultDatetime and defaultValue at the same time.");
} else if (defaultValue == null) {
defaultValue = parameters.get("defaultDatetime");
}
if (existingObs != null) {
valueWidget.setInitialValue(existingObs.getValueDatetime());
} else if (defaultValue != null && Mode.ENTER.equals(context.getMode())) {
valueWidget.setInitialValue(HtmlFormEntryUtil
.translateDatetimeParam(defaultValue, defaultDatetimeFormat));
}
if (dateWidget != null) {
context.registerWidget(dateWidget);
}
if (timeWidget != null) {
context.registerWidget(timeWidget);
}
}
}
context.registerWidget(valueWidget);
context.registerErrorWidget(valueWidget, errorWidget);
if (parameters.get("showUnits") != null) {
if ("true".equalsIgnoreCase(parameters.get("showUnits"))) {
showUnits = true;
} else if (!"false".equalsIgnoreCase(parameters.get("showUnits"))) {
showUnits = true;
unitsCode = parameters.get("showUnits");
}
}
if (parameters.get("unitsCssClass") != null) {
unitsCssClass = parameters.get("unitsCssClass");
}
// if a date is requested, do that too
if ("true".equals(parameters.get("showDate")) || parameters.containsKey("dateLabel")) {
if (parameters.containsKey("dateLabel")){
dateLabel = parameters.get("dateLabel");
}
dateWidget = new DateWidget();
context.registerWidget(dateWidget);
context.registerErrorWidget(dateWidget, errorWidget);
if (existingObs != null) {
dateWidget.setInitialValue(existingObs.getObsDatetime());
} else if (parameters.get("defaultObsDatetime") != null) {
// Make sure this format continues to match
// the <obs> attribute defaultObsDatetime documentation at
// https://wiki.openmrs.org/display/docs/HTML+Form+Entry+Module+HTML+Reference#HTMLFormEntryModuleHTMLReference-%3Cobs%3E
String supportedDateFormat = "yyyy-MM-dd-HH-mm";
dateWidget.setInitialValue(HtmlFormEntryUtil.translateDatetimeParam(parameters.get("defaultObsDatetime"),
supportedDateFormat));
}
}
// if an accessionNumber is requested, do that too