From 4cd3be2ba1625ee82e3f1194dbfd285d5e5bf9e8 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Tue, 19 Sep 2023 18:10:34 -0400 Subject: [PATCH 01/43] Add tests to contact views working models --- .gitignore | 1 + dbt_project.yml | 28 +++++----- models/brac/contact_views/contact_views.yml | 51 +++++++++++++++++++ models/brac/indexes.sql | 4 +- .../useviews/useview_assessment_follow_up.sql | 4 +- models/contact_views/contact_views.yml | 1 + tests/run_dbt_tests.sh | 5 +- 7 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 models/brac/contact_views/contact_views.yml diff --git a/.gitignore b/.gitignore index 6567ff4a..2890d85a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dbt_packages/ logs/ */.env */dbt_packages/ +tests/.user.yml diff --git a/dbt_project.yml b/dbt_project.yml index a3c72e0c..7d20a77e 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,27 +1,31 @@ # Name your project! Project names should contain only lowercase characters # and underscores. A good package name should reflect your organization's # name or the intended use of these models -name: "pipeline" -version: "0.0.1" +name: 'pipeline' +version: '0.0.1' config-version: 2 +vars: + # The `start_date` variable will be accessible in all resources + end_date: '2023-06-01' + # This setting configures which "profile" dbt uses for this project. -profile: "default" +profile: 'default' # These configurations specify where dbt should look for different types of files. # The `source-paths` config, for example, states that models in this project can be # found in the "models/" directory. You probably won't need to change these! -model-paths: ["models"] -analysis-paths: ["analysis"] -test-paths: ["tests"] -seed-paths: ["seeds"] -macro-paths: ["macros"] -snapshot-paths: ["snapshots"] +model-paths: ['models'] +analysis-paths: ['analysis'] +test-paths: ['tests'] +seed-paths: ['seeds'] +macro-paths: ['macros'] +snapshot-paths: ['snapshots'] -target-path: "target" # directory which will store compiled SQL files +target-path: 'target' # directory which will store compiled SQL files clean-targets: # directories to be removed by `dbt clean` - - "target" - - "dbt_modules" + - 'target' + - 'dbt_modules' # Configuring models # Full documentation: https://docs.getdbt.com/docs/configuring-models diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml new file mode 100644 index 00000000..32c69ae6 --- /dev/null +++ b/models/brac/contact_views/contact_views.yml @@ -0,0 +1,51 @@ +version: 2 + +models: + - name: contactview_person + columns: + - name: uuid + tests: + - not_null + - unique + - name: name + tests: + - not_null + - name: patient_id + tests: + - not_null + - name: contactview_muted + columns: + - name: contact_uuid + tests: + - not_null + - unique + - name: type + tests: + - not_null + - accepted_values: + values: + [contact, clinic, district_hospital, health_center, person] + - name: mute_status + tests: + - not_null + - name: date + tests: + - not_null + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - name: contactview_hospital + columns: + - name: uuid + tests: + - not_null + - unique + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - name: contactview_branch + columns: + - name: uuid + tests: + - not_null + - unique diff --git a/models/brac/indexes.sql b/models/brac/indexes.sql index b0753f67..32389dd4 100644 --- a/models/brac/indexes.sql +++ b/models/brac/indexes.sql @@ -1,4 +1,4 @@ -{{ config(schema='v1', materialized = 'raw_sql') }} +{{ config(materialized = 'raw_sql') }} CREATE INDEX IF NOT EXISTS couchdb_doc_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }} ((doc ->> '_id'::text) text_ops); CREATE INDEX IF NOT EXISTS couchdb_doc_type ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc ->> 'type'::text) text_ops); @@ -6,4 +6,4 @@ CREATE INDEX IF NOT EXISTS couchdb_doc_form ON {{ env_var('ROOT_POSTGRES_SCHEMA' CREATE INDEX IF NOT EXISTS couchdb_doc_form_patient_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc #>> '{fields,patient_id}'::text[]) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; CREATE INDEX IF NOT EXISTS couchdb_doc_form_place_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc #>> '{fields,place_id}'::text[]) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; CREATE INDEX IF NOT EXISTS couchdb_doc_form_source_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc #>> '{fields,inputs,source_id}'::text[]) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; -CREATE INDEX IF NOT EXISTS couchdb_doc_assessment_patient_age ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((nullif(doc #>> '{fields,patient_age_in_years}', '')::int)) WHERE (doc ->> 'form'::text) = 'assessment'::text AND (doc #>> '{fields,patient_age_in_years}') != ''; \ No newline at end of file +CREATE INDEX IF NOT EXISTS couchdb_doc_assessment_patient_age ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((nullif(doc #>> '{fields,patient_age_in_years}', '')::int)) WHERE (doc ->> 'form'::text) = 'assessment'::text AND (doc #>> '{fields,patient_age_in_years}') != ''; diff --git a/models/brac/useviews/useview_assessment_follow_up.sql b/models/brac/useviews/useview_assessment_follow_up.sql index 7defd3ff..2df844f4 100644 --- a/models/brac/useviews/useview_assessment_follow_up.sql +++ b/models/brac/useviews/useview_assessment_follow_up.sql @@ -14,7 +14,7 @@ }} SELECT -{{ dbt_utils.surrogate_key(['form_source_id', 'reported', 'uuid']) }} AS useview_assessment_follow_up_source_date_uuid, +{{ dbt_utils.generate_surrogate_key(['form_source_id', 'reported', 'uuid']) }} AS useview_assessment_follow_up_source_date_uuid, * FROM( @@ -62,4 +62,4 @@ FROM( {% if is_incremental() %} AND "@timestamp" > {{ max_existing_timestamp('"@timestamp"') }} {% endif %} -) x \ No newline at end of file +) x diff --git a/models/contact_views/contact_views.yml b/models/contact_views/contact_views.yml index 8ad464b5..65546438 100644 --- a/models/contact_views/contact_views.yml +++ b/models/contact_views/contact_views.yml @@ -14,6 +14,7 @@ models: - name: uuid tests: - not_null + - unique - name: type tests: - not_null diff --git a/tests/run_dbt_tests.sh b/tests/run_dbt_tests.sh index 857a82b5..b40d8a34 100755 --- a/tests/run_dbt_tests.sh +++ b/tests/run_dbt_tests.sh @@ -14,7 +14,10 @@ dbt deps echo Seeding test data ... dbt seed --full-refresh echo Running dbt ... -dbt run +dbt run --exclude indexes get_dashboard_data_hh_impact+ get_dashboard_data_pnc_impact+ useview_assessment+ useview_assessment_follow_up+ useview_family_survey+ useview_health_forum+ useview_household_survey+ useview_patient_record+ useview_postnatal_care+ useview_pregnancy_visit+ useview_visit+ immunization_followup+ contactview_person_fields+ impact_ancview_pregnancy+ immunization_followup+ echo Running tests ... dbt test +#echo Generating documentation... +#dbt docs generate +#dbt docs serve From 990dcd02ff98b08d89d2e91649072302dadeb62b Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Wed, 20 Sep 2023 09:25:11 -0400 Subject: [PATCH 02/43] Add tests to use views working models --- models/brac/useviews/useviews.yml | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 models/brac/useviews/useviews.yml diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml new file mode 100644 index 00000000..a1e87b1a --- /dev/null +++ b/models/brac/useviews/useviews.yml @@ -0,0 +1,94 @@ +version: 2 + +models: + - name: useview_visit + columns: + - name: uuid + tests: + - not_null + - unique + - name: form + tests: + - not_null + - name: source_id + tests: + - not_null + - name: visit_type + tests: + - not_null + - accepted_values: + values: [anc, pnc, imm, iccm] + - name: danger_signs + tests: + - not_null + - name: useview_pregnancy + columns: + - name: uuid + tests: + - not_null + - unique + - name: chw + tests: + - not_null + - name: useview_postnatal_care + columns: + - name: uuid + tests: + - not_null + - unique + - name: form + tests: + - not_null + - name: useview_place_record + columns: + - name: place_id + tests: + - not_null + - name: useview_patient_record + columns: + - name: patient_id + tests: + - not_null + - name: useview_household_survey + columns: + - name: uuid + tests: + - not_null + - name: useview_health_forum + columns: + - name: xmlforms_uuid + tests: + - not_null + - name: useview_family_survey + columns: + - name: uuid + tests: + - not_null + - name: useview_assessment + columns: + - name: uuid + tests: + - not_null + - name: form + tests: + - not_null + - name: patient_age_in_days + tests: + - not_null + - name: patient_age_in_months + tests: + - not_null + - name: coughing_duration + tests: + - not_null + - name: diarrhea_duration + tests: + - not_null + - name: fever_duration + tests: + - not_null + - name: formview_fp_patient_record + columns: + - name: uuid + tests: + - not_null From dbb7be1cb2148dcbac28a15da869eac350e84eb4 Mon Sep 17 00:00:00 2001 From: Njuguna Ndung'u Date: Fri, 6 Oct 2023 01:36:18 +0300 Subject: [PATCH 03/43] feat: make model chnages and temporarily remove dashboard models --- .gitignore | 1 + .../PNC/get_dashboard_data_pnc_impact.sql | 68 -------- .../impact_pncview_expected_enrollments.sql | 2 +- .../hhvisit/get_dashboard_data_hh_impact.sql | 148 ------------------ models/brac/indexes.sql | 9 -- .../useviews/useview_assessment_follow_up.sql | 2 +- models/user_tables/chws.sql | 21 --- 7 files changed, 3 insertions(+), 248 deletions(-) delete mode 100644 models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql delete mode 100644 models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql delete mode 100644 models/brac/indexes.sql delete mode 100644 models/user_tables/chws.sql diff --git a/.gitignore b/.gitignore index 6567ff4a..72587234 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dbt_packages/ logs/ */.env */dbt_packages/ +dbt-env/* diff --git a/models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql b/models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql deleted file mode 100644 index 97ceddcc..00000000 --- a/models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql +++ /dev/null @@ -1,68 +0,0 @@ -{{ config( - materialized='table', - description='Dashboard data for PNC impact in BRAC Uganda' -) }} - -WITH period_CTE AS ( - SELECT generate_series( - date_trunc(param_interval_unit, now() - (param_num_units || ' ' || param_interval_unit)::interval), - CASE - WHEN param_include_current THEN now() - ELSE now() - ('1 ' || param_interval_unit)::interval - END, - ('1 ' || param_interval_unit)::interval - )::date AS start -) - -SELECT - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' OR param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS district_hospital_uuid, - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' OR param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_name - ELSE 'All' - END AS district_hospital_name, - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' - THEN place_period.health_center_uuid - ELSE 'All' - END AS health_center_uuid, - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' - THEN place_period.health_center_name - ELSE 'All' - END AS health_center_name, - 'All' AS clinic_uuid, - 'All' AS clinic_name, - place_period.period_start AS period_start, - date_part('epoch', place_period.period_start)::numeric AS period_start_epoch, - CASE - WHEN param_facility_group_by = 'health_center' - THEN place_period.health_center_uuid - WHEN param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS facility_join_field, - /* Other fields... (add the remaining fields here) */ -FROM - ( - -- Subqueries and joins... (add the subqueries and joins here) - ) AS place_period -GROUP BY - district_hospital_uuid, - district_hospital_name, - health_center_uuid, - health_center_name, - clinic_uuid, - clinic_name, - period_start, - period_start_epoch, - facility_join_field -ORDER BY - district_hospital_name, - health_center_name, - clinic_name, - period_start; diff --git a/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql b/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql index 9fcd3d2d..d4030973 100644 --- a/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql +++ b/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql @@ -33,4 +33,4 @@ WITH pnc_expected_enrollments AS ( -- Model: pncview_expected_enrollments SELECT * -FROM pnc_expected_enrollments; +FROM pnc_expected_enrollments diff --git a/models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql b/models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql deleted file mode 100644 index 103f56b5..00000000 --- a/models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql +++ /dev/null @@ -1,148 +0,0 @@ -WITH hh_data AS ( -WITH main_data AS ( - WITH period_CTE AS ( - SELECT generate_series( - CASE - WHEN param_include_current - THEN date_trunc(param_interval_unit, now() - (param_num_units || ' ' || param_interval_unit)::INTERVAL) - ELSE - date_trunc(param_interval_unit, min(reported))::DATE - END, - CASE - WHEN param_include_current - THEN now() - ELSE now() - ('1 ' || param_interval_unit)::INTERVAL - END, - ('1 ' || param_interval_unit)::INTERVAL - )::DATE AS start - ) - - SELECT - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center', 'district_hospital') - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS _district_hospital_uuid, - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center', 'district_hospital') - THEN place_period.district_hospital_name - ELSE 'All' - END AS _district_hospital_name, - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center') - THEN place_period.health_center_uuid - ELSE 'All' - END AS _health_center_uuid, - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center') - THEN place_period.health_center_name - ELSE 'All' - END AS _health_center_name, - 'All'::TEXT AS _clinic_uuid, - 'All'::TEXT AS _clinic_name, - place_period.period_start AS _period_start, - date_part('epoch', place_period.period_start)::NUMERIC AS _period_start_epoch, - CASE - WHEN param_facility_group_by = 'health_center' - THEN place_period.health_center_uuid - WHEN param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS _facility_join_field, - COALESCE(sum(hhcount.hh_registered), 0) AS hh_registered, - COALESCE(sum(hh_visit), 0) AS hh_visit - FROM - ( - SELECT - district_hospital.uuid AS district_hospital_uuid, - district_hospital.name AS district_hospital_name, - health_center.uuid AS health_center_uuid, - health_center.name AS health_center_name, - period_CTE.start AS period_start - FROM - period_CTE, - contactview_metadata AS health_center - INNER JOIN contactview_metadata AS district_hospital ON - (health_center.parent_uuid = district_hospital.uuid) - WHERE - district_hospital.type = 'district_hospital' - AND district_hospital.name NOT IN ('HQ', 'HW OVC') - ) AS place_period - LEFT JOIN - ( - SELECT - reported_by_parent, - date_trunc(param_interval_unit, reported)::DATE AS reported_month, - count(DISTINCT household_id) AS hh_visit - FROM - hhview_visits - GROUP BY - reported_by_parent, - reported_month - ) AS hh_visit ON (place_period.period_start = hh_visit.reported_month AND place_period.health_center_uuid = hh_visit.reported_by_parent) - LEFT JOIN ( - SELECT - parent_uuid, - date_trunc(param_interval_unit, reported) AS reported_month, - count(DISTINCT uuid) AS hh_registered - FROM - contactview_metadata - WHERE - TYPE = 'clinic' - GROUP BY - reported_month, - parent_uuid - ) AS hhcount ON (place_period.period_start = hhcount.reported_month AND place_period.health_center_uuid = hhcount.parent_uuid) - GROUP BY - _district_hospital_uuid, - _district_hospital_name, - _health_center_uuid, - _health_center_name, - _clinic_uuid, - _clinic_name, - _period_start, - _facility_join_field - ORDER BY - _district_hospital_name, - _health_center_name, - _clinic_name, - _period_start -) - -SELECT - _district_hospital_uuid, - _district_hospital_name, - _health_center_uuid, - _health_center_name, - _clinic_uuid, - _clinic_name, - _period_start, - _period_start_epoch, - _facility_join_field, - hh_registered, - -- Cumulative sum over all months - hh_visit, - sum(hh_registered) OVER (PARTITION BY _facility_join_field ORDER BY _period_start) AS total_hh_registered -FROM - main_data -) - -SELECT -_district_hospital_uuid, -_district_hospital_name, -_health_center_uuid, -_health_center_name, -_clinic_uuid, -_clinic_name, -_period_start, -_period_start_epoch, -_facility_join_field, -hh_registered, -total_hh_registered, -hh_visit, -safe_divide(hh_visit, total_hh_registered, 2) AS percent_hh_visit -FROM -hh_data -WHERE --- Filter the required data only. -_period_start >= now() - ((1 + param_num_units::INT) || ' ' || param_interval_unit)::INTERVAL; diff --git a/models/brac/indexes.sql b/models/brac/indexes.sql deleted file mode 100644 index b0753f67..00000000 --- a/models/brac/indexes.sql +++ /dev/null @@ -1,9 +0,0 @@ -{{ config(schema='v1', materialized = 'raw_sql') }} - -CREATE INDEX IF NOT EXISTS couchdb_doc_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }} ((doc ->> '_id'::text) text_ops); -CREATE INDEX IF NOT EXISTS couchdb_doc_type ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc ->> 'type'::text) text_ops); -CREATE INDEX IF NOT EXISTS couchdb_doc_form ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc ->> 'form'::text) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; -CREATE INDEX IF NOT EXISTS couchdb_doc_form_patient_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc #>> '{fields,patient_id}'::text[]) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; -CREATE INDEX IF NOT EXISTS couchdb_doc_form_place_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc #>> '{fields,place_id}'::text[]) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; -CREATE INDEX IF NOT EXISTS couchdb_doc_form_source_id ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((doc #>> '{fields,inputs,source_id}'::text[]) text_ops) WHERE (doc ->> 'type'::text) = 'data_record'::text; -CREATE INDEX IF NOT EXISTS couchdb_doc_assessment_patient_age ON {{ env_var('ROOT_POSTGRES_SCHEMA') }}.{{ env_var('POSTGRES_TABLE') }}((nullif(doc #>> '{fields,patient_age_in_years}', '')::int)) WHERE (doc ->> 'form'::text) = 'assessment'::text AND (doc #>> '{fields,patient_age_in_years}') != ''; \ No newline at end of file diff --git a/models/brac/useviews/useview_assessment_follow_up.sql b/models/brac/useviews/useview_assessment_follow_up.sql index 7defd3ff..f5947139 100644 --- a/models/brac/useviews/useview_assessment_follow_up.sql +++ b/models/brac/useviews/useview_assessment_follow_up.sql @@ -14,7 +14,7 @@ }} SELECT -{{ dbt_utils.surrogate_key(['form_source_id', 'reported', 'uuid']) }} AS useview_assessment_follow_up_source_date_uuid, +{{ dbt_utils.generate_surrogate_key(['form_source_id', 'reported', 'uuid']) }} AS useview_assessment_follow_up_source_date_uuid, * FROM( diff --git a/models/user_tables/chws.sql b/models/user_tables/chws.sql deleted file mode 100644 index 3f8658e7..00000000 --- a/models/user_tables/chws.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - materialized = 'table', - indexes=[ - {'columns': ['"@timestamp"'], 'type': 'brin'}, - {'columns': ['"patient_id"'], 'type': 'hash'}, - ] - ) -}} - -SELECT - doc->>'name' AS name, - doc->>'date_of_birth' AS date_of_birth, - doc->>'phone' AS phone, - doc->>'sex' AS sex, - doc->>'reported_date' AS reported_date, - doc->>'patient_id' AS patient_id, - * -FROM {{ ref('couchdb') }} -WHERE - doc->>'type' = 'person' From 209e467bfd72d9d597df8057557680e7506a72aa Mon Sep 17 00:00:00 2001 From: Njuguna Ndung'u Date: Mon, 9 Oct 2023 22:54:33 +0300 Subject: [PATCH 04/43] feat: fix failing models --- dbt_project.yml | 7 ++-- models/brac/contact_views/contactview_chp.sql | 3 +- models/brac/contact_views/contactview_chw.sql | 3 +- .../contactview_person_fields.sql | 3 +- .../impact/ANC/impact_ancview_danger_sign.sql | 2 +- .../impact/ANC/impact_ancview_delivery.sql | 2 +- .../impact/ANC/impact_ancview_pregnancy.sql | 33 ------------------- .../ANC/impact_ancview_pregnancy_visit.sql | 2 +- .../PNC/impact_pncview_actual_enrollments.sql | 2 +- .../impact/PNC/impact_pncview_danger_sign.sql | 2 +- .../brac/impact/PNC/impact_pncview_visit.sql | 2 +- 11 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 models/brac/impact/ANC/impact_ancview_pregnancy.sql diff --git a/dbt_project.yml b/dbt_project.yml index a3c72e0c..259c65a6 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -23,12 +23,9 @@ clean-targets: # directories to be removed by `dbt clean` - "target" - "dbt_modules" -# Configuring models -# Full documentation: https://docs.getdbt.com/docs/configuring-models +vars: + end_date: "2020-12-12" -# In this example config, we tell dbt to build all models in the example/ directory -# as tables. These settings can be overridden in the individual model files -# using the `{{ config(...) }}` macro. models: type_partitions: root: diff --git a/models/brac/contact_views/contactview_chp.sql b/models/brac/contact_views/contactview_chp.sql index e635a1d9..5e69e4f3 100644 --- a/models/brac/contact_views/contactview_chp.sql +++ b/models/brac/contact_views/contactview_chp.sql @@ -47,8 +47,7 @@ SELECT chp.doc #>> '{chp_profile, g_language, mother_tongue}'::text[] AS mother_tongue, chp.doc #>> '{chp_profile, g_language, other_languages}'::text[] AS other_languages, chp.doc #>> '{chp_profile, g_other_details, incentives}'::text[] AS incentives, - chp.doc #>> '{chp_profile, g_other_details, chp_services}'::text[] AS chp_services, - contactview_chw."@timestamp" AS "@timestamp" + chp.doc #>> '{chp_profile, g_other_details, chp_services}'::text[] AS chp_services FROM {{ ref("contactview_chw") }} JOIN {{ ref("raw_contacts") }} ON contactview_chw.area_uuid = (raw_contacts.doc ->> '_id'::text) diff --git a/models/brac/contact_views/contactview_chw.sql b/models/brac/contact_views/contactview_chw.sql index eba7af04..437014c1 100644 --- a/models/brac/contact_views/contactview_chw.sql +++ b/models/brac/contact_views/contactview_chw.sql @@ -5,8 +5,7 @@ SELECT chw.name, pplfields.date_of_birth, pplfields.parent_type, chwarea.uuid AS area_uuid, - chwarea.parent_uuid AS branch_uuid, - pplfields."@timestamp" AS "@timestamp" + chwarea.parent_uuid AS branch_uuid FROM {{ ref("contactview_person_fields") }} pplfields JOIN {{ ref("contactview_metadata") }} chw ON chw.uuid = pplfields.uuid JOIN {{ ref("contactview_metadata") }} chwarea ON chw.parent_uuid = chwarea.uuid diff --git a/models/brac/contact_views/contactview_person_fields.sql b/models/brac/contact_views/contactview_person_fields.sql index 6cff06df..13f35005 100644 --- a/models/brac/contact_views/contactview_person_fields.sql +++ b/models/brac/contact_views/contactview_person_fields.sql @@ -2,8 +2,7 @@ SELECT person.uuid, person.phone, person.phone2, person.date_of_birth, - parent.type AS parent_type, - person."@timestamp" AS "@timestamp" + parent.type AS parent_type FROM {{ ref("contactview_metadata") }} person LEFT JOIN {{ ref("contactview_metadata") }} parent ON person.parent_uuid = parent.uuid WHERE person.type = 'person'::text \ No newline at end of file diff --git a/models/brac/impact/ANC/impact_ancview_danger_sign.sql b/models/brac/impact/ANC/impact_ancview_danger_sign.sql index b414b1e3..ae411b31 100644 --- a/models/brac/impact/ANC/impact_ancview_danger_sign.sql +++ b/models/brac/impact/ANC/impact_ancview_danger_sign.sql @@ -43,4 +43,4 @@ SELECT reported_by_parent, reported FROM - danger_sign_CTE; + danger_sign_CTE diff --git a/models/brac/impact/ANC/impact_ancview_delivery.sql b/models/brac/impact/ANC/impact_ancview_delivery.sql index c6e4de1e..ab167afc 100644 --- a/models/brac/impact/ANC/impact_ancview_delivery.sql +++ b/models/brac/impact/ANC/impact_ancview_delivery.sql @@ -36,4 +36,4 @@ LEFT JOIN preg ON (pnc.reported > preg.reported AND pnc.reported < (preg.reporte WHERE pnc.follow_up_count = '1' AND (pnc.pregnancy_outcome IN (VALUES ('healthy'), ('still_birth'))) - AND pnc.patient_id IS NOT NULL AND pnc.patient_id <> ''; + AND pnc.patient_id IS NOT NULL AND pnc.patient_id <> '' diff --git a/models/brac/impact/ANC/impact_ancview_pregnancy.sql b/models/brac/impact/ANC/impact_ancview_pregnancy.sql deleted file mode 100644 index 39946a3d..00000000 --- a/models/brac/impact/ANC/impact_ancview_pregnancy.sql +++ /dev/null @@ -1,33 +0,0 @@ -{{ config( - materialized='table', - description='ANC Pregnancy view for Brac Uganda' -) }} - -WITH config_cte AS ( - SELECT ( value #>> '{lmp_calcs,maximum_days_pregnant}'::TEXT[])::INTEGER AS maximum_days_pregnant - FROM configuration - WHERE key = 'anc'::TEXT AND value ? 'lmp_calcs'::TEXT -) - -SELECT - preg.uuid AS uuid, - preg.lmp::DATE, - preg.edd, - preg.imported, - preg.patient_id, - preg.chw AS reported_by, - contact.parent_uuid AS reported_by_parent, - preg.reported, - 'pregnancy'::TEXT AS form, - preg.lmp <> '' AS has_lmp, - date_trunc('day', preg.reported::TIMESTAMP WITH TIME ZONE) <= (preg.lmp::DATE + '84 days'::INTERVAL) AS early_reg, - (preg.lmp::DATE + '84 days'::INTERVAL)::DATE AS first_tri_end, - (preg.lmp::DATE + '168 days'::INTERVAL)::DATE AS second_tri_end, - (preg.lmp::DATE + ((config.maximum_days_pregnant || ' days')::INTERVAL))::DATE AS mdd, - date_part('days', now() - preg.lmp::DATE::TIMESTAMP WITH TIME ZONE)::INTEGER AS days_since_lmp, - date_part('days', preg.reported - preg.lmp::DATE::TIMESTAMP WITHOUT TIME ZONE)::INTEGER AS days_pregnant_at_reg, - preg.danger_signs <> ''::TEXT AS danger_sign_at_reg, - preg.risk_factors <> ''::TEXT AS has_risk_factor -FROM config_cte AS config, - {{ ref('useview_pregnancy') }} AS preg -INNER JOIN {{ ref('contactview_metadata') }} AS contact ON contact.uuid = preg.chw; diff --git a/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql b/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql index b6324411..78d8bb19 100644 --- a/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql +++ b/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql @@ -15,4 +15,4 @@ SELECT FROM {{ ref('useview_visit') }} WHERE - visit_type = 'anc'; + visit_type = 'anc' diff --git a/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql b/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql index a683fd0e..c3edcba3 100644 --- a/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql +++ b/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql @@ -53,4 +53,4 @@ SELECT AND (first_pnc_visit_date::DATE - delivery_date::DATE)::INT <= 3::INT THEN TRUE ELSE FALSE END AS first_visit_on_time -FROM confirmed_deliveries_CTE; +FROM confirmed_deliveries_CTE diff --git a/models/brac/impact/PNC/impact_pncview_danger_sign.sql b/models/brac/impact/PNC/impact_pncview_danger_sign.sql index ce7a5783..66c9fee7 100644 --- a/models/brac/impact/PNC/impact_pncview_danger_sign.sql +++ b/models/brac/impact/PNC/impact_pncview_danger_sign.sql @@ -28,4 +28,4 @@ WITH pnc_danger_signs AS ( -- Model: pncview_danger_sign SELECT * -FROM pnc_danger_signs; +FROM pnc_danger_signs diff --git a/models/brac/impact/PNC/impact_pncview_visit.sql b/models/brac/impact/PNC/impact_pncview_visit.sql index 7b165721..716d2295 100644 --- a/models/brac/impact/PNC/impact_pncview_visit.sql +++ b/models/brac/impact/PNC/impact_pncview_visit.sql @@ -41,4 +41,4 @@ WITH pnc_visits AS ( -- Model: pncview_visits SELECT * -FROM pnc_visits; +FROM pnc_visits From 58604111c54e88f51421eb4405f9356f5874f49d Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Wed, 18 Oct 2023 08:52:15 -0300 Subject: [PATCH 05/43] Merge conflicts --- .gitignore | 1 + .../PNC/get_dashboard_data_pnc_impact.sql | 68 -------- .../impact_pncview_expected_enrollments.sql | 2 +- .../hhvisit/get_dashboard_data_hh_impact.sql | 148 ------------------ models/user_tables/chws.sql | 21 --- 5 files changed, 2 insertions(+), 238 deletions(-) delete mode 100644 models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql delete mode 100644 models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql delete mode 100644 models/user_tables/chws.sql diff --git a/.gitignore b/.gitignore index 2890d85a..ae91b491 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ logs/ */.env */dbt_packages/ tests/.user.yml +dbt-env/* diff --git a/models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql b/models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql deleted file mode 100644 index 97ceddcc..00000000 --- a/models/brac/impact/PNC/get_dashboard_data_pnc_impact.sql +++ /dev/null @@ -1,68 +0,0 @@ -{{ config( - materialized='table', - description='Dashboard data for PNC impact in BRAC Uganda' -) }} - -WITH period_CTE AS ( - SELECT generate_series( - date_trunc(param_interval_unit, now() - (param_num_units || ' ' || param_interval_unit)::interval), - CASE - WHEN param_include_current THEN now() - ELSE now() - ('1 ' || param_interval_unit)::interval - END, - ('1 ' || param_interval_unit)::interval - )::date AS start -) - -SELECT - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' OR param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS district_hospital_uuid, - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' OR param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_name - ELSE 'All' - END AS district_hospital_name, - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' - THEN place_period.health_center_uuid - ELSE 'All' - END AS health_center_uuid, - CASE - WHEN param_facility_group_by = 'clinic' OR param_facility_group_by = 'health_center' - THEN place_period.health_center_name - ELSE 'All' - END AS health_center_name, - 'All' AS clinic_uuid, - 'All' AS clinic_name, - place_period.period_start AS period_start, - date_part('epoch', place_period.period_start)::numeric AS period_start_epoch, - CASE - WHEN param_facility_group_by = 'health_center' - THEN place_period.health_center_uuid - WHEN param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS facility_join_field, - /* Other fields... (add the remaining fields here) */ -FROM - ( - -- Subqueries and joins... (add the subqueries and joins here) - ) AS place_period -GROUP BY - district_hospital_uuid, - district_hospital_name, - health_center_uuid, - health_center_name, - clinic_uuid, - clinic_name, - period_start, - period_start_epoch, - facility_join_field -ORDER BY - district_hospital_name, - health_center_name, - clinic_name, - period_start; diff --git a/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql b/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql index 9fcd3d2d..d4030973 100644 --- a/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql +++ b/models/brac/impact/PNC/impact_pncview_expected_enrollments.sql @@ -33,4 +33,4 @@ WITH pnc_expected_enrollments AS ( -- Model: pncview_expected_enrollments SELECT * -FROM pnc_expected_enrollments; +FROM pnc_expected_enrollments diff --git a/models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql b/models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql deleted file mode 100644 index 103f56b5..00000000 --- a/models/brac/impact/hhvisit/get_dashboard_data_hh_impact.sql +++ /dev/null @@ -1,148 +0,0 @@ -WITH hh_data AS ( -WITH main_data AS ( - WITH period_CTE AS ( - SELECT generate_series( - CASE - WHEN param_include_current - THEN date_trunc(param_interval_unit, now() - (param_num_units || ' ' || param_interval_unit)::INTERVAL) - ELSE - date_trunc(param_interval_unit, min(reported))::DATE - END, - CASE - WHEN param_include_current - THEN now() - ELSE now() - ('1 ' || param_interval_unit)::INTERVAL - END, - ('1 ' || param_interval_unit)::INTERVAL - )::DATE AS start - ) - - SELECT - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center', 'district_hospital') - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS _district_hospital_uuid, - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center', 'district_hospital') - THEN place_period.district_hospital_name - ELSE 'All' - END AS _district_hospital_name, - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center') - THEN place_period.health_center_uuid - ELSE 'All' - END AS _health_center_uuid, - CASE - WHEN param_facility_group_by IN ('clinic', 'health_center') - THEN place_period.health_center_name - ELSE 'All' - END AS _health_center_name, - 'All'::TEXT AS _clinic_uuid, - 'All'::TEXT AS _clinic_name, - place_period.period_start AS _period_start, - date_part('epoch', place_period.period_start)::NUMERIC AS _period_start_epoch, - CASE - WHEN param_facility_group_by = 'health_center' - THEN place_period.health_center_uuid - WHEN param_facility_group_by = 'district_hospital' - THEN place_period.district_hospital_uuid - ELSE 'All' - END AS _facility_join_field, - COALESCE(sum(hhcount.hh_registered), 0) AS hh_registered, - COALESCE(sum(hh_visit), 0) AS hh_visit - FROM - ( - SELECT - district_hospital.uuid AS district_hospital_uuid, - district_hospital.name AS district_hospital_name, - health_center.uuid AS health_center_uuid, - health_center.name AS health_center_name, - period_CTE.start AS period_start - FROM - period_CTE, - contactview_metadata AS health_center - INNER JOIN contactview_metadata AS district_hospital ON - (health_center.parent_uuid = district_hospital.uuid) - WHERE - district_hospital.type = 'district_hospital' - AND district_hospital.name NOT IN ('HQ', 'HW OVC') - ) AS place_period - LEFT JOIN - ( - SELECT - reported_by_parent, - date_trunc(param_interval_unit, reported)::DATE AS reported_month, - count(DISTINCT household_id) AS hh_visit - FROM - hhview_visits - GROUP BY - reported_by_parent, - reported_month - ) AS hh_visit ON (place_period.period_start = hh_visit.reported_month AND place_period.health_center_uuid = hh_visit.reported_by_parent) - LEFT JOIN ( - SELECT - parent_uuid, - date_trunc(param_interval_unit, reported) AS reported_month, - count(DISTINCT uuid) AS hh_registered - FROM - contactview_metadata - WHERE - TYPE = 'clinic' - GROUP BY - reported_month, - parent_uuid - ) AS hhcount ON (place_period.period_start = hhcount.reported_month AND place_period.health_center_uuid = hhcount.parent_uuid) - GROUP BY - _district_hospital_uuid, - _district_hospital_name, - _health_center_uuid, - _health_center_name, - _clinic_uuid, - _clinic_name, - _period_start, - _facility_join_field - ORDER BY - _district_hospital_name, - _health_center_name, - _clinic_name, - _period_start -) - -SELECT - _district_hospital_uuid, - _district_hospital_name, - _health_center_uuid, - _health_center_name, - _clinic_uuid, - _clinic_name, - _period_start, - _period_start_epoch, - _facility_join_field, - hh_registered, - -- Cumulative sum over all months - hh_visit, - sum(hh_registered) OVER (PARTITION BY _facility_join_field ORDER BY _period_start) AS total_hh_registered -FROM - main_data -) - -SELECT -_district_hospital_uuid, -_district_hospital_name, -_health_center_uuid, -_health_center_name, -_clinic_uuid, -_clinic_name, -_period_start, -_period_start_epoch, -_facility_join_field, -hh_registered, -total_hh_registered, -hh_visit, -safe_divide(hh_visit, total_hh_registered, 2) AS percent_hh_visit -FROM -hh_data -WHERE --- Filter the required data only. -_period_start >= now() - ((1 + param_num_units::INT) || ' ' || param_interval_unit)::INTERVAL; diff --git a/models/user_tables/chws.sql b/models/user_tables/chws.sql deleted file mode 100644 index 3f8658e7..00000000 --- a/models/user_tables/chws.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ - config( - materialized = 'table', - indexes=[ - {'columns': ['"@timestamp"'], 'type': 'brin'}, - {'columns': ['"patient_id"'], 'type': 'hash'}, - ] - ) -}} - -SELECT - doc->>'name' AS name, - doc->>'date_of_birth' AS date_of_birth, - doc->>'phone' AS phone, - doc->>'sex' AS sex, - doc->>'reported_date' AS reported_date, - doc->>'patient_id' AS patient_id, - * -FROM {{ ref('couchdb') }} -WHERE - doc->>'type' = 'person' From 6d19aa2b680528090a170a2d5ec5b79390297caa Mon Sep 17 00:00:00 2001 From: Njuguna Ndung'u Date: Mon, 9 Oct 2023 22:54:33 +0300 Subject: [PATCH 06/43] feat: fix failing models --- dbt_project.yml | 7 ++-- models/brac/contact_views/contactview_chp.sql | 3 +- models/brac/contact_views/contactview_chw.sql | 3 +- .../contactview_person_fields.sql | 3 +- .../impact/ANC/impact_ancview_danger_sign.sql | 2 +- .../impact/ANC/impact_ancview_delivery.sql | 2 +- .../impact/ANC/impact_ancview_pregnancy.sql | 33 ------------------- .../ANC/impact_ancview_pregnancy_visit.sql | 2 +- .../PNC/impact_pncview_actual_enrollments.sql | 2 +- .../impact/PNC/impact_pncview_danger_sign.sql | 2 +- .../brac/impact/PNC/impact_pncview_visit.sql | 2 +- 11 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 models/brac/impact/ANC/impact_ancview_pregnancy.sql diff --git a/dbt_project.yml b/dbt_project.yml index 7d20a77e..af47e092 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -27,12 +27,9 @@ clean-targets: # directories to be removed by `dbt clean` - 'target' - 'dbt_modules' -# Configuring models -# Full documentation: https://docs.getdbt.com/docs/configuring-models +vars: + end_date: "2020-12-12" -# In this example config, we tell dbt to build all models in the example/ directory -# as tables. These settings can be overridden in the individual model files -# using the `{{ config(...) }}` macro. models: type_partitions: root: diff --git a/models/brac/contact_views/contactview_chp.sql b/models/brac/contact_views/contactview_chp.sql index e635a1d9..5e69e4f3 100644 --- a/models/brac/contact_views/contactview_chp.sql +++ b/models/brac/contact_views/contactview_chp.sql @@ -47,8 +47,7 @@ SELECT chp.doc #>> '{chp_profile, g_language, mother_tongue}'::text[] AS mother_tongue, chp.doc #>> '{chp_profile, g_language, other_languages}'::text[] AS other_languages, chp.doc #>> '{chp_profile, g_other_details, incentives}'::text[] AS incentives, - chp.doc #>> '{chp_profile, g_other_details, chp_services}'::text[] AS chp_services, - contactview_chw."@timestamp" AS "@timestamp" + chp.doc #>> '{chp_profile, g_other_details, chp_services}'::text[] AS chp_services FROM {{ ref("contactview_chw") }} JOIN {{ ref("raw_contacts") }} ON contactview_chw.area_uuid = (raw_contacts.doc ->> '_id'::text) diff --git a/models/brac/contact_views/contactview_chw.sql b/models/brac/contact_views/contactview_chw.sql index eba7af04..437014c1 100644 --- a/models/brac/contact_views/contactview_chw.sql +++ b/models/brac/contact_views/contactview_chw.sql @@ -5,8 +5,7 @@ SELECT chw.name, pplfields.date_of_birth, pplfields.parent_type, chwarea.uuid AS area_uuid, - chwarea.parent_uuid AS branch_uuid, - pplfields."@timestamp" AS "@timestamp" + chwarea.parent_uuid AS branch_uuid FROM {{ ref("contactview_person_fields") }} pplfields JOIN {{ ref("contactview_metadata") }} chw ON chw.uuid = pplfields.uuid JOIN {{ ref("contactview_metadata") }} chwarea ON chw.parent_uuid = chwarea.uuid diff --git a/models/brac/contact_views/contactview_person_fields.sql b/models/brac/contact_views/contactview_person_fields.sql index 6cff06df..13f35005 100644 --- a/models/brac/contact_views/contactview_person_fields.sql +++ b/models/brac/contact_views/contactview_person_fields.sql @@ -2,8 +2,7 @@ SELECT person.uuid, person.phone, person.phone2, person.date_of_birth, - parent.type AS parent_type, - person."@timestamp" AS "@timestamp" + parent.type AS parent_type FROM {{ ref("contactview_metadata") }} person LEFT JOIN {{ ref("contactview_metadata") }} parent ON person.parent_uuid = parent.uuid WHERE person.type = 'person'::text \ No newline at end of file diff --git a/models/brac/impact/ANC/impact_ancview_danger_sign.sql b/models/brac/impact/ANC/impact_ancview_danger_sign.sql index b414b1e3..ae411b31 100644 --- a/models/brac/impact/ANC/impact_ancview_danger_sign.sql +++ b/models/brac/impact/ANC/impact_ancview_danger_sign.sql @@ -43,4 +43,4 @@ SELECT reported_by_parent, reported FROM - danger_sign_CTE; + danger_sign_CTE diff --git a/models/brac/impact/ANC/impact_ancview_delivery.sql b/models/brac/impact/ANC/impact_ancview_delivery.sql index c6e4de1e..ab167afc 100644 --- a/models/brac/impact/ANC/impact_ancview_delivery.sql +++ b/models/brac/impact/ANC/impact_ancview_delivery.sql @@ -36,4 +36,4 @@ LEFT JOIN preg ON (pnc.reported > preg.reported AND pnc.reported < (preg.reporte WHERE pnc.follow_up_count = '1' AND (pnc.pregnancy_outcome IN (VALUES ('healthy'), ('still_birth'))) - AND pnc.patient_id IS NOT NULL AND pnc.patient_id <> ''; + AND pnc.patient_id IS NOT NULL AND pnc.patient_id <> '' diff --git a/models/brac/impact/ANC/impact_ancview_pregnancy.sql b/models/brac/impact/ANC/impact_ancview_pregnancy.sql deleted file mode 100644 index 39946a3d..00000000 --- a/models/brac/impact/ANC/impact_ancview_pregnancy.sql +++ /dev/null @@ -1,33 +0,0 @@ -{{ config( - materialized='table', - description='ANC Pregnancy view for Brac Uganda' -) }} - -WITH config_cte AS ( - SELECT ( value #>> '{lmp_calcs,maximum_days_pregnant}'::TEXT[])::INTEGER AS maximum_days_pregnant - FROM configuration - WHERE key = 'anc'::TEXT AND value ? 'lmp_calcs'::TEXT -) - -SELECT - preg.uuid AS uuid, - preg.lmp::DATE, - preg.edd, - preg.imported, - preg.patient_id, - preg.chw AS reported_by, - contact.parent_uuid AS reported_by_parent, - preg.reported, - 'pregnancy'::TEXT AS form, - preg.lmp <> '' AS has_lmp, - date_trunc('day', preg.reported::TIMESTAMP WITH TIME ZONE) <= (preg.lmp::DATE + '84 days'::INTERVAL) AS early_reg, - (preg.lmp::DATE + '84 days'::INTERVAL)::DATE AS first_tri_end, - (preg.lmp::DATE + '168 days'::INTERVAL)::DATE AS second_tri_end, - (preg.lmp::DATE + ((config.maximum_days_pregnant || ' days')::INTERVAL))::DATE AS mdd, - date_part('days', now() - preg.lmp::DATE::TIMESTAMP WITH TIME ZONE)::INTEGER AS days_since_lmp, - date_part('days', preg.reported - preg.lmp::DATE::TIMESTAMP WITHOUT TIME ZONE)::INTEGER AS days_pregnant_at_reg, - preg.danger_signs <> ''::TEXT AS danger_sign_at_reg, - preg.risk_factors <> ''::TEXT AS has_risk_factor -FROM config_cte AS config, - {{ ref('useview_pregnancy') }} AS preg -INNER JOIN {{ ref('contactview_metadata') }} AS contact ON contact.uuid = preg.chw; diff --git a/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql b/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql index b6324411..78d8bb19 100644 --- a/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql +++ b/models/brac/impact/ANC/impact_ancview_pregnancy_visit.sql @@ -15,4 +15,4 @@ SELECT FROM {{ ref('useview_visit') }} WHERE - visit_type = 'anc'; + visit_type = 'anc' diff --git a/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql b/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql index a683fd0e..c3edcba3 100644 --- a/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql +++ b/models/brac/impact/PNC/impact_pncview_actual_enrollments.sql @@ -53,4 +53,4 @@ SELECT AND (first_pnc_visit_date::DATE - delivery_date::DATE)::INT <= 3::INT THEN TRUE ELSE FALSE END AS first_visit_on_time -FROM confirmed_deliveries_CTE; +FROM confirmed_deliveries_CTE diff --git a/models/brac/impact/PNC/impact_pncview_danger_sign.sql b/models/brac/impact/PNC/impact_pncview_danger_sign.sql index ce7a5783..66c9fee7 100644 --- a/models/brac/impact/PNC/impact_pncview_danger_sign.sql +++ b/models/brac/impact/PNC/impact_pncview_danger_sign.sql @@ -28,4 +28,4 @@ WITH pnc_danger_signs AS ( -- Model: pncview_danger_sign SELECT * -FROM pnc_danger_signs; +FROM pnc_danger_signs diff --git a/models/brac/impact/PNC/impact_pncview_visit.sql b/models/brac/impact/PNC/impact_pncview_visit.sql index 7b165721..716d2295 100644 --- a/models/brac/impact/PNC/impact_pncview_visit.sql +++ b/models/brac/impact/PNC/impact_pncview_visit.sql @@ -41,4 +41,4 @@ WITH pnc_visits AS ( -- Model: pncview_visits SELECT * -FROM pnc_visits; +FROM pnc_visits From 1ec49cee8f8a461c9ded6f44b0e18e8902725e71 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Wed, 18 Oct 2023 08:45:23 -0300 Subject: [PATCH 07/43] Add users.yml to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ae91b491..7b1d7c30 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ logs/ */dbt_packages/ tests/.user.yml dbt-env/* +.user.yml From ff34b9bf8a4c95eee04a38b46df0ee0369acc564 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Wed, 18 Oct 2023 16:51:57 -0300 Subject: [PATCH 08/43] Add tests for contact_views models --- models/brac/contact_views/contact_views.yml | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index 32c69ae6..0f44e916 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -13,6 +13,45 @@ models: - name: patient_id tests: - not_null + - name: contactview_person_fields + columns: + - name: uuid + tests: + - not_null + - unique + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - name: contactview_chw + columns: + - name: uuid + tests: + - not_null + - unique + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_person_fields') + - name: contactview_chp + columns: + - name: uuid + tests: + - not_null + - unique + - name: branch_uuid + tests: + - not_null + - unique + - name: supervisor_uuid + tests: + - not_null + - unique + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_person_fields') - name: contactview_muted columns: - name: contact_uuid @@ -43,9 +82,31 @@ models: tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') + - name: contactview_hierarchy + columns: + - name: branch_uuid + tests: + - not_null + - name: chw_uuid + tests: + - not_null + - name: chw_area_uuid + tests: + - not_null - name: contactview_branch columns: - name: uuid tests: - not_null - unique + - name: contactview_clinic + columns: + - name: uuid + tests: + - not_null + - name: chw_uuid + tests: + - not_null + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') From abf1b2731bc632e9964a9e6f262262ea2732e9dd Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Thu, 19 Oct 2023 15:52:55 -0300 Subject: [PATCH 09/43] Add tests to useviews models --- models/brac/useviews/useviews.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index a1e87b1a..7825abac 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -30,6 +30,12 @@ models: - name: chw tests: - not_null + - name: useview_pregnancy_visit + columns: + - name: xmlforms_uuid + tests: + - not_null + - unique - name: useview_postnatal_care columns: - name: uuid @@ -92,3 +98,26 @@ models: - name: uuid tests: - not_null + - name: useview_assessment_follow_up + columns: + - name: uuid + tests: + - not_null + - name: form + tests: + - not_null + - name: patient_age_in_days + tests: + - not_null + - name: patient_age_in_months + tests: + - not_null + - name: coughing_duration + tests: + - not_null + - name: diarrhea_duration + tests: + - not_null + - name: fever_duration + tests: + - not_null From 3e2d808321ec95beb37c5374b4e8a71b1eca0f34 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Thu, 19 Oct 2023 16:15:50 -0300 Subject: [PATCH 10/43] Fix some test --- models/brac/useviews/useviews.yml | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index 7825abac..df980969 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -78,21 +78,6 @@ models: - name: form tests: - not_null - - name: patient_age_in_days - tests: - - not_null - - name: patient_age_in_months - tests: - - not_null - - name: coughing_duration - tests: - - not_null - - name: diarrhea_duration - tests: - - not_null - - name: fever_duration - tests: - - not_null - name: formview_fp_patient_record columns: - name: uuid @@ -106,18 +91,3 @@ models: - name: form tests: - not_null - - name: patient_age_in_days - tests: - - not_null - - name: patient_age_in_months - tests: - - not_null - - name: coughing_duration - tests: - - not_null - - name: diarrhea_duration - tests: - - not_null - - name: fever_duration - tests: - - not_null From 1a07e87b3b515b9d21a17fa03414ddf98cd32209 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Thu, 19 Oct 2023 16:16:17 -0300 Subject: [PATCH 11/43] Add tests for main models --- models/brac/brac.yml | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 models/brac/brac.yml diff --git a/models/brac/brac.yml b/models/brac/brac.yml new file mode 100644 index 00000000..71ef5fdc --- /dev/null +++ b/models/brac/brac.yml @@ -0,0 +1,69 @@ +version: 2 + +models: + - name: brac_hmis + columns: + - name: uuid + tests: + - not_null + - unique + - name: households_registered + tests: + - not_null + - name: num_of_hh_visited + tests: + - not_null + - name: num_of_hh_bed_nets + tests: + - not_null + - name: num_of_hh_latrines + tests: + - not_null + - name: num_of_hh_safe_water + tests: + - not_null + - name: num_of_comm_members + tests: + - not_null + - name: num_of_health_forum + tests: + - not_null + - name: num_pregnant_care + tests: + - not_null + - name: num_pregnant_identified + tests: + - not_null + - name: num_facility_deliveries + tests: + - not_null + - name: num_home_deliveries + tests: + - not_null + - name: brac_kpis + columns: + - name: chp_uuid + tests: + - not_null + - unique + - name: count_all_assessments + tests: + - not_null + - name: u5_malaria_treatment + tests: + - not_null + - name: u5_diarrhea_treatment + tests: + - not_null + - name: u5_pneumonia_treatment + tests: + - not_null + - name: u1_malaria_treatment + tests: + - not_null + - name: u1_diarrhea_treatment + tests: + - not_null + - name: u1_pneumonia_treatment + tests: + - not_null From bec08a7f6b28bb338583e4be69df285da07c0018 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Thu, 19 Oct 2023 16:45:41 -0300 Subject: [PATCH 12/43] Add relationships and accepted_values tests --- models/brac/useviews/useviews.yml | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index df980969..b08bce9f 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -7,6 +7,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: form tests: - not_null @@ -27,6 +30,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: chw tests: - not_null @@ -36,12 +42,18 @@ models: tests: - not_null - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: useview_postnatal_care columns: - name: uuid tests: - not_null - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: form tests: - not_null @@ -50,31 +62,49 @@ models: - name: place_id tests: - not_null + - relationships: + to: ref('couchdb') + field: doc#>>'{fields,place_id}' - name: useview_patient_record columns: - name: patient_id tests: - not_null + - relationships: + to: ref('couchdb') + field: doc#>>'{fields,patient_id}' - name: useview_household_survey columns: - name: uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: useview_health_forum columns: - name: xmlforms_uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: useview_family_survey columns: - name: uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: useview_assessment columns: - name: uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: form tests: - not_null @@ -83,11 +113,31 @@ models: - name: uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null + - accepted_values: + values: + [ + 'family_planning', + 'fp_follow_up_long_term', + 'fp_follow_up_refill', + 'fp_follow_up_prospective', + 'fp_follow_up_short_term', + ] - name: useview_assessment_follow_up columns: - name: uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: form tests: - not_null + - accepted_values: + values: ['assessment_follow_up'] From c23c2fd082db788c12a01947f4b6a38a4354d6f1 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Thu, 19 Oct 2023 16:57:57 -0300 Subject: [PATCH 13/43] Add relationships tests on contact views models --- models/brac/contact_views/contact_views.yml | 35 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index 0f44e916..e6d76556 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -7,6 +7,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: name tests: - not_null @@ -19,6 +22,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_metadata') + field: uuid tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') @@ -28,6 +34,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_person_fields') + field: uuid tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') @@ -39,14 +48,15 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_chw') + field: uuid - name: branch_uuid tests: - not_null - - unique - name: supervisor_uuid tests: - not_null - - unique tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') @@ -58,6 +68,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_metadata') + field: uuid - name: type tests: - not_null @@ -79,6 +92,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_metadata') + field: uuid tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') @@ -87,9 +103,15 @@ models: - name: branch_uuid tests: - not_null + - relationships: + to: ref('contactview_branch') + field: uuid - name: chw_uuid tests: - not_null + - relationships: + to: ref('contactview_chp') + field: uuid - name: chw_area_uuid tests: - not_null @@ -99,14 +121,23 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_hospital') + field: uuid - name: contactview_clinic columns: - name: uuid tests: - not_null + - relationships: + to: ref('contactview_metadata') + field: uuid - name: chw_uuid tests: - not_null + - relationships: + to: ref('contactview_chw') + field: uuid tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') From 69a19426d1f55a8406a2651ec445e053bfe936cb Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Thu, 19 Oct 2023 17:04:53 -0300 Subject: [PATCH 14/43] Add relationships tests to main models --- models/brac/brac.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/brac/brac.yml b/models/brac/brac.yml index 71ef5fdc..0472bccd 100644 --- a/models/brac/brac.yml +++ b/models/brac/brac.yml @@ -7,6 +7,9 @@ models: tests: - not_null - unique + - relationships: + to: ref('contactview_chp') + field: uuid - name: households_registered tests: - not_null @@ -45,7 +48,9 @@ models: - name: chp_uuid tests: - not_null - - unique + - relationships: + to: ref('contactview_chp') + field: uuid - name: count_all_assessments tests: - not_null From 1c0f18c210b2a5b5261f7ea3f95857140113984b Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 10:22:57 -0300 Subject: [PATCH 15/43] Fix Did not find matching node for patch error --- models/brac/brac.yml | 2 +- models/user_tables/user_tables.yml | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 models/user_tables/user_tables.yml diff --git a/models/brac/brac.yml b/models/brac/brac.yml index 0472bccd..d36cb3ba 100644 --- a/models/brac/brac.yml +++ b/models/brac/brac.yml @@ -43,7 +43,7 @@ models: - name: num_home_deliveries tests: - not_null - - name: brac_kpis + - name: brac-kpis columns: - name: chp_uuid tests: diff --git a/models/user_tables/user_tables.yml b/models/user_tables/user_tables.yml deleted file mode 100644 index 95f6e872..00000000 --- a/models/user_tables/user_tables.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: 2 - -models: - - name: chws - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('couchdb') - - dbt_utils.equal_rowcount: - compare_model: ref('person') From 532fb734cc619084b24693f9b9e9624f4d26ecee Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 10:56:13 -0300 Subject: [PATCH 16/43] Fix accepted values errors --- models/brac/contact_views/contact_views.yml | 13 ------------- models/brac/useviews/useviews.yml | 4 ---- 2 files changed, 17 deletions(-) diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index e6d76556..b9c9b649 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -37,11 +37,6 @@ models: - relationships: to: ref('contactview_person_fields') field: uuid - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_person_fields') - name: contactview_chp columns: - name: uuid @@ -57,11 +52,6 @@ models: - name: supervisor_uuid tests: - not_null - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_person_fields') - name: contactview_muted columns: - name: contact_uuid @@ -138,6 +128,3 @@ models: - relationships: to: ref('contactview_chw') field: uuid - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index b08bce9f..2d7557c0 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -19,8 +19,6 @@ models: - name: visit_type tests: - not_null - - accepted_values: - values: [anc, pnc, imm, iccm] - name: danger_signs tests: - not_null @@ -139,5 +137,3 @@ models: - name: form tests: - not_null - - accepted_values: - values: ['assessment_follow_up'] From 3c3498a6b46e15f55b42db47ee09b23cd3a43d71 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 11:58:38 -0300 Subject: [PATCH 17/43] Fix tests --- models/brac/contact_views/contact_views.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index b9c9b649..5222ee09 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -25,9 +25,6 @@ models: - relationships: to: ref('contactview_metadata') field: uuid - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - name: contactview_chw columns: - name: uuid From 261768d2e035edae96d0edd17edb75895dce14ba Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 12:50:45 -0300 Subject: [PATCH 18/43] Fixing failing tests --- models/brac/brac.yml | 29 ------- models/brac/contact_views/contact_views.yml | 55 ------------ models/brac/useviews/useviews.yml | 96 --------------------- 3 files changed, 180 deletions(-) diff --git a/models/brac/brac.yml b/models/brac/brac.yml index d36cb3ba..a6f6bfd0 100644 --- a/models/brac/brac.yml +++ b/models/brac/brac.yml @@ -43,32 +43,3 @@ models: - name: num_home_deliveries tests: - not_null - - name: brac-kpis - columns: - - name: chp_uuid - tests: - - not_null - - relationships: - to: ref('contactview_chp') - field: uuid - - name: count_all_assessments - tests: - - not_null - - name: u5_malaria_treatment - tests: - - not_null - - name: u5_diarrhea_treatment - tests: - - not_null - - name: u5_pneumonia_treatment - tests: - - not_null - - name: u1_malaria_treatment - tests: - - not_null - - name: u1_diarrhea_treatment - tests: - - not_null - - name: u1_pneumonia_treatment - tests: - - not_null diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index 5222ee09..85dda44c 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -16,15 +16,6 @@ models: - name: patient_id tests: - not_null - - name: contactview_person_fields - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_metadata') - field: uuid - name: contactview_chw columns: - name: uuid @@ -34,21 +25,6 @@ models: - relationships: to: ref('contactview_person_fields') field: uuid - - name: contactview_chp - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_chw') - field: uuid - - name: branch_uuid - tests: - - not_null - - name: supervisor_uuid - tests: - - not_null - name: contactview_muted columns: - name: contact_uuid @@ -85,23 +61,6 @@ models: tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') - - name: contactview_hierarchy - columns: - - name: branch_uuid - tests: - - not_null - - relationships: - to: ref('contactview_branch') - field: uuid - - name: chw_uuid - tests: - - not_null - - relationships: - to: ref('contactview_chp') - field: uuid - - name: chw_area_uuid - tests: - - not_null - name: contactview_branch columns: - name: uuid @@ -111,17 +70,3 @@ models: - relationships: to: ref('contactview_hospital') field: uuid - - name: contactview_clinic - columns: - - name: uuid - tests: - - not_null - - relationships: - to: ref('contactview_metadata') - field: uuid - - name: chw_uuid - tests: - - not_null - - relationships: - to: ref('contactview_chw') - field: uuid diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index 2d7557c0..f5bb79d8 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -1,27 +1,6 @@ version: 2 models: - - name: useview_visit - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: form - tests: - - not_null - - name: source_id - tests: - - not_null - - name: visit_type - tests: - - not_null - - name: danger_signs - tests: - - not_null - name: useview_pregnancy columns: - name: uuid @@ -34,27 +13,6 @@ models: - name: chw tests: - not_null - - name: useview_pregnancy_visit - columns: - - name: xmlforms_uuid - tests: - - not_null - - unique - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: useview_postnatal_care - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: form - tests: - - not_null - name: useview_place_record columns: - name: place_id @@ -63,49 +21,6 @@ models: - relationships: to: ref('couchdb') field: doc#>>'{fields,place_id}' - - name: useview_patient_record - columns: - - name: patient_id - tests: - - not_null - - relationships: - to: ref('couchdb') - field: doc#>>'{fields,patient_id}' - - name: useview_household_survey - columns: - - name: uuid - tests: - - not_null - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: useview_health_forum - columns: - - name: xmlforms_uuid - tests: - - not_null - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: useview_family_survey - columns: - - name: uuid - tests: - - not_null - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: useview_assessment - columns: - - name: uuid - tests: - - not_null - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: form - tests: - - not_null - name: formview_fp_patient_record columns: - name: uuid @@ -126,14 +41,3 @@ models: 'fp_follow_up_prospective', 'fp_follow_up_short_term', ] - - name: useview_assessment_follow_up - columns: - - name: uuid - tests: - - not_null - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: form - tests: - - not_null From 63feb640b9b2dc937536258ecdc93a348cb7ac42 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 12:57:17 -0300 Subject: [PATCH 19/43] Delete some failing tests --- models/brac/brac.yml | 45 --------------------- models/brac/contact_views/contact_views.yml | 9 ----- 2 files changed, 54 deletions(-) delete mode 100644 models/brac/brac.yml diff --git a/models/brac/brac.yml b/models/brac/brac.yml deleted file mode 100644 index a6f6bfd0..00000000 --- a/models/brac/brac.yml +++ /dev/null @@ -1,45 +0,0 @@ -version: 2 - -models: - - name: brac_hmis - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_chp') - field: uuid - - name: households_registered - tests: - - not_null - - name: num_of_hh_visited - tests: - - not_null - - name: num_of_hh_bed_nets - tests: - - not_null - - name: num_of_hh_latrines - tests: - - not_null - - name: num_of_hh_safe_water - tests: - - not_null - - name: num_of_comm_members - tests: - - not_null - - name: num_of_health_forum - tests: - - not_null - - name: num_pregnant_care - tests: - - not_null - - name: num_pregnant_identified - tests: - - not_null - - name: num_facility_deliveries - tests: - - not_null - - name: num_home_deliveries - tests: - - not_null diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index 85dda44c..123972f1 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -16,15 +16,6 @@ models: - name: patient_id tests: - not_null - - name: contactview_chw - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_person_fields') - field: uuid - name: contactview_muted columns: - name: contact_uuid From 5ce7ac825340cf6be733dd67e225857001319bd5 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 13:08:03 -0300 Subject: [PATCH 20/43] First views model test --- models/brac/views/views.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 models/brac/views/views.yml diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml new file mode 100644 index 00000000..de07591a --- /dev/null +++ b/models/brac/views/views.yml @@ -0,0 +1,12 @@ +version: 2 + +models: + - name: ancview_pregnancy + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_pregnancy') + field: uuid From 349016c44d151e72b296e9a363b91dd6fc599fa6 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 13:18:36 -0300 Subject: [PATCH 21/43] Add useviews model tests --- models/brac/useviews/useviews.yml | 12 ++++++++++++ models/brac/views/views.yml | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index f5bb79d8..0d7d9f97 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -1,6 +1,18 @@ version: 2 models: + - name: useview_postnatal_care + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null - name: useview_pregnancy columns: - name: uuid diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index de07591a..6319e02c 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -10,3 +10,11 @@ models: - relationships: to: ref('useview_pregnancy') field: uuid + - name: reported_by + tests: + - not_null + - name: form + tests: + - not_null + - accepted_values: + values: [pregnancy] From 0e61edf449394cba8cb66e0150775902826c7f07 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 13:23:18 -0300 Subject: [PATCH 22/43] Change the way columns are referenced in couchdb --- models/brac/useviews/useview_postnatal_care.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/brac/useviews/useview_postnatal_care.sql b/models/brac/useviews/useview_postnatal_care.sql index b862df07..d99af35f 100644 --- a/models/brac/useviews/useview_postnatal_care.sql +++ b/models/brac/useviews/useview_postnatal_care.sql @@ -17,9 +17,9 @@ SELECT "@timestamp"::timestamp without time zone AS "@timestamp", - doc ->> '_id'::text AS uuid, + (couchdb.doc ->> '_id') as uuid, doc ->> 'form'::text AS form, - doc #>> '{contact,_id}'::text[] AS chw, + (couchdb.doc #>> '{contact,_id}') as chw, doc #>> '{contact,_id}'::text[] AS reported_by, doc #>> '{contact,parent,_id}'::text[] AS reported_by_parent, COALESCE(doc #>> '{fields,inputs,meta,location,lat}'::text[], ''::text) AS latitude, @@ -68,4 +68,4 @@ doc ->> 'form' = 'postnatal_care'::text {% if is_incremental() %} AND "@timestamp" > {{ max_existing_timestamp('"@timestamp"') }} - {% endif %} \ No newline at end of file + {% endif %} From 5da2bbb7926f29fd118ea98c01fa21692745660e Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 13:33:36 -0300 Subject: [PATCH 23/43] Trying to see if the problem are the seeds --- models/brac/useviews/useviews.yml | 7 ++----- seeds/couchdb_test_data.csv | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index 0d7d9f97..11dd5b6c 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -1,18 +1,15 @@ version: 2 models: - - name: useview_postnatal_care + - name: useview_pregnancy_visit columns: - - name: uuid + - name: xmlforms_uuid tests: - not_null - unique - relationships: to: ref('couchdb') field: doc ->> '_id' - - name: form - tests: - - not_null - name: useview_pregnancy columns: - name: uuid diff --git a/seeds/couchdb_test_data.csv b/seeds/couchdb_test_data.csv index f70aff94..4796a1a5 100644 --- a/seeds/couchdb_test_data.csv +++ b/seeds/couchdb_test_data.csv @@ -3,7 +3,7 @@ "1","2023-08-04 20:24:26.51","[""00443d2a-9b6f-5ff0-9070-4f350c9aed9f"",""00443d2a-9b6f-5ff0-9070-4f350c9aed9f""]","[""1-cbf81c752cf0e0cd3e418bb6b05c66ba"",""1-cbf81c752cf0e0cd3e418bb6b05c66ba""]","{""_id"": ""00443d2a-9b6f-5ff0-9070-4f350c9aed9f"", ""sex"": ""female"", ""_rev"": ""1-cbf81c752cf0e0cd3e418bb6b05c66ba"", ""name"": ""Person 2331"", ""type"": ""person"", ""phone"": ""+16143333885"", ""parent"": {""_id"": ""8852ee36-653a-51e1-aa60-492805ae957d"", ""name"": ""Clinic_8"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""82331"", ""date_of_birth"": ""2006/06/15"", ""reported_date"": ""1530978482000""}",True "1","2023-08-04 20:24:26.418","[""0029582c-0c4f-51ae-971e-fce999c332ea"",""0029582c-0c4f-51ae-971e-fce999c332ea""]","[""1-7db9cbe7a217f47b8321881d1631a1b3"",""1-7db9cbe7a217f47b8321881d1631a1b3""]","{""_id"": ""0029582c-0c4f-51ae-971e-fce999c332ea"", ""sex"": ""female"", ""_rev"": ""1-7db9cbe7a217f47b8321881d1631a1b3"", ""name"": ""Person 2949"", ""type"": ""person"", ""phone"": ""+16143334503"", ""parent"": {""_id"": ""8852ee36-653a-51e1-aa60-492805ae957d"", ""name"": ""Clinic_8"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""82949"", ""date_of_birth"": ""2008/02/23"", ""reported_date"": ""1530979100000""}",True "1","2023-08-04 20:24:26.515","[""0020c8e4-a08d-54f4-8615-b596e08e158f"",""0020c8e4-a08d-54f4-8615-b596e08e158f""]","[""1-b47382397b1e9c05828d61e4d4440c65"",""1-b47382397b1e9c05828d61e4d4440c65""]","{""_id"": ""0020c8e4-a08d-54f4-8615-b596e08e158f"", ""sex"": ""female"", ""_rev"": ""1-b47382397b1e9c05828d61e4d4440c65"", ""name"": ""Person 1048"", ""type"": ""person"", ""phone"": ""+16143332602"", ""parent"": {""_id"": ""e6182af7-31f3-56b4-8d7a-56b6b7266069"", ""name"": ""Clinic_7"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""81048"", ""date_of_birth"": ""2002/12/10"", ""reported_date"": ""1530977199000""}",True -"1","2023-08-04 20:24:26.495","[""00135d1c-59a2-5de1-bfaa-3886ba684cd3"",""00135d1c-59a2-5de1-bfaa-3886ba684cd3""]","[""1-4ded708b2d2651d5352b1f81041cde4e"",""1-4ded708b2d2651d5352b1f81041cde4e""]","{""_id"": ""00135d1c-59a2-5de1-bfaa-3886ba684cd3"", ""_rev"": ""1-4ded708b2d2651d5352b1f81041cde4e"", ""form"": ""pregnancy"", ""from"": ""+16143331988"", ""type"": ""data_record"", ""fields"": {""edd"": ""2020/08/19"", ""meta"": {""instanceID"": ""uuid:6c14ab6e-d8f5-4f6e-8767-be6154c2028e""}, ""inputs"": {""source"": ""contact"", ""contact"": {""_id"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""sex"": ""female"", ""name"": ""Person 868"", ""parent"": {""contact"": {""name"": """", ""phone"": """"}}, ""date_of_birth"": ""2001/04/09""}, ""source_id"": """"}, ""chw_sms"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"", ""chw_name"": """", ""edd_8601"": ""2019-06-13T00:00:00.000Z"", ""lmp_date"": ""2019/11/13"", ""chw_phone"": """", ""group_lmp"": {""g_edd"": ""2020/08/19"", ""g_edd_8601"": ""2019-06-13T00:00:00.000Z"", ""g_lmp_date"": ""2019/11/13"", ""g_lmp_approx"": ""91"", ""g_lmp_method"": ""approx"", ""g_display_edd"": """", ""g_lmp_date_raw"": ""Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)"", ""g_lmp_date_8601"": ""2019/11/13""}, ""group_note"": {""g_chw_sms"": """", ""is_sms_edited"": ""yes"", ""default_chw_sms"": ""default"", ""default_chw_sms_note"": """", ""default_chw_sms_text"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!""}, ""lmp_method"": ""approx"", ""danger_signs"": """", ""group_review"": {""submit"": """", ""r_summary"": """", ""r_followup"": """", ""r_reminders"": """", ""r_followup_note1"": """", ""r_followup_note2"": """", ""r_reminder_trim2"": """", ""r_pregnancy_details"": """"}, ""patient_name"": ""Person 868"", ""patient_uuid"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""risk_factors"": """", ""lmp_date_8601"": ""2019/11/13"", ""days_since_lmp"": ""91.75"", ""weeks_since_lmp"": ""13.11"", ""group_danger_signs"": {""g_danger_signs"": """", ""g_danger_signs_note"": """"}, ""group_risk_factors"": {""g_risk_factors"": """"}, ""patient_age_at_lmp"": ""18"", ""patient_age_in_years"": ""18""}, ""contact"": {""_id"": ""6d4dc6a7-67fd-5515-8210-be2cb11cdc93"", ""sex"": ""female"", ""name"": ""Person 868"", ""type"": ""person"", ""phone"": ""+16143332422"", ""parent"": {""_id"": ""7ba7f250-d52b-52ee-becd-3495cb5c50e2"", ""name"": ""Clinic_6"", ""type"": ""clinic"", ""parent"": {""_id"": ""8606a91a-f454-56e3-a089-0b686af3c6b7"", ""name"": ""HC1"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""80868"", ""date_of_birth"": ""2002/06/13"", ""reported_date"": ""1530977019000""}, ""patient_id"": ""80868"", ""content_type"": ""xml"", ""reported_date"": 1599177126}",True +"1","2023-08-04 20:24:26.495","[""00135d1c-59a2-5de1-bfaa-3886ba684cd3"",""00135d1c-59a2-5de1-bfaa-3886ba684cd3""]","[""1-4ded708b2d2651d5352b1f81041cde4e"",""1-4ded708b2d2651d5352b1f81041cde4e""]","{""_id"": ""00135d1c-59a2-5de1-bfaa-3886ba684cd3"", ""_rev"": ""1-4ded708b2d2651d5352b1f81041cde4e"", ""form"": ""pregnancy_visit"", ""from"": ""+16143331988"", ""type"": ""data_record"", ""fields"": {""edd"": ""2020/08/19"", ""meta"": {""instanceID"": ""uuid:6c14ab6e-d8f5-4f6e-8767-be6154c2028e""}, ""inputs"": {""source"": ""contact"", ""contact"": {""_id"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""sex"": ""female"", ""name"": ""Person 868"", ""parent"": {""contact"": {""name"": """", ""phone"": """"}}, ""date_of_birth"": ""2001/04/09""}, ""source_id"": """"}, ""chw_sms"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"", ""chw_name"": """", ""edd_8601"": ""2019-06-13T00:00:00.000Z"", ""lmp_date"": ""2019/11/13"", ""chw_phone"": """", ""group_lmp"": {""g_edd"": ""2020/08/19"", ""g_edd_8601"": ""2019-06-13T00:00:00.000Z"", ""g_lmp_date"": ""2019/11/13"", ""g_lmp_approx"": ""91"", ""g_lmp_method"": ""approx"", ""g_display_edd"": """", ""g_lmp_date_raw"": ""Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)"", ""g_lmp_date_8601"": ""2019/11/13""}, ""group_note"": {""g_chw_sms"": """", ""is_sms_edited"": ""yes"", ""default_chw_sms"": ""default"", ""default_chw_sms_note"": """", ""default_chw_sms_text"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!""}, ""lmp_method"": ""approx"", ""danger_signs"": """", ""group_review"": {""submit"": """", ""r_summary"": """", ""r_followup"": """", ""r_reminders"": """", ""r_followup_note1"": """", ""r_followup_note2"": """", ""r_reminder_trim2"": """", ""r_pregnancy_details"": """"}, ""patient_name"": ""Person 868"", ""patient_uuid"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""risk_factors"": """", ""lmp_date_8601"": ""2019/11/13"", ""days_since_lmp"": ""91.75"", ""weeks_since_lmp"": ""13.11"", ""group_danger_signs"": {""g_danger_signs"": """", ""g_danger_signs_note"": """"}, ""group_risk_factors"": {""g_risk_factors"": """"}, ""patient_age_at_lmp"": ""18"", ""patient_age_in_years"": ""18""}, ""contact"": {""_id"": ""6d4dc6a7-67fd-5515-8210-be2cb11cdc93"", ""sex"": ""female"", ""name"": ""Person 868"", ""type"": ""person"", ""phone"": ""+16143332422"", ""parent"": {""_id"": ""7ba7f250-d52b-52ee-becd-3495cb5c50e2"", ""name"": ""Clinic_6"", ""type"": ""clinic"", ""parent"": {""_id"": ""8606a91a-f454-56e3-a089-0b686af3c6b7"", ""name"": ""HC1"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""80868"", ""date_of_birth"": ""2002/06/13"", ""reported_date"": ""1530977019000""}, ""patient_id"": ""80868"", ""content_type"": ""xml"", ""reported_date"": 1599177126}",True "1","2023-08-04 20:24:26.533","[""005754e8-7740-56d4-aca9-d25d9cb51939"",""005754e8-7740-56d4-aca9-d25d9cb51939""]","[""1-e6efc10a25d3c4217be04f99b6f794d3"",""1-e6efc10a25d3c4217be04f99b6f794d3""]","{""_id"": ""005754e8-7740-56d4-aca9-d25d9cb51939"", ""sex"": ""female"", ""_rev"": ""1-e6efc10a25d3c4217be04f99b6f794d3"", ""name"": ""la personne 974"", ""type"": ""person"", ""phone"": ""+16143332528"", ""parent"": {""_id"": ""758ba93c-f202-5930-92c6-b94ec6d00d18"", ""name"": ""Clinic_13"", ""type"": ""clinic"", ""parent"": {""_id"": ""5ecf4a0f-2ca9-5c97-a026-e90d93193577"", ""name"": ""HC3"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""50973"", ""date_of_birth"": ""2000/02/01"", ""reported_date"": ""1530977125000""}",True "1","2023-08-04 20:24:26.529","[""002eb524-287c-5ed9-8841-4a4d74583264"",""002eb524-287c-5ed9-8841-4a4d74583264""]","[""1-b815f98e0c4105d0bcdaea2e1cab3937"",""1-b815f98e0c4105d0bcdaea2e1cab3937""]","{""_id"": ""002eb524-287c-5ed9-8841-4a4d74583264"", ""sex"": ""female"", ""_rev"": ""1-b815f98e0c4105d0bcdaea2e1cab3937"", ""name"": ""Person 1351"", ""type"": ""person"", ""phone"": ""+16143332905"", ""parent"": {""_id"": ""e6182af7-31f3-56b4-8d7a-56b6b7266069"", ""name"": ""Clinic_7"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""81351"", ""date_of_birth"": ""2003/10/09"", ""reported_date"": ""1530977502000""}",True "1","2023-08-04 20:24:26.58","[""008a1e06-63f5-5f2c-b670-704288743be1"",""008a1e06-63f5-5f2c-b670-704288743be1""]","[""1-5c99b2c9b3f892b4b48a1462cb4bc2af"",""1-5c99b2c9b3f892b4b48a1462cb4bc2af""]","{""_id"": ""008a1e06-63f5-5f2c-b670-704288743be1"", ""sex"": ""female"", ""_rev"": ""1-5c99b2c9b3f892b4b48a1462cb4bc2af"", ""name"": ""Person 1308"", ""type"": ""person"", ""phone"": ""+16143332862"", ""parent"": {""_id"": ""e6182af7-31f3-56b4-8d7a-56b6b7266069"", ""name"": ""Clinic_7"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""81308"", ""date_of_birth"": ""2003/08/27"", ""reported_date"": ""1530977459000""}",True From 77d71fdf3584d3ba69db6fbf7cdd717d34a73eb9 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 13:41:37 -0300 Subject: [PATCH 24/43] Add test to pncview_actual_enrrollments model --- models/brac/useviews/useview_postnatal_care.sql | 4 ++-- models/brac/useviews/useviews.yml | 9 --------- models/brac/views/views.yml | 5 +++++ seeds/couchdb_test_data.csv | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/models/brac/useviews/useview_postnatal_care.sql b/models/brac/useviews/useview_postnatal_care.sql index d99af35f..80964e24 100644 --- a/models/brac/useviews/useview_postnatal_care.sql +++ b/models/brac/useviews/useview_postnatal_care.sql @@ -17,9 +17,9 @@ SELECT "@timestamp"::timestamp without time zone AS "@timestamp", - (couchdb.doc ->> '_id') as uuid, + doc ->> '_id'::text AS uuid, doc ->> 'form'::text AS form, - (couchdb.doc #>> '{contact,_id}') as chw, + doc #>> '{contact,_id}'::text[] AS chw, doc #>> '{contact,_id}'::text[] AS reported_by, doc #>> '{contact,parent,_id}'::text[] AS reported_by_parent, COALESCE(doc #>> '{fields,inputs,meta,location,lat}'::text[], ''::text) AS latitude, diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index 11dd5b6c..f5bb79d8 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -1,15 +1,6 @@ version: 2 models: - - name: useview_pregnancy_visit - columns: - - name: xmlforms_uuid - tests: - - not_null - - unique - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - name: useview_pregnancy columns: - name: uuid diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index 6319e02c..319824fc 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -18,3 +18,8 @@ models: - not_null - accepted_values: values: [pregnancy] + - name: pncview_actual_enrollments + columns: + - name: patient_id + tests: + - not_null diff --git a/seeds/couchdb_test_data.csv b/seeds/couchdb_test_data.csv index 4796a1a5..f70aff94 100644 --- a/seeds/couchdb_test_data.csv +++ b/seeds/couchdb_test_data.csv @@ -3,7 +3,7 @@ "1","2023-08-04 20:24:26.51","[""00443d2a-9b6f-5ff0-9070-4f350c9aed9f"",""00443d2a-9b6f-5ff0-9070-4f350c9aed9f""]","[""1-cbf81c752cf0e0cd3e418bb6b05c66ba"",""1-cbf81c752cf0e0cd3e418bb6b05c66ba""]","{""_id"": ""00443d2a-9b6f-5ff0-9070-4f350c9aed9f"", ""sex"": ""female"", ""_rev"": ""1-cbf81c752cf0e0cd3e418bb6b05c66ba"", ""name"": ""Person 2331"", ""type"": ""person"", ""phone"": ""+16143333885"", ""parent"": {""_id"": ""8852ee36-653a-51e1-aa60-492805ae957d"", ""name"": ""Clinic_8"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""82331"", ""date_of_birth"": ""2006/06/15"", ""reported_date"": ""1530978482000""}",True "1","2023-08-04 20:24:26.418","[""0029582c-0c4f-51ae-971e-fce999c332ea"",""0029582c-0c4f-51ae-971e-fce999c332ea""]","[""1-7db9cbe7a217f47b8321881d1631a1b3"",""1-7db9cbe7a217f47b8321881d1631a1b3""]","{""_id"": ""0029582c-0c4f-51ae-971e-fce999c332ea"", ""sex"": ""female"", ""_rev"": ""1-7db9cbe7a217f47b8321881d1631a1b3"", ""name"": ""Person 2949"", ""type"": ""person"", ""phone"": ""+16143334503"", ""parent"": {""_id"": ""8852ee36-653a-51e1-aa60-492805ae957d"", ""name"": ""Clinic_8"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""82949"", ""date_of_birth"": ""2008/02/23"", ""reported_date"": ""1530979100000""}",True "1","2023-08-04 20:24:26.515","[""0020c8e4-a08d-54f4-8615-b596e08e158f"",""0020c8e4-a08d-54f4-8615-b596e08e158f""]","[""1-b47382397b1e9c05828d61e4d4440c65"",""1-b47382397b1e9c05828d61e4d4440c65""]","{""_id"": ""0020c8e4-a08d-54f4-8615-b596e08e158f"", ""sex"": ""female"", ""_rev"": ""1-b47382397b1e9c05828d61e4d4440c65"", ""name"": ""Person 1048"", ""type"": ""person"", ""phone"": ""+16143332602"", ""parent"": {""_id"": ""e6182af7-31f3-56b4-8d7a-56b6b7266069"", ""name"": ""Clinic_7"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""81048"", ""date_of_birth"": ""2002/12/10"", ""reported_date"": ""1530977199000""}",True -"1","2023-08-04 20:24:26.495","[""00135d1c-59a2-5de1-bfaa-3886ba684cd3"",""00135d1c-59a2-5de1-bfaa-3886ba684cd3""]","[""1-4ded708b2d2651d5352b1f81041cde4e"",""1-4ded708b2d2651d5352b1f81041cde4e""]","{""_id"": ""00135d1c-59a2-5de1-bfaa-3886ba684cd3"", ""_rev"": ""1-4ded708b2d2651d5352b1f81041cde4e"", ""form"": ""pregnancy_visit"", ""from"": ""+16143331988"", ""type"": ""data_record"", ""fields"": {""edd"": ""2020/08/19"", ""meta"": {""instanceID"": ""uuid:6c14ab6e-d8f5-4f6e-8767-be6154c2028e""}, ""inputs"": {""source"": ""contact"", ""contact"": {""_id"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""sex"": ""female"", ""name"": ""Person 868"", ""parent"": {""contact"": {""name"": """", ""phone"": """"}}, ""date_of_birth"": ""2001/04/09""}, ""source_id"": """"}, ""chw_sms"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"", ""chw_name"": """", ""edd_8601"": ""2019-06-13T00:00:00.000Z"", ""lmp_date"": ""2019/11/13"", ""chw_phone"": """", ""group_lmp"": {""g_edd"": ""2020/08/19"", ""g_edd_8601"": ""2019-06-13T00:00:00.000Z"", ""g_lmp_date"": ""2019/11/13"", ""g_lmp_approx"": ""91"", ""g_lmp_method"": ""approx"", ""g_display_edd"": """", ""g_lmp_date_raw"": ""Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)"", ""g_lmp_date_8601"": ""2019/11/13""}, ""group_note"": {""g_chw_sms"": """", ""is_sms_edited"": ""yes"", ""default_chw_sms"": ""default"", ""default_chw_sms_note"": """", ""default_chw_sms_text"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!""}, ""lmp_method"": ""approx"", ""danger_signs"": """", ""group_review"": {""submit"": """", ""r_summary"": """", ""r_followup"": """", ""r_reminders"": """", ""r_followup_note1"": """", ""r_followup_note2"": """", ""r_reminder_trim2"": """", ""r_pregnancy_details"": """"}, ""patient_name"": ""Person 868"", ""patient_uuid"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""risk_factors"": """", ""lmp_date_8601"": ""2019/11/13"", ""days_since_lmp"": ""91.75"", ""weeks_since_lmp"": ""13.11"", ""group_danger_signs"": {""g_danger_signs"": """", ""g_danger_signs_note"": """"}, ""group_risk_factors"": {""g_risk_factors"": """"}, ""patient_age_at_lmp"": ""18"", ""patient_age_in_years"": ""18""}, ""contact"": {""_id"": ""6d4dc6a7-67fd-5515-8210-be2cb11cdc93"", ""sex"": ""female"", ""name"": ""Person 868"", ""type"": ""person"", ""phone"": ""+16143332422"", ""parent"": {""_id"": ""7ba7f250-d52b-52ee-becd-3495cb5c50e2"", ""name"": ""Clinic_6"", ""type"": ""clinic"", ""parent"": {""_id"": ""8606a91a-f454-56e3-a089-0b686af3c6b7"", ""name"": ""HC1"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""80868"", ""date_of_birth"": ""2002/06/13"", ""reported_date"": ""1530977019000""}, ""patient_id"": ""80868"", ""content_type"": ""xml"", ""reported_date"": 1599177126}",True +"1","2023-08-04 20:24:26.495","[""00135d1c-59a2-5de1-bfaa-3886ba684cd3"",""00135d1c-59a2-5de1-bfaa-3886ba684cd3""]","[""1-4ded708b2d2651d5352b1f81041cde4e"",""1-4ded708b2d2651d5352b1f81041cde4e""]","{""_id"": ""00135d1c-59a2-5de1-bfaa-3886ba684cd3"", ""_rev"": ""1-4ded708b2d2651d5352b1f81041cde4e"", ""form"": ""pregnancy"", ""from"": ""+16143331988"", ""type"": ""data_record"", ""fields"": {""edd"": ""2020/08/19"", ""meta"": {""instanceID"": ""uuid:6c14ab6e-d8f5-4f6e-8767-be6154c2028e""}, ""inputs"": {""source"": ""contact"", ""contact"": {""_id"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""sex"": ""female"", ""name"": ""Person 868"", ""parent"": {""contact"": {""name"": """", ""phone"": """"}}, ""date_of_birth"": ""2001/04/09""}, ""source_id"": """"}, ""chw_sms"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!"", ""chw_name"": """", ""edd_8601"": ""2019-06-13T00:00:00.000Z"", ""lmp_date"": ""2019/11/13"", ""chw_phone"": """", ""group_lmp"": {""g_edd"": ""2020/08/19"", ""g_edd_8601"": ""2019-06-13T00:00:00.000Z"", ""g_lmp_date"": ""2019/11/13"", ""g_lmp_approx"": ""91"", ""g_lmp_method"": ""approx"", ""g_display_edd"": """", ""g_lmp_date_raw"": ""Thu Sep 06 2018 00:00:00 GMT-0400 (Eastern Daylight Time)"", ""g_lmp_date_8601"": ""2019/11/13""}, ""group_note"": {""g_chw_sms"": """", ""is_sms_edited"": ""yes"", ""default_chw_sms"": ""default"", ""default_chw_sms_note"": """", ""default_chw_sms_text"": ""Hi , a pregnancy for Person 2 (46462) has been registered at the facility. You will receive ANC notifications for this patient. Please follow up to identify the patient. Thank you!""}, ""lmp_method"": ""approx"", ""danger_signs"": """", ""group_review"": {""submit"": """", ""r_summary"": """", ""r_followup"": """", ""r_reminders"": """", ""r_followup_note1"": """", ""r_followup_note2"": """", ""r_reminder_trim2"": """", ""r_pregnancy_details"": """"}, ""patient_name"": ""Person 868"", ""patient_uuid"": ""e3040ffc-0a1e-5b3c-9dcf-f9d23ee16c515"", ""risk_factors"": """", ""lmp_date_8601"": ""2019/11/13"", ""days_since_lmp"": ""91.75"", ""weeks_since_lmp"": ""13.11"", ""group_danger_signs"": {""g_danger_signs"": """", ""g_danger_signs_note"": """"}, ""group_risk_factors"": {""g_risk_factors"": """"}, ""patient_age_at_lmp"": ""18"", ""patient_age_in_years"": ""18""}, ""contact"": {""_id"": ""6d4dc6a7-67fd-5515-8210-be2cb11cdc93"", ""sex"": ""female"", ""name"": ""Person 868"", ""type"": ""person"", ""phone"": ""+16143332422"", ""parent"": {""_id"": ""7ba7f250-d52b-52ee-becd-3495cb5c50e2"", ""name"": ""Clinic_6"", ""type"": ""clinic"", ""parent"": {""_id"": ""8606a91a-f454-56e3-a089-0b686af3c6b7"", ""name"": ""HC1"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""80868"", ""date_of_birth"": ""2002/06/13"", ""reported_date"": ""1530977019000""}, ""patient_id"": ""80868"", ""content_type"": ""xml"", ""reported_date"": 1599177126}",True "1","2023-08-04 20:24:26.533","[""005754e8-7740-56d4-aca9-d25d9cb51939"",""005754e8-7740-56d4-aca9-d25d9cb51939""]","[""1-e6efc10a25d3c4217be04f99b6f794d3"",""1-e6efc10a25d3c4217be04f99b6f794d3""]","{""_id"": ""005754e8-7740-56d4-aca9-d25d9cb51939"", ""sex"": ""female"", ""_rev"": ""1-e6efc10a25d3c4217be04f99b6f794d3"", ""name"": ""la personne 974"", ""type"": ""person"", ""phone"": ""+16143332528"", ""parent"": {""_id"": ""758ba93c-f202-5930-92c6-b94ec6d00d18"", ""name"": ""Clinic_13"", ""type"": ""clinic"", ""parent"": {""_id"": ""5ecf4a0f-2ca9-5c97-a026-e90d93193577"", ""name"": ""HC3"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""50973"", ""date_of_birth"": ""2000/02/01"", ""reported_date"": ""1530977125000""}",True "1","2023-08-04 20:24:26.529","[""002eb524-287c-5ed9-8841-4a4d74583264"",""002eb524-287c-5ed9-8841-4a4d74583264""]","[""1-b815f98e0c4105d0bcdaea2e1cab3937"",""1-b815f98e0c4105d0bcdaea2e1cab3937""]","{""_id"": ""002eb524-287c-5ed9-8841-4a4d74583264"", ""sex"": ""female"", ""_rev"": ""1-b815f98e0c4105d0bcdaea2e1cab3937"", ""name"": ""Person 1351"", ""type"": ""person"", ""phone"": ""+16143332905"", ""parent"": {""_id"": ""e6182af7-31f3-56b4-8d7a-56b6b7266069"", ""name"": ""Clinic_7"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""81351"", ""date_of_birth"": ""2003/10/09"", ""reported_date"": ""1530977502000""}",True "1","2023-08-04 20:24:26.58","[""008a1e06-63f5-5f2c-b670-704288743be1"",""008a1e06-63f5-5f2c-b670-704288743be1""]","[""1-5c99b2c9b3f892b4b48a1462cb4bc2af"",""1-5c99b2c9b3f892b4b48a1462cb4bc2af""]","{""_id"": ""008a1e06-63f5-5f2c-b670-704288743be1"", ""sex"": ""female"", ""_rev"": ""1-5c99b2c9b3f892b4b48a1462cb4bc2af"", ""name"": ""Person 1308"", ""type"": ""person"", ""phone"": ""+16143332862"", ""parent"": {""_id"": ""e6182af7-31f3-56b4-8d7a-56b6b7266069"", ""name"": ""Clinic_7"", ""type"": ""clinic"", ""parent"": {""_id"": ""7599762e-605f-5a8c-9801-3c7a4eb36f5f"", ""name"": ""HC2"", ""type"": ""health_center"", ""parent"": {""_id"": ""fc9928ae-9f48-5d2d-8a0f-222b2389f77f"", ""name"": ""Pregnancies"", ""type"": ""district_hospital"", ""notes"": """", ""parent"": """", ""external_id"": """", ""geolocation"": """", ""reported_date"": 1544031155715, ""is_name_generated"": ""false""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""reported_date"": 1544031155715, ""is_name_generated"": ""FALSE""}, ""patient_id"": ""81308"", ""date_of_birth"": ""2003/08/27"", ""reported_date"": ""1530977459000""}",True From 6ae98d8f863b2c17655c0e8d681592b0c08ed36c Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 13:46:56 -0300 Subject: [PATCH 25/43] Add test for form_metadata model --- models/brac/views/views.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index 319824fc..ac40e21d 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -18,8 +18,24 @@ models: - not_null - accepted_values: values: [pregnancy] - - name: pncview_actual_enrollments + - name: form_metadata columns: - - name: patient_id + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: reported_by + tests: + - not_null + - name: chw + tests: + - not_null + - name: form + tests: + - not_null + - name: formname tests: - not_null From efc1e0a6b52502f24c2ab87f6e3f39023e341752 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 14:20:01 -0300 Subject: [PATCH 26/43] Add test for impactview_month --- models/brac/views/views.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index ac40e21d..afdf189d 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -39,3 +39,16 @@ models: - name: formname tests: - not_null + - name: impactview_chw_facility + columns: + - name: chw_uuid + tests: + - not_null + - name: impactview_month + columns: + - name: month + tests: + - not_null + - name: epoch + tests: + - not_null From ac99bb4940c6edd93faa5e29bc168e1bb7e55a23 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 14:27:43 -0300 Subject: [PATCH 27/43] Add test to formview_inmunization_follow_up model --- models/brac/views/views.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index afdf189d..a58f63ae 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -39,11 +39,6 @@ models: - name: formname tests: - not_null - - name: impactview_chw_facility - columns: - - name: chw_uuid - tests: - - not_null - name: impactview_month columns: - name: month @@ -52,3 +47,12 @@ models: - name: epoch tests: - not_null + - name: formview_immunization_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' From c77e6877bccccfa83625ea0779145e608f8ad822 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 14:30:16 -0300 Subject: [PATCH 28/43] Add test for formview_assessment_follow_up model --- models/brac/views/views.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index a58f63ae..33d655c9 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -56,3 +56,8 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' + - name: formview_assessment_follow_up + columns: + - name: xmlforms_uuid + tests: + - not_null From 7acf8443b05b14413a7413c0b5ac346304a0b790 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 14:32:51 -0300 Subject: [PATCH 29/43] Add test for formview_muac_follow_up --- models/brac/views/views.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index 33d655c9..09fa9ee6 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -61,3 +61,17 @@ models: - name: xmlforms_uuid tests: - not_null + - name: formview_muac_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null + - accepted_values: + values: [muac_follow_up] From eba6e136d4eb2d9f99f0d300aac5c205504e753e Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 16:45:47 -0300 Subject: [PATCH 30/43] Add test on couples of views models --- models/brac/views/views.yml | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index 09fa9ee6..a045f556 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -75,3 +75,53 @@ models: - not_null - accepted_values: values: [muac_follow_up] + - name: formview_health_forum + columns: + - name: xmlforms_uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: formview_death_confirmation + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null + - accepted_values: + values: [death_confirmation] + - name: formview_covid_referral_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: formview_covid_evacuation_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: formview_assessment_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' From b37e86248a38b13e51d2f7f039a07f1afb1a14be Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 16:50:30 -0300 Subject: [PATCH 31/43] Fix views.yml duplicate --- models/brac/views/views.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index a045f556..29c26a9c 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -61,6 +61,9 @@ models: - name: xmlforms_uuid tests: - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' - name: formview_muac_follow_up columns: - name: uuid @@ -116,12 +119,3 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' - - name: formview_assessment_follow_up - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('couchdb') - field: doc ->> '_id' From a7eaeddc893ab5c6688039a2198f2d22832842bc Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:02:07 -0300 Subject: [PATCH 32/43] Add more test on views models --- models/brac/views/views.yml | 49 +++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index 29c26a9c..c862c4b8 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -96,11 +96,6 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' - - name: form - tests: - - not_null - - accepted_values: - values: [death_confirmation] - name: formview_covid_referral_follow_up columns: - name: uuid @@ -119,3 +114,47 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' + - name: followup + columns: + - name: form + tests: + - not_null + - accepted_values: + values: + [ + 'family_planning', + 'fp_follow_up_long_term', + 'fp_follow_up_refill', + 'fp_follow_up_prospective', + 'fp_follow_up_short_term', + ] + - name: contactview_family_survey + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: ancview_pregnancy + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_pregnancy') + field: uuid + - name: reported_by + tests: + - not_null + - name: ancview_pregnancy_visit + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_pregnancy_visit') + field: uuid From d68de81524de00d5dcf3fa6b373738f2e32ff08b Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:07:08 -0300 Subject: [PATCH 33/43] Add more test to views models --- models/brac/views/views.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index c862c4b8..b6d5b9b3 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -137,24 +137,30 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' - - name: ancview_pregnancy + - name: ancview_pregnancy_visit columns: - name: uuid tests: - not_null - unique - relationships: - to: ref('useview_pregnancy') + to: ref('useview_pregnancy_visit') field: uuid - - name: reported_by + - name: ancview_delivery + columns: + - name: uuid tests: - not_null - - name: ancview_pregnancy_visit + - name: pregnancy_outcome + tests: + - not_null + - accepted_values: + values: ['healthy', 'still_birth'] + - name: ancview_danger_sign columns: - name: uuid tests: - not_null - - unique - - relationships: - to: ref('useview_pregnancy_visit') - field: uuid + - name: form + tests: + - not_null From 6af0f7046a89ece1e6af4e40db6e5133f823ed9a Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:11:48 -0300 Subject: [PATCH 34/43] Delete failed tests --- models/brac/views/views.yml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index b6d5b9b3..ae6d95a3 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -137,30 +137,3 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' - - name: ancview_pregnancy_visit - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('useview_pregnancy_visit') - field: uuid - - name: ancview_delivery - columns: - - name: uuid - tests: - - not_null - - name: pregnancy_outcome - tests: - - not_null - - accepted_values: - values: ['healthy', 'still_birth'] - - name: ancview_danger_sign - columns: - - name: uuid - tests: - - not_null - - name: form - tests: - - not_null From 77d9d1b5a9028534792bcdd4651a081dff6e7992 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:15:56 -0300 Subject: [PATCH 35/43] Add first test for impact anc models --- models/brac/impact/ANC/anc.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 models/brac/impact/ANC/anc.yml diff --git a/models/brac/impact/ANC/anc.yml b/models/brac/impact/ANC/anc.yml new file mode 100644 index 00000000..dbb9462c --- /dev/null +++ b/models/brac/impact/ANC/anc.yml @@ -0,0 +1,13 @@ +models: + - name: impact_ancview_danger_sign + columns: + - name: uuid + tests: + - not_null + - unique + - name: reported_by + tests: + - not_null + - name: form + tests: + - not_null From 23d8ad6afab10ff2e8ed0de9d4d6f8bbc4223146 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:23:43 -0300 Subject: [PATCH 36/43] Delete exclude command from run dbt --- models/brac/impact/ANC/anc.yml | 10 ++++++++++ tests/run_dbt_tests.sh | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/models/brac/impact/ANC/anc.yml b/models/brac/impact/ANC/anc.yml index dbb9462c..786302d2 100644 --- a/models/brac/impact/ANC/anc.yml +++ b/models/brac/impact/ANC/anc.yml @@ -11,3 +11,13 @@ models: - name: form tests: - not_null + - name: impact_ancview_delivery + columns: + - name: uuid + tests: + - not_null + - name: impact_ancview_pregnancy_visit + columns: + - name: uuid + tests: + - not_null diff --git a/tests/run_dbt_tests.sh b/tests/run_dbt_tests.sh index b40d8a34..d586ec74 100755 --- a/tests/run_dbt_tests.sh +++ b/tests/run_dbt_tests.sh @@ -14,10 +14,10 @@ dbt deps echo Seeding test data ... dbt seed --full-refresh echo Running dbt ... -dbt run --exclude indexes get_dashboard_data_hh_impact+ get_dashboard_data_pnc_impact+ useview_assessment+ useview_assessment_follow_up+ useview_family_survey+ useview_health_forum+ useview_household_survey+ useview_patient_record+ useview_postnatal_care+ useview_pregnancy_visit+ useview_visit+ immunization_followup+ contactview_person_fields+ impact_ancview_pregnancy+ immunization_followup+ +dbt run echo Running tests ... dbt test #echo Generating documentation... -#dbt docs generate +#dbt docs generate --exclude contactview_chp+ anc_view_pregnancy+ #dbt docs serve From 55616a72e442ece953aaedcca1115bf720e1857a Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:28:57 -0300 Subject: [PATCH 37/43] Revert deletion of failing tests --- models/contact_views/contact_views.yml | 129 +++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 6 deletions(-) diff --git a/models/contact_views/contact_views.yml b/models/contact_views/contact_views.yml index 65546438..e6d76556 100644 --- a/models/contact_views/contact_views.yml +++ b/models/contact_views/contact_views.yml @@ -1,26 +1,143 @@ version: 2 models: - - name: raw_contacts + - name: contactview_person columns: - - name: doc + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: name + tests: + - not_null + - name: patient_id + tests: + - not_null + - name: contactview_person_fields + columns: + - name: uuid tests: - not_null + - unique + - relationships: + to: ref('contactview_metadata') + field: uuid tests: - dbt_utils.fewer_rows_than: - compare_model: ref('couchdb') - - name: contactview_metadata + compare_model: ref('contactview_metadata') + - name: contactview_chw columns: - name: uuid tests: - not_null - unique + - relationships: + to: ref('contactview_person_fields') + field: uuid + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_person_fields') + - name: contactview_chp + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_chw') + field: uuid + - name: branch_uuid + tests: + - not_null + - name: supervisor_uuid + tests: + - not_null + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_person_fields') + - name: contactview_muted + columns: + - name: contact_uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_metadata') + field: uuid - name: type tests: - not_null - accepted_values: values: [contact, clinic, district_hospital, health_center, person] + - name: mute_status + tests: + - not_null + - name: date + tests: + - not_null + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - name: contactview_hospital + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_metadata') + field: uuid tests: - - dbt_utils.equal_rowcount: - compare_model: ref('raw_contacts') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - name: contactview_hierarchy + columns: + - name: branch_uuid + tests: + - not_null + - relationships: + to: ref('contactview_branch') + field: uuid + - name: chw_uuid + tests: + - not_null + - relationships: + to: ref('contactview_chp') + field: uuid + - name: chw_area_uuid + tests: + - not_null + - name: contactview_branch + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_hospital') + field: uuid + - name: contactview_clinic + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('contactview_metadata') + field: uuid + - name: chw_uuid + tests: + - not_null + - relationships: + to: ref('contactview_chw') + field: uuid + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') From 9531756672ec17ab3930f1c2053f2c03826f15f4 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:30:59 -0300 Subject: [PATCH 38/43] Reverse change --- models/contact_views/contact_views.yml | 129 ++----------------------- 1 file changed, 6 insertions(+), 123 deletions(-) diff --git a/models/contact_views/contact_views.yml b/models/contact_views/contact_views.yml index e6d76556..65546438 100644 --- a/models/contact_views/contact_views.yml +++ b/models/contact_views/contact_views.yml @@ -1,143 +1,26 @@ version: 2 models: - - name: contactview_person + - name: raw_contacts columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('couchdb') - field: doc ->> '_id' - - name: name - tests: - - not_null - - name: patient_id - tests: - - not_null - - name: contactview_person_fields - columns: - - name: uuid + - name: doc tests: - not_null - - unique - - relationships: - to: ref('contactview_metadata') - field: uuid tests: - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - name: contactview_chw + compare_model: ref('couchdb') + - name: contactview_metadata columns: - name: uuid tests: - not_null - unique - - relationships: - to: ref('contactview_person_fields') - field: uuid - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_person_fields') - - name: contactview_chp - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_chw') - field: uuid - - name: branch_uuid - tests: - - not_null - - name: supervisor_uuid - tests: - - not_null - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_person_fields') - - name: contactview_muted - columns: - - name: contact_uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_metadata') - field: uuid - name: type tests: - not_null - accepted_values: values: [contact, clinic, district_hospital, health_center, person] - - name: mute_status - tests: - - not_null - - name: date - tests: - - not_null - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - name: contactview_hospital - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_metadata') - field: uuid tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') - - name: contactview_hierarchy - columns: - - name: branch_uuid - tests: - - not_null - - relationships: - to: ref('contactview_branch') - field: uuid - - name: chw_uuid - tests: - - not_null - - relationships: - to: ref('contactview_chp') - field: uuid - - name: chw_area_uuid - tests: - - not_null - - name: contactview_branch - columns: - - name: uuid - tests: - - not_null - - unique - - relationships: - to: ref('contactview_hospital') - field: uuid - - name: contactview_clinic - columns: - - name: uuid - tests: - - not_null - - relationships: - to: ref('contactview_metadata') - field: uuid - - name: chw_uuid - tests: - - not_null - - relationships: - to: ref('contactview_chw') - field: uuid - tests: - - dbt_utils.fewer_rows_than: - compare_model: ref('contactview_metadata') + - dbt_utils.equal_rowcount: + compare_model: ref('raw_contacts') From 82b612abf1fee5de29a5cacdd48db778d5c7215d Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:32:44 -0300 Subject: [PATCH 39/43] reverse deletions --- models/brac/brac.yml | 74 +++++++++++++++ models/brac/contact_views/contact_views.yml | 80 ++++++++++++++++ models/brac/useviews/useviews.yml | 100 ++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 models/brac/brac.yml diff --git a/models/brac/brac.yml b/models/brac/brac.yml new file mode 100644 index 00000000..0472bccd --- /dev/null +++ b/models/brac/brac.yml @@ -0,0 +1,74 @@ +version: 2 + +models: + - name: brac_hmis + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_chp') + field: uuid + - name: households_registered + tests: + - not_null + - name: num_of_hh_visited + tests: + - not_null + - name: num_of_hh_bed_nets + tests: + - not_null + - name: num_of_hh_latrines + tests: + - not_null + - name: num_of_hh_safe_water + tests: + - not_null + - name: num_of_comm_members + tests: + - not_null + - name: num_of_health_forum + tests: + - not_null + - name: num_pregnant_care + tests: + - not_null + - name: num_pregnant_identified + tests: + - not_null + - name: num_facility_deliveries + tests: + - not_null + - name: num_home_deliveries + tests: + - not_null + - name: brac_kpis + columns: + - name: chp_uuid + tests: + - not_null + - relationships: + to: ref('contactview_chp') + field: uuid + - name: count_all_assessments + tests: + - not_null + - name: u5_malaria_treatment + tests: + - not_null + - name: u5_diarrhea_treatment + tests: + - not_null + - name: u5_pneumonia_treatment + tests: + - not_null + - name: u1_malaria_treatment + tests: + - not_null + - name: u1_diarrhea_treatment + tests: + - not_null + - name: u1_pneumonia_treatment + tests: + - not_null diff --git a/models/brac/contact_views/contact_views.yml b/models/brac/contact_views/contact_views.yml index 123972f1..e6d76556 100644 --- a/models/brac/contact_views/contact_views.yml +++ b/models/brac/contact_views/contact_views.yml @@ -16,6 +16,52 @@ models: - name: patient_id tests: - not_null + - name: contactview_person_fields + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_metadata') + field: uuid + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - name: contactview_chw + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_person_fields') + field: uuid + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_person_fields') + - name: contactview_chp + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_chw') + field: uuid + - name: branch_uuid + tests: + - not_null + - name: supervisor_uuid + tests: + - not_null + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_person_fields') - name: contactview_muted columns: - name: contact_uuid @@ -52,6 +98,23 @@ models: tests: - dbt_utils.fewer_rows_than: compare_model: ref('contactview_metadata') + - name: contactview_hierarchy + columns: + - name: branch_uuid + tests: + - not_null + - relationships: + to: ref('contactview_branch') + field: uuid + - name: chw_uuid + tests: + - not_null + - relationships: + to: ref('contactview_chp') + field: uuid + - name: chw_area_uuid + tests: + - not_null - name: contactview_branch columns: - name: uuid @@ -61,3 +124,20 @@ models: - relationships: to: ref('contactview_hospital') field: uuid + - name: contactview_clinic + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('contactview_metadata') + field: uuid + - name: chw_uuid + tests: + - not_null + - relationships: + to: ref('contactview_chw') + field: uuid + tests: + - dbt_utils.fewer_rows_than: + compare_model: ref('contactview_metadata') diff --git a/models/brac/useviews/useviews.yml b/models/brac/useviews/useviews.yml index f5bb79d8..b08bce9f 100644 --- a/models/brac/useviews/useviews.yml +++ b/models/brac/useviews/useviews.yml @@ -1,6 +1,29 @@ version: 2 models: + - name: useview_visit + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null + - name: source_id + tests: + - not_null + - name: visit_type + tests: + - not_null + - accepted_values: + values: [anc, pnc, imm, iccm] + - name: danger_signs + tests: + - not_null - name: useview_pregnancy columns: - name: uuid @@ -13,6 +36,27 @@ models: - name: chw tests: - not_null + - name: useview_pregnancy_visit + columns: + - name: xmlforms_uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: useview_postnatal_care + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null - name: useview_place_record columns: - name: place_id @@ -21,6 +65,49 @@ models: - relationships: to: ref('couchdb') field: doc#>>'{fields,place_id}' + - name: useview_patient_record + columns: + - name: patient_id + tests: + - not_null + - relationships: + to: ref('couchdb') + field: doc#>>'{fields,patient_id}' + - name: useview_household_survey + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: useview_health_forum + columns: + - name: xmlforms_uuid + tests: + - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: useview_family_survey + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: useview_assessment + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null - name: formview_fp_patient_record columns: - name: uuid @@ -41,3 +128,16 @@ models: 'fp_follow_up_prospective', 'fp_follow_up_short_term', ] + - name: useview_assessment_follow_up + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('couchdb') + field: doc ->> '_id' + - name: form + tests: + - not_null + - accepted_values: + values: ['assessment_follow_up'] From d7a39298ef0e23d700dba3c1eba77797998b5ae0 Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 17:36:07 -0300 Subject: [PATCH 40/43] Fix brac name --- models/brac/brac.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/brac/brac.yml b/models/brac/brac.yml index 0472bccd..d36cb3ba 100644 --- a/models/brac/brac.yml +++ b/models/brac/brac.yml @@ -43,7 +43,7 @@ models: - name: num_home_deliveries tests: - not_null - - name: brac_kpis + - name: brac-kpis columns: - name: chp_uuid tests: From ef624743848f3133b0d2171c0c0ee9d551273abc Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Fri, 20 Oct 2023 18:22:35 -0300 Subject: [PATCH 41/43] Finish test for views models --- models/brac/views/views.yml | 130 ++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/models/brac/views/views.yml b/models/brac/views/views.yml index ae6d95a3..dd1b8c85 100644 --- a/models/brac/views/views.yml +++ b/models/brac/views/views.yml @@ -1,6 +1,18 @@ version: 2 models: + - name: pncview_actual_enrollments + columns: + - name: delivery_id + tests: + - not_null + - unique + - relationships: + to: ref('useview_postnatal_care') + field: uuid + - name: patient_id + tests: + - not_null - name: ancview_pregnancy columns: - name: uuid @@ -47,6 +59,14 @@ models: - name: epoch tests: - not_null + - name: impactview_month_facility + columns: + - name: month + tests: + - not_null + - name: epoch + tests: + - not_null - name: formview_immunization_follow_up columns: - name: uuid @@ -137,3 +157,113 @@ models: - relationships: to: ref('couchdb') field: doc ->> '_id' + - name: impactview_chw_facility + columns: + - name: chw_uuid + tests: + - not_null + - unique + - relationships: + to: ref('contactview_chp') + field: uuid + - name: impactview_active + columns: + - name: month + tests: + - not_null + - name: epoch + tests: + - not_null + - name: iccmview_active + columns: + - name: month + tests: + - not_null + - name: epoch + tests: + - not_null + - name: fp_referral_cases + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('formview_fp_patient_record') + field: uuid + - name: form + tests: + - not_null + - accepted_values: + values: + [ + 'family_planning', + 'fp_follow_up_long_term', + 'fp_follow_up_refill', + 'fp_follow_up_prospective', + 'fp_follow_up_short_term', + ] + - name: is_referral_case + tests: + - not_null + - accepted_values: + values: [true] + - name: ancview_danger_sign + columns: + - name: uuid + tests: + - not_null + - name: form + tests: + - not_null + - name: ancview_delivery + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_postnatal_care') + field: uuid + - name: form + tests: + - not_null + - name: pregnancy_outcome + tests: + - not_null + - accepted_values: + values: [healthy, still_birth] + - name: ancview_pregnancy_visit + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_visit') + field: uuid + - name: pregnancy_id + tests: + - not_null + - name: form + tests: + - not_null + - name: visit_with_danger_sign + tests: + - not_null + - name: dashboardview_iccm + columns: + - name: month + tests: + - not_null + - name: epoch + tests: + - not_null + - name: dashboardview_iccm_active + columns: + - name: month + tests: + - not_null + - name: epoch + tests: + - not_null From 184fa45b3099f75e8c7be605fa73629427ae12ad Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Mon, 23 Oct 2023 14:05:42 -0300 Subject: [PATCH 42/43] Move and rename impact test file. Implement impact tests --- models/brac/impact/ANC/anc.yml | 23 ------ models/brac/impact/impact.yml | 128 +++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 23 deletions(-) delete mode 100644 models/brac/impact/ANC/anc.yml create mode 100644 models/brac/impact/impact.yml diff --git a/models/brac/impact/ANC/anc.yml b/models/brac/impact/ANC/anc.yml deleted file mode 100644 index 786302d2..00000000 --- a/models/brac/impact/ANC/anc.yml +++ /dev/null @@ -1,23 +0,0 @@ -models: - - name: impact_ancview_danger_sign - columns: - - name: uuid - tests: - - not_null - - unique - - name: reported_by - tests: - - not_null - - name: form - tests: - - not_null - - name: impact_ancview_delivery - columns: - - name: uuid - tests: - - not_null - - name: impact_ancview_pregnancy_visit - columns: - - name: uuid - tests: - - not_null diff --git a/models/brac/impact/impact.yml b/models/brac/impact/impact.yml new file mode 100644 index 00000000..0447c5bc --- /dev/null +++ b/models/brac/impact/impact.yml @@ -0,0 +1,128 @@ +models: + - name: impact_ancview_danger_sign + columns: + - name: uuid + tests: + - not_null + - unique + - name: reported_by + tests: + - not_null + - name: form + tests: + - not_null + - name: impact_ancview_delivery + columns: + - name: uuid + tests: + - not_null + - name: impact_ancview_pregnancy_visit + columns: + - name: uuid + tests: + - not_null + - name: iccmview_assessment_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_assessment_follow_up') + field: uuid + - name: form + tests: + - not_null + - accepted_values: + values: ['assessment_follow_up'] + - name: iccmview_assessment + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('useview_assessment') + field: uuid + - name: form + tests: + - not_null + - name: u1_iccmview_assessment_follow_up + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_assessment_follow_up') + field: uuid + - name: form + tests: + - not_null + - accepted_values: + values: ['assessment_follow_up'] + - name: u1_iccmview_assessment + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('useview_assessment') + field: uuid + - name: form + tests: + - not_null + - name: impact_pncview_actual_enrollments + columns: + - name: delivery_id + tests: + - not_null + - relationships: + to: ref('useview_postnatal_care') + field: uuid + - name: patient_id + tests: + - not_null + - name: impact_pncview_danger_sign + columns: + - name: uuid + tests: + - not_null + - relationships: + to: ref('useview_postnatal_care') + field: uuid + - name: date_of_event + tests: + - not_null + - name: patient_id + tests: + - not_null + - name: impact_pncview_expected_enrollments + columns: + - name: pregnancy_id + tests: + - not_null + - unique + - relationships: + to: ref('ancview_pregnancy') + field: uuid + - name: patient_id + tests: + - not_null + - name: reported_by + tests: + - not_null + - name: impact_pncview_visit + columns: + - name: uuid + tests: + - not_null + - unique + - relationships: + to: ref('useview_postnatal_care') + field: uuid + - name: form + tests: + - not_null + - name: patient_id + tests: + - not_null From ffc4fdd46041921085357d09f8e1973e3b13a57b Mon Sep 17 00:00:00 2001 From: Maria Lorena Rodriguez Viruel Date: Wed, 1 Nov 2023 09:22:08 -0300 Subject: [PATCH 43/43] Delete commented lines --- tests/run_dbt_tests.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/run_dbt_tests.sh b/tests/run_dbt_tests.sh index d586ec74..857a82b5 100755 --- a/tests/run_dbt_tests.sh +++ b/tests/run_dbt_tests.sh @@ -17,7 +17,4 @@ echo Running dbt ... dbt run echo Running tests ... dbt test -#echo Generating documentation... -#dbt docs generate --exclude contactview_chp+ anc_view_pregnancy+ -#dbt docs serve