# ADL parser for python **Category:** [Tools](https://discourse.openehr.org/c/tool-dev/36) **Created:** 2024-08-01 07:46 UTC **Views:** 295 **Replies:** 6 **URL:** https://discourse.openehr.org/t/adl-parser-for-python/5528 --- ## Post #1 by @markbouts We are working on implementing an ADL parser in python so that we can use it to retrieve and validate data from our legacy database systems. We are facing some challenges implementing the description part. I can't imagine we are the first to work on such a tool. Does anyone have any pointers / leads (in any scripting/programming language) that may help us? --- ## Post #2 by @borut.jures Hi Mark! There are ANTLR4 grammars available for ADL: https://github.com/openEHR/openEHR-antlr4/tree/master/combined/src/main/antlr You can use ANTLR4 to generate your ADL parser in Python: https://www.antlr.org/download.html --- ## Post #3 by @Seref Hi @markbouts . It may help you if you provided a bit more detail regarding your use case, if you're able to of course. Which version of ADL? Data validation can be performed using archetypes in theory, but in practice there are downstream artefacts built from artefacts and these are usually used for data validation. This high level concept applies a bit differently to ADL versions, that's why I'm asking. I think the community may be able to help you by giving you feedback about your goals and assumptions if you're able to share a bit more. That may save you more time than getting your hands on a Python parser :) Re the Python parser itself, @borut.jures 's input would be where I'd start, so I won't add anything on top of that. --- ## Post #4 by @ian.mcnicoll One shortcut might be to use the Better web template format which you can generate from Archetype Designer for any template you create, or from the Better/Ehrbase APIs This is a pretty simple json format which contains most of the validation constraints and node descriptions you might need. This https://github.com/freshehr/wt2docx is in Typescript but should give you an idea and has some examples of web templates. I'd second @seref recommendation of the work done by @borut.jures asa great start pint but you might also want to contact @surfer who is behind https://github.com/orgs/crs4/repositories?type=all&q=openehr . I canlt see anything there specifically about ADL parsing but Giovanni might know more. --- ## Post #5 by @surfer Sorry, I can't help unfortunately. We didn't implement any ADL parser yet. --- ## Post #6 by @markbouts Sure @Seref, We currently have a working prototype system that can retrieve and process data from several legacy database systems. While we are aware of aql and it's purposes, we are currently bounded to these legacy database systems. Our system uses archetypes and GDL-defined rules to retrieve the necessary data. From there we can use that data for various CDS-like purposes implemented in python. Currently we only make use of the ontology part of the archetype to retrieve the data. However to ensure data validity, we also want to make use of the definition part of the ADL. This to make sure that the retrieved data adheres to some basic data constraints. Our initial thought was to also use GDL-defined rules, however this adds to the complexity of our overall system. We therefore prefer to use the data contraints included in the archetype itself. This to keep our system more scalable and maintainable Before creating something ourselves, we wanted to make sure we are not re-inventing the wheel. @borut.jures already gave a nice suggestion which we are currently looking into. Our system currently uses version 1.4 archetypes, but we are not bound to it --- ## Post #7 by @joostholslag Hi Mark, Interesting stuff. Using GDL for this I’ve not encountered before. Your usecase seems similar to what Zuyderland @Timeterror is working on. And also MUMC / Maastricht University @Pascal. Both are working on data extraction of legacy systems for secondary use (not decision support afaik). I’ve you can show more details like code or architecture, I’d be curious and as you’ve seen the community is quite eager to help:) Also the OpenAPI ITS spec could be interesting, it allows (careful which OpenAPI version/variant) generation of classes in many languages. --- **Canonical:** https://discourse.openehr.org/t/adl-parser-for-python/5528 **Original content:** https://discourse.openehr.org/t/adl-parser-for-python/5528