Fix #484 - Correctly parse resources containing an empty div tag as the narrative

This commit is contained in:
James 2016-11-03 07:51:11 -04:00
parent e7e0bf8d54
commit 3a5a771de7
6 changed files with 999 additions and 841 deletions

View File

@ -162,10 +162,13 @@ public class XhtmlDt extends BasePrimitive<List<XMLEvent>> {
int firstTagIndex = value.indexOf("<", hasProcessingInstruction ? 1 : 0);
if (firstTagIndex != -1) {
int firstTagEnd = value.indexOf(">", firstTagIndex);
int firstSlash = value.indexOf("/", firstTagIndex);
if (firstTagEnd != -1) {
String firstTag = value.substring(firstTagIndex, firstTagEnd);
if (!firstTag.contains(" xmlns")) {
value = value.substring(0, firstTagEnd) + DECL_XMLNS + value.substring(firstTagEnd);
if (firstSlash > firstTagEnd) {
String firstTag = value.substring(firstTagIndex, firstTagEnd);
if (!firstTag.contains(" xmlns")) {
value = value.substring(0, firstTagEnd) + DECL_XMLNS + value.substring(firstTagEnd);
}
}
}
}

View File

@ -51,6 +51,7 @@ import org.junit.Test;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.BundleEntry;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
@ -114,6 +115,23 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertEquals(200, resp.getStatusLine().getStatusCode());
}
/**
* See #484
*/
@Test
public void saveAndRetrieveBasicResource() throws IOException {
String input = IOUtils.toString(getClass().getResourceAsStream("/basic-stu3.xml"), StandardCharsets.UTF_8);
String respString = ourClient.transaction().withBundle(input).prettyPrint().execute();
ourLog.info(respString);
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = myFhirCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, respString);
IdDt id = new IdDt(bundle.getEntry().get(0).getResponse().getLocation());
Basic basic = ourClient.read().resource(Basic.class).withId(id).execute();
List<ExtensionDt> exts = basic.getUndeclaredExtensionsByUrl("http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/DateID");
assertEquals(1, exts.size());
}
/**
* See #438
*/

View File

@ -0,0 +1,59 @@
<Bundle>
<meta>
<lastUpdated value="2016-10-28T16:29:43Z" />
</meta>
<type value="transaction" />
<entry>
<resource>
<Basic>
<text>
<status value="generated" />
<div />
</text>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/DateID">
<valueDate value="2016-11-01" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/SptSolution">
<valueCoding value="SptSolution.CatFurSPTSoln" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/MethodOfFollowUp">
<valueCoding value="FollowUpMethod.ClinicVisit" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/SPTDefinition">
<valueString value="A positive skin prick test result was defined as a mean wheal diameter of 3mm greater than that of the negative control" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/SubjectNo">
<valueString value="4320" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/AIW">
<valueInteger value="58" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/FollowUp">
<valueCoding value="FollowUp.MSAge1Y" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/Subject">
<valueCoding value="Person.StudySubject" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/VariableLabel">
<valueString value="Child sensitised to cat (age 1 spt)" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/SPTDataType">
<valueCoding value="SkinPrickTestData.SPTResult" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/DataSource">
<valueCoding value="DataSource.ClinicalMeasurement" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/ClinicalType">
<valueCoding value="ClinicalMeasurement.SkinPrickTest" />
</extension>
<extension url="http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/DataSPTResult">
<valueCoding value="TestResult.Negative" />
</extension>
</Basic>
</resource>
<request>
<method value="POST" />
<url value="Basic" />
</request>
</entry>
</Bundle>

View File

