@precisa-saude/fhir 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +85 -0
  2. package/dist/biomarkers.cjs +67 -0
  3. package/dist/biomarkers.cjs.map +1 -0
  4. package/dist/biomarkers.d.cts +226 -0
  5. package/dist/biomarkers.d.ts +226 -0
  6. package/dist/biomarkers.js +67 -0
  7. package/dist/biomarkers.js.map +1 -0
  8. package/dist/chunk-2EVQ2ESB.cjs +2692 -0
  9. package/dist/chunk-2EVQ2ESB.cjs.map +1 -0
  10. package/dist/chunk-2X6MT5KE.cjs +1464 -0
  11. package/dist/chunk-2X6MT5KE.cjs.map +1 -0
  12. package/dist/chunk-3ILBFLVQ.cjs +63 -0
  13. package/dist/chunk-3ILBFLVQ.cjs.map +1 -0
  14. package/dist/chunk-FDOBUUGY.js +1464 -0
  15. package/dist/chunk-FDOBUUGY.js.map +1 -0
  16. package/dist/chunk-GFXKYXHW.cjs +436 -0
  17. package/dist/chunk-GFXKYXHW.cjs.map +1 -0
  18. package/dist/chunk-I6H35QXI.js +2692 -0
  19. package/dist/chunk-I6H35QXI.js.map +1 -0
  20. package/dist/chunk-N3ZCOLG2.js +63 -0
  21. package/dist/chunk-N3ZCOLG2.js.map +1 -0
  22. package/dist/chunk-O25F6G3K.cjs +153 -0
  23. package/dist/chunk-O25F6G3K.cjs.map +1 -0
  24. package/dist/chunk-S6VJHXJF.js +153 -0
  25. package/dist/chunk-S6VJHXJF.js.map +1 -0
  26. package/dist/chunk-UIDSSWBJ.js +251 -0
  27. package/dist/chunk-UIDSSWBJ.js.map +1 -0
  28. package/dist/chunk-VPMT4MRS.js +436 -0
  29. package/dist/chunk-VPMT4MRS.js.map +1 -0
  30. package/dist/chunk-Z6YE6FJ4.cjs +251 -0
  31. package/dist/chunk-Z6YE6FJ4.cjs.map +1 -0
  32. package/dist/converter-C-QpCcTL.d.ts +99 -0
  33. package/dist/converter-Dee-qjBV.d.cts +99 -0
  34. package/dist/converter.cjs +15 -0
  35. package/dist/converter.cjs.map +1 -0
  36. package/dist/converter.d.cts +2 -0
  37. package/dist/converter.d.ts +2 -0
  38. package/dist/converter.js +15 -0
  39. package/dist/converter.js.map +1 -0
  40. package/dist/fhir-types-D9hUzGrc.d.cts +129 -0
  41. package/dist/fhir-types-D9hUzGrc.d.ts +129 -0
  42. package/dist/importer.cjs +17 -0
  43. package/dist/importer.cjs.map +1 -0
  44. package/dist/importer.d.cts +60 -0
  45. package/dist/importer.d.ts +60 -0
  46. package/dist/importer.js +17 -0
  47. package/dist/importer.js.map +1 -0
  48. package/dist/index.cjs +540 -0
  49. package/dist/index.cjs.map +1 -0
  50. package/dist/index.d.cts +163 -0
  51. package/dist/index.d.ts +163 -0
  52. package/dist/index.js +540 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/reference-ranges.cjs +18 -0
  55. package/dist/reference-ranges.cjs.map +1 -0
  56. package/dist/reference-ranges.d.cts +106 -0
  57. package/dist/reference-ranges.d.ts +106 -0
  58. package/dist/reference-ranges.js +18 -0
  59. package/dist/reference-ranges.js.map +1 -0
  60. package/dist/units.cjs +19 -0
  61. package/dist/units.cjs.map +1 -0
  62. package/dist/units.d.cts +46 -0
  63. package/dist/units.d.ts +46 -0
  64. package/dist/units.js +19 -0
  65. package/dist/units.js.map +1 -0
  66. package/dist/validators.cjs +11 -0
  67. package/dist/validators.cjs.map +1 -0
  68. package/dist/validators.d.cts +23 -0
  69. package/dist/validators.d.ts +23 -0
  70. package/dist/validators.js +11 -0
  71. package/dist/validators.js.map +1 -0
  72. package/package.json +105 -0
