-- noqa: disable=all
-- This sql was autogenerated as a reference example using the library
-- CLI. Its format is tied to the specific database it was run against,
-- and it may not be correct for all databases. Use the CLI's build 
-- option to derive the best SQL for your dataset.

-- ###########################################################


CREATE TABLE discovery__tmp_allergyintolerance_clinicalstatus AS

    SELECT DISTINCT
        'allergyintolerance' AS table_name,
        'clinicalstatus' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM allergyintolerance,
    UNNEST(clinicalstatus.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_allergyintolerance_verificationstatus AS

    SELECT DISTINCT
        'allergyintolerance' AS table_name,
        'verificationstatus' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM allergyintolerance,
    UNNEST(verificationstatus.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_allergyintolerance_code AS

    SELECT DISTINCT
        'allergyintolerance' AS table_name,
        'code' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM allergyintolerance,
    UNNEST(code.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_allergyintolerance_reaction_substance AS
SELECT *
FROM (
    VALUES (
        'allergyintolerance',
        'reaction.substance',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_allergyintolerance_reaction_manifestation AS
SELECT *
FROM (
    VALUES (
        'allergyintolerance',
        'reaction.manifestation',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_allergyintolerance_reaction_exposureroute AS
SELECT *
FROM (
    VALUES (
        'allergyintolerance',
        'reaction.exposureroute',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_condition_category AS

    SELECT DISTINCT
        'condition' AS table_name,
        'category' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM condition,
    UNNEST(category) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_condition_code AS

    SELECT DISTINCT
        'condition' AS table_name,
        'code' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM condition,
    UNNEST(code.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_diagnosticreport_category AS

    SELECT DISTINCT
        'diagnosticreport' AS table_name,
        'category' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM diagnosticreport,
    UNNEST(category) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_diagnosticreport_code AS

    SELECT DISTINCT
        'diagnosticreport' AS table_name,
        'code' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM diagnosticreport,
    UNNEST(code.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_diagnosticreport_conclusioncode AS
SELECT *
FROM (
    VALUES (
        'diagnosticreport',
        'conclusioncode',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_documentreference_type AS

    SELECT DISTINCT
        'documentreference' AS table_name,
        'type' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM documentreference,
    UNNEST(type.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_documentreference_category AS

    SELECT DISTINCT
        'documentreference' AS table_name,
        'category' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM documentreference,
    UNNEST(category) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_encounter_class AS

    SELECT DISTINCT
        'encounter' AS table_name,
        'class' AS column_name,
        class.code,
        class.display,
        class.system
    FROM encounter;
CREATE TABLE discovery__tmp_encounter_type AS

    SELECT DISTINCT
        'encounter' AS table_name,
        'type' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM encounter,
    UNNEST(type) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_encounter_servicetype AS
SELECT *
FROM (
    VALUES (
        'encounter',
        'servicetype',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_encounter_priority AS
SELECT *
FROM (
    VALUES (
        'encounter',
        'priority',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_encounter_reasoncode AS

    SELECT DISTINCT
        'encounter' AS table_name,
        'reasoncode' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM encounter,
    UNNEST(reasoncode) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_encounter_hospitalization_dischargedisposition AS

    SELECT DISTINCT
        'encounter' AS table_name,
        'hospitalization.dischargedisposition' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM encounter,
    UNNEST(hospitalization.dischargedisposition.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_location_type AS
SELECT *
FROM (
    VALUES (
        'location',
        'type',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_medication_codecodeableconcept AS
SELECT *
FROM (
    VALUES (
        'medication',
        'codecodeableconcept',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_medication_medicationcode AS
SELECT *
FROM (
    VALUES (
        'medication',
        'medicationcode',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_medicationrequest_medicationcodeableconcept AS

    SELECT DISTINCT
        'medicationrequest' AS table_name,
        'medicationcodeableconcept' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM medicationrequest,
    UNNEST(medicationcodeableconcept.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_observation_category AS

    SELECT DISTINCT
        'observation' AS table_name,
        'category' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM observation,
    UNNEST(category) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_observation_code AS

    SELECT DISTINCT
        'observation' AS table_name,
        'code' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM observation,
    UNNEST(code.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_observation_component_code AS

    SELECT DISTINCT
        'observation' AS table_name,
        'component.code' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM observation,
    UNNEST(component) AS table_1 (col_1),
    UNNEST(col_1.code.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_observation_interpretation AS
SELECT *
FROM (
    VALUES (
        'observation',
        'interpretation',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_observation_valuecodeableconcept AS

    SELECT DISTINCT
        'observation' AS table_name,
        'valuecodeableconcept' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM observation,
    UNNEST(valuecodeableconcept.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_observation_dataabsentreason AS
SELECT *
FROM (
    VALUES (
        'observation',
        'dataabsentreason',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_organization_type AS

    SELECT DISTINCT
        'organization' AS table_name,
        'type' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM organization,
    UNNEST(type) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_patient_maritalstatus AS

    SELECT DISTINCT
        'patient' AS table_name,
        'maritalstatus' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM patient,
    UNNEST(maritalstatus.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_practitioner_qualification_code AS
SELECT *
FROM (
    VALUES (
        'practitioner',
        'qualification.code',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_practitionerrole_code AS

    SELECT DISTINCT
        'practitionerrole' AS table_name,
        'code' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM practitionerrole,
    UNNEST(code) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_practitionerrole_specialty AS

    SELECT DISTINCT
        'practitionerrole' AS table_name,
        'specialty' AS column_name,
        table_2.col_2.code,
        table_2.col_2.display,
        table_2.col_2.system
    FROM practitionerrole,
    UNNEST(specialty) AS table_1 (col_1),
    UNNEST(col_1.coding) as table_2 (col_2);
CREATE TABLE discovery__tmp_procedure_statusreason AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'statusreason',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_category AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'category',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_code AS

    SELECT DISTINCT
        'procedure' AS table_name,
        'code' AS column_name,
        table_1.col_1.code,
        table_1.col_1.display,
        table_1.col_1.system
    FROM procedure,
    UNNEST(code.coding) AS table_1 (col_1);
CREATE TABLE discovery__tmp_procedure_performer_function AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'performer.function',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_reasoncode AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'reasoncode',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_bodysite AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'bodysite',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_outcome AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'outcome',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_complication AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'complication',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_followup AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'followup',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_focaldevice_action AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'focalDevice.action',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__tmp_procedure_usedcode AS
SELECT *
FROM (
    VALUES (
        'procedure',
        'usedcode',
        '',
        '',
        ''
    )
)
    AS t (table_name, column_name, code, display, system);
CREATE TABLE discovery__code_sources AS
--noqa: disable=LTO2,LT09,CV06
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_allergyintolerance_clinicalstatus
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_allergyintolerance_verificationstatus
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_allergyintolerance_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_allergyintolerance_reaction_substance
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_allergyintolerance_reaction_manifestation
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_allergyintolerance_reaction_exposureroute
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_condition_category
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_condition_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_diagnosticreport_category
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_diagnosticreport_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_diagnosticreport_conclusioncode
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_documentreference_type
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_documentreference_category
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_encounter_class
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_encounter_type
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_encounter_servicetype
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_encounter_priority
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_encounter_reasoncode
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_encounter_hospitalization_dischargedisposition
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_location_type
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_medication_codecodeableconcept
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_medication_medicationcode
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_medicationrequest_medicationcodeableconcept
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_observation_category
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_observation_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_observation_component_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_observation_interpretation
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_observation_valuecodeableconcept
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_observation_dataabsentreason
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_organization_type
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_patient_maritalstatus
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_practitioner_qualification_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_practitionerrole_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_practitionerrole_specialty
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_statusreason
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_category
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_code
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_performer_function
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_reasoncode
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_bodysite
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_outcome
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_complication
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_followup
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_focaldevice_action
UNION ALL
SELECT
    table_name,
    column_name,
    code,
    display,
    system
FROM discovery__tmp_procedure_usedcode
;
