@precisa-saude/fhir 0.20.0 → 0.20.2
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/biomarkers.cjs +2 -2
- package/dist/biomarkers.js +1 -1
- package/dist/{chunk-OZGOBYLX.js → chunk-3XFDQQAP.js} +38 -26
- package/dist/chunk-3XFDQQAP.js.map +1 -0
- package/dist/chunk-A6HR4XDK.js +9 -0
- package/dist/chunk-A6HR4XDK.js.map +1 -0
- package/dist/{chunk-6TQ24JCA.js → chunk-LNYG5HBE.js} +20 -9
- package/dist/chunk-LNYG5HBE.js.map +1 -0
- package/dist/chunk-OR67NJDZ.cjs +9 -0
- package/dist/chunk-OR67NJDZ.cjs.map +1 -0
- package/dist/{chunk-NXOTXKVB.cjs → chunk-S6LWF5M4.cjs} +40 -3
- package/dist/chunk-S6LWF5M4.cjs.map +1 -0
- package/dist/{chunk-2KDLOCD2.cjs → chunk-SIX3LHER.cjs} +20 -9
- package/dist/chunk-SIX3LHER.cjs.map +1 -0
- package/dist/chunk-X6AIQ6RY.cjs +165 -0
- package/dist/chunk-X6AIQ6RY.cjs.map +1 -0
- package/dist/{chunk-3KIJIRCI.js → chunk-ZT5XBA5S.js} +40 -3
- package/dist/chunk-ZT5XBA5S.js.map +1 -0
- package/dist/cli.js +91 -32
- package/dist/converter.cjs +4 -3
- package/dist/converter.cjs.map +1 -1
- package/dist/converter.js +3 -2
- package/dist/importer.cjs +4 -3
- package/dist/importer.cjs.map +1 -1
- package/dist/importer.d.cts +2 -1
- package/dist/importer.d.ts +2 -1
- package/dist/importer.js +3 -2
- package/dist/index.cjs +11 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2KDLOCD2.cjs.map +0 -1
- package/dist/chunk-3KIJIRCI.js.map +0 -1
- package/dist/chunk-6TQ24JCA.js.map +0 -1
- package/dist/chunk-CFKXCL2N.cjs +0 -153
- package/dist/chunk-CFKXCL2N.cjs.map +0 -1
- package/dist/chunk-NXOTXKVB.cjs.map +0 -1
- package/dist/chunk-OZGOBYLX.js.map +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkOR67NJDZcjs = require('./chunk-OR67NJDZ.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkS6LWF5M4cjs = require('./chunk-S6LWF5M4.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunk3ILBFLVQcjs = require('./chunk-3ILBFLVQ.cjs');
|
|
15
|
+
|
|
16
|
+
// src/importer.ts
|
|
17
|
+
var MAX_OBSERVATIONS = 5e3;
|
|
18
|
+
var MAX_FILE_SIZE = 15 * 1024 * 1024;
|
|
19
|
+
function resolveBiomarkerCode(observation) {
|
|
20
|
+
const coding = _nullishCoalesce(_optionalChain([observation, 'access', _ => _.code, 'optionalAccess', _2 => _2.coding]), () => ( []));
|
|
21
|
+
const loincCode = _optionalChain([coding, 'access', _3 => _3.find, 'call', _4 => _4((c) => c.system === _chunkOR67NJDZcjs.LOINC_SYSTEM), 'optionalAccess', _5 => _5.code]);
|
|
22
|
+
const declaredCode = _optionalChain([coding, 'access', _6 => _6.find, 'call', _7 => _7((c) => c.system === _chunkOR67NJDZcjs.BIOMARKER_CODE_SYSTEM), 'optionalAccess', _8 => _8.code]);
|
|
23
|
+
const seenCodes = [
|
|
24
|
+
...loincCode ? [`LOINC ${loincCode}`] : [],
|
|
25
|
+
...declaredCode ? [`biomarker code ${declaredCode}`] : []
|
|
26
|
+
];
|
|
27
|
+
let reason;
|
|
28
|
+
if (seenCodes.length > 0) {
|
|
29
|
+
reason = `Unknown code: ${seenCodes.join(", ")}`;
|
|
30
|
+
} else if (coding.length > 0) {
|
|
31
|
+
const systems = [...new Set(coding.map((c) => _nullishCoalesce(c.system, () => ( "(sem system)"))))];
|
|
32
|
+
reason = `No code in a supported system (found: ${systems.join(", ")})`;
|
|
33
|
+
} else {
|
|
34
|
+
reason = "No code found in observation coding";
|
|
35
|
+
}
|
|
36
|
+
const fromLoinc = loincCode ? _chunkS6LWF5M4cjs.loincToCode.call(void 0, loincCode) : void 0;
|
|
37
|
+
if (fromLoinc) return { internalCode: fromLoinc, loincCode, reason };
|
|
38
|
+
if (declaredCode && _chunkS6LWF5M4cjs.isValidCode.call(void 0, declaredCode)) {
|
|
39
|
+
const canonical = _chunkS6LWF5M4cjs.normalizeCode.call(void 0, declaredCode);
|
|
40
|
+
return { internalCode: canonical, loincCode: _chunkS6LWF5M4cjs.codeToLoinc.call(void 0, canonical), reason };
|
|
41
|
+
}
|
|
42
|
+
return { loincCode, reason };
|
|
43
|
+
}
|
|
44
|
+
function extractFlag(observation) {
|
|
45
|
+
const code = _optionalChain([observation, 'access', _9 => _9.interpretation, 'optionalAccess', _10 => _10[0], 'optionalAccess', _11 => _11.coding, 'optionalAccess', _12 => _12[0], 'optionalAccess', _13 => _13.code]);
|
|
46
|
+
if (code === "H" || code === "HH") return "H";
|
|
47
|
+
if (code === "L" || code === "LL") return "L";
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
function extractObservationsFromBundle(bundle) {
|
|
51
|
+
const observations = [];
|
|
52
|
+
const skipped = [];
|
|
53
|
+
for (let i = 0; i < bundle.entry.length; i++) {
|
|
54
|
+
const entry = bundle.entry[i];
|
|
55
|
+
if (!entry.resource) {
|
|
56
|
+
skipped.push({ index: i, reason: "Entry has no resource" });
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (entry.resource.resourceType !== "Observation") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (observations.length >= MAX_OBSERVATIONS) {
|
|
63
|
+
skipped.push({ index: i, reason: `Maximum of ${MAX_OBSERVATIONS} observations exceeded` });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
observations.push(entry.resource);
|
|
67
|
+
}
|
|
68
|
+
return { observations, skipped };
|
|
69
|
+
}
|
|
70
|
+
function mapFHIRObservationToInternal(observation, index) {
|
|
71
|
+
const { internalCode, loincCode, reason } = resolveBiomarkerCode(observation);
|
|
72
|
+
if (!internalCode) {
|
|
73
|
+
return {
|
|
74
|
+
skipped: { index, loincCode, reason, resourceType: "Observation" }
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const definition = _chunkS6LWF5M4cjs.getDefinitionByCode.call(void 0, internalCode);
|
|
78
|
+
let value;
|
|
79
|
+
let unit = "";
|
|
80
|
+
let isQualitative = false;
|
|
81
|
+
if (_optionalChain([observation, 'access', _14 => _14.valueQuantity, 'optionalAccess', _15 => _15.value]) !== void 0) {
|
|
82
|
+
value = observation.valueQuantity.value;
|
|
83
|
+
unit = observation.valueQuantity.unit || observation.valueQuantity.code || "";
|
|
84
|
+
} else if (observation.valueString) {
|
|
85
|
+
value = observation.valueString;
|
|
86
|
+
isQualitative = true;
|
|
87
|
+
} else {
|
|
88
|
+
return {
|
|
89
|
+
skipped: {
|
|
90
|
+
index,
|
|
91
|
+
loincCode,
|
|
92
|
+
reason: "Observation has no value (valueQuantity or valueString)",
|
|
93
|
+
resourceType: "Observation"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const collectionDate = observation.effectiveDateTime || _optionalChain([observation, 'access', _16 => _16.effectivePeriod, 'optionalAccess', _17 => _17.start]) || "";
|
|
98
|
+
if (!collectionDate) {
|
|
99
|
+
return {
|
|
100
|
+
skipped: {
|
|
101
|
+
index,
|
|
102
|
+
loincCode,
|
|
103
|
+
reason: "Observation has no effectiveDateTime or effectivePeriod.start",
|
|
104
|
+
resourceType: "Observation"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
let referenceMin;
|
|
109
|
+
let referenceMax;
|
|
110
|
+
if (_optionalChain([observation, 'access', _18 => _18.referenceRange, 'optionalAccess', _19 => _19[0]])) {
|
|
111
|
+
referenceMin = _optionalChain([observation, 'access', _20 => _20.referenceRange, 'access', _21 => _21[0], 'access', _22 => _22.low, 'optionalAccess', _23 => _23.value]);
|
|
112
|
+
referenceMax = _optionalChain([observation, 'access', _24 => _24.referenceRange, 'access', _25 => _25[0], 'access', _26 => _26.high, 'optionalAccess', _27 => _27.value]);
|
|
113
|
+
}
|
|
114
|
+
const imported = {
|
|
115
|
+
biomarkerCode: internalCode,
|
|
116
|
+
biomarkerName: _optionalChain([definition, 'optionalAccess', _28 => _28.names, 'access', _29 => _29.pt, 'access', _30 => _30[0]]) || _optionalChain([definition, 'optionalAccess', _31 => _31.names, 'access', _32 => _32.en, 'access', _33 => _33[0]]) || observation.code.text || internalCode,
|
|
117
|
+
collectionDate,
|
|
118
|
+
flag: extractFlag(observation),
|
|
119
|
+
isQualitative,
|
|
120
|
+
loincCode,
|
|
121
|
+
referenceMax,
|
|
122
|
+
referenceMin,
|
|
123
|
+
unit: unit || _optionalChain([definition, 'optionalAccess', _34 => _34.unit]) || "",
|
|
124
|
+
value
|
|
125
|
+
};
|
|
126
|
+
return { observation: imported };
|
|
127
|
+
}
|
|
128
|
+
function processImportBundle(data) {
|
|
129
|
+
const validationErrors = _chunk3ILBFLVQcjs.validateFHIRImportBundle.call(void 0, data);
|
|
130
|
+
if (validationErrors.length > 0) {
|
|
131
|
+
return {
|
|
132
|
+
errors: validationErrors,
|
|
133
|
+
imported: [],
|
|
134
|
+
skipped: [],
|
|
135
|
+
totalProcessed: 0
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const bundle = data;
|
|
139
|
+
const { observations, skipped } = extractObservationsFromBundle(bundle);
|
|
140
|
+
const imported = [];
|
|
141
|
+
const allSkipped = [...skipped];
|
|
142
|
+
for (let i = 0; i < observations.length; i++) {
|
|
143
|
+
const result = mapFHIRObservationToInternal(observations[i], i);
|
|
144
|
+
if ("observation" in result) {
|
|
145
|
+
imported.push(result.observation);
|
|
146
|
+
} else {
|
|
147
|
+
allSkipped.push(result.skipped);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
errors: [],
|
|
152
|
+
imported,
|
|
153
|
+
skipped: allSkipped,
|
|
154
|
+
totalProcessed: observations.length
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
exports.MAX_OBSERVATIONS = MAX_OBSERVATIONS; exports.MAX_FILE_SIZE = MAX_FILE_SIZE; exports.extractObservationsFromBundle = extractObservationsFromBundle; exports.mapFHIRObservationToInternal = mapFHIRObservationToInternal; exports.processImportBundle = processImportBundle;
|
|
165
|
+
//# sourceMappingURL=chunk-X6AIQ6RY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-X6AIQ6RY.cjs","../src/importer.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACgDA,IAAM,iBAAA,EAAmB,GAAA;AACzB,IAAM,cAAA,EAAgB,GAAA,EAAK,KAAA,EAAO,IAAA;AAclC,SAAS,oBAAA,CAAqB,WAAA,EAI5B;AACA,EAAA,MAAM,OAAA,mCAAS,WAAA,mBAAY,IAAA,6BAAM,QAAA,UAAU,CAAC,GAAA;AAC5C,EAAA,MAAM,UAAA,kBAAY,MAAA,qBAAO,IAAA,mBAAK,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,OAAA,IAAW,8BAAY,CAAA,6BAAG,MAAA;AACjE,EAAA,MAAM,aAAA,kBAAe,MAAA,qBAAO,IAAA,mBAAK,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,OAAA,IAAW,uCAAqB,CAAA,6BAAG,MAAA;AAE7E,EAAA,MAAM,UAAA,EAAY;AAAA,IAChB,GAAI,UAAA,EAAY,CAAC,CAAA,MAAA,EAAS,SAAS,CAAA,CAAA;AACf,IAAA;AACtB,EAAA;AAOI,EAAA;AACsB,EAAA;AACE,IAAA;AACE,EAAA;AACO,IAAA;AAC1B,IAAA;AACJ,EAAA;AACI,IAAA;AACX,EAAA;AAE8B,EAAA;AACN,EAAA;AAEQ,EAAA;AAOE,IAAA;AAIE,IAAA;AACpC,EAAA;AAE2B,EAAA;AAC7B;AAKmE;AACxC,EAAA;AACU,EAAA;AACA,EAAA;AAC5B,EAAA;AACT;AAK8C;AAIH,EAAA;AACR,EAAA;AAEA,EAAA;AACH,IAAA;AACP,IAAA;AACc,MAAA;AACjC,MAAA;AACF,IAAA;AAEmB,IAAA;AAEjB,MAAA;AACF,IAAA;AAE2B,IAAA;AACQ,MAAA;AACjC,MAAA;AACF,IAAA;AAEmD,IAAA;AACrD,EAAA;AAE+B,EAAA;AACjC;AAME;AAGiC,EAAA;AAEd,EAAA;AACV,IAAA;AACwB,MAAA;AAC/B,IAAA;AACF,EAAA;AAEmB,EAAA;AAGf,EAAA;AACO,EAAA;AACS,EAAA;AAEW,EAAA;AACK,IAAA;AACD,IAAA;AACC,EAAA;AACd,IAAA;AACJ,IAAA;AACX,EAAA;AACE,IAAA;AACI,MAAA;AACP,QAAA;AACA,QAAA;AACQ,QAAA;AACM,QAAA;AAChB,MAAA;AACF,IAAA;AACF,EAAA;AAGmC,EAAA;AACd,EAAA;AACZ,IAAA;AACI,MAAA;AACP,QAAA;AACA,QAAA;AACQ,QAAA;AACM,QAAA;AAChB,MAAA;AACF,IAAA;AACF,EAAA;AAGI,EAAA;AACA,EAAA;AACiC,EAAA;AACR,IAAA;AACA,IAAA;AAC7B,EAAA;AAEsC,EAAA;AACrB,IAAA;AAEK,IAAA;AACpB,IAAA;AAC6B,IAAA;AAC7B,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACkC,IAAA;AAClC,IAAA;AACF,EAAA;AAE+B,EAAA;AACjC;AAKqE;AAE1C,EAAA;AACQ,EAAA;AACxB,IAAA;AACG,MAAA;AACG,MAAA;AACD,MAAA;AACM,MAAA;AAClB,IAAA;AACF,EAAA;AAEe,EAAA;AAGmB,EAAA;AAGO,EAAA;AACK,EAAA;AAEb,EAAA;AAChB,IAAA;AAEc,IAAA;AACK,MAAA;AAC3B,IAAA;AACyB,MAAA;AAChC,IAAA;AACF,EAAA;AAEO,EAAA;AACI,IAAA;AACT,IAAA;AACS,IAAA;AACoB,IAAA;AAC/B,EAAA;AACF;ADnIuC;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-X6AIQ6RY.cjs","sourcesContent":[null,"/**\n * FHIR Importer\n *\n * Parses FHIR R4 Bundles and extracts Observation resources with known LOINC codes,\n * mapping them to internal biomarker codes for storage as lab results.\n */\n\nimport {\n codeToLoinc,\n getDefinitionByCode,\n isValidCode,\n loincToCode,\n normalizeCode,\n} from './biomarkers';\nimport { BIOMARKER_CODE_SYSTEM, LOINC_SYSTEM } from './code-systems';\nimport type { FHIRBundle, FHIRObservation } from './fhir-types';\nimport { validateFHIRImportBundle } from './validators';\n\nexport interface ImportedObservation {\n biomarkerCode: string;\n biomarkerName: string;\n collectionDate: string;\n flag: 'H' | 'L' | '';\n isQualitative: boolean;\n /** Ausente nos biomarcadores sem LOINC publicado, como composição corporal. */\n loincCode?: string;\n referenceMax?: number;\n referenceMin?: number;\n unit: string;\n value: number | string;\n}\n\nexport interface SkippedEntry {\n index: number;\n loincCode?: string;\n reason: string;\n resourceType?: string;\n}\n\nexport interface ImportError {\n details: string;\n field: string;\n}\n\nexport interface FHIRImportResult {\n errors: ImportError[];\n imported: ImportedObservation[];\n skipped: SkippedEntry[];\n totalProcessed: number;\n}\n\n/**\n * Limites de importação.\n *\n * Uma Observation exportada ocupa cerca de 1,25KB em JSON compacto e 2,75KB\n * quando o arquivo vem indentado, medido sobre um histórico real de 998\n * Observations em 61 laudos. Nesse tamanho, 5000 Observations dão 6,0MB\n * compactos ou 13,1MB indentados, e por isso o teto de arquivo é 15MB: cobre\n * as duas formas com folga.\n *\n * Na densidade desse mesmo histórico (16 Observations por laudo), 5000\n * equivalem a cerca de 300 laudos.\n */\nconst MAX_OBSERVATIONS = 5000;\nconst MAX_FILE_SIZE = 15 * 1024 * 1024; // 15MB\n\n/**\n * Resolve o código interno do biomarcador a partir do `code.coding`.\n *\n * LOINC primeiro, que é o vocabulário que arquivos de terceiros usam. Quando\n * não resolve, cai para o coding de códigos internos, presente nos arquivos\n * exportados pela própria plataforma.\n *\n * O fallback cobre dois casos: biomarcadores sem LOINC publicado (composição\n * corporal, densidade óssea, escore de cálcio) e arquivos antigos, exportados\n * quando esses biomarcadores saíam com o placeholder `99999-9`, que não\n * resolve para nada.\n */\nfunction resolveBiomarkerCode(observation: FHIRObservation): {\n internalCode?: string;\n loincCode?: string;\n reason: string;\n} {\n const coding = observation.code?.coding ?? [];\n const loincCode = coding.find((c) => c.system === LOINC_SYSTEM)?.code;\n const declaredCode = coding.find((c) => c.system === BIOMARKER_CODE_SYSTEM)?.code;\n\n const seenCodes = [\n ...(loincCode ? [`LOINC ${loincCode}`] : []),\n ...(declaredCode ? [`biomarker code ${declaredCode}`] : []),\n ];\n\n // Três motivos distintos de descarte, que antes se confundiam num só. Sem\n // essa separação, um arquivo em SNOMED relatava \"nenhum código encontrado\",\n // sugerindo `coding` vazio quando na verdade o código existia e estava num\n // system que não tratamos. Para importação de terceiros, é a diferença entre\n // um diagnóstico acionável e um enigma.\n let reason: string;\n if (seenCodes.length > 0) {\n reason = `Unknown code: ${seenCodes.join(', ')}`;\n } else if (coding.length > 0) {\n const systems = [...new Set(coding.map((c) => c.system ?? '(sem system)'))];\n reason = `No code in a supported system (found: ${systems.join(', ')})`;\n } else {\n reason = 'No code found in observation coding';\n }\n\n const fromLoinc = loincCode ? loincToCode(loincCode) : undefined;\n if (fromLoinc) return { internalCode: fromLoinc, loincCode, reason };\n\n if (declaredCode && isValidCode(declaredCode)) {\n // `isValidCode` aceita alias, mas alias não serve como código armazenado:\n // 49 definições têm um, e tanto `codeToLoinc` quanto as faixas de\n // referência são indexadas só pelo canônico. Sem normalizar, `VLDL_Cholesterol`\n // entraria no lugar de `VLDL` e perderia o LOINC 13458-5 que ele tem.\n // Importar um Bundle é fronteira de dados, que é onde `normalizeCode` deve\n // ser aplicado.\n const canonical = normalizeCode(declaredCode);\n\n // `codeToLoinc` devolve undefined para quem não tem LOINC, que é o caso\n // esperado aqui. O campo fica de fora em vez de receber um valor inventado.\n return { internalCode: canonical, loincCode: codeToLoinc(canonical), reason };\n }\n\n return { loincCode, reason };\n}\n\n/**\n * Extract interpretation flag from Observation\n */\nfunction extractFlag(observation: FHIRObservation): 'H' | 'L' | '' {\n const code = observation.interpretation?.[0]?.coding?.[0]?.code;\n if (code === 'H' || code === 'HH') return 'H';\n if (code === 'L' || code === 'LL') return 'L';\n return '';\n}\n\n/**\n * Extract Observation resources from a FHIR Bundle\n */\nexport function extractObservationsFromBundle(bundle: FHIRBundle): {\n observations: FHIRObservation[];\n skipped: SkippedEntry[];\n} {\n const observations: FHIRObservation[] = [];\n const skipped: SkippedEntry[] = [];\n\n for (let i = 0; i < bundle.entry.length; i++) {\n const entry = bundle.entry[i]!;\n if (!entry.resource) {\n skipped.push({ index: i, reason: 'Entry has no resource' });\n continue;\n }\n\n if (entry.resource.resourceType !== 'Observation') {\n // Non-observation resources are silently skipped (Patient, DiagnosticReport, etc.)\n continue;\n }\n\n if (observations.length >= MAX_OBSERVATIONS) {\n skipped.push({ index: i, reason: `Maximum of ${MAX_OBSERVATIONS} observations exceeded` });\n continue;\n }\n\n observations.push(entry.resource as FHIRObservation);\n }\n\n return { observations, skipped };\n}\n\n/**\n * Map a FHIR Observation to internal format using LOINC→biomarker code lookup\n */\nexport function mapFHIRObservationToInternal(\n observation: FHIRObservation,\n index: number,\n): { observation: ImportedObservation } | { skipped: SkippedEntry } {\n const { internalCode, loincCode, reason } = resolveBiomarkerCode(observation);\n\n if (!internalCode) {\n return {\n skipped: { index, loincCode, reason, resourceType: 'Observation' },\n };\n }\n\n const definition = getDefinitionByCode(internalCode);\n\n // Extract value\n let value: number | string;\n let unit = '';\n let isQualitative = false;\n\n if (observation.valueQuantity?.value !== undefined) {\n value = observation.valueQuantity.value;\n unit = observation.valueQuantity.unit || observation.valueQuantity.code || '';\n } else if (observation.valueString) {\n value = observation.valueString;\n isQualitative = true;\n } else {\n return {\n skipped: {\n index,\n loincCode,\n reason: 'Observation has no value (valueQuantity or valueString)',\n resourceType: 'Observation',\n },\n };\n }\n\n // Extract collection date (effectiveDateTime or effectivePeriod.start)\n const collectionDate = observation.effectiveDateTime || observation.effectivePeriod?.start || '';\n if (!collectionDate) {\n return {\n skipped: {\n index,\n loincCode,\n reason: 'Observation has no effectiveDateTime or effectivePeriod.start',\n resourceType: 'Observation',\n },\n };\n }\n\n // Extract reference ranges\n let referenceMin: number | undefined;\n let referenceMax: number | undefined;\n if (observation.referenceRange?.[0]) {\n referenceMin = observation.referenceRange[0].low?.value;\n referenceMax = observation.referenceRange[0].high?.value;\n }\n\n const imported: ImportedObservation = {\n biomarkerCode: internalCode,\n biomarkerName:\n definition?.names.pt[0] || definition?.names.en[0] || observation.code.text || internalCode,\n collectionDate,\n flag: extractFlag(observation),\n isQualitative,\n loincCode,\n referenceMax,\n referenceMin,\n unit: unit || definition?.unit || '',\n value,\n };\n\n return { observation: imported };\n}\n\n/**\n * Process a complete FHIR Bundle for import\n */\nexport function processImportBundle(data: unknown): FHIRImportResult {\n // Structural validation\n const validationErrors = validateFHIRImportBundle(data);\n if (validationErrors.length > 0) {\n return {\n errors: validationErrors,\n imported: [],\n skipped: [],\n totalProcessed: 0,\n };\n }\n\n const bundle = data as FHIRBundle;\n\n // Extract observations\n const { observations, skipped } = extractObservationsFromBundle(bundle);\n\n // Map each observation to internal format\n const imported: ImportedObservation[] = [];\n const allSkipped: SkippedEntry[] = [...skipped];\n\n for (let i = 0; i < observations.length; i++) {\n const result = mapFHIRObservationToInternal(observations[i]!, i);\n\n if ('observation' in result) {\n imported.push(result.observation);\n } else {\n allSkipped.push(result.skipped);\n }\n }\n\n return {\n errors: [],\n imported,\n skipped: allSkipped,\n totalProcessed: observations.length,\n };\n}\n\nexport { MAX_FILE_SIZE, MAX_OBSERVATIONS };\n"]}
|
|
@@ -1433,8 +1433,45 @@ var BIOMARKER_DEFINITIONS = [
|
|
|
1433
1433
|
codeAliases: ["Urine_Microalbumin"],
|
|
1434
1434
|
loinc: "14957-5",
|
|
1435
1435
|
names: {
|
|
1436
|
-
en: [
|
|
1437
|
-
|
|
1436
|
+
en: [
|
|
1437
|
+
"Microalbumin Urine",
|
|
1438
|
+
"Urine Albumin",
|
|
1439
|
+
"Urine Microalbumin",
|
|
1440
|
+
"Microalbumin",
|
|
1441
|
+
"Microalbuminuria",
|
|
1442
|
+
"Albumin, Urine"
|
|
1443
|
+
],
|
|
1444
|
+
// Todas as formas abaixo, em pt e en, nomeiam o MESMO analito: albumina
|
|
1445
|
+
// dosada na urina. Não são exames diferentes.
|
|
1446
|
+
//
|
|
1447
|
+
// "Microalbumina" e "microalbuminúria" são herança de nomenclatura: o
|
|
1448
|
+
// prefixo micro nunca se referiu a uma molécula menor, e sim a uma
|
|
1449
|
+
// faixa de excreção. O analito é o mesmo, e por isso as duas formas
|
|
1450
|
+
// pertencem a esta entrada e não a uma separada.
|
|
1451
|
+
//
|
|
1452
|
+
// "Albumina Urinária" vem primeiro de propósito. O gerador do ValueSet
|
|
1453
|
+
// do IG usa o primeiro nome pt como display, então a ordem decide o
|
|
1454
|
+
// rótulo publicado — e essa é a forma que os laboratórios brasileiros
|
|
1455
|
+
// de fato imprimem.
|
|
1456
|
+
//
|
|
1457
|
+
// As formas foram tiradas de dado real, não inventadas: "Albumin,
|
|
1458
|
+
// Urine" e "Albumina Urinária" aparecem como rótulos `UNKNOWN_` na
|
|
1459
|
+
// auditoria de cobertura da plataforma, ou seja, chegaram em laudo e
|
|
1460
|
+
// não casaram com nada.
|
|
1461
|
+
//
|
|
1462
|
+
// Sem elas o pré-scan casava "Albumina Urinária" com `Albumin`, a
|
|
1463
|
+
// albumina sérica. A troca não é cosmética: albumina na urina é
|
|
1464
|
+
// marcador de lesão renal precoce, medida em mg/L, e a sérica é de
|
|
1465
|
+
// função hepática e estado nutricional, medida em g/dL.
|
|
1466
|
+
pt: [
|
|
1467
|
+
"Albumina Urin\xE1ria",
|
|
1468
|
+
"Albumina Urina",
|
|
1469
|
+
"Microalbumina",
|
|
1470
|
+
"Microalbumin\xFAria",
|
|
1471
|
+
"Microalbumina Urina",
|
|
1472
|
+
"Microalbumina na Urina",
|
|
1473
|
+
"Albumina na Urina"
|
|
1474
|
+
]
|
|
1438
1475
|
},
|
|
1439
1476
|
unit: "mg/L"
|
|
1440
1477
|
},
|
|
@@ -3245,4 +3282,4 @@ export {
|
|
|
3245
3282
|
getBiomarkersByCategory,
|
|
3246
3283
|
getBiomarkersForCategories
|
|
3247
3284
|
};
|
|
3248
|
-
//# sourceMappingURL=chunk-
|
|
3285
|
+
//# sourceMappingURL=chunk-ZT5XBA5S.js.map
|