diff --git a/cumulus_library/.sqlfluff b/cumulus_library/.sqlfluff index 460d1cc2..676cdc68 100644 --- a/cumulus_library/.sqlfluff +++ b/cumulus_library/.sqlfluff @@ -55,6 +55,7 @@ source_id = source_id table_cols = ["a","b"] table_cols_types = ["varchar", "varchar"] table_name = test_table +table_names = ["test_table"] table_suffix = 2024_01_01_11_11_11 target_col_prefix = prefix target_table = target_table diff --git a/cumulus_library/template_sql/base_templates.py b/cumulus_library/template_sql/base_templates.py index 5e4dc251..331ce42c 100644 --- a/cumulus_library/template_sql/base_templates.py +++ b/cumulus_library/template_sql/base_templates.py @@ -90,20 +90,19 @@ def get_codeable_concept_denormalize_query( ) -# TODO: change test of table_name to plural def get_column_datatype_query( schema_name: str, - table_name: str | list, + table_names: str | list, column_names: list | None = None, include_table_names: bool | None = False, ): """Gets the in-database data representation of a given column""" - if isinstance(table_name, str): - table_name = [table_name] + if isinstance(table_names, str): + table_names = [table_names] return get_base_template( "column_datatype", schema_name=schema_name, - table_name=table_name, + table_names=table_names, column_names=column_names, include_table_names=include_table_names, ) diff --git a/cumulus_library/template_sql/column_datatype.sql.jinja b/cumulus_library/template_sql/column_datatype.sql.jinja index 2b0e855a..837b0b51 100644 --- a/cumulus_library/template_sql/column_datatype.sql.jinja +++ b/cumulus_library/template_sql/column_datatype.sql.jinja @@ -1,13 +1,13 @@ SELECT {%- if include_table_names %} table_name, - {% endif %} + {%- endif %} column_name, data_type FROM information_schema.columns WHERE table_schema = '{{ schema_name }}' - AND table_name IN ('{{ table_name|join("', '")|lower }}') - {%- if column_names %} - AND LOWER(column_name) IN ('{{ column_names|join("', '")|lower }}') --noqa: LT05 - {% endif %} + AND table_name IN ('{{ table_names|join("', '")|lower }}') +{%- if column_names %} +AND LOWER(column_name) IN ('{{ column_names|join("', '")|lower }}') --noqa: LT05 +{%- endif %} diff --git a/tests/test_data/core/core__observation.txt b/tests/test_data/core/core__observation.txt index f3d1267e..e8d545e4 100644 --- a/tests/test_data/core/core__observation.txt +++ b/tests/test_data/core/core__observation.txt @@ -1,20 +1,20 @@ -('05e6184c-f3ef-017b-ce21-599d375020b3', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 6, 2), datetime.date(2018, 5, 28), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/8877ef1f-7cd7-3242-d7f0-73cf3f7165f4', 'Encounter/299b6495-3fe7-8db3-c494-6e1ce8b7986d', 'Observation/05e6184c-f3ef-017b-ce21-599d375020b3') -('0935feb5-36bc-6a6c-7969-841bacbabdfe', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 11), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/5ce2e599-fb6e-9b4d-3c2e-87310619b957', 'Encounter/4b03a408-6694-88e3-0e63-3ee464ecd6cd', 'Observation/0935feb5-36bc-6a6c-7969-841bacbabdfe') -('0d35c92c-8982-9737-2bae-79789514fde8', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 2), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/17fde357-dcc9-af8b-a8d3-4bd213afeb22', 'Encounter/32d0ae2d-1be8-9e90-a4da-4c222abd88a9', 'Observation/0d35c92c-8982-9737-2bae-79789514fde8') -('29a5c64c-9973-93d2-24a2-b2bcea3bdf4b', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 13), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/9eaa056b-1efc-0cc8-70ff-62c8f704cc13', 'Encounter/5c994000-aa78-2be5-e6cf-99f230d50c2f', 'Observation/29a5c64c-9973-93d2-24a2-b2bcea3bdf4b') -('34347a5f-a90a-f723-8121-919ca5364b7c', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 6, 14), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/267fc42d-cd9e-8527-1f9e-887fe7776147', 'Encounter/4c4d0730-201f-5b75-c657-8d0de09cc28f', 'Observation/34347a5f-a90a-f723-8121-919ca5364b7c') -('5ba3f97b-8ecc-0b87-bee1-abeffa7580b7', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 6, 14), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/267fc42d-cd9e-8527-1f9e-887fe7776147', 'Encounter/4c4d0730-201f-5b75-c657-8d0de09cc28f', 'Observation/5ba3f97b-8ecc-0b87-bee1-abeffa7580b7') -('701e9048-be5f-5b42-b582-97d1ff465438', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 15), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/c1bfec36-dc2c-afc8-c767-3d35ed2bf6f0', 'Encounter/8ff1dc01-5a28-b2d8-3b42-4b7a7d539970', 'Observation/701e9048-be5f-5b42-b582-97d1ff465438') -('84d65045-3a6e-5968-c35b-001d125b26d2', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 6, 13), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/3cf7af45-2bee-aa9c-d524-40b487149d60', 'Encounter/d2782687-6885-037c-957d-579fbd681d2a', 'Observation/84d65045-3a6e-5968-c35b-001d125b26d2') -('8930d451-d73c-5360-4b65-a8f9fdb43eae', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 6, 2), datetime.date(2018, 5, 28), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/8877ef1f-7cd7-3242-d7f0-73cf3f7165f4', 'Encounter/299b6495-3fe7-8db3-c494-6e1ce8b7986d', 'Observation/8930d451-d73c-5360-4b65-a8f9fdb43eae') -('8cc39753-79b9-2be9-77a7-157ca24ad5cf', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 6, 13), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/3cf7af45-2bee-aa9c-d524-40b487149d60', 'Encounter/d2782687-6885-037c-957d-579fbd681d2a', 'Observation/8cc39753-79b9-2be9-77a7-157ca24ad5cf') -('916b97ca-fb5f-71ce-0cff-70383a1aa668', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 9), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/e455ca3f-fc16-6ffc-297a-adc27e2db183', 'Encounter/98d4bd14-d78e-debb-e7dc-2df7786aedf3', 'Observation/916b97ca-fb5f-71ce-0cff-70383a1aa668') -('93b68c85-7046-025d-19a1-bffd42469601', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 7), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/ac91b90d-97e4-4fc5-41cd-036bac49e6e8', 'Encounter/dc5ed645-3979-e765-3e03-6ba2173027c3', 'Observation/93b68c85-7046-025d-19a1-bffd42469601') -('b1467052-96e1-a697-fd94-feffb6e1453b', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 10), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/b1467052-96e1-a697-fd94-feffb6e1453b') -('bc4dafcf-05ad-9b01-049b-f9c75bd8d53f', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 7), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/ac91b90d-97e4-4fc5-41cd-036bac49e6e8', 'Encounter/dc5ed645-3979-e765-3e03-6ba2173027c3', 'Observation/bc4dafcf-05ad-9b01-049b-f9c75bd8d53f') -('bdcea012-7a9a-193f-eb45-80dbceca6095', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 9), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/e455ca3f-fc16-6ffc-297a-adc27e2db183', 'Encounter/98d4bd14-d78e-debb-e7dc-2df7786aedf3', 'Observation/bdcea012-7a9a-193f-eb45-80dbceca6095') -('c62885ce-5f40-32a4-d8f6-ae945824b172', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 15), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/c1bfec36-dc2c-afc8-c767-3d35ed2bf6f0', 'Encounter/8ff1dc01-5a28-b2d8-3b42-4b7a7d539970', 'Observation/c62885ce-5f40-32a4-d8f6-ae945824b172') -('c802cfaf-6b9e-36fb-c7b1-1836cbc4f653', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 10), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/c802cfaf-6b9e-36fb-c7b1-1836cbc4f653') -('d9871961-3f7a-7cf7-0ced-460368db48e0', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 2), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/17fde357-dcc9-af8b-a8d3-4bd213afeb22', 'Encounter/32d0ae2d-1be8-9e90-a4da-4c222abd88a9', 'Observation/d9871961-3f7a-7cf7-0ced-460368db48e0') -('e47346a6-9fb7-bc9b-b8bb-006bfeebbd02', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '5778-6', 'http://loinc.org', None, None, None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 13), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/9eaa056b-1efc-0cc8-70ff-62c8f704cc13', 'Encounter/5c994000-aa78-2be5-e6cf-99f230d50c2f', 'Observation/e47346a6-9fb7-bc9b-b8bb-006bfeebbd02') -('efe12fc4-932e-90ab-05d5-05169bd815b1', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', None, 'final', '34533-0', 'http://loinc.org', None, None, None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 11), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/5ce2e599-fb6e-9b4d-3c2e-87310619b957', 'Encounter/4b03a408-6694-88e3-0e63-3ee464ecd6cd', 'Observation/efe12fc4-932e-90ab-05d5-05169bd815b1') +('05e6184c-f3ef-017b-ce21-599d375020b3', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 6, 2), datetime.date(2018, 5, 28), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/8877ef1f-7cd7-3242-d7f0-73cf3f7165f4', 'Encounter/299b6495-3fe7-8db3-c494-6e1ce8b7986d', 'Observation/05e6184c-f3ef-017b-ce21-599d375020b3') +('0935feb5-36bc-6a6c-7969-841bacbabdfe', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 11), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/5ce2e599-fb6e-9b4d-3c2e-87310619b957', 'Encounter/4b03a408-6694-88e3-0e63-3ee464ecd6cd', 'Observation/0935feb5-36bc-6a6c-7969-841bacbabdfe') +('0d35c92c-8982-9737-2bae-79789514fde8', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 2), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/17fde357-dcc9-af8b-a8d3-4bd213afeb22', 'Encounter/32d0ae2d-1be8-9e90-a4da-4c222abd88a9', 'Observation/0d35c92c-8982-9737-2bae-79789514fde8') +('29a5c64c-9973-93d2-24a2-b2bcea3bdf4b', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 13), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/9eaa056b-1efc-0cc8-70ff-62c8f704cc13', 'Encounter/5c994000-aa78-2be5-e6cf-99f230d50c2f', 'Observation/29a5c64c-9973-93d2-24a2-b2bcea3bdf4b') +('34347a5f-a90a-f723-8121-919ca5364b7c', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 6, 14), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/267fc42d-cd9e-8527-1f9e-887fe7776147', 'Encounter/4c4d0730-201f-5b75-c657-8d0de09cc28f', 'Observation/34347a5f-a90a-f723-8121-919ca5364b7c') +('5ba3f97b-8ecc-0b87-bee1-abeffa7580b7', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 6, 14), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/267fc42d-cd9e-8527-1f9e-887fe7776147', 'Encounter/4c4d0730-201f-5b75-c657-8d0de09cc28f', 'Observation/5ba3f97b-8ecc-0b87-bee1-abeffa7580b7') +('701e9048-be5f-5b42-b582-97d1ff465438', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 15), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/c1bfec36-dc2c-afc8-c767-3d35ed2bf6f0', 'Encounter/8ff1dc01-5a28-b2d8-3b42-4b7a7d539970', 'Observation/701e9048-be5f-5b42-b582-97d1ff465438') +('84d65045-3a6e-5968-c35b-001d125b26d2', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 6, 13), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/3cf7af45-2bee-aa9c-d524-40b487149d60', 'Encounter/d2782687-6885-037c-957d-579fbd681d2a', 'Observation/84d65045-3a6e-5968-c35b-001d125b26d2') +('8930d451-d73c-5360-4b65-a8f9fdb43eae', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 6, 2), datetime.date(2018, 5, 28), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/8877ef1f-7cd7-3242-d7f0-73cf3f7165f4', 'Encounter/299b6495-3fe7-8db3-c494-6e1ce8b7986d', 'Observation/8930d451-d73c-5360-4b65-a8f9fdb43eae') +('8cc39753-79b9-2be9-77a7-157ca24ad5cf', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 6, 13), datetime.date(2018, 6, 11), datetime.date(2018, 6, 1), datetime.date(2018, 1, 1), 'Patient/3cf7af45-2bee-aa9c-d524-40b487149d60', 'Encounter/d2782687-6885-037c-957d-579fbd681d2a', 'Observation/8cc39753-79b9-2be9-77a7-157ca24ad5cf') +('916b97ca-fb5f-71ce-0cff-70383a1aa668', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 9), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/e455ca3f-fc16-6ffc-297a-adc27e2db183', 'Encounter/98d4bd14-d78e-debb-e7dc-2df7786aedf3', 'Observation/916b97ca-fb5f-71ce-0cff-70383a1aa668') +('93b68c85-7046-025d-19a1-bffd42469601', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 7), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/ac91b90d-97e4-4fc5-41cd-036bac49e6e8', 'Encounter/dc5ed645-3979-e765-3e03-6ba2173027c3', 'Observation/93b68c85-7046-025d-19a1-bffd42469601') +('b1467052-96e1-a697-fd94-feffb6e1453b', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 10), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/b1467052-96e1-a697-fd94-feffb6e1453b') +('bc4dafcf-05ad-9b01-049b-f9c75bd8d53f', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 7), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/ac91b90d-97e4-4fc5-41cd-036bac49e6e8', 'Encounter/dc5ed645-3979-e765-3e03-6ba2173027c3', 'Observation/bc4dafcf-05ad-9b01-049b-f9c75bd8d53f') +('bdcea012-7a9a-193f-eb45-80dbceca6095', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 9), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/e455ca3f-fc16-6ffc-297a-adc27e2db183', 'Encounter/98d4bd14-d78e-debb-e7dc-2df7786aedf3', 'Observation/bdcea012-7a9a-193f-eb45-80dbceca6095') +('c62885ce-5f40-32a4-d8f6-ae945824b172', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 15), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/c1bfec36-dc2c-afc8-c767-3d35ed2bf6f0', 'Encounter/8ff1dc01-5a28-b2d8-3b42-4b7a7d539970', 'Observation/c62885ce-5f40-32a4-d8f6-ae945824b172') +('c802cfaf-6b9e-36fb-c7b1-1836cbc4f653', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 10), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/6385ddd7-2639-6505-3789-0521b8f66c8b', 'Encounter/fd0754a4-e96d-cba7-b3c0-77697a09c86e', 'Observation/c802cfaf-6b9e-36fb-c7b1-1836cbc4f653') +('d9871961-3f7a-7cf7-0ced-460368db48e0', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 2), datetime.date(2018, 7, 2), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/17fde357-dcc9-af8b-a8d3-4bd213afeb22', 'Encounter/32d0ae2d-1be8-9e90-a4da-4c222abd88a9', 'Observation/d9871961-3f7a-7cf7-0ced-460368db48e0') +('e47346a6-9fb7-bc9b-b8bb-006bfeebbd02', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '5778-6', 'http://loinc.org', None, None, None, '371254008', 'http://snomed.info/sct', 'Brown color (qualifier value)', datetime.date(2018, 7, 13), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/9eaa056b-1efc-0cc8-70ff-62c8f704cc13', 'Encounter/5c994000-aa78-2be5-e6cf-99f230d50c2f', 'Observation/e47346a6-9fb7-bc9b-b8bb-006bfeebbd02') +('efe12fc4-932e-90ab-05d5-05169bd815b1', 'laboratory', 'http://terminology.hl7.org/CodeSystem/observation-category', 'final', '34533-0', 'http://loinc.org', None, None, None, '167248002', 'http://snomed.info/sct', 'Urine smell ammoniacal (finding)', datetime.date(2018, 7, 11), datetime.date(2018, 7, 9), datetime.date(2018, 7, 1), datetime.date(2018, 1, 1), 'Patient/5ce2e599-fb6e-9b4d-3c2e-87310619b957', 'Encounter/4b03a408-6694-88e3-0e63-3ee464ecd6cd', 'Observation/efe12fc4-932e-90ab-05d5-05169bd815b1') diff --git a/tests/test_templates.py b/tests/test_templates.py index 571636c2..8f9d3ce4 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -164,13 +164,28 @@ def test_get_column_datatype_query(): FROM information_schema.columns WHERE table_schema = 'schema_name' - AND table_name = 'table_name' - AND LOWER(column_name) IN ('foo', 'bar') --noqa: LT05""" + AND table_name IN ('table_name')""" query = base_templates.get_column_datatype_query( schema_name="schema_name", - table_name="TABLE_NAME", + table_names="TABLE_NAME", + ) + assert query == expected + expected = """SELECT + table_name, + column_name, + data_type +FROM information_schema.columns +WHERE + table_schema = 'schema_name' + AND table_name IN ('table_name') +AND LOWER(column_name) IN ('foo', 'bar') --noqa: LT05""" + + query = base_templates.get_column_datatype_query( + schema_name="schema_name", + table_names="TABLE_NAME", column_names=["foo", "BAR"], + include_table_names=True, ) assert query == expected