diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index b7eb566db87..3bc62a0b181 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 1.0-SNAPSHOT + 0.1 ../pom.xml diff --git a/hapi-fhir-base/pom.xml.versionsBackup b/hapi-fhir-base/pom.xml.versionsBackup new file mode 100644 index 00000000000..b7eb566db87 --- /dev/null +++ b/hapi-fhir-base/pom.xml.versionsBackup @@ -0,0 +1,404 @@ + + 4.0.0 + + + ca.uhn.hapi.fhir + hapi-fhir + 1.0-SNAPSHOT + ../pom.xml + + + ca.uhn.hapi.fhir + hapi-fhir-base + jar + http://hl7api.sourceforge.net/hapi-fhir/ + + HAPI FHIR Base Library + + + + hl7api.sf.net + scp://shell.sourceforge.net/home/project-web/hl7api/htdocs/hapi-fhir + + + + + + + + + javax.json + javax.json-api + 1.0 + + + org.glassfish + javax.json + 1.0.4 + + + + + org.codehaus.woodstox + woodstox-core-asl + 4.2.0 + + + + + + org.thymeleaf + thymeleaf + 2.1.2.RELEASE + true + + + + + org.apache.commons + commons-lang3 + 3.2.1 + + + commons-codec + commons-codec + 1.9 + + + commons-io + commons-io + 2.4 + + + + + org.slf4j + slf4j-api + 1.7.6 + + + ch.qos.logback + logback-classic + 1.1.1 + true + + + + + org.apache.httpcomponents + httpclient + 4.3.3 + + + org.apache.httpcomponents + httpcore + 4.3.2 + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + + junit + junit + 4.11 + test + + + xmlunit + xmlunit + 1.5 + test + + + org.eclipse.jetty + jetty-servlets + 9.1.1.v20140108 + test + + + org.eclipse.jetty + jetty-servlet + 9.1.1.v20140108 + test + + + org.mockito + mockito-all + 1.9.5 + test + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + test + + + net.sf.json-lib + json-lib + 2.4 + jdk15-sources + test + + + + org.eclipse.jetty + jetty-server + 9.1.1.v20140108 + test + + + org.eclipse.jetty + jetty-servlet + 9.1.1.v20140108 + test + + + + commons-httpclient + commons-httpclient + 3.1 + test + + + + directory-naming + naming-java + 0.8 + test + + + org.hamcrest + hamcrest-all + ${hamcrest_version} + test + + + + + + + + + + maven-site-plugin + 3.3 + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.16 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + + default + + javadoc + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.4 + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + + project-team + issue-tracking + license + scm + + + + + + + + + UTF-8 + + + + + + maven-antrun-plugin + 1.7 + + + addSyntaxHighlighter + site + + run + + + + Adding Syntax Highlighter + + + ]]> + + var elements = document.getElementsByClassName("source"); + for (var i=0; i < elements.length; i++) { + var pres = elements[i].getElementsByTagName("pre"); + for (var j = 0; j < pres.length; j++) { + var pre = pres[j]; + if (pre.innerHTML.match(/\/\*/)) { + pre.className = 'brush: java'; + } else if (pre.innerHTML.match(/^\#/)) { + pre.className = 'brush: bash'; + } else if (pre.innerHTML.match(/\<\;\//)) { + pre.className = 'brush: xml'; + } else { + pre.className = 'brush: java'; + } + } + } + + SyntaxHighlighter.all(); + + + ]]> + + + + + + addAnalytics + post-site + + + Adding Google analytics in target/site for <body> + + + + + ]]> + + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-1395874-5', 'sourceforge.net'); + ga('send', 'pageview'); + + + + ]]> + + Adding Google analytics in target/site for <BODY> + + + ]]> + + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-1395874-5', 'sourceforge.net'); + ga('send', 'pageview'); + + + + ]]> + + Adding social plugins for HAPI + + + + +
+
+ + +

+ + +

