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.1.1 db/views/pathology_observation_digests_v01.sql
renalware-core-2.1.0 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.167 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.166 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.165 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.164 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.163 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.162 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.161 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.160 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.159 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.158 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.157 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.156 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.155 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.153 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.152 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.151 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.149 db/views/pathology_observation_digests_v01.sql
renalware-core-2.0.148 db/views/pathology_observation_digests_v01.sql