Skip to content

Commit 8828ebe

Browse files
committed
Load avaiable resource types with fhir-schema
1 parent d3cc67b commit 8828ebe

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

aidbox_python_sdk/db.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,21 @@ async def alchemy(self, statement, *, execute=False):
136136
return await self.raw_sql(query, execute=execute)
137137

138138
async def _get_all_entities_name(self):
139-
# TODO: refactor using StructureDefintion
139+
result = None
140+
141+
#Support legacy instalations with entity attribute data structure
140142
query_url = f"{self._settings.APP_INIT_URL}/Entity?type=resource&_elements=id&_count=999"
141143
async with self._client.get(query_url) as resp:
142144
json_resp = await resp.json()
143-
return [entry["resource"]["id"] for entry in json_resp.get("entry", [])]
145+
result = [entry["resource"]["id"] for entry in json_resp.get("entry", [])]
146+
147+
if result is None or len(result) == []:
148+
# Load resource type from fhir schema
149+
query_url = f"{self._settings.APP_INIT_URL}/$resource-types"
150+
async with self._client.get(query_url) as resp:
151+
json_resp = await resp.json()
152+
result = list(json_resp.keys())
153+
return result or []
144154

145155
async def _init_table_cache(self):
146156
table_names = await self._get_all_entities_name()

0 commit comments

Comments
 (0)