ACORD, enums and Groovy

ACORD publishes standards for information exchange by insurance and financial industries. As a part of their specifications, they provide lists (called lookups) of constant values (called type codes) for all kinds of items that insurance carriers, customers or users might need to communicate about.  For example, the lookup named OLI_LU_GENDER contains numeric values for genders. If two parties need to communicate about the rates for a policy to cover a male, age 35, non-smoker, then they can use an XML message that declares the applicant has:

<Gender tc="1"/>

where the tc=”1″ refers to the type code for ‘Male’.

As a developer writing web services that need to speak ACORD XML, it can be a tedious chore to have to keep referring to the ACORD manual to look up type codes. Fortunately, Java and Groovy make it easy to convert ACORD lookups into a library of enums.  With an IDE that does code completion, having the enums jar in your classpath is all you need to be able to work with ACORD lookups and type codes at a decent speed.  Simply start typing the name of a lookup (and most of the ones in the OLifE standard start with “OLI_LU_”) and the IDE prompts you with choices. Tab to select your lookup and hit “.” and then you’re prompted with a list of type codes. Easy!

enum OLI_LU_GENDER {

    OLI_GENDER_MALE(1, 'Male'),
    OLI_GENDER_FEMALE(2, 'Female')

    private final Integer typeCode
    private final String text

    OLI_LU_GENDER(Integer typeCode, String text) {
        this.typeCode = typeCode
        this.text = text
    }

    String getName() {
        return name()
    }

    Integer getTypeCode() {
        return typeCode
    }

    String getText() {
        return text
    }

    static def findByName(String searchArg) {
        return this.find { it.name == searchArg }
    }

    static def findByTypeCode(Integer searchArg) {
        return this.find { it.typeCode == searchArg }
    }

    static def findByText(String searchArg) {
        return this.find { it.text == searchArg }
    }

    static def findByTextIgnoreCase(String searchArg) {
        return this.find { it.text.equalsIgnoreCase(searchArg) }
    }

}

I realize that the example above breaks Java and Groovy naming conventions for classes. However, for recognition and usability I think that it’s more important to stick to the ACORD naming conventions and use the original name of the lookup for the name of the enum.

Here are some example usages:

    String renderAcordXml() {
        def xml = new StreamingMarkupBuilder().bind { builder ->
            mkp.xmlDeclaration()
            mkp.declareNamespace('xsd': 'http://www.w3.org/2001/XMLSchema',
                    '': 'http://ACORD.org/Standards/Life/2',
                    'xsi': 'http://www.w3.org/2001/XMLSchema-instance')
            TXLife('xsi:schemaLocation':
            'http://ACORD.org/Standards/Life/2 schema\\TXLife2.16.01.xsd'
            ) {
                TXLifeRequest() {
                    TransType(tc: OLI_LU_TRANS_TYPE_CODES.OLI_TRANS_NBSUB.typeCode, OLI_LU_TRANS_TYPE_CODES.OLI_TRANS_NBSUB.text)
                    OLifE {
                        Party(id: INSURED_PARTY_ID) {
                            Person() {
                                FirstName(data.firstName)
                                MiddleName(data.middleName)
                                LastName(data.lastName)
                                Gender(tc: OLI_LU_GENDER.OLI_GENDER_MALE.typeCode, OLI_LU_GENDER.OLI_GENDER_MALE.text)
                            }
                        }
                    }
                }
             }
          }
<g:select name="insuredGender"
             from="${OLI_LU_GENDER.values()}"
             optionKey="typeCode"
             optionValue="text" />
InsuranceQuote quote = new InsuranceQuote()
quote.applicantGender = OLI_LU_GENDER.findByTypeCode(params.insuredGender)
quote.validate()
quote.save()

I wish I could crowdsource the development of a complete enum jar for each ACORD standard, or at least share the one I’m creating, but the standards are not my intellectual property.  The best that I can do for you is to suggest that it should be possible, if you’re an ACORD member and have access to the standards documents, to write a script that can parse tabular lookup data out of the docs and write Groovy enum code from it.

#acord, #enums, #groovy