# Format of AT codes **Category:** [Implementation](https://discourse.openehr.org/c/implem/39) **Created:** 2023-04-24 17:54 UTC **Views:** 480 **Replies:** 2 **URL:** https://discourse.openehr.org/t/format-of-at-codes/3905 --- ## Post #1 by @richard.kavanagh Apologies if I have missed it in the documentation, but is there a stated rule for the format of AT codes? I have looked but don't see one, the class model seems to just say they are a string. Sidestepping, specialisations at the moment are the codes always ATnnnn (e.g. 4 digit numeric part)? The reason I ask is that ANTLR parser using the combined grammar (ADL 1.4) currently returns the AT codes in two parts the fixed 'AT' and then a number for the numeric part. To reconstitute the actual AT code I need to know how many zeroes to add. I haven't tried a specialised archetype ADL file yet, but I see from the documentation that codes such as 'AT0.1' can be encountered - that will be the next challenge. Thanks for your help. --- ## Post #2 by @thomas.beale The at codes in ADL 1.4 archetypes are not entirely regular - it's one of the things we fixed in ADL2 with the id codes. The codes in a top-level archetype are of the 4-digit form (for no good reason!) while those in specialised archetypes are regular, i.e. at1004.1.5 or at0.1.2. [quote="richard.kavanagh, post:1, topic:3905"] The reason I ask is that ANTLR parser using the combined grammar (ADL 1.4) currently returns the AT codes in two parts the fixed ‘AT’ and then a number for the numeric part. To reconstitute the actual AT code I need to know how many zeroes to add. [/quote] I think you are referring to the following lexer rules from OpenehrPatterns.g4: ``` // ---------- legacy ADL14 patterns ------- ADL14_AT_CODE : 'at' ADL14_CODE_STR ; ADL14_AC_CODE : 'ac' ADL14_CODE_STR ; fragment ADL14_CODE_STR : [0-9]+ ( '.' NUMBER )* ; ``` So that last line could probably be: ``` fragment ADL14_CODE_STR : [0-9][0-9][0-9][0-9] ( '.' NUMBER )* | '0' ( '.' NUMBER )+; ``` I don't have time to test this right now, but if you do, I think you will find it matches 4-digit top-level codes so that the string you get in the parser will not require any zero-filling; otherwise it matches codes of the form 'at0...'. This kind of annoyance is among the many reasons we defined ADL2 ;) See [this page](https://openehr.atlassian.net/wiki/spaces/ADL/pages/389775404/ADL2+backward+compatible+code+system) for some background on these codes. --- ## Post #3 by @richard.kavanagh Thanks Thomas, I will amend the grammar and give it another go. --- **Canonical:** https://discourse.openehr.org/t/format-of-at-codes/3905 **Original content:** https://discourse.openehr.org/t/format-of-at-codes/3905