Skip to content

Commit

Permalink
feat(app): use expansion tile for inhibition info
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Dec 5, 2024
1 parent fd4f0f3 commit 8437cb1
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 108 deletions.
26 changes: 16 additions & 10 deletions app/lib/common/models/drug/drug_inhibitors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,22 @@ Widget _drugInteractionTemplate(
String tooltipText,
_DisplayConfig displayConfig,
) {
return buildTable([
TableRowDefinition(
drugInteractionIndicator,
context.l10n.inhibitor_message(
displayConfig.userSalutation,
displayConfig.userGenitive,
),
tooltip: tooltipText,
)],
boldHeader: false,
return PrettyExpansionTile(
title: buildTable([
TableRowDefinition(
drugInteractionIndicator,
context.l10n.inhibitor_message(
displayConfig.userSalutation,
displayConfig.userGenitive,
),
)],
boldHeader: false,
),
titlePadding: EdgeInsets.zero,
childrenPadding: EdgeInsets.all(PharMeTheme.smallSpace),
children: [
Text(tooltipText),
],
);
}

Expand Down
211 changes: 113 additions & 98 deletions app/lib/drug/widgets/annotation_cards/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ class GuidelineAnnotationCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (drug.guidelines.isNotEmpty) ...[
..._buildHeader(context),
SizedBox(height: PharMeTheme.mediumSpace),
_buildCard(context),
SizedBox(height: PharMeTheme.smallSpace),
_buildResultSection(context),
SizedBox(height: PharMeTheme.smallToMediumSpace),
_buildSourcesSection(context),
SizedBox(height: PharMeTheme.smallSpace),
SizedBox(height: PharMeTheme.smallToMediumSpace),
Disclaimer(userGuideline: drug.userGuideline),
]
else ...[
..._buildHeader(context),
SizedBox(height: PharMeTheme.smallSpace),
_buildCard(context),
_buildResultSection(context),
],
],
),
Expand All @@ -45,73 +41,79 @@ class GuidelineAnnotationCard extends StatelessWidget {
);
}

Widget _buildCard(BuildContext context) {
Widget _buildResultSection(BuildContext context) {
final implicationText = drug.userGuideline?.annotations.implication;
final recommendationText = drug.userGuideline?.annotations.recommendation;
return RoundedCard(
key: Key('annotationCard'),
radius: PharMeTheme.innerCardRadius,
outerHorizontalPadding: 0,
outerVerticalPadding: 0,
color: drug.warningLevel.color,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
drug.warningLevel.icon,
color: PharMeTheme.onSurfaceText,
size: PharMeTheme.mediumToLargeSpace,
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildPhenotype(context),
SizedBox(height: PharMeTheme.smallToMediumSpace),
RoundedCard(
key: Key('annotationCard'),
radius: PharMeTheme.innerCardRadius,
outerHorizontalPadding: 0,
outerVerticalPadding: 0,
color: drug.warningLevel.color,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
drug.warningLevel.icon,
color: PharMeTheme.onSurfaceText,
size: PharMeTheme.mediumToLargeSpace,
),
),
TextSpan(
text: ' ${drug.warningLevel.getLabel(context)}',
),
]),
style: PharMeTheme.textTheme.titleMedium!.copyWith(
fontWeight: FontWeight.bold,
),
),
TextSpan(
text: ' ${drug.warningLevel.getLabel(context)}',
),
]),
style: PharMeTheme.textTheme.titleMedium!.copyWith(
fontWeight: FontWeight.bold,
),
),
SizedBox(height: PharMeTheme.smallToMediumSpace),
Text.rich(
TextSpan(
children: [
if (implicationText != null) TextSpan(
text: context.l10n.drugs_page_implication_description,
),
TextSpan(text: '\n'),
WidgetSpan(child: SizedBox(height: PharMeTheme.mediumSpace * 1.2)),
SizedBox(height: PharMeTheme.smallToMediumSpace),
Text.rich(
TextSpan(
text:
implicationText ?? context.l10n.drugs_page_no_guidelines_text,
style: implicationText != null
? TextStyle(fontWeight: FontWeight.bold)
: TextStyle(fontStyle: FontStyle.italic)
children: [
if (implicationText != null) TextSpan(
text: context.l10n.drugs_page_implication_description,
),
],
),
),
if (recommendationText != null) ...[
SizedBox(height: PharMeTheme.smallToMediumSpace),
Text.rich(
TextSpan(children: [
TextSpan(
text: context.l10n.drugs_page_recommendation_description,
WidgetSpan(child: SizedBox(height: PharMeTheme.mediumSpace * 1.2)),
TextSpan(
text:
implicationText ?? context.l10n.drugs_page_no_guidelines_text,
style: implicationText != null
? TextStyle(fontWeight: FontWeight.bold)
: TextStyle(fontStyle: FontStyle.italic)
),
],
),
TextSpan(text: '\n'),
WidgetSpan(child: SizedBox(height: PharMeTheme.mediumSpace * 1.2)),
TextSpan(
text: recommendationText,
style: TextStyle(fontWeight: FontWeight.bold),
),
if (recommendationText != null) ...[
SizedBox(height: PharMeTheme.smallToMediumSpace),
Text.rich(
TextSpan(children: [
TextSpan(
text: context.l10n.drugs_page_recommendation_description,
),
WidgetSpan(child: SizedBox(height: PharMeTheme.mediumSpace * 1.2)),
TextSpan(
text: recommendationText,
style: TextStyle(fontWeight: FontWeight.bold),
),
]),
),
]),
),
],
]
)
],
]
)
),
_maybeBuildPhenoconversionInformation(context) ?? SizedBox.shrink(),
],
);
}

