Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
81 changes: 81 additions & 0 deletions tests/realcases/test_empty_group_population.py
Original file line number Diff line number Diff line change
@@ -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",
}
18 changes: 6 additions & 12 deletions tests/sdc/test_populate.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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 == {
Expand Down Expand Up @@ -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 == {
Expand Down Expand Up @@ -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 == {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def create_parameters(**payload):
return {
"resourceType": "Parameters",
"parameter": [
{"name": name, "resource": resource} for name, resource in payload.items()
],
}