mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
fix(cycle): carry every logged day entry on the calendar read
The calendar grid carried flow, symptoms, BBT, the ovulation test and the mucus reading, and dropped the rest of the day log: intercourse, spotting, the pregnancy and progesterone tests, contraception and whether a note exists. The published contract also promised the three cervix signs while the route never sent them. The intent fields resolve through the same reader the day-log read uses, so an encrypted envelope reads the same on both, and the grid is served under the same cycle grant as the day log. Additive fields; the contract test pins the wire keys to the published schema.
This commit is contained in:
1 parent
d81518b5bf
commit
adec5bd045
7 files changed
+431
-31
No files matched your search
@@ -80,7 +80,13 @@ describe("buildCalendar", () => {
|
||||
cervixPosition: null,
|
||||
cervixFirmness: null,
|
||||
cervixOpening: null,
|
||||
intermenstrualBleeding: false,
|
||||
sexualActivity: false,
|
||||
pregnancyTest: null,
|
||||
progesteroneTest: null,
|
||||
contraceptive: null,
|
||||
hasSymptoms: true,
|
||||
hasNote: false,
|
||||
},
|
||||
];
|
||||
const { prediction, days } = buildCalendar(
|
||||
|
||||
+46
-17
@@ -111,11 +111,52 @@ function decryptSensitive(envelope: string | null): SensitiveEnvelope {
|
||||
}
|
||||
}
|
||||
|
||||
/** The five intent-revealing fields, as a reader should see them. */
|
||||
interface ResolvedSensitiveFields {
|
||||
sexualActivity: boolean;
|
||||
protectedSex: boolean | null;
|
||||
pregnancyTest: string | null;
|
||||
progesteroneTest: string | null;
|
||||
contraceptive: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the intent-revealing fields of one day-log row: from the encryption
|
||||
* envelope when the row carries one, else from the plaintext columns (the
|
||||
* flag-OFF path). The day-log read and the calendar grid both go through here,
|
||||
* so a day cannot show intercourse in one and not the other.
|
||||
*/
|
||||
export function resolveSensitiveFields(
|
||||
row: Pick<
|
||||
CycleDayLog,
|
||||
| "sensitiveEncrypted"
|
||||
| "sexualActivity"
|
||||
| "protectedSex"
|
||||
| "pregnancyTest"
|
||||
| "progesteroneTest"
|
||||
| "contraceptive"
|
||||
>,
|
||||
): ResolvedSensitiveFields {
|
||||
if (row.sensitiveEncrypted != null) {
|
||||
const enc = decryptSensitive(row.sensitiveEncrypted);
|
||||
return {
|
||||
sexualActivity: enc.sexualActivity ?? false,
|
||||
protectedSex: enc.protectedSex ?? null,
|
||||
pregnancyTest: enc.pregnancyTest ?? null,
|
||||
progesteroneTest: enc.progesteroneTest ?? null,
|
||||
contraceptive: enc.contraceptive ?? null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
sexualActivity: row.sexualActivity,
|
||||
protectedSex: row.protectedSex,
|
||||
pregnancyTest: row.pregnancyTest,
|
||||
progesteroneTest: row.progesteroneTest,
|
||||
contraceptive: row.contraceptive,
|
||||
};
|
||||
}
|
||||
|
||||
export function toCycleDayLogDTO(row: DayLogWithLinks): CycleDayLogDTO {
|
||||
// Prefer the encryption envelope when present; else read the plaintext
|
||||
// columns (the flag-OFF path).
|
||||
const enc = decryptSensitive(row.sensitiveEncrypted);
|
||||
const hasEnvelope = row.sensitiveEncrypted != null;
|
||||
return {
|
||||
id: row.id,
|
||||
date: row.date,
|
||||
@@ -129,19 +170,7 @@ export function toCycleDayLogDTO(row: DayLogWithLinks): CycleDayLogDTO {
|
||||
cervixPosition: row.cervixPosition,
|
||||
cervixFirmness: row.cervixFirmness,
|
||||
cervixOpening: row.cervixOpening,
|
||||
sexualActivity: hasEnvelope
|
||||
? (enc.sexualActivity ?? false)
|
||||
: row.sexualActivity,
|
||||
protectedSex: hasEnvelope ? (enc.protectedSex ?? null) : row.protectedSex,
|
||||
pregnancyTest: hasEnvelope
|
||||
? (enc.pregnancyTest ?? null)
|
||||
: row.pregnancyTest,
|
||||
progesteroneTest: hasEnvelope
|
||||
? (enc.progesteroneTest ?? null)
|
||||
: row.progesteroneTest,
|
||||
contraceptive: hasEnvelope
|
||||
? (enc.contraceptive ?? null)
|
||||
: row.contraceptive,
|
||||
...resolveSensitiveFields(row),
|
||||
symptoms: (row.symptomLinks ?? []).map((l) => ({
|
||||
key: l.symptom.key,
|
||||
severity: l.severity ?? null,
|
||||
|
||||
@@ -69,6 +69,27 @@ export interface CalendarDayDTO {
|
||||
ovulationTest: string | null;
|
||||
/** Logged cervical-mucus quality, or null. */
|
||||
cervicalMucus: string | null;
|
||||
/** Logged cervix signs (symptothermal secondary indicator), each or null. */
|
||||
cervixPosition: string | null;
|
||||
cervixFirmness: string | null;
|
||||
cervixOpening: string | null;
|
||||
/** Spotting / bleeding outside the period logged on this day. */
|
||||
intermenstrualBleeding: boolean;
|
||||
/**
|
||||
* Intercourse logged on this day. Read through the same resolver as the
|
||||
* day-log itself (plaintext column or the encrypted envelope), and carried
|
||||
* under the same `cycle` grant: a caller who may read this grid may read
|
||||
* the day log it summarises, and one who may not reaches neither.
|
||||
*/
|
||||
sexualActivity: boolean;
|
||||
/** Logged at-home pregnancy test result, or null. */
|
||||
pregnancyTest: string | null;
|
||||
/** Logged at-home progesterone test result, or null. */
|
||||
progesteroneTest: string | null;
|
||||
/** Logged contraceptive method, or null. */
|
||||
contraceptive: string | null;
|
||||
/** Whether the day carries a note. The note's text never rides the grid. */
|
||||
hasNote: boolean;
|
||||
}
|
||||
|
||||
/** Rows the calendar needs from each day-log. */
|
||||
@@ -83,7 +104,15 @@ export type CalendarDayLogRow = Pick<
|
||||
| "cervixPosition"
|
||||
| "cervixFirmness"
|
||||
| "cervixOpening"
|
||||
> & { hasSymptoms: boolean };
|
||||
| "intermenstrualBleeding"
|
||||
> & {
|
||||
hasSymptoms: boolean;
|
||||
hasNote: boolean;
|
||||
sexualActivity: boolean;
|
||||
pregnancyTest: string | null;
|
||||
progesteroneTest: string | null;
|
||||
contraceptive: string | null;
|
||||
};
|
||||
|
||||
/** Map MenstrualCycle rows (oldest→newest) to engine `CycleInput`. */
|
||||
export function toCycleInputs(
|
||||
@@ -449,6 +478,15 @@ export function buildCalendar(
|
||||
temperatureExcluded: log?.temperatureExcluded ?? false,
|
||||
ovulationTest: log?.ovulationTest ?? null,
|
||||
cervicalMucus: log?.cervicalMucus ?? null,
|
||||
cervixPosition: log?.cervixPosition ?? null,
|
||||
cervixFirmness: log?.cervixFirmness ?? null,
|
||||
cervixOpening: log?.cervixOpening ?? null,
|
||||
intermenstrualBleeding: log?.intermenstrualBleeding ?? false,
|
||||
sexualActivity: log?.sexualActivity ?? false,
|
||||
pregnancyTest: log?.pregnancyTest ?? null,
|
||||
progesteroneTest: log?.progesteroneTest ?? null,
|
||||
contraceptive: log?.contraceptive ?? null,
|
||||
hasNote: log?.hasNote ?? false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ const cyclePredictionDto = z
|
||||
"The materialised forecast. Fertile-window fields (and predictedOvulation/ovulationConfirmed) are server-suppressed (null/false) unless the goal is TRYING_TO_CONCEIVE or AVOID_PREGNANCY.",
|
||||
});
|
||||
|
||||
const cycleCalendarDayDto = z.object({
|
||||
export const cycleCalendarDayDto = z.object({
|
||||
date: z.string(),
|
||||
phase: cyclePhaseEnumOpenapi.nullable(),
|
||||
isPredictedPeriod: z.boolean(),
|
||||
@@ -218,6 +218,23 @@ const cycleCalendarDayDto = z.object({
|
||||
cervixPosition: cervixPositionEnum.nullable(),
|
||||
cervixFirmness: cervixFirmnessEnum.nullable(),
|
||||
cervixOpening: cervixOpeningEnum.nullable(),
|
||||
// v1.39.1 — the rest of what a day log can hold, so a day with only one of
|
||||
// these logged no longer reads as an empty day. Additive: an older client
|
||||
// that does not know a field ignores it.
|
||||
intermenstrualBleeding: z.boolean().meta({
|
||||
description: "Spotting or bleeding outside the period logged on this day.",
|
||||
}),
|
||||
sexualActivity: z.boolean().meta({
|
||||
description:
|
||||
"Intercourse logged on this day. Resolved from the plaintext column or the encrypted envelope, exactly as the day-log read resolves it, and served under the same cycle grant.",
|
||||
}),
|
||||
pregnancyTest: homeTestResultEnumOpenapi.nullable(),
|
||||
progesteroneTest: homeTestResultEnumOpenapi.nullable(),
|
||||
contraceptive: z.string().nullable(),
|
||||
hasNote: z.boolean().meta({
|
||||
description:
|
||||
"Whether the day carries a note. The note text is only on the day-log read.",
|
||||
}),
|
||||
});
|
||||
|
||||
const cycleVerdictDto = z
|
||||
|
||||
Reference in new issue
Block a user