fix: fallback to original dataset VR for XS

Co-authored-by: Davide Punzo <punzodavide@hotmail.it>
This commit is contained in:
Igor Octaviano 2020-12-03 12:15:27 -03:00 committed by GitHub
parent 138e0fb3bf
commit f57725ac8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 25 deletions

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { classes } from '@ohif/core'; import { classes, cornerstone as OHIFCornerstone } from '@ohif/core';
import dcmjs from 'dcmjs'; import dcmjs from 'dcmjs';
import DicomBrowserSelect from './DicomBrowserSelect'; import DicomBrowserSelect from './DicomBrowserSelect';
import moment from 'moment'; import moment from 'moment';
@ -10,6 +10,8 @@ const { ImageSet } = classes;
const { DicomMetaDictionary } = dcmjs.data; const { DicomMetaDictionary } = dcmjs.data;
const { nameMap } = DicomMetaDictionary; const { nameMap } = DicomMetaDictionary;
const { metadataProvider } = OHIFCornerstone;
const DicomTagBrowser = ({ displaySets, displaySetInstanceUID }) => { const DicomTagBrowser = ({ displaySets, displaySetInstanceUID }) => {
const [ const [
activeDisplaySetInstanceUID, activeDisplaySetInstanceUID,
@ -17,6 +19,7 @@ const DicomTagBrowser = ({ displaySets, displaySetInstanceUID }) => {
] = useState(displaySetInstanceUID); ] = useState(displaySetInstanceUID);
const [activeInstance, setActiveInstance] = useState(0); const [activeInstance, setActiveInstance] = useState(0);
const [tags, setTags] = useState([]); const [tags, setTags] = useState([]);
const [meta, setMeta] = useState('');
const [instanceList, setInstanceList] = useState([]); const [instanceList, setInstanceList] = useState([]);
const [displaySetList, setDisplaySetList] = useState([]); const [displaySetList, setDisplaySetList] = useState([]);
const [isImageStack, setIsImageStack] = useState(false); const [isImageStack, setIsImageStack] = useState(false);
@ -83,6 +86,7 @@ const DicomTagBrowser = ({ displaySets, displaySetInstanceUID }) => {
} }
setTags(getSortedTags(metadata)); setTags(getSortedTags(metadata));
setMeta(metadata);
setInstanceList(instanceList); setInstanceList(instanceList);
setDisplaySetList(newDisplaySetList); setDisplaySetList(newDisplaySetList);
setIsImageStack(isImageStack); setIsImageStack(isImageStack);
@ -114,41 +118,43 @@ const DicomTagBrowser = ({ displaySets, displaySetInstanceUID }) => {
options={displaySetList} options={displaySetList}
/> />
{instanceSelectList} {instanceSelectList}
<DicomTagTable tags={tags}></DicomTagTable> <DicomTagTable tags={tags} meta={meta}></DicomTagTable>
</div> </div>
); );
}; };
function DicomTagTable({ tags }) { function DicomTagTable({ tags, meta }) {
const rows = getFormattedRowsFromTags(tags); const rows = getFormattedRowsFromTags(tags, meta);
return ( return (
<div> <div>
<table className="dicom-tag-browser-table"> <table className="dicom-tag-browser-table">
<tr> <tbody>
<th className="dicom-tag-browser-table-left">Tag</th> <tr>
<th className="dicom-tag-browser-table-left">Value Representation</th> <th className="dicom-tag-browser-table-left">Tag</th>
<th className="dicom-tag-browser-table-left">Keyword</th> <th className="dicom-tag-browser-table-left">Value Representation</th>
<th className="dicom-tag-browser-table-left">Value</th> <th className="dicom-tag-browser-table-left">Keyword</th>
</tr> <th className="dicom-tag-browser-table-left">Value</th>
{rows.map(row => { </tr>
const className = row.className ? row.className : null; {rows.map((row, index) => {
const className = row.className ? row.className : null;
return ( return (
<tr className={className}> <tr className={className} key={`DICOMTagRow-${index}`}>
<td>{row[0]}</td> <td>{row[0]}</td>
<td className="dicom-tag-browser-table-center">{row[1]}</td> <td className="dicom-tag-browser-table-center">{row[1]}</td>
<td>{row[2]}</td> <td>{row[2]}</td>
<td>{row[3]}</td> <td>{row[3]}</td>
</tr> </tr>
); );
})} })}
</tbody>
</table> </table>
</div> </div>
); );
} }
function getFormattedRowsFromTags(tags) { function getFormattedRowsFromTags(tags, meta) {
const rows = []; const rows = [];
tags.forEach(tagInfo => { tags.forEach(tagInfo => {
@ -175,6 +181,17 @@ function getFormattedRowsFromTags(tags) {
rows.push(...formatedRowsFromTags); rows.push(...formatedRowsFromTags);
}); });
} else { } else {
if (tagInfo.vr === 'xs') {
try {
const dataset = metadataProvider.getStudyDataset(meta.StudyInstanceUID);
const tag = dcmjs.data.Tag.fromPString(tagInfo.tag).toCleanString();
const originalTagInfo = dataset[tag];
tagInfo.vr = originalTagInfo.vr;
} catch (error) {
console.error(`Failed to parse value representation for tag '${tagInfo.keyword}'`);
}
}
rows.push([ rows.push([
`${tagInfo.tagIndent}${tagInfo.tag}`, `${tagInfo.tagIndent}${tagInfo.tag}`,
tagInfo.vr, tagInfo.vr,

View File

@ -20,6 +20,7 @@ class MetadataProvider {
writable: false, writable: false,
value: new Map(), value: new Map(),
}); });
this.datasets = {};
} }
async addInstance(dicomJSONDatasetOrP10ArrayBuffer, options = {}) { async addInstance(dicomJSONDatasetOrP10ArrayBuffer, options = {}) {
@ -52,6 +53,7 @@ class MetadataProvider {
SOPInstanceUID, SOPInstanceUID,
} = naturalizedDataset; } = naturalizedDataset;
this._getAndCacheStudyDataset(StudyInstanceUID, dicomJSONDataset);
const study = this._getAndCacheStudy(StudyInstanceUID); const study = this._getAndCacheStudy(StudyInstanceUID);
const series = this._getAndCacheSeriesFromStudy(study, SeriesInstanceUID); const series = this._getAndCacheSeriesFromStudy(study, SeriesInstanceUID);
const instance = this._getAndCacheInstanceFromStudy(series, SOPInstanceUID); const instance = this._getAndCacheInstanceFromStudy(series, SOPInstanceUID);
@ -71,6 +73,16 @@ class MetadataProvider {
this.imageIdToUIDs.set(imageId, uids); this.imageIdToUIDs.set(imageId, uids);
} }
_getAndCacheStudyDataset(StudyInstanceUID, dataset) {
if (!this.datasets[StudyInstanceUID]) {
this.datasets[StudyInstanceUID] = dataset;
}
}
getStudyDataset(StudyInstanceUID) {
return this.datasets[StudyInstanceUID];
}
_getAndCacheStudy(StudyInstanceUID) { _getAndCacheStudy(StudyInstanceUID) {
const studies = this.studies; const studies = this.studies;
@ -83,6 +95,7 @@ class MetadataProvider {
return study; return study;
} }
_getAndCacheSeriesFromStudy(study, SeriesInstanceUID) { _getAndCacheSeriesFromStudy(study, SeriesInstanceUID) {
let series = study.series.get(SeriesInstanceUID); let series = study.series.get(SeriesInstanceUID);

View File

@ -15,8 +15,8 @@ const ErrorFallback = ({ error, componentStack, resetErrorBoundary }) => {
const OHIFErrorBoundary = ({ const OHIFErrorBoundary = ({
context = 'OHIF', context = 'OHIF',
onReset = () => {}, onReset = () => { },
onError = () => {}, onError = () => { },
fallbackComponent, fallbackComponent,
children, children,
}) => { }) => {
@ -45,7 +45,7 @@ OHIFErrorBoundary.propTypes = {
onReset: PropTypes.func, onReset: PropTypes.func,
onError: PropTypes.func, onError: PropTypes.func,
children: PropTypes.node.isRequired, children: PropTypes.node.isRequired,
fallbackComponent: PropTypes.element, fallbackComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func, PropTypes.element]),
}; };
export default OHIFErrorBoundary; export default OHIFErrorBoundary;