Skip to content

Commit

Permalink
feat(app): change display for drugs without guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 19, 2024
1 parent 84d21fa commit 775f52f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 107 deletions.
76 changes: 35 additions & 41 deletions app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,32 @@ void main() {
UserData.instance.activeDrugNames = ['Ibuprofen'];

group('integration test for the drugs page', () {
testWidgets('test loading', (tester) async {
when(() => mockDrugsCubit.state).thenReturn(DrugState.loading());
await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: DrugPage(testDrug, cubit: mockDrugsCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
);
final activitySelection = tester.firstWidget(
find.byType(Switch)
) as Switch;
expect(activitySelection.onChanged, isNull);
});

testWidgets('test loaded page', (tester) async {
when(() => mockDrugsCubit.state)
.thenReturn(DrugState.loaded());

late BuildContext context;

await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
Expand All @@ -107,7 +127,6 @@ void main() {
),
),
);

expect(find.text(testDrug.name.capitalize()), findsOneWidget);
expect(
find.textContaining(
Expand All @@ -133,29 +152,22 @@ void main() {
findsOneWidget,
);
expect(find.byType(Disclaimer), findsOneWidget);

// test the right color of the card
// ignore: omit_local_variable_types
final RoundedCard card = tester.firstWidget(
final card = tester.firstWidget(
find.byKey(
ValueKey('annotationCard'),
),
);
) as RoundedCard;
expect(
card.color,
testDrug.guidelines.first.annotations.warningLevel.color,
);

// test that drug activity can be set
final activitySelection = tester.firstWidget(
find.byType(Switch)
) as Switch;
expect(activitySelection.onChanged, isNotNull);

// test tooltips
context = tester.element(find.byType(Tooltip).first);
final context = tester.element(find.byType(Tooltip).first);
expect(
find.byTooltip(context.l10n.drugs_page_tooltip_guideline(
find.byTooltip(context.l10n.drugs_page_tooltip_guidelines_present(
testDrug.guidelines.first.externalData.first.source
)),
findsOneWidget,
Expand All @@ -165,7 +177,6 @@ void main() {
testWidgets('test loaded page without guidelines', (tester) async {
when(() => mockDrugsCubit.state).thenReturn(
DrugState.loaded());

await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
Expand All @@ -190,33 +201,16 @@ void main() {
),
),
);

expect(find.text(testDrugWithoutGuidelines.name), findsOneWidget);
});

testWidgets('test loading', (tester) async {
when(() => mockDrugsCubit.state).thenReturn(DrugState.loading());

await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: DrugPage(testDrug, cubit: mockDrugsCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
final context = tester.element(find.byType(Scaffold).first);
expect(
find.text(context.l10n.drugs_page_no_guidelines_text),
findsOneWidget,
);
expect(
find.byTooltip(context.l10n.drugs_page_tooltip_guidelines_missing),
findsOneWidget,
);

final activitySelection = tester.firstWidget(
find.byType(Switch)
) as Switch;
expect(activitySelection.onChanged, isNull);
});
});
}
12 changes: 5 additions & 7 deletions app/lib/common/utilities/pdf_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,10 @@ List<pw.Widget> _buildUserPart(
'green': '✅',
null: '❔',
};
final implication = drug.userGuideline?.annotations.implication ??
buildContext.l10n.drugs_page_no_guidelines_for_phenotype_implication(
drug.name
);
final recommendation = drug.userGuideline?.annotations.recommendation ??
buildContext.l10n.drugs_page_no_guidelines_for_phenotype_recommendation;
final userGuidelineText = drug.userGuideline != null
? '${drug.userGuideline?.annotations.implication} '
'${drug.userGuideline?.annotations.recommendation}'
: buildContext.l10n.drugs_page_no_guidelines_text;
return [
_buildSubheading(buildContext.l10n.pdf_heading_user_data),
_buildTextBlockSpacer(),
Expand Down Expand Up @@ -270,7 +268,7 @@ List<pw.Widget> _buildUserPart(
_PdfSegment(
child: _PdfDescription(
title: buildContext.l10n.pdf_user_guideline,
text: '$implication $recommendation',
text: userGuidelineText,
icon: warningLevelIcons[drug.warningLevel.name],
emojiFont: emoji,
),
Expand Down
58 changes: 22 additions & 36 deletions app/lib/drug/widgets/annotation_cards/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ class GuidelineAnnotationCard extends StatelessWidget {
}

Widget _buildCard(BuildContext context) {
final implicationText = drug.userGuideline?.annotations.implication ??
context.l10n.drugs_page_no_guidelines_for_phenotype_implication(
drug.name
);
final recommendationText = drug.userGuideline?.annotations.recommendation ??
context.l10n.drugs_page_no_guidelines_for_phenotype_recommendation;
final implicationText = drug.userGuideline?.annotations.implication;
final recommendationText = drug.userGuideline?.annotations.recommendation;
return RoundedCard(
key: Key('annotationCard'),
radius: PharMeTheme.innerCardRadius,
Expand Down Expand Up @@ -76,46 +72,36 @@ class GuidelineAnnotationCard extends StatelessWidget {
),
SizedBox(height: PharMeTheme.smallToMediumSpace),
Text.rich(
TextSpan(text: implicationText),
),
SizedBox(height: PharMeTheme.smallToMediumSpace),
Text.rich(
TextSpan(children: [
TextSpan(
text: context.l10n.drugs_page_recommendation_description,
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: recommendationText),
]),
TextSpan(
text:
implicationText ?? context.l10n.drugs_page_no_guidelines_text,
),
),
...[
if (recommendationText != null) ...[
SizedBox(height: PharMeTheme.smallToMediumSpace),
Disclaimer(userGuideline: drug.userGuideline),
Text.rich(
TextSpan(children: [
TextSpan(
text: context.l10n.drugs_page_recommendation_description,
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: recommendationText),
]),
),
],
SizedBox(height: PharMeTheme.smallToMediumSpace),
Disclaimer(userGuideline: drug.userGuideline),
]
)
);
}

String _buildGuidelineTooltipText(BuildContext context) {
return drug.userGuideline != null
// Case 1: a guideline is present
? context.l10n.drugs_page_tooltip_guideline(
drug.userGuideline!.externalData.first.source
return drug.userOrFirstGuideline != null
? context.l10n.drugs_page_tooltip_guidelines_present(
drug.userOrFirstGuideline!.externalData.first.source
)
: drug.userOrFirstGuideline != null
// Case 2: a guideline for the drug is present but not for the genotype
? drug.guidelineGenotypes.all(UserData.instance.genotypeResults!.isMissing)
// Case 2.1: all genes are not tested
? context.l10n.drugs_page_tooltip_missing_guideline_not_tested
// Case 2.2: at least some genes tested
: context.l10n.drugs_page_tooltip_missing_guideline_for_drug_or_genotype(
context.l10n.drugs_page_tooltip_missing_genotype
)
// Case 3: the drug has no guidelines
: context.l10n.drugs_page_tooltip_missing_guideline_for_drug_or_genotype(
context.l10n.drugs_page_tooltip_missing_drug
);
: context.l10n.drugs_page_tooltip_guidelines_missing;
}

List<Widget> _buildHeader(BuildContext context) {
Expand Down
26 changes: 3 additions & 23 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,7 @@
"drugs_page_active_warn_header": "Are you sure you want to change the medication usage status?",
"drugs_page_active_warn": "This can interact with your results for other medications.",
"drugs_page_header_guideline": "DNA-based clinical guideline",
"drugs_page_no_guidelines_for_phenotype_implication": "More information is needed to comment on your DNA's influence on {drugName}.",
"@drugs_page_no_guidelines_for_phenotype_implication": {
"placeholders": {
"drugName": {
"type": "String",
"example": "bupropion"
}
}
},
"drugs_page_no_guidelines_for_phenotype_recommendation": "Clinical dosing may apply; no pharmacogenomic recommendation can be made at this time. Consult your pharmacist or doctor for more information.",
"drugs_page_no_guidelines_text": "No pharmacogenomic 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": {
"placeholders": {
Expand All @@ -145,7 +136,7 @@
}
}
},
"drugs_page_tooltip_guideline": "{source} guidelines are used to inform the content on this page. These guidelines provide recommendations on which drugs to use based on your DNA.",
"drugs_page_tooltip_guidelines_present": "{source} guidelines are used to inform the content on this page. These guidelines provide recommendations on which drugs to use based on your DNA.",
"@drugs_page_tooltip_guideline": {
"placeholders": {
"source": {
Expand All @@ -154,18 +145,7 @@
}
}
},
"drugs_page_tooltip_missing_drug": "this medication",
"drugs_page_tooltip_missing_genotype": "your genotype",
"drugs_page_tooltip_missing_guideline_for_drug_or_genotype": "Guidelines provide recommendations on which medications to use based on your DNA. However, no guideline is present for {drugOrGenotype} (yet).",
"@drugs_page_tooltip_missing_guideline_for_drug_or_genotype": {
"placeholders": {
"drugOrGenotype": {
"type": "String",
"example": "this medication"
}
}
},
"drugs_page_tooltip_missing_guideline_not_tested": "Guidelines provide recommendations on which medications to use based on your DNA. However, your genetic test result does not include the information needed to make such a recommendation for this medication.",
"drugs_page_tooltip_guidelines_missing": "Guidelines provide recommendations on which medications to use based on your DNA. However, no guideline is present for this medication (yet).",
"drugs_page_recommendation_description": "What to do: ",

"report_content_explanation": "This is your PGx test report. Tap on a gene name for more details on your results and a list of implicated medications.",
Expand Down

0 comments on commit 775f52f

Please sign in to comment.