Skip to content

Commit

Permalink
refactor(#706): make drug required in phenoconversion functions
Browse files Browse the repository at this point in the history
... so that we do not forget it at some point but rather
explicitly set drug to null
  • Loading branch information
tamslo committed Sep 5, 2024
1 parent 96b6cfa commit 836d4ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
26 changes: 12 additions & 14 deletions app/lib/common/models/drug/drug_inhibitors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ String _getPhenoconversionConsequence(
BuildContext context,
GenotypeResult genotypeResult,
{
String? drug,
required String? drug,
required _DisplayConfig displayConfig,
}
) {
Expand All @@ -126,7 +126,7 @@ String _getPhenoconversionConsequence(
String _getInhibitorsString(
BuildContext context,
GenotypeResult genotypeResult,
{ String? drug }
{ required String? drug }
) {
return context.l10n.inhibitors_tooltip(enumerationWithAnd(
getDrugsWithBrandNames(_activeInhibitorsFor(
Expand All @@ -141,7 +141,7 @@ String _inhibitionTooltipText(
BuildContext context,
GenotypeResult genotypeResult,
{
String? drug,
required String? drug,
required _DisplayConfig displayConfig,
}
) {
Expand Down Expand Up @@ -179,7 +179,7 @@ Table _drugInteractionTemplate(
);
}

List<String> _activeInhibitorsFor(String gene, { String? drug }) {
List<String> _activeInhibitorsFor(String gene, { required String? drug }) {
return UserData.instance.activeDrugNames == null
? <String>[]
: UserData.instance.activeDrugNames!.filter(
Expand All @@ -206,7 +206,7 @@ bool isInhibitor(String drugName) {

bool isInhibited(
GenotypeResult genotypeResult,
{ String? drug }
{ required String? drug }
) {
final activeInhibitors = _activeInhibitorsFor(
genotypeResult.gene,
Expand All @@ -226,7 +226,7 @@ List<String> inhibitedGenes(Drug drug) {

MapEntry<String, String>? getOverwrittenLookup (
String gene,
{ String? drug }
{ required String? drug }
) {
final inhibitors = strongDrugInhibitors[gene];
if (inhibitors == null) return null;
Expand All @@ -242,7 +242,7 @@ MapEntry<String, String>? getOverwrittenLookup (

String possiblyAdaptedPhenotype(
GenotypeResult genotypeResult,
{ String? drug }
{ required String? drug }
) {
final originalPhenotype = genotypeResult.phenotypeDisplayString;
if (!isInhibited(genotypeResult, drug: drug)) {
Expand All @@ -262,24 +262,24 @@ String inhibitionTooltipText(
BuildContext context,
List<GenotypeResult> genotypeResults,
{
String? drug,
String partSeparator = '\n\n',
required String? drug,
bool userFacing = true,
}
) {
final displayConfig = _getDisplayConfig(context, userFacing: userFacing);
final inhibitedGenotypeResults = genotypeResults.filter(
(genotypeResult) => isInhibited(genotypeResult, drug: drug)
).toList();
var tooltipText = '';
for (final (index, genotypeResult) in inhibitedGenotypeResults.indexed) {
final separator = index == 0 ? '' : partSeparator;
final separator = index == 0 ? '' : displayConfig.partSeparator;
// ignore: use_string_buffers
tooltipText = '$tooltipText$separator${
_inhibitionTooltipText(
context,
genotypeResult,
drug: drug,
displayConfig: _getDisplayConfig(context, userFacing: userFacing),
displayConfig: displayConfig,
)
}';
}
Expand All @@ -289,9 +289,7 @@ String inhibitionTooltipText(
Table buildDrugInteractionInfo(
BuildContext context,
List<GenotypeResult> genotypeResults,
{
String? drug,
}
{ required String? drug }
) {
return _drugInteractionTemplate(
context,
Expand Down
5 changes: 3 additions & 2 deletions app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class GenePage extends HookWidget {
_buildPhenotypeRow(context),
],
),
if (isInhibited(genotypeResult)) ...[
if (isInhibited(genotypeResult, drug: null)) ...[
SizedBox(height: PharMeTheme.smallSpace),
buildDrugInteractionInfo(
context,
[genotypeResult],
drug: null,
),
]
],
Expand Down Expand Up @@ -93,7 +94,7 @@ class GenePage extends HookWidget {
TableRow _buildPhenotypeRow(BuildContext context) {
return _buildRow(
context.l10n.gene_page_phenotype,
possiblyAdaptedPhenotype(genotypeResult),
possiblyAdaptedPhenotype(genotypeResult, drug: null),
tooltip:
context.l10n.gene_page_phenotype_tooltip,
);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class GeneCard extends StatelessWidget {
),
SizedBox(height: 8),
Text(
possiblyAdaptedPhenotype(genotypeResult),
possiblyAdaptedPhenotype(genotypeResult, drug: null),
style: PharMeTheme.textTheme.titleSmall,
),
],
Expand Down

0 comments on commit 836d4ed

Please sign in to comment.