Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Jan 14, 2025
1 parent e59aed8 commit bcfc59f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 123 deletions.
2 changes: 1 addition & 1 deletion functions/src/healthSummary/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class HealthSummaryPdfGenerator extends PdfGenerator {
[
this.texts.vitalsSection.bodyWeightTable.rowTitle,
this.data.latestBodyWeight?.toFixed(0) ?? '---',
this.data.averageBodyWeight?.toFixed(0) ?? '---',
this.data.lastSevenDayAverageBodyWeight?.toFixed(0) ?? '---',
this.data.bodyWeightRange?.toFixed(0) ?? '---',
].map((title) => this.cell(title)),
],
Expand Down
21 changes: 17 additions & 4 deletions functions/src/models/healthSummaryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import {
advanceDateByDays,
average,
UserMedicationRecommendationType,
type FHIRAppointment,
Expand Down Expand Up @@ -40,14 +41,24 @@ export class HealthSummaryData {
recommendations: UserMedicationRecommendation[]
vitals: HealthSummaryVitals
symptomScores: SymptomScore[]
now: Date

// Computed Properties - Body Weight

get latestBodyWeight(): number | null {
return this.vitals.bodyWeight.at(0)?.value ?? null
}

get averageBodyWeight(): number | null {
get lastSevenDayAverageBodyWeight(): number | null {
const bodyWeightValues = this.vitals.bodyWeight
.filter(
(observation) => observation.date >= advanceDateByDays(this.now, -7),
)
.map((observation) => observation.value)
return average(bodyWeightValues) ?? null
}

get medianBodyWeight(): number | null {
return (
average(this.vitals.bodyWeight.map((observation) => observation.value)) ??
null
Expand Down Expand Up @@ -136,12 +147,12 @@ export class HealthSummaryData {
}

get weightCategory(): HealthSummaryWeightCategory {
const averageWeight = this.averageBodyWeight
const medianWeight = this.medianBodyWeight
const latestWeight = this.latestBodyWeight
if (averageWeight === null || latestWeight === null)
if (medianWeight === null || latestWeight === null)
return HealthSummaryWeightCategory.MISSING

return latestWeight - averageWeight > 1 ?
return latestWeight - medianWeight >= 3 ?
HealthSummaryWeightCategory.INCREASING
: HealthSummaryWeightCategory.STABLE_OR_DECREASING
}
Expand All @@ -156,6 +167,7 @@ export class HealthSummaryData {
recommendations: UserMedicationRecommendation[]
vitals: HealthSummaryVitals
symptomScores: SymptomScore[]
now: Date
}) {
this.name = input.name
this.dateOfBirth = input.dateOfBirth
Expand All @@ -164,5 +176,6 @@ export class HealthSummaryData {
this.recommendations = input.recommendations
this.vitals = input.vitals
this.symptomScores = input.symptomScores
this.now = input.now
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('HealthSummaryService', () => {
it('should fetch health summary data', async () => {
const actualData = await healthSummaryService.getHealthSummaryData(
'mockUser',
new Date(2024, 2, 2, 12, 30),
QuantityUnit.lbs,
)
console.log('actualData:', actualData.nextAppointment?.start.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class DefaultHealthSummaryService implements HealthSummaryService {

async getHealthSummaryData(
userId: string,
date: Date,
weightUnit: QuantityUnit,
): Promise<HealthSummaryData> {
const [
Expand All @@ -50,7 +51,7 @@ export class DefaultHealthSummaryService implements HealthSummaryService {
this.patientService.getNextAppointment(userId),
this.patientService.getMedicationRecommendations(userId),
this.patientService.getSymptomScores(userId, { limit: 5 }),
this.getVitals(userId, advanceDateByDays(new Date(), -14), weightUnit),
this.getVitals(userId, advanceDateByDays(date, -14), weightUnit),
])

const clinician =
Expand All @@ -66,6 +67,7 @@ export class DefaultHealthSummaryService implements HealthSummaryService {
recommendations: recommendations.map((doc) => doc.content),
vitals: vitals,
symptomScores: symptomScores.map((doc) => doc.content),
now: date,
})
}

Expand Down
Loading

0 comments on commit bcfc59f

Please sign in to comment.