%3 (target) stg_patients (target) stg_patients birth_date city county death_date ethnicity gender healthcare_coverage healthcare_expenses latitude longitude race street_address zip_code (source) stg_person (source) stg_person birth_datetime ethnicity_source_value gender_source_value race_source_value (source) stg_person:f0->(target) stg_patients:f0 (source) stg_person:f1->(target) stg_patients:f4 (source) stg_person:f2->(target) stg_patients:f5 (source) stg_person:f3->(target) stg_patients:f10 (source) stg_location (source) stg_location city county latitude longitude address_1 address_2 zip state (source) stg_location:f0->(target) stg_patients:f1 (source) stg_location:f1->(target) stg_patients:f2 (source) stg_location:f2->(target) stg_patients:f8 (source) stg_location:f3->(target) stg_patients:f9 (source) stg_location:f4->(target) stg_patients:f11 (source) stg_location:f5->(target) stg_patients:f11 (source) stg_location:f6->(target) stg_patients:f12 (target) stg_organizations (target) stg_organizations CITY STATE ZIP facility_name latitude longitude street_address (source) stg_location:f0->(target) stg_organizations:f0 (source) stg_location:f7->(target) stg_organizations:f1 (source) stg_location:f6->(target) stg_organizations:f2 (source) stg_location:f2->(target) stg_organizations:f4 (source) stg_location:f3->(target) stg_organizations:f5 (source) stg_location:f4->(target) stg_organizations:f6 (source) stg_location:f5->(target) stg_organizations:f6 (target) stg_providers (target) stg_providers CITY GENDER SPECIALITY STATE ZIP latitude longitude provider_name street_address (source) stg_location:f0->(target) stg_providers:f0 (source) stg_location:f7->(target) stg_providers:f3 (source) stg_location:f6->(target) stg_providers:f4 (source) stg_location:f2->(target) stg_providers:f5 (source) stg_location:f3->(target) stg_providers:f6 (source) stg_location:f4->(target) stg_providers:f8 (source) stg_location:f5->(target) stg_providers:f8 (source) stg_death (source) stg_death death_datetime (source) stg_death:f0->(target) stg_patients:f3 (source) stg_cost (source) stg_cost paid_by_payer paid_by_primary total_charge total_paid paid_by_patient (source) stg_cost:f0->(target) stg_patients:f6 (source) stg_cost:f1->(target) stg_patients:f6 (source) stg_cost:f2->(target) stg_patients:f7 (target) stg_claims (target) stg_claims illness_onset_date patient_outstanding_amount service_date (source) stg_cost:f2->(target) stg_claims:f1 (source) stg_cost:f3->(target) stg_claims:f1 (target) stg_encounters (target) stg_encounters base_cost encounter_end encounter_start payer_coverage procedure_code total_cost (source) stg_cost:f0->(target) stg_encounters:f3 (source) stg_cost:f2->(target) stg_encounters:f5 (target) stg_medications (target) stg_medications order_end_datetime order_start_datetime payer_coverage_amount total_cost (source) stg_cost:f0->(target) stg_medications:f2 (source) stg_cost:f2->(target) stg_medications:f3 (target) stg_payers (target) stg_payers covered_amount member_months payer_name uncovered_amount unique_customers (source) stg_cost:f0->(target) stg_payers:f0 (source) stg_cost:f4->(target) stg_payers:f3 (target) stg_allergies (target) stg_allergies allergen_code allergen_description allergy_end_date allergy_start_date (source) stg_condition_occurrence (source) stg_condition_occurrence condition_source_value condition_end_date condition_start_date (source) stg_condition_occurrence:f0->(target) stg_allergies:f0 (source) stg_condition_occurrence:f0->(target) stg_allergies:f1 (source) stg_condition_occurrence:f1->(target) stg_allergies:f2 (source) stg_condition_occurrence:f2->(target) stg_allergies:f3 (source) stg_condition_occurrence:f2->(target) stg_claims:f0 (target) stg_conditions (target) stg_conditions condition_end_date condition_start_date (source) stg_condition_occurrence:f1->(target) stg_conditions:f0 (source) stg_condition_occurrence:f2->(target) stg_conditions:f1 (target) stg_careplans (target) stg_careplans care_plan_id end_date start_date treatment_code (source) stg_procedure_occurrence (source) stg_procedure_occurrence procedure_occurrence_id procedure_source_value procedure_cost procedure_datetime (source) stg_procedure_occurrence:f0->(target) stg_careplans:f0 (source) stg_procedure_occurrence:f1->(target) stg_careplans:f3 (source) stg_procedure_occurrence:f2->(target) stg_encounters:f0 (source) stg_procedure_occurrence:f1->(target) stg_encounters:f4 (target) stg_immunizations (target) stg_immunizations base_cost immunization_datetime (source) stg_procedure_occurrence:f2->(target) stg_immunizations:f0 (source) stg_procedure_occurrence:f3->(target) stg_immunizations:f1 (target) stg_procedures (target) stg_procedures procedure_cost procedure_end_time procedure_start_time (source) stg_procedure_occurrence:f2->(target) stg_procedures:f0 (source) stg_procedure_occurrence:f3->(target) stg_procedures:f2 (source) stg_visit_occurrence (source) stg_visit_occurrence visit_end_date visit_start_date visit_end_datetime visit_start_datetime (source) stg_visit_occurrence:f0->(target) stg_careplans:f1 (source) stg_visit_occurrence:f1->(target) stg_careplans:f2 (source) stg_visit_occurrence:f1->(target) stg_claims:f2 (source) stg_visit_occurrence:f2->(target) stg_encounters:f1 (source) stg_visit_occurrence:f3->(target) stg_encounters:f2 (source) stg_visit_occurrence:f2->(target) stg_procedures:f1 (target) stg_devices (target) stg_devices usage_end_date usage_start_date (source) stg_device (source) stg_device device_exposure_end_date device_exposure_start_date (source) stg_device:f0->(target) stg_devices:f0 (source) stg_device:f1->(target) stg_devices:f1 (source) stg_drug_exposure (source) stg_drug_exposure drug_exposure_end_date drug_exposure_start_date (source) stg_drug_exposure:f0->(target) stg_medications:f0 (source) stg_drug_exposure:f1->(target) stg_medications:f1 (target) stg_observations (target) stg_observations DESCRIPTION UNITS data_type observation_datetime observation_value (source) stg_observation (source) stg_observation observation_source_value unit_source_value value_as_number value_as_string observation_datetime (source) stg_observation:f0->(target) stg_observations:f0 (source) stg_observation:f1->(target) stg_observations:f1 (source) stg_observation:f2->(target) stg_observations:f2 (source) stg_observation:f3->(target) stg_observations:f2 (source) stg_observation:f4->(target) stg_observations:f3 (source) stg_observation:f2->(target) stg_observations:f4 (source) stg_observation:f3->(target) stg_observations:f4 (source) stg_care_site (source) stg_care_site care_site_name (source) stg_care_site:f0->(target) stg_organizations:f3 (source) stg_payer_plan_period (source) stg_payer_plan_period payer_plan_period_start_date payer_plan_period_end_date payer_source_value payer_plan_period_id (source) stg_payer_plan_period:f0->(target) stg_payers:f1 (source) stg_payer_plan_period:f1->(target) stg_payers:f1 (source) stg_payer_plan_period:f2->(target) stg_payers:f2 (source) stg_payer_plan_period:f3->(target) stg_payers:f4 (source) stg_provider (source) stg_provider gender_source_value specialty_source_value provider_name (source) stg_provider:f0->(target) stg_providers:f1 (source) stg_provider:f1->(target) stg_providers:f2 (source) stg_provider:f2->(target) stg_providers:f7 (target) stg_supplies (target) stg_supplies
%3 (target) stg_patients (target) stg_patients birth_date city county death_date ethnicity gender healthcare_coverage healthcare_expenses latitude longitude race street_address zip_code (source) stg_person (source) stg_person birth_datetime ethnicity_source_value gender_source_value race_source_value (source) stg_person:f0->(target) stg_patients:f0 (source) stg_person:f1->(target) stg_patients:f4 (source) stg_person:f2->(target) stg_patients:f5 (source) stg_person:f3->(target) stg_patients:f10 (source) stg_location (source) stg_location city county latitude longitude address_1 address_2 zip (source) stg_location:f0->(target) stg_patients:f1 (source) stg_location:f1->(target) stg_patients:f2 (source) stg_location:f2->(target) stg_patients:f8 (source) stg_location:f3->(target) stg_patients:f9 (source) stg_location:f4->(target) stg_patients:f11 (source) stg_location:f5->(target) stg_patients:f11 (source) stg_location:f6->(target) stg_patients:f12 (source) stg_death (source) stg_death death_datetime (source) stg_death:f0->(target) stg_patients:f3 (source) stg_cost (source) stg_cost paid_by_payer paid_by_primary total_charge (source) stg_cost:f0->(target) stg_patients:f6 (source) stg_cost:f1->(target) stg_patients:f6 (source) stg_cost:f2->(target) stg_patients:f7
SELECT 
    CAST(p.birth_datetime AS DATE) AS birth_date,
    l.city,
    l.county,
    CAST(d.death_datetime AS DATE) AS death_date,
    CASE 
        WHEN p.ethnicity_source_value = 'Hispanic or Latino' THEN 'hispanic'
        WHEN p.ethnicity_source_value = 'Not Hispanic or Latino' THEN 'nonhispanic'
        ELSE p.ethnicity_source_value
    END AS ethnicity,
    p.gender_source_value AS gender,
    SUM(c.paid_by_payer + c.paid_by_primary) AS healthcare_coverage,
    c.total_charge AS healthcare_expenses,
    l.latitude,
    l.longitude,
    CASE 
        WHEN p.race_source_value = 'Black or African American' THEN 'black'
        WHEN p.race_source_value = 'White' THEN 'white'
        ELSE p.race_source_value
    END AS race,
    CONCAT(l.address_1, ' ', l.address_2) AS street_address,
    l.zip AS zip_code
