Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
jamesagnew 2016-07-23 18:51:08 -04:00
commit a9b29d5088
5 changed files with 77 additions and 33 deletions

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.rest.server.interceptor;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.HashSet;
import java.util.Set;

View File

@ -3,7 +3,6 @@ package ca.uhn.fhir.parser;
import org.hl7.fhir.dstu3.exceptions.FHIRException;
import org.hl7.fhir.dstu3.model.Identifier;
import org.hl7.fhir.dstu3.model.MessageHeader;
import org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent;
import ca.uhn.fhir.model.api.annotation.Block;
import ca.uhn.fhir.model.api.annotation.Child;
@ -11,7 +10,7 @@ import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
@ResourceDef(name = "FooMessageHeader")
@ResourceDef(name = "MessageHeader")
public class FooMessageHeader extends MessageHeader {
private static final long serialVersionUID = 1L;

View File

@ -5,18 +5,13 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
@ -24,6 +19,7 @@ import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains;
import org.hl7.fhir.dstu3.exceptions.FHIRException;
import org.hl7.fhir.dstu3.model.Address.AddressUse;
import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory;
import org.hl7.fhir.dstu3.model.Attachment;
@ -79,6 +75,8 @@ import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.parser.PatientWithExtendedContactDstu3.CustomContactComponent;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;
@ -113,30 +111,51 @@ public class JsonParserDstu3Test {
ourLog.info(output);
assertThat(output, containsString("\"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\""));
}
@Test
public void testValidateCustomStructure() throws Exception {
FooMessageHeader.FooMessageSourceComponent source = new FooMessageHeader.FooMessageSourceComponent();
source.getMessageHeaderApplicationId().setValue("APPID");
source.setName("NAME");
source.setEndpoint("http://foo");
FooMessageHeader header = new FooMessageHeader();
header.setTimestamp(new Date());
header.getEvent().setSystem("http://system").setCode("value");
header.setSource(source);
FhirValidator val = ourCtx.newValidator();
val.setValidateAgainstStandardSchema(true);
val.setValidateAgainstStandardSchematron(true);
ValidationResult result = val.validateWithResult(header);
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
assertTrue(result.isSuccessful());
}
@Test
public void testEncodeUndeclaredBlock() throws Exception {
FooMessageHeader.FooMessageSourceComponent source = new FooMessageHeader.FooMessageSourceComponent();
source.getMessageHeaderApplicationId().setValue("APPID");
source.setName("NAME");
FooMessageHeader header = new FooMessageHeader();
header.setSource(source);
Bundle bundle = new Bundle();
bundle.addEntry().setResource(header);
IParser p = ourCtx.newJsonParser();
p.setPrettyPrint(true);
String encode = p.encodeResourceToString(bundle);
ourLog.info(encode);
assertThat(encode, containsString("\"value\": \"APPID\""));
IParser p = ourCtx.newJsonParser();
p.setPrettyPrint(true);
String encode = p.encodeResourceToString(bundle);
ourLog.info(encode);
assertThat(encode, containsString("\"value\": \"APPID\""));
}
/**
* See #344
*/
@ -728,8 +747,8 @@ public class JsonParserDstu3Test {
ourLog.info(encoded);
assertThat(encoded, containsString("Patient"));
assertThat(encoded,
stringContainsInOrder("\"tag\"", "\"system\": \"foo\",", "\"code\": \"bar\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\"", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\""));
assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\": \"foo\",", "\"code\": \"bar\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\"",
"\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\""));
assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus")));
@ -947,7 +966,7 @@ public class JsonParserDstu3Test {
PatientWithExtendedContactDstu3 patient = new PatientWithExtendedContactDstu3();
patient.setId("123");
CustomContactComponent customContactComponent = new CustomContactComponent();
customContactComponent.getEyeColour().setValue("EYE");
customContactComponent.getName().addFamily("FAMILY");
@ -955,8 +974,10 @@ public class JsonParserDstu3Test {
String val = parser.encodeResourceToString(patient);
ourLog.info(val);
assertEquals("{\"resourceType\":\"Patient\",\"id\":\"123\",\"contact\":[{\"extension\":[{\"url\":\"http://foo.com/contact-eyecolour\",\"valueIdentifier\":{\"value\":\"EYE\"}}],\"name\":{\"family\":[\"FAMILY\"]}}]}", val);
assertEquals(
"{\"resourceType\":\"Patient\",\"id\":\"123\",\"contact\":[{\"extension\":[{\"url\":\"http://foo.com/contact-eyecolour\",\"valueIdentifier\":{\"value\":\"EYE\"}}],\"name\":{\"family\":[\"FAMILY\"]}}]}",
val);
FhirContext newCtx = FhirContext.forDstu3();
PatientWithExtendedContactDstu3 actual = newCtx.newJsonParser().parseResource(PatientWithExtendedContactDstu3.class, val);
@ -1087,7 +1108,7 @@ public class JsonParserDstu3Test {
" }\n" +
"}";
//@formatter:on
ExplanationOfBenefit eob = ourCtx.newJsonParser().parseResource(ExplanationOfBenefit.class, input);
assertEquals(Reference.class, eob.getCoverage().getCoverage().getClass());
@ -1192,7 +1213,6 @@ public class JsonParserDstu3Test {
assertThat(ourCtx.newJsonParser().setOmitResourceId(true).encodeResourceToString(p), not(containsString("123")));
}
@Test
@Ignore
public void testParseAndEncodeBundle() throws Exception {
@ -1410,7 +1430,6 @@ public class JsonParserDstu3Test {
assertEquals(StringType.class, comm.getPayload().get(2).getContent().getClass());
}
@Test
public void testParseAndEncodeComments() throws IOException {
//@formatter:off
@ -1563,10 +1582,9 @@ public class JsonParserDstu3Test {
} catch (DataFormatException e) {
assertEquals("Failed to parse JSON content, error was: Content does not appear to be FHIR JSON, first non-whitespace character was: '[' (must be '{')", e.getMessage());
}
assertEquals(Bundle.class, ourCtx.newJsonParser().parseResource(" {\"resourceType\" : \"Bundle\"}").getClass());
}
@Test
@ -1632,7 +1650,7 @@ public class JsonParserDstu3Test {
}
@Test(expected=DataFormatException.class)
@Test(expected = DataFormatException.class)
public void testParseWithTrailingContent() throws Exception {
//@formatter:off
String bundle = "{\n" +
@ -1643,7 +1661,7 @@ public class JsonParserDstu3Test {
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, bundle);
}
/**
* See #163
*/

View File

@ -33,6 +33,7 @@
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-base</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>

View File

@ -78,6 +78,12 @@
DSTU2 HL7org structures with the JAX-RS module. Thanks to Carlo Mion
for the pull request!
</action>
<action type="fix">
hapi-fhir-testpage-overlay project contained an unneccesary
dependency on hapi-fhir-jpaserver-base module, which resulted in
projects using the overlay having a large number of unnneded
JARs included
</action>
<action type="add" issue="403">
It is not possible to configure both the parser and the context to
preserve versions in resource references (default behaviour is to