diff --git a/aom/src/main/java/com/nedap/archie/aom/Archetype.java b/aom/src/main/java/com/nedap/archie/aom/Archetype.java index bec81b870..5adc436c6 100644 --- a/aom/src/main/java/com/nedap/archie/aom/Archetype.java +++ b/aom/src/main/java/com/nedap/archie/aom/Archetype.java @@ -10,12 +10,18 @@ import com.nedap.archie.definitions.AdlCodeDefinitions; import com.nedap.archie.query.AOMPathQuery; import com.nedap.archie.xml.adapters.ArchetypeTerminologyAdapter; +import com.nedap.archie.xml.adapters.StringDictionaryMapAdapter; +import com.nedap.archie.xml.adapters.StringDictionaryUtil; +import com.nedap.archie.xml.types.StringDictionaryItem; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.LinkedHashMap; @@ -46,7 +52,7 @@ "buildUid", "rmRelease", "generated", - "otherMetaData" + "xmlOtherMetaData" }) public class Archetype extends AuthoredResource { @@ -70,10 +76,31 @@ public class Archetype extends AuthoredResource { private String rmRelease; @XmlAttribute(name="is_generated") private Boolean generated = false; + //this is a specific map type to make a JAXB-adapter work. ugly jaxb + //alternative: define an extra field, use hooks to fill it just in time instead + @XmlTransient + private LinkedHashMap otherMetaData = new LinkedHashMap<>(); @XmlElement(name="other_meta_data") - //TODO: this probably requires a custom XmlAdapter - private Map otherMetaData = new LinkedHashMap<>(); + @JsonIgnore + private List xmlOtherMetaData; + + // Invoked by Jaxb Marshaller after unmarshalling + public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if(xmlOtherMetaData != null) { + otherMetaData = StringDictionaryUtil.convertStringDictionaryListToStringMap(xmlOtherMetaData); + } + } + + // Invoked by Jaxb Marshaller before marshalling + public boolean beforeMarshal(Marshaller marshaller) { + if(otherMetaData == null) { + xmlOtherMetaData = null; + } else { + xmlOtherMetaData = StringDictionaryUtil.convertStringMapIntoStringDictionaryList(otherMetaData); + } + return true; + } public String getParentArchetypeId() { return parentArchetypeId; @@ -162,7 +189,7 @@ public Map getOtherMetaData() { } public void setOtherMetaData(Map otherMetaData) { - this.otherMetaData = otherMetaData; + this.otherMetaData = new LinkedHashMap<>(otherMetaData); } public void addOtherMetadata(String text, String value) { diff --git a/aom/src/main/java/com/nedap/archie/aom/LanguageSection.java b/aom/src/main/java/com/nedap/archie/aom/LanguageSection.java index b87b29873..01ad187cb 100644 --- a/aom/src/main/java/com/nedap/archie/aom/LanguageSection.java +++ b/aom/src/main/java/com/nedap/archie/aom/LanguageSection.java @@ -4,6 +4,7 @@ import com.nedap.archie.base.OpenEHRBase; import com.nedap.archie.base.terminology.TerminologyCode; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/aom/src/main/java/com/nedap/archie/aom/OperationalTemplate.java b/aom/src/main/java/com/nedap/archie/aom/OperationalTemplate.java index 14f1cd24a..28af3f2f4 100644 --- a/aom/src/main/java/com/nedap/archie/aom/OperationalTemplate.java +++ b/aom/src/main/java/com/nedap/archie/aom/OperationalTemplate.java @@ -1,16 +1,26 @@ package com.nedap.archie.aom; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import com.nedap.archie.aom.terminology.ArchetypeTerm; import com.nedap.archie.aom.terminology.ArchetypeTerminology; import com.nedap.archie.aom.utils.AOMUtils; import com.nedap.archie.paths.PathSegment; +import com.nedap.archie.xml.adapters.ArchetypeTerminologyAdapter; +import com.nedap.archie.xml.adapters.StringDictionaryUtil; +import com.nedap.archie.xml.types.StringDictionaryItem; +import com.nedap.archie.xml.types.XmlArchetypeTerminology; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; +import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -26,11 +36,72 @@ public class OperationalTemplate extends AuthoredArchetype { /** * terminology extracts from subarchetypes, for example snomed codes, multiple choice thingies, etc */ - @XmlElement(name="terminology_extracts") //TODO: requires an adapter for JAXB to work + @XmlTransient private Map terminologyExtracts = new ConcurrentHashMap<>();//TODO: is this correct? - @XmlElement(name="component_terminologies") //TODO: requires an adapter for JAXB to work + @XmlTransient private Map componentTerminologies = new ConcurrentHashMap<>(); + @XmlElement(name="terminology_extracts") + private List xmlTerminologyExtracts; + @XmlElement(name="component_terminologies") + private List xmlComponentTerminologies; + + @Override + public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + super.afterUnmarshal(unmarshaller, parent); + if(xmlTerminologyExtracts != null) { + ArchetypeTerminologyAdapter archetypeTerminologyAdapter = new ArchetypeTerminologyAdapter(); + for(XmlArchetypeTerminology terminology:xmlTerminologyExtracts) { + try { + ArchetypeTerminology converted = archetypeTerminologyAdapter.unmarshal(terminology); + terminologyExtracts.put(terminology.getArchetypeId(), converted); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + } + if(xmlComponentTerminologies != null) { + ArchetypeTerminologyAdapter archetypeTerminologyAdapter = new ArchetypeTerminologyAdapter(); + for(XmlArchetypeTerminology terminology:xmlComponentTerminologies) { + try { + ArchetypeTerminology converted = archetypeTerminologyAdapter.unmarshal(terminology); + componentTerminologies.put(terminology.getArchetypeId(), converted); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + } + } + + // Invoked by Marshaller after it has created an instance of this object. + @Override + public boolean beforeMarshal(Marshaller marshaller) { + super.beforeMarshal(marshaller); + if(terminologyExtracts != null && !terminologyExtracts.isEmpty()) { + ArchetypeTerminologyAdapter archetypeTerminologyAdapter = new ArchetypeTerminologyAdapter(); + xmlTerminologyExtracts = new ArrayList<>(); + for(Map.Entry terminology:terminologyExtracts.entrySet()) { + XmlArchetypeTerminology converted = archetypeTerminologyAdapter.marshal(terminology.getValue()); + converted.setArchetypeId(terminology.getKey()); + xmlTerminologyExtracts.add(converted); + } + } else { + xmlTerminologyExtracts = null; + } + if(componentTerminologies != null && !componentTerminologies.isEmpty()) { + ArchetypeTerminologyAdapter archetypeTerminologyAdapter = new ArchetypeTerminologyAdapter(); + xmlComponentTerminologies = new ArrayList<>(); + for(Map.Entry terminology:componentTerminologies.entrySet()) { + XmlArchetypeTerminology converted = archetypeTerminologyAdapter.marshal(terminology.getValue()); + converted.setArchetypeId(terminology.getKey()); + xmlComponentTerminologies.add(converted); + } + } else { + xmlComponentTerminologies = null; + } + return true; + } + public Map getTerminologyExtracts() { return terminologyExtracts; diff --git a/aom/src/main/java/com/nedap/archie/aom/package-info.java b/aom/src/main/java/com/nedap/archie/aom/package-info.java new file mode 100644 index 000000000..53da5b083 --- /dev/null +++ b/aom/src/main/java/com/nedap/archie/aom/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.aom; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/aom/src/main/java/com/nedap/archie/aom/primitives/package-info.java b/aom/src/main/java/com/nedap/archie/aom/primitives/package-info.java new file mode 100644 index 000000000..54976e345 --- /dev/null +++ b/aom/src/main/java/com/nedap/archie/aom/primitives/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.aom.primitives; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/aom/src/main/java/com/nedap/archie/aom/terminology/ArchetypeTerminology.java b/aom/src/main/java/com/nedap/archie/aom/terminology/ArchetypeTerminology.java index 236e800d7..102ebd675 100644 --- a/aom/src/main/java/com/nedap/archie/aom/terminology/ArchetypeTerminology.java +++ b/aom/src/main/java/com/nedap/archie/aom/terminology/ArchetypeTerminology.java @@ -30,14 +30,11 @@ public class ArchetypeTerminology extends ArchetypeModelObject { private String originalLanguage; @XmlElement(name="concept_code") private String conceptCode; - @XmlTransient//TODO! - //@XmlElement(name="term_definitions") + @XmlTransient //converted to XmlArchetypeTerminology, so not used in jaxb private Map> termDefinitions = new ConcurrentHashMap<>(); - //@XmlElement(name="term_bindings") - @XmlTransient//TODO! + @XmlTransient //converted to XmlArchetypeTerminology, so not used in jaxb private Map> termBindings = new ConcurrentHashMap<>(); - //@XmlElement(name="terminology_extracts") - @XmlTransient//TODO! + @XmlTransient //converted to XmlArchetypeTerminology, so not used in jaxb private Map> terminologyExtracts = new ConcurrentHashMap<>(); @XmlElement(name="value_sets") private Map valueSets = new ConcurrentHashMap<>(); diff --git a/aom/src/main/java/com/nedap/archie/aom/terminology/package-info.java b/aom/src/main/java/com/nedap/archie/aom/terminology/package-info.java new file mode 100644 index 000000000..c80b82de5 --- /dev/null +++ b/aom/src/main/java/com/nedap/archie/aom/terminology/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.aom.terminology; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/aom/src/main/java/com/nedap/archie/rules/package-info.java b/aom/src/main/java/com/nedap/archie/rules/package-info.java new file mode 100644 index 000000000..bdfef6a88 --- /dev/null +++ b/aom/src/main/java/com/nedap/archie/rules/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rules; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/aom/src/main/java/com/nedap/archie/xml/adapters/ArchetypeTerminologyAdapter.java b/aom/src/main/java/com/nedap/archie/xml/adapters/ArchetypeTerminologyAdapter.java index 4742e8560..c9c311ffc 100644 --- a/aom/src/main/java/com/nedap/archie/xml/adapters/ArchetypeTerminologyAdapter.java +++ b/aom/src/main/java/com/nedap/archie/xml/adapters/ArchetypeTerminologyAdapter.java @@ -10,6 +10,7 @@ import javax.xml.bind.annotation.adapters.XmlAdapter; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -23,7 +24,7 @@ public class ArchetypeTerminologyAdapter extends XmlAdapter { @Override - public XmlArchetypeTerminology marshal(ArchetypeTerminology terminology) throws Exception { + public XmlArchetypeTerminology marshal(ArchetypeTerminology terminology) { if(terminology == null) { return null; } @@ -71,7 +72,7 @@ private List convertIntoCodeDefinitionSetList(Map convertIntoValueSetMap(List valueSets) { return result; } - private Map> convertIntoTermBindingsMap(List termBindings) throws Exception{ + private Map> convertIntoTermBindingsMap(List termBindings) throws URISyntaxException { Map> result = new LinkedHashMap<>(); for(TermBindingSet set:termBindings) { Map termMap = StringDictionaryUtil.convertStringDictionaryListToUriMap(set.getItems()); diff --git a/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryMapAdapter.java b/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryMapAdapter.java new file mode 100644 index 000000000..1e215cf44 --- /dev/null +++ b/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryMapAdapter.java @@ -0,0 +1,21 @@ +package com.nedap.archie.xml.adapters; + +import com.nedap.archie.aom.TranslationDetails; +import com.nedap.archie.xml.types.StringDictionaryItem; +import com.nedap.archie.xml.types.XmlTranslationDetails; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +public class StringDictionaryMapAdapter extends XmlAdapter, LinkedHashMap> { + @Override + public LinkedHashMap unmarshal(ArrayList v) throws Exception { + return StringDictionaryUtil.convertStringDictionaryListToStringMap(v); + } + + @Override + public ArrayList marshal(LinkedHashMap v) throws Exception { + return StringDictionaryUtil.convertStringMapIntoStringDictionaryList(v); + } +} diff --git a/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryUtil.java b/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryUtil.java index 2639f9b59..042c984d0 100644 --- a/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryUtil.java +++ b/aom/src/main/java/com/nedap/archie/xml/adapters/StringDictionaryUtil.java @@ -53,11 +53,11 @@ public static Map convertStringDictionaryListToUriMap(List convertStringDictionaryListToStringMap(List items) { + public static LinkedHashMap convertStringDictionaryListToStringMap(List items) { if(items == null) { return null; } - Map termMap = new LinkedHashMap<>(); + LinkedHashMap termMap = new LinkedHashMap<>(); for(StringDictionaryItem term:items) { termMap.put(term.getId(),term.getValue()); } diff --git a/aom/src/main/java/com/nedap/archie/xml/types/XmlArchetypeTerminology.java b/aom/src/main/java/com/nedap/archie/xml/types/XmlArchetypeTerminology.java index 9efe4b7b7..b80b2cac5 100644 --- a/aom/src/main/java/com/nedap/archie/xml/types/XmlArchetypeTerminology.java +++ b/aom/src/main/java/com/nedap/archie/xml/types/XmlArchetypeTerminology.java @@ -18,6 +18,8 @@ @XmlAccessorType(XmlAccessType.FIELD) public class XmlArchetypeTerminology { + @XmlAttribute(name="archetype_id") + private String archetypeId; @XmlAttribute(name="is_differential") private Boolean differential; @XmlAttribute(name="original_language") @@ -34,6 +36,14 @@ public class XmlArchetypeTerminology { @XmlElement(name="value_sets") private List valueSets = new ArrayList<>(); + public String getArchetypeId() { + return archetypeId; + } + + public void setArchetypeId(String archetypeId) { + this.archetypeId = archetypeId; + } + public List getTermDefinitions() { return termDefinitions; } diff --git a/aom/src/main/java/com/nedap/archie/xml/types/XmlResourceDescription.java b/aom/src/main/java/com/nedap/archie/xml/types/XmlResourceDescription.java index 3ada2a81a..a875d7786 100644 --- a/aom/src/main/java/com/nedap/archie/xml/types/XmlResourceDescription.java +++ b/aom/src/main/java/com/nedap/archie/xml/types/XmlResourceDescription.java @@ -42,7 +42,7 @@ public class XmlResourceDescription { private List conversionDetails; @XmlElement(name = "other_details") private List otherDetails; - @XmlElement(required = true, type = ResourceDescriptionItem.class) + @XmlElement(required = true, type = XmlResourceDescriptionItem.class) private List details; public List getOriginalAuthor() { diff --git a/aom/src/main/java/com/nedap/archie/xml/types/package-info.java b/aom/src/main/java/com/nedap/archie/xml/types/package-info.java new file mode 100644 index 000000000..d74eee96d --- /dev/null +++ b/aom/src/main/java/com/nedap/archie/xml/types/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.xml.types; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/archie-utils/src/main/java/com/nedap/archie/xml/JAXBUtil.java b/archie-utils/src/main/java/com/nedap/archie/xml/JAXBUtil.java index 64028aa87..ed6377ed7 100644 --- a/archie-utils/src/main/java/com/nedap/archie/xml/JAXBUtil.java +++ b/archie-utils/src/main/java/com/nedap/archie/xml/JAXBUtil.java @@ -1,6 +1,12 @@ package com.nedap.archie.xml; import com.google.common.collect.Lists; +import com.nedap.archie.aom.AuthoredResource; +import com.nedap.archie.aom.LanguageSection; +import com.nedap.archie.aom.ResourceDescription; +import com.nedap.archie.aom.ResourceDescriptionItem; +import com.nedap.archie.aom.TranslationDetails; +import com.nedap.archie.aom.terminology.ArchetypeTerminology; import com.nedap.archie.rminfo.ArchieAOMInfoLookup; import com.nedap.archie.rminfo.ArchieRMInfoLookup; import com.nedap.archie.xml.types.XmlResourceDescriptionItem; @@ -39,6 +45,7 @@ private static synchronized void initArchieJaxbContext() { classes.addAll(ArchieRMInfoLookup.getInstance().getRmTypeNameToClassMap().values()); //extra classes from the adapters package that are not directly referenced.\ classes.add(XmlResourceDescriptionItem.class); + removeClasses(classes); archieJaxbContext = JAXBContext.newInstance(classes.toArray(new Class[0])); } catch (JAXBException e) { throw new RuntimeException(e);//programmer error, tests will fail @@ -51,6 +58,7 @@ public static synchronized JAXBContext createAOMContext() { List> classes = Lists.newArrayList(ArchieAOMInfoLookup.getInstance().getRmTypeNameToClassMap().values()); //extra classes from the adapters package that are not directly referenced.\ classes.add(XmlResourceDescriptionItem.class); + removeClasses(classes); return JAXBContext.newInstance(classes.toArray(new Class[0])); } catch (JAXBException e) { throw new RuntimeException(e);//programmer error, tests will fail @@ -60,10 +68,28 @@ public static synchronized JAXBContext createAOMContext() { public static synchronized JAXBContext createRMContext() { try { List> classes = Lists.newArrayList(ArchieRMInfoLookup.getInstance().getRmTypeNameToClassMap().values()); + removeClasses(classes); return JAXBContext.newInstance(classes.toArray(new Class[0])); } catch (JAXBException e) { throw new RuntimeException(e);//programmer error, tests will fail } } + private static void removeClasses(List> classes) { + //remove classes that are adapted to other classes anyway, particularly those using maps + removeAllInstances(classes, ResourceDescription.class); + removeAllInstances(classes, ResourceDescriptionItem.class); + removeAllInstances(classes, LanguageSection.class); + removeAllInstances(classes, ArchetypeTerminology.class); + removeAllInstances(classes, TranslationDetails.class); + removeAllInstances(classes, AuthoredResource.class); + } + + private static void removeAllInstances(List something, T instance) { + boolean found; + do { + found = something.remove(instance); + } while(found); + } + } diff --git a/base/src/main/java/com/nedap/archie/base/package-info.java b/base/src/main/java/com/nedap/archie/base/package-info.java new file mode 100644 index 000000000..6a03ac3c0 --- /dev/null +++ b/base/src/main/java/com/nedap/archie/base/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.base; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/base/src/main/java/com/nedap/archie/base/terminology/package-info.java b/base/src/main/java/com/nedap/archie/base/terminology/package-info.java new file mode 100644 index 000000000..3199f2076 --- /dev/null +++ b/base/src/main/java/com/nedap/archie/base/terminology/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.base.terminology; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/base/src/main/java/com/nedap/archie/definitions/package-info.java b/base/src/main/java/com/nedap/archie/definitions/package-info.java new file mode 100644 index 000000000..06bd5a38e --- /dev/null +++ b/base/src/main/java/com/nedap/archie/definitions/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.definitions; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/archetyped/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/archetyped/package-info.java new file mode 100644 index 000000000..58db51ebc --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/archetyped/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.archetyped; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/changecontrol/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/changecontrol/package-info.java new file mode 100644 index 000000000..0e6f68f1c --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/changecontrol/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.changecontrol; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/composition/Activity.java b/openehr-rm/src/main/java/com/nedap/archie/rm/composition/Activity.java index 4a6e99d62..48f775599 100644 --- a/openehr-rm/src/main/java/com/nedap/archie/rm/composition/Activity.java +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/composition/Activity.java @@ -23,7 +23,7 @@ /** * Created by pieter.bos on 04/11/15. */ -@XmlRootElement(name = "activity", namespace = "http://schemas.openehr.org/v1" ) +@XmlRootElement(name = "activity" ) @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "ACTIVITY", propOrder = { "description", diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/composition/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/composition/package-info.java new file mode 100644 index 000000000..4497fc055 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/composition/package-info.java @@ -0,0 +1,6 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.composition; + +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlNsForm; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datastructures/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datastructures/package-info.java new file mode 100644 index 000000000..152f012eb --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datastructures/package-info.java @@ -0,0 +1,8 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", /*xmlns = {@XmlNs(prefix = "", namespaceURI = "http://schemas.openehr.org/v1") + +}*/ elementFormDefault = XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datastructures; + +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlNsForm; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datatypes/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datatypes/package-info.java new file mode 100644 index 000000000..a00536e1c --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datatypes/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datatypes; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/DvText.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/DvText.java index e739ea74d..3d5847a0c 100644 --- a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/DvText.java +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/DvText.java @@ -8,6 +8,7 @@ import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import java.util.ArrayList; import java.util.List; @@ -16,6 +17,7 @@ /** * Created by pieter.bos on 04/11/15. */ +@XmlRootElement(name = "DV_TEXT") @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "DV_TEXT", propOrder = { "value", diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/encapsulated/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/encapsulated/package-info.java new file mode 100644 index 000000000..e5c4bafe2 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/encapsulated/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datavalues.encapsulated; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/package-info.java new file mode 100644 index 000000000..145791874 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datavalues; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/quantity/datetime/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/quantity/datetime/package-info.java new file mode 100644 index 000000000..7231bc627 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/quantity/datetime/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datavalues.quantity.datetime; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/quantity/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/quantity/package-info.java new file mode 100644 index 000000000..7e7db4f13 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/quantity/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datavalues.quantity; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/timespecification/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/timespecification/package-info.java new file mode 100644 index 000000000..bb94868ae --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/datavalues/timespecification/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.datavalues.timespecification; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/demographic/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/demographic/package-info.java new file mode 100644 index 000000000..2362c60af --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/demographic/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.demographic; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/directory/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/directory/package-info.java new file mode 100644 index 000000000..021fe027e --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/directory/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.directory; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/ehr/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/ehr/package-info.java new file mode 100644 index 000000000..bacf0f104 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/ehr/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.ehr; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/generic/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/generic/package-info.java new file mode 100644 index 000000000..5aa38b69f --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/generic/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.generic; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/integration/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/integration/package-info.java new file mode 100644 index 000000000..2673be88b --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/integration/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.integration; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/package-info.java index d5b88ff97..b6f59a3d3 100644 --- a/openehr-rm/src/main/java/com/nedap/archie/rm/package-info.java +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/package-info.java @@ -1,3 +1,5 @@ -@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) -package com.nedap.archie.rm; \ No newline at end of file +package com.nedap.archie.rm; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/security/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/security/package-info.java new file mode 100644 index 000000000..b0f8d7e88 --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/security/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.security; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/ArchetypeID.java b/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/ArchetypeID.java index e0158d60f..635b488d0 100644 --- a/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/ArchetypeID.java +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/ArchetypeID.java @@ -5,6 +5,7 @@ import com.nedap.archie.rminfo.RMPropertyIgnore; import javax.annotation.Nullable; +import javax.xml.bind.Unmarshaller; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -251,4 +252,12 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(super.hashCode(), namespace, qualifiedRmEntity, domainConcept, rmOriginator, rmName, rmEntity, specialisation, versionId); } + + // after JAXB unmarshalling, set the field values correctly + public void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if(this.rmName == null) { + parseValue(getValue()); + } + + } } diff --git a/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/package-info.java b/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/package-info.java new file mode 100644 index 000000000..9e49b406f --- /dev/null +++ b/openehr-rm/src/main/java/com/nedap/archie/rm/support/identification/package-info.java @@ -0,0 +1,5 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.openehr.org/v1", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED) + +package com.nedap.archie.rm.support.identification; + +import javax.xml.bind.annotation.XmlNs; \ No newline at end of file diff --git a/openehr-rm/src/test/resources/com/nedap/archie/rm/composition/test_all_types.fixed.v1.xml b/openehr-rm/src/test/resources/com/nedap/archie/rm/composition/test_all_types.fixed.v1.xml index e21401ee6..ae6dd4029 100644 --- a/openehr-rm/src/test/resources/com/nedap/archie/rm/composition/test_all_types.fixed.v1.xml +++ b/openehr-rm/src/test/resources/com/nedap/archie/rm/composition/test_all_types.fixed.v1.xml @@ -1,18 +1,19 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://schemas.openehr.org/v1"> Test all types - - - - - - - - - + + + openEHR-EHR-COMPOSITION.test_all_types.v1 + + + test_all_types.en.v1 + + 1.0.2 + ISO_639-1 diff --git a/tools/src/main/java/com/nedap/archie/query/APathToXPathConverter.java b/tools/src/main/java/com/nedap/archie/query/APathToXPathConverter.java index 6bea3929c..535d393ab 100644 --- a/tools/src/main/java/com/nedap/archie/query/APathToXPathConverter.java +++ b/tools/src/main/java/com/nedap/archie/query/APathToXPathConverter.java @@ -117,13 +117,26 @@ private static void writeTree(StringBuilder output, ParseTree tree, boolean inPr for(int i = 0; i < tree.getChildCount(); i++) { ParseTree child = tree.getChild(i); if(child instanceof TerminalNode) { - boolean shouldAppendSpace = literalsThatShouldHaveSpacing.contains(child.getText().toLowerCase()); - if(shouldAppendSpace) { - output.append(" "); + boolean continueIf = true; + if(!inPredicate && child.getText().equals("/")) { + if(i + 1 < tree.getChildCount()) { + if(!tree.getChild(i+1).getText().equals("/")) { + output.append("/"); + output.append(ArchieNamespaceResolver.OPENEHR_NS_PREFIX); + output.append(":"); + continueIf = false; + } + } } - output.append(child.getText()); - if(shouldAppendSpace) { - output.append(" "); + if (continueIf) { + boolean shouldAppendSpace = literalsThatShouldHaveSpacing.contains(child.getText().toLowerCase()); + if (shouldAppendSpace) { + output.append(" "); + } + output.append(child.getText()); + if (shouldAppendSpace) { + output.append(" "); + } } } else if (child instanceof AndExprContext) { for(int j = 0; j < child.getChildCount(); j++) { @@ -155,7 +168,7 @@ private static void writeTree(StringBuilder output, ParseTree tree, boolean inPr output.append("position() = "); output.append(child.getText()); } else if(filterExprContext.primaryExpr().Literal() != null) { - output.append("name/value = "); + output.append("openehr:name/openehr:value = "); output.append(child.getText()); } else { writeTree(output, child, inPredicate); diff --git a/tools/src/main/java/com/nedap/archie/query/ArchieNamespaceResolver.java b/tools/src/main/java/com/nedap/archie/query/ArchieNamespaceResolver.java index 848f2c8ab..50f8ff67a 100644 --- a/tools/src/main/java/com/nedap/archie/query/ArchieNamespaceResolver.java +++ b/tools/src/main/java/com/nedap/archie/query/ArchieNamespaceResolver.java @@ -11,6 +11,7 @@ */ class ArchieNamespaceResolver implements NamespaceContext { + public static final String OPENEHR_NS_PREFIX = "openehr"; private final Document document; public ArchieNamespaceResolver(Document document) { @@ -20,12 +21,17 @@ public ArchieNamespaceResolver(Document document) { public String getNamespaceURI(String prefix) { if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { return document.lookupNamespaceURI(null); + } else if(prefix.equals(OPENEHR_NS_PREFIX)) { + return "http://schemas.openehr.org/v1"; } else { return document.lookupNamespaceURI(prefix); } } public String getPrefix(String namespaceURI) { + if(namespaceURI.equalsIgnoreCase("http://schemas.openehr.org/v1")) { + return OPENEHR_NS_PREFIX; + } return document.lookupPrefix(namespaceURI); } diff --git a/tools/src/main/java/com/nedap/archie/query/RMQueryContext.java b/tools/src/main/java/com/nedap/archie/query/RMQueryContext.java index 939a9a1d3..bf04ce403 100644 --- a/tools/src/main/java/com/nedap/archie/query/RMQueryContext.java +++ b/tools/src/main/java/com/nedap/archie/query/RMQueryContext.java @@ -12,6 +12,7 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; +import javax.xml.namespace.NamespaceContext; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -21,7 +22,9 @@ import javax.xml.xpath.XPathFactory; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Objects; /** * It's done by converting the RM objects into an XML-DOM using JAXB's Binder. XPATH is then evaluated against the DOM. @@ -57,14 +60,14 @@ public RMQueryContext(ModelInfoLookup lookup, Object rootNode, JAXBContext jaxbC this.rootNode = rootNode; this.modelInfoLooup = lookup; this.binder = jaxbContext.createBinder(); - domForQueries = createBlankDOMDocument(true); + domForQueries = createBlankDOMDocument(false); binder.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //Marshall Query object to a blank DOM document. //Binder will maintains association between two views. binder.marshal( rootNode/*new JAXBElement(qname, Query.class, query)*/ , domForQueries); - firstXPathNode = domForQueries.getFirstChild().getNodeName(); + firstXPathNode = ArchieNamespaceResolver.OPENEHR_NS_PREFIX + ":" + domForQueries.getFirstChild().getNodeName(); //print to stdout // Marshaller marshaller = jaxbContext.createMarshaller(); @@ -100,8 +103,6 @@ public List findList(String query) throws XPathExpressionException { String convertedQuery = APathToXPathConverter.convertQueryToXPath(query, firstXPathNode); XPath xpath = xPathFactory.newXPath(); - - xpath.setNamespaceContext(new ArchieNamespaceResolver(domForQueries)); NodeList foundNodes = (NodeList) xpath.evaluate(convertedQuery, domForQueries, XPathConstants.NODESET); @@ -123,6 +124,9 @@ private T getJAXBNode(Node node) { //JAXB sometimes has trouble binding primitive values. Looks like a bug in Xerces //very annoying. Here's our workaround: lookup the parent node and manually get the correct attribute String nodeName = node.getNodeName(); +// if(nodeName.contains(":")) { +// nodeName = nodeName.substring(nodeName.indexOf(":")+1); +// } //the parent usually can be found easily Object parent = binder.getJAXBNode(node.getParentNode()); if(parent == null) { diff --git a/tools/src/main/java/com/nedap/archie/query/UniqueNodePathBuilder.java b/tools/src/main/java/com/nedap/archie/query/UniqueNodePathBuilder.java index 5bbfcc618..54a3f8fff 100644 --- a/tools/src/main/java/com/nedap/archie/query/UniqueNodePathBuilder.java +++ b/tools/src/main/java/com/nedap/archie/query/UniqueNodePathBuilder.java @@ -24,11 +24,18 @@ private static StringBuilder constructPathInner(Node node) { String archetypeNodeId = Optional.ofNullable(node.getAttributes().getNamedItem("archetype_node_id")) .map(Node::getNodeValue) .orElse(null); - String pathSegment = new PathSegment(node.getNodeName(), archetypeNodeId, findNodeIndex(node, parent)).toString(); + String pathSegment = new PathSegment(removeNameSpace(node.getNodeName()), archetypeNodeId, findNodeIndex(node, parent)).toString(); return constructPathInner(parent).append(pathSegment); } } + private static String removeNameSpace(String nodeName) { + if(nodeName.contains(":")) { + return nodeName.substring(nodeName.indexOf(":")+1); + } + return nodeName; + } + private static Integer findNodeIndex(Node node, Node parent) { Integer nodeIndex = null; int numberOfFoundNodes = 0; diff --git a/tools/src/test/java/com/nedap/archie/query/RMQueryContextTest.java b/tools/src/test/java/com/nedap/archie/query/RMQueryContextTest.java index 49d06eb22..2e4467b00 100644 --- a/tools/src/test/java/com/nedap/archie/query/RMQueryContextTest.java +++ b/tools/src/test/java/com/nedap/archie/query/RMQueryContextTest.java @@ -45,7 +45,7 @@ public void simpleTest() throws Exception { RMQueryContext queryContext = getQueryContext(); assertEquals(Lists.newArrayList(composition.getContext()), queryContext.findList("/context")); - DvText text = (DvText) queryContext.findList("/context/other_context/items[name/value = 'Qualification']/items[id5]/value").get(0); + DvText text = (DvText) queryContext.findList("/context/other_context/items[openehr:name/openehr:value = 'Qualification']/items[id5]/value").get(0); assertNotNull(text); } @@ -91,8 +91,10 @@ public void multipleItems() throws Exception { //and check that retrieving a sub-element also retrieves more than one element - List values = queryContext.findList("/context/other_context[id2]/items[id3]/items[id5]/value"); + List values = queryContext.findListWithPaths("/context/other_context[id2]/items[id3]/items[id5]/value"); assertEquals(2, values.size()); + assertEquals("/context/other_context[id2]/items[id3,1]/items[id5,2]/value", values.get(0).getPath()); + assertEquals("/context/other_context[id2]/items[id3,2]/items[id5,2]/value", values.get(1).getPath()); } @Test diff --git a/tools/src/test/java/com/nedap/archie/xml/JAXBAOMRoundTripTest.java b/tools/src/test/java/com/nedap/archie/xml/JAXBAOMRoundTripTest.java index 5658412a4..aada07bd4 100644 --- a/tools/src/test/java/com/nedap/archie/xml/JAXBAOMRoundTripTest.java +++ b/tools/src/test/java/com/nedap/archie/xml/JAXBAOMRoundTripTest.java @@ -95,6 +95,7 @@ public void operationalTemplate() throws Exception { Flattener flattener = new Flattener(repository, BuiltinReferenceModels.getAvailableModelInfoLookups()).createOperationalTemplate(true); Archetype operationalTemplate = flattener.flatten(bloodPressureComposition); + operationalTemplate.getOtherMetaData().put("test", "something"); String xml = marshal(operationalTemplate); System.out.println(xml); diff --git a/tools/src/test/java/com/nedap/archie/xml/JAXBAOMTest.java b/tools/src/test/java/com/nedap/archie/xml/JAXBAOMTest.java index 33ab158d7..edca75019 100644 --- a/tools/src/test/java/com/nedap/archie/xml/JAXBAOMTest.java +++ b/tools/src/test/java/com/nedap/archie/xml/JAXBAOMTest.java @@ -66,7 +66,7 @@ public void serializeCDuration() throws Exception { @Test public void parseCDuration() throws Exception { String xml = "\n" + - "\n" + + "\n" + " \n" + " \n" + " ISO_639-1\n" + diff --git a/tools/src/test/java/com/nedap/archie/xml/JAXBRMRoundTripTest.java b/tools/src/test/java/com/nedap/archie/xml/JAXBRMRoundTripTest.java index feb9184a5..6e7f0bf04 100644 --- a/tools/src/test/java/com/nedap/archie/xml/JAXBRMRoundTripTest.java +++ b/tools/src/test/java/com/nedap/archie/xml/JAXBRMRoundTripTest.java @@ -11,9 +11,11 @@ import com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime; import com.nedap.archie.rm.datavalues.quantity.datetime.DvTime; import com.nedap.archie.rminfo.ArchieRMInfoLookup; +import com.nedap.archie.rminfo.MetaModels; import com.nedap.archie.testutil.TestUtil; import org.junit.Before; import org.junit.Test; +import org.openehr.referencemodels.BuiltinReferenceModels; import javax.xml.bind.Marshaller; import java.io.StringReader; @@ -40,7 +42,7 @@ public class JAXBRMRoundTripTest { @Before public void setup() { testUtil = new TestUtil(); - parser = new ADLParser(new RMConstraintImposer()); + parser = new ADLParser(BuiltinReferenceModels.getMetaModels()); } @Test diff --git a/tools/src/test/java/com/nedap/archie/xml/JAXBRMTest.java b/tools/src/test/java/com/nedap/archie/xml/JAXBRMTest.java index 66dd2505f..25e14eb71 100644 --- a/tools/src/test/java/com/nedap/archie/xml/JAXBRMTest.java +++ b/tools/src/test/java/com/nedap/archie/xml/JAXBRMTest.java @@ -6,8 +6,10 @@ import org.junit.Test; import org.threeten.extra.PeriodDuration; +import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; import java.io.StringReader; import java.io.StringWriter; import java.time.Period; @@ -25,7 +27,8 @@ public void serializeDuration() throws Exception { StringWriter writer = new StringWriter(); Marshaller marshaller = JAXBUtil.getArchieJAXBContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(element, writer); + JAXBElement element1 = new JAXBElement<>(new QName("http://schemas.openehr.org/v1", "element"), Element.class, null, element); + marshaller.marshal(element1, writer); String xml = writer.toString(); assertTrue(xml, xml.contains("P10D")); } @@ -46,7 +49,7 @@ public void serializeNegativeDuration() throws Exception { @Test public void parseDuration() throws Exception { String xml = "\n" + - "\n" + + "\n" + " \n" + " duration\n" + " \n" + @@ -62,7 +65,7 @@ public void parseDuration() throws Exception { @Test public void parseNegativeDuration() throws Exception { String xml = "\n" + - "\n" + + "\n" + " \n" + " duration\n" + " \n" + @@ -78,7 +81,7 @@ public void parseNegativeDuration() throws Exception { @Test public void parseNegativePeriodDuration() throws Exception { String xml = "\n" + - "\n" + + "\n" + " \n" + " duration\n" + " \n" +