FROM 
    "memory"."cocoon_schema"."stg_person" p
JOIN 
    "memory"."cocoon_schema"."stg_location" l ON p.location_id = l.location_id
LEFT JOIN 
    "memory"."cocoon_schema"."stg_death" d ON p.person_id = d.person_id
LEFT JOIN 
    "memory"."cocoon_schema"."stg_cost" c ON p.person_id = c.person_id
GROUP BY 
    p.person_id, p.birth_datetime, l.city, l.county, d.death_datetime, 
    p.ethnicity_source_value, p.gender_source_value, c.total_charge, 
    l.latitude, l.longitude, p.race_source_value, l.address_1, l.address_2, l.zip
birth_date city county death_date ethnicity gender healthcare_coverage healthcare_expenses latitude longitude race street_address zip_code
0 1985-05-20 Springfield Hampden 2023-05-15 nonhispanic M 800.0 500.0 40.7128 -74.0060 white 123 Main St Suite 100 12345
1 1990-08-10 Riverdale Archie 2023-06-20 hispanic F 2600.0 1500.0 34.0522 -118.2437 black 456 Elm St Apt 202 67890
%3 (target) stg_allergies (target) stg_allergies allergen_code allergen_description allergy_end_date allergy_start_date (source) stg_condition_occurrence (source) stg_condition_occurrence condition_source_value condition_end_date condition_start_date (source) stg_condition_occurrence:f0->(target) stg_allergies:f0 (source) stg_condition_occurrence:f0->(target) stg_allergies:f1 (source) stg_condition_occurrence:f1->(target) stg_allergies:f2 (source) stg_condition_occurrence:f2->(target) stg_allergies:f3
SELECT 
    sco.condition_source_value AS allergen_code,
    sco.condition_source_value AS allergen_description,
    sco.condition_end_date AS allergy_end_date,
    sco.condition_start_date AS allergy_start_date
