Skip to content

Commit

Permalink
feat(#456): localize PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
tamara-slosarek authored and tamslo committed Aug 3, 2023
1 parent 8a8bc72 commit 95e362b
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 31 deletions.
87 changes: 56 additions & 31 deletions app/lib/common/utilities/pdf_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import 'package:printing/printing.dart';

import '../module.dart';

const noValueString = 'n/a';

Future<String> createPdf(
Drug drug,
BuildContext buildContext,
Expand Down Expand Up @@ -47,10 +45,10 @@ pw.Widget buildPdfPage(
) {
return pw.Wrap(
children: [
..._buildHeader(drug),
..._buildHeader(drug, buildContext),
_buildTextBlockSpacer(),
_buildTextSpacer(),
..._buildDrugPart(drug),
..._buildDrugPart(drug, buildContext),
_buildTextBlockSpacer(),
..._buildUserPart(context, buildContext, drug, emoji),
_buildTextBlockSpacer(),
Expand All @@ -76,7 +74,7 @@ pw.Text _buildSubheading(String text) => pw.Text(
),
);

List<pw.Widget> _buildHeader(Drug drug) {
List<pw.Widget> _buildHeader(Drug drug, BuildContext buildContext) {
return [
_PdfSegment(
child: pw.Text(
Expand All @@ -91,7 +89,7 @@ List<pw.Widget> _buildHeader(Drug drug) {
_buildTextSpacer(),
_PdfSegment(
child: pw.Text(
'PGx report',
buildContext.l10n.pdf_pgx_report,
style: pw.TextStyle(
fontSize: PharMeTheme.mediumSpace,
),
Expand All @@ -101,42 +99,47 @@ List<pw.Widget> _buildHeader(Drug drug) {
];
}

List<pw.Widget> _buildDrugPart(Drug drug) {
List<pw.Widget> _buildDrugPart(Drug drug, BuildContext buildContext) {
return [
_PdfSegment(
child: _PdfDescription(
title: 'Drug class',
title: buildContext.l10n.drugs_page_header_drugclass,
text: drug.annotations.drugclass,
),
),
_buildTextSpacer(),
_PdfSegment(
child: _PdfDescription(
title: 'Indication',
title: buildContext.l10n.pdf_indication,
text: drug.annotations.indication,
),
),
_buildTextSpacer(),
_PdfSegment(
child: _PdfDescription(
title: 'Brand names',
title: buildContext.l10n.pdf_brand_names,
text: drug.annotations.brandNames.join(', '),
),
),
];
}

String _getPhenotypeInfo(String gene) {
final phenotype = UserData.phenotypeFor(gene) ?? noValueString;
final lookup = UserData.lookupFor(gene) ?? noValueString;
String? _getPhenotypeInfo(String gene) {
final phenotype = UserData.phenotypeFor(gene);
final lookup = UserData.lookupFor(gene);
if (phenotype == null) return null;
return lookup == phenotype ? phenotype : '$phenotype ($lookup)';
}

String _userInfoPerGene(Drug drug, String? Function(String gene) getInfo) {
if (drug.guidelines.isEmpty) return noValueString;
String _userInfoPerGene(
Drug drug,
String? Function(String) getInfo,
BuildContext buildContext,
) {
if (drug.guidelines.isEmpty) return buildContext.l10n.pdf_no_value;
final guidelineGenes = drug.guidelines.first.lookupkey.keys.toList();
return guidelineGenes.map((gene) =>
'$gene: ${getInfo(gene) ?? noValueString}'
'$gene: ${getInfo(gene) ?? buildContext.l10n.pdf_no_value}'
).join(', ');
}

Expand All @@ -147,9 +150,21 @@ List<pw.Widget> _buildUserPart(
Font emoji,
) {
final userGuideline = drug.userGuideline();
final patientGenotype = _userInfoPerGene(drug, UserData.genotypeFor);
final patientPhenotype = _userInfoPerGene(drug, _getPhenotypeInfo);
final allelesTested = _userInfoPerGene(drug, UserData.allelesTestedFor);
final patientGenotype = _userInfoPerGene(
drug,
UserData.genotypeFor,
buildContext,
);
final patientPhenotype = _userInfoPerGene(
drug,
_getPhenotypeInfo,
buildContext,
);
final allelesTested = _userInfoPerGene(
drug,
UserData.allelesTestedFor,
buildContext,
);
final warningLevelIcons = {
'red': '❌',
'yellow': '⚠',
Expand All @@ -161,28 +176,28 @@ List<pw.Widget> _buildUserPart(
_buildTextBlockSpacer(),
_PdfSegment(
child: _PdfDescription(
title: 'Genotype',
title: buildContext.l10n.gene_page_genotype,
text: patientGenotype,
),
),
_buildTextSpacer(),
_PdfSegment(
child: _PdfDescription(
title: 'Phenotype',
title: buildContext.l10n.gene_page_phenotype,
text: patientPhenotype
),
),
_buildTextSpacer(),
_PdfSegment(
child: _PdfDescription(
title: 'Tested alleles',
title: buildContext.l10n.pdf_tested_alleles,
text: allelesTested,
),
),
_buildTextBlockSpacer(),
_PdfSegment(
child: _PdfDescription(
title: 'User guideline',
title: buildContext.l10n.pdf_user_guideline,
text: userGuideline != null ?
'${userGuideline.annotations.implication} '
' ${userGuideline.annotations.recommendation}' :
Expand All @@ -203,7 +218,7 @@ List<pw.Widget> _buildExternalGuidelinePart(
buildContext.l10n.pdf_heading_clinical_guidelines
);
return externalData == null ?
[ heading, _buildTextBlockSpacer(), pw.Text(noValueString) ] :
[ heading, _buildTextBlockSpacer(), pw.Text(buildContext.l10n.pdf_no_value) ] :
[
heading,
_buildTextBlockSpacer(),
Expand All @@ -216,14 +231,17 @@ List<pw.Widget> _buildExternalGuidelinePart(
...externalGuidelines,
_buildTextBlockSpacer(),
_buildTextDivider(),
..._buildGuidelinePart(guideline)
..._buildGuidelinePart(guideline, buildContext)
]
),
_buildTextDivider()
];
}

List<pw.Widget> _buildGuidelinePart(GuidelineExtData guideline) {
List<pw.Widget> _buildGuidelinePart(
GuidelineExtData guideline,
BuildContext buildContext
) {
return [
_PdfSegment(
child: pw.Text(
Expand All @@ -234,7 +252,7 @@ List<pw.Widget> _buildGuidelinePart(GuidelineExtData guideline) {
_buildTextBlockSpacer(),
_PdfSegment(
child: _PdfDescription(
title: '${guideline.source} guideline link'
title: buildContext.l10n.pdf_guideline_link(guideline.source)
),
),
_PdfSegment(child:
Expand All @@ -252,23 +270,30 @@ List<pw.Widget> _buildGuidelinePart(GuidelineExtData guideline) {
_buildTextSpacer(),
_PdfSegment(
child: _PdfDescription(
title: '${guideline.source} recommendation',
title: buildContext.l10n.pdf_guideline_recommmendation(
guideline.source,
),
text: guideline.recommendation),
),
_buildTextSpacer(),
...guideline.implications.entries
.map((implication) => _PdfSegment(
child: _PdfDescription(
title:
'${guideline.source} implication for ${implication.key}',
buildContext.l10n.pdf_guideline_gene_implication(
guideline.source,
implication.key
),
text: implication.value,
)))
.toList(),
_buildTextSpacer(),
_PdfSegment(
child: _PdfDescription(
title: '${guideline.source} comment',
text: guideline.comments,
title: buildContext.l10n.pdf_guideline_comment(guideline.source),
text: guideline.comments.isNullOrBlank ?
buildContext.l10n.pdf_no_value :
guideline.comments
),
),
];
Expand Down
50 changes: 50 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,59 @@
"gene_page_affected_drugs_tooltip": "The drugs listed here are affected by your variant of this gene.",
"gene_page_no_affected_drugs": "Your variant of this gene has no known effect on any drug.",

"pdf_pgx_report": "PGx Report",
"pdf_heading_user_data": "User data",
"pdf_heading_clinical_guidelines": "Clinical guideline(s)",
"pdf_info_clinical_guidelines": "Clinical guideline(s) relevant for the phenotype. For more fine-grained information (e.g., in case of multiple guidelines) please refer to the original guideline (see URLs below).",
"pdf_no_value": "n/a",
"pdf_indication": "Indication",
"pdf_brand_names": "Brand names",
"pdf_tested_alleles": "Tested alleles",
"pdf_user_guideline": "User guideline",
"pdf_guideline_link": "{guidelineSource} guideline link",
"@pdf_guideline_link": {
"description": "Sourcec of the guideline",
"placeholders": {
"guidelineSource": {
"type": "String",
"example": "CPIC"
}
}
},
"pdf_guideline_recommmendation": "{guidelineSource} recommendation",
"@pdf_guideline_recommmendation": {
"description": "Sourcec of the guideline",
"placeholders": {
"guidelineSource": {
"type": "String",
"example": "CPIC"
}
}
},
"pdf_guideline_gene_implication": "{guidelineSource} implication for {geneSymbol}",
"@pdf_guideline_gene_implication": {
"description": "Sourcec of the guideline",
"placeholders": {
"guidelineSource": {
"type": "String",
"example": "CPIC"
},
"geneSymbol": {
"type": "String",
"example": "CYP2D6"
}
}
},
"pdf_guideline_comment": "{guidelineSource} comment",
"@pdf_guideline_comment": {
"description": "Sourcec of the guideline",
"placeholders": {
"guidelineSource": {
"type": "String",
"example": "CPIC"
}
}
},

"nav_report": "Report",
"tab_report": "Gene report",
Expand Down

0 comments on commit 95e362b

Please sign in to comment.