ISSUE: Invalid SQL Generated When Searching by Patient Name, ID, or Study Description

When searching for an existing study by Patient Name, ID, or Study Description, no results are found, and the following error is logged by Orthanc:

{“log”:“E0710 00:42:54.772681 HTTP-7 PluginsManager.cpp:154] PostgreSQL error: ERROR: unterminated quoted string at or near "‘\’) ) AS studies INNER JOIN Resources series ON series.parentId = studies.internalId GROUP BY studies.publicId ) AS studies_series INNER JOIN Resources instances ON instances.parentId = studies_series.series_internal_id GROUP BY studies_series.studies_public_id"\n”,“stream”:“stderr”,“attrs”:{“tag”:“orthanc”},“time”:“2024-07-10T00:42:54.772822905Z”}
{“log”:“LINE 1: …= 16 AND tagElement = 16 AND value LIKE $1 ESCAPE ‘\’) ) AS …\n”,“stream”:“stderr”,“attrs”:{“tag”:“orthanc”},“time”:“2024-07-10T00:42:54.772826208Z”}
{“log”:" ^\n",“stream”:“stderr”,“attrs”:{“tag”:“orthanc”},“time”:“2024-07-10T00:42:54.772828456Z”}

However, the search is successful when using Patient Birth Date or Study Date.

Steps to Reproduce:

  1. Go to the search interface.
  2. Enter a Patient Name, ID, or Study Description in the search field.
  3. Execute the search.
  4. Observe that no results are returned and the above error is logged.

Expected Behavior: Search results should be returned when querying by Patient Name, ID, or Study Description without any SQL errors.

Actual Behavior: No results are returned, and an SQL error is logged indicating an unterminated quoted string.

Environment:

  • Orthanc Version: 1.12.4
  • PostgreSQL-Index Plugin: 6.2
  • Orthanc-Explorer-2 Plugin: 1.5.1

Hi,

Well, this does not happen with, e.g., this sample setup.

So you’ll have to provide more info on your setup for us to reproduce …

Best regards,

Alain

Hi Alain,

Thanks for the quick response!

I noticed some variation from the minimal sample setup you provided, so there could be a field or flag that we have missed in our configuration. It should be noted that we see the same error when requesting studies via a DICOM Query Retrieve from a DICOM receiver.

Here is our full Orthanc configuration file:

version: “3.5”
services:
orthanc:
restart: unless-stopped
image: orthancteam/orthanc
ports: [“4242:4242”, “8042:8042”]
environment:
POSTGRESQL_PLUGIN_ENABLED: “true”
depends_on:
- postgres
volumes:
- /usr/share/orthanc/plugins/:/data/orthanc/plugins/
- /mnt/dcmdata/orthanc/:/var/lib/orthanc/db/
- {{ orthanc_root_dir }}:/etc/orthanc/
logging:
driver: json-file
options:
labels: “orthanc_status”
tag: orthanc
postgres:
restart: unless-stopped
image: postgres:15
environment:
POSTGRES_DB: orthanc
POSTGRES_USER: orthanc
POSTGRES_PASSWORD: {{ orthanc_db_pass }}
volumes:
- {{ postgres_data_dir }}:/var/lib/postgresql/data
ports:
- “5432:5432”

why ???

If you are mapping locally built plugins into the container, I’m sure you understand that I’m not able to reproduce your issue (I won’t even try).

Please start from the working sample I have provided and modify it until it fails. If you are using custom plugins that have not been built for the Docker container, you should double check your code …