Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Jan 9, 2025
1 parent 6ccbfde commit af81979
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
17 changes: 5 additions & 12 deletions functions/src/healthSummary/generate+localizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function healthSummaryLocalizations(languages: string[]) {
symptomScore: HealthSummarySymptomScoreCategory | null
dizziness: HealthSummaryDizzinessCategory | null
weight: HealthSummaryWeightCategory | null
}): string | null {
}): string[] | null {
if (
input.recommendations === null ||
input.symptomScore === null ||
Expand All @@ -81,18 +81,11 @@ export function healthSummaryLocalizations(languages: string[]) {
symptomScore: input.symptomScore,
dizziness: input.dizziness,
weight: input.weight,
})?.map((text) => text.localize(...languages)) ?? []
}) ?? []

switch (messages.length) {
case 0:
return null
case 1:
return messages[0]
default:
return messages
.map((message, index) => ` ${index + 1}. ${message}`)
.join('\n')
}
if (messages.length === 0) return null

return messages.map((text) => text.localize(...languages))
},
},
currentMedicationsSection: {
Expand Down
33 changes: 19 additions & 14 deletions functions/src/healthSummary/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ class HealthSummaryPdfGenerator extends PdfGenerator {
addKeyPointsSection() {
this.addSectionTitle(this.texts.keyPointsSection.title)

const text = this.texts.keyPointsSection.text({
const texts = this.texts.keyPointsSection.text({
recommendations: this.data.recommendationsCategory,
symptomScore: this.data.symptomScoreCategory,
dizziness: this.data.dizzinessCategory,
weight: this.data.weightCategory,
})
if (text !== null) {
this.addText(text, this.textStyles.bodyColored)
if (texts !== null) {
if (texts.length === 1) {
this.addText(texts[0], this.textStyles.bodyColored)
} else {
this.addList(texts, this.textStyles.bodyColored)
}
} else {
this.addText(
this.texts.keyPointsSection.defaultText,
Expand Down Expand Up @@ -197,19 +201,20 @@ class HealthSummaryPdfGenerator extends PdfGenerator {
if (optimizations.length === 0) return
this.addSectionTitle(this.texts.medicationRecommendationsSection.title)

optimizations.forEach((recommendation, index) => {
const title = recommendation.displayInformation.title.localize(
...this.options.languages,
)
const description =
recommendation.displayInformation.description.localize(
this.addList(
optimizations.map((recommendation) => {
const title = recommendation.displayInformation.title.localize(
...this.options.languages,
)
this.addText(
` ${index + 1}. ${title}: ${description}`,
this.textStyles.bodyColored,
)
})
const description =
recommendation.displayInformation.description.localize(
...this.options.languages,
)
return `${title}: ${description}`
}),
this.textStyles.bodyColored,
)

this.moveDown(this.textStyles.body.fontSize / 2)
this.addText(
this.texts.medicationRecommendationsSection.description,
Expand Down
15 changes: 15 additions & 0 deletions functions/src/healthSummary/pdfGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ export class PdfGenerator {
}
}

addList(texts: string[], textStyle: TextStyle) {
texts.forEach((text, index) => {
this.indent(1, textStyle)
this.addText(`${index + 1}.`, textStyle)
this.moveDown(-textStyle.fontSize * 1.5)
this.indent(1.5, textStyle)
this.addText(text, textStyle)
this.indent(-2.5, textStyle)
})
}

addLine(
start: { x: number; y: number },
end: { x: number; y: number },
Expand Down Expand Up @@ -315,4 +326,8 @@ export class PdfGenerator {
title: title,
}
}

private indent(amount: number, textStyle: TextStyle) {
this.cursor.x += amount * textStyle.fontSize
}
}
Binary file modified functions/src/tests/resources/mockHealthSummary.pdf
Binary file not shown.

0 comments on commit af81979

Please sign in to comment.