Unit tests up to date and maybe we need to use r4 path
This commit is contained in:
parent
b0635a91cd
commit
c67554e5aa
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<artifactId>hapi-fhir-converter</artifactId>
|
<artifactId>hapi-fhir-converter</artifactId>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<version>3.5.1-PHRFIX-SNAPSHOT</version>
|
<version>3.6.1-PHRFIX-SNAPSHOT</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-client</artifactId>
|
<artifactId>hapi-fhir-client</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<artifactId>hapi-fhir-validation</artifactId>
|
<artifactId>hapi-fhir-validation</artifactId>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<version>3.5.1-PHRFIX-SNAPSHOT</version>
|
<version>3.6.1-PHRFIX-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>HAPI FHIR - Validation</name>
|
<name>HAPI FHIR - Validation</name>
|
||||||
|
|
||||||
|
@ -19,17 +19,17 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-base</artifactId>
|
<artifactId>hapi-fhir-base</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-utilities</artifactId>
|
<artifactId>hapi-fhir-utilities</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-converter</artifactId>
|
<artifactId>hapi-fhir-converter</artifactId>
|
||||||
<version>3.5.1-PHRFIX-SNAPSHOT</version>
|
<version>3.6.1-PHRFIX-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -64,49 +64,49 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-structures-dstu2</artifactId>
|
<artifactId>hapi-fhir-structures-dstu2</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
|
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-structures-dstu2.1</artifactId>
|
<artifactId>hapi-fhir-structures-dstu2.1</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-validation-resources-dstu2</artifactId>
|
<artifactId>hapi-fhir-validation-resources-dstu2</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-structures-dstu3</artifactId>
|
<artifactId>hapi-fhir-structures-dstu3</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
|
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-structures-r4</artifactId>
|
<artifactId>hapi-fhir-structures-r4</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
|
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -119,13 +119,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-server</artifactId>
|
<artifactId>hapi-fhir-server</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ca.uhn.hapi.fhir</groupId>
|
<groupId>ca.uhn.hapi.fhir</groupId>
|
||||||
<artifactId>hapi-fhir-client</artifactId>
|
<artifactId>hapi-fhir-client</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -36,6 +36,8 @@ import org.hl7.fhir.dstu3.model.Type;
|
||||||
import org.hl7.fhir.dstu3.model.UriType;
|
import org.hl7.fhir.dstu3.model.UriType;
|
||||||
import org.hl7.fhir.dstu3.model.ValueSet;
|
import org.hl7.fhir.dstu3.model.ValueSet;
|
||||||
import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent;
|
import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent;
|
||||||
|
import org.hl7.fhir.instance.validation.DefaultEnableWhenEvaluator;
|
||||||
|
import org.hl7.fhir.instance.validation.IEnableWhenEvaluator;
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
package org.hl7.fhir.instance.validation;
|
||||||
|
|
||||||
|
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemEnableWhenComponent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
|
||||||
|
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
|
||||||
|
import org.hl7.fhir.r4.elementmodel.Element;
|
||||||
|
|
||||||
|
public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isQuestionEnabled(QuestionnaireItemComponent item, List<QuestionnaireResponseItemComponent> resp) {
|
||||||
|
|
||||||
|
boolean enabled = true;
|
||||||
|
|
||||||
|
if(item.hasEnableWhen()) {
|
||||||
|
|
||||||
|
enabled = false;
|
||||||
|
|
||||||
|
for( QuestionnaireItemEnableWhenComponent enable : item.getEnableWhen()) {
|
||||||
|
|
||||||
|
if(enable.getHasAnswer()) {
|
||||||
|
// check if referenced question has answer
|
||||||
|
|
||||||
|
String itemId = enable.getQuestion();
|
||||||
|
|
||||||
|
for(QuestionnaireResponseItemComponent respItem : resp) {
|
||||||
|
if(respItem.getLinkId().equalsIgnoreCase(itemId) && respItem.hasAnswer()) {
|
||||||
|
|
||||||
|
//TODO check answer value
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// and if not
|
||||||
|
|
||||||
|
String itemId = enable.getQuestion();
|
||||||
|
|
||||||
|
for(QuestionnaireResponseItemComponent respItem : resp) {
|
||||||
|
if(respItem.getLinkId().equalsIgnoreCase(itemId) && !respItem.hasAnswer()) {
|
||||||
|
|
||||||
|
//TODO check answer value
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isQuestionEnabled(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent item,
|
||||||
|
Element element) {
|
||||||
|
boolean enabled = true;
|
||||||
|
|
||||||
|
if(item.hasEnableWhen()) {
|
||||||
|
|
||||||
|
enabled = false;
|
||||||
|
|
||||||
|
for( org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemEnableWhenComponent enable : item.getEnableWhen()) {
|
||||||
|
|
||||||
|
if(enable.hasAnswer()) {
|
||||||
|
// check if referenced question has answer
|
||||||
|
|
||||||
|
String itemId = enable.getQuestion();
|
||||||
|
|
||||||
|
List<Element> items = new ArrayList<Element>();
|
||||||
|
element.getNamedChildren("item", items);
|
||||||
|
|
||||||
|
for(Element respItem : items) {
|
||||||
|
|
||||||
|
// TODO toteuta uudelleen
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// and if not
|
||||||
|
|
||||||
|
String itemId = enable.getQuestion();
|
||||||
|
|
||||||
|
List<Element> items = new ArrayList<Element>();
|
||||||
|
element.getNamedChildren("item", items);
|
||||||
|
|
||||||
|
for(Element respItem : items) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.hl7.fhir.instance.validation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
|
||||||
|
import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
|
||||||
|
import org.hl7.fhir.r4.elementmodel.Element;
|
||||||
|
|
||||||
|
public interface IEnableWhenEvaluator {
|
||||||
|
|
||||||
|
public boolean isQuestionEnabled(QuestionnaireItemComponent item, List<QuestionnaireResponseItemComponent> theResponseItems);
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isQuestionEnabled(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent qItem,
|
||||||
|
Element element);
|
||||||
|
|
||||||
|
}
|
|
@ -5,11 +5,15 @@ import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.hl7.fhir.r4.model.Reference;
|
||||||
|
import org.hl7.fhir.exceptions.*;
|
||||||
import org.hl7.fhir.convertors.VersionConvertorConstants;
|
import org.hl7.fhir.convertors.VersionConvertorConstants;
|
||||||
import org.hl7.fhir.exceptions.DefinitionException;
|
import org.hl7.fhir.exceptions.DefinitionException;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.exceptions.PathEngineException;
|
import org.hl7.fhir.exceptions.PathEngineException;
|
||||||
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
||||||
|
import org.hl7.fhir.instance.validation.DefaultEnableWhenEvaluator;
|
||||||
|
import org.hl7.fhir.instance.validation.IEnableWhenEvaluator;
|
||||||
import org.hl7.fhir.r4.conformance.ProfileUtilities;
|
import org.hl7.fhir.r4.conformance.ProfileUtilities;
|
||||||
import org.hl7.fhir.r4.context.IWorkerContext;
|
import org.hl7.fhir.r4.context.IWorkerContext;
|
||||||
import org.hl7.fhir.r4.context.IWorkerContext.ValidationResult;
|
import org.hl7.fhir.r4.context.IWorkerContext.ValidationResult;
|
||||||
|
@ -198,6 +202,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
private IEvaluationContext externalHostServices;
|
private IEvaluationContext externalHostServices;
|
||||||
private boolean noExtensibleWarnings;
|
private boolean noExtensibleWarnings;
|
||||||
private String serverBase;
|
private String serverBase;
|
||||||
|
|
||||||
|
private IEnableWhenEvaluator myEnableWhenEvaluator = new DefaultEnableWhenEvaluator();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keeps track of whether a particular profile has been checked or not yet
|
* Keeps track of whether a particular profile has been checked or not yet
|
||||||
|
@ -2777,9 +2783,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
|
||||||
List<Element> mapItem = map.get(qItem.getLinkId());
|
List<Element> mapItem = map.get(qItem.getLinkId());
|
||||||
if (mapItem != null)
|
if (mapItem != null)
|
||||||
validateQuestionannaireResponseItem(qsrc, qItem, errors, mapItem, stack, inProgress);
|
validateQuestionannaireResponseItem(qsrc, qItem, errors, mapItem, stack, inProgress);
|
||||||
else
|
else {
|
||||||
rule(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), !qItem.getRequired(), "No response found for required item "+qItem.getLinkId());
|
//item is missing, is the question enabled?
|
||||||
}
|
if(! myEnableWhenEvaluator.isQuestionEnabled(qItem, element)) {
|
||||||
|
|
||||||
|
rule(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), !qItem.getRequired(), "No response found for required item "+qItem.getLinkId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateQuestionnaireResponseItemQuantity( List<ValidationMessage> errors, Element answer, NodeStack stack) {
|
private void validateQuestionnaireResponseItemQuantity( List<ValidationMessage> errors, Element answer, NodeStack stack) {
|
||||||
|
|
|
@ -348,10 +348,6 @@ public class QuestionnaireResponseValidatorDstu3Test {
|
||||||
enable.setQuestion("link0");
|
enable.setQuestion("link0");
|
||||||
enable.setHasAnswer(true);
|
enable.setHasAnswer(true);
|
||||||
|
|
||||||
|
|
||||||
//q.getItemFirstRep().addEnableWhen().
|
|
||||||
//q.addItem().setLinkId("link1").setRequired(true).setType(QuestionnaireItemType.STRING);
|
|
||||||
|
|
||||||
QuestionnaireResponse qa = new QuestionnaireResponse();
|
QuestionnaireResponse qa = new QuestionnaireResponse();
|
||||||
qa.setStatus(QuestionnaireResponseStatus.COMPLETED);
|
qa.setStatus(QuestionnaireResponseStatus.COMPLETED);
|
||||||
qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1");
|
qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1");
|
||||||
|
|
Loading…
Reference in New Issue