Modifying or filtering incoming DICOM instances in Orthanc

Learn how to reject, filter or modify DICOM instances as they arrive in Orthanc, which scripting layer fits each case, and what to confirm before production use.

On this page

Filtering and modifying incoming DICOM instances in Orthanc

A team receiving images from modalities or peers often needs to act before anything reaches the archive: reject studies that do not belong to the site, correct a mislabeled tag, or add a marker that routes the image to the right workflow. In Orthanc, this work happens while instances arrive over DICOM C-STORE, so the decision is made per instance, not after the study is already indexed. The capability covers three outcomes: accepting an instance as received, rejecting it so the sending device receives a failure status, or changing its content before it is stored. Teams usually need it when several modalities or referring sites feed one archive and their metadata is inconsistent, or when a policy forbids certain patients, institutions or modalities from being stored at all.

The Lua and Python split matters for planning. Lua scripts are the lighter option for filtering incoming C-STORE traffic and reacting to events, and they are covered in the sibling Lua topic. The Python plugin is where modifying received instances is documented. According to the Orthanc Book, filtering incoming C-STORE instances and modifying received instances are features added in plugin release 4.0 of the Python plugin, so confirm the plugin version in your environment before designing around either feature. Check the Python plugin documentation for the current callback names, return values and any changes since 4.0, because the exact behavior of rejection and modification is defined there and not in this summary.

Before building the logic, decide who owns the rules and what must be logged. A rule that silently changes a patient identifier can break matching with existing records, so the team should agree which fields may be altered, who approves new rules, and how each change is recorded in an audit trail. Test rejections against the real sending devices in a non-production Orthanc, confirm how the modality reports a refused store, and check that OverwriteInstances behavior is understood for re-sent instances that the new rules touch. Ask the implementer to show where each modification is logged and how the log is protected, since a change record that the same administrators can edit provides weak evidence.

Choosing Lua or Python for incoming instance control

The first question is whether the team needs to reject instances or change them. Filtering decides whether an incoming C-STORE instance is accepted or refused, based on its metadata or the sending source. Modification changes the content of instances that are already accepted, such as rewriting tags or adding values before storage. The Orthanc Book's Python plugin page documents both modifying received instances and filtering incoming C-STORE instances as features added in plugin release 4.0, so a team that needs both jobs in one language has a documented option.

  • Reject only: a Lua filter that returns accept or refuse for each incoming instance covers rules such as blocking unknown modalities or unexpected modalities.
  • Change received data: modifying instances on arrival is the Python plugin's documented feature from release 4.0 onward.
  • Both jobs: a single Python plugin can handle filtering and modification, which avoids splitting logic across two runtimes.
  • Mixed rules: keep rejection rules and rewrite rules in separate functions so each can be tested on its own.
  • Confirm the version: check the plugin version installed in your Orthanc build before you design around these features.

Before you commit, write down which of your rules reject data and which rewrite it, then map each rule to a language.

Configuration options and when each fits

This table compares the four main ways to control incoming DICOM instances in Orthanc: a Lua incoming filter, a Python modification hook, the OverwriteInstances behavior, and an external audit log. Read each row against your workflow to see when the option fits and what it costs you to run. The main takeaway is that filtering and modification happen at different points, so the choice depends on whether you need to reject, change, or merely record what arrives.

OptionWhen it fitsMain trade-off
Lua incoming filterYou need to accept or reject C-STORE instances on arrival based on tags such as modality, institution, or series description.Logic runs for every incoming instance, so slow or complex scripts add latency. Rejected images must be handled by the sending modality.
Python modification hookYou need to change received instances, such as normalizing tags or adding values, before they are stored. The Python plugin documents this from release 4.0.Changes alter stored data, so you must confirm the rules with your clinical and governance owners. Python adds a plugin dependency to maintain.
OverwriteInstances behaviorA sender may resend an instance that already exists and you need to decide whether the new copy replaces the stored one.Overwriting can silently replace the original data. Confirm the setting against the official docs for your Orthanc version before relying on it.
External audit logYour compliance or quality team needs a record of what was received, rejected, or changed, kept outside the server's own state.You must design, store, and protect the log yourself. Confirm what Orthanc records natively and what your integration must add.

Setting up a filter and modification pipeline

