@precisa-saude/fhir 0.1.0

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.
Files changed (72) hide show
  1. package/README.md +85 -0
  2. package/dist/biomarkers.cjs +67 -0
  3. package/dist/biomarkers.cjs.map +1 -0
  4. package/dist/biomarkers.d.cts +226 -0
  5. package/dist/biomarkers.d.ts +226 -0
  6. package/dist/biomarkers.js +67 -0
  7. package/dist/biomarkers.js.map +1 -0
  8. package/dist/chunk-2EVQ2ESB.cjs +2692 -0
  9. package/dist/chunk-2EVQ2ESB.cjs.map +1 -0
  10. package/dist/chunk-2X6MT5KE.cjs +1464 -0
  11. package/dist/chunk-2X6MT5KE.cjs.map +1 -0
  12. package/dist/chunk-3ILBFLVQ.cjs +63 -0
  13. package/dist/chunk-3ILBFLVQ.cjs.map +1 -0
  14. package/dist/chunk-FDOBUUGY.js +1464 -0
  15. package/dist/chunk-FDOBUUGY.js.map +1 -0
  16. package/dist/chunk-GFXKYXHW.cjs +436 -0
  17. package/dist/chunk-GFXKYXHW.cjs.map +1 -0
  18. package/dist/chunk-I6H35QXI.js +2692 -0
  19. package/dist/chunk-I6H35QXI.js.map +1 -0
  20. package/dist/chunk-N3ZCOLG2.js +63 -0
  21. package/dist/chunk-N3ZCOLG2.js.map +1 -0
  22. package/dist/chunk-O25F6G3K.cjs +153 -0
  23. package/dist/chunk-O25F6G3K.cjs.map +1 -0
  24. package/dist/chunk-S6VJHXJF.js +153 -0
  25. package/dist/chunk-S6VJHXJF.js.map +1 -0
  26. package/dist/chunk-UIDSSWBJ.js +251 -0
  27. package/dist/chunk-UIDSSWBJ.js.map +1 -0
  28. package/dist/chunk-VPMT4MRS.js +436 -0
  29. package/dist/chunk-VPMT4MRS.js.map +1 -0
  30. package/dist/chunk-Z6YE6FJ4.cjs +251 -0
  31. package/dist/chunk-Z6YE6FJ4.cjs.map +1 -0
  32. package/dist/converter-C-QpCcTL.d.ts +99 -0
  33. package/dist/converter-Dee-qjBV.d.cts +99 -0
  34. package/dist/converter.cjs +15 -0
  35. package/dist/converter.cjs.map +1 -0
  36. package/dist/converter.d.cts +2 -0
  37. package/dist/converter.d.ts +2 -0
  38. package/dist/converter.js +15 -0
  39. package/dist/converter.js.map +1 -0
  40. package/dist/fhir-types-D9hUzGrc.d.cts +129 -0
  41. package/dist/fhir-types-D9hUzGrc.d.ts +129 -0
  42. package/dist/importer.cjs +17 -0
  43. package/dist/importer.cjs.map +1 -0
  44. package/dist/importer.d.cts +60 -0
  45. package/dist/importer.d.ts +60 -0
  46. package/dist/importer.js +17 -0
  47. package/dist/importer.js.map +1 -0
  48. package/dist/index.cjs +540 -0
  49. package/dist/index.cjs.map +1 -0
  50. package/dist/index.d.cts +163 -0
  51. package/dist/index.d.ts +163 -0
  52. package/dist/index.js +540 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/reference-ranges.cjs +18 -0
  55. package/dist/reference-ranges.cjs.map +1 -0
  56. package/dist/reference-ranges.d.cts +106 -0
  57. package/dist/reference-ranges.d.ts +106 -0
  58. package/dist/reference-ranges.js +18 -0
  59. package/dist/reference-ranges.js.map +1 -0
  60. package/dist/units.cjs +19 -0
  61. package/dist/units.cjs.map +1 -0
  62. package/dist/units.d.cts +46 -0
  63. package/dist/units.d.ts +46 -0
  64. package/dist/units.js +19 -0
  65. package/dist/units.js.map +1 -0
  66. package/dist/validators.cjs +11 -0
  67. package/dist/validators.cjs.map +1 -0
  68. package/dist/validators.d.cts +23 -0
  69. package/dist/validators.d.ts +23 -0
  70. package/dist/validators.js +11 -0
  71. package/dist/validators.js.map +1 -0
  72. package/package.json +105 -0
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @precisa-saude/fhir
2
+
3
+ Tipos FHIR R4, 183+ definições de biomarcadores com códigos LOINC, faixas de referência (SBPC/ML, SBC, SBD), conversores e importadores para o contexto clínico brasileiro.
4
+
5
+ ## Instalação
6
+
7
+ ```bash
8
+ npm install @precisa-saude/fhir
9
+ ```
10
+
11
+ ## Uso rápido
12
+
13
+ ### Faixas de referência
14
+
15
+ ```ts
16
+ import { getReferenceRange } from '@precisa-saude/fhir';
17
+
18
+ const range = getReferenceRange('Cholesterol');
19
+ // { min: 0, max: 190, optimalMax: 190, unit: 'mg/dL', ... }
20
+
21
+ const rangeForUser = getReferenceRange('HDL', { sex: 'F', age: 35 });
22
+ // Faixa ajustada por sexo e idade
23
+ ```
24
+
25
+ ### Converter resultados laboratoriais para FHIR R4
26
+
27
+ ```ts
28
+ import { labResultToFHIRBundle } from '@precisa-saude/fhir';
29
+
30
+ const bundle = labResultToFHIRBundle(report, observations, userProfile);
31
+ // Retorna um FHIR Bundle com DiagnosticReport, Observations e Patient
32
+ ```
33
+
34
+ ### Normalizar códigos de biomarcadores
35
+
36
+ ```ts
37
+ import { normalizeCode, codeToLoinc, loincToCode } from '@precisa-saude/fhir';
38
+
39
+ normalizeCode('CholHDL_Ratio'); // 'Cholesterol_HDL_Ratio'
40
+ codeToLoinc('HDL'); // '2085-9'
41
+ loincToCode('2085-9'); // 'HDL'
42
+ ```
43
+
44
+ ### Consultar definições de biomarcadores
45
+
46
+ ```ts
47
+ import { getDefinitionByCode, getAllDefinitions } from '@precisa-saude/fhir';
48
+
49
+ const def = getDefinitionByCode('HDL');
50
+ // { code: 'HDL', loinc: '2085-9', names: { pt: [...], en: [...] }, ... }
51
+
52
+ const all = getAllDefinitions(); // 183+ definições
53
+ ```
54
+
55
+ ## Sub-path imports
56
+
57
+ Para tree-shaking otimizado, cada módulo pode ser importado individualmente:
58
+
59
+ ```ts
60
+ import { BIOMARKER_DEFINITIONS } from '@precisa-saude/fhir/biomarkers';
61
+ import { getReferenceRange } from '@precisa-saude/fhir/reference-ranges';
62
+ import { labResultToFHIRBundle } from '@precisa-saude/fhir/converter';
63
+ import { processImportBundle } from '@precisa-saude/fhir/importer';
64
+ import { getCanonicalUnit, unitToUCUM } from '@precisa-saude/fhir/units';
65
+ import { validateFHIRObservation } from '@precisa-saude/fhir/validators';
66
+ ```
67
+
68
+ ## Módulos
69
+
70
+ | Sub-path | Descrição |
71
+ | --------------------- | ---------------------------------------------------------------- |
72
+ | `/biomarkers` | 183+ definições com códigos LOINC, nomes pt/en, categorias |
73
+ | `/reference-ranges` | Faixas de referência por sexo/idade (SBPC/ML, SBC, SBD, OMS) |
74
+ | `/converter` | Converte dados laboratoriais para FHIR R4 Bundle |
75
+ | `/importer` | Importa FHIR Bundle de volta para estruturas internas |
76
+ | `/units` | Mapeamento de unidades, conversão para UCUM |
77
+ | `/validators` | Validação de recursos FHIR (DiagnosticReport, Observation, Bundle) |
78
+
79
+ ## Aviso médico
80
+
81
+ Este pacote fornece ferramentas de software para padronização de dados clínicos. **Não substitui orientação médica profissional.** Consulte o [DISCLAIMER.md](../../DISCLAIMER.md) na raiz do repositório para detalhes completos.
82
+
83
+ ## Licença
84
+
85
+ [Apache-2.0](../../LICENSE)
@@ -0,0 +1,67 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ var _chunk2EVQ2ESBcjs = require('./chunk-2EVQ2ESB.cjs');
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+ exports.BIOMARKER_DEFINITIONS = _chunk2EVQ2ESBcjs.BIOMARKER_DEFINITIONS; exports.CAC_INDICATOR_CODES = _chunk2EVQ2ESBcjs.CAC_INDICATOR_CODES; exports.DEXA_CATEGORIES = _chunk2EVQ2ESBcjs.DEXA_CATEGORIES; exports.DEXA_INDICATOR_CODES = _chunk2EVQ2ESBcjs.DEXA_INDICATOR_CODES; exports.codeToLoinc = _chunk2EVQ2ESBcjs.codeToLoinc; exports.filterVisibleBiomarkers = _chunk2EVQ2ESBcjs.filterVisibleBiomarkers; exports.findCodeByName = _chunk2EVQ2ESBcjs.findCodeByName; exports.generateCacFullReference = _chunk2EVQ2ESBcjs.generateCacFullReference; exports.generateDexaFullReference = _chunk2EVQ2ESBcjs.generateDexaFullReference; exports.generateFilteredLLMReference = _chunk2EVQ2ESBcjs.generateFilteredLLMReference; exports.generateLLMReference = _chunk2EVQ2ESBcjs.generateLLMReference; exports.getAllCodes = _chunk2EVQ2ESBcjs.getAllCodes; exports.getAllDefinitions = _chunk2EVQ2ESBcjs.getAllDefinitions; exports.getAllLoincCodes = _chunk2EVQ2ESBcjs.getAllLoincCodes; exports.getAllSearchPatterns = _chunk2EVQ2ESBcjs.getAllSearchPatterns; exports.getBiomarkersByCategory = _chunk2EVQ2ESBcjs.getBiomarkersByCategory; exports.getBiomarkersForCategories = _chunk2EVQ2ESBcjs.getBiomarkersForCategories; exports.getDefinitionByCode = _chunk2EVQ2ESBcjs.getDefinitionByCode; exports.getDefinitionByLoinc = _chunk2EVQ2ESBcjs.getDefinitionByLoinc; exports.getDefinitionsBySex = _chunk2EVQ2ESBcjs.getDefinitionsBySex; exports.getSexForCode = _chunk2EVQ2ESBcjs.getSexForCode; exports.getVisibleDefinitions = _chunk2EVQ2ESBcjs.getVisibleDefinitions; exports.isBiomarkerVisible = _chunk2EVQ2ESBcjs.isBiomarkerVisible; exports.isCacDocument = _chunk2EVQ2ESBcjs.isCacDocument; exports.isDexaDocument = _chunk2EVQ2ESBcjs.isDexaDocument; exports.isValidCode = _chunk2EVQ2ESBcjs.isValidCode; exports.isValidLoinc = _chunk2EVQ2ESBcjs.isValidLoinc; exports.loincToCode = _chunk2EVQ2ESBcjs.loincToCode; exports.normalizeCode = _chunk2EVQ2ESBcjs.normalizeCode; exports.toBiomarkerTests = _chunk2EVQ2ESBcjs.toBiomarkerTests; exports.validateLoincNameMatch = _chunk2EVQ2ESBcjs.validateLoincNameMatch;
67
+ //# sourceMappingURL=biomarkers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/rafael/Github/precisa-saude/fhir-brasil/packages/core/dist/biomarkers.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,shEAAC","file":"/Users/rafael/Github/precisa-saude/fhir-brasil/packages/core/dist/biomarkers.cjs"}
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Biomarker Definitions - Single Source of Truth
3
+ *
4
+ * This file defines all supported biomarkers with:
5
+ * - LOINC codes (canonical identifier for cross-language matching)
6
+ * - Internal codes (for UI display)
7
+ * - Portuguese and English names
8
+ * - Categories
9
+ * - Default units
10
+ *
11
+ * The LLM extraction prompt includes these definitions so it can output
12
+ * LOINC codes directly, eliminating the need for name-matching logic.
13
+ */
14
+ interface BiomarkerDefinition {
15
+ category: string | string[];
16
+ code: string;
17
+ codeAliases?: string[];
18
+ hidden?: boolean;
19
+ loinc?: string;
20
+ loincAliases?: string[];
21
+ names: {
22
+ en: string[];
23
+ pt: string[];
24
+ };
25
+ sex?: 'male' | 'female' | 'both';
26
+ unit?: string;
27
+ }
28
+ /** @deprecated Use `BiomarkerDefinition` instead */
29
+ type SupportedBiomarker = BiomarkerDefinition;
30
+ /**
31
+ * All supported biomarker definitions
32
+ */
33
+ declare const BIOMARKER_DEFINITIONS: BiomarkerDefinition[];
34
+ /**
35
+ * Convert LOINC code to internal code
36
+ */
37
+ declare function loincToCode(loinc: string): string | undefined;
38
+ /**
39
+ * Convert internal code to LOINC
40
+ */
41
+ declare function codeToLoinc(code: string): string | undefined;
42
+ /**
43
+ * Check if a LOINC code is in our supported list
44
+ */
45
+ declare function isValidLoinc(loinc: string): boolean;
46
+ /**
47
+ * Check if a code is valid (canonical or alias)
48
+ */
49
+ declare function isValidCode(code: string): boolean;
50
+ /**
51
+ * Normalize a code alias to its canonical form.
52
+ * Returns the canonical code if input is an alias, otherwise returns the input unchanged.
53
+ *
54
+ * Use this at data boundaries (e.g. parsing lab results) to map incoming aliases
55
+ * to canonical codes. Do NOT use this as a fallback inside lookup functions —
56
+ * dictionary keys (e.g. biomarkerRangeDefinitions) must use canonical codes directly.
57
+ */
58
+ declare function normalizeCode(code: string): string;
59
+ /**
60
+ * Get the sex relevance for a biomarker code
61
+ * @returns 'male', 'female', or 'both' (default)
62
+ */
63
+ declare function getSexForCode(code: string): 'male' | 'female' | 'both';
64
+ /**
65
+ * Get all biomarker definitions filtered by sex
66
+ * @param sex - 'male', 'female', or 'both' (returns all)
67
+ */
68
+ declare function getDefinitionsBySex(sex: 'male' | 'female' | 'both'): BiomarkerDefinition[];
69
+ /**
70
+ * Get biomarker definition by code
71
+ */
72
+ declare function getDefinitionByCode(code: string): BiomarkerDefinition | undefined;
73
+ /**
74
+ * Get biomarker definition by LOINC
75
+ */
76
+ declare function getDefinitionByLoinc(loinc: string): BiomarkerDefinition | undefined;
77
+ /**
78
+ * Get all biomarker definitions
79
+ */
80
+ declare function getAllDefinitions(): BiomarkerDefinition[];
81
+ /**
82
+ * Get all visible biomarker definitions (excludes hidden biomarkers)
83
+ */
84
+ declare function getVisibleDefinitions(): BiomarkerDefinition[];
85
+ /**
86
+ * Get all supported internal codes (canonical codes only, not aliases)
87
+ */
88
+ declare function getAllCodes(): string[];
89
+ /**
90
+ * Get all supported LOINC codes
91
+ */
92
+ declare function getAllLoincCodes(): string[];
93
+ /**
94
+ * Generate LLM reference prompt for biomarker extraction
95
+ * This is included in the extraction prompt so the LLM can output LOINC codes directly
96
+ */
97
+ declare function generateLLMReference(): string;
98
+ /**
99
+ * Generate biomarkerTests format for UI compatibility
100
+ * This replaces the old hardcoded biomarkerTests.ts
101
+ * Excludes hidden biomarkers from the output
102
+ */
103
+ declare function toBiomarkerTests(): Record<string, Array<{
104
+ pt: string;
105
+ en: string;
106
+ code: string;
107
+ }>>;
108
+ /**
109
+ * Biomarker search pattern for OCR text anchoring
110
+ */
111
+ interface BiomarkerSearchPattern {
112
+ code: string;
113
+ loinc?: string;
114
+ names: string[];
115
+ }
116
+ /**
117
+ * Get all biomarker search patterns for OCR text anchoring
118
+ * Returns a flat list of all biomarker codes with their searchable names
119
+ */
120
+ declare function getAllSearchPatterns(): BiomarkerSearchPattern[];
121
+ /**
122
+ * Generate filtered LLM reference for specific biomarker codes
123
+ * Only includes biomarkers that were found in the OCR text
124
+ */
125
+ declare function generateFilteredLLMReference(codes: string[]): string;
126
+ /**
127
+ * DEXA indicator biomarker codes
128
+ * When these are found in OCR text, the document is likely a DEXA/body composition scan
129
+ */
130
+ declare const DEXA_INDICATOR_CODES: readonly ["BodyFatPct", "FatMass", "LeanMass", "BMC", "FatFreeMass", "TotalMass"];
131
+ /**
132
+ * DEXA-related categories that should be included when a DEXA document is detected
133
+ */
134
+ declare const DEXA_CATEGORIES: readonly ["composicao-corporal", "densidade-ossea"];
135
+ /**
136
+ * Generate full DEXA/body composition reference for LLM extraction
137
+ * This includes ALL body composition biomarkers (regional metrics, VAT, bone density)
138
+ * that may not be detected by OCR anchoring due to table layouts
139
+ *
140
+ * Use this when DEXA indicator biomarkers (BodyFatPct, FatMass, LeanMass, etc.)
141
+ * are detected in the document
142
+ */
143
+ declare function generateDexaFullReference(): string;
144
+ /**
145
+ * Check if a list of biomarker codes indicates a DEXA/body composition document
146
+ */
147
+ declare function isDexaDocument(matchedCodes: string[]): boolean;
148
+ /**
149
+ * CAC (Coronary Artery Calcium) indicator biomarker codes
150
+ * When these are found in OCR text, the document is likely a CAC scoring report
151
+ */
152
+ declare const CAC_INDICATOR_CODES: readonly ["CAC", "CAC_LAD", "CAC_LCX", "CAC_RCA", "CAC_Percentile"];
153
+ /**
154
+ * Generate full CAC reference for LLM extraction
155
+ * This includes all CAC-related biomarkers (total score, per-vessel, percentile, aortic valve)
156
+ */
157
+ declare function generateCacFullReference(): string;
158
+ /**
159
+ * Check if a list of biomarker codes indicates a CAC scoring document
160
+ */
161
+ declare function isCacDocument(matchedCodes: string[]): boolean;
162
+ /**
163
+ * Find a biomarker code by name (with normalization)
164
+ * This is a fallback when LOINC lookup fails
165
+ * @param name - The biomarker name from the LLM output
166
+ * @returns The internal code if found, undefined otherwise
167
+ */
168
+ declare function findCodeByName(name: string): string | undefined;
169
+ /**
170
+ * Validate that a LOINC code matches a given name
171
+ * Returns the correct code if they match, or the name-based code if they don't
172
+ * This catches cases where LLM provides a valid-but-wrong LOINC
173
+ * @param loinc - The LOINC code provided by LLM
174
+ * @param name - The biomarker name provided by LLM
175
+ * @returns Object with code and whether a correction was made
176
+ */
177
+ declare function validateLoincNameMatch(loinc: string, name: string): {
178
+ code: string | undefined;
179
+ corrected: boolean;
180
+ };
181
+ /**
182
+ * Check if a biomarker code should be displayed in the UI
183
+ *
184
+ * Returns false for:
185
+ * - UNKNOWN_ codes (unrecognized biomarkers)
186
+ * - Biomarkers marked as hidden in their definition
187
+ *
188
+ * @param code - The biomarker code to check
189
+ * @returns true if the biomarker should be displayed
190
+ */
191
+ declare function isBiomarkerVisible(code: string): boolean;
192
+ /**
193
+ * Filter an array of biomarkers to only include visible ones
194
+ *
195
+ * @param biomarkers - Array of objects with a `code` property
196
+ * @returns Filtered array with only visible biomarkers
197
+ */
198
+ declare function filterVisibleBiomarkers<T extends {
199
+ code: string;
200
+ }>(biomarkers: T[]): T[];
201
+ /**
202
+ * Get all biomarkers for a specific category
203
+ *
204
+ * @param category - The category slug (e.g., 'coracao', 'tireoide')
205
+ * @param options - Optional filters
206
+ * @param options.includeHidden - Include hidden biomarkers (default: false)
207
+ * @param options.sex - Filter by sex ('male', 'female', or 'both' for all)
208
+ * @returns Array of biomarker definitions for the category
209
+ */
210
+ declare function getBiomarkersByCategory(category: string, options?: {
211
+ includeHidden?: boolean;
212
+ sex?: 'male' | 'female' | 'both';
213
+ }): BiomarkerDefinition[];
214
+ /**
215
+ * Get all biomarkers for multiple categories
216
+ *
217
+ * @param categories - Array of category slugs
218
+ * @param options - Optional filters (same as getBiomarkersByCategory)
219
+ * @returns Array of biomarker definitions grouped by category
220
+ */
221
+ declare function getBiomarkersForCategories(categories: string[], options?: {
222
+ includeHidden?: boolean;
223
+ sex?: 'male' | 'female' | 'both';
224
+ }): Record<string, BiomarkerDefinition[]>;
225
+
226
+ export { BIOMARKER_DEFINITIONS, type BiomarkerDefinition, type BiomarkerSearchPattern, CAC_INDICATOR_CODES, DEXA_CATEGORIES, DEXA_INDICATOR_CODES, type SupportedBiomarker, codeToLoinc, filterVisibleBiomarkers, findCodeByName, generateCacFullReference, generateDexaFullReference, generateFilteredLLMReference, generateLLMReference, getAllCodes, getAllDefinitions, getAllLoincCodes, getAllSearchPatterns, getBiomarkersByCategory, getBiomarkersForCategories, getDefinitionByCode, getDefinitionByLoinc, getDefinitionsBySex, getSexForCode, getVisibleDefinitions, isBiomarkerVisible, isCacDocument, isDexaDocument, isValidCode, isValidLoinc, loincToCode, normalizeCode, toBiomarkerTests, validateLoincNameMatch };
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Biomarker Definitions - Single Source of Truth
3
+ *
4
+ * This file defines all supported biomarkers with:
5
+ * - LOINC codes (canonical identifier for cross-language matching)
6
+ * - Internal codes (for UI display)
7
+ * - Portuguese and English names
8
+ * - Categories
9
+ * - Default units
10
+ *
11
+ * The LLM extraction prompt includes these definitions so it can output
12
+ * LOINC codes directly, eliminating the need for name-matching logic.
13
+ */
14
+ interface BiomarkerDefinition {
15
+ category: string | string[];
16
+ code: string;
17
+ codeAliases?: string[];
18
+ hidden?: boolean;
19
+ loinc?: string;
20
+ loincAliases?: string[];
21
+ names: {
22
+ en: string[];
23
+ pt: string[];
24
+ };
25
+ sex?: 'male' | 'female' | 'both';
26
+ unit?: string;
27
+ }
28
+ /** @deprecated Use `BiomarkerDefinition` instead */
29
+ type SupportedBiomarker = BiomarkerDefinition;
30
+ /**
31
+ * All supported biomarker definitions
32
+ */
33
+ declare const BIOMARKER_DEFINITIONS: BiomarkerDefinition[];
34
+ /**
35
+ * Convert LOINC code to internal code
36
+ */
37
+ declare function loincToCode(loinc: string): string | undefined;
38
+ /**
39
+ * Convert internal code to LOINC
40
+ */
41
+ declare function codeToLoinc(code: string): string | undefined;
42
+ /**
43
+ * Check if a LOINC code is in our supported list
44
+ */
45
+ declare function isValidLoinc(loinc: string): boolean;
46
+ /**
47
+ * Check if a code is valid (canonical or alias)
48
+ */
49
+ declare function isValidCode(code: string): boolean;
50
+ /**
51
+ * Normalize a code alias to its canonical form.
52
+ * Returns the canonical code if input is an alias, otherwise returns the input unchanged.
53
+ *
54
+ * Use this at data boundaries (e.g. parsing lab results) to map incoming aliases
55
+ * to canonical codes. Do NOT use this as a fallback inside lookup functions —
56
+ * dictionary keys (e.g. biomarkerRangeDefinitions) must use canonical codes directly.
57
+ */
58
+ declare function normalizeCode(code: string): string;
59
+ /**
60
+ * Get the sex relevance for a biomarker code
61
+ * @returns 'male', 'female', or 'both' (default)
62
+ */
63
+ declare function getSexForCode(code: string): 'male' | 'female' | 'both';
64
+ /**
65
+ * Get all biomarker definitions filtered by sex
66
+ * @param sex - 'male', 'female', or 'both' (returns all)
67
+ */
68
+ declare function getDefinitionsBySex(sex: 'male' | 'female' | 'both'): BiomarkerDefinition[];
69
+ /**
70
+ * Get biomarker definition by code
71
+ */
72
+ declare function getDefinitionByCode(code: string): BiomarkerDefinition | undefined;
73
+ /**
74
+ * Get biomarker definition by LOINC
75
+ */
76
+ declare function getDefinitionByLoinc(loinc: string): BiomarkerDefinition | undefined;
77
+ /**
78
+ * Get all biomarker definitions
79
+ */
80
+ declare function getAllDefinitions(): BiomarkerDefinition[];
81
+ /**
82
+ * Get all visible biomarker definitions (excludes hidden biomarkers)
83
+ */
84
+ declare function getVisibleDefinitions(): BiomarkerDefinition[];
85
+ /**
86
+ * Get all supported internal codes (canonical codes only, not aliases)
87
+ */
88
+ declare function getAllCodes(): string[];
89
+ /**
90
+ * Get all supported LOINC codes
91
+ */
92
+ declare function getAllLoincCodes(): string[];
93
+ /**
94
+ * Generate LLM reference prompt for biomarker extraction
95
+ * This is included in the extraction prompt so the LLM can output LOINC codes directly
96
+ */
97
+ declare function generateLLMReference(): string;
98
+ /**
99
+ * Generate biomarkerTests format for UI compatibility
100
+ * This replaces the old hardcoded biomarkerTests.ts
101
+ * Excludes hidden biomarkers from the output
102
+ */
103
+ declare function toBiomarkerTests(): Record<string, Array<{
104
+ pt: string;
105
+ en: string;
106
+ code: string;
107
+ }>>;
108
+ /**
109
+ * Biomarker search pattern for OCR text anchoring
110
+ */
111
+ interface BiomarkerSearchPattern {
112
+ code: string;
113
+ loinc?: string;
114
+ names: string[];
115
+ }
116
+ /**
117
+ * Get all biomarker search patterns for OCR text anchoring
118
+ * Returns a flat list of all biomarker codes with their searchable names
119
+ */
120
+ declare function getAllSearchPatterns(): BiomarkerSearchPattern[];
121
+ /**
122
+ * Generate filtered LLM reference for specific biomarker codes
123
+ * Only includes biomarkers that were found in the OCR text
124
+ */
125
+ declare function generateFilteredLLMReference(codes: string[]): string;
126
+ /**
127
+ * DEXA indicator biomarker codes
128
+ * When these are found in OCR text, the document is likely a DEXA/body composition scan
129
+ */
130
+ declare const DEXA_INDICATOR_CODES: readonly ["BodyFatPct", "FatMass", "LeanMass", "BMC", "FatFreeMass", "TotalMass"];
131
+ /**
132
+ * DEXA-related categories that should be included when a DEXA document is detected
133
+ */
134
+ declare const DEXA_CATEGORIES: readonly ["composicao-corporal", "densidade-ossea"];
135
+ /**
136
+ * Generate full DEXA/body composition reference for LLM extraction
137
+ * This includes ALL body composition biomarkers (regional metrics, VAT, bone density)
138
+ * that may not be detected by OCR anchoring due to table layouts
139
+ *
140
+ * Use this when DEXA indicator biomarkers (BodyFatPct, FatMass, LeanMass, etc.)
141
+ * are detected in the document
142
+ */
143
+ declare function generateDexaFullReference(): string;
144
+ /**
145
+ * Check if a list of biomarker codes indicates a DEXA/body composition document
146
+ */
147
+ declare function isDexaDocument(matchedCodes: string[]): boolean;
148
+ /**
149
+ * CAC (Coronary Artery Calcium) indicator biomarker codes
150
+ * When these are found in OCR text, the document is likely a CAC scoring report
151
+ */
152
+ declare const CAC_INDICATOR_CODES: readonly ["CAC", "CAC_LAD", "CAC_LCX", "CAC_RCA", "CAC_Percentile"];
153
+ /**
154
+ * Generate full CAC reference for LLM extraction
155
+ * This includes all CAC-related biomarkers (total score, per-vessel, percentile, aortic valve)
156
+ */
157
+ declare function generateCacFullReference(): string;
158
+ /**
159
+ * Check if a list of biomarker codes indicates a CAC scoring document
160
+ */
161
+ declare function isCacDocument(matchedCodes: string[]): boolean;
162
+ /**
163
+ * Find a biomarker code by name (with normalization)
164
+ * This is a fallback when LOINC lookup fails
165
+ * @param name - The biomarker name from the LLM output
166
+ * @returns The internal code if found, undefined otherwise
167
+ */
168
+ declare function findCodeByName(name: string): string | undefined;
169
+ /**
170
+ * Validate that a LOINC code matches a given name
171
+ * Returns the correct code if they match, or the name-based code if they don't
172
+ * This catches cases where LLM provides a valid-but-wrong LOINC
173
+ * @param loinc - The LOINC code provided by LLM
174
+ * @param name - The biomarker name provided by LLM
175
+ * @returns Object with code and whether a correction was made
176
+ */
177
+ declare function validateLoincNameMatch(loinc: string, name: string): {
178
+ code: string | undefined;
179
+ corrected: boolean;
180
+ };
181
+ /**
182
+ * Check if a biomarker code should be displayed in the UI
183
+ *
184
+ * Returns false for:
185
+ * - UNKNOWN_ codes (unrecognized biomarkers)
186
+ * - Biomarkers marked as hidden in their definition
187
+ *
188
+ * @param code - The biomarker code to check
189
+ * @returns true if the biomarker should be displayed
190
+ */
191
+ declare function isBiomarkerVisible(code: string): boolean;
192
+ /**
193
+ * Filter an array of biomarkers to only include visible ones
194
+ *
195
+ * @param biomarkers - Array of objects with a `code` property
196
+ * @returns Filtered array with only visible biomarkers
197
+ */
198
+ declare function filterVisibleBiomarkers<T extends {
199
+ code: string;
200
+ }>(biomarkers: T[]): T[];
201
+ /**
202
+ * Get all biomarkers for a specific category
203
+ *
204
+ * @param category - The category slug (e.g., 'coracao', 'tireoide')
205
+ * @param options - Optional filters
206
+ * @param options.includeHidden - Include hidden biomarkers (default: false)
207
+ * @param options.sex - Filter by sex ('male', 'female', or 'both' for all)
208
+ * @returns Array of biomarker definitions for the category
209
+ */
210
+ declare function getBiomarkersByCategory(category: string, options?: {
211
+ includeHidden?: boolean;
212
+ sex?: 'male' | 'female' | 'both';
213
+ }): BiomarkerDefinition[];
214
+ /**
215
+ * Get all biomarkers for multiple categories
216
+ *
217
+ * @param categories - Array of category slugs
218
+ * @param options - Optional filters (same as getBiomarkersByCategory)
219
+ * @returns Array of biomarker definitions grouped by category
220
+ */
221
+ declare function getBiomarkersForCategories(categories: string[], options?: {
222
+ includeHidden?: boolean;
223
+ sex?: 'male' | 'female' | 'both';
224
+ }): Record<string, BiomarkerDefinition[]>;
225
+
226
+ export { BIOMARKER_DEFINITIONS, type BiomarkerDefinition, type BiomarkerSearchPattern, CAC_INDICATOR_CODES, DEXA_CATEGORIES, DEXA_INDICATOR_CODES, type SupportedBiomarker, codeToLoinc, filterVisibleBiomarkers, findCodeByName, generateCacFullReference, generateDexaFullReference, generateFilteredLLMReference, generateLLMReference, getAllCodes, getAllDefinitions, getAllLoincCodes, getAllSearchPatterns, getBiomarkersByCategory, getBiomarkersForCategories, getDefinitionByCode, getDefinitionByLoinc, getDefinitionsBySex, getSexForCode, getVisibleDefinitions, isBiomarkerVisible, isCacDocument, isDexaDocument, isValidCode, isValidLoinc, loincToCode, normalizeCode, toBiomarkerTests, validateLoincNameMatch };
@@ -0,0 +1,67 @@
1
+ import {
2
+ BIOMARKER_DEFINITIONS,
3
+ CAC_INDICATOR_CODES,
4
+ DEXA_CATEGORIES,
5
+ DEXA_INDICATOR_CODES,
6
+ codeToLoinc,
7
+ filterVisibleBiomarkers,
8
+ findCodeByName,
9
+ generateCacFullReference,
10
+ generateDexaFullReference,
11
+ generateFilteredLLMReference,
12
+ generateLLMReference,
13
+ getAllCodes,
14
+ getAllDefinitions,
15
+ getAllLoincCodes,
16
+ getAllSearchPatterns,
17
+ getBiomarkersByCategory,
18
+ getBiomarkersForCategories,
19
+ getDefinitionByCode,
20
+ getDefinitionByLoinc,
21
+ getDefinitionsBySex,
22
+ getSexForCode,
23
+ getVisibleDefinitions,
24
+ isBiomarkerVisible,
25
+ isCacDocument,
26
+ isDexaDocument,
27
+ isValidCode,
28
+ isValidLoinc,
29
+ loincToCode,
30
+ normalizeCode,
31
+ toBiomarkerTests,
32
+ validateLoincNameMatch
33
+ } from "./chunk-I6H35QXI.js";
34
+ export {
35
+ BIOMARKER_DEFINITIONS,
36
+ CAC_INDICATOR_CODES,
37
+ DEXA_CATEGORIES,
38
+ DEXA_INDICATOR_CODES,
39
+ codeToLoinc,
40
+ filterVisibleBiomarkers,
41
+ findCodeByName,
42
+ generateCacFullReference,
43
+ generateDexaFullReference,
44
+ generateFilteredLLMReference,
45
+ generateLLMReference,
46
+ getAllCodes,
47
+ getAllDefinitions,
48
+ getAllLoincCodes,
49
+ getAllSearchPatterns,
50
+ getBiomarkersByCategory,
51
+ getBiomarkersForCategories,
52
+ getDefinitionByCode,
53
+ getDefinitionByLoinc,
54
+ getDefinitionsBySex,
55
+ getSexForCode,
56
+ getVisibleDefinitions,
57
+ isBiomarkerVisible,
58
+ isCacDocument,
59
+ isDexaDocument,
60
+ isValidCode,
61
+ isValidLoinc,
62
+ loincToCode,
63
+ normalizeCode,
64
+ toBiomarkerTests,
65
+ validateLoincNameMatch
66
+ };
67
+ //# sourceMappingURL=biomarkers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}