nuVistA/htdocs/adapter/view.dcm.html
2023-08-29 21:29:15 -04:00

64 lines
2.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DICOM</title>
<style type="text/css">
figure {
border: 1px solid #000;
}
figcaption {
border-bottom: 1px solid #000;
padding: 0.25em;
background-color: #ccc;
}
</style>
</head>
<body>
<script type="text/javascript" src="/adapter/dicom.ts.js"></script>
<script type="text/javascript">
function request(method, url, responseType) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
if(responseType) xhr.responseType = responseType;
xhr.onload = resolve;
xhr.onerror = reject;
xhr.send();
});
}
function createElementX(tag, attrs) {
var res = document.createElement(tag);
if(attrs) for(var k in attrs) if(attrs.hasOwnProperty(k)) res.setAttribute(k, attrs[k]);
for(var i = 2, child; i < arguments.length; ++i) res.appendChild((typeof (child = arguments[i]) === 'string') || (child instanceof String) ? document.createTextNode(child) : child);
return res;
}
var pathname = window.location.pathname, filename = document.title = pathname.split('/').pop();
var body = document.body;
var header = document.createElement('div');
header.append(createElementX('a', { href: pathname }, 'Download ' + filename))
body.appendChild(header);
request('GET', pathname, 'arraybuffer').then(function(evt) {
var filedata = evt.target.response;
var cnv = document.createElement('canvas'), renderer = new dicom.ts.Renderer(cnv), img;
var dataset = dicom.ts.parseImage(filedata), count = dataset.numberOfFrames;
header.appendChild(createElementX('div', null, dataset.patientName + ' #' + dataset.patientID));
header.appendChild(createElementX('div', null, dataset.imageDescription));
header.appendChild(createElementX('div', null, dataset.studyDate.toLocaleDateString('sv-SE') + ' @ ' + dataset.studyTime));
header.appendChild(createElementX('div', null, dataset.modality + ' series #' + dataset.seriesNumber));
(function renderall(i) {
if((i = i || 0) >= count) return;
renderer.render(dataset, i).then(function() {
body.appendChild(createElementX('figure', null, createElementX('figcaption', null, 'Image ' + (i + 1) + ' of ' + count), img = createElementX('img', { src: cnv.toDataURL() })));
img.style.width = '100%';
renderall(i + 1);
});
})();
})
</script>
</body>
</html>