Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tblock79 committed Aug 28, 2024
1 parent 615f39c commit 686ea40
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions bookkeeping/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,50 +205,50 @@ async def find_task(request) -> JSONResponse:
if study_filter=="true":
study_filter_term = "and tasks.study_uid is not null"

# query_string = f"""select max(a.acc) as acc, max(a.mrn) as mrn, max(a.task_id) as task_id, max(a.scope) as scope, max(a.time) as time,
# string_agg(b.data->'info'->>'applied_rule', ', ' order by b.id) as rule,
# string_agg(b.data->'info'->>'triggered_rules', ',' order by b.id) as triggered_rules
# from (select tasks.id as task_id,
# tag_accessionnumber as acc,
# tag_patientid as mrn,
# data->'info'->>'uid_type' as scope,
# tasks.time::timestamp {tz_conversion} as time
# from tasks
# left join dicom_series on dicom_series.series_uid = tasks.series_uid
# where parent_id is null {filter_term} {study_filter_term}
# order by date_trunc('second', tasks.time) desc, tasks.id desc
# limit 512) a
# left join tasks b on (b.parent_id = a.task_id or b.id = a.task_id)
# group by a.task_id
# order by max(a.time) desc
# """

query_string = f"""WITH task_data AS (
SELECT
tasks.id AS task_id,
tag_accessionnumber AS acc,
tag_patientid AS mrn,
data->'info'->>'uid_type' AS scope,
tasks.time::timestamp {tz_conversion} AS time
FROM tasks
LEFT JOIN dicom_series ON dicom_series.series_uid = tasks.series_uid
WHERE parent_id IS NULL {filter_term} {study_filter_term}
ORDER BY tasks.time DESC, tasks.id DESC
LIMIT 512
)
SELECT
MAX(a.acc) AS acc,
MAX(a.mrn) AS mrn,
MAX(a.task_id) AS task_id,
MAX(a.scope) AS scope,
MAX(a.time) AS time,
STRING_AGG(b.data->'info'->>'applied_rule', ', ' ORDER BY b.id) AS rule,
STRING_AGG(b.data->'info'->>'triggered_rules', ',' ORDER BY b.id) AS triggered_rules
FROM task_data a
LEFT JOIN tasks b ON (b.parent_id = a.task_id OR b.id = a.task_id)
GROUP BY a.task_id
ORDER BY MAX(a.time) DESC;
query_string = f"""select max(a.acc) as acc, max(a.mrn) as mrn, max(a.task_id) as task_id, max(a.scope) as scope, max(a.time) as time,
string_agg(b.data->'info'->>'applied_rule', ', ' order by b.id) as rule,
string_agg(b.data->'info'->>'triggered_rules', ',' order by b.id) as triggered_rules
from (select tasks.id as task_id,
tag_accessionnumber as acc,
tag_patientid as mrn,
data->'info'->>'uid_type' as scope,
tasks.time::timestamp {tz_conversion} as time
from tasks
left join dicom_series on dicom_series.series_uid = tasks.series_uid
where parent_id is null {filter_term} {study_filter_term}
order by date_trunc('second', tasks.time) desc, tasks.id desc
limit 512) a
left join tasks b on (b.parent_id = a.task_id or b.id = a.task_id)
group by a.task_id
order by max(a.time) desc
"""

# query_string = f"""WITH task_data AS (
# SELECT
# tasks.id AS task_id,
# tag_accessionnumber AS acc,
# tag_patientid AS mrn,
# data->'info'->>'uid_type' AS scope,
# tasks.time::timestamp {tz_conversion} AS time
# FROM tasks
# LEFT JOIN dicom_series ON dicom_series.series_uid = tasks.series_uid
# WHERE parent_id IS NULL {filter_term} {study_filter_term}
# ORDER BY tasks.time DESC, tasks.id DESC
# LIMIT 512
# )
# SELECT
# MAX(a.acc) AS acc,
# MAX(a.mrn) AS mrn,
# MAX(a.task_id) AS task_id,
# MAX(a.scope) AS scope,
# MAX(a.time) AS time,
# STRING_AGG(b.data->'info'->>'applied_rule', ', ' ORDER BY b.id) AS rule,
# STRING_AGG(b.data->'info'->>'triggered_rules', ',' ORDER BY b.id) AS triggered_rules
# FROM task_data a
# LEFT JOIN tasks b ON (b.parent_id = a.task_id OR b.id = a.task_id)
# GROUP BY a.task_id
# ORDER BY MAX(a.time) DESC;
# """
#print(query_string)
query = sqlalchemy.text(query_string)

Expand Down

0 comments on commit 686ea40

Please sign in to comment.