Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT name,
- encounter_type_id,
- CONCAT('{',
- '"report_name": "', name, '", ',
- '"flat_table_name": "', table_name, '", ',
- '"encounter_type_uuid": "', uuid, '", ',
- '"table_columns": ', json_obj, ' ',
- '}') AS json_data,
- encounter_type_uuid
- FROM (SELECT DISTINCT et.name,
- encounter_type_id,
- concat('mamba_flat_encounter_',
- LOWER(LEFT(REGEXP_REPLACE(REGEXP_REPLACE(et.name, '[^a-zA-Z0-9_ ]+', '_'), '[ _]+', '_'),
- 18))) AS table_name,
- et.uuid,
- (SELECT JSON_OBJECTAGG(name, uuid)
- FROM (SELECT DISTINCT et.encounter_type_id,
- LOWER(LEFT(REGEXP_REPLACE(REGEXP_REPLACE(cn.name, '[^a-zA-Z0-9_ ]+', '_'),
- '[ _]+', '_'), 35)) AS name,
- c.uuid
- FROM openmrs.obs o
- INNER JOIN openmrs.encounter e
- ON e.encounter_id = o.encounter_id
- INNER JOIN openmrs.encounter_type et
- ON e.encounter_type = et.encounter_type_id
- INNER JOIN openmrs.concept_name cn
- ON cn.concept_id = o.concept_id
- INNER JOIN openmrs.concept c
- ON cn.concept_id = c.concept_id
- WHERE et.name = 'Care and Treatment Service Enrolment'
- AND cn.locale = 'en'
- AND cn.voided = 0
- AND cn.locale_preferred = 1
- AND et.retired = 0) json_obj) json_obj,
- et.uuid as encounter_type_uuid
- FROM openmrs.encounter_type et
- INNER JOIN openmrs.encounter e
- ON e.encounter_type = et.encounter_type_id
- WHERE et.name = 'Care and Treatment Service Enrolment') as final;
Advertisement
Add Comment
Please, Sign In to add comment