From 387ebfd23b0172a3d46a91f9fdb7b03821a116c9 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Tue, 5 Dec 2023 14:45:44 +0100 Subject: [PATCH] feat(#674): add indicators to gene cards --- app/lib/common/models/drug/drug.dart | 11 ++++++ app/lib/common/utilities/color_utils.dart | 10 ++++++ app/lib/report/pages/report.dart | 44 +++++++++++++++++++++-- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 app/lib/common/utilities/color_utils.dart diff --git a/app/lib/common/models/drug/drug.dart b/app/lib/common/models/drug/drug.dart index e962bf98..64f36920 100644 --- a/app/lib/common/models/drug/drug.dart +++ b/app/lib/common/models/drug/drug.dart @@ -91,6 +91,17 @@ extension DrugWithUserGuideline on Drug { ); } +extension DrugGuidelineGenes on Drug { + List get guidelineGenes => guidelines.isNotEmpty + ? guidelines.first.lookupkey.keys.toList() + : []; +} + +extension DrugWarningLevel on Drug { + WarningLevel get warningLevel => + userGuideline()?.annotations.warningLevel ?? WarningLevel.none; +} + /// Filters for drugs with non-OK warning level extension CriticalDrugs on List { List filterCritical() { diff --git a/app/lib/common/utilities/color_utils.dart b/app/lib/common/utilities/color_utils.dart new file mode 100644 index 00000000..e239cb53 --- /dev/null +++ b/app/lib/common/utilities/color_utils.dart @@ -0,0 +1,10 @@ + +import '../module.dart'; + +// From https://stackoverflow.com/a/58604669 +Color darkenColor(Color color, [double amount = 0.1]) { + assert(amount >= 0 && amount <= 1); + final hsl = HSLColor.fromColor(color); + final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0)); + return hslDark.toColor(); +} \ No newline at end of file diff --git a/app/lib/report/pages/report.dart b/app/lib/report/pages/report.dart index 3bb42c38..706e201f 100644 --- a/app/lib/report/pages/report.dart +++ b/app/lib/report/pages/report.dart @@ -1,6 +1,8 @@ import 'package:provider/provider.dart'; +import '../../common/models/drug/cached_drugs.dart'; import '../../common/module.dart'; +import '../../common/utilities/color_utils.dart'; import '../../common/utilities/guideline_utils.dart'; class ReportPage extends StatelessWidget { @@ -79,6 +81,35 @@ class GeneCard extends StatelessWidget { final phenotypeText = phenotypeInformation.adaptionText.isNullOrBlank ? phenotypeInformation.phenotype : '${phenotypeInformation.phenotype}$drugInteractionIndicator'; + final affectedDrugs = CachedDrugs.instance.drugs?.filter( + (drug) => drug.guidelineGenes.contains(phenotype.geneSymbol) + ) ?? []; + final warningLevelIndicators = WarningLevel.values.map( + (warningLevel) { + final warningLevelCount = affectedDrugs.filter( + (drug) => drug.warningLevel == warningLevel + ).length; + final textColor = darkenColor(warningLevel.color, 0.4); + return warningLevelCount > 0 + ? Row( + textDirection: TextDirection.ltr, + children: [ + Icon( + warningLevel.icon, + size: PharMeTheme.mediumSpace, + color: textColor, + ), + SizedBox(width: PharMeTheme.smallSpace / 2), + Text( + warningLevelCount.toString(), + style: TextStyle(color: textColor), + ), + SizedBox(width: PharMeTheme.smallSpace), + ] + ) + : SizedBox.shrink(); + } + ).toList(); return RoundedCard( onTap: () => context.router.push(GeneRoute(phenotype: phenotype)), padding: EdgeInsets.all(8), @@ -93,9 +124,16 @@ class GeneCard extends StatelessWidget { style: PharMeTheme.textTheme.titleMedium ), SizedBox(height: 8), - Text( - phenotypeText, - style: PharMeTheme.textTheme.titleSmall), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + phenotypeText, + style: PharMeTheme.textTheme.titleSmall + ), + Row(children: warningLevelIndicators), + ], + ), ], ), ),