Skip to content

Commit

Permalink
refactor(app): add constant SpecialLookups
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 23, 2024
1 parent 0743cad commit fda8d9f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
17 changes: 17 additions & 0 deletions app/lib/common/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ const cpicLookupUrl =

const drugInteractionIndicator = '*';
const drugInteractionIndicatorName = 'asterisk';

enum SpecialLookup {
any,
anyNotHandled,
noResult,
}

extension SpecialLookupValue on SpecialLookup {
String get value {
final valueMap = {
SpecialLookup.any: '*',
SpecialLookup.anyNotHandled: '~',
SpecialLookup.noResult: 'No Result',
};
return valueMap[this]!;
}
}
16 changes: 11 additions & 5 deletions app/lib/common/models/drug/drug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension DrugExtension on Drug {
Guideline? _getExactGuideline() {
final exactGuidelines = guidelines.filter(
(guideline) => guideline.lookupkey.none(
(gene, variants) => variants.contains('~')
(gene, variants) => variants.contains(SpecialLookup.anyNotHandled.value)
)
);
return exactGuidelines.firstOrNullWhere(
Expand All @@ -102,7 +102,7 @@ extension DrugExtension on Drug {
if (guidelines.isEmpty) return null;
final partialGuidelines = guidelines.filter(
(guideline) => guideline.lookupkey.values.any(
(values) => values.contains('~'),
(values) => values.contains(SpecialLookup.anyNotHandled.value),
),
);
if (partialGuidelines.isEmpty) return null;
Expand All @@ -118,7 +118,9 @@ extension DrugExtension on Drug {
(guideline) => guideline.lookupkey.all(
(gene, variants) => geneCombination.contains(gene)
? _lookupsMatchUserData(gene, variants)
: variants.any((variant) => variant == '~'),
: variants.any(
(variant) => variant == SpecialLookup.anyNotHandled.value
),
),
);
}
Expand All @@ -130,7 +132,9 @@ extension DrugExtension on Drug {
Guideline? get userGuideline {
final anyFallbackGuideline = guidelines.firstOrNullWhere(
(guideline) => guideline.lookupkey.all(
(gene, variants) => variants.any((variant) => variant == '*')
(gene, variants) => variants.any(
(variant) => variant == SpecialLookup.any.value
)
),
);
if (anyFallbackGuideline != null) return anyFallbackGuideline;
Expand All @@ -140,7 +144,9 @@ extension DrugExtension on Drug {
if (partiallyHandledGuideline != null) return partiallyHandledGuideline;
return guidelines.firstOrNullWhere(
(guideline) => guideline.lookupkey.all(
(gene, variants) => variants.any((variant) => variant == '~')
(gene, variants) => variants.any(
(variant) => variant == SpecialLookup.anyNotHandled.value
)
),
);
}
Expand Down

0 comments on commit fda8d9f

Please sign in to comment.