Code Table Hierarchy

Code table files can define a single code table or a hierarchy of code tables. A hierarchy is where multiple code tables are linked into a number of levels. Selecting a code at a particular level will reduce the number of selections available at the next level. Any number of levels in a code table hierarchy is supported.

For example, Code Table Hierarchy shows a sample hierarchy. Selecting Ireland as the country will return a sub-list of Meath and Wexford and selecting Meath as the county will return sub-list of Trim and Navan. Alternatively, selecting England will return a sub-list of Stafford and London, etc.

Table 1. Address Hierarchy
Level 1 Level 2 Level 3
Country County Town
Ireland Meath Navan
    Trim
  Wexford Gorey
    Enniscorthy
England Stafford Bednall
    Stone
  London Earlsfield
    Eltham

To define a code table hierarchy a code table (CTX) file should be created with a code table defined for each level in the hierarchy. To indicate that the code table file contains a hierarchy, the hierarchy_name attribute should be defined on the <codetables> element.

Figure 1. Usage of hierarchy_name attribute
<codetables package="curam"
               hierarchy_name="AddressHierarchy">
<description>
  A description of the hierarchy.
</description>

Each <codetable> defined must then be linked using the parent_codetable attribute of the <codetable> element. The parent_codetable value should be set to the name of an existing <codetable> in the file, where the specified code table is the parent in the hierarchy. All code tables defined in the file, excluding the top level code table, must have a valid parent_codetable attribute defined for them. A <codetable> can be linked to only one parent <codetable> and cannot be used in more than one code table hierarchy.

Figure 2. Usage of parent_codetable attribute
<codetable java_identifier="COUNTY"
              name="County" parent_codetable="Country">

Each <code> entry in a code table is finally linked to a <code> entry in the parent code table, using the parent_code attribute. The parent_code value must be the value of a <code> existing in the specified parent code table. A child <code> cannot be linked to more than one parent <codetable>.

Figure 3. Usage of parent_code attribute
<code java_identifier="MEATH"
         value="MEATH" parent_code="IRELAND" status="ENABLED">

The hierarchy defined in Code Table Hierarchy can be represented as follows in a code table file.

Figure 4. Code Table Hierarchy Example
<?xml version="1.0" encoding="UTF-8" ?>
<codetables package="curam" hierarchy_name="AddressHierarchy">
  <description>
    A description of the hierarchy.
  </description>

  <codetable java_identifier="COUNTRY" name="Country">
    <displaynames>
      <name language="en">Country</name>
    <displaynames>
    <code java_identifier="IRL" value="IRLND" default="true"
           status="ENABLED">
      <locale language="en" sort_order="1">
        <description>Ireland</description>
      </locale>
    </code>
    <code java_identifier="GB" value="ENGLND" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>England</description>
      </locale>
    </code>
  </codetable>

  <codetable java_identifier="COUNTY" name="County"
             parent_codetable="Country">
    <displaynames>
      <name language="en">County</name>
    </displaynames>
    <code java_identifier="MEATH" value="MTH"
          parent_code="IRLND" status="ENABLED">
      <locale language="en" sort_order="1">
        <description>Meath</description>
      </locale>
    </code>
    <code java_identifier="WEXFORD" value="WXFD"
          parent_code="IRLND" status="ENABLED">
      <locale language="en" sort_order="1">
        <description>Wexford</description>
      </locale>
    </code>
    <code java_identifier="STAFFORD" value="STFFRD"
          parent_code="ENGLND" status="ENABLED">
      <locale language="en" sort_order="1">
        <description>Stafford</description>
      </locale>
    </code>
    <code java_identifier="LONDON" value="LNDN"
          parent_code="ENGLND" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>London</description>
      </locale>
    </code>
  </codetable>

  <codetable java_identifier="TOWN" name="Town"
             parent_codetable="County">
    <code java_identifier="NAVAN" value="NVN"
          parent_code="MTH" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>Navan</description>
      </locale>
    </code>
    <code java_identifier="TRIM" value="TRM"
          parent_code="MTH" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>Trim</description>
      </locale>
    </code>
    <code java_identifier="GOREY" value="GRY"
          parent_code="WXFD" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>Gorey</description>
      </locale>
    </code>
    <code java_identifier="ENNISCORTHY" value="ENC"
          parent_code="WXFD" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>Enniscorthy</description>
      </locale>
    </code>
    <code java_identifier="ELTHAM" value="ELTM"
          parent_code="LNDN" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>Eltham</description>
      </locale>
    </code>
    <code java_identifier="EARLSFIELD" value="ELFD"
          parent_code="LNDN" status="ENABLED">
      <locale language="en" sort_order="2">
        <description>Earlsfield</description>
      </locale>
    </code>
    <code java_identifier="BEDNALL" value="BDNL"
          parent_code="STFFRD" status="ENABLED">
      <locale language="en" sort_order="4">
        <description>Bednall</description>
      </locale>
    </code>
    <code java_identifier="STONE" value="STN"
          parent_code="STFFRD" status="ENABLED">
      <locale language="en" sort_order="4">
        <description>Stone</description>
      </locale>
    </code>
  </codetable>
</codetables>

The artefacts listed in Artefacts Produced by ctgen Build Target are also generated for code table files that define a hierarchy.

Properties files are generated for <displaynames> elements. A symbol definition Java file is generated for each code table in the hierarchy. A single SQL file is generated, containing the relevant inserts to the CodeTableHeader and CodeTableItem database tables for all defined code tables. These insert statements will include the population of the parentCode field in the CodeTableItem table and the parent_codetable field in the CodeTableHeader table. An insert entry is also generated for the CodeTableHierarchy database table. This table is used for administration purposes only.

Note: The code table hierarchies can only be created through code table (CTX) files and not through the admin screens. The admin screens can only be used to maintain the code table hierarchies.