This sequence takes an Orthanc server from a version check to a tested pipeline that accepts or rejects incoming DICOM instances, modifies the ones it keeps, and confirms the stored result. Each step ends with a check so the team knows whether to move on.

  1. Confirm the Orthanc and Python plugin versions

    Record the Orthanc core version and the Python plugin release running on the test server before writing any code. The Orthanc Book documents modifying received instances and filtering incoming C-STORE instances as features added in plugin release 4.0, so a server on an older plugin cannot run this pipeline as described. Check the core version against the Orthanc NEWS file and your change-control records, and confirm the plugin version with your platform team. Done when both versions are written in the change ticket and the test server reports the same versions.

  2. Place the script in the configured location

    Copy the Python script into the directory that your Orthanc configuration points to for plugins, and confirm the configuration file loads the Python plugin with that path. Keep the script under version control and restrict write access to the file so that only the operations team can change it. Restart the test instance and read the startup log for errors from the plugin or the script. Done when the log shows the plugin loaded without errors and the script's startup message appears.

  3. Define the accept or reject rule

    Write the filter that decides whether each incoming C-STORE instance is accepted or rejected, based on the sending modality's AE title and the DICOM attributes you need to check. Start with a narrow rule that rejects a small, known set of input so the effect is easy to see. Test it with a test modality or a DICOM echo and store tool, sending one accepted and one rejected instance. Done when the accepted instance appears in the index and the rejected one is absent from both the index and the storage area.

  4. Define the modification rules

    Add the rules that change the instances you keep, such as replacing a tag, setting a value required by your workflow, or removing a private tag. Limit each change to the attributes named in your written specification, and record which attributes each rule touches. Send a test instance with known values and compare the incoming values with the stored values. Done when every change matches the specification and no attribute outside the list has changed.

  5. Test overwrite behavior with duplicate instances

    Send the same SOP Instance UID twice, first with the original values and then with a changed value, and observe what Orthanc stores. Check the OverwriteInstances setting in your configuration, because it controls whether a second copy replaces the first. Confirm that the behavior matches the policy your data owners approved, and record the result for each case you tested. Done when the duplicate test produces the expected stored value and the result is documented in the test log.

  6. Verify results in the stored index

    Query the REST API for the test instances and compare the stored tags, study and series identifiers, and the instance count with the expected results from your test plan. Check that rejected instances do not appear in the index or the storage area, and that modified instances carry the intended values. Keep a copy of the test inputs and outputs for the audit trail of changes. Done when every expected result is confirmed, any mismatch is logged with a ticket, and the pipeline is approved for a wider test.

How a received instance moves through the filter and modification steps

The point to settle first is that an incoming instance does not pass through a single hook. In Orthanc, a C-STORE arrival is handled by the DICOM SCP, then the server decides whether to accept or refuse it, may let scripts or plugins inspect or change it, and finally writes it to storage and the index. The Lua and Python callbacks that filter or modify instances sit inside that sequence, so a rejection made by a script stops the flow before the instance is stored, while a modification made by a script changes what gets stored and indexed. The exact order of these steps, including whether a modification runs before or after the server's own checks such as its acceptance rules and the OverwriteInstances setting, is not something to assume from memory. Confirm it against the Orthanc version you run, by reading the event documentation for that release and by testing one instance through each path in a non-production instance.

When a script rejects an instance, the sender does not receive a success status. The sending modality or peer sees a DICOM failure on that store request, and the instance does not appear in the index or the file storage. The receiving team must check three things: the logs of the Orthanc instance, to confirm the rejection came from the intended callback and was not an error in the script itself; the sender's own store log, because many modalities retry or queue failed sends and may resend the same object repeatedly; and whether any failed instance was expected to be kept for review, since a rejected instance is not stored and cannot be inspected later in Orthanc. Treat a script error as a serious fault, not a quiet pass, and confirm with the sending site how it handles a refused store before you go live.

Modifications create a second question: which version of the instance is the one of record. If a script changes tags on arrival, the stored object and the sender's original can differ, so any later query, retrieval or matching by the sender may fail or appear to point to a different study. Decide in advance whether the modified instance is the authoritative copy, document the change, and test a full round trip (store, query, retrieve) with a sample from each sending device. Ask your Orthanc partner or the Orthanc Team to confirm how the chosen version handles overwrites, since a resend of an already modified instance is where duplicate or conflicting records most often appear.

Incoming C-STORE decision path in Orthanc

The path starts when a modality or peer sends a C-STORE request to Orthanc. The filter callback decides whether the instance is accepted or rejected before anything is written. Accepted instances may then be modified, pass an OverwriteInstances check against the existing copy, and reach storage, where the audit entry records what changed. Check that rejected instances never reach storage and that each accepted change is logged in the order shown.

Decision path for an instance arriving over DICOM C-STORE in Orthanc.

Security risks when scripts change incoming data

Scripts that filter or modify incoming DICOM instances sit close to patient data and to the server's own control surface. The cards below cover the risks that connect those scripts to the REST API, the execution routes, remote access and the audit trail.

