reorganize packages, start converting overall app to react (very broken at the moment)
This commit is contained in:
1 parent
024fe1a448
commit
5f30f7bd35
479 files changed
+5364
-11611
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import jsPDF from 'jspdf';
|
||||
import _ from 'underscore';
|
||||
|
||||
export class BaseReport {
|
||||
constructor(options) {
|
||||
const defaultOptions = {
|
||||
width: 595.28,
|
||||
height: 841.89,
|
||||
marginTop: 30,
|
||||
marginLeft: 40,
|
||||
marginRight: 40,
|
||||
marginBottom: 30,
|
||||
showPageNumber: true
|
||||
};
|
||||
|
||||
this.options = _.extend(defaultOptions, options);
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.doc = new jsPDF('portrait', 'pt', [this.options.width, this.options.height]);
|
||||
this.options.width = Math.floor(this.options.width);
|
||||
this.options.height = Math.floor(this.options.height);
|
||||
this.currentPage = 1;
|
||||
this.printStatic();
|
||||
}
|
||||
|
||||
printStatic() {
|
||||
this.x = this.options.marginLeft;
|
||||
this.y = this.options.marginTop;
|
||||
this.printHeader();
|
||||
if (this.options.showPageNumber) {
|
||||
this.printPageNumber();
|
||||
}
|
||||
}
|
||||
|
||||
newPage() {
|
||||
this.doc.addPage();
|
||||
this.currentPage++;
|
||||
this.printStatic();
|
||||
}
|
||||
|
||||
printHeader() {
|
||||
const { marginLeft, marginRight, width } = this.options;
|
||||
const doc = this.doc;
|
||||
let y = this.y;
|
||||
|
||||
// Print the logo strokes
|
||||
doc.setDrawColor(0).setLineWidth(1);
|
||||
doc.roundedRect(marginLeft + 0.5, y + 0.5, 8, 8, 0.5, 0.5, 'D');
|
||||
doc.roundedRect(marginLeft + 11, y + 0.5, 8, 8, 0.5, 0.5, 'D');
|
||||
doc.roundedRect(marginLeft + 0.5, y + 11, 8, 8, 0.5, 0.5, 'D');
|
||||
doc.roundedRect(marginLeft + 11, y + 11, 8, 8, 0.5, 0.5, 'D');
|
||||
|
||||
// Print the logo text
|
||||
doc.setFont('Serif').setFontSize(16).setFontStyle('normal').setTextColor(0);
|
||||
doc.text('Open Health Imaging Foundation', 66, y + 14);
|
||||
y += 24;
|
||||
|
||||
// Print header horizontal line
|
||||
doc.setDrawColor(0).setLineWidth(0.5);
|
||||
doc.line(marginLeft, y, width - marginRight, y);
|
||||
y += 1;
|
||||
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
printPageNumber() {
|
||||
const doc = this.doc;
|
||||
const { marginBottom, marginRight, width, height } = this.options;
|
||||
doc.setFont('Verdana');
|
||||
doc.setFontSize(8);
|
||||
doc.setFontStyle('normal');
|
||||
doc.setTextColor(0);
|
||||
const text = `PAGE ${this.currentPage}`;
|
||||
const size = doc.getTextDimensions(text);
|
||||
doc.text(text, width - marginRight - size.w, height - marginBottom + (size.h / 2));
|
||||
}
|
||||
|
||||
save(fileName) {
|
||||
this.doc.save(fileName || 'report.pdf');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { BaseReport } from './base';
|
||||
|
||||
export class MeasurementReport extends BaseReport {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
printHeader() {
|
||||
super.printHeader();
|
||||
|
||||
const { marginLeft, marginRight, width, header } = this.options;
|
||||
const doc = this.doc;
|
||||
let y = this.y;
|
||||
|
||||
// don't print the header if not given
|
||||
if (!header) return;
|
||||
|
||||
// Print trial label
|
||||
y += 10;
|
||||
doc.setFont('verdana');
|
||||
doc.setFontSize(8);
|
||||
doc.setFontStyle('bold');
|
||||
doc.setTextColor(255);
|
||||
doc.setFillColor(16);
|
||||
const trialLabel = header.trial;
|
||||
const trialLabelWidth = doc.getTextWidth(trialLabel) + 8;
|
||||
doc.roundedRect(marginLeft, y, trialLabelWidth, 15, 3, 3, 'F');
|
||||
doc.text(trialLabel, marginLeft + 4, y + 10.5);
|
||||
|
||||
// Print patient information
|
||||
doc.setFont('verdana');
|
||||
doc.setFontSize(10);
|
||||
doc.setFontStyle('normal');
|
||||
doc.setTextColor(0);
|
||||
doc.text(`${header.patientName}\t${header.mrn}`, marginLeft + trialLabelWidth + 10, y + 11);
|
||||
y += 25;
|
||||
|
||||
// Print timepoint header
|
||||
doc.setFillColor(229);
|
||||
doc.rect(marginLeft, y, width - marginLeft - marginRight, 18, 'F');
|
||||
doc.setFont('verdana');
|
||||
doc.setFontSize(9);
|
||||
doc.setFontStyle('normal');
|
||||
doc.setTextColor(0);
|
||||
doc.text(header.timepoint.toUpperCase(), marginLeft + 4, y + 12.5);
|
||||
y += 18;
|
||||
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
printMeasurement(measurementData) {
|
||||
const { marginLeft, marginRight, marginBottom, width, height } = this.options;
|
||||
const infoHeight = 28;
|
||||
const rectSize = Math.round((width - marginLeft - marginRight - 3) / 2);
|
||||
const doc = this.doc;
|
||||
let { x, y } = this;
|
||||
const { image, location, info } = measurementData;
|
||||
const type = measurementData.type.toUpperCase();
|
||||
const number = measurementData.number.toString();
|
||||
|
||||
if (y + rectSize + infoHeight > height - marginBottom) {
|
||||
this.newPage();
|
||||
x = this.x;
|
||||
y = this.y;
|
||||
}
|
||||
|
||||
// Print the image
|
||||
doc.setFillColor(0);
|
||||
doc.rect(x, y, rectSize, rectSize, 'F');
|
||||
doc.addImage(image, 'JPEG', x + 1, y + 1, rectSize - 2, rectSize - 2);
|
||||
y += rectSize;
|
||||
|
||||
// Print the measurement type
|
||||
doc.setFont('verdana').setFontSize(10).setFontStyle('bold').setTextColor(255);
|
||||
const typeWidth = Math.round(doc.getTextWidth(type));
|
||||
const typeX = x + rectSize - typeWidth;
|
||||
doc.setFillColor(64);
|
||||
doc.rect(typeX - 8, y - 16, typeWidth + 8, 16, 'F');
|
||||
doc.text(type, typeX - 4, y - 5);
|
||||
|
||||
// Print the measurement number
|
||||
doc.setFillColor(224);
|
||||
doc.circle(x + 9, y - 10, 7, 'F');
|
||||
doc.setFont('courier').setTextColor(0);
|
||||
const numberHalfWidth = doc.getTextWidth(number) / 2;
|
||||
doc.text(number, x + 9 - numberHalfWidth, y - 7);
|
||||
|
||||
// Print the measurement location and info
|
||||
doc.setFillColor(240);
|
||||
doc.rect(x, y, rectSize, infoHeight, 'F');
|
||||
doc.setFont('verdana').setFontSize(9);
|
||||
doc.text(location, x + 4, y + 11);
|
||||
doc.setFontStyle('normal');
|
||||
doc.text(info, x + 4, y + 24);
|
||||
y += infoHeight;
|
||||
|
||||
if (x === marginLeft) {
|
||||
this.x = width - marginRight - rectSize;
|
||||
} else {
|
||||
this.x = marginLeft;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import moment from 'moment';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
export const getExportMeasurementData = async (measurementApi, timepointApi) => {
|
||||
const currentTimepoint = timepointApi.current();
|
||||
const { timepointId } = currentTimepoint;
|
||||
const study = OHIF.viewer.Studies.findBy({
|
||||
studyInstanceUid: currentTimepoint.studyInstanceUids[0]
|
||||
});
|
||||
const { studyDescription, patientId, studyDate } = study;
|
||||
const patientName = OHIF.viewerbase.helpers.formatPN(study.patientName);
|
||||
|
||||
// All headers
|
||||
const measurementData = {
|
||||
patientName,
|
||||
mrn: patientId,
|
||||
studyDate: moment(studyDate).format('MMM DD YYYY'),
|
||||
studyDescription,
|
||||
data: []
|
||||
};
|
||||
|
||||
const addNewMeasurement = async (measurement) => {
|
||||
const imageId = OHIF.viewerbase.getImageIdForImagePath(measurement.imagePath);
|
||||
const { seriesDescription, seriesDate, modality, seriesInstanceUid } = cornerstone.metaData.get('series', imageId);
|
||||
const meanStdDev = measurement.meanStdDev || {};
|
||||
|
||||
measurementData.data.push({
|
||||
seriesModality: modality,
|
||||
seriesDate: moment(seriesDate).format('MMM DD YYYY'),
|
||||
seriesDescription,
|
||||
seriesInstanceUid,
|
||||
measurementTool: measurement.toolType,
|
||||
measurementDescription: OHIF.measurements.getLocationLabel(measurement.location) || 'No description',
|
||||
number: measurement.measurementNumber,
|
||||
length: measurement.length || '-',
|
||||
mean: meanStdDev.mean || '-',
|
||||
stdDev: meanStdDev.stdDev || '-',
|
||||
area: measurement.area || '-'
|
||||
});
|
||||
};
|
||||
|
||||
let allMeasurements = [];
|
||||
Object.keys(measurementApi.toolGroups).forEach( toolGroup => {
|
||||
let measurements = measurementApi.fetch(toolGroup, { timepointId });
|
||||
allMeasurements = allMeasurements.concat(measurements);
|
||||
});
|
||||
const iterator = allMeasurements[Symbol.iterator]();
|
||||
|
||||
let measurement;
|
||||
let current = iterator.next();
|
||||
while (!current.done) {
|
||||
measurement = current.value;
|
||||
await addNewMeasurement(measurement);
|
||||
current = iterator.next();
|
||||
}
|
||||
|
||||
return measurementData;
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
import { getExportMeasurementData } from "./reportMeasurementData";
|
||||
|
||||
const columnDelimiter = ',';
|
||||
const lineDelimiter = '\n';
|
||||
const headers = {
|
||||
patientName: 'Patient Name',
|
||||
mrn: 'MRN',
|
||||
studyDate: 'Study Date',
|
||||
seriesModality: 'Series Modality',
|
||||
seriesDate: 'Series Date',
|
||||
seriesDescription: 'Series Description',
|
||||
seriesInstanceUid: 'Series InstanceUid',
|
||||
measurementTool: 'Measurement Tool',
|
||||
measurementDescription: 'Measurement Description',
|
||||
length: 'Length',
|
||||
mean: 'Mean',
|
||||
stdDev: 'stdDev',
|
||||
area: 'area'
|
||||
};
|
||||
|
||||
export const getCSVMeasurementData = async (measurementApi, timepointApi) => {
|
||||
let lineData = [];
|
||||
let csvData = '';
|
||||
const dataObject = await getExportMeasurementData(measurementApi, timepointApi);
|
||||
|
||||
for(header in headers) {
|
||||
lineData.push(headers[header]);
|
||||
}
|
||||
csvData += lineData.join(columnDelimiter) + lineDelimiter;
|
||||
|
||||
for(measurementLine of dataObject.data) {
|
||||
lineData = [
|
||||
dataObject.patientName,
|
||||
dataObject.mrn,
|
||||
dataObject.studyDate,
|
||||
measurementLine.seriesModality,
|
||||
measurementLine.seriesDate,
|
||||
measurementLine.seriesDescription,
|
||||
measurementLine.seriesInstanceUid,
|
||||
measurementLine.measurementTool,
|
||||
measurementLine.measurementDescription,
|
||||
measurementLine.length,
|
||||
measurementLine.mean,
|
||||
measurementLine.stdDev,
|
||||
measurementLine.area
|
||||
];
|
||||
csvData += lineData.join(columnDelimiter) + lineDelimiter;
|
||||
}
|
||||
|
||||
return csvData;
|
||||
};
|
||||
Reference in new issue
Block a user