DICOM query(/retrieve) using the REST-API

Hi,

First of all, let me say that I'm still very new to Orthanc and I'm not an expert in DICOM. So my question is probably very naive, it is also very simple. What I want is to use the REST API to do some DICOM queries. The FAQ gives some nice examples and what I get from this is that, as a Orthanc client, you can do the following:

(1) You can use the Rest API to query a remote modality (indirectly using C-Find SCU), for instance like this:
curl http://localhost:8042/modalities/pacs/find-patient -X POST -d '{"PatientName":"JOD*","PatientSex":"M"}'

(2) You can query the local modality (i.e. the Orthanc server) using a DICOM client (such as Osirix). This does not, however, use the REST API but uses C-Find

(3) You can 'browse' / index the local modality, for instance by using the python RestToolbox or curl

I have some python code to do the latter (3), i.e. to loop over all studies and 'query' the database in this way for some DICOM tags. This is a bit cumbersome but works. But it seems to me it should also be possible to do (1) but then on the local (Orthanc) server instead of on a remote server (e.g. by having 'ORTHANC' in place of 'pacs' in the above example, or something along that line). I think Orthanc probably has all the functionality to do this or am I missing something?

Cheers,
Marcel.

Dear Marcel,

Yes, this is definitely possible. You first have to declare your local Orthanc in the “DicomModalities” section of its configuration file [1]:

{
[…]

// The list of the known DICOM modalities
“DicomModalities” : {
“local” : [ “ORTHANC”, “localhost”, 4242 ]

}
}

Then, the following request will succeed:

curl http://localhost:8042/modalities/local/find-patient -X POST -d ‘{“PatientName”:“*”,“PatientSex”:“M”}’

HTH,
Sébastien-

[1] https://code.google.com/p/orthanc/wiki/OrthancConfiguration

So this redirects the query to itself... Mhhh, doesn't work for me however. Some are some lines from my Configuration.json (it is all in all pretty standard):

  "HttpPort" : 8042,
  "DicomAet" : "PLORTHANC",
  "DicomCheckCalledAet" : false,
  "DicomPort" : 4242,
  "RemoteAccessAllowed" : true,
  "SslEnabled" : false,
  "SslCertificate" : "certificate.pem",
  "AuthenticationEnabled" : false,
  "RegisteredUsers" : { "admin" : "admin" }
  "DicomModalities" : {
    "MRI-PRISMA" : [ "PRISMA", "prisma.dccn.nl", 104 ],
    "MRI-SKYRA" : [ "SKYRA", "skyra.dccn.nl", 104 ],
    "MRI-AVANTO" : [ "AVANTO", "avanto.dccn.nl", 104 ],
    "local" : [ "PLORTHANC", "localhost", 4242 ]
  },

I tried many things and got e.g. this:

