Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OZ-630: Fixed patient attributes' values based on concepts #15

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions analytics/dsl/flattening/queries/patients.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,31 @@ SELECT
person_address.longitude AS address_longitude,
(
SELECT LISTAGG(
CONCAT_WS(': ', pa_type.name,
CONCAT_WS(
': ',
a.attribute_type_name,
a.attribute_value
), ' / '
)
FROM (
SELECT DISTINCT
pa.person_id,
pa_type.name AS attribute_type_name,
CASE
WHEN pa_type.format = 'org.openmrs.Concept' THEN cn.name
ELSE pa.`value`
END
), ' / '
)
FROM person_attribute pa
LEFT JOIN person_attribute_type pa_type ON pa.person_attribute_type_id = pa_type.person_attribute_type_id
LEFT JOIN concept c ON pa.`value` = c.uuid
LEFT JOIN concept_name cn ON c.concept_id = cn.concept_id AND cn.locale_preferred = '1' AND cn.locale = 'en' AND cn.voided = '0'
WHERE pa.person_id = patient.patient_id
END AS attribute_value
FROM
person_attribute pa
LEFT JOIN person_attribute_type pa_type ON pa.person_attribute_type_id = pa_type.person_attribute_type_id
LEFT JOIN concept c ON pa.`value` = c.uuid
LEFT JOIN concept_name cn ON c.concept_id = cn.concept_id
WHERE
pa.person_id = patient.patient_id
AND cn.locale_preferred = '1'
AND cn.locale = 'en'
AND cn.voided = '0'
) AS a
) AS attributes,
person.dead AS dead,
person.death_date AS death_date,
Expand Down