From ed15bb7767c5bb28c8d35a6e3209673aeafb1c68 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Wed, 4 Sep 2024 23:21:17 +0200 Subject: [PATCH] feat(#706): shorten phenoconversion text on gene page --- .../common/models/drug/drug_inhibitors.dart | 50 ++++++++++++++++- app/lib/common/widgets/annotation_table.dart | 21 ++++++- app/lib/l10n/app_en.arb | 7 ++- app/lib/report/pages/gene.dart | 56 ++----------------- 4 files changed, 77 insertions(+), 57 deletions(-) diff --git a/app/lib/common/models/drug/drug_inhibitors.dart b/app/lib/common/models/drug/drug_inhibitors.dart index 2cb24691..cf9c39a6 100644 --- a/app/lib/common/models/drug/drug_inhibitors.dart +++ b/app/lib/common/models/drug/drug_inhibitors.dart @@ -97,6 +97,54 @@ String possiblyAdaptedPhenotype(GenotypeResult genotypeResult) { return '$overwritePhenotype$drugInteractionIndicator'; } +String getDrugNames(String drugName) { + final drug = CachedDrugs.instance.drugs!.firstWhere( + (drug) => drug.name == drugName + ); + if (drug.annotations.brandNames.isEmpty) return drugName; + return '$drugName (${drug.annotations.brandNames.join(', ')})'; +} + +String inhibitionTooltipText( + BuildContext context, + GenotypeResult genotypeResult, + { String? drug } +) { + final activeInhibitors = activeInhibitorsFor( + genotypeResult.gene, + drug: drug, + ); + final activeInhibitorsWithBrandNames = + activeInhibitors.map(getDrugNames).toList(); + final inhibitorsString = enumerationWithAnd( + activeInhibitorsWithBrandNames, + context, + ); + return context.l10n.inhibitors_tooltip(inhibitorsString); +} + +Table buildDrugInteractionInfo( + BuildContext context, + GenotypeResult genotypeResult, + { String? drug } +) { + final activeInhibitors = activeInhibitorsFor( + genotypeResult.gene, + drug: drug, + ); + final consequence = activeInhibitors.all(isModerateInhibitor) + ? context.l10n.inhibitors_consequence_not_adapted + : context.l10n.inhibitors_consequence_adapted(genotypeResult.phenotype); + return buildTable([ + TableRowDefinition( + drugInteractionIndicator, + '${context.l10n.inhibitor_message} ($consequence)', + tooltip: inhibitionTooltipText(context, genotypeResult, drug: drug), + )], + boldHeader: false, + ); +} + bool isInhibited( GenotypeResult genotypeResult, { String? drug } @@ -191,4 +239,4 @@ MapEntry? getOverwrittenLookup ( }); if (lookup == null) return null; return lookup; -} \ No newline at end of file +} diff --git a/app/lib/common/widgets/annotation_table.dart b/app/lib/common/widgets/annotation_table.dart index 1bfd17c0..7b5f392e 100644 --- a/app/lib/common/widgets/annotation_table.dart +++ b/app/lib/common/widgets/annotation_table.dart @@ -1,9 +1,11 @@ +import '../../drug/widgets/tooltip_icon.dart'; import '../module.dart'; class TableRowDefinition { - const TableRowDefinition(this.key, this.value); + const TableRowDefinition(this.key, this.value, { this.tooltip }); final String key; final String value; + final String? tooltip; } Table buildTable( @@ -21,6 +23,7 @@ Table buildTable( style ?? PharMeTheme.textTheme.bodyMedium!, boldHeader: boldHeader, isLast: index == rowDefinitions.length - 1, + tooltip: rowDefinition.tooltip, )).toList(), ); } @@ -32,6 +35,7 @@ TableRow _buildRow( { required bool boldHeader, required bool isLast, + String? tooltip, } ) { return TableRow( @@ -48,7 +52,20 @@ TableRow _buildRow( : textStyle, ), ), - Text(value, style: textStyle), + Text.rich( + TextSpan( + children: [ + TextSpan(text: value), + if (tooltip.isNotNullOrBlank) ...[ + TextSpan(text: ' '), + WidgetSpan( + child: TooltipIcon(tooltip!), + ), + ], + ], + style: textStyle, + ), + ), ], ); } \ No newline at end of file diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index 68020e06..17154f39 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -103,6 +103,11 @@ } }, + "inhibitor_message": "One or more of the medications you are currently taking may interact with your genetic result", + "inhibitors_consequence_adapted": "phenotype adapted from {originalPhenotype}", + "inhibitors_consequence_not_adapted": "phenotype not adapted", + "inhibitors_tooltip": "Current interacting medications: {inhibitors}", + "drugs_page_inhibitor_direct_salutation": "you are", "drugs_page_inhibitor_direct_salutation_genitive": "your", "drugs_page_inhibitor_third_person_salutation": "the user is", @@ -271,8 +276,6 @@ } }, "gene_page_no_relevant_drugs": "This gene has no known effect on any medications.", - "gene_page_inhibitor_drugs": "The following medications can interact with your results for this gene:", - "gene_page_further_inhibitor_drugs": "The following medications can also interact with your results for this gene:", "gene_page_activity_score": "Activity score", diff --git a/app/lib/report/pages/gene.dart b/app/lib/report/pages/gene.dart index 37cc3ce6..bc30cb32 100644 --- a/app/lib/report/pages/gene.dart +++ b/app/lib/report/pages/gene.dart @@ -61,11 +61,13 @@ class GenePage extends HookWidget { _buildPhenotypeRow(context), ], ), - if (isInhibited(genotypeResult)) - ...buildDrugInteractionInfo( + if (isInhibited(genotypeResult)) ...[ + SizedBox(height: PharMeTheme.smallSpace), + buildDrugInteractionInfo( context, genotypeResult, ), + ] ], )), SizedBox(height: PharMeTheme.smallToMediumSpace), @@ -117,54 +119,4 @@ class GenePage extends HookWidget { ), Padding(padding: EdgeInsets.fromLTRB(0, 4, 0, 4), child: Text(value)), ]); - - List buildDrugInteractionInfo( - BuildContext context, - GenotypeResult genotypeResult, - ) { - final phenotypeInformation = UserData.phenotypeInformationFor( - genotypeResult, - context, - useLongPrefix: true, - ); - if (phenotypeInformation.adaptionText.isNotNullOrBlank) { - final furtherInhibitors = inhibitorsFor(genotypeResult.gene).filter( - (drugName) => - !UserData.activeInhibitorsFor(genotypeResult.gene).contains(drugName) - ); - var phenotypeInformationText = ''; - if (phenotypeInformation.overwrittenPhenotypeText.isNotNullOrBlank) { - phenotypeInformationText = '${formatAsSentence( - phenotypeInformation.overwrittenPhenotypeText! - )} '; - } - phenotypeInformationText = '$phenotypeInformationText${formatAsSentence( - phenotypeInformation.adaptionText! - )}'; - return [ - SizedBox(height: PharMeTheme.smallSpace), - buildTable( - [TableRowDefinition( - drugInteractionIndicator, - phenotypeInformationText, - )], - boldHeader: false, - ), - SizedBox(height: PharMeTheme.smallSpace), - Text(context.l10n.gene_page_further_inhibitor_drugs), - SizedBox(height: PharMeTheme.smallSpace), - Text( - furtherInhibitors.join(', ') - ), - ]; - } - return [ - SizedBox(height: PharMeTheme.smallSpace), - Text(context.l10n.gene_page_inhibitor_drugs), - SizedBox(height: PharMeTheme.smallSpace), - Text( - inhibitorsFor(genotypeResult.gene).join(', ') - ), - ]; - } }