Merge pull request #141 from hapifhir/validator_cleaning

Validator cleaning
This commit is contained in:
Grahame Grieve 2020-02-25 08:11:28 +11:00 committed by GitHub
commit 41c4f5f299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 109 additions and 133 deletions

View File

@ -88,7 +88,7 @@
<archive> <archive>
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<mainClass>org.hl7.fhir.r5.validation.Validator</mainClass> <mainClass>org.hl7.fhir.validation.Validator</mainClass>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
/*- /*-
* #%L * #%L

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
/*- /*-
* #%L * #%L

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.hl7.fhir.convertors.*; import org.hl7.fhir.convertors.*;
@ -22,7 +22,7 @@ import org.hl7.fhir.r5.terminologies.ConceptMapEngine;
import org.hl7.fhir.r5.utils.*; import org.hl7.fhir.r5.utils.*;
import org.hl7.fhir.r5.utils.IResourceValidator.*; import org.hl7.fhir.r5.utils.IResourceValidator.*;
import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices; import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices;
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator; import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.utilities.IniFile; import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
/*- /*-
* #%L * #%L
@ -49,13 +49,8 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
import java.awt.Desktop; import java.awt.Desktop;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -85,14 +80,13 @@ import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.utils.KeyGenerator; import org.hl7.fhir.r5.utils.KeyGenerator;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.validation.ValidationEngine.ScanOutputItem; import org.hl7.fhir.validation.ValidationEngine.ScanOutputItem;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.cache.PackageCacheManager; import org.hl7.fhir.utilities.cache.PackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion; import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
/** /**
* A executable class that will validate one or more FHIR resources against * A executable class that will validate one or more FHIR resources against

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
/* /*
* #%L * #%L

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
@ -16,7 +16,6 @@ import org.hl7.fhir.r5.model.StructureDefinition.ExtensionContextType;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.UriType; import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.validation.XVerExtensionManager.XVerExtensionStatus;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation;
/*- /*-
* #%L * #%L

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation.codesystem;
/*- /*-
* #%L * #%L
@ -30,6 +30,7 @@ import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent; import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.validation.BaseValidator;
public class CodeSystemValidator extends BaseValidator { public class CodeSystemValidator extends BaseValidator {

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation.instance;
/*- /*-
* #%L * #%L
@ -9,9 +9,9 @@ package org.hl7.fhir.r5.validation;
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -28,14 +28,13 @@ import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.*; import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.model.Questionnaire.*; import org.hl7.fhir.r5.model.Questionnaire.*;
import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.validation.instancevalidator.utils.ValidatorHostContext; import org.hl7.fhir.validation.instance.utils.ValidatorHostContext;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
/** /**
* Evaluates Questionnaire.item.enableWhen against a QuestionnaireResponse. * Evaluates Questionnaire.item.enableWhen against a QuestionnaireResponse.
* Ignores possible modifierExtensions and extensions. * Ignores possible modifierExtensions and extensions.
*
*/ */
public class EnableWhenEvaluator { public class EnableWhenEvaluator {
public static final String LINKID_ELEMENT = "linkId"; public static final String LINKID_ELEMENT = "linkId";
@ -46,26 +45,29 @@ public class EnableWhenEvaluator {
public static class QuestionnaireAnswerPair { public static class QuestionnaireAnswerPair {
private QuestionnaireItemComponent q; private QuestionnaireItemComponent q;
private Element a; private Element a;
public QuestionnaireAnswerPair(QuestionnaireItemComponent q, Element a) { public QuestionnaireAnswerPair(QuestionnaireItemComponent q, Element a) {
super(); super();
this.q = q; this.q = q;
this.a = a; this.a = a;
} }
public QuestionnaireItemComponent getQ() { public QuestionnaireItemComponent getQ() {
return q; return q;
} }
public Element getA() { public Element getA() {
return a; return a;
} }
} }
public static class QStack extends ArrayList<QuestionnaireAnswerPair> { public static class QStack extends ArrayList<QuestionnaireAnswerPair> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Questionnaire q; private Questionnaire q;
private Element a; private Element a;
public QStack(Questionnaire q, Element a) { public QStack(Questionnaire q, Element a) {
super(); super();
this.q = q; this.q = q;
@ -97,40 +99,30 @@ public class EnableWhenEvaluator {
/** /**
* Evaluation result of enableWhen condition * Evaluation result of enableWhen condition
* *
* @param enabled * @param enabled Evaluation result
* Evaluation result * @param enableWhenCondition Evaluated enableWhen condition
* @param linkId
* LinkId of the questionnaire item
* @param enableWhenCondition
* Evaluated enableWhen condition
* @param responseItem
* item in QuestionnaireResponse
*/ */
public EnableWhenResult(boolean enabled, QuestionnaireItemEnableWhenComponent enableWhenCondition) { public EnableWhenResult(boolean enabled, QuestionnaireItemEnableWhenComponent enableWhenCondition) {
this.enabled = enabled; this.enabled = enabled;
this.enableWhenCondition = enableWhenCondition; this.enableWhenCondition = enableWhenCondition;
} }
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }
public QuestionnaireItemEnableWhenComponent getEnableWhenCondition() { public QuestionnaireItemEnableWhenComponent getEnableWhenCondition() {
return enableWhenCondition; return enableWhenCondition;
} }
} }
/** /**
* the stack contains a set of QR items that represent the tree of the QR being validated, each tagged with the definition of the item from the Q for the QR being validated * the stack contains a set of QR items that represent the tree of the QR being validated, each tagged with the definition of the item from the Q for the QR being validated
* * <p>
* the itembeing validated is in the context of the stack. For root items, the stack is empty. * the itembeing validated is in the context of the stack. For root items, the stack is empty.
* * <p>
* The context Questionnaire and QuestionnaireResponse are always available * The context Questionnaire and QuestionnaireResponse are always available
*
* @param questionnaireItem
* @param questionnaireResponse
* @param qstack
* @return
*/ */
public boolean isQuestionEnabled(ValidatorHostContext hostContext, QuestionnaireItemComponent qitem, QStack qstack, FHIRPathEngine engine) { public boolean isQuestionEnabled(ValidatorHostContext hostContext, QuestionnaireItemComponent qitem, QStack qstack, FHIRPathEngine engine) {
if (hasExpressionExtension(qitem)) { if (hasExpressionExtension(qitem)) {
@ -138,22 +130,22 @@ public class EnableWhenEvaluator {
ExpressionNode node = engine.parse(expr); ExpressionNode node = engine.parse(expr);
return engine.evaluateToBoolean(hostContext, qstack.a, qstack.a, qstack.a, node); return engine.evaluateToBoolean(hostContext, qstack.a, qstack.a, qstack.a, node);
} }
if (!qitem.hasEnableWhen()) { if (!qitem.hasEnableWhen()) {
return true; return true;
} }
List<EnableWhenResult> evaluationResults = qitem.getEnableWhen() List<EnableWhenResult> evaluationResults = qitem.getEnableWhen()
.stream() .stream()
.map(enableCondition -> evaluateCondition(enableCondition, qitem, qstack)) .map(enableCondition -> evaluateCondition(enableCondition, qitem, qstack))
.collect(Collectors.toList()); .collect(Collectors.toList());
return checkConditionResults(evaluationResults, qitem); return checkConditionResults(evaluationResults, qitem);
} }
private boolean hasExpressionExtension(QuestionnaireItemComponent qitem) { private boolean hasExpressionExtension(QuestionnaireItemComponent qitem) {
return qitem.hasExtension("http://phr.kanta.fi/StructureDefinition/fiphr-ext-questionnaire-enablewhen") || // finnish extension return qitem.hasExtension("http://phr.kanta.fi/StructureDefinition/fiphr-ext-questionnaire-enablewhen") || // finnish extension
qitem.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression"); // sdc extension qitem.hasExtension("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression"); // sdc extension
} }
private String getExpression(QuestionnaireItemComponent qitem) { private String getExpression(QuestionnaireItemComponent qitem) {
@ -164,17 +156,18 @@ public class EnableWhenEvaluator {
if ("text/fhirpath".equals(expr.getLanguage())) { if ("text/fhirpath".equals(expr.getLanguage())) {
return expr.getExpression(); return expr.getExpression();
} else { } else {
throw new FHIRException("Unsupported language '"+expr.getLanguage()+"' for enableWhen extension http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression"); throw new FHIRException("Unsupported language '" + expr.getLanguage() + "' for enableWhen extension http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-enableWhenExpression");
} }
} }
throw new Error("How did you get here?"); throw new Error("How did you get here?");
} }
public boolean checkConditionResults(List<EnableWhenResult> evaluationResults, QuestionnaireItemComponent questionnaireItem) { public boolean checkConditionResults(List<EnableWhenResult> evaluationResults, QuestionnaireItemComponent questionnaireItem) {
if ((questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ANY) || evaluationResults.size() == 1){ if ((questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ANY) || evaluationResults.size() == 1) {
return evaluationResults.stream().anyMatch(EnableWhenResult::isEnabled); return evaluationResults.stream().anyMatch(EnableWhenResult::isEnabled);
} if (questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ALL){ }
if (questionnaireItem.hasEnableBehavior() && questionnaireItem.getEnableBehavior() == EnableWhenBehavior.ALL) {
return evaluationResults.stream().allMatch(EnableWhenResult::isEnabled); return evaluationResults.stream().allMatch(EnableWhenResult::isEnabled);
} }
//TODO: Throw exception? enableBehavior is mandatory when there are multiple conditions //TODO: Throw exception? enableBehavior is mandatory when there are multiple conditions
@ -183,18 +176,18 @@ public class EnableWhenEvaluator {
protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition, QuestionnaireItemComponent qitem, QStack qstack) { protected EnableWhenResult evaluateCondition(QuestionnaireItemEnableWhenComponent enableCondition, QuestionnaireItemComponent qitem, QStack qstack) {
List<Element> answerItems = findQuestionAnswers(qstack, qitem, enableCondition); List<Element> answerItems = findQuestionAnswers(qstack, qitem, enableCondition);
QuestionnaireItemOperator operator = enableCondition.getOperator(); QuestionnaireItemOperator operator = enableCondition.getOperator();
if (operator == QuestionnaireItemOperator.EXISTS){ if (operator == QuestionnaireItemOperator.EXISTS) {
DataType answer = enableCondition.getAnswer(); DataType answer = enableCondition.getAnswer();
if (!(answer instanceof BooleanType)){ if (!(answer instanceof BooleanType)) {
throw new UnprocessableEntityException("Exists-operator requires answerBoolean"); throw new UnprocessableEntityException("Exists-operator requires answerBoolean");
} }
return new EnableWhenResult(((BooleanType)answer).booleanValue() != answerItems.isEmpty(), enableCondition); return new EnableWhenResult(((BooleanType) answer).booleanValue() != answerItems.isEmpty(), enableCondition);
} }
boolean result = answerItems boolean result = answerItems
.stream() .stream()
.anyMatch(answer -> evaluateAnswer(answer, enableCondition.getAnswer(), enableCondition.getOperator())); .anyMatch(answer -> evaluateAnswer(answer, enableCondition.getAnswer(), enableCondition.getOperator()));
return new EnableWhenResult(result, enableCondition); return new EnableWhenResult(result, enableCondition);
} }
@ -235,71 +228,71 @@ public class EnableWhenEvaluator {
} }
if (!actualAnswer.getClass().equals(expectedAnswer.getClass())) { if (!actualAnswer.getClass().equals(expectedAnswer.getClass())) {
throw new UnprocessableEntityException("Expected answer and actual answer have incompatible types"); throw new UnprocessableEntityException("Expected answer and actual answer have incompatible types");
} }
if (expectedAnswer instanceof Coding) { if (expectedAnswer instanceof Coding) {
return compareCodingAnswer((Coding)expectedAnswer, (Coding)actualAnswer, questionnaireItemOperator); return compareCodingAnswer((Coding) expectedAnswer, (Coding) actualAnswer, questionnaireItemOperator);
} else if ((expectedAnswer instanceof PrimitiveType)) { } else if ((expectedAnswer instanceof PrimitiveType)) {
return comparePrimitiveAnswer((PrimitiveType<?>)actualAnswer, (PrimitiveType<?>)expectedAnswer, questionnaireItemOperator); return comparePrimitiveAnswer((PrimitiveType<?>) actualAnswer, (PrimitiveType<?>) expectedAnswer, questionnaireItemOperator);
} else if (expectedAnswer instanceof Quantity) { } else if (expectedAnswer instanceof Quantity) {
return compareQuantityAnswer((Quantity)actualAnswer, (Quantity)expectedAnswer, questionnaireItemOperator); return compareQuantityAnswer((Quantity) actualAnswer, (Quantity) expectedAnswer, questionnaireItemOperator);
} }
// TODO: Attachment, reference? // TODO: Attachment, reference?
throw new UnprocessableEntityException("Unimplemented answer type: " + expectedAnswer.getClass()); throw new UnprocessableEntityException("Unimplemented answer type: " + expectedAnswer.getClass());
} }
private boolean compareQuantityAnswer(Quantity actualAnswer, Quantity expectedAnswer, QuestionnaireItemOperator questionnaireItemOperator) { private boolean compareQuantityAnswer(Quantity actualAnswer, Quantity expectedAnswer, QuestionnaireItemOperator questionnaireItemOperator) {
return compareComparable(actualAnswer.getValue(), expectedAnswer.getValue(), questionnaireItemOperator); return compareComparable(actualAnswer.getValue(), expectedAnswer.getValue(), questionnaireItemOperator);
} }
private boolean comparePrimitiveAnswer(PrimitiveType<?> actualAnswer, PrimitiveType<?> expectedAnswer, QuestionnaireItemOperator questionnaireItemOperator) { private boolean comparePrimitiveAnswer(PrimitiveType<?> actualAnswer, PrimitiveType<?> expectedAnswer, QuestionnaireItemOperator questionnaireItemOperator) {
if (actualAnswer.getValue() instanceof Comparable){ if (actualAnswer.getValue() instanceof Comparable) {
return compareComparable((Comparable<?>)actualAnswer.getValue(), (Comparable<?>) expectedAnswer.getValue(), questionnaireItemOperator); return compareComparable((Comparable<?>) actualAnswer.getValue(), (Comparable<?>) expectedAnswer.getValue(), questionnaireItemOperator);
} else if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL) {
return actualAnswer.equalsShallow(expectedAnswer); return actualAnswer.equalsShallow(expectedAnswer);
} else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL) {
return !actualAnswer.equalsShallow(expectedAnswer); return !actualAnswer.equalsShallow(expectedAnswer);
} }
throw new UnprocessableEntityException("Bad operator for PrimitiveType comparison"); throw new UnprocessableEntityException("Bad operator for PrimitiveType comparison");
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"})
private boolean compareComparable(Comparable actual, Comparable expected, private boolean compareComparable(Comparable actual, Comparable expected,
QuestionnaireItemOperator questionnaireItemOperator) { QuestionnaireItemOperator questionnaireItemOperator) {
int result = actual.compareTo(expected); int result = actual.compareTo(expected);
if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL){ if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL) {
return result == 0; return result == 0;
} else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL) {
return result != 0; return result != 0;
} else if (questionnaireItemOperator == QuestionnaireItemOperator.GREATER_OR_EQUAL){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.GREATER_OR_EQUAL) {
return result >= 0; return result >= 0;
} else if (questionnaireItemOperator == QuestionnaireItemOperator.LESS_OR_EQUAL){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.LESS_OR_EQUAL) {
return result <= 0; return result <= 0;
} else if (questionnaireItemOperator == QuestionnaireItemOperator.LESS_THAN){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.LESS_THAN) {
return result < 0; return result < 0;
} else if (questionnaireItemOperator == QuestionnaireItemOperator.GREATER_THAN){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.GREATER_THAN) {
return result > 0; return result > 0;
} }
throw new UnprocessableEntityException("Bad operator for PrimitiveType comparison: "+questionnaireItemOperator.toCode()); throw new UnprocessableEntityException("Bad operator for PrimitiveType comparison: " + questionnaireItemOperator.toCode());
} }
/** /**
* Recursively look for answers to questions with the given link id, working upwards given the context * Recursively look for answers to questions with the given link id, working upwards given the context
* * <p>
* For discussion about this, see https://chat.fhir.org/#narrow/stream/179255-questionnaire/topic/enable-when * For discussion about this, see https://chat.fhir.org/#narrow/stream/179255-questionnaire/topic/enable-when
* * <p>
- given sourceQ - question that contains the enableWhen reference and targetQ - question that the enableWhen references in the Q and also sourceA - answer for sourceQ and targetA - answer for targetQ in the QR * - given sourceQ - question that contains the enableWhen reference and targetQ - question that the enableWhen references in the Q and also sourceA - answer for sourceQ and targetA - answer for targetQ in the QR
- work up from sourceQ until you find the Q group that also contains targetQ - this is groupQ * - work up from sourceQ until you find the Q group that also contains targetQ - this is groupQ
- work up from sourceA until you find the QR group that matches groupQ - this is groupA * - work up from sourceA until you find the QR group that matches groupQ - this is groupA
- any targetA in groupA are input for the enableWhen decision * - any targetA in groupA are input for the enableWhen decision
*/ */
private List<Element> findQuestionAnswers(QStack qstack, QuestionnaireItemComponent sourceQ, QuestionnaireItemEnableWhenComponent ew) { private List<Element> findQuestionAnswers(QStack qstack, QuestionnaireItemComponent sourceQ, QuestionnaireItemEnableWhenComponent ew) {
QuestionnaireItemComponent targetQ = qstack.getQ().getQuestion(ew.getQuestion()); QuestionnaireItemComponent targetQ = qstack.getQ().getQuestion(ew.getQuestion());
if (targetQ != null) { if (targetQ != null) {
QuestionnaireItemComponent groupQ = qstack.getQ().getCommonGroup(sourceQ, targetQ); QuestionnaireItemComponent groupQ = qstack.getQ().getCommonGroup(sourceQ, targetQ);
if (groupQ == null) { // root is Q itself if (groupQ == null) { // root is Q itself
return findOnItem(qstack.getA(), ew.getQuestion()); return findOnItem(qstack.getA(), ew.getQuestion());
@ -341,16 +334,16 @@ public class EnableWhenEvaluator {
private List<Element> extractAnswer(Element item) { private List<Element> extractAnswer(Element item) {
return item.getChildrenByName(ANSWER_ELEMENT) return item.getChildrenByName(ANSWER_ELEMENT)
.stream() .stream()
.flatMap(c -> c.getChildren().stream()) .flatMap(c -> c.getChildren().stream())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private boolean compareCodingAnswer(Coding expectedAnswer, Coding actualAnswer, QuestionnaireItemOperator questionnaireItemOperator) { private boolean compareCodingAnswer(Coding expectedAnswer, Coding actualAnswer, QuestionnaireItemOperator questionnaireItemOperator) {
boolean result = compareSystems(expectedAnswer, actualAnswer) && compareCodes(expectedAnswer, actualAnswer); boolean result = compareSystems(expectedAnswer, actualAnswer) && compareCodes(expectedAnswer, actualAnswer);
if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL){ if (questionnaireItemOperator == QuestionnaireItemOperator.EQUAL) {
return result == true; return result == true;
} else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL){ } else if (questionnaireItemOperator == QuestionnaireItemOperator.NOT_EQUAL) {
return result == false; return result == false;
} }
throw new UnprocessableEntityException("Bad operator for Coding comparison"); throw new UnprocessableEntityException("Bad operator for Coding comparison");
@ -378,7 +371,7 @@ public class EnableWhenEvaluator {
private boolean hasLinkId(Element item, String linkId) { private boolean hasLinkId(Element item, String linkId) {
Element linkIdChild = item.getNamedChild(LINKID_ELEMENT); Element linkIdChild = item.getNamedChild(LINKID_ELEMENT);
if (linkIdChild != null && linkIdChild.getValue().equals(linkId)){ if (linkIdChild != null && linkIdChild.getValue().equals(linkId)) {
return true; return true;
} }
return false; return false;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation.instancevalidator; package org.hl7.fhir.validation.instance;
/*- /*-
* #%L * #%L
@ -126,11 +126,9 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.IResourceValidator; import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.validation.BaseValidator; import org.hl7.fhir.validation.BaseValidator;
import org.hl7.fhir.r5.validation.EnableWhenEvaluator; import org.hl7.fhir.validation.instance.EnableWhenEvaluator.QStack;
import org.hl7.fhir.r5.validation.EnableWhenEvaluator.QStack; import org.hl7.fhir.validation.XVerExtensionManager;
import org.hl7.fhir.r5.validation.XVerExtensionManager;
import org.hl7.fhir.r5.validation.instancevalidator.utils.*;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.Utilities.DecimalStatus; import org.hl7.fhir.utilities.Utilities.DecimalStatus;
@ -142,6 +140,7 @@ import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.validation.ValidationMessage.Source; import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
import org.hl7.fhir.utilities.xhtml.NodeType; import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.validation.instance.utils.*;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import com.google.gson.Gson; import com.google.gson.Gson;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation.instancevalidator; package org.hl7.fhir.validation.instance;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;

View File

@ -1,7 +1,7 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator; import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
public class ChildIterator { public class ChildIterator {

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.ElementDefinition; import org.hl7.fhir.r5.model.ElementDefinition;

View File

@ -1,7 +1,6 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;

View File

@ -1,8 +1,8 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator; import org.hl7.fhir.validation.instance.InstanceValidator;
public class ResolvedReference { public class ResolvedReference {

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation.instancevalidator.utils; package org.hl7.fhir.validation.instance.utils;
import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;

View File

@ -1,4 +1,4 @@
package org.hl7.fhir.r5.validation; package org.hl7.fhir.validation.profile;
/*- /*-
* #%L * #%L
@ -20,7 +20,6 @@ package org.hl7.fhir.r5.validation;
* #L% * #L%
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
@ -34,6 +33,7 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.validation.BaseValidator;
public class ProfileValidator extends BaseValidator { public class ProfileValidator extends BaseValidator {

View File

@ -2,8 +2,7 @@ package org.hl7.fhir.validation.tests;
import org.hl7.fhir.r4.context.SimpleWorkerContext; import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.validation.Validator; import org.hl7.fhir.validation.Validator;
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Test; import org.junit.Test;
public class CDAValidationTestCase { public class CDAValidationTestCase {

View File

@ -2,9 +2,7 @@ package org.hl7.fhir.validation.tests;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.validation.NativeHostServices; import org.hl7.fhir.validation.NativeHostServices;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Test; import org.junit.Test;
public class NativeHostServiceTester { public class NativeHostServiceTester {

View File

@ -1,19 +1,15 @@
package org.hl7.fhir.validation.tests; package org.hl7.fhir.validation.tests;
import java.awt.Desktop;
import java.io.File; import java.io.File;
import java.util.UUID; import java.util.UUID;
import org.hl7.fhir.r5.conformance.ProfileComparer; import org.hl7.fhir.r5.conformance.ProfileComparer;
import org.hl7.fhir.r5.model.FhirPublication; import org.hl7.fhir.r5.model.FhirPublication;
import org.hl7.fhir.r5.model.OperationOutcome;
import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.utils.KeyGenerator; import org.hl7.fhir.r5.utils.KeyGenerator;
import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.validation.ValidationEngine; import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.tests.utilities.TestUtilities; import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
public class ProfileComparisonTests { public class ProfileComparisonTests {

View File

@ -3,7 +3,7 @@ package org.hl7.fhir.validation.tests;
import java.io.File; import java.io.File;
import org.hl7.fhir.r4.test.utils.TestingUtilities; import org.hl7.fhir.r4.test.utils.TestingUtilities;
import org.hl7.fhir.r5.validation.Validator; import org.hl7.fhir.validation.Validator;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.junit.Test; import org.junit.Test;

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.validation.tests; package org.hl7.fhir.validation.tests;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -10,8 +9,7 @@ import org.hl7.fhir.r5.model.OperationOutcome;
import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity; import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent; import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.validation.ValidationEngine; import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.validation.tests.utilities.TestUtilities; import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;

View File

@ -26,8 +26,8 @@ import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.r5.utils.IResourceValidator; import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.r5.utils.IResourceValidator.IValidatorResourceFetcher; import org.hl7.fhir.r5.utils.IResourceValidator.IValidatorResourceFetcher;
import org.hl7.fhir.r5.utils.IResourceValidator.ReferenceValidationPolicy; import org.hl7.fhir.r5.utils.IResourceValidator.ReferenceValidationPolicy;
import org.hl7.fhir.r5.validation.instancevalidator.InstanceValidator; import org.hl7.fhir.validation.instance.InstanceValidator;
import org.hl7.fhir.r5.validation.ValidationEngine; import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;