Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ generated one.
```
'INSERT INTO dot.configured_tests VALUES(TRUE, 'ScanProject1', '0cdc9702-91e0-3499-b6f0-4dec12ad0f08', 'ASSESS-1', 3, '', '',
'', 'ancview_pregnancy', 'relationships', 'uuid', '',
$${"name": "danger_signs_with_no_pregnancy", "to": "ref('dot_model__ancview_danger_sign')", "field": "pregnancy_uuid"}$$,
$${"name": "danger_signs_with_no_pregnancy", "to": "ancview_danger_sign", "field": "pregnancy_uuid"}$$,
'2021-12-23 19:00:00.000 -0500', '2021-12-23 19:00:00.000 -0500', 'your-name');
```
2. `unique`
Expand Down Expand Up @@ -413,7 +413,7 @@ generated one.
```
INSERT INTO dot.configured_tests VALUES(TRUE, 'ScanProject1', '7f78de0e-8268-3da6-8845-9a445457cc9a', 'DUPLICATE-1', 3, '',
'', '', 'ancview_pregnancy', 'possible_duplicate_forms', '', '',
$${"table_specific_reported_date": "delivery_date", "table_specific_patient_uuid": "patient_id", "table_specific_uuid": "uuid"}$$, '2021-12-23 19:00:00.000 -0500', '2021-12-23 19:00:00.000 -0500', 'your-name');
$${"date_column": "delivery_date", "group_column": "patient_id", "id_column": "uuid"}$$, '2021-12-23 19:00:00.000 -0500', '2021-12-23 19:00:00.000 -0500', 'your-name');
```
7. `associated_columns_not_null`
<br><br>
Expand All @@ -429,7 +429,7 @@ generated one.
INSERT INTO dot.configured_tests VALUES(TRUE, 'ScanProject1', '0cdc9702-91e0-3499-b6f0-4dec12ad0f08', 'BIAS-1', 3,
'Test for miscalibrated thermometer', '', '', 'ancview_pregnancy', 'expect_similar_means_across_reporters',
'child_temperature_pre_chw', '', '{"key": "reported_by","quantity": "child_temperature_pre_chw",
"form_name": "dot_model__iccmview_assessment","id_column": "reported_by"}', '2022-01-19 20:00:00.000 -0500',
"data_table": "iccmview_assessment","id_column": "reported_by"}', '2022-01-19 20:00:00.000 -0500',
'2022-01-19 20:00:00.000 -0500', 'your-name');
```
9. `expression_is_true`
Expand Down
12 changes: 6 additions & 6 deletions db/dot/2-upload_static_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ INSERT INTO dot.test_types VALUES('expression_is_true', 'dbt', 'Test to confirm

-- dot.test_parameters_interface
-- INSERT INTO dot.test_parameters_interface VALUES('relationships', 'name', 'function_argument', 'Name of the test');
INSERT INTO dot.test_parameters_interface VALUES('relationships', 'reference', 'view/table', $$ref('dot_model__ancview_pregnancy')$$, 'Referenced field to be checked if missing');
INSERT INTO dot.test_parameters_interface VALUES('relationships', 'to', 'view/table', 'ancview_pregnancy', 'Referenced entity to be checked if missing');
INSERT INTO dot.test_parameters_interface VALUES('relationships', 'field', 'entity any field', 'uuid', 'Field being checked');
-- INSERT INTO dot.test_parameters_interface VALUES('not_negative_string_column', 'name', 'function_argument', 'Name of column to be check3ed for non-negative values');
INSERT INTO dot.test_parameters_interface VALUES('accepted_values', 'values', 'list of values', $$["dog","cat","ostrich"]$$,'List of accepted values for the field being checked');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'table_specific_reported_date', 'entity date field', 'reported', 'Column which indicates when form created');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'table_specific_patient_uuid', 'entity id field', 'patient_id', 'Column which holds to patient uuid');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'table_specific_uuid', 'entity id field', 'uuid', 'UUID for records in the table (form) being checked');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'table_specific_period', 'one of (hour, day, week)', 'day','Specified period to check for duplicates (hour, day, week)');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'date_column', 'entity date field', 'reported', 'Column which indicates when the record was created or reported');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'group_column', 'entity id field', 'patient_id', 'Column used to group records when checking for duplicates');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'id_column', 'entity id field', 'uuid', 'Primary id for records in the table being checked');
INSERT INTO dot.test_parameters_interface VALUES('possible_duplicate_forms', 'period', 'one of (hour, day, week)', 'day','Specified period to check for duplicates (hour, day, week)');
INSERT INTO dot.test_parameters_interface VALUES('custom_sql', 'query', 'sql statement', $$SELECT field1, field2, 'table1' as \"primary_table\", 'field1' as \"primary_table_id_field\" WHERE COLOR='green'$$,'Custom SQL to use to determine test fails, SQL is defined in columns test_parameter');
-- INSERT INTO dot.test_parameters_interface VALUES('expression_is_true', 'name', 'function_argument', 'Name of the test');
INSERT INTO dot.test_parameters_interface VALUES('expression_is_true', 'condition', 'entity columns boolean logic', '(patient_age_in_months<24) and (malaria_give_act is not null)','Where clause of rows that are going to be checked');
INSERT INTO dot.test_parameters_interface VALUES('expression_is_true', 'expression', 'entity columns boolean logic', 'malaria_act_dosage is not null', 'If not true, the row fails the test');
INSERT INTO dot.test_parameters_interface VALUES('expect_similar_means_across_reporters', 'key', 'entity id field', 'reported_by', 'The grouping field to check means by, ie a person-specific id');
INSERT INTO dot.test_parameters_interface VALUES('expect_similar_means_across_reporters', 'quantity', 'entity numeric field', 'temperature', 'The name of the numeric field to analyze for variation');
INSERT INTO dot.test_parameters_interface VALUES('expect_similar_means_across_reporters', 'data_table', 'view/table', 'dot_model__iccmview_assessment', 'The name of entity view where data is');
INSERT INTO dot.test_parameters_interface VALUES('expect_similar_means_across_reporters', 'data_table', 'view/table', 'iccmview_assessment', 'The name of entity view where data is');
INSERT INTO dot.test_parameters_interface VALUES('expect_similar_means_across_reporters', 'id_column', 'entity id field', 'reported_by', 'The id column to use to get failed test records');

-- dot.scenario_test_types
Expand Down
3 changes: 1 addition & 2 deletions db/dot/4-upload_sample_dot_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ INSERT INTO dot.configured_tests VALUES(TRUE, 'ScanProject1', '0cdc9702-91e0-349

INSERT INTO dot.configured_tests VALUES(TRUE, 'ScanProject1', '36d33837-bd92-370a-963a-264a4d5b2bac', 'DUPLICATE-1',
6, 'Duplicate flight record', '', '', 'all_flight_data', 'possible_duplicate_forms', '', '',
$${"table_specific_reported_date": "departure_time", "table_specific_patient_uuid": "airline", "table_specific_uuid":
"uuid", "table_specific_period": "day"}$$, '2021-12-23 19:00:00.000 -0500', '2022-03-21 19:00:00.000 -0500', 'Matt');
$${"date_column": "departure_time", "group_column": "airline", "id_column": "uuid", "period": "day"}$$, '2021-12-23 19:00:00.000 -0500', '2022-03-21 19:00:00.000 -0500', 'Matt');

INSERT INTO dot.configured_tests VALUES(TRUE, 'ScanProject1', 'c4a3da8f-32f4-4e9b-b135-354de203ca90', 'TREAT-1',
5, 'Number of stops has a reasonable value', '', '', 'all_flight_data', 'custom_sql', '', '',
Expand Down
38,499 changes: 38,498 additions & 1 deletion docker/appsmith/DOT App V2.json

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions dot/dbt/macros/test_possible_duplicate_forms.sql
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
-- Test to check if a patient was reported more than once in a specified period.
-- Test to check if the same group key appears more than once in a specified period.
-- Input period parameter is database specific (https://hub.getdbt.com/dbt-labs/dbt_utils/0.1.13/)
-- Some valid values for PostgreSQL include 'day', 'week', 'hour'
-- Some valid values for PostgreSQL include 'day', 'week', 'hour'
-- (See https://www.postgresql.org/docs/9.1/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC)
-- If so, flag as possible duplicate form.
-- TODO Convert these parameter names to generic. Be sure to update DB schema and samples
{% macro test_possible_duplicate_forms(model, table_specific_reported_date='reported', table_specific_patient_uuid='patient_uuid', table_specific_uuid='uuid', table_specific_period='hour', name='possible_duplicate_records') %}
-- If so, flag as possible duplicate records.
{% macro test_possible_duplicate_forms(model, date_column='reported', group_column='patient_uuid', id_column='uuid', period='hour', name='possible_duplicate_records') %}

with records_per_patient_period as (
with records_per_group_period as (
select
date_trunc('{{ table_specific_period}}', {{ table_specific_reported_date }}::timestamp) as date_period,
{{ table_specific_patient_uuid }} as patient_uuid_to_flag,
count({{ table_specific_uuid }}) as number_of_records
date_trunc('{{ period}}', {{ date_column }}::timestamp) as date_period,
{{ group_column }} as group_key_to_flag,
count({{ id_column }}) as number_of_records
FROM {{ model }}
group by 1, 2
),

possible_duplicate_combinations as (
select *
from records_per_patient_period
from records_per_group_period
where number_of_records > 1
)

select array_agg({{ table_specific_uuid }}) as uuid_list -- postgres only?
select array_agg({{ id_column }}) as uuid_list -- postgres only?
from possible_duplicate_combinations pdc
left join {{ model }} m
on date_trunc('{{ table_specific_period}}', m.{{ table_specific_reported_date }}::timestamp) = pdc.date_period
and m.{{ table_specific_patient_uuid }} = pdc.patient_uuid_to_flag
on date_trunc('{{ period}}', m.{{ date_column }}::timestamp) = pdc.date_period
and m.{{ group_column }} = pdc.group_key_to_flag
having count(*) > 0

{% endmacro %}
Loading
Loading