Skip to content

Commit

Permalink
feat(#653): re-introduce boolean to show or not show drug-drug intera…
Browse files Browse the repository at this point in the history
…ction indicator
  • Loading branch information
tamslo committed Aug 24, 2023
1 parent 0450081 commit fb9cea4
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 20 deletions.
25 changes: 16 additions & 9 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import 'drug_items/drug_cards.dart';

List<Widget> buildDrugList(
BuildContext context,
DrugListState state, {
String? noDrugsMessage,
List<Widget> Function(
BuildContext context,
List<Drug> drugs,
{ Map? buildParams }
) buildDrugItems = buildDrugCards,
Map? drugItemsBuildParams,
}) {
DrugListState state,
{
String? noDrugsMessage,
List<Widget> Function(
BuildContext context,
List<Drug> drugs,
{
Map? buildParams,
bool showDrugInteractionIndicator,
}
) buildDrugItems = buildDrugCards,
bool showDrugInteractionIndicator = false,
Map? drugItemsBuildParams,
}
) {
List<Widget> buildDrugList(List<Drug> drugs, FilterState filter) {
final filteredDrugs = filter.filter(drugs);
if (filteredDrugs.isEmpty && noDrugsMessage != null) {
Expand All @@ -21,6 +27,7 @@ List<Widget> buildDrugList(
context,
filteredDrugs,
buildParams: drugItemsBuildParams,
showDrugInteractionIndicator: showDrugInteractionIndicator,
);
}
return state.when(
Expand Down
13 changes: 9 additions & 4 deletions app/lib/common/widgets/drug_list/drug_items/drug_cards.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import '../../../module.dart';
import 'utils.dart';

List<Widget> buildDrugCards(
BuildContext context,
List<Drug> drugs,
{ Map? buildParams }
{
Map? buildParams,
bool showDrugInteractionIndicator = false,
}
) {
int warningLevelSeverity(Drug drug) {
final warningLevel = drug.userGuideline()?.annotations.warningLevel
Expand All @@ -23,6 +27,7 @@ List<Widget> buildDrugCards(
.push(DrugRoute(drug: drug))
.then((_) => context.read<DrugListCubit>().search()),
drug: drug,
showDrugInteractionIndicator: showDrugInteractionIndicator,
)
).toList();
}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../../../module.dart';
import 'utils.dart';

bool isDrugSelected(Drug drug) {
return UserData.instance.activeDrugNames!.contains(drug.name);
Expand All @@ -7,7 +8,10 @@ bool isDrugSelected(Drug drug) {
List<Widget> buildDrugCheckboxList(
BuildContext context,
List<Drug> drugs,
{ Map? buildParams }
{
Map? buildParams,
bool showDrugInteractionIndicator = false,
}
) {
if (buildParams == null) throw Exception();
final onCheckboxChange = buildParams['onCheckboxChange'];
Expand All @@ -25,7 +29,7 @@ List<Widget> 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,
Expand Down
13 changes: 13 additions & 0 deletions app/lib/common/widgets/drug_list/drug_items/utils.dart
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 19 additions & 1 deletion app/lib/common/widgets/drug_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -18,8 +19,12 @@ class DrugSearch extends HookWidget {
final List<Widget> Function(
BuildContext context,
List<Drug> drugs,
{ Map? buildParams }
{
Map? buildParams,
bool showDrugInteractionIndicator,
}
) buildDrugItems;
final bool showDrugInteractionIndicator;
final DrugListCubit cubit;
final Map? drugItemsBuildParams;

Expand Down Expand Up @@ -66,17 +71,30 @@ class DrugSearch extends HookWidget {
buildDrugItems: buildDrugItems,
noDrugsMessage: noDrugsMessage,
drugItemsBuildParams: drugItemsBuildParams,
showDrugInteractionIndicator:
showDrugInteractionIndicator,
),
),
),
),
..._maybeShowDrugInteractionExplanation(context),
],
);
}
)
);
}

List<Widget> _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<DrugListCubit>();
final filter = cubit.filter;
Expand Down
1 change: 1 addition & 0 deletions app/lib/drug_selection/pages/drug_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class DrugSelectionPage extends HookWidget {
.read<DrugSelectionPageCubit>()
.updateDrugActivity(drug, value),
},
showDrugInteractionIndicator: false,
);
}
}
8 changes: 4 additions & 4 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions app/lib/search/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SearchPage extends HookWidget {
showFilter: true,
buildDrugItems: buildDrugCards,
cubit: cubit,
showDrugInteractionIndicator: true,
),
);
}
Expand Down

0 comments on commit fb9cea4

Please sign in to comment.