+ + ]]>
+
+ + +
+
+ + run + +
+
+
+ + org.apache.maven.plugins + maven-javadoc-plugin + true + + 128m + 1g + true + false + false + + + + package + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + + + package + + jar-no-fork + + + + +
+
+ +
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index ad1aa63e758..7b3fb880d13 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -8,6 +8,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.apache.commons.lang3.text.WordUtils; + import ca.uhn.fhir.model.api.BaseResourceReference; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IDatatype; @@ -50,26 +52,26 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD @Override void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { Map> datatypeAttributeNameToDefinition=new HashMap>(); + myDatatypeToAttributeName = new HashMap, String>(); for (BaseRuntimeElementDefinition next : theClassToElementDefinitions.values()) { if (next instanceof IRuntimeDatatypeDefinition) { if (!((IRuntimeDatatypeDefinition) next).isSpecialization()) { - String attrName = "value" + next.getName().substring(0, 1).toUpperCase() + next.getName().substring(1); + String attrName = "value" + WordUtils.capitalize(next.getName()); datatypeAttributeNameToDefinition.put(attrName, next); datatypeAttributeNameToDefinition.put(attrName.toLowerCase(), next); + myDatatypeToAttributeName.put(next.getImplementingClass(), attrName); } } } myAttributeNameToDefinition=datatypeAttributeNameToDefinition; - myDatatypeToAttributeName = new HashMap, String>(); myDatatypeToDefinition = new HashMap, BaseRuntimeElementDefinition>(); for (Entry> next : myAttributeNameToDefinition.entrySet()) { @SuppressWarnings("unchecked") Class type = (Class) next.getValue().getImplementingClass(); - myDatatypeToAttributeName.put(type, next.getKey()); myDatatypeToDefinition.put(type, next.getValue()); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index b715898edd6..7681043e8ea 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -240,10 +240,13 @@ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger if (nextDef instanceof RuntimeResourceReferenceDefinition) { RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef; for (Class next : rr.getResourceTypes()) { - RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next); StructureElementDefinitionType type = elem.getDefinition().addType(); type.getCode().setValue("ResourceReference"); - type.getProfile().setValueAsString(resDef.getResourceProfile()); + + if (next != IResource.class) { + RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next); + type.getProfile().setValueAsString(resDef.getResourceProfile()); + } } return; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/DurationDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/DurationDt.java index a9e415401e3..ec66a16a3d3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/DurationDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/composite/DurationDt.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.model.dstu.composite; import ca.uhn.fhir.model.api.annotation.DatatypeDef; -@DatatypeDef(name = "duration") +@DatatypeDef(name = "Duration") public class DurationDt extends QuantityDt { // TODO: implement restricions diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java index ae4113e3d42..4a7de9a02ca 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.parser; -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.IOException; import java.io.Reader; @@ -29,10 +30,12 @@ import javax.json.stream.JsonGeneratorFactory; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.text.WordUtils; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; import ca.uhn.fhir.context.BaseRuntimeElementDefinition; +import ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeChildDeclaredExtensionDefinition; import ca.uhn.fhir.context.RuntimeChildNarrativeDefinition; @@ -307,6 +310,7 @@ public class JsonParser extends BaseParser implements IParser { } case OBJECT: { theState.enteringNewElement(null, theName); + parseAlternates(theAlternateVal, theState); JsonObject nextObject = (JsonObject) theJsonVal; boolean preResource = false; if (theState.isPreResource()) { @@ -421,6 +425,17 @@ public class JsonParser extends BaseParser implements IParser { } } + private void addToHeldExtensions(int valueIdx, ArrayList> list, RuntimeChildDeclaredExtensionDefinition theDef, IElement theValue) { + list.ensureCapacity(valueIdx); + while (list.size() <= valueIdx) { + list.add(null); + } + if (list.get(valueIdx) == null) { + list.set(valueIdx, new ArrayList()); + } + list.get(valueIdx).add(new HeldExtension(theDef, theValue)); + } + private void assertObjectOfType(JsonValue theResourceTypeObj, ValueType theValueType, String thePosition) { if (theResourceTypeObj.getValueType() != theValueType) { throw new DataFormatException("Invalid content of element " + thePosition + ", expected " + theValueType); @@ -582,22 +597,12 @@ public class JsonParser extends BaseParser implements IParser { } if (nextChild instanceof RuntimeChildDeclaredExtensionDefinition) { - - // TODO: hold and return RuntimeChildDeclaredExtensionDefinition extDef = (RuntimeChildDeclaredExtensionDefinition) nextChild; if (extDef.isModifier()) { - theEventWriter.writeStartObject("modifierExtension"); + addToHeldExtensions(valueIdx, modifierExtensions, extDef, nextValue); } else { - theEventWriter.writeStartObject("extension"); + addToHeldExtensions(valueIdx, extensions, extDef, nextValue); } - - String extensionUrl = nextChild.getExtensionUrl(); - theEventWriter.write("url", extensionUrl); - // theEventWriter.writeName(childName); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName); - - theEventWriter.writeEnd(); - } else { if (currentChildName == null || !currentChildName.equals(childName)) { @@ -634,49 +639,51 @@ public class JsonParser extends BaseParser implements IParser { } if (extensions.size() > 0 || modifierExtensions.size() > 0) { - theEventWriter.writeStartArray('_' + currentChildName); + // Ignore extensions if we're encoding a resource, since they are handled one level up + if (currentChildName != null) { + theEventWriter.writeStartArray('_' + currentChildName); - for (int i = 0; i < valueIdx; i++) { - boolean haveContent = false; - if (extensions.size() > i && extensions.get(i) != null && extensions.get(i).isEmpty() == false) { - haveContent = true; - theEventWriter.writeStartObject(); - theEventWriter.writeStartArray("extension"); - for (HeldExtension nextExt : extensions.get(i)) { - nextExt.write(theResDef, theResource, theEventWriter); + for (int i = 0; i < valueIdx; i++) { + boolean haveContent = false; + if (extensions.size() > i && extensions.get(i) != null && extensions.get(i).isEmpty() == false) { + haveContent = true; + theEventWriter.writeStartObject(); + theEventWriter.writeStartArray("extension"); + for (HeldExtension nextExt : extensions.get(i)) { + nextExt.write(theResDef, theResource, theEventWriter); + } + theEventWriter.writeEnd(); + theEventWriter.writeEnd(); + } + + if (!haveContent) { + // theEventWriter.writeEnd(); + theEventWriter.writeNull(); } - theEventWriter.writeEnd(); - theEventWriter.writeEnd(); } - if (!haveContent) { - // theEventWriter.writeEnd(); - theEventWriter.writeNull(); - } + // if (extensions.size() > 0) { + // + // theEventWriter.name(extType); + // theEventWriter.beginArray(); + // for (ArrayList next : extensions) { + // if (next == null || next.isEmpty()) { + // theEventWriter.nullValue(); + // } else { + // theEventWriter.beginArray(); + // // next.write(theEventWriter); + // theEventWriter.endArray(); + // } + // } + // for (int i = extensions.size(); i < valueIdx; i++) { + // theEventWriter.nullValue(); + // } + // theEventWriter.endArray(); + // } + + theEventWriter.writeEnd(); } - - // if (extensions.size() > 0) { - // - // theEventWriter.name(extType); - // theEventWriter.beginArray(); - // for (ArrayList next : extensions) { - // if (next == null || next.isEmpty()) { - // theEventWriter.nullValue(); - // } else { - // theEventWriter.beginArray(); - // // next.write(theEventWriter); - // theEventWriter.endArray(); - // } - // } - // for (int i = extensions.size(); i < valueIdx; i++) { - // theEventWriter.nullValue(); - // } - // theEventWriter.endArray(); - // } - - theEventWriter.writeEnd(); } - } } @@ -686,7 +693,6 @@ public class JsonParser extends BaseParser implements IParser { encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren()); } - private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull) throws IOException { super.containResourcesForEncoding(theResource); @@ -703,12 +709,79 @@ public class JsonParser extends BaseParser implements IParser { theEventWriter.write("id", theResource.getId().getValue()); } + extractAndWriteExtensionsAsDirectChild(theResource, theEventWriter, resDef, theResDef, theResource); + encodeCompositeElementToStreamWriter(theResDef, theResource, theResource, theEventWriter, resDef); theEventWriter.writeEnd(); } + /** + * This is useful only for the two cases where extensions are encoded as direct children (e.g. not in some object called _name): resource extensions, and extension extensions + */ + private void extractAndWriteExtensionsAsDirectChild(IElement theElement, JsonGenerator theEventWriter, BaseRuntimeElementDefinition theElementDef, RuntimeResourceDefinition theResDef, + IResource theResource) throws IOException { + List extensions = new ArrayList(0); + List modifierExtensions = new ArrayList(0); + // Undeclared extensions + extractUndeclaredExtensions(theElement, extensions, modifierExtensions); + + // Declared extensions + extractDeclaredExtensions(theElement, theElementDef, extensions, modifierExtensions); + + // Write the extensions + writeExtensionsAsDirectChild(theResource, theEventWriter, theResDef, extensions, modifierExtensions); + } + + private void writeExtensionsAsDirectChild(IResource theResource, JsonGenerator theEventWriter, RuntimeResourceDefinition resDef, List extensions, + List modifierExtensions) throws IOException { + if (extensions.isEmpty() == false) { + theEventWriter.writeStartArray("extension"); + for (HeldExtension next : extensions) { + next.write(resDef, theResource, theEventWriter); + } + theEventWriter.writeEnd(); + } + if (modifierExtensions.isEmpty() == false) { + theEventWriter.writeStartArray("modifierExtension"); + for (HeldExtension next : modifierExtensions) { + next.write(resDef, theResource, theEventWriter); + } + theEventWriter.writeEnd(); + } + } + + private void extractUndeclaredExtensions(IElement theResource, List extensions, List modifierExtensions) { + if (theResource instanceof ISupportsUndeclaredExtensions) { + List ext = ((ISupportsUndeclaredExtensions) theResource).getUndeclaredExtensions(); + for (ExtensionDt next : ext) { + extensions.add(new HeldExtension(next)); + } + + ext = ((ISupportsUndeclaredExtensions) theResource).getUndeclaredModifierExtensions(); + for (ExtensionDt next : ext) { + modifierExtensions.add(new HeldExtension(next)); + } + } + } + + private void extractDeclaredExtensions(IElement theResource, BaseRuntimeElementDefinition resDef, List extensions, List modifierExtensions) { + for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsNonModifier()) { + for (IElement nextValue : nextDef.getAccessor().getValues(theResource)) { + if (nextValue != null) { + extensions.add(new HeldExtension(nextDef, nextValue)); + } + } + } + for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsModifier()) { + for (IElement nextValue : nextDef.getAccessor().getValues(theResource)) { + if (nextValue != null) { + modifierExtensions.add(new HeldExtension(nextDef, nextValue)); + } + } + } + } private void writeAtomLink(JsonGenerator theEventWriter, String theRel, StringDt theLink) { if (isNotBlank(theLink.getValue())) { @@ -748,14 +821,38 @@ public class JsonParser extends BaseParser implements IParser { private class HeldExtension { private ExtensionDt myUndeclaredExtension; + private RuntimeChildDeclaredExtensionDefinition myDef; + private IElement myValue; public HeldExtension(ExtensionDt theUndeclaredExtension) { + assert theUndeclaredExtension != null; myUndeclaredExtension = theUndeclaredExtension; } + public HeldExtension(RuntimeChildDeclaredExtensionDefinition theDef, IElement theValue) { + assert theDef != null; + assert theValue != null; + myDef = theDef; + myValue = theValue; + } + public void write(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter) throws IOException { if (myUndeclaredExtension != null) { writeUndeclaredExt(theResDef, theResource, theEventWriter, myUndeclaredExtension); + } else { + theEventWriter.writeStartObject(); + theEventWriter.write("url", myDef.getExtensionUrl()); + + BaseRuntimeElementDefinition def = myDef.getChildElementDefinitionByDatatype(myValue.getClass()); + if (def.getChildType() == ChildTypeEnum.RESOURCE_BLOCK) { + extractAndWriteExtensionsAsDirectChild(myValue, theEventWriter, def, theResDef, theResource); + } else { + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, myValue, def, "value" + WordUtils.capitalize(def.getName())); + } + + // theEventWriter.name(myUndeclaredExtension.get); + + theEventWriter.writeEnd(); } } @@ -775,7 +872,7 @@ public class JsonParser extends BaseParser implements IParser { } else { BaseRuntimeElementDefinition def = myContext.getElementDefinition(value.getClass()); // theEventWriter.writeName("value" + def.getName()); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, value, def, "value" + def.getName()); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, value, def, "value" + WordUtils.capitalize(def.getName())); } // theEventWriter.name(myUndeclaredExtension.get); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java index 9a696ce26de..03995311889 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java @@ -183,7 +183,6 @@ public class XmlParser extends BaseParser implements IParser { return parseBundle(streamReader); } - @Override public T parseResource(Class theResourceType, Reader theReader) { XMLEventReader streamReader; @@ -277,7 +276,8 @@ public class XmlParser extends BaseParser implements IParser { } } - private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theEventWriter, IElement nextValue, String childName, BaseRuntimeElementDefinition childDef, String theExtensionUrl) throws XMLStreamException, DataFormatException { + private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theEventWriter, IElement nextValue, String childName, + BaseRuntimeElementDefinition childDef, String theExtensionUrl, boolean theIncludedResource) throws XMLStreamException, DataFormatException { if (nextValue.isEmpty()) { return; } @@ -289,7 +289,7 @@ public class XmlParser extends BaseParser implements IParser { if (value != null) { theEventWriter.writeStartElement(childName); theEventWriter.writeAttribute("value", value); - encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, nextValue); + encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, nextValue, theIncludedResource); theEventWriter.writeEndElement(); } break; @@ -301,7 +301,7 @@ public class XmlParser extends BaseParser implements IParser { theEventWriter.writeAttribute("url", theExtensionUrl); } BaseRuntimeElementCompositeDefinition childCompositeDef = (BaseRuntimeElementCompositeDefinition) childDef; - encodeCompositeElementToStreamWriter(theResDef, theResource, nextValue, theEventWriter, childCompositeDef); + encodeCompositeElementToStreamWriter(theResDef, theResource, nextValue, theEventWriter, childCompositeDef, theIncludedResource); theEventWriter.writeEndElement(); break; } @@ -341,22 +341,23 @@ public class XmlParser extends BaseParser implements IParser { } - private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, List children) throws XMLStreamException, DataFormatException { + private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, + List children, boolean theIncludedResource) throws XMLStreamException, DataFormatException { for (BaseRuntimeChildDefinition nextChild : children) { - if (nextChild instanceof RuntimeChildNarrativeDefinition) { + if (nextChild instanceof RuntimeChildNarrativeDefinition && !theIncludedResource) { INarrativeGenerator gen = myContext.getNarrativeGenerator(); if (gen != null) { NarrativeDt narr = gen.generateNarrative(theResDef.getResourceProfile(), theResource); - if (narr!=null) { + if (narr != null) { RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild; String childName = nextChild.getChildNameByDatatype(child.getDatatype()); BaseRuntimeElementDefinition type = child.getChildByName(childName); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, childName, type, null); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, childName, type, null, theIncludedResource); continue; } } } - + List values = nextChild.getAccessor().getValues(theElement); if (values == null || values.isEmpty()) { continue; @@ -383,27 +384,27 @@ public class XmlParser extends BaseParser implements IParser { } theEventWriter.writeAttribute("url", extensionUrl); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childName, childDef, null); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childName, childDef, null, theIncludedResource); theEventWriter.writeEndElement(); } else { - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childName, childDef, extensionUrl); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childName, childDef, extensionUrl, theIncludedResource); } } } } - - private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, BaseRuntimeElementCompositeDefinition resDef) throws XMLStreamException, DataFormatException { - encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, theElement); - encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getExtensions()); - encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren()); + private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, + BaseRuntimeElementCompositeDefinition resDef, boolean theIncludedResource) throws XMLStreamException, DataFormatException { + encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, theElement, theIncludedResource); + encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getExtensions(), theIncludedResource); + encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren(), theIncludedResource); } - private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, IElement theElement) throws XMLStreamException, DataFormatException { + private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, IElement theElement, boolean theIncludedResource) throws XMLStreamException, DataFormatException { if (theElement instanceof ISupportsUndeclaredExtensions) { ISupportsUndeclaredExtensions res = (ISupportsUndeclaredExtensions) theElement; - encodeUndeclaredExtensions(theResDef, theResource, theWriter, res.getUndeclaredExtensions(), "extension"); - encodeUndeclaredExtensions(theResDef, theResource, theWriter, res.getUndeclaredModifierExtensions(), "modifierExtension"); + encodeUndeclaredExtensions(theResDef, theResource, theWriter, res.getUndeclaredExtensions(), "extension", theIncludedResource); + encodeUndeclaredExtensions(theResDef, theResource, theWriter, res.getUndeclaredModifierExtensions(), "modifierExtension", theIncludedResource); } } @@ -414,7 +415,7 @@ public class XmlParser extends BaseParser implements IParser { reference = myContext.getResourceDefinition(theRef.getResourceType()).getName() + '/' + theRef.getResourceId(); } } - + if (!(theRef.getDisplay().isEmpty())) { theEventWriter.writeStartElement("display"); theEventWriter.writeAttribute("value", theRef.getDisplay().getValue()); @@ -427,7 +428,12 @@ public class XmlParser extends BaseParser implements IParser { } } - private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludeResourceId) throws XMLStreamException, DataFormatException { + /** + * @param theIncludedResource + * Set to true only if this resource is an "included" resource, as opposed to a "root level" resource by itself or in a bundle entry + * + */ + private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource) throws XMLStreamException, DataFormatException { super.containResourcesForEncoding(theResource); RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource); @@ -438,16 +444,17 @@ public class XmlParser extends BaseParser implements IParser { theEventWriter.writeStartElement(resDef.getName()); theEventWriter.writeDefaultNamespace(FHIR_NS); - if (theIncludeResourceId && StringUtils.isNotBlank(theResource.getId().getValue())) { + if (theIncludedResource && StringUtils.isNotBlank(theResource.getId().getValue())) { theEventWriter.writeAttribute("id", theResource.getId().getValue()); } - encodeCompositeElementToStreamWriter(resDef, theResource, theResource, theEventWriter, resDef); + encodeCompositeElementToStreamWriter(resDef, theResource, theResource, theEventWriter, resDef, theIncludedResource); theEventWriter.writeEndElement(); } - private void encodeUndeclaredExtensions(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, List extensions, String tagName) throws XMLStreamException, DataFormatException { + private void encodeUndeclaredExtensions(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, List extensions, String tagName, boolean theIncludedResource) + throws XMLStreamException, DataFormatException { for (ExtensionDt next : extensions) { theWriter.writeStartElement(tagName); theWriter.writeAttribute("url", next.getUrl().getValue()); @@ -460,11 +467,11 @@ public class XmlParser extends BaseParser implements IParser { throw new ConfigurationException("Unable to encode extension, unregognized child element type: " + nextValue.getClass().getCanonicalName()); } BaseRuntimeElementDefinition childDef = extDef.getChildElementDefinitionByDatatype(nextValue.getClass()); - encodeChildElementToStreamWriter(theResDef, theResource, theWriter, nextValue, childName, childDef, null); + encodeChildElementToStreamWriter(theResDef, theResource, theWriter, nextValue, childName, childDef, null, theIncludedResource); } // child extensions - encodeExtensionsIfPresent(theResDef, theResource, theWriter, next); + encodeExtensionsIfPresent(theResDef, theResource, theWriter, next, theIncludedResource); theWriter.writeEndElement(); } @@ -540,7 +547,7 @@ public class XmlParser extends BaseParser implements IParser { } else { theEventWriter.writeStartElement(se.getName().getPrefix(), se.getName().getLocalPart(), se.getName().getNamespaceURI()); } - for (Iterator attrIter = se.getAttributes(); attrIter.hasNext(); ) { + for (Iterator attrIter = se.getAttributes(); attrIter.hasNext();) { Attribute next = (Attribute) attrIter.next(); theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue()); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java index 30cc5eb9150..5b8129f06c6 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java @@ -107,7 +107,6 @@ public class JsonParserTest { public void testSimpleResourceEncode() throws IOException { FhirContext ctx = new FhirContext(Observation.class); - // String name = "/observation-example-eeg.xml"; String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); Patient obs = ctx.newXmlParser().parseResource(Patient.class, xmlString); @@ -117,7 +116,8 @@ public class JsonParserTest { ctx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out)); - String encoded = ctx.newJsonParser().encodeResourceToString(obs); + IParser jsonParser = ctx.newJsonParser(); + String encoded = jsonParser.encodeResourceToString(obs); ourLog.info(encoded); String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json")); @@ -125,10 +125,48 @@ public class JsonParserTest { JSON expected = JSONSerializer.toJSON(jsonString); JSON actual = JSONSerializer.toJSON(encoded.trim()); + ourLog.info("Expected: {}", expected); + ourLog.info("Actual : {}", actual); assertEquals(expected.toString(), actual.toString()); } + + + + @Test + public void testSimpleResourceEncodeWithCustomType() throws IOException { + + FhirContext ctx = new FhirContext(MyObservationWithExtensions.class); + String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); + MyObservationWithExtensions obs = ctx.newXmlParser().parseResource(MyObservationWithExtensions.class, xmlString); + + assertEquals(0, obs.getAllUndeclaredExtensions().size()); + assertEquals("aaaa", obs.getExtAtt().getContentType().getValue()); + assertEquals("str1", obs.getMoreExt().getStr1().getValue()); + assertEquals("2011-01-02", obs.getModExt().getValueAsString()); + + List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions(); + ExtensionDt undeclaredExtension = undeclaredExtensions.get(0); + assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl().getValue()); + + ctx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out)); + + IParser jsonParser = ctx.newJsonParser(); + String encoded = jsonParser.encodeResourceToString(obs); + ourLog.info(encoded); + + String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json")); + + JSON expected = JSONSerializer.toJSON(jsonString); + JSON actual = JSONSerializer.toJSON(encoded.trim()); + + ourLog.info("Expected: {}", expected); + ourLog.info("Actual : {}", actual); + assertEquals(expected.toString(), actual.toString()); + + } + @Test public void testSimpleBundleEncode() throws IOException { @@ -261,10 +299,8 @@ public class JsonParserTest { HumanNameDt given = name.addGiven("Joe"); ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#givenext", new StringDt("Hello")); given.addUndeclaredExtension(ext2); - String output = new FhirContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); - ourLog.info(output); - String enc = new FhirContext().newJsonParser().encodeResourceToString(patient); + ourLog.info(enc); //@formatter:off assertThat(enc, containsString(("{" + " \"resourceType\":\"Patient\"," + @@ -283,7 +319,7 @@ public class JsonParserTest { " \"extension\":[" + " {" + " \"url\":\"http://examples.com#givenext\"," + - " \"valuestring\":\"Hello\"" + + " \"valueString\":\"Hello\"" + " }" + " ]" + " }" + @@ -291,7 +327,12 @@ public class JsonParserTest { "}").replaceAll(" +", ""))); //@formatter:on - Patient parsed = new FhirContext().newJsonParser().parseResource(Patient.class, new StringReader(enc)); + IParser newJsonParser = new FhirContext().newJsonParser(); + StringReader reader = new StringReader(enc); + Patient parsed = newJsonParser.parseResource(Patient.class, reader); + + ourLog.info(new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed)); + assertEquals(1, parsed.getNameFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").size()); ExtensionDt ext = parsed.getNameFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").get(0); assertEquals("Hello", ext.getValueAsPrimitive().getValue()); @@ -309,10 +350,8 @@ public class JsonParserTest { ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#givenext", new StringDt("Hello")); family.addUndeclaredExtension(ext2); - String output = new FhirContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); - ourLog.info(output); - String enc = new FhirContext().newJsonParser().encodeResourceToString(patient); + ourLog.info(enc); //@formatter:off assertThat(enc, containsString(("{\n" + " \"resourceType\":\"Patient\",\n" + @@ -326,7 +365,7 @@ public class JsonParserTest { " \"extension\":[\n" + " {\n" + " \"url\":\"http://examples.com#givenext\",\n" + - " \"valuestring\":\"Hello\"\n" + + " \"valueString\":\"Hello\"\n" + " }\n" + " ]\n" + " }\n" + diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/MyObservationWithExtensions.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/MyObservationWithExtensions.java new file mode 100644 index 00000000000..21a0925f214 --- /dev/null +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/MyObservationWithExtensions.java @@ -0,0 +1,114 @@ +package ca.uhn.fhir.parser; + +import java.util.Collections; +import java.util.List; + +import ca.uhn.fhir.model.api.BaseElement; +import ca.uhn.fhir.model.api.IElement; +import ca.uhn.fhir.model.api.IResourceBlock; +import ca.uhn.fhir.model.api.annotation.Block; +import ca.uhn.fhir.model.api.annotation.Child; +import ca.uhn.fhir.model.api.annotation.Extension; +import ca.uhn.fhir.model.api.annotation.ResourceDef; +import ca.uhn.fhir.model.dstu.composite.AttachmentDt; +import ca.uhn.fhir.model.dstu.resource.Patient; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.util.ElementUtil; + +@ResourceDef(name="Patient") +public class MyObservationWithExtensions extends Patient { + + @Extension(url = "urn:patientext:att", definedLocally = false, isModifier = false) + @Child(name = "extAtt", order = 0) + private AttachmentDt myExtAtt; + + @Extension(url = "urn:patientext:moreext", definedLocally = false, isModifier = false) + @Child(name = "moreExt", order = 1) + private MoreExt myMoreExt; + + @Extension(url = "urn:modext", definedLocally = false, isModifier = true) + @Child(name = "modExt", order = 2) + private DateDt myModExt; + + public AttachmentDt getExtAtt() { + return myExtAtt; + } + + public MoreExt getMoreExt() { + return myMoreExt; + } + + public void setMoreExt(MoreExt theMoreExt) { + myMoreExt = theMoreExt; + } + + public DateDt getModExt() { + return myModExt; + } + + public void setModExt(DateDt theModExt) { + myModExt = theModExt; + } + + public void setExtAtt(AttachmentDt theExtAtt) { + myExtAtt = theExtAtt; + } + + @Override + public boolean isEmpty() { + return super.isEmpty() && ElementUtil.isEmpty(myExtAtt, myModExt, myMoreExt); + } + + /** + * Block class for child element: Observation.referenceRange (Provides guide for interpretation) + * + *

+ * Definition: Guidance on how to interpret the value by comparison to a normal or recommended range + *

+ */ + @Block(name = "Observation.someExtensions") + public static class MoreExt extends BaseElement implements IResourceBlock { + + @Extension(url = "urn:patientext:moreext:1", definedLocally = false, isModifier = false) + @Child(name = "str1", order = 0) + private StringDt myStr1; + + @Extension(url = "urn:patientext:moreext:2", definedLocally = false, isModifier = false) + @Child(name = "str2", order = 1) + private StringDt myStr2; + + public StringDt getStr1() { + return myStr1; + } + + public void setStr1(StringDt theStr1) { + myStr1 = theStr1; + } + + public StringDt getStr2() { + return myStr2; + } + + public void setStr2(StringDt theStr2) { + myStr2 = theStr2; + } + + @Override + public List getAllPopulatedChildElements() { + return Collections.emptyList(); + } + + @Override + public List getAllPopulatedChildElementsOfType(Class theType) { + return Collections.emptyList(); + } + + @Override + public boolean isEmpty() { + return ElementUtil.isEmpty(myStr1, myStr2); + } + + } + +} diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index beb398ac55c..8c8203133cb 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -6,7 +6,13 @@ import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.StringReader; +import java.nio.charset.Charset; +import java.util.List; + +import net.sf.json.JSON; +import net.sf.json.JSONSerializer; import org.apache.commons.io.IOUtils; import org.custommonkey.xmlunit.Diff; @@ -581,4 +587,74 @@ public class XmlParserTest { assertEquals("Hello", ext.getValueAsPrimitive().getValue()); } + + + + + + @Test + public void testSimpleResourceEncode() throws IOException, SAXException { + + FhirContext ctx = new FhirContext(Observation.class); + String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8")); + Patient obs = ctx.newJsonParser().parseResource(Patient.class, xmlString); + + List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions(); + ExtensionDt undeclaredExtension = undeclaredExtensions.get(0); + assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl().getValue()); + + ctx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out)); + + IParser jsonParser = ctx.newXmlParser(); + String encoded = jsonParser.encodeResourceToString(obs); + ourLog.info(encoded); + + String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml")); + + String expected = (jsonString); + String actual = (encoded.trim()); + + Diff d = new Diff(new StringReader(expected), new StringReader(actual)); + assertTrue(d.toString(), d.identical()); + + + } + + + + + @Test + public void testSimpleResourceEncodeWithCustomType() throws IOException, SAXException { + + FhirContext ctx = new FhirContext(MyObservationWithExtensions.class); + String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8")); + MyObservationWithExtensions obs = ctx.newJsonParser().parseResource(MyObservationWithExtensions.class, xmlString); + + assertEquals(0, obs.getAllUndeclaredExtensions().size()); + assertEquals("aaaa", obs.getExtAtt().getContentType().getValue()); + assertEquals("str1", obs.getMoreExt().getStr1().getValue()); + assertEquals("2011-01-02", obs.getModExt().getValueAsString()); + + List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions(); + ExtensionDt undeclaredExtension = undeclaredExtensions.get(0); + assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl().getValue()); + + ctx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out)); + + IParser jsonParser = ctx.newXmlParser(); + String encoded = jsonParser.encodeResourceToString(obs); + ourLog.info(encoded); + + String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml")); + + String expected = (jsonString); + String actual = (encoded.trim()); + + Diff d = new Diff(new StringReader(expected), new StringReader(actual)); + assertTrue(d.toString(), d.identical()); + + + + } + } diff --git a/hapi-fhir-base/src/test/resources/example-patient-general.json b/hapi-fhir-base/src/test/resources/example-patient-general.json index 0ca689ceabe..4678e29a85d 100644 --- a/hapi-fhir-base/src/test/resources/example-patient-general.json +++ b/hapi-fhir-base/src/test/resources/example-patient-general.json @@ -13,11 +13,11 @@ "extension":[ { "url":"urn:patientext:moreext:1", - "valuestring":"str1" + "valueString":"str1" }, { "url":"urn:patientext:moreext:2", - "valuestring":"str2" + "valueString":"str2" } ] } @@ -25,7 +25,7 @@ "modifierExtension":[ { "url":"urn:modext", - "valuedate":"2011-01-02" + "valueDate":"2011-01-02" } ], "text":{ @@ -124,7 +124,7 @@ "extension":[ { "url":"http://hl7.org/fhir/Profile/iso-21090#qualifier", - "valuecode":"VV" + "valueCode":"VV" } ] }, diff --git a/hapi-fhir-base/src/test/resources/example-patient-general.xml b/hapi-fhir-base/src/test/resources/example-patient-general.xml index 28f49ab3b0d..84018bed288 100644 --- a/hapi-fhir-base/src/test/resources/example-patient-general.xml +++ b/hapi-fhir-base/src/test/resources/example-patient-general.xml @@ -1,4 +1,5 @@ - + + diff --git a/hapi-fhir-structures-dstu/pom.xml b/hapi-fhir-structures-dstu/pom.xml index 83237387346..81788c3073b 100644 --- a/hapi-fhir-structures-dstu/pom.xml +++ b/hapi-fhir-structures-dstu/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 1.0-SNAPSHOT + 0.1 ../pom.xml @@ -19,7 +19,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 1.0-SNAPSHOT + 0.1 @@ -28,7 +28,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 1.0-SNAPSHOT + 0.1 @@ -39,30 +39,84 @@ ca.uhn.fhir.model.dstu + + adversereaction alert + allergyintolerance + appointmentresponse + appointment + availability + careplan + claim + composition + conceptmap + condition conformance + coverage + deviceobservationreport device diagnosticorder diagnosticreport + documentmanifest + documentreference encounter + + familyhistory + geneexpression + geneticanalysis group + gvfmeta + gvfvariant imagingstudy + immunizationrecommendation + immunization + list location media + medicationadministration + medicationdispense + medicationprescription medication + medicationstatement + messageheader + microarray + observation operationoutcome + orderresponse + order organization + other patient + person practitioner + procedure profile + protocol + + provenance query + questionnaire relatedperson + remittance + resource + securityevent + sequence + sequencinganalysis + sequencinglab + slot specimen substance + supply + template + test + user + valueset + vcfmeta + vcfvariant true diff --git a/hapi-tinder-plugin/.classpath b/hapi-tinder-plugin/.classpath index c967e1bd5c7..7bbf0de5900 100644 --- a/hapi-tinder-plugin/.classpath +++ b/hapi-tinder-plugin/.classpath @@ -1,7 +1,6 @@ - diff --git a/hapi-tinder-plugin/pom.xml b/hapi-tinder-plugin/pom.xml index 7d7fc85086d..781e5c5c1cb 100644 --- a/hapi-tinder-plugin/pom.xml +++ b/hapi-tinder-plugin/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 1.0-SNAPSHOT + 0.1 ../pom.xml @@ -20,7 +20,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 1.0-SNAPSHOT + 0.1 diff --git a/hapi-tinder-plugin/pom.xml.versionsBackup b/hapi-tinder-plugin/pom.xml.versionsBackup new file mode 100644 index 00000000000..7d7fc85086d --- /dev/null +++ b/hapi-tinder-plugin/pom.xml.versionsBackup @@ -0,0 +1,145 @@ + + 4.0.0 + + + ca.uhn.hapi.fhir + hapi-fhir + 1.0-SNAPSHOT + ../pom.xml + + + ca.uhn.hapi.fhir + hapi-tinder-plugin + maven-plugin + + + HAPI Tinder Plugin + + + + ca.uhn.hapi.fhir + hapi-fhir-base + 1.0-SNAPSHOT + + + + org.apache.velocity + velocity + 1.7 + + + org.apache.velocity + velocity-tools + 2.0 + + + + + + org.apache.commons + commons-lang3 + 3.2.1 + + + commons-io + commons-io + 2.4 + + + + + org.slf4j + slf4j-api + 1.7.6 + + + ch.qos.logback + logback-classic + 1.1.1 + true + + + + + junit + junit + 4.11 + test + + + org.apache.commons + commons-io + 1.3.2 + test + + + + + org.apache.maven + maven-project + 2.2.1 + + + org.apache.maven + maven-plugin-api + 3.2.1 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.2 + provided + + + + + 3.1.1 + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + + + + report + + + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + + + true + + + + + mojo-descriptor + + descriptor + + + + + + + + + + diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureParser.java index d190e846a98..172a90a715f 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureParser.java @@ -27,8 +27,8 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ExtensionDt; +import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.SimpleSetter; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; import ca.uhn.fhir.tinder.model.BaseElement; @@ -160,7 +160,7 @@ public abstract class BaseStructureParser { Class.forName(type); return (type); } catch (ClassNotFoundException e4) { - throw new MojoFailureException("Unknown type: " + theNextType); + throw new MojoFailureException("Unknown type: " + theNextType + " - Have locally defined names: " + new TreeSet(myLocallyDefinedClassNames.keySet())); } } } diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureSpreadsheetParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureSpreadsheetParser.java index a9ef102a75c..5b0b5a9eb0c 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureSpreadsheetParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/BaseStructureSpreadsheetParser.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.tinder; import java.io.InputStream; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -12,8 +13,8 @@ import org.w3c.dom.NodeList; import ca.uhn.fhir.tinder.model.AnyChild; import ca.uhn.fhir.tinder.model.BaseElement; -import ca.uhn.fhir.tinder.model.Child; import ca.uhn.fhir.tinder.model.BaseRootType; +import ca.uhn.fhir.tinder.model.Child; import ca.uhn.fhir.tinder.model.ResourceBlock; import ca.uhn.fhir.tinder.model.ResourceBlockCopy; import ca.uhn.fhir.tinder.model.SearchParameter; @@ -32,10 +33,18 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser private int myColV2Mapping; public void parse() throws Exception { - + int index = 0; for (InputStream nextInputStream : getInputStreams()) { - Document file = XMLUtils.parse(nextInputStream, false); + ourLog.info("Reading spreadsheet file {}", getInputStreamNames().get(index)); + + Document file; + try { + file = XMLUtils.parse(nextInputStream, false); + } catch (Exception e) { + throw new Exception("Failed during reading: " + getInputStreamNames().get(index), e); + } + Element dataElementsSheet = (Element) file.getElementsByTagName("Worksheet").item(0); NodeList tableList = dataElementsSheet.getElementsByTagName("Table"); Element table = (Element) tableList.item(0); @@ -55,11 +64,11 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser parseBasicElements(resourceRow, resource); resource.setId(resource.getName().toLowerCase()); - + if (this instanceof ResourceGeneratorUsingSpreadsheet) { resource.setProfile("http://hl7.org/fhir/profiles/" + resource.getElementName()); } - + Map elements = new HashMap(); elements.put(resource.getElementName(), resource); @@ -105,6 +114,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser } + index++; } ourLog.info("Parsed {} spreadsheet structures", getResources().size()); @@ -166,6 +176,8 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser protected abstract Collection getInputStreams(); + protected abstract List getInputStreamNames(); + private void parseFirstRow(Element theDefRow) { for (int i = 0; i < 20; i++) { String nextName = cellValue(theDefRow, i); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/DatatypeGeneratorUsingSpreadsheet.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/DatatypeGeneratorUsingSpreadsheet.java index f5ab687eb01..ff93e06f243 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/DatatypeGeneratorUsingSpreadsheet.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/DatatypeGeneratorUsingSpreadsheet.java @@ -1,6 +1,5 @@ package ca.uhn.fhir.tinder; -import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; @@ -25,23 +24,10 @@ public class DatatypeGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP protected Collection getInputStreams() { ArrayList retVal = new ArrayList(); - retVal.add(getClass().getResourceAsStream("/dt/address.xml")); - retVal.add(getClass().getResourceAsStream("/dt/coding.xml")); - retVal.add(getClass().getResourceAsStream("/dt/humanname.xml")); - retVal.add(getClass().getResourceAsStream("/dt/period.xml")); - retVal.add(getClass().getResourceAsStream("/dt/ratio.xml")); - retVal.add(getClass().getResourceAsStream("/dt/schedule.xml")); - retVal.add(getClass().getResourceAsStream("/dt/attachment.xml")); - retVal.add(getClass().getResourceAsStream("/dt/contact.xml")); - retVal.add(getClass().getResourceAsStream("/dt/identifier.xml")); - retVal.add(getClass().getResourceAsStream("/dt/quantity.xml")); - retVal.add(getClass().getResourceAsStream("/dt/resourcereference.xml")); - retVal.add(getClass().getResourceAsStream("/dt/codeableconcept.xml")); -// retVal.add(getClass().getResourceAsStream("/dt/extension.xml")); -// retVal.add(getClass().getResourceAsStream("/dt/narrative.xml")); - retVal.add(getClass().getResourceAsStream("/dt/range.xml")); - retVal.add(getClass().getResourceAsStream("/dt/sampleddata.xml")); - + for (String next : getInputStreamNames()) { + retVal.add(getClass().getResourceAsStream(next)); + } + return retVal; } @@ -50,5 +36,29 @@ public class DatatypeGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP return new Composite(); } + @Override + protected List getInputStreamNames() { + ArrayList retVal = new ArrayList(); + + retVal.add(("/dt/address.xml")); + retVal.add(("/dt/coding.xml")); + retVal.add(("/dt/humanname.xml")); + retVal.add(("/dt/period.xml")); + retVal.add(("/dt/ratio.xml")); + retVal.add(("/dt/schedule.xml")); + retVal.add(("/dt/attachment.xml")); + retVal.add(("/dt/contact.xml")); + retVal.add(("/dt/identifier.xml")); + retVal.add(("/dt/quantity.xml")); + retVal.add(("/dt/resourcereference.xml")); + retVal.add(("/dt/codeableconcept.xml")); +// retVal.add(("/dt/extension.xml")); +// retVal.add(("/dt/narrative.xml")); + retVal.add(("/dt/range.xml")); + retVal.add(("/dt/sampleddata.xml")); + + return retVal; + } + } diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ProfileParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ProfileParser.java index 1c167e0bfa4..af62e2b63a0 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ProfileParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ProfileParser.java @@ -4,7 +4,6 @@ import static org.apache.commons.lang.StringUtils.capitalize; import static org.apache.commons.lang.StringUtils.isBlank; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ResourceGeneratorUsingSpreadsheet.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ResourceGeneratorUsingSpreadsheet.java index 69f3ec3d2b3..75e67d46993 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ResourceGeneratorUsingSpreadsheet.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ResourceGeneratorUsingSpreadsheet.java @@ -18,6 +18,7 @@ public class ResourceGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP private ArrayList myInputStreams; + private List myInputStreamNames; @Override protected String getTemplate() { @@ -143,6 +144,7 @@ public class ResourceGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP } public void setBaseResourceNames(List theBaseResourceNames) throws MojoFailureException { + myInputStreamNames = theBaseResourceNames; myInputStreams = new ArrayList(); for (String next : theBaseResourceNames) { @@ -154,6 +156,10 @@ public class ResourceGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP } } + public List getInputStreamNames() { + return myInputStreamNames; + } + @Override protected BaseRootType createRootType() { return new Resource(); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java index ffa7bc0a084..8133562bbd7 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java @@ -1,7 +1,6 @@ package ca.uhn.fhir.tinder; import java.io.File; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/BaseElement.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/BaseElement.java index 01f48625838..18f3fc37061 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/BaseElement.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/BaseElement.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.tinder.model; -import static org.apache.commons.lang.StringUtils.*; +import static org.apache.commons.lang.StringUtils.isNotBlank; import java.util.ArrayList; import java.util.Collections; @@ -237,8 +237,11 @@ public abstract class BaseElement { String[] types = typeString.replace("=", "").split("\\|"); for (String nextType : types) { nextType = nextType.trim(); + if (nextType.endsWith(")")){ + nextType = nextType.substring(0, nextType.length()-1); + } if (nextType.toLowerCase().startsWith("resource(")) { - nextType = nextType.substring("Resource(".length(), nextType.length() - 1); + nextType = nextType.substring("Resource(".length(), nextType.length()); nextType = nextType.substring(0, 1).toUpperCase() + nextType.substring(1); } else { nextType = nextType.substring(0, 1).toUpperCase() + nextType.substring(1); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ValueSetTm.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ValueSetTm.java index 4daab67fcf5..fc6bc95e8d4 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ValueSetTm.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ValueSetTm.java @@ -2,11 +2,8 @@ package ca.uhn.fhir.tinder.model; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import org.codehaus.plexus.util.StringUtils; diff --git a/hapi-tinder-plugin/src/main/resources/res/activitydefinition-extensions-spreadsheet.xml b/hapi-tinder-plugin/src/main/resources/res/activitydefinition-extensions-spreadsheet.xml new file mode 100644 index 00000000000..5118153e5ea --- /dev/null +++ b/hapi-tinder-plugin/src/main/resources/res/activitydefinition-extensions-spreadsheet.xml @@ -0,0 +1,430 @@ + + + + + Grahame + Lloyd McKenzie + 2012-03-19T11:17:14Z + 2013-04-19T20:47:52Z + 14.00 + + + + + + 6090 + 15570 + 6225 + 1365 + 2 + False + False + + + + + + + + + + + + + + + + + + + + + + + + Name + Value + + + id + + + + name + ActivityDefinition HL7 Extensions + + + author.name + HL7 + + + author.reference + + + + code + + + description + Defines common extensions used with or related to the ActivityDefinition shared definition + + + status + draft + + + date + + + + profile + + + + resource + + + binding + + + version + 0.01 + + + extension.uri + http://hl7.org/fhir/extensions/ActivityDefinition + +
+ + +
+