Bump FHIR version to 1.0.0
This commit is contained in:
parent
f04147dcfd
commit
64cc5d4659
|
@ -160,7 +160,7 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
|
||||||
|
|
||||||
retVal.setPublisher(myPublisher);
|
retVal.setPublisher(myPublisher);
|
||||||
retVal.setDate(DateTimeDt.withCurrentTime());
|
retVal.setDate(DateTimeDt.withCurrentTime());
|
||||||
retVal.setFhirVersion("0.5.0"); // TODO: pull from model
|
retVal.setFhirVersion("1.0.0"); // TODO: pull from model
|
||||||
retVal.setAcceptUnknown(UnknownContentCodeEnum.UNKNOWN_EXTENSIONS); // TODO: make this configurable - this is a fairly big effort since the parser
|
retVal.setAcceptUnknown(UnknownContentCodeEnum.UNKNOWN_EXTENSIONS); // TODO: make this configurable - this is a fairly big effort since the parser
|
||||||
// needs to be modified to actually allow it
|
// needs to be modified to actually allow it
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
|
||||||
|
|
||||||
retVal.setPublisher(myPublisher);
|
retVal.setPublisher(myPublisher);
|
||||||
retVal.setDate(new Date());
|
retVal.setDate(new Date());
|
||||||
retVal.setFhirVersion("0.5.0"); // TODO: pull from model
|
retVal.setFhirVersion("1.0.0"); // TODO: pull from model
|
||||||
retVal.setAcceptUnknown(UnknownContentCode.EXTENSIONS); // TODO: make this configurable - this is a fairly big effort since the parser
|
retVal.setAcceptUnknown(UnknownContentCode.EXTENSIONS); // TODO: make this configurable - this is a fairly big effort since the parser
|
||||||
// needs to be modified to actually allow it
|
// needs to be modified to actually allow it
|
||||||
|
|
||||||
|
|
|
@ -890,7 +890,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
String p = stack.addToLiteralPath("meta", "profile", ":"+Integer.toString(i));
|
String p = stack.addToLiteralPath("meta", "profile", ":"+Integer.toString(i));
|
||||||
if (rule(errors, IssueType.INVALID, element.line(), element.col(), p, !Utilities.noString(ref), "StructureDefinition reference invalid")) {
|
if (rule(errors, IssueType.INVALID, element.line(), element.col(), p, !Utilities.noString(ref), "StructureDefinition reference invalid")) {
|
||||||
StructureDefinition pr = context.fetchResource(StructureDefinition.class, ref);
|
StructureDefinition pr = context.fetchResource(StructureDefinition.class, ref);
|
||||||
if (warning(errors, IssueType.INVALID, element.line(), element.col(), p, pr != null, "StructureDefinition reference could not be resolved")) {
|
if (warning(errors, IssueType.INVALID, element.line(), element.col(), p, pr != null, "StructureDefinition reference \"{0}\" could not be resolved", ref)) {
|
||||||
if (rule(errors, IssueType.STRUCTURE, element.line(), element.col(), p, pr.hasSnapshot(), "StructureDefinition has no snapshot - validation is against the snapshot, so it must be provided")) {
|
if (rule(errors, IssueType.STRUCTURE, element.line(), element.col(), p, pr.hasSnapshot(), "StructureDefinition has no snapshot - validation is against the snapshot, so it must be provided")) {
|
||||||
validateElement(errors, pr, pr.getSnapshot().getElement().get(0), null, null, element, element.getName(), stack);
|
validateElement(errors, pr, pr.getSnapshot().getElement().get(0), null, null, element, element.getName(), stack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ca.uhn.fhir.validation;
|
package ca.uhn.fhir.validation;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
@ -8,6 +9,7 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hl7.fhir.instance.model.CodeType;
|
import org.hl7.fhir.instance.model.CodeType;
|
||||||
|
@ -23,6 +25,8 @@ import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||||
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
|
|
||||||
public class FhirInstanceValidatorTest {
|
public class FhirInstanceValidatorTest {
|
||||||
|
|
||||||
|
@ -120,20 +124,29 @@ public class FhirInstanceValidatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateJsonResource() {
|
public void testValidateRawJsonResource() {
|
||||||
// @formatter:off
|
//@formatter:off
|
||||||
String input = "{" + "\"resourceType\":\"Patient\"," + "\"id\":\"123\"" + "}";
|
String input =
|
||||||
// @formatter:on
|
"{" +
|
||||||
|
"\"resourceType\":\"Patient\"," +
|
||||||
|
"\"id\":\"123\"" +
|
||||||
|
"}";
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
ValidationResult output = myVal.validateWithResult(input);
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
assertEquals(output.toString(), 0, output.getMessages().size());
|
assertEquals(output.toString(), 0, output.getMessages().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateJsonResourceBadAttributes() {
|
public void testValidateRawJsonResourceBadAttributes() {
|
||||||
// @formatter:off
|
//@formatter:off
|
||||||
String input = "{" + "\"resourceType\":\"Patient\"," + "\"id\":\"123\"," + "\"foo\":\"123\"" + "}";
|
String input =
|
||||||
// @formatter:on
|
"{" +
|
||||||
|
"\"resourceType\":\"Patient\"," +
|
||||||
|
"\"id\":\"123\"," +
|
||||||
|
"\"foo\":\"123\"" +
|
||||||
|
"}";
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
ValidationResult output = myVal.validateWithResult(input);
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
assertEquals(output.toString(), 1, output.getMessages().size());
|
assertEquals(output.toString(), 1, output.getMessages().size());
|
||||||
|
@ -143,6 +156,34 @@ public class FhirInstanceValidatorTest {
|
||||||
assertEquals("Element is unknown or does not match any slice", output.getMessages().get(0).getMessage());
|
assertEquals("Element is unknown or does not match any slice", output.getMessages().get(0).getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateRawXmlResource() {
|
||||||
|
//@formatter:off
|
||||||
|
String input =
|
||||||
|
"<Patient xmlns=\"http://hl7.org/fhir\">" +
|
||||||
|
"<id value=\"123\"/>" +
|
||||||
|
"</Patient>";
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
|
assertEquals(output.toString(), 0, output.getMessages().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateRawXmlResourceBadAttributes() {
|
||||||
|
// @formatter:off
|
||||||
|
String input = "<Patient xmlns=\"http://hl7.org/fhir\">" + "<id value=\"123\"/>" + "<foo value=\"222\"/>"
|
||||||
|
+ "</Patient>";
|
||||||
|
// @formatter:on
|
||||||
|
|
||||||
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
|
assertEquals(output.toString(), 1, output.getMessages().size());
|
||||||
|
ourLog.info(output.getMessages().get(0).getLocationString());
|
||||||
|
ourLog.info(output.getMessages().get(0).getMessage());
|
||||||
|
assertEquals("/f:Patient/f:foo", output.getMessages().get(0).getLocationString());
|
||||||
|
assertEquals("Element is unknown or does not match any slice", output.getMessages().get(0).getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateResourceFailingInvariant() {
|
public void testValidateResourceFailingInvariant() {
|
||||||
Observation input = new Observation();
|
Observation input = new Observation();
|
||||||
|
@ -158,6 +199,68 @@ public class FhirInstanceValidatorTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateResourceContainingProfileDeclarationDoesntResolve() {
|
||||||
|
addValidConcept("http://loinc.org", "12345");
|
||||||
|
|
||||||
|
Observation input = new Observation();
|
||||||
|
input.getMeta().addProfile("http://foo/myprofile");
|
||||||
|
|
||||||
|
input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345");
|
||||||
|
input.setStatus(ObservationStatus.FINAL);
|
||||||
|
|
||||||
|
myInstanceVal.setValidationSupport(myMockSupport);
|
||||||
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
|
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
|
||||||
|
assertEquals(errors.toString(), 1, errors.size());
|
||||||
|
assertEquals("StructureDefinition reference \"http://foo/myprofile\" could not be resolved", errors.get(0).getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateResourceContainingProfileDeclaration() {
|
||||||
|
addValidConcept("http://loinc.org", "12345");
|
||||||
|
|
||||||
|
Observation input = new Observation();
|
||||||
|
input.getMeta().addProfile("http://hl7.org/fhir/StructureDefinition/devicemetricobservation");
|
||||||
|
|
||||||
|
input.addIdentifier().setSystem("http://acme").setValue("12345");
|
||||||
|
input.getEncounter().setReference("http://foo.com/Encounter/9");
|
||||||
|
input.setStatus(ObservationStatus.FINAL);
|
||||||
|
input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345");
|
||||||
|
|
||||||
|
myInstanceVal.setValidationSupport(myMockSupport);
|
||||||
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
|
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
|
||||||
|
|
||||||
|
assertThat(errors.toString(), containsString("Element '/f:Observation.subject': minimum required = 1, but only found 0"));
|
||||||
|
assertThat(errors.toString(), containsString("Element encounter @ /f:Observation: max allowed = 0, but found 1"));
|
||||||
|
assertThat(errors.toString(), containsString("Element '/f:Observation.device': minimum required = 1, but only found 0"));
|
||||||
|
assertThat(errors.toString(), containsString(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateResourceWithDefaultValueset() {
|
||||||
|
Observation input = new Observation();
|
||||||
|
|
||||||
|
input.setStatus(ObservationStatus.FINAL);
|
||||||
|
input.getCode().setText("No code here!");
|
||||||
|
|
||||||
|
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(input));
|
||||||
|
|
||||||
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
|
assertEquals(output.getMessages().size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateResourceWithDefaultValuesetBadCode() {
|
||||||
|
String input = "<Observation xmlns=\"http://hl7.org/fhir\">\n" + " <status value=\"notvalidcode\"/>\n"
|
||||||
|
+ " <code>\n" + " <text value=\"No code here!\"/>\n" + " </code>\n" + "</Observation>";
|
||||||
|
ValidationResult output = myVal.validateWithResult(input);
|
||||||
|
assertEquals(
|
||||||
|
"Coded value notvalidcode is not in value set http://hl7.org/fhir/ValueSet/observation-status (http://hl7.org/fhir/ValueSet/observation-status)",
|
||||||
|
output.getMessages().get(0).getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateResourceWithExampleBindingCodeValidationFailing() {
|
public void testValidateResourceWithExampleBindingCodeValidationFailing() {
|
||||||
Observation input = new Observation();
|
Observation input = new Observation();
|
||||||
|
@ -188,52 +291,4 @@ public class FhirInstanceValidatorTest {
|
||||||
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
|
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
|
||||||
assertEquals(errors.toString(), 0, errors.size());
|
assertEquals(errors.toString(), 0, errors.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateResourceWithDefaultValueset() {
|
|
||||||
Observation input = new Observation();
|
|
||||||
|
|
||||||
input.setStatus(ObservationStatus.FINAL);
|
|
||||||
input.getCode().setText("No code here!");
|
|
||||||
|
|
||||||
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(input));
|
|
||||||
|
|
||||||
ValidationResult output = myVal.validateWithResult(input);
|
|
||||||
assertEquals(output.getMessages().size(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateResourceWithDefaultValuesetBadCode() {
|
|
||||||
String input = "<Observation xmlns=\"http://hl7.org/fhir\">\n" + " <status value=\"notvalidcode\"/>\n"
|
|
||||||
+ " <code>\n" + " <text value=\"No code here!\"/>\n" + " </code>\n" + "</Observation>";
|
|
||||||
ValidationResult output = myVal.validateWithResult(input);
|
|
||||||
assertEquals(
|
|
||||||
"Coded value notvalidcode is not in value set http://hl7.org/fhir/ValueSet/observation-status (http://hl7.org/fhir/ValueSet/observation-status)",
|
|
||||||
output.getMessages().get(0).getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateXmlResource() {
|
|
||||||
// @formatter:off
|
|
||||||
String input = "<Patient xmlns=\"http://hl7.org/fhir\">" + "<id value=\"123\"/>" + "</Patient>";
|
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
ValidationResult output = myVal.validateWithResult(input);
|
|
||||||
assertEquals(output.toString(), 0, output.getMessages().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testValidateXmlResourceBadAttributes() {
|
|
||||||
// @formatter:off
|
|
||||||
String input = "<Patient xmlns=\"http://hl7.org/fhir\">" + "<id value=\"123\"/>" + "<foo value=\"222\"/>"
|
|
||||||
+ "</Patient>";
|
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
ValidationResult output = myVal.validateWithResult(input);
|
|
||||||
assertEquals(output.toString(), 1, output.getMessages().size());
|
|
||||||
ourLog.info(output.getMessages().get(0).getLocationString());
|
|
||||||
ourLog.info(output.getMessages().get(0).getMessage());
|
|
||||||
assertEquals("/f:Patient/f:foo", output.getMessages().get(0).getLocationString());
|
|
||||||
assertEquals("Element is unknown or does not match any slice", output.getMessages().get(0).getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue