mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-11 23:34:43 +00:00
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
|
@Test
|
||||||
public void testExists2() throws IOException {
|
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", "4.0.1"));
|
||||||
Assert.assertTrue(!client.exists("hl7.fhir.r4.core", "1.0.2"));
|
Assert.assertTrue(!client.exists("hl7.fhir.r4.core", "1.0.2"));
|
||||||
Assert.assertTrue(!client.exists("hl7.fhir.nothing", "1.0.1"));
|
Assert.assertTrue(!client.exists("hl7.fhir.nothing", "1.0.1"));
|
||||||
@ -64,7 +64,7 @@ public class PackageClientTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearch2() throws IOException {
|
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);
|
List<PackageInfo> matches = client.search("core", null, null, false);
|
||||||
for (PackageInfo pi : matches) {
|
for (PackageInfo pi : matches) {
|
||||||
System.out.println(pi.toString());
|
System.out.println(pi.toString());
|
||||||
@ -74,14 +74,14 @@ public class PackageClientTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchNoMatches2() throws IOException {
|
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);
|
List<PackageInfo> matches = client.search("corezxxx", null, null, false);
|
||||||
Assert.assertTrue(matches.size() == 0);
|
Assert.assertTrue(matches.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVersions2() throws IOException {
|
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");
|
List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3");
|
||||||
for (PackageInfo pi : matches) {
|
for (PackageInfo pi : matches) {
|
||||||
System.out.println(pi.toString());
|
System.out.println(pi.toString());
|
||||||
@ -91,7 +91,7 @@ public class PackageClientTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVersions2A() throws IOException {
|
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");
|
List<PackageInfo> matches = client.getVersions("hl7.fhir.us.core");
|
||||||
for (PackageInfo pi : matches) {
|
for (PackageInfo pi : matches) {
|
||||||
System.out.println(pi.toString());
|
System.out.println(pi.toString());
|
||||||
@ -101,7 +101,7 @@ public class PackageClientTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVersionsNone2() throws IOException {
|
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");
|
List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3X");
|
||||||
Assert.assertTrue(matches.size() == 0);
|
Assert.assertTrue(matches.size() == 0);
|
||||||
}
|
}
|
||||||
|
@ -3602,7 +3602,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||||||
} else if (element.getType().equals("Observation")) {
|
} else if (element.getType().equals("Observation")) {
|
||||||
validateObservation(errors, element, stack);
|
validateObservation(errors, element, stack);
|
||||||
} else if (element.getType().equals("Questionnaire")) {
|
} 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")) {
|
} else if (element.getType().equals("QuestionnaireResponse")) {
|
||||||
validateQuestionannaireResponse(hostContext, errors, element, stack);
|
validateQuestionannaireResponse(hostContext, errors, element, stack);
|
||||||
} else if (element.getType().equals("CapabilityStatement")) {
|
} else if (element.getType().equals("CapabilityStatement")) {
|
||||||
@ -3621,27 +3623,29 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||||||
return res;
|
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);
|
List<Element> list = getItems(element);
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
Element e = list.get(i);
|
Element e = list.get(i);
|
||||||
NodeStack ns = stack.push(element, i, e.getProperty().getDefinition(), e.getProperty().getDefinition());
|
NodeStack ns = stack.push(e, i, e.getProperty().getDefinition(), e.getProperty().getDefinition());
|
||||||
validateQuestionnaireElement(errors, ns, element, e, new ArrayList<>());
|
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) {
|
private void validateQuestionnaireElement(List<ValidationMessage> errors, NodeStack ns, Element questionnaire, Element item, List<Element> parents) {
|
||||||
// R4+
|
// R4+
|
||||||
if (FHIRVersion.isR4Plus(context.getVersion())) {
|
if (FHIRVersion.isR4Plus(context.getVersion())) {
|
||||||
if (item.hasChild("enableWhen")) {
|
if (item.hasChildren("enableWhen")) {
|
||||||
Element ew = item.getNamedChild("enableWhen");
|
List<Element> ewl = item.getChildren("enableWhen");
|
||||||
|
for (Element ew : ewl) {
|
||||||
|
// Element ew = item.getNamedChild("enableWhen");
|
||||||
String ql = ew.getNamedChildValue("question");
|
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")) {
|
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);
|
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")) {
|
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);
|
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 != 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")) {
|
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");
|
warning(errors, IssueType.BUSINESSRULE, ns.literalPath, isBefore(item, tgt, parents), "The target of this enableWhen rule ("+ql+") comes after the question itself");
|
||||||
}
|
}
|
||||||
@ -3651,6 +3655,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isBefore(Element item, Element tgt, List<Element> parents) {
|
private boolean isBefore(Element item, Element tgt, List<Element> parents) {
|
||||||
// we work up the list, looking for tgt in the children of the parents
|
// we work up the list, looking for tgt in the children of the parents
|
||||||
@ -3677,7 +3682,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
|||||||
for (Element e : element.getChildren()) {
|
for (Element e : element.getChildren()) {
|
||||||
if (e == descendant)
|
if (e == descendant)
|
||||||
return true;
|
return true;
|
||||||
if (isChild(element, descendant))
|
if (isChild(e, descendant))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user