curl -v http://admin:admin@pl-torque.dccn.nl:8042/modalities/PLORTHANC/find-patient -X POST -d '{"PatientName":"*","PatientSex":"M"}'
* Hostname was NOT found in DNS cache
* Trying 131.174.44.95...
* Connected to pl-torque.dccn.nl (131.174.44.95) port 8042 (#0)
* Server auth using Basic with user 'admin'

POST /modalities/PLORTHANC/find-patient HTTP/1.1
Authorization: Basic YWRtaW46YWRtaW4=
User-Agent: curl/7.38.0
Host: pl-torque.dccn.nl:8042
Accept: */*
Content-Length: 36
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 36 out of 36 bytes
< HTTP/1.1 404 Not Found
< Content-Length: 0
<
* Connection #0 to host pl-torque.dccn.nl left intact

I also tried to do queries using (dcmtk) C-FIND SCU, but these weren't successful either (here asking for the PatientID for a certain PatientName):

findscu -v -P -aet PLORTHANC localhost 4242 dicomqry.dcm
I: Requesting Association
I: Association Accepted (Max Send PDV: 16372)
I: ===================== OUTGOING DIMSE MESSAGE ====================
I: Message Type : C-FIND RQ
I: Presentation Context ID : 1
I: Message ID : 1
I: Affected SOP Class UID : FINDPatientRootQueryRetrieveInformationModel
I: Data Set : present
I: Priority : low
I: ======================= END DIMSE MESSAGE =======================
I: Find SCU Request Identifiers:
I:
I: # Dicom-Data-Set
I: # Used TransferSyntax: Little Endian Explicit
I: (0010,0010) PN [20140413_alebac_301202506_S25 ] # 30, 1 PatientName
I: (0010,0020) LO (no value available) # 0, 0 PatientID
I:
I: ===================== INCOMING DIMSE MESSAGE ====================
I: Message Type : C-FIND RSP
I: Message ID Being Responded To : 1
I: Affected SOP Class UID : FINDPatientRootQueryRetrieveInformationModel
I: Data Set : none
I: DIMSE Status : 0xc000: Error: Failed - Unable to process
I: ======================= END DIMSE MESSAGE =======================
I: Releasing Association

The Orthanc logs just say this:
E0424 13:59:06.251377 24633 FindScp.cpp:134] C-FIND request handler has failed: Bad request

I'm stuck kind of now, do you perhaps have any suggestions that could help me go further?

As a side note, I was wondering, why not built in this localhost-loop by default, i.e. without having to specify the localhost as a known modality (it knows itself after all)? Now you get potential funny side effects like having [local] as an option when sending studies to (remote) modalities using the webexplorer...

Cheers and thanks a lot for your time & effort,
Marcel

p.s. the DICOM query was constructed as follows:
cat dicomqry.dump
(0010,0010) PN [20140413_alebac_301202506_S25] # 20, 1 PatientName
(0010,0020) LO # PatientID

and then:
dump2dcm dicomqry.dump dicomqry.dcm

This then yields:
dcmdump dicomqry.dcm

# Dicom-File-Format

# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0000) UL 202 # 4, 1 FileMetaInformationGroupLength
(0002,0001) OB 00\01 # 2, 1 FileMetaInformationVersion
(0002,0002) UI [1.2.276.0.7230010.3.1.0.1] # 26, 1 MediaStorageSOPClassUID
(0002,0003) UI [1.2.276.0.7230010.3.1.4.2927845164.20927.1429867526.348893] # 58, 1 MediaStorageSOPInstanceUID
(0002,0010) UI =LittleEndianExplicit # 20, 1 TransferSyntaxUID
(0002,0012) UI [1.2.276.0.7230010.3.0.3.6.0] # 28, 1 ImplementationClassUID
(0002,0013) SH [OFFIS_DCMTK_360] # 16, 1 ImplementationVersionName

# Dicom-Data-Set
# Used TransferSyntax: Little Endian Explicit
(0010,0010) PN [20140413_alebac_301202506_S25] # 30, 1 PatientName
(0010,0020) LO (no value available) # 0, 0 PatientID

Ah, by RTFM I managed at least to get the C-FIND SCU working. I needed to add:
(0008,0052) CS [PATIENT] # QueryRetrieveLevel!
to the dump-file.

No I'm still stuck why the REST query doesn't work...

What I’m trying to figure out … is how to do a C-FIND, but only by REST, getting a REST reply.

I mean … doing a query like the ones that DICOM clients sends … but get the results by REST, no DICOM.

I reviewed how the web-explorer does … but seems to get ALL the patients and the iterate throught them … that’s not usable to me, as the patients DB it’s too big …

Hi Marcel,

What if you try "modalities/local/" instead of "modalities/PLORTHANC/" ?

Alain

I don't know what has happened but miraculously my REST queries (the exact same ones) now all work! :slight_smile:

Now all I need to do is figure out how to translate this into python code using the RestToolbox :stuck_out_tongue:

Eureka!! …

So basically what that do, it’s a ‘loopback’ conection … wonderfull!!

Now I could finish my AngularJS proyect … :slight_smile: