@tekkare/romulus 0.1.359 → 0.1.361

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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "0.1.358",
7
+ "version": "0.1.360",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -33,6 +33,7 @@ const props = withDefaults(defineProps<{
33
33
  tooltipDir: 'bottom',
34
34
  })
35
35
 
36
+ const rootRef = ref<HTMLElement>()
36
37
  const rowRef = ref<HTMLElement>()
37
38
  const visibleCount = ref(props.tags.length)
38
39
 
@@ -64,15 +65,27 @@ async function measure() {
64
65
  count++
65
66
  }
66
67
  visibleCount.value = count
68
+ if (count === items.length) return
69
+
70
+ // Le « +N » s'installe a droite et reprend de la place : la derniere
71
+ // etiquette gardee peut alors passer a la ligne, ou elle serait masquee
72
+ // sans etre comptee. On retire celles qui ont glisse.
73
+ await nextTick()
74
+ const kept = [...row.querySelectorAll<HTMLElement>('[data-rm-tag]')]
75
+ let fit = kept.length
76
+ while (fit > 1 && kept[fit - 1].offsetTop > firstTop) fit--
77
+ visibleCount.value = fit
67
78
  }
68
79
 
69
80
  let observer: ResizeObserver | undefined
70
81
 
71
82
  onMounted(() => {
72
83
  measure()
73
- if (typeof ResizeObserver !== 'undefined' && rowRef.value) {
84
+ // On observe la rangee entiere : la liste prend sa largeur naturelle, elle
85
+ // ne grandirait pas avec la carte et rien ne se reafficherait.
86
+ if (typeof ResizeObserver !== 'undefined' && rootRef.value) {
74
87
  observer = new ResizeObserver(() => measure())
75
- observer.observe(rowRef.value)
88
+ observer.observe(rootRef.value)
76
89
  }
77
90
  })
78
91
  onBeforeUnmount(() => observer?.disconnect())
@@ -80,7 +93,7 @@ watch(() => props.tags, measure, { deep: true })
80
93
  </script>
81
94
 
82
95
  <template>
83
- <div class="rm-tag-row" :data-rm-tags="JSON.stringify(items)">
96
+ <div ref="rootRef" class="rm-tag-row" :data-rm-tags="JSON.stringify(items)">
84
97
  <div ref="rowRef" class="rm-tag-row__items">
85
98
  <RmTag v-for="tag in shown" :key="tag.label" data-rm-tag :variant="tag.variant">{{ tag.label }}</RmTag>
86
99
  </div>
@@ -91,5 +104,5 @@ watch(() => props.tags, measure, { deep: true })
91
104
  </template>
92
105
 
93
106
  <style scoped>
94
- .rm-tag-row{align-items:center;width:100%}.rm-tag-row,.rm-tag-row__items{display:flex;gap:var(--space-8)}.rm-tag-row__items{flex:1;flex-wrap:wrap;max-height:24px;min-width:0;overflow:hidden}.rm-tag-row__more{color:var(--text-secondary);font-size:var(--font-12,12px);white-space:nowrap}
107
+ .rm-tag-row{align-items:center;width:100%}.rm-tag-row,.rm-tag-row__items{display:flex;gap:var(--space-8)}.rm-tag-row__items{flex:0 1 auto;flex-wrap:wrap;max-height:24px;min-width:0;overflow:hidden}.rm-tag-row__more{color:var(--text-secondary);font-size:var(--font-12,12px);white-space:nowrap}
95
108
  </style>
@@ -2,8 +2,9 @@
2
2
  * Suggestions de la barre de sujets de la creation guidee : maladies,
3
3
  * molecules et marques, dans une seule liste groupee.
4
4
  *
5
- * - Maladies, CIM-10 : le dictionnaire des hospitalisations par diagnostic
6
- * (libelles FR et EN, codes a 3 et 4 caracteres), interroge a chaque frappe.
5
+ * - Maladies, CIM-10 : les diagnostics MCO du PMSI par /api/oip/icd10
6
+ * (libelles FR et EN, codes a 3 et 4 caracteres), a defaut le dictionnaire
7
+ * des hospitalisations (anglais), interroges a chaque frappe.
7
8
  * - Maladies rares : les tags Orphanet des avis HAS (FR et EN) et des essais
8
9
  * NCT (EN), charges une fois puis filtres dans le navigateur, comme
9
10
  * l'assistant de fr_drugs_app. Le code relie les deux langues.
@@ -54,6 +55,42 @@ function keywords(query: string) {
54
55
  .map((word) => word.replace(/[sx]$/, ""));
55
56
  }
56
57
 
58
+ /**
59
+ * Le nom dans la langue de la saisie : « disease » propose l'anglais,
60
+ * « maladie » le francais, et la recherche des sources suit ce nom. A egalite
61
+ * (un code tape, un mot commun aux deux), la langue de l'ecran.
62
+ */
63
+ function typedLang(query: string, labels: Partial<Record<GuidedLang, string>>): GuidedLang | null {
64
+ if (!labels.fr || !labels.en) return null;
65
+ // Decide seulement la saisie trouvee dans un seul des deux noms :
66
+ // « parkinson » se lit dans les deux, la langue de l'ecran tranche.
67
+ const fr = rank(labels.fr, query) < 4;
68
+ const en = rank(labels.en, query) < 4;
69
+ if (fr !== en) return fr ? "fr" : "en";
70
+ if (fr) return null;
71
+ const words = keywords(query);
72
+ const frFuzzy = matchesFuzzy(fold(labels.fr), words);
73
+ const enFuzzy = matchesFuzzy(fold(labels.en), words);
74
+ return frFuzzy === enFuzzy ? null : frFuzzy ? "fr" : "en";
75
+ }
76
+
77
+ function typedLabel(query: string, labels: Partial<Record<GuidedLang, string>>, lang: GuidedLang): string {
78
+ return labels[typedLang(query, labels) ?? lang] || labels.fr || labels.en || "";
79
+ }
80
+
81
+ /**
82
+ * Une liste dans une seule langue : chaque nom dans celle de la saisie, et
83
+ * ceux qu'elle ne departage pas (« Overlapping lesion of breast » sous
84
+ * « breast cancer ») dans celle de la plupart des autres.
85
+ */
86
+ function typedLabels(query: string, rows: Partial<Record<GuidedLang, string>>[], lang: GuidedLang): string[] {
87
+ const langs = rows.map((labels) => typedLang(query, labels));
88
+ const fr = langs.filter((value) => value === "fr").length;
89
+ const en = langs.filter((value) => value === "en").length;
90
+ const fallback: GuidedLang = fr === en ? lang : fr > en ? "fr" : "en";
91
+ return rows.map((labels, index) => labels[langs[index] ?? fallback] || labels.fr || labels.en || "");
92
+ }
93
+
57
94
  /** Aucune faute sous 5 lettres, une jusqu'a 7, deux au-dela. */
58
95
  function allowedTypos(word: string) {
59
96
  if (word.length < 5) return 0;
@@ -161,18 +198,79 @@ async function rareDiseases(query: string, lang: GuidedLang): Promise<GuidedSubj
161
198
  })
162
199
  .filter((item) => item.score < 4)
163
200
  .sort((a, b) => a.score - b.score || a.tag.priority - b.tag.priority || a.tag.label.length - b.tag.label.length)
164
- // Une maladie ne sort qu'une fois, sous son nom dans la langue de l'ecran
165
- // quand il existe : « myasthenia gravis » propose « Myasthenie grave ».
201
+ // Une maladie ne sort qu'une fois, sous son nom dans la langue de la
202
+ // saisie (cf. typedLabel).
166
203
  .filter((item, index, all) => all.findIndex((other) => other.tag.code === item.tag.code) === index)
167
204
  .slice(0, MAX)
168
205
  .map(({ tag }) => {
169
- const shown = (byCode.get(tag.code) ?? []).filter((other) => other.lang === lang).sort((a, b) => a.priority - b.priority)[0] ?? tag;
170
- const subject: GuidedSubject = { focus: "disease", label: shown.label, code: tag.code, system: "orpha" };
206
+ const names = (byCode.get(tag.code) ?? []).sort((a, b) => a.priority - b.priority);
207
+ const label = typedLabel(query, { fr: names.find((name) => name.lang === "fr")?.label, en: names.find((name) => name.lang === "en")?.label }, lang) || tag.label;
208
+ const subject: GuidedSubject = { focus: "disease", label, code: tag.code, system: "orpha" };
171
209
  return { ...subject, hint: `ORPHA:${tag.code}`, key: subjectKey(subject) };
172
210
  });
173
211
  }
174
212
 
175
- async function icd10Diseases(query: string, lang: GuidedLang): Promise<GuidedSubjectSuggestion[]> {
213
+ /**
214
+ * « Tumeur maligne du sein » se dit « cancer du sein », « malignant neoplasm
215
+ * of breast » « breast cancer » : le nom courant, sauf a avoir tape le terme
216
+ * savant (« tumeur », « neoplasm »).
217
+ */
218
+ function commonCancerName(label: string, query: string): string {
219
+ if (/\b(tumeurs?|malignes?|neoplasms?|malignant)\b/.test(query)) return label;
220
+ const fr = label.match(/^tumeur maligne\b\s*(.*)$/i);
221
+ if (fr) return sentence(`cancer ${fr[1]}`.trim());
222
+ const en = label.match(/^malignant neoplasms? of (?:the )?([^,]+)(.*)$/i);
223
+ // « breast cancer », mais « cancer of central portion of breast ».
224
+ if (en) return sentence(/\bof\b/i.test(en[1]!) || en[1]!.trim().split(/\s+/).length > 2 ? `cancer of ${en[1]!.trim()}${en[2]}` : `${en[1]!.trim()} cancer${en[2]}`);
225
+ return label;
226
+ }
227
+
228
+ /**
229
+ * La CIM-10 en francais et en anglais : la route du layer lit les diagnostics
230
+ * MCO du PMSI, seuls a porter les libelles FR de toute la CIM-10. Sans elle
231
+ * (index injoignable avec la cle de l'app), le dictionnaire des cancers puis
232
+ * l'index des hospitalisations.
233
+ */
234
+ async function icd10Diseases(search: string, lang: GuidedLang): Promise<GuidedSubjectSuggestion[]> {
235
+ const query = fold(search);
236
+ const code = search.replace(/[.\s]/g, "").toUpperCase();
237
+ const cancerWords = /\b(cancers?|tumeurs?|malignes?|carcinomes?|neoplasms?|malignant|tumou?rs?)\b/i;
238
+ const organ = cancerWords.test(query)
239
+ ? query
240
+ .replace(new RegExp(cancerWords.source, "gi"), " ")
241
+ .replace(/\b(de la|de l'|du|des|de|d'|of the|of)\b/gi, " ")
242
+ .replace(/\s+/g, " ")
243
+ .trim()
244
+ : "";
245
+ try {
246
+ const rows = await $fetch<{ code: string; fr: string; en: string }[]>("/api/oip/icd10", {
247
+ query: {
248
+ // La CIM-10 ne dit jamais « cancer » : « cancer du » cherche « tumeur
249
+ // maligne du » (et non « canoe ou kayak », a deux fautes pres).
250
+ q: query.replace(/\bcancers?\b/g, "tumeur maligne"),
251
+ code: /^[A-Z]\d{1,3}$/.test(code) ? code : undefined,
252
+ organ: organ || undefined,
253
+ },
254
+ });
255
+ if (rows?.length) {
256
+ const labels = typedLabels(
257
+ query,
258
+ rows.map((row) => ({ fr: commonCancerName(sentence(row.fr), query), en: commonCancerName(sentence(row.en), query) })),
259
+ lang,
260
+ );
261
+ return rows.map((row, index) => {
262
+ const subject: GuidedSubject = { focus: "disease", label: labels[index]!, code: row.code, system: "icd10" };
263
+ return { ...subject, hint: `CIM-10 ${row.code}`, key: subjectKey(subject) };
264
+ });
265
+ }
266
+ } catch {
267
+ // Les autres dictionnaires prennent le relais.
268
+ }
269
+ const [cancer, hospitalizations] = await Promise.allSettled([cancerDiseases(query, lang), icd10FromHospitalizations(search, lang)]);
270
+ return [...(cancer.status === "fulfilled" ? cancer.value : []), ...(hospitalizations.status === "fulfilled" ? hospitalizations.value : [])];
271
+ }
272
+
273
+ async function icd10FromHospitalizations(query: string, lang: GuidedLang): Promise<GuidedSubjectSuggestion[]> {
176
274
  const code = query.replace(/[.\s]/g, "").toUpperCase();
177
275
  const isCode = /^[A-Z]\d{1,3}[A-Z]?$/.test(code);
178
276
  // Le dictionnaire dit « tumeur maligne du sein », on tape « cancer du sein » :
@@ -231,7 +329,7 @@ async function icd10Diseases(query: string, lang: GuidedLang): Promise<GuidedSub
231
329
  });
232
330
  return (response?.hits?.hits ?? []).map((hit: any) => {
233
331
  const source = hit._source ?? {};
234
- const label = sentence(clean(lang === "en" ? source.diagnosis_label : source.diagnosis_label_fr) || clean(source.diagnosis_label));
332
+ const label = typedLabel(fold(query), { fr: sentence(clean(source.diagnosis_label_fr)), en: sentence(clean(source.diagnosis_label)) }, lang);
235
333
  const subject: GuidedSubject = { focus: "disease", label, code: clean(source.diagnosis_code), system: "icd10" };
236
334
  return { ...subject, hint: `CIM-10 ${subject.code}`, key: subjectKey(subject) };
237
335
  });
