Skip to content

Commit

Permalink
[ALS-7466] Harmony among consents
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Oct 1, 2024
1 parent 9d0a770 commit 070c0cd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void mySQLProperties(DynamicPropertyRegistry registry) {
void shouldListAllConcepts() {
List<Concept> actual = subject.getConcepts(new Filter(List.of(), "", List.of()), Pageable.unpaged());

Assertions.assertEquals(29, actual.size());
Assertions.assertEquals(30, actual.size());
}

@Test
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> actual = template.queryForList(pair.query(), pair.params(), Integer.class);
List<Integer> 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());
Expand Down
20 changes: 20 additions & 0 deletions src/test/resources/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
\.


Expand Down Expand Up @@ -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]
\.


Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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
--
Expand Down

0 comments on commit 070c0cd

Please sign in to comment.