Skip to content

Commit 7e8ea8e

Browse files
committed
[DC-1022] Fixes failing integration test.
Adds creating concept_ancestor_extension table in main_test.py Signed-off-by: Krishna Kalluri <[email protected]>
1 parent ed0a93c commit 7e8ea8e

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

data_steward/common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Python imports
22
import os
33

4+
import jinja2
5+
46
# Project imports
57
from constants.bq_utils import VALIDATION_DATASET_REGEX
68
from constants.validation.participants.identity_match import REPORT_DIRECTORY_REGEX
7-
import jinja2
89

910
# AOU required PII tables
1011
PII_WILDCARD = 'pii*'
@@ -112,6 +113,9 @@
112113
CONCEPT, CONCEPT_ANCESTOR, CONCEPT_CLASS, CONCEPT_RELATIONSHIP,
113114
CONCEPT_SYNONYM, DOMAIN, DRUG_STRENGTH, RELATIONSHIP, VOCABULARY
114115
]
116+
117+
CONCEPT_ANCESTOR_EXTENSION = 'concept_ancestor_extension'
118+
115119
# Achilles
116120
ACHILLES_ANALYSIS = 'achilles_analysis'
117121
ACHILLES_RESULTS = 'achilles_results'

data_steward/tools/generate_concept_ancestor_extension.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
import argparse
1717
import logging
1818

19+
from common import CONCEPT_ANCESTOR_EXTENSION
1920
from utils import bq
2021

2122
LOGGER = logging.getLogger(__name__)
2223

23-
CONCEPT_ANCESTOR_EXTENSION = 'concept_ancestor_extension'
24-
2524
CONCEPT_ANCESTOR_EXT_QUERY = '''
2625
DECLARE
2726
num_of_new_records INT64;
@@ -43,14 +42,14 @@
4342
c.vocabulary_id = 'LOINC'
4443
AND domain_id = 'Measurement' ) AS loinc_ids
4544
JOIN
46-
`ehr_ops.concept_relationship` AS cr
45+
`{project}.{dataset}.concept_relationship` AS cr
4746
ON
4847
loinc_ids.ancestor_concept_id = cr.concept_id_1
4948
AND relationship_id IN ('Subsumes',
5049
'Component of')
5150
AND cr.concept_id_1 <> cr.concept_id_2
5251
JOIN
53-
`ehr_ops.concept` AS c2
52+
`{project}.{dataset}.concept` AS c2
5453
ON
5554
cr.concept_id_2 = c2.concept_id
5655
AND c2.domain_id = 'Measurement' );
@@ -113,7 +112,7 @@
113112
END LOOP
114113
;
115114
CREATE OR REPLACE TABLE
116-
ehr_ops.concept_ancestor_extension AS
115+
`{project}.{dataset}.{ancestor_extension}` AS
117116
SELECT
118117
ancestor_concept_id,
119118
descendant_concept_id,

data_steward/validation/metrics/required_labs_sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
SELECT
2828
*
2929
FROM
30-
`{project_id}.{vocab_dataset_id}.concept_ancestor_extension`
31-
)
30+
`{project_id}.{ehr_ops_dataset_id}.concept_ancestor_extension`
31+
),
3232
3333
get_direct_parents_loinc_group AS
3434
(

tests/integration_tests/data_steward/validation/main_test.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Unit test components of data_steward.validation.main
33
"""
44
from __future__ import print_function
5+
56
import json
67
import os
78
import unittest
@@ -10,14 +11,15 @@
1011
import mock
1112
from bs4 import BeautifulSoup as bs
1213

13-
import bq_utils
1414
import app_identity
15+
import bq_utils
1516
import common
16-
from constants import bq_utils as bq_consts
17-
from constants.validation import main as main_consts
1817
import gcs_utils
1918
import resources
19+
from constants import bq_utils as bq_consts
20+
from constants.validation import main as main_consts
2021
from tests import test_util
22+
from tools.generate_concept_ancestor_extension import generate_concept_ancestor_extension
2123
from validation import main
2224
from validation.metrics import required_labs
2325

@@ -46,12 +48,19 @@ def setUp(self):
4648
self._empty_bucket()
4749
test_util.delete_all_tables(self.bigquery_dataset_id)
4850
self._create_drug_class_table(self.bigquery_dataset_id)
51+
self._create_concept_ancestor_extension(self.project_id,
52+
self.bigquery_dataset_id)
4953

5054
def _empty_bucket(self):
5155
bucket_items = gcs_utils.list_bucket(self.hpo_bucket)
5256
for bucket_item in bucket_items:
5357
gcs_utils.delete_object(self.hpo_bucket, bucket_item['name'])
5458

59+
@staticmethod
60+
def _create_concept_ancestor_extension(project_id, dataset_id):
61+
if not bq_utils.table_exists(common.CONCEPT_ANCESTOR_EXTENSION):
62+
generate_concept_ancestor_extension(project_id, dataset_id)
63+
5564
@staticmethod
5665
def _create_drug_class_table(bigquery_dataset_id):
5766

@@ -86,7 +95,7 @@ def _create_drug_class_table(bigquery_dataset_id):
8695
if not bq_utils.table_exists(common.CONCEPT_ANCESTOR):
8796
bq_utils.create_standard_table(common.CONCEPT_ANCESTOR,
8897
common.CONCEPT_ANCESTOR)
89-
q = """INSERT INTO {dataset}.concept_ancestor
98+
q = """INSERT INTO {dataset}.concept_ancestor
9099
SELECT * FROM {vocab}.concept_ancestor""".format(
91100
dataset=bigquery_dataset_id, vocab=common.VOCABULARY_DATASET)
92101
bq_utils.query(q)

0 commit comments

Comments
 (0)