From fb9cea465448081516d129aa64bf75f15274a491 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Thu, 24 Aug 2023 15:23:11 +0200 Subject: [PATCH] feat(#653): re-introduce boolean to show or not show drug-drug interaction indicator --- app/lib/common/widgets/drug_list/builder.dart | 25 ++++++++++++------- .../drug_list/drug_items/drug_cards.dart | 13 +++++++--- .../drug_items/drug_checkbox_list.dart | 8 ++++-- .../widgets/drug_list/drug_items/utils.dart | 13 ++++++++++ app/lib/common/widgets/drug_search.dart | 20 ++++++++++++++- .../drug_selection/pages/drug_selection.dart | 1 + app/lib/l10n/app_en.arb | 8 +++--- app/lib/search/pages/search.dart | 1 + 8 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 app/lib/common/widgets/drug_list/drug_items/utils.dart diff --git a/app/lib/common/widgets/drug_list/builder.dart b/app/lib/common/widgets/drug_list/builder.dart index cd229063..40d05f7f 100644 --- a/app/lib/common/widgets/drug_list/builder.dart +++ b/app/lib/common/widgets/drug_list/builder.dart @@ -3,15 +3,21 @@ import 'drug_items/drug_cards.dart'; List buildDrugList( BuildContext context, - DrugListState state, { - String? noDrugsMessage, - List Function( - BuildContext context, - List drugs, - { Map? buildParams } - ) buildDrugItems = buildDrugCards, - Map? drugItemsBuildParams, -}) { + DrugListState state, + { + String? noDrugsMessage, + List Function( + BuildContext context, + List drugs, + { + Map? buildParams, + bool showDrugInteractionIndicator, + } + ) buildDrugItems = buildDrugCards, + bool showDrugInteractionIndicator = false, + Map? drugItemsBuildParams, + } +) { List buildDrugList(List drugs, FilterState filter) { final filteredDrugs = filter.filter(drugs); if (filteredDrugs.isEmpty && noDrugsMessage != null) { @@ -21,6 +27,7 @@ List buildDrugList( context, filteredDrugs, buildParams: drugItemsBuildParams, + showDrugInteractionIndicator: showDrugInteractionIndicator, ); } return state.when( diff --git a/app/lib/common/widgets/drug_list/drug_items/drug_cards.dart b/app/lib/common/widgets/drug_list/drug_items/drug_cards.dart index d27b2a2a..44678046 100644 --- a/app/lib/common/widgets/drug_list/drug_items/drug_cards.dart +++ b/app/lib/common/widgets/drug_list/drug_items/drug_cards.dart @@ -1,9 +1,13 @@ import '../../../module.dart'; +import 'utils.dart'; List buildDrugCards( BuildContext context, List drugs, - { Map? buildParams } + { + Map? buildParams, + bool showDrugInteractionIndicator = false, + } ) { int warningLevelSeverity(Drug drug) { final warningLevel = drug.userGuideline()?.annotations.warningLevel @@ -23,6 +27,7 @@ List buildDrugCards( .push(DrugRoute(drug: drug)) .then((_) => context.read().search()), drug: drug, + showDrugInteractionIndicator: showDrugInteractionIndicator, ) ).toList(); } @@ -31,17 +36,17 @@ class DrugCard extends StatelessWidget { const DrugCard({ required this.onTap, required this.drug, + required this.showDrugInteractionIndicator, }); final VoidCallback onTap; final Drug drug; + final bool showDrugInteractionIndicator; @override Widget build(BuildContext context) { final warningLevel = drug.userGuideline()?.annotations.warningLevel; - var drugName = drug.name.capitalize(); - if (isInhibitor(drug)) drugName = '$drugName *'; - + final drugName = formatDrugName(drug, showDrugInteractionIndicator); return Padding( padding: EdgeInsets.symmetric(vertical: PharMeTheme.smallSpace / 2), child: RoundedCard( diff --git a/app/lib/common/widgets/drug_list/drug_items/drug_checkbox_list.dart b/app/lib/common/widgets/drug_list/drug_items/drug_checkbox_list.dart index 43818045..3ecda1d3 100644 --- a/app/lib/common/widgets/drug_list/drug_items/drug_checkbox_list.dart +++ b/app/lib/common/widgets/drug_list/drug_items/drug_checkbox_list.dart @@ -1,4 +1,5 @@ import '../../../module.dart'; +import 'utils.dart'; bool isDrugSelected(Drug drug) { return UserData.instance.activeDrugNames!.contains(drug.name); @@ -7,7 +8,10 @@ bool isDrugSelected(Drug drug) { List buildDrugCheckboxList( BuildContext context, List drugs, - { Map? buildParams } + { + Map? buildParams, + bool showDrugInteractionIndicator = false, + } ) { if (buildParams == null) throw Exception(); final onCheckboxChange = buildParams['onCheckboxChange']; @@ -25,7 +29,7 @@ List buildDrugCheckboxList( enabled: checkboxesEnabled, value: isDrugSelected(drug), onChanged: (value) => onCheckboxChange(drug, value), - title: Text(drug.name.capitalize()), + title: Text(formatDrugName(drug, showDrugInteractionIndicator)), subtitle: (drug.annotations.brandNames.isNotEmpty) ? Text('(${drug.annotations.brandNames.join(", ")})') : null, diff --git a/app/lib/common/widgets/drug_list/drug_items/utils.dart b/app/lib/common/widgets/drug_list/drug_items/utils.dart new file mode 100644 index 00000000..67a4e843 --- /dev/null +++ b/app/lib/common/widgets/drug_list/drug_items/utils.dart @@ -0,0 +1,13 @@ +import '../../../module.dart'; + +String formatDrugName( + Drug drug, + // ignore: avoid_positional_boolean_parameters + bool showDrugInteractionIndicator, +) { + var drugName = drug.name.capitalize(); + if (showDrugInteractionIndicator && isInhibitor(drug)) { + drugName = '$drugName *'; + } + return drugName; +} \ No newline at end of file diff --git a/app/lib/common/widgets/drug_search.dart b/app/lib/common/widgets/drug_search.dart index a5ec6e1b..153abe3d 100644 --- a/app/lib/common/widgets/drug_search.dart +++ b/app/lib/common/widgets/drug_search.dart @@ -9,6 +9,7 @@ class DrugSearch extends HookWidget { Key? key, required this.showFilter, required this.buildDrugItems, + required this.showDrugInteractionIndicator, this.drugItemsBuildParams, DrugListCubit? cubit, }) : cubit = cubit ?? DrugListCubit(), @@ -18,8 +19,12 @@ class DrugSearch extends HookWidget { final List Function( BuildContext context, List drugs, - { Map? buildParams } + { + Map? buildParams, + bool showDrugInteractionIndicator, + } ) buildDrugItems; + final bool showDrugInteractionIndicator; final DrugListCubit cubit; final Map? drugItemsBuildParams; @@ -66,10 +71,13 @@ class DrugSearch extends HookWidget { buildDrugItems: buildDrugItems, noDrugsMessage: noDrugsMessage, drugItemsBuildParams: drugItemsBuildParams, + showDrugInteractionIndicator: + showDrugInteractionIndicator, ), ), ), ), + ..._maybeShowDrugInteractionExplanation(context), ], ); } @@ -77,6 +85,16 @@ class DrugSearch extends HookWidget { ); } + List _maybeShowDrugInteractionExplanation(BuildContext context) { + if (!showDrugInteractionIndicator) return []; + return [ + SizedBox(height: PharMeTheme.smallSpace), + Text( + context.l10n.search_page_asterisk_explanation + ), + ]; + } + Widget buildFilter(BuildContext context) { final cubit = context.read(); final filter = cubit.filter; diff --git a/app/lib/drug_selection/pages/drug_selection.dart b/app/lib/drug_selection/pages/drug_selection.dart index 64df0b69..8e046298 100644 --- a/app/lib/drug_selection/pages/drug_selection.dart +++ b/app/lib/drug_selection/pages/drug_selection.dart @@ -88,6 +88,7 @@ class DrugSelectionPage extends HookWidget { .read() .updateDrugActivity(drug, value), }, + showDrugInteractionIndicator: false, ); } } diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index b18c9126..3e427f79 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -31,7 +31,7 @@ "search_page_filter_yellow": "Show yellow warning level", "search_page_filter_red": "Show red warning level", "search_page_filter_gray": "Show gray warning level", - "search_page_asterisk_explanation": "Drugs with an asterisk (*) influence results for other drugs", + "search_page_asterisk_explanation": "Taking drugs with an asterisk (*) can influence your results for other drugs", "search_no_drugs": "No drugs found. Try adjusting the search term{amendment}.", "@search_no_drugs": { "description": "Disclaimer for when no drug was found in the search", @@ -43,7 +43,7 @@ } }, "drugs_page_disclaimer": "This assessment is ONLY based on your genetics. Important factors like weight, age and pre-existing conditions are not considered.", - "drugs_page_is_inhibitor": "Taking {drugName} influences your results for guidelines based on the following gene(s): {geneSymbols}", + "drugs_page_is_inhibitor": "Taking {drugName} can influence your results for the following gene(s): {geneSymbols}", "@drugs_page_is_inhibitor": { "description": "Disclaimer for when the current drug influences other guidelines", "placeholders": { @@ -86,7 +86,7 @@ "drugs_page_header_active": "Usage status", "drugs_page_active": "I am currently taking this drug.", "drugs_page_active_warn_header": "Are you sure you want to change the drug usage status?", - "drugs_page_active_warn": "This can influence the guidelines you receive for other drugs.", + "drugs_page_active_warn": "This can influence your results for other drugs.", "drugs_page_header_guideline": "Clinical Guideline", "drugs_page_no_guidelines_for_phenotype_implication": "More information is needed to comment on your DNA's influence on {drugName}.", "@drugs_page_no_guidelines_for_phenotype_implication": { @@ -149,7 +149,7 @@ "gene_page_affected_drugs": "Affected drugs", "gene_page_affected_drugs_tooltip": "The drugs listed here are affected by your variant of this gene.", "gene_page_no_affected_drugs": "Your variant of this gene has no known effect on any drug.", - "gene_page_inhibitor_drugs": "Guidelines based on this gene are influenced by taking the following drugs:", + "gene_page_inhibitor_drugs": "Your results for this gene can be influenced by taking any of the following drugs:", "pdf_pgx_report": "PGx Report", "pdf_heading_user_data": "User data", diff --git a/app/lib/search/pages/search.dart b/app/lib/search/pages/search.dart index c1a1d5bd..f528ce72 100644 --- a/app/lib/search/pages/search.dart +++ b/app/lib/search/pages/search.dart @@ -24,6 +24,7 @@ class SearchPage extends HookWidget { showFilter: true, buildDrugItems: buildDrugCards, cubit: cubit, + showDrugInteractionIndicator: true, ), ); }