-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
140e55a
(report) Add TX_CURR report
reagan-meant 170ba23
Improved the Tx Curr report
reagan-meant 83f810d
Add comments
reagan-meant a7cb43f
Add more disaggregation
reagan-meant ac44d4f
Address comments
reagan-meant 38315c5
Add unit tests
reagan-meant 1ac432f
Update PR
reagan-meant 6626cb6
Fix failing tests
reagan-meant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
535 changes: 535 additions & 0 deletions
535
api/src/main/java/org/openmrs/module/drcreports/reports/DRCTxCurrReportManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...rc/main/resources/org/openmrs/module/drcreports/sql/DRCArtLessthanThreeMonthsDispense.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| 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 < 90 | ||
| 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; |
24 changes: 24 additions & 0 deletions
24
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCArtSixAndAboveMonthsDispense.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| 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 >= 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; |
26 changes: 26 additions & 0 deletions
26
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCArtThreeToFiveMonthsDispense.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
15 changes: 15 additions & 0 deletions
15
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCLivePatients.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
27 changes: 27 additions & 0 deletions
27
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrInitiation.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 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) BETWEEN :onOrAfter AND :onOrBefore | ||
| ) | ||
| AND EXISTS ( | ||
| -- Check for initiation date concept within date range | ||
| SELECT 1 | ||
| FROM obs o_init_date | ||
| INNER JOIN concept c_init_date ON o_init_date.concept_id = c_init_date.concept_id | ||
| WHERE o_init_date.person_id = p.patient_id | ||
| AND o_init_date.voided = 0 | ||
| AND c_init_date.uuid = '159599AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Initiation date concept | ||
| AND DATE(o_init_date.value_datetime) BETWEEN :onOrAfter AND :onOrBefore | ||
| ) | ||
| ORDER BY p.patient_id; |
73 changes: 73 additions & 0 deletions
73
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrMultiMonth.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
34 changes: 34 additions & 0 deletions
34
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrNotStoppedART.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| 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) BETWEEN :onOrAfter AND :onOrBefore | ||
| AND NOT EXISTS ( | ||
| -- Must have resumed ART after this stop in the same reporting period | ||
| SELECT 1 | ||
| FROM obs o_resume | ||
| INNER JOIN concept c_question_resume ON o_resume.concept_id = c_question_resume.concept_id | ||
| INNER JOIN concept c_answer_resume ON o_resume.value_coded = c_answer_resume.concept_id | ||
| WHERE o_resume.person_id = p.patient_id | ||
| AND o_resume.voided = 0 | ||
| AND c_question_resume.uuid = '1255AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Decision on ART during this visit | ||
| AND c_answer_resume.uuid = '162904AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Resume ART | ||
| AND DATE(o_resume.obs_datetime) BETWEEN :onOrAfter AND :onOrBefore | ||
| AND o_resume.obs_datetime > o_date.value_datetime | ||
| ) | ||
| ) | ||
| ORDER BY p.patient_id; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.