Clean up enableWhen testing in validator for Questionnaire resources

This commit is contained in:
James Agnew 2019-04-17 15:54:40 -04:00
parent ed22a46775
commit 2176e7c64d
9 changed files with 50 additions and 39 deletions

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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;
}

View File

@ -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());
}
}

View File

@ -39,6 +39,7 @@ public class XhtmlType extends Element {
}
public XhtmlType() {
this(new Narrative());
// "<div xmlns=\""+FormatUtilities.XHTML_NS+"\"></div>"
}

View File

@ -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;
}

View File

@ -85,6 +85,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.18</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -149,16 +149,22 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
}
/**
* Recursively look for answers to questions with the given link id
*/
private List<Element> findQuestionAnswers(Element questionnaireResponse, String question) {
List<Element> 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<Element> retVal = new ArrayList<>();
List<Element> items = questionnaireResponse.getChildren(ITEM_ELEMENT);
for (Element next : items) {
if (hasLinkId(next, question)) {
List<Element> answers = extractAnswer(next);
retVal.addAll(answers);
}
retVal.addAll(findQuestionAnswers(next, question));
}
return retVal;
}
private List<Element> extractAnswer(Element item) {
@ -197,14 +203,6 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
}
return true;
}
private List<Element> findSubItems(Element item) {
List<Element> 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);

View File

@ -149,16 +149,22 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
}
/**
* Recursively look for answers to questions with the given link id
*/
private List<Element> findQuestionAnswers(Element questionnaireResponse, String question) {
List<Element> 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<Element> retVal = new ArrayList<>();
List<Element> items = questionnaireResponse.getChildren(ITEM_ELEMENT);
for (Element next : items) {
if (hasLinkId(next, question)) {
List<Element> answers = extractAnswer(next);
retVal.addAll(answers);
}
retVal.addAll(findQuestionAnswers(next, question));
}
return retVal;
}
private List<Element> extractAnswer(Element item) {
@ -197,14 +203,6 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
}
return true;
}
private List<Element> findSubItems(Element item) {
List<Element> 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);