Skip to content

Commit da02157

Browse files
committed
feat(dicom): fit to page responsive layout, clinical light theme & real .dcm file upload parser
1 parent 982130d commit da02157

10 files changed

Lines changed: 5784 additions & 2365 deletions

File tree

‎dist/api/erp-invoices.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎dist/app/dicom/index.html‎

Lines changed: 1109 additions & 582 deletions
Large diffs are not rendered by default.

‎dist/demo/dicom/index.html‎

Lines changed: 1109 additions & 582 deletions
Large diffs are not rendered by default.

‎dist/dicom/index.html‎

Lines changed: 1109 additions & 582 deletions
Large diffs are not rendered by default.

‎dist/styles.css‎

Lines changed: 251 additions & 12 deletions
Large diffs are not rendered by default.

‎dist/styles/output.css‎

Lines changed: 251 additions & 12 deletions
Large diffs are not rendered by default.

‎public/styles/output.css‎

Lines changed: 251 additions & 12 deletions
Large diffs are not rendered by default.

‎src/dicom-parser.ts‎

Lines changed: 527 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/dicom.test.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,72 @@ describe("Clinical DICOM 3.0 Diagnostic Engine & RECIST 1.1 Staging", () => {
372372
expect(MODALITY_CONFIGS.MR.unit).toBe("SI");
373373
expect(MODALITY_CONFIGS.PET.unit).toBe("SUV");
374374
});
375+
376+
// 11. Zero-Dependency DICOM 3.0 (Part 10) Client-Side Parser
377+
it("parses valid DICOM Part 10 buffer and extracts clinical metadata & 16-bit CT pixel data", async () => {
378+
const { parseDicom, createSyntheticDicomBuffer } = await import("../src/dicom-parser");
379+
380+
const syntheticBuffer = createSyntheticDicomBuffer({
381+
patientName: "TEST^PATIENT^M",
382+
patientId: "#RAD-2026-X01",
383+
modality: "CT",
384+
rows: 128,
385+
columns: 128,
386+
windowCenter: -600,
387+
windowWidth: 1500
388+
});
389+
390+
expect(syntheticBuffer.byteLength).toBeGreaterThan(132 + 128 * 128 * 2);
391+
392+
// Verify 'DICM' signature at offset 128
393+
const u8 = new Uint8Array(syntheticBuffer);
394+
const magic = String.fromCharCode(u8[128], u8[129], u8[130], u8[131]);
395+
expect(magic).toBe("DICM");
396+
397+
// Parse DICOM
398+
const parsed = parseDicom(syntheticBuffer);
399+
400+
expect(parsed.metadata.patientName).toBe("TEST^PATIENT^M");
401+
expect(parsed.metadata.patientId).toBe("#RAD-2026-X01");
402+
expect(parsed.metadata.modality).toBe("CT");
403+
expect(parsed.metadata.rows).toBe(128);
404+
expect(parsed.metadata.columns).toBe(128);
405+
expect(parsed.metadata.bitsAllocated).toBe(16);
406+
expect(parsed.metadata.windowCenter).toBe(-600);
407+
expect(parsed.metadata.windowWidth).toBe(1500);
408+
expect(parsed.metadata.rescaleSlope).toBe(1);
409+
expect(parsed.metadata.rescaleIntercept).toBe(0);
410+
411+
// Verify Decoded Pixel Array
412+
expect(parsed.pixelData.length).toBe(128 * 128);
413+
expect(parsed.minPixelValue).toBeLessThanOrEqual(-700); // Air / Lung parenchyma
414+
expect(parsed.maxPixelValue).toBeGreaterThanOrEqual(400); // Cortical Ribs / Spine
415+
416+
// Verify ImageData rendering with W/L transfer function
417+
const mockImageData = {
418+
width: 128,
419+
height: 128,
420+
data: new Uint8ClampedArray(128 * 128 * 4)
421+
} as unknown as ImageData;
422+
423+
const rendered = parsed.renderToImageData(mockImageData, -600, 1500);
424+
expect(rendered.data.length).toBe(128 * 128 * 4);
425+
// Alpha channel must be 255 for all pixels
426+
expect(rendered.data[3]).toBe(255);
427+
expect(rendered.data[7]).toBe(255);
428+
429+
// In Lung window (W: 1500, L: -600), -1000 HU air is charcoal gray (floor(((-1000 - (-1350)) / 1500) * 255) = 59)
430+
expect(rendered.data[0]).toBe(59);
431+
});
432+
433+
// 12. DICOM Parser Error Handling & Edge Cases
434+
it("handles malformed or truncated DICOM buffers gracefully", async () => {
435+
const { parseDicom } = await import("../src/dicom-parser");
436+
437+
// Too small buffer (< 132 bytes)
438+
const tinyBuffer = new ArrayBuffer(50);
439+
expect(() => parseDicom(tinyBuffer)).toThrow("Buffer too small");
440+
});
375441
});
376442

443+

‎views/app-dicom.html‎

Lines changed: 1109 additions & 582 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)