FROM 
    "memory"."cocoon_schema"."stg_condition_occurrence" AS sco
allergen_code allergen_description allergy_end_date allergy_start_date
0 Diabetes Diabetes 2021-01-20 2021-01-10
1 Hypertension Hypertension 2021-02-25 2021-02-15
%3 (target) stg_careplans (target) stg_careplans care_plan_id end_date start_date treatment_code (source) stg_procedure_occurrence (source) stg_procedure_occurrence procedure_occurrence_id procedure_source_value (source) stg_procedure_occurrence:f0->(target) stg_careplans:f0 (source) stg_procedure_occurrence:f1->(target) stg_careplans:f3 (source) stg_visit_occurrence (source) stg_visit_occurrence visit_end_date visit_start_date (source) stg_visit_occurrence:f0->(target) stg_careplans:f1 (source) stg_visit_occurrence:f1->(target) stg_careplans:f2
SELECT 
    po.procedure_occurrence_id AS care_plan_id,
    vo.visit_end_date AS end_date,
    vo.visit_start_date AS start_date,
    po.procedure_source_value AS treatment_code
FROM 
    "memory"."cocoon_schema"."stg_procedure_occurrence" po
JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" vo
    ON po.visit_occurrence_id = vo.visit_occurrence_id
care_plan_id end_date start_date treatment_code
0 2 2023-01-12 2023-01-10 PROC2
1 1 2023-01-12 2023-01-10 PROC1
%3 (target) stg_claims (target) stg_claims illness_onset_date patient_outstanding_amount service_date (source) stg_condition_occurrence (source) stg_condition_occurrence condition_start_date (source) stg_condition_occurrence:f0->(target) stg_claims:f0 (source) stg_cost (source) stg_cost total_charge total_paid (source) stg_cost:f0->(target) stg_claims:f1 (source) stg_cost:f1->(target) stg_claims:f1 (source) stg_visit_occurrence (source) stg_visit_occurrence visit_start_date (source) stg_visit_occurrence:f0->(target) stg_claims:f2
SELECT 
    co.condition_start_date AS illness_onset_date,
    (c.total_charge - c.total_paid) AS patient_outstanding_amount,
    vo.visit_start_date AS service_date
