@precisa-saude/fhir 0.22.3 → 0.24.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/dist/{chunk-RZPFCPLH.js → chunk-NKA4JGNI.js} +2 -1
- package/dist/chunk-NKA4JGNI.js.map +1 -0
- package/dist/{chunk-MZ36NSTX.cjs → chunk-RSKFZ5UB.cjs} +3 -2
- package/dist/chunk-RSKFZ5UB.cjs.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/{converter-Bp3ZhyUQ.d.cts → converter-CO7q_s52.d.cts} +28 -3
- package/dist/{converter-BciZxRkK.d.ts → converter-x5Gcw-03.d.ts} +28 -3
- package/dist/converter.cjs +2 -2
- package/dist/converter.d.cts +2 -2
- package/dist/converter.d.ts +2 -2
- package/dist/converter.js +1 -1
- package/dist/{fhir-types-jTJayiwn.d.cts → fhir-types-Bmvac6o0.d.cts} +1 -1
- package/dist/{fhir-types-jTJayiwn.d.ts → fhir-types-Bmvac6o0.d.ts} +1 -1
- package/dist/importer.d.cts +1 -1
- package/dist/importer.d.ts +1 -1
- package/dist/index.cjs +32 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -5
- package/dist/index.d.ts +46 -5
- package/dist/index.js +28 -1
- package/dist/index.js.map +1 -1
- package/dist/validators.d.cts +1 -1
- package/dist/validators.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-MZ36NSTX.cjs.map +0 -1
- package/dist/chunk-RZPFCPLH.js.map +0 -1
|
@@ -250,10 +250,11 @@ function labResultToFHIRBundle(report, observations, userProfile) {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
export {
|
|
253
|
+
BUNDLE_BASE_URL,
|
|
253
254
|
entryFullUrl,
|
|
254
255
|
labObservationToFHIR,
|
|
255
256
|
labReportToFHIR,
|
|
256
257
|
userProfileToFHIR,
|
|
257
258
|
labResultToFHIRBundle
|
|
258
259
|
};
|
|
259
|
-
//# sourceMappingURL=chunk-
|
|
260
|
+
//# sourceMappingURL=chunk-NKA4JGNI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bundle-urls.ts","../src/converter.ts"],"sourcesContent":["/**\n * Endereço das entradas de um Bundle.\n *\n * O `fullUrl` identifica a entrada, e é contra ele que o validador resolve as\n * referências entre os recursos. Um Bundle com `subject.reference` valendo\n * `Patient/abc` só resolve se alguma entrada tiver `fullUrl` terminando em\n * `/Patient/abc`: a referência relativa é lida contra a base do `fullUrl` da\n * entrada, que é como os exemplos da própria HL7 montam Bundle de coleção.\n *\n * Antes o `fullUrl` era `urn:uuid:observation-<laudo>-<código>`, que erra duas\n * vezes. `urn:uuid:` exige a sintaxe de UUID e aquilo não era um UUID, e num\n * Bundle de entradas `urn:uuid:` a referência precisa repetir a URN inteira,\n * então nenhuma das relativas resolvia. Um laudo de 22 marcadores saía com 24\n * erros de URN e 22 referências perdidas.\n */\n/**\n * Recurso que já tem id, e por isso pode ser endereçado numa entrada.\n *\n * No FHIR o `id` é opcional, porque um recurso pode viajar sem identidade\n * própria. Numa entrada de Bundle ele não pode: sem id não há `fullUrl`, e sem\n * `fullUrl` nenhuma referência chega ao recurso. Os conversores daqui sempre\n * atribuem um, e o tipo passa a dizer isso em vez de deixar `undefined` chegar\n * até a montagem da URL.\n */\nexport type Addressable<T> = T & { id: string };\n\n/**\n * Base dos `fullUrl`.\n *\n * Não precisa responder a uma requisição: no FHIR o `fullUrl` é identidade, não\n * endereço de download. Fica sob um domínio nosso para não colidir com a\n * identidade de recurso de outra instituição, que é o risco real de usar\n * `example.org` em dado que sai da máquina.\n */\nexport const BUNDLE_BASE_URL = 'https://precisa-saude.com.br/fhir';\n\n/**\n * Monta o `fullUrl` a partir do próprio recurso.\n *\n * Recebe o recurso em vez do tipo e do id soltos de propósito. O defeito que\n * isto substitui nasceu de montar os dois lados em separado: o `fullUrl` dizia\n * `observation-demo-Hgb` enquanto o recurso tinha id `demo-Hgb`, e ninguém\n * percebeu porque nada obrigava os dois a concordarem.\n *\n * O parâmetro pede o mínimo que a URL consome, e não a união de recursos que\n * este pacote converte. Um Bundle pode carregar qualquer recurso do R4, e quem\n * acrescenta uma entrada de um tipo que não está nessa união (um `Specimen`,\n * por exemplo) precisa do mesmo endereço, senão monta o dele e as duas formas\n * divergem outra vez.\n */\nexport const entryFullUrl = (resource: Addressable<{ resourceType: string }>): string =>\n `${BUNDLE_BASE_URL}/${resource.resourceType}/${resource.id}`;\n","/**\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 Addressable, entryFullUrl } from './bundle-urls';\nimport { BIOMARKER_CODE_SYSTEM, LOINC_SYSTEM } from './code-systems';\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): Addressable<FHIRObservation> {\n const loincCode = codeToLoinc(observation.biomarkerCode);\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: Addressable<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 // Sem LOINC, o coding LOINC simplesmente não sai. Antes ia `99999-9`,\n // que não é código LOINC nenhum: publicava sob `http://loinc.org` uma\n // afirmação falsa, e quem consumisse o bundle confiando no system\n // trataria aquilo como código de verdade. Composição corporal, densidade\n // óssea e escore de cálcio não têm LOINC, e o certo é a lacuna explícita.\n coding: [\n ...(loincCode\n ? [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: LOINC_SYSTEM,\n },\n ]\n : []),\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: BIOMARKER_CODE_SYSTEM,\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): Addressable<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): Addressable<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 const resource = labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n );\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n // Os ids vêm dos recursos já montados, e não de uma segunda montagem da mesma\n // regra. O `DiagnosticReport.result` aponta para eles, e era aqui que a\n // referência se separava do recurso.\n const observationIds = fhirObservations.map((entry) => entry.resource.id);\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 { fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient },\n { fullUrl: entryFullUrl(diagnosticReport), resource: diagnosticReport },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAkCO,IAAM,kBAAkB;AAgBxB,IAAM,eAAe,CAAC,aAC3B,GAAG,eAAe,IAAI,SAAS,YAAY,IAAI,SAAS,EAAE;;;AC/B5D,SAAS,mBAAmB,MAAoB;AAC9C,UAAQ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d,MAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -255,5 +255,6 @@ function labResultToFHIRBundle(report, observations, userProfile) {
|
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
|
|
259
|
+
exports.BUNDLE_BASE_URL = BUNDLE_BASE_URL; exports.entryFullUrl = entryFullUrl; exports.labObservationToFHIR = labObservationToFHIR; exports.labReportToFHIR = labReportToFHIR; exports.userProfileToFHIR = userProfileToFHIR; exports.labResultToFHIRBundle = labResultToFHIRBundle;
|
|
260
|
+
//# sourceMappingURL=chunk-RSKFZ5UB.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-RSKFZ5UB.cjs","../src/bundle-urls.ts","../src/converter.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACsBO,IAAM,gBAAA,EAAkB,mCAAA;AAgBxB,IAAM,aAAA,EAAe,CAAC,QAAA,EAAA,GAC3B,CAAA,EAAA;ADpCgC;AACA;AEIc;AAChC,EAAA;AACP,IAAA;AACI,MAAA;AAAA;AACJ,IAAA;AACI,MAAA;AAAA;AACT,IAAA;AACS,MAAA;AACX,EAAA;AACF;AAK+B;AACf,EAAA;AACP,IAAA;AACI,MAAA;AACJ,IAAA;AACI,MAAA;AACT,IAAA;AACS,MAAA;AACX,EAAA;AACF;AAME;AAI8B,EAAA;AAGhB,EAAA;AACc,EAAA;AACN,EAAA;AAGwB,EAAA;AAClC,IAAA;AACR,MAAA;AACU,QAAA;AACN,UAAA;AACQ,YAAA;AACG,YAAA;AACD,YAAA;AACV,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AACM,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMI,MAAA;AAEF,QAAA;AACE,UAAA;A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EF,IAAA;AACoB,IAAA;AACf,IAAA;AACI,IAAA;AACG,IAAA;AACJ,IAAA;AACc,IAAA;AAC5B,IAAA;AACS,IAAA;AACe,MAAA;AACxB,IAAA;AACF,EAAA;AACF;AAMkC;AACD,EAAA;AACD,EAAA;AACL,EAAA;AAElB,EAAA;AAED,IAAA;AACE,MAAA;AACwB,QAAA;AACG,QAAA;AACnB,QAAA;AACY,UAAA;AAGA,UAAA;AACF,QAAA;AACI,QAAA;AACG,QAAA;AACzB,MAAA;AAEF,IAAA;AACe,IAAA;AACH,IAAA;AACJ,IAAA;AACN,IAAA;AACJ,MAAA;AACE,QAAA;AAC0B,QAAA;AACZ,QAAA;AAChB,MAAA;AACF,IAAA;AACc,IAAA;AAEZ,IAAA;AACyB,MAAA;AACA,MAAA;AAErB,IAAA;AACyB,MAAA;AACA,MAAA;AAEzB,IAAA;AACR,EAAA;AACF;AAOE;AAI8B,EAAA;AAGL,EAAA;AACN,IAAA;AACW,MAAA;AAC1B,MAAA;AACO,MAAA;AACT,IAAA;AAEkB,IAAA;AACnB,EAAA;AAKsB,EAAA;AAGE,EAAA;AAGL,EAAA;AAEb,EAAA;AACE,IAAA;AACmB,MAAA;AACA,MAAA;AACrB,MAAA;AACL,IAAA;AACc,IAAA;AACR,IAAA;AACR,EAAA;AACF;AFxEkC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-RSKFZ5UB.cjs","sourcesContent":[null,"/**\n * Endereço das entradas de um Bundle.\n *\n * O `fullUrl` identifica a entrada, e é contra ele que o validador resolve as\n * referências entre os recursos. Um Bundle com `subject.reference` valendo\n * `Patient/abc` só resolve se alguma entrada tiver `fullUrl` terminando em\n * `/Patient/abc`: a referência relativa é lida contra a base do `fullUrl` da\n * entrada, que é como os exemplos da própria HL7 montam Bundle de coleção.\n *\n * Antes o `fullUrl` era `urn:uuid:observation-<laudo>-<código>`, que erra duas\n * vezes. `urn:uuid:` exige a sintaxe de UUID e aquilo não era um UUID, e num\n * Bundle de entradas `urn:uuid:` a referência precisa repetir a URN inteira,\n * então nenhuma das relativas resolvia. Um laudo de 22 marcadores saía com 24\n * erros de URN e 22 referências perdidas.\n */\n/**\n * Recurso que já tem id, e por isso pode ser endereçado numa entrada.\n *\n * No FHIR o `id` é opcional, porque um recurso pode viajar sem identidade\n * própria. Numa entrada de Bundle ele não pode: sem id não há `fullUrl`, e sem\n * `fullUrl` nenhuma referência chega ao recurso. Os conversores daqui sempre\n * atribuem um, e o tipo passa a dizer isso em vez de deixar `undefined` chegar\n * até a montagem da URL.\n */\nexport type Addressable<T> = T & { id: string };\n\n/**\n * Base dos `fullUrl`.\n *\n * Não precisa responder a uma requisição: no FHIR o `fullUrl` é identidade, não\n * endereço de download. Fica sob um domínio nosso para não colidir com a\n * identidade de recurso de outra instituição, que é o risco real de usar\n * `example.org` em dado que sai da máquina.\n */\nexport const BUNDLE_BASE_URL = 'https://precisa-saude.com.br/fhir';\n\n/**\n * Monta o `fullUrl` a partir do próprio recurso.\n *\n * Recebe o recurso em vez do tipo e do id soltos de propósito. O defeito que\n * isto substitui nasceu de montar os dois lados em separado: o `fullUrl` dizia\n * `observation-demo-Hgb` enquanto o recurso tinha id `demo-Hgb`, e ninguém\n * percebeu porque nada obrigava os dois a concordarem.\n *\n * O parâmetro pede o mínimo que a URL consome, e não a união de recursos que\n * este pacote converte. Um Bundle pode carregar qualquer recurso do R4, e quem\n * acrescenta uma entrada de um tipo que não está nessa união (um `Specimen`,\n * por exemplo) precisa do mesmo endereço, senão monta o dele e as duas formas\n * divergem outra vez.\n */\nexport const entryFullUrl = (resource: Addressable<{ resourceType: string }>): string =>\n `${BUNDLE_BASE_URL}/${resource.resourceType}/${resource.id}`;\n","/**\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 Addressable, entryFullUrl } from './bundle-urls';\nimport { BIOMARKER_CODE_SYSTEM, LOINC_SYSTEM } from './code-systems';\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): Addressable<FHIRObservation> {\n const loincCode = codeToLoinc(observation.biomarkerCode);\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: Addressable<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 // Sem LOINC, o coding LOINC simplesmente não sai. Antes ia `99999-9`,\n // que não é código LOINC nenhum: publicava sob `http://loinc.org` uma\n // afirmação falsa, e quem consumisse o bundle confiando no system\n // trataria aquilo como código de verdade. Composição corporal, densidade\n // óssea e escore de cálcio não têm LOINC, e o certo é a lacuna explícita.\n coding: [\n ...(loincCode\n ? [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: LOINC_SYSTEM,\n },\n ]\n : []),\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: BIOMARKER_CODE_SYSTEM,\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): Addressable<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): Addressable<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 const resource = labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n );\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n // Os ids vêm dos recursos já montados, e não de uma segunda montagem da mesma\n // regra. O `DiagnosticReport.result` aponta para eles, e era aqui que a\n // referência se separava do recurso.\n const observationIds = fhirObservations.map((entry) => entry.resource.id);\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 { fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient },\n { fullUrl: entryFullUrl(diagnosticReport), resource: diagnosticReport },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"]}
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as FHIRPatient } from './fhir-types-
|
|
1
|
+
import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as FHIRPatient } from './fhir-types-Bmvac6o0.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Endereço das entradas de um Bundle.
|
|
@@ -15,7 +15,6 @@ import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as
|
|
|
15
15
|
* então nenhuma das relativas resolvia. Um laudo de 22 marcadores saía com 24
|
|
16
16
|
* erros de URN e 22 referências perdidas.
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* Recurso que já tem id, e por isso pode ser endereçado numa entrada.
|
|
21
20
|
*
|
|
@@ -28,6 +27,32 @@ import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as
|
|
|
28
27
|
type Addressable<T> = T & {
|
|
29
28
|
id: string;
|
|
30
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Base dos `fullUrl`.
|
|
32
|
+
*
|
|
33
|
+
* Não precisa responder a uma requisição: no FHIR o `fullUrl` é identidade, não
|
|
34
|
+
* endereço de download. Fica sob um domínio nosso para não colidir com a
|
|
35
|
+
* identidade de recurso de outra instituição, que é o risco real de usar
|
|
36
|
+
* `example.org` em dado que sai da máquina.
|
|
37
|
+
*/
|
|
38
|
+
declare const BUNDLE_BASE_URL = "https://precisa-saude.com.br/fhir";
|
|
39
|
+
/**
|
|
40
|
+
* Monta o `fullUrl` a partir do próprio recurso.
|
|
41
|
+
*
|
|
42
|
+
* Recebe o recurso em vez do tipo e do id soltos de propósito. O defeito que
|
|
43
|
+
* isto substitui nasceu de montar os dois lados em separado: o `fullUrl` dizia
|
|
44
|
+
* `observation-demo-Hgb` enquanto o recurso tinha id `demo-Hgb`, e ninguém
|
|
45
|
+
* percebeu porque nada obrigava os dois a concordarem.
|
|
46
|
+
*
|
|
47
|
+
* O parâmetro pede o mínimo que a URL consome, e não a união de recursos que
|
|
48
|
+
* este pacote converte. Um Bundle pode carregar qualquer recurso do R4, e quem
|
|
49
|
+
* acrescenta uma entrada de um tipo que não está nessa união (um `Specimen`,
|
|
50
|
+
* por exemplo) precisa do mesmo endereço, senão monta o dele e as duas formas
|
|
51
|
+
* divergem outra vez.
|
|
52
|
+
*/
|
|
53
|
+
declare const entryFullUrl: (resource: Addressable<{
|
|
54
|
+
resourceType: string;
|
|
55
|
+
}>) => string;
|
|
31
56
|
|
|
32
57
|
/**
|
|
33
58
|
* Generic Lab Result Types
|
|
@@ -125,4 +150,4 @@ declare function userProfileToFHIR(profile: UserProfileData): Addressable<FHIRPa
|
|
|
125
150
|
*/
|
|
126
151
|
declare function labResultToFHIRBundle(report: LabReportData, observations: LabObservationData[], userProfile: UserProfileData): FHIRBundle;
|
|
127
152
|
|
|
128
|
-
export { type Addressable as A, type Flag as F, type Gender as G, type InterventionData as I, type LabObservationData as L, type OverallStatus as O, type UserProfileData as U, type LabReportData as a, labReportToFHIR as b, labResultToFHIRBundle as c, labObservationToFHIR as l, userProfileToFHIR as u };
|
|
153
|
+
export { type Addressable as A, BUNDLE_BASE_URL as B, type Flag as F, type Gender as G, type InterventionData as I, type LabObservationData as L, type OverallStatus as O, type UserProfileData as U, type LabReportData as a, labReportToFHIR as b, labResultToFHIRBundle as c, entryFullUrl as e, labObservationToFHIR as l, userProfileToFHIR as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as FHIRPatient } from './fhir-types-
|
|
1
|
+
import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as FHIRPatient } from './fhir-types-Bmvac6o0.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Endereço das entradas de um Bundle.
|
|
@@ -15,7 +15,6 @@ import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as
|
|
|
15
15
|
* então nenhuma das relativas resolvia. Um laudo de 22 marcadores saía com 24
|
|
16
16
|
* erros de URN e 22 referências perdidas.
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* Recurso que já tem id, e por isso pode ser endereçado numa entrada.
|
|
21
20
|
*
|
|
@@ -28,6 +27,32 @@ import { a as FHIRObservation, k as FHIRDiagnosticReport, b as FHIRBundle, m as
|
|
|
28
27
|
type Addressable<T> = T & {
|
|
29
28
|
id: string;
|
|
30
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Base dos `fullUrl`.
|
|
32
|
+
*
|
|
33
|
+
* Não precisa responder a uma requisição: no FHIR o `fullUrl` é identidade, não
|
|
34
|
+
* endereço de download. Fica sob um domínio nosso para não colidir com a
|
|
35
|
+
* identidade de recurso de outra instituição, que é o risco real de usar
|
|
36
|
+
* `example.org` em dado que sai da máquina.
|
|
37
|
+
*/
|
|
38
|
+
declare const BUNDLE_BASE_URL = "https://precisa-saude.com.br/fhir";
|
|
39
|
+
/**
|
|
40
|
+
* Monta o `fullUrl` a partir do próprio recurso.
|
|
41
|
+
*
|
|
42
|
+
* Recebe o recurso em vez do tipo e do id soltos de propósito. O defeito que
|
|
43
|
+
* isto substitui nasceu de montar os dois lados em separado: o `fullUrl` dizia
|
|
44
|
+
* `observation-demo-Hgb` enquanto o recurso tinha id `demo-Hgb`, e ninguém
|
|
45
|
+
* percebeu porque nada obrigava os dois a concordarem.
|
|
46
|
+
*
|
|
47
|
+
* O parâmetro pede o mínimo que a URL consome, e não a união de recursos que
|
|
48
|
+
* este pacote converte. Um Bundle pode carregar qualquer recurso do R4, e quem
|
|
49
|
+
* acrescenta uma entrada de um tipo que não está nessa união (um `Specimen`,
|
|
50
|
+
* por exemplo) precisa do mesmo endereço, senão monta o dele e as duas formas
|
|
51
|
+
* divergem outra vez.
|
|
52
|
+
*/
|
|
53
|
+
declare const entryFullUrl: (resource: Addressable<{
|
|
54
|
+
resourceType: string;
|
|
55
|
+
}>) => string;
|
|
31
56
|
|
|
32
57
|
/**
|
|
33
58
|
* Generic Lab Result Types
|
|
@@ -125,4 +150,4 @@ declare function userProfileToFHIR(profile: UserProfileData): Addressable<FHIRPa
|
|
|
125
150
|
*/
|
|
126
151
|
declare function labResultToFHIRBundle(report: LabReportData, observations: LabObservationData[], userProfile: UserProfileData): FHIRBundle;
|
|
127
152
|
|
|
128
|
-
export { type Addressable as A, type Flag as F, type Gender as G, type InterventionData as I, type LabObservationData as L, type OverallStatus as O, type UserProfileData as U, type LabReportData as a, labReportToFHIR as b, labResultToFHIRBundle as c, labObservationToFHIR as l, userProfileToFHIR as u };
|
|
153
|
+
export { type Addressable as A, BUNDLE_BASE_URL as B, type Flag as F, type Gender as G, type InterventionData as I, type LabObservationData as L, type OverallStatus as O, type UserProfileData as U, type LabReportData as a, labReportToFHIR as b, labResultToFHIRBundle as c, entryFullUrl as e, labObservationToFHIR as l, userProfileToFHIR as u };
|
package/dist/converter.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkRSKFZ5UBcjs = require('./chunk-RSKFZ5UB.cjs');
|
|
7
7
|
require('./chunk-OR67NJDZ.cjs');
|
|
8
8
|
require('./chunk-AM2RCUUJ.cjs');
|
|
9
9
|
require('./chunk-MJ254F5K.cjs');
|
|
@@ -12,5 +12,5 @@ require('./chunk-MJ254F5K.cjs');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
exports.labObservationToFHIR =
|
|
15
|
+
exports.labObservationToFHIR = _chunkRSKFZ5UBcjs.labObservationToFHIR; exports.labReportToFHIR = _chunkRSKFZ5UBcjs.labReportToFHIR; exports.labResultToFHIRBundle = _chunkRSKFZ5UBcjs.labResultToFHIRBundle; exports.userProfileToFHIR = _chunkRSKFZ5UBcjs.userProfileToFHIR;
|
|
16
16
|
//# sourceMappingURL=converter.cjs.map
|
package/dist/converter.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-
|
|
2
|
-
export {
|
|
1
|
+
export { l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-CO7q_s52.cjs';
|
|
2
|
+
export { e as FHIRAddress, f as FHIRAnnotation, g as FHIRAttachment, b as FHIRBundle, h as FHIRBundleEntry, i as FHIRCodeableConcept, d as FHIRCoding, j as FHIRContactPoint, k as FHIRDiagnosticReport, l as FHIRHumanName, c as FHIRIdentifier, F as FHIRMedicationStatement, a as FHIRObservation, m as FHIRPatient, n as FHIRPeriod, o as FHIRQuantity, p as FHIRReference, q as FHIRReferenceRange } from './fhir-types-Bmvac6o0.cjs';
|
package/dist/converter.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-
|
|
2
|
-
export {
|
|
1
|
+
export { l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-x5Gcw-03.js';
|
|
2
|
+
export { e as FHIRAddress, f as FHIRAnnotation, g as FHIRAttachment, b as FHIRBundle, h as FHIRBundleEntry, i as FHIRCodeableConcept, d as FHIRCoding, j as FHIRContactPoint, k as FHIRDiagnosticReport, l as FHIRHumanName, c as FHIRIdentifier, F as FHIRMedicationStatement, a as FHIRObservation, m as FHIRPatient, n as FHIRPeriod, o as FHIRQuantity, p as FHIRReference, q as FHIRReferenceRange } from './fhir-types-Bmvac6o0.js';
|
package/dist/converter.js
CHANGED
|
@@ -133,4 +133,4 @@ interface FHIRBundleEntry {
|
|
|
133
133
|
resource: FHIRPatient | FHIRDiagnosticReport | FHIRObservation | FHIRMedicationStatement;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
export type { FHIRMedicationStatement as F, FHIRObservation as a, FHIRBundle as b, FHIRIdentifier as c,
|
|
136
|
+
export type { FHIRMedicationStatement as F, FHIRObservation as a, FHIRBundle as b, FHIRIdentifier as c, FHIRCoding as d, FHIRAddress as e, FHIRAnnotation as f, FHIRAttachment as g, FHIRBundleEntry as h, FHIRCodeableConcept as i, FHIRContactPoint as j, FHIRDiagnosticReport as k, FHIRHumanName as l, FHIRPatient as m, FHIRPeriod as n, FHIRQuantity as o, FHIRReference as p, FHIRReferenceRange as q };
|
|
@@ -133,4 +133,4 @@ interface FHIRBundleEntry {
|
|
|
133
133
|
resource: FHIRPatient | FHIRDiagnosticReport | FHIRObservation | FHIRMedicationStatement;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
export type { FHIRMedicationStatement as F, FHIRObservation as a, FHIRBundle as b, FHIRIdentifier as c,
|
|
136
|
+
export type { FHIRMedicationStatement as F, FHIRObservation as a, FHIRBundle as b, FHIRIdentifier as c, FHIRCoding as d, FHIRAddress as e, FHIRAnnotation as f, FHIRAttachment as g, FHIRBundleEntry as h, FHIRCodeableConcept as i, FHIRContactPoint as j, FHIRDiagnosticReport as k, FHIRHumanName as l, FHIRPatient as m, FHIRPeriod as n, FHIRQuantity as o, FHIRReference as p, FHIRReferenceRange as q };
|
package/dist/importer.d.cts
CHANGED
package/dist/importer.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
var _chunkRSKFZ5UBcjs = require('./chunk-RSKFZ5UB.cjs');
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -233,14 +234,14 @@ function interventionToFHIRObservation(intervention, patientId) {
|
|
|
233
234
|
}
|
|
234
235
|
function interventionsToFHIRBundle(interventions, userProfile) {
|
|
235
236
|
const patientId = userProfile.userId;
|
|
236
|
-
const fhirPatient =
|
|
237
|
+
const fhirPatient = _chunkRSKFZ5UBcjs.userProfileToFHIR.call(void 0, userProfile);
|
|
237
238
|
const entries = interventions.map((intervention) => {
|
|
238
239
|
const isMedication = intervention.type === "medication" || intervention.type === "supplement";
|
|
239
240
|
const resource = isMedication ? interventionToFHIRMedicationStatement(intervention, patientId) : interventionToFHIRObservation(intervention, patientId);
|
|
240
|
-
return { fullUrl:
|
|
241
|
+
return { fullUrl: _chunkRSKFZ5UBcjs.entryFullUrl.call(void 0, resource), resource };
|
|
241
242
|
});
|
|
242
243
|
return {
|
|
243
|
-
entry: [{ fullUrl:
|
|
244
|
+
entry: [{ fullUrl: _chunkRSKFZ5UBcjs.entryFullUrl.call(void 0, fhirPatient), resource: fhirPatient }, ...entries],
|
|
244
245
|
resourceType: "Bundle",
|
|
245
246
|
type: "collection"
|
|
246
247
|
};
|
|
@@ -603,6 +604,32 @@ function cnsToFHIRIdentifier(cns) {
|
|
|
603
604
|
};
|
|
604
605
|
}
|
|
605
606
|
|
|
607
|
+
// src/specimen-types.ts
|
|
608
|
+
var BR_TIPO_AMOSTRA_VALUESET = "https://rnds-fhir.saude.gov.br/ValueSet/BRTipoAmostra-1.0";
|
|
609
|
+
var HL7_SPECIMEN_TYPE_SYSTEM = "http://terminology.hl7.org/CodeSystem/v2-0487";
|
|
610
|
+
var CODINGS = [
|
|
611
|
+
{ code: "SER", display: "Soro" },
|
|
612
|
+
{ code: "PLAS", display: "Plasma" },
|
|
613
|
+
{ code: "WB", display: "Sangue Total" },
|
|
614
|
+
{ code: "UR", display: "Urina" },
|
|
615
|
+
{ code: "CSF", display: "L\xEDquor" },
|
|
616
|
+
{ code: "SAL", display: "Saliva" }
|
|
617
|
+
];
|
|
618
|
+
var INVISIBLE = /\p{Cf}/gu;
|
|
619
|
+
var normalize = (text) => text.replace(INVISIBLE, "").normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
620
|
+
var BY_NORMALIZED_TEXT = new Map(
|
|
621
|
+
CODINGS.map(({ code, display }) => [
|
|
622
|
+
normalize(display),
|
|
623
|
+
{ code, display, system: HL7_SPECIMEN_TYPE_SYSTEM }
|
|
624
|
+
])
|
|
625
|
+
);
|
|
626
|
+
var specimenTypeCoding = (text) => BY_NORMALIZED_TEXT.get(normalize(text));
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
606
633
|
|
|
607
634
|
|
|
608
635
|
|
|
@@ -689,5 +716,5 @@ function cnsToFHIRIdentifier(cns) {
|
|
|
689
716
|
|
|
690
717
|
|
|
691
718
|
|
|
692
|
-
exports.AGE_BRACKETS = AGE_BRACKETS; exports.BIOMARKER_CODE_SYSTEM = _chunkOR67NJDZcjs.BIOMARKER_CODE_SYSTEM; exports.BIOMARKER_DEFAULT_UNIT = _chunkMJ254F5Kcjs.BIOMARKER_DEFAULT_UNIT; exports.BIOMARKER_DEFINITIONS = _chunkAM2RCUUJcjs.BIOMARKER_DEFINITIONS; exports.BIOMARKER_UNITS = _chunkMJ254F5Kcjs.BIOMARKER_UNITS; exports.BODY_FAT_ZONES = BODY_FAT_ZONES; exports.CAC_INDICATOR_CODES = _chunkAM2RCUUJcjs.CAC_INDICATOR_CODES; exports.CATEGORY_GROUPS = CATEGORY_GROUPS; exports.CATEGORY_SCREENING_INTERVALS = CATEGORY_SCREENING_INTERVALS; exports.DEXA_CATEGORIES = _chunkAM2RCUUJcjs.DEXA_CATEGORIES; exports.DEXA_INDICATOR_CODES = _chunkAM2RCUUJcjs.DEXA_INDICATOR_CODES; exports.LOINC_SYSTEM = _chunkOR67NJDZcjs.LOINC_SYSTEM; exports.MAX_FILE_SIZE = _chunkHV77ZKP6cjs.MAX_FILE_SIZE; exports.MAX_OBSERVATIONS = _chunkHV77ZKP6cjs.MAX_OBSERVATIONS; exports.T_SCORE_ZONES = T_SCORE_ZONES; exports.UNIT_TO_UCUM = _chunkMJ254F5Kcjs.UNIT_TO_UCUM; exports.ZONE_DEFS = ZONE_DEFS; exports.applyFallbackReferenceRanges = _chunkERALICUKcjs.applyFallbackReferenceRanges; exports.biomarkerRangeDefinitions = _chunkERALICUKcjs.biomarkerRangeDefinitions; exports.calculateNextScreeningDate = calculateNextScreeningDate; exports.cnsToFHIRIdentifier = cnsToFHIRIdentifier; exports.codeToLoinc = _chunkAM2RCUUJcjs.codeToLoinc; exports.convertUnit = _chunkMJ254F5Kcjs.convertUnit; exports.cpfToFHIRIdentifier = cpfToFHIRIdentifier; exports.defaultReferenceRanges = _chunkERALICUKcjs.defaultReferenceRanges; exports.extractObservationsFromBundle = _chunkHV77ZKP6cjs.extractObservationsFromBundle; exports.filterVisibleBiomarkers = _chunkAM2RCUUJcjs.filterVisibleBiomarkers; exports.findCodeByName = _chunkAM2RCUUJcjs.findCodeByName; exports.formatCNS = formatCNS; exports.formatCPF = formatCPF; exports.generateCacFullReference = _chunkAM2RCUUJcjs.generateCacFullReference; exports.generateDexaFullReference = _chunkAM2RCUUJcjs.generateDexaFullReference; exports.generateFilteredLLMReference = _chunkAM2RCUUJcjs.generateFilteredLLMReference; exports.generateLLMReference = _chunkAM2RCUUJcjs.generateLLMReference; exports.getAllCodes = _chunkAM2RCUUJcjs.getAllCodes; exports.getAllDefinitions = _chunkAM2RCUUJcjs.getAllDefinitions; exports.getAllLoincCodes = _chunkAM2RCUUJcjs.getAllLoincCodes; exports.getAllSearchPatterns = _chunkAM2RCUUJcjs.getAllSearchPatterns; exports.getBiomarkersByCategory = _chunkAM2RCUUJcjs.getBiomarkersByCategory; exports.getBiomarkersForCategories = _chunkAM2RCUUJcjs.getBiomarkersForCategories; exports.getCanonicalUnit = _chunkMJ254F5Kcjs.getCanonicalUnit; exports.getCategoriesByInterval = getCategoriesByInterval; exports.getCategoryGroup = getCategoryGroup; exports.getDaysUntilScreening = getDaysUntilScreening; exports.getDefaultUnit = _chunkMJ254F5Kcjs.getDefaultUnit; exports.getDefinitionByCode = _chunkAM2RCUUJcjs.getDefinitionByCode; exports.getDefinitionByLoinc = _chunkAM2RCUUJcjs.getDefinitionByLoinc; exports.getDefinitionsBySex = _chunkAM2RCUUJcjs.getDefinitionsBySex; exports.getDueCategories = getDueCategories; exports.getFallbackReferenceRange = _chunkERALICUKcjs.getFallbackReferenceRange; exports.getRangeDirection = _chunkERALICUKcjs.getRangeDirection; exports.getReferenceRange = _chunkERALICUKcjs.getReferenceRange; exports.getSIUnit = _chunkMJ254F5Kcjs.getSIUnit; exports.getScreeningInterval = getScreeningInterval; exports.getSexForCode = _chunkAM2RCUUJcjs.getSexForCode; exports.getVisibleDefinitions = _chunkAM2RCUUJcjs.getVisibleDefinitions; exports.interventionToFHIRMedicationStatement = interventionToFHIRMedicationStatement; exports.interventionToFHIRObservation = interventionToFHIRObservation; exports.interventionsToFHIRBundle = interventionsToFHIRBundle; exports.isBiomarkerVisible = _chunkAM2RCUUJcjs.isBiomarkerVisible; exports.isCacDocument = _chunkAM2RCUUJcjs.isCacDocument; exports.isDexaDocument = _chunkAM2RCUUJcjs.isDexaDocument; exports.isScreeningDue = isScreeningDue; exports.isValidCode = _chunkAM2RCUUJcjs.isValidCode; exports.isValidLoinc = _chunkAM2RCUUJcjs.isValidLoinc; exports.labObservationToFHIR =
|
|
719
|
+
exports.AGE_BRACKETS = AGE_BRACKETS; exports.BIOMARKER_CODE_SYSTEM = _chunkOR67NJDZcjs.BIOMARKER_CODE_SYSTEM; exports.BIOMARKER_DEFAULT_UNIT = _chunkMJ254F5Kcjs.BIOMARKER_DEFAULT_UNIT; exports.BIOMARKER_DEFINITIONS = _chunkAM2RCUUJcjs.BIOMARKER_DEFINITIONS; exports.BIOMARKER_UNITS = _chunkMJ254F5Kcjs.BIOMARKER_UNITS; exports.BODY_FAT_ZONES = BODY_FAT_ZONES; exports.BR_TIPO_AMOSTRA_VALUESET = BR_TIPO_AMOSTRA_VALUESET; exports.BUNDLE_BASE_URL = _chunkRSKFZ5UBcjs.BUNDLE_BASE_URL; exports.CAC_INDICATOR_CODES = _chunkAM2RCUUJcjs.CAC_INDICATOR_CODES; exports.CATEGORY_GROUPS = CATEGORY_GROUPS; exports.CATEGORY_SCREENING_INTERVALS = CATEGORY_SCREENING_INTERVALS; exports.DEXA_CATEGORIES = _chunkAM2RCUUJcjs.DEXA_CATEGORIES; exports.DEXA_INDICATOR_CODES = _chunkAM2RCUUJcjs.DEXA_INDICATOR_CODES; exports.HL7_SPECIMEN_TYPE_SYSTEM = HL7_SPECIMEN_TYPE_SYSTEM; exports.LOINC_SYSTEM = _chunkOR67NJDZcjs.LOINC_SYSTEM; exports.MAX_FILE_SIZE = _chunkHV77ZKP6cjs.MAX_FILE_SIZE; exports.MAX_OBSERVATIONS = _chunkHV77ZKP6cjs.MAX_OBSERVATIONS; exports.T_SCORE_ZONES = T_SCORE_ZONES; exports.UNIT_TO_UCUM = _chunkMJ254F5Kcjs.UNIT_TO_UCUM; exports.ZONE_DEFS = ZONE_DEFS; exports.applyFallbackReferenceRanges = _chunkERALICUKcjs.applyFallbackReferenceRanges; exports.biomarkerRangeDefinitions = _chunkERALICUKcjs.biomarkerRangeDefinitions; exports.calculateNextScreeningDate = calculateNextScreeningDate; exports.cnsToFHIRIdentifier = cnsToFHIRIdentifier; exports.codeToLoinc = _chunkAM2RCUUJcjs.codeToLoinc; exports.convertUnit = _chunkMJ254F5Kcjs.convertUnit; exports.cpfToFHIRIdentifier = cpfToFHIRIdentifier; exports.defaultReferenceRanges = _chunkERALICUKcjs.defaultReferenceRanges; exports.entryFullUrl = _chunkRSKFZ5UBcjs.entryFullUrl; exports.extractObservationsFromBundle = _chunkHV77ZKP6cjs.extractObservationsFromBundle; exports.filterVisibleBiomarkers = _chunkAM2RCUUJcjs.filterVisibleBiomarkers; exports.findCodeByName = _chunkAM2RCUUJcjs.findCodeByName; exports.formatCNS = formatCNS; exports.formatCPF = formatCPF; exports.generateCacFullReference = _chunkAM2RCUUJcjs.generateCacFullReference; exports.generateDexaFullReference = _chunkAM2RCUUJcjs.generateDexaFullReference; exports.generateFilteredLLMReference = _chunkAM2RCUUJcjs.generateFilteredLLMReference; exports.generateLLMReference = _chunkAM2RCUUJcjs.generateLLMReference; exports.getAllCodes = _chunkAM2RCUUJcjs.getAllCodes; exports.getAllDefinitions = _chunkAM2RCUUJcjs.getAllDefinitions; exports.getAllLoincCodes = _chunkAM2RCUUJcjs.getAllLoincCodes; exports.getAllSearchPatterns = _chunkAM2RCUUJcjs.getAllSearchPatterns; exports.getBiomarkersByCategory = _chunkAM2RCUUJcjs.getBiomarkersByCategory; exports.getBiomarkersForCategories = _chunkAM2RCUUJcjs.getBiomarkersForCategories; exports.getCanonicalUnit = _chunkMJ254F5Kcjs.getCanonicalUnit; exports.getCategoriesByInterval = getCategoriesByInterval; exports.getCategoryGroup = getCategoryGroup; exports.getDaysUntilScreening = getDaysUntilScreening; exports.getDefaultUnit = _chunkMJ254F5Kcjs.getDefaultUnit; exports.getDefinitionByCode = _chunkAM2RCUUJcjs.getDefinitionByCode; exports.getDefinitionByLoinc = _chunkAM2RCUUJcjs.getDefinitionByLoinc; exports.getDefinitionsBySex = _chunkAM2RCUUJcjs.getDefinitionsBySex; exports.getDueCategories = getDueCategories; exports.getFallbackReferenceRange = _chunkERALICUKcjs.getFallbackReferenceRange; exports.getRangeDirection = _chunkERALICUKcjs.getRangeDirection; exports.getReferenceRange = _chunkERALICUKcjs.getReferenceRange; exports.getSIUnit = _chunkMJ254F5Kcjs.getSIUnit; exports.getScreeningInterval = getScreeningInterval; exports.getSexForCode = _chunkAM2RCUUJcjs.getSexForCode; exports.getVisibleDefinitions = _chunkAM2RCUUJcjs.getVisibleDefinitions; exports.interventionToFHIRMedicationStatement = interventionToFHIRMedicationStatement; exports.interventionToFHIRObservation = interventionToFHIRObservation; exports.interventionsToFHIRBundle = interventionsToFHIRBundle; exports.isBiomarkerVisible = _chunkAM2RCUUJcjs.isBiomarkerVisible; exports.isCacDocument = _chunkAM2RCUUJcjs.isCacDocument; exports.isDexaDocument = _chunkAM2RCUUJcjs.isDexaDocument; exports.isScreeningDue = isScreeningDue; exports.isValidCode = _chunkAM2RCUUJcjs.isValidCode; exports.isValidLoinc = _chunkAM2RCUUJcjs.isValidLoinc; exports.labObservationToFHIR = _chunkRSKFZ5UBcjs.labObservationToFHIR; exports.labReportToFHIR = _chunkRSKFZ5UBcjs.labReportToFHIR; exports.labResultToFHIRBundle = _chunkRSKFZ5UBcjs.labResultToFHIRBundle; exports.listMappedSubcategories = listMappedSubcategories; exports.loincToCode = _chunkAM2RCUUJcjs.loincToCode; exports.mapFHIRObservationToInternal = _chunkHV77ZKP6cjs.mapFHIRObservationToInternal; exports.normalizeCode = _chunkAM2RCUUJcjs.normalizeCode; exports.plural = plural; exports.pluralCount = pluralCount; exports.pluralPhrase = pluralPhrase; exports.pluralPhraseCount = pluralPhraseCount; exports.processImportBundle = _chunkHV77ZKP6cjs.processImportBundle; exports.specimenTypeCoding = specimenTypeCoding; exports.toBiomarkerTests = _chunkAM2RCUUJcjs.toBiomarkerTests; exports.unitToUCUM = _chunkMJ254F5Kcjs.unitToUCUM; exports.userProfileToFHIR = _chunkRSKFZ5UBcjs.userProfileToFHIR; exports.validateCNS = validateCNS; exports.validateCPF = validateCPF; exports.validateFHIRDiagnosticReport = _chunk3ILBFLVQcjs.validateFHIRDiagnosticReport; exports.validateFHIRImportBundle = _chunk3ILBFLVQcjs.validateFHIRImportBundle; exports.validateFHIRObservation = _chunk3ILBFLVQcjs.validateFHIRObservation; exports.validateLoincNameMatch = _chunkAM2RCUUJcjs.validateLoincNameMatch;
|
|
693
720
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/index.cjs","../src/category-groups.ts","../src/intervention-converter.ts","../src/dexa-zone-data.ts","../src/screening-intervals.ts","../src/i18n.ts","../src/identifiers.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;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,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACxCO,IAAM,gBAAA,EAA4D;AAAA,EACvE,cAAA,EAAgB;AAAA,IACd,EAAA,EAAI,gBAAA;AAAA,IACJ,EAAA,EAAI,gBAAA;AAAA,IACJ,IAAA,EAAM,gBAAA;AAAA,IACN,a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IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AAAA;AAGA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AAAA;AAGA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACF;AAKiG;AAC7C,EAAA;AACpD;AAOkC;AACkB,EAAA;AACpD;AAK+D;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,EAAA;AACpD;AAQ+C;AAChB,EAAA;AACI,EAAA;AACiB,EAAA;AACpD;AASiE;AACxC,EAAA;AACS,IAAA;AAChC,EAAA;AACO,EAAA;AACG,IAAA;AACH,IAAA;AACgB,IAAA;AACvB,EAAA;AACF;AASiE;AACxC,EAAA;AACS,IAAA;AAChC,EAAA;AACO,EAAA;AACG,IAAA;AACH,IAAA;AACgB,IAAA;AACvB,EAAA;AACF;AN+coD;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;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;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","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/index.cjs","sourcesContent":[null,"/**\n * Agrupamento de categorias clínicas em 10 grupos de alto nível.\n *\n * `BiomarkerDefinition.category` armazena 20 sub-categorias (granularidade\n * fina, ex: `tireoide`, `pancreas`). Este módulo agrupa essas\n * sub-categorias em 10 buckets clínicos amplos para apresentação no\n * site, na API pública e em material de divulgação.\n *\n * As sub-categorias permanecem como fonte da verdade nos dados; este\n * agrupamento é uma camada derivada.\n */\n\nexport type CategoryGroup =\n | 'cardiovascular'\n | 'metabolico-endocrino'\n | 'renal-eletrolitico'\n | 'hepatico-biliar'\n | 'hematologico'\n | 'imunologico'\n | 'oncologico'\n | 'nutricional-ambiental'\n | 'saude-reprodutiva'\n | 'composicao-envelhecimento';\n\nexport interface CategoryGroupInfo {\n /** Rótulo em inglês */\n en: string;\n /** Rótulo em português */\n pt: string;\n /** Slug (kebab-case, sem acento) */\n slug: CategoryGroup;\n /** Sub-categorias da fonte agrupadas neste bucket */\n subcategories: readonly string[];\n}\n\nexport const CATEGORY_GROUPS: Record<CategoryGroup, CategoryGroupInfo> = {\n cardiovascular: {\n en: 'Cardiovascular',\n pt: 'Cardiovascular',\n slug: 'cardiovascular',\n subcategories: ['coracao'],\n },\n 'composicao-envelhecimento': {\n en: 'Body Composition & Aging',\n pt: 'Composição Corporal e Envelhecimento',\n slug: 'composicao-envelhecimento',\n subcategories: ['composicao-corporal', 'densidade-ossea', 'estresse-envelhecimento'],\n },\n hematologico: {\n en: 'Hematology',\n pt: 'Hematológico',\n slug: 'hematologico',\n subcategories: ['sangue'],\n },\n 'hepatico-biliar': {\n en: 'Hepatic & Biliary',\n pt: 'Hepático e Biliar',\n slug: 'hepatico-biliar',\n subcategories: ['figado'],\n },\n imunologico: {\n en: 'Immunology',\n pt: 'Imunológico',\n slug: 'imunologico',\n subcategories: ['autoimunidade', 'regulacao-imunologica'],\n },\n 'metabolico-endocrino': {\n en: 'Metabolic & Endocrine',\n pt: 'Metabólico e Endócrino',\n slug: 'metabolico-endocrino',\n subcategories: ['metabolico', 'pancreas', 'hormonios', 'tireoide'],\n },\n 'nutricional-ambiental': {\n en: 'Nutrition & Environmental Exposure',\n pt: 'Nutricional e Exposição Ambiental',\n slug: 'nutricional-ambiental',\n subcategories: ['nutrientes', 'toxinas-ambientais'],\n },\n oncologico: {\n en: 'Oncology',\n pt: 'Oncológico',\n slug: 'oncologico',\n subcategories: ['marcadores-tumorais'],\n },\n 'renal-eletrolitico': {\n en: 'Renal & Electrolytes',\n pt: 'Renal e Eletrolítico',\n slug: 'renal-eletrolitico',\n subcategories: ['rins', 'urina', 'eletrolitos'],\n },\n 'saude-reprodutiva': {\n en: 'Reproductive Health',\n pt: 'Saúde Reprodutiva',\n slug: 'saude-reprodutiva',\n subcategories: ['saude-feminina', 'saude-masculina'],\n },\n};\n\nconst SUBCATEGORY_TO_GROUP = new Map<string, CategoryGroup>();\nfor (const group of Object.values(CATEGORY_GROUPS)) {\n for (const sub of group.subcategories) {\n SUBCATEGORY_TO_GROUP.set(sub, group.slug);\n }\n}\n\n/**\n * Resolve a sub-categoria (granular) para o grupo de alto nível (10 buckets).\n */\nexport function getCategoryGroup(subcategory: string): CategoryGroup | undefined {\n return SUBCATEGORY_TO_GROUP.get(subcategory);\n}\n\n/**\n * Lista todas as sub-categorias mapeadas em algum grupo.\n */\nexport function listMappedSubcategories(): readonly string[] {\n return [...SUBCATEGORY_TO_GROUP.keys()];\n}\n","/**\n * FHIR Intervention Converter\n *\n * Converts interventions (medication, supplement, diet, exercise, sleep)\n * to FHIR R4 MedicationStatement and Observation resources.\n */\n\nimport { type Addressable, entryFullUrl } from './bundle-urls';\nimport { userProfileToFHIR } from './converter';\nimport type { FHIRBundle, FHIRMedicationStatement, FHIRObservation } from './fhir-types';\nimport type { InterventionData, UserProfileData } from './types';\n\n/**\n * Determine MedicationStatement/Observation status based on end date\n */\nfunction interventionStatus(endDate?: string): 'active' | 'completed' {\n if (!endDate) return 'active';\n return new Date(endDate) < new Date() ? 'completed' : 'active';\n}\n\n/**\n * LOINC-like codes for lifestyle observation types\n */\nconst LIFESTYLE_CODES: Record<string, { code: string; display: string }> = {\n diet: { code: '81259-4', display: 'Diet' },\n exercise: { code: '73985-4', display: 'Exercise activity' },\n sleep: { code: '93832-4', display: 'Sleep duration' },\n};\n\n/**\n * Convert medication/supplement intervention to FHIR MedicationStatement\n */\nexport function interventionToFHIRMedicationStatement(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRMedicationStatement> {\n const statement: Addressable<FHIRMedicationStatement> = {\n category: {\n coding: [\n {\n code: 'patientspecified',\n display: 'Patient Specified',\n system: 'http://terminology.hl7.org/CodeSystem/medication-statement-category',\n },\n ],\n },\n dateAsserted: intervention.startDate,\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n medicationCodeableConcept: {\n text: intervention.name,\n },\n resourceType: 'MedicationStatement',\n status: interventionStatus(intervention.endDate),\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n if (intervention.notes) {\n statement.note = [{ text: intervention.notes }];\n }\n\n return statement;\n}\n\n/**\n * Convert diet/exercise/sleep intervention to FHIR Observation (social-history)\n */\nexport function interventionToFHIRObservation(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRObservation> {\n const lifestyleCode = LIFESTYLE_CODES[intervention.type];\n\n const observation: Addressable<FHIRObservation> = {\n category: [\n {\n coding: [\n {\n code: 'social-history',\n display: 'Social History',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: lifestyleCode\n ? [\n {\n code: lifestyleCode.code,\n display: lifestyleCode.display,\n system: 'http://loinc.org',\n },\n ]\n : [],\n text: intervention.name,\n },\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n valueString: intervention.name,\n };\n\n if (intervention.notes) {\n observation.note = [{ text: intervention.notes }];\n }\n\n return observation;\n}\n\n/**\n * Convert all interventions to a FHIR Bundle\n */\nexport function interventionsToFHIRBundle(\n interventions: InterventionData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n const fhirPatient = userProfileToFHIR(userProfile);\n\n const entries = interventions.map((intervention) => {\n const isMedication = intervention.type === 'medication' || intervention.type === 'supplement';\n const resource = isMedication\n ? interventionToFHIRMedicationStatement(intervention, patientId)\n : interventionToFHIRObservation(intervention, patientId);\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n return {\n entry: [{ fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient }, ...entries],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n","/**\n * Structured zone data for DEXA body composition and bone density charts.\n *\n * Body fat zones derived from Gallagher et al. Am J Clin Nutr 2000;72:694-701 (PMID: 10966886)\n * and ACSM Guidelines for Exercise Testing, 11th Ed (2021).\n *\n * T-Score zones from WHO criteria (Kanis JA, Osteoporos Int, PMID: 7696835).\n */\n\nexport interface BodyFatZone {\n ageMax: number;\n ageMin: number;\n color: string;\n fatPctMax: number;\n fatPctMin: number;\n label: string;\n sex: 'F' | 'M';\n}\n\ninterface AgeBracket {\n ageMax: number;\n ageMin: number;\n label: string;\n}\n\nconst AGE_BRACKETS: AgeBracket[] = [\n { ageMax: 25, ageMin: 18, label: '18-25' },\n { ageMax: 35, ageMin: 26, label: '26-35' },\n { ageMax: 45, ageMin: 36, label: '36-45' },\n { ageMax: 55, ageMin: 46, label: '46-55' },\n { ageMax: 99, ageMin: 56, label: '56+' },\n];\n\n// Zone boundaries per age bracket for men: [essential, athletic, fitness, average, obese]\n// Each value is the upper bound of the zone\nconst MALE_ZONES: number[][] = [\n [5, 10, 20, 25, 40],\n [5, 11, 21, 26, 40],\n [5, 12, 22, 27, 40],\n [5, 13, 23, 28, 40],\n [5, 14, 24, 29, 40],\n];\n\nconst FEMALE_ZONES: number[][] = [\n [13, 18, 28, 32, 45],\n [13, 18, 29, 33, 45],\n [13, 19, 30, 34, 45],\n [13, 20, 31, 35, 45],\n [13, 20, 32, 36, 45],\n];\n\ninterface ZoneDefinition {\n color: string;\n label: string;\n}\n\nconst ZONE_DEFS: ZoneDefinition[] = [\n { color: '#3b82f6', label: 'Essencial' },\n { color: '#06b6d4', label: 'Atlético' },\n { color: '#22c55e', label: 'Fitness' },\n { color: '#eab308', label: 'Média' },\n { color: '#ef4444', label: 'Obeso' },\n];\n\nfunction buildZones(sex: 'F' | 'M', zoneData: number[][]): BodyFatZone[] {\n const zones: BodyFatZone[] = [];\n for (let i = 0; i < AGE_BRACKETS.length; i++) {\n const bracket = AGE_BRACKETS[i]!;\n const b = zoneData[i]!;\n zones.push({\n ...bracket,\n color: ZONE_DEFS[0]!.color,\n fatPctMax: b[0]!,\n fatPctMin: 0,\n label: ZONE_DEFS[0]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[1]!.color,\n fatPctMax: b[1]!,\n fatPctMin: b[0]!,\n label: ZONE_DEFS[1]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[2]!.color,\n fatPctMax: b[2]!,\n fatPctMin: b[1]!,\n label: ZONE_DEFS[2]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[3]!.color,\n fatPctMax: b[3]!,\n fatPctMin: b[2]!,\n label: ZONE_DEFS[3]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[4]!.color,\n fatPctMax: b[4]!,\n fatPctMin: b[3]!,\n label: ZONE_DEFS[4]!.label,\n sex,\n });\n }\n return zones;\n}\n\nexport const BODY_FAT_ZONES: BodyFatZone[] = [\n ...buildZones('M', MALE_ZONES),\n ...buildZones('F', FEMALE_ZONES),\n];\n\nexport { AGE_BRACKETS, ZONE_DEFS };\n\nexport interface TScoreZone {\n color: string;\n label: string;\n max: number;\n min: number;\n}\n\nexport const T_SCORE_ZONES: TScoreZone[] = [\n { color: '#22c55e', label: 'Normal', max: 4, min: -1.0 },\n { color: '#eab308', label: 'Osteopenia', max: -1.0, min: -2.5 },\n { color: '#ef4444', label: 'Osteoporose', max: -2.5, min: -5 },\n];\n","/**\n * Screening Intervals Configuration\n *\n * Defines recommended screening intervals for different biomarker categories\n * based on clinical guidelines and best practices.\n */\n\n/**\n * Screening interval in months\n */\nexport type ScreeningIntervalMonths = 3 | 6 | 12;\n\n/**\n * Biomarker category with its recommended screening interval\n */\nexport interface CategoryScreeningInterval {\n category: string;\n intervalMonths: ScreeningIntervalMonths;\n nameEn: string;\n namePt: string;\n}\n\n/**\n * Screening interval configuration for each category\n *\n * Categories are grouped by their recommended screening intervals:\n * - 3 months: Body composition and bone density (frequently changing metrics)\n * - 6 months: Metabolic panel and nutrients (moderate change rate)\n * - 12 months: Standard blood panels (stable long-term markers)\n */\nexport const CATEGORY_SCREENING_INTERVALS: CategoryScreeningInterval[] = [\n // 3-month intervals - Body composition (frequently changing)\n {\n category: 'composicao-corporal',\n intervalMonths: 3,\n nameEn: 'Body Composition',\n namePt: 'Composição Corporal',\n },\n {\n category: 'densidade-ossea',\n intervalMonths: 3,\n nameEn: 'Bone Density',\n namePt: 'Densidade Óssea',\n },\n\n // 6-month intervals - Metabolic and nutrients\n {\n category: 'metabolico',\n intervalMonths: 6,\n nameEn: 'Metabolic Panel',\n namePt: 'Painel Metabólico',\n },\n {\n category: 'nutrientes',\n intervalMonths: 6,\n nameEn: 'Nutrients',\n namePt: 'Nutrientes',\n },\n {\n category: 'pancreas',\n intervalMonths: 6,\n nameEn: 'Pancreas',\n namePt: 'Pâncreas',\n },\n\n // 12-month intervals - Standard blood panels\n {\n category: 'coracao',\n intervalMonths: 12,\n nameEn: 'Heart Health',\n namePt: 'Saúde Cardiovascular',\n },\n {\n category: 'tireoide',\n intervalMonths: 12,\n nameEn: 'Thyroid',\n namePt: 'Tireoide',\n },\n {\n category: 'sangue',\n intervalMonths: 12,\n nameEn: 'Blood Count',\n namePt: 'Hemograma',\n },\n {\n category: 'figado',\n intervalMonths: 12,\n nameEn: 'Liver Function',\n namePt: 'Função Hepática',\n },\n {\n category: 'rins',\n intervalMonths: 12,\n nameEn: 'Kidney Function',\n namePt: 'Função Renal',\n },\n {\n category: 'saude-feminina',\n intervalMonths: 12,\n nameEn: \"Women's Health\",\n namePt: 'Saúde Feminina',\n },\n {\n category: 'saude-masculina',\n intervalMonths: 12,\n nameEn: \"Men's Health\",\n namePt: 'Saúde Masculina',\n },\n {\n category: 'eletrolitos',\n intervalMonths: 12,\n nameEn: 'Electrolytes',\n namePt: 'Eletrólitos',\n },\n {\n category: 'estresse-envelhecimento',\n intervalMonths: 12,\n nameEn: 'Stress & Aging',\n namePt: 'Estresse e Envelhecimento',\n },\n {\n category: 'autoimunidade',\n intervalMonths: 12,\n nameEn: 'Autoimmunity',\n namePt: 'Autoimunidade',\n },\n {\n category: 'regulacao-imunologica',\n intervalMonths: 12,\n nameEn: 'Immune Regulation',\n namePt: 'Regulação Imunológica',\n },\n {\n category: 'toxinas-ambientais',\n intervalMonths: 12,\n nameEn: 'Environmental Toxins',\n namePt: 'Toxinas Ambientais',\n },\n {\n category: 'urina',\n intervalMonths: 12,\n nameEn: 'Urinalysis',\n namePt: 'Urina',\n },\n];\n\n/**\n * Get screening interval for a category\n */\nexport const getScreeningInterval = (category: string): CategoryScreeningInterval | undefined => {\n return CATEGORY_SCREENING_INTERVALS.find((c) => c.category === category);\n};\n\n/**\n * Get all categories with a specific interval\n */\nexport const getCategoriesByInterval = (\n intervalMonths: ScreeningIntervalMonths,\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((c) => c.intervalMonths === intervalMonths);\n};\n\n/**\n * Calculate next screening date based on last test date and category\n */\nexport const calculateNextScreeningDate = (lastTestDate: Date, category: string): Date | null => {\n const interval = getScreeningInterval(category);\n if (!interval) return null;\n\n const nextDate = new Date(lastTestDate);\n nextDate.setMonth(nextDate.getMonth() + interval.intervalMonths);\n return nextDate;\n};\n\n/**\n * Check if a category is due for screening\n */\nexport const isScreeningDue = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): boolean => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return false;\n return referenceDate >= nextDate;\n};\n\n/**\n * Get categories that are due for screening based on last test dates\n */\nexport const getDueCategories = (\n lastTestDates: Record<string, Date>,\n referenceDate: Date = new Date(),\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((interval) => {\n const lastDate = lastTestDates[interval.category];\n if (!lastDate) return true; // Never tested = due\n return isScreeningDue(lastDate, interval.category, referenceDate);\n });\n};\n\n/**\n * Get days until next screening for a category\n */\nexport const getDaysUntilScreening = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): number | null => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return null;\n\n const diffTime = nextDate.getTime() - referenceDate.getTime();\n return Math.ceil(diffTime / (1000 * 60 * 60 * 24));\n};\n","/**\n * Portuguese pluralization utility using native Intl.PluralRules\n * Provides automatic pluralization for common words used in the app\n */\n\nconst pluralRules = new Intl.PluralRules('pt-BR');\n\n/**\n * Dictionary of Portuguese words with their plural forms\n * Key is the singular form, value is the plural form\n */\nconst dictionary: Record<string, string> = {\n // Common nouns\n arquivo: 'arquivos',\n biomarcador: 'biomarcadores',\n // Past participles (masculine)\n cadastrado: 'cadastrados',\n // Past participles (feminine)\n concluída: 'concluídas',\n confirmado: 'confirmados',\n convertido: 'convertidos',\n convidado: 'convidados',\n convite: 'convites',\n disponível: 'disponíveis',\n documento: 'documentos',\n enviado: 'enviados',\n exame: 'exames',\n excluída: 'excluídas',\n\n excluído: 'excluídos',\n // Verbs (3rd person)\n falhou: 'falharam',\n falta: 'faltam',\n ignorado: 'ignorados',\n item: 'itens',\n outro: 'outros',\n página: 'páginas',\n pendente: 'pendentes',\n registro: 'registros',\n removido: 'removidos',\n\n resultado: 'resultados',\n revisão: 'revisões',\n\n revogado: 'revogados',\n usuário: 'usuários',\n};\n\n/**\n * Get the plural form of a word from the dictionary\n * Falls back to adding 's' if word is not in dictionary\n */\nconst getPluralForm = (singular: string): string => {\n return dictionary[singular] ?? `${singular}s`;\n};\n\n/**\n * Returns the correct singular or plural form based on count\n * Uses Intl.PluralRules for proper locale-aware pluralization\n *\n * @example\n * plural(1, 'usuário') // 'usuário'\n * plural(3, 'usuário') // 'usuários'\n * plural(0, 'registro') // 'registros'\n */\nexport const plural = (count: number, word: string): string => {\n const rule = pluralRules.select(count);\n return rule === 'one' ? word : getPluralForm(word);\n};\n\n/**\n * Returns count with the correct singular or plural form\n *\n * @example\n * pluralCount(1, 'usuário') // '1 usuário'\n * pluralCount(3, 'usuário') // '3 usuários'\n */\nexport const pluralCount = (count: number, word: string): string => {\n return `${count} ${plural(count, word)}`;\n};\n\n/**\n * Returns the correct form for compound phrases (noun + adjective)\n * Both words are pluralized together\n *\n * @example\n * pluralPhrase(1, 'usuário', 'cadastrado') // 'usuário cadastrado'\n * pluralPhrase(3, 'usuário', 'cadastrado') // 'usuários cadastrados'\n * pluralPhrase(2, 'revisão', 'excluída') // 'revisões excluídas'\n */\nexport const pluralPhrase = (count: number, noun: string, adjective: string): string => {\n const rule = pluralRules.select(count);\n if (rule === 'one') {\n return `${noun} ${adjective}`;\n }\n return `${getPluralForm(noun)} ${getPluralForm(adjective)}`;\n};\n\n/**\n * Returns count with the correct compound phrase form\n *\n * @example\n * pluralPhraseCount(1, 'usuário', 'cadastrado') // '1 usuário cadastrado'\n * pluralPhraseCount(3, 'convite', 'enviado') // '3 convites enviados'\n */\nexport const pluralPhraseCount = (count: number, noun: string, adjective: string): string => {\n return `${count} ${pluralPhrase(count, noun, adjective)}`;\n};\n","/**\n * Helpers para identificadores brasileiros — CPF e CNS\n *\n * Validação, formatação e conversão para FHIR Identifier.\n * Algoritmos de validação baseados nas especificações oficiais:\n * - CPF: Receita Federal (mod-11, dois dígitos verificadores)\n * - CNS: Ministério da Saúde (mod-11 para definitivos, soma ponderada para provisórios)\n */\n\nimport type { FHIRIdentifier } from './fhir-types';\n\nconst CPF_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cpf';\nconst CNS_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cns';\n\n/**\n * Remove caracteres não-numéricos de uma string.\n */\nfunction digitsOnly(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Valida um CPF brasileiro usando algoritmo mod-11.\n *\n * @param cpf — CPF com ou sem formatação (ex: \"123.456.789-09\" ou \"12345678909\")\n * @returns true se o CPF é estruturalmente válido\n */\nexport function validateCPF(cpf: string): boolean {\n const digits = digitsOnly(cpf);\n\n if (digits.length !== 11) return false;\n\n // Rejeitar sequências de dígitos iguais (ex: 111.111.111-11)\n if (/^(\\d)\\1{10}$/.test(digits)) return false;\n\n // Primeiro dígito verificador\n let sum = 0;\n for (let i = 0; i < 9; i++) {\n sum += Number(digits[i]) * (10 - i);\n }\n let remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[9])) return false;\n\n // Segundo dígito verificador\n sum = 0;\n for (let i = 0; i < 10; i++) {\n sum += Number(digits[i]) * (11 - i);\n }\n remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[10])) return false;\n\n return true;\n}\n\n/**\n * Valida um CNS (Cartão Nacional de Saúde) brasileiro.\n *\n * CNS definitivos começam com 1 ou 2 (mod-11).\n * CNS provisórios começam com 7, 8 ou 9 (soma ponderada mod-11 = 0).\n *\n * @param cns — CNS com 15 dígitos\n * @returns true se o CNS é estruturalmente válido\n */\nexport function validateCNS(cns: string): boolean {\n const digits = digitsOnly(cns);\n\n if (digits.length !== 15) return false;\n\n const firstDigit = digits[0]!;\n\n // CNS deve começar com 1, 2 (definitivo) ou 7, 8, 9 (provisório)\n if (!['1', '2', '7', '8', '9'].includes(firstDigit)) return false;\n\n // Ambos os tipos usam soma ponderada mod-11 = 0\n let sum = 0;\n for (let i = 0; i < 15; i++) {\n sum += Number(digits[i]) * (15 - i);\n }\n return sum % 11 === 0;\n}\n\n/**\n * Formata um CPF como XXX.XXX.XXX-XX.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns CPF formatado ou a string original se inválido\n */\nexport function formatCPF(cpf: string): string {\n const digits = digitsOnly(cpf);\n if (digits.length !== 11) return cpf;\n return `${digits.slice(0, 3)}.${digits.slice(3, 6)}.${digits.slice(6, 9)}-${digits.slice(9)}`;\n}\n\n/**\n * Formata um CNS como XXX XXXX XXXX XXXX.\n *\n * @param cns — CNS com 15 dígitos\n * @returns CNS formatado ou a string original se inválido\n */\nexport function formatCNS(cns: string): string {\n const digits = digitsOnly(cns);\n if (digits.length !== 15) return cns;\n return `${digits.slice(0, 3)} ${digits.slice(3, 7)} ${digits.slice(7, 11)} ${digits.slice(11)}`;\n}\n\n/**\n * Converte um CPF para um FHIR Identifier.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns FHIR Identifier com sistema RNDS para CPF\n * @throws Error se o CPF for inválido\n */\nexport function cpfToFHIRIdentifier(cpf: string): FHIRIdentifier {\n if (!validateCPF(cpf)) {\n throw new Error('CPF inválido');\n }\n return {\n system: CPF_SYSTEM,\n use: 'official',\n value: digitsOnly(cpf),\n };\n}\n\n/**\n * Converte um CNS para um FHIR Identifier.\n *\n * @param cns — CNS com 15 dígitos\n * @returns FHIR Identifier com sistema RNDS para CNS\n * @throws Error se o CNS for inválido\n */\nexport function cnsToFHIRIdentifier(cns: string): FHIRIdentifier {\n if (!validateCNS(cns)) {\n throw new Error('CNS inválido');\n }\n return {\n system: CNS_SYSTEM,\n use: 'official',\n value: digitsOnly(cns),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/index.cjs","../src/category-groups.ts","../src/intervention-converter.ts","../src/dexa-zone-data.ts","../src/screening-intervals.ts","../src/i18n.ts","../src/identifiers.ts","../src/specimen-types.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;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,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;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AAA;AACH,EAAA;AACO,EAAA;AACT;AAE6C;AACd,EAAA;AACE,EAAA;AACjC;AAW2C;AACS,EAAA;AACE,EAAA;AACL,EAAA;AACjD;AH4MoD;AACA;AIlTqB;AAAA;AAEvE,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AAAA;AAGA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AAAA;AAGA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR,IAAA;AACA,IAAA;AACV,EAAA;AACA,EAAA;AACY,IAAA;AACM,IAAA;AACR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AWkD;AACnB,EAAA;AAEI,EAAA;AAEN,EAAA;AAGuB,EAAA;AAGxC,EAAA;AACmB,EAAA;AACM,IAAA;AACnC,EAAA;AACoB,EAAA;AACtB;AAQ+C;AAChB,EAAA;AACI,EAAA;AACiB,EAAA;AACpD;AAQ+C;AAChB,EAAA;AACI,EAAA;AACiB,EAAA;AACpD;AASiE;AACxC,EAAA;AACS,IAAA;AAChC,EAAA;AACO,EAAA;AACG,IAAA;AACH,IAAA;AACgB,IAAA;AACvB,EAAA;AACF;AASiE;AACxC,EAAA;AACS,IAAA;AAChC,EAAA;AACO,EAAA;AACG,IAAA;AACH,IAAA;AACgB,IAAA;AACvB,EAAA;AACF;ANgdoD;AACA;AOvkBZ;AAUA;AAW0B;AACjC,EAAA;AACG,EAAA;AACI,EAAA;AACP,EAAA;AACE,EAAA;AACA,EAAA;AACnC;AAoBkB;AAIQ;AAOK;AACM,EAAA;AAChB,IAAA;AACQ,IAAA;AAC1B,EAAA;AACH;AAUE;APihBkD;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;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;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;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/index.cjs","sourcesContent":[null,"/**\n * Agrupamento de categorias clínicas em 10 grupos de alto nível.\n *\n * `BiomarkerDefinition.category` armazena 20 sub-categorias (granularidade\n * fina, ex: `tireoide`, `pancreas`). Este módulo agrupa essas\n * sub-categorias em 10 buckets clínicos amplos para apresentação no\n * site, na API pública e em material de divulgação.\n *\n * As sub-categorias permanecem como fonte da verdade nos dados; este\n * agrupamento é uma camada derivada.\n */\n\nexport type CategoryGroup =\n | 'cardiovascular'\n | 'metabolico-endocrino'\n | 'renal-eletrolitico'\n | 'hepatico-biliar'\n | 'hematologico'\n | 'imunologico'\n | 'oncologico'\n | 'nutricional-ambiental'\n | 'saude-reprodutiva'\n | 'composicao-envelhecimento';\n\nexport interface CategoryGroupInfo {\n /** Rótulo em inglês */\n en: string;\n /** Rótulo em português */\n pt: string;\n /** Slug (kebab-case, sem acento) */\n slug: CategoryGroup;\n /** Sub-categorias da fonte agrupadas neste bucket */\n subcategories: readonly string[];\n}\n\nexport const CATEGORY_GROUPS: Record<CategoryGroup, CategoryGroupInfo> = {\n cardiovascular: {\n en: 'Cardiovascular',\n pt: 'Cardiovascular',\n slug: 'cardiovascular',\n subcategories: ['coracao'],\n },\n 'composicao-envelhecimento': {\n en: 'Body Composition & Aging',\n pt: 'Composição Corporal e Envelhecimento',\n slug: 'composicao-envelhecimento',\n subcategories: ['composicao-corporal', 'densidade-ossea', 'estresse-envelhecimento'],\n },\n hematologico: {\n en: 'Hematology',\n pt: 'Hematológico',\n slug: 'hematologico',\n subcategories: ['sangue'],\n },\n 'hepatico-biliar': {\n en: 'Hepatic & Biliary',\n pt: 'Hepático e Biliar',\n slug: 'hepatico-biliar',\n subcategories: ['figado'],\n },\n imunologico: {\n en: 'Immunology',\n pt: 'Imunológico',\n slug: 'imunologico',\n subcategories: ['autoimunidade', 'regulacao-imunologica'],\n },\n 'metabolico-endocrino': {\n en: 'Metabolic & Endocrine',\n pt: 'Metabólico e Endócrino',\n slug: 'metabolico-endocrino',\n subcategories: ['metabolico', 'pancreas', 'hormonios', 'tireoide'],\n },\n 'nutricional-ambiental': {\n en: 'Nutrition & Environmental Exposure',\n pt: 'Nutricional e Exposição Ambiental',\n slug: 'nutricional-ambiental',\n subcategories: ['nutrientes', 'toxinas-ambientais'],\n },\n oncologico: {\n en: 'Oncology',\n pt: 'Oncológico',\n slug: 'oncologico',\n subcategories: ['marcadores-tumorais'],\n },\n 'renal-eletrolitico': {\n en: 'Renal & Electrolytes',\n pt: 'Renal e Eletrolítico',\n slug: 'renal-eletrolitico',\n subcategories: ['rins', 'urina', 'eletrolitos'],\n },\n 'saude-reprodutiva': {\n en: 'Reproductive Health',\n pt: 'Saúde Reprodutiva',\n slug: 'saude-reprodutiva',\n subcategories: ['saude-feminina', 'saude-masculina'],\n },\n};\n\nconst SUBCATEGORY_TO_GROUP = new Map<string, CategoryGroup>();\nfor (const group of Object.values(CATEGORY_GROUPS)) {\n for (const sub of group.subcategories) {\n SUBCATEGORY_TO_GROUP.set(sub, group.slug);\n }\n}\n\n/**\n * Resolve a sub-categoria (granular) para o grupo de alto nível (10 buckets).\n */\nexport function getCategoryGroup(subcategory: string): CategoryGroup | undefined {\n return SUBCATEGORY_TO_GROUP.get(subcategory);\n}\n\n/**\n * Lista todas as sub-categorias mapeadas em algum grupo.\n */\nexport function listMappedSubcategories(): readonly string[] {\n return [...SUBCATEGORY_TO_GROUP.keys()];\n}\n","/**\n * FHIR Intervention Converter\n *\n * Converts interventions (medication, supplement, diet, exercise, sleep)\n * to FHIR R4 MedicationStatement and Observation resources.\n */\n\nimport { type Addressable, entryFullUrl } from './bundle-urls';\nimport { userProfileToFHIR } from './converter';\nimport type { FHIRBundle, FHIRMedicationStatement, FHIRObservation } from './fhir-types';\nimport type { InterventionData, UserProfileData } from './types';\n\n/**\n * Determine MedicationStatement/Observation status based on end date\n */\nfunction interventionStatus(endDate?: string): 'active' | 'completed' {\n if (!endDate) return 'active';\n return new Date(endDate) < new Date() ? 'completed' : 'active';\n}\n\n/**\n * LOINC-like codes for lifestyle observation types\n */\nconst LIFESTYLE_CODES: Record<string, { code: string; display: string }> = {\n diet: { code: '81259-4', display: 'Diet' },\n exercise: { code: '73985-4', display: 'Exercise activity' },\n sleep: { code: '93832-4', display: 'Sleep duration' },\n};\n\n/**\n * Convert medication/supplement intervention to FHIR MedicationStatement\n */\nexport function interventionToFHIRMedicationStatement(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRMedicationStatement> {\n const statement: Addressable<FHIRMedicationStatement> = {\n category: {\n coding: [\n {\n code: 'patientspecified',\n display: 'Patient Specified',\n system: 'http://terminology.hl7.org/CodeSystem/medication-statement-category',\n },\n ],\n },\n dateAsserted: intervention.startDate,\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n medicationCodeableConcept: {\n text: intervention.name,\n },\n resourceType: 'MedicationStatement',\n status: interventionStatus(intervention.endDate),\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n if (intervention.notes) {\n statement.note = [{ text: intervention.notes }];\n }\n\n return statement;\n}\n\n/**\n * Convert diet/exercise/sleep intervention to FHIR Observation (social-history)\n */\nexport function interventionToFHIRObservation(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRObservation> {\n const lifestyleCode = LIFESTYLE_CODES[intervention.type];\n\n const observation: Addressable<FHIRObservation> = {\n category: [\n {\n coding: [\n {\n code: 'social-history',\n display: 'Social History',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: lifestyleCode\n ? [\n {\n code: lifestyleCode.code,\n display: lifestyleCode.display,\n system: 'http://loinc.org',\n },\n ]\n : [],\n text: intervention.name,\n },\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n valueString: intervention.name,\n };\n\n if (intervention.notes) {\n observation.note = [{ text: intervention.notes }];\n }\n\n return observation;\n}\n\n/**\n * Convert all interventions to a FHIR Bundle\n */\nexport function interventionsToFHIRBundle(\n interventions: InterventionData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n const fhirPatient = userProfileToFHIR(userProfile);\n\n const entries = interventions.map((intervention) => {\n const isMedication = intervention.type === 'medication' || intervention.type === 'supplement';\n const resource = isMedication\n ? interventionToFHIRMedicationStatement(intervention, patientId)\n : interventionToFHIRObservation(intervention, patientId);\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n return {\n entry: [{ fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient }, ...entries],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n","/**\n * Structured zone data for DEXA body composition and bone density charts.\n *\n * Body fat zones derived from Gallagher et al. Am J Clin Nutr 2000;72:694-701 (PMID: 10966886)\n * and ACSM Guidelines for Exercise Testing, 11th Ed (2021).\n *\n * T-Score zones from WHO criteria (Kanis JA, Osteoporos Int, PMID: 7696835).\n */\n\nexport interface BodyFatZone {\n ageMax: number;\n ageMin: number;\n color: string;\n fatPctMax: number;\n fatPctMin: number;\n label: string;\n sex: 'F' | 'M';\n}\n\ninterface AgeBracket {\n ageMax: number;\n ageMin: number;\n label: string;\n}\n\nconst AGE_BRACKETS: AgeBracket[] = [\n { ageMax: 25, ageMin: 18, label: '18-25' },\n { ageMax: 35, ageMin: 26, label: '26-35' },\n { ageMax: 45, ageMin: 36, label: '36-45' },\n { ageMax: 55, ageMin: 46, label: '46-55' },\n { ageMax: 99, ageMin: 56, label: '56+' },\n];\n\n// Zone boundaries per age bracket for men: [essential, athletic, fitness, average, obese]\n// Each value is the upper bound of the zone\nconst MALE_ZONES: number[][] = [\n [5, 10, 20, 25, 40],\n [5, 11, 21, 26, 40],\n [5, 12, 22, 27, 40],\n [5, 13, 23, 28, 40],\n [5, 14, 24, 29, 40],\n];\n\nconst FEMALE_ZONES: number[][] = [\n [13, 18, 28, 32, 45],\n [13, 18, 29, 33, 45],\n [13, 19, 30, 34, 45],\n [13, 20, 31, 35, 45],\n [13, 20, 32, 36, 45],\n];\n\ninterface ZoneDefinition {\n color: string;\n label: string;\n}\n\nconst ZONE_DEFS: ZoneDefinition[] = [\n { color: '#3b82f6', label: 'Essencial' },\n { color: '#06b6d4', label: 'Atlético' },\n { color: '#22c55e', label: 'Fitness' },\n { color: '#eab308', label: 'Média' },\n { color: '#ef4444', label: 'Obeso' },\n];\n\nfunction buildZones(sex: 'F' | 'M', zoneData: number[][]): BodyFatZone[] {\n const zones: BodyFatZone[] = [];\n for (let i = 0; i < AGE_BRACKETS.length; i++) {\n const bracket = AGE_BRACKETS[i]!;\n const b = zoneData[i]!;\n zones.push({\n ...bracket,\n color: ZONE_DEFS[0]!.color,\n fatPctMax: b[0]!,\n fatPctMin: 0,\n label: ZONE_DEFS[0]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[1]!.color,\n fatPctMax: b[1]!,\n fatPctMin: b[0]!,\n label: ZONE_DEFS[1]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[2]!.color,\n fatPctMax: b[2]!,\n fatPctMin: b[1]!,\n label: ZONE_DEFS[2]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[3]!.color,\n fatPctMax: b[3]!,\n fatPctMin: b[2]!,\n label: ZONE_DEFS[3]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[4]!.color,\n fatPctMax: b[4]!,\n fatPctMin: b[3]!,\n label: ZONE_DEFS[4]!.label,\n sex,\n });\n }\n return zones;\n}\n\nexport const BODY_FAT_ZONES: BodyFatZone[] = [\n ...buildZones('M', MALE_ZONES),\n ...buildZones('F', FEMALE_ZONES),\n];\n\nexport { AGE_BRACKETS, ZONE_DEFS };\n\nexport interface TScoreZone {\n color: string;\n label: string;\n max: number;\n min: number;\n}\n\nexport const T_SCORE_ZONES: TScoreZone[] = [\n { color: '#22c55e', label: 'Normal', max: 4, min: -1.0 },\n { color: '#eab308', label: 'Osteopenia', max: -1.0, min: -2.5 },\n { color: '#ef4444', label: 'Osteoporose', max: -2.5, min: -5 },\n];\n","/**\n * Screening Intervals Configuration\n *\n * Defines recommended screening intervals for different biomarker categories\n * based on clinical guidelines and best practices.\n */\n\n/**\n * Screening interval in months\n */\nexport type ScreeningIntervalMonths = 3 | 6 | 12;\n\n/**\n * Biomarker category with its recommended screening interval\n */\nexport interface CategoryScreeningInterval {\n category: string;\n intervalMonths: ScreeningIntervalMonths;\n nameEn: string;\n namePt: string;\n}\n\n/**\n * Screening interval configuration for each category\n *\n * Categories are grouped by their recommended screening intervals:\n * - 3 months: Body composition and bone density (frequently changing metrics)\n * - 6 months: Metabolic panel and nutrients (moderate change rate)\n * - 12 months: Standard blood panels (stable long-term markers)\n */\nexport const CATEGORY_SCREENING_INTERVALS: CategoryScreeningInterval[] = [\n // 3-month intervals - Body composition (frequently changing)\n {\n category: 'composicao-corporal',\n intervalMonths: 3,\n nameEn: 'Body Composition',\n namePt: 'Composição Corporal',\n },\n {\n category: 'densidade-ossea',\n intervalMonths: 3,\n nameEn: 'Bone Density',\n namePt: 'Densidade Óssea',\n },\n\n // 6-month intervals - Metabolic and nutrients\n {\n category: 'metabolico',\n intervalMonths: 6,\n nameEn: 'Metabolic Panel',\n namePt: 'Painel Metabólico',\n },\n {\n category: 'nutrientes',\n intervalMonths: 6,\n nameEn: 'Nutrients',\n namePt: 'Nutrientes',\n },\n {\n category: 'pancreas',\n intervalMonths: 6,\n nameEn: 'Pancreas',\n namePt: 'Pâncreas',\n },\n\n // 12-month intervals - Standard blood panels\n {\n category: 'coracao',\n intervalMonths: 12,\n nameEn: 'Heart Health',\n namePt: 'Saúde Cardiovascular',\n },\n {\n category: 'tireoide',\n intervalMonths: 12,\n nameEn: 'Thyroid',\n namePt: 'Tireoide',\n },\n {\n category: 'sangue',\n intervalMonths: 12,\n nameEn: 'Blood Count',\n namePt: 'Hemograma',\n },\n {\n category: 'figado',\n intervalMonths: 12,\n nameEn: 'Liver Function',\n namePt: 'Função Hepática',\n },\n {\n category: 'rins',\n intervalMonths: 12,\n nameEn: 'Kidney Function',\n namePt: 'Função Renal',\n },\n {\n category: 'saude-feminina',\n intervalMonths: 12,\n nameEn: \"Women's Health\",\n namePt: 'Saúde Feminina',\n },\n {\n category: 'saude-masculina',\n intervalMonths: 12,\n nameEn: \"Men's Health\",\n namePt: 'Saúde Masculina',\n },\n {\n category: 'eletrolitos',\n intervalMonths: 12,\n nameEn: 'Electrolytes',\n namePt: 'Eletrólitos',\n },\n {\n category: 'estresse-envelhecimento',\n intervalMonths: 12,\n nameEn: 'Stress & Aging',\n namePt: 'Estresse e Envelhecimento',\n },\n {\n category: 'autoimunidade',\n intervalMonths: 12,\n nameEn: 'Autoimmunity',\n namePt: 'Autoimunidade',\n },\n {\n category: 'regulacao-imunologica',\n intervalMonths: 12,\n nameEn: 'Immune Regulation',\n namePt: 'Regulação Imunológica',\n },\n {\n category: 'toxinas-ambientais',\n intervalMonths: 12,\n nameEn: 'Environmental Toxins',\n namePt: 'Toxinas Ambientais',\n },\n {\n category: 'urina',\n intervalMonths: 12,\n nameEn: 'Urinalysis',\n namePt: 'Urina',\n },\n];\n\n/**\n * Get screening interval for a category\n */\nexport const getScreeningInterval = (category: string): CategoryScreeningInterval | undefined => {\n return CATEGORY_SCREENING_INTERVALS.find((c) => c.category === category);\n};\n\n/**\n * Get all categories with a specific interval\n */\nexport const getCategoriesByInterval = (\n intervalMonths: ScreeningIntervalMonths,\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((c) => c.intervalMonths === intervalMonths);\n};\n\n/**\n * Calculate next screening date based on last test date and category\n */\nexport const calculateNextScreeningDate = (lastTestDate: Date, category: string): Date | null => {\n const interval = getScreeningInterval(category);\n if (!interval) return null;\n\n const nextDate = new Date(lastTestDate);\n nextDate.setMonth(nextDate.getMonth() + interval.intervalMonths);\n return nextDate;\n};\n\n/**\n * Check if a category is due for screening\n */\nexport const isScreeningDue = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): boolean => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return false;\n return referenceDate >= nextDate;\n};\n\n/**\n * Get categories that are due for screening based on last test dates\n */\nexport const getDueCategories = (\n lastTestDates: Record<string, Date>,\n referenceDate: Date = new Date(),\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((interval) => {\n const lastDate = lastTestDates[interval.category];\n if (!lastDate) return true; // Never tested = due\n return isScreeningDue(lastDate, interval.category, referenceDate);\n });\n};\n\n/**\n * Get days until next screening for a category\n */\nexport const getDaysUntilScreening = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): number | null => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return null;\n\n const diffTime = nextDate.getTime() - referenceDate.getTime();\n return Math.ceil(diffTime / (1000 * 60 * 60 * 24));\n};\n","/**\n * Portuguese pluralization utility using native Intl.PluralRules\n * Provides automatic pluralization for common words used in the app\n */\n\nconst pluralRules = new Intl.PluralRules('pt-BR');\n\n/**\n * Dictionary of Portuguese words with their plural forms\n * Key is the singular form, value is the plural form\n */\nconst dictionary: Record<string, string> = {\n // Common nouns\n arquivo: 'arquivos',\n biomarcador: 'biomarcadores',\n // Past participles (masculine)\n cadastrado: 'cadastrados',\n // Past participles (feminine)\n concluída: 'concluídas',\n confirmado: 'confirmados',\n convertido: 'convertidos',\n convidado: 'convidados',\n convite: 'convites',\n disponível: 'disponíveis',\n documento: 'documentos',\n enviado: 'enviados',\n exame: 'exames',\n excluída: 'excluídas',\n\n excluído: 'excluídos',\n // Verbs (3rd person)\n falhou: 'falharam',\n falta: 'faltam',\n ignorado: 'ignorados',\n item: 'itens',\n outro: 'outros',\n página: 'páginas',\n pendente: 'pendentes',\n registro: 'registros',\n removido: 'removidos',\n\n resultado: 'resultados',\n revisão: 'revisões',\n\n revogado: 'revogados',\n usuário: 'usuários',\n};\n\n/**\n * Get the plural form of a word from the dictionary\n * Falls back to adding 's' if word is not in dictionary\n */\nconst getPluralForm = (singular: string): string => {\n return dictionary[singular] ?? `${singular}s`;\n};\n\n/**\n * Returns the correct singular or plural form based on count\n * Uses Intl.PluralRules for proper locale-aware pluralization\n *\n * @example\n * plural(1, 'usuário') // 'usuário'\n * plural(3, 'usuário') // 'usuários'\n * plural(0, 'registro') // 'registros'\n */\nexport const plural = (count: number, word: string): string => {\n const rule = pluralRules.select(count);\n return rule === 'one' ? word : getPluralForm(word);\n};\n\n/**\n * Returns count with the correct singular or plural form\n *\n * @example\n * pluralCount(1, 'usuário') // '1 usuário'\n * pluralCount(3, 'usuário') // '3 usuários'\n */\nexport const pluralCount = (count: number, word: string): string => {\n return `${count} ${plural(count, word)}`;\n};\n\n/**\n * Returns the correct form for compound phrases (noun + adjective)\n * Both words are pluralized together\n *\n * @example\n * pluralPhrase(1, 'usuário', 'cadastrado') // 'usuário cadastrado'\n * pluralPhrase(3, 'usuário', 'cadastrado') // 'usuários cadastrados'\n * pluralPhrase(2, 'revisão', 'excluída') // 'revisões excluídas'\n */\nexport const pluralPhrase = (count: number, noun: string, adjective: string): string => {\n const rule = pluralRules.select(count);\n if (rule === 'one') {\n return `${noun} ${adjective}`;\n }\n return `${getPluralForm(noun)} ${getPluralForm(adjective)}`;\n};\n\n/**\n * Returns count with the correct compound phrase form\n *\n * @example\n * pluralPhraseCount(1, 'usuário', 'cadastrado') // '1 usuário cadastrado'\n * pluralPhraseCount(3, 'convite', 'enviado') // '3 convites enviados'\n */\nexport const pluralPhraseCount = (count: number, noun: string, adjective: string): string => {\n return `${count} ${pluralPhrase(count, noun, adjective)}`;\n};\n","/**\n * Helpers para identificadores brasileiros — CPF e CNS\n *\n * Validação, formatação e conversão para FHIR Identifier.\n * Algoritmos de validação baseados nas especificações oficiais:\n * - CPF: Receita Federal (mod-11, dois dígitos verificadores)\n * - CNS: Ministério da Saúde (mod-11 para definitivos, soma ponderada para provisórios)\n */\n\nimport type { FHIRIdentifier } from './fhir-types';\n\nconst CPF_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cpf';\nconst CNS_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cns';\n\n/**\n * Remove caracteres não-numéricos de uma string.\n */\nfunction digitsOnly(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Valida um CPF brasileiro usando algoritmo mod-11.\n *\n * @param cpf — CPF com ou sem formatação (ex: \"123.456.789-09\" ou \"12345678909\")\n * @returns true se o CPF é estruturalmente válido\n */\nexport function validateCPF(cpf: string): boolean {\n const digits = digitsOnly(cpf);\n\n if (digits.length !== 11) return false;\n\n // Rejeitar sequências de dígitos iguais (ex: 111.111.111-11)\n if (/^(\\d)\\1{10}$/.test(digits)) return false;\n\n // Primeiro dígito verificador\n let sum = 0;\n for (let i = 0; i < 9; i++) {\n sum += Number(digits[i]) * (10 - i);\n }\n let remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[9])) return false;\n\n // Segundo dígito verificador\n sum = 0;\n for (let i = 0; i < 10; i++) {\n sum += Number(digits[i]) * (11 - i);\n }\n remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[10])) return false;\n\n return true;\n}\n\n/**\n * Valida um CNS (Cartão Nacional de Saúde) brasileiro.\n *\n * CNS definitivos começam com 1 ou 2 (mod-11).\n * CNS provisórios começam com 7, 8 ou 9 (soma ponderada mod-11 = 0).\n *\n * @param cns — CNS com 15 dígitos\n * @returns true se o CNS é estruturalmente válido\n */\nexport function validateCNS(cns: string): boolean {\n const digits = digitsOnly(cns);\n\n if (digits.length !== 15) return false;\n\n const firstDigit = digits[0]!;\n\n // CNS deve começar com 1, 2 (definitivo) ou 7, 8, 9 (provisório)\n if (!['1', '2', '7', '8', '9'].includes(firstDigit)) return false;\n\n // Ambos os tipos usam soma ponderada mod-11 = 0\n let sum = 0;\n for (let i = 0; i < 15; i++) {\n sum += Number(digits[i]) * (15 - i);\n }\n return sum % 11 === 0;\n}\n\n/**\n * Formata um CPF como XXX.XXX.XXX-XX.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns CPF formatado ou a string original se inválido\n */\nexport function formatCPF(cpf: string): string {\n const digits = digitsOnly(cpf);\n if (digits.length !== 11) return cpf;\n return `${digits.slice(0, 3)}.${digits.slice(3, 6)}.${digits.slice(6, 9)}-${digits.slice(9)}`;\n}\n\n/**\n * Formata um CNS como XXX XXXX XXXX XXXX.\n *\n * @param cns — CNS com 15 dígitos\n * @returns CNS formatado ou a string original se inválido\n */\nexport function formatCNS(cns: string): string {\n const digits = digitsOnly(cns);\n if (digits.length !== 15) return cns;\n return `${digits.slice(0, 3)} ${digits.slice(3, 7)} ${digits.slice(7, 11)} ${digits.slice(11)}`;\n}\n\n/**\n * Converte um CPF para um FHIR Identifier.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns FHIR Identifier com sistema RNDS para CPF\n * @throws Error se o CPF for inválido\n */\nexport function cpfToFHIRIdentifier(cpf: string): FHIRIdentifier {\n if (!validateCPF(cpf)) {\n throw new Error('CPF inválido');\n }\n return {\n system: CPF_SYSTEM,\n use: 'official',\n value: digitsOnly(cpf),\n };\n}\n\n/**\n * Converte um CNS para um FHIR Identifier.\n *\n * @param cns — CNS com 15 dígitos\n * @returns FHIR Identifier com sistema RNDS para CNS\n * @throws Error se o CNS for inválido\n */\nexport function cnsToFHIRIdentifier(cns: string): FHIRIdentifier {\n if (!validateCNS(cns)) {\n throw new Error('CNS inválido');\n }\n return {\n system: CNS_SYSTEM,\n use: 'official',\n value: digitsOnly(cns),\n };\n}\n","/**\n * Código do tipo de amostra a partir do material impresso no laudo.\n *\n * O perfil `BRAmostraBiologica-1.0` da RNDS vincula `Specimen.type` ao ValueSet\n * `BRTipoAmostra-1.0` com força `required`, exige `type.coding` (1..1) e proíbe\n * `type.text` (0..0). Um `Specimen` só com o texto do laudo não passa, e é o que\n * a extração produzia.\n *\n * O ValueSet tem 63 códigos, e quase todos são de vigilância respiratória vindos\n * do GAL: swab nasofaríngeo, lavado brônquico, fragmento de órgão. Para laudo de\n * rotina sobram seis, e esses seis cobrem o que um painel de sangue e urina\n * imprime.\n *\n * Não há código para fezes no ValueSet. Isso não afeta a extração, cujo catálogo\n * não tem nenhum biomarcador de origem fecal: um parasitológico não vira\n * `Observation`, então não chega a pedir `Specimen`.\n *\n * @see https://rnds-fhir.saude.gov.br/StructureDefinition-BRAmostraBiologica-1.0.html\n * @see https://rnds-fhir.saude.gov.br/ValueSet-BRTipoAmostra-1.0.html\n */\nimport type { FHIRCoding } from './fhir-types';\n\n/** ValueSet ao qual `Specimen.type` está vinculado no `BRAmostraBiologica`. */\nexport const BR_TIPO_AMOSTRA_VALUESET = 'https://rnds-fhir.saude.gov.br/ValueSet/BRTipoAmostra-1.0';\n\n/**\n * CodeSystem dos códigos que este módulo emite.\n *\n * O ValueSet também inclui o `BRTipoAmostraGAL`, que traz \"Sangue\" e \"Sangue com\n * EDTA\" soltos. Ficaram de fora porque a URL canônica daquele CodeSystem não foi\n * confirmada na fonte, e código de terminologia não se deduz de slug. Material\n * assim cai no caminho de não mapeado até alguém abrir o IG e confirmar.\n */\nexport const HL7_SPECIMEN_TYPE_SYSTEM = 'http://terminology.hl7.org/CodeSystem/v2-0487';\n\n/**\n * Os `display` são cópia literal do ValueSet, com a caixa dele.\n *\n * A chave é o texto já normalizado, e por enquanto é só o próprio display. Não\n * há sinônimo inventado aqui: a extração copia o material verbatim do laudo, e a\n * lista de variações que os laboratórios de fato imprimem ainda não foi medida\n * (a captura de material entrou em produção em 05/09/2026). Variação real\n * observada entra depois, com o laudo que a produziu.\n */\nconst CODINGS: ReadonlyArray<{ code: string; display: string }> = [\n { code: 'SER', display: 'Soro' },\n { code: 'PLAS', display: 'Plasma' },\n { code: 'WB', display: 'Sangue Total' },\n { code: 'UR', display: 'Urina' },\n { code: 'CSF', display: 'Líquor' },\n { code: 'SAL', display: 'Saliva' },\n];\n\n/**\n * Caixa, acento e espaço sobrando não distinguem material.\n *\n * Só isso. Não separa `camelCase` nem troca barra por espaço, ao contrário do\n * normalizador de nomes de biomarcador: \"Soro/Plasma\" impresso numa linha só é\n * ambíguo de verdade, e escolher um dos dois seria inferência. Sem casar, ele\n * segue o caminho do não mapeado.\n *\n * Os caracteres invisíveis saem antes, e a divisão entre as duas regras é a do\n * próprio Unicode: `\\p{Cf}` são os de formatação, que não ocupam espaço e por\n * isso são apagados, e `\\s` são os de espaço, que são colapsados. A camada de\n * texto de PDF emite os dois tipos, e um U+200B no meio de \"Soro\" derruba o\n * casamento sem deixar rastro na tela.\n *\n * Vale a categoria em vez da lista porque a lista nunca fecha. Enumerando, o\n * hífen opcional (U+00AD) tinha ficado de fora, e ele aparece justamente onde\n * um nome composto como \"Sangue Total\" quebra de linha.\n */\nconst INVISIBLE = /\\p{Cf}/gu;\n\nconst normalize = (text: string): string =>\n text\n .replace(INVISIBLE, '')\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/\\s+/g, ' ')\n .trim();\n\nconst BY_NORMALIZED_TEXT = new Map(\n CODINGS.map(({ code, display }) => [\n normalize(display),\n { code, display, system: HL7_SPECIMEN_TYPE_SYSTEM } satisfies FHIRCoding,\n ]),\n);\n\n/**\n * Coding do ValueSet para o material impresso, ou `undefined` sem casar.\n *\n * `undefined` é resposta legítima e não erro: o laudo pode trazer um material\n * fora do ValueSet, ou uma grafia que ninguém viu ainda. Quem chama decide o que\n * fazer, e a decisão que não existe é preencher com um código aproximado.\n */\nexport const specimenTypeCoding = (text: string): FHIRCoding | undefined =>\n BY_NORMALIZED_TEXT.get(normalize(text));\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { I as InterventionData, A as Addressable, U as UserProfileData } from './converter-
|
|
2
|
-
export { F as Flag, G as Gender, L as LabObservationData, a as LabReportData, O as OverallStatus, l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-
|
|
1
|
+
import { I as InterventionData, A as Addressable, U as UserProfileData } from './converter-CO7q_s52.cjs';
|
|
2
|
+
export { B as BUNDLE_BASE_URL, F as Flag, G as Gender, L as LabObservationData, a as LabReportData, O as OverallStatus, e as entryFullUrl, l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-CO7q_s52.cjs';
|
|
3
3
|
export { BIOMARKER_DEFINITIONS, BiomarkerDefinition, BiomarkerSearchPattern, CAC_INDICATOR_CODES, DEXA_CATEGORIES, DEXA_INDICATOR_CODES, 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 } from './biomarkers.cjs';
|
|
4
4
|
export { BIOMARKER_DEFAULT_UNIT, BIOMARKER_UNITS, BiomarkerUnitConfig, ConversionResult, UNIT_TO_UCUM, convertUnit, getCanonicalUnit, getDefaultUnit, getSIUnit, unitToUCUM } from './units.cjs';
|
|
5
|
-
import { F as FHIRMedicationStatement, a as FHIRObservation, b as FHIRBundle, c as FHIRIdentifier } from './fhir-types-
|
|
6
|
-
export {
|
|
5
|
+
import { F as FHIRMedicationStatement, a as FHIRObservation, b as FHIRBundle, c as FHIRIdentifier, d as FHIRCoding } from './fhir-types-Bmvac6o0.cjs';
|
|
6
|
+
export { e as FHIRAddress, f as FHIRAnnotation, g as FHIRAttachment, h as FHIRBundleEntry, i as FHIRCodeableConcept, j as FHIRContactPoint, k as FHIRDiagnosticReport, l as FHIRHumanName, m as FHIRPatient, n as FHIRPeriod, o as FHIRQuantity, p as FHIRReference, q as FHIRReferenceRange } from './fhir-types-Bmvac6o0.cjs';
|
|
7
7
|
export { FHIRImportResult, ImportError, ImportedObservation, MAX_FILE_SIZE, MAX_OBSERVATIONS, SkippedEntry, extractObservationsFromBundle, mapFHIRObservationToInternal, processImportBundle } from './importer.cjs';
|
|
8
8
|
export { validateFHIRDiagnosticReport, validateFHIRImportBundle, validateFHIRObservation } from './validators.cjs';
|
|
9
9
|
export { BiomarkerRangeDefinition, BiomarkerReferenceRange, FastingRequirement, PregnancyTrimester, RangeDirection, RangeVariant, ReferenceRangeContext, SexKey, applyFallbackReferenceRanges, biomarkerRangeDefinitions, defaultReferenceRanges, getFallbackReferenceRange, getRangeDirection, getReferenceRange } from './reference-ranges.cjs';
|
|
@@ -267,4 +267,45 @@ declare function cpfToFHIRIdentifier(cpf: string): FHIRIdentifier;
|
|
|
267
267
|
*/
|
|
268
268
|
declare function cnsToFHIRIdentifier(cns: string): FHIRIdentifier;
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Código do tipo de amostra a partir do material impresso no laudo.
|
|
272
|
+
*
|
|
273
|
+
* O perfil `BRAmostraBiologica-1.0` da RNDS vincula `Specimen.type` ao ValueSet
|
|
274
|
+
* `BRTipoAmostra-1.0` com força `required`, exige `type.coding` (1..1) e proíbe
|
|
275
|
+
* `type.text` (0..0). Um `Specimen` só com o texto do laudo não passa, e é o que
|
|
276
|
+
* a extração produzia.
|
|
277
|
+
*
|
|
278
|
+
* O ValueSet tem 63 códigos, e quase todos são de vigilância respiratória vindos
|
|
279
|
+
* do GAL: swab nasofaríngeo, lavado brônquico, fragmento de órgão. Para laudo de
|
|
280
|
+
* rotina sobram seis, e esses seis cobrem o que um painel de sangue e urina
|
|
281
|
+
* imprime.
|
|
282
|
+
*
|
|
283
|
+
* Não há código para fezes no ValueSet. Isso não afeta a extração, cujo catálogo
|
|
284
|
+
* não tem nenhum biomarcador de origem fecal: um parasitológico não vira
|
|
285
|
+
* `Observation`, então não chega a pedir `Specimen`.
|
|
286
|
+
*
|
|
287
|
+
* @see https://rnds-fhir.saude.gov.br/StructureDefinition-BRAmostraBiologica-1.0.html
|
|
288
|
+
* @see https://rnds-fhir.saude.gov.br/ValueSet-BRTipoAmostra-1.0.html
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
/** ValueSet ao qual `Specimen.type` está vinculado no `BRAmostraBiologica`. */
|
|
292
|
+
declare const BR_TIPO_AMOSTRA_VALUESET = "https://rnds-fhir.saude.gov.br/ValueSet/BRTipoAmostra-1.0";
|
|
293
|
+
/**
|
|
294
|
+
* CodeSystem dos códigos que este módulo emite.
|
|
295
|
+
*
|
|
296
|
+
* O ValueSet também inclui o `BRTipoAmostraGAL`, que traz "Sangue" e "Sangue com
|
|
297
|
+
* EDTA" soltos. Ficaram de fora porque a URL canônica daquele CodeSystem não foi
|
|
298
|
+
* confirmada na fonte, e código de terminologia não se deduz de slug. Material
|
|
299
|
+
* assim cai no caminho de não mapeado até alguém abrir o IG e confirmar.
|
|
300
|
+
*/
|
|
301
|
+
declare const HL7_SPECIMEN_TYPE_SYSTEM = "http://terminology.hl7.org/CodeSystem/v2-0487";
|
|
302
|
+
/**
|
|
303
|
+
* Coding do ValueSet para o material impresso, ou `undefined` sem casar.
|
|
304
|
+
*
|
|
305
|
+
* `undefined` é resposta legítima e não erro: o laudo pode trazer um material
|
|
306
|
+
* fora do ValueSet, ou uma grafia que ninguém viu ainda. Quem chama decide o que
|
|
307
|
+
* fazer, e a decisão que não existe é preencher com um código aproximado.
|
|
308
|
+
*/
|
|
309
|
+
declare const specimenTypeCoding: (text: string) => FHIRCoding | undefined;
|
|
310
|
+
|
|
311
|
+
export { AGE_BRACKETS, Addressable, BIOMARKER_CODE_SYSTEM, BODY_FAT_ZONES, BR_TIPO_AMOSTRA_VALUESET, type BodyFatZone, CATEGORY_GROUPS, CATEGORY_SCREENING_INTERVALS, type CategoryGroup, type CategoryGroupInfo, type CategoryScreeningInterval, FHIRBundle, FHIRCoding, FHIRIdentifier, FHIRMedicationStatement, FHIRObservation, HL7_SPECIMEN_TYPE_SYSTEM, InterventionData, LOINC_SYSTEM, type ScreeningIntervalMonths, type TScoreZone, T_SCORE_ZONES, UserProfileData, ZONE_DEFS, calculateNextScreeningDate, cnsToFHIRIdentifier, cpfToFHIRIdentifier, formatCNS, formatCPF, getCategoriesByInterval, getCategoryGroup, getDaysUntilScreening, getDueCategories, getScreeningInterval, interventionToFHIRMedicationStatement, interventionToFHIRObservation, interventionsToFHIRBundle, isScreeningDue, listMappedSubcategories, plural, pluralCount, pluralPhrase, pluralPhraseCount, specimenTypeCoding, validateCNS, validateCPF };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { I as InterventionData, A as Addressable, U as UserProfileData } from './converter-
|
|
2
|
-
export { F as Flag, G as Gender, L as LabObservationData, a as LabReportData, O as OverallStatus, l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-
|
|
1
|
+
import { I as InterventionData, A as Addressable, U as UserProfileData } from './converter-x5Gcw-03.js';
|
|
2
|
+
export { B as BUNDLE_BASE_URL, F as Flag, G as Gender, L as LabObservationData, a as LabReportData, O as OverallStatus, e as entryFullUrl, l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-x5Gcw-03.js';
|
|
3
3
|
export { BIOMARKER_DEFINITIONS, BiomarkerDefinition, BiomarkerSearchPattern, CAC_INDICATOR_CODES, DEXA_CATEGORIES, DEXA_INDICATOR_CODES, 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 } from './biomarkers.js';
|
|
4
4
|
export { BIOMARKER_DEFAULT_UNIT, BIOMARKER_UNITS, BiomarkerUnitConfig, ConversionResult, UNIT_TO_UCUM, convertUnit, getCanonicalUnit, getDefaultUnit, getSIUnit, unitToUCUM } from './units.js';
|
|
5
|
-
import { F as FHIRMedicationStatement, a as FHIRObservation, b as FHIRBundle, c as FHIRIdentifier } from './fhir-types-
|
|
6
|
-
export {
|
|
5
|
+
import { F as FHIRMedicationStatement, a as FHIRObservation, b as FHIRBundle, c as FHIRIdentifier, d as FHIRCoding } from './fhir-types-Bmvac6o0.js';
|
|
6
|
+
export { e as FHIRAddress, f as FHIRAnnotation, g as FHIRAttachment, h as FHIRBundleEntry, i as FHIRCodeableConcept, j as FHIRContactPoint, k as FHIRDiagnosticReport, l as FHIRHumanName, m as FHIRPatient, n as FHIRPeriod, o as FHIRQuantity, p as FHIRReference, q as FHIRReferenceRange } from './fhir-types-Bmvac6o0.js';
|
|
7
7
|
export { FHIRImportResult, ImportError, ImportedObservation, MAX_FILE_SIZE, MAX_OBSERVATIONS, SkippedEntry, extractObservationsFromBundle, mapFHIRObservationToInternal, processImportBundle } from './importer.js';
|
|
8
8
|
export { validateFHIRDiagnosticReport, validateFHIRImportBundle, validateFHIRObservation } from './validators.js';
|
|
9
9
|
export { BiomarkerRangeDefinition, BiomarkerReferenceRange, FastingRequirement, PregnancyTrimester, RangeDirection, RangeVariant, ReferenceRangeContext, SexKey, applyFallbackReferenceRanges, biomarkerRangeDefinitions, defaultReferenceRanges, getFallbackReferenceRange, getRangeDirection, getReferenceRange } from './reference-ranges.js';
|
|
@@ -267,4 +267,45 @@ declare function cpfToFHIRIdentifier(cpf: string): FHIRIdentifier;
|
|
|
267
267
|
*/
|
|
268
268
|
declare function cnsToFHIRIdentifier(cns: string): FHIRIdentifier;
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Código do tipo de amostra a partir do material impresso no laudo.
|
|
272
|
+
*
|
|
273
|
+
* O perfil `BRAmostraBiologica-1.0` da RNDS vincula `Specimen.type` ao ValueSet
|
|
274
|
+
* `BRTipoAmostra-1.0` com força `required`, exige `type.coding` (1..1) e proíbe
|
|
275
|
+
* `type.text` (0..0). Um `Specimen` só com o texto do laudo não passa, e é o que
|
|
276
|
+
* a extração produzia.
|
|
277
|
+
*
|
|
278
|
+
* O ValueSet tem 63 códigos, e quase todos são de vigilância respiratória vindos
|
|
279
|
+
* do GAL: swab nasofaríngeo, lavado brônquico, fragmento de órgão. Para laudo de
|
|
280
|
+
* rotina sobram seis, e esses seis cobrem o que um painel de sangue e urina
|
|
281
|
+
* imprime.
|
|
282
|
+
*
|
|
283
|
+
* Não há código para fezes no ValueSet. Isso não afeta a extração, cujo catálogo
|
|
284
|
+
* não tem nenhum biomarcador de origem fecal: um parasitológico não vira
|
|
285
|
+
* `Observation`, então não chega a pedir `Specimen`.
|
|
286
|
+
*
|
|
287
|
+
* @see https://rnds-fhir.saude.gov.br/StructureDefinition-BRAmostraBiologica-1.0.html
|
|
288
|
+
* @see https://rnds-fhir.saude.gov.br/ValueSet-BRTipoAmostra-1.0.html
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
/** ValueSet ao qual `Specimen.type` está vinculado no `BRAmostraBiologica`. */
|
|
292
|
+
declare const BR_TIPO_AMOSTRA_VALUESET = "https://rnds-fhir.saude.gov.br/ValueSet/BRTipoAmostra-1.0";
|
|
293
|
+
/**
|
|
294
|
+
* CodeSystem dos códigos que este módulo emite.
|
|
295
|
+
*
|
|
296
|
+
* O ValueSet também inclui o `BRTipoAmostraGAL`, que traz "Sangue" e "Sangue com
|
|
297
|
+
* EDTA" soltos. Ficaram de fora porque a URL canônica daquele CodeSystem não foi
|
|
298
|
+
* confirmada na fonte, e código de terminologia não se deduz de slug. Material
|
|
299
|
+
* assim cai no caminho de não mapeado até alguém abrir o IG e confirmar.
|
|
300
|
+
*/
|
|
301
|
+
declare const HL7_SPECIMEN_TYPE_SYSTEM = "http://terminology.hl7.org/CodeSystem/v2-0487";
|
|
302
|
+
/**
|
|
303
|
+
* Coding do ValueSet para o material impresso, ou `undefined` sem casar.
|
|
304
|
+
*
|
|
305
|
+
* `undefined` é resposta legítima e não erro: o laudo pode trazer um material
|
|
306
|
+
* fora do ValueSet, ou uma grafia que ninguém viu ainda. Quem chama decide o que
|
|
307
|
+
* fazer, e a decisão que não existe é preencher com um código aproximado.
|
|
308
|
+
*/
|
|
309
|
+
declare const specimenTypeCoding: (text: string) => FHIRCoding | undefined;
|
|
310
|
+
|
|
311
|
+
export { AGE_BRACKETS, Addressable, BIOMARKER_CODE_SYSTEM, BODY_FAT_ZONES, BR_TIPO_AMOSTRA_VALUESET, type BodyFatZone, CATEGORY_GROUPS, CATEGORY_SCREENING_INTERVALS, type CategoryGroup, type CategoryGroupInfo, type CategoryScreeningInterval, FHIRBundle, FHIRCoding, FHIRIdentifier, FHIRMedicationStatement, FHIRObservation, HL7_SPECIMEN_TYPE_SYSTEM, InterventionData, LOINC_SYSTEM, type ScreeningIntervalMonths, type TScoreZone, T_SCORE_ZONES, UserProfileData, ZONE_DEFS, calculateNextScreeningDate, cnsToFHIRIdentifier, cpfToFHIRIdentifier, formatCNS, formatCPF, getCategoriesByInterval, getCategoryGroup, getDaysUntilScreening, getDueCategories, getScreeningInterval, interventionToFHIRMedicationStatement, interventionToFHIRObservation, interventionsToFHIRBundle, isScreeningDue, listMappedSubcategories, plural, pluralCount, pluralPhrase, pluralPhraseCount, specimenTypeCoding, validateCNS, validateCPF };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BUNDLE_BASE_URL,
|
|
2
3
|
entryFullUrl,
|
|
3
4
|
labObservationToFHIR,
|
|
4
5
|
labReportToFHIR,
|
|
5
6
|
labResultToFHIRBundle,
|
|
6
7
|
userProfileToFHIR
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NKA4JGNI.js";
|
|
8
9
|
import {
|
|
9
10
|
MAX_FILE_SIZE,
|
|
10
11
|
MAX_OBSERVATIONS,
|
|
@@ -602,6 +603,27 @@ function cnsToFHIRIdentifier(cns) {
|
|
|
602
603
|
value: digitsOnly(cns)
|
|
603
604
|
};
|
|
604
605
|
}
|
|
606
|
+
|
|
607
|
+
// src/specimen-types.ts
|
|
608
|
+
var BR_TIPO_AMOSTRA_VALUESET = "https://rnds-fhir.saude.gov.br/ValueSet/BRTipoAmostra-1.0";
|
|
609
|
+
var HL7_SPECIMEN_TYPE_SYSTEM = "http://terminology.hl7.org/CodeSystem/v2-0487";
|
|
610
|
+
var CODINGS = [
|
|
611
|
+
{ code: "SER", display: "Soro" },
|
|
612
|
+
{ code: "PLAS", display: "Plasma" },
|
|
613
|
+
{ code: "WB", display: "Sangue Total" },
|
|
614
|
+
{ code: "UR", display: "Urina" },
|
|
615
|
+
{ code: "CSF", display: "L\xEDquor" },
|
|
616
|
+
{ code: "SAL", display: "Saliva" }
|
|
617
|
+
];
|
|
618
|
+
var INVISIBLE = /\p{Cf}/gu;
|
|
619
|
+
var normalize = (text) => text.replace(INVISIBLE, "").normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
620
|
+
var BY_NORMALIZED_TEXT = new Map(
|
|
621
|
+
CODINGS.map(({ code, display }) => [
|
|
622
|
+
normalize(display),
|
|
623
|
+
{ code, display, system: HL7_SPECIMEN_TYPE_SYSTEM }
|
|
624
|
+
])
|
|
625
|
+
);
|
|
626
|
+
var specimenTypeCoding = (text) => BY_NORMALIZED_TEXT.get(normalize(text));
|
|
605
627
|
export {
|
|
606
628
|
AGE_BRACKETS,
|
|
607
629
|
BIOMARKER_CODE_SYSTEM,
|
|
@@ -609,11 +631,14 @@ export {
|
|
|
609
631
|
BIOMARKER_DEFINITIONS,
|
|
610
632
|
BIOMARKER_UNITS,
|
|
611
633
|
BODY_FAT_ZONES,
|
|
634
|
+
BR_TIPO_AMOSTRA_VALUESET,
|
|
635
|
+
BUNDLE_BASE_URL,
|
|
612
636
|
CAC_INDICATOR_CODES,
|
|
613
637
|
CATEGORY_GROUPS,
|
|
614
638
|
CATEGORY_SCREENING_INTERVALS,
|
|
615
639
|
DEXA_CATEGORIES,
|
|
616
640
|
DEXA_INDICATOR_CODES,
|
|
641
|
+
HL7_SPECIMEN_TYPE_SYSTEM,
|
|
617
642
|
LOINC_SYSTEM,
|
|
618
643
|
MAX_FILE_SIZE,
|
|
619
644
|
MAX_OBSERVATIONS,
|
|
@@ -628,6 +653,7 @@ export {
|
|
|
628
653
|
convertUnit,
|
|
629
654
|
cpfToFHIRIdentifier,
|
|
630
655
|
defaultReferenceRanges,
|
|
656
|
+
entryFullUrl,
|
|
631
657
|
extractObservationsFromBundle,
|
|
632
658
|
filterVisibleBiomarkers,
|
|
633
659
|
findCodeByName,
|
|
@@ -680,6 +706,7 @@ export {
|
|
|
680
706
|
pluralPhrase,
|
|
681
707
|
pluralPhraseCount,
|
|
682
708
|
processImportBundle,
|
|
709
|
+
specimenTypeCoding,
|
|
683
710
|
toBiomarkerTests,
|
|
684
711
|
unitToUCUM,
|
|
685
712
|
userProfileToFHIR,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/category-groups.ts","../src/intervention-converter.ts","../src/dexa-zone-data.ts","../src/screening-intervals.ts","../src/i18n.ts","../src/identifiers.ts"],"sourcesContent":["/**\n * Agrupamento de categorias clínicas em 10 grupos de alto nível.\n *\n * `BiomarkerDefinition.category` armazena 20 sub-categorias (granularidade\n * fina, ex: `tireoide`, `pancreas`). Este módulo agrupa essas\n * sub-categorias em 10 buckets clínicos amplos para apresentação no\n * site, na API pública e em material de divulgação.\n *\n * As sub-categorias permanecem como fonte da verdade nos dados; este\n * agrupamento é uma camada derivada.\n */\n\nexport type CategoryGroup =\n | 'cardiovascular'\n | 'metabolico-endocrino'\n | 'renal-eletrolitico'\n | 'hepatico-biliar'\n | 'hematologico'\n | 'imunologico'\n | 'oncologico'\n | 'nutricional-ambiental'\n | 'saude-reprodutiva'\n | 'composicao-envelhecimento';\n\nexport interface CategoryGroupInfo {\n /** Rótulo em inglês */\n en: string;\n /** Rótulo em português */\n pt: string;\n /** Slug (kebab-case, sem acento) */\n slug: CategoryGroup;\n /** Sub-categorias da fonte agrupadas neste bucket */\n subcategories: readonly string[];\n}\n\nexport const CATEGORY_GROUPS: Record<CategoryGroup, CategoryGroupInfo> = {\n cardiovascular: {\n en: 'Cardiovascular',\n pt: 'Cardiovascular',\n slug: 'cardiovascular',\n subcategories: ['coracao'],\n },\n 'composicao-envelhecimento': {\n en: 'Body Composition & Aging',\n pt: 'Composição Corporal e Envelhecimento',\n slug: 'composicao-envelhecimento',\n subcategories: ['composicao-corporal', 'densidade-ossea', 'estresse-envelhecimento'],\n },\n hematologico: {\n en: 'Hematology',\n pt: 'Hematológico',\n slug: 'hematologico',\n subcategories: ['sangue'],\n },\n 'hepatico-biliar': {\n en: 'Hepatic & Biliary',\n pt: 'Hepático e Biliar',\n slug: 'hepatico-biliar',\n subcategories: ['figado'],\n },\n imunologico: {\n en: 'Immunology',\n pt: 'Imunológico',\n slug: 'imunologico',\n subcategories: ['autoimunidade', 'regulacao-imunologica'],\n },\n 'metabolico-endocrino': {\n en: 'Metabolic & Endocrine',\n pt: 'Metabólico e Endócrino',\n slug: 'metabolico-endocrino',\n subcategories: ['metabolico', 'pancreas', 'hormonios', 'tireoide'],\n },\n 'nutricional-ambiental': {\n en: 'Nutrition & Environmental Exposure',\n pt: 'Nutricional e Exposição Ambiental',\n slug: 'nutricional-ambiental',\n subcategories: ['nutrientes', 'toxinas-ambientais'],\n },\n oncologico: {\n en: 'Oncology',\n pt: 'Oncológico',\n slug: 'oncologico',\n subcategories: ['marcadores-tumorais'],\n },\n 'renal-eletrolitico': {\n en: 'Renal & Electrolytes',\n pt: 'Renal e Eletrolítico',\n slug: 'renal-eletrolitico',\n subcategories: ['rins', 'urina', 'eletrolitos'],\n },\n 'saude-reprodutiva': {\n en: 'Reproductive Health',\n pt: 'Saúde Reprodutiva',\n slug: 'saude-reprodutiva',\n subcategories: ['saude-feminina', 'saude-masculina'],\n },\n};\n\nconst SUBCATEGORY_TO_GROUP = new Map<string, CategoryGroup>();\nfor (const group of Object.values(CATEGORY_GROUPS)) {\n for (const sub of group.subcategories) {\n SUBCATEGORY_TO_GROUP.set(sub, group.slug);\n }\n}\n\n/**\n * Resolve a sub-categoria (granular) para o grupo de alto nível (10 buckets).\n */\nexport function getCategoryGroup(subcategory: string): CategoryGroup | undefined {\n return SUBCATEGORY_TO_GROUP.get(subcategory);\n}\n\n/**\n * Lista todas as sub-categorias mapeadas em algum grupo.\n */\nexport function listMappedSubcategories(): readonly string[] {\n return [...SUBCATEGORY_TO_GROUP.keys()];\n}\n","/**\n * FHIR Intervention Converter\n *\n * Converts interventions (medication, supplement, diet, exercise, sleep)\n * to FHIR R4 MedicationStatement and Observation resources.\n */\n\nimport { type Addressable, entryFullUrl } from './bundle-urls';\nimport { userProfileToFHIR } from './converter';\nimport type { FHIRBundle, FHIRMedicationStatement, FHIRObservation } from './fhir-types';\nimport type { InterventionData, UserProfileData } from './types';\n\n/**\n * Determine MedicationStatement/Observation status based on end date\n */\nfunction interventionStatus(endDate?: string): 'active' | 'completed' {\n if (!endDate) return 'active';\n return new Date(endDate) < new Date() ? 'completed' : 'active';\n}\n\n/**\n * LOINC-like codes for lifestyle observation types\n */\nconst LIFESTYLE_CODES: Record<string, { code: string; display: string }> = {\n diet: { code: '81259-4', display: 'Diet' },\n exercise: { code: '73985-4', display: 'Exercise activity' },\n sleep: { code: '93832-4', display: 'Sleep duration' },\n};\n\n/**\n * Convert medication/supplement intervention to FHIR MedicationStatement\n */\nexport function interventionToFHIRMedicationStatement(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRMedicationStatement> {\n const statement: Addressable<FHIRMedicationStatement> = {\n category: {\n coding: [\n {\n code: 'patientspecified',\n display: 'Patient Specified',\n system: 'http://terminology.hl7.org/CodeSystem/medication-statement-category',\n },\n ],\n },\n dateAsserted: intervention.startDate,\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n medicationCodeableConcept: {\n text: intervention.name,\n },\n resourceType: 'MedicationStatement',\n status: interventionStatus(intervention.endDate),\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n if (intervention.notes) {\n statement.note = [{ text: intervention.notes }];\n }\n\n return statement;\n}\n\n/**\n * Convert diet/exercise/sleep intervention to FHIR Observation (social-history)\n */\nexport function interventionToFHIRObservation(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRObservation> {\n const lifestyleCode = LIFESTYLE_CODES[intervention.type];\n\n const observation: Addressable<FHIRObservation> = {\n category: [\n {\n coding: [\n {\n code: 'social-history',\n display: 'Social History',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: lifestyleCode\n ? [\n {\n code: lifestyleCode.code,\n display: lifestyleCode.display,\n system: 'http://loinc.org',\n },\n ]\n : [],\n text: intervention.name,\n },\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n valueString: intervention.name,\n };\n\n if (intervention.notes) {\n observation.note = [{ text: intervention.notes }];\n }\n\n return observation;\n}\n\n/**\n * Convert all interventions to a FHIR Bundle\n */\nexport function interventionsToFHIRBundle(\n interventions: InterventionData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n const fhirPatient = userProfileToFHIR(userProfile);\n\n const entries = interventions.map((intervention) => {\n const isMedication = intervention.type === 'medication' || intervention.type === 'supplement';\n const resource = isMedication\n ? interventionToFHIRMedicationStatement(intervention, patientId)\n : interventionToFHIRObservation(intervention, patientId);\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n return {\n entry: [{ fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient }, ...entries],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n","/**\n * Structured zone data for DEXA body composition and bone density charts.\n *\n * Body fat zones derived from Gallagher et al. Am J Clin Nutr 2000;72:694-701 (PMID: 10966886)\n * and ACSM Guidelines for Exercise Testing, 11th Ed (2021).\n *\n * T-Score zones from WHO criteria (Kanis JA, Osteoporos Int, PMID: 7696835).\n */\n\nexport interface BodyFatZone {\n ageMax: number;\n ageMin: number;\n color: string;\n fatPctMax: number;\n fatPctMin: number;\n label: string;\n sex: 'F' | 'M';\n}\n\ninterface AgeBracket {\n ageMax: number;\n ageMin: number;\n label: string;\n}\n\nconst AGE_BRACKETS: AgeBracket[] = [\n { ageMax: 25, ageMin: 18, label: '18-25' },\n { ageMax: 35, ageMin: 26, label: '26-35' },\n { ageMax: 45, ageMin: 36, label: '36-45' },\n { ageMax: 55, ageMin: 46, label: '46-55' },\n { ageMax: 99, ageMin: 56, label: '56+' },\n];\n\n// Zone boundaries per age bracket for men: [essential, athletic, fitness, average, obese]\n// Each value is the upper bound of the zone\nconst MALE_ZONES: number[][] = [\n [5, 10, 20, 25, 40],\n [5, 11, 21, 26, 40],\n [5, 12, 22, 27, 40],\n [5, 13, 23, 28, 40],\n [5, 14, 24, 29, 40],\n];\n\nconst FEMALE_ZONES: number[][] = [\n [13, 18, 28, 32, 45],\n [13, 18, 29, 33, 45],\n [13, 19, 30, 34, 45],\n [13, 20, 31, 35, 45],\n [13, 20, 32, 36, 45],\n];\n\ninterface ZoneDefinition {\n color: string;\n label: string;\n}\n\nconst ZONE_DEFS: ZoneDefinition[] = [\n { color: '#3b82f6', label: 'Essencial' },\n { color: '#06b6d4', label: 'Atlético' },\n { color: '#22c55e', label: 'Fitness' },\n { color: '#eab308', label: 'Média' },\n { color: '#ef4444', label: 'Obeso' },\n];\n\nfunction buildZones(sex: 'F' | 'M', zoneData: number[][]): BodyFatZone[] {\n const zones: BodyFatZone[] = [];\n for (let i = 0; i < AGE_BRACKETS.length; i++) {\n const bracket = AGE_BRACKETS[i]!;\n const b = zoneData[i]!;\n zones.push({\n ...bracket,\n color: ZONE_DEFS[0]!.color,\n fatPctMax: b[0]!,\n fatPctMin: 0,\n label: ZONE_DEFS[0]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[1]!.color,\n fatPctMax: b[1]!,\n fatPctMin: b[0]!,\n label: ZONE_DEFS[1]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[2]!.color,\n fatPctMax: b[2]!,\n fatPctMin: b[1]!,\n label: ZONE_DEFS[2]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[3]!.color,\n fatPctMax: b[3]!,\n fatPctMin: b[2]!,\n label: ZONE_DEFS[3]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[4]!.color,\n fatPctMax: b[4]!,\n fatPctMin: b[3]!,\n label: ZONE_DEFS[4]!.label,\n sex,\n });\n }\n return zones;\n}\n\nexport const BODY_FAT_ZONES: BodyFatZone[] = [\n ...buildZones('M', MALE_ZONES),\n ...buildZones('F', FEMALE_ZONES),\n];\n\nexport { AGE_BRACKETS, ZONE_DEFS };\n\nexport interface TScoreZone {\n color: string;\n label: string;\n max: number;\n min: number;\n}\n\nexport const T_SCORE_ZONES: TScoreZone[] = [\n { color: '#22c55e', label: 'Normal', max: 4, min: -1.0 },\n { color: '#eab308', label: 'Osteopenia', max: -1.0, min: -2.5 },\n { color: '#ef4444', label: 'Osteoporose', max: -2.5, min: -5 },\n];\n","/**\n * Screening Intervals Configuration\n *\n * Defines recommended screening intervals for different biomarker categories\n * based on clinical guidelines and best practices.\n */\n\n/**\n * Screening interval in months\n */\nexport type ScreeningIntervalMonths = 3 | 6 | 12;\n\n/**\n * Biomarker category with its recommended screening interval\n */\nexport interface CategoryScreeningInterval {\n category: string;\n intervalMonths: ScreeningIntervalMonths;\n nameEn: string;\n namePt: string;\n}\n\n/**\n * Screening interval configuration for each category\n *\n * Categories are grouped by their recommended screening intervals:\n * - 3 months: Body composition and bone density (frequently changing metrics)\n * - 6 months: Metabolic panel and nutrients (moderate change rate)\n * - 12 months: Standard blood panels (stable long-term markers)\n */\nexport const CATEGORY_SCREENING_INTERVALS: CategoryScreeningInterval[] = [\n // 3-month intervals - Body composition (frequently changing)\n {\n category: 'composicao-corporal',\n intervalMonths: 3,\n nameEn: 'Body Composition',\n namePt: 'Composição Corporal',\n },\n {\n category: 'densidade-ossea',\n intervalMonths: 3,\n nameEn: 'Bone Density',\n namePt: 'Densidade Óssea',\n },\n\n // 6-month intervals - Metabolic and nutrients\n {\n category: 'metabolico',\n intervalMonths: 6,\n nameEn: 'Metabolic Panel',\n namePt: 'Painel Metabólico',\n },\n {\n category: 'nutrientes',\n intervalMonths: 6,\n nameEn: 'Nutrients',\n namePt: 'Nutrientes',\n },\n {\n category: 'pancreas',\n intervalMonths: 6,\n nameEn: 'Pancreas',\n namePt: 'Pâncreas',\n },\n\n // 12-month intervals - Standard blood panels\n {\n category: 'coracao',\n intervalMonths: 12,\n nameEn: 'Heart Health',\n namePt: 'Saúde Cardiovascular',\n },\n {\n category: 'tireoide',\n intervalMonths: 12,\n nameEn: 'Thyroid',\n namePt: 'Tireoide',\n },\n {\n category: 'sangue',\n intervalMonths: 12,\n nameEn: 'Blood Count',\n namePt: 'Hemograma',\n },\n {\n category: 'figado',\n intervalMonths: 12,\n nameEn: 'Liver Function',\n namePt: 'Função Hepática',\n },\n {\n category: 'rins',\n intervalMonths: 12,\n nameEn: 'Kidney Function',\n namePt: 'Função Renal',\n },\n {\n category: 'saude-feminina',\n intervalMonths: 12,\n nameEn: \"Women's Health\",\n namePt: 'Saúde Feminina',\n },\n {\n category: 'saude-masculina',\n intervalMonths: 12,\n nameEn: \"Men's Health\",\n namePt: 'Saúde Masculina',\n },\n {\n category: 'eletrolitos',\n intervalMonths: 12,\n nameEn: 'Electrolytes',\n namePt: 'Eletrólitos',\n },\n {\n category: 'estresse-envelhecimento',\n intervalMonths: 12,\n nameEn: 'Stress & Aging',\n namePt: 'Estresse e Envelhecimento',\n },\n {\n category: 'autoimunidade',\n intervalMonths: 12,\n nameEn: 'Autoimmunity',\n namePt: 'Autoimunidade',\n },\n {\n category: 'regulacao-imunologica',\n intervalMonths: 12,\n nameEn: 'Immune Regulation',\n namePt: 'Regulação Imunológica',\n },\n {\n category: 'toxinas-ambientais',\n intervalMonths: 12,\n nameEn: 'Environmental Toxins',\n namePt: 'Toxinas Ambientais',\n },\n {\n category: 'urina',\n intervalMonths: 12,\n nameEn: 'Urinalysis',\n namePt: 'Urina',\n },\n];\n\n/**\n * Get screening interval for a category\n */\nexport const getScreeningInterval = (category: string): CategoryScreeningInterval | undefined => {\n return CATEGORY_SCREENING_INTERVALS.find((c) => c.category === category);\n};\n\n/**\n * Get all categories with a specific interval\n */\nexport const getCategoriesByInterval = (\n intervalMonths: ScreeningIntervalMonths,\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((c) => c.intervalMonths === intervalMonths);\n};\n\n/**\n * Calculate next screening date based on last test date and category\n */\nexport const calculateNextScreeningDate = (lastTestDate: Date, category: string): Date | null => {\n const interval = getScreeningInterval(category);\n if (!interval) return null;\n\n const nextDate = new Date(lastTestDate);\n nextDate.setMonth(nextDate.getMonth() + interval.intervalMonths);\n return nextDate;\n};\n\n/**\n * Check if a category is due for screening\n */\nexport const isScreeningDue = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): boolean => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return false;\n return referenceDate >= nextDate;\n};\n\n/**\n * Get categories that are due for screening based on last test dates\n */\nexport const getDueCategories = (\n lastTestDates: Record<string, Date>,\n referenceDate: Date = new Date(),\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((interval) => {\n const lastDate = lastTestDates[interval.category];\n if (!lastDate) return true; // Never tested = due\n return isScreeningDue(lastDate, interval.category, referenceDate);\n });\n};\n\n/**\n * Get days until next screening for a category\n */\nexport const getDaysUntilScreening = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): number | null => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return null;\n\n const diffTime = nextDate.getTime() - referenceDate.getTime();\n return Math.ceil(diffTime / (1000 * 60 * 60 * 24));\n};\n","/**\n * Portuguese pluralization utility using native Intl.PluralRules\n * Provides automatic pluralization for common words used in the app\n */\n\nconst pluralRules = new Intl.PluralRules('pt-BR');\n\n/**\n * Dictionary of Portuguese words with their plural forms\n * Key is the singular form, value is the plural form\n */\nconst dictionary: Record<string, string> = {\n // Common nouns\n arquivo: 'arquivos',\n biomarcador: 'biomarcadores',\n // Past participles (masculine)\n cadastrado: 'cadastrados',\n // Past participles (feminine)\n concluída: 'concluídas',\n confirmado: 'confirmados',\n convertido: 'convertidos',\n convidado: 'convidados',\n convite: 'convites',\n disponível: 'disponíveis',\n documento: 'documentos',\n enviado: 'enviados',\n exame: 'exames',\n excluída: 'excluídas',\n\n excluído: 'excluídos',\n // Verbs (3rd person)\n falhou: 'falharam',\n falta: 'faltam',\n ignorado: 'ignorados',\n item: 'itens',\n outro: 'outros',\n página: 'páginas',\n pendente: 'pendentes',\n registro: 'registros',\n removido: 'removidos',\n\n resultado: 'resultados',\n revisão: 'revisões',\n\n revogado: 'revogados',\n usuário: 'usuários',\n};\n\n/**\n * Get the plural form of a word from the dictionary\n * Falls back to adding 's' if word is not in dictionary\n */\nconst getPluralForm = (singular: string): string => {\n return dictionary[singular] ?? `${singular}s`;\n};\n\n/**\n * Returns the correct singular or plural form based on count\n * Uses Intl.PluralRules for proper locale-aware pluralization\n *\n * @example\n * plural(1, 'usuário') // 'usuário'\n * plural(3, 'usuário') // 'usuários'\n * plural(0, 'registro') // 'registros'\n */\nexport const plural = (count: number, word: string): string => {\n const rule = pluralRules.select(count);\n return rule === 'one' ? word : getPluralForm(word);\n};\n\n/**\n * Returns count with the correct singular or plural form\n *\n * @example\n * pluralCount(1, 'usuário') // '1 usuário'\n * pluralCount(3, 'usuário') // '3 usuários'\n */\nexport const pluralCount = (count: number, word: string): string => {\n return `${count} ${plural(count, word)}`;\n};\n\n/**\n * Returns the correct form for compound phrases (noun + adjective)\n * Both words are pluralized together\n *\n * @example\n * pluralPhrase(1, 'usuário', 'cadastrado') // 'usuário cadastrado'\n * pluralPhrase(3, 'usuário', 'cadastrado') // 'usuários cadastrados'\n * pluralPhrase(2, 'revisão', 'excluída') // 'revisões excluídas'\n */\nexport const pluralPhrase = (count: number, noun: string, adjective: string): string => {\n const rule = pluralRules.select(count);\n if (rule === 'one') {\n return `${noun} ${adjective}`;\n }\n return `${getPluralForm(noun)} ${getPluralForm(adjective)}`;\n};\n\n/**\n * Returns count with the correct compound phrase form\n *\n * @example\n * pluralPhraseCount(1, 'usuário', 'cadastrado') // '1 usuário cadastrado'\n * pluralPhraseCount(3, 'convite', 'enviado') // '3 convites enviados'\n */\nexport const pluralPhraseCount = (count: number, noun: string, adjective: string): string => {\n return `${count} ${pluralPhrase(count, noun, adjective)}`;\n};\n","/**\n * Helpers para identificadores brasileiros — CPF e CNS\n *\n * Validação, formatação e conversão para FHIR Identifier.\n * Algoritmos de validação baseados nas especificações oficiais:\n * - CPF: Receita Federal (mod-11, dois dígitos verificadores)\n * - CNS: Ministério da Saúde (mod-11 para definitivos, soma ponderada para provisórios)\n */\n\nimport type { FHIRIdentifier } from './fhir-types';\n\nconst CPF_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cpf';\nconst CNS_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cns';\n\n/**\n * Remove caracteres não-numéricos de uma string.\n */\nfunction digitsOnly(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Valida um CPF brasileiro usando algoritmo mod-11.\n *\n * @param cpf — CPF com ou sem formatação (ex: \"123.456.789-09\" ou \"12345678909\")\n * @returns true se o CPF é estruturalmente válido\n */\nexport function validateCPF(cpf: string): boolean {\n const digits = digitsOnly(cpf);\n\n if (digits.length !== 11) return false;\n\n // Rejeitar sequências de dígitos iguais (ex: 111.111.111-11)\n if (/^(\\d)\\1{10}$/.test(digits)) return false;\n\n // Primeiro dígito verificador\n let sum = 0;\n for (let i = 0; i < 9; i++) {\n sum += Number(digits[i]) * (10 - i);\n }\n let remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[9])) return false;\n\n // Segundo dígito verificador\n sum = 0;\n for (let i = 0; i < 10; i++) {\n sum += Number(digits[i]) * (11 - i);\n }\n remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[10])) return false;\n\n return true;\n}\n\n/**\n * Valida um CNS (Cartão Nacional de Saúde) brasileiro.\n *\n * CNS definitivos começam com 1 ou 2 (mod-11).\n * CNS provisórios começam com 7, 8 ou 9 (soma ponderada mod-11 = 0).\n *\n * @param cns — CNS com 15 dígitos\n * @returns true se o CNS é estruturalmente válido\n */\nexport function validateCNS(cns: string): boolean {\n const digits = digitsOnly(cns);\n\n if (digits.length !== 15) return false;\n\n const firstDigit = digits[0]!;\n\n // CNS deve começar com 1, 2 (definitivo) ou 7, 8, 9 (provisório)\n if (!['1', '2', '7', '8', '9'].includes(firstDigit)) return false;\n\n // Ambos os tipos usam soma ponderada mod-11 = 0\n let sum = 0;\n for (let i = 0; i < 15; i++) {\n sum += Number(digits[i]) * (15 - i);\n }\n return sum % 11 === 0;\n}\n\n/**\n * Formata um CPF como XXX.XXX.XXX-XX.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns CPF formatado ou a string original se inválido\n */\nexport function formatCPF(cpf: string): string {\n const digits = digitsOnly(cpf);\n if (digits.length !== 11) return cpf;\n return `${digits.slice(0, 3)}.${digits.slice(3, 6)}.${digits.slice(6, 9)}-${digits.slice(9)}`;\n}\n\n/**\n * Formata um CNS como XXX XXXX XXXX XXXX.\n *\n * @param cns — CNS com 15 dígitos\n * @returns CNS formatado ou a string original se inválido\n */\nexport function formatCNS(cns: string): string {\n const digits = digitsOnly(cns);\n if (digits.length !== 15) return cns;\n return `${digits.slice(0, 3)} ${digits.slice(3, 7)} ${digits.slice(7, 11)} ${digits.slice(11)}`;\n}\n\n/**\n * Converte um CPF para um FHIR Identifier.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns FHIR Identifier com sistema RNDS para CPF\n * @throws Error se o CPF for inválido\n */\nexport function cpfToFHIRIdentifier(cpf: string): FHIRIdentifier {\n if (!validateCPF(cpf)) {\n throw new Error('CPF inválido');\n }\n return {\n system: CPF_SYSTEM,\n use: 'official',\n value: digitsOnly(cpf),\n };\n}\n\n/**\n * Converte um CNS para um FHIR Identifier.\n *\n * @param cns — CNS com 15 dígitos\n * @returns FHIR Identifier com sistema RNDS para CNS\n * @throws Error se o CNS for inválido\n */\nexport function cnsToFHIRIdentifier(cns: string): FHIRIdentifier {\n if (!validateCNS(cns)) {\n throw new Error('CNS inválido');\n }\n return {\n system: CNS_SYSTEM,\n use: 'official',\n value: digitsOnly(cns),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCO,IAAM,kBAA4D;AAAA,EACvE,gBAAgB;AAAA,IACd,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,eAAe,CAAC,SAAS;AAAA,EAC3B;AAAA,EACA,6BAA6B;AAAA,IAC3B,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,eAAe,CAAC,uBAAuB,mBAAmB,yBAAyB;AAAA,EACrF;AAAA,EACA,cAAc;AAAA,IACZ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,eAAe,CAAC,QAAQ;AA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AAI,QAAO;AACjC,SAAO,GAAG,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC;AAC7F;AAQO,SAAS,UAAU,KAAqB;AAC7C,QAAM,SAAS,WAAW,GAAG;AAC7B,MAAI,OAAO,WAAW,GAAI,QAAO;AACjC,SAAO,GAAG,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,GAAG,EAAE,CAAC,IAAI,OAAO,MAAM,EAAE,CAAC;AAC/F;AASO,SAAS,oBAAoB,KAA6B;AAC/D,MAAI,CAAC,YAAY,GAAG,GAAG;AACrB,UAAM,IAAI,MAAM,iBAAc;AAAA,EAChC;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,OAAO,WAAW,GAAG;AAAA,EACvB;AACF;AASO,SAAS,oBAAoB,KAA6B;AAC/D,MAAI,CAAC,YAAY,GAAG,GAAG;AACrB,UAAM,IAAI,MAAM,iBAAc;AAAA,EAChC;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,OAAO,WAAW,GAAG;AAAA,EACvB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/category-groups.ts","../src/intervention-converter.ts","../src/dexa-zone-data.ts","../src/screening-intervals.ts","../src/i18n.ts","../src/identifiers.ts","../src/specimen-types.ts"],"sourcesContent":["/**\n * Agrupamento de categorias clínicas em 10 grupos de alto nível.\n *\n * `BiomarkerDefinition.category` armazena 20 sub-categorias (granularidade\n * fina, ex: `tireoide`, `pancreas`). Este módulo agrupa essas\n * sub-categorias em 10 buckets clínicos amplos para apresentação no\n * site, na API pública e em material de divulgação.\n *\n * As sub-categorias permanecem como fonte da verdade nos dados; este\n * agrupamento é uma camada derivada.\n */\n\nexport type CategoryGroup =\n | 'cardiovascular'\n | 'metabolico-endocrino'\n | 'renal-eletrolitico'\n | 'hepatico-biliar'\n | 'hematologico'\n | 'imunologico'\n | 'oncologico'\n | 'nutricional-ambiental'\n | 'saude-reprodutiva'\n | 'composicao-envelhecimento';\n\nexport interface CategoryGroupInfo {\n /** Rótulo em inglês */\n en: string;\n /** Rótulo em português */\n pt: string;\n /** Slug (kebab-case, sem acento) */\n slug: CategoryGroup;\n /** Sub-categorias da fonte agrupadas neste bucket */\n subcategories: readonly string[];\n}\n\nexport const CATEGORY_GROUPS: Record<CategoryGroup, CategoryGroupInfo> = {\n cardiovascular: {\n en: 'Cardiovascular',\n pt: 'Cardiovascular',\n slug: 'cardiovascular',\n subcategories: ['coracao'],\n },\n 'composicao-envelhecimento': {\n en: 'Body Composition & Aging',\n pt: 'Composição Corporal e Envelhecimento',\n slug: 'composicao-envelhecimento',\n subcategories: ['composicao-corporal', 'densidade-ossea', 'estresse-envelhecimento'],\n },\n hematologico: {\n en: 'Hematology',\n pt: 'Hematológico',\n slug: 'hematologico',\n subcategories: ['sangue'],\n },\n 'hepatico-biliar': {\n en: 'Hepatic & Biliary',\n pt: 'Hepático e Biliar',\n slug: 'hepatico-biliar',\n subcategories: ['figado'],\n },\n imunologico: {\n en: 'Immunology',\n pt: 'Imunológico',\n slug: 'imunologico',\n subcategories: ['autoimunidade', 'regulacao-imunologica'],\n },\n 'metabolico-endocrino': {\n en: 'Metabolic & Endocrine',\n pt: 'Metabólico e Endócrino',\n slug: 'metabolico-endocrino',\n subcategories: ['metabolico', 'pancreas', 'hormonios', 'tireoide'],\n },\n 'nutricional-ambiental': {\n en: 'Nutrition & Environmental Exposure',\n pt: 'Nutricional e Exposição Ambiental',\n slug: 'nutricional-ambiental',\n subcategories: ['nutrientes', 'toxinas-ambientais'],\n },\n oncologico: {\n en: 'Oncology',\n pt: 'Oncológico',\n slug: 'oncologico',\n subcategories: ['marcadores-tumorais'],\n },\n 'renal-eletrolitico': {\n en: 'Renal & Electrolytes',\n pt: 'Renal e Eletrolítico',\n slug: 'renal-eletrolitico',\n subcategories: ['rins', 'urina', 'eletrolitos'],\n },\n 'saude-reprodutiva': {\n en: 'Reproductive Health',\n pt: 'Saúde Reprodutiva',\n slug: 'saude-reprodutiva',\n subcategories: ['saude-feminina', 'saude-masculina'],\n },\n};\n\nconst SUBCATEGORY_TO_GROUP = new Map<string, CategoryGroup>();\nfor (const group of Object.values(CATEGORY_GROUPS)) {\n for (const sub of group.subcategories) {\n SUBCATEGORY_TO_GROUP.set(sub, group.slug);\n }\n}\n\n/**\n * Resolve a sub-categoria (granular) para o grupo de alto nível (10 buckets).\n */\nexport function getCategoryGroup(subcategory: string): CategoryGroup | undefined {\n return SUBCATEGORY_TO_GROUP.get(subcategory);\n}\n\n/**\n * Lista todas as sub-categorias mapeadas em algum grupo.\n */\nexport function listMappedSubcategories(): readonly string[] {\n return [...SUBCATEGORY_TO_GROUP.keys()];\n}\n","/**\n * FHIR Intervention Converter\n *\n * Converts interventions (medication, supplement, diet, exercise, sleep)\n * to FHIR R4 MedicationStatement and Observation resources.\n */\n\nimport { type Addressable, entryFullUrl } from './bundle-urls';\nimport { userProfileToFHIR } from './converter';\nimport type { FHIRBundle, FHIRMedicationStatement, FHIRObservation } from './fhir-types';\nimport type { InterventionData, UserProfileData } from './types';\n\n/**\n * Determine MedicationStatement/Observation status based on end date\n */\nfunction interventionStatus(endDate?: string): 'active' | 'completed' {\n if (!endDate) return 'active';\n return new Date(endDate) < new Date() ? 'completed' : 'active';\n}\n\n/**\n * LOINC-like codes for lifestyle observation types\n */\nconst LIFESTYLE_CODES: Record<string, { code: string; display: string }> = {\n diet: { code: '81259-4', display: 'Diet' },\n exercise: { code: '73985-4', display: 'Exercise activity' },\n sleep: { code: '93832-4', display: 'Sleep duration' },\n};\n\n/**\n * Convert medication/supplement intervention to FHIR MedicationStatement\n */\nexport function interventionToFHIRMedicationStatement(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRMedicationStatement> {\n const statement: Addressable<FHIRMedicationStatement> = {\n category: {\n coding: [\n {\n code: 'patientspecified',\n display: 'Patient Specified',\n system: 'http://terminology.hl7.org/CodeSystem/medication-statement-category',\n },\n ],\n },\n dateAsserted: intervention.startDate,\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n medicationCodeableConcept: {\n text: intervention.name,\n },\n resourceType: 'MedicationStatement',\n status: interventionStatus(intervention.endDate),\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n if (intervention.notes) {\n statement.note = [{ text: intervention.notes }];\n }\n\n return statement;\n}\n\n/**\n * Convert diet/exercise/sleep intervention to FHIR Observation (social-history)\n */\nexport function interventionToFHIRObservation(\n intervention: InterventionData,\n patientId: string,\n): Addressable<FHIRObservation> {\n const lifestyleCode = LIFESTYLE_CODES[intervention.type];\n\n const observation: Addressable<FHIRObservation> = {\n category: [\n {\n coding: [\n {\n code: 'social-history',\n display: 'Social History',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: lifestyleCode\n ? [\n {\n code: lifestyleCode.code,\n display: lifestyleCode.display,\n system: 'http://loinc.org',\n },\n ]\n : [],\n text: intervention.name,\n },\n effectivePeriod: {\n end: intervention.endDate,\n start: intervention.startDate,\n },\n id: `intervention-${intervention.interventionId}`,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n valueString: intervention.name,\n };\n\n if (intervention.notes) {\n observation.note = [{ text: intervention.notes }];\n }\n\n return observation;\n}\n\n/**\n * Convert all interventions to a FHIR Bundle\n */\nexport function interventionsToFHIRBundle(\n interventions: InterventionData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n const fhirPatient = userProfileToFHIR(userProfile);\n\n const entries = interventions.map((intervention) => {\n const isMedication = intervention.type === 'medication' || intervention.type === 'supplement';\n const resource = isMedication\n ? interventionToFHIRMedicationStatement(intervention, patientId)\n : interventionToFHIRObservation(intervention, patientId);\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n return {\n entry: [{ fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient }, ...entries],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n","/**\n * Structured zone data for DEXA body composition and bone density charts.\n *\n * Body fat zones derived from Gallagher et al. Am J Clin Nutr 2000;72:694-701 (PMID: 10966886)\n * and ACSM Guidelines for Exercise Testing, 11th Ed (2021).\n *\n * T-Score zones from WHO criteria (Kanis JA, Osteoporos Int, PMID: 7696835).\n */\n\nexport interface BodyFatZone {\n ageMax: number;\n ageMin: number;\n color: string;\n fatPctMax: number;\n fatPctMin: number;\n label: string;\n sex: 'F' | 'M';\n}\n\ninterface AgeBracket {\n ageMax: number;\n ageMin: number;\n label: string;\n}\n\nconst AGE_BRACKETS: AgeBracket[] = [\n { ageMax: 25, ageMin: 18, label: '18-25' },\n { ageMax: 35, ageMin: 26, label: '26-35' },\n { ageMax: 45, ageMin: 36, label: '36-45' },\n { ageMax: 55, ageMin: 46, label: '46-55' },\n { ageMax: 99, ageMin: 56, label: '56+' },\n];\n\n// Zone boundaries per age bracket for men: [essential, athletic, fitness, average, obese]\n// Each value is the upper bound of the zone\nconst MALE_ZONES: number[][] = [\n [5, 10, 20, 25, 40],\n [5, 11, 21, 26, 40],\n [5, 12, 22, 27, 40],\n [5, 13, 23, 28, 40],\n [5, 14, 24, 29, 40],\n];\n\nconst FEMALE_ZONES: number[][] = [\n [13, 18, 28, 32, 45],\n [13, 18, 29, 33, 45],\n [13, 19, 30, 34, 45],\n [13, 20, 31, 35, 45],\n [13, 20, 32, 36, 45],\n];\n\ninterface ZoneDefinition {\n color: string;\n label: string;\n}\n\nconst ZONE_DEFS: ZoneDefinition[] = [\n { color: '#3b82f6', label: 'Essencial' },\n { color: '#06b6d4', label: 'Atlético' },\n { color: '#22c55e', label: 'Fitness' },\n { color: '#eab308', label: 'Média' },\n { color: '#ef4444', label: 'Obeso' },\n];\n\nfunction buildZones(sex: 'F' | 'M', zoneData: number[][]): BodyFatZone[] {\n const zones: BodyFatZone[] = [];\n for (let i = 0; i < AGE_BRACKETS.length; i++) {\n const bracket = AGE_BRACKETS[i]!;\n const b = zoneData[i]!;\n zones.push({\n ...bracket,\n color: ZONE_DEFS[0]!.color,\n fatPctMax: b[0]!,\n fatPctMin: 0,\n label: ZONE_DEFS[0]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[1]!.color,\n fatPctMax: b[1]!,\n fatPctMin: b[0]!,\n label: ZONE_DEFS[1]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[2]!.color,\n fatPctMax: b[2]!,\n fatPctMin: b[1]!,\n label: ZONE_DEFS[2]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[3]!.color,\n fatPctMax: b[3]!,\n fatPctMin: b[2]!,\n label: ZONE_DEFS[3]!.label,\n sex,\n });\n zones.push({\n ...bracket,\n color: ZONE_DEFS[4]!.color,\n fatPctMax: b[4]!,\n fatPctMin: b[3]!,\n label: ZONE_DEFS[4]!.label,\n sex,\n });\n }\n return zones;\n}\n\nexport const BODY_FAT_ZONES: BodyFatZone[] = [\n ...buildZones('M', MALE_ZONES),\n ...buildZones('F', FEMALE_ZONES),\n];\n\nexport { AGE_BRACKETS, ZONE_DEFS };\n\nexport interface TScoreZone {\n color: string;\n label: string;\n max: number;\n min: number;\n}\n\nexport const T_SCORE_ZONES: TScoreZone[] = [\n { color: '#22c55e', label: 'Normal', max: 4, min: -1.0 },\n { color: '#eab308', label: 'Osteopenia', max: -1.0, min: -2.5 },\n { color: '#ef4444', label: 'Osteoporose', max: -2.5, min: -5 },\n];\n","/**\n * Screening Intervals Configuration\n *\n * Defines recommended screening intervals for different biomarker categories\n * based on clinical guidelines and best practices.\n */\n\n/**\n * Screening interval in months\n */\nexport type ScreeningIntervalMonths = 3 | 6 | 12;\n\n/**\n * Biomarker category with its recommended screening interval\n */\nexport interface CategoryScreeningInterval {\n category: string;\n intervalMonths: ScreeningIntervalMonths;\n nameEn: string;\n namePt: string;\n}\n\n/**\n * Screening interval configuration for each category\n *\n * Categories are grouped by their recommended screening intervals:\n * - 3 months: Body composition and bone density (frequently changing metrics)\n * - 6 months: Metabolic panel and nutrients (moderate change rate)\n * - 12 months: Standard blood panels (stable long-term markers)\n */\nexport const CATEGORY_SCREENING_INTERVALS: CategoryScreeningInterval[] = [\n // 3-month intervals - Body composition (frequently changing)\n {\n category: 'composicao-corporal',\n intervalMonths: 3,\n nameEn: 'Body Composition',\n namePt: 'Composição Corporal',\n },\n {\n category: 'densidade-ossea',\n intervalMonths: 3,\n nameEn: 'Bone Density',\n namePt: 'Densidade Óssea',\n },\n\n // 6-month intervals - Metabolic and nutrients\n {\n category: 'metabolico',\n intervalMonths: 6,\n nameEn: 'Metabolic Panel',\n namePt: 'Painel Metabólico',\n },\n {\n category: 'nutrientes',\n intervalMonths: 6,\n nameEn: 'Nutrients',\n namePt: 'Nutrientes',\n },\n {\n category: 'pancreas',\n intervalMonths: 6,\n nameEn: 'Pancreas',\n namePt: 'Pâncreas',\n },\n\n // 12-month intervals - Standard blood panels\n {\n category: 'coracao',\n intervalMonths: 12,\n nameEn: 'Heart Health',\n namePt: 'Saúde Cardiovascular',\n },\n {\n category: 'tireoide',\n intervalMonths: 12,\n nameEn: 'Thyroid',\n namePt: 'Tireoide',\n },\n {\n category: 'sangue',\n intervalMonths: 12,\n nameEn: 'Blood Count',\n namePt: 'Hemograma',\n },\n {\n category: 'figado',\n intervalMonths: 12,\n nameEn: 'Liver Function',\n namePt: 'Função Hepática',\n },\n {\n category: 'rins',\n intervalMonths: 12,\n nameEn: 'Kidney Function',\n namePt: 'Função Renal',\n },\n {\n category: 'saude-feminina',\n intervalMonths: 12,\n nameEn: \"Women's Health\",\n namePt: 'Saúde Feminina',\n },\n {\n category: 'saude-masculina',\n intervalMonths: 12,\n nameEn: \"Men's Health\",\n namePt: 'Saúde Masculina',\n },\n {\n category: 'eletrolitos',\n intervalMonths: 12,\n nameEn: 'Electrolytes',\n namePt: 'Eletrólitos',\n },\n {\n category: 'estresse-envelhecimento',\n intervalMonths: 12,\n nameEn: 'Stress & Aging',\n namePt: 'Estresse e Envelhecimento',\n },\n {\n category: 'autoimunidade',\n intervalMonths: 12,\n nameEn: 'Autoimmunity',\n namePt: 'Autoimunidade',\n },\n {\n category: 'regulacao-imunologica',\n intervalMonths: 12,\n nameEn: 'Immune Regulation',\n namePt: 'Regulação Imunológica',\n },\n {\n category: 'toxinas-ambientais',\n intervalMonths: 12,\n nameEn: 'Environmental Toxins',\n namePt: 'Toxinas Ambientais',\n },\n {\n category: 'urina',\n intervalMonths: 12,\n nameEn: 'Urinalysis',\n namePt: 'Urina',\n },\n];\n\n/**\n * Get screening interval for a category\n */\nexport const getScreeningInterval = (category: string): CategoryScreeningInterval | undefined => {\n return CATEGORY_SCREENING_INTERVALS.find((c) => c.category === category);\n};\n\n/**\n * Get all categories with a specific interval\n */\nexport const getCategoriesByInterval = (\n intervalMonths: ScreeningIntervalMonths,\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((c) => c.intervalMonths === intervalMonths);\n};\n\n/**\n * Calculate next screening date based on last test date and category\n */\nexport const calculateNextScreeningDate = (lastTestDate: Date, category: string): Date | null => {\n const interval = getScreeningInterval(category);\n if (!interval) return null;\n\n const nextDate = new Date(lastTestDate);\n nextDate.setMonth(nextDate.getMonth() + interval.intervalMonths);\n return nextDate;\n};\n\n/**\n * Check if a category is due for screening\n */\nexport const isScreeningDue = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): boolean => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return false;\n return referenceDate >= nextDate;\n};\n\n/**\n * Get categories that are due for screening based on last test dates\n */\nexport const getDueCategories = (\n lastTestDates: Record<string, Date>,\n referenceDate: Date = new Date(),\n): CategoryScreeningInterval[] => {\n return CATEGORY_SCREENING_INTERVALS.filter((interval) => {\n const lastDate = lastTestDates[interval.category];\n if (!lastDate) return true; // Never tested = due\n return isScreeningDue(lastDate, interval.category, referenceDate);\n });\n};\n\n/**\n * Get days until next screening for a category\n */\nexport const getDaysUntilScreening = (\n lastTestDate: Date,\n category: string,\n referenceDate: Date = new Date(),\n): number | null => {\n const nextDate = calculateNextScreeningDate(lastTestDate, category);\n if (!nextDate) return null;\n\n const diffTime = nextDate.getTime() - referenceDate.getTime();\n return Math.ceil(diffTime / (1000 * 60 * 60 * 24));\n};\n","/**\n * Portuguese pluralization utility using native Intl.PluralRules\n * Provides automatic pluralization for common words used in the app\n */\n\nconst pluralRules = new Intl.PluralRules('pt-BR');\n\n/**\n * Dictionary of Portuguese words with their plural forms\n * Key is the singular form, value is the plural form\n */\nconst dictionary: Record<string, string> = {\n // Common nouns\n arquivo: 'arquivos',\n biomarcador: 'biomarcadores',\n // Past participles (masculine)\n cadastrado: 'cadastrados',\n // Past participles (feminine)\n concluída: 'concluídas',\n confirmado: 'confirmados',\n convertido: 'convertidos',\n convidado: 'convidados',\n convite: 'convites',\n disponível: 'disponíveis',\n documento: 'documentos',\n enviado: 'enviados',\n exame: 'exames',\n excluída: 'excluídas',\n\n excluído: 'excluídos',\n // Verbs (3rd person)\n falhou: 'falharam',\n falta: 'faltam',\n ignorado: 'ignorados',\n item: 'itens',\n outro: 'outros',\n página: 'páginas',\n pendente: 'pendentes',\n registro: 'registros',\n removido: 'removidos',\n\n resultado: 'resultados',\n revisão: 'revisões',\n\n revogado: 'revogados',\n usuário: 'usuários',\n};\n\n/**\n * Get the plural form of a word from the dictionary\n * Falls back to adding 's' if word is not in dictionary\n */\nconst getPluralForm = (singular: string): string => {\n return dictionary[singular] ?? `${singular}s`;\n};\n\n/**\n * Returns the correct singular or plural form based on count\n * Uses Intl.PluralRules for proper locale-aware pluralization\n *\n * @example\n * plural(1, 'usuário') // 'usuário'\n * plural(3, 'usuário') // 'usuários'\n * plural(0, 'registro') // 'registros'\n */\nexport const plural = (count: number, word: string): string => {\n const rule = pluralRules.select(count);\n return rule === 'one' ? word : getPluralForm(word);\n};\n\n/**\n * Returns count with the correct singular or plural form\n *\n * @example\n * pluralCount(1, 'usuário') // '1 usuário'\n * pluralCount(3, 'usuário') // '3 usuários'\n */\nexport const pluralCount = (count: number, word: string): string => {\n return `${count} ${plural(count, word)}`;\n};\n\n/**\n * Returns the correct form for compound phrases (noun + adjective)\n * Both words are pluralized together\n *\n * @example\n * pluralPhrase(1, 'usuário', 'cadastrado') // 'usuário cadastrado'\n * pluralPhrase(3, 'usuário', 'cadastrado') // 'usuários cadastrados'\n * pluralPhrase(2, 'revisão', 'excluída') // 'revisões excluídas'\n */\nexport const pluralPhrase = (count: number, noun: string, adjective: string): string => {\n const rule = pluralRules.select(count);\n if (rule === 'one') {\n return `${noun} ${adjective}`;\n }\n return `${getPluralForm(noun)} ${getPluralForm(adjective)}`;\n};\n\n/**\n * Returns count with the correct compound phrase form\n *\n * @example\n * pluralPhraseCount(1, 'usuário', 'cadastrado') // '1 usuário cadastrado'\n * pluralPhraseCount(3, 'convite', 'enviado') // '3 convites enviados'\n */\nexport const pluralPhraseCount = (count: number, noun: string, adjective: string): string => {\n return `${count} ${pluralPhrase(count, noun, adjective)}`;\n};\n","/**\n * Helpers para identificadores brasileiros — CPF e CNS\n *\n * Validação, formatação e conversão para FHIR Identifier.\n * Algoritmos de validação baseados nas especificações oficiais:\n * - CPF: Receita Federal (mod-11, dois dígitos verificadores)\n * - CNS: Ministério da Saúde (mod-11 para definitivos, soma ponderada para provisórios)\n */\n\nimport type { FHIRIdentifier } from './fhir-types';\n\nconst CPF_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cpf';\nconst CNS_SYSTEM = 'http://rnds.saude.gov.br/fhir/r4/NamingSystem/cns';\n\n/**\n * Remove caracteres não-numéricos de uma string.\n */\nfunction digitsOnly(value: string): string {\n return value.replace(/\\D/g, '');\n}\n\n/**\n * Valida um CPF brasileiro usando algoritmo mod-11.\n *\n * @param cpf — CPF com ou sem formatação (ex: \"123.456.789-09\" ou \"12345678909\")\n * @returns true se o CPF é estruturalmente válido\n */\nexport function validateCPF(cpf: string): boolean {\n const digits = digitsOnly(cpf);\n\n if (digits.length !== 11) return false;\n\n // Rejeitar sequências de dígitos iguais (ex: 111.111.111-11)\n if (/^(\\d)\\1{10}$/.test(digits)) return false;\n\n // Primeiro dígito verificador\n let sum = 0;\n for (let i = 0; i < 9; i++) {\n sum += Number(digits[i]) * (10 - i);\n }\n let remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[9])) return false;\n\n // Segundo dígito verificador\n sum = 0;\n for (let i = 0; i < 10; i++) {\n sum += Number(digits[i]) * (11 - i);\n }\n remainder = (sum * 10) % 11;\n if (remainder === 10) remainder = 0;\n if (remainder !== Number(digits[10])) return false;\n\n return true;\n}\n\n/**\n * Valida um CNS (Cartão Nacional de Saúde) brasileiro.\n *\n * CNS definitivos começam com 1 ou 2 (mod-11).\n * CNS provisórios começam com 7, 8 ou 9 (soma ponderada mod-11 = 0).\n *\n * @param cns — CNS com 15 dígitos\n * @returns true se o CNS é estruturalmente válido\n */\nexport function validateCNS(cns: string): boolean {\n const digits = digitsOnly(cns);\n\n if (digits.length !== 15) return false;\n\n const firstDigit = digits[0]!;\n\n // CNS deve começar com 1, 2 (definitivo) ou 7, 8, 9 (provisório)\n if (!['1', '2', '7', '8', '9'].includes(firstDigit)) return false;\n\n // Ambos os tipos usam soma ponderada mod-11 = 0\n let sum = 0;\n for (let i = 0; i < 15; i++) {\n sum += Number(digits[i]) * (15 - i);\n }\n return sum % 11 === 0;\n}\n\n/**\n * Formata um CPF como XXX.XXX.XXX-XX.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns CPF formatado ou a string original se inválido\n */\nexport function formatCPF(cpf: string): string {\n const digits = digitsOnly(cpf);\n if (digits.length !== 11) return cpf;\n return `${digits.slice(0, 3)}.${digits.slice(3, 6)}.${digits.slice(6, 9)}-${digits.slice(9)}`;\n}\n\n/**\n * Formata um CNS como XXX XXXX XXXX XXXX.\n *\n * @param cns — CNS com 15 dígitos\n * @returns CNS formatado ou a string original se inválido\n */\nexport function formatCNS(cns: string): string {\n const digits = digitsOnly(cns);\n if (digits.length !== 15) return cns;\n return `${digits.slice(0, 3)} ${digits.slice(3, 7)} ${digits.slice(7, 11)} ${digits.slice(11)}`;\n}\n\n/**\n * Converte um CPF para um FHIR Identifier.\n *\n * @param cpf — CPF com 11 dígitos (com ou sem formatação)\n * @returns FHIR Identifier com sistema RNDS para CPF\n * @throws Error se o CPF for inválido\n */\nexport function cpfToFHIRIdentifier(cpf: string): FHIRIdentifier {\n if (!validateCPF(cpf)) {\n throw new Error('CPF inválido');\n }\n return {\n system: CPF_SYSTEM,\n use: 'official',\n value: digitsOnly(cpf),\n };\n}\n\n/**\n * Converte um CNS para um FHIR Identifier.\n *\n * @param cns — CNS com 15 dígitos\n * @returns FHIR Identifier com sistema RNDS para CNS\n * @throws Error se o CNS for inválido\n */\nexport function cnsToFHIRIdentifier(cns: string): FHIRIdentifier {\n if (!validateCNS(cns)) {\n throw new Error('CNS inválido');\n }\n return {\n system: CNS_SYSTEM,\n use: 'official',\n value: digitsOnly(cns),\n };\n}\n","/**\n * Código do tipo de amostra a partir do material impresso no laudo.\n *\n * O perfil `BRAmostraBiologica-1.0` da RNDS vincula `Specimen.type` ao ValueSet\n * `BRTipoAmostra-1.0` com força `required`, exige `type.coding` (1..1) e proíbe\n * `type.text` (0..0). Um `Specimen` só com o texto do laudo não passa, e é o que\n * a extração produzia.\n *\n * O ValueSet tem 63 códigos, e quase todos são de vigilância respiratória vindos\n * do GAL: swab nasofaríngeo, lavado brônquico, fragmento de órgão. Para laudo de\n * rotina sobram seis, e esses seis cobrem o que um painel de sangue e urina\n * imprime.\n *\n * Não há código para fezes no ValueSet. Isso não afeta a extração, cujo catálogo\n * não tem nenhum biomarcador de origem fecal: um parasitológico não vira\n * `Observation`, então não chega a pedir `Specimen`.\n *\n * @see https://rnds-fhir.saude.gov.br/StructureDefinition-BRAmostraBiologica-1.0.html\n * @see https://rnds-fhir.saude.gov.br/ValueSet-BRTipoAmostra-1.0.html\n */\nimport type { FHIRCoding } from './fhir-types';\n\n/** ValueSet ao qual `Specimen.type` está vinculado no `BRAmostraBiologica`. */\nexport const BR_TIPO_AMOSTRA_VALUESET = 'https://rnds-fhir.saude.gov.br/ValueSet/BRTipoAmostra-1.0';\n\n/**\n * CodeSystem dos códigos que este módulo emite.\n *\n * O ValueSet também inclui o `BRTipoAmostraGAL`, que traz \"Sangue\" e \"Sangue com\n * EDTA\" soltos. Ficaram de fora porque a URL canônica daquele CodeSystem não foi\n * confirmada na fonte, e código de terminologia não se deduz de slug. Material\n * assim cai no caminho de não mapeado até alguém abrir o IG e confirmar.\n */\nexport const HL7_SPECIMEN_TYPE_SYSTEM = 'http://terminology.hl7.org/CodeSystem/v2-0487';\n\n/**\n * Os `display` são cópia literal do ValueSet, com a caixa dele.\n *\n * A chave é o texto já normalizado, e por enquanto é só o próprio display. Não\n * há sinônimo inventado aqui: a extração copia o material verbatim do laudo, e a\n * lista de variações que os laboratórios de fato imprimem ainda não foi medida\n * (a captura de material entrou em produção em 05/09/2026). Variação real\n * observada entra depois, com o laudo que a produziu.\n */\nconst CODINGS: ReadonlyArray<{ code: string; display: string }> = [\n { code: 'SER', display: 'Soro' },\n { code: 'PLAS', display: 'Plasma' },\n { code: 'WB', display: 'Sangue Total' },\n { code: 'UR', display: 'Urina' },\n { code: 'CSF', display: 'Líquor' },\n { code: 'SAL', display: 'Saliva' },\n];\n\n/**\n * Caixa, acento e espaço sobrando não distinguem material.\n *\n * Só isso. Não separa `camelCase` nem troca barra por espaço, ao contrário do\n * normalizador de nomes de biomarcador: \"Soro/Plasma\" impresso numa linha só é\n * ambíguo de verdade, e escolher um dos dois seria inferência. Sem casar, ele\n * segue o caminho do não mapeado.\n *\n * Os caracteres invisíveis saem antes, e a divisão entre as duas regras é a do\n * próprio Unicode: `\\p{Cf}` são os de formatação, que não ocupam espaço e por\n * isso são apagados, e `\\s` são os de espaço, que são colapsados. A camada de\n * texto de PDF emite os dois tipos, e um U+200B no meio de \"Soro\" derruba o\n * casamento sem deixar rastro na tela.\n *\n * Vale a categoria em vez da lista porque a lista nunca fecha. Enumerando, o\n * hífen opcional (U+00AD) tinha ficado de fora, e ele aparece justamente onde\n * um nome composto como \"Sangue Total\" quebra de linha.\n */\nconst INVISIBLE = /\\p{Cf}/gu;\n\nconst normalize = (text: string): string =>\n text\n .replace(INVISIBLE, '')\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/\\s+/g, ' ')\n .trim();\n\nconst BY_NORMALIZED_TEXT = new Map(\n CODINGS.map(({ code, display }) => [\n normalize(display),\n { code, display, system: HL7_SPECIMEN_TYPE_SYSTEM } satisfies FHIRCoding,\n ]),\n);\n\n/**\n * Coding do ValueSet para o material impresso, ou `undefined` sem casar.\n *\n * `undefined` é resposta legítima e não erro: o laudo pode trazer um material\n * fora do ValueSet, ou uma grafia que ninguém viu ainda. Quem chama decide o que\n * fazer, e a decisão que não existe é preencher com um código aproximado.\n */\nexport const specimenTypeCoding = (text: string): FHIRCoding | undefined =>\n BY_NORMALIZED_TEXT.get(normalize(text));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCO,IAAM,kBAA4D;AAAA,EACvE,gBAAgB;AAAA,IACd,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,eAAe,CAAC,SAAS;AAAA,EAC3B;AAAA,EACA,6BAA6B;AAAA,IAC3B,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,eAAe,CAAC,uBAAuB,mBAAmB,yBAAyB;AAAA,EACrF;AAAA,EACA,cAAc;AAAA,IACZ,IAA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AAY;AAElB,IAAM,YAAY,CAAC,SACjB,KACG,QAAQ,WAAW,EAAE,EACrB,UAAU,KAAK,EACf,QAAQ,oBAAoB,EAAE,EAC9B,YAAY,EACZ,QAAQ,QAAQ,GAAG,EACnB,KAAK;AAEV,IAAM,qBAAqB,IAAI;AAAA,EAC7B,QAAQ,IAAI,CAAC,EAAE,MAAM,QAAQ,MAAM;AAAA,IACjC,UAAU,OAAO;AAAA,IACjB,EAAE,MAAM,SAAS,QAAQ,yBAAyB;AAAA,EACpD,CAAC;AACH;AASO,IAAM,qBAAqB,CAAC,SACjC,mBAAmB,IAAI,UAAU,IAAI,CAAC;","names":[]}
|
package/dist/validators.d.cts
CHANGED
package/dist/validators.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-MZ36NSTX.cjs","../src/bundle-urls.ts","../src/converter.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACwBO,IAAM,gBAAA,EAAkB,mCAAA;AAUxB,IAAM,aAAA,EAAe,CAAC,QAAA,EAAA,GAC3B,CAAA,EAAA;ADhCgC;AACA;AEIc;AAChC,EAAA;AACP,IAAA;AACI,MAAA;AAAA;AACJ,IAAA;AACI,MAAA;AAAA;AACT,IAAA;AACS,MAAA;AACX,EAAA;AACF;AAK+B;AACf,EAAA;AACP,IAAA;AACI,MAAA;AACJ,IAAA;AACI,MAAA;AACT,IAAA;AACS,MAAA;AACX,EAAA;AACF;AAME;AAI8B,EAAA;AAGhB,EAAA;AACc,EAAA;AACN,EAAA;AAGwB,EAAA;AAClC,IAAA;AACR,MAAA;AACU,QAAA;AACN,UAAA;AACQ,YAAA;AACG,YAAA;AACD,YAAA;AACV,UAAA;AACF,QAAA;AACF,MAAA;AACF,IAAA;AACM,IAAA;A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,YAAA;AACG,YAAA;AACD,YAAA;AACV,UAAA;AACF,QAAA;AACF,MAAA;AAEF,IAAA;AACoB,IAAA;AACf,IAAA;AACI,IAAA;AACG,IAAA;AACJ,IAAA;AACc,IAAA;AAC5B,IAAA;AACS,IAAA;AACe,MAAA;AACxB,IAAA;AACF,EAAA;AACF;AAMkC;AACD,EAAA;AACD,EAAA;AACL,EAAA;AAElB,EAAA;AAED,IAAA;AACE,MAAA;AACwB,QAAA;AACG,QAAA;AACnB,QAAA;AACY,UAAA;AAGA,UAAA;AACF,QAAA;AACI,QAAA;AACG,QAAA;AACzB,MAAA;AAEF,IAAA;AACe,IAAA;AACH,IAAA;AACJ,IAAA;AACN,IAAA;AACJ,MAAA;AACE,QAAA;AAC0B,QAAA;AACZ,QAAA;AAChB,MAAA;AACF,IAAA;AACc,IAAA;AAEZ,IAAA;AACyB,MAAA;AACA,MAAA;AAErB,IAAA;AACyB,MAAA;AACA,MAAA;AAEzB,IAAA;AACR,EAAA;AACF;AAOE;AAI8B,EAAA;AAGL,EAAA;AACN,IAAA;AACW,MAAA;AAC1B,MAAA;AACO,MAAA;AACT,IAAA;AAEkB,IAAA;AACnB,EAAA;AAKsB,EAAA;AAGE,EAAA;AAGL,EAAA;AAEb,EAAA;AACE,IAAA;AACmB,MAAA;AACA,MAAA;AACrB,MAAA;AACL,IAAA;AACc,IAAA;AACR,IAAA;AACR,EAAA;AACF;AFxEkC;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fhir-brasil/fhir-brasil/packages/core/dist/chunk-MZ36NSTX.cjs","sourcesContent":[null,"/**\n * Endereço das entradas de um Bundle.\n *\n * O `fullUrl` identifica a entrada, e é contra ele que o validador resolve as\n * referências entre os recursos. Um Bundle com `subject.reference` valendo\n * `Patient/abc` só resolve se alguma entrada tiver `fullUrl` terminando em\n * `/Patient/abc`: a referência relativa é lida contra a base do `fullUrl` da\n * entrada, que é como os exemplos da própria HL7 montam Bundle de coleção.\n *\n * Antes o `fullUrl` era `urn:uuid:observation-<laudo>-<código>`, que erra duas\n * vezes. `urn:uuid:` exige a sintaxe de UUID e aquilo não era um UUID, e num\n * Bundle de entradas `urn:uuid:` a referência precisa repetir a URN inteira,\n * então nenhuma das relativas resolvia. Um laudo de 22 marcadores saía com 24\n * erros de URN e 22 referências perdidas.\n */\nimport type { FHIRBundleEntry } from './fhir-types';\n\n/**\n * Recurso que já tem id, e por isso pode ser endereçado numa entrada.\n *\n * No FHIR o `id` é opcional, porque um recurso pode viajar sem identidade\n * própria. Numa entrada de Bundle ele não pode: sem id não há `fullUrl`, e sem\n * `fullUrl` nenhuma referência chega ao recurso. Os conversores daqui sempre\n * atribuem um, e o tipo passa a dizer isso em vez de deixar `undefined` chegar\n * até a montagem da URL.\n */\nexport type Addressable<T> = T & { id: string };\n\n/**\n * Base dos `fullUrl`.\n *\n * Não precisa responder a uma requisição: no FHIR o `fullUrl` é identidade, não\n * endereço de download. Fica sob um domínio nosso para não colidir com a\n * identidade de recurso de outra instituição, que é o risco real de usar\n * `example.org` em dado que sai da máquina.\n */\nexport const BUNDLE_BASE_URL = 'https://precisa-saude.com.br/fhir';\n\n/**\n * Monta o `fullUrl` a partir do próprio recurso.\n *\n * Recebe o recurso em vez do tipo e do id soltos de propósito. O defeito que\n * isto substitui nasceu de montar os dois lados em separado: o `fullUrl` dizia\n * `observation-demo-Hgb` enquanto o recurso tinha id `demo-Hgb`, e ninguém\n * percebeu porque nada obrigava os dois a concordarem.\n */\nexport const entryFullUrl = (resource: Addressable<FHIRBundleEntry['resource']>): string =>\n `${BUNDLE_BASE_URL}/${resource.resourceType}/${resource.id}`;\n","/**\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 Addressable, entryFullUrl } from './bundle-urls';\nimport { BIOMARKER_CODE_SYSTEM, LOINC_SYSTEM } from './code-systems';\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): Addressable<FHIRObservation> {\n const loincCode = codeToLoinc(observation.biomarkerCode);\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: Addressable<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 // Sem LOINC, o coding LOINC simplesmente não sai. Antes ia `99999-9`,\n // que não é código LOINC nenhum: publicava sob `http://loinc.org` uma\n // afirmação falsa, e quem consumisse o bundle confiando no system\n // trataria aquilo como código de verdade. Composição corporal, densidade\n // óssea e escore de cálcio não têm LOINC, e o certo é a lacuna explícita.\n coding: [\n ...(loincCode\n ? [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: LOINC_SYSTEM,\n },\n ]\n : []),\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: BIOMARKER_CODE_SYSTEM,\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): Addressable<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): Addressable<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 const resource = labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n );\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n // Os ids vêm dos recursos já montados, e não de uma segunda montagem da mesma\n // regra. O `DiagnosticReport.result` aponta para eles, e era aqui que a\n // referência se separava do recurso.\n const observationIds = fhirObservations.map((entry) => entry.resource.id);\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 { fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient },\n { fullUrl: entryFullUrl(diagnosticReport), resource: diagnosticReport },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundle-urls.ts","../src/converter.ts"],"sourcesContent":["/**\n * Endereço das entradas de um Bundle.\n *\n * O `fullUrl` identifica a entrada, e é contra ele que o validador resolve as\n * referências entre os recursos. Um Bundle com `subject.reference` valendo\n * `Patient/abc` só resolve se alguma entrada tiver `fullUrl` terminando em\n * `/Patient/abc`: a referência relativa é lida contra a base do `fullUrl` da\n * entrada, que é como os exemplos da própria HL7 montam Bundle de coleção.\n *\n * Antes o `fullUrl` era `urn:uuid:observation-<laudo>-<código>`, que erra duas\n * vezes. `urn:uuid:` exige a sintaxe de UUID e aquilo não era um UUID, e num\n * Bundle de entradas `urn:uuid:` a referência precisa repetir a URN inteira,\n * então nenhuma das relativas resolvia. Um laudo de 22 marcadores saía com 24\n * erros de URN e 22 referências perdidas.\n */\nimport type { FHIRBundleEntry } from './fhir-types';\n\n/**\n * Recurso que já tem id, e por isso pode ser endereçado numa entrada.\n *\n * No FHIR o `id` é opcional, porque um recurso pode viajar sem identidade\n * própria. Numa entrada de Bundle ele não pode: sem id não há `fullUrl`, e sem\n * `fullUrl` nenhuma referência chega ao recurso. Os conversores daqui sempre\n * atribuem um, e o tipo passa a dizer isso em vez de deixar `undefined` chegar\n * até a montagem da URL.\n */\nexport type Addressable<T> = T & { id: string };\n\n/**\n * Base dos `fullUrl`.\n *\n * Não precisa responder a uma requisição: no FHIR o `fullUrl` é identidade, não\n * endereço de download. Fica sob um domínio nosso para não colidir com a\n * identidade de recurso de outra instituição, que é o risco real de usar\n * `example.org` em dado que sai da máquina.\n */\nexport const BUNDLE_BASE_URL = 'https://precisa-saude.com.br/fhir';\n\n/**\n * Monta o `fullUrl` a partir do próprio recurso.\n *\n * Recebe o recurso em vez do tipo e do id soltos de propósito. O defeito que\n * isto substitui nasceu de montar os dois lados em separado: o `fullUrl` dizia\n * `observation-demo-Hgb` enquanto o recurso tinha id `demo-Hgb`, e ninguém\n * percebeu porque nada obrigava os dois a concordarem.\n */\nexport const entryFullUrl = (resource: Addressable<FHIRBundleEntry['resource']>): string =>\n `${BUNDLE_BASE_URL}/${resource.resourceType}/${resource.id}`;\n","/**\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 Addressable, entryFullUrl } from './bundle-urls';\nimport { BIOMARKER_CODE_SYSTEM, LOINC_SYSTEM } from './code-systems';\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): Addressable<FHIRObservation> {\n const loincCode = codeToLoinc(observation.biomarkerCode);\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: Addressable<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 // Sem LOINC, o coding LOINC simplesmente não sai. Antes ia `99999-9`,\n // que não é código LOINC nenhum: publicava sob `http://loinc.org` uma\n // afirmação falsa, e quem consumisse o bundle confiando no system\n // trataria aquilo como código de verdade. Composição corporal, densidade\n // óssea e escore de cálcio não têm LOINC, e o certo é a lacuna explícita.\n coding: [\n ...(loincCode\n ? [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: LOINC_SYSTEM,\n },\n ]\n : []),\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: BIOMARKER_CODE_SYSTEM,\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): Addressable<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): Addressable<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 const resource = labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n );\n\n return { fullUrl: entryFullUrl(resource), resource };\n });\n\n // Os ids vêm dos recursos já montados, e não de uma segunda montagem da mesma\n // regra. O `DiagnosticReport.result` aponta para eles, e era aqui que a\n // referência se separava do recurso.\n const observationIds = fhirObservations.map((entry) => entry.resource.id);\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 { fullUrl: entryFullUrl(fhirPatient), resource: fhirPatient },\n { fullUrl: entryFullUrl(diagnosticReport), resource: diagnosticReport },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAoCO,IAAM,kBAAkB;AAUxB,IAAM,eAAe,CAAC,aAC3B,GAAG,eAAe,IAAI,SAAS,YAAY,IAAI,SAAS,EAAE;;;AC3B5D,SAAS,mBAAmB,MAAoB;AAC9C,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA;AAAA,IACT,KAAK;AACH,aAAO;AAAA;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAKA,SAAS,sBAAsB,MAAoB;AACjD,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAKO,SAAS,qBACd,aACA,WACA,gBAC8B;AAC9B,QAAM,YAAY,YAAY,YAAY,aAAa;AAEvD,QAAM,aACJ,YAAY,QAAQ,eAAe,YAAY,aAAa,KAAK,YAAY;AAC/E,QAAM,WAAW,WAAW,UAAU;AACtC,QAAM,gBAAgB,YAAY,iBAAiB,OAAO,YAAY,UAAU;AAGhF,QAAM,UAAwC;AAAA,IAC5C,UAAU;AAAA,MACR;AAAA,QACE,QAAQ;AAAA,UACN;AAAA,YACE,MAAM;AAAA,YACN,SAAS;AAAA,YACT,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMJ,QAAQ;AAAA,QACN,GAAI,YACA;AAAA,UACE;AAAA,YACE,MAAM;AAAA,YACN,SAAS,YAAY;AAAA,YACrB,QAAQ;AAAA,UACV;AAAA,QACF,IACA,CAAC;AAAA,QACL;AAAA,UACE,MAAM,YAAY;AAA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