ohif-viewer/extensions/tmtv/src/utils/createAndDownloadTMTVReport.js
Bill Wallace 57205703bb
Fix contour annotations RTSS saving (#5545)
* [WIP] Fix contour annotations RTSS saving

* fix: Export image sop image reference provider

* Fixes for download with filename

* Updates to fix metadata issues with CS3D

* Updates to save menu

* Fixing some additional re-save metadata

* Add support for saving with predecessor image sequence

* PR comment fixes

* fix: Load RTSS after save

* fix segmentation save

* fix load of mixed seg/rt studies

* Use frame module to get information on the frame shown

* Fix study browser to use instances.length when numImageFrames not present

* fix: Load of display set split from multiple non-FOR referenes

* Fix RT and SEG applying to wrong series because of using
referenced series sequence without checkout sop instances

* Fix save seg

* Update to released CS3D versions

* test: Add revokeObjectURL to test download blob

* Add hard dependency on mode-basic to fix build order issues

* fix: build

* Try to fix build segmentation

* PR comments

* PR comment update
2025-11-21 13:07:26 -05:00

55 lines
1.6 KiB
JavaScript

import { utils } from '@ohif/core';
const { downloadCsv } = utils;
export default function createAndDownloadTMTVReport(segReport, additionalReportRows, options = {}) {
const firstReport = segReport[Object.keys(segReport)[0]];
const columns = Object.keys(firstReport);
const csv = [
columns
.map(column =>
column.toLowerCase().startsWith('namedstats_') ? column.substring(11) : column
)
.join(','),
];
Object.values(segReport).forEach(segmentation => {
const row = [];
columns.forEach(column => {
// if it is array then we need to replace , with space to avoid csv parsing error
row.push(
segmentation[column] && typeof segmentation[column] === 'object'
? Array.isArray(segmentation[column])
? segmentation[column].join(' ')
: segmentation[column].value && Array.isArray(segmentation[column].value)
? segmentation[column].value.join(' ')
: (segmentation[column].value ?? segmentation[column])
: segmentation[column]
);
});
csv.push(row.join(','));
});
csv.push('');
csv.push('');
csv.push('');
csv.push(`Patient ID,${firstReport.PatientID}`);
csv.push(`Study Date,${firstReport.StudyDate}`);
csv.push('');
additionalReportRows.forEach(({ key, value: values }) => {
const temp = [];
temp.push(`${key}`);
Object.keys(values).forEach(k => {
temp.push(`${k}`);
temp.push(`${values[k]}`);
});
csv.push(temp.join(','));
});
downloadCsv(csv.join('\n'), {
filename: options.filename ?? `${firstReport.PatientID}_tmtv.csv`,
});
}