FROM 
    "memory"."cocoon_schema"."stg_visit_occurrence" vo
LEFT JOIN 
    "memory"."cocoon_schema"."stg_condition_occurrence" co
    ON vo.visit_occurrence_id = co.visit_occurrence_id
LEFT JOIN 
    "memory"."cocoon_schema"."stg_cost" c
    ON vo.person_id = c.person_id
illness_onset_date patient_outstanding_amount service_date
0 2021-01-10 NaN 2023-01-10
1 2021-02-15 NaN 2023-02-15
%3 (target) stg_conditions (target) stg_conditions condition_end_date condition_start_date (source) stg_condition_occurrence (source) stg_condition_occurrence condition_end_date condition_start_date (source) stg_condition_occurrence:f0->(target) stg_conditions:f0 (source) stg_condition_occurrence:f1->(target) stg_conditions:f1
SELECT 
    co.condition_end_date,
    co.condition_start_date
FROM 
    "memory"."cocoon_schema"."stg_condition_occurrence" co
JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" vo
    ON co.visit_occurrence_id = vo.visit_occurrence_id
condition_end_date condition_start_date
0 2021-01-20 2021-01-10
1 2021-02-25 2021-02-15
%3 (target) stg_devices (target) stg_devices usage_end_date usage_start_date (source) stg_device (source) stg_device device_exposure_end_date device_exposure_start_date (source) stg_device:f0->(target) stg_devices:f0 (source) stg_device:f1->(target) stg_devices:f1
SELECT 
    sd.device_exposure_end_date AS usage_end_date,
    sd.device_exposure_start_date AS usage_start_date
FROM 
    "memory"."cocoon_schema"."stg_device" sd
JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" svo
    ON sd.visit_occurrence_id = svo.visit_occurrence_id
usage_end_date usage_start_date
0 2023-01-20 2023-01-15
1 2023-02-25 2023-02-20
%3 (target) stg_encounters (target) stg_encounters base_cost encounter_end encounter_start payer_coverage procedure_code total_cost (source) stg_procedure_occurrence (source) stg_procedure_occurrence procedure_cost procedure_source_value (source) stg_procedure_occurrence:f0->(target) stg_encounters:f0 (source) stg_procedure_occurrence:f1->(target) stg_encounters:f4 (source) stg_visit_occurrence (source) stg_visit_occurrence visit_end_datetime visit_start_datetime (source) stg_visit_occurrence:f0->(target) stg_encounters:f1 (source) stg_visit_occurrence:f1->(target) stg_encounters:f2 (source) stg_cost (source) stg_cost paid_by_payer total_charge (source) stg_cost:f0->(target) stg_encounters:f3 (source) stg_cost:f1->(target) stg_encounters:f5
SELECT 
    spo.procedure_cost AS base_cost,
    svo.visit_end_datetime AS encounter_end,
    svo.visit_start_datetime AS encounter_start,
    sc.paid_by_payer AS payer_coverage,
    spo.procedure_source_value AS procedure_code,
    sc.total_charge AS total_cost
FROM 
    "memory"."cocoon_schema"."stg_procedure_occurrence" spo
JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" svo
    ON spo.visit_occurrence_id = svo.visit_occurrence_id
JOIN 
    "memory"."cocoon_schema"."stg_cost" sc
    ON spo.person_id = sc.person_id
%3 (target) stg_immunizations (target) stg_immunizations base_cost immunization_datetime (source) stg_procedure_occurrence (source) stg_procedure_occurrence procedure_cost procedure_datetime (source) stg_procedure_occurrence:f0->(target) stg_immunizations:f0 (source) stg_procedure_occurrence:f1->(target) stg_immunizations:f1
SELECT 
    spo.procedure_cost AS base_cost,
    spo.procedure_datetime AS immunization_datetime
FROM 
    "memory"."cocoon_schema"."stg_procedure_occurrence" spo
LEFT JOIN 
    "memory"."cocoon_schema"."stg_person" sp ON spo.person_id = sp.person_id
LEFT JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" svo ON spo.visit_occurrence_id = svo.visit_occurrence_id
LEFT JOIN 
    "memory"."cocoon_schema"."stg_provider" sprov ON spo.provider_id = sprov.provider_id
LEFT JOIN 
    "memory"."cocoon_schema"."stg_cost" sc ON spo.procedure_occurrence_id = sc.cost_id
base_cost immunization_datetime
0 200.0 2023-01-15 10:00:00
1 450.0 2023-02-20 14:30:00
%3 (target) stg_medications (target) stg_medications order_end_datetime order_start_datetime payer_coverage_amount total_cost (source) stg_drug_exposure (source) stg_drug_exposure drug_exposure_end_date drug_exposure_start_date (source) stg_drug_exposure:f0->(target) stg_medications:f0 (source) stg_drug_exposure:f1->(target) stg_medications:f1 (source) stg_cost (source) stg_cost paid_by_payer total_charge (source) stg_cost:f0->(target) stg_medications:f2 (source) stg_cost:f1->(target) stg_medications:f3
SELECT 
    de.drug_exposure_end_date AS order_end_datetime,
    de.drug_exposure_start_date AS order_start_datetime,
    c.paid_by_payer AS payer_coverage_amount,
    c.total_charge AS total_cost
FROM 
    "memory"."cocoon_schema"."stg_drug_exposure" de
JOIN 
    "memory"."cocoon_schema"."stg_person" p ON de.person_id = p.person_id
JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" vo ON de.visit_occurrence_id = vo.visit_occurrence_id
JOIN 
    "memory"."cocoon_schema"."stg_cost" c ON de.person_id = c.person_id
%3 (target) stg_observations (target) stg_observations DESCRIPTION UNITS data_type observation_datetime observation_value (source) stg_observation (source) stg_observation observation_source_value unit_source_value value_as_number value_as_string observation_datetime (source) stg_observation:f0->(target) stg_observations:f0 (source) stg_observation:f1->(target) stg_observations:f1 (source) stg_observation:f2->(target) stg_observations:f2 (source) stg_observation:f3->(target) stg_observations:f2 (source) stg_observation:f4->(target) stg_observations:f3 (source) stg_observation:f2->(target) stg_observations:f4 (source) stg_observation:f3->(target) stg_observations:f4
SELECT 
    obs.observation_source_value AS DESCRIPTION,
    obs.unit_source_value AS UNITS,
    CASE 
        WHEN obs.value_as_number IS NOT NULL THEN 'numeric'
        WHEN obs.value_as_string IS NOT NULL THEN 'text'
        ELSE 'unknown'
    END AS data_type,
    obs.observation_datetime AS observation_datetime,
    COALESCE(CAST(obs.value_as_number AS VARCHAR), obs.value_as_string) AS observation_value
FROM 
    "memory"."cocoon_schema"."stg_observation" obs
WHERE 
    obs.observation_source_value IS NOT NULL
    OR obs.unit_source_value IS NOT NULL
    OR obs.value_as_number IS NOT NULL
    OR obs.value_as_string IS NOT NULL
    OR obs.observation_datetime IS NOT NULL
DESCRIPTION UNITS data_type observation_datetime observation_value
0 Blood Pressure mmHg numeric 2023-01-01 08:00:00 98.6
1 Heart Rate beats/min numeric 2023-01-02 09:30:00 99.5
%3 (target) stg_organizations (target) stg_organizations CITY STATE ZIP facility_name latitude longitude street_address (source) stg_location (source) stg_location city state zip latitude longitude address_1 address_2 (source) stg_location:f0->(target) stg_organizations:f0 (source) stg_location:f1->(target) stg_organizations:f1 (source) stg_location:f2->(target) stg_organizations:f2 (source) stg_location:f3->(target) stg_organizations:f4 (source) stg_location:f4->(target) stg_organizations:f5 (source) stg_location:f5->(target) stg_organizations:f6 (source) stg_location:f6->(target) stg_organizations:f6 (source) stg_care_site (source) stg_care_site care_site_name (source) stg_care_site:f0->(target) stg_organizations:f3
SELECT 
    l.city AS CITY,
    l.state AS STATE,
    l.zip AS ZIP,
    cs.care_site_name AS facility_name,
    l.latitude AS latitude,
    l.longitude AS longitude,
    CONCAT(l.address_1, COALESCE(', ' || l.address_2, '')) AS street_address
FROM 
    "memory"."cocoon_schema"."stg_care_site" cs
JOIN 
    "memory"."cocoon_schema"."stg_location" l ON cs.location_id = l.location_id
CITY STATE ZIP facility_name latitude longitude street_address
0 Springfield NY 12345 City Hospital 40.7128 -74.0060 123 Main St, Suite 100
1 Riverdale CA 67890 Rural Clinic 34.0522 -118.2437 456 Elm St, Apt 202
%3 (target) stg_payers (target) stg_payers covered_amount member_months payer_name uncovered_amount unique_customers (source) stg_cost (source) stg_cost paid_by_payer paid_by_patient (source) stg_cost:f0->(target) stg_payers:f0 (source) stg_cost:f1->(target) stg_payers:f3 (source) stg_payer_plan_period (source) stg_payer_plan_period payer_plan_period_start_date payer_plan_period_end_date payer_source_value payer_plan_period_id (source) stg_payer_plan_period:f0->(target) stg_payers:f1 (source) stg_payer_plan_period:f1->(target) stg_payers:f1 (source) stg_payer_plan_period:f2->(target) stg_payers:f2 (source) stg_payer_plan_period:f3->(target) stg_payers:f4
SELECT 
    SUM(sc.paid_by_payer) AS covered_amount,
    SUM(DATEDIFF('month', CAST(spp.payer_plan_period_end_date AS DATE), CAST(spp.payer_plan_period_start_date AS DATE))) AS member_months,
    spp.payer_source_value AS payer_name,
    SUM(sc.paid_by_patient) AS uncovered_amount,
    COUNT(DISTINCT spp.payer_plan_period_id) AS unique_customers
FROM 
    "memory"."cocoon_schema"."stg_cost" sc
JOIN 
    "memory"."cocoon_schema"."stg_person" sp ON sc.person_id = sp.person_id
JOIN 
    "memory"."cocoon_schema"."stg_payer_plan_period" spp ON sp.person_id = spp.person_id
GROUP BY 
    spp.payer_source_value
%3 (target) stg_procedures (target) stg_procedures procedure_cost procedure_end_time procedure_start_time (source) stg_procedure_occurrence (source) stg_procedure_occurrence procedure_cost procedure_datetime (source) stg_procedure_occurrence:f0->(target) stg_procedures:f0 (source) stg_procedure_occurrence:f1->(target) stg_procedures:f2 (source) stg_visit_occurrence (source) stg_visit_occurrence visit_end_datetime (source) stg_visit_occurrence:f0->(target) stg_procedures:f1
SELECT 
    spo.procedure_cost AS procedure_cost,
    svo.visit_end_datetime AS procedure_end_time,
    spo.procedure_datetime AS procedure_start_time
FROM 
    "memory"."cocoon_schema"."stg_procedure_occurrence" spo
JOIN 
    "memory"."cocoon_schema"."stg_visit_occurrence" svo
    ON spo.visit_occurrence_id = svo.visit_occurrence_id
procedure_cost procedure_end_time procedure_start_time
0 450.0 2023-01-12 15:00:00 2023-02-20 14:30:00
1 200.0 2023-01-12 15:00:00 2023-01-15 10:00:00
%3 (target) stg_providers (target) stg_providers CITY GENDER SPECIALITY STATE ZIP latitude longitude provider_name street_address (source) stg_location (source) stg_location city state zip latitude longitude address_1 address_2 (source) stg_location:f0->(target) stg_providers:f0 (source) stg_location:f1->(target) stg_providers:f3 (source) stg_location:f2->(target) stg_providers:f4 (source) stg_location:f3->(target) stg_providers:f5 (source) stg_location:f4->(target) stg_providers:f6 (source) stg_location:f5->(target) stg_providers:f8 (source) stg_location:f6->(target) stg_providers:f8 (source) stg_provider (source) stg_provider gender_source_value specialty_source_value provider_name (source) stg_provider:f0->(target) stg_providers:f1 (source) stg_provider:f1->(target) stg_providers:f2 (source) stg_provider:f2->(target) stg_providers:f7
SELECT 
    l.city AS CITY,
    p.gender_source_value AS GENDER,
    p.specialty_source_value AS SPECIALITY,
    l.state AS STATE,
    l.zip AS ZIP,
    l.latitude,
    l.longitude,
    p.provider_name,
    CASE 
        WHEN l.address_2 IS NOT NULL THEN CONCAT(l.address_1, ' ', l.address_2)
        ELSE l.address_1
    END AS street_address
FROM 
    "memory"."cocoon_schema"."stg_provider" p
CROSS JOIN 
    "memory"."cocoon_schema"."stg_location" l
CITY GENDER SPECIALITY STATE ZIP latitude longitude provider_name street_address
0 Springfield F Cardiology NY 12345 40.7128 -74.0060 Dr. Jane Smith 123 Main St Suite 100
1 Riverdale F Cardiology CA 67890 34.0522 -118.2437 Dr. Jane Smith 456 Elm St Apt 202
2 Springfield M Neurology NY 12345 40.7128 -74.0060 Dr. John Doe 123 Main St Suite 100
3 Riverdale M Neurology CA 67890 34.0522 -118.2437 Dr. John Doe 456 Elm St Apt 202
%3 (target) stg_supplies (target) stg_supplies