OHIF-190 - Rehydrate PR (#1835)

* WIP rehydration.

* WIP OHIF-190 rehydrate.

* Remove debugger statements.

* Merge in and fix after OHIF-197 and OHIF-198

* Remove console.log

* Fix typo

* fix length tracking bug

* Respond to reviewer comments.
This commit is contained in:
James Petts authored and GitHub committed 2020-07-01 11:08:56 +02:00
1 parent 25de9046b3
commit bc2bde890b
17 files changed
+674 -46

No files matched your search

@@ -155,6 +155,32 @@ class MeasurementService {
return source;
}
getSource(name, version) {
const { sources } = this;
const id = this._getSourceId(name, version);
return sources[id];
}
getSourceMappings(name, version) {
const { mappings } = this;
const id = this._getSourceId(name, version);
return mappings[id];
}
_getSourceId(name, version) {
const { sources } = this;
const sourceId = Object.keys(sources).find(sourceId => {
const source = sources[sourceId];
return source.name === name && source.version === version;
});
return sourceId;
}
/**
* Add a new measurement matching criteria along with mapping functions.
*
@@ -256,6 +282,93 @@ class MeasurementService {
}
}
/**
* Add a raw measurement into a source so that it may be
* Converted to/from annotation in the same way. E.g. import serialized data
* Of the same form as the measurement source.
* @param {MeasurementSource} source The measurement source instance.
* @param {string} definition The source definition you want to add the measuremnet to.
* @param {object} data The data you wish to add to the source.
* @param {function} toMeasurementSchema A function to get the `data` into the same shape as the source definition.
*/
addRawMeasurement(source, definition, data, toMeasurementSchema) {
if (!this._isValidSource(source)) {
log.warn('Invalid source. Exiting early.');
return;
}
const sourceInfo = this._getSourceInfo(source);
if (!definition) {
log.warn('No source definition provided. Exiting early.');
return;
}
if (!this._sourceHasMappings(source)) {
log.warn(
`No measurement mappings found for '${sourceInfo}' source. Exiting early.`
);
return;
}
let measurement = {};
try {
/* Convert measurement */
measurement = toMeasurementSchema(data);
/* Assign measurement source instance */
measurement.source = source;
} catch (error) {
log.warn(
`Failed to map '${sourceInfo}' measurement for definition ${definition}:`,
error.message
);
return;
}
if (!this._isValidMeasurement(measurement)) {
log.warn(
`Attempting to add or update a invalid measurement provided by '${sourceInfo}'. Exiting early.`
);
return;
}
let internalId = data.id;
if (!internalId) {
internalId = guid();
log.warn(`Measurement ID not found. Generating UID: ${internalId}`);
}
const newMeasurement = {
...measurement,
modifiedTimestamp: Math.floor(Date.now() / 1000),
id: internalId,
};
if (this.measurements[internalId]) {
log.info(
`Measurement already defined. Updating measurement.`,
newMeasurement
);
this.measurements[internalId] = newMeasurement;
this._broadcastChange(
this.EVENTS.MEASUREMENT_UPDATED,
source,
newMeasurement
);
} else {
log.info(`Measurement added.`, newMeasurement);
this.measurements[internalId] = newMeasurement;
this._broadcastChange(
this.EVENTS.MEASUREMENT_ADDED,
source,
newMeasurement
);
}
return newMeasurement.id;
}
/**
* Adds or update persisted measurements.
*
@@ -15,13 +15,22 @@ const ViewportActionBar = ({
showNavArrows,
showPatientInfo: patientInfoVisibility,
onSeriesChange,
onHydrationClick,
}) => {
const [showPatientInfo, setShowPatientInfo] = useState(patientInfoVisibility);
// TODO -> Remake this component with a bunch of generic slots that can be filled,
// Its not generic at all, isTracked etc shouldn't be parts of this component.
// It shouldn't care that a tracking mode or SR exists.
// Things like the right/left buttons should be made into smaller
// Components you can compose.
// OHIF-200 ticket.
const {
label,
isTracked,
isLocked,
isHydrated,
modality,
studyDate,
currentSeries,
@@ -44,18 +53,30 @@ const ViewportActionBar = ({
const renderIconStatus = () => {
if (modality === 'SR') {
return (
<div className="relative flex p-1 border rounded border-primary-light">
<span className="text-sm font-bold leading-none text-primary-light">
SR
</span>
{isLocked && (
<Icon
name="lock"
className="absolute w-3 text-white"
style={{ top: -6, right: -6 }}
/>
<>
<div className="relative flex p-1 border rounded border-primary-light">
<span className="text-sm font-bold leading-none text-primary-light">
SR
</span>
{isLocked && (
<Icon
name="lock"
className="absolute w-3 text-white"
style={{ top: -6, right: -6 }}
/>
)}
</div>
{!isLocked && !isHydrated && (
<div className="relative flex p-1 border rounded border-primary-light">
<span
className="text-sm font-bold leading-none text-primary-light"
onClick={onHydrationClick}
>
Edit
</span>
</div>
)}
</div>
</>
);
}
@@ -28,13 +28,13 @@ function ViewerViewportGrid(props) {
displaySets => {
displaySets.sort((a, b) => {
const isImageSet = x => x instanceof ImageSet;
return (isImageSet(a) === isImageSet(b)) ? 0 : isImageSet(a) ? -1 : 1;
return isImageSet(a) === isImageSet(b) ? 0 : isImageSet(a) ? -1 : 1;
});
viewportGridService.setDisplaysetForViewport({
viewportIndex: 0,
displaySetInstanceUID: displaySets[0].displaySetInstanceUID,
});
},
}
);
return () => {