-
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 3 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
472 changes: 472 additions & 0 deletions
472
api/src/main/java/org/openmrs/module/drcreports/reports/DRCTx_CurrReportManager.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
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; |
30 changes: 30 additions & 0 deletions
30
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,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 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) >= :onOrAfter | ||
| AND DATE(o_init_date.value_datetime) <= :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; |
23 changes: 23 additions & 0 deletions
23
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrNotStopedART.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,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; |
17 changes: 17 additions & 0 deletions
17
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrNotTransferredOut.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,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; |
19 changes: 19 additions & 0 deletions
19
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrResumeART.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,19 @@ | ||
| 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' -- Decision on ART during this visit | ||
| AND c_answer.uuid = '162904AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Resume ART | ||
|
|
||
| AND DATE(o.obs_datetime) >= :onOrAfter | ||
| AND DATE(o.obs_datetime) <= :onOrBefore | ||
| ) | ||
| ORDER BY p.patient_id; |
48 changes: 48 additions & 0 deletions
48
api/src/main/resources/org/openmrs/module/drcreports/sql/DRCTxCurrTransferPMTCT.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,48 @@ | ||
| 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 = '83e40f2c-c316-43e6-a12e-20a338100281' -- What do you want to do? | ||
| AND c_answer.uuid IN ( | ||
| '160563AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', -- Transfer in | ||
| '163532AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- Enroll into PMTCT | ||
| ) | ||
| AND DATE(o.obs_datetime) >= :onOrAfter | ||
| AND DATE(o.obs_datetime) <= :onOrBefore | ||
| AND ( | ||
| -- If answer is Transfer In, must have ART Regimen in same encounter | ||
| (c_answer.uuid = '160563AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o_regimen | ||
| INNER JOIN concept c_regimen ON o_regimen.concept_id = c_regimen.concept_id | ||
| WHERE o_regimen.encounter_id = o.encounter_id | ||
| AND o_regimen.voided = 0 | ||
| AND c_regimen.uuid = 'dfbe256e-30ba-4033-837a-2e8477f2e7cd' -- ART Regimen | ||
| AND o_regimen.value_coded IS NOT NULL | ||
| ) | ||
| ) | ||
| OR | ||
| -- If answer is PMTCT, must have Prevention being taken in same encounter | ||
ibacher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| (c_answer.uuid = '163532AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | ||
| AND EXISTS ( | ||
| SELECT 1 | ||
| FROM obs o_prevention | ||
| INNER JOIN concept c_prevention ON o_prevention.concept_id = c_prevention.concept_id | ||
| WHERE o_prevention.encounter_id = o.encounter_id | ||
| AND o_prevention.voided = 0 | ||
| AND c_prevention.uuid = '163532AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' -- ART Prevention being taken | ||
| AND o_prevention.value_coded IS NOT NULL | ||
|
||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ORDER BY p.patient_id; | ||
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.