SQL queries to look for missing questions

Check Questions For Missing Enumerators

This query checks if active version questions are bound to enumerators that are missing. The is_enumerator_missing column will be true if the enumerator does not exist in the questions table.

select
    v.id as versions_id,
    v.lifecycle_stage as versions_lifecycle_stage,
    q.id as questions_id,
    q.name as question_name,
    q.question_type,
    q.enumerator_id,
    case when eq.id is null then true else false end as is_enumerator_missing
from questions as q
inner join versions_questions as vq
    on vq.questions_id = q.id
inner join versions as v
    on vq.versions_id = v.id
left join questions as eq
    on q.enumerator_id = eq.id
where q.enumerator_id is not null
and eq.id is null
and v.lifecycle_stage = 'active'
order by v.id desc

Check Programs for Missing Questions

This query flattens out the program block_definitions json. The debug_notes column will provide a message describing problems that were found.

The query debug_notes currently checks if

  • questionDefinition points to a question that doesn't exist

  • questionDefinition enumerator points to a question that doesn't exist

  • hidePredicate points to a question that doesn't exist

Last updated

Was this helpful?