From 9118408c2645408a3df577d78ae4ffe549971a4c Mon Sep 17 00:00:00 2001 From: Brenin Rhodes Date: Tue, 29 Oct 2024 10:44:26 -0600 Subject: [PATCH 1/2] Allow for an empty context response --- .../plandefinition/apply/ApplyProcessor.java | 2 +- .../populate/ProcessItemWithContext.java | 4 +++ .../populate/ProcessItemWithContextTests.java | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/plandefinition/apply/ApplyProcessor.java b/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/plandefinition/apply/ApplyProcessor.java index a9dcf9e38..f22dccf68 100644 --- a/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/plandefinition/apply/ApplyProcessor.java +++ b/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/plandefinition/apply/ApplyProcessor.java @@ -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"); + var formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss"); request.getModelResolver() .setValue( questionnaire, diff --git a/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java b/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java index e181f425a..7b6b6c2a0 100644 --- a/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java +++ b/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java @@ -71,6 +71,10 @@ List processContextItem(PopulateRequest request, IBaseBack }) .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)) diff --git a/cqf-fhir-cr/src/test/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContextTests.java b/cqf-fhir-cr/src/test/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContextTests.java index 288463537..b9f37ce5e 100644 --- a/cqf-fhir-cr/src/test/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContextTests.java +++ b/cqf-fhir-cr/src/test/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContextTests.java @@ -8,6 +8,7 @@ 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; @@ -15,6 +16,7 @@ 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; @@ -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 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()); + } } From 71cac9bc7131c86e0a5d07deb25d062ecc35e4e4 Mon Sep 17 00:00:00 2001 From: Brenin Rhodes Date: Tue, 29 Oct 2024 11:41:59 -0600 Subject: [PATCH 2/2] add comment --- .../fhir/cr/questionnaire/populate/ProcessItemWithContext.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java b/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java index 7b6b6c2a0..87274d4c2 100644 --- a/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java +++ b/cqf-fhir-cr/src/main/java/org/opencds/cqf/fhir/cr/questionnaire/populate/ProcessItemWithContext.java @@ -69,6 +69,7 @@ List processContextItem(PopulateRequest request, IBaseBack return null; } }) + // filtering nulls here to prevent unnecessary duplicate responseItems .filter(r -> nonNull(r)) .collect(Collectors.toList()); if (populationContext.isEmpty()) {