Changes between Version 3 and Version 4 of AdvancedQueries


Ignore:
Timestamp:
08/25/25 13:17:25 (8 days ago)
Author:
221007
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedQueries

    v3 v4  
    284284  );
    285285}}}
     286
     287
     288=== Квери кое ги влече пациентите со слични дијагнози
     289
     290{{{
     291with selected_person_diagnosis as(
     292    select distinct d.diagnosis_id as diagnosis_id, d.short_description as label
     293    from person p
     294             join report r on r.person_id = p.person_id
     295             join medicalreport_diagnosis mrd on mrd.report_id = r.report_id
     296             join diagnosis d on mrd.diagnosis_id = d.diagnosis_id
     297    where p.person_id = 14 --parameter (the most of them are person_id = 1)
     298)
     299select cast(p2.person_id as bigint),
     300       p2.name || ' ' || p2.surname as full_name,
     301       cast(count(distinct spd.diagnosis_id) as bigint) as matching_diagnoses_count,
     302       string_agg(distinct spd.label, ', ') as matching_labels
     303from selected_person_diagnosis spd
     304         join medicalreport_diagnosis mrd2 on mrd2.diagnosis_id = spd.diagnosis_id
     305         join report r2 on r2.report_id = mrd2.report_id
     306         join person p2 on p2.person_id = r2.person_id
     307where p2.person_id != 14 --parameter of the person
     308group by p2.person_id, p2.name, p2.surname
     309having count(distinct spd.diagnosis_id) >=1
     310order by matching_diagnoses_count desc;
     311}}}