diff --git a/tests/realcases/test_empty_group_population.py b/tests/realcases/test_empty_group_population.py new file mode 100644 index 0000000..4bb09f2 --- /dev/null +++ b/tests/realcases/test_empty_group_population.py @@ -0,0 +1,81 @@ +import utils + +questionnaire_data = { + "resourceType": "Questionnaire", + "status": "active", + "launchContext": [ + { + "name": "LaunchPatient", + "type": "Patient", + "description": "The patient that is to be used to pre-populate the form", + }, + { + "name": "questionnaire", + "type": "Questionnaire", + "description": "This questionnaire template instantiation", + }, + { + "name": "RelatedResources", + "type": "Bundle", + "description": "Patient's related resources", + }, + ], + "contained": [ + { + "resourceType": "Bundle", + "id": "RelatedResources", + "type": "batch", + "entry": [ + { + "request": { + "method": "GET", + "url": "/MedicationStatement?patient={{%LaunchPatient.id}}&status=active", + } + }, + ], + } + ], + "sourceQueries": [{"localRef": "Bundle#RelatedResources"}], + "item": [ + { + "linkId": "group", + "type": "group", + "repeats": True, + "itemContext": { + "language": "text/fhirpath", + "expression": "%RelatedResources.entry[0].resource.entry.resource.medication.coding", + }, + "item": [ + { + "linkId": "top-question", + "type": "choice", + "initialExpression": { + "language": "text/fhirpath", + "expression": "where(system = 'http://snomed.info/sct')", + }, + "required": True, + "text": "What medicines do you take?", + "answerValueSet": "medication", + }, + ], + } + ], + "id": "generated", +} + + +async def test_populate(sdk, safe_db): + p = sdk.client.resource("Patient") + await p.save() + + questionnaire = sdk.client.resource("Questionnaire", **questionnaire_data) + + p = await sdk.client.execute( + "Questionnaire/$populate", + data=utils.create_parameters(LaunchPatient=p, questionnaire=questionnaire), + ) + + assert p == { + "questionnaire": "generated", + "resourceType": "QuestionnaireResponse", + } diff --git a/tests/sdc/test_populate.py b/tests/sdc/test_populate.py index a2100cc..9a637ba 100644 --- a/tests/sdc/test_populate.py +++ b/tests/sdc/test_populate.py @@ -1,10 +1,4 @@ -def create_parameters(**payload): - return { - "resourceType": "Parameters", - "parameter": [ - {"name": name, "resource": resource} for name, resource in payload.items() - ], - } +import utils async def test_initial_expression_populate(sdk, safe_db): @@ -32,7 +26,7 @@ async def test_initial_expression_populate(sdk, safe_db): launch_patient = {"resourceType": "Patient", "id": "patienit-id"} p = await q.execute( - "$populate", data=create_parameters(LaunchPatient=launch_patient) + "$populate", data=utils.create_parameters(LaunchPatient=launch_patient) ) assert p == { @@ -91,7 +85,7 @@ async def test_item_context_with_repeats_populate(sdk, safe_db): } p = await q.execute( - "$populate", data=create_parameters(LaunchPatient=launch_patient) + "$populate", data=utils.create_parameters(LaunchPatient=launch_patient) ) assert p == { @@ -187,7 +181,7 @@ async def test_item_context_without_repeats_populate(sdk, safe_db): } p = await q.execute( - "$populate", data=create_parameters(LaunchPatient=launch_patient) + "$populate", data=utils.create_parameters(LaunchPatient=launch_patient) ) assert p == { @@ -279,7 +273,7 @@ async def test_source_queries_populate(sdk, safe_db): await q.save() - p = await q.execute("$populate", data=create_parameters(LaunchPatient=p)) + p = await q.execute("$populate", data=utils.create_parameters(LaunchPatient=p)) assert p == { "resourceType": "QuestionnaireResponse", @@ -360,7 +354,7 @@ async def test_multiple_answers_populate(sdk, safe_db): ], } - p = await q.execute("$populate", data=create_parameters(Diet=diet)) + p = await q.execute("$populate", data=utils.create_parameters(Diet=diet)) assert p == { "resourceType": "QuestionnaireResponse", diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..419efd4 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,7 @@ +def create_parameters(**payload): + return { + "resourceType": "Parameters", + "parameter": [ + {"name": name, "resource": resource} for name, resource in payload.items() + ], + }