@@ -0,0 +1,251 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2EVQ2ESBcjs = require('./chunk-2EVQ2ESB.cjs');
4
+
5
+
6
+
7
+ var _chunkGFXKYXHWcjs = require('./chunk-GFXKYXHW.cjs');
8
+
9
+ // src/converter.ts
10
+ function interpretationCode(flag) {
11
+ switch (flag) {
12
+ case "H":
13
+ return "H";
14
+ // High
15
+ case "L":
16
+ return "L";
17
+ // Low
18
+ default:
19
+ return "N";
20
+ }
21
+ }
22
+ function interpretationDisplay(flag) {
23
+ switch (flag) {
24
+ case "H":
25
+ return "High";
26
+ case "L":
27
+ return "Low";
28
+ default:
29
+ return "Normal";
30
+ }
31
+ }
32
+ function labObservationToFHIR(observation, patientId, laboratoryName) {
33
+ const loincCode = _chunk2EVQ2ESBcjs.codeToLoinc.call(void 0, observation.biomarkerCode) || "99999-9";
34
+ const sourceUnit = observation.unit || _chunkGFXKYXHWcjs.getDefaultUnit.call(void 0, observation.biomarkerCode) || observation.unit;
35
+ const ucumUnit = _chunkGFXKYXHWcjs.unitToUCUM.call(void 0, sourceUnit);
36
+ const isQualitative = observation.isQualitative || typeof observation.value === "string";
37
+ const fhirObs = {
38
+ category: [
39
+ {
40
+ coding: [
41
+ {
42
+ code: "laboratory",
43
+ display: "Laboratory",
44
+ system: "http://terminology.hl7.org/CodeSystem/observation-category"
45
+ }
46
+ ]
47
+ }
48
+ ],
49
+ code: {
50
+ coding: [
51
+ {
52
+ code: loincCode,
53
+ display: observation.biomarkerName,
54
+ system: "http://loinc.org"
55
+ },
56
+ {
57
+ code: observation.biomarkerCode,
58
+ display: observation.biomarkerName,
59
+ system: "http://fhir-brasil.dev/biomarker-codes"
60
+ }
61
+ ],
62
+ text: observation.biomarkerName
63
+ },
64
+ effectiveDateTime: observation.collectionDate,
65
+ id: `${observation.reportId}-${observation.biomarkerCode}`,
66
+ interpretation: [
67
+ {
68
+ coding: [
69
+ {
70
+ code: interpretationCode(observation.flag),
71
+ display: interpretationDisplay(observation.flag),
72
+ system: "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"
73
+ }
74
+ ]
75
+ }
76
+ ],
77
+ performer: laboratoryName ? [{ display: laboratoryName }] : void 0,
78
+ resourceType: "Observation",
79
+ status: "final",
80
+ subject: {
81
+ reference: `Patient/${patientId}`
82
+ }
83
+ };
84
+ if (isQualitative) {
85
+ fhirObs.valueString = String(observation.value);
86
+ } else {
87
+ fhirObs.valueQuantity = {
88
+ code: ucumUnit,
89
+ system: "http://unitsofmeasure.org",
90
+ unit: sourceUnit,
91
+ value: observation.value
92
+ };
93
+ if (observation.referenceMin !== void 0 && observation.referenceMax !== void 0) {
94
+ fhirObs.referenceRange = [
95
+ {
96
+ high: {
97
+ code: ucumUnit,
98
+ system: "http://unitsofmeasure.org",
99
+ unit: sourceUnit,
100
+ value: observation.referenceMax
101
+ },
102
+ low: {
103
+ code: ucumUnit,
104
+ system: "http://unitsofmeasure.org",
105
+ unit: sourceUnit,
106
+ value: observation.referenceMin
107
+ }
108
+ }
109
+ ];
110
+ }
111
+ }
112
+ return fhirObs;
113
+ }
114
+ function labReportToFHIR(report, patientId, observationIds) {
115
+ let status;
116
+ switch (report.processingStatus) {
117
+ case "complete":
118
+ status = "final";
119
+ break;
120
+ case "partial":
121
+ status = "partial";
122
+ break;
123
+ case "pending_review":
124
+ status = "preliminary";
125
+ break;
126
+ default:
127
+ status = "final";
128
+ }
129
+ return {
130
+ category: [
131
+ {
132
+ coding: [
133
+ {
134
+ code: "LAB",
135
+ display: "Laboratory",
136
+ system: "http://terminology.hl7.org/CodeSystem/v2-0074"
137
+ }
138
+ ]
139
+ }
140
+ ],
141
+ code: {
142
+ coding: [
143
+ {
144
+ code: "11502-2",
145
+ // Laboratory report
146
+ display: "Laboratory report",
147
+ system: "http://loinc.org"
148
+ }
149
+ ],
150
+ text: "Laboratory Results"
151
+ },
152
+ conclusion: report.overallStatus === "NORMAL" ? "All results within normal limits" : "One or more abnormal results detected",
153
+ conclusionCode: report.overallStatus === "ANORMAL" ? [
154
+ {
155
+ coding: [
156
+ {
157
+ code: "A",
158
+ display: "Abnormal",
159
+ system: "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"
160
+ }
161
+ ]
162
+ }
163
+ ] : void 0,
164
+ effectiveDateTime: report.collectionDate,
165
+ id: report.reportId,
166
+ issued: report.createdAt,
167
+ performer: report.laboratoryName ? [{ display: report.laboratoryName }] : void 0,
168
+ resourceType: "DiagnosticReport",
169
+ result: observationIds.map((id) => ({ reference: `Observation/${id}` })),
170
+ status,
171
+ subject: {
172
+ reference: `Patient/${patientId}`
173
+ }
174
+ };
175
+ }
176
+ function userProfileToFHIR(profile) {
177
+ const nameParts = profile.name.split(" ");
178
+ const given = nameParts.slice(0, -1);
179
+ const family = nameParts[nameParts.length - 1] || "";
180
+ return {
181
+ address: profile.address ? [
182
+ {
183
+ city: profile.address.city,
184
+ country: profile.address.country || "BR",
185
+ line: [
186
+ profile.address.street && profile.address.number ? `${profile.address.street}, ${profile.address.number}` : profile.address.street,
187
+ profile.address.complement
188
+ ].filter(Boolean),
189
+ postalCode: profile.address.postalCode,
190
+ state: profile.address.state
191
+ }
192
+ ] : void 0,
193
+ birthDate: profile.birthDate,
194
+ gender: profile.gender,
195
+ id: profile.userId,
196
+ name: [
197
+ {
198
+ family,
199
+ given: given.length > 0 ? given : void 0,
200
+ text: profile.name
201
+ }
202
+ ],
203
+ resourceType: "Patient",
204
+ telecom: [
205
+ ...profile.email ? [{ system: "email", value: profile.email }] : [],
206
+ ...profile.phone ? [{ system: "phone", value: profile.phone }] : []
207
+ ].length > 0 ? [
208
+ ...profile.email ? [{ system: "email", value: profile.email }] : [],
209
+ ...profile.phone ? [{ system: "phone", value: profile.phone }] : []
210
+ ] : void 0
211
+ };
212
+ }
213
+ function labResultToFHIRBundle(report, observations, userProfile) {
214
+ const patientId = userProfile.userId;
215
+ const fhirObservations = observations.map((obs) => ({
216
+ fullUrl: `urn:uuid:observation-${obs.reportId}-${obs.biomarkerCode}`,
217
+ resource: labObservationToFHIR(
218
+ { ...obs, collectionDate: report.collectionDate },
219
+ patientId,
220
+ report.laboratoryName
221
+ )
222
+ }));
223
+ const observationIds = observations.map(
224
+ (obs) => `observation-${obs.reportId}-${obs.biomarkerCode}`
225
+ );
226
+ const diagnosticReport = labReportToFHIR(report, patientId, observationIds);
227
+ const fhirPatient = userProfileToFHIR(userProfile);
228
+ return {
229
+ entry: [
230
+ {
231
+ fullUrl: `urn:uuid:${patientId}`,
232
+ resource: fhirPatient
233
+ },
234
+ {
235
+ fullUrl: `urn:uuid:diagnostic-report-${report.reportId}`,
236
+ resource: diagnosticReport
237
+ },
238
+ ...fhirObservations
239
+ ],
240
+ resourceType: "Bundle",
241
+ type: "collection"
242
+ };
243
+ }
244
+
245
+
246
+
247
+
248
+
249
+
250
+ exports.labObservationToFHIR = labObservationToFHIR; exports.labReportToFHIR = labReportToFHIR; exports.userProfileToFHIR = userProfileToFHIR; exports.labResultToFHIRBundle = labResultToFHIRBundle;
251
+ //# sourceMappingURL=chunk-Z6YE6FJ4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/rafael/Github/precisa-saude/fhir-brasil/packages/core/dist/chunk-Z6YE6FJ4.cjs","../src/converter.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACUA,SAAS,kBAAA,CAAmB,IAAA,EAAoB;AAC9C,EAAA,OAAA,CAAQ,IAAA,EAAM;AAAA,IACZ,KAAK,GAAA;AACH,MAAA,OAAO,GAAA;AAAA;AAAA,IACT,KAAK,GAAA;AACH,MAAA,OAAO,GAAA;AAAA;AAAA,IACT,OAAA;AACE,MAAA,OAAO,GAAA;AAAA,EACX;AACF;AAKA,SAAS,qBAAA,CAAsB,IAAA,EAAoB;AACjD,EAAA,OAAA,CAAQ,IAAA,EAAM;AAAA,IACZ,KAAK,GAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT,KAAK,GAAA;AACH,MAAA,OAAO,KAAA;AAAA,IACT,OAAA;AACE,MAAA,OAAO,QAAA;AAAA,EACX;AACF;AAKO,SAAS,oBAAA,CACd,WAAA,EACA,SAAA,EACA,cAAA,EACiB;AACjB,EAAA,MAAM,UAAA,EAAY,2CAAA,WAAY,CAAY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ACF,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAEQ,MAAA;AACA,MAAA;AACJ,IAAA;AAEQ,MAAA;AACA,MAAA;AAEN,IAAA;AACR,EAAA;AACF;AAMgB;AAKR,EAAA;AAGA,EAAA;AACJ,IAAA;AACA,IAAA;AACI,MAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACA,EAAA;AAEI,EAAA;AACH,IAAA;AACH,EAAA;AAGM,EAAA;AAGA,EAAA;AAEC,EAAA;AACL,IAAA;AACE,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AACG,MAAA;AACL,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;ADxES;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/rafael/Github/precisa-saude/fhir-brasil/packages/core/dist/chunk-Z6YE6FJ4.cjs","sourcesContent":[null,"/**\n * FHIR Converter\n *\n * Converts lab results to FHIR R4 DiagnosticReport and Observation resources.\n * See: https://hl7.org/fhir/diagnosticreport.html\n */\n\nimport { codeToLoinc } from './biomarkers';\nimport type { FHIRBundle, FHIRDiagnosticReport, FHIRObservation, FHIRPatient } from './fhir-types';\nimport { getDefaultUnit, unitToUCUM } from './units';\nimport type { Flag, LabObservationData, LabReportData, UserProfileData } from './types';\n\n// Re-export all types and functions\nexport * from './fhir-types';\n\n/**\n * Convert Flag to FHIR interpretation code\n */\nfunction interpretationCode(flag: Flag): string {\n switch (flag) {\n case 'H':\n return 'H'; // High\n case 'L':\n return 'L'; // Low\n default:\n return 'N'; // Normal\n }\n}\n\n/**\n * Convert Flag to FHIR interpretation display\n */\nfunction interpretationDisplay(flag: Flag): string {\n switch (flag) {\n case 'H':\n return 'High';\n case 'L':\n return 'Low';\n default:\n return 'Normal';\n }\n}\n\n/**\n * Convert generic lab observation to FHIR Observation\n */\nexport function labObservationToFHIR(\n observation: LabObservationData,\n patientId: string,\n laboratoryName?: string,\n): FHIRObservation {\n const loincCode = codeToLoinc(observation.biomarkerCode) || '99999-9';\n // Use default unit if source unit is empty\n const sourceUnit =\n observation.unit || getDefaultUnit(observation.biomarkerCode) || observation.unit;\n const ucumUnit = unitToUCUM(sourceUnit);\n const isQualitative = observation.isQualitative || typeof observation.value === 'string';\n\n // Base observation structure\n const fhirObs: FHIRObservation = {\n category: [\n {\n coding: [\n {\n code: 'laboratory',\n display: 'Laboratory',\n system: 'http://terminology.hl7.org/CodeSystem/observation-category',\n },\n ],\n },\n ],\n code: {\n coding: [\n {\n code: loincCode,\n display: observation.biomarkerName,\n system: 'http://loinc.org',\n },\n {\n code: observation.biomarkerCode,\n display: observation.biomarkerName,\n system: 'http://fhir-brasil.dev/biomarker-codes',\n },\n ],\n text: observation.biomarkerName,\n },\n effectiveDateTime: observation.collectionDate,\n id: `${observation.reportId}-${observation.biomarkerCode}`,\n interpretation: [\n {\n coding: [\n {\n code: interpretationCode(observation.flag),\n display: interpretationDisplay(observation.flag),\n system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation',\n },\n ],\n },\n ],\n performer: laboratoryName ? [{ display: laboratoryName }] : undefined,\n resourceType: 'Observation',\n status: 'final',\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n\n // Add value based on type (qualitative = string, quantitative = number)\n if (isQualitative) {\n fhirObs.valueString = String(observation.value);\n } else {\n fhirObs.valueQuantity = {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.value as number,\n };\n\n // Reference range only applies to quantitative values\n if (observation.referenceMin !== undefined && observation.referenceMax !== undefined) {\n fhirObs.referenceRange = [\n {\n high: {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.referenceMax,\n },\n low: {\n code: ucumUnit,\n system: 'http://unitsofmeasure.org',\n unit: sourceUnit,\n value: observation.referenceMin,\n },\n },\n ];\n }\n }\n\n return fhirObs;\n}\n\n/**\n * Convert generic lab report to FHIR DiagnosticReport\n */\nexport function labReportToFHIR(\n report: LabReportData,\n patientId: string,\n observationIds: string[],\n): FHIRDiagnosticReport {\n // Map processing status to FHIR status\n let status: FHIRDiagnosticReport['status'];\n switch (report.processingStatus) {\n case 'complete':\n status = 'final';\n break;\n case 'partial':\n status = 'partial';\n break;\n case 'pending_review':\n status = 'preliminary';\n break;\n default:\n status = 'final';\n }\n\n return {\n category: [\n {\n coding: [\n {\n code: 'LAB',\n display: 'Laboratory',\n system: 'http://terminology.hl7.org/CodeSystem/v2-0074',\n },\n ],\n },\n ],\n code: {\n coding: [\n {\n code: '11502-2', // Laboratory report\n display: 'Laboratory report',\n system: 'http://loinc.org',\n },\n ],\n text: 'Laboratory Results',\n },\n conclusion:\n report.overallStatus === 'NORMAL'\n ? 'All results within normal limits'\n : 'One or more abnormal results detected',\n conclusionCode:\n report.overallStatus === 'ANORMAL'\n ? [\n {\n coding: [\n {\n code: 'A',\n display: 'Abnormal',\n system: 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation',\n },\n ],\n },\n ]\n : undefined,\n effectiveDateTime: report.collectionDate,\n id: report.reportId,\n issued: report.createdAt,\n performer: report.laboratoryName ? [{ display: report.laboratoryName }] : undefined,\n resourceType: 'DiagnosticReport',\n result: observationIds.map((id) => ({ reference: `Observation/${id}` })),\n status,\n subject: {\n reference: `Patient/${patientId}`,\n },\n };\n}\n\n/**\n * Convert user profile to FHIR Patient\n * NOTE: CPF is intentionally excluded for privacy (LGPD compliance)\n */\nexport function userProfileToFHIR(profile: UserProfileData): FHIRPatient {\n const nameParts = profile.name.split(' ');\n const given = nameParts.slice(0, -1);\n const family = nameParts[nameParts.length - 1] || '';\n\n return {\n address: profile.address\n ? [\n {\n city: profile.address.city,\n country: profile.address.country || 'BR',\n line: [\n profile.address.street && profile.address.number\n ? `${profile.address.street}, ${profile.address.number}`\n : profile.address.street,\n profile.address.complement,\n ].filter(Boolean) as string[],\n postalCode: profile.address.postalCode,\n state: profile.address.state,\n },\n ]\n : undefined,\n birthDate: profile.birthDate,\n gender: profile.gender,\n id: profile.userId,\n name: [\n {\n family,\n given: given.length > 0 ? given : undefined,\n text: profile.name,\n },\n ],\n resourceType: 'Patient',\n telecom:\n [\n ...(profile.email ? [{ system: 'email' as const, value: profile.email }] : []),\n ...(profile.phone ? [{ system: 'phone' as const, value: profile.phone }] : []),\n ].length > 0\n ? [\n ...(profile.email ? [{ system: 'email' as const, value: profile.email }] : []),\n ...(profile.phone ? [{ system: 'phone' as const, value: profile.phone }] : []),\n ]\n : undefined,\n };\n}\n\n/**\n * Convert complete lab result to FHIR Bundle\n * This is the main function for exporting lab results to FHIR R4 format\n */\nexport function labResultToFHIRBundle(\n report: LabReportData,\n observations: LabObservationData[],\n userProfile: UserProfileData,\n): FHIRBundle {\n const patientId = userProfile.userId;\n\n // Convert observations\n const fhirObservations = observations.map((obs) => ({\n fullUrl: `urn:uuid:observation-${obs.reportId}-${obs.biomarkerCode}`,\n resource: labObservationToFHIR(\n { ...obs, collectionDate: report.collectionDate },\n patientId,\n report.laboratoryName,\n ),\n }));\n\n const observationIds = observations.map(\n (obs) => `observation-${obs.reportId}-${obs.biomarkerCode}`,\n );\n\n // Convert report\n const diagnosticReport = labReportToFHIR(report, patientId, observationIds);\n\n // Convert patient\n const fhirPatient = userProfileToFHIR(userProfile);\n\n return {\n entry: [\n {\n fullUrl: `urn:uuid:${patientId}`,\n resource: fhirPatient,\n },\n {\n fullUrl: `urn:uuid:diagnostic-report-${report.reportId}`,\n resource: diagnosticReport,\n },\n ...fhirObservations,\n ],\n resourceType: 'Bundle',\n type: 'collection',\n };\n}\n"]}
@@ -0,0 +1,99 @@
1
+ import { a as FHIRObservation, j as FHIRDiagnosticReport, b as FHIRBundle, l as FHIRPatient } from './fhir-types-D9hUzGrc.js';
2
+
3
+ /**
4
+ * Generic Lab Result Types
5
+ *
6
+ * Type definitions for lab results that work with any laboratory format.
7
+ * Used by the FHIR converter to transform internal data to FHIR R4 resources.
8
+ */
9
+ type OverallStatus = 'NORMAL' | 'ANORMAL';
10
+ type Flag = 'H' | 'L' | '';
11
+ type Gender = 'male' | 'female' | 'other' | 'unknown';
12
+ /**
13
+ * Lab report data for FHIR conversion
14
+ */
15
+ interface LabReportData {
16
+ collectionDate: string;
17
+ createdAt: string;
18
+ laboratoryName?: string;
19
+ overallStatus: OverallStatus;
20
+ processingStatus?: 'complete' | 'partial' | 'pending_review';
21
+ reportId: string;
22
+ userId: string;
23
+ }
24
+ /**
25
+ * Individual biomarker observation for FHIR conversion
26
+ */
27
+ interface LabObservationData {
28
+ biomarkerCode: string;
29
+ biomarkerName: string;
30
+ collectionDate?: string;
31
+ flag: Flag;
32
+ isQualitative?: boolean;
33
+ referenceMax?: number;
34
+ referenceMin?: number;
35
+ reportId: string;
36
+ unit: string;
37
+ value: number | string;
38
+ }
39
+ /**
40
+ * Intervention data for FHIR conversion
41
+ */
42
+ interface InterventionData {
43
+ endDate?: string;
44
+ interventionId: string;
45
+ name: string;
46
+ notes?: string;
47
+ startDate: string;
48
+ type: 'medication' | 'diet' | 'exercise' | 'sleep' | 'supplement';
49
+ }
50
+ /**
51
+ * User profile data for FHIR Patient resource
52
+ */
53
+ interface UserProfileData {
54
+ address?: {
55
+ street?: string;
56
+ number?: string;
57
+ complement?: string;
58
+ neighborhood?: string;
59
+ city?: string;
60
+ state?: string;
61
+ postalCode?: string;
62
+ country?: string;
63
+ };
64
+ birthDate?: string;
65
+ cpf?: string;
66
+ email?: string;
67
+ gender?: Gender;
68
+ name: string;
69
+ phone?: string;
70
+ userId: string;
71
+ }
72
+
73
+ /**
74
+ * FHIR Converter
75
+ *
76
+ * Converts lab results to FHIR R4 DiagnosticReport and Observation resources.
77
+ * See: https://hl7.org/fhir/diagnosticreport.html
78
+ */
79
+
80
+ /**
81
+ * Convert generic lab observation to FHIR Observation
82
+ */
83
+ declare function labObservationToFHIR(observation: LabObservationData, patientId: string, laboratoryName?: string): FHIRObservation;
84
+ /**
85
+ * Convert generic lab report to FHIR DiagnosticReport
86
+ */
87
+ declare function labReportToFHIR(report: LabReportData, patientId: string, observationIds: string[]): FHIRDiagnosticReport;
88
+ /**
89
+ * Convert user profile to FHIR Patient
90
+ * NOTE: CPF is intentionally excluded for privacy (LGPD compliance)
91
+ */
92
+ declare function userProfileToFHIR(profile: UserProfileData): FHIRPatient;
93
+ /**
94
+ * Convert complete lab result to FHIR Bundle
95
+ * This is the main function for exporting lab results to FHIR R4 format
96
+ */
97
+ declare function labResultToFHIRBundle(report: LabReportData, observations: LabObservationData[], userProfile: UserProfileData): FHIRBundle;
98
+
99
+ export { 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 };
@@ -0,0 +1,99 @@
1
+ import { a as FHIRObservation, j as FHIRDiagnosticReport, b as FHIRBundle, l as FHIRPatient } from './fhir-types-D9hUzGrc.cjs';
2
+
3
+ /**
4
+ * Generic Lab Result Types
5
+ *
6
+ * Type definitions for lab results that work with any laboratory format.
7
+ * Used by the FHIR converter to transform internal data to FHIR R4 resources.
8
+ */
9
+ type OverallStatus = 'NORMAL' | 'ANORMAL';
10
+ type Flag = 'H' | 'L' | '';
11
+ type Gender = 'male' | 'female' | 'other' | 'unknown';
12
+ /**
13
+ * Lab report data for FHIR conversion
14
+ */
15
+ interface LabReportData {
16
+ collectionDate: string;
17
+ createdAt: string;
18
+ laboratoryName?: string;
19
+ overallStatus: OverallStatus;
20
+ processingStatus?: 'complete' | 'partial' | 'pending_review';
21
+ reportId: string;
22
+ userId: string;
23
+ }
24
+ /**
25
+ * Individual biomarker observation for FHIR conversion
26
+ */
27
+ interface LabObservationData {
28
+ biomarkerCode: string;
29
+ biomarkerName: string;
30
+ collectionDate?: string;
31
+ flag: Flag;
32
+ isQualitative?: boolean;
33
+ referenceMax?: number;
34
+ referenceMin?: number;
35
+ reportId: string;
36
+ unit: string;
37
+ value: number | string;
38
+ }
39
+ /**
40
+ * Intervention data for FHIR conversion
41
+ */
42
+ interface InterventionData {
43
+ endDate?: string;
44
+ interventionId: string;
45
+ name: string;
46
+ notes?: string;
47
+ startDate: string;
48
+ type: 'medication' | 'diet' | 'exercise' | 'sleep' | 'supplement';
49
+ }
50
+ /**
51
+ * User profile data for FHIR Patient resource
52
+ */
53
+ interface UserProfileData {
54
+ address?: {
55
+ street?: string;
56
+ number?: string;
57
+ complement?: string;
58
+ neighborhood?: string;
59
+ city?: string;
60
+ state?: string;
61
+ postalCode?: string;
62
+ country?: string;
63
+ };
64
+ birthDate?: string;
65
+ cpf?: string;
66
+ email?: string;
67
+ gender?: Gender;
68
+ name: string;
69
+ phone?: string;
70
+ userId: string;
71
+ }
72
+
73
+ /**
74
+ * FHIR Converter
75
+ *
76
+ * Converts lab results to FHIR R4 DiagnosticReport and Observation resources.
77
+ * See: https://hl7.org/fhir/diagnosticreport.html
78
+ */
79
+
80
+ /**
81
+ * Convert generic lab observation to FHIR Observation
82
+ */
83
+ declare function labObservationToFHIR(observation: LabObservationData, patientId: string, laboratoryName?: string): FHIRObservation;
84
+ /**
85
+ * Convert generic lab report to FHIR DiagnosticReport
86
+ */
87
+ declare function labReportToFHIR(report: LabReportData, patientId: string, observationIds: string[]): FHIRDiagnosticReport;
88
+ /**
89
+ * Convert user profile to FHIR Patient
90
+ * NOTE: CPF is intentionally excluded for privacy (LGPD compliance)
91
+ */
92
+ declare function userProfileToFHIR(profile: UserProfileData): FHIRPatient;
93
+ /**
94
+ * Convert complete lab result to FHIR Bundle
95
+ * This is the main function for exporting lab results to FHIR R4 format
96
+ */
97
+ declare function labResultToFHIRBundle(report: LabReportData, observations: LabObservationData[], userProfile: UserProfileData): FHIRBundle;
98
+
99
+ export { 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 };
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkZ6YE6FJ4cjs = require('./chunk-Z6YE6FJ4.cjs');
7
+ require('./chunk-2EVQ2ESB.cjs');
8
+ require('./chunk-GFXKYXHW.cjs');
9
+
10
+
11
+
12
+
13
+
14
+ exports.labObservationToFHIR = _chunkZ6YE6FJ4cjs.labObservationToFHIR; exports.labReportToFHIR = _chunkZ6YE6FJ4cjs.labReportToFHIR; exports.labResultToFHIRBundle = _chunkZ6YE6FJ4cjs.labResultToFHIRBundle; exports.userProfileToFHIR = _chunkZ6YE6FJ4cjs.userProfileToFHIR;
15
+ //# sourceMappingURL=converter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/rafael/Github/precisa-saude/fhir-brasil/packages/core/dist/converter.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,6QAAC","file":"/Users/rafael/Github/precisa-saude/fhir-brasil/packages/core/dist/converter.cjs"}
@@ -0,0 +1,2 @@
1
+ export { c as FHIRAddress, d as FHIRAnnotation, e as FHIRAttachment, b as FHIRBundle, f as FHIRBundleEntry, g as FHIRCodeableConcept, h as FHIRCoding, i as FHIRContactPoint, j as FHIRDiagnosticReport, k as FHIRHumanName, F as FHIRMedicationStatement, a as FHIRObservation, l as FHIRPatient, m as FHIRPeriod, n as FHIRQuantity, o as FHIRReference, p as FHIRReferenceRange } from './fhir-types-D9hUzGrc.cjs';
2
+ export { l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-Dee-qjBV.cjs';
@@ -0,0 +1,2 @@
1
+ export { c as FHIRAddress, d as FHIRAnnotation, e as FHIRAttachment, b as FHIRBundle, f as FHIRBundleEntry, g as FHIRCodeableConcept, h as FHIRCoding, i as FHIRContactPoint, j as FHIRDiagnosticReport, k as FHIRHumanName, F as FHIRMedicationStatement, a as FHIRObservation, l as FHIRPatient, m as FHIRPeriod, n as FHIRQuantity, o as FHIRReference, p as FHIRReferenceRange } from './fhir-types-D9hUzGrc.js';
2
+ export { l as labObservationToFHIR, b as labReportToFHIR, c as labResultToFHIRBundle, u as userProfileToFHIR } from './converter-C-QpCcTL.js';
@@ -0,0 +1,15 @@
1
+ import {
2
+ labObservationToFHIR,
3
+ labReportToFHIR,
4
+ labResultToFHIRBundle,
5
+ userProfileToFHIR
6
+ } from "./chunk-UIDSSWBJ.js";
7
+ import "./chunk-I6H35QXI.js";
8
+ import "./chunk-VPMT4MRS.js";
9
+ export {
10
+ labObservationToFHIR,
11
+ labReportToFHIR,
12
+ labResultToFHIRBundle,
13
+ userProfileToFHIR
14
+ };
15
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * FHIR R4 Resource Types
3
+ *
4
+ * Type definitions for FHIR R4 resources used in lab result conversion.
5
+ * See: https://hl7.org/fhir/R4/
6
+ */
7
+ interface FHIRCodeableConcept {
8
+ coding?: FHIRCoding[];
9
+ text?: string;
10
+ }
11
+ interface FHIRCoding {
12
+ code?: string;
13
+ display?: string;
14
+ system?: string;
15
+ }
16
+ interface FHIRReference {
17
+ display?: string;
18
+ reference?: string;
19
+ }
20
+ interface FHIRQuantity {
21
+ code?: string;
22
+ system?: string;
23
+ unit?: string;
24
+ value?: number;
25
+ }
26
+ interface FHIRReferenceRange {
27
+ high?: FHIRQuantity;
28
+ low?: FHIRQuantity;
29
+ text?: string;
30
+ }
31
+ interface FHIRPeriod {
32
+ end?: string;
33
+ start?: string;
34
+ }
35
+ interface FHIRObservation {
36
+ category?: FHIRCodeableConcept[];
37
+ code: FHIRCodeableConcept;
38
+ effectiveDateTime?: string;
39
+ effectivePeriod?: FHIRPeriod;
40
+ id?: string;
41
+ interpretation?: FHIRCodeableConcept[];
42
+ issued?: string;
43
+ note?: FHIRAnnotation[];
44
+ performer?: FHIRReference[];
45
+ referenceRange?: FHIRReferenceRange[];
46
+ resourceType: 'Observation';
47
+ status: 'registered' | 'preliminary' | 'final' | 'amended' | 'corrected' | 'cancelled';
48
+ subject?: FHIRReference;
49
+ valueQuantity?: FHIRQuantity;
50
+ valueString?: string;
51
+ }
52
+ interface FHIRAnnotation {
53
+ authorString?: string;
54
+ text: string;
55
+ time?: string;
56
+ }
57
+ interface FHIRDiagnosticReport {
58
+ category?: FHIRCodeableConcept[];
59
+ code: FHIRCodeableConcept;
60
+ conclusion?: string;
61
+ conclusionCode?: FHIRCodeableConcept[];
62
+ effectiveDateTime?: string;
63
+ id?: string;
64
+ issued?: string;
65
+ performer?: FHIRReference[];
66
+ presentedForm?: FHIRAttachment[];
67
+ resourceType: 'DiagnosticReport';
68
+ result?: FHIRReference[];
69
+ resultsInterpreter?: FHIRReference[];
70
+ status: 'registered' | 'partial' | 'preliminary' | 'final' | 'amended' | 'corrected' | 'cancelled';
71
+ subject?: FHIRReference;
72
+ }
73
+ interface FHIRAttachment {
74
+ contentType?: string;
75
+ creation?: string;
76
+ data?: string;
77
+ title?: string;
78
+ url?: string;
79
+ }
80
+ interface FHIRPatient {
81
+ address?: FHIRAddress[];
82
+ birthDate?: string;
83
+ gender?: 'male' | 'female' | 'other' | 'unknown';
84
+ id?: string;
85
+ name?: FHIRHumanName[];
86
+ resourceType: 'Patient';
87
+ telecom?: FHIRContactPoint[];
88
+ }
89
+ interface FHIRHumanName {
90
+ family?: string;
91
+ given?: string[];
92
+ text?: string;
93
+ }
94
+ interface FHIRContactPoint {
95
+ system?: 'phone' | 'email' | 'fax' | 'pager' | 'url' | 'sms' | 'other';
96
+ value?: string;
97
+ }
98
+ interface FHIRAddress {
99
+ city?: string;
100
+ country?: string;
101
+ line?: string[];
102
+ postalCode?: string;
103
+ state?: string;
104
+ }
105
+ interface FHIRMedicationStatement {
106
+ category?: FHIRCodeableConcept;
107
+ dateAsserted?: string;
108
+ effectivePeriod?: FHIRPeriod;
109
+ id?: string;
110
+ medicationCodeableConcept?: FHIRCodeableConcept;
111
+ note?: FHIRAnnotation[];
112
+ resourceType: 'MedicationStatement';
113
+ status: 'active' | 'completed' | 'entered-in-error' | 'intended' | 'not-taken' | 'on-hold' | 'stopped' | 'unknown';
114
+ subject?: FHIRReference;
115
+ }
116
+ /**
117
+ * FHIR Bundle containing all resources
118
+ */
119
+ interface FHIRBundle {
120
+ entry: FHIRBundleEntry[];
121
+ resourceType: 'Bundle';
122
+ type: 'collection' | 'document' | 'message' | 'transaction' | 'batch';
123
+ }
124
+ interface FHIRBundleEntry {
125
+ fullUrl?: string;
126
+ resource: FHIRPatient | FHIRDiagnosticReport | FHIRObservation | FHIRMedicationStatement;
127
+ }
128
+
129
+ export type { FHIRMedicationStatement as F, FHIRObservation as a, FHIRBundle as b, FHIRAddress as c, FHIRAnnotation as d, FHIRAttachment as e, FHIRBundleEntry as f, FHIRCodeableConcept as g, FHIRCoding as h, FHIRContactPoint as i, FHIRDiagnosticReport as j, FHIRHumanName as k, FHIRPatient as l, FHIRPeriod as m, FHIRQuantity as n, FHIRReference as o, FHIRReferenceRange as p };