-
Notifications
You must be signed in to change notification settings - Fork 2
(report) Add TX_CURR report #32
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
Changes from 4 commits
140e55a
170ba23
83f810d
a7cb43f
ac44d4f
38315c5
1ac432f
6626cb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||||||||||||||
| SELECT DISTINCT p.patient_id | ||||||||||||||||||||||||||||||||||||||||||
| FROM patient p | ||||||||||||||||||||||||||||||||||||||||||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||||||||||||||||||||||||||||||||||||||||||
| WHERE pe.voided = 0 | ||||||||||||||||||||||||||||||||||||||||||
| AND p.voided = 0 | ||||||||||||||||||||||||||||||||||||||||||
| AND EXISTS ( | ||||||||||||||||||||||||||||||||||||||||||
| SELECT 1 | ||||||||||||||||||||||||||||||||||||||||||
| FROM obs o | ||||||||||||||||||||||||||||||||||||||||||
| INNER JOIN concept c ON o.concept_id = c.concept_id | ||||||||||||||||||||||||||||||||||||||||||
| WHERE o.person_id = p.patient_id | ||||||||||||||||||||||||||||||||||||||||||
| AND o.voided = 0 | ||||||||||||||||||||||||||||||||||||||||||
| AND c.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||||||||||||||||||||||||||||||||||||||||||
| AND o.value_numeric IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||
| AND o.value_numeric < 90 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| Value | NOT Value |
|---|---|
| True | False |
| False | True |
| Null | Null |
| Value | AND True | AND False | AND Null |
|---|---|---|---|
| True | True | False | Null |
| False | False | False | Null |
| Null | Null | Null | Null |
| Value | OR True | OR False | OR Null |
|---|---|---|---|
| True | True | True | Null |
| False | True | False | Null |
| Null | Null | Null | Null |
Basically, any operation that involves a NULL results in a NULL, and NULL is not true, so the row isn't matched.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| SELECT DISTINCT p.patient_id | ||
| FROM patient p | ||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||
| WHERE pe.voided = 0 | ||
| AND p.voided = 0 | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o | ||
| INNER JOIN concept c ON o.concept_id = c.concept_id | ||
| WHERE o.person_id = p.patient_id | ||
| AND o.voided = 0 | ||
| AND c.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||
| AND o.value_numeric IS NOT NULL | ||
| AND o.value_numeric > 180 | ||
|
||
| AND o.obs_datetime = ( | ||
| SELECT MAX(o2.obs_datetime) | ||
| FROM obs o2 | ||
| INNER JOIN concept c2 ON o2.concept_id = c2.concept_id | ||
| WHERE o2.person_id = o.person_id | ||
| AND o2.voided = 0 | ||
| AND c2.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||
| AND o2.value_numeric IS NOT NULL | ||
| ) | ||
| ) | ||
| ORDER BY p.patient_id; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| SELECT DISTINCT p.patient_id | ||
| FROM patient p | ||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||
| WHERE pe.voided = 0 | ||
| AND p.voided = 0 | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o | ||
| INNER JOIN concept c ON o.concept_id = c.concept_id | ||
| WHERE o.person_id = p.patient_id | ||
| AND o.voided = 0 | ||
| AND c.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||
| AND o.value_numeric IS NOT NULL | ||
| AND o.value_numeric >= 90 | ||
| AND o.value_numeric <= 179 | ||
| AND o.obs_datetime = ( | ||
| SELECT MAX(o2.obs_datetime) | ||
| FROM obs o2 | ||
| INNER JOIN concept c2 ON o2.concept_id = c2.concept_id | ||
| WHERE o2.person_id = o.person_id | ||
| AND o2.voided = 0 | ||
| AND c2.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||
| AND o2.value_numeric IS NOT NULL | ||
| ) | ||
| ) | ||
| ORDER BY p.patient_id; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| SELECT DISTINCT p.patient_id | ||
| FROM patient p | ||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||
| WHERE pe.voided = 0 | ||
| AND p.voided = 0 | ||
| AND NOT EXISTS ( | ||
| -- Check that patient does NOT have death date observation | ||
| SELECT 1 | ||
| FROM obs o | ||
| INNER JOIN concept c ON o.concept_id = c.concept_id | ||
| WHERE o.person_id = p.patient_id | ||
| AND o.voided = 0 | ||
| AND c.uuid = '1543AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | ||
| ) | ||
| ORDER BY p.patient_id; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||
| SELECT DISTINCT p.patient_id | ||||||||||
| FROM patient p | ||||||||||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||||||||||
| WHERE pe.voided = 0 | ||||||||||
| AND p.voided = 0 | ||||||||||
| AND EXISTS ( | ||||||||||
| SELECT 1 | ||||||||||
| FROM obs o | ||||||||||
| INNER JOIN concept c_question ON o.concept_id = c_question.concept_id | ||||||||||
| INNER JOIN concept c_answer ON o.value_coded = c_answer.concept_id | ||||||||||
| WHERE o.person_id = p.patient_id | ||||||||||
| AND o.voided = 0 | ||||||||||
| AND c_question.uuid = '1255AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- ART initiation during this visit | ||||||||||
| AND c_answer.uuid = '1256AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Start ART | ||||||||||
|
|
||||||||||
| AND DATE(o.obs_datetime) >= :onOrAfter | ||||||||||
| AND DATE(o.obs_datetime) <= :onOrBefore | ||||||||||
|
||||||||||
| AND DATE(o.obs_datetime) >= :onOrAfter | |
| AND DATE(o.obs_datetime) <= :onOrBefore | |
| AND DATE(o.obs_datetime) BETWEEN :onOrAfter AND :onOrBefore | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| SELECT DISTINCT p.patient_id | ||
| FROM patient p | ||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||
| WHERE pe.voided = 0 | ||
| AND p.voided = 0 | ||
| AND EXISTS ( | ||
| -- Check for "Next Appointment Date" within or beyond date range | ||
| SELECT 1 | ||
| FROM obs o_appt | ||
| INNER JOIN concept c_appt ON o_appt.concept_id = c_appt.concept_id | ||
| WHERE o_appt.person_id = p.patient_id | ||
| AND o_appt.voided = 0 | ||
| AND c_appt.uuid = '5096AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | ||
| AND DATE(o_appt.value_datetime) >= :onOrAfter | ||
| ) | ||
| AND EXISTS ( | ||
| -- Check ARV coverage: Either drugs cover entire range OR drugs end in range with appointment/visit logic | ||
| SELECT 1 | ||
| FROM encounter e_consult | ||
| INNER JOIN encounter_type et ON e_consult.encounter_type = et.encounter_type_id | ||
| INNER JOIN obs o_arv ON o_arv.encounter_id = e_consult.encounter_id | ||
| INNER JOIN concept c_arv ON o_arv.concept_id = c_arv.concept_id | ||
| WHERE e_consult.patient_id = p.patient_id | ||
| AND e_consult.voided = 0 | ||
| AND o_arv.voided = 0 | ||
| AND et.uuid = 'cb0a65a7-0587-477e-89b9-cf2fd144f1d4' | ||
| AND c_arv.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||
| AND DATE(e_consult.encounter_datetime) <= :onOrBefore | ||
| AND ( | ||
| -- Either: ARV quantity covers the entire date range | ||
| DATE_ADD(DATE(e_consult.encounter_datetime), INTERVAL o_arv.value_numeric DAY) >= :onOrBefore | ||
| OR | ||
| -- Or: Drugs end within date range with appointment/visit logic based on timing | ||
| ( | ||
| DATE_ADD(DATE(e_consult.encounter_datetime), INTERVAL o_arv.value_numeric DAY) < :onOrBefore | ||
| AND DATE_ADD(DATE(e_consult.encounter_datetime), INTERVAL o_arv.value_numeric DAY) >= :onOrAfter | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o_appt | ||
| INNER JOIN concept c_appt ON o_appt.concept_id = c_appt.concept_id | ||
| WHERE o_appt.person_id = p.patient_id | ||
| AND o_appt.voided = 0 | ||
| AND c_appt.uuid = '5096AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | ||
| AND ( | ||
| -- If appointment is within 28 days of end date, just check it exists | ||
| (DATE(o_appt.value_datetime) > DATE_SUB(:onOrBefore, INTERVAL 28 DAY)) | ||
| OR | ||
| -- If appointment is 28+ days before end date, must have subsequent visit WITH drug dispensing | ||
| ( | ||
| DATE(o_appt.value_datetime) <= DATE_SUB(:onOrBefore, INTERVAL 28 DAY) | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM encounter e_subsequent | ||
| INNER JOIN encounter_type et_subsequent ON e_subsequent.encounter_type = et_subsequent.encounter_type_id | ||
| INNER JOIN obs o_arv_subsequent ON o_arv_subsequent.encounter_id = e_subsequent.encounter_id | ||
| INNER JOIN concept c_arv_subsequent ON o_arv_subsequent.concept_id = c_arv_subsequent.concept_id | ||
| WHERE e_subsequent.patient_id = p.patient_id | ||
| AND e_subsequent.voided = 0 | ||
| AND o_arv_subsequent.voided = 0 | ||
| AND et_subsequent.uuid = 'cb0a65a7-0587-477e-89b9-cf2fd144f1d4' | ||
| AND c_arv_subsequent.uuid = '3a0709e9-d7a8-44b9-9512-111db5ce3989' | ||
| AND o_arv_subsequent.value_numeric IS NOT NULL | ||
| AND o_arv_subsequent.value_numeric > 0 | ||
| AND DATE(e_subsequent.encounter_datetime) > DATE(o_appt.value_datetime) | ||
| AND DATE(e_subsequent.encounter_datetime) <= :onOrBefore | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ORDER BY p.patient_id; |
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| SELECT DISTINCT p.patient_id | ||
| FROM patient p | ||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||
| WHERE pe.voided = 0 | ||
| AND p.voided = 0 | ||
| AND NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o | ||
| INNER JOIN concept c_question ON o.concept_id = c_question.concept_id | ||
| INNER JOIN concept c_answer ON o.value_coded = c_answer.concept_id | ||
| INNER JOIN obs o_date ON o.encounter_id = o_date.encounter_id | ||
| INNER JOIN concept c_date ON o_date.concept_id = c_date.concept_id | ||
| WHERE o.person_id = p.patient_id | ||
| AND o.voided = 0 | ||
| AND o_date.voided = 0 | ||
| AND c_question.uuid = '1255AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Decision on ART during this visit | ||
| AND c_answer.uuid = '1260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Stopped ART | ||
| AND c_date.uuid = '162572AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Stop Date | ||
|
|
||
| AND DATE(o_date.value_datetime) >= :onOrAfter | ||
| AND DATE(o_date.value_datetime) <= :onOrBefore | ||
| ) | ||
| ORDER BY p.patient_id; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| SELECT DISTINCT p.patient_id | ||
| FROM patient p | ||
| INNER JOIN person pe ON p.patient_id = pe.person_id | ||
| WHERE pe.voided = 0 | ||
| AND p.voided = 0 | ||
| AND NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o | ||
| INNER JOIN concept c ON o.concept_id = c.concept_id | ||
| WHERE o.person_id = p.patient_id | ||
| AND o.voided = 0 | ||
| AND c.uuid = '160649AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Date Transferred | ||
|
|
||
| AND DATE(o.value_datetime) >= :onOrAfter | ||
| AND DATE(o.value_datetime) <= :onOrBefore | ||
| ) | ||
| ORDER BY p.patient_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change the label here to "3 months or less" and similarly in French.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually less than 3 months, fixed.