Scripts can alter patient data silently

A filter or modification script runs on every instance that arrives, so a faulty rule can change identifiers, drop images or misroute studies without anyone noticing. Before go-live, test each rule against a sample set of instances from each modality and confirm that studies still group correctly by patient and study identifiers. Keep a rollback copy of the script and document who may change it. Treat script edits as changes to clinical records, with review and sign-off.

Python plugin docs

Disable the execute-script route

The Orthanc security FAQ warns that the /tools/execute-script route can let a malicious user run any system command. Confirm that this route is disabled in your configuration and that no automation depends on it. Scripts that need system actions should run through approved, reviewed hooks instead. Check the setting after every upgrade, because a configuration rewrite can re-enable routes you turned off.

Security FAQ

Lock down the export route

The security FAQ also notes that the export route can overwrite files on the server. Scripts that modify instances often write intermediate files, so an open export route creates a path to overwrite archive content or configuration. Keep the route disabled unless a documented workflow needs it, and restrict any write locations to a dedicated directory with limited permissions. Verify the file permissions of the Orthanc service account.

Enable authentication before remote access

By default Orthanc accepts HTTP connections only from localhost. If RemoteAccessAllowed is enabled, the Book recommends setting AuthenticationEnabled to true with users defined in RegisteredUsers. Confirm that every account used by scripts and integrations has a named owner and the least privilege it needs. Serve the API over HTTPS through a reverse proxy when it is exposed beyond the local network.

Security FAQ

Control access per request

When several teams or systems call the REST API, a single shared account makes it impossible to tell who changed or read an instance. The advanced authorization plugin forwards each request's token to an external service that decides access and returns HTTP 403 when denied. Evaluate whether your identity provider can issue tokens for service accounts and users, and test that denied requests fail closed.

Authorization plugin docs

Protect the audit trail from tampering

A record of what a script changed is only useful if an operator cannot quietly edit it. Write audit entries to a location that the Orthanc service account can append to but not rewrite, and ship copies to a separate log system with its own retention. Ask whether changes to script files, configuration and the audit store are themselves logged. Test the trail by making a known change and confirming that it appears in the external copy.

Questions teams ask before changing incoming instances

How much effort does it take to filter or modify incoming DICOM instances in Orthanc?

Effort depends mostly on how many rules you need and how well they are defined. A single filter that rejects a known modality or a small set of series is a short build. Rules that rewrite tags, check consistency across studies, or depend on local naming conventions take longer because each rule needs test data, edge-case review and sign-off from the people who own the clinical or research workflow. The Python plugin documents modifying received instances and filtering incoming C-STORE instances as features added in plugin release 4.0, so confirm your target plugin version before scoping. Ask any partner to split the estimate into rule design, build, test and rollout.

What does the work need from our team?

You need a named owner for the imaging workflow who can define which instances must be accepted, changed or rejected, and what happens to rejected images. You also need access to a non-production Orthanc with representative DICOM samples from every modality that sends to it, plus someone who can review changes against your patient-data and retention policies. Engineers need to be comfortable with Lua or Python, the REST API and the Orthanc configuration file. Your radiology or research staff should confirm expected outcomes, because a rule that looks correct in code can still reject valid studies.

Can our own team build and validate this without a partner?

Often yes, if you have someone who already runs Orthanc and writes Lua or Python, and if the rules are limited in number. Teams usually struggle with validation rather than coding: they need realistic test sets, a repeatable way to send test C-STORE traffic, and a record of what was accepted or changed. Consider a partner when the rules touch many modalities, when changes must be explained to auditors, or when no one on staff has time to maintain the scripts after go-live. Orthanc Team SRL sells deployment, configuration and development services, with pre-paid dedicated support hours valid for 12 months, quoted on request.

How long does validation take?

Validation time follows the number of modalities, the variety of DICOM objects they send, and how many decisions need human approval. Plan for a test cycle on a non-production server, then a supervised period on production traffic where rejected and modified instances are reviewed before the rules are trusted. The time for each step is specific to your environment, so ask any partner or internal lead to break validation into sample collection, test runs, clinical review and rollback rehearsal, and to state which of those they assume you will staff.

What drives the cost of changing incoming instances?

The main drivers are the number of rules, the number of modalities and sites feeding the server, the complexity of the DICOM logic, and the amount of testing evidence required. A rule that rejects instances by one attribute costs less than one that rewrites several attributes and checks them against an external system. Recurring costs appear when modality configurations change, when Orthanc or plugin versions move, or when new rules are added. Ask for a quote that separates one-time build and validation from any ongoing support or upgrade work, and that lists the modalities and rule count it assumes.

