Unit tests up to date and maybe we need to use r4 path

This commit is contained in:
Eeva Turkka 2018-11-02 15:54:34 +02:00
parent 15610c9498
commit 92936d6889
5 changed files with 72 additions and 9 deletions

View File

@ -36,6 +36,8 @@ import org.hl7.fhir.dstu3.model.Type;
import org.hl7.fhir.dstu3.model.UriType;
import org.hl7.fhir.dstu3.model.ValueSet;
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.IssueType;

View File

@ -1,12 +1,14 @@
package org.hl7.fhir.dstu3.validation;
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 {
@ -54,6 +56,54 @@ public class DefaultEnableWhenEvaluator implements IEnableWhenEvaluator {
}
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;
}

View File

@ -1,13 +1,18 @@
package org.hl7.fhir.dstu3.validation;
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);
}

View File

@ -10,6 +10,8 @@ import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.PathEngineException;
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.context.IWorkerContext;
import org.hl7.fhir.r4.context.IWorkerContext.ValidationResult;
@ -198,6 +200,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
private IEvaluationContext externalHostServices;
private boolean noExtensibleWarnings;
private String serverBase;
private IEnableWhenEvaluator myEnableWhenEvaluator = new DefaultEnableWhenEvaluator();
/*
* Keeps track of whether a particular profile has been checked or not yet
@ -2777,9 +2782,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
List<Element> mapItem = map.get(qItem.getLinkId());
if (mapItem != null)
validateQuestionannaireResponseItem(qsrc, qItem, errors, mapItem, stack, inProgress);
else
rule(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), !qItem.getRequired(), "No response found for required item "+qItem.getLinkId());
}
else {
//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) {

View File

@ -348,10 +348,6 @@ public class QuestionnaireResponseValidatorDstu3Test {
enable.setQuestion("link0");
enable.setHasAnswer(true);
//q.getItemFirstRep().addEnableWhen().
//q.addItem().setLinkId("link1").setRequired(true).setType(QuestionnaireItemType.STRING);
QuestionnaireResponse qa = new QuestionnaireResponse();
qa.setStatus(QuestionnaireResponseStatus.COMPLETED);
qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1");