diff --git a/db/schema.sql b/db/schema.sql index 877ce65..d04ef2d 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -105,6 +105,7 @@ CREATE TABLE dict.facet__concept_node ( CONSTRAINT fk_facet FOREIGN KEY (FACET_ID) REFERENCES dict.facet(FACET_ID), CONSTRAINT fk_concept_node FOREIGN KEY (CONCEPT_NODE_ID) REFERENCES dict.concept_node(CONCEPT_NODE_ID) ); + CREATE TABLE IF NOT EXISTS dict.dataset_harmonization ( dataset_harmonization_id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY, diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptFilterQueryGenerator.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptFilterQueryGenerator.java index 17438de..663af35 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptFilterQueryGenerator.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptFilterQueryGenerator.java @@ -24,6 +24,15 @@ dataset.dataset_id IN ( WHERE concat(dataset.ref, '.', consent.consent_code) IN (:consents) OR (dataset.ref IN (:consents) AND consent.consent_code = '') + UNION + SELECT + dataset_harmonization.harmonized_dataset_id + FROM consent + JOIN dataset_harmonization ON dataset_harmonization.source_dataset_id = consent.dataset_id + LEFT JOIN dataset ON dataset.dataset_id = dataset_harmonization.source_dataset_id + WHERE + concat(dataset.ref, '.', consent.consent_code) IN (:consents) OR + (dataset.ref IN (:consents) AND consent.consent_code = '') ) AND """; diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetQueryGenerator.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetQueryGenerator.java index ae97630..81eb2a0 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetQueryGenerator.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetQueryGenerator.java @@ -24,6 +24,15 @@ dataset.dataset_id IN ( WHERE concat(dataset.ref, '.', consent.consent_code) IN (:consents) OR (dataset.ref IN (:consents) AND consent.consent_code = '') + UNION + SELECT + dataset_harmonization.harmonized_dataset_id + FROM consent + JOIN dataset_harmonization ON dataset_harmonization.source_dataset_id = consent.dataset_id + LEFT JOIN dataset ON dataset.dataset_id = dataset_harmonization.source_dataset_id + WHERE + concat(dataset.ref, '.', consent.consent_code) IN (:consents) OR + (dataset.ref IN (:consents) AND consent.consent_code = '') ) AND """; diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java index cbaf996..92fb84b 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptRepositoryTest.java @@ -49,7 +49,7 @@ static void mySQLProperties(DynamicPropertyRegistry registry) { void shouldListAllConcepts() { List actual = subject.getConcepts(new Filter(List.of(), "", List.of()), Pageable.unpaged()); - Assertions.assertEquals(29, actual.size()); + Assertions.assertEquals(30, actual.size()); } @Test @@ -115,7 +115,7 @@ void shouldFilterByBothSearchAndFacet() { void shouldGetCount() { long actual = subject.countConcepts(new Filter(List.of(), "", List.of())); - Assertions.assertEquals(29L, actual); + Assertions.assertEquals(30L, actual); } @Test diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/filter/ConceptFilterQueryGeneratorTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/filter/ConceptFilterQueryGeneratorTest.java index c8c732c..ba26ffb 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/filter/ConceptFilterQueryGeneratorTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/filter/ConceptFilterQueryGeneratorTest.java @@ -44,6 +44,17 @@ static void mySQLProperties(DynamicPropertyRegistry registry) { @Autowired NamedParameterJdbcTemplate template; + @Test + void shouldGenerateForHarmonizedConsents() { + Filter filter = new Filter(List.of(), "", List.of("phs001963.c1")); + QueryParamPair pair = subject.generateFilterQuery(filter, Pageable.unpaged()); + + List actual = template.queryForList(pair.query(), pair.params(), Integer.class); + List expected = List.of(270); + + Assertions.assertEquals(expected, actual); + } + @Test void shouldGenerateForFacetAndSearchNoMatch() { Filter f = new Filter(List.of(new Facet("phs000007", "FHS", "", "", null, null, "study_ids_dataset_ids", null)), "smoke", List.of()); diff --git a/src/test/resources/seed.sql b/src/test/resources/seed.sql index fa99555..042a4d7 100644 --- a/src/test/resources/seed.sql +++ b/src/test/resources/seed.sql @@ -395,6 +395,7 @@ COPY public.concept_node (concept_node_id, dataset_id, name, display, concept_ty 267 14 Low coverage WGS Low coverage WGS categorical \\Variant Data Type\\Low coverage WGS\\ 265 'coverag':5,8,11 'data':2 'low':4,7,10 'true':13 'type':3 'variant':1 'wgs':6,9,12 268 14 WES WES categorical \\Variant Data Type\\WES\\ 265 'data':2 'exom':7 'sequenc':8 'true':9 'type':3 'variant':1 'wes':4,5 'whole':6 269 14 WGS WGS categorical \\Variant Data Type\\WGS\\ 265 'data':2 'genom':7 'sequenc':8 'true':9 'type':3 'variant':1 'wgs':4,5 'whole':6 +270 26 harmonized_var harmonized_var continuous \\phs003566\\harmonized_var\\ 263 'ecgsamplebas':5,8 'origin':4,7 'phs003566':1 'visit01':2,3,6 \. @@ -518,6 +519,7 @@ COPY public.concept_node_meta (concept_node_meta_id, concept_node_id, key, value 133 211 values [100, 500] 36 222 values [0, 150] 66 242 values [0, 30] +134 270 values [0, 21] \. @@ -556,6 +558,7 @@ COPY public.dataset (dataset_id, ref, full_name, abbreviation, description) FROM 23 phs002808 Nulliparous Pregnancy Outcomes Study: Monitoring Mothers-to-be Heart Health Study (nuMoM2b Heart Health Study) nuMoM2b 24 phs003566 Systolic Blood Pressure Intervention Trial (SPRINT-Imaging) SPRINT 25 phs001963 DEMENTIA-SEQ: WGS in Lewy Body Dementia and Frontotemporal Dementia DEMENTIA-SEQ +26 harmonized My Cool Harmonized Dataset abv harmony \. @@ -1052,6 +1055,23 @@ ALTER TABLE ONLY public.concept_node ADD CONSTRAINT fk_study FOREIGN KEY (dataset_id) REFERENCES public.dataset(dataset_id); +CREATE TABLE IF NOT EXISTS public.dataset_harmonization +( + dataset_harmonization_id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY, + harmonized_dataset_id INT NOT NULL, + source_dataset_id INT NOT NULL, + UNIQUE (harmonized_dataset_id, source_dataset_id), + CONSTRAINT fk_harmonized_dataset_id FOREIGN KEY (harmonized_dataset_id) REFERENCES public.dataset (dataset_id), + CONSTRAINT fk_source_dataset_id FOREIGN KEY (source_dataset_id) REFERENCES public.dataset (dataset_id) +); + +INSERT INTO public.dataset_harmonization (dataset_harmonization_id, harmonized_dataset_id, source_dataset_id) VALUES + (1, 26, 25), + (1, 26, 24), + (1, 26, 23), + (1, 26, 22); + + -- -- PostgreSQL database dump complete --