Sha256: bb420e6dea04adf92833a71bb3fcb49254a1878d3da72708ec1daef743ac1e1a

Contents?: true

Size: 854 Bytes

Versions: 56

Compression:

Stored size: 854 Bytes

Contents

/*
Returns a jsonb hash of OBX results for each day a patient had an observation.

Example output:

patient_id  observation_date  observations
------------------------------------------
1           2018-02-02        {"CYA": "14"}
1           2016-06-15        {"CMVD": "0.10"}
1           2016-03-15        {"NA": "137", "TP": "74", "ALB": "48", "ALP": "71", ...
1           2016-02-29        {"NA": "136", "TP": "78", "ALB": "47", "ALP": "71", ...
*/

select obs_req.patient_id, cast(observed_at as date) as observed_on,
jsonb_object_agg(obs_desc.code, obs.result) results
from pathology_observations obs
inner join pathology_observation_requests obs_req on obs.request_id = obs_req.id
inner join pathology_observation_descriptions obs_desc on obs.description_id = obs_desc.id
group by patient_id, observed_on
order by patient_id asc, observed_on desc;

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
renalware-core-2.0.147 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.146 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.145 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.144 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.143 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.142 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.141 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.140 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.139 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.138 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.137 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.136 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.135 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.134 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.133 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.132 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.131 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.130 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.129 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.128 db/views/pathology_observation_digests_v01.sql