Sha256: c1a614f214d4b2a82b0b0f3c68d37c9395753945d0cc2000bd871ad9a40c6b77

Contents?: true

Size: 1.72 KB

Versions: 65

Compression:

Stored size: 1.72 KB

Contents

-- Note that in the example of
-- greatest(count(cca_2_1_to_2_4), 1) we default to a 1 if count is 0 which you think
-- would ff
select
  modality_desc       modality,
  count(patient_id)   patient_count,
  round(avg(cca),2)   avg_cca,
  round(count(cca_2_1_to_2_4) / greatest(count(cca), 1.0) * 100.0, 2) pct_cca_2_1_to_2_4,
  round(count(pth_gt_300) / greatest(count(pth), 1.0) * 100.0, 2)         pct_pth_gt_300,
  round(count(pth_gt_800) / greatest(count(pth), 1.0) * 100.0, 2)         pct_pth_gt_800_pct,
  round(avg(phos),2)  avg_phos,
  max(phos)           max_phos,
  round(count(phos_lt_1_8)   / greatest(count(phos), 1.0) * 100.0, 2) pct_phos_lt_1_8

  from (
    select
    p.id patient_id,
    md.name modality_desc
    from patients p
    inner join modality_modalities m on m.patient_id = p.id
    inner join modality_descriptions md on m.description_id = md.id
  ) e1
  left join lateral (select result::decimal pth  from pathology_current_observations where description_code = 'PTH'  and patient_id = e1.patient_id) e2 ON true
  left join lateral (select result::decimal phos from pathology_current_observations where description_code = 'PHOS' and patient_id = e1.patient_id) e3 ON true
  left join lateral (select result::decimal cca  from pathology_current_observations where description_code = 'CCA'  and patient_id = e1.patient_id) e4 ON true
  left join lateral (select phos phos_lt_1_8 where phos < 1.8) e5 ON true
  left join lateral (select pth pth_gt_800 where pth > 800) e6 ON true
  left join lateral (select pth pth_gt_300 where pth > 300) e7 ON true
  left join lateral (select cca cca_2_1_to_2_4 where cca between 2.1 and 2.4) e8 ON true
  where modality_desc in ('HD','PD','Transplant', 'Low Clearance')
  group by modality_desc

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
renalware-core-2.0.58 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.57 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.56 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.55 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.54 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.53 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.52 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.51 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.50 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.48 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.47 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.46 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.45 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.44 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.43 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.42 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.41 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.40 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.39 db/views/reporting_bone_audit_v01.sql
renalware-core-2.0.38 db/views/reporting_bone_audit_v01.sql