Skip to content

Commit e6c48b4

Browse files
committed
fix: display of DST crossing interval
1 parent 5a396d0 commit e6c48b4

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

apps/viz-backend/app/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import re
3-
from typing import List
3+
from typing import List, cast
44

55
from database import SessionLocal
66
from fastapi import Depends, FastAPI, HTTPException, Query
@@ -193,6 +193,7 @@ def get_intervals(
193193
"columns": [
194194
"measurement_datetime",
195195
"value_as_number",
196+
"value_as_concept_id",
196197
"unit_concept_id",
197198
"measurement_source_value",
198199
"unit_source_value",
@@ -226,6 +227,7 @@ def get_intervals(
226227
"columns": [
227228
"observation_datetime",
228229
"value_as_number",
230+
"value_as_concept_id",
229231
"observation_source_value",
230232
"observation_source_concept_id",
231233
],
@@ -286,11 +288,19 @@ async def get_patient_data(person_id: str, db: Session = Depends(get_db)) -> dic
286288
for table_name in tables:
287289

288290
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+
289298
query = text(
290299
f"""
291-
SELECT t.*, c.concept_name, c.concept_id
300+
SELECT t.*, c.concept_name, c.concept_id {select_additional}
292301
FROM {data_schema}.{table_name} as t
293302
JOIN {data_schema}.concept c ON t.{table['concept_id']} = c.concept_id
303+
{join_additional}
294304
WHERE person_id = :person_id""" # nosec: result_schema and data_schema are checked above (is_valid_identifier)
295305
)
296306

@@ -314,7 +324,7 @@ async def get_concepts(
314324
"""
315325

316326
table = tables[table_name]
317-
columns = []
327+
columns: list[str] = [cast(str, table["concept_id"])]
318328
concept_joins: list[str] = []
319329

320330
for column in table["columns"]:

apps/viz-frontend/src/PatientPlots.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ const generateTraceKey = (interval) => {
1212
return `[${interval.cohort_category}]` + (descriptionPart ? ` ${descriptionPart}` : '');
1313
};
1414

15+
16+
function getDSTAdjustedDuration(startStr, endStr) {
17+
const start = new Date(startStr);
18+
const end = new Date(endStr);
19+
20+
let durationMs = end - start;
21+
22+
// Adjust for DST shift if needed
23+
const offsetDiffMinutes = start.getTimezoneOffset() - end.getTimezoneOffset();
24+
const offsetDiffMs = offsetDiffMinutes * 60 * 1000;
25+
26+
return durationMs + offsetDiffMs;
27+
}
28+
29+
1530
const PatientPlots = ({ runId, personId, personSourceValue, selectedDate }) => {
1631
const [patientData, setPatientData] = useState([]);
1732

@@ -64,7 +79,7 @@ const PatientPlots = ({ runId, personId, personSourceValue, selectedDate }) => {
6479
};
6580
}
6681

67-
const duration = new Date(interval.interval_end) - new Date(interval.interval_start);
82+
const duration = getDSTAdjustedDuration(interval.interval_start, interval.interval_end);
6883

6984
traceMap[traceKey].base.push(new Date(interval.interval_start));
7085
traceMap[traceKey].x.push(Math.max(duration, 20000));

0 commit comments

Comments
 (0)