Does anyone implemented a transformation between AQL and XML?

Just curious :slight_smile:

I’m adding version control features to EHRServer (https://github.com/ppazos/cabolabs-ehrserver) and I want to add some kind of AQL support in the future. Right now we have an internal querying model that abstracts from the physical database and allows the creation of queries for openEHR data from a UI.
My idea is to have some kind of transformation between the EHRServer query model and AQL, and instead of struggle with AQL parsers I would like to do some XML transformations to import and export AQL (I do not need to actually execute AQL, the execution of the internal query model is working ok).

Comments and ideas are very welcome!

Depending on how your XML is constructed, it is very easy to convert AQL to XQuery, or ADL-path to XPath.

Bert

Hi Bert,

I don’t have any XML :smiley: My question is about ADL, not it’s interpretation/execution, that is already handled by the current querying component of the EHRServer.

What I’m curious about is if someone has a transformation between AQL syntax and XML, in other words, a XML expression of an AQL query.

An AQL query can be instantiated and executed over any database, while XQuery is already an instance of a query (because it uses XPaths not ADL paths) and can be executed only in XML databases (and relational that support XML columns). The EHRServer database is relational, without any XML columns.

Also, what I need is a bidirectional transformation AQL ↔ XML. I guess it would be difficult to generate AQL from an XQuery expression.

Hi Pablo,

I’m a bit confused. What are you asking for? AQL does not have an object model that has been published, it has a grammar, so an XML representation of AQL would at best be AQL in XML syntax. If that is what you’re after, I can’t see how that could help? The point of AQL is sending the same query to multiple implementations, so its use means that you’d have to deal with an AQL parser.

If you want to develop an XML syntax for AQL, you’d still have to use an AQL parser to import AQL as you’ve described in your OP. It sounds like you’re trying to develop a mapping from AQL to your internal query execution, which is fine, but the XML syntax for AQL sounds redundant in that scenario.

Care to explain a bit more?

Regards
Seref

sorry, I misunderstood.

I cannot help you any further

Bert

Hi Seref,

Yes! Just need the transformation to have an AQL in XML syntax.

What I was thinking is trying to add support to AQL in the EHRServer, doing something like this:

AQL (syntax) <=(transformation)=> XML (syntax) <=(mapping)=> EHRServer Query Model (OO) <=(ORM)=> Query Storage

I already have the part for Evaluating/Executing queries that are represented in the EHRServer Query Model.

Having this I can import and export AQL, and I don’t need to actualy “execute” AQL.

This is in fact one way of implementing “The point of AQL is sending the same query to multiple implementations”.

Why not dealing with AQL directly?

In my experience in implementing software with ADLs and OPTs, managing OPTs in XML is way simpler: I can write my own parsers for specific tasks without the need of parsing the whole structure and then deal with an object instance in memory (sometimes buggy, difficult to access specific data, APIs not so well defined, non implemented methods, etc). So it is a matter of risk management and cost reduction (since I’m the only one working on the EHRServer I need to search for the shortest path to do each task will a certain level of quality).

So I have the same idea with AQL: not deal with AQL parsers or object instances, just the XML. The idea of this request is that I don’t want to develop an XML syntax for XML: it would be great if someone else already have that done so I can reuse.

This way I don’t need to “have to deal with an AQL parser” :slight_smile:

Hope that helps!

Hi Pablo,

Sorry but I still don’t get it :slight_smile: How are you going to do the following without an AQL parser?:

AQL (syntax) <=(transformation)=> XML (syntax)

If you have an xml form of AQL and use only that, you’d have to force your users write queries in the xml form of AQL which would defeat the whole purpose of the AQL.

So I’m still not seeing how you’re gaining anything with an XML form of AQL.

Best regards
Seref

Hi Seref, what I asked here was if anyone did implemented that, so I don’t have to :slight_smile:

As I said, my experience tells me it requires more hours-man to work with a syntax, a model and a parser than having XML and parse parts of it when required (so I can have 1. many ad-hoc parsers, 2. no model just ad-hoc data structures, 3. no API, 4. no parser e.g. it requires a lot of time to find a problem update the jj, generate the parser and test).

Hope that clarifies my vision.

Of course, I didn’t started yet to do anything about AQL support, just trying to make the community aware that I’ll do so and maybe generate some collaboration momentum. Maybe the syntax definition is very stable and there are a lot of good parsers for Java, but the syntax definition I found seems to be old (https://openehr.atlassian.net/wiki/display/spec/Archetype+Query+Language+Grammar & https://openehr.atlassian.net/wiki/display/spec/AQL-+Archetype+Query+Language) and I don’t know about AQL parsers for Java (just found this old discussion, no response about the parser: http://lists.openehr.org/pipermail/openehr-technical_lists.openehr.org/2009-March/004400.html).

I’m sure I need to do more research, but I doubt I can find the basic building blocks, even to start working with AQL directly.

Please if you know where I can find stuff to help me, any pointers will be very welcome!

Ok, I think I see what you mean now.

AQL is not part of the official specification and there is not much other than the grammar for the implementers so you’re right about not having a lot to work with.

On the other hand, if you’re going to do AQL, you’re going to have to have a parser. Marand has kindly provided an ANTLR grammar here: https://openehr.atlassian.net/wiki/display/spec/AQL-+Archetype+Query+Language

To use this grammar, you’re going to have to invest into learning ANLTR and inevitably into parser generators. Not an easy topic if you’re not familiar with it but I personally think it is worth it.

due to way ANTLR works, Marand’s grammar should get you really close to what you’re asking without much effort. You’ll probably have more of a challenge when trying to map the output of the parser to your query mechanism.

So the obvious pointer is the ANTLR grammar, the rest depends on your efforts :slight_smile:

All the best
Seref

Hi Pablo,

I think I have seen an AQL parser and some basic query generation within Liu EEE. Maybe Erik can provide further information on this.

Best,

Birger

Great! Thanks for the info.

Hi!

Sorry for joining the discussion late. (Vacation season)

During the development of LiU EEE (https://github.com/LiU-IMT/EEE) we (in addition to AQL-to-XQuery-translation) actually created a simple XML-representation of the AQL parse-tree for initial debugging/analysis purposes. I do not think we maintained this XML-debugging feature in the later parts of application development so it is most likely buggy or defunct. You may play around with the code in https://github.com/LiU-IMT/EEE/blob/master/src/main/java/se/liu/imt/mi/eee/AQL_Parser/AqlParser.jj and set the return type to XML instead of XQuery_EEE_0_1.

Hi Pablo,

I see Seref has provided some technical input. Just a note on what AQL is for, and why it is a language with a parser etc. The goal is to have queries that rely only on archetypes, and that can be shared across systems and vendors, enabling CDS and other second level processing solutions to be economic. The point of having a language is that the language is standard for this purpose, and that in each type of installation, an interpreter, or pre-compiler or similar, converts the AQL statements to what they need to be in that installation. The result will usually be different for each different vendor / type of solution - due to different DB, schema etc.

The AQL grammars currently online are what is in use - AQL is in fact very stable. However it will certainly get upgraded this year, due to useful changes made by the guys at Marand, to do with server side processing, functions etc. We also need to upgrade its terminology handling and specify some of the semantics better, which Seref knows a lot about.

- thomas

Hi Thomas, thanks for your input.

I understand perfectly the what and why. Personally I’m looking for the easiest path possible to start testing (not implementing) how to integrate AQL with the EHRServer, because I don’t have much developmwnt time and don’t have money to hire developers. Actually I’m looking for partners that want to fund this open source project.

In the other hand, the published grammars are a little old and don’t know who’s maintaining them, or if those are being maintained at all. And I don’t have much experience working with grammars, so for me the learning curve will be huge. So for me a XML or JSON form of AQL queries is a nice starting point.

Also I would like AQL to become normative (part of the openEHR specs, as well as opts :). Right now the docs we have available is one paper (I think from 2007), and a couple of wiki pages. Not sure if the doc and the grammars match or not.