Encode meta element even if it only contains tags

This commit is contained in:
jamesagnew 2015-05-09 18:01:53 -04:00
parent 2ce921f39b
commit e9c09c6ba0
5 changed files with 74 additions and 3 deletions

View File

@ -718,7 +718,7 @@ public class JsonParser extends BaseParser implements IParser {
versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource); 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"); theEventWriter.writeStartObject("meta");
writeOptionalTagWithTextNode(theEventWriter, "versionId", versionIdPart); writeOptionalTagWithTextNode(theEventWriter, "versionId", versionIdPart);
writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", updated); writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", updated);

View File

@ -797,7 +797,7 @@ public class XmlParser extends BaseParser implements IParser {
List<BaseCodingDt> securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS); List<BaseCodingDt> securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
List<IdDt> profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES); List<IdDt> profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(resource); 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"); theEventWriter.writeStartElement("meta");
writeOptionalTagWithValue(theEventWriter, "versionId", versionIdPart); writeOptionalTagWithValue(theEventWriter, "versionId", versionIdPart);
if (updated != null) { if (updated != null) {

View File

@ -958,6 +958,52 @@ public class XmlParserDstu2Test {
assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1)); 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("<Patient xmlns=\"http://hl7.org/fhir\">",
"<meta>",
"<meta>",
"<tag>",
"<system value=\"scheme1\"/>",
"<code value=\"term1\"/>",
"<display value=\"label1\"/>",
"</tag>",
"<tag>",
"<system value=\"scheme2\"/>",
"<code value=\"term2\"/>",
"<display value=\"label2\"/>",
"</tag>",
"</meta>",
"</meta>",
"<name>",
"<family value=\"FAMILY\"/>",
"</name>",
"</Patient>"));
//@formatter:on
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
List<IdDt> 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 @Test
public void testDuration() { public void testDuration() {
Encounter enc = new Encounter(); Encounter enc = new Encounter();

View File

@ -10,6 +10,11 @@
<action type="add"> <action type="add">
Add support for reference implementation structures. Add support for reference implementation structures.
</action> </action>
<action type="fix">
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.
</action>
</release> </release>
<release version="1.0" date="2015-May-8"> <release version="1.0" date="2015-May-8">
<action type="add"> <action type="add">

View File

@ -45,7 +45,27 @@
</section> </section>
<section name="Announcements"> <section name="Announcements">
<p>
<b>May 8, 2015 - HAPI FHIR 1.0 Released</b> - 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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
<p>
As always, you can see the complete list of what has
changed by consulting the <a href="./changes-report.html">changelog</a>, and the
<a href="./download.html">download page</a> has information on where to get it.
</p>
<p>
- <a href="mailto:jamesagnew@users.sourceforge.net">James Agnew</a>
</p>
<p> <p>
<b>March 14, 2015 - HAPI FHIR 0.9 Released</b> - HAPI 0.9 has now been released. This <b>March 14, 2015 - HAPI FHIR 0.9 Released</b> - 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 release is an important one. It brings a number of fixes and new features, and most importantly