Skip to content

Commit

Permalink
feat(app): add indicators for drug list and improve
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 29, 2024
1 parent 9d0db1d commit c6d8a9c
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 115 deletions.
66 changes: 60 additions & 6 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ typedef DrugItemBuilder = List<Widget> Function(
}
);

// TODO(tamslo): https://github.com/hpi-dhc/PharMe/issues/731
class DrugList extends HookWidget {
const DrugList({
super.key,
Expand All @@ -19,7 +20,7 @@ class DrugList extends HookWidget {
this.showDrugInteractionIndicator = false,
this.searchForDrugClass = true,
this.drugActivityChangeable = false,
this.buildContainer,
required this.buildContainer,
});

final DrugListState state;
Expand All @@ -32,7 +33,11 @@ class DrugList extends HookWidget {
// in the "All medications" list to make searching and toggling a medication's
// activity less confusing
final bool drugActivityChangeable;
final Widget Function(List<Widget> children)? buildContainer;
final Widget Function({
List<Widget>? children,
Widget? indicator,
Widget? noDrugsMessage,
}) buildContainer;

Widget _buildDrugList(
BuildContext context,
Expand All @@ -46,7 +51,7 @@ class DrugList extends HookWidget {
searchForDrugClass: searchForDrugClass,
).sortedBy((drug) => drug.name);
if (filteredDrugs.isEmpty && noDrugsMessage != null) {
return errorIndicator(noDrugsMessage!);
return buildContainer(noDrugsMessage: errorIndicator(noDrugsMessage!));
}
List<Widget>? activeDrugsList;
// Do not show repeated active drugs when searching in medication selection
Expand Down Expand Up @@ -126,9 +131,18 @@ class DrugList extends HookWidget {
],
if (activeDrugsList == null) ...allDrugsList,
];
return (buildContainer != null)
? buildContainer!(drugLists)
: Column(crossAxisAlignment: CrossAxisAlignment.start, children: drugLists);
final indicator = _maybeBuildDrugListIndicator(
context: context,
drugs: drugs,
filter: filter,
activeDrugs: activeDrugs,
otherDrugsExpanded: currentlyExpanded,
currentlyEnabled: currentlyEnabled,
);
return buildContainer(
children: drugLists,
indicator: indicator,
);
}

@override
Expand All @@ -144,4 +158,44 @@ class DrugList extends HookWidget {
loading: loadingIndicator,
);
}

Widget _maybeBuildDrugListIndicator({
required BuildContext context,
required List<Drug> drugs,
required FilterState filter,
required ActiveDrugs activeDrugs,
required bool otherDrugsExpanded,
required bool currentlyEnabled,
}) {
var indicatorText = '';
if (currentlyEnabled && !otherDrugsExpanded) {
final listHelperText = context.l10n.show_all_dropdown_text(
context.l10n.drugs_show_all_dropdown_item,
context.l10n.drugs_show_all_dropdown_items,
);
indicatorText = listHelperText;
}
if (showDrugInteractionIndicator) {
final filteredDrugs = filter.filter(
drugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
);
if (filteredDrugs.any((drug) => isInhibitor(drug.name))) {
final inhibitorText = context.l10n.search_page_indicator_explanation(
drugInteractionIndicatorName,
drugInteractionIndicator
);
if (indicatorText.isNotBlank) {
indicatorText = '$indicatorText\n\n$inhibitorText';
} else {
indicatorText = inhibitorText;
}
}
}
if (indicatorText.isNotBlank) {
return PageIndicatorExplanation(indicatorText);
}
return SizedBox.shrink();
}
}
80 changes: 27 additions & 53 deletions app/lib/common/widgets/drug_search/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
import '../../../../common/module.dart';
import '../../../drug/widgets/tooltip_icon.dart';

