Skip to content
Reference

Filters

The rule syntax, field paths, operators and AND/OR groups that decide which messages a trigger accepts.

On this page

A filter drops a message before its workflow runs. A trigger takes a message only when its filter passes. The same rules drive a condition step in rules mode, and the builder shows the verdict on a loaded sample.

json
{
  "logic": "AND",
  "rules": [
    { "field": "MSH.9.1", "operator": "equals", "value": "ADT" },
    { "field": "PV1.2", "operator": "in", "value": ["I", "E"] }
  ],
  "groups": [
    {
      "logic": "OR",
      "rules": [
        { "field": "MSH.4", "operator": "equals", "value": "FACILITY_A" },
        { "field": "MSH.4", "operator": "equals", "value": "FACILITY_B" }
      ]
    }
  ]
}

This filter passes an ADT message for an inpatient or emergency visit from either facility.

Rules

Each rule has three parts.

PartWhat it is
fieldThe path to read. See Field paths.
operatorHow to compare. See Operators.
valueWhat to compare with: a string, a number, or a list of strings.
ignoreCaseOptional. true ignores case, false matches it, for equals, not_equals, contains, starts_with, ends_with, in, not_in, matches and regex. Left out, contains ignores case and the others match it. In the builder: match case or ignore case.
matchOptional, on a wildcard path such as OBX[*].5: any (default) passes when one value passes, all when every one does. No values at all counts as one absent value.

AND and OR groups

logic combines the filter's own rules and its groups. AND needs every part to pass. OR needs one.

A group has its own logic and its own rules, and counts as one part of the outer logic. Groups go one level deep. A group inside a group is not supported.

An empty filter passes everything. An empty group passes.

Field paths

HL7v2 and X12 segments

A segment path is the segment name, then a field number, then optional component and subcomponent numbers, all separated by dots.

PathReads
MSH.9The whole of MSH-9, such as ADT^A01.
MSH.9.1Component 1 of MSH-9, such as ADT.
PID.3.4.1Subcomponent 1 of component 4 of PID-3.
ST.1Field 1 of the X12 ST segment.

Numbers start at 1. Field, component and subcomponent numbers follow HL7 notation, so MSH.9.1 is the first component of MSH-9 and PID.5.2 is the given name in PID-5. A filter saved before this rule is upgraded when the engine loads it.

For MSH, field 1 is the field separator and field 2 is the encoding characters, as in the HL7 standard, so MSH.9 is the message type.

A plain path reads the first occurrence of a segment: for a message with several OBX segments, OBX.5 is the value in the first one. Name another occurrence or repetition like this. Numbers are 1-based.

PathReads
OBX[2].5OBX-5 of the second OBX.
OBX[*].5OBX-5 of every OBX. The rule's match decides.
PID.3(2).1Component 1 of the second repetition of PID-3.
PID.3(*)Every repetition of PID-3. The rule's match decides.

Repeats

A repeating field holds several values separated by ~, such as two patient identifiers in PID-3.

  • A path without a component, such as PID.3, reads the whole field, including every repeat. contains and regex look through all of them.
  • A path with a component, such as PID.3.1, reads that component of the first repeat only. To read another repeat, name it: PID.3(2).1, or PID.3(*).1 for all of them.

The repeat separator comes from MSH-2. The engine uses ~ if the message does not say.

In the builder, the rule's field picker lists the sample's fields. With the flat field-path view on (off by default), it also offers each repetition and occurrence, such as PID.3(2).1, PID.3(*).1 and OBX[2].5, and a Retrohook key typed into the field, such as PID.3[0].1, is saved as PID.3(1).1. See Field paths.

Empty means absent

An empty field, component or subcomponent reads as absent on every message shape. exists is false for it and not_exists is true. equals "" never matches an empty field, so use not_exists.

Other paths

PathReads
$.resourceTypeA JSON path in a FHIR resource or any JSON body. Arrays use $.entry[0].resource.
a.b.cA plain dot path into the data.
messageTypeA top-level value of the trigger payload, such as messageType or sendingFacility.

On an MLLP trigger, the filter sees the trigger payload with the parsed segments laid over it, so messageType and PV1.2 both work. An sftp or file pickup run whose content is HL7 is read the same way, so MSH.9.1 works there too; a binary (base64) pickup has no segments. content and file.name can be filtered as well.

XML paths

A path that starts with xpath: reads an XML message with an XPath expression, such as xpath://Patient/identifier/@value. The XML is the message itself, or its content, data or rawMessage text, so it works on an SFTP pickup run and on a webhook XML body. Several matches give a list, and the rule's match decides.

XML with a DOCTYPE or ENTITY declaration is never parsed: the path reads as absent, so the rule fails closed. Saving refuses an expression outside the supported subset.

Operators

OperatorPasses when
equalsThe value equals value. Numbers and strings compare as text. Case matters unless ignoreCase is true.
not_equalsIt does not.
containsThe value contains value. Case does not matter unless ignoreCase is false.
starts_withThe value starts with value. Case matters unless ignoreCase is true.
ends_withThe value ends with value. Case matters unless ignoreCase is true.
regexA JavaScript regular expression matches anywhere in the value. A bad pattern fails the rule. Saving refuses a filter with a pattern that does not compile, or a script with a syntax error, with 400.
matchesThe whole value matches a glob: * for any run of characters, ? for one. ADT^A0* matches ADT^A01. A list passes when any glob matches.
existsThe field is present and not empty.
not_existsThe field is absent or empty.
inThe value equals one item of the list.
not_inThe value equals no item of the list. An absent field passes.
greater_thanThe value and value are numbers and the value is larger.
less_thanThe same, smaller. A non-numeric value fails.

Every operator except exists, not_exists, not_equals and not_in fails when the field is absent.

Custom script

A filter may carry a customScript. It runs last, in the same sandbox as JavaScript transforms, with two values: data (the message) and passed (the result of the rules). Return true to accept the message.

A filter with a script and no rules runs the script on every message, with passed set to true, so the script alone decides. This is how an imported Mirth JavaScript source filter arrives.

If the script throws, the message is rejected (fails closed, as a Mirth filter error does), whether or not the filter has rules, and the trigger writes a trigger.filter.script_error audit entry with ids only. A script that throws on a missing field therefore filters those messages, so test a script with messages that lack the fields it reads. On a polling trigger a throwing script rejects nothing: the poll stops before the item and records that the script failed (the error itself is in the engine log), and the item is read again on the next poll.

Test it

Take this synthetic message:

text
MSH|^~\&|EHR_A|FACILITY_A|||20260101120000||ADT^A01|MSG0001|T|2.5.1
PID|1||MRN0001||TESTPATIENT^SAMPLE
PV1|1|I

With the filter at the top of this page, MSH.9.1 is ADT, PV1.2 is I and MSH.4 is FACILITY_A, so it passes. Change PV1.2 to O and it is dropped.

Reference