@tekkare/romulus 0.1.267 → 0.1.269
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
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Le catalogue complet des widgets de projet du layer : le contenu du projet,
|
|
3
|
+
* les essais et publications (France Augmented Science), les ventes et le
|
|
4
|
+
* reglementaire medicament (fr_drugs_app).
|
|
5
|
+
*
|
|
6
|
+
* Le tableau de bord d'un projet est commun a toutes les apps : un widget
|
|
7
|
+
* pose dans une app dont le `kind` manque au catalogue d'une autre y est garde
|
|
8
|
+
* mais pas affiche. Une app qui montre des projets de plusieurs apps (oip7)
|
|
9
|
+
* prend ce catalogue dans son `#oip-app/projects` :
|
|
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.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
19
|
+
import { PROJECT_RESOURCES_WIDGET, type OipProjectWidgetContext } from "./projects";
|
|
20
|
+
import { OIP_SCIENCE_DASHBOARD_WIDGETS } from "../oip-science/dashboardWidgets";
|
|
21
|
+
import { OIP_DRUG_DASHBOARD_WIDGETS } from "../oip-drugs/dashboardWidgets";
|
|
22
|
+
|
|
23
|
+
export { OIP_SCIENCE_DASHBOARD_WIDGETS, OIP_DRUG_DASHBOARD_WIDGETS };
|
|
24
|
+
export { oipProjectBrands } from "../oip-drugs/dashboardWidgets";
|
|
25
|
+
|
|
26
|
+
export const OIP_DASHBOARD_WIDGETS: RmWidgetKind<OipProjectWidgetContext>[] = [
|
|
27
|
+
PROJECT_RESOURCES_WIDGET,
|
|
28
|
+
...OIP_SCIENCE_DASHBOARD_WIDGETS,
|
|
29
|
+
...OIP_DRUG_DASHBOARD_WIDGETS,
|
|
30
|
+
];
|
|
@@ -0,0 +1,1017 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les widgets medicament du tableau de bord d'un projet (portage du catalogue
|
|
3
|
+
* de fr_drugs_app, dont France Augmented Science avait une copie partielle) :
|
|
4
|
+
* ventes en ville et a l'hopital, avis HAS, jalons reglementaires,
|
|
5
|
+
* presentations ANSM, acces precoces, prix.
|
|
6
|
+
*
|
|
7
|
+
* Un widget n'est pas une requete libre : c'est une entree d'ici (`kind`),
|
|
8
|
+
* reglee par quelques parametres (marques, mesure, secteur) et affichee sous
|
|
9
|
+
* une des visualisations qu'elle permet. Le `kind` est celui qu'enregistre le
|
|
10
|
+
* tableau de bord du projet, commun a toutes les apps : il ne se renomme pas.
|
|
11
|
+
*
|
|
12
|
+
* Les marques sont celles du projet, lues dans les documents ranges (cf.
|
|
13
|
+
* oipProjectBrands) : le layer ne passe pas de marques aux widgets.
|
|
14
|
+
*
|
|
15
|
+
* Regles suivies (vault, drug-reimbursement et export-and-views) :
|
|
16
|
+
* - une comparaison a un an s'ancre sur le dernier mois de la SOURCE, jamais
|
|
17
|
+
* sur l'horloge, et compare le meme mois de l'annee d'avant ;
|
|
18
|
+
* - toute requete a `size` fixe compare `hits.total` a ce qu'elle a rendu et
|
|
19
|
+
* le dit si elle tronque.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { ES_INDEX } from "./esIndices";
|
|
23
|
+
import { SOURCE_UUIDS } from "./composables/useDirectusSources";
|
|
24
|
+
import { HEART_SOURCE_UUIDS } from "./utils/sourceUuids";
|
|
25
|
+
import { OIP_RESOURCE_SPECS } from "../utils/oipResources";
|
|
26
|
+
import type { OipProjectWidgetContext } from "../oip-defaults/projects";
|
|
27
|
+
import {
|
|
28
|
+
rmJoinNotes,
|
|
29
|
+
rmLastYears,
|
|
30
|
+
rmMissingNote,
|
|
31
|
+
rmSeriesByBrand,
|
|
32
|
+
rmSince,
|
|
33
|
+
rmTruncationNote,
|
|
34
|
+
rmWithin,
|
|
35
|
+
rmYearsParam,
|
|
36
|
+
type RmDashboardLang,
|
|
37
|
+
type RmWidgetData,
|
|
38
|
+
type RmWidgetKind,
|
|
39
|
+
type RmWidgetParam,
|
|
40
|
+
} from "@tekkare/romulus/utils/dashboard";
|
|
41
|
+
|
|
42
|
+
type Lang = RmDashboardLang;
|
|
43
|
+
type WidgetParam = RmWidgetParam;
|
|
44
|
+
type WidgetData = RmWidgetData;
|
|
45
|
+
|
|
46
|
+
type WidgetContext = OipProjectWidgetContext;
|
|
47
|
+
type WidgetKind = RmWidgetKind<WidgetContext>;
|
|
48
|
+
|
|
49
|
+
// --- Elasticsearch -----------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
async function search(index: string, body: Record<string, unknown>): Promise<any> {
|
|
52
|
+
// Le proxy du layer (cluster `drugs`), joignable depuis toutes les apps.
|
|
53
|
+
return $fetch(`/api/oip/es?cluster=drugs&index=${encodeURIComponent(index)}`, { method: "POST", body });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function hitsOf(response: any): any[] {
|
|
57
|
+
return (response?.hits?.hits ?? []).map((hit: any) => hit._source);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Le message de troncature d'une reponse ES, ou rien : jamais un graphe partiel sans le dire. */
|
|
61
|
+
function truncation(response: any, lang: Lang): string | undefined {
|
|
62
|
+
return rmTruncationNote(response?.hits?.hits?.length ?? 0, response?.hits?.total?.value ?? 0, lang);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const EURO = (measure: string) => (/price|value|amount|bse|rem/.test(measure) ? "€" : undefined);
|
|
66
|
+
|
|
67
|
+
// --- Parametres partages ------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
const MEDICAM_MEASURE: WidgetParam = {
|
|
70
|
+
key: "measure",
|
|
71
|
+
label: { fr: "Mesure", en: "Measure" },
|
|
72
|
+
options: [
|
|
73
|
+
{ value: "unit_reimbursed", label: { fr: "Boîtes remboursées", en: "Reimbursed packs" } },
|
|
74
|
+
{ value: "value_public_price", label: { fr: "Valeur en prix public (€)", en: "Value at public price (€)" } },
|
|
75
|
+
{ value: "factory_value", label: { fr: "Prix fabricant HT (€)", en: "Ex-factory value (€)" } },
|
|
76
|
+
{ value: "amount_reimbursed", label: { fr: "Montant remboursé (€)", en: "Amount reimbursed (€)" } },
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const MEDICAM_SECTOR: WidgetParam = {
|
|
81
|
+
key: "sector",
|
|
82
|
+
label: { fr: "Secteur", en: "Sector" },
|
|
83
|
+
options: [
|
|
84
|
+
{ value: "total", label: { fr: "Total", en: "Total" } },
|
|
85
|
+
{ value: "office", label: { fr: "Ville", en: "Office based" } },
|
|
86
|
+
{ value: "hospital", label: { fr: "Hôpital (public et ESPIC)", en: "Hospital (public and ESPIC)" } },
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const PHMEV_MEASURE: WidgetParam = {
|
|
91
|
+
key: "measure",
|
|
92
|
+
label: { fr: "Mesure", en: "Measure" },
|
|
93
|
+
options: [
|
|
94
|
+
{ value: "unit_reimbursed", label: { fr: "Boîtes remboursées", en: "Reimbursed packs" } },
|
|
95
|
+
{ value: "value_public_price", label: { fr: "Valeur en prix public (€)", en: "Value at public price (€)" } },
|
|
96
|
+
{ value: "amount_reimbursed", label: { fr: "Montant remboursé (€)", en: "Amount reimbursed (€)" } },
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const SUS_MEASURE: WidgetParam = {
|
|
101
|
+
key: "measure",
|
|
102
|
+
label: { fr: "Mesure", en: "Measure" },
|
|
103
|
+
options: [
|
|
104
|
+
{ value: "bse", label: { fr: "Base de remboursement (€)", en: "Reimbursement base (€)" } },
|
|
105
|
+
{ value: "unit", label: { fr: "Unités", en: "Units" } },
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const RETRO_MEASURE: WidgetParam = {
|
|
110
|
+
key: "measure",
|
|
111
|
+
label: { fr: "Mesure", en: "Measure" },
|
|
112
|
+
options: [
|
|
113
|
+
{ value: "bse", label: { fr: "Base de remboursement (€)", en: "Reimbursement base (€)" } },
|
|
114
|
+
{ value: "rem", label: { fr: "Montant remboursé (€)", en: "Amount reimbursed (€)" } },
|
|
115
|
+
{ value: "unit", label: { fr: "Unités", en: "Units" } },
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Huit ans de mois au plus par marque dans l'index mensuel Medic'AM. */
|
|
120
|
+
const MEDICAM_MONTHS = 100;
|
|
121
|
+
|
|
122
|
+
async function medicamMonthly(brands: string[], sector: string, measure: string, lang: Lang) {
|
|
123
|
+
const field = `${sector}_${measure}`;
|
|
124
|
+
const response = await search(ES_INDEX.RETAIL_MONTHLY_BRAND, {
|
|
125
|
+
size: Math.min(10_000, brands.length * MEDICAM_MONTHS),
|
|
126
|
+
track_total_hits: true,
|
|
127
|
+
_source: ["code", "period", field],
|
|
128
|
+
query: {
|
|
129
|
+
bool: {
|
|
130
|
+
filter: [{ terms: { "code.keyword": brands } }, { term: { period_interval: 1 } }],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const rows = hitsOf(response).map((doc) => ({
|
|
135
|
+
brand: String(doc.code),
|
|
136
|
+
period: String(doc.period),
|
|
137
|
+
value: typeof doc[field] === "number" ? doc[field] : null,
|
|
138
|
+
}));
|
|
139
|
+
return { rows, note: truncation(response, lang) };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* `period_index` est commun a tout l'index : 1 est le dernier mois de la
|
|
144
|
+
* SOURCE (pas de la marque), 13 le meme mois un an plus tot. C'est l'ancre de
|
|
145
|
+
* R-01, sans requete de plus pour la trouver.
|
|
146
|
+
*/
|
|
147
|
+
const LAST_MONTH = 1;
|
|
148
|
+
const SAME_MONTH_LAST_YEAR = 13;
|
|
149
|
+
|
|
150
|
+
function monthLabel(period: string, lang: Lang) {
|
|
151
|
+
const [year, month] = period.split("-").map(Number);
|
|
152
|
+
return new Date(year!, month! - 1, 1).toLocaleDateString(lang === "fr" ? "fr-FR" : "en-US", {
|
|
153
|
+
month: "long",
|
|
154
|
+
year: "numeric",
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function annualBrands(
|
|
159
|
+
index: string,
|
|
160
|
+
extraFilter: Record<string, unknown>[],
|
|
161
|
+
brands: string[],
|
|
162
|
+
measure: string,
|
|
163
|
+
lang: Lang,
|
|
164
|
+
years?: string,
|
|
165
|
+
) {
|
|
166
|
+
const response = await search(index, {
|
|
167
|
+
// Une ligne par marque et par an : une vingtaine d'annees au plus.
|
|
168
|
+
size: Math.min(10_000, brands.length * 20),
|
|
169
|
+
track_total_hits: true,
|
|
170
|
+
_source: ["code", "period", measure],
|
|
171
|
+
query: { bool: { filter: [{ terms: { "code.keyword": brands } }, ...extraFilter] } },
|
|
172
|
+
});
|
|
173
|
+
const rows = hitsOf(response).map((doc) => ({
|
|
174
|
+
brand: String(doc.code),
|
|
175
|
+
period: String(doc.period),
|
|
176
|
+
value: typeof doc[measure] === "number" ? doc[measure] : null,
|
|
177
|
+
}));
|
|
178
|
+
const data = rmLastYears(rmSeriesByBrand(rows, brands), years, false);
|
|
179
|
+
return {
|
|
180
|
+
...data,
|
|
181
|
+
unit: EURO(measure),
|
|
182
|
+
note: rmJoinNotes(truncation(response, lang), rmMissingNote(brands, new Set(rows.map((r) => r.brand)), lang)),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// --- Reglementaire -------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
const OPINION_TYPES: Record<string, Record<Lang, string>> = {
|
|
189
|
+
drug_opinion: { fr: "Avis de la CT", en: "Transparency Committee opinion" },
|
|
190
|
+
early_access_decision: { fr: "Accès précoce", en: "Early access" },
|
|
191
|
+
eval: { fr: "Évaluation économique", en: "Economic evaluation" },
|
|
192
|
+
alert: { fr: "Alerte de sécurité", en: "Safety alert" },
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const TEXT = (fr: string, en: string) => ({ fr, en });
|
|
196
|
+
|
|
197
|
+
function col(
|
|
198
|
+
key: string,
|
|
199
|
+
label: Record<Lang, string>,
|
|
200
|
+
lang: Lang,
|
|
201
|
+
kind?: "numeric" | "date" | "long",
|
|
202
|
+
optional?: "optional",
|
|
203
|
+
) {
|
|
204
|
+
return {
|
|
205
|
+
key,
|
|
206
|
+
label: label[lang],
|
|
207
|
+
...(kind === "numeric" ? { numeric: true } : {}),
|
|
208
|
+
...(kind === "date" ? { date: true } : {}),
|
|
209
|
+
...(kind === "long" ? { long: true } : {}),
|
|
210
|
+
...(optional ? { optional: true } : {}),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Une date ISO tronquee au jour, ou rien : les index melangent `2026-07-08` et
|
|
216
|
+
* des horodatages. Une date a zero (`1970-01-01`, vue sur des AMM EMA) est une
|
|
217
|
+
* date manquante, pas un jalon de 1970.
|
|
218
|
+
*/
|
|
219
|
+
function day(value: unknown): string | null {
|
|
220
|
+
if (typeof value !== "string" || !value) return null;
|
|
221
|
+
const date = value.slice(0, 10);
|
|
222
|
+
return date.startsWith("1970-01-01") ? null : date;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const byDateDesc = (key: string) => (a: Record<string, any>, b: Record<string, any>) =>
|
|
226
|
+
String(b[key] ?? "").localeCompare(String(a[key] ?? ""));
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Les avis HAS des marques : un document par `brand_group`, ses avis dans
|
|
230
|
+
* `brand_history`. Une marque vendue en association (« A + B ») n'a pas de
|
|
231
|
+
* document a son seul nom : elle n'est pas retrouvee ici.
|
|
232
|
+
*/
|
|
233
|
+
async function hasOpinions(brands: string[]) {
|
|
234
|
+
const response = await search(ES_INDEX.BRAND_HAS, {
|
|
235
|
+
size: brands.length,
|
|
236
|
+
_source: ["brand_group", "brand_history"],
|
|
237
|
+
query: { terms: { "brand_group.keyword": brands } },
|
|
238
|
+
});
|
|
239
|
+
const docs = hitsOf(response);
|
|
240
|
+
const opinions = docs.flatMap((doc) =>
|
|
241
|
+
(Array.isArray(doc.brand_history) ? doc.brand_history : []).map((h: any) => ({ ...h, group: String(doc.brand_group) })),
|
|
242
|
+
);
|
|
243
|
+
return { docs, opinions, found: new Set(docs.map((doc) => String(doc.brand_group))) };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function levels(list: unknown, lang: Lang): string {
|
|
247
|
+
if (!Array.isArray(list)) return "";
|
|
248
|
+
return [...new Set(list.map((x: any) => (lang === "en" ? x?.type_en : x?.type) ?? x?.type).filter(Boolean))].join(", ");
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function opinionKind(h: any, lang: Lang): string {
|
|
252
|
+
const key = h.document_type === "alert" ? "alert" : h.opinion_type;
|
|
253
|
+
return OPINION_TYPES[key]?.[lang] ?? String(key ?? "");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const opinionDate = (h: any) => day(h.decision_date) ?? day(h.security_start_date);
|
|
257
|
+
|
|
258
|
+
/** Les autorisations EMA et FDA des marques, filtrees sur le nom exact (l'index melange les casses). */
|
|
259
|
+
async function approvals(brands: string[]) {
|
|
260
|
+
const response = await search(ES_INDEX.DRUG_APPROVALS, {
|
|
261
|
+
size: Math.min(500, brands.length * 10),
|
|
262
|
+
_source: ["brands", "source_name", "first_approval_date", "latest_update_date", "orphan", "local_id"],
|
|
263
|
+
query: {
|
|
264
|
+
bool: {
|
|
265
|
+
filter: [{ terms: { "source_name.keyword": ["EMA", "FDA"] } }],
|
|
266
|
+
must: [
|
|
267
|
+
{
|
|
268
|
+
nested: {
|
|
269
|
+
path: "brands",
|
|
270
|
+
query: { bool: { should: brands.map((brand) => ({ match_phrase: { "brands.brand": brand } })), minimum_should_match: 1 } },
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
const wanted = new Set(brands);
|
|
278
|
+
return hitsOf(response).flatMap((doc) => {
|
|
279
|
+
const names = (doc.brands ?? []).map((b: any) => String(b?.brand ?? "").toUpperCase());
|
|
280
|
+
const brand = names.find((name: string) => wanted.has(name));
|
|
281
|
+
return brand ? [{ ...doc, brand }] : [];
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const REGULATORY = { fr: "Réglementaire (Hub-R)", en: "Regulatory (Hub-R)" };
|
|
286
|
+
|
|
287
|
+
// --- Catalogue ----------------------------------------------------------------
|
|
288
|
+
|
|
289
|
+
const SALES = { fr: "Ventes en ville (Medic'AM)", en: "Retail sales (Medic'AM)" };
|
|
290
|
+
const HOSPITAL = { fr: "Hôpital", en: "Hospital" };
|
|
291
|
+
|
|
292
|
+
const DRUG_WIDGETS: WidgetKind[] = [
|
|
293
|
+
{
|
|
294
|
+
kind: "medicam.evolution",
|
|
295
|
+
sources: [SOURCE_UUIDS.medicam],
|
|
296
|
+
group: SALES,
|
|
297
|
+
title: { fr: "Évolution mensuelle Medic'AM", en: "Medic'AM monthly evolution" },
|
|
298
|
+
description: {
|
|
299
|
+
fr: "Une courbe par marque, tout l'historique mensuel de la source.",
|
|
300
|
+
en: "One line per brand, the source's whole monthly history.",
|
|
301
|
+
},
|
|
302
|
+
viz: ["line", "bar", "table"],
|
|
303
|
+
usesBrands: true,
|
|
304
|
+
params: [MEDICAM_MEASURE, MEDICAM_SECTOR, rmYearsParam(["1", "2", "3", "5"])],
|
|
305
|
+
size: { w: 8, h: 5 },
|
|
306
|
+
async fetch(params, { brands, lang }) {
|
|
307
|
+
const { rows, note } = await medicamMonthly(brands, params.sector!, params.measure!, lang);
|
|
308
|
+
return {
|
|
309
|
+
...rmLastYears(rmSeriesByBrand(rows, brands), params.years, true),
|
|
310
|
+
unit: EURO(params.measure!),
|
|
311
|
+
note: rmJoinNotes(note, rmMissingNote(brands, new Set(rows.map((r) => r.brand)), lang)),
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
kind: "medicam.lastMonth",
|
|
317
|
+
sources: [SOURCE_UUIDS.medicam],
|
|
318
|
+
group: SALES,
|
|
319
|
+
title: { fr: "Dernier mois Medic'AM", en: "Medic'AM last month" },
|
|
320
|
+
description: {
|
|
321
|
+
fr: "Le dernier mois de la source comparé au même mois de l'année précédente, par marque.",
|
|
322
|
+
en: "The source's last month against the same month a year earlier, per brand.",
|
|
323
|
+
},
|
|
324
|
+
viz: ["kpi", "table"],
|
|
325
|
+
usesBrands: true,
|
|
326
|
+
params: [MEDICAM_MEASURE, MEDICAM_SECTOR],
|
|
327
|
+
size: { w: 4, h: 5 },
|
|
328
|
+
async fetch(params, { brands, lang }) {
|
|
329
|
+
const field = `${params.sector}_${params.measure}`;
|
|
330
|
+
const response = await search(ES_INDEX.RETAIL_MONTHLY_BRAND, {
|
|
331
|
+
size: brands.length * 2,
|
|
332
|
+
_source: ["code", "period", "period_index", field],
|
|
333
|
+
query: {
|
|
334
|
+
bool: {
|
|
335
|
+
filter: [
|
|
336
|
+
{ terms: { "code.keyword": brands } },
|
|
337
|
+
{ term: { period_interval: 1 } },
|
|
338
|
+
{ terms: { period_index: [LAST_MONTH, SAME_MONTH_LAST_YEAR] } },
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
const docs = hitsOf(response);
|
|
344
|
+
const at = (index: number) => docs.find((d) => d.period_index === index)?.period as string | undefined;
|
|
345
|
+
const last = at(LAST_MONTH);
|
|
346
|
+
const before = at(SAME_MONTH_LAST_YEAR);
|
|
347
|
+
const value = (brand: string, index: number) => {
|
|
348
|
+
const doc = docs.find((d) => d.code === brand && d.period_index === index);
|
|
349
|
+
return typeof doc?.[field] === "number" ? (doc[field] as number) : null;
|
|
350
|
+
};
|
|
351
|
+
const items = brands
|
|
352
|
+
.filter((brand) => value(brand, LAST_MONTH) !== null)
|
|
353
|
+
.map((brand) => {
|
|
354
|
+
const current = value(brand, LAST_MONTH)!;
|
|
355
|
+
const previous = value(brand, SAME_MONTH_LAST_YEAR);
|
|
356
|
+
return {
|
|
357
|
+
label: brand,
|
|
358
|
+
value: current,
|
|
359
|
+
previous,
|
|
360
|
+
trend: previous ? ((current - previous) / previous) * 100 : undefined,
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
return {
|
|
364
|
+
type: "kpi",
|
|
365
|
+
items,
|
|
366
|
+
period: last && before ? `${monthLabel(last, lang)} vs ${monthLabel(before, lang)}` : "",
|
|
367
|
+
unit: EURO(params.measure!),
|
|
368
|
+
note: rmMissingNote(brands, new Set(items.map((i) => i.label)), lang),
|
|
369
|
+
};
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
kind: "medicam.share",
|
|
374
|
+
sources: [SOURCE_UUIDS.medicam],
|
|
375
|
+
group: SALES,
|
|
376
|
+
title: { fr: "Répartition des ventes sur 12 mois", en: "Sales split over 12 months" },
|
|
377
|
+
description: {
|
|
378
|
+
fr: "La part de chaque marque du projet sur les douze derniers mois de la source.",
|
|
379
|
+
en: "Each project brand's share over the source's last twelve months.",
|
|
380
|
+
},
|
|
381
|
+
viz: ["donut", "bar", "table"],
|
|
382
|
+
usesBrands: true,
|
|
383
|
+
params: [MEDICAM_MEASURE, MEDICAM_SECTOR],
|
|
384
|
+
size: { w: 4, h: 5 },
|
|
385
|
+
async fetch(params, { brands, lang }) {
|
|
386
|
+
const field = `${params.sector}_${params.measure}`;
|
|
387
|
+
const response = await search(ES_INDEX.RETAIL_MONTHLY_BRAND, {
|
|
388
|
+
size: 0,
|
|
389
|
+
query: {
|
|
390
|
+
bool: {
|
|
391
|
+
filter: [
|
|
392
|
+
{ terms: { "code.keyword": brands } },
|
|
393
|
+
{ term: { period_interval: 1 } },
|
|
394
|
+
{ range: { period_index: { gte: LAST_MONTH, lt: SAME_MONTH_LAST_YEAR } } },
|
|
395
|
+
],
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
aggs: {
|
|
399
|
+
brands: {
|
|
400
|
+
terms: { field: "code.keyword", size: brands.length },
|
|
401
|
+
aggs: { total: { sum: { field } } },
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
const parts = (response?.aggregations?.brands?.buckets ?? [])
|
|
406
|
+
.map((bucket: any) => ({ name: String(bucket.key), value: Math.round(bucket.total.value ?? 0) }))
|
|
407
|
+
.filter((part: { value: number }) => part.value > 0)
|
|
408
|
+
.sort((a: { value: number }, b: { value: number }) => b.value - a.value);
|
|
409
|
+
return {
|
|
410
|
+
type: "parts",
|
|
411
|
+
parts,
|
|
412
|
+
unit: EURO(params.measure!),
|
|
413
|
+
note: rmMissingNote(brands, new Set(parts.map((p: { name: string }) => p.name)), lang),
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
kind: "phmev.annual",
|
|
419
|
+
sources: [SOURCE_UUIDS.phmev],
|
|
420
|
+
group: SALES,
|
|
421
|
+
title: { fr: "Prescriptions hospitalières en ville (PHMEV)", en: "Hospital prescriptions dispensed in retail (PHMEV)" },
|
|
422
|
+
description: {
|
|
423
|
+
fr: "Six années de délivrances en ville prescrites à l'hôpital, par marque.",
|
|
424
|
+
en: "Six years of retail dispensing prescribed in hospitals, per brand.",
|
|
425
|
+
},
|
|
426
|
+
viz: ["bar", "line", "table"],
|
|
427
|
+
usesBrands: true,
|
|
428
|
+
params: [PHMEV_MEASURE, rmYearsParam(["3", "5"])],
|
|
429
|
+
size: { w: 6, h: 5 },
|
|
430
|
+
async fetch(params, { brands, lang }) {
|
|
431
|
+
const measure = params.measure!;
|
|
432
|
+
// L'ancre stable de la marque : `{MARQUE}_TOTAL`, une ligne pour six ans.
|
|
433
|
+
const response = await search(ES_INDEX.OUTPATIENT_BRAND, {
|
|
434
|
+
size: brands.length,
|
|
435
|
+
query: { ids: { values: brands.map((brand) => `${brand}_TOTAL`) } },
|
|
436
|
+
});
|
|
437
|
+
const rows = hitsOf(response).flatMap((doc) => {
|
|
438
|
+
const max = Number(doc.max_period);
|
|
439
|
+
return [0, 1, 2, 3, 4, 5].map((back) => ({
|
|
440
|
+
brand: String(doc.code),
|
|
441
|
+
period: String(max - back),
|
|
442
|
+
value: typeof doc[`${measure}_p${back}`] === "number" ? doc[`${measure}_p${back}`] : null,
|
|
443
|
+
}));
|
|
444
|
+
});
|
|
445
|
+
return {
|
|
446
|
+
...rmLastYears(rmSeriesByBrand(rows, brands), params.years, false),
|
|
447
|
+
unit: EURO(measure),
|
|
448
|
+
note: rmMissingNote(brands, new Set(rows.map((r) => r.brand)), lang),
|
|
449
|
+
};
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
kind: "sus.annual",
|
|
454
|
+
sources: [SOURCE_UUIDS.sus],
|
|
455
|
+
group: HOSPITAL,
|
|
456
|
+
title: { fr: "Liste en sus, dépense annuelle", en: "Add-on list, annual spending" },
|
|
457
|
+
description: {
|
|
458
|
+
fr: "Toutes activités et tous secteurs confondus, par marque et par année.",
|
|
459
|
+
en: "All activities and sectors together, per brand and year.",
|
|
460
|
+
},
|
|
461
|
+
viz: ["bar", "line", "table"],
|
|
462
|
+
usesBrands: true,
|
|
463
|
+
params: [SUS_MEASURE, rmYearsParam(["3", "5"])],
|
|
464
|
+
size: { w: 6, h: 5 },
|
|
465
|
+
fetch: (params, { brands, lang }) =>
|
|
466
|
+
annualBrands(
|
|
467
|
+
ES_INDEX.HOSPITAL_ANNUAL_SUS,
|
|
468
|
+
[
|
|
469
|
+
{ term: { "sector.keyword": "TOTAL" } },
|
|
470
|
+
{ term: { "activity.keyword": "TOTAL" } },
|
|
471
|
+
{ term: { analysis_type: 1 } },
|
|
472
|
+
],
|
|
473
|
+
brands,
|
|
474
|
+
params.measure!,
|
|
475
|
+
lang,
|
|
476
|
+
params.years,
|
|
477
|
+
),
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
kind: "retrocession.annual",
|
|
481
|
+
sources: [SOURCE_UUIDS.retrocession],
|
|
482
|
+
group: HOSPITAL,
|
|
483
|
+
title: { fr: "Rétrocession, dépense annuelle", en: "Retrocession, annual spending" },
|
|
484
|
+
description: {
|
|
485
|
+
fr: "Médicaments rétrocédés par les pharmacies hospitalières, par marque et par année.",
|
|
486
|
+
en: "Drugs dispensed by hospital pharmacies to outpatients, per brand and year.",
|
|
487
|
+
},
|
|
488
|
+
viz: ["bar", "line", "table"],
|
|
489
|
+
usesBrands: true,
|
|
490
|
+
params: [RETRO_MEASURE, rmYearsParam(["3", "5"])],
|
|
491
|
+
size: { w: 6, h: 5 },
|
|
492
|
+
fetch: (params, { brands, lang }) =>
|
|
493
|
+
annualBrands(
|
|
494
|
+
ES_INDEX.HOSPITAL_ANNUAL_RETROCESSION,
|
|
495
|
+
[{ term: { "level.keyword": "brand" } }],
|
|
496
|
+
brands,
|
|
497
|
+
params.measure!,
|
|
498
|
+
lang,
|
|
499
|
+
params.years,
|
|
500
|
+
),
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
kind: "has.opinions",
|
|
504
|
+
sources: [HEART_SOURCE_UUIDS.HAS],
|
|
505
|
+
group: REGULATORY,
|
|
506
|
+
title: { fr: "Avis de la HAS", en: "HAS opinions" },
|
|
507
|
+
description: {
|
|
508
|
+
fr: "Tous les avis des marques, du plus récent au plus ancien : type, nature de la demande, SMR, ASMR.",
|
|
509
|
+
en: "Every opinion on the brands, newest first: type, request, SMR, ASMR.",
|
|
510
|
+
},
|
|
511
|
+
viz: ["table", "cards"],
|
|
512
|
+
usesBrands: true,
|
|
513
|
+
params: [rmYearsParam(["1", "3", "5", "10"])],
|
|
514
|
+
size: { w: 12, h: 6 },
|
|
515
|
+
async fetch(params, { brands, lang }) {
|
|
516
|
+
const { docs, opinions, found } = await hasOpinions(brands);
|
|
517
|
+
const rows = opinions
|
|
518
|
+
.map((h: any) => ({
|
|
519
|
+
date: opinionDate(h),
|
|
520
|
+
brand: String(h.brand ?? h.group),
|
|
521
|
+
type: opinionKind(h, lang),
|
|
522
|
+
nature: String((lang === "en" ? h.nature_of_request_regroup_en : h.nature_of_request_regroup) ?? h.nature_of_request_regroup ?? ""),
|
|
523
|
+
smr: levels(h.smr, lang),
|
|
524
|
+
asmr: levels(h.asmr, lang),
|
|
525
|
+
status: String(h.opinion_status ?? ""),
|
|
526
|
+
code: String(h.has_code ?? ""),
|
|
527
|
+
indication: String(h.indication ?? ""),
|
|
528
|
+
}))
|
|
529
|
+
.sort(byDateDesc("date"));
|
|
530
|
+
const kept = rmWithin(rows, "date", rmSince(params.years));
|
|
531
|
+
return {
|
|
532
|
+
type: "rows",
|
|
533
|
+
columns: [
|
|
534
|
+
col("date", TEXT("Date", "Date"), lang, "date"),
|
|
535
|
+
col("brand", TEXT("Marque", "Brand"), lang),
|
|
536
|
+
col("type", TEXT("Type", "Type"), lang),
|
|
537
|
+
col("nature", TEXT("Demande", "Request"), lang),
|
|
538
|
+
col("smr", TEXT("SMR", "SMR"), lang),
|
|
539
|
+
col("asmr", TEXT("ASMR", "ASMR"), lang),
|
|
540
|
+
col("status", TEXT("Statut", "Status"), lang),
|
|
541
|
+
col("code", TEXT("Code HAS", "HAS code"), lang, undefined, "optional"),
|
|
542
|
+
col("indication", TEXT("Indication", "Indication"), lang, "long", "optional"),
|
|
543
|
+
],
|
|
544
|
+
rows: kept,
|
|
545
|
+
// Une carte par marque, comme la recherche HAS, ses avis bornes a la periode.
|
|
546
|
+
cards: {
|
|
547
|
+
kind: "has",
|
|
548
|
+
items: docs.map((doc) => {
|
|
549
|
+
const from = rmSince(params.years);
|
|
550
|
+
const history = (doc.brand_history ?? []).filter((h: any) => !from || (opinionDate(h) ?? "") >= from);
|
|
551
|
+
return { _source: { ...doc, brand_history: history } };
|
|
552
|
+
}).filter((item) => item._source.brand_history.length),
|
|
553
|
+
},
|
|
554
|
+
note: rmMissingNote(brands, found, lang),
|
|
555
|
+
};
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
kind: "has.asmr",
|
|
560
|
+
sources: [HEART_SOURCE_UUIDS.HAS],
|
|
561
|
+
group: REGULATORY,
|
|
562
|
+
title: { fr: "Niveaux d'ASMR obtenus", en: "ASMR levels obtained" },
|
|
563
|
+
description: {
|
|
564
|
+
fr: "Les avis de la commission de la transparence des marques, comptés par niveau d'ASMR.",
|
|
565
|
+
en: "The brands' Transparency Committee opinions, counted by ASMR level.",
|
|
566
|
+
},
|
|
567
|
+
viz: ["donut", "bar", "table"],
|
|
568
|
+
usesBrands: true,
|
|
569
|
+
params: [rmYearsParam(["3", "5", "10"])],
|
|
570
|
+
size: { w: 4, h: 5 },
|
|
571
|
+
async fetch(params, { brands, lang }) {
|
|
572
|
+
const { opinions, found } = await hasOpinions(brands);
|
|
573
|
+
const counts = new Map<string, number>();
|
|
574
|
+
const from = rmSince(params.years);
|
|
575
|
+
for (const h of opinions) {
|
|
576
|
+
if (!Array.isArray(h.asmr) || !h.asmr.length) continue;
|
|
577
|
+
if (from && !((opinionDate(h) ?? "") >= from)) continue;
|
|
578
|
+
const level = (lang === "en" ? h.asmr[0]?.type_en : h.asmr[0]?.type) ?? h.asmr[0]?.type;
|
|
579
|
+
if (!level) continue;
|
|
580
|
+
const name = `ASMR ${level}`;
|
|
581
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
582
|
+
}
|
|
583
|
+
return {
|
|
584
|
+
type: "parts",
|
|
585
|
+
parts: [...counts].map(([name, value]) => ({ name, value })).sort((a, b) => a.name.localeCompare(b.name)),
|
|
586
|
+
note: rmMissingNote(brands, found, lang),
|
|
587
|
+
};
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
kind: "has.yearly",
|
|
592
|
+
sources: [HEART_SOURCE_UUIDS.HAS],
|
|
593
|
+
group: REGULATORY,
|
|
594
|
+
title: { fr: "Avis HAS par année", en: "HAS opinions per year" },
|
|
595
|
+
description: {
|
|
596
|
+
fr: "Le nombre d'avis publiés chaque année, par marque.",
|
|
597
|
+
en: "How many opinions were published each year, per brand.",
|
|
598
|
+
},
|
|
599
|
+
viz: ["bar", "line", "table"],
|
|
600
|
+
usesBrands: true,
|
|
601
|
+
params: [rmYearsParam(["5", "10"])],
|
|
602
|
+
size: { w: 6, h: 5 },
|
|
603
|
+
async fetch(params, { brands, lang }) {
|
|
604
|
+
const { opinions, found } = await hasOpinions(brands);
|
|
605
|
+
const counts = new Map<string, number>();
|
|
606
|
+
for (const h of opinions) {
|
|
607
|
+
const date = opinionDate(h);
|
|
608
|
+
if (!date) continue;
|
|
609
|
+
const key = `${h.group}|${date.slice(0, 4)}`;
|
|
610
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
611
|
+
}
|
|
612
|
+
const rows = [...counts].map(([key, value]) => {
|
|
613
|
+
const [brand, period] = key.split("|");
|
|
614
|
+
return { brand: brand!, period: period!, value };
|
|
615
|
+
});
|
|
616
|
+
return { ...rmLastYears(rmSeriesByBrand(rows, brands), params.years, false), note: rmMissingNote(brands, found, lang) };
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
kind: "regulatory.milestones",
|
|
621
|
+
sources: [HEART_SOURCE_UUIDS.EMA, HEART_SOURCE_UUIDS.FDA, HEART_SOURCE_UUIDS.ANSM, HEART_SOURCE_UUIDS.PUT, HEART_SOURCE_UUIDS.HAS],
|
|
622
|
+
group: REGULATORY,
|
|
623
|
+
title: { fr: "Jalons réglementaires", en: "Regulatory milestones" },
|
|
624
|
+
description: {
|
|
625
|
+
fr: "AMM européenne et américaine, AMM en France, accès précoce, avis de la HAS : une seule frise, du plus récent au plus ancien.",
|
|
626
|
+
en: "EU and US approvals, French approval, early access, HAS opinions: one timeline, newest first.",
|
|
627
|
+
},
|
|
628
|
+
viz: ["table"],
|
|
629
|
+
usesBrands: true,
|
|
630
|
+
params: [rmYearsParam(["1", "3", "5", "10"])],
|
|
631
|
+
size: { w: 12, h: 6 },
|
|
632
|
+
async fetch(params, { brands, lang }) {
|
|
633
|
+
const en = lang === "en";
|
|
634
|
+
const [approved, ansm, put, has] = await Promise.all([
|
|
635
|
+
approvals(brands),
|
|
636
|
+
search(ES_INDEX.CIS_ANSM, {
|
|
637
|
+
size: 0,
|
|
638
|
+
query: { terms: { "brand.keyword": brands } },
|
|
639
|
+
// `authorization_date` est un mot-cle : pas de `min`, mais une date
|
|
640
|
+
// ISO se trie dans l'ordre du texte. La plus ancienne par marque.
|
|
641
|
+
aggs: {
|
|
642
|
+
brands: {
|
|
643
|
+
terms: { field: "brand.keyword", size: brands.length },
|
|
644
|
+
aggs: {
|
|
645
|
+
first: {
|
|
646
|
+
top_hits: { size: 1, _source: ["authorization_date"], sort: [{ authorization_date: { order: "asc", missing: "_last" } }] },
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
},
|
|
651
|
+
}),
|
|
652
|
+
search(ES_INDEX.PUT_HAS, {
|
|
653
|
+
size: Math.min(500, brands.length * 30),
|
|
654
|
+
_source: ["brand", "authorization_date", "aap_type_fr", "aap_type_en", "status_fr", "status_en"],
|
|
655
|
+
query: { terms: { "brand.keyword": brands } },
|
|
656
|
+
}),
|
|
657
|
+
hasOpinions(brands),
|
|
658
|
+
]);
|
|
659
|
+
const rows: Record<string, string | number | null>[] = [];
|
|
660
|
+
for (const doc of approved) {
|
|
661
|
+
rows.push({
|
|
662
|
+
date: day(doc.first_approval_date),
|
|
663
|
+
brand: doc.brand,
|
|
664
|
+
step: en ? `${doc.source_name} approval` : `AMM ${doc.source_name}`,
|
|
665
|
+
detail: [doc.local_id, doc.orphan ? (en ? "orphan" : "orphelin") : ""].filter(Boolean).join(", "),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
for (const bucket of ansm?.aggregations?.brands?.buckets ?? []) {
|
|
669
|
+
rows.push({
|
|
670
|
+
date: day(bucket.first?.hits?.hits?.[0]?._source?.authorization_date),
|
|
671
|
+
brand: String(bucket.key),
|
|
672
|
+
step: en ? "French approval (ANSM)" : "AMM en France (ANSM)",
|
|
673
|
+
detail: en ? "first presentation" : "première présentation",
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
for (const doc of hitsOf(put)) {
|
|
677
|
+
const brand = (Array.isArray(doc.brand) ? doc.brand : [doc.brand]).map(String).find((b: string) => brands.includes(b));
|
|
678
|
+
rows.push({
|
|
679
|
+
date: day(doc.authorization_date),
|
|
680
|
+
brand: brand ?? String(doc.brand),
|
|
681
|
+
step: en ? `Early access, ${doc.aap_type_en ?? ""}` : `Accès précoce, ${doc.aap_type_fr ?? ""}`,
|
|
682
|
+
detail: String((en ? doc.status_en : doc.status_fr) ?? ""),
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
for (const h of has.opinions) {
|
|
686
|
+
if (h.document_type === "alert") continue;
|
|
687
|
+
rows.push({
|
|
688
|
+
date: opinionDate(h),
|
|
689
|
+
brand: String(h.brand ?? h.group),
|
|
690
|
+
step: en ? `HAS, ${opinionKind(h, lang)}` : `HAS, ${opinionKind(h, lang)}`,
|
|
691
|
+
detail: [
|
|
692
|
+
(en ? h.nature_of_request_regroup_en : h.nature_of_request_regroup) ?? "",
|
|
693
|
+
levels(h.asmr, lang) ? `ASMR ${levels(h.asmr, lang)}` : "",
|
|
694
|
+
]
|
|
695
|
+
.filter(Boolean)
|
|
696
|
+
.join(", "),
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
type: "rows",
|
|
701
|
+
columns: [
|
|
702
|
+
col("date", TEXT("Date", "Date"), lang, "date"),
|
|
703
|
+
col("brand", TEXT("Marque", "Brand"), lang),
|
|
704
|
+
col("step", TEXT("Étape", "Milestone"), lang),
|
|
705
|
+
col("detail", TEXT("Détail", "Detail"), lang, "long"),
|
|
706
|
+
],
|
|
707
|
+
// Sans date, le jalon reste, en fin de frise : il existe, sa date manque.
|
|
708
|
+
rows: rmWithin(rows.sort(byDateDesc("date")), "date", rmSince(params.years)),
|
|
709
|
+
note: truncation(put, lang),
|
|
710
|
+
};
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
kind: "ansm.presentations",
|
|
715
|
+
sources: [HEART_SOURCE_UUIDS.ANSM],
|
|
716
|
+
group: REGULATORY,
|
|
717
|
+
title: { fr: "Présentations autorisées (ANSM)", en: "Authorised presentations (ANSM)" },
|
|
718
|
+
description: {
|
|
719
|
+
fr: "Chaque spécialité des marques : titulaire, date d'AMM, statut et commercialisation.",
|
|
720
|
+
en: "Each product of the brands: holder, approval date, status and marketing.",
|
|
721
|
+
},
|
|
722
|
+
viz: ["table", "cards"],
|
|
723
|
+
usesBrands: true,
|
|
724
|
+
params: [],
|
|
725
|
+
size: { w: 12, h: 5 },
|
|
726
|
+
async fetch(_params, { brands, lang }) {
|
|
727
|
+
const response = await search(ES_INDEX.CIS_ANSM, {
|
|
728
|
+
size: Math.min(1000, brands.length * 50),
|
|
729
|
+
track_total_hits: true,
|
|
730
|
+
_source: ["brand", "cis_code", "cis_label", "owner_regroup", "authorization_date", "amm_status", "commercialization_status", "atc5_french_code_label", "atc5_english_code_label"],
|
|
731
|
+
query: { terms: { "brand.keyword": brands } },
|
|
732
|
+
sort: [{ authorization_date: { order: "desc", missing: "_last" } }],
|
|
733
|
+
});
|
|
734
|
+
const docs = hitsOf(response);
|
|
735
|
+
// Comme la page ANSM : une carte par marque, ses CIS dessous.
|
|
736
|
+
const byBrand = new Map<string, any[]>();
|
|
737
|
+
for (const hit of response?.hits?.hits ?? []) {
|
|
738
|
+
const brand = String(hit._source?.brand ?? "");
|
|
739
|
+
byBrand.set(brand, [...(byBrand.get(brand) ?? []), hit]);
|
|
740
|
+
}
|
|
741
|
+
return {
|
|
742
|
+
type: "rows",
|
|
743
|
+
cards: { kind: "ansm", items: [...byBrand.values()].map((hits) => ({ brand: hits[0]._source, cisHits: hits })) },
|
|
744
|
+
columns: [
|
|
745
|
+
col("brand", TEXT("Marque", "Brand"), lang),
|
|
746
|
+
col("label", TEXT("Spécialité", "Product"), lang),
|
|
747
|
+
col("owner", TEXT("Titulaire", "Holder"), lang),
|
|
748
|
+
col("date", TEXT("AMM", "Approval"), lang, "date"),
|
|
749
|
+
col("status", TEXT("Statut de l'AMM", "Approval status"), lang),
|
|
750
|
+
col("marketed", TEXT("Commercialisation", "Marketing"), lang),
|
|
751
|
+
col("cis", TEXT("Code CIS", "CIS code"), lang, undefined, "optional"),
|
|
752
|
+
col("atc5", TEXT("Molécule (ATC5)", "Molecule (ATC5)"), lang, undefined, "optional"),
|
|
753
|
+
],
|
|
754
|
+
rows: docs.map((doc) => ({
|
|
755
|
+
cis: String(doc.cis_code ?? ""),
|
|
756
|
+
atc5: String((lang === "en" ? doc.atc5_english_code_label : doc.atc5_french_code_label) ?? ""),
|
|
757
|
+
brand: String(doc.brand ?? ""),
|
|
758
|
+
label: String(doc.cis_label ?? ""),
|
|
759
|
+
owner: String(doc.owner_regroup ?? ""),
|
|
760
|
+
date: day(doc.authorization_date),
|
|
761
|
+
status: String(doc.amm_status ?? ""),
|
|
762
|
+
marketed: String(doc.commercialization_status ?? ""),
|
|
763
|
+
})),
|
|
764
|
+
note: rmJoinNotes(truncation(response, lang), rmMissingNote(brands, new Set(docs.map((d) => String(d.brand))), lang)),
|
|
765
|
+
};
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
kind: "put.programs",
|
|
770
|
+
sources: [HEART_SOURCE_UUIDS.PUT],
|
|
771
|
+
group: REGULATORY,
|
|
772
|
+
title: { fr: "Accès précoce et compassionnel", en: "Early and compassionate access" },
|
|
773
|
+
description: {
|
|
774
|
+
fr: "Les protocoles d'utilisation des marques : type, statut, aire thérapeutique.",
|
|
775
|
+
en: "The brands' use protocols: type, status, therapeutic area.",
|
|
776
|
+
},
|
|
777
|
+
viz: ["table", "cards"],
|
|
778
|
+
usesBrands: true,
|
|
779
|
+
params: [rmYearsParam(["1", "3", "5"])],
|
|
780
|
+
size: { w: 12, h: 5 },
|
|
781
|
+
async fetch(params, { brands, lang }) {
|
|
782
|
+
const en = lang === "en";
|
|
783
|
+
const response = await search(ES_INDEX.PUT_HAS, {
|
|
784
|
+
size: Math.min(500, brands.length * 30),
|
|
785
|
+
track_total_hits: true,
|
|
786
|
+
query: { terms: { "brand.keyword": brands } },
|
|
787
|
+
sort: [{ authorization_date: { order: "desc", missing: "_last" } }],
|
|
788
|
+
});
|
|
789
|
+
const docs = hitsOf(response);
|
|
790
|
+
return {
|
|
791
|
+
type: "rows",
|
|
792
|
+
columns: [
|
|
793
|
+
col("date", TEXT("Autorisation", "Authorised"), lang, "date"),
|
|
794
|
+
col("brand", TEXT("Marque", "Brand"), lang),
|
|
795
|
+
col("type", TEXT("Type", "Type"), lang),
|
|
796
|
+
col("status", TEXT("Statut", "Status"), lang),
|
|
797
|
+
col("area", TEXT("Aire thérapeutique", "Therapeutic area"), lang),
|
|
798
|
+
col("dci", TEXT("DCI", "INN"), lang, undefined, "optional"),
|
|
799
|
+
col("indication", TEXT("Indication", "Indication"), lang, "long", "optional"),
|
|
800
|
+
],
|
|
801
|
+
rows: rmWithin(docs.map((doc) => ({
|
|
802
|
+
dci: String(doc.dci ?? ""),
|
|
803
|
+
indication: String((en ? doc.indication_en : doc.indication_fr) ?? ""),
|
|
804
|
+
date: day(doc.authorization_date),
|
|
805
|
+
brand: (Array.isArray(doc.brand) ? doc.brand : [doc.brand]).join(", "),
|
|
806
|
+
type: String((en ? doc.aap_type_en : doc.aap_type_fr) ?? ""),
|
|
807
|
+
status: String((en ? doc.status_en : doc.status_fr) ?? ""),
|
|
808
|
+
area: String((en ? doc.therapeutic_area_en : doc.therapeutic_area_fr) ?? ""),
|
|
809
|
+
})), "date", rmSince(params.years)),
|
|
810
|
+
cards: {
|
|
811
|
+
kind: "put",
|
|
812
|
+
items: (response?.hits?.hits ?? []).filter((hit: any) => {
|
|
813
|
+
const from = rmSince(params.years);
|
|
814
|
+
return !from || (day(hit._source?.authorization_date) ?? "") >= from;
|
|
815
|
+
}),
|
|
816
|
+
},
|
|
817
|
+
note: truncation(response, lang),
|
|
818
|
+
};
|
|
819
|
+
},
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
kind: "prices.presentations",
|
|
823
|
+
sources: [HEART_SOURCE_UUIDS.PRICE_TRACKER],
|
|
824
|
+
group: REGULATORY,
|
|
825
|
+
title: { fr: "Prix des présentations", en: "Presentation prices" },
|
|
826
|
+
description: {
|
|
827
|
+
fr: "Le dernier prix public et fabricant, une ligne par présentation (CIP) ou regroupé par marque comme la page Prix.",
|
|
828
|
+
en: "The latest public and ex-factory price, one row per presentation (CIP) or grouped by brand as on the Prices page.",
|
|
829
|
+
},
|
|
830
|
+
viz: ["table", "cards"],
|
|
831
|
+
usesBrands: true,
|
|
832
|
+
params: [
|
|
833
|
+
{
|
|
834
|
+
key: "group",
|
|
835
|
+
label: { fr: "Regroupement", en: "Grouping" },
|
|
836
|
+
options: [
|
|
837
|
+
{ value: "presentation", label: { fr: "Une ligne par CIP", en: "One row per CIP" } },
|
|
838
|
+
{ value: "brand", label: { fr: "Par marque", en: "Per brand" } },
|
|
839
|
+
],
|
|
840
|
+
},
|
|
841
|
+
],
|
|
842
|
+
size: { w: 12, h: 5 },
|
|
843
|
+
async fetch(params, { brands, lang }) {
|
|
844
|
+
const response = await search(ES_INDEX.DRUG_CARDS, {
|
|
845
|
+
size: Math.min(1000, brands.length * 50),
|
|
846
|
+
track_total_hits: true,
|
|
847
|
+
// Les champs de la carte de la page Prix (useHeartGroupedPrice), plus l'historique.
|
|
848
|
+
_source: [
|
|
849
|
+
"brand",
|
|
850
|
+
"label",
|
|
851
|
+
"cis_label",
|
|
852
|
+
"presentation_label",
|
|
853
|
+
"local_drug_id",
|
|
854
|
+
"molecule",
|
|
855
|
+
"manufacturer",
|
|
856
|
+
"atc4",
|
|
857
|
+
"atc5",
|
|
858
|
+
"distribution_channel",
|
|
859
|
+
"commercialization_status",
|
|
860
|
+
"commercialization_date",
|
|
861
|
+
"last_price_update",
|
|
862
|
+
"last_source_update",
|
|
863
|
+
"is_retrocession",
|
|
864
|
+
"is_sus",
|
|
865
|
+
"changed_history",
|
|
866
|
+
"reimbursement_history",
|
|
867
|
+
],
|
|
868
|
+
query: { terms: { "brand.keyword": brands } },
|
|
869
|
+
});
|
|
870
|
+
const docs = hitsOf(response);
|
|
871
|
+
const note = rmJoinNotes(truncation(response, lang), rmMissingNote(brands, new Set(docs.map((d) => String(d.brand))), lang));
|
|
872
|
+
// La carte de la page Prix attend un groupe par marque (cf. mapBucket de useHeartGroupedPrice).
|
|
873
|
+
const groups = new Map<string, any[]>();
|
|
874
|
+
for (const hit of response?.hits?.hits ?? []) {
|
|
875
|
+
const brand = String(hit._source?.brand ?? "");
|
|
876
|
+
groups.set(brand, [...(groups.get(brand) ?? []), { ...hit._source, id: hit._id }]);
|
|
877
|
+
}
|
|
878
|
+
const priceCards = {
|
|
879
|
+
kind: "prices" as const,
|
|
880
|
+
items: [...groups].map(([brand, products]) => ({
|
|
881
|
+
group_key: brand,
|
|
882
|
+
brand,
|
|
883
|
+
count: products.length,
|
|
884
|
+
ids: products.map((p) => p.id),
|
|
885
|
+
last_price_update: products.map((p) => p.last_price_update).filter(Boolean).sort().pop() ?? null,
|
|
886
|
+
manufacturers: [...new Set(products.map((p) => p.manufacturer).filter(Boolean))],
|
|
887
|
+
molecules: [...new Set(products.map((p) => p.molecule).filter(Boolean))],
|
|
888
|
+
products,
|
|
889
|
+
})),
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
/** Le prix le plus recent d'un type (1 : fabricant HT, 11 : public). */
|
|
893
|
+
const latest = (history: any[], type: number) =>
|
|
894
|
+
history
|
|
895
|
+
.filter((h) => h.price_type_id === type && typeof h.new_price === "number")
|
|
896
|
+
.sort((a, b) => String(b.application_date).localeCompare(String(a.application_date)))[0];
|
|
897
|
+
const presentations = docs.map((doc) => {
|
|
898
|
+
const history = Array.isArray(doc.changed_history) ? doc.changed_history : [];
|
|
899
|
+
const pub = latest(history, 11);
|
|
900
|
+
const fac = latest(history, 1);
|
|
901
|
+
const rates = (Array.isArray(doc.reimbursement_history) ? doc.reimbursement_history : [])
|
|
902
|
+
.filter((r: any) => typeof r.reimbursement_rate === "number")
|
|
903
|
+
.sort((a: any, b: any) => String(b.application_date).localeCompare(String(a.application_date)));
|
|
904
|
+
const dates = [pub?.application_date, fac?.application_date].filter(Boolean).sort();
|
|
905
|
+
return {
|
|
906
|
+
brand: String(doc.brand ?? ""),
|
|
907
|
+
label: String(doc.label ?? ""),
|
|
908
|
+
cip: doc.local_drug_id == null ? "" : String(doc.local_drug_id),
|
|
909
|
+
molecule: String(doc.molecule ?? ""),
|
|
910
|
+
manufacturer: String(doc.manufacturer ?? ""),
|
|
911
|
+
channel: String(doc.distribution_channel ?? ""),
|
|
912
|
+
status: String(doc.commercialization_status ?? ""),
|
|
913
|
+
public: pub?.new_price ?? null,
|
|
914
|
+
factory: fac?.new_price ?? null,
|
|
915
|
+
// Un ecart en euros avec le prix precedent, pas un pourcentage.
|
|
916
|
+
variation: typeof fac?.price_variation === "number" ? Math.round(fac.price_variation * 100) / 100 : null,
|
|
917
|
+
rate: rates[0] ? Math.round(rates[0].reimbursement_rate * 100) : null,
|
|
918
|
+
date: day(dates[dates.length - 1]) ?? day(doc.last_price_update),
|
|
919
|
+
};
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
if (params.group === "brand") {
|
|
923
|
+
// Comme les cartes de la page Prix : une marque, ses presentations
|
|
924
|
+
// comptees, ses laboratoires et la fourchette de ses prix.
|
|
925
|
+
const byBrand = new Map<string, typeof presentations>();
|
|
926
|
+
for (const row of presentations) byBrand.set(row.brand, [...(byBrand.get(row.brand) ?? []), row]);
|
|
927
|
+
const range = (values: (number | null)[], pick: "min" | "max") => {
|
|
928
|
+
const kept = values.filter((v): v is number => typeof v === "number");
|
|
929
|
+
return kept.length ? Math[pick](...kept) : null;
|
|
930
|
+
};
|
|
931
|
+
// « BRISTOL-MYERS SQUIBB » et « BRISTOL MYERS SQUIBB » sont le meme
|
|
932
|
+
// laboratoire : on dedoublonne sans la ponctuation, on garde la premiere graphie.
|
|
933
|
+
const join = (values: string[]) => {
|
|
934
|
+
const seen = new Map<string, string>();
|
|
935
|
+
for (const value of values.filter(Boolean)) {
|
|
936
|
+
const key = value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
937
|
+
if (!seen.has(key)) seen.set(key, value);
|
|
938
|
+
}
|
|
939
|
+
return [...seen.values()].join(", ");
|
|
940
|
+
};
|
|
941
|
+
return {
|
|
942
|
+
type: "rows",
|
|
943
|
+
columns: [
|
|
944
|
+
col("brand", TEXT("Marque", "Brand"), lang),
|
|
945
|
+
col("count", TEXT("Présentations", "Presentations"), lang, "numeric"),
|
|
946
|
+
col("manufacturer", TEXT("Laboratoire", "Manufacturer"), lang),
|
|
947
|
+
col("molecule", TEXT("Molécule", "Molecule"), lang, undefined, "optional"),
|
|
948
|
+
col("channel", TEXT("Canaux", "Channels"), lang, undefined, "optional"),
|
|
949
|
+
col("publicMin", TEXT("Prix public min (€)", "Min public price (€)"), lang, "numeric"),
|
|
950
|
+
col("publicMax", TEXT("Prix public max (€)", "Max public price (€)"), lang, "numeric"),
|
|
951
|
+
col("factoryMin", TEXT("PFHT min (€)", "Min ex-factory (€)"), lang, "numeric", "optional"),
|
|
952
|
+
col("factoryMax", TEXT("PFHT max (€)", "Max ex-factory (€)"), lang, "numeric", "optional"),
|
|
953
|
+
col("date", TEXT("Dernière mise à jour", "Last update"), lang, "date"),
|
|
954
|
+
],
|
|
955
|
+
rows: [...byBrand].map(([brand, rows]) => ({
|
|
956
|
+
brand,
|
|
957
|
+
count: rows.length,
|
|
958
|
+
manufacturer: join(rows.map((r) => r.manufacturer)),
|
|
959
|
+
molecule: join(rows.map((r) => r.molecule)),
|
|
960
|
+
channel: join(rows.map((r) => r.channel)),
|
|
961
|
+
publicMin: range(rows.map((r) => r.public), "min"),
|
|
962
|
+
publicMax: range(rows.map((r) => r.public), "max"),
|
|
963
|
+
factoryMin: range(rows.map((r) => r.factory), "min"),
|
|
964
|
+
factoryMax: range(rows.map((r) => r.factory), "max"),
|
|
965
|
+
date: rows.map((r) => r.date).filter(Boolean).sort().pop() ?? null,
|
|
966
|
+
})),
|
|
967
|
+
cards: priceCards,
|
|
968
|
+
note,
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
return {
|
|
973
|
+
type: "rows",
|
|
974
|
+
columns: [
|
|
975
|
+
col("brand", TEXT("Marque", "Brand"), lang),
|
|
976
|
+
col("label", TEXT("Présentation", "Presentation"), lang, "long"),
|
|
977
|
+
col("cip", TEXT("CIP / UCD", "CIP / UCD"), lang, undefined, "optional"),
|
|
978
|
+
col("molecule", TEXT("Molécule", "Molecule"), lang, undefined, "optional"),
|
|
979
|
+
col("manufacturer", TEXT("Laboratoire", "Manufacturer"), lang, undefined, "optional"),
|
|
980
|
+
col("channel", TEXT("Canal", "Channel"), lang),
|
|
981
|
+
col("status", TEXT("Commercialisation", "Marketing"), lang, undefined, "optional"),
|
|
982
|
+
col("public", TEXT("Prix public (€)", "Public price (€)"), lang, "numeric"),
|
|
983
|
+
col("factory", TEXT("Prix fabricant HT (€)", "Ex-factory price (€)"), lang, "numeric"),
|
|
984
|
+
col("variation", TEXT("Dernière variation PFHT (€)", "Last ex-factory change (€)"), lang, "numeric", "optional"),
|
|
985
|
+
col("rate", TEXT("Remboursement (%)", "Reimbursement (%)"), lang, "numeric", "optional"),
|
|
986
|
+
col("date", TEXT("Appliqué le", "Effective"), lang, "date"),
|
|
987
|
+
],
|
|
988
|
+
rows: presentations.sort((a, b) => a.brand.localeCompare(b.brand) || a.label.localeCompare(b.label)),
|
|
989
|
+
cards: priceCards,
|
|
990
|
+
note,
|
|
991
|
+
};
|
|
992
|
+
},
|
|
993
|
+
},
|
|
994
|
+
];
|
|
995
|
+
|
|
996
|
+
/** Les familles de ventes, ou la marque se lit dans le code du document. */
|
|
997
|
+
const SALES_TYPES = new Set(OIP_RESOURCE_SPECS.filter((spec) => spec.kind.titleFromId).map((spec) => spec.type));
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Les marques du projet, en majuscules comme le `code` des index de ventes :
|
|
1001
|
+
* celles des ventes rangees et des avis HAS, lues dans les documents que la
|
|
1002
|
+
* page a relus (repris de fr_drugs_app).
|
|
1003
|
+
*/
|
|
1004
|
+
export function oipProjectBrands(docs: WidgetContext["docs"]): string[] {
|
|
1005
|
+
const brands = docs.flatMap(({ type, source }) => {
|
|
1006
|
+
if (SALES_TYPES.has(type)) return [String(source?.code ?? "")];
|
|
1007
|
+
if (type === "FrHasBrand") return String(source?.brand_group ?? "").split("+");
|
|
1008
|
+
return [];
|
|
1009
|
+
});
|
|
1010
|
+
return [...new Set(brands.map((brand) => brand.trim().toUpperCase()).filter(Boolean))].sort();
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/** Les widgets medicament, chacun recevant les marques du projet. */
|
|
1014
|
+
export const OIP_DRUG_DASHBOARD_WIDGETS: WidgetKind[] = DRUG_WIDGETS.map((kind) => ({
|
|
1015
|
+
...kind,
|
|
1016
|
+
fetch: (params, context) => kind.fetch(params, { ...context, brands: oipProjectBrands(context.docs) }),
|
|
1017
|
+
}));
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les widgets science du tableau de bord d'un projet (portage de France
|
|
3
|
+
* Augmented Science) : les essais et les publications ranges, comptes dans les
|
|
4
|
+
* documents que la page a deja relus. Aucune requete : ils marchent dans toute
|
|
5
|
+
* app qui affiche le projet.
|
|
6
|
+
*
|
|
7
|
+
* Le `kind` est celui qu'enregistre le tableau de bord du projet, commun a
|
|
8
|
+
* toutes les apps : il ne se renomme pas.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { RmDashboardLang, RmWidgetData, RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
12
|
+
import type { OipProjectWidgetContext } from "../oip-defaults/projects";
|
|
13
|
+
|
|
14
|
+
type Lang = RmDashboardLang;
|
|
15
|
+
type WidgetData = RmWidgetData;
|
|
16
|
+
type WidgetContext = OipProjectWidgetContext;
|
|
17
|
+
|
|
18
|
+
const PROJECT = { fr: "Projet", en: "Project" };
|
|
19
|
+
|
|
20
|
+
/** Phase et statut des essais ranges, quel que soit le registre. */
|
|
21
|
+
function trialsOf(docs: WidgetContext["docs"]) {
|
|
22
|
+
return docs.flatMap((doc) => {
|
|
23
|
+
if (doc.type === "ClinicalTrialsNCT") return [{ phase: doc.source.phase, status: doc.source.overall_status }];
|
|
24
|
+
if (doc.type === "ClinicalTrialsEUCT") return [{ phase: doc.source.trial_phase, status: doc.source.global_status }];
|
|
25
|
+
return [];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Une part par valeur, la plus grande d'abord ; une valeur absente se dit. */
|
|
30
|
+
function countParts(values: unknown[], lang: Lang): WidgetData {
|
|
31
|
+
const counts = new Map<string, number>();
|
|
32
|
+
for (const value of values) {
|
|
33
|
+
const name = (Array.isArray(value) ? value.join(", ") : String(value ?? "")).trim() || (lang === "en" ? "Not specified" : "Non renseigné");
|
|
34
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
type: "parts",
|
|
38
|
+
parts: [...counts].map(([name, value]) => ({ name, value })).sort((a, b) => b.value - a.value),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Les essais et les publications du projet. */
|
|
43
|
+
export const OIP_SCIENCE_DASHBOARD_WIDGETS: RmWidgetKind<WidgetContext>[] = [
|
|
44
|
+
{
|
|
45
|
+
kind: "project.trialsByPhase",
|
|
46
|
+
group: PROJECT,
|
|
47
|
+
title: { fr: "Essais du projet par phase", en: "Project trials by phase" },
|
|
48
|
+
description: {
|
|
49
|
+
fr: "Les essais NCT et EUCT rangés dans le projet, par phase.",
|
|
50
|
+
en: "The NCT and EUCT trials filed in the project, per phase.",
|
|
51
|
+
},
|
|
52
|
+
viz: ["donut", "bar", "table"],
|
|
53
|
+
sources: [],
|
|
54
|
+
usesBrands: false,
|
|
55
|
+
params: [],
|
|
56
|
+
size: { w: 4, h: 5 },
|
|
57
|
+
async fetch(_params, { docs, lang }) {
|
|
58
|
+
return countParts(trialsOf(docs).map((t) => t.phase), lang);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
kind: "project.trialsByStatus",
|
|
63
|
+
group: PROJECT,
|
|
64
|
+
title: { fr: "Essais du projet par statut", en: "Project trials by status" },
|
|
65
|
+
description: {
|
|
66
|
+
fr: "Les essais NCT et EUCT rangés dans le projet, par statut de recrutement.",
|
|
67
|
+
en: "The NCT and EUCT trials filed in the project, per recruitment status.",
|
|
68
|
+
},
|
|
69
|
+
viz: ["donut", "bar", "table"],
|
|
70
|
+
sources: [],
|
|
71
|
+
usesBrands: false,
|
|
72
|
+
params: [],
|
|
73
|
+
size: { w: 4, h: 5 },
|
|
74
|
+
async fetch(_params, { docs, lang }) {
|
|
75
|
+
return countParts(trialsOf(docs).map((t) => t.status), lang);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
kind: "project.publicationsByYear",
|
|
80
|
+
group: PROJECT,
|
|
81
|
+
title: { fr: "Publications du projet par année", en: "Project publications by year" },
|
|
82
|
+
description: {
|
|
83
|
+
fr: "Les publications PubMed rangées dans le projet, par année de parution.",
|
|
84
|
+
en: "The PubMed publications filed in the project, per publication year.",
|
|
85
|
+
},
|
|
86
|
+
viz: ["bar", "line", "table"],
|
|
87
|
+
sources: [],
|
|
88
|
+
usesBrands: false,
|
|
89
|
+
params: [],
|
|
90
|
+
size: { w: 6, h: 5 },
|
|
91
|
+
async fetch(_params, { docs, lang }) {
|
|
92
|
+
const byYear = new Map<string, number>();
|
|
93
|
+
for (const doc of docs) {
|
|
94
|
+
if (doc.type !== "PubMed") continue;
|
|
95
|
+
const year = String(doc.source.pubdate ?? "").match(/\d{4}/)?.[0];
|
|
96
|
+
if (year) byYear.set(year, (byYear.get(year) ?? 0) + 1);
|
|
97
|
+
}
|
|
98
|
+
const categories = [...byYear.keys()].sort();
|
|
99
|
+
return {
|
|
100
|
+
type: "series",
|
|
101
|
+
categories,
|
|
102
|
+
series: [{ name: lang === "en" ? "Publications" : "Publications", data: categories.map((y) => byYear.get(y)!) }],
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
@@ -171,6 +171,17 @@ const DRUG_VIEWS: Record<string, string> = {
|
|
|
171
171
|
const TRIALS = { fr: "Essais cliniques", en: "Clinical trials" };
|
|
172
172
|
const MATCHING = { fr: "Expertises", en: "Expertise" };
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* La specialite principale d'un professionnel : l'annuaire range une liste
|
|
176
|
+
* d'objets (`hcp_specialty_type`, `hcp_specialty_label_regroup`), jamais une
|
|
177
|
+
* chaine. Lue telle quelle, la ligne d'un projet affichait « [object Object] ».
|
|
178
|
+
*/
|
|
179
|
+
function hcpSpecialty(value: unknown): string {
|
|
180
|
+
const specs: any[] = Array.isArray(value) ? value : value ? [value] : [];
|
|
181
|
+
const principal = specs.find((s) => s?.hcp_specialty_type === "PRINCIPAL") ?? specs[0];
|
|
182
|
+
return typeof principal === "string" ? principal : String(principal?.hcp_specialty_label_regroup ?? "");
|
|
183
|
+
}
|
|
184
|
+
|
|
174
185
|
const T = {
|
|
175
186
|
description: tab("study-description", "Description de l'étude", "Study description"),
|
|
176
187
|
investigators: tab("investigators", "Investigateurs", "Investigators"),
|
|
@@ -286,7 +297,7 @@ export const OIP_RESOURCE_SPECS: OipResourceSpec[] = [
|
|
|
286
297
|
icon: "UserCircle",
|
|
287
298
|
source: ["hcp_code", "hcp_first_name", "hcp_family_name", "specialty", "address"],
|
|
288
299
|
title: (s) => `${s.hcp_first_name || ""} ${s.hcp_family_name || ""}`.trim() || String(s.hcp_code),
|
|
289
|
-
subtitle: (s) => [s.specialty, s.address?.[0]?.hcp_city].filter(Boolean).join(" · "),
|
|
300
|
+
subtitle: (s) => [hcpSpecialty(s.specialty), s.address?.[0]?.hcp_city].filter(Boolean).join(" · "),
|
|
290
301
|
path: (s) => `/hcps/${s.hcp_code}/informations`,
|
|
291
302
|
},
|
|
292
303
|
// L'_id de l'annuaire est `10_<RPPS>` ; la page de la fiche, le RPPS seul.
|