On Fri, May 26, 2017 at 3:25 AM, Thibault Nélis <
t...@osimis.io> wrote:
>
> > I am trying to retrieve a value that is a UID and is marked as a
> > string via the REST api of Orthanc.
> >
> > In navigating the REST interface, I expected all values from
> > '/instances/{id}/content/*' to have an Content Type of
> > 'application/json'. However when you retrieve a single value such as
> > 'instances/{id}/content/0020-000d/' it returns it as
> > 'application/octet-stream'.
> >
> > I can handle that however, I was expecting it to be a JSON string
> > especially if the type in the tags states "String".
>
> Actually I believe the data model here is the one described in DICOM
> (DICOM Data Dictionary), not JSON. If there were an "application/dicom-
> attribute" media type or similar it would probably be appropriate, but
> failing that application/octet-stream is the most sensible one IMO.
That is fair. I just assumed that since the REST API was returning
JSON for the content endpoint, that it would continue to return JSON
for attributes as well. I am able to detect for this, but it is more
workarounds than I would prefer.
I suppose is it possible to document in the REST API on Google Drive
which endpoints will serve JSON and which will serve
application-octet?
The use case that I have is a proxy for Orthanc, and I expected to
just proxy JSON for the "/instance/{id}/content/*" endpoint.
> > The actual issue I wanted to bring up, is that since it is returning
> > a non-JSON string, when parsing it with any http client, there is an
> > extra space (or space-like character) returned at the end of the
> > string.
> >
> > I have tried this with a few different patients. I am running Orthanc
> > 1.2.0 on Windows from Osimis.
> >
> > It looks like this in Python3 as a raw
> > string: b'1.2.840.113619.2.55.3.1678393098.910.1486472352.534\x00'
> >
> > Do you know why the '\x00' is being appended?
>
> Here is the DICOM Data Dictionary:
>
http://dicom.nema.org/medical/dicom/current/output/html/part06.html
>
> Lookup the attribute you're observing: 0020,000D (Study Instance UID).
> You'll see that its DICOM Value Representation is "UI".
>
> Here is the list of DICOM Value Representations:
>
http://dicom.nema.org/medical/dicom/current/output/html/part05.html#tab
> le_6.2-1
>
> Lookup "UI".
> You'll have all the information you need to parse it correctly (as you
> can see it is definitely not a JSON string, no quotes). This includes
> the trailing null byte and a small rationale. Please note that this is
> padding, it may not always appear (but AFAICT there can be only one if
> it's there).
I agree that it is possible for a trailing null byte to be present. If
you look at the "/tags" on an instance and look at the
StudyInstanceUID value (or any tag that returns a string) it doesn't
contain the null byte. However, when you access it via
/content/0020-000d/ it does contain the null byte. That to me isn't
consistent.
I suppose what I am looking for is the same result as parsing the
value from "/tags" when accessing it via content.
I am actually trying to do this for a specific tag for RT Structure
Set, so the tags are quite nested, so using the
"/instance/{id}/content/*" endpoint is preferred, otherwise the
request takes a long time to return.
> > Also when running this via curl and python, the content-length is
> > stated as 52, but if you check the length of the string it is only 51
> > characters.
>
> I cannot reproduce that unfortunately (see attached log, both the
> Content-Length and the actual entity body are 42 bytes long in my
> example). Can you provide the exact method you're using to get that
> reading?
So using the RT Struct from the dicompyler-core test data (
https://github.com/dicompyler/dicompyler-core/tree/master/tests/testdata/example_data),
following your test methods, I got a value of 44 for the
content-length when accessing the attribute directly (see attachment).
If you execute the following AJAX request in the console of the
Orthanc Web viewer (a surrogate to access the JSON content), the value
is also 44:
$.get('/instances/53f436e0-9c63bce0-20118a60-eb66e036-4e64188b/content/0020-000d/',
function(data) {
console.log(data.length);
});
44
However, when querying the JSON string in "/tags" you will see the
length of the string returned is only 43 characters.
$.getJSON('/instances/53f436e0-9c63bce0-20118a60-eb66e036-4e64188b/tags',
function(data) {
console.log(data["0020,000d"]["Value"].length);
});
43
This mismatch is what I am concerned about, and have to work around.
The JSON content is stripping the null byte, and I have to do the same
in my user code when processing the attribute directly.
Furthermore, what is interesting is that Orthanc will take both
versions (with and without the null byte) when you query
"/tools/lookup" with the UID.
In my opinion, and for consistency, I think the value returned by the
"/instance/{id}/content/*" should match the JSON string, especially
since "/tools/lookup" does not differentiate. This would simplify user
code, as it would not need to parse the data, and it seems to already
be occurring for the Orthanc JSON output.
Hope this makes sense.
Adit