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

Add Creatable and Changeable interfaces

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Should
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Platform 2.2.0, Core 2.2.0
    • Component/s: None
    • Labels:
      None
    • Complexity:
      Low

      Description

      Background

      OpenmrsData and OpenmrsMetadata extend Auditable. Historically, if a given class doesn't support some fields – e.g if it's immutable, we just exclude the changedBy and dateChanged fields in the database table and the hbm files but this leaves redundant methods behind.

      One of the benefits of introducing Creatable and Changeable interfaces is a class like Order can be tweaked to extend BaseOpenmrsObject and implement Creatable, Voidable, and Serializable and you can also annotate it separately with JPA annotations. Currently separate JPA annotations on Order are not possible, since Order extends BaseOpenmrsData that has annotated changedBy and dateChanged fields, which are not in the orders table, hence hibernate freaks out.

      Suggestion

      Add the interfaces and abstract classes below

      Creatable.java
      public interface Creatable extends OpenmrsObject {
          User getCreator();
          void setCreator(User creator);
          Date getDateCreated();
          void setDateCreated(Date dateCreated);
      }
      
      Changeable.java
      public interface Changeable extends OpenmrsObject {
          User getChangedBy();
          void setChangedBy(User changedBy);
          Date getDateChanged();
          void setDateChanged(Date dateChanged);
      }
      


      OpenmrsImmutableData.java
      public interface OpenmrsImmutableData extends Creatable, Voidable {
      }
      


      OpenmrsBaseImmutableData.java
      //This should add the necessary fields and annotate them like in OpenmrsBaseData
      public abstract class BaseOpenmrsImmutableData extends BaseOpenmrsObject implements OpenmrsImmutableData {
      }
      


      Update Auditable to the signature below and remove all existing methods

      Auditable.java
      public interface Auditable extends Creatable, Changeable {
      }
      


      Update Order class to this

      Order.java
      public class Order extends OpenmrsBaseImmutableData {
      }
      


      You might need to update some code that was written based on the Auditable interface but specific to creator or changedBy fields e.g in AuditableInterceptor the logic should work for an Object that is Creatable but not Changeable and vice versa

      Extra Credit

      There are other openmrs data classes that are not changeable (don't have changedBy and dateChanged fields) and are Voidable that might need to be updated to extend BaseOpenmrsImmutableData e.g ConceptName, ConceptNameTag, Obs

        Gliffy Diagrams

          Attachments

            Issue Links

              Attachments-Category-Modification

                Activity

                  People

                  • Assignee:
                    wyclif Wyclif Luyima
                    Reporter:
                    wyclif Wyclif Luyima
                  • Votes:
                    0 Vote for this issue
                    Watchers:
                    3 Start watching this issue

                    Dates

                    • Created:
                      Updated:
                      Resolved: