From 2176e7c64dd09a356f0dac7ed23c435ca8be7dfb Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 17 Apr 2019 15:54:40 -0400 Subject: [PATCH] Clean up enableWhen testing in validator for Questionnaire resources --- .../org/hl7/fhir/dstu2/model/InstantType.java | 4 ++- .../org/hl7/fhir/dstu3/model/InstantType.java | 4 ++- .../org/hl7/fhir/r4/model/InstantType.java | 3 +- .../hl7/fhir/r4/model/ResourceFactory.java | 3 +- .../java/org/hl7/fhir/r4/model/XhtmlType.java | 1 + .../org/hl7/fhir/r5/model/InstantType.java | 3 +- org.hl7.fhir.validation/pom.xml | 7 ++++ .../DefaultEnableWhenEvaluator.java | 32 +++++++++---------- .../DefaultEnableWhenEvaluator.java | 32 +++++++++---------- 9 files changed, 50 insertions(+), 39 deletions(-) diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/InstantType.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/InstantType.java index 7aa8e62f4..d943781ef 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/InstantType.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/InstantType.java @@ -218,7 +218,9 @@ public class InstantType extends BaseDateTimeType { @Override public InstantType copy() { - return new InstantType(getValue()); + InstantType ret = new InstantType(); + ret.setValueAsString(getValueAsString()); + return ret; } /** diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/InstantType.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/InstantType.java index d1fd35ecd..16a93b08f 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/InstantType.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/InstantType.java @@ -218,7 +218,9 @@ public class InstantType extends BaseDateTimeType { @Override public InstantType copy() { - return new InstantType(getValueAsString()); + InstantType ret = new InstantType(); + ret.setValueAsString(getValueAsString()); + return ret; } /** diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/InstantType.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/InstantType.java index b6de2fcb5..baffafa09 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/InstantType.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/InstantType.java @@ -218,7 +218,8 @@ public class InstantType extends BaseDateTimeType { @Override public InstantType copy() { - InstantType ret = new InstantType(getValueAsString()); + InstantType ret = new InstantType(); + ret.setValueAsString(getValueAsString()); copyValues(ret); return ret; } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceFactory.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceFactory.java index 3c9ed920b..ebbfaa133 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceFactory.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceFactory.java @@ -686,8 +686,9 @@ public class ResourceFactory extends Factory { case 116076: return new UriType(); case 116079: return new UrlType(); case 3601339: return new UuidType(); + case 114035747: return new XhtmlType(); default: - throw new FHIRException("Unknown Resource or Type Name '"+name+"'"); + throw new FHIRException("Unknown Resource or Type Name '"+name+"': " + name.hashCode()); } } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/XhtmlType.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/XhtmlType.java index 2e721b952..c5e50d4b9 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/XhtmlType.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/XhtmlType.java @@ -39,6 +39,7 @@ public class XhtmlType extends Element { } public XhtmlType() { + this(new Narrative()); // "
" } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/InstantType.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/InstantType.java index e11009c93..eb21e35e3 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/InstantType.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/InstantType.java @@ -218,7 +218,8 @@ public class InstantType extends BaseDateTimeType { @Override public InstantType copy() { - InstantType ret = new InstantType(getValueAsString()); + InstantType ret = new InstantType(); + ret.setValueAsString(getValueAsString()); copyValues(ret); return ret; } diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index d3aa2a4a5..319de686f 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -85,6 +85,13 @@ test + + org.apache.commons + commons-compress + 1.18 + test + + diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java index 44d62a409..f3f9a3e03 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/DefaultEnableWhenEvaluator.java @@ -149,16 +149,22 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { } + /** + * Recursively look for answers to questions with the given link id + */ private List findQuestionAnswers(Element questionnaireResponse, String question) { - List matchingItems = questionnaireResponse.getChildren(ITEM_ELEMENT) - .stream() - .flatMap(i -> findSubItems(i).stream()) - .filter(i -> hasLinkId(i, question)) - .collect(Collectors.toList()); - return matchingItems - .stream() - .flatMap(e -> extractAnswer(e).stream()) - .collect(Collectors.toList()); + List retVal = new ArrayList<>(); + + List items = questionnaireResponse.getChildren(ITEM_ELEMENT); + for (Element next : items) { + if (hasLinkId(next, question)) { + List answers = extractAnswer(next); + retVal.addAll(answers); + } + retVal.addAll(findQuestionAnswers(next, question)); + } + + return retVal; } private List extractAnswer(Element item) { @@ -197,14 +203,6 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { } return true; } - private List findSubItems(Element item) { - List results = item.getChildren(LINKID_ELEMENT) - .stream() - .flatMap(i -> findSubItems(i).stream()) - .collect(Collectors.toList()); - results.add(item); - return results; - } private boolean hasLinkId(Element item, String linkId) { Element linkIdChild = item.getNamedChild(LINKID_ELEMENT); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java index 8634c2730..f15d7c368 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/DefaultEnableWhenEvaluator.java @@ -149,16 +149,22 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { } + /** + * Recursively look for answers to questions with the given link id + */ private List findQuestionAnswers(Element questionnaireResponse, String question) { - List matchingItems = questionnaireResponse.getChildren(ITEM_ELEMENT) - .stream() - .flatMap(i -> findSubItems(i).stream()) - .filter(i -> hasLinkId(i, question)) - .collect(Collectors.toList()); - return matchingItems - .stream() - .flatMap(e -> extractAnswer(e).stream()) - .collect(Collectors.toList()); + List retVal = new ArrayList<>(); + + List items = questionnaireResponse.getChildren(ITEM_ELEMENT); + for (Element next : items) { + if (hasLinkId(next, question)) { + List answers = extractAnswer(next); + retVal.addAll(answers); + } + retVal.addAll(findQuestionAnswers(next, question)); + } + + return retVal; } private List extractAnswer(Element item) { @@ -197,14 +203,6 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator { } return true; } - private List findSubItems(Element item) { - List results = item.getChildren(ITEM_ELEMENT) - .stream() - .flatMap(i -> findSubItems(i).stream()) - .collect(Collectors.toList()); - results.add(item); - return results; - } private boolean hasLinkId(Element item, String linkId) { Element linkIdChild = item.getNamedChild(LINKID_ELEMENT);