Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Save units and calibration #354

Merged
merged 10 commits into from
Jun 19, 2023
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"example": "examples"
},
"scripts": {
"test": "jest --testTimeout 60000",
"test": "jest --testTimeout 60000 .",
"build": "rollup -c",
"build:examples": "npm run build && npx cpx 'build/**/*.{js,map}' examples/js",
"start": "rollup -c -w",
Expand Down
1 change: 0 additions & 1 deletion src/ValueRepresentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class ValueRepresentation {
validationLog.error("Invalid vr type", type, "- using US");
vr = VRinstances["US"];
} else {
console.log("validationLog", validationLog.level);
validationLog.error("Invalid vr type", type, "- using UN");
vr = VRinstances["UN"];
}
Expand Down
14 changes: 5 additions & 9 deletions src/adapters/Cornerstone/CircleRoi.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import MeasurementReport from "./MeasurementReport";
import TID300Circle from "../../utilities/TID300/Circle";
import CORNERSTONE_4_TAG from "./cornerstone4Tag";
import { toArray } from "../helpers.js";

const CIRCLEROI = "CircleRoi";
const FINDING = "121071";
const FINDING_SITE = "G-C0E3";

class CircleRoi {
constructor() {}

/** Gets the measurement data for cornerstone, given DICOM SR measurement data. */
static getMeasurementData(MeasurementGroup) {
const {
defaultState,
NUMGroup,
SCOORDGroup
} = MeasurementReport.getSetupMeasurementData(MeasurementGroup);
const { defaultState, NUMGroup, SCOORDGroup } =
MeasurementReport.getSetupMeasurementData(MeasurementGroup);

const { GraphicData } = SCOORDGroup;

Expand Down Expand Up @@ -71,7 +65,7 @@ class CircleRoi {
static getTID300RepresentationArguments(tool) {
const { cachedStats = {}, handles, finding, findingSites } = tool;
const { start: center, end } = handles;
const { area, radius } = cachedStats;
const { area, areaUnit = "mm2", unit = "mm", radius } = cachedStats;

const perimeter = 2 * Math.PI * radius;
const points = [];
Expand All @@ -83,7 +77,9 @@ class CircleRoi {

return {
area,
areaUnit,
perimeter,
unit,
radius,
points,
trackingIdentifierTextValue,
Expand Down
16 changes: 4 additions & 12 deletions src/utilities/TID300/Bidirectional.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DicomMetaDictionary } from "../../DicomMetaDictionary.js";
import TID300Measurement from "./TID300Measurement.js";
import unit2CodingValue from "./unit2CodingValue.js";

export default class Bidirectional extends TID300Measurement {
contentItem() {
Expand All @@ -8,6 +9,7 @@ export default class Bidirectional extends TID300Measurement {
shortAxis,
longAxisLength,
shortAxisLength,
unit,
ReferencedSOPSequence
} = this.props;

Expand All @@ -21,12 +23,7 @@ export default class Bidirectional extends TID300Measurement {
CodeMeaning: "Long Axis"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "millimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: longAxisLength
},
ContentSequence: {
Expand Down Expand Up @@ -55,12 +52,7 @@ export default class Bidirectional extends TID300Measurement {
CodeMeaning: "Short Axis"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "millimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: shortAxisLength
},
ContentSequence: {
Expand Down
41 changes: 41 additions & 0 deletions src/utilities/TID300/Calibration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import TID300Measurement from "./TID300Measurement.js";
import unit2CodingValue from "./unit2CodingValue.js";

export default class Calibration extends TID300Measurement {
contentItem() {
const {
point1,
point2,
unit = "mm",
distance,
ReferencedSOPSequence
} = this.props;

return this.getMeasurement([
{
RelationshipType: "CONTAINS",
ValueType: "NUM",
ConceptNameCodeSequence: {
CodeValue: "102304005",
CodingSchemeDesignator: "SCT",
CodeMeaning: "Calibration Ruler"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: distance
},
ContentSequence: {
RelationshipType: "INFERRED FROM",
ValueType: "SCOORD",
GraphicType: "POLYLINE",
GraphicData: [point1.x, point1.y, point2.x, point2.y],
ContentSequence: {
RelationshipType: "SELECTED FROM",
ValueType: "IMAGE",
ReferencedSOPSequence
}
}
}
]);
}
}
20 changes: 6 additions & 14 deletions src/utilities/TID300/Circle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DicomMetaDictionary } from "../../DicomMetaDictionary.js";
import TID300Measurement from "./TID300Measurement.js";
import unit2CodingValue from "./unit2CodingValue.js";

/**
* Expand an array of points stored as objects into
Expand All @@ -26,7 +26,9 @@ export default class Circle extends TID300Measurement {
ReferencedSOPSequence,
use3DSpatialCoordinates = false,
perimeter,
area
area,
areaUnit = "mm2",
unit = "mm"
} = this.props;

// Combine all lengths to save the perimeter
Expand All @@ -47,12 +49,7 @@ export default class Circle extends TID300Measurement {
CodeMeaning: "Perimeter" // TODO: Look this up from a Code Meaning dictionary
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "millimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: perimeter
},
ContentSequence: {
Expand All @@ -79,12 +76,7 @@ export default class Circle extends TID300Measurement {
CodeMeaning: "Area" // TODO: Look this up from a Code Meaning dictionary
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm2",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "SquareMilliMeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(areaUnit),
NumericValue: area
},
ContentSequence: {
Expand Down
10 changes: 3 additions & 7 deletions src/utilities/TID300/Ellipse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TID300Measurement from "./TID300Measurement.js";
import unit2CodingValue from "./unit2CodingValue.js";

/**
* Expand an array of points stored as objects into
Expand All @@ -20,7 +21,7 @@ function expandPoints(points) {

export default class Ellipse extends TID300Measurement {
contentItem() {
const { points, ReferencedSOPSequence, area } = this.props;
const { points, ReferencedSOPSequence, area, areaUnit } = this.props;

const GraphicData = expandPoints(points);

Expand All @@ -34,12 +35,7 @@ export default class Ellipse extends TID300Measurement {
CodeMeaning: "AREA"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm2",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "squaremillimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(areaUnit),
NumericValue: area
},
ContentSequence: {
Expand Down
17 changes: 9 additions & 8 deletions src/utilities/TID300/Length.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { DicomMetaDictionary } from "../../DicomMetaDictionary.js";
import TID300Measurement from "./TID300Measurement.js";
import unit2CodingValue from "./unit2CodingValue.js";

export default class Length extends TID300Measurement {
contentItem() {
const { point1, point2, distance, ReferencedSOPSequence } = this.props;
const {
point1,
point2,
unit = "mm",
distance,
ReferencedSOPSequence
} = this.props;

return this.getMeasurement([
{
Expand All @@ -15,12 +21,7 @@ export default class Length extends TID300Measurement {
CodeMeaning: "Length"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "millimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: distance
},
ContentSequence: {
Expand Down
22 changes: 8 additions & 14 deletions src/utilities/TID300/Polygon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DicomMetaDictionary } from "../../DicomMetaDictionary.js";
import TID300Measurement from "./TID300Measurement.js";
import unit2CodingValue from "./unit2CodingValue.js";

/**
* Expand an array of points stored as objects into
Expand All @@ -26,11 +27,14 @@ export default class Polygon extends TID300Measurement {
contentItem() {
const {
points,
perimeter,
unit = "mm",
area,
areaUnit,
ReferencedSOPSequence,
use3DSpatialCoordinates = false
} = this.props;

const perimeter = {};
const GraphicData = expandPoints(points);

return this.getMeasurement([
Expand All @@ -43,12 +47,7 @@ export default class Polygon extends TID300Measurement {
CodeMeaning: "Perimeter"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "millimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: perimeter
},
ContentSequence: {
Expand All @@ -74,13 +73,8 @@ export default class Polygon extends TID300Measurement {
CodeMeaning: "Area"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm2",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "SquareMilliMeter"
},
NumericValue: perimeter
MeasurementUnitsCodeSequence: unit2CodingValue(areaUnit),
NumericValue: area
},
ContentSequence: {
RelationshipType: "INFERRED FROM",
Expand Down
22 changes: 7 additions & 15 deletions src/utilities/TID300/Polyline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DicomMetaDictionary } from "../../DicomMetaDictionary.js";
import TID300Measurement from "./TID300Measurement.js";
import TID300Measurement from "./TID300Measurement";
import unit2CodingValue from "./unit2CodingValue";

/**
* Expand an array of points stored as objects into
Expand Down Expand Up @@ -27,9 +27,11 @@ export default class Polyline extends TID300Measurement {
const {
points,
area,
areaUnit = "mm2",
ReferencedSOPSequence,
use3DSpatialCoordinates = false,
perimeter
perimeter,
unit = "mm"
} = this.props;

const GraphicData = expandPoints(points);
Expand All @@ -45,12 +47,7 @@ export default class Polyline extends TID300Measurement {
CodeMeaning: "Perimeter"
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "millimeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(unit),
NumericValue: perimeter
},
ContentSequence: {
Expand All @@ -77,12 +74,7 @@ export default class Polyline extends TID300Measurement {
CodeMeaning: "Area" // TODO: Look this up from a Code Meaning dictionary
},
MeasuredValueSequence: {
MeasurementUnitsCodeSequence: {
CodeValue: "mm2",
CodingSchemeDesignator: "UCUM",
CodingSchemeVersion: "1.4",
CodeMeaning: "SquareMilliMeter"
},
MeasurementUnitsCodeSequence: unit2CodingValue(areaUnit),
NumericValue: area
},
ContentSequence: {
Expand Down
8 changes: 6 additions & 2 deletions src/utilities/TID300/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import CobbAngle from "./CobbAngle";
import Bidirectional from "./Bidirectional.js";
import Polyline from "./Polyline.js";
import Polygon from "./Polygon.js";
import Ellipse from "./Ellipse.js";
import Ellipse from "./Ellipse";
import Circle from "./Circle";
import Calibration from "./Calibration";
import unit2CodingValue from "./unit2CodingValue";

// To be implemented:
// - Cornerstone Probe
Expand Down Expand Up @@ -73,7 +75,9 @@ const TID300 = {
Polyline,
Polygon,
Ellipse,
Circle
Circle,
Calibration,
unit2CodingValue
};

export { TID300Measurement, Length };
Expand Down
Loading