/** @see HtmlGeneratorElement#generateHtml(FormEntryContext) */
  @Override
  public String generateHtml(FormEntryContext context) {
    StringBuilder ret = new StringBuilder();

    // if an id has been specified, wrap the whole encounter element in a span tag so that we access
    // property values via javascript
    // also register property accessors for all the widgets
    if (id != null) {
      ret.append("<span id='" + id + "'>");

      // note that if this element ever handles multiple widgets, the names of the provider and
      // location accessors will need unique names
      if (dateWidget != null) {
        context.registerPropertyAccessorInfo(
            id + ".value",
            context.getFieldNameIfRegistered(dateWidget),
            "dateFieldGetterFunction",
            null,
            "dateSetterFunction");
        context.registerPropertyAccessorInfo(
            id + ".error", context.getFieldNameIfRegistered(dateErrorWidget), null, null, null);
      } else if (providerWidget != null) {
        context.registerPropertyAccessorInfo(
            id + ".value", context.getFieldNameIfRegistered(providerWidget), null, null, null);
        context.registerPropertyAccessorInfo(
            id + ".error", context.getFieldNameIfRegistered(providerErrorWidget), null, null, null);
      } else if (locationWidget != null) {
        context.registerPropertyAccessorInfo(
            id + ".value", context.getFieldNameIfRegistered(locationWidget), null, null, null);
        context.registerPropertyAccessorInfo(
            id + ".error", context.getFieldNameIfRegistered(locationErrorWidget), null, null, null);
      } else if (encounterTypeWidget != null) {
        context.registerPropertyAccessorInfo(
            id + ".value", context.getFieldNameIfRegistered(encounterTypeWidget), null, null, null);
        context.registerPropertyAccessorInfo(
            id + ".error",
            context.getFieldNameIfRegistered(encounterTypeErrorWidget),
            null,
            null,
            null);
      }
    }

    if (dateWidget != null) {
      ret.append(dateWidget.generateHtml(context));
      if (context.getMode() != Mode.VIEW) ret.append(dateErrorWidget.generateHtml(context));
    }
    if (timeWidget != null) {
      ret.append("&#160;");
      ret.append(timeWidget.generateHtml(context));
      if (context.getMode() != Mode.VIEW) ret.append(timeErrorWidget.generateHtml(context));
    }
    if (providerWidget != null) {
      ret.append(providerWidget.generateHtml(context));
      if (context.getMode() != Mode.VIEW) ret.append(providerErrorWidget.generateHtml(context));
    }
    if (locationWidget != null) {
      ret.append(locationWidget.generateHtml(context));
      if (context.getMode() != Mode.VIEW) ret.append(locationErrorWidget.generateHtml(context));
    }
    if (encounterTypeWidget != null) {
      ret.append(encounterTypeWidget.generateHtml(context));
      if (context.getMode() != Mode.VIEW)
        ret.append(encounterTypeErrorWidget.generateHtml(context));
    }
    if (voidWidget != null) {
      if (context.getMode() == Mode.EDIT) // only show void option if the encounter already exists.
      ret.append(voidWidget.generateHtml(context));
    }

    // close out the span if we have an id tag
    if (id != null) {
      ret.append("</span>");
    }

    return ret.toString();
  }