Code Monkey home page Code Monkey logo

Comments (18)

ahmetaltay33 avatar ahmetaltay33 commented on May 26, 2024 1

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.

pieper avatar pieper commented on May 26, 2024

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.

MohsinAther avatar MohsinAther commented on May 26, 2024

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.

pieper avatar pieper commented on May 26, 2024

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.

MohsinAther avatar MohsinAther commented on May 26, 2024

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.

pieper avatar pieper commented on May 26, 2024

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.

MohsinAther avatar MohsinAther commented on May 26, 2024

but i need pixeldata aswell

from dcmjs.

pieper avatar pieper commented on May 26, 2024

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.

MohsinAther avatar MohsinAther commented on May 26, 2024

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.

pieper avatar pieper commented on May 26, 2024

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.

lam0620 avatar lam0620 commented on May 26, 2024

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.

pieper avatar pieper commented on May 26, 2024

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.

lam0620 avatar lam0620 commented on May 26, 2024

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.

pieper avatar pieper commented on May 26, 2024

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.

lam0620 avatar lam0620 commented on May 26, 2024

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.

pieper avatar pieper commented on May 26, 2024

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.

lam0620 avatar lam0620 commented on May 26, 2024

Hi @pieper

  1. I fixed my issues about converting dicom dataset to dicom json model by creating new code based on DicomMetaDictionary.denaturalizeDataset()

  2. 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!
  1. 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.

pieper avatar pieper commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.