Skip to content

Commit

Permalink
feat(#638): show influence of active drugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tamara-slosarek authored and tamslo committed Aug 3, 2023
1 parent 64ff37b commit 589528f
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 40 deletions.
16 changes: 16 additions & 0 deletions app/lib/common/models/drug/drug_inhibitors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

// structure: gene symbol -> drug name -> overwriting lookupkey

import 'package:dartx/dartx.dart';

import 'drug.dart';

const Map<String, Map<String, String>> drugInhibitors = {
'CYP2D6': {
// 0.0 is a lookupkey for a type of poor metabolizer
Expand All @@ -22,3 +26,15 @@ const Map<String, Map<String, String>> drugInhibitors = {
'mirabegron': '1.0',
}
};


bool isInhibitor(Drug drug) {
final influencingDrugs = drugInhibitors.keys.flatMap(
(gene) => drugInhibitors[gene]!.keys);
return influencingDrugs.contains(drug.name);
}

List<String> inhibitorFor(Drug drug) {
return drugInhibitors.keys.filter(
(gene) => drugInhibitors[gene]!.containsKey(drug.name)).toList();
}
55 changes: 34 additions & 21 deletions app/lib/common/pages/drug/widgets/annotation_cards/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,48 @@ class DrugAnnotationCard extends StatelessWidget {
]
]),
SizedBox(height: 4),
if (isInhibitor(drug)) ...[
SizedBox(height: 8),
Text(context.l10n.drugs_page_is_inhibitor(
drug.name,
inhibitorFor(drug).join(', '),
)),
],
Divider(color: PharMeTheme.borderColor),
SizedBox(height: 4),
SubHeader(context.l10n.drugs_page_header_active),
CheckboxListTile(
activeColor: PharMeTheme.primaryColor,
title: Text(context.l10n.drugs_page_active),
value: isActive,
onChanged: (newValue) => showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(context.l10n.drugs_page_active_warn_header),
content: Text(context.l10n.drugs_page_active_warn),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () => Navigator.pop(context, 'Cancel'),
child: Text(context.l10n.action_cancel),
onChanged: (newValue) => {
if (isInhibitor(drug)) {
showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(context.l10n.drugs_page_active_warn_header),
content: Text(context.l10n.drugs_page_active_warn),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () => Navigator.pop(context, 'Cancel'),
child: Text(context.l10n.action_cancel),
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context, 'OK');
setActivity(newValue);
},
child: Text(context.l10n.action_continue),
),
],
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context, 'OK');
setActivity(newValue);
},
child: Text(context.l10n.action_continue),
),
],
),
),
)
} else {
setActivity(newValue)
}
},
controlAffinity: ListTileControlAffinity.leading,
),
],
Expand Down
16 changes: 14 additions & 2 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ List<Widget> buildDrugList(
BuildContext context,
DrugListState state, {
String? noDrugsMessage,
bool? showInfluenceOnOtherDrugs,
}) =>
state.when(
initial: () => [Container()],
Expand All @@ -13,6 +14,7 @@ List<Widget> buildDrugList(
drugs,
filter,
noDrugsMessage: noDrugsMessage,
showInfluenceOnOtherDrugs: showInfluenceOnOtherDrugs,
),
loading: () => [loadingIndicator()],
);
Expand All @@ -22,6 +24,7 @@ List<Widget> _buildDrugCards(
List<Drug> drugs,
FilterState filter, {
String? noDrugsMessage,
bool? showInfluenceOnOtherDrugs,
}) {
final filteredDrugs = filter.filter(drugs);
if (filteredDrugs.isEmpty && noDrugsMessage != null) {
Expand Down Expand Up @@ -49,7 +52,10 @@ List<Widget> _buildDrugCards(
onTap: () => context.router
.push(DrugRoute(drug: drug))
.then((_) => context.read<DrugListCubit>().search()),
drug: drug)),
drug: drug,
showInfluenceOnOtherDrugs: showInfluenceOnOtherDrugs ?? false,
)
),
SizedBox(height: 12)
]))
];
Expand All @@ -59,14 +65,20 @@ class DrugCard extends StatelessWidget {
const DrugCard({
required this.onTap,
required this.drug,
required this.showInfluenceOnOtherDrugs
});

final VoidCallback onTap;
final Drug drug;
final bool showInfluenceOnOtherDrugs;

@override
Widget build(BuildContext context) {
final warningLevel = drug.userGuideline()?.annotations.warningLevel;
var drugName = drug.name.capitalize();
if (showInfluenceOnOtherDrugs) {
if (isInhibitor(drug)) drugName = '$drugName *';
}

return RoundedCard(
onTap: onTap,
Expand All @@ -84,7 +96,7 @@ class DrugCard extends StatelessWidget {
Icon(warningLevel?.icon ?? indeterminateIcon),
SizedBox(width: 4),
Text(
drug.name.capitalize(),
drugName,
style: PharMeTheme.textTheme.titleMedium!
.copyWith(fontWeight: FontWeight.bold),
),
Expand Down
18 changes: 17 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,23 @@
"search_page_filter_yellow": "Yellow warning level",
"search_page_filter_red": "Red warning level",
"search_page_filter_gray": "No warning level",
"search_page_asterisk_explanation": "Drugs with an asterisk (*) influence results for other drugs",

"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": {
"description": "Disclaimer for when the phenotype has been adjusted based on a current drug",
"placeholders": {
"drugName": {
"type": "String",
"example": "bupropion"
},
"geneSymbols": {
"type": "String",
"example": "CYP2D6, CYP2C19"
}
}
},
"drugs_page_overwritten_phenotype": "adjusted based on you taking {drugName}",
"@drugs_page_overwritten_phenotype": {
"description": "Disclaimer for when the phenotype has been adjusted based on a current drug",
Expand Down Expand Up @@ -63,7 +78,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 may adjust the guidelines you receive for other drugs.",
"drugs_page_active_warn": "This may influence the guidelines you receive for other drugs.",
"drugs_page_header_guideline": "Clinical Guideline",
"drugs_page_header_recommendation": "Recommendation",
"drugs_page_no_guidelines_for_phenotype_implication": "More information is needed to comment on your DNA's influence on {drugName}.",
Expand Down Expand Up @@ -129,6 +144,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:",

"pdf_pgx_report": "PGx Report",
"pdf_heading_user_data": "User data",
Expand Down
45 changes: 31 additions & 14 deletions app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,38 @@ class GenePage extends HookWidget {
),
SizedBox(height: 12),
RoundedCard(
child: Table(
columnWidths: Map.from({
0: IntrinsicColumnWidth(),
1: IntrinsicColumnWidth(flex: 1),
}),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildRow(
context.l10n.gene_page_genotype, phenotype.genotype,
tooltip: context.l10n.gene_page_genotype_tooltip),
_buildRow(context.l10n.gene_page_phenotype,
UserData.phenotypeFor(phenotype.geneSymbol)!,
tooltip: context.l10n.gene_page_phenotype_tooltip),
],
),
),
Table(
columnWidths: Map.from({
0: IntrinsicColumnWidth(),
1: IntrinsicColumnWidth(flex: 1),
}),
children: [
_buildRow(
context.l10n.gene_page_genotype,
phenotype.genotype,
tooltip: context.l10n.gene_page_genotype_tooltip
),
_buildRow(context.l10n.gene_page_phenotype,
UserData.phenotypeFor(phenotype.geneSymbol)!,
tooltip:
context.l10n.gene_page_phenotype_tooltip
),
],
),
if (drugInhibitors.containsKey(phenotype.geneSymbol))
...[
SizedBox(height: PharMeTheme.smallSpace),
Text(context.l10n.gene_page_inhibitor_drugs),
SizedBox(height: PharMeTheme.smallSpace),
Text(drugInhibitors[phenotype.geneSymbol]!.keys
.join(', ')
),
],
],
)),
SizedBox(height: 12),
SubHeader(context.l10n.gene_page_affected_drugs,
tooltip: context.l10n.gene_page_affected_drugs_tooltip),
Expand Down
15 changes: 13 additions & 2 deletions app/lib/search/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@ class SearchPage extends HookWidget {
TooltipIcon(context.l10n.search_page_tooltip_search),
buildFilter(context),
]),
body: buildDrugList(context, state,
noDrugsMessage: context.l10n.err_no_drugs),
body: [
Padding(
padding: EdgeInsets.symmetric(
vertical: PharMeTheme.smallSpace,
horizontal: PharMeTheme.mediumSpace
),
child: Text(context.l10n.search_page_asterisk_explanation),
),
...buildDrugList(context, state,
noDrugsMessage: context.l10n.err_no_drugs,
showInfluenceOnOtherDrugs: true
),
],
);
}));
}
Expand Down

0 comments on commit 589528f

Please sign in to comment.