1
1
import json
2
2
import re
3
- from typing import List
3
+ from typing import List , cast
4
4
5
5
from database import SessionLocal
6
6
from fastapi import Depends , FastAPI , HTTPException , Query
@@ -193,6 +193,7 @@ def get_intervals(
193
193
"columns" : [
194
194
"measurement_datetime" ,
195
195
"value_as_number" ,
196
+ "value_as_concept_id" ,
196
197
"unit_concept_id" ,
197
198
"measurement_source_value" ,
198
199
"unit_source_value" ,
@@ -226,6 +227,7 @@ def get_intervals(
226
227
"columns" : [
227
228
"observation_datetime" ,
228
229
"value_as_number" ,
230
+ "value_as_concept_id" ,
229
231
"observation_source_value" ,
230
232
"observation_source_concept_id" ,
231
233
],
@@ -286,11 +288,19 @@ async def get_patient_data(person_id: str, db: Session = Depends(get_db)) -> dic
286
288
for table_name in tables :
287
289
288
290
table = tables [table_name ]
291
+ select_additional = ""
292
+ join_additional = ""
293
+
294
+ if "value_as_concept_id" in table ["columns" ]:
295
+ select_additional = ", c_value.concept_name as value_concept_name"
296
+ join_additional = f"LEFT JOIN { data_schema } .concept c_value ON t.value_as_concept_id = c_value.concept_id"
297
+
289
298
query = text (
290
299
f"""
291
- SELECT t.*, c.concept_name, c.concept_id
300
+ SELECT t.*, c.concept_name, c.concept_id { select_additional }
292
301
FROM { data_schema } .{ table_name } as t
293
302
JOIN { data_schema } .concept c ON t.{ table ['concept_id' ]} = c.concept_id
303
+ { join_additional }
294
304
WHERE person_id = :person_id""" # nosec: result_schema and data_schema are checked above (is_valid_identifier)
295
305
)
296
306
@@ -314,7 +324,7 @@ async def get_concepts(
314
324
"""
315
325
316
326
table = tables [table_name ]
317
- columns = []
327
+ columns : list [ str ] = [cast ( str , table [ "concept_id" ]) ]
318
328
concept_joins : list [str ] = []
319
329
320
330
for column in table ["columns" ]:
0 commit comments