Skip to content

Commit

Permalink
Add survey criteria
Browse files Browse the repository at this point in the history
* Loads all survey data for real time filtering.
* Improves question/answer name handling, though indexing changes will
  be needed to handle global search correctly.
* Multi-select plus instance level data still to be dealt with.
* Config changes will come separately since they'll break stored data.
* Filter generation shares code with existing entity group criteria.
* Copies some filter generation code from entity group criteria but this
  allows the config and selection data to be distinct from entity group
  criteria.  There is already some divergence and this allows them to
  evolve separately. This wasn't originally planned but handling
  backwards compatability while switching to a new
  plugin/config/selection data seemed pretty sketchy.
* Fixes a bug where entity group criteria with modifiers but no
  selection weren't handled correctly.
* Testing is weird because we don't currently have survey data. The
  basics are the same as entity group criteria so using the same data
  for now but TBD how we want to handle this.
  • Loading branch information
tjennison-work committed Sep 12, 2024
1 parent 6ce84d8 commit 1c58d1e
Show file tree
Hide file tree
Showing 21 changed files with 1,734 additions and 461 deletions.
174 changes: 151 additions & 23 deletions docs/generated/PROTOCOL_BUFFERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

## Table of Contents

- [column.proto](#column-proto)
- [Column](#tanagra-Column)

- [criteriaselector/configschema/attribute.proto](#criteriaselector_configschema_attribute-proto)
- [Attribute](#tanagra-configschema-Attribute)

Expand All @@ -11,7 +14,6 @@

- [criteriaselector/configschema/entity_group.proto](#criteriaselector_configschema_entity_group-proto)
- [EntityGroup](#tanagra-configschema-EntityGroup)
- [EntityGroup.Column](#tanagra-configschema-EntityGroup-Column)
- [EntityGroup.EntityGroupConfig](#tanagra-configschema-EntityGroup-EntityGroupConfig)

- [criteriaselector/configschema/multi_attribute.proto](#criteriaselector_configschema_multi_attribute-proto)
Expand All @@ -20,6 +22,10 @@
- [criteriaselector/configschema/output_unfiltered.proto](#criteriaselector_configschema_output_unfiltered-proto)
- [OutputUnfiltered](#tanagra-configschema-OutputUnfiltered)

- [criteriaselector/configschema/survey.proto](#criteriaselector_configschema_survey-proto)
- [Survey](#tanagra-configschema-Survey)
- [Survey.EntityGroupConfig](#tanagra-configschema-Survey-EntityGroupConfig)

- [criteriaselector/configschema/text_search.proto](#criteriaselector_configschema_text_search-proto)
- [TextSearch](#tanagra-configschema-TextSearch)

Expand Down Expand Up @@ -50,6 +56,10 @@
- [criteriaselector/dataschema/output_unfiltered.proto](#criteriaselector_dataschema_output_unfiltered-proto)
- [OutputUnfiltered](#tanagra-dataschema-OutputUnfiltered)

- [criteriaselector/dataschema/survey.proto](#criteriaselector_dataschema_survey-proto)
- [Survey](#tanagra-dataschema-Survey)
- [Survey.Selection](#tanagra-dataschema-Survey-Selection)

- [criteriaselector/dataschema/text_search.proto](#criteriaselector_dataschema_text_search-proto)
- [TextSearch](#tanagra-dataschema-TextSearch)
- [TextSearch.Selection](#tanagra-dataschema-TextSearch-Selection)
Expand Down Expand Up @@ -93,6 +103,42 @@



<a name="column-proto"></a>
<p align="right"><a href="#top">Top</a></p>

## column.proto



<a name="tanagra-Column"></a>

### Column
Defines a column in the UI.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [string](#string) | | A unique key for the column. By default, used to look up attributes in the displayed data. |
| width_string | [string](#string) | | Passed directly to the style of the column. &#34;100%&#34; can be used to take up space remaining after laying out fixed columns. |
| width_double | [double](#double) | | Units used by the UI library to standardize dimensions. |
| title | [string](#string) | | The visible title of the column. |
| sortable | [bool](#bool) | | Whether the column supports sorting. |
| filterable | [bool](#bool) | | Whether the column supports filtering. |















<a name="criteriaselector_configschema_attribute-proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down Expand Up @@ -176,8 +222,8 @@ which have condition_name of &#34;Diabetes&#34;).

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| columns | [EntityGroup.Column](#tanagra-configschema-EntityGroup-Column) | repeated | Columns displayed in the list view. |
| hierarchy_columns | [EntityGroup.Column](#tanagra-configschema-EntityGroup-Column) | repeated | Columns displayed in the hierarchy view. |
| columns | [tanagra.Column](#tanagra-Column) | repeated | Columns displayed in the list view. |
| hierarchy_columns | [tanagra.Column](#tanagra-Column) | repeated | Columns displayed in the hierarchy view. |
| name_column_index | [int32](#int32) | | This has been replaced by nameAttribute for determining stored names. Now this only determines which is the primary column for checkboxes, etc. |
| classification_entity_groups | [EntityGroup.EntityGroupConfig](#tanagra-configschema-EntityGroup-EntityGroupConfig) | repeated | Entity groups where the related entity is what is selected (e.g. condition when filtering condition_occurrences). |
| grouping_entity_groups | [EntityGroup.EntityGroupConfig](#tanagra-configschema-EntityGroup-EntityGroupConfig) | repeated | Entity groups where the related entity is not what is selected (e.g. brands when filtering ingredients or genotyping platforms when filtering people). |
Expand All @@ -192,26 +238,6 @@ which have condition_name of &#34;Diabetes&#34;).



<a name="tanagra-configschema-EntityGroup-Column"></a>

### EntityGroup.Column
Defines a column in the UI.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [string](#string) | | A unique key for the column. By default, used to look up attributes in the displayed data. |
| width_string | [string](#string) | | Passed directly to the style of the column. &#34;100%&#34; can be used to take up space remaining after laying out fixed columns. |
| width_double | [double](#double) | | Units used by the UI library to standardize dimensions. |
| title | [string](#string) | | The visible title of the column. |
| sortable | [bool](#bool) | | Whether the column supports sorting. |
| filterable | [bool](#bool) | | Whether the column supports filtering. |






<a name="tanagra-configschema-EntityGroup-EntityGroupConfig"></a>

### EntityGroup.EntityGroupConfig
Expand Down Expand Up @@ -307,6 +333,57 @@ include entire entities (e.g. demographics).



<a name="criteriaselector_configschema_survey-proto"></a>
<p align="right"><a href="#top">Top</a></p>

## criteriaselector/configschema/survey.proto



<a name="tanagra-configschema-Survey"></a>

### Survey



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| columns | [tanagra.Column](#tanagra-Column) | repeated | Columns displayed in the list view. |
| entity_groups | [Survey.EntityGroupConfig](#tanagra-configschema-Survey-EntityGroupConfig) | repeated | Entity groups where the related entity is what is selected (e.g. surveyBasics when filtering surveyOccurrence). |
| value_configs | [tanagra.ValueConfig](#tanagra-ValueConfig) | repeated | Optional configuration of a categorical or numeric value associated with the selection (e.g. a numeric answer). Applied to the entire selection so generally not compatible with multi_select. Currently only one is supported. |
| default_sort | [tanagra.SortOrder](#tanagra-SortOrder) | | The sort order to use in the list view, or in hierarchies where no sort order has been specified. |
| nameAttribute | [string](#string) | optional | The attribute used to name selections if not the first column. This can be used to include extra context with the selected values that&#39;s not visible in the table view. |






<a name="tanagra-configschema-Survey-EntityGroupConfig"></a>

### Survey.EntityGroupConfig



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id | [string](#string) | | The id of the entity group. |
| sort_order | [tanagra.SortOrder](#tanagra-SortOrder) | | The sort order applied to this entity group when displayed in the hierarchy view. |















<a name="criteriaselector_configschema_text_search-proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down Expand Up @@ -644,6 +721,57 @@ values.



<a name="criteriaselector_dataschema_survey-proto"></a>
<p align="right"><a href="#top">Top</a></p>

## criteriaselector/dataschema/survey.proto



<a name="tanagra-dataschema-Survey"></a>

### Survey
Data for an entity group criteria is a list of selected values.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| selected | [Survey.Selection](#tanagra-dataschema-Survey-Selection) | repeated | |
| value_data | [tanagra.ValueData](#tanagra-ValueData) | | Data for an additional categorical or numeric value associated with the selection (e.g. a numeric answer). |






<a name="tanagra-dataschema-Survey-Selection"></a>

### Survey.Selection



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| key | [tanagra.Key](#tanagra-Key) | | The key of the selected value, which references a related entity (e.g. surveyBasics when filtering surveyOccurrence). |
| name | [string](#string) | | The visible name for the selection. This is stored to avoid extra lookups when rendering. |
| entityGroup | [string](#string) | | The entity group is stored to differentiate between them when multiple are configured within a single criteria. |
| question_key | [tanagra.Key](#tanagra-Key) | | If the selected item is an answer, the key of the question it belongs to. |
| question_name | [string](#string) | | If the selected item is an answer, the visible name of the question it belongs to. |















<a name="criteriaselector_dataschema_text_search-proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down
5 changes: 5 additions & 0 deletions docs/generated/UNDERLAY_CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ Use `plugin: "multiAttribute"`.

Use `plugin: "outputUnfiltered"`.

### SZCorePlugin.SURVEY
**required** [SZCorePlugin](#szcoreplugin)

Use `plugin: "survey"`.

### SZCorePlugin.TEXT_SEARCH
**required** [SZCorePlugin](#szcoreplugin)

Expand Down
25 changes: 20 additions & 5 deletions ui/src/components/treegrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Typography from "@mui/material/Typography";
import produce from "immer";
import { GridBox } from "layout/gridBox";
import GridLayout from "layout/gridLayout";
import * as columnProto from "proto/column";
import {
ChangeEvent,
MutableRefObject,
Expand Down Expand Up @@ -49,8 +50,8 @@ export type TreeGridItem = {
data: TreeGridRowData;
};

export type TreeGridData = {
[key: TreeGridId]: TreeGridItem;
export type TreeGridData<ItemType extends TreeGridItem = TreeGridItem> = {
[key: TreeGridId]: ItemType;
};

export type TreeGridColumn = {
Expand Down Expand Up @@ -84,9 +85,9 @@ export type TreeGridFilters = {
[col: string]: string;
};

export type TreeGridProps = {
export type TreeGridProps<ItemType extends TreeGridItem = TreeGridItem> = {
columns: TreeGridColumn[];
data: TreeGridData;
data: TreeGridData<ItemType>;
defaultExpanded?: TreeGridId[];
highlightId?: TreeGridId;
rowCustomization?: (
Expand All @@ -109,7 +110,9 @@ export type TreeGridProps = {
onFilter?: (filters: TreeGridFilters) => void;
};

export function TreeGrid(props: TreeGridProps) {
export function TreeGrid<ItemType extends TreeGridItem = TreeGridItem>(
props: TreeGridProps<ItemType>
) {
const theme = useTheme();

const [state, updateState] = useImmer<TreeGridState>(
Expand Down Expand Up @@ -391,6 +394,18 @@ export function useArrayAsTreeGridData<
}, [array]);
}

export function fromProtoColumns(
columns: columnProto.Column[]
): TreeGridColumn[] {
return columns.map((c) => ({
key: c.key,
width: c.widthString ?? c.widthDouble ?? 100,
title: c.title,
sortable: c.sortable,
filterable: c.filterable,
}));
}

function renderChildren(
theme: Theme,
props: TreeGridProps,
Expand Down
13 changes: 1 addition & 12 deletions ui/src/criteria/classification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Loading from "components/loading";
import { Search } from "components/search";
import { useSimpleDialog } from "components/simpleDialog";
import {
fromProtoColumns,
TreeGrid,
TreeGridColumn,
TreeGridData,
Expand Down Expand Up @@ -1022,18 +1023,6 @@ function fromProtoSortOrder(sortOrder: sortOrderProto.SortOrder): SortOrder {
};
}

function fromProtoColumns(
columns: configProto.EntityGroup_Column[]
): TreeGridColumn[] {
return columns.map((c) => ({
key: c.key,
width: c.widthString ?? c.widthDouble ?? 100,
title: c.title,
sortable: c.sortable,
filterable: c.filterable,
}));
}

function nameAttribute(config: configProto.EntityGroup) {
return (
config.nameAttribute ?? config.columns[config.nameColumnIndex ?? 0].key
Expand Down
Loading

0 comments on commit 1c58d1e

Please sign in to comment.