CaCu record: grouped NCI comparison, Spanish outcome names, survival texts and risk-only scales
The NCI comparison shows the reference once per horizon and one block per model, saying the reasons that every incompatible comparison shares only once. Outcome names are translated for display only (the API identifiers stay), and the reference outcome is read from the answer. The CaCu survival card is titled as survival and states that its curves estimate the clinical scenario's group, not an individual. Survival and recurrence estimates no longer feed the risk scales, curves, probability table or PDF.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { Parameters } from 'fhir/r4';
|
||||
import { horizonLabel, referenceView } from './reference-risk';
|
||||
import { groupReference, horizonLabel, outcomeText, referenceView } from './reference-risk';
|
||||
|
||||
const part = (name: string, extra: object) => ({ name, ...extra }) as any;
|
||||
const answer = (...parameter: object[]): Parameters =>
|
||||
@@ -88,3 +88,173 @@ describe('the reference answer as the section shows it', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const cmp = (
|
||||
model: string,
|
||||
outcome: string,
|
||||
status: string,
|
||||
reasons: string[],
|
||||
extra: object[] = [],
|
||||
) =>
|
||||
part('comparison', {
|
||||
part: [
|
||||
part('model', { valueCode: model }),
|
||||
part('title', { valueString: model }),
|
||||
part('outcome', { valueString: outcome }),
|
||||
...extra,
|
||||
part('status', { valueCode: status }),
|
||||
...reasons.map((r) => part('reason', { valueCode: r })),
|
||||
],
|
||||
});
|
||||
const two = (a: object[], b: object[]) =>
|
||||
answer(
|
||||
part('status', { valueCode: 'resolved' }),
|
||||
part('horizon', {
|
||||
part: [
|
||||
part('years', { valueInteger: 0 }),
|
||||
part('published', { valueBoolean: true }),
|
||||
part('reference', { valueDecimal: 0.001 }),
|
||||
...a,
|
||||
],
|
||||
}),
|
||||
part('horizon', {
|
||||
part: [
|
||||
part('years', { valueInteger: 5 }),
|
||||
part('published', { valueBoolean: true }),
|
||||
part('reference', { valueDecimal: 0.0027 }),
|
||||
...b,
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
describe('outcome names', () => {
|
||||
it('translates the known outcomes for display and leaves the API identifier untouched', () => {
|
||||
expect(outcomeText('cancer')).toBe('Cáncer');
|
||||
expect(outcomeText('CIN2+ within one year')).toBe('CIN2+ en un año');
|
||||
expect(outcomeText('CIN3+')).toBe('CIN3 o más grave (CIN3+)');
|
||||
expect(outcomeText('something new')).toBe('something new');
|
||||
expect(outcomeText(undefined)).toBe('');
|
||||
const view = referenceView(
|
||||
two([cmp('m', 'cancer', 'not_comparable', ['outcome_differs'])], []),
|
||||
);
|
||||
expect(view.horizons[0].comparisons[0].outcome).toBe('cancer');
|
||||
});
|
||||
});
|
||||
|
||||
describe('grouping the comparison', () => {
|
||||
const reasons = ['outcome_differs', 'population_not_verified'];
|
||||
it('keeps every model, horizon, value and interval, and says shared reasons once', () => {
|
||||
const g = groupReference(
|
||||
referenceView(
|
||||
two(
|
||||
[
|
||||
cmp(
|
||||
'a',
|
||||
'CIN2+',
|
||||
'not_comparable',
|
||||
[...reasons, 'index_date_differs'],
|
||||
[part('institutional', { valueDecimal: 0.05 })],
|
||||
),
|
||||
cmp('b', 'cancer', 'not_comparable', reasons),
|
||||
],
|
||||
[
|
||||
cmp('a', 'CIN2+', 'not_comparable', reasons, [
|
||||
part('institutional', { valueDecimal: 0.07 }),
|
||||
part('institutional-low', { valueDecimal: 0.05 }),
|
||||
part('institutional-high', { valueDecimal: 0.09 }),
|
||||
]),
|
||||
cmp('b', 'cancer', 'not_comparable', [...reasons, 'horizon_not_published_by_model']),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(g.reference.map((r) => [r.years, r.reference])).toEqual([
|
||||
[0, 0.001],
|
||||
[5, 0.0027],
|
||||
]);
|
||||
expect(g.common).toEqual(reasons); // every model gives them
|
||||
expect(g.models.map((m) => [m.model, m.outcome, m.rows.length])).toEqual([
|
||||
['a', 'CIN2+', 2],
|
||||
['b', 'cancer', 2],
|
||||
]);
|
||||
expect(g.models[0].reasons).toEqual([]); // nothing else shared by both of a's horizons
|
||||
expect(g.models[0].rows[0].reasons).toEqual(['index_date_differs']);
|
||||
expect(g.models[0].rows[1]).toMatchObject({
|
||||
institutional: 0.07,
|
||||
low: 0.05,
|
||||
high: 0.09,
|
||||
reasons: [],
|
||||
});
|
||||
expect(g.models[1].rows[1].reasons).toEqual(['horizon_not_published_by_model']);
|
||||
});
|
||||
it('never merges across outcomes: reasons are only shared where every compared row has them', () => {
|
||||
const g = groupReference(
|
||||
referenceView(
|
||||
two(
|
||||
[
|
||||
cmp('a', 'CIN2+', 'not_comparable', ['outcome_differs']),
|
||||
cmp('b', 'cancer', 'not_comparable', ['no_reference']),
|
||||
],
|
||||
[],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(g.common).toEqual([]);
|
||||
expect(g.models.flatMap((m) => m.rows.flatMap((r) => r.reasons))).toEqual([
|
||||
'outcome_differs',
|
||||
'no_reference',
|
||||
]);
|
||||
});
|
||||
it('a comparable row keeps its difference and a missing interval stays missing', () => {
|
||||
const g = groupReference(
|
||||
referenceView(
|
||||
two(
|
||||
[
|
||||
cmp(
|
||||
'a',
|
||||
'CIN3+',
|
||||
'comparable',
|
||||
[],
|
||||
[
|
||||
part('institutional', { valueDecimal: 0.01 }),
|
||||
part('difference-pp', { valueDecimal: 0.9 }),
|
||||
],
|
||||
),
|
||||
],
|
||||
[],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(g.models[0].rows[0]).toMatchObject({
|
||||
status: 'comparable',
|
||||
differencePp: 0.9,
|
||||
low: undefined,
|
||||
});
|
||||
});
|
||||
it('without a model it says so once, with its reasons', () => {
|
||||
const g = groupReference(
|
||||
referenceView(
|
||||
two(
|
||||
[
|
||||
part('comparison', {
|
||||
part: [
|
||||
part('status', { valueCode: 'not_comparable' }),
|
||||
part('reason', { valueCode: 'no_institutional_model' }),
|
||||
],
|
||||
}),
|
||||
],
|
||||
[
|
||||
part('comparison', {
|
||||
part: [
|
||||
part('status', { valueCode: 'not_comparable' }),
|
||||
part('reason', { valueCode: 'no_institutional_model' }),
|
||||
],
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(g.models).toEqual([]);
|
||||
expect(g.withoutModel).toEqual(['no_institutional_model']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user