Implementing Dynamic Tag with Attribute Coercion via Python Sidecar & XSLT

7 views
Skip to first unread message

Rady

unread,
Dec 21, 2025, 11:07:44 AM (22 hours ago) Dec 21
to dcm4che

Hello dcm4che Community,

I wanted to share a solution I’ve recently implemented for dcm4chee-arc-light that addresses a common challenge: Dynamic, database-driven tag modification during outgoing transfers.

The Challenge:
In our environment, we needed to modify the Retrieve AE Title (0008,0054) and Accession Number (0008,0050) on-the-fly when data is moved via C-MOVE to a destination. This logic depends on an external MySQL database, and we required the changes to be transient (in-memory only) to ensure the original data in our S3-backed storage remained untouched.

The Solution:
I’ve developed a "Sidecar Bridge" pattern that allows dcm4chee to maintain its enterprise-scale performance while gaining the agility of external scripting:

  1. Attribute Coercion: A standard rule in the Archive Device set to C_STORE_RQ and role SCP.

  2. XSLT Script: A namespace-agnostic stylesheet that uses the XSLT document() function to make real-time HTTP calls.

  3. Python FastAPI Bridge: A lightweight service that queries the MySQL database and returns the required tags as XML.

  4. Performance Optimization: We implemented TTL (Time-To-Live) Caching on the Python side to ensure that multi-image studies don't overwhelm the database, resulting in near-zero latency for subsequent instances.

The Implementation Journey:
It took about a week of deep-diving into the archive’s internal XML representation and WildFly’s logging subsystems to get this production-ready. I found that the "secret" to success was building a local XSLT testing environment in Python to simulate dcm4chee’s behavior, which allowed for rapid iteration without needing to trigger real moves or restart the container.

I have documented the full technical breakdown, including:

  • The FastAPI code with async database handling.

  • The XSLT stylesheet designed for both production and local testing.

  • The WildFly logging configuration required to see xsl:message output in the server.log.

  • The Testing Suite I used to validate the flow before deployment.

You can find the comprehensive guide and all code samples on my blog:
👉 https://radyworks.wordpress.com/

I’m sharing this in hopes it helps anyone looking to extend dcm4chee’s routing capabilities with external business logic. 

Reply all
Reply to author
Forward
0 new messages