Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $populate issue with missing responseItems for a null population context #569

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected void initApply(ApplyRequest request) {
var version = request.resolvePathString(request.getPlanDefinition(), "version");
if (version != null) {
var subject = request.getSubjectId().getIdPart();
var formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ssZ");
barhodes marked this conversation as resolved.
Show resolved Hide resolved
var formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss");
request.getModelResolver()
.setValue(
questionnaire,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ List<IBaseBackboneElement> processContextItem(PopulateRequest request, IBaseBack
return null;
}
})
// filtering nulls here to prevent unnecessary duplicate responseItems
.filter(r -> nonNull(r))
.collect(Collectors.toList());
if (populationContext.isEmpty()) {
// We always want to return a responseItem even if we have nothing to populate
populationContext.add(null);
}
return populationContext.stream()
.map(context ->
processPopulationContext(request, item, contextExpression.getName(), context, profileAdapter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Questionnaire;
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent;
import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -74,4 +76,28 @@ void testMissingProfileLogsException() {
assertTrue(operationOutcome.hasIssue());
assertEquals(2, operationOutcome.getIssue().size());
}

@Test
void testNoContextStillReturnsResponseItem() {
var questionnaire = new Questionnaire();
doReturn(FhirContext.forR4Cached()).when(repository).fhirContext();
var populateRequest = newPopulateRequestForVersion(FhirVersionEnum.R4, libraryEngine, questionnaire);
var questionnaireItem = new QuestionnaireItemComponent()
.setLinkId("1")
.setDefinition("http://hl7.org/fhir/Patient#Patient.name.given");
var extensions = Arrays.asList(new Extension(Constants.SDC_QUESTIONNAIRE_ITEM_POPULATION_CONTEXT));
questionnaireItem.setExtension(extensions);
var expression = new CqfExpression().setLanguage("text/cql").setExpression("%subject.name.given[0]");
List<IBase> expressionResults = new ArrayList<>();
doReturn(expression)
.when(expressionProcessor)
.getCqfExpression(populateRequest, extensions, Constants.SDC_QUESTIONNAIRE_ITEM_POPULATION_CONTEXT);
doReturn(expressionResults)
.when(expressionProcessor)
.getExpressionResultForItem(populateRequest, expression, "1");
var actual = processItemWithContext.processContextItem(populateRequest, questionnaireItem);
assertEquals(1, actual.size());
assertTrue(
((QuestionnaireResponseItemComponent) actual.get(0)).getAnswer().isEmpty());
}
}