@precisa-saude/fhir 0.5.1 → 0.6.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.
- package/README.md +3 -3
- package/dist/{chunk-RGHKKL3W.js → chunk-4KGWSF55.js} +2 -2
- package/dist/{chunk-4EB4LIIT.cjs → chunk-CPZ7YNON.cjs} +4 -4
- package/dist/{chunk-4EB4LIIT.cjs.map → chunk-CPZ7YNON.cjs.map} +1 -1
- package/dist/{chunk-ZUBHCXUV.cjs → chunk-LYDCZW4C.cjs} +3 -3
- package/dist/{chunk-ZUBHCXUV.cjs.map → chunk-LYDCZW4C.cjs.map} +1 -1
- package/dist/{chunk-VPMT4MRS.js → chunk-R25V2E6S.js} +49 -6
- package/dist/chunk-R25V2E6S.js.map +1 -0
- package/dist/{chunk-35S3GSRK.js → chunk-YXYGKTVB.js} +2 -2
- package/dist/{chunk-GFXKYXHW.cjs → chunk-ZYSD6A2K.cjs} +49 -6
- package/dist/chunk-ZYSD6A2K.cjs.map +1 -0
- package/dist/cli.js +4 -5
- package/dist/converter.cjs +3 -3
- package/dist/converter.js +2 -2
- package/dist/index.cjs +8 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/reference-ranges.cjs +3 -3
- package/dist/reference-ranges.js +2 -2
- package/dist/units.cjs +4 -2
- package/dist/units.cjs.map +1 -1
- package/dist/units.d.cts +15 -1
- package/dist/units.d.ts +15 -1
- package/dist/units.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-GFXKYXHW.cjs.map +0 -1
- package/dist/chunk-VPMT4MRS.js.map +0 -1
- /package/dist/{chunk-RGHKKL3W.js.map → chunk-4KGWSF55.js.map} +0 -0
- /package/dist/{chunk-35S3GSRK.js.map → chunk-YXYGKTVB.js.map} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @precisa-saude/fhir
|
|
2
2
|
|
|
3
|
-
Tipos FHIR R4,
|
|
3
|
+
Tipos FHIR R4, 180+ 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
4
|
|
|
5
5
|
## Instalação
|
|
6
6
|
|
|
@@ -49,7 +49,7 @@ import { getDefinitionByCode, getAllDefinitions } from '@precisa-saude/fhir';
|
|
|
49
49
|
const def = getDefinitionByCode('HDL');
|
|
50
50
|
// { code: 'HDL', loinc: '2085-9', names: { pt: [...], en: [...] }, ... }
|
|
51
51
|
|
|
52
|
-
const all = getAllDefinitions(); //
|
|
52
|
+
const all = getAllDefinitions(); // 180+ definições
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
## Sub-path imports
|
|
@@ -69,7 +69,7 @@ import { validateFHIRObservation } from '@precisa-saude/fhir/validators';
|
|
|
69
69
|
|
|
70
70
|
| Sub-path | Descrição |
|
|
71
71
|
| ------------------- | ------------------------------------------------------------------ |
|
|
72
|
-
| `/biomarkers` |
|
|
72
|
+
| `/biomarkers` | 180+ definições com códigos LOINC, nomes pt/en, categorias |
|
|
73
73
|
| `/reference-ranges` | Faixas de referência por sexo/idade (SBPC/ML, SBC, SBD, OMS) |
|
|
74
74
|
| `/converter` | Converte dados laboratoriais para FHIR R4 Bundle |
|
|
75
75
|
| `/importer` | Importa FHIR Bundle de volta para estruturas internas |
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
getDefaultUnit,
|
|
6
6
|
unitToUCUM
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-R25V2E6S.js";
|
|
8
8
|
|
|
9
9
|
// src/converter.ts
|
|
10
10
|
function interpretationCode(flag) {
|
|
@@ -248,4 +248,4 @@ export {
|
|
|
248
248
|
userProfileToFHIR,
|
|
249
249
|
labResultToFHIRBundle
|
|
250
250
|
};
|
|
251
|
-
//# sourceMappingURL=chunk-
|
|
251
|
+
//# sourceMappingURL=chunk-4KGWSF55.js.map
|
|
@@ -4,7 +4,7 @@ var _chunk2EVQ2ESBcjs = require('./chunk-2EVQ2ESB.cjs');
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkZYSD6A2Kcjs = require('./chunk-ZYSD6A2K.cjs');
|
|
8
8
|
|
|
9
9
|
// src/converter.ts
|
|
10
10
|
function interpretationCode(flag) {
|
|
@@ -31,8 +31,8 @@ function interpretationDisplay(flag) {
|
|
|
31
31
|
}
|
|
32
32
|
function labObservationToFHIR(observation, patientId, laboratoryName) {
|
|
33
33
|
const loincCode = _chunk2EVQ2ESBcjs.codeToLoinc.call(void 0, observation.biomarkerCode) || "99999-9";
|
|
34
|
-
const sourceUnit = observation.unit ||
|
|
35
|
-
const ucumUnit =
|
|
34
|
+
const sourceUnit = observation.unit || _chunkZYSD6A2Kcjs.getDefaultUnit.call(void 0, observation.biomarkerCode) || observation.unit;
|
|
35
|
+
const ucumUnit = _chunkZYSD6A2Kcjs.unitToUCUM.call(void 0, sourceUnit);
|
|
36
36
|
const isQualitative = observation.isQualitative || typeof observation.value === "string";
|
|
37
37
|
const fhirObs = {
|
|
38
38
|
category: [
|
|
@@ -248,4 +248,4 @@ function labResultToFHIRBundle(report, observations, userProfile) {
|
|
|
248
248
|
|
|
249
249
|
|
|
250
250
|
exports.labObservationToFHIR = labObservationToFHIR; exports.labReportToFHIR = labReportToFHIR; exports.userProfileToFHIR = userProfileToFHIR; exports.labResultToFHIRBundle = labResultToFHIRBundle;
|
|
251
|
-
//# sourceMappingURL=chunk-
|
|
251
|
+
//# sourceMappingURL=chunk-CPZ7YNON.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-4EB4LIIT.cjs","../src/converter.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AAC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;AAEX,QAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AAIA,IAAA;AAGQ,MAAA;AACE,QAAA;AAAQ,UAAA;AACN,YAAA;AACQ,YAAA;AACG,YAAA;AACD,UAAA;AAEZ,QAAA;AACF,MAAA;AAEF,IAAA;AACN,IAAA;AACI,IAAA;AACJ,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAMgB;AACR,EAAA;AACA,EAAA;AACA,EAAA;AAEC,EAAA;AACL,IAAA;AAEM,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AAAM,UAAA;AAGgB,UAAA;AAEtB,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AAEF,IAAA;AACJ,IAAA;AACA,IAAA;AACI,IAAA;AACJ,IAAA;AACE,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAEQ,MAAA;AACA,MAAA;AACJ,IAAA;AAEQ,MAAA;AACA,MAAA;AAEN,IAAA;AACR,EAAA;AACF;AAMgB;AAKR,EAAA;AAGA,EAAA;AACJ,IAAA;AACA,IAAA;AACI,MAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACA,EAAA;AAEI,EAAA;AACH,IAAA;AACH,EAAA;AAGM,EAAA;AAGA,EAAA;AAEC,EAAA;AACL,IAAA;AACE,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AACG,MAAA;AACL,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;ADxES;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-4EB4LIIT.cjs","sourcesContent":[null,"/**\n * FHIR Converter\n *\n * Converts lab results to FHIR R4 DiagnosticReport and Observation resources.\n * See: https://hl7.org/fhir/diagnosticreport.html\n */\n\nimport { codeToLoinc } from './biomarkers';\nimport type { FHIRBundle, FHIRDiagnosticReport, FHIRObservation, FHIRPatient } from './fhir-types';\nimport type { Flag, LabObservationData, LabReportData, UserProfileData } from './types';\nimport { getDefaultUnit, unitToUCUM } from './units';\n\n// Re-export all types and functions\nexport * from './fhir-types';\n\n/**\n * Convert Flag to FHIR interpretation code\n */\nfunction interpretationCode(flag: Flag): string {\n switch (flag) {\n case 'H':\n return 'H'; // High\n case 'L':\n return 'L'; // Low\n default:\n return 'N'; // Normal\n }\n}\n\n/**\n * Convert Flag to FHIR interpretation display\n */\nfunction interpretationDisplay(flag: Flag): string {\n switch (flag) {\n case 'H':\n return 'High';\n case 'L':\n return 'Low';\n default:\n return 'Normal';\n }\n}\n\n/**\n * Convert generic lab observation to FHIR Observation\n */\nexport function labObservationToFHIR(\n observation: LabObservationData,\n patientId: string,\n laboratoryName?: string,\n): FHIRObservation {\n const loincCode = codeToLoinc(observation.biomarkerCode) || '99999-9';\n // Use default unit if source unit is empty\n const sourceUnit =\n observation.unit || getDefaultUnit(observation.biomarkerCode) || observation.unit;\n const ucumUnit = unitToUCUM(sourceUnit);\n const isQualitative = observation.isQualitative || typeof observation.value === 'string';\n\n // Base observation structure\n const fhirObs: FHIRObservation = {\n category: [\n {\n coding: [\n {\n code: 'laboratory',\n display: 'Laboratory',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: 'http://loinc.org',\n },\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: 'http://fhir-brasil.dev/biomarker-codes',\n },\n ],\n text: observation.biomarkerName,\n },\n effectiveDateTime: observation.collectionDate,\n id: `${observation.reportId}-${observation.biomarkerCode}`,\n interpretation: [\n {\n coding: [\n {\n code: interpretationCode(observation.flag),\n display: interpretationDisplay(observation.flag),\n system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation',\n },\n ],\n },\n ],\n performer: laboratoryName ? [{ display: laboratoryName }] : undefined,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n // Add value based on type (qualitative = string, quantitative = number)\n if (isQualitative) {\n fhirObs.valueString = String(observation.value);\n } else {\n fhirObs.valueQuantity = {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.value as number,\n };\n\n // Reference range only applies to quantitative values\n if (observation.referenceMin !== undefined && observation.referenceMax !== undefined) {\n fhirObs.referenceRange = [\n {\n high: {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.referenceMax,\n },\n low: {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.referenceMin,\n },\n },\n ];\n }\n }\n\n return fhirObs;\n}\n\n/**\n * Convert generic lab report to FHIR DiagnosticReport\n */\nexport function labReportToFHIR(\n report: LabReportData,\n patientId: string,\n observationIds: string[],\n): FHIRDiagnosticReport {\n // Map processing status to FHIR status\n let status: FHIRDiagnosticReport['status'];\n switch (report.processingStatus) {\n case 'complete':\n status = 'final';\n break;\n case 'partial':\n status = 'partial';\n break;\n case 'pending_review':\n status = 'preliminary';\n break;\n default:\n status = 'final';\n }\n\n return {\n category: [\n {\n coding: [\n {\n code: 'LAB',\n display: 'Laboratory',\n system: 'http://terminology.hl7.org/CodeSystem/v2-0074',\n },\n ],\n },\n ],\n code: {\n coding: [\n {\n code: '11502-2', // Laboratory report\n display: 'Laboratory report',\n system: 'http://loinc.org',\n },\n ],\n text: 'Laboratory Results',\n },\n conclusion:\n report.overallStatus === 'NORMAL'\n ? 'All results within normal limits'\n : 'One or more abnormal results detected',\n conclusionCode:\n report.overallStatus === 'ANORMAL'\n ? [\n {\n coding: [\n {\n code: 'A',\n display: 'Abnormal',\n system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation',\n },\n ],\n },\n ]\n : undefined,\n effectiveDateTime: report.collectionDate,\n id: report.reportId,\n issued: report.createdAt,\n performer: report.laboratoryName ? [{ display: report.laboratoryName }] : undefined,\n resourceType: 'DiagnosticReport',\n result: observationIds.map((id) => ({ reference: `Observation/${id}` })),\n status,\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n}\n\n/**\n * Convert user profile to FHIR Patient\n * NOTE: CPF is intentionally excluded for privacy (LGPD compliance)\n */\nexport function userProfileToFHIR(profile: UserProfileData): FHIRPatient {\n const nameParts = profile.name.split(' ');\n const given = nameParts.slice(0, -1);\n const family = nameParts[nameParts.length - 1] || '';\n\n return {\n address: profile.address\n ? [\n {\n city: profile.address.city,\n country: profile.address.country || 'BR',\n line: [\n profile.address.street && profile.address.number\n ? `${profile.address.street}, ${profile.address.number}`\n : profile.address.street,\n profile.address.complement,\n ].filter(Boolean) as string[],\n postalCode: profile.address.postalCode,\n state: profile.address.state,\n },\n ]\n : undefined,\n birthDate: profile.birthDate,\n gender: profile.gender,\n id: profile.userId,\n name: [\n {\n family,\n given: given.length > 0 ? given : undefined,\n text: profile.name,\n },\n ],\n resourceType: 'Patient',\n telecom:\n [\n ...(profile.email ? [{ system: 'email' as const, value: profile.email }] : []),\n ...(profile.phone ? [{ system: 'phone' as const, value: profile.phone }] : []),\n ].length > 0\n ? [\n ...(profile.email ? [{ system: 'email' as const, value: profile.email }] : []),\n ...(profile.phone ? [{ system: 'phone' as const, value: profile.phone }] : []),\n ]\n : undefined,\n };\n}\n\n/**\n * Convert complete lab result to FHIR Bundle\n * This is the main function for exporting lab results to FHIR R4 format\n */\nexport function labResultToFHIRBundle(\n report: LabReportData,\n observations: LabObservationData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n\n // Convert observations\n const fhirObservations = observations.map((obs) => ({\n fullUrl: `urn:uuid:observation-${obs.reportId}-${obs.biomarkerCode}`,\n resource: labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n ),\n }));\n\n const observationIds = observations.map(\n (obs) => `observation-${obs.reportId}-${obs.biomarkerCode}`,\n );\n\n // Convert report\n const diagnosticReport = labReportToFHIR(report, patientId, observationIds);\n\n // Convert patient\n const fhirPatient = userProfileToFHIR(userProfile);\n\n return {\n entry: [\n {\n fullUrl: `urn:uuid:${patientId}`,\n resource: fhirPatient,\n },\n {\n fullUrl: `urn:uuid:diagnostic-report-${report.reportId}`,\n resource: diagnosticReport,\n },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-CPZ7YNON.cjs","../src/converter.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACUA,SAAS,kBAAA,CAAmB,IAAA,EAAoB;AAC9C,EAAA,OAAA,CAAQ,IAAA,EAAM;AAAA,IACZ,KAAK,GAAA;AACH,MAAA,OAAO,GAAA;AAAA;AAAA,IACT,KAAK,GAAA;AACH,MAAA,OAAO,GAAA;AAAA;AAAA,IACT,OAAA;AACE,MAAA,OAAO,GAAA;AAAA,EACX;AACF;AAKA,SAAS,qBAAA,CAAsB,IAAA,EAAoB;AACjD,EAAA,OAAA,CAAQ,IAAA,EAAM;AAAA,IACZ,KAAK,GAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT,KAAK,GAAA;AACH,MAAA,OAAO,KAAA;AAAA,IACT,OAAA;AACE,MAAA,OAAO,QAAA;AAAA,EACX;AACF;AAKO,SAAS,oBAAA,CACd,WAAA,EACA,SAAA,EACA,cAAA,EACiB;AACjB,EAAA,MAAM,UAAA,EAAY,2CAAA,WAAY,CAAY,aAAa,EAAA,GAAK,SAAA;AAE5D,EAAA,MAAM,WAAA,EACJ,WAAA,CAAY,KAAA,GAAQ,8CAAA,WAAe,CAAY,aAAa,EAAA,GAAK,WAAA,CAAY,IAA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B;AAKR,EAAA;AAGA,EAAA;AACJ,IAAA;AACA,IAAA;AACI,MAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACA,EAAA;AAEI,EAAA;AACH,IAAA;AACH,EAAA;AAGM,EAAA;AAGA,EAAA;AAEC,EAAA;AACL,IAAA;AACE,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AACG,MAAA;AACL,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;ADxES;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-CPZ7YNON.cjs","sourcesContent":[null,"/**\n * FHIR Converter\n *\n * Converts lab results to FHIR R4 DiagnosticReport and Observation resources.\n * See: https://hl7.org/fhir/diagnosticreport.html\n */\n\nimport { codeToLoinc } from './biomarkers';\nimport type { FHIRBundle, FHIRDiagnosticReport, FHIRObservation, FHIRPatient } from './fhir-types';\nimport type { Flag, LabObservationData, LabReportData, UserProfileData } from './types';\nimport { getDefaultUnit, unitToUCUM } from './units';\n\n// Re-export all types and functions\nexport * from './fhir-types';\n\n/**\n * Convert Flag to FHIR interpretation code\n */\nfunction interpretationCode(flag: Flag): string {\n switch (flag) {\n case 'H':\n return 'H'; // High\n case 'L':\n return 'L'; // Low\n default:\n return 'N'; // Normal\n }\n}\n\n/**\n * Convert Flag to FHIR interpretation display\n */\nfunction interpretationDisplay(flag: Flag): string {\n switch (flag) {\n case 'H':\n return 'High';\n case 'L':\n return 'Low';\n default:\n return 'Normal';\n }\n}\n\n/**\n * Convert generic lab observation to FHIR Observation\n */\nexport function labObservationToFHIR(\n observation: LabObservationData,\n patientId: string,\n laboratoryName?: string,\n): FHIRObservation {\n const loincCode = codeToLoinc(observation.biomarkerCode) || '99999-9';\n // Use default unit if source unit is empty\n const sourceUnit =\n observation.unit || getDefaultUnit(observation.biomarkerCode) || observation.unit;\n const ucumUnit = unitToUCUM(sourceUnit);\n const isQualitative = observation.isQualitative || typeof observation.value === 'string';\n\n // Base observation structure\n const fhirObs: FHIRObservation = {\n category: [\n {\n coding: [\n {\n code: 'laboratory',\n display: 'Laboratory',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: 'http://loinc.org',\n },\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: 'http://fhir-brasil.dev/biomarker-codes',\n },\n ],\n text: observation.biomarkerName,\n },\n effectiveDateTime: observation.collectionDate,\n id: `${observation.reportId}-${observation.biomarkerCode}`,\n interpretation: [\n {\n coding: [\n {\n code: interpretationCode(observation.flag),\n display: interpretationDisplay(observation.flag),\n system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation',\n },\n ],\n },\n ],\n performer: laboratoryName ? [{ display: laboratoryName }] : undefined,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n // Add value based on type (qualitative = string, quantitative = number)\n if (isQualitative) {\n fhirObs.valueString = String(observation.value);\n } else {\n fhirObs.valueQuantity = {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.value as number,\n };\n\n // Reference range only applies to quantitative values\n if (observation.referenceMin !== undefined && observation.referenceMax !== undefined) {\n fhirObs.referenceRange = [\n {\n high: {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.referenceMax,\n },\n low: {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.referenceMin,\n },\n },\n ];\n }\n }\n\n return fhirObs;\n}\n\n/**\n * Convert generic lab report to FHIR DiagnosticReport\n */\nexport function labReportToFHIR(\n report: LabReportData,\n patientId: string,\n observationIds: string[],\n): FHIRDiagnosticReport {\n // Map processing status to FHIR status\n let status: FHIRDiagnosticReport['status'];\n switch (report.processingStatus) {\n case 'complete':\n status = 'final';\n break;\n case 'partial':\n status = 'partial';\n break;\n case 'pending_review':\n status = 'preliminary';\n break;\n default:\n status = 'final';\n }\n\n return {\n category: [\n {\n coding: [\n {\n code: 'LAB',\n display: 'Laboratory',\n system: 'http://terminology.hl7.org/CodeSystem/v2-0074',\n },\n ],\n },\n ],\n code: {\n coding: [\n {\n code: '11502-2', // Laboratory report\n display: 'Laboratory report',\n system: 'http://loinc.org',\n },\n ],\n text: 'Laboratory Results',\n },\n conclusion:\n report.overallStatus === 'NORMAL'\n ? 'All results within normal limits'\n : 'One or more abnormal results detected',\n conclusionCode:\n report.overallStatus === 'ANORMAL'\n ? [\n {\n coding: [\n {\n code: 'A',\n display: 'Abnormal',\n system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation',\n },\n ],\n },\n ]\n : undefined,\n effectiveDateTime: report.collectionDate,\n id: report.reportId,\n issued: report.createdAt,\n performer: report.laboratoryName ? [{ display: report.laboratoryName }] : undefined,\n resourceType: 'DiagnosticReport',\n result: observationIds.map((id) => ({ reference: `Observation/${id}` })),\n status,\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n}\n\n/**\n * Convert user profile to FHIR Patient\n * NOTE: CPF is intentionally excluded for privacy (LGPD compliance)\n */\nexport function userProfileToFHIR(profile: UserProfileData): FHIRPatient {\n const nameParts = profile.name.split(' ');\n const given = nameParts.slice(0, -1);\n const family = nameParts[nameParts.length - 1] || '';\n\n return {\n address: profile.address\n ? [\n {\n city: profile.address.city,\n country: profile.address.country || 'BR',\n line: [\n profile.address.street && profile.address.number\n ? `${profile.address.street}, ${profile.address.number}`\n : profile.address.street,\n profile.address.complement,\n ].filter(Boolean) as string[],\n postalCode: profile.address.postalCode,\n state: profile.address.state,\n },\n ]\n : undefined,\n birthDate: profile.birthDate,\n gender: profile.gender,\n id: profile.userId,\n name: [\n {\n family,\n given: given.length > 0 ? given : undefined,\n text: profile.name,\n },\n ],\n resourceType: 'Patient',\n telecom:\n [\n ...(profile.email ? [{ system: 'email' as const, value: profile.email }] : []),\n ...(profile.phone ? [{ system: 'phone' as const, value: profile.phone }] : []),\n ].length > 0\n ? [\n ...(profile.email ? [{ system: 'email' as const, value: profile.email }] : []),\n ...(profile.phone ? [{ system: 'phone' as const, value: profile.phone }] : []),\n ]\n : undefined,\n };\n}\n\n/**\n * Convert complete lab result to FHIR Bundle\n * This is the main function for exporting lab results to FHIR R4 format\n */\nexport function labResultToFHIRBundle(\n report: LabReportData,\n observations: LabObservationData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n\n // Convert observations\n const fhirObservations = observations.map((obs) => ({\n fullUrl: `urn:uuid:observation-${obs.reportId}-${obs.biomarkerCode}`,\n resource: labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n ),\n }));\n\n const observationIds = observations.map(\n (obs) => `observation-${obs.reportId}-${obs.biomarkerCode}`,\n );\n\n // Convert report\n const diagnosticReport = labReportToFHIR(report, patientId, observationIds);\n\n // Convert patient\n const fhirPatient = userProfileToFHIR(userProfile);\n\n return {\n entry: [\n {\n fullUrl: `urn:uuid:${patientId}`,\n resource: fhirPatient,\n },\n {\n fullUrl: `urn:uuid:diagnostic-report-${report.reportId}`,\n resource: diagnosticReport,\n },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkZYSD6A2Kcjs = require('./chunk-ZYSD6A2K.cjs');
|
|
4
4
|
|
|
5
5
|
// src/reference-ranges.ts
|
|
6
6
|
var biomarkerRangeDefinitions = {
|
|
@@ -1636,7 +1636,7 @@ function applyFallbackReferenceRanges(biomarkers) {
|
|
|
1636
1636
|
}
|
|
1637
1637
|
const fallback = getFallbackReferenceRange(biomarker.code);
|
|
1638
1638
|
if (fallback) {
|
|
1639
|
-
const canonicalUnit =
|
|
1639
|
+
const canonicalUnit = _chunkZYSD6A2Kcjs.getCanonicalUnit.call(void 0, biomarker.code);
|
|
1640
1640
|
const unitsMatch = !biomarker.unit || biomarker.unit.toLowerCase() === fallback.unit.toLowerCase() || canonicalUnit && biomarker.unit.toLowerCase() === canonicalUnit.toLowerCase() || // Handle common unit variations
|
|
1641
1641
|
biomarker.unit === "%" && fallback.unit === "%";
|
|
1642
1642
|
if (unitsMatch) {
|
|
@@ -1661,4 +1661,4 @@ function applyFallbackReferenceRanges(biomarkers) {
|
|
|
1661
1661
|
|
|
1662
1662
|
|
|
1663
1663
|
exports.biomarkerRangeDefinitions = biomarkerRangeDefinitions; exports.defaultReferenceRanges = defaultReferenceRanges; exports.getReferenceRange = getReferenceRange; exports.getRangeDirection = getRangeDirection; exports.getFallbackReferenceRange = getFallbackReferenceRange; exports.applyFallbackReferenceRanges = applyFallbackReferenceRanges;
|
|
1664
|
-
//# sourceMappingURL=chunk-
|
|
1664
|
+
//# sourceMappingURL=chunk-LYDCZW4C.cjs.map
|