Files
medreport_mrb2b/supabase/sql/analysis.sql
2025-07-15 17:12:52 +03:00

147 lines
3.2 KiB
SQL

-- Create analysis for /home/analysis-results
INSERT INTO medreport.analysis_groups (
id,
original_id,
name,
"order",
created_at,
updated_at
)
VALUES (
1, -- id
'GROUP_ORIG_001', -- original_id
'Blood Tests', -- name
1, -- order
NOW(), -- created_at
NOW() -- updated_at
);
INSERT INTO medreport.analysis_elements (
id,
analysis_id_oid,
analysis_id_original,
tehik_short_loinc,
tehik_loinc_name,
analysis_name_lab,
"order",
created_at,
updated_at,
parent_analysis_group_id,
material_groups
)
VALUES (
1, -- id (must match the one used in analyses)
'OID12345', -- analysis_id_oid
'ORIG123', -- analysis_id_original
'LNC123-4', -- tehik_short_loinc
'Hemoglobiin', -- tehik_loinc_name
'Hemoglobiin (Lab)', -- analysis_name_lab
1, -- order
NOW(), -- created_at
NOW(), -- updated_at
1, -- parent_analysis_group_id
'{}'::jsonb[] -- material_groups (empty array for now)
);
INSERT INTO medreport.analyses (
id,
analysis_id_oid,
analysis_id_original,
tehik_short_loinc,
tehik_loinc_name,
analysis_name_lab,
"order",
created_at,
updated_at,
parent_analysis_element_id
)
VALUES (
101, -- id
'OID12345', -- analysis_id_oid
'ORIG123', -- analysis_id_original
'LNC123-4', -- tehik_short_loinc
'Hemoglobiin', -- tehik_loinc_name
'Hemoglobiin (Lab)', -- analysis_name_lab
1, -- order
NOW(), -- created_at
NOW(), -- updated_at
1 -- parent_analysis_element_id
);
INSERT INTO medreport.analysis_orders (
analysis_element_ids,
analysis_ids,
user_id,
status,
id
) VALUES (
ARRAY[1, 2, 3],
ARRAY[101, 102],
'8dcb4354-77be-4915-a2cd-8fc573e675d6',
'COMPLETED',
'10' -- unique id
);
INSERT INTO medreport.analysis_responses (
id,
analysis_order_id,
order_number,
order_status,
user_id
)
VALUES (
'1', -- unique id
'10', -- ID of medreport.analysis_orders
'123',
'COMPLETED',
'8dcb4354-77be-4915-a2cd-8fc573e675d6'
)
ON CONFLICT (order_number)
DO UPDATE SET
analysis_order_id = EXCLUDED.analysis_order_id,
order_status = EXCLUDED.order_status,
user_id = EXCLUDED.user_id
RETURNING id;
INSERT INTO medreport.analysis_response_elements (
id,
analysis_response_id,
analysis_element_original_id,
unit,
response_value,
response_time,
norm_upper,
norm_upper_included,
norm_lower,
norm_lower_included,
norm_status,
original_response_element,
created_at,
updated_at,
analysis_name
)
VALUES
-- Repeat this row for each element
(
'1000', -- unique id
'1', -- ID of medreport.analysis_responses
'2',
'g/L',
146,
NOW()::timestamptz,
5,
true,
1,
false,
3,
'{"original_name": "Hgb", "value": 13.5}'::jsonb,
NOW(),
NOW(),
'Hematokrit'
);