Skip to content

Commit

Permalink
refactor(#706): add global isInhibited method
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 4, 2024
1 parent cea0f29 commit 7fba3f0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
27 changes: 18 additions & 9 deletions app/lib/common/models/userdata/userdata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ part 'userdata.g.dart';

const _boxName = 'userdata';

const overwritePhenotype = 'Poor Metabolizer';

/// UserData is a singleton data-class which contains various user-specific
/// data It is intended to be loaded from a Hive box once at app launch, from
/// where it's contents can be modified by accessing it's properties.
Expand Down Expand Up @@ -61,17 +63,9 @@ class UserData {
genotypeResult.gene,
drug: drug,
);
if (activeInhibitors.isEmpty) {
if (!isInhibited(genotypeResult, drug: drug)) {
return PhenotypeInformation(phenotype: originalPhenotype);
}
final overwritePhenotype = context.l10n.general_poor_metabolizer;
final currentPhenotypeEqualsOverwritePhenotype =
originalPhenotype.toLowerCase() == overwritePhenotype.toLowerCase();
if (currentPhenotypeEqualsOverwritePhenotype) {
return PhenotypeInformation(
phenotype: originalPhenotype,
);
}
final overwrittenLookup = UserData.overwrittenLookup(
genotypeResult.gene,
drug: drug,
Expand Down Expand Up @@ -235,3 +229,18 @@ List<String> activeDrugsFromHTTPResponse(Response resp) {
}
return activeDrugs;
}

bool isInhibited(
GenotypeResult genotypeResult,
{ String? drug }
) {
final activeInhibitors = UserData.activeInhibitorsFor(
genotypeResult.gene,
drug: drug,
);
final originalPhenotype = genotypeResult.phenotypeDisplayString;
final phenotypeCanBeInhibited =
originalPhenotype.toLowerCase() != overwritePhenotype.toLowerCase();
return activeInhibitors.isNotEmpty && phenotypeCanBeInhibited;
}

1 change: 0 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"general_continue": "Continue",
"general_retry": "Retry",
"general_and": "and",
"general_poor_metabolizer": "Poor Metabolizer",
"general_not_tested": "Not tested",

"warning_level_green": "Standard precautions",
Expand Down
21 changes: 4 additions & 17 deletions app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ class GenePage extends HookWidget {
final GenotypeResult genotypeResult;
final DrugListCubit cubit;

bool _isInhibited(BuildContext context, GenotypeResult genotypeResult) {
final phenotypeInformation = UserData.phenotypeInformationFor(
genotypeResult,
context,
);
return phenotypeInformation.overwrittenPhenotypeText.isNotNullOrBlank;
}


@override
Widget build(BuildContext context) {
return Consumer<ActiveDrugs>(
Expand Down Expand Up @@ -70,7 +61,7 @@ class GenePage extends HookWidget {
_buildPhenotypeRow(context),
],
),
if (_isInhibited(context, genotypeResult))
if (isInhibited(genotypeResult))
...buildDrugInteractionInfo(
context,
genotypeResult,
Expand Down Expand Up @@ -98,13 +89,9 @@ class GenePage extends HookWidget {
}

TableRow _buildPhenotypeRow(BuildContext context) {
final phenotypeInformation = UserData.phenotypeInformationFor(
genotypeResult,
context,
);
final phenotypeText = phenotypeInformation.adaptionText.isNotNullOrBlank
? '${phenotypeInformation.phenotype}$drugInteractionIndicator'
: phenotypeInformation.phenotype;
final phenotypeText = isInhibited(genotypeResult)
? '${genotypeResult.phenotypeDisplayString}$drugInteractionIndicator'
: genotypeResult.phenotypeDisplayString;
return _buildRow(
context.l10n.gene_page_phenotype,
phenotypeText,
Expand Down
10 changes: 3 additions & 7 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,9 @@ class GeneCard extends StatelessWidget {

@override
Widget build(BuildContext context) {
final phenotypeInformation = UserData.phenotypeInformationFor(
genotypeResult,
context,
);
final phenotypeText = phenotypeInformation.adaptionText.isNullOrBlank
? phenotypeInformation.phenotype
: '${phenotypeInformation.phenotype}$drugInteractionIndicator';
final phenotypeText = isInhibited(genotypeResult)
? genotypeResult.phenotypeDisplayString
: '${genotypeResult.phenotypeDisplayString}$drugInteractionIndicator';
final hasLegend = warningLevelCounts.values.any((count) => count > 0);
return RoundedCard(
onTap: () => context.router.push(
Expand Down

0 comments on commit 7fba3f0

Please sign in to comment.