Skip to content

Commit

Permalink
feat(app): add current medication gene list
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 28, 2024
1 parent 06f0480 commit 536e135
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 24 deletions.
18 changes: 18 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,24 @@
}
}
},
"report_current_medications": "Gene report for current medication interactions ({geneNumber} genes)",
"@report_current_medications": {
"placeholders": {
"geneNumber": {
"type": "int",
"example": "3"
}
}
},
"report_all_medications": "Gene report for all known medication interactions ({geneNumber} genes)",
"@report_all_medications": {
"placeholders": {
"geneNumber": {
"type": "int",
"example": "19"
}
}
},
"report_no_result_genes": "Genes with no result",
"@report_no_result_genes": {},

Expand Down
89 changes: 65 additions & 24 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,38 @@ class ReportPage extends StatelessWidget {
).values.sum();
}

Widget _buildReportPage(BuildContext context, ActiveDrugs activeDrugs) {
final userGenotypes = UserData.instance.genotypeResults!.values;
List<Drug> _getAffectedDrugs(
String genotypeResultKey,
{
List<String>? drugSubset,
}) {
final allAffectedDrugs = DrugsWithGuidelines.instance.drugs?.filter(
(drug) => drug.guidelineGenotypes.contains(genotypeResultKey)
).toList() ?? [];
if (drugSubset != null) {
return allAffectedDrugs.filter(
(drug) => drugSubset.contains(drug.name)
).toList();
}
return allAffectedDrugs;
}

List<Widget> _buildGeneCards({ List<String>? drugsToFilterBy }) {
final userGenotypes = drugsToFilterBy != null
? UserData.instance.genotypeResults!.values.filter((genotypeResult) =>
_getAffectedDrugs(
genotypeResult.key.value,
drugSubset: drugsToFilterBy,
).isNotEmpty
)
: UserData.instance.genotypeResults!.values;
final warningLevelCounts = <String, WarningLevelCounts>{};
for (final genotypeResult in userGenotypes) {
warningLevelCounts[genotypeResult.key.value] = {};
final affectedDrugs = DrugsWithGuidelines.instance.drugs?.filter(
(drug) => drug.guidelineGenotypes.contains(genotypeResult.key.value)
) ?? [];
final affectedDrugs = _getAffectedDrugs(
genotypeResult.key.value,
drugSubset: drugsToFilterBy,
);
for (final warningLevel in WarningLevel.values) {
warningLevelCounts[genotypeResult.key.value]![warningLevel] =
affectedDrugs.filter(
Expand All @@ -51,10 +75,18 @@ class ReportPage extends StatelessWidget {
),
);
}
final sortedGenotypesWithResults = sortedGenotypes.filter(
(genotypeResult) => !_hasNoResult(genotypeResult)
);
final sortedGenotypesWithoutResults = sortedGenotypes.filter(_hasNoResult);
return sortedGenotypes.map((genotypeResult) =>
GeneCard(
genotypeResult,
warningLevelCounts[genotypeResult.key.value]!,
key: Key('gene-card-${genotypeResult.key.value}')
)
).toList();
}

Widget _buildReportPage(BuildContext context, ActiveDrugs activeDrugs) {
final currentMedicationGeneCards = _buildGeneCards(drugsToFilterBy: activeDrugs.names);
final allGeneCards = _buildGeneCards();
final hasActiveInhibitors = activeDrugs.names.any(isInhibitor);
return PopScope(
canPop: false,
Expand All @@ -78,25 +110,34 @@ class ReportPage extends StatelessWidget {
]
),
),
...sortedGenotypesWithResults.map((genotypeResult) => GeneCard(
genotypeResult,
warningLevelCounts[genotypeResult.key.value]!,
key: Key('gene-card-${genotypeResult.key.value}')
)),
if (sortedGenotypesWithoutResults.isNotEmpty) ...[
if (currentMedicationGeneCards.isNotEmpty) ...[
SubheaderDivider(
text: context.l10n.report_no_result_genes,
key: Key('header-no-result'),
text: context.l10n.report_current_medications(
currentMedicationGeneCards.length,
),
key: Key('header-current'),
useLine: false,
),
...sortedGenotypesWithoutResults.map((genotypeResult) =>
GeneCard(
genotypeResult,
warningLevelCounts[genotypeResult.key.value]!,
key: Key('gene-card-${genotypeResult.key.value}')
)
),
...currentMedicationGeneCards,
],
if (
allGeneCards.isNotEmpty &&
currentMedicationGeneCards.isNotEmpty
) PrettyExpansionTile(
key: Key('header-all'),
title: SubheaderDivider(
text: context.l10n.report_all_medications(
allGeneCards.length,
),
useLine: false,
),
initiallyExpanded: true,
visualDensity: VisualDensity.compact,
titlePadding: EdgeInsets.zero,
childrenPadding: EdgeInsets.zero,
children: allGeneCards,
),
if (currentMedicationGeneCards.isEmpty) ...allGeneCards,
],
),
if (hasActiveInhibitors) PageIndicatorExplanation(
Expand Down

0 comments on commit 536e135

Please sign in to comment.