From e9c09c6ba06ebbd3df267055ef930e62743158c0 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sat, 9 May 2015 18:01:53 -0400 Subject: [PATCH] Encode meta element even if it only contains tags --- .../java/ca/uhn/fhir/parser/JsonParser.java | 2 +- .../java/ca/uhn/fhir/parser/XmlParser.java | 2 +- .../uhn/fhir/parser/XmlParserDstu2Test.java | 46 +++++++++++++++++++ src/changes/changes.xml | 5 ++ src/site/xdoc/index.xml | 22 ++++++++- 5 files changed, 74 insertions(+), 3 deletions(-) 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 1105e3b7214..a54af9b871f 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 @@ -718,7 +718,7 @@ public class JsonParser extends BaseParser implements IParser { versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource); } - if (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, profiles) == false) { + if (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, tags, profiles) == false) { theEventWriter.writeStartObject("meta"); writeOptionalTagWithTextNode(theEventWriter, "versionId", versionIdPart); writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", updated); 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 1e1a0af5684..20c0f4e443d 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 @@ -797,7 +797,7 @@ public class XmlParser extends BaseParser implements IParser { List securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS); List profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES); TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(resource); - if (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, profiles) == false) { + if (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, tags, profiles) == false) { theEventWriter.writeStartElement("meta"); writeOptionalTagWithValue(theEventWriter, "versionId", versionIdPart); if (updated != null) { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java index 44de103e24c..c7543ee36bc 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java @@ -958,6 +958,52 @@ public class XmlParserDstu2Test { assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1)); } + @Test + public void testEncodeAndParseMetaProfiles() { + Patient p = new Patient(); + p.addName().addFamily("FAMILY"); + + TagList tagList = new TagList(); + tagList.addTag("scheme1", "term1", "label1"); + tagList.addTag("scheme2", "term2", "label2"); + ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList); + + String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p); + ourLog.info(enc); + + //@formatter:off + assertThat(enc, stringContainsInOrder("", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "")); + //@formatter:on + + Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc); + List gotLabels = ResourceMetadataKeyEnum.PROFILES.get(parsed); + assertNull(gotLabels); + + tagList = ResourceMetadataKeyEnum.TAG_LIST.get(parsed); + assertEquals(2, tagList.size()); + + assertEquals(new Tag("scheme1", "term1", "label1"), tagList.get(0)); + assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1)); + } + @Test public void testDuration() { Encounter enc = new Encounter(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 54b89065e69..8ced5d3ef14 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -10,6 +10,11 @@ Add support for reference implementation structures. + + Parsers did not encode the resource meta element if the resource + had tags but no other meta elements. Thanks to Bill de Beaubien and + Claude Nanjo for finding this. + diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index cac658b0773..9661bece336 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -45,7 +45,27 @@
- +

+ May 8, 2015 - HAPI FHIR 1.0 Released - HAPI 1.0 has been released! As always, 1.0 brings lots of fixes and features, and also brings the DSTU2 model classes up to the May 2015 DSTU2 ballot candidate structure definitions. Upgrading is recommended. +

+

+ At the same time, I am uploading the first builds of HAPI FHIR 1.1-SNAPSHOT. In the next release cycle we are introducing support for the FHIR reference implementation structures. This is an exciting development because it marks the beginning of an effort to merge the two libraries. This will mean that RI users can take advantage of HAPI's powerful client and server frameworks, and HAPI users can take advantage of the RI's powerful validation tooling. +

+

+ I will note that 1.1 will bring a few minor API changes, so upgrading your application to this level may require a few tweaks. Specifically, a new interface (IBaseResource) has been introduced which acts as a superinterface for both HAPI's structures and the RI ones. +

+

+ The existing IResource (HAPI's resource interface) extends this new interface, as does an interface called IRefImplInterface which marks RI structures. Some methods in the parser and in the client which previously returned IResource (HAPI's resource interface) now return IBaseResource, so a cast to IResource may be required in some cases. If you are feeling adventurous and want to give these structures a spin, go for it! Feel free to post questions here. +

+

+ As always, you can see the complete list of what has + changed by consulting the changelog, and the + download page has information on where to get it. +

+

+ - James Agnew +

+

March 14, 2015 - HAPI FHIR 0.9 Released - HAPI 0.9 has now been released. This release is an important one. It brings a number of fixes and new features, and most importantly