@ -48,6 +48,7 @@ import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Basic;
import ca.uhn.fhir.model.dstu2.resource.Binary;
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
import ca.uhn.fhir.model.dstu2.resource.Condition;
@ -125,7 +126,6 @@ public class JsonParserDstu2Test {
assertEquals(true, obs.getReadOnly().getValue().booleanValue());
}
/**
* See #390
*/
@ -144,6 +144,7 @@ public class JsonParserDstu2Test {
assertEquals(0, b.getEntry().size());
}
@Test
public void testEncodeAndParseExtensions() throws Exception {
@ -301,7 +302,7 @@ public class JsonParserDstu2Test {
assertEquals(new Tag("scheme1", "term1", "label1"), tagList.get(0));
assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1));
}
/**
* See #336
*/
@ -359,7 +360,6 @@ public class JsonParserDstu2Test {
}
@Test
public void testEncodeAndParseSecurityLabels() {
Patient p = new Patient();
@ -424,7 +424,7 @@ public class JsonParserDstu2Test {
assertEquals("VERSION2", label.getVersion());
}
@Test
public void testEncodeBundleNewBundleNoText() {
@ -446,7 +446,7 @@ public class JsonParserDstu2Test {
}
@Test
public void testEncodeBundleOldBundleNoText() {
@ -465,6 +465,7 @@ public class JsonParserDstu2Test {
assertEquals(1, b.getEntries().size());
}
/**
* Fixing #89
@ -494,7 +495,7 @@ public class JsonParserDstu2Test {
String actual = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
assertThat(actual, not(containsString("78ef6f64c2f2")));
}
@Test
public void testEncodeEmptyBinary() {
String output = ourCtx.newJsonParser().encodeResourceToString(new Binary());
@ -564,7 +565,6 @@ public class JsonParserDstu2Test {
}
@Test
public void testEncodeExtensionUndeclaredNonModifier() {
Observation obs = new Observation();
@ -602,7 +602,7 @@ public class JsonParserDstu2Test {
assertEquals("ext_url_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getValue()).getValue());
}
@Test
public void testEncodeExtensionUndeclaredNonModifierWithChildExtension() {
Observation obs = new Observation();
@ -647,6 +647,7 @@ public class JsonParserDstu2Test {
assertEquals("sub_ext_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getExtension().get(0).getValue()).getValue());
}
/**
* See #428
*/
@ -1490,6 +1491,16 @@ public class JsonParserDstu2Test {
}
/**
* See #484
*/
@Test
public void testParseNarrativeWithEmptyDiv() {
String input = "{\"resourceType\":\"Basic\",\"id\":\"1\",\"text\":{\"status\":\"generated\",\"div\":\"<div/>\"}}";
Basic basic = ourCtx.newJsonParser().parseResource(Basic.class, input);
assertEquals("<div/>", basic.getText().getDivAsString());
}
/**
* See #359 - This is the base test with no nulls, other testParseNullsFOO have nulls in them
*/

View File

@ -16,24 +16,65 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Address.AddressUse;
import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory;
import org.hl7.fhir.dstu3.model.Attachment;
import org.hl7.fhir.dstu3.model.AuditEvent;
import org.hl7.fhir.dstu3.model.Basic;
import org.hl7.fhir.dstu3.model.Binary;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Communication;
import org.hl7.fhir.dstu3.model.Condition;
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
import org.hl7.fhir.dstu3.model.Conformance;
import org.hl7.fhir.dstu3.model.Conformance.UnknownContentCode;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.DiagnosticReport;
import org.hl7.fhir.dstu3.model.EnumFactory;
import org.hl7.fhir.dstu3.model.Enumeration;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.ExplanationOfBenefit;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.HumanName;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu3.model.Linkage;
import org.hl7.fhir.dstu3.model.Medication;
import org.hl7.fhir.dstu3.model.MedicationOrder;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.PrimitiveType;
import org.hl7.fhir.dstu3.model.Quantity;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.RelatedPerson;
import org.hl7.fhir.dstu3.model.SampledData;
import org.hl7.fhir.dstu3.model.SimpleQuantity;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.collect.Sets;
@ -58,7 +99,7 @@ public class JsonParserDstu3Test {
ourCtx.setNarrativeGenerator(null);
}
@Test
public void testEncodeAndParseExtensions() throws Exception {
@ -224,7 +265,7 @@ public class JsonParserDstu3Test {
assertEquals("sec_label2", tagList.get(1).getDisplay());
}
/**
* See #336
*/
@ -278,7 +319,8 @@ public class JsonParserDstu3Test {
assertEquals(null, name.getFamily().get(2).getExtension().get(0).getId());
}
@Test
public void testEncodeAndParseSecurityLabels() {
Patient p = new Patient();
@ -338,8 +380,6 @@ public class JsonParserDstu3Test {
assertEquals("DISPLAY2", label.getDisplay());
assertEquals("VERSION2", label.getVersion());
}
@Test
public void testEncodeBundleNewBundleNoText() {
@ -359,6 +399,8 @@ public class JsonParserDstu3Test {
}
/**
* See #326
*/
@ -394,7 +436,7 @@ public class JsonParserDstu3Test {
));
//@formatter:on
}
@Test
public void testEncodeDoesntIncludeUuidId() {
Patient p = new Patient();
@ -404,14 +446,13 @@ public class JsonParserDstu3Test {
String actual = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
assertThat(actual, not(containsString("78ef6f64c2f2")));
}
@Test
public void testEncodeEmptyBinary() {
String output = ourCtx.newJsonParser().encodeResourceToString(new Binary());
assertEquals("{\"resourceType\":\"Binary\"}", output);
}
/**
* #158
*/
@ -427,7 +468,8 @@ public class JsonParserDstu3Test {
String encoded = ourCtx.newJsonParser().encodeResourceToString(p);
assertThat(encoded, not(containsString("tag")));
}
/**
* #158
*/
@ -917,7 +959,7 @@ public class JsonParserDstu3Test {
assertThat(encode, containsString("\"value\": \"APPID\""));
}
@Test
public void testEncodeUndeclaredExtensionWithEnumerationContent() {
IParser parser = ourCtx.newJsonParser();
@ -938,7 +980,7 @@ public class JsonParserDstu3Test {
assertEquals("home", ref.getValue().toCode());
}
@Test
public void testEncodeWithDontEncodeElements() throws Exception {
Patient patient = new Patient();
@ -1678,6 +1720,16 @@ public class JsonParserDstu3Test {
}
/**
* See #484
*/
@Test
public void testParseNarrativeWithEmptyDiv() {
String input = "{\"resourceType\":\"Basic\",\"id\":\"1\",\"text\":{\"status\":\"generated\",\"div\":\"<div/>\"}}";
Basic basic = ourCtx.newJsonParser().parseResource(Basic.class, input);
assertEquals("<div/>", basic.getText().getDivAsString());
}
/**
* See #163
*/