Skip to content

Commit 27fb3ff

Browse files
committed
remove aidbox_client and utilize optional fce_converter in fhir_server/operations
1 parent 21b8987 commit 27fb3ff

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

app/fhir_server/operations.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22

3+
import aiohttp
34
from aiohttp import web
45
from fhirpy.lib import AsyncFHIRClient
56

@@ -24,14 +25,30 @@
2425
@routes.get("/Questionnaire/{id}/$assemble")
2526
async def assemble_handler(request: web.BaseRequest):
2627
client: AsyncFHIRClient = request.app["client"]
27-
aidbox_client = request.aidbox_client
28+
fce_converter_url = getattr(request.app["settings"], "FCE_CONVERTER_URL", None)
2829

2930
questionnaire = (
3031
await client.resources("Questionnaire").search(_id=request.match_info["id"]).get()
3132
)
3233

34+
if fce_converter_url:
35+
async with aiohttp.ClientSession() as session:
36+
37+
async def to_fce(fhir_resource):
38+
async with session.post(
39+
f"{fce_converter_url}/to-fce", json=dict(fhir_resource)
40+
) as resp:
41+
return await resp.json()
42+
43+
fce_questionnaire = await to_fce(dict(questionnaire))
44+
assembled_lazy = await assemble(client, fce_questionnaire, to_fce)
45+
assembled = json.loads(json.dumps(assembled_lazy, default=list))
46+
47+
async with session.post(f"{fce_converter_url}/to-fhir", json=assembled) as resp:
48+
return web.json_response(await resp.json())
49+
3350
async def get_to_first_class_extension(fhir_resource):
34-
return to_first_class_extension(fhir_resource, aidbox_client)
51+
return to_first_class_extension(fhir_resource)
3552

3653
assembled_questionnaire_lazy = await assemble(
3754
client, to_first_class_extension(questionnaire), get_to_first_class_extension

app/fhir_server/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ def __init__(self, **custom_settings):
1515
BASE_URL=os.getenv("BASE_URL", "http://devbox:8080/fhir"),
1616
AUTH_TOKEN=os.getenv("AUTH_TOKEN"),
1717
FHIRPATH_MAPPING_SERVICE=os.getenv("FHIRPATH_MAPPING_SERVICE"),
18+
FCE_CONVERTER_URL=os.getenv("FCE_CONVERTER_URL"),
1819
)

0 commit comments

Comments
 (0)