Comments (18)
My javascript solution for converting dicom Json to dicom Dataset.
<script src="https://unpkg.com/dcmjs"></script>
<script src="https://unpkg.com/dicomweb-client"></script>
<script>
const dwc = DICOMwebClient.api.DICOMwebClient;
const options = {
url: "https://server.dcmjs.org/dcm4chee-arc/aets/DCM4CHEE/rs"
};
const dicomweb = new dwc(options);
const getStudies = async () => {
const studies = await dicomweb.searchForStudies(
{
queryParams:
{
limit: 10,
offset: 0,
fuzzymatching: true,
StudyDate: "20090101-20211231",
ModalitiesInStudy: "CT",
includefield: "00081030,00080060"
}
});
return studies;
}
const convertToDataset = (dcmJson) => {
return dcmjs.data.DicomMetaDictionary.naturalizeDataset(dcmJson);
}
const getStudiesAsDataset = async () => {
const studies = await getStudies();
const result = new Array();
studies.forEach(study => {
const dataset = convertToDataset(study);
result.push(dataset);
});
return result;
}
getStudiesAsDataset().then(studiesDs => {
studiesDs.forEach(study => {
console.log('Study Instance UID: ' + study.StudyInstanceUID);
console.log('Accession Number: ' + study.AccessionNumber);
console.log('Patient ID: ' + study.PatientID);
console.log('Patient Name: ' + study.PatientName);
});
});
</script>
from dcmjs.
It's basically the same. You can populate the javascript object from scratch rather than using one loaded from a file. You can follow the basic style shown in #64 (use tag names and the hex and vr are pulled from the dictionary).
from dcmjs.
I loaded my js file and edited the tag. but im unable to save it correctly. i also used "WriteBufferStream" but not working
Error "Cannot read property 'isLittleEndian' of undefined". whereas write function take 3 args
static write(jsonObjects, useStream, syntax)
i'm doing something wrong ?
const dcmjs = require("dcmjs");
const fs = require("fs");
const filePath = require("./data.json");
var dataset = dcmjs.data.DicomMetaDictionary.naturalizeDataset(filePath);
dataset.PatientName = "DemoPatient"
dataset = dcmjs.data.DicomMetaDictionary.denaturalizeDataset(dataset);
let new_file_WriterBuffer = dcmjs.data.DicomMessage.write(dataset)
fs.writeFileSync("./seriesImage1.dcm", new_file_WriterBuffer);
from dcmjs.
Hard to say at a glance, but the best bet is probably just to print out each variable as you go and confirm it has the value you expect. Or start with the other working example and make incremental changes and confirm each one. This week is kind of busy for me, but probably next week we should make a some examples (tests) that cover this use case.
from dcmjs.
i have added a debugger and watched each and every value .
let DicomDict = dcmjs.data.DicomMessage.readFile(arrayBuffer);
this line is converting, dicom file from buffer to object => output is a object which has metadata and dict objects and same object is calling write function
DicomDict.write();
i have made the same js object in "DicomDict" variable as given in example and tried (without let DicomDict = dcmjs.data.DicomMessage.readFile(arrayBuffer); )
and then called
DicomDict.write();
Error => DicomDict.write() is not a function.
it would be really appreciated if you can help me in this in comments. thanks
from dcmjs.
Hi - maybe you already figured this out, but if not this code might help.
Basically this WIP code converts between part10 and json files. It doesn't handle PixelData or other data that should be base64 encoded but it works for other data.
https://github.com/dcmjs-org/dcmjs/blob/add-commander/bin/dcmjs-cli.js#L32-L43
from dcmjs.
but i need pixeldata aswell
from dcmjs.
Yes, I plan to add that to the dump/undump with base64 encode/decode according to the standard (or maybe as a separate file so the json is easier to manipulate).
In any case you should be able to just set PixelData to be the right kind of TypedArray.
I hope this is enough to get you going. If you get something working please post it here for future reference. Or if it's not working let me know and I can try to flesh out some more examples (obviously this project needs more documentation anyway 😄 )
from dcmjs.
i have written a new function and passing json to it. (i hardcoded some meta just for testing purpose, and added pixel data to 7fe00010 tag. its writing the dcm file. meta is correct but viewers i.e RadiAnt could not open it. and i tried to view in dicom tree viewer which is showing its tree perfectly. but i dont know, im missing something.
function toArrayBuffer(buf) {
var ab = new ArrayBuffer(buf.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buf.length; ++i) {
view[i] = buf[i];
}
return ab;
}
var meta = { '7fe00010': { vr:'OB', Value:[]}}
var buff = Buffer.from(buffer['7fe00010'].InlineBinary)
meta['7fe00010'].Value.push(toArrayBuffer(buff));
var meta={}
meta['00020002'] = {vr: 'UI', Value: [buffer['00080016'].Value[0]]};
meta['00020003'] = {vr: 'UI', Value: [buffer['00080018'].Value[0]]};
meta['00020010'] = {vr: 'UI', Value: ["1.2.840.10008.1.2"]};
meta['00020012'] = {vr: 'UI', Value: ["2.25.661331934852393026330823390029087831751"]};
meta['00020013'] = {vr: 'SH', Value: ["DICOMzero-0.0"]};
delete buffer['7fe00010']
var dicomDict = new DicomDict(meta);
dicomDict.dict = buffer;
return dicomDict;
from dcmjs.
Here's some code to generate an image instance from scratch. The resulting file can be loaded in 3D Slicer, so it should be a good starting point for you:
https://github.com/dcmjs-org/dcmjs/blob/add-commander/examples/nodejs/generate.js
from dcmjs.
Any body know how to convert DICOM dataset to json ?
"00080018" : {
"vr" : "UI",
"Value" : [
"1.3.12.2.1107.5.4.3.321890.19960124.162922.29"
]
},
"00080020" : {
"vr" : "DA",
"Value" : [
"19511013"
]
}......
from dcmjs.
The example linked above does this, but using a dataset with names (a namified
version of the dicom json model).
You can see a round trip from part10 to json model back to edited part10 here:
https://github.com/dcmjs-org/dcmjs/blob/add-commander/examples/nodejs/readwrite.js
from dcmjs.
Thanks @pieper
Does dcmjs support convert dicom dataset to dicom json model ?
Same: http://dicom.nema.org/dicom/2013/output/chtml/part18/sect_F.4.html
from dcmjs.
That should be DicomDict.dict
in the example (I can't doublecheck right now - I'm away from my regular desk until next week).
https://github.com/dcmjs-org/dcmjs/blob/add-commander/examples/nodejs/readwrite.js#L9
What's your overall goal? You can also look at the dicomweb-server code which works with that form.
from dcmjs.
Thank you @pieper . Let me check.
My overall goal is
I'd like to convert a dicom dataset responsed from DIMSE (use dimse-dicom package) to dicom json model for dicomweb client as ohif viewer react version.
from dcmjs.
Sounds good @lam0620, let us know how it goes.
For reference, we are also looking at the option of building a DIMSE gateway on the server side as described in this issue. We are leaning toward the dcmtk-node option since dimse-dicom isn't actively developed at the moment.
from dcmjs.
Hi @pieper
-
I fixed my issues about converting dicom dataset to dicom json model by creating new code based on DicomMetaDictionary.denaturalizeDataset()
-
DIMSE gateway
I can not build use dimse-dicom yet, so I use OHIF meteor version to make a DIMSE gateway
- Remove unuse pakages, files from OHIF
- Add new restful APIs (QIDO, WADO-RS) => not sure right!!!
- Test work with OHIF react version <--> DIMSE gateway <--> CC PACS model
DICOM can be displayed correctly!
- Other
I will try research https://github.com/jmhmd/dcmtk-node!
https://github.com/sync-for-science/dcmrs-broker A DIMSE getway use dcm4che lib.
Currently only the retrieval of DICOM Part 10 objects is supported. The retrieval of bulk data and meta data are not supported.
from dcmjs.
Sounds like the original issue has been resolved. @lam0620, let us know if you have follow up information that might be useful for others in the future.
from dcmjs.
Related Issues (20)
- [mutiple Qs]: convert .jpg to .dcm, no dicom header, could't not find declaration module ''dcmjs",... HOT 5
- DicomMessage.readFile failes if GroupLength parameter is wrong calculated HOT 4
- use SegmentNumber from the segment metadata exporting DICOM SEG. HOT 6
- US cine loops with Transfer Syntax RLE Lossless are corrupted after DicomMessage.write when fragmentMultiframe option is enabled HOT 5
- anonymizer uses incorrect tag names HOT 1
- The saved image file is inconsistent with the source file. HOT 9
- private Tags take element wrong into account HOT 1
- Segmentation loading with wadors not working HOT 1
- dcmjs-imaging HOT 2
- Invalid tag in sequence : Unable to parse MR Dicom file in dcmjs. Cornerstone able to parse and works fine HOT 1
- Order of tags gets messed up when edition DICOM SEG HOT 5
- Length of Decimal String larger than 16 characters
- Lots of 'Invalid vr type... ' log messages in dcmjs release 0.29.11 HOT 4
- modifying dicom meta-data HOT 2
- Reading dicom file HOT 1
- Getting ERROR: Value exceeds max length for some DICOM tags HOT 2
- Write issue for JPEG2000Loseless images HOT 3
- Issue with pixel redaction for JPEGLoseless type HOT 1
- Change in PixelSequence value HOT 1
- Support for reading from a readable stream HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dcmjs.