Expand All @@ -123,24 +125,30 @@ class GuidelineAnnotationCard extends StatelessWidget {
: context.l10n.drugs_page_tooltip_guideline_missing;
}

List<Widget> _buildHeader(BuildContext context) {
List<GenotypeResult>? _getGenotypeResults() {
if (drug.userGuideline == null && drug.guidelines.isEmpty) {
return [
Text(
context.l10n.drugs_page_guidelines_empty(drug.name),
style: TextStyle(fontStyle: FontStyle.italic),
),
];
} else {
final genotypeResults = drug.guidelineGenotypes.map((genotypeKey) =>
UserData.instance.genotypeResults![genotypeKey] ??
// Should not be null but to be safe
GenotypeResult.missingResult(
GenotypeKey.extractGene(genotypeKey),
variant: GenotypeKey.maybeExtractVariant(genotypeKey),
)
).toList();
final geneDescriptions = genotypeResults.map((genotypeResult) =>
return null;
}
return drug.guidelineGenotypes.map((genotypeKey) =>
UserData.instance.genotypeResults![genotypeKey] ??
// Should not be null but to be safe
GenotypeResult.missingResult(
GenotypeKey.extractGene(genotypeKey),
variant: GenotypeKey.maybeExtractVariant(genotypeKey),
)
).toList();
}

Widget _buildPhenotype(BuildContext context) {
final genotypeResults = _getGenotypeResults();
if (genotypeResults == null) {
return Text(
context.l10n.drugs_page_guidelines_empty(drug.name),
style: TextStyle(fontStyle: FontStyle.italic),
);
}
return buildTable(
genotypeResults.map((genotypeResult) =>
TableRowDefinition(
genotypeResult.geneDisplayString,
possiblyAdaptedPhenotype(
Expand All @@ -149,21 +157,28 @@ class GuidelineAnnotationCard extends StatelessWidget {
drug: drug.name,
),
)
).toList();
return [
buildTable(geneDescriptions),
if (genotypeResults.any(
(genotypeResult) => isInhibited(genotypeResult, drug: drug.name)
)) ...[
SizedBox(height: PharMeTheme.smallSpace),
buildDrugInteractionInfo(
context,
genotypeResults,
drug: drug.name,
),
],
];
).toList(),
);
}

Widget? _maybeBuildPhenoconversionInformation(BuildContext context) {
final genotypeResults = _getGenotypeResults();
if (
genotypeResults != null &&
genotypeResults.any(
(genotypeResult) => isInhibited(genotypeResult, drug: drug.name)
)
) {
return Padding(
padding: EdgeInsets.only(top: PharMeTheme.smallSpace),
child: buildDrugInteractionInfo(
context,
genotypeResults,
drug: drug.name,
),
);
}
return null;
}

Widget _buildSourcesSection(BuildContext context) {
Expand Down

0 comments on commit 8437cb1

Please sign in to comment.