Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#637): show unknown guidelines as green #659

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/lib/common/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

Uri anniUrl([String slug = '']) =>
Expand All @@ -22,7 +21,6 @@ final cpicMaxCacheTime = Duration(days: 90);
const maxCachedDrugs = 10;
const cpicLookupUrl =
'https://api.cpicpgx.org/v1/diplotype?select=genesymbol,diplotype,generesult,lookupkey';
const indeterminateIcon = Icons.help_outline_rounded;

const drugInteractionIndicator = '*';
const drugInteractionIndicatorName = 'asterisk';
6 changes: 4 additions & 2 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'package:hive/hive.dart';

import '../../module.dart';
import '../../utilities/guideline_utils.dart';

part 'drug.g.dart';

Expand Down Expand Up @@ -92,8 +93,9 @@
extension CriticalDrugs on List<Drug> {
List<Drug> filterCritical() {
return filter((drug) {
final warningLevel = drug.userGuideline()?.annotations.warningLevel;
return warningLevel != null && warningLevel != WarningLevel.green;
final warningLevel = getWarningLevel(drug.userGuideline());
return warningLevel != WarningLevel.none &&
warningLevel != WarningLevel.green;

Check warning on line 98 in app/lib/common/models/drug/drug.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/common/models/drug/drug.dart#L96-L98

Added lines #L96 - L98 were not covered by tests
}).toList();
}
}
3 changes: 2 additions & 1 deletion app/lib/common/models/drug/warning_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension WarningLevelIcon on WarningLevel {
WarningLevel.red.name: Icons.dangerous_rounded,
WarningLevel.yellow.name: Icons.warning_rounded,
WarningLevel.green.name: Icons.check_circle_rounded,
WarningLevel.none.name: Icons.help_outline_rounded,
};

IconData get icon => WarningLevelIcon._iconMap[name]!;
Expand All @@ -30,7 +31,7 @@ extension WarningLevelSeverity on WarningLevel {
WarningLevel.red.name: 2,
WarningLevel.yellow.name: 1,
WarningLevel.green.name: 0,
WarningLevel.none.name: -1,
WarningLevel.none.name: 0,
};
int get severity => WarningLevelSeverity._severityMap[name]!;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:url_launcher/url_launcher.dart';

import '../../../../module.dart';
import '../../../../utilities/guideline_utils.dart';
import '../sub_header.dart';

class GuidelineAnnotationCard extends StatelessWidget {
Expand Down Expand Up @@ -35,7 +36,7 @@ class GuidelineAnnotationCard extends StatelessWidget {
}

Widget _buildCard(BuildContext context) {
final warningLevel = guideline?.annotations.warningLevel;
final warningLevel = getWarningLevel(guideline);
final upperCardText = guideline?.annotations.implication ??
context.l10n.drugs_page_no_guidelines_for_phenotype_implication(
drug!.name
Expand All @@ -47,14 +48,13 @@ class GuidelineAnnotationCard extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
color: warningLevel?.color ?? PharMeTheme.indeterminateColor,
color: warningLevel.color,
child: Padding(
padding: EdgeInsets.all(12),
child:
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(children: [
Icon(warningLevel?.icon ?? indeterminateIcon,
color: PharMeTheme.onSurfaceText),
Icon(warningLevel.icon, color: PharMeTheme.onSurfaceText),
SizedBox(width: 12),
Flexible(
child: Text(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class PharMeTheme {

static const surfaceColor = Colors.white;
static const onSurfaceColor = Color(0xffe5e5e5);
static const indeterminateColor = onSurfaceColor;
static const onSurfaceText = Color(0xff444648);
static const backgroundColor = Colors.white;
static const errorColor = Color(0xccf52a2a);
Expand Down Expand Up @@ -104,6 +103,7 @@ extension WarningLevelColor on WarningLevel {
WarningLevel.red.name: Color(0xffffafaf),
WarningLevel.yellow.name: Color(0xffffebcc),
WarningLevel.green.name: Color(0xffcfe8cf),
WarningLevel.none.name: Color(0xffcfe8cf),
};

Color get color => WarningLevelColor._colorMap[name]!;
Expand Down
4 changes: 4 additions & 0 deletions app/lib/common/utilities/guideline_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import '../module.dart';

WarningLevel getWarningLevel(Guideline? guideline) =>
guideline?.annotations.warningLevel ?? WarningLevel.none;
14 changes: 6 additions & 8 deletions app/lib/common/widgets/drug_list/drug_items/drug_cards.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../../../module.dart';
import '../../../utilities/guideline_utils.dart';
import 'utils.dart';

List<Widget> buildDrugCards(
Expand All @@ -9,11 +10,8 @@ List<Widget> buildDrugCards(
bool showDrugInteractionIndicator = false,
}
) {
int warningLevelSeverity(Drug drug) {
final warningLevel = drug.userGuideline()?.annotations.warningLevel
?? WarningLevel.none;
return warningLevel.severity;
}
int warningLevelSeverity(Drug drug) =>
getWarningLevel(drug.userGuideline()).severity;
drugs.sort((drugA, drugB) {
final warningLevelComparison = -warningLevelSeverity(drugA)
.compareTo(warningLevelSeverity(drugB));
Expand Down Expand Up @@ -45,15 +43,15 @@ class DrugCard extends StatelessWidget {

@override
Widget build(BuildContext context) {
final warningLevel = drug.userGuideline()?.annotations.warningLevel;
final warningLevel = getWarningLevel(drug.userGuideline());
final drugName = formatDrugName(drug, showDrugInteractionIndicator);
return Padding(
padding: EdgeInsets.symmetric(vertical: PharMeTheme.smallSpace / 2),
child: RoundedCard(
onTap: onTap,
padding: EdgeInsets.all(8),
radius: 16,
color: warningLevel?.color ?? PharMeTheme.indeterminateColor,
color: warningLevel.color,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand All @@ -62,7 +60,7 @@ class DrugCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Icon(warningLevel?.icon ?? indeterminateIcon),
Icon(warningLevel.icon),
SizedBox(width: 4),
Text(
drugName,
Expand Down
4 changes: 2 additions & 2 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"search_page_filter_green": "Show green warning level",
"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_filter_gray": "Show drugs without guidelines",
"search_page_indicator_explanation": "Taking drugs with an {indicatorName} ({indicator}) can influence your results for other drugs",
"@search_page_indicator_explanation": {
"description": "Explanation of drug-drug interaction indicators",
Expand Down Expand Up @@ -111,7 +111,7 @@
}
}
},
"drugs_page_no_guidelines_for_phenotype_recommendation": "No recommendation can be made at this time. Consult your pharmacist or doctor for more information.",
"drugs_page_no_guidelines_for_phenotype_recommendation": "Clinical dosing applies; no pharmacogenetic recommendation can be made at this time. Consult your pharmacist or doctor for more information.",
"drugs_page_sources_description": "Tap here to review the corresponding guideline published by {source}",
"@drugs_page_sources_description": {
"description": "Instructions to open external source",
Expand Down
Loading