# Parsing of Archetypes/Templates **Category:** [Technical (archive)](https://discourse.openehr.org/c/technical-archive/156) **Created:** 2018-11-12 08:18 UTC **Views:** 2 **Replies:** 10 **URL:** https://discourse.openehr.org/t/parsing-of-archetypes-templates/15547 --- ## Post #1 by @system Hello, For a project we want to create a generic mechanism to transform archetypes into FHIR Logical Models, so we can store, retrieve and query archetype instance with FHIR tools \(CQL, FHIR\-REST\-API\-query\)\. At the moment we just want to read/write archetypes and not archetype instances\. We are looking for existing components to parse and process archetypes\. I have some questions I encountered related to these issues: \- I have found several projects that store openEHR\-data \(archetypes as well as archetype instances\) into different data substrates \(Neo4J, ARM \(archetype relational mapping\), EtherCIS\)\. Although I have not yet looked at the code of these projects I assume that they take an archetype XML\-file, parse it and thus create a runtime object of the archetype\. That runtime object can then be given as a parameter to a persistence layer \(e\.g\. JOOQ, Hibernate, etc\.\)\. In order to reuse something from already existing projects I am looking for a parser that creates a runtime object from an archetype\-XML\-String, so we can write our own components that transform it into a FHIR runtime object\. The component we are looking for should preferably be written in Java, as this is our language of choice in our project\. \- I am not ye sure if we are looking for a method to transform archetypes, templates or operational templates into FHIR related structures, as I am not yet that familiar with which data structure is preferably used for which kind of task\. Therefore, component that, instead of archetypes, parse templates or operational templates would be appreciated as well\. Greetings Georg --- ## Post #2 by @system Hello George, If you are looking for something to handle ADL 2 archetypes - the most recent version -, have a look at https://github.com/opener/archie . It is a java library that can parse archetypes, flatten and validate them, create operational templates and more. Are you using the openehr reference model, or something else like fihr? Although Archie can parse and serialize archetypes in XML, archetypes are usually stored as ADL. This is a custom more readable format. Of course you can then easily convert it to XML or Json to work with them in other tools where you do not have an ADL parser ready. Note that for ADL 2 as far as I know there is no official XSD released yet, so it is possible you run into compatibility problems with XML. For ADL 1.4 this is not a problem. Regards, Pieter Bos --- ## Post #3 by @system Sorry, I first replied to Pieter Bos only, now to the list\. Pieter already replied to me that the question was not about XSD to check datasets was \. So, read my reply, for those interested in easy validating datasets: It is possible to have an XSD to describe the AOM, but you cannot have an XSD to describe an archetype and check a dataset with it\. Archetypes can have logical constructs which are not allowed in XSD\. It has to do with elements with the same name on the same level, that is not allowed in XSD, even not when there are different attributes\. You can use Schematron to check an archetyped XML dataset\. I believe the LinkEHR editor generates such Schematrons\. I also found Schematron validator for JSON, I think that this is very interesting for some kernel software developers, because XML is slowly becoming something of an previous era\. https://www.npmjs.com/package/jsontron Good luck with it\. Bert\. --- ## Post #4 by @system Hi Peter, The Archie\-Toolkit looks promising\. I tried to parse one of the archetypes from the CKM \(BloodPressure\) and tried to parse the exported ADL\. However, I got a Exception when trying this because the exported ADL does not seem to be parseable: line 1:24 mismatched input '1\.4' expecting VERSION\_ID line 2:1 mismatched input 'openEHR\-EHR\-OBSERVATION\.blood\_pressure\.v1' expecting ARCHETYPE\_HRID With the exported XML and the try to unmarshal the XML with the JAXBUtil I also did not succeed\. Is there somewhere a testcase were I can see a working example of a parsed ADL String ? Greetings Georg Hello George, If you are looking for something to handle ADL 2 archetypes \- the most recent version \-, have a look at https://github.com/opener/archie \. It is a java library that can parse archetypes, flatten and validate them, create operational templates and more\. Are you using the openehr reference model, or something else like fihr? Although Archie can parse and serialize archetypes in XML, archetypes are usually stored as ADL\. This is a custom more readable format\. Of course you can then easily convert it to XML or Json to work with them in other tools where you do not have an ADL parser ready\. Note that for ADL 2 as far as I know there is no official XSD released yet, so it is possible you run into compatibility problems with XML\. For ADL 1\.4 this is not a problem\. Regards, Pieter Bos --- ## Post #5 by @yampeku Hello Georg, Archie is meant to be used with ADL2 archetypes, if you want to parse 1.4 archetypes I think java implementation you mentioned before is your current best option. Regards --- ## Post #6 by @system Yes, [https://github.com/openEHR/java-libs](https://github.com/openEHR/java-libs) works for ADL 1.4. If you want the latest and newest, ADL 2 is the way to go. You can convert the archetypes to ADL 2 using the ADL workbench and they will parse with Archie. The workbench can be found at http://www.openehr.org. If you want compatibility with existing systems, ADL 1.4 for now – I think most EHRs are 1.4 only at the moment. Regards, Pieter Bos --- ## Post #7 by @system you can, it's called a Template Data Schema \(TDS\), and is generated from the Template Designer and I think the new Marand ADL\-designer\. Its intended exactly for checking data sets\.\.\. whether this is the real requirement being talked about here may be another question\. \- thomas --- ## Post #8 by @system >> you can, it's called a Template Data Schema \(TDS\), and is generated from the Template Designer and I think the new Marand ADL\-designer\. Its intended exactly for checking data sets\.\.\. > > Of course you can write any validation tool you want, but you cannot do this and still conform to the XML Schema standard, that is why Schematron became important\. With Schematron you can validate anything\. As I wrote this morning, LinkEhr also generates Schematron for validation purpose\. this already works \(for nearly 10 years\) and it validates against the XML schema standard\. What it doesn't do is validate everything you want to validate, i\.e\. not all things in the archetypes\. But it's good enough most of the time\. To do things properly, I agree, you would probably use Schematron \+ XSD, or personally I have always thought that Schematron \+ Relax\-NG would be better\. >> whether this is the real requirement being talked about here may be another question\. > > You are right, it was not what was asked, still I thought it would be interesting for others to know that there is a JSON Schematron parser \(instead of an XML Schematron\-parser\), which can be used to validate JSON OpenEhr\-datasets against archetypes/templates\. that might be an interesting thing to have in the openEHR toolkit\. We are just now revising and re\-organising all the openEHR XSDs, and also adding in some JSON\-schemas\. Any related artefacts that anyone wants to contribute, or fragments that could be used in something larger would be appreciated \- it will all get posted in the specifications\-ITS\-XML git repo under the usual CC licence\. --- ## Post #9 by @system > >> Sorry, I first replied to Pieter Bos only, now to the list\. Pieter already replied to me that the question was not about XSD to check datasets was \. >> >> So, read my reply, for those interested in easy validating datasets: >> >> It is possible to have an XSD to describe the AOM, but you cannot have an XSD to describe an archetype and check a dataset with it\. >> > > you can, it's called a Template Data Schema \(TDS\), and is generated from the Template Designer and I think the new Marand ADL\-designer\. Its intended exactly for checking data sets\.\.\. Of course you can write any validation tool you want, but you cannot do this and still conform to the XML Schema standard, that is why Schematron became important\. With Schematron you can validate anything\. As I wrote this morning, LinkEhr also generates Schematron for validation purpose\. > whether this is the real requirement being talked about here may be another question\. You are right, it was not what was asked, still I thought it would be interesting for others to know that there is a JSON Schematron parser \(instead of an XML Schematron\-parser\), which can be used to validate JSON OpenEhr\-datasets against archetypes/templates\. I wrote an AOM\(OpenEhr/CEN13606\)\-Schematron\-validation\-generator years ago, exactly for this reason, I must have the sourcecode somewhere\. Good for Marand to have validation too, because checking data\-sets before storing them is an important responsibility of an OpenEhr\-kernel\. Bert --- ## Post #10 by @system > >>> you can, it's called a Template Data Schema \(TDS\), and is generated from the Template Designer and I think the new Marand ADL\-designer\. Its intended exactly for checking data sets\.\.\. >> >> Of course you can write any validation tool you want, but you cannot do this and still conform to the XML Schema standard, that is why Schematron became important\. With Schematron you can validate anything\. As I wrote this morning, LinkEhr also generates Schematron for validation purpose\. > > this already works \(for nearly 10 years\) and it validates against the XML schema standard\. What it doesn't do is validate everything you want to validate, i\.e\. not all things in the archetypes\. But it's good enough most of the time\. > I am in the proud possession of the book, "Definitive XML Schema 1\.1" by Priscilla Walmsley\. We had this discussion a few times already I quote from https://www.mail-archive.com/search?q=walmsley&l=openehr-technical%40lists.openehr.org https://www.mail-archive.com/openehr-technical@lists.openehr.org/msg07405.html >> Another very important restriction for using XML Schema, in my opinion, >> is that you cannot have two or more elements with the same name but a >> different data type\. This data type must be in detail the same\. XML Schema >> regards an Element with a Dv\_Text as a different datatype from an Element >> with a Dv\_CodedText\. >> >> Both elements will be called "items" in an XML schema representing an >> OpenEhr data structure, and thus is not allowed having them different >> details in data types\. Sorry for the funny font, > To do things properly, I agree, you would probably use Schematron \+ XSD, or personally I have always thought that Schematron \+ Relax\-NG would be better\. > Also I went through that path, with Relax NG, I struggled quite some time with this, and not me alone\. Ask Diego why LinkEhr does not export RelaxNG or XML Schema but Schematron as validation files \(although, it was like this a few years ago, it still is so in the version I have\)\. The XSD standard\-constraint mentioned above also becomes visible with standard XML libraries\. If I would have time I would proof it to you in a simple way\. >>> whether this is the real requirement being talked about here may be another question\. >> >> You are right, it was not what was asked, still I thought it would be interesting for others to know that there is a JSON Schematron parser \(instead of an XML Schematron\-parser\), which can be used to validate JSON OpenEhr\-datasets against archetypes/templates\. > > that might be an interesting thing to have in the openEHR toolkit\. We are just now revising and re\-organising all the openEHR XSDs, and also adding in some JSON\-schemas\. Any related artefacts that anyone wants to contribute, or fragments that could be used in something larger would be appreciated \- it will all get posted in the specifications\-ITS\-XML git repo under the usual CC licence\. > OpenEhr uses XSD schemas for class descriptions, there is no problem at all\. It is even an often used methodology in the Java world to describe/generate class\-interfaces\. The problem is when using XML Schema for validation of archetyped XML\-data\. But again, this was not the problem the question was initially about\. Sorry for the confusion\. Bert --- ## Post #11 by @system This already happens in a Item\-List, so the constraint is quite easy to trigger\. --- **Canonical:** https://discourse.openehr.org/t/parsing-of-archetypes-templates/15547 **Original content:** https://discourse.openehr.org/t/parsing-of-archetypes-templates/15547