Skip to content

Commit

Permalink
feat(app): make unknown results italic
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Jan 23, 2025
1 parent 70fcdf5 commit a1d9737
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 29 deletions.
7 changes: 7 additions & 0 deletions app/lib/common/constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

import 'module.dart';

const medicationsIcon = FontAwesomeIcons.pills;
const genesIcon = FontAwesomeIcons.dna;

Expand Down Expand Up @@ -32,6 +34,11 @@ enum SpecialLookup {
noResult,
}

List<String> unknownPhenotypes(BuildContext context) => [
'Indeterminate',
context.l10n.general_not_tested,
];

extension SpecialLookupValue on SpecialLookup {
String get value {
final valueMap = {
Expand Down
60 changes: 47 additions & 13 deletions app/lib/common/widgets/annotation_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ class TableRowDefinition {
{
this.keyTooltip,
this.valueTooltip,
this.italicValue = false,
}
);

final String key;
final String value;
final String? keyTooltip;
final String? valueTooltip;
final bool italicValue;
}

Widget buildTable(
List<TableRowDefinition> rowDefinitions,
{
TextStyle? style,
bool boldKey = true,
bool italicValue = false,
}
) {
return Column(
Expand All @@ -32,13 +33,10 @@ Widget buildTable(
defaultColumnWidth: IntrinsicColumnWidth(),
children: [
_buildRow(
rowDefinition.key,
rowDefinition.value,
rowDefinition,
style ?? PharMeTheme.textTheme.bodyMedium!,
boldKey: boldKey,
isLast: index == rowDefinitions.length - 1,
keyTooltip: rowDefinition.keyTooltip,
valueTooltip: rowDefinition.valueTooltip,
),
],
),
Expand All @@ -47,14 +45,11 @@ Widget buildTable(
}

TableRow _buildRow(
String key,
String value,
TableRowDefinition rowDefinition,
TextStyle textStyle,
{
required bool boldKey,
required bool isLast,
String? keyTooltip,
String? valueTooltip,
}
) {
return TableRow(
Expand All @@ -67,8 +62,8 @@ TableRow _buildRow(
child: Text.rich(
TextSpan(
children: [
TextSpan(text: key),
..._maybeBuildTooltip(keyTooltip),
TextSpan(text: rowDefinition.key),
..._maybeBuildTooltip(rowDefinition.keyTooltip),
],
style: boldKey
? textStyle.copyWith(fontWeight: FontWeight.bold)
Expand All @@ -79,8 +74,13 @@ TableRow _buildRow(
Text.rich(
TextSpan(
children: [
TextSpan(text: value),
..._maybeBuildTooltip(valueTooltip),
TextSpan(
text: rowDefinition.value,
style: rowDefinition.italicValue
? textStyle.copyWith(fontStyle: FontStyle.italic)
: textStyle,
),
..._maybeBuildTooltip(rowDefinition.valueTooltip),
],
style: textStyle,
),
Expand All @@ -100,4 +100,38 @@ List<WidgetSpan> _maybeBuildTooltip(String? tooltip) {
WidgetSpan(child: SizedBox(height: tooltipSize)),
]
: [];
}

bool testResultIsUnknown(BuildContext context, String phenotype) =>
unknownPhenotypes(context).contains(phenotype);

TableRowDefinition testResultTableRow(
BuildContext context,
{
required String key,
required String value,
String? keyTooltip,
}
) => TableRowDefinition(
key,
value,
keyTooltip: keyTooltip,
italicValue: testResultIsUnknown(context, value),
);

TableRowDefinition phenotypeTableRow(
BuildContext context,
{
required String key,
required GenotypeResult genotypeResult,
required String? drug,
String? keyTooltip,
}
) {
return testResultTableRow(
context,
key: key,
value: possiblyAdaptedPhenotype(context, genotypeResult, drug: drug),
keyTooltip: keyTooltip,
);
}
14 changes: 6 additions & 8 deletions app/lib/drug/widgets/annotation_cards/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,12 @@ class GuidelineAnnotationCard extends StatelessWidget {
}
return buildTable(
genotypeResults.map((genotypeResult) =>
TableRowDefinition(
genotypeResult.geneDisplayString,
possiblyAdaptedPhenotype(
context,
genotypeResult,
drug: drug.name,
),
)
phenotypeTableRow(
context,
key: genotypeResult.geneDisplayString,
genotypeResult: genotypeResult,
drug: drug.name,
),
).toList(),
);
}
Expand Down
15 changes: 9 additions & 6 deletions app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ class GenePage extends HookWidget {
}

Widget _buildGeneResults(BuildContext context) => buildTable([
TableRowDefinition(
context.l10n.gene_page_genotype,
genotypeResult.variantDisplayString(context),
testResultTableRow(
context,
key: context.l10n.gene_page_genotype,
value: genotypeResult.variantDisplayString(context),
keyTooltip: context.l10n.gene_page_genotype_tooltip,
),
TableRowDefinition(
context.l10n.gene_page_phenotype,
possiblyAdaptedPhenotype(context, genotypeResult, drug: null),
phenotypeTableRow(
context,
key: context.l10n.gene_page_phenotype,
genotypeResult: genotypeResult,
drug: null,
keyTooltip: context.l10n.gene_page_phenotype_tooltip,
),
]);
Expand Down
13 changes: 11 additions & 2 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ class GeneCard extends StatelessWidget {
),
)
: null;
final phenotype = possiblyAdaptedPhenotype(
context,
genotypeResult,
drug: null,
);
return RoundedCard(
onTap: () async {
// ignore: use_build_context_synchronously
Expand Down Expand Up @@ -391,8 +396,12 @@ class GeneCard extends StatelessWidget {
runSpacing: PharMeTheme.smallSpace * 0.5,
children: [
Text(
possiblyAdaptedPhenotype(context, genotypeResult, drug: null),
style: PharMeTheme.textTheme.titleSmall,
phenotype,
style: testResultIsUnknown(context, phenotype)
? PharMeTheme.textTheme.titleSmall!.copyWith(
fontStyle: FontStyle.italic,
)
: PharMeTheme.textTheme.titleSmall,
),
SizedBox(width: PharMeTheme.smallSpace),
medicationIndicators ?? SizedBox.shrink(),
Expand Down

0 comments on commit a1d9737

Please sign in to comment.