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

#61 Use aidbox $to-format for $assemble operations #63

Merged
merged 2 commits into from
Sep 3, 2024
Merged
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
28 changes: 20 additions & 8 deletions app/aidbox/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from aiohttp import web

from app.converter import from_first_class_extension, to_first_class_extension
from app.converter.aidbox import from_first_class_extension, to_first_class_extension

from ..sdc import (
assemble,
Expand Down Expand Up @@ -30,7 +30,9 @@ async def assemble_op(request: AidboxSdcRequest):
assembled_questionnaire_lazy = await assemble(request.fhir_client, questionnaire)
assembled_questionnaire = json.loads(json.dumps(assembled_questionnaire_lazy, default=list))
if request.is_fhir:
assembled_questionnaire = from_first_class_extension(assembled_questionnaire)
assembled_questionnaire = await from_first_class_extension(
assembled_questionnaire, request.aidbox_client
)
return web.json_response(assembled_questionnaire)


Expand All @@ -40,7 +42,9 @@ async def constraint_check_operation(request: AidboxSdcRequest):
env = parameter_to_env(request.resource)

questionnaire = (
to_first_class_extension(env["Questionnaire"]) if request.is_fhir else env["Questionnaire"]
await to_first_class_extension(env["Questionnaire"], request.aidbox_client)
if request.is_fhir
else env["Questionnaire"]
)
as_root = questionnaire.get("runOnBehalfOfRoot")
client = client if as_root else get_user_sdk_client(request.request, request.client)
Expand All @@ -54,7 +58,9 @@ async def get_questionnaire_context_operation(request: AidboxSdcRequest):
env = parameter_to_env(request.resource)

questionnaire = (
to_first_class_extension(env["Questionnaire"]) if request.is_fhir else env["Questionnaire"]
await to_first_class_extension(env["Questionnaire"], request.aidbox_client)
if request.is_fhir
else env["Questionnaire"]
)
as_root = questionnaire.get("runOnBehalfOfRoot")
client = client if as_root else get_user_sdk_client(request.request, request.client)
Expand All @@ -81,7 +87,7 @@ async def extract_questionnaire_operation(request: AidboxSdcRequest):
elif resource["resourceType"] == "Parameters":
env = parameter_to_env(request.resource)
questionnaire = (
to_first_class_extension(env["Questionnaire"])
await to_first_class_extension(env["Questionnaire"], request.aidbox_client)
if request.is_fhir
else env["Questionnaire"]
)
Expand Down Expand Up @@ -147,14 +153,18 @@ async def populate_questionnaire(request: AidboxSdcRequest):
)

questionnaire = (
to_first_class_extension(env["Questionnaire"]) if request.is_fhir else env["Questionnaire"]
await to_first_class_extension(env["Questionnaire"], request.aidbox_client)
if request.is_fhir
else env["Questionnaire"]
)
as_root = questionnaire.get("runOnBehalfOfRoot")
client = request.client if as_root else get_user_sdk_client(request.request, request.client)

populated_resource = await populate(client, questionnaire, env)
if request.is_fhir:
populated_resource = from_first_class_extension(populated_resource)
populated_resource = await from_first_class_extension(
populated_resource, request.aidbox_client
)
return web.json_response(populated_resource)


Expand All @@ -172,7 +182,9 @@ async def populate_questionnaire_instance(request: AidboxSdcRequest):

populated_resource = await populate(client, questionnaire, env)
if request.is_fhir:
populated_resource = from_first_class_extension(populated_resource)
populated_resource = await from_first_class_extension(
populated_resource, request.aidbox_client
)
return web.json_response(populated_resource)


Expand Down
12 changes: 12 additions & 0 deletions app/converter/aidbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
async def from_first_class_extension(fce_resource, aidbox_client):
fhir_resource = await aidbox_client.execute(
"/$to-format/fhir", method="post", data=fce_resource, params=None
)
return fhir_resource.get("resource")


async def to_first_class_extension(fhir_resource, aidbox_client):
fce_resource = await aidbox_client.execute(
"/$to-format/aidbox", method="post", data=fhir_resource, params=None
)
return fce_resource.get("resource")
26 changes: 14 additions & 12 deletions tests/sdc/test_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,14 @@ async def test_assemble_sub_questionnaire_fhir(aidbox_client, safe_db):
"status": "active",
"resourceType": "Questionnaire",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
"valueCanonical": "StructureMap/create-another-patient",
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
"valueCanonical": "StructureMap/create-patient",
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext",
"extension": [
Expand All @@ -560,23 +568,17 @@ async def test_assemble_sub_questionnaire_fhir(aidbox_client, safe_db):
"valueCoding": {
"system": "http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext",
"code": "LaunchPatient",
"system": "http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext",
},
},
{"url": "type", "valueCode": "Patient"},
{
"url": "type",
"valueCode": "Patient",
},
],
},
{
"url": "https://jira.hl7.org/browse/FHIR-22356#assembledFrom",
"valueCanonical": q.id,
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
"valueCanonical": "StructureMap/create-another-patient",
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-targetStructureMap",
"valueCanonical": "StructureMap/create-patient",
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-assembledFrom",
"valueCanonical": q['id']
},
],
}
Loading