Skip to content

Commit

Permalink
refactor(#674): add allGuidelineGenes as CachedDrugs extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Dec 5, 2023
1 parent c783702 commit 90588f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 14 additions & 0 deletions app/lib/common/models/drug/cached_drugs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ Future<void> initCachedDrugs() async {
final cachedDrugs = Hive.box<CachedDrugs>(_boxName);
CachedDrugs._instance = cachedDrugs.get('data') ?? CachedDrugs();
}

extension CachedDrugsMethods on CachedDrugs {
Set<String> get allGuidelineGenes {
final guidelineGenes = <String>{};
if (CachedDrugs.instance.drugs != null) {
for (final drug in CachedDrugs.instance.drugs!) {
for (final guideline in drug.guidelines) {
guideline.lookupkey.keys.forEach(guidelineGenes.add);
}
}
}
return guidelineGenes;
}
}
9 changes: 1 addition & 8 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ class ReportPage extends StatelessWidget {

Widget _buildReportPage(BuildContext context, ActiveDrugs activeDrugs) {
final hasActiveInhibitors = activeDrugs.names.any(isInhibitor);
final genes = <String>{};
for (final drug in CachedDrugs.instance.drugs!) {
for (final guideline in drug.guidelines) {
guideline.lookupkey.keys.forEach(genes.add);
}
}

final notTestedString = context.l10n.general_not_tested;
final userPhenotypes = genes.map(
final userPhenotypes = CachedDrugs.instance.allGuidelineGenes.map(
(geneSymbol) => UserData.instance.lookups![geneSymbol] ??
CpicPhenotype(
geneSymbol: geneSymbol,
Expand Down

0 comments on commit 90588f4

Please sign in to comment.