Skip to content

Commit

Permalink
feat(#674): add indicators to gene cards
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Dec 5, 2023
1 parent ddfdfa2 commit 387ebfd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ extension DrugWithUserGuideline on Drug {
);
}

extension DrugGuidelineGenes on Drug {
List<String> 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<Drug> {
List<Drug> filterCritical() {
Expand Down
10 changes: 10 additions & 0 deletions app/lib/common/utilities/color_utils.dart
Original file line number Diff line number Diff line change
@@ -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();
}
44 changes: 41 additions & 3 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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),
],
),
],
),
),
Expand Down

0 comments on commit 387ebfd

Please sign in to comment.