-
{{ s.label }}
-
- @if (s.risk; as r) {
-
- }
+ @if (groups().length) {
+
Divisiones numéricas descriptivas; no representan umbrales clínicos.
+ }
+ @for (g of groups(); track $index) {
+ @if (g.title) {
+
{{ g.title }}{{ g.index ? ' · fecha índice ' + g.index : '' }}
+ }
+ @for (s of g.scales; track s.label) {
+
+
+ {{ s.label }}
+ @if (s.risk; as r) {
+ @if (r.low !== undefined && r.high !== undefined) {
+ · IC 95 %: {{ r.low * 100 | number: '1.1-2' }}–{{
+ r.high * 100 | number: '1.1-2'
+ }}
+ %
+ }
+ } @else {
+ · No disponible
+ }
+
+
+
+ @if (s.risk; as r) {
+
+
{{ r.p * 100 | number: '1.1-2' }} %
+ }
+
+
+ 0 %25 %50 %75 %100 %
+
- @if (s.risk; as r) {
-
{{ r.p * 100 | number: '1.1-2' }} %
- @if (r.low !== undefined) {
-
- IC 95 %: {{ r.low * 100 | number: '1.1-2' }}–{{ r.high! * 100 | number: '1.1-2' }} %
-
- }
- } @else {
-
No disponible
- }
-
+ }
}
`,
styles: `
- .scale {
- align-items: center;
- display: flex;
- flex-wrap: wrap;
- gap: 12px;
- margin-bottom: 8px;
+ .note {
+ margin: 0 0 8px;
}
- .line {
- background: linear-gradient(to right, #a8c243, #c24269);
- flex: 1 1 200px;
- height: 8px;
+ .risk-scale {
+ margin: 8px 0 14px;
+ max-width: 740px;
+ }
+ .risk-scale p {
+ margin: 0;
+ }
+ .risk-plot {
+ padding-top: 24px;
position: relative;
}
- .mark {
- background: #333;
+ .risk-line {
+ background: linear-gradient(
+ to right,
+ #42a77e 0 25%,
+ #a8c243 25% 50%,
+ #df8640 50% 75%,
+ #c24269 75% 100%
+ );
height: 16px;
+ }
+ .unavailable .risk-line {
+ background: repeating-linear-gradient(
+ to right,
+ #d9dfe2 0,
+ #d9dfe2 calc(25% - 1px),
+ #fff calc(25% - 1px),
+ #fff 25%
+ );
+ }
+ .risk-marker {
+ background: #17324d;
+ bottom: -2px;
+ height: 20px;
position: absolute;
- top: -4px;
+ transform: translateX(-50%);
width: 3px;
}
+ .risk-value {
+ color: #17324d;
+ font-size: 13px;
+ position: absolute;
+ top: 1px;
+ transform: translateX(-50%);
+ white-space: nowrap;
+ }
+ .risk-labels {
+ display: flex;
+ font-size: 12px;
+ justify-content: space-between;
+ margin-top: 3px;
+ }
`,
})
export class RiskScales {
- readonly scales = input.required
();
+ readonly groups = input.required();
}
diff --git a/src/app/paciente/stages.spec.ts b/src/app/paciente/stages.spec.ts
index bcadb58..fab29c5 100644
--- a/src/app/paciente/stages.spec.ts
+++ b/src/app/paciente/stages.spec.ts
@@ -1,5 +1,5 @@
import { EXT } from '../fhir';
-import { route } from './stages';
+import { between, interval, route } from './stages';
const ext = (name: string, value: object) => ({ url: EXT + name, ...value });
const cytology = (...extension: object[]): any => ({ effectiveDateTime: '2026-01-10', extension });
@@ -24,3 +24,103 @@ describe('the route of a cytology', () => {
expect(states('2026-01-15').slice(2)).toEqual(['unknown', 'unknown', 'unknown']);
});
});
+
+describe('the days between stages', () => {
+ it('counts whole days and says nothing for a missing or out-of-order day', () => {
+ expect(between('2026-01-10', '2026-02-01')).toBe(22);
+ expect(between('2026-01-10', '2026-01-10')).toBe(0);
+ expect(between(undefined, '2026-02-01')).toBeUndefined();
+ expect(between('2026-02-01', '2026-01-10')).toBeUndefined();
+ });
+ it('writes a dash, never a zero, for a missing day, and marks an interval that rests on an inference', () => {
+ expect(interval(undefined, '2026-02-01')).toBe('—');
+ expect(interval('2026-01-10', undefined)).toBe('—');
+ expect(interval('2026-01-10', '2026-01-11')).toBe('1 día');
+ expect(interval('2026-01-10', '2026-02-01')).toBe('22 días');
+ expect(interval('2026-01-10', '2026-02-01', true)).toBe('22 días (inferido)');
+ });
+ it('knows an ambiguous stage the backend does not publish yet', () => {
+ const report = cytology(ext('colposcopy-date', { valueDate: '2026-02-01' }));
+ expect(route(report, '2026-12-31').map((s) => s.state)).not.toContain('ambiguous');
+ });
+});
+
+describe('the route by what the backend says of each stage', () => {
+ const full = (...more: object[]) =>
+ cytology(
+ ext('report-date', { valueDate: '2026-01-20' }),
+ ext('colposcopy-date', { valueDate: '2026-02-01' }),
+ ext('stage-colposcopy-state', { valueCode: 'inferred' }),
+ ext('stage-colposcopy-source', { valueCode: 'clinical-note' }),
+ ext('stage-colposcopy-source', { valueCode: 'biopsy-order' }),
+ ext('biopsy-request-date', { valueDate: '2026-02-01' }),
+ ext('biopsy-date', { valueDate: '2026-03-01' }),
+ ext('biopsy-link', { valueCode: 'recorded' }),
+ ext('stage-biopsy-state', { valueCode: 'recorded' }),
+ ext('stage-biopsy-source', { valueCode: 'biopsy-record' }),
+ ext('diagnosis-date', { valueDate: '2026-03-10' }),
+ ext('stage-diagnosis-state', { valueCode: 'inferred' }),
+ ext('stage-diagnosis-source', { valueCode: 'clinical-note' }),
+ ...more,
+ );
+ it('carries the state and every source of each stage, and the form for the first two', () => {
+ const stages = route(full(), '2026-12-31');
+ expect(stages.map((s) => s.state)).toEqual([
+ 'recorded',
+ 'recorded',
+ 'inferred',
+ 'recorded',
+ 'inferred',
+ ]);
+ expect(stages.map((s) => s.sources)).toEqual([
+ ['cytology-form'],
+ ['cytology-form'],
+ ['clinical-note', 'biopsy-order'],
+ ['biopsy-record'],
+ ['clinical-note'],
+ ]);
+ });
+ it("an ambiguous or pending state is the backend's, and a source it does not know is dropped", () => {
+ const ambiguous = full().extension!.map((e: any) =>
+ e.url.endsWith('stage-biopsy-state') ? { ...e, valueCode: 'ambiguous' } : e,
+ );
+ expect(route({ ...full(), extension: ambiguous }, '2026-12-31')[3].state).toBe('ambiguous');
+ const odd = full(ext('stage-diagnosis-source', { valueCode: 'something-new' }));
+ expect(route(odd, '2026-12-31')[4].sources).toEqual(['clinical-note']);
+ const pending = cytology(
+ ext('stage-biopsy-state', { valueCode: 'pending' }),
+ ext('biopsy-request-date', { valueDate: '2026-02-01' }),
+ ext('biopsy-link', { valueCode: 'inferred' }),
+ ext('stage-biopsy-source', { valueCode: 'date-association' }),
+ );
+ const biopsy = route(pending, '2026-12-31')[3];
+ expect(biopsy).toMatchObject({
+ state: 'pending',
+ requested: '2026-02-01',
+ sources: ['date-association'],
+ });
+ expect(biopsy.day).toBeUndefined();
+ });
+ it('by a cut-off before a stage its state is not known, and one before the report is pending', () => {
+ const early = route(full(), '2026-01-25');
+ expect(early.slice(2).map((s) => s.state)).toEqual(['unknown', 'unknown', 'unknown']);
+ expect(early.slice(2).map((s) => s.sources)).toEqual([undefined, undefined, undefined]);
+ const between = route(full(), '2026-02-15')[3];
+ expect(between).toMatchObject({ state: 'pending', requested: '2026-02-01' });
+ });
+ it('a request with no biopsy day and no pending state is not read as pending when the backend speaks', () => {
+ // reported outside the route's horizon: the backend gives the request and no biopsy state
+ const outside = cytology(
+ ext('biopsy-request-date', { valueDate: '2026-02-01' }),
+ ext('colposcopy-date', { valueDate: '2026-02-01' }),
+ ext('stage-colposcopy-state', { valueCode: 'inferred' }),
+ );
+ expect(route(outside, '2026-12-31')[3].state).toBe('unknown');
+ // a report with no state extensions: the request alone reads as pending
+ const older = cytology(ext('biopsy-request-date', { valueDate: '2026-02-01' }));
+ expect(route(older, '2026-12-31')[3].state).toBe('pending');
+ });
+ it('an ambiguous stage rests no interval on its day', () => {
+ expect(interval(undefined, '2026-03-01')).toBe('—');
+ });
+});
diff --git a/src/app/paciente/stages.ts b/src/app/paciente/stages.ts
index 5c7ce4c..ef82253 100644
--- a/src/app/paciente/stages.ts
+++ b/src/app/paciente/stages.ts
@@ -1,39 +1,84 @@
import { Component, computed, input } from '@angular/core';
import type { DiagnosticReport } from 'fhir/r4';
-import { ext } from '../fhir';
+import { EXT, ext } from '../fhir';
-/** A step of the route that a cytology starts. A day with no state is unknown. */
+/** A step of the route that a cytology starts. A day with no state is unknown. `ambiguous` is how
+ * the page would draw a step the backend flagged as ambiguous; the current contract never does. */
export interface Stage {
label: string;
day?: string;
- state: 'recorded' | 'inferred' | 'pending' | 'unknown';
+ state: 'recorded' | 'inferred' | 'pending' | 'ambiguous' | 'unknown';
+ /** where the stage's day comes from, as the backend says it (see `SOURCES`); none: not said */
+ sources?: string[];
+ /** what a stage without a day knows: a biopsy requested on this day */
+ requested?: string;
}
+/** Where a stage's day comes from. */
+export const SOURCES: Record = {
+ 'cytology-form': 'Formulario de citología',
+ 'clinical-note': 'Nota clínica',
+ 'biopsy-order': 'Orden de biopsia',
+ 'biopsy-record': 'Registro de la biopsia (nombra la citología)',
+ 'date-association': 'Asociación por fechas',
+};
+
export const STATES: Record = {
recorded: 'Registrada',
inferred: 'Inferida por fechas',
pending: 'Pendiente',
+ ambiguous: 'Ambigua',
unknown: 'Sin dato',
};
-/** The route of one cytology, as its report says it, by `cutoff`. */
+/** The route of one cytology, as its report says it, by `cutoff`. The backend says each later
+ * stage's state and sources (`stage--state`, `stage--source`); a report without them
+ * is read from its days and the biopsy link. */
export function route(cytology: DiagnosticReport | undefined, cutoff: string): Stage[] {
const by = (day?: string) => (day && day.slice(0, 10) <= cutoff ? day.slice(0, 10) : undefined);
const at = (name: string) => by(ext(cytology, name)?.valueDate);
- const step = (label: string, day: string | undefined, known: Stage['state']): Stage => ({
+ const said = (k: string) => ext(cytology, `stage-${k}-state`)?.valueCode;
+ const published = ['colposcopy', 'biopsy', 'diagnosis'].some((k) => said(k));
+ const from = (k: string) =>
+ (cytology?.extension ?? [])
+ .filter((e) => e.url === EXT + `stage-${k}-source`)
+ .map((e) => e.valueCode!)
+ .filter((c) => c in SOURCES);
+ const KNOWN: Stage['state'][] = ['recorded', 'inferred', 'pending', 'ambiguous'];
+ /** A stage's state by what the backend says (or, with nothing said, by `otherwise`). */
+ const later = (
+ label: string,
+ k: string,
+ day: string | undefined,
+ otherwise: Stage['state'],
+ ): Stage => {
+ const state = said(k) as Stage['state'] | undefined;
+ const found = state && KNOWN.includes(state) && state !== 'pending' ? state : otherwise;
+ return { label, day, state: day ? found : 'unknown', sources: day ? from(k) : undefined };
+ };
+ const day = (label: string, d: string | undefined, sources: string[]): Stage => ({
label,
- day,
- state: day ? known : 'unknown',
+ day: d,
+ state: d ? 'recorded' : 'unknown',
+ sources: d ? sources : undefined,
});
const linked = ext(cytology, 'biopsy-link')?.valueCode === 'recorded' ? 'recorded' : 'inferred';
- const biopsy = step('Reporte de biopsia', at('biopsy-date'), linked);
- if (!biopsy.day && at('biopsy-request-date')) biopsy.state = 'pending';
+ const biopsy = later('Reporte de biopsia', 'biopsy', at('biopsy-date'), linked);
+ const requested = at('biopsy-request-date');
+ const reportedAfter = !!ext(cytology, 'biopsy-date')?.valueDate && !biopsy.day;
+ // asked by the cut-off and not reported by it: pending (the backend's pending, or a report after the
+ // cut-off); a report with no states at all reads a request with no day as pending
+ if (!biopsy.day && requested && (reportedAfter || said('biopsy') === 'pending' || !published)) {
+ biopsy.state = 'pending';
+ biopsy.requested = requested;
+ biopsy.sources = from('biopsy');
+ }
return [
- step('Toma de muestra', by(cytology?.effectiveDateTime), 'recorded'),
- step('Resultado de citología', at('report-date'), 'recorded'),
- step('Colposcopía', at('colposcopy-date'), 'inferred'),
+ day('Toma de muestra', by(cytology?.effectiveDateTime), ['cytology-form']),
+ day('Resultado de citología', at('report-date'), ['cytology-form']),
+ later('Colposcopía', 'colposcopy', at('colposcopy-date'), 'inferred'),
biopsy,
- step('Diagnóstico', at('diagnosis-date'), 'inferred'),
+ later('Diagnóstico', 'diagnosis', at('diagnosis-date'), 'inferred'),
];
}
@@ -43,32 +88,46 @@ export function between(from?: string, to?: string): number | undefined {
return Math.round((Date.parse(to) - Date.parse(from)) / 86_400_000);
}
-/** The stages as a line of dots; `detail` adds each one's state, day and days elapsed. */
+/** Days between two stages as text: "—" for a missing day (never a zero), and "(inferido)" when the
+ * interval rests on a stage that is only inferred from dates. */
+export function interval(from?: string, to?: string, inferred = false): string {
+ const days = between(from, to);
+ return days === undefined
+ ? '—'
+ : `${days} ${days === 1 ? 'día' : 'días'}${inferred ? ' (inferido)' : ''}`;
+}
+
+/** The stages as a line of nodes joined by a line; `detail` adds each one's state, day and the
+ * days elapsed since the previous stage and since the sample. */
@Component({
selector: 'app-stages',
template: `
-
+
@for (s of shown(); track s.label) {
- -
-
+
-
+
@if (detail()) {
- {{ s.label }}
- {{ s.text }}
- @if (s.day) {
- {{ s.day }}
- }
- @if (s.previous !== undefined) {
- {{ s.previous }} días desde la etapa anterior
- }
- @if (s.sample !== undefined) {
- {{ s.sample }} días desde la toma
- }
+
+ {{ s.label }}
+ {{ s.text }}
+ {{
+ s.day ?? (s.requested ? 'Solicitada el ' + s.requested : 'Sin fecha')
+ }}
+ @if (s.origin) {
+ Procedencia: {{ s.origin }}
+ }
+ Desde anterior: {{ s.previous }}
+ Desde toma: {{ s.sample }}
+
}
}
`,
styles: `
+ :host {
+ display: block;
+ }
ol {
display: flex;
gap: 6px;
@@ -76,33 +135,110 @@ export function between(from?: string, to?: string): number | undefined {
margin: 0;
padding: 0;
}
- ol.detail {
- flex-wrap: wrap;
- gap: 16px;
+ li {
+ position: relative;
}
- .detail li {
- display: flex;
- flex: 1 1 120px;
- flex-direction: column;
- font-size: 0.85rem;
- }
- .dot {
- border: 2px solid #9aa3ab;
+ /* the states: recorded is solid green, inferred double blue, pending a pale solid, ambiguous a
+ double rose border, and what has no data a dashed empty circle */
+ .node {
+ background: #fff;
+ border: 2px dashed #667b8a;
border-radius: 50%;
- display: inline-block;
+ box-sizing: border-box;
+ display: block;
height: 12px;
+ position: relative;
width: 12px;
+ z-index: 1;
}
.recorded {
- background: #6a8000;
- border-color: #6a8000;
+ background: #387b66;
+ border-style: solid;
}
.inferred {
- background: #a8c243;
- border-color: #6a8000;
+ background: #4269a0;
+ border-style: double;
}
.pending {
- border-color: #c24269;
+ background: #fff1c9;
+ border-style: solid;
+ }
+ .ambiguous {
+ border-color: #a84460;
+ border-style: double;
+ }
+
+ /* the detail: one column per stage across the whole width, the nodes joined by a line */
+ ol.detail {
+ background: #fff;
+ border: 1px solid #dce3e7;
+ border-radius: 8px;
+ gap: 0;
+ padding: 18px 12px;
+ }
+ .detail li {
+ flex: 1;
+ min-width: 0;
+ text-align: center;
+ }
+ .detail .node {
+ height: 18px;
+ margin: 0 auto;
+ width: 18px;
+ }
+ .detail li:not(:last-child)::after {
+ border-top: 1px solid #667b8a;
+ content: '';
+ left: calc(50% + 9px);
+ position: absolute;
+ right: calc(-50% + 9px);
+ top: 9px;
+ }
+ .info {
+ color: #60717d;
+ display: flex;
+ flex-direction: column;
+ font-size: 12px;
+ gap: 3px;
+ overflow-wrap: anywhere;
+ padding: 8px 4px 0;
+ }
+ .info strong {
+ color: #243d4b;
+ }
+ .interval {
+ color: #365b69;
+ font-weight: 600;
+ }
+ .origin {
+ font-style: italic;
+ }
+
+ @media (max-width: 700px) {
+ ol.detail {
+ display: block;
+ }
+ .detail li {
+ display: flex;
+ gap: 12px;
+ padding-bottom: 10px;
+ text-align: left;
+ }
+ .detail li:not(:last-child)::after {
+ border-left: 1px solid #667b8a;
+ border-top: 0;
+ bottom: 0;
+ left: 9px;
+ right: auto;
+ top: 18px;
+ }
+ .detail .node {
+ flex: none;
+ margin: 0;
+ }
+ .info {
+ padding: 0;
+ }
}
`,
})
@@ -111,11 +247,21 @@ export class Stages {
readonly detail = input(false);
protected readonly shown = computed(() => {
const all = this.stages();
+ const inferred = (s?: Stage) => s?.state === 'inferred';
+ // an ambiguous stage has a day the backend does not stand behind: no interval rests on it
+ const day = (s?: Stage) => (s?.state === 'ambiguous' ? undefined : s?.day);
return all.map((s, i) => ({
...s,
text: STATES[s.state],
- previous: i ? between(all[i - 1].day, s.day) : undefined,
- sample: i > 1 ? between(all[0].day, s.day) : undefined,
+ title: `${s.label}: ${STATES[s.state]}`,
+ origin: (s.sources ?? []).map((c) => SOURCES[c]).join(' · '),
+ previous: i ? interval(day(all[i - 1]), day(s), inferred(s) || inferred(all[i - 1])) : '—',
+ sample: interval(day(all[0]), day(s), inferred(s)),
}));
});
+ protected readonly summary = computed(() =>
+ this.shown()
+ .map((s) => s.title)
+ .join('; '),
+ );
}