-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding logic for the immunization data
- Loading branch information
1 parent
32d0596
commit b7e3fe3
Showing
18 changed files
with
209 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
with data as ( | ||
select | ||
distinct clientid, | ||
gender, | ||
birthdate, | ||
maritalstatus, | ||
program, | ||
facilityid | ||
from {{ ref('stg_client_demographics') }} | ||
|
||
union | ||
|
||
select | ||
'-1' as clientid, | ||
'Unknown' as gender, | ||
cast('1900-01-01' as date) as birthdate, | ||
'Unknown' as maritalstatus, | ||
'Unkonwn' as program, | ||
-999 as facilityid | ||
|
||
) | ||
select | ||
{{ dbt_utils.surrogate_key(['clientid']) }} as client_key, | ||
clientid as client_id, | ||
gender, | ||
birthdate, | ||
maritalstatus, | ||
program, | ||
facilityid | ||
from data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
with data as ( | ||
select | ||
distinct facilityid, | ||
facilityname , | ||
facilitycountry, | ||
facilityregion | ||
from {{ ref('stg_facility') }} | ||
|
||
union | ||
|
||
select | ||
-1 as facilityid, | ||
'Unknown' as facilityname, | ||
'Unknown' as facilitycountry, | ||
'Unknown' as facilityregion | ||
) | ||
select | ||
{{ dbt_utils.surrogate_key(['facilityid']) }} as facility_key, | ||
facilityid as facility_id, | ||
facilityname as facility_name, | ||
facilitycountry as country, | ||
facilityregion as facility_region | ||
from data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
with data as ( | ||
select | ||
distinct immunizationstatus | ||
from {{ ref('stg_immunization') }} | ||
|
||
union | ||
|
||
select | ||
'-1' as immunization_status | ||
) | ||
select | ||
{{ dbt_utils.surrogate_key(['immunizationstatus']) }} as immunization_status_key, | ||
immunizationstatus as immunization_status | ||
from data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
with data as ( | ||
select | ||
vaccinecode, | ||
displaylong, | ||
displayshort | ||
from {{ ref('stg_vaccine') }} | ||
|
||
union | ||
|
||
select | ||
'-1' as vaccinecode, | ||
'Unknown' as displaylong, | ||
'Unknown' as displayshort | ||
) | ||
select | ||
{{ dbt_utils.surrogate_key(['vaccinecode']) }} as vaccine_key, | ||
vaccinecode as vaccine_code, | ||
displaylong, | ||
displayshort | ||
from data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version: 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
select | ||
coalesce(facility_key, {{ var('unknown_key') }}) as facility_key, | ||
coalesce(client_key, {{ var('unknown_key') }}) as client_key, | ||
coalesce(vaccine_key, {{ var('unknown_key') }}) as vaccine_key, | ||
coalesce(occurence.date_key, {{ var('date_unknown_key') }}) as occurence_date_key, | ||
coalesce(status.immunization_status_key, {{ var('unknown_key') }}) as immunization_status_key, | ||
dosequantity as dose_quantity, | ||
dosenumber as dose_number, | ||
case | ||
when age(immunization.occurrencedate, client.birthdate) = interval '12 months' then true | ||
else false | ||
end is_12_months_old_at_immunization, | ||
case | ||
when age(immunization.occurrencedate, client.birthdate) = interval '24 months' then true | ||
else false | ||
end is_24_months_old_at_immunization | ||
from {{ ref ('stg_immunization') }} as immunization | ||
left join {{ ref('dim_client') }} as client on client.client_id = immunization.clientid | ||
left join {{ ref('dim_facility') }} as facility on facility.facility_id = immunization.facilityid | ||
left join {{ ref('dim_vaccine') }} as vaccine on vaccine.vaccine_code = immunization.vaccinecode | ||
left join {{ ref('dim_date') }} as occurence on occurence.date = immunization.occurrencedate | ||
left join {{ ref('dim_vaccination_status') }} as status on status.immunization_status = immunization.immunizationstatus | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version: 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
version: 2 | ||
sources: | ||
- name: | ||
database: | ||
schema: | ||
- name: base_layer | ||
database: analytics | ||
schema: base_layer | ||
tables: | ||
- name: | ||
description: | ||
- name: clientdemographics | ||
description: Client demographics | ||
- name: clientrelationship | ||
description: client relationships | ||
- name: encounter | ||
description: encounter viits | ||
- name: facility | ||
description: facility list | ||
- name: immunization | ||
description: immunization encounters | ||
- name: lab | ||
description: lab data | ||
- name: medication | ||
description: medication data | ||
- name: organization | ||
description: organization data | ||
- name: vaccine | ||
description: types of vaccines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: stg_client_demographics | ||
description: Data on client demographics where each entry is a single patient | ||
columns: | ||
- name: gender | ||
description: Gender of client | ||
data_tests: | ||
- not_null | ||
- accepted_values: | ||
values: ['FEMALE', 'MALE'] | ||
- name: stg_facility | ||
description: Data on facility details | ||
columns: | ||
- name: facilityname | ||
description: facilityname | ||
data_tests: | ||
- unique | ||
- not_null | ||
- name: stg_immunization | ||
description: Data on immunization encounters | ||
columns: | ||
- name: vaccinecode | ||
description: Universal vaccine code associated with a vaccine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select | ||
* | ||
from {{ source('base_layer', 'clientdemographics') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select | ||
* | ||
from {{ source('base_layer', 'facility') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select | ||
* | ||
from {{ source('base_layer', 'immunization') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select | ||
* | ||
from {{ source('base_layer', 'vaccine') }} |
21 changes: 21 additions & 0 deletions
21
models/universal_semantic_layer/aggregate_immunization.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
select | ||
facility.facility_name, | ||
client.gender, | ||
vaccine.displaylong as vaccine_name, | ||
status.immunization_status, | ||
dim_date."date" as date_of_immunization, | ||
count(distinct case when immunization_data.is_12_months_old_at_immunization = true then client.client_key end) as no_children_immunized_at_12_months, | ||
count(distinct case when immunization_data.is_24_months_old_at_immunization = true then client.client_key end) as no_children_immunized_at_24_months | ||
from {{ ref('fct_immunization') }} as immunization_data | ||
left join {{ ref('dim_facility') }} as facility on facility.facility_key = immunization_data.facility_key | ||
left join {{ ref('dim_client') }} as client on client.client_key = immunization_data.client_key | ||
left join {{ ref('dim_vaccine') }} as vaccine on vaccine.vaccine_key = immunization_data.vaccine_key | ||
left join {{ ref('dim_vaccination_status') }} as status on status.immunization_status_key = immunization_data.immunization_status_key | ||
left join {{ ref('dim_date') }} as dim_date on dim_date.date_key = immunization_data.occurence_date_key | ||
where status.immunization_status = 'Fully Immunized' | ||
group by | ||
facility.facility_name, | ||
client.gender, | ||
vaccine.displaylong, | ||
status.immunization_status, | ||
dim_date."date" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version: 2 |