What is the risk of rejecting or modifying images in production?

The main risk is losing or altering clinical data. A filter that is too broad can refuse valid studies, and a modification that changes identifiers can break matching with existing records. Keep rules narrow, log every decision, and test rollback before go-live. Orthanc's security FAQ also warns that the /tools/execute-script route can let a malicious user run system commands, so keep that route disabled while you change scripts. Review your configuration with the security team before enabling any new route.

How do we keep an audit trail of the changes?

Decide up front what each change must record: the original and new values of altered attributes, the rule that acted, the source modality and the time of the decision. Write these records to a log or database that your compliance team can review, and protect them with the same access controls as the images. Confirm with your compliance or privacy team which records they need and how long they must be kept. A tool that alters data without leaving a clear record of what changed will be hard to defend in a review.

When should we bring in a partner for this work?

Bring in a partner when the scope spans several sites or modalities, when rules must pass a formal review, or when your team cannot commit people to build, test and maintain the scripts. DeployOpen plans, implements, customizes, hardens and documents self-hosted open-source platforms inside your own infrastructure, and works from a fixed scope agreed in writing before work starts. Ongoing support and upgrades are available as retainers. Ask for the written scope, the deliverables, and the evidence you will receive before you sign.

Keeping an audit trail of every change

An audit trail for incoming instances should let you answer, for any single image, what arrived, who sent it, what Orthanc changed or refused, and which rule did it. For each modified instance, record the receive time, the calling AE title and remote host, the original SOP Instance UID and the new one if it was rewritten, the Patient ID and Accession Number before and after, and the name and version of the Lua or Python rule that acted. For each rejected instance, record the same sender and time fields plus the rule that rejected it and the reason returned to the modality. Write these records from inside the script at the moment of the decision, not from a later comparison, because once the original is overwritten the before values are gone unless you saved them.

Store the trail outside the Orthanc database and its DICOM storage area, in a location the Orthanc service account can append to but not edit, such as a separate log file shipped to your central log platform or an append-only object storage bucket. Keep the original DICOM files for rejected or heavily rewritten instances only if your policy allows it, since they contain the patient data you are trying to control. To verify the trail, sample records each week, confirm that the logged new identifiers exist in Orthanc through the REST API, and confirm that rejected instances are absent. Test this on a non-production instance first, using a small set of illustrative test files.

Confirm retention periods, who may read the trail, and whether the records themselves count as protected health information with your compliance team and privacy officer before you design the log format. Those answers decide how long records are kept, whether they must be encrypted, and whether they can be stored with general application logs. The Orthanc Book security FAQ covers baseline access settings for the server, but retention and review obligations come from your own policies and applicable regulations.

How DeployOpen scopes and delivers incoming instance controls

DeployOpen works on incoming instance controls as a written scope: which C-STORE filters, modifications and audit records your Orthanc server needs, tested against your own modalities before go-live. The work runs inside your infrastructure, and the deliverables are scripts, test evidence and runbooks your team can maintain.

How we scope

  • Engagements are fixed-scope, with the list of accepted and rejected sending devices agreed in writing before work starts.
  • The scope lists which tags are changed, which instances are rejected and the reason codes that appear in logs.
  • Scope covers the Orthanc version and plugin set you run, including whether Lua, Python or both will host the logic.
  • Ongoing support after handover can be arranged as a retainer, and it is priced from the written scope rather than a list.

How we build

  • Filter rules are written as Lua callbacks or Python plugin handlers, depending on the decisions recorded in scope.
  • Each rule is tested with sample instances from every sending modality, including edge cases such as missing tags.
  • Modification logic is checked against OverwriteInstances behavior so re-sent studies do not silently change stored data.
  • Audit records for each changed or rejected instance are built and reviewed against the retention rules you specify.

How we hand over

  • Handover includes the scripts, configuration files and a test set that your team can rerun after upgrades.
  • A runbook describes how to add a sending device, change a rule and read the audit trail without vendor help.
  • Documentation records which controls are in place, so your compliance and security teams can review the evidence.
  • Your team receives a walkthrough of rejected-instance handling, including how to notify senders when an image is refused.

How we support

  • Support covers rule changes after Orthanc upgrades, since filter callbacks should be retested against each new release.
  • Confirm with Orthanc Team SRL which plugin and API behavior applies to your installed version before planning changes.
  • Periodic retesting of filters and audit output can be included in a retainer, with findings reported with fixes.
  • Ask for a written description of how support requests, change control and access to your environment are handled.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.