# Questions about flattening the template **Category:** [Reference Implementation: Java (archive)](https://discourse.openehr.org/c/reference-implementation-java-archive/154) **Created:** 2012-02-14 20:55 UTC **Views:** 4 **Replies:** 5 **URL:** https://discourse.openehr.org/t/questions-about-flattening-the-template/16154 --- ## Post #1 by @martin_g Hello, I try to implement the openEHR standard for Android and have done so for nearly all sublibs of the openEHR standard, but there is a problem with the oet-parser: After loading a template successfully I want to flatten it like this: [CODE] flattened = flattener.toFlattenedArchetype(template, archetypeMap, templateMap); [/CODE] But I always get an exception thrown in the Flattener.java in the method "flattenArchetyped". After debugging I realised that my template's definition instance is none of the "supported" ones. I always get the definition or rather classname"ArchetypedImpl" - it does not matter which template I load and which definition it has in the xml code. Do you have any idea what could be wrong here? Due to the fact that a the "getDefinition" method of the TEMPLATE class returns an Archetyped it seems really logical that I always get this ... Another question: Does an .opt parser exist for the java-ref-impl? Thanks in advance for every answer. best regards! --- ## Post #2 by @system Hi\! How do you produce your OET template, manually or with Ocean's OET template designer? For your question, currently there is no opt template parser in the java ref impl\. Cheers, Rong --- ## Post #3 by @martin_g Hi, thanks for the fast answer. the OET templates I use for testing I got from the SVN repository of the open-ehr-refimpl (in the oet-parser's test resource folder) best regards, Martin 2012/2/16 Rong Chen <[rong.acode@gmail.com](mailto:rong.acode@gmail.com)> --- ## Post #4 by @system OK, have you modified the template in any way? Have you supplied needed archetypes for flattening? and finally what is the exception you got? /Rong --- ## Post #5 by @martin_g Hi, thanks again, no I haven't modified the templates and due to the supplied needed archetypes: yes I think so (see code below - just to mention this: the debug print shows the correct values of the template). The exception I get is thrown in the Flattener.java (see below the stacktrace). thanks! [EXCEPTION] org.openehr.am.template.FlatteningException: Unkown archetyped sub-type at org.openehr.am.template.Flattener.flattenArchetyped(Flattener.java:174) at org.openehr.am.template.Flattener.toFlattenedArchetype(Flattener.java:133) at org.openehr.am.template.Flattener.toFlattenedArchetype(Flattener.java:119) .... [\EXCEPTION] Here's the code: [CODE] Flattener flattener = new Flattener(); String[] ids = { "openEHR-EHR-COMPOSITION.prescription.v1", "openEHR-EHR-INSTRUCTION.medication.v1", "openEHR-EHR-ITEM_TREE.medication.v1", "openEHR-EHR-ITEM_TREE.medication_mod.v1", "openEHR-EHR-SECTION.medications.v1", "openEHR-EHR-ITEM_TREE.medication_test_one.v1", "openEHR-EHR-ITEM_TREE.medication_test_three.v1", "openEHR-EHR-ITEM_TREE.medication_multiple_constraint_test.v1", "openEHR-EHR-ITEM_TREE.medication_multiple_constraint_test2.v1", "openEHR-EHR-SECTION.ad_hoc_heading.v1", "openEHR-EHR-SECTION.simple_section_name.v1", "openEHR-EHR-COMPOSITION.test.v1", "openEHR-EHR-EVALUATION.structured_summary.v1", "openEHR-EHR-EVALUATION.review_of_procedures.v1", "openEHR-EHR-ACTION.medication.v1", "openEHR-EHR-ITEM_TREE.medication.v1", "openEHR-EHR-ITEM_TREE.medication_quantity_test.v1", "openEHR-EHR-ITEM_TREE.medication_quantity_test2.v1", "openEHR-EHR-OBSERVATION.waist_hip.v2", "openEHR-EHR-OBSERVATION.lab_test.v1", "openEHR-EHR-OBSERVATION.heart_failure_stage.v2", "openEHR-EHR-EVALUATION.medication_review.v1" }; archetypeMap = new HashMap(); for(String id : ids) { Archetype archetype; try { archetype = loadArchetype(id + ".adl"); archetypeMap.put(archetype.getArchetypeId().toString(), archetype); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { parser = new OETParser(); template = loadTemplate("prescription.oet"); System.out.println(template.getId()); Archetyped xy = template.getDefinition(); //this if is just for debugging --> xy always is an instance of ArchetypedImpl if(xy instanceof ArchetypedImpl){ System.out.println("TRUE"); Node test = xy.getDomNode().getAttributes().item(0); System.out.println(xy.getArchetypeId() + "\n DESCRIPTION: " + xy.getDomNode().getLocalName() + " " + test.getLocalName() + " " + test.getNodeValue()); } flattened = flattener.toFlattenedArchetype(template, archetypeMap, templateMap); } catch (FlatteningException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } [\CODE] 2012/2/20 Rong Chen <[rong.acode@gmail.com](mailto:rong.acode@gmail.com)> --- ## Post #6 by @system Sorry for the late response\. Lost track of this one after vacation\.\. I really don't see any problem with your code\. I wonder if you could run the unit tests on oet\-parser successfully? Please note that you should only use the components, adl\-parser etc from the TRUNK\. /Rong --- **Canonical:** https://discourse.openehr.org/t/questions-about-flattening-the-template/16154 **Original content:** https://discourse.openehr.org/t/questions-about-flattening-the-template/16154