@tekkare/romulus 0.1.350 → 0.1.351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/layer/app/components/project/Dashboard.vue +8 -8
- package/layer/app/components/project/Page.vue +3 -2
- package/layer/app/composables/useProjectDashboard.ts +96 -18
- package/layer/app/oip-defaults/dashboardWidgets.ts +14 -14
- package/layer/app/oip-drugs/dashboardWidgets.ts +7 -4
- package/layer/app/oip-italy/dashboardWidgets.ts +318 -0
- package/layer/app/oip-patients/dashboardWidgets.ts +236 -0
- package/layer/app/oip-patients/kinds.ts +10 -2
- package/layer/app/oip-science/dashboardWidgets.ts +7 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
L'onglet « Tableau de bord » d'un projet : RmDashboard branche sur le
|
|
3
|
-
catalogue (
|
|
3
|
+
catalogue (le meme dans toutes les apps, cf. PROJECT_CATALOG)
|
|
4
4
|
et sur l'API des projets (useProjectDashboard, porte par la page : la vue
|
|
5
5
|
d'ensemble en lit l'apercu, et l'onglet garde ses widgets charges quand on
|
|
6
6
|
le quitte, KeepAlive). Repris de France Augmented Science et d'OIP Case
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
qu'elle declare (`sources`), le meme que le panneau Sources et les pieds
|
|
14
14
|
de carte des pages ; le contenu du projet, sans producteur public, est le
|
|
15
15
|
projet lu a l'instant ;
|
|
16
|
-
- les modeles du menu « Modeles » : ceux du layer
|
|
17
|
-
|
|
16
|
+
- les modeles du menu « Modeles » : ceux du layer (PROJECT_TEMPLATES, les
|
|
17
|
+
memes dans toutes les apps), puis les tableaux des autres projets de
|
|
18
18
|
l'utilisateur, a copier ;
|
|
19
19
|
- l'export de l'onglet (tuile Export du rail, rapport PDF) : un onglet de
|
|
20
20
|
classeur par widget, avec ses nombres bruts et les memes sources.
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
import type { RmExportSheet } from "@tekkare/romulus/utils/export";
|
|
46
46
|
import type { RmDashboardTemplate, RmWidgetKind, RmWidgetSource } from "@tekkare/romulus/utils/dashboard";
|
|
47
47
|
import { useOipApi } from "#oip-app/api";
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
import { PROJECT_CATALOG, type ProjectBoard } from "../../composables/useProjectDashboard";
|
|
48
|
+
import { PROJECT_WORDING } from "#oip-projects";
|
|
49
|
+
import type { OipProjectWidgetContext as WidgetContext } from "../../oip-defaults/projects";
|
|
50
|
+
import { PROJECT_CATALOG, PROJECT_TEMPLATES, type ProjectBoard } from "../../composables/useProjectDashboard";
|
|
51
51
|
import { visibleExportCharts } from "../../utils/exportPage";
|
|
52
52
|
import useDirectusSources, { PENDING } from "../../oip-drugs/composables/useDirectusSources";
|
|
53
53
|
|
|
@@ -104,8 +104,8 @@ onMounted(() => projects.load());
|
|
|
104
104
|
|
|
105
105
|
/** Les modeles du layer et de l'app (un `id` d'app l'emporte), puis les autres projets de l'utilisateur, les dix plus recents. */
|
|
106
106
|
const templates = computed<RmDashboardTemplate[]>(() => {
|
|
107
|
-
|
|
108
|
-
const models =
|
|
107
|
+
// Les modeles du layer, les memes dans toutes les apps (cf. useProjectDashboard).
|
|
108
|
+
const models = PROJECT_TEMPLATES;
|
|
109
109
|
const others = projects.projects.value
|
|
110
110
|
.filter((project) => project.id !== props.projectId && !project.href)
|
|
111
111
|
.sort((a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? "")))
|
|
@@ -199,7 +199,6 @@ import {
|
|
|
199
199
|
PROJECTS_UPSELL,
|
|
200
200
|
PROJECT_WORDING,
|
|
201
201
|
WATCHABLE_PROJECT_TYPES,
|
|
202
|
-
projectBrands,
|
|
203
202
|
projectExternalHref,
|
|
204
203
|
useProjectScopeRows,
|
|
205
204
|
useProjectSuggestions,
|
|
@@ -208,6 +207,7 @@ import {
|
|
|
208
207
|
import type { ProjectItem } from "../../composables/useProjects";
|
|
209
208
|
import { oipProjectHydrate, useOipProjectKinds } from "../../composables/useOipProjectKinds";
|
|
210
209
|
import { PROJECT_CATALOG, useProjectDashboard } from "../../composables/useProjectDashboard";
|
|
210
|
+
import { oipProjectBrands } from "../../oip-drugs/dashboardWidgets";
|
|
211
211
|
import type { OipProjectWidgetContext } from "../../oip-defaults/projects";
|
|
212
212
|
import { rmWidgetBrands, rmWidgetKind, rmWidgetParams } from "@tekkare/romulus/utils/dashboard";
|
|
213
213
|
import type {
|
|
@@ -657,7 +657,8 @@ const inboxItems = computed<ProjectInboxItem[]>(() => {
|
|
|
657
657
|
/** Ce que le projet donne a ses widgets : ce que la page a deja relu, et le client de l'app. */
|
|
658
658
|
const widgetApi = useOipApi();
|
|
659
659
|
const widgetContext = computed<OipProjectWidgetContext>(() => ({
|
|
660
|
-
|
|
660
|
+
// Une seule lecture des marques, celle du layer : le tableau est le meme dans toutes les apps.
|
|
661
|
+
brands: oipProjectBrands(dashboardDocs.value),
|
|
661
662
|
lang: lang.value,
|
|
662
663
|
groups: dashboardGroups.value,
|
|
663
664
|
docs: dashboardDocs.value,
|
|
@@ -1,40 +1,118 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Le tableau de bord d'un projet et son branchement sur l'API
|
|
3
3
|
* (`projects.dashboard`, un par projet, commun aux membres et aux apps).
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* Le tableau est le meme quelle que soit l'app qui l'ouvre : un seul
|
|
6
|
+
* catalogue (celui du layer), un seul tableau de depart, une seule liste de
|
|
7
|
+
* modeles, une seule lecture des marques. Le contrat de l'app
|
|
8
|
+
* (`PROJECT_DASHBOARD_WIDGETS`, `defaultProjectDashboard`,
|
|
9
|
+
* `PROJECT_DASHBOARD_TEMPLATES`, `projectBrands`) n'y entre plus : une app
|
|
10
|
+
* qui ajoutait ses widgets les rendait invisibles dans les autres, et un
|
|
11
|
+
* projet sans tableau enregistre s'ouvrait differemment selon l'app.
|
|
6
12
|
*
|
|
7
13
|
* Le tableau de depart se calcule sur le contexte du projet (ses lignes, ses
|
|
8
|
-
* marques, son Inbox) et
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
14
|
+
* marques, son Inbox) et ne pose que les widgets qui ont quelque chose a
|
|
15
|
+
* montrer ; il se recalcule quand le contexte change, tant que rien n'est
|
|
16
|
+
* enregistre. Tout le reste (sauvegarde temporisee, kinds inconnus
|
|
17
|
+
* conserves) est a useRmDashboard, dans Romulus.
|
|
12
18
|
*/
|
|
13
19
|
|
|
14
20
|
import { useOipApi } from "#oip-app/api";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
21
|
+
import type { RmDashboardModel, RmDashboardWidget } from "@tekkare/romulus/utils/dashboard";
|
|
22
|
+
import { rmAddableWidgets, rmNewWidgetId } from "@tekkare/romulus/utils/dashboard";
|
|
23
|
+
import {
|
|
24
|
+
PROJECT_LAYER_TEMPLATES,
|
|
25
|
+
PROJECT_LAYER_WIDGETS,
|
|
26
|
+
type OipProjectDashboardTemplate,
|
|
27
|
+
type OipProjectWidgetContext,
|
|
28
|
+
} from "../oip-defaults/projects";
|
|
29
|
+
import { OIP_DASHBOARD_WIDGETS } from "../oip-defaults/dashboardWidgets";
|
|
30
|
+
|
|
31
|
+
/** Le catalogue de l'onglet, le meme dans toutes les apps : les widgets du contenu, puis ceux des familles. */
|
|
32
|
+
export const PROJECT_CATALOG = [
|
|
33
|
+
...PROJECT_LAYER_WIDGETS,
|
|
34
|
+
...OIP_DASHBOARD_WIDGETS.filter((entry) => !PROJECT_LAYER_WIDGETS.some((own) => own.kind === entry.kind)),
|
|
35
|
+
];
|
|
17
36
|
|
|
18
37
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
38
|
+
* Les widgets du tableau de depart, dans l'ordre de lecture : ce que le
|
|
39
|
+
* projet range et ce qui a bouge, puis une rangee par famille de donnees
|
|
40
|
+
* (ventes, reglementaire, essais, Italie, cas), puis l'activite. Chacun ne
|
|
41
|
+
* se pose que s'il a quelque chose a montrer pour ce projet.
|
|
22
42
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
43
|
+
const DEFAULT_LAYOUT: Array<{ kind: string; viz: RmDashboardWidget["viz"]; w: number; h: number }> = [
|
|
44
|
+
{ kind: "project.resources", viz: "donut", w: 4, h: 5 },
|
|
45
|
+
{ kind: "project.changes", viz: "kpi", w: 8, h: 5 },
|
|
46
|
+
// Ventes (fr_drugs_app)
|
|
47
|
+
{ kind: "medicam.evolution", viz: "line", w: 8, h: 5 },
|
|
48
|
+
{ kind: "medicam.lastMonth", viz: "kpi", w: 4, h: 5 },
|
|
49
|
+
{ kind: "sus.annual", viz: "bar", w: 6, h: 5 },
|
|
50
|
+
{ kind: "phmev.annual", viz: "bar", w: 6, h: 5 },
|
|
51
|
+
// Reglementaire (fr_drugs_app)
|
|
52
|
+
{ kind: "regulatory.milestones", viz: "table", w: 8, h: 6 },
|
|
53
|
+
{ kind: "has.asmr", viz: "donut", w: 4, h: 6 },
|
|
54
|
+
// Essais et publications (France Augmented Science)
|
|
55
|
+
{ kind: "project.trialsByPhase", viz: "bar", w: 4, h: 5 },
|
|
56
|
+
{ kind: "project.trialsByStatus", viz: "donut", w: 4, h: 5 },
|
|
57
|
+
{ kind: "project.publicationsByYear", viz: "bar", w: 4, h: 5 },
|
|
58
|
+
// Italie (Italy One)
|
|
59
|
+
{ kind: "it.aifa.yearly", viz: "bar", w: 6, h: 5 },
|
|
60
|
+
{ kind: "it.prices.count", viz: "bar", w: 6, h: 5 },
|
|
61
|
+
// Cas (OIP Case Atlas)
|
|
62
|
+
{ kind: "cases.keyFigures", viz: "kpi", w: 8, h: 5 },
|
|
63
|
+
{ kind: "patients.byDisease", viz: "bar", w: 4, h: 5 },
|
|
64
|
+
// Activite
|
|
65
|
+
{ kind: "project.recent", viz: "table", w: 8, h: 6 },
|
|
66
|
+
{ kind: "project.activity", viz: "table", w: 4, h: 6 },
|
|
26
67
|
];
|
|
27
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Pose les widgets ligne par ligne sur les 12 colonnes : un widget qui ne
|
|
71
|
+
* tient plus sur la ligne passe a la suivante, sans trou laisse par ceux
|
|
72
|
+
* qui n'ont rien a montrer.
|
|
73
|
+
*/
|
|
74
|
+
function pack(entries: Array<{ kind: string; viz: RmDashboardWidget["viz"]; w: number; h: number }>): RmDashboardModel {
|
|
75
|
+
const widgets: RmDashboardWidget[] = [];
|
|
76
|
+
let x = 0;
|
|
77
|
+
let y = 0;
|
|
78
|
+
let rowHeight = 0;
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
if (x + entry.w > 12) {
|
|
81
|
+
x = 0;
|
|
82
|
+
y += rowHeight;
|
|
83
|
+
rowHeight = 0;
|
|
84
|
+
}
|
|
85
|
+
widgets.push({ id: rmNewWidgetId(), kind: entry.kind, viz: entry.viz, params: {}, layout: { x, y, w: entry.w, h: entry.h } });
|
|
86
|
+
x += entry.w;
|
|
87
|
+
rowHeight = Math.max(rowHeight, entry.h);
|
|
88
|
+
}
|
|
89
|
+
return { version: 1, widgets };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Le tableau de depart d'un projet, le meme dans toutes les apps. */
|
|
93
|
+
export function oipDefaultDashboard(context: OipProjectWidgetContext): RmDashboardModel {
|
|
94
|
+
const addable = new Set(rmAddableWidgets(PROJECT_CATALOG, context).map((entry) => entry.kind));
|
|
95
|
+
return pack(DEFAULT_LAYOUT.filter((entry) => addable.has(entry.kind)));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Les modeles du menu « Modeles », les memes dans toutes les apps. */
|
|
99
|
+
export const PROJECT_TEMPLATES: OipProjectDashboardTemplate[] = PROJECT_LAYER_TEMPLATES.map((template) =>
|
|
100
|
+
template.id === "overview"
|
|
101
|
+
? {
|
|
102
|
+
...template,
|
|
103
|
+
description: { fr: "Le contenu, ce qui a bougé, puis les données de chaque famille.", en: "The content, what changed, then each family's data." },
|
|
104
|
+
build: oipDefaultDashboard,
|
|
105
|
+
}
|
|
106
|
+
: template,
|
|
107
|
+
);
|
|
108
|
+
|
|
28
109
|
export function useProjectDashboard(projectId: string, context: () => OipProjectWidgetContext) {
|
|
29
110
|
const api = useOipApi();
|
|
30
111
|
return useRmDashboard({
|
|
31
112
|
catalog: PROJECT_CATALOG,
|
|
32
113
|
load: async () => (await api.projects.getDashboard(projectId))?.dashboard ?? null,
|
|
33
114
|
save: (dashboard) => api.projects.saveDashboard(projectId, dashboard),
|
|
34
|
-
defaults: () =>
|
|
35
|
-
const current = context();
|
|
36
|
-
return oipPruneDashboard(defaultProjectDashboard(current), PROJECT_CATALOG, current);
|
|
37
|
-
},
|
|
115
|
+
defaults: () => oipDefaultDashboard(context()),
|
|
38
116
|
});
|
|
39
117
|
}
|
|
40
118
|
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Le catalogue complet des widgets de projet
|
|
3
|
-
* les essais et publications (France Augmented
|
|
4
|
-
* reglementaire medicament (fr_drugs_app)
|
|
2
|
+
* Le catalogue complet des widgets de projet, le meme dans toutes les apps :
|
|
3
|
+
* le contenu du projet, les essais et publications (France Augmented
|
|
4
|
+
* Science), les ventes et le reglementaire medicament (fr_drugs_app), les
|
|
5
|
+
* actes AIFA et prix italiens (Italy One), les cas (OIP Case Atlas).
|
|
5
6
|
*
|
|
6
|
-
* Le tableau de bord d'un projet est
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* export { OIP_DASHBOARD_WIDGETS as PROJECT_DASHBOARD_WIDGETS } from "@tekkare/romulus/layer-defaults/dashboardWidgets";
|
|
12
|
-
*
|
|
13
|
-
* Le catalogue par defaut (`PROJECT_DASHBOARD_WIDGETS` de oip-defaults/projects)
|
|
14
|
-
* reste le seul contenu du projet : les widgets medicament lisent des index
|
|
15
|
-
* francais, qu'une app d'un autre pays n'a pas a proposer.
|
|
7
|
+
* Le tableau de bord d'un projet est enregistre une fois, pour toutes les
|
|
8
|
+
* apps : chacune doit pouvoir afficher chaque widget qu'une autre y a pose.
|
|
9
|
+
* Les apps n'ajoutent donc plus de widgets a elles (cf. PROJECT_CATALOG de
|
|
10
|
+
* useProjectDashboard, qui ignore `PROJECT_DASHBOARD_WIDGETS` du contrat).
|
|
11
|
+
* Un widget sans donnee pour le projet se cache (`available`, marques).
|
|
16
12
|
*/
|
|
17
13
|
|
|
18
14
|
import type { RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
19
15
|
import { PROJECT_RESOURCES_WIDGET, type OipProjectWidgetContext } from "./projects";
|
|
20
16
|
import { OIP_SCIENCE_DASHBOARD_WIDGETS } from "../oip-science/dashboardWidgets";
|
|
21
17
|
import { OIP_DRUG_DASHBOARD_WIDGETS } from "../oip-drugs/dashboardWidgets";
|
|
18
|
+
import { OIP_ITALY_DASHBOARD_WIDGETS } from "../oip-italy/dashboardWidgets";
|
|
19
|
+
import { OIP_PATIENT_DASHBOARD_WIDGETS } from "../oip-patients/dashboardWidgets";
|
|
22
20
|
|
|
23
|
-
export { OIP_SCIENCE_DASHBOARD_WIDGETS, OIP_DRUG_DASHBOARD_WIDGETS };
|
|
21
|
+
export { OIP_SCIENCE_DASHBOARD_WIDGETS, OIP_DRUG_DASHBOARD_WIDGETS, OIP_ITALY_DASHBOARD_WIDGETS, OIP_PATIENT_DASHBOARD_WIDGETS };
|
|
24
22
|
/**
|
|
25
23
|
* Les marques que les widgets medicament lisent, a exporter sous le nom
|
|
26
24
|
* `projectBrands` par toute app qui prend ces widgets (`usesBrands`) :
|
|
@@ -33,4 +31,6 @@ export const OIP_DASHBOARD_WIDGETS: RmWidgetKind<OipProjectWidgetContext>[] = [
|
|
|
33
31
|
PROJECT_RESOURCES_WIDGET,
|
|
34
32
|
...OIP_SCIENCE_DASHBOARD_WIDGETS,
|
|
35
33
|
...OIP_DRUG_DASHBOARD_WIDGETS,
|
|
34
|
+
...OIP_ITALY_DASHBOARD_WIDGETS,
|
|
35
|
+
...OIP_PATIENT_DASHBOARD_WIDGETS,
|
|
36
36
|
];
|
|
@@ -997,15 +997,18 @@ const DRUG_WIDGETS: WidgetKind[] = [
|
|
|
997
997
|
const SALES_TYPES = new Set(OIP_RESOURCE_SPECS.filter((spec) => spec.kind.titleFromId).map((spec) => spec.type));
|
|
998
998
|
|
|
999
999
|
/**
|
|
1000
|
-
* Les marques du projet, en majuscules comme le `code` des index de ventes
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1000
|
+
* Les marques du projet, en majuscules comme le `code` des index de ventes,
|
|
1001
|
+
* lues dans les documents que la page a relus : le `code` des ventes, le
|
|
1002
|
+
* `brand_group` des avis HAS, et le champ `brand` de toute autre fiche qui en
|
|
1003
|
+
* porte un (prix, ANSM, MITM, actes AIFA, prix italiens...). Une seule
|
|
1004
|
+
* lecture pour toutes les apps : le tableau de bord d'un projet est le meme
|
|
1005
|
+
* partout.
|
|
1003
1006
|
*/
|
|
1004
1007
|
export function oipProjectBrands(docs: WidgetContext["docs"]): string[] {
|
|
1005
1008
|
const brands = docs.flatMap(({ type, source }) => {
|
|
1006
1009
|
if (SALES_TYPES.has(type)) return [String(source?.code ?? "")];
|
|
1007
1010
|
if (type === "FrHasBrand") return String(source?.brand_group ?? "").split("+");
|
|
1008
|
-
return [];
|
|
1011
|
+
return typeof source?.brand === "string" ? [source.brand] : [];
|
|
1009
1012
|
});
|
|
1010
1013
|
return [...new Set(brands.map((brand) => brand.trim().toUpperCase()).filter(Boolean))].sort();
|
|
1011
1014
|
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les widgets de projet d'Italy One (actes de l'AIFA, prix italiens du Price
|
|
3
|
+
* Tracker), repris de son `app/oip/projects.ts` pour que le tableau de bord
|
|
4
|
+
* d'un projet soit le meme dans toutes les apps.
|
|
5
|
+
*
|
|
6
|
+
* Ils lisent les marques rangees dans le projet (oipProjectBrands) et
|
|
7
|
+
* interrogent les index par le proxy du layer (cluster `drugs`, ou les deux
|
|
8
|
+
* index sont au catalogue de fr_drugs_app). Les `kind` sont ceux d'Italy
|
|
9
|
+
* One : les tableaux deja enregistres les retrouvent.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
rmJoinNotes,
|
|
14
|
+
rmLastYears,
|
|
15
|
+
rmMissingNote,
|
|
16
|
+
rmSeriesByBrand,
|
|
17
|
+
rmSince,
|
|
18
|
+
rmTruncationNote,
|
|
19
|
+
rmWithin,
|
|
20
|
+
rmYearsParam,
|
|
21
|
+
type RmDashboardLang,
|
|
22
|
+
type RmWidgetColumn,
|
|
23
|
+
type RmWidgetKind,
|
|
24
|
+
} from "@tekkare/romulus/utils/dashboard";
|
|
25
|
+
import type { OipProjectWidgetContext } from "../oip-defaults/projects";
|
|
26
|
+
import { ES_INDEX } from "../oip-drugs/esIndices";
|
|
27
|
+
import { oipProjectBrands } from "../oip-drugs/dashboardWidgets";
|
|
28
|
+
|
|
29
|
+
type Lang = RmDashboardLang;
|
|
30
|
+
type WidgetKind = RmWidgetKind<OipProjectWidgetContext>;
|
|
31
|
+
|
|
32
|
+
const AIFA_SOURCE = "a91e97d1-b6b2-4f65-98b4-0914d14c4ac0";
|
|
33
|
+
const OPINION_INDEX = ES_INDEX.APPROVAL_IT_AIFA;
|
|
34
|
+
const PRICE_INDEX = ES_INDEX.WW_PRICE_TRACKER;
|
|
35
|
+
|
|
36
|
+
// Plafonds des listes : au-dela, la note de troncature le dit.
|
|
37
|
+
const MAX_ACTS = 1000;
|
|
38
|
+
const MAX_PRESENTATIONS = 1000;
|
|
39
|
+
|
|
40
|
+
const REGULATORY = { fr: "Réglementaire (AIFA)", en: "Regulatory (AIFA)" };
|
|
41
|
+
const PRICES = { fr: "Prix (Italie)", en: "Prices (Italy)" };
|
|
42
|
+
|
|
43
|
+
const T = (lang: Lang, fr: string, en: string) => (lang === "en" ? en : fr);
|
|
44
|
+
|
|
45
|
+
function col(key: string, label: string, extra: Partial<RmWidgetColumn> = {}): RmWidgetColumn {
|
|
46
|
+
return { key, label, ...extra };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function search(index: string, body: Record<string, unknown>): Promise<any> {
|
|
50
|
+
return $fetch(`/api/oip/es?cluster=drugs&index=${encodeURIComponent(index)}`, { method: "POST", body });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Les familles italiennes : un projet sans aucune d'elles ne propose pas ces widgets. */
|
|
54
|
+
const ITALIAN_TYPES = new Set(["ItApproval", "ItDrugPrice", "ItDrugReimbursement"]);
|
|
55
|
+
const hasItaly = (context: OipProjectWidgetContext) => context.docs.some((doc) => ITALIAN_TYPES.has(doc.type));
|
|
56
|
+
|
|
57
|
+
/** Note quand le projet ne range encore aucune marque. */
|
|
58
|
+
const noBrandNote = (lang: Lang) =>
|
|
59
|
+
T(lang, "Aucune marque dans le projet : ajoutez des actes AIFA ou des prix depuis Italy One.", "No brand in the project yet: add AIFA acts or prices from Italy One.");
|
|
60
|
+
|
|
61
|
+
const day = (value: unknown) => String(value ?? "").slice(0, 10);
|
|
62
|
+
|
|
63
|
+
// --- Prix : les regles d'Italy One (usePriceGroups) -------------------------
|
|
64
|
+
|
|
65
|
+
const PRICE_TYPES: { id: number; en: string; fr: string }[] = [
|
|
66
|
+
{ id: 1, en: "Ex-factory", fr: "Prix ex-usine" },
|
|
67
|
+
{ id: 2, en: "Wholesale", fr: "Prix grossiste" },
|
|
68
|
+
{ id: 11, en: "Public price", fr: "Prix public" },
|
|
69
|
+
{ id: 12, en: "Reimbursement", fr: "Remboursement" },
|
|
70
|
+
{ id: 13, en: "Government", fr: "Prix gouvernement" },
|
|
71
|
+
{ id: 14, en: "Patient price", fr: "Prix patient" },
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
/** Un prix qui ne fait que redire un prix en amont disparait des que celui-ci est publie. */
|
|
75
|
+
const SUPERSEDED_BY: Record<number, number[]> = { 11: [1], 13: [1], 12: [1, 11] };
|
|
76
|
+
|
|
77
|
+
/** L'historique d'un type de prix, du plus recent au plus ancien (l'index ne le garantit pas). */
|
|
78
|
+
const historyOf = (product: any, priceTypeId?: number) =>
|
|
79
|
+
(product?.price_history ?? [])
|
|
80
|
+
.filter((item: any) => priceTypeId === undefined || item.price_type_id === priceTypeId)
|
|
81
|
+
.slice()
|
|
82
|
+
.sort((a: any, b: any) => new Date(b.application_date ?? 0).getTime() - new Date(a.application_date ?? 0).getTime());
|
|
83
|
+
|
|
84
|
+
/** Un changement n'en est un que si les deux prix sont des nombres et different. */
|
|
85
|
+
const priceDelta = (entry: any) => {
|
|
86
|
+
const from = entry?.last_price;
|
|
87
|
+
const to = entry?.new_price;
|
|
88
|
+
if (from === null || from === undefined || to === null || to === undefined) return null;
|
|
89
|
+
if (!Number.isFinite(Number(from)) || !Number.isFinite(Number(to))) return null;
|
|
90
|
+
if (Number(from) === Number(to)) return null;
|
|
91
|
+
return Number(to) - Number(from);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const formatPrice = (value: number) =>
|
|
95
|
+
value.toLocaleString("fr-FR", Math.abs(value) < 3 ? { minimumFractionDigits: 3, maximumFractionDigits: 3 } : { maximumFractionDigits: 1 }).replace(",", ".");
|
|
96
|
+
|
|
97
|
+
const typeLabel = (id: number, lang: Lang) => {
|
|
98
|
+
const type = PRICE_TYPES.find((entry) => entry.id === id);
|
|
99
|
+
return type ? (lang === "en" ? type.en : type.fr) : String(id);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Le prix retenu d'un produit : ex-usine, sinon prix public, sinon remboursement. */
|
|
103
|
+
function mainPrice(product: any): { typeId: number; price: number } | null {
|
|
104
|
+
const order = [1, 11, 12, ...PRICE_TYPES.map((entry) => entry.id).filter((id) => ![1, 11, 12].includes(id))];
|
|
105
|
+
for (const id of order) {
|
|
106
|
+
if (SUPERSEDED_BY[id]?.some((above) => historyOf(product, above).length)) continue;
|
|
107
|
+
const current = historyOf(product, id)[0];
|
|
108
|
+
if (current && Number.isFinite(Number(current.new_price))) return { typeId: id, price: Number(current.new_price) };
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// --- Actes de l'AIFA --------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
async function aifaActs(brands: string[]) {
|
|
116
|
+
const response = await search(OPINION_INDEX, {
|
|
117
|
+
size: MAX_ACTS,
|
|
118
|
+
track_total_hits: true,
|
|
119
|
+
query: { bool: { must: [{ terms: { "brand.keyword": brands } }] } },
|
|
120
|
+
sort: [{ decision_date: { order: "desc", missing: "_last" } }],
|
|
121
|
+
_source: ["brand", "decision_date", "document_type", "nature_of_request", "nature_of_request_en", "theme_en", "indication", "indication_en", "has_code"],
|
|
122
|
+
});
|
|
123
|
+
const acts = (response?.hits?.hits ?? []).map((hit: any) => hit._source);
|
|
124
|
+
return { acts, response, found: new Set<string>(acts.map((act: any) => String(act.brand))) };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const AIFA_ACTS: WidgetKind = {
|
|
128
|
+
kind: "it.aifa.acts",
|
|
129
|
+
sources: [AIFA_SOURCE],
|
|
130
|
+
group: REGULATORY,
|
|
131
|
+
title: { fr: "Actes de l'AIFA", en: "AIFA acts" },
|
|
132
|
+
description: {
|
|
133
|
+
fr: "Les actes réglementaires de l'AIFA sur les marques du projet, du plus récent au plus ancien.",
|
|
134
|
+
en: "AIFA regulatory acts on the project's brands, newest first.",
|
|
135
|
+
},
|
|
136
|
+
viz: ["table"],
|
|
137
|
+
usesBrands: false,
|
|
138
|
+
available: hasItaly,
|
|
139
|
+
params: [rmYearsParam(["1", "3", "5", "10"])],
|
|
140
|
+
size: { w: 12, h: 6 },
|
|
141
|
+
async fetch(params, { docs, lang }) {
|
|
142
|
+
const brands = oipProjectBrands(docs);
|
|
143
|
+
if (!brands.length) return { type: "rows", columns: [], rows: [], note: noBrandNote(lang) };
|
|
144
|
+
const { acts, response, found } = await aifaActs(brands);
|
|
145
|
+
const rows = acts.map((act: any) => ({
|
|
146
|
+
date: day(act.decision_date),
|
|
147
|
+
brand: String(act.brand ?? ""),
|
|
148
|
+
nature: String(act.nature_of_request_en || act.nature_of_request || ""),
|
|
149
|
+
theme: String(act.theme_en ?? ""),
|
|
150
|
+
code: String(act.has_code ?? ""),
|
|
151
|
+
indication: String((lang === "en" ? act.indication_en : act.indication) || act.indication || ""),
|
|
152
|
+
}));
|
|
153
|
+
return {
|
|
154
|
+
type: "rows",
|
|
155
|
+
columns: [
|
|
156
|
+
col("date", T(lang, "Date", "Date"), { date: true }),
|
|
157
|
+
col("brand", T(lang, "Marque", "Brand")),
|
|
158
|
+
col("nature", T(lang, "Nature de la demande", "Nature of request")),
|
|
159
|
+
col("theme", T(lang, "Aire thérapeutique", "Therapeutic area"), { optional: true }),
|
|
160
|
+
col("code", T(lang, "Référence", "Reference"), { optional: true }),
|
|
161
|
+
col("indication", T(lang, "Indication", "Indication"), { long: true, optional: true }),
|
|
162
|
+
],
|
|
163
|
+
rows: rmWithin(rows, "date", rmSince(params.years)),
|
|
164
|
+
note: rmJoinNotes(rmTruncationNote(acts.length, response?.hits?.total?.value ?? 0, lang), rmMissingNote(brands, found, lang)),
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const AIFA_YEARLY: WidgetKind = {
|
|
170
|
+
kind: "it.aifa.yearly",
|
|
171
|
+
sources: [AIFA_SOURCE],
|
|
172
|
+
group: REGULATORY,
|
|
173
|
+
title: { fr: "Actes de l'AIFA par année", en: "AIFA acts per year" },
|
|
174
|
+
description: { fr: "Le nombre d'actes publiés chaque année, par marque du projet.", en: "How many acts were published each year, per project brand." },
|
|
175
|
+
viz: ["bar", "line", "table"],
|
|
176
|
+
usesBrands: false,
|
|
177
|
+
available: hasItaly,
|
|
178
|
+
params: [rmYearsParam(["5", "10"])],
|
|
179
|
+
size: { w: 6, h: 5 },
|
|
180
|
+
async fetch(params, { docs, lang }) {
|
|
181
|
+
const brands = oipProjectBrands(docs);
|
|
182
|
+
if (!brands.length) return { type: "series", categories: [], series: [], note: noBrandNote(lang) };
|
|
183
|
+
// Une agregation plutot qu'une liste : une marque ancienne compte des centaines d'actes.
|
|
184
|
+
const response = await search(OPINION_INDEX, {
|
|
185
|
+
size: 0,
|
|
186
|
+
query: { bool: { must: [{ terms: { "brand.keyword": brands } }] } },
|
|
187
|
+
aggs: {
|
|
188
|
+
brands: {
|
|
189
|
+
terms: { field: "brand.keyword", size: brands.length },
|
|
190
|
+
aggs: { years: { date_histogram: { field: "decision_date", calendar_interval: "year", format: "yyyy", min_doc_count: 1 } } },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
const buckets = response?.aggregations?.brands?.buckets ?? [];
|
|
195
|
+
const rows = buckets.flatMap((bucket: any) =>
|
|
196
|
+
(bucket.years?.buckets ?? []).map((year: any) => ({ brand: String(bucket.key), period: String(year.key_as_string), value: year.doc_count as number })),
|
|
197
|
+
);
|
|
198
|
+
const found = new Set<string>(buckets.map((bucket: any) => String(bucket.key)));
|
|
199
|
+
return { ...rmLastYears(rmSeriesByBrand(rows, brands), params.years, false), note: rmMissingNote(brands, found, lang) };
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const AIFA_NATURES: WidgetKind = {
|
|
204
|
+
kind: "it.aifa.natures",
|
|
205
|
+
sources: [AIFA_SOURCE],
|
|
206
|
+
group: REGULATORY,
|
|
207
|
+
title: { fr: "Actes de l'AIFA par nature", en: "AIFA acts by nature" },
|
|
208
|
+
description: { fr: "Les actes des marques du projet, comptés par nature de la demande.", en: "The project brands' acts, counted by nature of request." },
|
|
209
|
+
viz: ["donut", "bar", "table"],
|
|
210
|
+
usesBrands: false,
|
|
211
|
+
available: hasItaly,
|
|
212
|
+
params: [rmYearsParam(["1", "3", "5", "10"])],
|
|
213
|
+
size: { w: 6, h: 5 },
|
|
214
|
+
async fetch(params, { docs, lang }) {
|
|
215
|
+
const brands = oipProjectBrands(docs);
|
|
216
|
+
if (!brands.length) return { type: "parts", parts: [], note: noBrandNote(lang) };
|
|
217
|
+
const from = rmSince(params.years);
|
|
218
|
+
// La nature en anglais dans les deux langues, comme Italy One (l'original est en italien).
|
|
219
|
+
const response = await search(OPINION_INDEX, {
|
|
220
|
+
size: 0,
|
|
221
|
+
query: { bool: { must: [{ terms: { "brand.keyword": brands } }, ...(from ? [{ range: { decision_date: { gte: from } } }] : [])] } },
|
|
222
|
+
aggs: { natures: { terms: { field: "nature_of_request_en.keyword", size: 20 } }, brands: { terms: { field: "brand.keyword", size: brands.length } } },
|
|
223
|
+
});
|
|
224
|
+
const parts = (response?.aggregations?.natures?.buckets ?? []).map((bucket: any) => ({ name: String(bucket.key), value: bucket.doc_count as number }));
|
|
225
|
+
const found = new Set<string>((response?.aggregations?.brands?.buckets ?? []).map((bucket: any) => String(bucket.key)));
|
|
226
|
+
return { type: "parts", parts, note: rmMissingNote(brands, found, lang) };
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// --- Prix italiens ----------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
const PRICE_LIST: WidgetKind = {
|
|
233
|
+
kind: "it.prices.presentations",
|
|
234
|
+
sources: [AIFA_SOURCE],
|
|
235
|
+
group: PRICES,
|
|
236
|
+
title: { fr: "Prix des présentations (Italie)", en: "Presentation prices (Italy)" },
|
|
237
|
+
description: {
|
|
238
|
+
fr: "Les présentations italiennes des marques du projet, avec leur prix en vigueur et leur dernier changement.",
|
|
239
|
+
en: "The project brands' Italian presentations, with their current price and last change.",
|
|
240
|
+
},
|
|
241
|
+
viz: ["table"],
|
|
242
|
+
usesBrands: false,
|
|
243
|
+
available: hasItaly,
|
|
244
|
+
params: [],
|
|
245
|
+
size: { w: 12, h: 6 },
|
|
246
|
+
async fetch(_params, { docs, lang }) {
|
|
247
|
+
const brands = oipProjectBrands(docs);
|
|
248
|
+
if (!brands.length) return { type: "rows", columns: [], rows: [], note: noBrandNote(lang) };
|
|
249
|
+
const response = await search(PRICE_INDEX, {
|
|
250
|
+
size: MAX_PRESENTATIONS,
|
|
251
|
+
track_total_hits: true,
|
|
252
|
+
query: { bool: { must: [{ term: { "country_code.keyword": "it" } }, { terms: { "brand.keyword": brands } }] } },
|
|
253
|
+
sort: [{ last_price_update: { order: "desc", missing: "_last" } }],
|
|
254
|
+
_source: ["brand", "label_local", "local_drug_id", "manufacturer_regroup", "manufacturer", "price_history", "last_price_update"],
|
|
255
|
+
});
|
|
256
|
+
const products = (response?.hits?.hits ?? []).map((hit: any) => hit._source);
|
|
257
|
+
const found = new Set<string>(products.map((product: any) => String(product.brand)));
|
|
258
|
+
const rows = products.map((product: any) => {
|
|
259
|
+
const main = mainPrice(product);
|
|
260
|
+
const change = main ? historyOf(product, main.typeId).find((item: any) => priceDelta(item) !== null) : null;
|
|
261
|
+
return {
|
|
262
|
+
brand: String(product.brand ?? ""),
|
|
263
|
+
product: String(product.label_local ?? "").toUpperCase(),
|
|
264
|
+
code: String(product.local_drug_id ?? ""),
|
|
265
|
+
company: String(product.manufacturer_regroup ?? product.manufacturer ?? ""),
|
|
266
|
+
type: main ? typeLabel(main.typeId, lang) : "",
|
|
267
|
+
price: main ? `${formatPrice(main.price)} €` : null,
|
|
268
|
+
change: change ? day(change.application_date) : null,
|
|
269
|
+
evol: change && Number(change.last_price) ? Math.round((priceDelta(change)! / Number(change.last_price)) * 10000) / 100 : null,
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
type: "rows",
|
|
274
|
+
columns: [
|
|
275
|
+
col("brand", T(lang, "Marque", "Brand")),
|
|
276
|
+
col("product", T(lang, "Présentation", "Presentation"), { long: true }),
|
|
277
|
+
col("code", "AIC", { optional: true }),
|
|
278
|
+
col("company", T(lang, "Laboratoire", "Company"), { optional: true }),
|
|
279
|
+
col("type", T(lang, "Type de prix", "Price type")),
|
|
280
|
+
col("price", T(lang, "Prix", "Price"), { numeric: true }),
|
|
281
|
+
col("change", T(lang, "Dernier changement", "Last change"), { date: true }),
|
|
282
|
+
col("evol", T(lang, "% évol.", "% evol"), { numeric: true, optional: true }),
|
|
283
|
+
],
|
|
284
|
+
rows,
|
|
285
|
+
note: rmJoinNotes(rmTruncationNote(products.length, response?.hits?.total?.value ?? 0, lang), rmMissingNote(brands, found, lang)),
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const PRICE_COUNT: WidgetKind = {
|
|
291
|
+
kind: "it.prices.count",
|
|
292
|
+
sources: [AIFA_SOURCE],
|
|
293
|
+
group: PRICES,
|
|
294
|
+
title: { fr: "Présentations par marque (Italie)", en: "Presentations per brand (Italy)" },
|
|
295
|
+
description: { fr: "Le nombre de présentations italiennes de chaque marque du projet.", en: "How many Italian presentations each project brand has." },
|
|
296
|
+
viz: ["bar", "donut", "table"],
|
|
297
|
+
usesBrands: false,
|
|
298
|
+
available: hasItaly,
|
|
299
|
+
params: [],
|
|
300
|
+
size: { w: 6, h: 5 },
|
|
301
|
+
async fetch(_params, { docs, lang }) {
|
|
302
|
+
const brands = oipProjectBrands(docs);
|
|
303
|
+
if (!brands.length) return { type: "parts", parts: [], note: noBrandNote(lang) };
|
|
304
|
+
const response = await search(PRICE_INDEX, {
|
|
305
|
+
size: 0,
|
|
306
|
+
query: { bool: { must: [{ term: { "country_code.keyword": "it" } }, { terms: { "brand.keyword": brands } }] } },
|
|
307
|
+
aggs: { brands: { terms: { field: "brand.keyword", size: brands.length } } },
|
|
308
|
+
});
|
|
309
|
+
const buckets = response?.aggregations?.brands?.buckets ?? [];
|
|
310
|
+
return {
|
|
311
|
+
type: "parts",
|
|
312
|
+
parts: buckets.map((bucket: any) => ({ name: String(bucket.key), value: bucket.doc_count as number })),
|
|
313
|
+
note: rmMissingNote(brands, new Set(buckets.map((bucket: any) => String(bucket.key))), lang),
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export const OIP_ITALY_DASHBOARD_WIDGETS: WidgetKind[] = [AIFA_ACTS, AIFA_YEARLY, AIFA_NATURES, PRICE_LIST, PRICE_COUNT];
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les widgets de projet d'OIP Case Atlas (cas de maladies rares, cas apres
|
|
3
|
+
* vaccination), repris de son `utils/dashboardWidgets.ts` pour que le tableau
|
|
4
|
+
* de bord d'un projet soit le meme dans toutes les apps.
|
|
5
|
+
*
|
|
6
|
+
* Ils comptent ce que le projet range, a partir des documents deja relus par
|
|
7
|
+
* la page (champs `source` de PATIENT_KIND et VACCINE_KIND) : aucune requete
|
|
8
|
+
* de plus. Les `kind` sont ceux de Case Atlas : les tableaux deja
|
|
9
|
+
* enregistres les retrouvent.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { RmDashboardLang, RmWidgetData, RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
13
|
+
import type { OipProjectWidgetContext } from "../oip-defaults/projects";
|
|
14
|
+
import { OUTCOME_LABELS, patientDiseaseName, patientLabelOf } from "./labels";
|
|
15
|
+
import { SERIOUSNESS_LABELS, vaccineLabelOf } from "./vaccineLabels";
|
|
16
|
+
|
|
17
|
+
type Lang = RmDashboardLang;
|
|
18
|
+
type WidgetKind = RmWidgetKind<OipProjectWidgetContext>;
|
|
19
|
+
|
|
20
|
+
const PATIENT = "PatientProfile";
|
|
21
|
+
const VACCINE = "VaccinePatient";
|
|
22
|
+
|
|
23
|
+
const TEXT = (fr: string, en: string) => ({ fr, en });
|
|
24
|
+
const CASES = TEXT("Cas (Case Atlas)", "Cases (Case Atlas)");
|
|
25
|
+
const PATIENTS = TEXT("Maladies rares", "Rare diseases");
|
|
26
|
+
const VACCINES = TEXT("Vaccins", "Vaccines");
|
|
27
|
+
|
|
28
|
+
/** Au-dela, les valeurs les moins citees se regroupent : un donut de 40 parts ne se lit plus. */
|
|
29
|
+
const TOP = 12;
|
|
30
|
+
|
|
31
|
+
const sourcesOf = (docs: OipProjectWidgetContext["docs"], type: string) => docs.filter((doc) => doc.type === type).map((doc) => doc.source ?? {});
|
|
32
|
+
|
|
33
|
+
const has = (type: string) => (context: OipProjectWidgetContext) => context.docs.some((doc) => doc.type === type);
|
|
34
|
+
const hasCases = (context: OipProjectWidgetContext) => context.docs.some((doc) => doc.type === PATIENT || doc.type === VACCINE);
|
|
35
|
+
|
|
36
|
+
const listOf = (value: unknown): string[] =>
|
|
37
|
+
(Array.isArray(value) ? value : value === null || value === undefined || value === "" ? [] : [value]).map((v) => String(v).trim()).filter(Boolean);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Les parts d'une liste de valeurs (un cas peut en porter plusieurs : ses
|
|
41
|
+
* genes, ses maladies), les plus citees d'abord. Ce qui depasse TOP se range
|
|
42
|
+
* sous « Autres », et la note le dit.
|
|
43
|
+
*/
|
|
44
|
+
function countParts(values: string[][], lang: Lang): RmWidgetData {
|
|
45
|
+
const counts = new Map<string, number>();
|
|
46
|
+
for (const list of values) for (const value of new Set(list)) counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
47
|
+
const sorted = [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
48
|
+
const parts = sorted.slice(0, TOP).map(([name, value]) => ({ name, value }));
|
|
49
|
+
const rest = sorted.slice(TOP).reduce((sum, [, value]) => sum + value, 0);
|
|
50
|
+
if (rest) parts.push({ name: lang === "en" ? "Others" : "Autres", value: rest });
|
|
51
|
+
const missing = values.filter((list) => !list.length).length;
|
|
52
|
+
const notes = [
|
|
53
|
+
sorted.length > TOP
|
|
54
|
+
? lang === "en"
|
|
55
|
+
? `${sorted.length - TOP} less frequent values grouped under Others.`
|
|
56
|
+
: `${sorted.length - TOP} valeurs moins fréquentes regroupées sous Autres.`
|
|
57
|
+
: "",
|
|
58
|
+
missing ? (lang === "en" ? `${missing} case${missing > 1 ? "s" : ""} without this information.` : `${missing} cas sans cette information.`) : "",
|
|
59
|
+
].filter(Boolean);
|
|
60
|
+
return { type: "parts", parts, ...(notes.length ? { note: notes.join(" ") } : {}) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Le pays d'un cas : ceux du groupe pour une cohorte, sinon celui du cas. */
|
|
64
|
+
const countriesOf = (doc: Record<string, any>) => (listOf(doc.cohort_country_names).length ? listOf(doc.cohort_country_names) : listOf(doc.country));
|
|
65
|
+
|
|
66
|
+
export const OIP_PATIENT_DASHBOARD_WIDGETS: WidgetKind[] = [
|
|
67
|
+
{
|
|
68
|
+
kind: "cases.keyFigures",
|
|
69
|
+
group: CASES,
|
|
70
|
+
title: TEXT("Chiffres clés des cas", "Case key figures"),
|
|
71
|
+
description: TEXT("Cas de maladies rares, cas après vaccination, patients décrits, articles et pays.", "Rare disease cases, vaccine cases, patients described, papers and countries."),
|
|
72
|
+
viz: ["kpi", "table"],
|
|
73
|
+
sources: [],
|
|
74
|
+
usesBrands: false,
|
|
75
|
+
available: hasCases,
|
|
76
|
+
params: [],
|
|
77
|
+
size: { w: 8, h: 5 },
|
|
78
|
+
async fetch(_params, { docs, lang }) {
|
|
79
|
+
const patients = sourcesOf(docs, PATIENT);
|
|
80
|
+
const vaccines = sourcesOf(docs, VACCINE);
|
|
81
|
+
const all = [...patients, ...vaccines];
|
|
82
|
+
// Un groupe compte ses membres ; un cas seul, une personne.
|
|
83
|
+
const people = all.reduce((sum, doc) => sum + (doc.record_type === "cohort" ? Number(doc.n_patients) || 0 : 1), 0);
|
|
84
|
+
const papers = new Set(all.map((doc) => doc.pmid).filter(Boolean)).size;
|
|
85
|
+
const countries = new Set(all.flatMap(countriesOf)).size;
|
|
86
|
+
const kpi = (fr: string, en: string, value: number) => ({ label: lang === "en" ? en : fr, value, previous: null });
|
|
87
|
+
return {
|
|
88
|
+
type: "kpi",
|
|
89
|
+
period: "",
|
|
90
|
+
items: [
|
|
91
|
+
kpi("Cas de maladies rares", "Rare disease cases", patients.length),
|
|
92
|
+
kpi("Cas après vaccination", "Vaccine cases", vaccines.length),
|
|
93
|
+
kpi("Patients décrits", "Patients described", people),
|
|
94
|
+
kpi("Articles", "Papers", papers),
|
|
95
|
+
kpi("Pays", "Countries", countries),
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
kind: "cases.byYear",
|
|
102
|
+
group: CASES,
|
|
103
|
+
title: TEXT("Cas par année de publication", "Cases per publication year"),
|
|
104
|
+
description: TEXT("Les cas du projet par année de l'article, une série par famille.", "The project's cases per paper year, one series per family."),
|
|
105
|
+
viz: ["bar", "line", "table"],
|
|
106
|
+
sources: [],
|
|
107
|
+
usesBrands: false,
|
|
108
|
+
available: hasCases,
|
|
109
|
+
params: [],
|
|
110
|
+
size: { w: 8, h: 5 },
|
|
111
|
+
async fetch(_params, { docs, lang }) {
|
|
112
|
+
const families = [
|
|
113
|
+
{ type: PATIENT, name: lang === "en" ? "Rare disease cases" : "Cas de maladies rares" },
|
|
114
|
+
{ type: VACCINE, name: lang === "en" ? "Vaccine cases" : "Cas après vaccination" },
|
|
115
|
+
];
|
|
116
|
+
const years = new Set<string>();
|
|
117
|
+
const counts = families.map(({ type }) => {
|
|
118
|
+
const byYear = new Map<string, number>();
|
|
119
|
+
for (const doc of sourcesOf(docs, type)) {
|
|
120
|
+
const year = String(doc.year ?? "").match(/\d{4}/)?.[0];
|
|
121
|
+
if (!year) continue;
|
|
122
|
+
years.add(year);
|
|
123
|
+
byYear.set(year, (byYear.get(year) ?? 0) + 1);
|
|
124
|
+
}
|
|
125
|
+
return byYear;
|
|
126
|
+
});
|
|
127
|
+
const categories = [...years].sort();
|
|
128
|
+
return {
|
|
129
|
+
type: "series",
|
|
130
|
+
categories,
|
|
131
|
+
series: families
|
|
132
|
+
.map((family, index) => ({ name: family.name, data: categories.map((year) => counts[index]!.get(year) ?? 0) }))
|
|
133
|
+
.filter((serie) => serie.data.some(Boolean)),
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
kind: "cases.byCountry",
|
|
139
|
+
group: CASES,
|
|
140
|
+
title: TEXT("Cas par pays", "Cases per country"),
|
|
141
|
+
description: TEXT("Les pays des cas du projet, toutes familles confondues.", "Where the project's cases come from, all families together."),
|
|
142
|
+
viz: ["bar", "donut", "table"],
|
|
143
|
+
sources: [],
|
|
144
|
+
usesBrands: false,
|
|
145
|
+
available: hasCases,
|
|
146
|
+
params: [],
|
|
147
|
+
size: { w: 4, h: 5 },
|
|
148
|
+
async fetch(_params, { docs, lang }) {
|
|
149
|
+
return countParts(docs.filter((doc) => doc.type === PATIENT || doc.type === VACCINE).map((doc) => countriesOf(doc.source ?? {})), lang);
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
kind: "patients.byDisease",
|
|
154
|
+
group: PATIENTS,
|
|
155
|
+
title: TEXT("Maladies rares du projet", "Project rare diseases"),
|
|
156
|
+
description: TEXT("Les cas de maladies rares du projet, par maladie Orphanet.", "The project's rare disease cases, per Orphanet disease."),
|
|
157
|
+
viz: ["bar", "donut", "table"],
|
|
158
|
+
sources: [],
|
|
159
|
+
usesBrands: false,
|
|
160
|
+
available: has(PATIENT),
|
|
161
|
+
params: [],
|
|
162
|
+
size: { w: 6, h: 5 },
|
|
163
|
+
async fetch(_params, { docs, lang }) {
|
|
164
|
+
return countParts(
|
|
165
|
+
sourcesOf(docs, PATIENT).map((doc) => {
|
|
166
|
+
const orpha = listOf(doc.condition_name_orpha);
|
|
167
|
+
return orpha.length ? orpha : listOf(patientDiseaseName(doc));
|
|
168
|
+
}),
|
|
169
|
+
lang,
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
kind: "patients.byGene",
|
|
175
|
+
group: PATIENTS,
|
|
176
|
+
title: TEXT("Gènes des cas", "Case genes"),
|
|
177
|
+
description: TEXT("Les gènes cités par les cas de maladies rares du projet.", "The genes named by the project's rare disease cases."),
|
|
178
|
+
viz: ["bar", "donut", "table"],
|
|
179
|
+
sources: [],
|
|
180
|
+
usesBrands: false,
|
|
181
|
+
available: has(PATIENT),
|
|
182
|
+
params: [],
|
|
183
|
+
size: { w: 6, h: 5 },
|
|
184
|
+
async fetch(_params, { docs, lang }) {
|
|
185
|
+
return countParts(sourcesOf(docs, PATIENT).map((doc) => listOf(doc.genes)), lang);
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
kind: "patients.byOutcome",
|
|
190
|
+
group: PATIENTS,
|
|
191
|
+
title: TEXT("Issue des cas", "Case outcomes"),
|
|
192
|
+
description: TEXT("Les cas de maladies rares du projet, par issue rapportée.", "The project's rare disease cases, per reported outcome."),
|
|
193
|
+
viz: ["donut", "bar", "table"],
|
|
194
|
+
sources: [],
|
|
195
|
+
usesBrands: false,
|
|
196
|
+
available: has(PATIENT),
|
|
197
|
+
params: [],
|
|
198
|
+
size: { w: 4, h: 5 },
|
|
199
|
+
async fetch(_params, { docs, lang }) {
|
|
200
|
+
return countParts(
|
|
201
|
+
sourcesOf(docs, PATIENT).map((doc) => (doc.outcome && doc.outcome !== "unknown" ? [patientLabelOf(OUTCOME_LABELS, doc.outcome, lang)] : [])),
|
|
202
|
+
lang,
|
|
203
|
+
);
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
kind: "vaccines.byVaccine",
|
|
208
|
+
group: VACCINES,
|
|
209
|
+
title: TEXT("Vaccins des cas", "Case vaccines"),
|
|
210
|
+
description: TEXT("Les cas après vaccination du projet, par vaccin.", "The project's vaccine cases, per vaccine."),
|
|
211
|
+
viz: ["donut", "bar", "table"],
|
|
212
|
+
sources: [],
|
|
213
|
+
usesBrands: false,
|
|
214
|
+
available: has(VACCINE),
|
|
215
|
+
params: [],
|
|
216
|
+
size: { w: 4, h: 5 },
|
|
217
|
+
async fetch(_params, { docs, lang }) {
|
|
218
|
+
return countParts(sourcesOf(docs, VACCINE).map((doc) => listOf(doc.vaccine_product_label || doc.vaccine_product)), lang);
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
kind: "vaccines.bySeriousness",
|
|
223
|
+
group: VACCINES,
|
|
224
|
+
title: TEXT("Gravité des cas", "Case seriousness"),
|
|
225
|
+
description: TEXT("Les cas après vaccination du projet, par gravité rapportée.", "The project's vaccine cases, per reported seriousness."),
|
|
226
|
+
viz: ["donut", "bar", "table"],
|
|
227
|
+
sources: [],
|
|
228
|
+
usesBrands: false,
|
|
229
|
+
available: has(VACCINE),
|
|
230
|
+
params: [],
|
|
231
|
+
size: { w: 4, h: 5 },
|
|
232
|
+
async fetch(_params, { docs, lang }) {
|
|
233
|
+
return countParts(sourcesOf(docs, VACCINE).map((doc) => listOf(doc.seriousness).map((value) => vaccineLabelOf(SERIOUSNESS_LABELS, value, lang))), lang);
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
];
|
|
@@ -26,7 +26,11 @@ export const PATIENT_KIND: RmProjectKind = {
|
|
|
26
26
|
label: { fr: "Cas de maladies rares", en: "Rare disease cases" },
|
|
27
27
|
icon: "UsersThree",
|
|
28
28
|
// Les champs du titre, et ceux des autres sujets du meme article (cf. PatientFiche).
|
|
29
|
-
|
|
29
|
+
// Les champs des widgets du tableau de bord en plus (maladie Orphanet, genes, issue, pays).
|
|
30
|
+
source: [
|
|
31
|
+
"record_id", "record_type", "condition", "cohort_condition", "label", "n_patients", "pmid", "year",
|
|
32
|
+
"condition_name_orpha", "genes", "outcome", "country", "cohort_country_names",
|
|
33
|
+
],
|
|
30
34
|
title: (s, lang) => patientDiseaseName(s) || (lang === "fr" ? "Pathologie non précisée" : "Condition not stated"),
|
|
31
35
|
subtitle: (s) =>
|
|
32
36
|
[s.record_type === "cohort" ? "" : patientLabel(s.label), s.pmid ? `PMID ${s.pmid}` : "", s.year]
|
|
@@ -40,7 +44,11 @@ export const VACCINE_KIND: RmProjectKind = {
|
|
|
40
44
|
index: OIP_PATIENT_INDEXES.VACCINE_PATIENTS,
|
|
41
45
|
label: { fr: "Cas après vaccination", en: "Vaccine cases" },
|
|
42
46
|
icon: "Syringe",
|
|
43
|
-
|
|
47
|
+
// Les champs des widgets du tableau de bord en plus (vaccin, gravite, pays).
|
|
48
|
+
source: [
|
|
49
|
+
"record_id", "event_term", "label", "vaccine_product_label", "pmid", "year",
|
|
50
|
+
"vaccine_product", "seriousness", "record_type", "n_patients", "country", "cohort_country_names",
|
|
51
|
+
],
|
|
44
52
|
title: (s, lang) => s.event_term || (lang === "fr" ? "Événement non nommé" : "Event not named"),
|
|
45
53
|
subtitle: (s) => [s.vaccine_product_label, s.pmid ? `PMID ${s.pmid}` : "", s.year].filter(Boolean).join(" · "),
|
|
46
54
|
path: vaccinePath,
|
|
@@ -39,6 +39,10 @@ function countParts(values: unknown[], lang: Lang): WidgetData {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** Un widget d'essais ou de publications ne se propose qu'a un projet qui en range. */
|
|
43
|
+
const hasTrials = (context: WidgetContext) => context.docs.some((doc) => doc.type === "ClinicalTrialsNCT" || doc.type === "ClinicalTrialsEUCT");
|
|
44
|
+
const hasPublications = (context: WidgetContext) => context.docs.some((doc) => doc.type === "PubMed");
|
|
45
|
+
|
|
42
46
|
/** Les essais et les publications du projet. */
|
|
43
47
|
export const OIP_SCIENCE_DASHBOARD_WIDGETS: RmWidgetKind<WidgetContext>[] = [
|
|
44
48
|
{
|
|
@@ -52,6 +56,7 @@ export const OIP_SCIENCE_DASHBOARD_WIDGETS: RmWidgetKind<WidgetContext>[] = [
|
|
|
52
56
|
viz: ["donut", "bar", "table"],
|
|
53
57
|
sources: [],
|
|
54
58
|
usesBrands: false,
|
|
59
|
+
available: hasTrials,
|
|
55
60
|
params: [],
|
|
56
61
|
size: { w: 4, h: 5 },
|
|
57
62
|
async fetch(_params, { docs, lang }) {
|
|
@@ -69,6 +74,7 @@ export const OIP_SCIENCE_DASHBOARD_WIDGETS: RmWidgetKind<WidgetContext>[] = [
|
|
|
69
74
|
viz: ["donut", "bar", "table"],
|
|
70
75
|
sources: [],
|
|
71
76
|
usesBrands: false,
|
|
77
|
+
available: hasTrials,
|
|
72
78
|
params: [],
|
|
73
79
|
size: { w: 4, h: 5 },
|
|
74
80
|
async fetch(_params, { docs, lang }) {
|
|
@@ -86,6 +92,7 @@ export const OIP_SCIENCE_DASHBOARD_WIDGETS: RmWidgetKind<WidgetContext>[] = [
|
|
|
86
92
|
viz: ["bar", "line", "table"],
|
|
87
93
|
sources: [],
|
|
88
94
|
usesBrands: false,
|
|
95
|
+
available: hasPublications,
|
|
89
96
|
params: [],
|
|
90
97
|
size: { w: 6, h: 5 },
|
|
91
98
|
async fetch(_params, { docs, lang }) {
|