// TODO(tamslo): https://github.com/hpi-dhc/PharMe/issues/731
class DrugSearch extends HookWidget {
const DrugSearch({
super.key,
Expand Down Expand Up @@ -31,33 +32,33 @@ class DrugSearch extends HookWidget {
@override
Widget build(BuildContext context) {
final searchController = useTextEditingController();
return Column(
children: [
Padding(
padding: EdgeInsets.all(PharMeTheme.smallSpace),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: _buildSearchBarItems(context, searchController),
),
),
DrugList(
state: state,
activeDrugs: activeDrugs,
buildDrugItems: buildDrugItems,
showDrugInteractionIndicator: showDrugInteractionIndicator,
noDrugsMessage: context.l10n.search_no_drugs(
showFilter
? context.l10n.search_no_drugs_with_filter_amendment
: ''
),
searchForDrugClass: searchForDrugClass,
buildContainer:
(children) => scrollList(keepPosition: keepPosition, children),
drugActivityChangeable: drugActivityChangeable,
return DrugList(
state: state,
activeDrugs: activeDrugs,
buildDrugItems: buildDrugItems,
showDrugInteractionIndicator: showDrugInteractionIndicator,
noDrugsMessage: context.l10n.search_no_drugs(
showFilter
? context.l10n.search_no_drugs_with_filter_amendment
: ''
),
searchForDrugClass: searchForDrugClass,
buildContainer:
({children, indicator, noDrugsMessage}) => Column(
children: [
Padding(
padding: EdgeInsets.all(PharMeTheme.smallSpace),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: _buildSearchBarItems(context, searchController),
),
),
if (children != null) scrollList(keepPosition: keepPosition, children),
if (noDrugsMessage != null) noDrugsMessage,
if (indicator != null) indicator,
],
),
_maybeBuildInteractionIndicator(context, state, activeDrugs)
?? SizedBox.shrink(),
],
drugActivityChangeable: drugActivityChangeable,
);
}

Expand Down Expand Up @@ -92,31 +93,4 @@ class DrugSearch extends HookWidget {
],
];
}

Widget? _maybeBuildInteractionIndicator(
BuildContext context,
DrugListState state,
ActiveDrugs activeDrugs,
) {
return state.whenOrNull(
loaded: (drugs, filter) {
if (showDrugInteractionIndicator) {
final filteredDrugs = filter.filter(
drugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
);
if (filteredDrugs.any((drug) => isInhibitor(drug.name))) {
return PageIndicatorExplanation(
context.l10n.search_page_indicator_explanation(
drugInteractionIndicatorName,
drugInteractionIndicator
),
);
}
}
return null;
}
);
}
}
4 changes: 4 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@
"@report_show_all_dropdown_item": {},
"report_show_all_dropdown_items": "genes with known medication interactions",
"@report_show_all_dropdown_items": {},
"drugs_show_all_dropdown_item": "medication",
"@drugs_show_all_dropdown_item": {},
"drugs_show_all_dropdown_items": "medication with clinically relevant gene interactions",
"@drugs_show_all_dropdown_items": {},

"gene_page_headline": "{gene} report",
"@gene_page_headline": {
Expand Down
118 changes: 62 additions & 56 deletions app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,80 @@ class GenePage extends HookWidget {
builder: (context, activeDrugs, child) => BlocProvider(
create: (context) => cubit,
child: BlocBuilder<DrugListCubit, DrugListState>(
builder: (context, state) => pageScaffold(
builder: (context, state) => unscrollablePageScaffold(
title:
context.l10n.gene_page_headline(genotypeResult.geneDisplayString),
body: [
Padding(
padding: EdgeInsets.symmetric(
horizontal: PharMeTheme.smallToMediumSpace,
vertical: PharMeTheme.mediumSpace
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
body: DrugList(
state: state,
activeDrugs: activeDrugs,
noDrugsMessage: context.l10n.gene_page_no_relevant_drugs,
buildContainer: ({children, indicator, noDrugsMessage}) =>
Column(
children: [
SubHeader(
context.l10n.gene_page_your_result(
genotypeResult.geneDisplayString,
Padding(
padding: EdgeInsets.symmetric(
horizontal: PharMeTheme.smallToMediumSpace,
vertical: PharMeTheme.mediumSpace
),
tooltip: context.l10n
.gene_page_name_tooltip(
genotypeResult.gene,
),
),
SizedBox(height: PharMeTheme.smallToMediumSpace),
RoundedCard(
radius: PharMeTheme.mediumSpace,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Table(
columnWidths: Map.from({
0: IntrinsicColumnWidth(),
1: IntrinsicColumnWidth(flex: 1),
}),
children: [
_buildRow(
context.l10n.gene_page_genotype,
genotypeResult.variantDisplayString(context),
tooltip: context.l10n.gene_page_genotype_tooltip
),
_buildPhenotypeRow(context),
],
SubHeader(
context.l10n.gene_page_your_result(
genotypeResult.geneDisplayString,
),
tooltip: context.l10n
.gene_page_name_tooltip(
genotypeResult.gene,
),
),
if (isInhibited(genotypeResult, drug: null)) ...[
SizedBox(height: PharMeTheme.smallSpace),
buildDrugInteractionInfo(
context,
[genotypeResult],
drug: null,
SizedBox(height: PharMeTheme.smallToMediumSpace),
RoundedCard(
radius: PharMeTheme.mediumSpace,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Table(
columnWidths: Map.from({
0: IntrinsicColumnWidth(),
1: IntrinsicColumnWidth(flex: 1),
}),
children: [
_buildRow(
context.l10n.gene_page_genotype,
genotypeResult.variantDisplayString(context),
tooltip: context.l10n.gene_page_genotype_tooltip
),
_buildPhenotypeRow(context),
],
),
if (isInhibited(genotypeResult, drug: null)) ...[
SizedBox(height: PharMeTheme.smallSpace),
buildDrugInteractionInfo(
context,
[genotypeResult],
drug: null,
),
]
],
)),
SizedBox(height: PharMeTheme.smallToMediumSpace),
SubHeader(
context.l10n.gene_page_relevant_drugs,
tooltip: context.l10n.gene_page_relevant_drugs_tooltip(
genotypeResult.geneDisplayString
),
]
],
)),
SizedBox(height: PharMeTheme.smallToMediumSpace),
SubHeader(
context.l10n.gene_page_relevant_drugs,
tooltip: context.l10n.gene_page_relevant_drugs_tooltip(
genotypeResult.geneDisplayString
),
SizedBox(height: PharMeTheme.smallSpace),
],
),
),
SizedBox(height: PharMeTheme.smallSpace),
DrugList(
state: state,
activeDrugs: activeDrugs,
noDrugsMessage: context.l10n.gene_page_no_relevant_drugs,
),
],
if (children != null) scrollList(children),
if (noDrugsMessage != null) noDrugsMessage,
if (indicator != null) indicator,
]
),
),
],
),
),
),
)
Expand Down
1 change: 1 addition & 0 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ReportPage extends HookWidget {
).toList();
}

// TODO(tamslo): https://github.com/hpi-dhc/PharMe/issues/731
Widget _maybeBuildPageIndicators(
BuildContext context,
Iterable<GenotypeResult> relevantGenes,
Expand Down
1 change: 1 addition & 0 deletions pharme.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"Statins",
"subfolders",
"tacrolimus",
"tamslo",
"terbinafine",
"tobramycin",
"tramadol",
Expand Down

0 comments on commit c6d8a9c

Please sign in to comment.