Skip to content

Commit

Permalink
Use aidbox $to-fromat for $assemble operations
Browse files Browse the repository at this point in the history
Ref #61
  • Loading branch information
qscgyjqscgyj committed Sep 2, 2024
1 parent 0118476 commit e66bac7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
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")
27 changes: 13 additions & 14 deletions tests/sdc/test_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,16 @@ async def test_assemble_sub_questionnaire_fhir(aidbox_client, safe_db):
],
"status": "active",
"resourceType": "Questionnaire",
"assembledFrom": q['id'],
"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 +569,13 @@ 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",
},
],
}

0 comments on commit e66bac7

Please sign in to comment.