first commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import fs from 'node:fs'
|
||||
import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs'
|
||||
import { WorkerMessageHandler } from 'pdfjs-dist/legacy/build/pdf.worker.mjs'
|
||||
import { parseEncodedVaccinationRecordMetadata } from '../../src/lib/vaccinationRecordMetadata.js'
|
||||
|
||||
globalThis.pdfjsWorker = { WorkerMessageHandler }
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @returns {Promise<{ patientName: string, dateOfBirth: string, notes: string, rows: object[] }>}
|
||||
*/
|
||||
export async function parseVaccinationRecordPdf(filePath) {
|
||||
const data = new Uint8Array(fs.readFileSync(filePath))
|
||||
const doc = await getDocument({ data, useSystemFonts: true }).promise
|
||||
const page = await doc.getPage(1)
|
||||
const content = await page.getTextContent()
|
||||
|
||||
const textItems = content.items.map((item) => item.str)
|
||||
const metadataText =
|
||||
textItems.find((s) => s.startsWith('CTM_VR:')) ??
|
||||
textItems.find((s) => s.includes('CTM_VR:')) ??
|
||||
textItems.join('')
|
||||
return parseEncodedVaccinationRecordMetadata(metadataText)
|
||||
}
|
||||
Reference in New Issue
Block a user