@@ -304,7 +402,7 @@ async function cancerDiseases(query: string, lang: GuidedLang): Promise<GuidedSu
304
402
  .sort((a, b) => a.score - b.score || a.cancer.code.localeCompare(b.cancer.code))
305
403
  .slice(0, MAX)
306
404
  .map(({ cancer }) => {
307
- const subject: GuidedSubject = { focus: "disease", label: lang === "en" ? cancer.en : cancer.fr, code: cancer.code, system: "icd10" };
405
+ const subject: GuidedSubject = { focus: "disease", label: typedLabel(query, { fr: cancer.fr, en: cancer.en }, lang), code: cancer.code, system: "icd10" };
308
406
  return { ...subject, hint: `CIM-10 ${cancer.code}`, key: subjectKey(subject) };
309
407
  });
310
408
  }
@@ -360,17 +458,15 @@ async function drugs(query: string, lang: GuidedLang) {
360
458
  export async function suggestGuidedSubjects(search: string, lang: GuidedLang): Promise<GuidedSubjectGroups> {
361
459
  const query = fold(search);
362
460
  if (query.length < 2) return { diseases: [], molecules: [], brands: [] };
363
- const [cancer, icd, rare, drug] = await Promise.allSettled([
364
- cancerDiseases(query, lang),
461
+ const [icd, rare, drug] = await Promise.allSettled([
365
462
  icd10Diseases(search.trim(), lang),
366
463
  rareDiseases(query, lang),
367
464
  drugs(search.trim(), lang),
368
465
  ]);
369
466
  const value = <T>(result: PromiseSettledResult<T>, fallback: T) => (result.status === "fulfilled" ? result.value : fallback);
370
- // Les cancers d'abord (libelles FR surs), puis le reste de la CIM-10, puis
371
- // les maladies rares ; un meme code ne sort qu'une fois.
467
+ // La CIM-10, puis les maladies rares ; un meme code ne sort qu'une fois.
372
468
  const seen = new Set<string>();
373
- const diseases = [...value(cancer, []), ...value(icd, []), ...value(rare, [])]
469
+ const diseases = [...value(icd, []), ...value(rare, [])]
374
470
  .filter((entry) => !seen.has(entry.key) && !!seen.add(entry.key))
375
471
  .slice(0, MAX + 2);
376
472
  const { brands, molecules } = value(drug, { brands: [], molecules: [] });
@@ -0,0 +1,104 @@
1
+ import { createError, defineEventHandler, getQuery } from "h3";
2
+ import { requireOipSession } from "../../utils/oipAuth";
3
+ import { resolveOipEsIndex } from "../../utils/oipEsIndices";
4
+ import { oipReportIndexUsage } from "../../utils/oipIndexUsage";
5
+
6
+ /**
7
+ * GET /api/oip/icd10?q=&code=&organ=, servi par le layer OIP : la CIM-10 en
8
+ * francais et en anglais, pour les sujets de la creation guidee de projet.
9
+ *
10
+ * La source est l'index des diagnostics MCO du PMSI (ReaLifeData) : le seul
11
+ * qui porte les libelles FR de toute la CIM-10 (« E66 - OBESITE ET
12
+ * SURPOIDS »), celui des hospitalisations tous pays n'ayant que l'anglais.
13
+ * Ses lignes portent aussi des effectifs RLD : il reste hors du proxy
14
+ * /api/oip/es, et cette route ne rend que le code et ses deux libelles.
15
+ *
16
+ * - `q` : la saisie, sans accent (l'index n'en a pas).
17
+ * - `code` : la saisie lue comme un code (« E66 », « C509 »).
18
+ * - `organ` : la saisie sans « cancer », cherchee parmi les tumeurs (codes C) :
19
+ * on tape « cancer du sein », la CIM-10 dit « tumeur maligne du sein ».
20
+ */
21
+
22
+ /** ope_pmsi_mco_diagnosis_staging : lu en production aussi par l'app RLD. */
23
+ const MCO_DIAGNOSIS = "b3327a39-4b4f-4ce9-8713-503696fcb4f5";
24
+ const MAX = 6;
25
+
26
+ /** « E66 - OBESITE ET SURPOIDS » : le code, puis le libelle. */
27
+ function split(value: unknown): [string, string] {
28
+ const text = String(value ?? "");
29
+ const at = text.indexOf(" - ");
30
+ return at < 0 ? [text.trim(), ""] : [text.slice(0, at).trim(), text.slice(at + 3).trim()];
31
+ }
32
+
33
+ export default defineEventHandler(async (event) => {
34
+ await requireOipSession(event);
35
+ const { q, code, organ } = getQuery(event) as { q?: string; code?: string; organ?: string };
36
+ const query = String(q ?? "").trim().slice(0, 100);
37
+ if (query.length < 2) return [];
38
+
39
+ const target = ((useRuntimeConfig().oipEs ?? {}) as Record<string, Record<string, string | undefined>>).drugs;
40
+ if (!target?.domain || !target.auth) throw createError({ status: 503, message: "Elasticsearch cluster not configured: drugs" });
41
+
42
+ let physical = MCO_DIAGNOSIS;
43
+ try {
44
+ physical = await resolveOipEsIndex(MCO_DIAGNOSIS);
45
+ } catch (error: any) {
46
+ if (error?.statusCode !== 503 && error?.status !== 503) throw error;
47
+ physical = "ope_pmsi_mco_diagnosis_staging";
48
+ }
49
+ oipReportIndexUsage(event, [physical]);
50
+
51
+ const codeValue = /^[A-Z]\d{1,3}$/.test(String(code ?? "")) ? String(code) : "";
52
+ const organValue = String(organ ?? "").trim().slice(0, 100);
53
+ const fields = ["code_fr", "code_en"];
54
+ const startsWith = query.toUpperCase().replace(/[.?+*|{}[\]()"\\#@&<>~]/g, "\\$&");
55
+ const matches = [
56
+ ...(codeValue ? [{ prefix: { "code_fr.keyword": { value: codeValue, boost: 4 } } }] : []),
57
+ ...(organValue.length >= 2
58
+ ? [
59
+ {
60
+ bool: {
61
+ must: [{ multi_match: { query: organValue, fields, operator: "and", fuzziness: "AUTO", prefix_length: 2 } }],
62
+ filter: [{ prefix: { "code_fr.keyword": "C" } }],
63
+ boost: 2,
64
+ },
65
+ },
66
+ ]
67
+ : []),
68
+ // Le libelle qui commence par la saisie (« Obesite et surpoids ») avant celui qui la contient.
69
+ { regexp: { "code_fr.keyword": { value: `[A-Z][0-9]{2}[0-9]? - ${startsWith}.*`, boost: 30 } } },
70
+ { match_phrase_prefix: { code_fr: { query, boost: 3 } } },
71
+ { match_phrase_prefix: { code_en: { query, boost: 3 } } },
72
+ { multi_match: { query, fields, operator: "and", fuzziness: "AUTO", prefix_length: 2 } },
73
+ ];
74
+ const domain = target.domain.replace(/^https?:\/\//, "").replace(/\/+$/, "");
75
+ const response: any = await $fetch(`https://${domain}/${physical}/_search`, {
76
+ method: "POST",
77
+ headers: { authorization: `ApiKey ${target.auth}`, "content-type": "application/json" },
78
+ body: {
79
+ size: MAX,
80
+ _source: fields,
81
+ // Une ligne par code et par annee : un document par code.
82
+ collapse: { field: "code_fr.keyword" },
83
+ query: {
84
+ bool: {
85
+ // Codes CIM-10 de l'OMS (E66, C509) : les extensions de l'ATIH (E6603)
86
+ // ne se retrouvent dans aucun autre index.
87
+ filter: [{ regexp: { "code_fr.keyword": "[A-Z][0-9]{2}[0-9]? - .*" } }],
88
+ must: [{ bool: { should: matches, minimum_should_match: 1 } }],
89
+ // La categorie (E66) devant ses sous-codes (E668), qui repetent ses mots.
90
+ // Bonus a la mesure des scores texte (une quarantaine).
91
+ should: [{ regexp: { "code_fr.keyword": { value: "[A-Z][0-9]{2} - .*", boost: 15 } } }],
92
+ },
93
+ },
94
+ // A pertinence egale, le code court (C50) passe avant ses sous-codes.
95
+ sort: [{ _score: "desc" }, { "code_fr.keyword": "asc" }],
96
+ },
97
+ });
98
+
99
+ return (response?.hits?.hits ?? []).map((hit: any) => {
100
+ const [code, fr] = split(hit._source?.code_fr);
101
+ const [, en] = split(hit._source?.code_en);
102
+ return { code, fr, en };
103
+ });
104
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tekkare/romulus",
3
- "version": "0.1.359",
3
+ "version": "0.1.361",
4
4
  "description": "Romulus Design System - Nuxt module by Tekkare",
5
5
  "license": "MIT",
6
6
  "type": "module",