I like it. A lot. I come back to this, which I have been ranting about for some time
https://blueprints.launchpad.net/dhis2/+spec/regex-validation Seeing that they are more or less following this route to some degree (it would at least seem from the discussion) with regex validation of attributes, seems like a very wise move. Otherwise, I can imagine chaos will result. If we could do this with the new attributes, this would obviously add a lot more control of what would get in an attribute, such as a national identity number, which would make it a lot easier to do something with, i.e. "getOrganisationUnitByAttribute(attribute, value)" Ergo, it would seem that an organisation unit code is also an attribute, but a predefined one which can actually do something "e.g. getOrganisationUnitByCode" (but which is lacking validation, which seemingly would be useful). Regards, Jason On Sun, Sep 25, 2011 at 5:25 PM, Bob Jolliffe <[email protected]> wrote: > Couldn't help but notice that the openmrs team are also engaged in a > process of defining generic attributes. And making them the subject > of design calls :-) > > It might be useful to compare. Two things i pick up from the below is > that there seems to be much effort put into attribute types (validated > strings, dates etc) though I don't see the coded attributes which we > have and (ii) they DO have an interface, Customizable, which applies > to all classes which can e extended. > > Interesting to see these efforts happening at the same time. > > Cheers > Bob > > ---------- Forwarded message ---------- > From: Darius Jazayeri <[email protected]> > Date: 24 September 2011 21:03 > Subject: [OPENMRS-DEV] Current state of attributes > To: [email protected] > > > Hi All, > On our last few design calls we've been working through the generic > AttributeType mechanism that we're introducing in 1.9. (see ticket) > I wanted to summarize the current state of things. Some of this is in > trunk, but some is refactoring I'm doing. I'm especially interested in > thoughts about how these classes should be linked together with > parameterized types, since I'm not convinced I've gotten that right: > interface CustomDatatypeHandler<T> > > Capable of converting T to/from a String that can be persisted in the > varchar column of a database. E.g. a date would be stored as > yyyy-mm-dd and an image might be stored as a uri pointing to a PACS > system. Also capable of validating T, e.g. so we can use a plain > java.util.Date to represent "date-in-past" but limit its possible > values. > Defines a String "datatypeHandled", e.g. "date", "regex-validated-string") > T fromPersistedString(String) > String toPersistedString(T) > void validate(T) > String render(String persistedValue, String view) > can be configured with setHandlerConfiguration(String) > > interface CustomDatatyped > > holds the definition of a custom datatype (which is handled by a > handler of the above interface). For example VisitAttributeType and > GlobalProperty (we're able to do typed GPs trivially now) > required: String getDatatype() > optional: String getPreferredHandlerClassname() > > if specified, will be handled by this specific CustomDatatypeHandler, > otherwise it will be handled by the default handler for this thing's > datatype > > optional: String getHandlerConfig() > > interface AttributeType<OwningType extends Customizable> extends > CustomDatatyped, OpenmrsMetadata > > for user-defined extensions to core domain objects, which would be > handled by adding custom database columns in a less generic system. > E.g. VisitAttributeType implements AttributeType<Visit> > datatype/handler specified via CustomDatatyped superinterface > Integer getMinOccurs() > Integer getMaxOccurs() > > class VisitAttributeType, class LocationAttributeType, class > ProviderAttributeType > > trivial implementations of AttributeType (via BaseAttributeType) > > interface Customizable<AttrClass extends Attribute> > > Implemented by domain classes that may be customized by the user via > custom attributes. E.g. Visit implements Customizable<VisitAttribute>, > Location implements Customizable<LocationAttribute> > Has convenience methods for dealing with a collection of attributes, > of different types: > Collection<AttrClass> getAttributes() //includes voided > Collection<AttrClass> getActiveAttributes() //non-voided > void addAttribute(AttrClass) > void setAttribute(AttrClass) //voids other attributes of the given type > > interface CustomValue > > holds a value managed by a CustomDatatypeHandler. E.g. VisitAttribute, > GlobalProperty. Any implementation of this has a corresponding > CustomDatatyped implementation. "persistedValue" is a String suitable > for persisting in a db varchar column; "objectValue" is what you'd > want to work with in the API. > String getPersistedValue() > void setPersistedValue() > Object getObjectValue() // don't remember why this isn't <T> > void setObjectValue(Object) > > interface Attribute<OwningType extends Customizable> implements > CustomValue, OpenmrsData > > value corresponding to an AttributeType (which defines its datatype, > whether it's required, whether it can repeat, etc), e.g. > VisitAttribute corresponds to VisitAttributeType > OwningType getOwner() > void setOwner(OwningType) > AttributeType<OwningType> getAttributeType() > > class VisitAttribute, class LocationAttribute, class ProviderAttribute > > trivial implementation of Attribute (via BaseAttribute) > > class GlobalProperty implements CustomDatatyped, CustomValue > > this is interesting in that it both defines a custom datatype and > stores its value > > Thoughts welcome... > -Darius > ________________________________ > Click here to unsubscribe from OpenMRS Developers' mailing list > > _______________________________________________ > Mailing list: https://launchpad.net/~dhis2-devs > Post to : [email protected] > Unsubscribe : https://launchpad.net/~dhis2-devs > More help : https://help.launchpad.net/ListHelp > _______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

