Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sikina committed Jul 18, 2024
1 parent 1238ed0 commit 5bab91c
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 2 deletions.
18 changes: 18 additions & 0 deletions no_facets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SELECT
facet.facet_id, count(*) as facet_count
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN concept_node ON concept_node.concept_node_id = fcn.concept_node_id
LEFT JOIN concept_node_meta AS continuous_min ON concept_node.concept_node_id = continuous_min.concept_node_id AND continuous_min.KEY = 'min'
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
continuous_min.value <> '' OR
continuous_max.value <> '' OR
categorical_values.value <> ''
GROUP BY
facet.facet_id
ORDER BY
facet_count DESC
60 changes: 60 additions & 0 deletions one_facet.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(
SELECT
facet.facet_id, count(*) as facet_count
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN concept_node ON concept_node.concept_node_id = fcn.concept_node_id
LEFT JOIN concept_node_meta AS continuous_min ON concept_node.concept_node_id = continuous_min.concept_node_id AND continuous_min.KEY = 'min'
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
fc.name = 'study_ids_dataset_ids'
AND (
continuous_min.value <> '' OR
continuous_max.value <> '' OR
categorical_values.value <> ''
)
GROUP BY
facet.facet_id
ORDER BY
facet_count DESC
)
UNION
(
WITH matching_concepts AS (
SELECT
concept_node.concept_node_id AS concept_node_id
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN concept_node ON concept_node.concept_node_id = fcn.concept_node_id
LEFT JOIN concept_node_meta AS continuous_min ON concept_node.concept_node_id = continuous_min.concept_node_id AND continuous_min.KEY = 'min'
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
fc.name = 'study_ids_dataset_ids'
AND facet.name IN ('phs000007')
AND (
continuous_min.value <> '' OR
continuous_max.value <> '' OR
categorical_values.value <> ''
)
)
SELECT
facet.facet_id, count(*) as facet_count
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN matching_concepts ON fcn.concept_node_id = matching_concepts.concept_node_id
WHERE
fc.name <> 'study_ids_dataset_ids'
GROUP BY
facet.facet_id
ORDER BY
facet_count DESC
)

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class FacetQueryGeneratorTest {
@Autowired
FacetQueryGenerator generator;

// {"facets":[{"name":"LOINC","display":"LOINC","description":null,"count":1,"children":null,"category":"nsrr_harmonized","meta":null,"categoryRef":{"display":"Common Data Element Collection","name":"nsrr_harmonized","description":""}},{"name":"phs000007","display":"FHS","description":null,"count":1,"children":null,"category":"study_ids_dataset_ids","meta":null,"categoryRef":{"display":"Study IDs/Dataset IDs","name":"study_ids_dataset_ids","description":""}}],"search":""}

@Test
void shouldaaa() {
Filter jim = new Filter(List.of(
Expand All @@ -26,8 +28,9 @@ void shouldaaa() {
System.out.println(query);
}


@Test
void shouldaaa2() {
void shouldaa() {
Filter jim = new Filter(List.of(
new Facet("phs000007", "", "", null, null, "study_ids_dataset_ids", null)
), "");
Expand All @@ -36,7 +39,7 @@ void shouldaaa2() {
}

@Test
void shoudlbrungus() {
void shoulda() {
Filter jim = new Filter(List.of(), "");
String query = generator.createFacetSQLAndPopulateParams(jim, new MapSqlParameterSource());
System.out.println(query);
Expand Down
87 changes: 87 additions & 0 deletions two_cats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
WITH facet_category_cat_0_concepts AS (
SELECT
concept_node.concept_node_id
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN concept_node ON concept_node.concept_node_id = fcn.concept_node_id
LEFT JOIN concept_node_meta AS continuous_min ON concept_node.concept_node_id = continuous_min.concept_node_id AND continuous_min.KEY = 'min'
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
(fc.name, facet.name) IN (('nsrr_harmonized', 'LOINC'))
AND (
continuous_min.value <> '' OR
continuous_max.value <> '' OR
categorical_values.value <> ''
)
)
,
facet_category_cat_1_concepts AS (
SELECT
concept_node.concept_node_id
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN concept_node ON concept_node.concept_node_id = fcn.concept_node_id
LEFT JOIN concept_node_meta AS continuous_min ON concept_node.concept_node_id = continuous_min.concept_node_id AND continuous_min.KEY = 'min'
LEFT JOIN concept_node_meta AS continuous_max ON concept_node.concept_node_id = continuous_max.concept_node_id AND continuous_max.KEY = 'max'
LEFT JOIN concept_node_meta AS categorical_values ON concept_node.concept_node_id = categorical_values.concept_node_id AND categorical_values.KEY = 'values'
WHERE
(fc.name, facet.name) IN (('study_ids_dataset_ids', 'phs000007'))
AND (
continuous_min.value <> '' OR
continuous_max.value <> '' OR
categorical_values.value <> ''
)
)
(
SELECT
facet.facet_id, count(*) as facet_count
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
WHERE
fcn.concept_node_id IN (SELECT * FROM facet_category_cat_1_concepts)
AND fc.name = 'study_ids_dataset_ids'
GROUP BY
facet.facet_id
ORDER BY
facet_count DESC
)

UNION
(
SELECT
facet.facet_id, count(*) as facet_count
FROM
facet
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
WHERE
fcn.concept_node_id IN (SELECT * FROM facet_category_cat_0_concepts)
AND fc.name = 'nsrr_harmonized'
GROUP BY
facet.facet_id
ORDER BY
facet_count DESC
)
UNION
(
SELECT
facet.facet_id, count(*) as facet_count
FROM
facet
JOIN facet_category fc on fc.facet_category_id = facet.facet_category_id
JOIN facet__concept_node fcn ON fcn.facet_id = facet.facet_id
WHERE
fc.name NOT IN ('nsrr_harmonized', 'study_ids_dataset_ids')
AND fcn.concept_node_id IN (SELECT * FROM facet_category_cat_0_concepts UNION SELECT * FROM facet_category_cat_1_concepts)
GROUP BY
facet.facet_id
ORDER BY
facet_count DESC
)

0 comments on commit 5bab91c

Please sign in to comment.