Skip to content

Commit 85c5331

Browse files
author
Ada Ball
committed
add total clusters initiated
1 parent f4a4de1 commit 85c5331

5 files changed

Lines changed: 123 additions & 0 deletions

File tree

apps/report-execution/src/libraries/pa_01.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from src.libraries.support.pa_01.queries import (
1313
case_interview_rows_query,
1414
cases_with_no_partners_query,
15+
clusters_initiated_query,
1516
filtered_cases_query,
1617
partner_notification_query,
1718
period_partners_query,
@@ -87,6 +88,7 @@ def execute(
8788
testing_index=trx.query(testing_index_query(subset_query)),
8889
period_partners=trx.query(period_partners_query(subset_query)),
8990
cases_with_no_partners=trx.query(cases_with_no_partners_query(subset_query)),
91+
clusters_initiated=trx.query(clusters_initiated_query(subset_query))
9092
)
9193

9294
# build output CSV data for each worker

apps/report-execution/src/libraries/support/pa_01/calculations.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def build_partners_and_clusters_initiated_output(
201201
cases_with_no_partners, cases_with_no_partners_percentage = (
202202
_calc_cases_with_no_partners(tables.cases_with_no_partners, cases_ixd, worker)
203203
)
204+
total_clusters_initiated = _calc_total_clusters_initiated(tables.clusters_initiated, worker)
204205

205206
# output CSV data
206207
rows: list[Pa01Row] = [
@@ -258,6 +259,15 @@ def build_partners_and_clusters_initiated_output(
258259
cases_with_no_partners_percentage,
259260
None,
260261
),
262+
(
263+
_worker_for_csv(worker),
264+
PARTNERS_AND_CLUSTERS_INITIATED,
265+
'Total Clusters Initiated',
266+
None,
267+
total_clusters_initiated,
268+
None,
269+
None,
270+
),
261271
]
262272

263273
return rows
@@ -535,6 +545,15 @@ def _calc_cases_with_no_partners(
535545
return count, _percent_for_csv(count, cases_ixd)
536546

537547

548+
def _calc_total_clusters_initiated(
549+
clusters_initiated: Table, worker: Pa01Worker | None = None
550+
) -> int:
551+
"""Calculate 'Total Clusters Initiated' count. Calculates for all workers if passed
552+
in worker is None."""
553+
rows = _rows_for_worker(clusters_initiated, worker)
554+
return _count_distinct_case_ids(rows)
555+
556+
538557
# helpers
539558
def _rows_for_worker(table: Table, worker: Pa01Worker | None = None) -> list[dict]:
540559
"""Filter a given table's data for the given worker. If the given worker is None

apps/report-execution/src/libraries/support/pa_01/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Pa01Tables:
3838
testing_index: Table
3939
period_partners: Table
4040
cases_with_no_partners: Table
41+
clusters_initiated: Table
4142

4243

4344
@dataclass(frozen=True)

apps/report-execution/src/libraries/support/pa_01/queries.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,56 @@ def cases_with_no_partners_query(subset_query: str) -> str:
413413
FROM pp
414414
);
415415
"""
416+
417+
418+
def clusters_initiated_query(subset_query: str) -> str:
419+
return f"""
420+
WITH base AS
421+
(
422+
{subset_query}
423+
),
424+
filtered_cases AS
425+
(
426+
-- STD_HIV_DATAMART1 in SAS
427+
SELECT b.*
428+
FROM base b
429+
INNER JOIN RDB.dbo.INVESTIGATION i
430+
ON i.INVESTIGATION_KEY = b.INVESTIGATION_KEY
431+
AND i.INV_CASE_STATUS IN ('Probable', 'Confirmed')
432+
AND b.CA_INTERVIEWER_ASSIGN_DT IS NOT NULL
433+
)
434+
SELECT DISTINCT a.INVESTIGATION_KEY,
435+
PROVIDER_QUICK_CODE,
436+
a.inv_local_id AS STD_INV_LOCAL_ID,
437+
f.FL_FUP_DISPOSITION,
438+
e.LOCAL_ID AS INV_LOCAL_ID,
439+
a.FL_FUP_DISPO_DT,
440+
a.FL_FUP_INIT_ASSGN_DT,
441+
a.INVESTIGATOR_INTERVIEW_KEY,
442+
a.INVESTIGATOR_INTERVIEW_QC
443+
FROM filtered_cases a
444+
INNER JOIN RDB.dbo.F_INTERVIEW_CASE b
445+
ON a.INVESTIGATION_KEY = b.INVESTIGATION_KEY
446+
INNER JOIN RDB.dbo.D_INTERVIEW c
447+
ON c.D_INTERVIEW_KEY = b.D_INTERVIEW_KEY
448+
AND c.RECORD_STATUS_CD <> 'LOG_DEL'
449+
INNER JOIN RDB.dbo.F_CONTACT_RECORD_CASE d
450+
ON a.INVESTIGATION_KEY = d.SUBJECT_INVESTIGATION_KEY
451+
AND c.d_interview_key = d.CONTACT_INTERVIEW_KEY
452+
AND d.CONTACT_INTERVIEW_KEY <> 1
453+
INNER JOIN RDB.dbo.D_CONTACT_RECORD e
454+
ON e.D_CONTACT_RECORD_KEY = d.D_CONTACT_RECORD_KEY
455+
AND e.RECORD_STATUS_CD <> 'LOG_DEL'
456+
INNER JOIN RDB.dbo.D_provider
457+
ON D_provider.provider_key = a.INVESTIGATOR_INTERVIEW_KEY
458+
INNER JOIN RDB.dbo.STD_HIV_DATAMART f
459+
ON d.CONTACT_INVESTIGATION_KEY = f.Investigation_key
460+
AND e.CTT_REFERRAL_BASIS IN (
461+
'A1 - Associate 1',
462+
'A2 - Associate 2',
463+
'A3 - Associate 3',
464+
'S1 - Social Contact 1',
465+
'S2 - Social Contact 2',
466+
'S3 - Social Contact 3'
467+
);
468+
"""

apps/report-execution/tests/integration/libraries/snapshots/pa_01/test_execute_report_check_data_hiv/snapshot.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@
158158
- 180
159159
- 97.3%
160160
- null
161+
- !!python/tuple
162+
- ALL
163+
- Partners & Clusters Initiated
164+
- Total Clusters Initiated
165+
- null
166+
- 8
167+
- null
168+
- null
161169
- !!python/tuple
162170
- adevraj
163171
- Case Assignments & Outcomes
@@ -318,6 +326,14 @@
318326
- 32
319327
- 94.1%
320328
- null
329+
- !!python/tuple
330+
- adevraj
331+
- Partners & Clusters Initiated
332+
- Total Clusters Initiated
333+
- null
334+
- 0
335+
- null
336+
- null
321337
- !!python/tuple
322338
- avance
323339
- Case Assignments & Outcomes
@@ -478,6 +494,14 @@
478494
- 48
479495
- 98.0%
480496
- null
497+
- !!python/tuple
498+
- avance
499+
- Partners & Clusters Initiated
500+
- Total Clusters Initiated
501+
- null
502+
- 0
503+
- null
504+
- null
481505
- !!python/tuple
482506
- dbowman
483507
- Case Assignments & Outcomes
@@ -638,6 +662,14 @@
638662
- 46
639663
- 95.8%
640664
- null
665+
- !!python/tuple
666+
- dbowman
667+
- Partners & Clusters Initiated
668+
- Total Clusters Initiated
669+
- null
670+
- 2
671+
- null
672+
- null
641673
- !!python/tuple
642674
- fpoole
643675
- Case Assignments & Outcomes
@@ -798,6 +830,14 @@
798830
- 40
799831
- 97.6%
800832
- null
833+
- !!python/tuple
834+
- fpoole
835+
- Partners & Clusters Initiated
836+
- Total Clusters Initiated
837+
- null
838+
- 3
839+
- null
840+
- null
801841
- !!python/tuple
802842
- gfreeman
803843
- Case Assignments & Outcomes
@@ -958,3 +998,11 @@
958998
- 38
959999
- 95.0%
9601000
- null
1001+
- !!python/tuple
1002+
- gfreeman
1003+
- Partners & Clusters Initiated
1004+
- Total Clusters Initiated
1005+
- null
1006+
- 3
1007+
- null
1008+
- null

0 commit comments

Comments
 (0)