fix Questionnaire EnableWhen validation + fix up tests for public package server
This commit is contained in:
parent
fccd3c1871
commit
91e475a1a1
|
@ -56,7 +56,7 @@ public class PackageClientTests {
|
|||
|
||||
@Test
|
||||
public void testExists2() throws IOException {
|
||||
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||
PackageClient client = new PackageClient("http://test.fhir.org/packages");
|
||||
Assert.assertTrue(client.exists("hl7.fhir.r4.core", "4.0.1"));
|
||||
Assert.assertTrue(!client.exists("hl7.fhir.r4.core", "1.0.2"));
|
||||
Assert.assertTrue(!client.exists("hl7.fhir.nothing", "1.0.1"));
|
||||
|
@ -64,7 +64,7 @@ public class PackageClientTests {
|
|||
|
||||
@Test
|
||||
public void testSearch2() throws IOException {
|
||||
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||
PackageClient client = new PackageClient("http://test.fhir.org/packages");
|
||||
List<PackageInfo> matches = client.search("core", null, null, false);
|
||||
for (PackageInfo pi : matches) {
|
||||
System.out.println(pi.toString());
|
||||
|
@ -74,14 +74,14 @@ public class PackageClientTests {
|
|||
|
||||
@Test
|
||||
public void testSearchNoMatches2() throws IOException {
|
||||
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||
PackageClient client = new PackageClient("http://test.fhir.org/packages");
|
||||
List<PackageInfo> matches = client.search("corezxxx", null, null, false);
|
||||
Assert.assertTrue(matches.size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersions2() throws IOException {
|
||||
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||
PackageClient client = new PackageClient("http://test.fhir.org/packages");
|
||||
List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3");
|
||||
for (PackageInfo pi : matches) {
|
||||
System.out.println(pi.toString());
|
||||
|
@ -91,7 +91,7 @@ public class PackageClientTests {
|
|||
|
||||
@Test
|
||||
public void testVersions2A() throws IOException {
|
||||
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||
PackageClient client = new PackageClient("http://test.fhir.org/packages");
|
||||
List<PackageInfo> matches = client.getVersions("hl7.fhir.us.core");
|
||||
for (PackageInfo pi : matches) {
|
||||
System.out.println(pi.toString());
|
||||
|
@ -101,7 +101,7 @@ public class PackageClientTests {
|
|||
|
||||
@Test
|
||||
public void testVersionsNone2() throws IOException {
|
||||
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||
PackageClient client = new PackageClient("http://test.fhir.org/packages");
|
||||
List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3X");
|
||||
Assert.assertTrue(matches.size() == 0);
|
||||
}
|
||||
|
|
|
@ -3602,7 +3602,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
} else if (element.getType().equals("Observation")) {
|
||||
validateObservation(errors, element, stack);
|
||||
} else if (element.getType().equals("Questionnaire")) {
|
||||
validateQuestionannaire(errors, element, stack);
|
||||
ArrayList<Element> parents = new ArrayList<>();
|
||||
parents.add(element);
|
||||
validateQuestionannaireItem(errors, element, element, stack, parents);
|
||||
} else if (element.getType().equals("QuestionnaireResponse")) {
|
||||
validateQuestionannaireResponse(hostContext, errors, element, stack);
|
||||
} else if (element.getType().equals("CapabilityStatement")) {
|
||||
|
@ -3621,32 +3623,35 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
return res;
|
||||
}
|
||||
|
||||
private void validateQuestionannaire(List<ValidationMessage> errors, Element element, NodeStack stack) {
|
||||
private void validateQuestionannaireItem(List<ValidationMessage> errors, Element element, Element questionnaire, NodeStack stack, List<Element> parents) {
|
||||
List<Element> list = getItems(element);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Element e = list.get(i);
|
||||
NodeStack ns = stack.push(element, i, e.getProperty().getDefinition(), e.getProperty().getDefinition());
|
||||
validateQuestionnaireElement(errors, ns, element, e, new ArrayList<>());
|
||||
NodeStack ns = stack.push(e, i, e.getProperty().getDefinition(), e.getProperty().getDefinition());
|
||||
validateQuestionnaireElement(errors, ns, questionnaire, e, parents);
|
||||
validateQuestionannaireItem(errors, e, questionnaire, ns, list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void validateQuestionnaireElement(List<ValidationMessage> errors, NodeStack ns, Element questionnaire, Element item, List<Element> parents) {
|
||||
// R4+
|
||||
if (FHIRVersion.isR4Plus(context.getVersion())) {
|
||||
if (item.hasChild("enableWhen")) {
|
||||
Element ew = item.getNamedChild("enableWhen");
|
||||
String ql = ew.getNamedChildValue("question");
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, ql != null, "Questions with an enableWhen must have a value for the question link")) {
|
||||
Element tgt = getQuestionById(item, ql);
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt == null, "Questions with an enableWhen cannot refer to an inner question for it's enableWhen condition")) {
|
||||
tgt = getQuestionById(questionnaire, ql);
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt != null, "Unable to find "+ql+" target for this question enableWhen")) {
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt != item, "Target for this question enableWhen can't reference itself")) {
|
||||
warning(errors, IssueType.BUSINESSRULE, ns.literalPath, isBefore(item, tgt, parents), "The target of this enableWhen rule ("+ql+") comes after the question itself");
|
||||
if (item.hasChildren("enableWhen")) {
|
||||
List<Element> ewl = item.getChildren("enableWhen");
|
||||
for (Element ew : ewl) {
|
||||
// Element ew = item.getNamedChild("enableWhen");
|
||||
String ql = ew.getNamedChildValue("question");
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, ql != null, "Questions with an enableWhen must have a value for the question link")) {
|
||||
Element tgt = getQuestionById(item, ql);
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt == null, "Questions with an enableWhen cannot refer to an inner question for it's enableWhen condition")) {
|
||||
tgt = getQuestionById(questionnaire, ql);
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt != null, "Unable to find target '"+ql+"' for this question enableWhen")) {
|
||||
if (rule(errors, IssueType.BUSINESSRULE, ns.literalPath, tgt != item, "Target for this question enableWhen can't reference itself")) {
|
||||
warning(errors, IssueType.BUSINESSRULE, ns.literalPath, isBefore(item, tgt, parents), "The target of this enableWhen rule ("+ql+") comes after the question itself");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3677,7 +3682,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||
for (Element e : element.getChildren()) {
|
||||
if (e == descendant)
|
||||
return true;
|
||||
if (isChild(element, descendant))
|
||||
if (isChild(e, descendant))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue