Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-2243

Add AttributeTypeHandler to the API, which can be used by multiple classes that need to support user-defined Attributes

    XMLWordPrintable

    Details

    • Complexity:
      High

      Description

      Frequently we want to allow implementations to add attributes to different domain objects that are custom to that specific implementation. (This is equivalent to adding a column to a table in custom software.)

      For example Person has PersonAttribute (and PersonAttributeType), Visit has VisitAttribute (and VisitAttributeType), etc.

      The pattern we used when implementing PersonAttribute and PersonAttributeType (i.e. have a "format" column which specifies the java class of the attribute value) isn't quite right, so we want to provide a better mechanism. Initially this will be used in Visit Attributes, but eventually it will be extended to other attributes as well.

      We will add "AttributeTypeHandler", an interface whose implementations:

      • control the way that values are converted to and from Strings (for database storage)
      • control what widget is displayed in the UI for this attribute type

      Finding a way to implement this without mixing up our API and UI layers is going to be tricky...

      Approximate design:

      interface AttributeHandler<T> { // T is the type returned by this handler, e.g. java.lang.String or java.util.Date.
          String getName(Locale locale);
          String serialize(T);
          T deserialize(String);
      }
      
      /** hint to UI technology to display this as a dropdown  */
      interface ConstrainedOptionAttributeHandler<T> extends AttributeType<T> {
          Map<String, String> getOptions(Locale locale) // should return an ordered map from attribute value to display label
      }
      
      /** hint to UI technology to display this as an autosuggest */
      interface SuggestedOptionsAttributeHandler<T> extends AttributeType<T> {
          Map<String, String> getSuggestions(String typedSoFar, Locale locale) // should return an ordered map from attribute value to display label
      }
      
      /** explicitly specify what UI widget to use */
      interface WidgetDrivenAttributeHandler<T> extends AttributeType<T> {
          String getWidgetName();
          Map<String, Object> getWidgetConfiguration();
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darius Darius Jazayeri [X] (Inactive)
              Reporter:
              darius Darius Jazayeri [X] (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: